Skip to contentSkip to conversation

linux/types.h: add sector_t and blkcnt_t types

PATCH Superseded [email protected] 3 participants 5 messages Feb 26, 2016 – Mar 1, 2016

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 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 v4 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
#3 lore raw

PATCH v4 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.

Current implementation supports only XZ decompressor.

---
Changes:
v4: - add promt to mount examples
- rework squashfs_read to enable non linear reading
- embed super_block into squashfs_priv
- check malloc' return value

v3: - rework inode searching
- eliminate memleaks in directory search

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                    |  32 +++
 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                     | 445 ++++++++++++++++++++++++++++++++
 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                    | 346 +++++++++++++++++++++++++
 fs/squashfs/page_actor.c               |  99 +++++++
 fs/squashfs/page_actor.h               |  53 ++++
 fs/squashfs/squashfs.c                 | 377 +++++++++++++++++++++++++++
 fs/squashfs/squashfs.h                 | 142 +++++++++++
 fs/squashfs/squashfs_fs.h              | 453 +++++++++++++++++++++++++++++++++
 fs/squashfs/squashfs_fs_i.h            |  52 ++++
 fs/squashfs/squashfs_fs_sb.h           |  82 ++++++
 fs/squashfs/super.c                    | 344 +++++++++++++++++++++++++
 fs/squashfs/xz_wrapper.c               | 190 ++++++++++++++
 25 files changed, 4159 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..88c97eb
@@ -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::
+
+  barebox:/ mkdir /mnt
+  barebox:/ mount -t squashfs /dev/spiflash.FileSystem /mnt
+  barebox:/ ls /mnt
+  zImage barebox.bin
+  barebox:/ 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..f2bb702 100644
@@ -15,4 +15,5 @@ obj-$(CONFIG_FS_EFI)	 += efi.o
 obj-$(CONFIG_FS_EFIVARFS) += efivarfs.o
 obj-$(CONFIG_FS_SMHFS) += smhfs.o
 obj-$(CONFIG_FS_PSTORE) += pstore/
+obj-$(CONFIG_FS_SQUASHFS) += squashfs/
 obj-$(CONFIG_FS_RATP)	+= ratpfs.o
fs/squashfs/Kconfig new file +32 -0
new file mode 100644
index 0000000..dc25d93
@@ -0,0 +1,32 @@
+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"
+	default y
+	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 +445 -0

445 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 +346 -0

346 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 +377 -0

377 lines not on this page · raw message

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

94 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 +344 -0

344 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.

#2 lore raw

Re: [PATCH v4 2/3] linux/fs.h: add types and routines needed for SquashFS

In reply to [email protected]
Quoted 55 lines · On Fri, 26 Feb 2016 16:19:44 +0100 [email protected] wrote:

From: Yegor Yefremov <[email protected]>

---
 include/linux/fs.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
include/linux/fs.h +22 -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;

include/linux/fs.h struct file { · line 388

Quoted 6 lines
include/linux/fs.h +3 -0
@@ -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;

checkpatch.pl reports about an error here:

ERROR: code indent should use tabs where possible

Quoted 11 lines
include/linux/fs.h +2 -0
+}
+
 #endif /* _LINUX_FS_H */
Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 8 lines
-- 
Best regards,
  Antony Pavlov

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

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

In reply to [email protected]
Quoted 73 lines · On Fri, Feb 26, 2016 at 04:19:45PM +0100, [email protected] wrote:

From: Yegor Yefremov <[email protected]>

The driver was imported from Linux 4.4.

Current implementation supports only XZ decompressor.

---
Changes:
v4: - add promt to mount examples
- rework squashfs_read to enable non linear reading
- embed super_block into squashfs_priv
- check malloc' return value

v3: - rework inode searching
- eliminate memleaks in directory search

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

fs/squashfs/squashfs.c new file +48 -0
+
+static int squashfs_read(struct device_d *_dev, FILE *f, void *buf,
+		size_t insize)
+{
+	unsigned int size = insize;
+	unsigned int pos = f->pos;
+	unsigned int ofs;
+	unsigned int now;
+	unsigned int idx;
+	unsigned int data_block_pos, data_block;
+	struct squashfs_page *page = f->priv;
+
+	data_block = f->pos / (32 * PAGE_CACHE_SIZE);
+	if (data_block != page->data_block) {
+		page->data_block = data_block;
+		page->idx = 0;
+	}
+
+	data_block_pos = f->pos - page->data_block * 32 * PAGE_CACHE_SIZE;
+	idx = data_block_pos / PAGE_CACHE_SIZE;
+	page->real_page.index = page->data_block * 32;
+
+	while (size) {
+		if (page->idx == 0)
+			squashfs_readpage(NULL, &page->real_page);
+
+		/* Read till end of current buffer page */
+		ofs = pos % PAGE_CACHE_SIZE;
+		if (ofs) {
+			now = min(size, PAGE_CACHE_SIZE - ofs);
+			memcpy(buf, page->buf[idx] + ofs, now);
+
+			size -= now;
+			pos += now;
+			buf += now;
+			idx++;
+			if (idx > 31) {
+				idx = 0;
+				page->idx = 0;
+				page->data_block++;
+				page->real_page.index = page->data_block * 32;
+				continue;
+			}
+		}
+
+		/* Do full buffer pages */
+		while (size >= PAGE_CACHE_SIZE) {
+			memcpy(buf, page->buf[idx], PAGE_CACHE_SIZE);

fs/squashfs/squashfs.c line 259

Quoted 10 lines
fs/squashfs/squashfs.c new file +10 -0
+			size -= PAGE_CACHE_SIZE;
+			pos += PAGE_CACHE_SIZE;
+			buf += PAGE_CACHE_SIZE;
+			idx++;
+			if (idx > 31) {
+				idx = 0;
+				page->idx = 0;
+				page->data_block++;
+				page->real_page.index = page->data_block * 32;
+				continue;

Here you increase the real_page.index without calling squashfs_readpage() again.

The outer loop shouldn't be necessary. It is used in the if (ofs) above, but this doesn't look entirely correct.

I think you are doing too much in this function. It should be easier if you create a helper function that takes the current file position and returns the buffer that belongs to this position. See below for a (completely untested) template:

static int squashfs_read_buf(struct squashfs_page *page, int pos, void **buf)

{
	unsigned int data_block = pos / (32 * PAGE_CACHE_SIZE);
	unsigned int data_block_pos = pos % (32 * PAGE_CACHE_SIZE);
	unsigned int idx = data_block_pos / PAGE_CACHE_SIZE;

	if (data_block != page->data_block) {
		page->real_page.index = data_block * 32;
		squashfs_readpage(NULL, &page->real_page);
		page->data_block = data_block;
	}

	*buf = page->buf[idx];

	return 0;
}

static int squashfs_read(struct device_d *_dev, FILE *f, void *buf,
size_t insize)

{
	unsigned int size = insize;
	unsigned int pos = f->pos;
	unsigned int ofs;
	unsigned int now;
	void *pagebuf;
	struct squashfs_page *page = f->priv;

	/* Read till end of current buffer page */
	ofs = pos % PAGE_CACHE_SIZE;
	if (ofs) {
		squashfs_read_buf(page, pos, &pagebuf);

		now = min(size, PAGE_CACHE_SIZE - ofs);
		memcpy(buf, pagebuf + ofs, now);

		size -= now;
		pos += now;
		buf += now;
	}

	/* Do full buffer pages */
	while (size >= PAGE_CACHE_SIZE) {
		squashfs_read_buf(page, pos, &pagebuf);

		memcpy(buf, pagebuf, PAGE_CACHE_SIZE);
		size -= PAGE_CACHE_SIZE;
		pos += PAGE_CACHE_SIZE;
		buf += PAGE_CACHE_SIZE;
	}

	/* And the rest */
	if (size) {
		squashfs_read_buf(page, pos, &pagebuf);
		memcpy(buf, pagebuf, size);
		size  = 0;
	}

	return insize;
}

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