Skip to contentSkip to conversation

fat: Simplify calc_fat_clusters code

PATCH In review Seunghun Lee 2 participants 3 messages Sep 2, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fat: Simplify calc_fat_clusters code

Code for fat12 and fat16/32 can be merged to one.

---
 fs/fat/inode.c |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
fs/fat/inode.c +2 -5
index 756aead..6992dea 100644
@@ -1307,12 +1307,9 @@ static unsigned long calc_fat_clusters(struct super_block *sb)
 	struct msdos_sb_info *sbi = MSDOS_SB(sb);
 
 	/* Divide first to avoid overflow */
-	if (sbi->fat_bits != 12) {
-		unsigned long ent_per_sec = sb->s_blocksize * 8 / sbi->fat_bits;
-		return ent_per_sec * sbi->fat_length;
-	}
+	unsigned long ent_per_sec = sb->s_blocksize * 8 / sbi->fat_bits;
 
-	return sbi->fat_length * sb->s_blocksize * 8 / sbi->fat_bits;
+	return ent_per_sec * sbi->fat_length;
 }
 
 static bool fat_bpb_is_zero(struct fat_boot_sector *b)
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw
Quoted 7 lines · Seunghun Lee
fs/fat/inode.c +0 -0
index 756aead..6992dea 100644
@@ -1307,12 +1307,9 @@ static unsigned long calc_fat_clusters(struct super_block *sb)
 	struct msdos_sb_info *sbi = MSDOS_SB(sb);
 

fs/fat/inode.c static unsigned long calc_fat_clusters(struct super_block *sb) · line 1313

Quoted 10 lines
fs/fat/inode.c +2 -5
 	/* Divide first to avoid overflow */
-	if (sbi->fat_bits != 12) {
-		unsigned long ent_per_sec = sb->s_blocksize * 8 / sbi->fat_bits;
-		return ent_per_sec * sbi->fat_length;
-	}
+	unsigned long ent_per_sec = sb->s_blocksize * 8 / sbi->fat_bits;
 
-	return sbi->fat_length * sb->s_blocksize * 8 / sbi->fat_bits;
+	return ent_per_sec * sbi->fat_length;
 }

When sbi->fat_bits == 12, it doesn't work, right? (there is the remainder)

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#2 lore raw
Quoted 16 lines · OGAWA Hirofumi
Quoted 14 lines · Seunghun Lee
fs/fat/inode.c +1 -4
index 756aead..6992dea 100644
@@ -1307,12 +1307,9 @@ static unsigned long calc_fat_clusters(struct super_block *sb)
 	struct msdos_sb_info *sbi = MSDOS_SB(sb);
 
 	/* Divide first to avoid overflow */
-	if (sbi->fat_bits != 12) {
-		unsigned long ent_per_sec = sb->s_blocksize * 8 / sbi->fat_bits;
-		return ent_per_sec * sbi->fat_length;
-	}
+	unsigned long ent_per_sec = sb->s_blocksize * 8 / sbi->fat_bits;
 
Quoted 6 lines

fs/fat/inode.c static unsigned long calc_fat_clusters(struct super_block *sb) · line 1313

Quoted 3 lines
fs/fat/inode.c +1 -1
-	return sbi->fat_length * sb->s_blocksize * 8 / sbi->fat_bits;
+	return ent_per_sec * sbi->fat_length;
 }

When sbi->fat_bits == 12, it doesn't work, right? (there is the remainder)

Thanks.

Yes, you are right.

I didn't think about the remainder.

Thanks.