Tsvetelina said:
Hello, I am writing a program in C that implements the UNIX command ls -l.
I understood that the number after total is the blocks that are given to
the files? I am completely sure because I couldn't find information about it.
Can someone help me and tell me what it is that number and how I can calculated
to show it in my implementation. Thanks in advance
Click the Coreutils "sources" link, to get a 9,371,720 byte download.
The source for "ls" is in there, and likely in a million other places.
This would be a GNU version of "ls", and you can use these packages
on a Windows system.
http://gnuwin32.sourceforge.net/packages/coreutils.htm
"Sources Zip 9371720 21 April 2005 MD5sum = 5cbd86c56e6eb29b6af2810849d08c8c
(
http://iweb.dl.sourceforge.net/project/gnuwin32/coreutils/5.3.0/coreutils-5.3.0-src.zip )
If you download the documentation link, it has a PDF document in it
"Documentation Zip 4540924 21 April 2005 MD5sum = ee0b456daf011d6e348cc64adafe968a
The coreutils.pdf document (1,315,345 bytes) has the documentation. This is
what it lists for the -l option on PDF page 63.
*******
‘-l’
‘--format=long’
‘--format=verbose’
In addition to the name of each file, print the file type, permissions, number of hard
links, owner name, group name, size, and timestamp (see Section 10.1.6 [Formatting
file timestamps], page 59), normally the modification time.
Normally the size is printed as a byte count without punctuation, but this can
be overridden (see Section 2.3 [Block size], page 3). For example, ‘-h’ prints an
abbreviated, human-readable count, and ‘--block-size="’1"’ prints a byte count
with the thousands separator of the current locale.
For each directory that is listed, preface the files with a line ‘total blocks’, where
blocks is the total disk allocation for all files in that directory. The block size currently
defaults to 1024 bytes, but this can be overridden (see Section 2.3 [Block size],
page 3). The blocks computed counts each hard link separately; this is arguably a
deficiency.
*******
With so many systems around, running a copy of "ls", you can modify your
code until it matches the output of the system provided copy of "ls".
For example, on my Windows computer here, I run virtual machine software
(you can get VirtualBox for free), and you can run a Linux distribution
in there, to observe the "ls" command in action. Or, the Coreutils
package above, will allow you to run a port of "ls" in Windows.
"The block size currently defaults to 1024 bytes" tells you how the
block size in a directory is derived.
HTH,
Paul