Subject: [PATCH 12/16] Squashfs: header files
Subsystems (2)
--- fs/squashfs/squashfs.h | 100 +++++++++++ include/linux/squashfs_fs.h | 383 ++++++++++++++++++++++++++++++++++++++++ include/linux/squashfs_fs_i.h | 45 +++++ include/linux/squashfs_fs_sb.h | 76 ++++++++ 4 files changed, 604 insertions(+), 0 deletions(-)
fs/squashfs/squashfs.h new file +100 -0
@@ -0,0 +1,100 @@ +/* +* Squashfs - a compressed read only filesystem for Linux +* +* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008 +* Phillip Lougher <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2, +* or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +* squashfs.h +*/ + +#ifdef SQUASHFS_TRACE +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args) +#else +#define TRACE(s, args...) {} +#endif + +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args) + +#define SERROR(s, args...) \ + do { \ + if (!silent) \ + printk(KERN_ERR "SQUASHFS error: "s, ## args);\ + } while (0) + +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args) + +static inline struct squashfs_inode_info *SQUASHFS_I (struct inode *inode) +{ + return list_entry(inode, struct squashfs_inode_info, vfs_inode); +} + +/* block.c */ +extern unsigned int squashfs_read_data (struct super_block *,void *, +long long ,unsigned int ,long long *,int ); + +/* cache.c */ +extern struct squashfs_cache *squashfs_cache_init (char *,int ,int ,int ); +extern void squashfs_cache_delete (struct squashfs_cache *); +struct squashfs_cache_entry *squashfs_cache_get (struct super_block *, +struct squashfs_cache *,long long ,int ); +void squashfs_cache_put (struct squashfs_cache *,struct squashfs_cache_entry *); +extern int squashfs_read_metadata (struct super_block *,void *, +long long ,unsigned int ,int ,long long *, +unsigned int *); +extern struct squashfs_cache_entry *get_cached_fragment (struct super_block *, +long long ,int ); +extern void release_cached_fragment (struct squashfs_sb_info *, +struct squashfs_cache_entry *); + +/* export.c */ +extern __le64 *read_inode_lookup_table (struct super_block *,long long , +unsigned int ); + +/* fragment.c */ +extern int get_fragment_location (struct super_block *,unsigned int , +long long *); +extern __le64 *read_fragment_index_table (struct super_block *,long long , +unsigned int ); + +/* id.c */ +extern int squashfs_get_id (struct super_block *,unsigned int ,unsigned int *); +extern __le64 *read_id_index_table (struct super_block *,long long , +unsigned short ); + +/* inode.c */ +extern struct inode *squashfs_iget (struct super_block *,long long , +unsigned int ); +extern int squashfs_read_inode (struct inode *,long long ); + +/* +* Inodes and files operations +*/ + +/* dir.c */ +extern const struct file_operations squashfs_dir_ops; + +/* export.c */ +extern const struct export_operations squashfs_export_ops; + +/* file.c */ +extern const struct address_space_operations squashfs_aops; + +/* namei.c */ +extern const struct inode_operations squashfs_dir_inode_ops; + +/* symlink.c */ +extern const struct address_space_operations squashfs_symlink_aops;
include/linux/squashfs_fs.h new file +383 -0
383 lines not on this page · raw message
include/linux/squashfs_fs_i.h new file +45 -0
45 lines not on this page · raw message
include/linux/squashfs_fs_sb.h new file +76 -0
76 lines not on this page · raw message
Signature · 1 line
1.5.2.5
On Fri, 2008-10-17 at 16:42 +0100, Phillip Lougher wrote:
[snip]
Quoted 52 lines
include/linux/squashfs_fs.h new file +52
-0+ +struct squashfs_reg_inode { +__le16 inode_type; +__le16 mode; +__le16 uid; +__le16 guid; +__le32 mtime; +__le32 inode_number; +__le32 start_block; +__le32 fragment; +__le32 offset; +__le32 file_size; +__le16 block_list[0 ]; +}; + +struct squashfs_lreg_inode { +__le16 inode_type; +__le16 mode; +__le16 uid; +__le16 guid; +__le32 mtime; +__le32 inode_number; +__le64 start_block; +__le64 file_size; +__le64 sparse; +__le32 nlink; +__le32 fragment; +__le32 offset; +__le32 xattr; +__le16 block_list[0 ]; +}; + +struct squashfs_dir_inode { +__le16 inode_type; +__le16 mode; +__le16 uid; +__le16 guid; +__le32 mtime; +__le32 inode_number; +__le32 start_block; +__le32 nlink; +__le16 file_size; +__le16 offset; +__le32 parent_inode; +}; + +struct squashfs_ldir_inode { +__le16 inode_type; +__le16 mode; +__le16 uid; +__le16 guid; +__le32 mtime;
include/linux/squashfs_fs.h line 351
Quoted 10 lines
include/linux/squashfs_fs.h new file +10
-0+__le32 inode_number; +__le32 nlink; +__le32 file_size; +__le32 start_block; +__le32 parent_inode; +__le16 i_count; +__le16 offset; +struct squashfs_dir_index index[0 ]; +}; +
[snip]
Something that seems weird is the inconsistency in the ordering of these structs. The base part is the same across all inodes but for your reg/lreg dir/ldir pairs you seem to shuffle the order of the added parts. Is there a reason for this? Is their layout the same on disk (baring the extra data in the l versions)? If so they probably should be the same in the struct.
Quoted 9 lines · David P. Quigley
Something that seems weird is the inconsistency in the ordering of these structs. The base part is the same across all inodes but for your reg/lreg dir/ldir pairs you seem to shuffle the order of the added parts. Is there a reason for this? Is their layout the same on disk (baring the extra data in the l versions)? If so they probably should be the same in the struct.
They're deliberately shuffled about to eliminate holes (due to alignment contraints), and to maximise compression. Shifting to cluster similar fields can get better compression, and the current layout is the result of a lot of work to to get the best ordering.
For example:
Quoted 5 lines
Quoted 5 lines
include/linux/squashfs_fs.h new file +5
-0+struct squashfs_reg_inode { +__le16 inode_type; +__le16 mode; +__le16 uid; +__le16 guid;
Quoted 8 lines
include/linux/squashfs_fs.h line 303
Quoted 8 lines
include/linux/squashfs_fs.h new file +8
-0+__le32 mtime; +__le32 inode_number; +__le32 start_block; +__le32 fragment; +__le32 offset; +__le32 file_size; +__le16 block_list[0 ]; +};
Inode_number, start_block, fragment clustered together because in most filesystems they'll contain a lot of zero bits (filesystems mainly being small). Better compression.
Quoted 9 lines
Quoted 9 lines
include/linux/squashfs_fs.h new file +9
-0+ +struct squashfs_lreg_inode { +__le16 inode_type; +__le16 mode; +__le16 uid; +__le16 guid; +__le32 mtime; +__le32 inode_number; +__le64 start_block;
Quoted 8 lines
include/linux/squashfs_fs.h line 320
Quoted 8 lines
include/linux/squashfs_fs.h new file +8
-0+__le64 file_size; +__le64 sparse; +__le32 nlink; +__le32 fragment; +__le32 offset; +__le32 xattr; +__le16 block_list[0 ]; +};
Start_block, file_size have been doubled, and the fragment field consequently moved to preserve 64-bit alignment constraints on 64-bit quantities (no holes). Plus moving fragment means it can be grouped with the new nlink field giving a nice run of zero bits (non-extended regular files have an implicit nlink of 1).
fs/squashfs/squashfs.h line 28
Quoted 8 lines · Phillip Lougher
fs/squashfs/squashfs.h new file +5
-0+#ifdef SQUASHFS_TRACE +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args) +#else +#define TRACE(s, args...) {} +#endif
Just use
#define TRACE(s, args...) pr_debug("SQUASHFS: "s, ## args)so we always get printf()-format checking, irrespective of whether DEBUG is defined or not.
If you really want to keep the KERN_NOTICE (and the SQUASHFS_TRACE), you can use
#ifdef SQUASHFS_TRACE
#define TRACE(s, args...) pr_notice("SQUASHFS: "s, ## args)
#else
#define TRACE(s, args...) pr_debug("SQUASHFS: "s, ## args)
#endifQuoted 1 line
+#define
ERROR(s, args...)printk(KERN_ERR "SQUASHFS error: "s, ## args)
^^^^^^^^^^^^^^^^ pr_err(
fs/squashfs/squashfs.h line 35
Quoted 5 lines
fs/squashfs/squashfs.h new file +5
-0+ +#define SERROR(s, args...) \ + do { \ + if (!silent) \ + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
^^^^^^^^^^^^^^^^ pr_err(
fs/squashfs/squashfs.h line 36
Quoted 1 line
fs/squashfs/squashfs.h new file +1
-0+ }while (0 )
(yes, I know SERROR() no longer exists in CVS)
fs/squashfs/squashfs.h
Quoted 2 lines
fs/squashfs/squashfs.h new file +2
-0+ +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
^^^^^^^^^^^^^^^^ pr_warning(
Quoted 27 lines
include/linux/squashfs_fs.h new file +24
-0+/* Filesystem flags */ +#define SQUASHFS_NOI 0 +#define SQUASHFS_NOD 1 +#define SQUASHFS_NOF 3 +#define SQUASHFS_NO_FRAG 4 +#define SQUASHFS_ALWAYS_FRAG 5 +#define SQUASHFS_DUPLICATE 6 +#define SQUASHFS_EXPORT 7 + +#define SQUASHFS_BIT (flag, bit) ((flag >> bit) & 1) + +#define SQUASHFS_UNCOMPRESSED_INODES (flags) SQUASHFS_BIT(flags, \ + SQUASHFS_NOI) + +#define SQUASHFS_UNCOMPRESSED_DATA (flags) SQUASHFS_BIT(flags, \ + SQUASHFS_NOD) + +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS (flags) SQUASHFS_BIT(flags, \ + SQUASHFS_NOF) + +#define SQUASHFS_NO_FRAGMENTS (flags) SQUASHFS_BIT(flags, \ + SQUASHFS_NO_FRAG) + +#define SQUASHFS_ALWAYS_FRAGMENTS (flags) SQUASHFS_BIT(flags, \
include/linux/squashfs_fs.h line 87
Quoted 10 lines
include/linux/squashfs_fs.h new file +10
-0+ SQUASHFS_ALWAYS_FRAG) + +#define SQUASHFS_DUPLICATES (flags) SQUASHFS_BIT(flags, \ + SQUASHFS_DUPLICATE) + +#define SQUASHFS_EXPORTABLE (flags) SQUASHFS_BIT(flags, \ + SQUASHFS_EXPORT) + +#define SQUASHFS_MKFLAGS (noi, nod, nof, no_frag, always_frag, \ + duplicate_checking, exportable) (noi | (nod << 1) \
^
include/linux/squashfs_fs.h line 88
Quoted 1 line
include/linux/squashfs_fs.h new file +1
-0+ | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
^ ^ ^
include/linux/squashfs_fs.h line 89
Quoted 1 line
include/linux/squashfs_fs.h new file +1
-0+ (duplicate_checking << 6) | (exportable << 7))
^ ^
For the shifts, you can use the SQUASHFS_* filesystem flags defined above instead of the hardcoded numbers.
SQUASHFS_MKFLAGS() isn't used by the kernel, only by the tools (mksquashfs)?
include/linux/squashfs_fs.h line 193
Quoted 2 lines
include/linux/squashfs_fs.h new file +2
-0+/* meta index cache */ +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
^^^^^^^^^^^^
I was wondering whether a meta index is an unsigned int' or an __le32', but I couldn't find it easily.
With kind regards,
Geert Uytterhoeven
Software Architect
Sony Techsoft Centre Europe
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium
Phone: +32 (0)2 700 8453 Fax: +32 (0)2 700 8622 E-mail: [email protected] Internet: http://www.sony-europe.com/
A division of Sony Europe (Belgium) N.V.
VAT BE 0413.825.160 · RPR Brussels
Fortis · BIC GEBABEBB · IBAN BE41293037680010
Quoted 11 lines · Geert Uytterhoeven
fs/squashfs/squashfs.h line 28
Quoted 5 lines · Phillip Lougher
fs/squashfs/squashfs.h new file +5
-0+#ifdef SQUASHFS_TRACE +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args) +#else +#define TRACE(s, args...) {} +#endif Just use
#define TRACE(s, args...) pr_debug("SQUASHFS: "s, ## args)
OK.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)^^^^^^^^^^^^^^^^ pr_warning(
OK.
Quoted 3 lines
SQUASHFS_MKFLAGS()isn't used by the kernel, only by the tools (mksquashfs)?
Only used by mksquashfs. I pulled out the user-space only stuff into a separate include, but must have missed this one.
Quoted 6 lines
include/linux/squashfs_fs.h line 193
Quoted 2 lines
include/linux/squashfs_fs.h new file +2
-0+/* meta index cache */ +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))^^^^^^^^^^^^I was wondering whether a meta index is an
unsigned int' or an__le32', but I couldn't find it easily.
Unsigned int, it's used internally by the index cache code (file.c). It works out how many block indexes can fit into one compressed metadata block.
Phillip