linux/types.h: add sector_t and blkcnt_t types
Subsystems (3)
PATCH v3 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
@@ -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
PATCH v3 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
@@ -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.mntconst 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
PATCH v3 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:
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 | 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 | 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 | 325 +++++++++++++++++++++++ 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, 4106 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
@@ -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
@@ -90,5 +90,6 @@ config FS_SMHFS Barebox source fs/pstore/Kconfig +source fs/squashfs/Kconfig endmenu
fs/Makefile +1 -0
@@ -15,3 +15,4 @@ 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/
fs/squashfs/Kconfig new file +31 -0
@@ -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
@@ -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
@@ -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 +325 -0
325 lines not on this page · raw message
fs/squashfs/squashfs.h new file +138 -0
138 lines not on this page · raw message
fs/squashfs/squashfs_fs.h new file +453 -0
11 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.
Re: [PATCH v3 3/3] fs: add support for SquashFS 4.0
Quoted 8 lines · On Fri, 19 Feb 2016 15:49:15 +0100 [email protected] wrote:
From: Yegor Yefremov <[email protected]>
The driver was imported from Linux 4.4.
Current implementation supports only XZ decompressor.
Cc Antony Pavlov <[email protected]>Signed-off-by Yegor Yefremov <[email protected]>
I have just tested this series on AR9331-based board, so
However there are some issues, see below
Quoted 8 lines
Documentation/filesystems/squashfs.rst new file +5
-0@@ -0,0 +1,15 @@ +.. index:: squashfs (filesystem) + +SquashFS filesystem +=================== +
Documentation/filesystems/squashfs.rst line 15
Quoted 10 lines
Documentation/filesystems/squashfs.rst new file +10
-0+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
Please add barebox prompt to this example, e.g.:
barebox:/ mkdir /mnt
barebox:/ mount -t squashfs /dev/spiflash.FileSystem /mnt barebox:/ ls /mnt
zImage barebox.bin
barebox:/ umount /mnt
I suppose that the 'squashfs squashfs0: squashfs_mount' message is redundant, e.g:
barebox:/ mount -t squashfs /dev/spiflash.linux /mnt/ squashfs squashfs0: squashfs_mount
barebox:/ ls /mnt/
bin boot dev etc home init lib lib32 linuxrc media mnt opt proc root run sbin sys tmp usr var
Also I see a memory leak on mount (By mistake I have tried to mount non-cdev squashfs image):
barebox:/ meminfo
used: 2693564
free: 14074728
barebox:/ mount -t squashfs rootfs.20160223.xz-squashfs /mnt/ squashfs squashfs0: probe failed: Invalid argument
mount: Invalid argument
barebox:/ meminfo
used: 2693636
free: 14074644
barebox:/ mount -t squashfs rootfs.20160223.xz-squashfs /mnt/ squashfs squashfs0: probe failed: Invalid argument
mount: Invalid argument
barebox:/ meminfo
used: 2693748
free: 14074524
barebox:/ mount -t squashfs rootfs.20160223.xz-squashfs /mnt/ squashfs squashfs0: probe failed: Invalid argument
mount: Invalid argument
barebox:/ meminfo
used: 2693832
free: 14074428
--
Best regards,
Antony Pavlov
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v3 3/3] fs: add support for SquashFS 4.0
In reply to [email protected]Quoted 28 lines · On Fri, Feb 19, 2016 at 03:49:15PM +0100, [email protected] wrote:
From: Yegor Yefremov <[email protected]>
The driver was imported from Linux 4.4.
+++ b/fs/squashfs/Kconfig
fs/squashfs/Kconfig new file +21
-0@@ -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"
fs/squashfs/Kconfig line 31
Quoted 10 lines
fs/squashfs/Kconfig new file +10
-0+ 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.
As long as XZ is the only option, does it make sense to make this visible? I rather suggest an invisible "default y" option.
Quoted 14 lines
fs/squashfs/squashfs.c new file +14
-0+ +struct squashfs_priv { +struct super_block *sb; +}; + +static struct inode *squashfs_findfile (struct super_block *sb, +const char *filename,char *buf) +{ +char *next; +char fpath[128 ]; +char *name = fpath; +struct inode *inode; +struct inode *t_inode =NULL ; +
fs/squashfs/squashfs.c line 74
Quoted 10 lines
fs/squashfs/squashfs.c new file +10
-0+strcpy (fpath, filename); + +/* Remove all leading slashes */ +while (*name =='/' ) + name++; + + inode =duplicate_inode (sb->s_root->d_inode); + +/* +* Handle root-direcoty ('/')
s/direcoty/directory/
Quoted 39 lines
fs/squashfs/squashfs.c new file +39
-0+*/ +if (!name || *name =='\0' ) +return inode; + +for (;;) { +/* Extract the actual part from the pathname. */ + next =strchr (name,'/' ); +if (next) { +/* Remove all leading slashes. */ +while (*next =='/' ) + *(next++) ='\0' ; + } + + t_inode =squashfs_lookup (inode, name,0 ); +if (t_inode ==NULL ) +break ; + +/* +* Check if directory with this name exists +*/ + +/* Found the node! */ +if (!next || *next =='\0' ) { +if (buf !=NULL ) +sprintf (buf,"%s" , name); + +free (squashfs_i (inode)); +return t_inode; + } + + name = next; + +free (squashfs_i (inode)); + inode = t_inode; + } + +free (squashfs_i (inode)); +return NULL ; +}
fs/squashfs/squashfs.c line 123
Quoted 10 lines
fs/squashfs/squashfs.c new file +10
-0+ +static int squashfs_probe (struct device_d *dev) +{ +struct fs_device_d *fsdev; +struct squashfs_priv *priv; +int ret; + + fsdev =dev_to_fs_device (dev); + + priv =xmalloc (sizeof (struct squashfs_priv ));
xzalloc is usually safer here. Even if you know that all fields are initialized properly later, once we add new fields we usually expect them to be initialized to zero.
fs/squashfs/squashfs.c line 131
Quoted 8 lines
fs/squashfs/squashfs.c new file +8
-0+ dev->priv = priv; + + ret =fsdev_open_cdev (fsdev); +if (ret) + goto err_out; + + + priv->sb =squashfs_mount (fsdev,0 );
You could embed a struct super_block into struct squashfs_priv. That would save you one extra allocation.
Quoted 28 lines
fs/squashfs/squashfs.c new file +28
-0+if (IS_ERR (priv->sb)) { +dev_info (dev,"no valid squashfs found\n" ); + ret =PTR_ERR (priv->sb); + goto err_out; + } + +return 0 ; + +err_out: +free (priv); + +return ret; +} + +static void squashfs_remove (struct device_d *dev) +{ +struct squashfs_priv *priv = dev->priv; + +squashfs_put_super (priv->sb); +free (priv->sb); +free (priv); +} + +static int squashfs_open (struct device_d *dev,FILE *file,const char *filename) +{ +struct squashfs_priv *priv = dev->priv; +struct inode *inode; +struct squashfs_page *page;
fs/squashfs/squashfs.c line 169
Quoted 10 lines
fs/squashfs/squashfs.c new file +10
-0+int i; + + inode =squashfs_findfile (priv->sb, filename,NULL ); +if (!inode) +return -ENOENT ; + + page =malloc (sizeof (struct squashfs_page )); + page->buf =calloc (32 ,sizeof (*page->buf)); +for (i =0 ; i <32 ; i++) + page->buf[i] =malloc (PAGE_CACHE_SIZE );
Given the amount of memory you allocate here malloc is a good choice, but please check the return value.
Quoted 27 lines
fs/squashfs/squashfs.c new file +27
-0+ + page->data_block =0 ; + page->idx =0 ; + page->real_page.inode = inode; + file->size = inode->i_size; + file->priv = page; + +return 0 ; +} + +static int squashfs_close (struct device_d *dev,FILE *f) +{ +struct squashfs_page *page = f->priv; +int i; + +for (i =0 ; i <32 ; i++) +free (page->buf[i]); + +free (page->buf); +free (squashfs_i (page->real_page.inode)); +free (page); + +return 0 ; +} + +static int squashfs_read (struct device_d *_dev,FILE *f,void *buf, +size_t insize)
fs/squashfs/squashfs.c line 206
Quoted 10 lines
fs/squashfs/squashfs.c new file +10
-0+{ +unsigned int size = insize; +int offset, idx; +int data_block_pos; +struct squashfs_page *page = f->priv; + +if (f->pos >= (page->data_block +1 ) *32 *PAGE_CACHE_SIZE ) { + page->data_block++; + page->idx =0 ; + }
You seem to assume here that files are only read linearly. You have to do something more clever here to support lseek.
Quoted 11 lines
fs/squashfs/squashfs.c new file +11
-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 ; + offset = data_block_pos - idx *PAGE_CACHE_SIZE ; + +if (page->idx ==0 ) +squashfs_readpage (NULL , &page->real_page); + +memcpy (buf, page->buf[idx] + offset, size); +
fs/squashfs/squashfs.c line 227
Quoted 10 lines
fs/squashfs/squashfs.c new file +10
-0+return insize; +} + +static loff_t squashfs_lseek (struct device_d *dev,FILE *f,loff_t pos) +{ + f->pos = pos; + +return pos; +} +
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