ls -Llan
does
with slightly different output.
You will need to use the stat(2)
system call, and the
opendir(3C)
and readdir(3C)
C library functions.
The output should be like the following (program name here is ls-X):
% ls-X /bin/ls /kernel -r-xr-xr-x(555) 1 0 2 18120 Oct 6 3:43:05 2007 /bin/ls /kernel: drwxr-xr-x(755) 9 0 3 512 Sep 2 7:29:41 2006 /kernel/. drwxr-xr-x(755) 27 0 0 1024 Jan 26 6:15:00 2008 /kernel/.. drwxr-xr-x(755) 3 0 3 2048 Jan 13 8:08:08 2007 /kernel/drv drwxr-xr-x(755) 3 0 3 512 Sep 2 7:29:39 2006 /kernel/exec drwxr-xr-x(755) 3 0 3 512 Dec 7 14:16:32 2006 /kernel/fs drwxr-xr-x(755) 4 0 3 1024 Sep 2 7:29:41 2006 /kernel/misc drwxr-xr-x(755) 3 0 3 512 Feb 17 8:41:30 2006 /kernel/sched drwxr-xr-x(755) 3 0 3 512 Feb 17 8:46:28 2006 /kernel/strmod drwxr-xr-x(755) 3 0 3 512 Sep 2 7:29:45 2006 /kernel/sys -rwxr-xr-x(755) 1 0 0 1223264 Sep 2 7:29:41 2006 /kernel/genunix % ls-X /bin/su -r-s--x--x(4511) 1 0 3 17976 Oct 6 3:46:04 2007 /bin/su % ls-X /dev/null /dev/rdsk/c0t0d0s0 /dev/dsk/c0t0d0s2 /etc/.syslog_door /etc/initpipe crw-rw-rw-(666) 1 0 3 13, 2 Jan 26 15:32:53 2008 /dev/null crw-r-----(640) 1 0 21 32, 0 May 11 16:12:43 2006 /dev/rdsk/c0t0d0s0 brw-r-----(640) 1 0 21 32, 2 Sep 3 8:52:55 2005 /dev/dsk/c0t0d0s2 Drw-r--r--(644) 1 0 0 0 Feb 17 9:08:30 2006 /etc/.syslog_door prw-------(600) 1 0 0 0 Nov 24 18:55:24 2007 /etc/initpipeThe beginning is the same as
ls -l
, that is the file type
(hint: use the `S_IS*' macros found in
/usr/include/sys/stat.h
with the file permission bits) and
sticky bits). Following that you should
have the permission bits in octal in parens (use a bitwise and with proper
mask), then the number of links,
numeric uid, numeric gid, size (for non-device files)*, date (Note the
format above, use cftime()
), then the file name. For
directories you will need to read the filenames contained in it and
have a line for each file. You should support all the filetypes correctly.
ls
-lL
does, which is printout the major and minor device numbers
in the size field of the stat
struct. You do this by
passing the st_rdev
field to the major()
and
minor()
macros. Read the makedev(3C)
man
page for header files to include to get these macros.
Also add a -a option to ls-X which will print out the username and groupname for the owner of files neatly instead of the numeric uid and gid.
Do the following test runs (or equivalent, for example, if the exact device doesn't exist on the system you are testing on replace with another one that does exist) in the given order:
ls-X ls -Llan ls-X -a ls -Lla ls-X . .. ls -Llan . .. ls-X -a . .. ls -Lla . .. ls-X /bin/ls /kernel ls -Lln /bin/ls /kernel ls-X -a /bin/ls /kernel ls -Ll /bin/ls /kernel ls-X /dev/null /dev/rdsk/c1d0s0 /dev/dsk/c1d0s2 ; char and block files ls -Lln /dev/null /dev/rdsk/c1d0s0 /dev/dsk/c1d0s2 ls-X -a /dev/null /dev/rdsk/c1d0s0 /dev/dsk/c1d0s2 ls -Ll /dev/null /dev/rdsk/c1d0s0 /dev/dsk/c1d0s2 ls-X /etc/.syslog_door /etc/initpipe ; a door and a pipe ls -Llan /etc/.syslog_door /etc/initpipe ls-X -a /etc/.syslog_door /etc/initpipe ls -Ll /etc/.syslog_door /etc/initpipe ls-X /bin/su ; suid bit correct ls -Llan /bin/su ls-X -a /bin/su ls -Ll /bin/su ls-X /bin/write ; sgid bit correct ls -Lln /bin/write ls-X -a /bin/write ls -Ll /bin/writeThe TA will do additional tests as well. Upload your code to Sakai as a tar file as done with the projects.