LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (http://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   why block number changed after change of file? (http://www.linuxquestions.org/questions/linux-kernel-70/why-block-number-changed-after-change-of-file-730802/)

bitzsk 06-04-2009 10:44 PM

why block number changed after change of file?
 
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@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

exvor 06-04-2009 10:49 PM

I would venture the block number is where the file is actually stored in the file system. The reason it would change i venture is because when you touch it it gets read to memory and then rewritten to another part of the disk. Gotta remember that the hard drive does spin.

pixellany 06-05-2009 07:10 AM

This is neat---learn something new every day!!

It is in fact the block number on the partition, starting at the beginning of the partition.

You can see it like this (assumes your data is on sda1):

dd if=/dev/sda1 bs=4096 skip=3013843 count=1 | hexdump -C | more

And the previous location using:
dd if=/dev/sda1 bs=4096 skip=2501741 count=1 | hexdump -C | more

(If necessary,use a higher number for count to see more of the file)

I did not know that a filesystem would move things around this way, but it makes sense. When you add to a file, the filesystem cannot assume that there is room where it was--therefor it simply finds space based on the new size. The old space is freed up and is available for something that will fit there. (I'm guessing that this is how it works.......)


All times are GMT -5. The time now is 10:00 AM.