ext2: Fix the max file size for ext2 file system.
PATCH 1/1 ext2: Fix the max file size for ext2 file system.
The max file size for ext2 file system is now calculated with hardcoded 4K block size. The patch fixes it to be calculated with the right block size.
--- fs/ext2/super.c | 32 ++++++++++++++++++++++++++++---- 1 files changed, 28 insertions(+), 4 deletions(-)
fs/ext2/super.c +28 -4
@@ -603,11 +603,31 @@ static int ext2_check_descriptors (struct super_block * sb)static loff_t ext2_max_size (int bits) {loff_t res =EXT2_NDIR_BLOCKS ; -/* This constant is calculated to be the largest file size for a -* dense, 4k-blocksize file such that the total number of +int meta_blocks; +loff_t upper_limit; + +/* This is calculated to be the largest file size for a +* dense, file such that the total number of * sectors in the file, including data and all indirect blocks, -* does not exceed 2^32. */ -const loff_t upper_limit =0x1ff7fffd000LL ; +* does not exceed 2^32 -1 +* __u32 i_blocks representing the total number of +* 512 bytes blocks of the file +*/ + upper_limit = (1LL <<32 ) -1 ; + +/* total blocks in file system block size */ + upper_limit >>= (bits -9 ); + + +/* indirect blocks */ + meta_blocks =1 ; +/* double indirect blocks */ + meta_blocks +=1 + (1LL << (bits-2 )); +/* tripple indirect blocks */ + meta_blocks +=1 + (1LL << (bits-2 )) + (1LL << (2 *(bits-2 ))); + + upper_limit -= meta_blocks; + upper_limit <<= bits; res +=1LL << (bits-2 ); res +=1LL << (2 *(bits-2 ));
@@ -615,6 +635,10 @@ static loff_t ext2_max_size(int bits) res <<= bits;if (res > upper_limit) res = upper_limit; + +if (res >MAX_LFS_FILESIZE ) + res =MAX_LFS_FILESIZE ; +return res; }
Signature · 1 line
1.5.3.4.206.g58ba4-dirty
PATCH 1/1 ext3: Fix the max file size for ext3 file system.
The max file size for ext3 file system is now calculated with hardcoded 4K block size. The patch fixes it to be calculated with the right block size.
--- fs/ext3/super.c | 32 ++++++++++++++++++++++++++++---- 1 files changed, 28 insertions(+), 4 deletions(-)
fs/ext3/super.c +28 -4
@@ -1362,11 +1362,31 @@ static void ext3_orphan_cleanup (struct super_block * sb,static loff_t ext3_max_size (int bits) {loff_t res =EXT3_NDIR_BLOCKS ; -/* This constant is calculated to be the largest file size for a -* dense, 4k-blocksize file such that the total number of +int meta_blocks; +loff_t upper_limit; + +/* This is calculated to be the largest file size for a +* dense, file such that the total number of * sectors in the file, including data and all indirect blocks, -* does not exceed 2^32. */ -const loff_t upper_limit =0x1ff7fffd000LL ; +* does not exceed 2^32 -1 +* __u32 i_blocks representing the total number of +* 512 bytes blocks of the file +*/ + upper_limit = (1LL <<32 ) -1 ; + +/* total blocks in file system block size */ + upper_limit >>= (bits -9 ); + + +/* indirect blocks */ + meta_blocks =1 ; +/* double indirect blocks */ + meta_blocks +=1 + (1LL << (bits-2 )); +/* tripple indirect blocks */ + meta_blocks +=1 + (1LL << (bits-2 )) + (1LL << (2 *(bits-2 ))); + + upper_limit -= meta_blocks; + upper_limit <<= bits; res +=1LL << (bits-2 ); res +=1LL << (2 *(bits-2 ));
@@ -1374,6 +1394,10 @@ static loff_t ext3_max_size(int bits) res <<= bits;if (res > upper_limit) res = upper_limit; + +if (res >MAX_LFS_FILESIZE ) + res =MAX_LFS_FILESIZE ; +return res; }
Signature · 1 line
1.5.3.4.206.g58ba4-dirty
fs/ext2/super.c static int ext2_check_descriptors (struct super_block * sb) · line 627
Quoted 6 lines · Aneesh Kumar K.V
fs/ext2/super.c +6
-0+/* indirect blocks */ + meta_blocks =1 ; +/* double indirect blocks */ + meta_blocks +=1 + (1LL << (bits-2 )); +/* tripple indirect blocks */ + meta_blocks +=1 + (1LL << (bits-2 )) + (1LL << (2 *(bits-2 )));
It may be worthwhile calculating how many indirect blocks there actually are in a file that size. Also note that your comments are backward - there is at most a single triple indirect block per file.
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Quoted 10 lines · Andreas Dilger
fs/ext2/super.c static int ext2_check_descriptors (struct super_block * sb) · line 627
Quoted 6 lines · Aneesh Kumar K.V
fs/ext2/super.c +6
-0+/* indirect blocks */ + meta_blocks =1 ; +/* double indirect blocks */ + meta_blocks +=1 + (1LL << (bits-2 )); +/* tripple indirect blocks */ + meta_blocks +=1 + (1LL << (bits-2 )) + (1LL << (2 *(bits-2 )));It may be worthwhile calculating how many indirect blocks there actually are in a file that size.
The math become more confusing for that right ?. I am not sure we need to be that specific.
Quoted 2 lines
Also note that your comments are backward - there is at most a single triple indirect block per file.
What i meant by those comment was, the count of meta data blocks taken for different type of indirect blocks.
-aneesh