Skip to contentSkip to conversation

fat: use s_blocksize_bits where SECTOR SIZE alignment is needed

PATCH In review Namjae Jeon 2 participants 3 messages Nov 3, 2012 – Nov 11, 2012

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

PATCH v2 1/3 fat: use s_blocksize_bits where SECTOR SIZE alignment is needed

Currently there is hard-coding at various places in FAT for using the SECTOR size alignment. So, In order to remove the hard coding we need to change the usage of '9' in FAT code.

---
 fs/fat/file.c  |    3 ++-
 fs/fat/inode.c |    9 ++++++---
 fs/fat/misc.c  |    9 ++++++---
 3 files changed, 14 insertions(+), 7 deletions(-)
fs/fat/file.c +2 -1
index 1f81cb4..e6dd081 100644
@@ -276,7 +276,8 @@ static int fat_free(struct inode *inode, int skip)
 
 		free_start = ret;
 	}
-	inode->i_blocks = skip << (MSDOS_SB(sb)->cluster_bits - 9);
+	inode->i_blocks = skip << (MSDOS_SB(sb)->cluster_bits -
+						sb->s_blocksize_bits);
 
 	/* Freeing the remained cluster chain */
 	return fat_free_clusters(inode, free_start);
fs/fat/inode.c +6 -3
index 80c6fdd..d077f57 100644
@@ -387,7 +387,8 @@ static int fat_calc_dir_size(struct inode *inode)
 /* doesn't deal with root inode */
 static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
 {
-	struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
+	struct super_block *sb = inode->i_sb;
+	struct msdos_sb_info *sbi = MSDOS_SB(sb);
 	int error;
 
 	MSDOS_I(inode)->i_pos = 0;
@@ -431,7 +432,8 @@ static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
 	fat_save_attrs(inode, de->attr);
 
 	inode->i_blocks = ((inode->i_size + (sbi->cluster_size - 1))
-			   & ~((loff_t)sbi->cluster_size - 1)) >> 9;
+			   & ~((loff_t)sbi->cluster_size - 1)) >>
+			   sb->s_blocksize_bits;
 
 	fat_time_fat2unix(sbi, &inode->i_mtime, de->time, de->date, 0);
 	if (sbi->options.isvfat) {
@@ -1148,7 +1150,8 @@ static int fat_read_root(struct inode *inode)
 		inode->i_size = sbi->dir_entries * sizeof(struct msdos_dir_entry);
 	}
 	inode->i_blocks = ((inode->i_size + (sbi->cluster_size - 1))
-			   & ~((loff_t)sbi->cluster_size - 1)) >> 9;
+			   & ~((loff_t)sbi->cluster_size - 1)) >>
+			   sb->s_blocksize_bits;
 	MSDOS_I(inode)->i_logstart = 0;
 	MSDOS_I(inode)->mmu_private = inode->i_size;
 
fs/fat/misc.c +6 -3
index 6d93360..f78469f 100644
@@ -150,13 +150,16 @@ int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster)
 		} else
 			mark_inode_dirty(inode);
 	}
-	if (new_fclus != (inode->i_blocks >> (sbi->cluster_bits - 9))) {
+	if (new_fclus != (inode->i_blocks >> (sbi->cluster_bits -
+			 sb->s_blocksize_bits))) {
 		fat_fs_error(sb, "clusters badly computed (%d != %llu)",
 			     new_fclus,
-			     (llu)(inode->i_blocks >> (sbi->cluster_bits - 9)));
+			     (llu)(inode->i_blocks >> (sbi->cluster_bits -
+			     sb->s_blocksize_bits)));
 		fat_cache_inval_inode(inode);
 	}
-	inode->i_blocks += nr_cluster << (sbi->cluster_bits - 9);
+	inode->i_blocks += nr_cluster << (sbi->cluster_bits -
+			   sb->s_blocksize_bits);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw
Quoted 3 lines · Namjae Jeon

Currently there is hard-coding at various places in FAT for using the SECTOR size alignment. So, In order to remove the hard coding we need to change the usage of '9' in FAT code.

NACK. 512 is right size for i_blocks.

Quoted 80 lines
---
 fs/fat/file.c  |    3 ++-
 fs/fat/inode.c |    9 ++++++---
 fs/fat/misc.c  |    9 ++++++---
 3 files changed, 14 insertions(+), 7 deletions(-)
fs/fat/file.c +2 -1
index 1f81cb4..e6dd081 100644
@@ -276,7 +276,8 @@ static int fat_free(struct inode *inode, int skip)
 
 		free_start = ret;
 	}
-	inode->i_blocks = skip << (MSDOS_SB(sb)->cluster_bits - 9);
+	inode->i_blocks = skip << (MSDOS_SB(sb)->cluster_bits -
+						sb->s_blocksize_bits);
 
 	/* Freeing the remained cluster chain */
 	return fat_free_clusters(inode, free_start);
fs/fat/inode.c +6 -3
index 80c6fdd..d077f57 100644
@@ -387,7 +387,8 @@ static int fat_calc_dir_size(struct inode *inode)
 /* doesn't deal with root inode */
 static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
 {
-	struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
+	struct super_block *sb = inode->i_sb;
+	struct msdos_sb_info *sbi = MSDOS_SB(sb);
 	int error;
 
 	MSDOS_I(inode)->i_pos = 0;
@@ -431,7 +432,8 @@ static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
 	fat_save_attrs(inode, de->attr);
 
 	inode->i_blocks = ((inode->i_size + (sbi->cluster_size - 1))
-			   & ~((loff_t)sbi->cluster_size - 1)) >> 9;
+			   & ~((loff_t)sbi->cluster_size - 1)) >>
+			   sb->s_blocksize_bits;
 
 	fat_time_fat2unix(sbi, &inode->i_mtime, de->time, de->date, 0);
 	if (sbi->options.isvfat) {
@@ -1148,7 +1150,8 @@ static int fat_read_root(struct inode *inode)
 		inode->i_size = sbi->dir_entries * sizeof(struct msdos_dir_entry);
 	}
 	inode->i_blocks = ((inode->i_size + (sbi->cluster_size - 1))
-			   & ~((loff_t)sbi->cluster_size - 1)) >> 9;
+			   & ~((loff_t)sbi->cluster_size - 1)) >>
+			   sb->s_blocksize_bits;
 	MSDOS_I(inode)->i_logstart = 0;
 	MSDOS_I(inode)->mmu_private = inode->i_size;
 
fs/fat/misc.c +6 -3
index 6d93360..f78469f 100644
@@ -150,13 +150,16 @@ int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster)
 		} else
 			mark_inode_dirty(inode);
 	}
-	if (new_fclus != (inode->i_blocks >> (sbi->cluster_bits - 9))) {
+	if (new_fclus != (inode->i_blocks >> (sbi->cluster_bits -
+			 sb->s_blocksize_bits))) {
 		fat_fs_error(sb, "clusters badly computed (%d != %llu)",
 			     new_fclus,
-			     (llu)(inode->i_blocks >> (sbi->cluster_bits - 9)));
+			     (llu)(inode->i_blocks >> (sbi->cluster_bits -
+			     sb->s_blocksize_bits)));
 		fat_cache_inval_inode(inode);
 	}
-	inode->i_blocks += nr_cluster << (sbi->cluster_bits - 9);
+	inode->i_blocks += nr_cluster << (sbi->cluster_bits -
+			   sb->s_blocksize_bits);
 
 	return 0;
 }
Signature · 1 line
OGAWA Hirofumi <[email protected]>
#2 lore raw

2012/11/5 OGAWA Hirofumi <[email protected]>:

Quoted 7 lines
Quoted 3 lines · Namjae Jeon

Currently there is hard-coding at various places in FAT for using the SECTOR size alignment. So, In order to remove the hard coding we need to change the usage of '9' in FAT code.

NACK. 512 is right size for i_blocks.

Yes, You're right. plz ignore this patch.
Thanks.

Quoted 84 lines
Quoted 71 lines
---
 fs/fat/file.c  |    3 ++-
 fs/fat/inode.c |    9 ++++++---
 fs/fat/misc.c  |    9 ++++++---
 3 files changed, 14 insertions(+), 7 deletions(-)
fs/fat/file.c +2 -1
index 1f81cb4..e6dd081 100644
@@ -276,7 +276,8 @@ static int fat_free(struct inode *inode, int skip)
 
              free_start = ret;
      }
-     inode->i_blocks = skip << (MSDOS_SB(sb)->cluster_bits - 9);
+     inode->i_blocks = skip << (MSDOS_SB(sb)->cluster_bits -
+                                             sb->s_blocksize_bits);
 
      /* Freeing the remained cluster chain */
      return fat_free_clusters(inode, free_start);
fs/fat/inode.c +6 -3
index 80c6fdd..d077f57 100644
@@ -387,7 +387,8 @@ static int fat_calc_dir_size(struct inode *inode)
 /* doesn't deal with root inode */
 static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
 {
-     struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
+     struct super_block *sb = inode->i_sb;
+     struct msdos_sb_info *sbi = MSDOS_SB(sb);
      int error;
 
      MSDOS_I(inode)->i_pos = 0;
@@ -431,7 +432,8 @@ static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
      fat_save_attrs(inode, de->attr);
 
      inode->i_blocks = ((inode->i_size + (sbi->cluster_size - 1))
-                        & ~((loff_t)sbi->cluster_size - 1)) >> 9;
+                        & ~((loff_t)sbi->cluster_size - 1)) >>
+                        sb->s_blocksize_bits;
 
      fat_time_fat2unix(sbi, &inode->i_mtime, de->time, de->date, 0);
      if (sbi->options.isvfat) {
@@ -1148,7 +1150,8 @@ static int fat_read_root(struct inode *inode)
              inode->i_size = sbi->dir_entries * sizeof(struct msdos_dir_entry);
      }
      inode->i_blocks = ((inode->i_size + (sbi->cluster_size - 1))
-                        & ~((loff_t)sbi->cluster_size - 1)) >> 9;
+                        & ~((loff_t)sbi->cluster_size - 1)) >>
+                        sb->s_blocksize_bits;
      MSDOS_I(inode)->i_logstart = 0;
      MSDOS_I(inode)->mmu_private = inode->i_size;
 
fs/fat/misc.c +2 -2
index 6d93360..f78469f 100644
@@ -150,13 +150,16 @@ int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster)
              } else
                      mark_inode_dirty(inode);
      }
-     if (new_fclus != (inode->i_blocks >> (sbi->cluster_bits - 9))) {
+     if (new_fclus != (inode->i_blocks >> (sbi->cluster_bits -
+                      sb->s_blocksize_bits))) {
              fat_fs_error(sb, "clusters badly computed (%d != %llu)",
                           new_fclus,
-                          (llu)(inode->i_blocks >> (sbi->cluster_bits - 9)));

fs/fat/misc.c int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster) · line 165

Quoted 10 lines
fs/fat/misc.c +4 -1
+                          (llu)(inode->i_blocks >> (sbi->cluster_bits -
+                          sb->s_blocksize_bits)));
              fat_cache_inval_inode(inode);
      }
-     inode->i_blocks += nr_cluster << (sbi->cluster_bits - 9);
+     inode->i_blocks += nr_cluster << (sbi->cluster_bits -
+                        sb->s_blocksize_bits);
 
      return 0;
 }

--
OGAWA Hirofumi <[email protected]>