linux ext4普通盘为什么目录大小是4k?

Why does every directory have a size 4096 bytes (4 K)?

To understand this, you'd better have some basic knowledge of the following (file system):

  • inode (contains file attributes, metadata of file, pointer structure)
  • file (can be considered a table with 2 columns, filename and its inode, inode points to the raw data blocks on the block device)
  • directory (just a special file, container for other filenames. It contains an array of filenames and inode numbers for each filename. Also it describes the relationship between parent and children.)
  • symbolic link VS hard link
  • dentry (directory entries)

    ...

    On typical ext4 file system (I reckon most likely this is what you are using), the default inode size is 256 bytes, block size is 4096 bytes.

A directory is just a special file which contains an array of filenames and inode numbers. When the directory was created, the file system allocated 1 inode to the directory with a "filename" (dir name in fact). The inode points to a single data block (minimum overhead), which is 4096 bytes. That's why you see 4096 / 4.0K when using ls.

要理解这个,你首先要懂:(注: 这里我用c7.4,默认xfs:/etc/fstab,我又挂了一个格式化成ext4做的实验)

inode:
file
directory
symblic: 软链接

参阅:

磁盘MBR分区机制- inode/Block深入实战

linux的inode和block-软硬链接



我猜目录名字占了第一个inode-index.

inode-index和inodetable单独开辟了一个block

目录是特殊的文件,目录内容包含: 文件名+inode号, 当目录被创建后,文件系统会给这个目录分配1个inode+特殊文件(即以目录为名). inode指向一个block. 所有你才会看到目录大小为4k.

这就能理解目录里的文件,文件名字保存在了所在目录的block里.

查看和修改ext4的inode和block

ext4 默认inode大小是256bytes, block大小是4096bytes

[root@moban ~]# dumpe2fs /dev/sdb |grep "Inode size"
Inode size: 256 [root@moban ~]# dumpe2fs /dev/sdb |grep "Block size"
Block size: 4096 - 格式化时候指定inode和block大小
[root@moban ~]# mkfs.ext4 -I 2048 -b 2048 /dev/sdb

查看目录的inode内容

最新文章

  1. Linux 文件的基本操作
  2. 【BZOJ-3790】神奇项链 Manacher + 树状数组(奇葩) + DP
  3. JS-OC通信之Cordova简介
  4. select--from--where--group by--having--order by 依次顺序
  5. GDAL中RasterIO函数(把文件读取为一个一维数组)和ReadBlock函数(读取栅格数据块)
  6. 动态加载JS脚本的4种方法
  7. html基本基础
  8. jQuery 1.9 移除了 $.browser 的替代方法
  9. 如何对Site Settings页面进行定制化 添加一个setting 链接
  10. Docker 如何支持多种日志方案?- 每天5分钟玩转 Docker 容器技术(88)
  11. Left Join on 多条件查询时,条件过滤的问题
  12. gradle 汉化
  13. 阿里云的免费型DV SSL证书
  14. kepware http接口 c语言 ruby
  15. html5式程序员表白
  16. Js_cookie保存登录名
  17. DBUtils工具
  18. IOS开发----生成静态库(.a)
  19. 手写数字识别---demo
  20. 【Unity】同时打开多个项目工程

热门文章

  1. Lucene解析 - 基本概念
  2. Axure JS弹窗提示部件
  3. Eclipse和MyEclipse使用技巧--如何解决新建一个包的时候,工具帮生成了多个包的问题?
  4. Linux常见命令缩写
  5. 关于Thinkpad的立体声麦克风输入
  6. 《Java设计模式》之模板方法模式
  7. 【LeetCode】230. Kth Smallest Element in a BST (2 solutions)
  8. Ubuntu Linux 环境变量PATH设置
  9. 树莓派进阶之路 (015) - 树莓派使用DS18B20模块测量温度
  10. c运行库、c标准库、windows API的区别和联系