LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices



Reply
 
Search this Thread
Old 06-04-2009, 11:44 PM   #1
bitzsk
LQ Newbie
 
Registered: Apr 2009
Posts: 15

Rep: Reputation: 0
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

Last edited by bitzsk; 06-04-2009 at 11:47 PM.
 
Old 06-04-2009, 11:49 PM   #2
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,496

Rep: Reputation: 68
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.
 
Old 06-05-2009, 08:10 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
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.......)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Did IDE block device label changed with Kernel > 2.6.27 ? maus Linux - Kernel 2 06-07-2009 04:28 PM
How to get minor number in block driver transfer request cjlinux Linux - Newbie 0 03-09-2009 11:26 AM
bad magic number to open super block Ritho Linux - Newbie 1 03-06-2008 09:02 AM
Bad magic number in super-block Cadmium Linux - Newbie 2 10-03-2007 02:50 AM
Bad magic number in super-block kubokubik Linux - Newbie 4 01-26-2005 11:52 AM


All times are GMT -5. The time now is 03:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration