linux 目录大小 4096,Linux 块与文件大小

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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值