1

I have created file named sometext with random data inside. I wanted to check metadata of this file using several programs. I have used filefrag and stat program.

 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 $ 

Both programs shows that the file size is 16 bytes and the block size is 4096 bytes. So far so good, but stat show that file takes 8 blocks and filefrag show that file takes 1 block.

Why there is such big difference? What have I missed?

0

IO block is chunk size for interchange with block device.

Block (stat) is number of filesystem cells (and of cause depend on filesystem type), needed for store a file. It's can be easy to test:

$ 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 bytes

8192 bytes / 512 bytes = 16 Blocks

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

It's two read/write operations need to read/write file from/to block device.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.