RE: why block number changed after change of file?

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

 



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


_______________________________________________
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