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? if it is memory block number ,how to get the unchangable hard-disk block number? 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://listman.redhat.com/archives/ext3-users/attachments/20090605/08790c50/attachment.htm>
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
Zhang Shukun wrote:> 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?The implementation is free to change a file's block number at any time.> is the block number the hard-disk block number or memory > block number?It is the current hard-disk block number. But there is no law that says a file's data must always be on the same place on the disk. In fact, it cannot be, because the new version of the data and the old version cannot be in the same place at the same time, and there's no point in putting the new data over the old data.> if it is memory block number, > how to get the unchangable hard-disk block number?There is no "unchangable block number" for the first data byte of a particular file. That will change if the data at the beginning of the file changes, because the old and new data cannot be at the same place at the same time. Imagine if you have a bunch of buckets on your desk, these are like hard disk blocks. And you have a pointer to a bucket, this is like the first data block. Someone says "replace the data with this new data". How can you do this safely? If you just try to replace the data in a given bucket, and you half-finish, you leave the data corrupt. So you do this: 1) You find an empty bucket. 2) You put the new data in it. 3) You move the pointer to the new bucket. 4) You mark the old bucket free. This is safe, but the net result is that changing the data the pointer points to changes the pointer. Defragmentation also changes the block numbers, and the filesystem has no way to promise you it won't defragment either. What is your outer problem? Odds are there's a right way to solve it. DS