Skip to contentSkip to conversation

linux/types.h: add sector_t and blkcnt_t types

PATCH Superseded [email protected] 2 participants 6 messages Feb 16, 2016 – Feb 19, 2016

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 linux/types.h: add sector_t and blkcnt_t types

From: Yegor Yefremov <[email protected]>

---
 include/linux/types.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/linux/types.h +16 -0
index 9f8eb67..f64ec4a 100644
@@ -157,6 +157,22 @@ typedef __u32 __bitwise __wsum;
 #define __aligned_be64 __be64 __attribute__((aligned(8)))
 #define __aligned_le64 __le64 __attribute__((aligned(8)))
 
+/**
+ * The type used for indexing onto a disc or disc partition.
+ *
+ * Linux always considers sectors to be 512 bytes long independently
+ * of the devices real block size.
+ *
+ * blkcnt_t is the type of the inode's block count.
+ */
+#ifdef CONFIG_LBDAF
+typedef u64 sector_t;
+typedef u64 blkcnt_t;
+#else
+typedef unsigned long sector_t;
+typedef unsigned long blkcnt_t;
+#endif
+
 /*
  * The type of an index into the pagecache.
  */
Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH v2 2/3 linux/fs.h: add types and routines needed for SquashFS

From: Yegor Yefremov <[email protected]>

---
 include/linux/fs.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
include/linux/fs.h +27 -0
index 7e9886a..e11a602 100644
@@ -19,6 +19,26 @@
 #endif
 
 /*
+ * File types
+ *
+ * NOTE! These match bits 12..15 of stat.st_mode
+ * (ie "(i_mode >> 12) & 15").
+ */
+#define DT_UNKNOWN	0
+#define DT_FIFO		1
+#define DT_CHR		2
+#define DT_DIR		4
+#define DT_BLK		6
+#define DT_REG		8
+#define DT_LNK		10
+#define DT_SOCK		12
+#define DT_WHT		14
+
+struct dir_context {
+	loff_t pos;
+};
+
+/*
  * These are the fs-independent mount-flags: up to 32 flags are supported
  */
 #define MS_RDONLY	 1	/* Mount read-only */
@@ -74,6 +94,7 @@ struct inode {
 	struct timespec		i_mtime;
 	struct timespec		i_ctime;
 	unsigned int		i_blkbits;
+	blkcnt_t		i_blocks;
 	unsigned short          i_bytes;
 	umode_t			i_mode;
 	spinlock_t		i_lock;	/* i_blocks, i_bytes, maybe i_size */
@@ -194,6 +215,7 @@ struct file_system_type {
 
 struct file {
 	struct path		f_path;
+	struct inode		*f_inode;	/* cached value */
 #define f_dentry	f_path.dentry
 #define f_vfsmnt	f_path.mnt
 	const struct file_operations	*f_op;
@@ -361,4 +383,9 @@ struct file {
 #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
 #define I_DIRTY_ALL (I_DIRTY | I_DIRTY_TIME)
 
+static inline loff_t i_size_read(const struct inode *inode)
+{
+        return inode->i_size;
+}
+
 #endif /* _LINUX_FS_H */
Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH v2 3/3 fs: add support for SquashFS 4.0

In reply to [email protected]

From: Yegor Yefremov <[email protected]>

The driver was imported from Linux 4.4.

---
Changes:
v2: - fix checkpatch errors
- remove spinlock/wait code from cache implementation
- fix directory listing
- add documentation entry about SquashFS
- fix compiling without XZ enabled
- fix some memory leaks

 Documentation/filesystems/squashfs.rst |  15 ++
 fs/Kconfig                             |   1 +
 fs/Makefile                            |   1 +
 fs/squashfs/Kconfig                    |  31 +++
 fs/squashfs/Makefile                   |  13 +
 fs/squashfs/block.c                    | 212 +++++++++++++++
 fs/squashfs/cache.c                    | 393 ++++++++++++++++++++++++++++
 fs/squashfs/decompressor.c             | 140 ++++++++++
 fs/squashfs/decompressor.h             |  57 ++++
 fs/squashfs/decompressor_single.c      |  83 ++++++
 fs/squashfs/file.c                     | 460 +++++++++++++++++++++++++++++++++
 fs/squashfs/file_cache.c               |  35 +++
 fs/squashfs/fragment.c                 |  94 +++++++
 fs/squashfs/id.c                       |  98 +++++++
 fs/squashfs/inode.c                    | 402 ++++++++++++++++++++++++++++
 fs/squashfs/namei.c                    | 381 +++++++++++++++++++++++++++
 fs/squashfs/page_actor.c               |  99 +++++++
 fs/squashfs/page_actor.h               |  53 ++++
 fs/squashfs/squashfs.c                 | 356 +++++++++++++++++++++++++
 fs/squashfs/squashfs.h                 | 138 ++++++++++
 fs/squashfs/squashfs_fs.h              | 453 ++++++++++++++++++++++++++++++++
 fs/squashfs/squashfs_fs_i.h            |  52 ++++
 fs/squashfs/squashfs_fs_sb.h           |  82 ++++++
 fs/squashfs/super.c                    | 348 +++++++++++++++++++++++++
 fs/squashfs/xz_wrapper.c               | 190 ++++++++++++++
 25 files changed, 4187 insertions(+)
 create mode 100644 Documentation/filesystems/squashfs.rst
 create mode 100644 fs/squashfs/Kconfig
 create mode 100644 fs/squashfs/Makefile
 create mode 100644 fs/squashfs/block.c
 create mode 100644 fs/squashfs/cache.c
 create mode 100644 fs/squashfs/decompressor.c
 create mode 100644 fs/squashfs/decompressor.h
 create mode 100644 fs/squashfs/decompressor_single.c
 create mode 100644 fs/squashfs/file.c
 create mode 100644 fs/squashfs/file_cache.c
 create mode 100644 fs/squashfs/fragment.c
 create mode 100644 fs/squashfs/id.c
 create mode 100644 fs/squashfs/inode.c
 create mode 100644 fs/squashfs/namei.c
 create mode 100644 fs/squashfs/page_actor.c
 create mode 100644 fs/squashfs/page_actor.h
 create mode 100644 fs/squashfs/squashfs.c
 create mode 100644 fs/squashfs/squashfs.h
 create mode 100644 fs/squashfs/squashfs_fs.h
 create mode 100644 fs/squashfs/squashfs_fs_i.h
 create mode 100644 fs/squashfs/squashfs_fs_sb.h
 create mode 100644 fs/squashfs/super.c
 create mode 100644 fs/squashfs/xz_wrapper.c
Documentation/filesystems/squashfs.rst new file +15 -0
new file mode 100644
index 0000000..be82973
@@ -0,0 +1,15 @@
+.. index:: squashfs (filesystem)
+
+SquashFS filesystem
+===================
+
+SquashFS is a highly compressed read-only filesystem for Linux.
+It uses zlib, lzo or xz compression to compress both files, inodes
+and directories. A SquashFS filesystem can be mounted using the
+:ref:`command_mount` command::
+
+  mkdir /mnt
+  mount -t squashfs /dev/spiflash.FileSystem /mnt
+  ls /mnt
+  zImage barebox.bin
+  umount /mnt
fs/Kconfig +1 -0
index 56fe41a..c7c42ac 100644
@@ -90,6 +90,7 @@ config FS_SMHFS
 	  Barebox
 
 source fs/pstore/Kconfig
+source fs/squashfs/Kconfig
 
 config FS_RATP
 	bool
fs/Makefile +1 -0
index 7896e38..e245a8f 100644
@@ -16,3 +16,4 @@ obj-$(CONFIG_FS_EFIVARFS) += efivarfs.o
 obj-$(CONFIG_FS_SMHFS) += smhfs.o
 obj-$(CONFIG_FS_PSTORE) += pstore/
 obj-$(CONFIG_FS_RATP)	+= ratpfs.o
+obj-$(CONFIG_FS_SQUASHFS) += squashfs/
fs/squashfs/Kconfig new file +31 -0
new file mode 100644
index 0000000..d8836d5
@@ -0,0 +1,31 @@
+menuconfig FS_SQUASHFS
+	bool
+	prompt "squashfs support"
+	help
+	  Saying Y here includes support for SquashFS 4.0 (a Compressed
+	  Read-Only File System).  Squashfs is a highly compressed read-only
+	  filesystem for Linux.  It uses zlib, lzo or xz compression to
+	  compress both files, inodes and directories.  Inodes in the system
+	  are very small and all blocks are packed to minimise data overhead.
+	  Block sizes greater than 4K are supported up to a maximum of 1 Mbytes
+	  (default block size 128K).  SquashFS 4.0 supports 64 bit filesystems
+	  and files (larger than 4GB), full uid/gid information, hard links and
+	  timestamps.
+
+	  Squashfs is intended for general read-only filesystem use, for
+	  archival use (i.e. in cases where a .tar.gz file may be used), and in
+	  embedded systems where low overhead is needed.  Further information
+	  and tools are available from http://squashfs.sourceforge.net.
+
+config SQUASHFS_XZ
+	bool "Include support for XZ compressed file systems"
+	depends on FS_SQUASHFS
+	select XZ_DECOMPRESS
+	help
+	  Saying Y here includes support for reading Squashfs file systems
+	  compressed with XZ compression.  XZ gives better compression than
+	  the default zlib compression, at the expense of greater CPU and
+	  memory overhead.
+
+	  XZ is not the standard compression used in Squashfs and so most
+	  file systems will be readable without selecting this option.
fs/squashfs/Makefile new file +13 -0
new file mode 100644
index 0000000..c0d024c
@@ -0,0 +1,13 @@
+obj-y	+= squashfs.o
+obj-y	+= block.o
+obj-y	+= cache.o
+obj-y	+= decompressor.o
+obj-y	+= decompressor_single.o
+obj-y	+= file.o
+obj-y	+= file_cache.o
+obj-y	+= fragment.o
+obj-y	+= id.o
+obj-y	+= inode.o
+obj-y	+= namei.o
+obj-y	+= super.o
+obj-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o
fs/squashfs/block.c new file +212 -0

212 lines not on this page · raw message

fs/squashfs/cache.c new file +393 -0

393 lines not on this page · raw message

fs/squashfs/decompressor.c new file +140 -0

140 lines not on this page · raw message

fs/squashfs/decompressor.h new file +57 -0

57 lines not on this page · raw message

fs/squashfs/decompressor_single.c new file +83 -0

83 lines not on this page · raw message

fs/squashfs/file.c new file +460 -0

460 lines not on this page · raw message

fs/squashfs/file_cache.c new file +35 -0
new file mode 100644
index 0000000..9443e45
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013
+ * Phillip Lougher <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#include <linux/fs.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/pagemap.h>
+
+#include "squashfs_fs.h"
+#include "squashfs_fs_sb.h"
+#include "squashfs_fs_i.h"
+#include "squashfs.h"
+
+/* Read separately compressed datablock and memcopy into page cache */
+int squashfs_readpage_block(struct page *page, u64 block, int bsize)
+{
+	struct inode *i = page->inode;
+	struct squashfs_cache_entry *buffer = squashfs_get_datablock(i->i_sb,
+		block, bsize);
+	int res = buffer->error;
+
+	if (res)
+		ERROR("Unable to read page, block %llx, size %x\n", block,
+			bsize);
+	else
+		squashfs_copy_cache(page, buffer, buffer->length, 0);
+
+	squashfs_cache_put(buffer);
+	return res;
+}
fs/squashfs/fragment.c new file +94 -0

94 lines not on this page · raw message

fs/squashfs/id.c new file +98 -0

98 lines not on this page · raw message

fs/squashfs/inode.c new file +402 -0

402 lines not on this page · raw message

fs/squashfs/namei.c new file +381 -0

381 lines not on this page · raw message

fs/squashfs/page_actor.c new file +99 -0

99 lines not on this page · raw message

fs/squashfs/page_actor.h new file +53 -0

53 lines not on this page · raw message

fs/squashfs/squashfs.c new file +356 -0

356 lines not on this page · raw message

fs/squashfs/squashfs.h new file +138 -0

67 lines not on this page · raw message

fs/squashfs/squashfs_fs.h new file +453 -0

453 lines not on this page · raw message

fs/squashfs/squashfs_fs_i.h new file +52 -0

52 lines not on this page · raw message

fs/squashfs/squashfs_fs_sb.h new file +82 -0

82 lines not on this page · raw message

fs/squashfs/super.c new file +348 -0

348 lines not on this page · raw message

fs/squashfs/xz_wrapper.c new file +190 -0

190 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Part of the diff is not shown here. View the raw message.

#3 lore raw

Re: [PATCH v2 3/3] fs: add support for SquashFS 4.0

Quoted 5 lines · On Tue, Feb 16, 2016 at 9:23 AM, <[email protected]> wrote:

From: Yegor Yefremov <[email protected]>

The driver was imported from Linux 4.4.

Quoted 8 lines

---
Changes:
v2: - fix checkpatch errors
- remove spinlock/wait code from cache implementation
- fix directory listing
- add documentation entry about SquashFS
- fix compiling without XZ enabled
- fix some memory leaks

Memory leaks:

1. mount still produces 20 bytes, that I still haven't identified
2. ls -l has about 300 bytes, how do I best handle qstr duplicating? Its name is *const char **. If I'm doing alloc() I'm breaking this qualifier.
3. reading a file, i.e. cat has no memory leak so far according to meminfo

Yegor

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw

Re: [PATCH v2 3/3] fs: add support for SquashFS 4.0

Quoted 15 lines · Yegor Yefremov
Quoted 5 lines · On Tue, Feb 16, 2016 at 9:23 AM, <[email protected]> wrote:

From: Yegor Yefremov <[email protected]>

The driver was imported from Linux 4.4.

Quoted 8 lines

---
Changes:
v2: - fix checkpatch errors
- remove spinlock/wait code from cache implementation
- fix directory listing
- add documentation entry about SquashFS
- fix compiling without XZ enabled
- fix some memory leaks

Quoted 3 lines

Memory leaks:

1. mount still produces 20 bytes, that I still haven't identified

Does this accumulate if you repeat mount/unmount? Usually when allocating/freeing bunches of memory you don't have the exact amount of memory free afterwards.

Quoted 3 lines

2. ls -l has about 300 bytes, how do I best handle qstr duplicating? Its name is *const char **. If I'm doing alloc() I'm breaking this qualifier.

Why do you alloc? In squashfs_readdir() you can do a nm.name = dentry->d_name.name instead of doing an extra allocation for the string.

Quoted 1 line

3. reading a file, i.e. cat has no memory leak so far according to meminfo

\o/

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

Re: [PATCH v2 3/3] fs: add support for SquashFS 4.0

Quoted 16 lines · Sascha Hauer
Quoted 15 lines · Yegor Yefremov
Quoted 13 lines · On Tue, Feb 16, 2016 at 9:23 AM, <[email protected]> wrote:

From: Yegor Yefremov <[email protected]>

The driver was imported from Linux 4.4.

---
Changes:
v2: - fix checkpatch errors
- remove spinlock/wait code from cache implementation
- fix directory listing
- add documentation entry about SquashFS
- fix compiling without XZ enabled
- fix some memory leaks

Quoted 7 lines
Quoted 3 lines

Memory leaks:

1. mount still produces 20 bytes, that I still haven't identified

Does this accumulate if you repeat mount/unmount? Usually when allocating/freeing bunches of memory you don't have the exact amount of memory free afterwards.

hm, here is my output:

barebox:/ mkdir -p /mnt; meminfo; mount -t squashfs /dev/spiflash.FileSystem /mnt; umount /mnt; meminfo
used: 101804
free: 4087068
squashfs squashfs0: squashfs_mount
used: 101816
free: 4087052
barebox:/ mkdir -p /mnt; meminfo; mount -t squashfs /dev/spiflash.FileSystem /mnt; umount /mnt; meminfo
used: 101848
free: 4087024
squashfs squashfs0: squashfs_mount
used: 101860
free: 4087004
barebox:/ mkdir -p /mnt; meminfo; mount -t squashfs /dev/spiflash.FileSystem /mnt; umount /mnt; meminfo
used: 101844
free: 4087024
squashfs squashfs0: squashfs_mount
used: 101864
free: 4086996

Quoted 3 lines
Quoted 3 lines

2. ls -l has about 300 bytes, how do I best handle qstr duplicating? Its name is *const char **. If I'm doing alloc() I'm breaking this qualifier.

Fixed.

Quoted 7 lines

Why do you alloc? In squashfs_readdir() you can do a nm.name = dentry->d_name.name instead of doing an extra allocation for the string.

Quoted 1 line

3. reading a file, i.e. cat has no memory leak so far according to meminfo

\o/

Yegor

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox