Re: why block number changed after change of file?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Zhang Shukun wrote:
> 
> hi,
> 
> i touch a new file and input the content "a" to it, next i use filefrag
> to see the block number of the file , and then open the file to change
> the content of the file to "aa", next use filefrag to check the block
> number again, but why block number changed after change of file? is the
> block number the hard-disk block number or memory block number? 

filefrag reports the location on-disk.

> if it is
> memory block number ,how to get the unchangable hard-disk block number?

filefrag (or the underlying ioctl it calls, FIBMAP (or better, FIEMAP))
is the right tool / interface.

vim truncates & rewrites the file; this goes back to the allocator in
ext3, and for whatever reason, it picks a new block this time.

$ echo foo > testfile
$ strace -otrace vim testfile
... look at the trace ...
open("testfile", O_WRONLY|O_CREAT|O_TRUNC, 0664) = 3

This sequence does the same:

# echo bar > testfile
# filefrag -v testfile | grep ^First
First block: 1284630
# echo baz > testfile
# filefrag -v testfile | grep ^First
First block: 1284530

Slightly strange, but nothing really wrong with it ....

-Eric

> Thanks!
> 
> the commands displays as follow:
> 
> zsk@zsk-laptop:~$ sudo filefrag -v a
> Checking a
> Filesystem type is: ef53
> Filesystem cylinder groups is approximately 104
> Blocksize of file a is 4096
> File size of a is 3 (1 blocks)
> First block: 2501741
> Last block: 2501741
> a: 1 extent found
> zsk@zsk-laptop:~$ vim a
> zsk@zsk-laptop:~$ sudo filefrag -v a
> Checking a
> Filesystem type is: ef53
> Filesystem cylinder groups is approximately 104
> Blocksize of file a is 4096
> File size of a is 4 (1 blocks)
> First block: 3013843
> Last block: 3013843
> a: 1 extent found
> -- 
> Regards,
> Sucan

_______________________________________________
Ext3-users mailing list
Ext3-users@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/ext3-users

[Index of Archives]         [Linux RAID]     [Kernel Development]     [Red Hat Install]     [Video 4 Linux]     [Postgresql]     [Fedora]     [Gimp]     [Yosemite News]

  Powered by Linux