From 4826d83d9c4f6bbf61f997e7b68547b4bffd8a49 Mon Sep 17 00:00:00 2001 From: Ajeet Yadav Date: Thu, 2 Feb 2012 13:04:49 +0530 Subject: Squashfs: use define instead of constant Its better to use defined name instead of constant Signed-off-by: Ajeet Yadav Signed-off-by: Phillip Lougher --- fs/squashfs/dir.c | 3 +-- fs/squashfs/namei.c | 3 +-- fs/squashfs/squashfs_fs.h | 3 +++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/squashfs/dir.c b/fs/squashfs/dir.c index 9dfe2ce0fb7..4a812bfcdd5 100644 --- a/fs/squashfs/dir.c +++ b/fs/squashfs/dir.c @@ -173,8 +173,7 @@ static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir) dir_count = le32_to_cpu(dirh.count) + 1; - /* dir_count should never be larger than 256 */ - if (dir_count > 256) + if (dir_count > SQUASHFS_DIR_COUNT) goto failed_read; while (dir_count--) { diff --git a/fs/squashfs/namei.c b/fs/squashfs/namei.c index 0682b38d7e3..66c70fc8c80 100644 --- a/fs/squashfs/namei.c +++ b/fs/squashfs/namei.c @@ -177,8 +177,7 @@ static struct dentry *squashfs_lookup(struct inode *dir, struct dentry *dentry, dir_count = le32_to_cpu(dirh.count) + 1; - /* dir_count should never be larger than 256 */ - if (dir_count > 256) + if (dir_count > SQUASHFS_DIR_COUNT) goto data_error; while (dir_count--) { diff --git a/fs/squashfs/squashfs_fs.h b/fs/squashfs/squashfs_fs.h index e8e14645de9..b2f9f623ac9 100644 --- a/fs/squashfs/squashfs_fs.h +++ b/fs/squashfs/squashfs_fs.h @@ -52,6 +52,9 @@ /* Max length of filename (not 255) */ #define SQUASHFS_NAME_LEN 256 +/* Max value for directory header count*/ +#define SQUASHFS_DIR_COUNT 256 + #define SQUASHFS_INVALID_FRAG (0xffffffffU) #define SQUASHFS_INVALID_XATTR (0xffffffffU) #define SQUASHFS_INVALID_BLK (-1LL) -- cgit v1.2.3-18-g5258 From ec9267b61dca524ccd111b593dcfa4bbcb81ecd6 Mon Sep 17 00:00:00 2001 From: Phillip Lougher Date: Tue, 6 Mar 2012 01:18:49 +0000 Subject: Squashfs: update comment removing reference to zlib only Comment was written when Squashfs only supported zlib compression. This comment is now misleading given Squashfs supports other compression algorithms. Signed-off-by: Phillip Lougher --- fs/squashfs/block.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c index ed0eb2a921f..fb50652e4e1 100644 --- a/fs/squashfs/block.c +++ b/fs/squashfs/block.c @@ -83,7 +83,8 @@ static struct buffer_head *get_block_length(struct super_block *sb, * filesystem), otherwise the length is obtained from the first two bytes of * the metadata block. A bit in the length field indicates if the block * is stored uncompressed in the filesystem (usually because compression - * generated a larger block - this does occasionally happen with zlib). + * generated a larger block - this does occasionally happen with compression + * algorithms). */ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index, int length, u64 *next_index, int srclength, int pages) -- cgit v1.2.3-18-g5258 From 68a8c397bf1bc16640e87d229025ffd4e4b54e6c Mon Sep 17 00:00:00 2001 From: Phillip Lougher Date: Tue, 6 Mar 2012 23:02:49 +0000 Subject: Squashfs: remove redundant length initialisation in squashfs_readdir Signed-off-by: Phillip Lougher --- fs/squashfs/dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/squashfs/dir.c b/fs/squashfs/dir.c index 4a812bfcdd5..7142a6fd28d 100644 --- a/fs/squashfs/dir.c +++ b/fs/squashfs/dir.c @@ -105,7 +105,7 @@ static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir) struct inode *inode = file->f_dentry->d_inode; struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info; u64 block = squashfs_i(inode)->start + msblk->directory_table; - int offset = squashfs_i(inode)->offset, length = 0, dir_count, size, + int offset = squashfs_i(inode)->offset, length, dir_count, size, type, err; unsigned int inode_number; struct squashfs_dir_header dirh; -- cgit v1.2.3-18-g5258 From bd3a518948a9b5fa869d096cd9bc062e0320449f Mon Sep 17 00:00:00 2001 From: Phillip Lougher Date: Wed, 7 Mar 2012 21:21:07 +0000 Subject: Squashfs: remove redundant length initialisation in squashfs_lookup Signed-off-by: Phillip Lougher --- fs/squashfs/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/squashfs/namei.c b/fs/squashfs/namei.c index 66c70fc8c80..abcc58f3c15 100644 --- a/fs/squashfs/namei.c +++ b/fs/squashfs/namei.c @@ -144,7 +144,7 @@ static struct dentry *squashfs_lookup(struct inode *dir, struct dentry *dentry, struct squashfs_dir_entry *dire; u64 block = squashfs_i(dir)->start + msblk->directory_table; int offset = squashfs_i(dir)->offset; - int err, length = 0, dir_count, size; + int err, length, dir_count, size; TRACE("Entered squashfs_lookup [%llx:%x]\n", block, offset); -- cgit v1.2.3-18-g5258 From 47f4396e516639eb8cbd660e1c1c356b5a80aa25 Mon Sep 17 00:00:00 2001 From: Phillip Lougher Date: Thu, 8 Mar 2012 00:45:57 +0000 Subject: Squashfs: get rid of obsolete definitions in header file Most of these were never used by the kernel code, but belong to the time when the header file was used by both the kernel code and the user space tools. Signed-off-by: Phillip Lougher --- fs/squashfs/squashfs_fs.h | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/fs/squashfs/squashfs_fs.h b/fs/squashfs/squashfs_fs.h index b2f9f623ac9..9e2349d07cb 100644 --- a/fs/squashfs/squashfs_fs.h +++ b/fs/squashfs/squashfs_fs.h @@ -30,11 +30,6 @@ /* size of metadata (inode and directory) blocks */ #define SQUASHFS_METADATA_SIZE 8192 -#define SQUASHFS_METADATA_LOG 13 - -/* default size of data blocks */ -#define SQUASHFS_FILE_SIZE 131072 -#define SQUASHFS_FILE_LOG 17 /* default size of block device I/O */ #ifdef CONFIG_SQUASHFS_4K_DEVBLK_SIZE @@ -46,9 +41,6 @@ #define SQUASHFS_FILE_MAX_SIZE 1048576 #define SQUASHFS_FILE_MAX_LOG 20 -/* Max number of uids and gids */ -#define SQUASHFS_IDS 65536 - /* Max length of filename (not 255) */ #define SQUASHFS_NAME_LEN 256 @@ -145,9 +137,6 @@ #define SQUASHFS_MKINODE(A, B) ((long long)(((long long) (A)\ << 16) + (B))) -/* Translate between VFS mode and squashfs mode */ -#define SQUASHFS_MODE(A) ((A) & 0xfff) - /* fragment and fragment table defines */ #define SQUASHFS_FRAGMENT_BYTES(A) \ ((A) * sizeof(struct squashfs_fragment_entry)) @@ -218,11 +207,6 @@ /* cached data constants for filesystem */ #define SQUASHFS_CACHED_BLKS 8 -#define SQUASHFS_MAX_FILE_SIZE_LOG 64 - -#define SQUASHFS_MAX_FILE_SIZE (1LL << \ - (SQUASHFS_MAX_FILE_SIZE_LOG - 2)) - /* meta index cache */ #define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int)) #define SQUASHFS_META_ENTRIES 127 -- cgit v1.2.3-18-g5258 From 2158d3fd2769546cd9004eaeb776fee946155238 Mon Sep 17 00:00:00 2001 From: Phillip Lougher Date: Fri, 9 Mar 2012 02:27:49 +0000 Subject: Squashfs: fix f_pos check in get_dir_index_using_offset One off error in the f_pos check. If f_pos is 3 or less don't bother reading the index because we're at the start of the directory, and we obviously already know where that is on disk. This eliminates an unnecessary read. Signed-off-by: Phillip Lougher --- fs/squashfs/dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/squashfs/dir.c b/fs/squashfs/dir.c index 7142a6fd28d..b381305c9a4 100644 --- a/fs/squashfs/dir.c +++ b/fs/squashfs/dir.c @@ -64,7 +64,7 @@ static int get_dir_index_using_offset(struct super_block *sb, * is offset by 3 because we invent "." and ".." entries which are * not actually stored in the directory. */ - if (f_pos < 3) + if (f_pos <= 3) return f_pos; f_pos -= 3; -- cgit v1.2.3-18-g5258 From 4b0180a49f08dd1c681cdc99edc9e0cec0a833fa Mon Sep 17 00:00:00 2001 From: Phillip Lougher Date: Fri, 9 Mar 2012 03:02:59 +0000 Subject: Squashfs: add mount time sanity check for block_size and block_log match Squashfs currently has a sanity check for block_size less than or equal to the maximum block_size (1 Mbyte). This catches some superblock corruption, but obviously with a block_size maximum of 1 Mbyte there's 7 correct values (4K, 8K, 16K, 32K, ... etc) and a lot of incorrect values which are not caught by this check. The Squashfs superblock, however, has both a block_size and a block_log (2^block_log == block_size). Checking that the block_size matches the block_log is a much more robust check. Corruption of the superblock is unlikely to produce values which match, and it also ensures the block_size is an exact power of two. Signed-off-by: Phillip Lougher --- fs/squashfs/super.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c index ecaa2f7bdb8..a55a9c57be1 100644 --- a/fs/squashfs/super.c +++ b/fs/squashfs/super.c @@ -158,10 +158,15 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent) goto failed_mount; } + /* Check block log for sanity */ msblk->block_log = le16_to_cpu(sblk->block_log); if (msblk->block_log > SQUASHFS_FILE_MAX_LOG) goto failed_mount; + /* Check that block_size and block_log match */ + if (msblk->block_size != (1 << msblk->block_log)) + goto failed_mount; + /* Check the root inode for sanity */ root_inode = le64_to_cpu(sblk->root_inode); if (SQUASHFS_INODE_OFFSET(root_inode) > SQUASHFS_METADATA_SIZE) -- cgit v1.2.3-18-g5258