fat: add i_disksize to represent uninitialized size
Subsystems (2)
PATCH v5 1/5 fat: add i_disksize to represent uninitialized size
Adding i_disksize to represent uninitialized allocated size. And mmu_private represent initialized allocated size. i_disksize - is always kept cluster size aligned mmu_private - is normally block size aligned
--- fs/fat/fat.h | 3 ++- fs/fat/file.c | 5 ++++- fs/fat/inode.c | 11 +++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-)
fs/fat/fat.h +2 -1
@@ -119,7 +119,8 @@ struct msdos_inode_info {unsigned int cache_valid_id;/* NOTE: mmu_private is 64bits, so must hold ->i_mutex to access */ -loff_t mmu_private;/* physically allocated size */ +loff_t mmu_private;/* physically allocated size (initialized) */ +loff_t i_disksize;/* physically allocated size (uninitialized) */ int i_start;/* first cluster or 0 */ int i_logstart;/* logical first cluster */
fs/fat/file.c +4 -1
@@ -300,8 +300,11 @@ void fat_truncate_blocks(struct inode *inode, loff_t offset)* This protects against truncating a file bigger than it was then * trying to write into the hole. */ -if (MSDOS_I (inode)->mmu_private > offset) +if (MSDOS_I (inode)->mmu_private > offset) {MSDOS_I (inode)->mmu_private = offset; +MSDOS_I (inode)->i_disksize =round_up (offset, + sbi->cluster_size); + } nr_clusters = (offset + (cluster_size -1 )) >> sbi->cluster_bits;
fs/fat/inode.c +9 -2
@@ -104,6 +104,7 @@ static struct fat_floppy_defaults {static int fat_add_cluster (struct inode *inode) {int err, cluster; +struct msdos_sb_info *sbi =MSDOS_SB (inode->i_sb); err =fat_alloc_clusters (inode, &cluster,1 );if (err)
@@ -113,6 +114,9 @@ static int fat_add_cluster(struct inode *inode) err =fat_chain_add (inode, cluster,1 );if (err)fat_free_clusters (inode, cluster); +else +MSDOS_I (inode)->i_disksize += sbi->cluster_size; +return err; }
@@ -469,7 +473,6 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) error =fat_calc_dir_size (inode);if (error <0 )return error; -MSDOS_I (inode)->mmu_private = inode->i_size;set_nlink (inode,fat_subdirs (inode)); }else {/* not a directory */
@@ -484,8 +487,11 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) inode->i_op = &fat_file_inode_operations; inode->i_fop = &fat_file_operations; inode->i_mapping->a_ops = &fat_aops; -MSDOS_I (inode)->mmu_private = inode->i_size; } + +MSDOS_I (inode)->mmu_private = inode->i_size; +MSDOS_I (inode)->i_disksize =round_up (inode->i_size, sbi->cluster_size); +if (de->attr &ATTR_SYS ) {if (sbi->options.sys_immutable) inode->i_flags |=S_IMMUTABLE ;
@@ -1293,6 +1299,7 @@ static int fat_read_root(struct inode *inode) & ~((loff_t)sbi->cluster_size - 1)) >> 9;MSDOS_I (inode)->i_logstart =0 ;MSDOS_I (inode)->mmu_private = inode->i_size; +MSDOS_I (inode)->i_disksize =round_up (inode->i_size, sbi->cluster_size);fat_save_attrs (inode,ATTR_DIR ); inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec =0 ;
Signature · 1 line
1.7.11-rc0
OGAWA Hirofumi
maintainerQuoted 4 lines · Namjae Jeon
Adding
i_disksizeto represent uninitialized allocated size. Andmmu_privaterepresent initialized allocated size.i_disksize- is always kept cluster size alignedmmu_private- is normally block size aligned
Hi,
While reading this with fresh mind, I've now noticed i_disksize is lesser i_blocks in fatfs?
Well, if fallocate inode, what number should we return? I.e. it returns really allocated blocks, or fake blocks in i_size?
If we can use i_blocks (fatfs doesn't have hole), maybe, this patch become simpler. If not, I think we should add i_disksize changes more like i_blocks does.
What do you think?
Thanks.
Quoted 90 lines
Signed-off-by Namjae Jeon <[email protected]>Signed-off-by Amit Sahrawat <[email protected]>--- fs/fat/fat.h | 3 ++- fs/fat/file.c | 5 ++++- fs/fat/inode.c | 11 +++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-)fs/fat/fat.h +2
-1@@ -119,7 +119,8 @@ struct msdos_inode_info {unsigned int cache_valid_id;/* NOTE: mmu_private is 64bits, so must hold ->i_mutex to access */ -loff_t mmu_private;/* physically allocated size */ +loff_t mmu_private;/* physically allocated size (initialized) */ +loff_t i_disksize;/* physically allocated size (uninitialized) */ int i_start;/* first cluster or 0 */ int i_logstart;/* logical first cluster */ fs/fat/file.c +4
-1@@ -300,8 +300,11 @@ void fat_truncate_blocks(struct inode *inode, loff_t offset)* This protects against truncating a file bigger than it was then * trying to write into the hole. */ -if (MSDOS_I (inode)->mmu_private > offset) +if (MSDOS_I (inode)->mmu_private > offset) {MSDOS_I (inode)->mmu_private = offset; +MSDOS_I (inode)->i_disksize =round_up (offset, + sbi->cluster_size); + } nr_clusters = (offset + (cluster_size -1 )) >> sbi->cluster_bits;fs/fat/inode.c +9
-2@@ -104,6 +104,7 @@ static struct fat_floppy_defaults {static int fat_add_cluster (struct inode *inode) {int err, cluster; +struct msdos_sb_info *sbi =MSDOS_SB (inode->i_sb); err =fat_alloc_clusters (inode, &cluster,1 );if (err)@@ -113,6 +114,9 @@ static int fat_add_cluster(struct inode *inode) err =fat_chain_add (inode, cluster,1 );if (err)fat_free_clusters (inode, cluster); +else +MSDOS_I (inode)->i_disksize += sbi->cluster_size; +return err; }@@ -469,7 +473,6 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) error =fat_calc_dir_size (inode);if (error <0 )return error; -MSDOS_I (inode)->mmu_private = inode->i_size;set_nlink (inode,fat_subdirs (inode)); }else {/* not a directory */ @@ -484,8 +487,11 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) inode->i_op = &fat_file_inode_operations; inode->i_fop = &fat_file_operations; inode->i_mapping->a_ops = &fat_aops; -MSDOS_I (inode)->mmu_private = inode->i_size; } + +MSDOS_I (inode)->mmu_private = inode->i_size; +MSDOS_I (inode)->i_disksize =round_up (inode->i_size, sbi->cluster_size); +if (de->attr &ATTR_SYS ) {if (sbi->options.sys_immutable) inode->i_flags |=S_IMMUTABLE ;@@ -1293,6 +1299,7 @@ static int fat_read_root(struct inode *inode) & ~((loff_t)sbi->cluster_size - 1)) >> 9;MSDOS_I (inode)->i_logstart =0 ;MSDOS_I (inode)->mmu_private = inode->i_size; +MSDOS_I (inode)->i_disksize =round_up (inode->i_size, sbi->cluster_size);fat_save_attrs (inode,ATTR_DIR ); inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec =0 ;
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Quoted 9 lines
Quoted 4 lines · Namjae Jeon
Adding
i_disksizeto represent uninitialized allocated size. Andmmu_privaterepresent initialized allocated size.i_disksize- is always kept cluster size alignedmmu_private- is normally block size alignedHi,
Hi OGAWA,
Quoted 3 lines
While reading this with fresh mind, I've now noticed
i_disksizeis lesseri_blocksin fatfs?
Yes.
Quoted 3 lines
Well, if fallocate inode, what number should we return? I.e. it returns really allocated blocks, or fake blocks in
i_size?
It should return allocated blocks. And i_blocks is also updated by fat_chain_add in fat_fallocate.
Quoted 4 lines
If we can use
i_blocks(fatfs doesn't have hole), maybe, this patch become simpler. If not, I think we should addi_disksizechanges more likei_blocksdoes.
Yes, We can use i_blocks instead of i_disksize.
Quoted 2 lines
What do you think?
As you pointed out, Using i_blocks will make this patch more simple.
Thanks for review!
Quoted 4 lines
Thanks.
OGAWA Hirofumi <[email protected]>