linux ext4 文件大小,[svc]为何linux ext4文件系统目录默认大小是4k?

Linux ext4文件系统中,目录大小通常显示为4K,这是因为每个目录被视为一种特殊文件,包含文件名和inode号的数组。创建目录时,系统分配1个inode和1个数据块给目录,该数据块默认大小为4096字节。inode指向这个数据块,从而目录占用4K空间。目录内的文件名实际存储在这个数据块中。了解这一点需要对inode、文件、目录和block等概念有一定认识。
摘要由CSDN通过智能技术生成

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: 软链接

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

8e0ddf7e5e4444a192f9698781323316.png

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

c3e5b94dc2449fd3c7faea50bb604607.png

目录是特殊的文件,目录内容包含: 文件名+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内容

d01afe932d58663eee81a3e9af1caa6c.png

bcfcd724d5f3f672ac2436f557bbd0c9.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值