当前位置:   article > 正文

linux ext4文件系统为什么目录大小是4k?_linux reader 都是4kb的文件

linux reader 都是4kb的文件

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/204137
推荐阅读
相关标签
  

闽ICP备14008679号