why block number changed after change of file?
Eric Sandeen
sandeen at redhat.com
Fri Jun 5 04:00:27 UTC 2009
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 at 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 at zsk-laptop:~$ vim a
> zsk at 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
More information about the Ext3-users
mailing list