W
windstorm
int main( void )
{
int fd,size,position;
char buf[20];
char lkl[] = "hello,world!";
fd = creat( "test",0644 );
size = write( fd,lkl,sizeof(lkl) );
close(fd);
fd = open( "test",O_RDWR );
size = read( fd,buf,sizeof(buf) );
printf( "fd is %s,the length is %d\n\n",buf,size );
position = lseek( fd,70000000,SEEK_END);
size = write( fd,lk,sizeof(lkl) );
close(fd);
return 1;
}
This is just test code, I wanna see what the file will be if I make
the file pointer point to the end and move it by API lseek. That is
what you can see in the code. After a lot of tests, I found that the
file's size which can be saw by the command "ls -ls" will change
according to the lseek's second parameter distance.
For example:
If the dist is 4000 or less than 4000, the block which is filled by
file "test" will be 4K, it's reasonable for the minimal size of block
is 4K.
If the dist is 5000-480000, the block which is filled by file "test"
will be 8K, it's reasonable for the position where the second string
lk be written is out of block 1, so maybe we need two block to save
file "test".
But the follow is something I can not understand. If the dist is more
than 480000, such as 700000, the block which is filled by file "test"
will be 8.5K.
I change the dist to 7000000 direct, the block which is filled by file
"test" will be 15K. And if it is changed to 70000000, the block will
be 75K.
In my opnion, there only have two string in the file, so although
length of file will increase as I increase the distance moved by
lseek, the ACTUAL block size filled by "test" file will keep to be 8K.
But actually I am wrong. So who can explain it for me ?
Thanks very much!
{
int fd,size,position;
char buf[20];
char lkl[] = "hello,world!";
fd = creat( "test",0644 );
size = write( fd,lkl,sizeof(lkl) );
close(fd);
fd = open( "test",O_RDWR );
size = read( fd,buf,sizeof(buf) );
printf( "fd is %s,the length is %d\n\n",buf,size );
position = lseek( fd,70000000,SEEK_END);
size = write( fd,lk,sizeof(lkl) );
close(fd);
return 1;
}
This is just test code, I wanna see what the file will be if I make
the file pointer point to the end and move it by API lseek. That is
what you can see in the code. After a lot of tests, I found that the
file's size which can be saw by the command "ls -ls" will change
according to the lseek's second parameter distance.
For example:
If the dist is 4000 or less than 4000, the block which is filled by
file "test" will be 4K, it's reasonable for the minimal size of block
is 4K.
If the dist is 5000-480000, the block which is filled by file "test"
will be 8K, it's reasonable for the position where the second string
lk be written is out of block 1, so maybe we need two block to save
file "test".
But the follow is something I can not understand. If the dist is more
than 480000, such as 700000, the block which is filled by file "test"
will be 8.5K.
I change the dist to 7000000 direct, the block which is filled by file
"test" will be 15K. And if it is changed to 70000000, the block will
be 75K.
In my opnion, there only have two string in the file, so although
length of file will increase as I increase the distance moved by
lseek, the ACTUAL block size filled by "test" file will keep to be 8K.
But actually I am wrong. So who can explain it for me ?
Thanks very much!