<div dir="ltr">Like I said, you need to use <span style="font-family:arial,sans-serif;font-size:12px">st_blocks*512 instead of </span><span style="font-family:arial,sans-serif;font-size:12px">st_size for each file.</span><div><span style="font-family:arial,sans-serif;font-size:12px">To count total blocks, you should add all </span><span style="font-family:arial,sans-serif;font-size:12px">st_blocks first, and then convert to units of 512 or </span><font face="arial, sans-serif"><span style="font-size:12px">BLOCKSIZE.</span></font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 17, 2014 at 12:11 AM, 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">In the long format part of ls.pdf<br>
<br>
In addition, for each directory whose contents are displayed, the total number of blocks in units of 512 bytes<br>
or BLOCKSIZE (see ENVIRONMENT)used by the files in the directory is displayed on a line by itself<br>
immediately before the information for the files in the directory.<br>
<br>
What I ask is the how to count the number of file system blocks actually used by each file in units of 512 bytes or<br>
BLOCKSIZE (see ENVIRONMENT) (-s, -l total)<br>
<br>
<br>
在 10/16/2014 11:49 PM,Sen Jiang 写道:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
Blocks should be calculated using st_blocks*512, not st_size.<br>
<br>
According to ls.pdf:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
a total sum for all the file sizes is output on a line before the<br>
listing.<br>
</blockquote>
<br>
We need to print sum of file sizes instead of number of blocks, not<br>
sure if it&#39;s typo.<br>
<br>
On Thu, Oct 16, 2014 at 10:15 PM, zding4 &lt;<a href="mailto:zding4@stevens.edu" target="_blank">zding4@stevens.edu</a>&gt; wrote:<br>
<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
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<br>
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;<br>
file1<br>
 2 d-wx--x--x+ 3 zding4 student     3 Oct 16 18:48 test<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>
</div></div><a href="https://lists.stevens.edu/mailman/listinfo/cs631apue" target="_blank">https://lists.stevens.edu/<u></u>mailman/listinfo/cs631apue</a> [1]<br>
</blockquote>
<br>
<br>
<br>
Links:<br>
------<br>
[1] <a href="https://lists.stevens.edu/mailman/listinfo/cs631apue" target="_blank">https://lists.stevens.edu/<u></u>mailman/listinfo/cs631apue</a><br>
</blockquote>
</blockquote></div><br></div>