<div dir="ltr"><div>Blocks should be calculated using st_blocks*512, not st_size.</div><div><br></div>According to ls.pdf:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">a total sum for all the file sizes is output on a line before the listing.<br></blockquote><div>We need to print sum of file sizes instead of number of blocks, not sure if it&#39;s typo.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 16, 2014 at 10:15 PM, zding4 <span dir="ltr">&lt;<a href="mailto:zding4@stevens.edu" target="_blank">zding4@stevens.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I find some very confusing output of Linux ls when I play it.<br>
<br>
here is the output<br>
<br>
zding4@avatar:~/apue/midterm$ ls -ls<br>
total 52<br>
 1 -rw-r--r--+ 1 zding4 student    37 Oct 13 21:33 Makefile<br>
21 -rwxr-xr-x+ 1 zding4 student 20060 Oct 16 20:02 a.out<br>
 3 -rw-r--r--+ 1 zding4 student  1634 Oct 16 20:04 alink<br>
 3 -rw-r--r--+ 1 zding4 student  1173 Oct 13 14:30 chldlist.c<br>
 1 -rw-r--r--+ 1 zding4 student     0 Oct 14 15:24 dfsf?????????bla.txt<br>
 2 drwxr-xr-x+ 2 zding4 student     2 Oct 16 19:20 empty<br>
 3 -rw-r--r--+ 1 zding4 student  1598 Oct 16 20:04 file2<br>
 2 -rw-r--r--+ 1 zding4 student   748 Oct 12 22:44 l.h<br>
17 -rw-r--r--+ 1 zding4 student 11408 Oct 16 20:25 ls.c<br>
 1 -rw-r--r--+ 1 zding4 student     0 Oct 13 21:47 out<br>
 1 lrwxrwxrwx  1 zding4 student     5 Oct 16 20:12 slink -&gt; file1<br>
 2 d-wx--x--x+ 3 zding4 student     3 Oct 16 18:48 test<br>
<br>
<br>
first is that<br>
1+21+3+3+1+2+3+2+17+1+1+2 != 52<br>
<br>
The size of test directory is only 3 but it takes 2 blocks<br>
<br>
Any idea why this happen?<br>
<br>
When I implement ls,<br>
The block number is `st_size/BLOCKSIZE`<br>
And the total is the sum of files&#39; block number.<br>
<br>
______________________________<u></u>_________________<br>
cs631apue mailing list<br>
<a href="mailto:cs631apue@lists.stevens.edu" target="_blank">cs631apue@lists.stevens.edu</a><br>
<a href="https://lists.stevens.edu/mailman/listinfo/cs631apue" target="_blank">https://lists.stevens.edu/<u></u>mailman/listinfo/cs631apue</a><br>
</blockquote></div><br></div>