diff options
author | Theodore Ts'o <tytso@mit.edu> | 2011-06-04 10:20:47 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2011-06-04 17:43:10 -0400 |
commit | 1da5ef707904cf99300a0fb36b9ae3b29dbc8bde (patch) | |
tree | 4df7edba6286ccfc9f78aabc4ea506179913d9ad /lib/ext2fs | |
parent | ae9e37cd114385764864518057ff854b3f335440 (diff) | |
download | e2fsprogs-1da5ef707904cf99300a0fb36b9ae3b29dbc8bde.tar.gz |
libext2fs: change fs->clustersize to fs->cluster_ratio_bits
The log2 of the ratio of cluster size to block size is far more useful
than just storing the cluster size. So make this change, and then
define basic utility macros: EXT2FS_CLUSTER_RATIO(),
EXT2FS_CLUSTER_MASK(), EXT2FS_B2C(), EXT2FS_C2B(), and
EXT2FS_NUM_B2C().
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'lib/ext2fs')
-rw-r--r-- | lib/ext2fs/ext2fs.h | 13 | ||||
-rw-r--r-- | lib/ext2fs/initialize.c | 3 | ||||
-rw-r--r-- | lib/ext2fs/openfs.c | 8 |
3 files changed, 21 insertions, 3 deletions
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 516eb1af..5379422b 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -195,7 +195,7 @@ struct struct_ext2_filsys { char * device_name; struct ext2_super_block * super; unsigned int blocksize; - int clustersize; + int cluster_ratio_bits; dgrp_t group_desc_count; unsigned long desc_blocks; struct ext2_group_desc * group_desc; @@ -547,6 +547,17 @@ typedef struct ext2_icount *ext2_icount_t; #define EXT2_LIB_SOFTSUPP_INCOMPAT (0) #define EXT2_LIB_SOFTSUPP_RO_COMPAT (EXT4_FEATURE_RO_COMPAT_BIGALLOC) + +/* Translate a block number to a cluster number */ +#define EXT2FS_CLUSTER_RATIO(fs) (1 << (fs)->cluster_ratio_bits) +#define EXT2FS_CLUSTER_MASK(fs) (EXT2FS_CLUSTER_RATIO(fs) - 1) +#define EXT2FS_B2C(fs, blk) ((blk) >> (fs)->cluster_ratio_bits) +/* Translate a cluster number to a block number */ +#define EXT2FS_C2B(fs, cluster) ((cluster) << (fs)->cluster_ratio_bits) +/* Translate # of blks to # of clusters */ +#define EXT2FS_NUM_B2C(fs, blks) (((blks) + EXT2FS_CLUSTER_MASK(fs)) >> \ + (fs)->cluster_ratio_bits) + /* * function prototypes */ diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index c109d08e..b9d45aef 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -178,7 +178,8 @@ errcode_t ext2fs_initialize(const char *name, int flags, super->s_creator_os = CREATOR_OS; fs->blocksize = EXT2_BLOCK_SIZE(super); - fs->clustersize = EXT2_CLUSTER_SIZE(super); + fs->cluster_ratio_bits = super->s_log_cluster_size - + super->s_log_block_size; /* default: (fs->blocksize*8) blocks/group, up to 2^16 (GDT limit) */ set_field(s_blocks_per_group, fs->blocksize * 8); diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index f87c1717..a598ca04 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -250,7 +250,13 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; } - fs->clustersize = EXT2_CLUSTER_SIZE(fs->super); + fs->cluster_ratio_bits = fs->super->s_log_cluster_size - + fs->super->s_log_block_size; + if (EXT2_BLOCKS_PER_GROUP(fs->super) != + EXT2_CLUSTERS_PER_GROUP(fs->super) << fs->cluster_ratio_bits) { + retval = EXT2_ET_CORRUPT_SUPERBLOCK; + goto cleanup; + } fs->inode_blocks_per_group = ((EXT2_INODES_PER_GROUP(fs->super) * EXT2_INODE_SIZE(fs->super) + EXT2_BLOCK_SIZE(fs->super) - 1) / |