Results 21 to 30 of 45
Originally Posted by bitzsk
One thing i cant understand is that when i open a file and delete same charactors, then save the file. i guess the block number should ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 06-10-2009 #21
Rubberman,Your uncertainity is correct. New block may or mayn't allocated ,it's based on the application which uses the files.The starting block of the file will likely not change, though I am not certain of that.
We have file's content in buffer,while modifying kernel takes the next available block number from its free list and stores the content in to it,If the application asks the kernel to do so.
You can check that with simple example :
Original file st1 - note block number(5939201) and inode
Now i'm adding some content using cat command[root@ctsingtofed08 tmp]# filefrag -v st1
Checking st1
Filesystem type is: ef53
Filesystem cylinder groups is approximately 303
Blocksize of file st1 is 4096
File size of st1 is 512 (1 blocks)
First block: 5939201
Last block: 5939201
st1: 1 extent found
[root@ctsingtofed08 tmp]# ls -i st1
5925319 st1
Inode remains the same.[root@ctsingtofed08 tmp]# cat >> st1
sdfs
Now i added some content using vi[root@ctsingtofed08 tmp]# ls -i st1
5925319 st1
and the block number too.
[root@ctsingtofed08 tmp]# filefrag -v st1
Checking st1
Filesystem type is: ef53
Filesystem cylinder groups is approximately 303
Blocksize of file st1 is 4096
File size of st1 is 517 (1 blocks)
First block: 5939201
Last block: 5939201
st1: 1 extent found
[root@ctsingtofed08 tmp]#
#vi st1
added some value and closed it.
Now Inode values remains the same ,but block number is changed.
[So it's purely based on the application,(vi or cat)the way how they open the file.root@ctsingtofed08 tmp]# filefrag -v st1
Checking st1
Filesystem type is: ef53
Filesystem cylinder groups is approximately 303
Blocksize of file st1 is 4096
File size of st1 is 529 (1 blocks)
First block: 6063105
Last block: 6063105
st1: 1 extent foundFirst they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-----
FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org
- 06-10-2009 #22Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,160
Well, that's because vi, and a lot of other editors, save the old version of the file, and when you save the changes, write the entire data set to a new file. So, this is expected. As you say, this is up to the application. However, that is not due to behavior of the OS, but solely due to behavior of the application. When you modify a file with VI or nedit, you have the old copy, and it is almost certain that it occupies the same location you found it at originally, before the changes.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 06-10-2009 #23
Thansks for more insight on this issue
I need to understand how the application can change a block numbers.
I created a file
touch it.txt
then wrote messy problem to append data to it
Both inode and block numbers are same,every time i added a character to file.[root@ctsingtofed08 tmp]# cat test.c
main(){
int fp;
char x='x';
fp=open("it.txt",2);
lseek(fp,0,2);
write(fp,&x,1);
close(fp);
}
So above one is similar to cat command.
I thought it was related OS functionality , (like an application opening a file with special argument) will write the file in another location. -I realized that's not the case.
Can you suggest me example program or pseudo codes for another case?
(may be comparing source code vi and cat might be the best option - i guess)First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-----
FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org
- 06-10-2009 #24
Thank you. even the file has one block, it will change when add something. as follows:
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 13 (1 blocks)
First block: 3013938
Last block: 3013938
a: 1 extent found
zsk@zsk-laptop:~$ cat a
hello,world!
zsk@zsk-laptop:~$ vim a
zsk@zsk-laptop:~$ cat a
hi,hello,world!
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 16 (1 blocks)
First block: 3013924
Last block: 3013924
a: 1 extent found
- 06-10-2009 #25
Hi bitzsk,
try using
I guess,Now the block won't change.cat >> aFirst they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-----
FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org
- 06-10-2009 #26Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,160
When you edit a file in VI, changes are recorded to .filename.swp. When you save the file, the original file, with the changes, are saved to a new file, and the old one is deleted. This is why you will find that the block number of the file has changed. The original file is not acutally modified. VI keeps all data in core memory. Other editors act differently, but with the same effect. The nedit editor renames the original file as a backup, and saves the changed data to a new file with the same name as the original. Each application can behave in a somewhat different manner, so the fact that the block numbers have changed really means very little.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 06-10-2009 #27
yeah, cat >> a will not change the inode and block number. but the different behavire of cat and vi command confused me. i don't know the mechanism of these commands.
- 06-10-2009 #28
First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-----
FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org
- 06-10-2009 #29
First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-----
FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org
- 06-10-2009 #30
hi, Rubberman
i am doing a project which is related to security, in the block-level to protect a file against for written even if you have the ROOT privilege. i save the block number of a file first, so when you try to edit the file , i will get the blocks what you are writing for, and compare the blocks with which i saved before,if there are same, the written will be stopped,but if you don't send me the old block number but a new one, i can't control the write behavior any more.
and if you use cat command to change the file ,i can control
and if you use vim command to change the file, i cant control.



Reply With Quote

