Dear Mani,<br><br>-> It depends upon the actual disk block size not the file system block size .. <br><br>I think that it always depends on the file-system block size.<br>A disk block size will always less than or equal to File system block size.<br>
For example, say a FS X has block size 2K and disk block size =512.<br>So, when you create a 1 byte file, file_size = 1byte and disk blocks =4.<br>Now, if another FS Y has block size 4K and you create a 1 byte file then :-<br>
file_size = 1 byte and disk blocks= 8. <br><br><div class="gmail_quote">On Mon, Aug 8, 2011 at 12:46 PM, mani <span dir="ltr"><<a href="mailto:manishrma@gmail.com">manishrma@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><div>The ls uses st_size while du uses st_blocks. </div></div>So <br>st_size                "file size in bytes"<br>        st_blocks        "number of 512 byte blocks allocated".<br>It depends upon the actual disk block size not the file system block size .. <br>
<div class="im">
<div>try using the ls -ls it will give you both the o/p's .</div>
<br></div>Are you using the same hard disk with same disk block size ? <br><div><div></div><div class="h5"><br><br><div class="gmail_quote">On Sat, Aug 6, 2011 at 9:51 PM, mani <span dir="ltr"><<a href="mailto:manishrma@gmail.com" target="_blank">manishrma@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Dear Ashish,</div>
<div> </div>
<div>The ls uses st_size while du uses st_blocks. </div>
<div>try using the ls -ls it will give you both the o/p's .</div>
<div> </div>
<div>Thanks </div>
<div>Manish <br><br></div>
<div class="gmail_quote"><div><div></div><div>On Fri, Aug 5, 2011 at 7:45 AM, Ashish Sangwan <span dir="ltr"><<a href="mailto:ashishsangwan2@gmail.com" target="_blank">ashishsangwan2@gmail.com</a>></span> wrote:<br>
</div></div><blockquote style="border-left:#ccc 1px solid;margin:0px 0px 0px 0.8ex;padding-left:1ex" class="gmail_quote"><div><div></div><div>
<p>I write 1 program to create sparse file which contains alternate empty blocks and data blocks. For example block1=empty, block2=data, block3=empty .....</p><pre><code>#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;
}
</code></pre>
<p>Suppose, I create a new_sparse_file using this above code.</p>
<p>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.</p>
<p>On xfs, block size of 4kb, ls -lh shows 16KB but du -h shows 12kb.</p>
<div>Why are there different kinds of behavior?</div>
<div> </div>
<div>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.</div><br></div></div>_______________________________________________<br>Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br><a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
<br></blockquote></div><br>
</blockquote></div><br>
</div></div></blockquote></div><br>