linux ext4文件系统为什么目录大小是4k?

Why does every directory have a size 4096 bytes (4 K)?](https://askubuntu.com/questions/186813/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.

Example:

root@ubuntu:~# tune2fs -l /dev/ubuntu/root 
tune2fs 1.42 (29-Nov-2011)
Filesystem volume name:   <none>
Last mounted on:          /
Filesystem UUID:          2fca4cbb-22f1-4328-ab13-cacedb360930
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              967680
Block count:              3931136
Reserved block count:     0
Free blocks:              2537341
Free inodes:              517736
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      416
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8064
Inode blocks per group:   504
RAID stride:              35637
Flex block group size:    16
Filesystem created:       Thu Mar 15 14:31:04 2012
Last mount time:          Sat Oct 20 20:28:04 2012
Last write time:          Sat Oct 20 20:23:32 2012
Mount count:              1
Maximum mount count:      -1
Last checked:             Sat Oct 20 20:22:57 2012
Check interval:           0 (<none>)
Lifetime writes:          54 GB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:           256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
First orphan inode:       272350
Default directory hash:   half_md4
Directory Hash Seed:      d582ad79-75a0-4964-9a48-33ddba04df5c
Journal backup:           inode blocks

Linux中一切皆文件,文件夹创建过程中会为分配一个inode,文件系统inode会指向磁盘的一个块,块大小由文件系统决定,从以上信息可知文件系统的块的大小为4k。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值