diff options
-rw-r--r-- | lib/ext2fs/ext2fs.h | 13 | ||||
-rw-r--r-- | lib/ext2fs/initialize.c | 3 | ||||
-rw-r--r-- | lib/ext2fs/openfs.c | 8 | ||||
-rw-r--r-- | misc/mke2fs.c | 5 |
4 files changed, 24 insertions, 5 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) / diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 9f28901a..c46df6ce 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -619,9 +619,10 @@ static void show_stats(ext2_filsys fs) if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, EXT4_FEATURE_RO_COMPAT_BIGALLOC)) printf(_("Cluster size=%u (log=%u)\n"), - fs->clustersize, s->s_log_cluster_size); + fs->blocksize << fs->cluster_ratio_bits, + s->s_log_cluster_size); else - printf(_("Fragment size=%u (log=%u)\n"), fs->clustersize, + printf(_("Fragment size=%u (log=%u)\n"), EXT2_CLUSTER_SIZE(s), s->s_log_cluster_size); printf(_("Stride=%u blocks, Stripe width=%u blocks\n"), s->s_raid_stride, s->s_raid_stripe_width); |