[U-Boot] [PATCH 3/8] EXT2: Rework ext2fs_blockgroup() function
Marek Vasut
marex at denx.de
Fri Jun 8 19:31:48 CEST 2012
Rework the function, constify every possible component.
Signed-off-by: Marek Vasut <marex at denx.de>
Cc: Wolfgang Denk <wd at denx.de>
---
fs/ext2/ext2fs.c | 31 ++++++++++++++-----------------
1 file changed, 14 insertions(+), 17 deletions(-)
diff --git a/fs/ext2/ext2fs.c b/fs/ext2/ext2fs.c
index f9e9228..69fe1d1 100644
--- a/fs/ext2/ext2fs.c
+++ b/fs/ext2/ext2fs.c
@@ -43,25 +43,22 @@ int indir2_size = 0;
int indir2_blkno = -1;
static unsigned int inode_size;
-
-static int ext2fs_blockgroup
- (struct ext2_data *data, int group, struct ext2_block_group *blkgrp) {
- unsigned int blkno;
- unsigned int blkoff;
- unsigned int desc_per_blk;
-
- desc_per_blk = EXT2_BLOCK_SIZE(data) / sizeof(struct ext2_block_group);
-
- blkno = __le32_to_cpu(data->sblock.first_data_block) + 1 +
- group / desc_per_blk;
- blkoff = (group % desc_per_blk) * sizeof(struct ext2_block_group);
-#ifdef DEBUG
- printf ("ext2fs read %d group descriptor (blkno %d blkoff %d)\n",
+static int ext2fs_blockgroup(struct ext2_data *data, int group,
+ struct ext2_block_group *blkgrp)
+{
+ struct ext2_sblock *sb = &data->sblock;
+ const unsigned int blk_sz = EXT2_BLOCK_SIZE(data);
+ const unsigned int grp_sz = sizeof(struct ext2_block_group);
+ const unsigned int desc_per_blk = blk_sz / grp_sz;
+ const unsigned int blkoff = (group % desc_per_blk) * grp_sz;
+ const unsigned int first_block = __le32_to_cpu(sb->first_data_block);
+ const unsigned int blkno = first_block + 1 + group / desc_per_blk;
+
+ debug("EXT2: read %d group descriptor (blkno %d blkoff %d)\n",
group, blkno, blkoff);
-#endif
- return (ext2fs_devread (blkno << LOG2_EXT2_BLOCK_SIZE(data),
- blkoff, sizeof(struct ext2_block_group), (char *)blkgrp));
+ return ext2fs_devread(blkno << LOG2_EXT2_BLOCK_SIZE(data),
+ blkoff, grp_sz, (char *)blkgrp);
}
static int ext2fs_read_inode(struct ext2_data *data, int ino,
--
1.7.10
More information about the U-Boot
mailing list