我创建了一个sometext
以随机数据命名的文件。我想使用多个程序检查该文件的元数据。我已经使用filefrag
和stat
编程了。
kd@kd-VPCEB2S1E ~/Downloads $ stat sometext
File: 'sometext'
Size: 16 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 6298184 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ kd) Gid: ( 1000/ kd)
Access: 2018-04-19 09:39:07.263246674 +0200
Modify: 2018-04-19 09:39:06.527234524 +0200
Change: 2018-04-19 09:39:06.527234524 +0200
Birth: -
kd@kd-VPCEB2S1E ~/Downloads $ filefrag -v sometext
Filesystem type is: ef53
File size of sometext is 16 (1 block of 4096 bytes)
ext: logical_offset: physical_offset: length: expected: flags:
0: 0.. 0: 25369307.. 25369307: 1: last,eof
sometext: 1 extent found
kd@kd-VPCEB2S1E ~/Downloads $
两个程序都显示文件大小为16 bytes
,block
大小为4096 bytes
。到目前为止一切顺利,但stat
显示该文件需要8 blocks
并filefrag
显示该文件需要1 block
。
为什么会有这么大的差别呢?我错过了什么?
答案1
IO块是块大小用于与块设备互换。
堵塞( stat
) 是文件系统的编号细胞(当然取决于文件系统类型),存储文件所需的。测试起来很容易:
$ stat shell
File: ‘shell’
Size: 4295 Blocks: 16 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 16997503 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 1000/ yurij) Gid: ( 1000/ yurij)
Access: 2018-04-11 18:17:38.614827347 +0300
Modify: 2018-04-11 18:17:34.359967012 +0300
Change: 2018-04-19 01:07:03.729000000 +0300
Birth: -
$ pwd
/home/yurij/develop/shell/usr/local/bin
$ sudo blockdev --getbsz /dev/mapper/cl-root
[sudo] password for yurij:
512 # cell size in bytes
8 KB = 8192 字节
8192 字节 / 512 字节 = 16 块
filefrag
:
$ filefrag -v shell
Filesystem type is: 58465342
File size of shell is 4295 (2 blocks of 4096 bytes)
ext: logical_offset: physical_offset: length: expected: flags:
0: 0.. 1: 1141480.. 1141481: 2: eof
shell: 1 extent found
从块设备读取文件/向块设备写入文件需要两个读/写操作。