From 2f1b7cd29fa4917f19d2624afc773d941684c5df Mon Sep 17 00:00:00 2001 From: Ryusuke Konishi Date: Thu, 22 Jul 2010 03:22:18 +0900 Subject: nilfs2: clarify byte offset in super block format This inserts comments indicating hexadecimal offset in declaration of nilfs_super_block structure so that people can know offset of its fields without counting from the head. Signed-off-by: Ryusuke Konishi --- include/linux/nilfs2_fs.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/linux/nilfs2_fs.h b/include/linux/nilfs2_fs.h index 8c2c6116e78..cc3465e5be3 100644 --- a/include/linux/nilfs2_fs.h +++ b/include/linux/nilfs2_fs.h @@ -160,7 +160,7 @@ struct nilfs_super_root { * struct nilfs_super_block - structure of super block on disk */ struct nilfs_super_block { - __le32 s_rev_level; /* Revision level */ +/*00*/ __le32 s_rev_level; /* Revision level */ __le16 s_minor_rev_level; /* minor revision level */ __le16 s_magic; /* Magic signature */ @@ -169,47 +169,47 @@ struct nilfs_super_block { is excluded. */ __le16 s_flags; /* flags */ __le32 s_crc_seed; /* Seed value of CRC calculation */ - __le32 s_sum; /* Check sum of super block */ +/*10*/ __le32 s_sum; /* Check sum of super block */ __le32 s_log_block_size; /* Block size represented as follows blocksize = 1 << (s_log_block_size + 10) */ __le64 s_nsegments; /* Number of segments in filesystem */ - __le64 s_dev_size; /* block device size in bytes */ +/*20*/ __le64 s_dev_size; /* block device size in bytes */ __le64 s_first_data_block; /* 1st seg disk block number */ - __le32 s_blocks_per_segment; /* number of blocks per full segment */ +/*30*/ __le32 s_blocks_per_segment; /* number of blocks per full segment */ __le32 s_r_segments_percentage; /* Reserved segments percentage */ __le64 s_last_cno; /* Last checkpoint number */ - __le64 s_last_pseg; /* disk block addr pseg written last */ +/*40*/ __le64 s_last_pseg; /* disk block addr pseg written last */ __le64 s_last_seq; /* seq. number of seg written last */ - __le64 s_free_blocks_count; /* Free blocks count */ +/*50*/ __le64 s_free_blocks_count; /* Free blocks count */ __le64 s_ctime; /* Creation time (execution time of newfs) */ - __le64 s_mtime; /* Mount time */ +/*60*/ __le64 s_mtime; /* Mount time */ __le64 s_wtime; /* Write time */ - __le16 s_mnt_count; /* Mount count */ +/*70*/ __le16 s_mnt_count; /* Mount count */ __le16 s_max_mnt_count; /* Maximal mount count */ __le16 s_state; /* File system state */ __le16 s_errors; /* Behaviour when detecting errors */ __le64 s_lastcheck; /* time of last check */ - __le32 s_checkinterval; /* max. time between checks */ +/*80*/ __le32 s_checkinterval; /* max. time between checks */ __le32 s_creator_os; /* OS */ __le16 s_def_resuid; /* Default uid for reserved blocks */ __le16 s_def_resgid; /* Default gid for reserved blocks */ __le32 s_first_ino; /* First non-reserved inode */ - __le16 s_inode_size; /* Size of an inode */ +/*90*/ __le16 s_inode_size; /* Size of an inode */ __le16 s_dat_entry_size; /* Size of a dat entry */ __le16 s_checkpoint_size; /* Size of a checkpoint */ __le16 s_segment_usage_size; /* Size of a segment usage */ - __u8 s_uuid[16]; /* 128-bit uuid for volume */ - char s_volume_name[80]; /* volume name */ +/*98*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */ +/*A8*/ char s_volume_name[80]; /* volume name */ - __le32 s_c_interval; /* Commit interval of segment */ +/*F8*/ __le32 s_c_interval; /* Commit interval of segment */ __le32 s_c_block_max; /* Threshold of data amount for the segment construction */ __u32 s_reserved[192]; /* padding to the end of the block */ -- cgit v1.2.3-18-g5258 From 1a80a1763fb760b3a84a28df87515f7cdc07a4f4 Mon Sep 17 00:00:00 2001 From: Ryusuke Konishi Date: Thu, 22 Jul 2010 03:22:19 +0900 Subject: nilfs2: add feature set fields to super block This adds three new fields to nilfs_super_block structure, compatible feature set, readonly-compatible feature set, and incompatible feature set in order to prepare for future disk format modifications. The role of these fields conforms to those of ext3 or other filesystems. Most important flags are the incompatible feature set; it is used to refuse to mount the filesystem which sets an incompatible feature the kernel doesn't know about. Signed-off-by: Ryusuke Konishi --- include/linux/nilfs2_fs.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/nilfs2_fs.h b/include/linux/nilfs2_fs.h index cc3465e5be3..7dd4cd49449 100644 --- a/include/linux/nilfs2_fs.h +++ b/include/linux/nilfs2_fs.h @@ -212,7 +212,10 @@ struct nilfs_super_block { /*F8*/ __le32 s_c_interval; /* Commit interval of segment */ __le32 s_c_block_max; /* Threshold of data amount for the segment construction */ - __u32 s_reserved[192]; /* padding to the end of the block */ +/*100*/ __le64 s_feature_compat; /* Compatible feature set */ + __le64 s_feature_compat_ro; /* Read-only compatible feature set */ + __le64 s_feature_incompat; /* Incompatible feature set */ + __u32 s_reserved[186]; /* padding to the end of the block */ }; /* @@ -227,6 +230,16 @@ struct nilfs_super_block { #define NILFS_CURRENT_REV 2 /* current major revision */ #define NILFS_MINOR_REV 0 /* minor revision */ +/* + * Feature set definitions + * + * If there is a bit set in the incompatible feature set that the kernel + * doesn't know about, it should refuse to mount the filesystem. + */ +#define NILFS_FEATURE_COMPAT_SUPP 0ULL +#define NILFS_FEATURE_COMPAT_RO_SUPP 0ULL +#define NILFS_FEATURE_INCOMPAT_SUPP 0ULL + /* * Bytes count of super_block for CRC-calculation */ -- cgit v1.2.3-18-g5258 From 6cda9fa2575ec0869fe77b0bdf295c0e51868cab Mon Sep 17 00:00:00 2001 From: Ryusuke Konishi Date: Sun, 25 Jul 2010 20:39:03 +0900 Subject: nilfs2: avoid rec_len overflow with 64KB block size With 64KB blocksize, a directory entry can have size 64KB which does not fit into 16 bits we have for entry length. So this patch stores 0xffff instead and converts value when read from / written to disk. Nilfs derives its directory implementation from ext2 filesystem, and this draws upon the corresponding change on ext2. Signed-off-by: Ryusuke Konishi --- include/linux/nilfs2_fs.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'include') diff --git a/include/linux/nilfs2_fs.h b/include/linux/nilfs2_fs.h index 7dd4cd49449..970828a5ffc 100644 --- a/include/linux/nilfs2_fs.h +++ b/include/linux/nilfs2_fs.h @@ -326,7 +326,25 @@ enum { #define NILFS_DIR_ROUND (NILFS_DIR_PAD - 1) #define NILFS_DIR_REC_LEN(name_len) (((name_len) + 12 + NILFS_DIR_ROUND) & \ ~NILFS_DIR_ROUND) +#define NILFS_MAX_REC_LEN ((1<<16)-1) +static inline unsigned nilfs_rec_len_from_disk(__le16 dlen) +{ + unsigned len = le16_to_cpu(dlen); + + if (len == NILFS_MAX_REC_LEN) + return 1 << 16; + return len; +} + +static inline __le16 nilfs_rec_len_to_disk(unsigned len) +{ + if (len == (1 << 16)) + return cpu_to_le16(NILFS_MAX_REC_LEN); + else if (len > (1 << 16)) + BUG(); + return cpu_to_le16(len); +} /** * struct nilfs_finfo - file information -- cgit v1.2.3-18-g5258 From 89c0fd014d34d409a7b196667c2b9a4813b6c968 Mon Sep 17 00:00:00 2001 From: Ryusuke Konishi Date: Sun, 25 Jul 2010 22:44:53 +0900 Subject: nilfs2: reject filesystem with unsupported block size This inserts sanity check that refuses to mount a filesystem with unsupported block size. Previously, kernel code of nilfs was looking only limitation of devices though mkfs.nilfs2 limits the range of block sizes; there was no check that prevents rec_len overflow with larger block sizes. With this change, block sizes larger than 64KB or smaller than 1KB will get rejected explicitly by kernel. Signed-off-by: Ryusuke Konishi --- include/linux/nilfs2_fs.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/linux/nilfs2_fs.h b/include/linux/nilfs2_fs.h index 970828a5ffc..f5487b6f91e 100644 --- a/include/linux/nilfs2_fs.h +++ b/include/linux/nilfs2_fs.h @@ -286,6 +286,12 @@ struct nilfs_super_block { #define NILFS_NAME_LEN 255 +/* + * Block size limitations + */ +#define NILFS_MIN_BLOCK_SIZE 1024 +#define NILFS_MAX_BLOCK_SIZE 65536 + /* * The new version of the directory entry. Since V0 structures are * stored in intel byte order, and the name_len field could never be -- cgit v1.2.3-18-g5258