More patch description fixups. Standardize case.
[ext4-patch-queue.git] / ext2_fix_max_size.patch
blob510a4cccb52468d2b6b0714cf28ccb28a35b727e
1 ext2: Fix the max file size for ext2 file system.
3 From: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
5 The max file size for ext2 file system is now calculated
6 with hardcoded 4K block size. The patch fixes it to be
7 calculated with the right block size.
9 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
10 ---
12 fs/ext2/super.c | 32 ++++++++++++++++++++++++++++----
13 1 files changed, 28 insertions(+), 4 deletions(-)
16 diff --git a/fs/ext2/super.c b/fs/ext2/super.c
17 index 154e25f..6abaf75 100644
18 --- a/fs/ext2/super.c
19 +++ b/fs/ext2/super.c
20 @@ -680,11 +680,31 @@ static int ext2_check_descriptors (struct super_block * sb)
21 static loff_t ext2_max_size(int bits)
23 loff_t res = EXT2_NDIR_BLOCKS;
24 - /* This constant is calculated to be the largest file size for a
25 - * dense, 4k-blocksize file such that the total number of
26 + int meta_blocks;
27 + loff_t upper_limit;
29 + /* This is calculated to be the largest file size for a
30 + * dense, file such that the total number of
31 * sectors in the file, including data and all indirect blocks,
32 - * does not exceed 2^32. */
33 - const loff_t upper_limit = 0x1ff7fffd000LL;
34 + * does not exceed 2^32 -1
35 + * __u32 i_blocks representing the total number of
36 + * 512 bytes blocks of the file
37 + */
38 + upper_limit = (1LL << 32) - 1;
40 + /* total blocks in file system block size */
41 + upper_limit >>= (bits - 9);
44 + /* indirect blocks */
45 + meta_blocks = 1;
46 + /* double indirect blocks */
47 + meta_blocks += 1 + (1LL << (bits-2));
48 + /* tripple indirect blocks */
49 + meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2)));
51 + upper_limit -= meta_blocks;
52 + upper_limit <<= bits;
54 res += 1LL << (bits-2);
55 res += 1LL << (2*(bits-2));
56 @@ -692,6 +712,10 @@ static loff_t ext2_max_size(int bits)
57 res <<= bits;
58 if (res > upper_limit)
59 res = upper_limit;
61 + if (res > MAX_LFS_FILESIZE)
62 + res = MAX_LFS_FILESIZE;
64 return res;