Thread (4 messages) 4 messages, 2 authors, 2011-08-08

Creating sparse file on XFS and EXT3 has different results

From: mani <hidden>
Date: 2011-08-08 03:46:09

The ls uses st_size while du uses st_blocks.
So
st_size "file size in bytes"
st_blocks "number of 512 byte blocks allocated".
It depends upon the actual disk block size not the file system block size ..

try using the ls -ls it will give you both the o/p's .

Are you using the same hard disk with same disk block size ?


On Sat, Aug 6, 2011 at 9:51 PM, mani [off-list ref] wrote:
Dear Ashish,

The ls uses st_size while du uses st_blocks.
try using the ls -ls it will give you both the o/p's .

Thanks
Manish

On Fri, Aug 5, 2011 at 7:45 AM, Ashish Sangwan [off-list ref]wrote:
quoted
I write 1 program to create sparse file which contains alternate empty
blocks and data blocks. For example block1=empty, block2=data, block3=empty
.....

#define BLOCK_SIZE 4096
void *buf;
int main(int argc, char **argv)
{
buf=malloc(512);
memset(buf,"a",512);
int fd=0;
int i;
int sector_per_block=BLOCK_SIZE/512;
int block_count=4;
if(argc !=2 ){
        printf("Wrong usage\n USAGE: program absolute_path_to_write\n");
        _exit(-1);
}
fd=open(argv[1],O_RDWR | O_CREAT,0666);
if(fd <= 0){
        printf("file open failed\n");
        _exit(0);
}
while(block_count > 0){
        lseek(fd,BLOCK_SIZE,SEEK_CUR);
        block_count--;
        for(i=0;i<sector_per_block;i++)
        write(fd,buf,512);
        block_count--;
}
close(fd);
return 0;
}

Suppose, I create a new_sparse_file using this above code.

When I run this program, on ext3 FS with block size 4KB, ls -lh shows size
of new_sparse_file as 16KB, while du -h shows 8 kb, which, I think is
correct.

On xfs, block size of 4kb, ls -lh shows 16KB but du -h shows 12kb.
Why are there different kinds of behavior?

If I increase the block_count to be written so that a 200MB file is
created, on XFS du -h shows 187MB and on EXT3 it shows 101MB.

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110808/6cba0c02/attachment-0001.html 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help