Linux

來自 filefrag 和 stat 的塊之間的區別

  • April 19, 2018

我在sometext裡面創建了用隨機數據命名的文件。我想使用幾個程序檢查這個文件的元數據。我已經使用filefragstat程式。

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 bytesblock大小為4096 bytes. 到目前為止一切順利,但stat顯示該文件需要8 blocksfilefrag顯示該文件需要1 block.

為什麼會有這麼大的差異?我錯過了什麼?

IO 塊是用於與塊設備交換的塊大小。

Block ( 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

這是兩個讀/寫操作需要從/向塊設備讀取/寫入文件。

引用自:https://unix.stackexchange.com/questions/438665