EXT2格式 块大小为1024字节的话,单一文件最大容量是16GB,块大小为4096字节的话,单一文件最大容量为2TB

http://hi.baidu.com/mycnwhitewater/item/3f43b0c683a1c163f6c95d4c

EXT2格式 块大小为1024字节的话,单一文件最大容量是16GB,块大小为4096字节的话,单一文件最大容量为2TB

如果你愿意,看看kernel源代码吧
位置: ~/fs/ext2/supper.c
看这个函数:
C/C++ code

/* * Maximal file size. There is a direct, and {,double-,triple-}indirect * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks. * We need to be 1 filesystem block less than the 2^32 sector limit. */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 * sectors in the file, including data and all indirect blocks, * does not exceed 2^32. */const loff_t upper_limit = 0x1ff7fffd000LL; res += 1LL << (bits-2); res += 1LL << (2*(bits-2)); res += 1LL << (3*(bits-2)); res <<= bits; if (res > upper_limit) res = upper_limit; return res; }



调用上面函数的地方:
C/C++ code

staticint ext2_fill_super(struct super_block *sb, void*data, int silent) { ... sb->s_maxbytes = ext2_max_size(sb->s_blocksize_bits); ...}



其中supper block中定义的s_maxbytes就是用作限制文件大小的!!
查获定义知道: EXT2_NDIR_BLOCKS = 12;

所以当blocksize = 1024的时候,sb->s_blocksize_bits = 10 (2^1024);
这时候的sb->s_maxbytes = ext2_max_size (10); 计算出来,就约等于2^34 bytes(即16GB)!

当blocksize = 4096的时候,res = 12 (2^12 = 4096) (约等于);
这时候 sb->s_maxbytes = ext3_max_size (12); 计算出来,约定于 2^42 bytes(即4TB),
也就是res = 4G(约等于);计算知道res > upper_limit。而upper_limit约等于2T。所以两者取小。res = 2T;
这样最大文件大小 sb->s_maxbytes = 2T;