CISC361-010 Homework 4

Assigned: May 4, 2009, Due: May 18, 2009

  1. (35 pts) Write an ls program
    This program should act similar to what 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/initpipe
    
    
    The 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.
    *For device files (char and block) you should do the same as 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.

    Test Runs

    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/write
    
    The TA will do additional tests as well. Upload your code to Sakai as a tar file as done with the projects.

  2. (5 pts) A RAID can fail if two or more of its drives crash within a short time interval (RAID5). Suppose that the probability of one drive crashing in a given hour is p. What is the probability of a k-drive RAID failing in a given hour.

  3. (15 pts) Disk requests come in to the disk driver for cylinders 10, 22, 20, 2, 40, 6 and 38 in that order. A seek takes 6 msec per cylinder moved. How much seek time is needed for
    (a) First-come, first served.
    (b) Closest cylinder next.
    (c) Elevator algoritym (initially moving upward).
    In all cases, the arm is initially at cylinder 20.

  4. (5 pts) Give 5 different path names for the file /etc/passwd.

  5. (10 pts) Some operating systems provide a system call rename to give a file a new name. Explain or give pseudo-code for why this system call is not necessary.

  6. (20 pts, each 4 pts) ZFS questions
    1. Give the ZFS commands that would be used to mirror the disks c1t0d0, c1t1d0 and c1t2d0 to the disks c2t0d0, c2t1d0, and c2t2d0.
    2. Give a demo of how to use zfs snapshots that are done on your acad home directory to recover a deleted file. (do not show how to create a snapshot, use the ones that exist!)
    3. Do some research (web search) and explain what the RAID-5 write hole problem is. Explain how RAID-Z solves this.
    4. Explain what scrub means in ZFS.
    5. Explain how ACLs work in ZFS. Include what standard they follow. Include commands that would be used to give user bobby permission to write to a file and deny user johnny from viewing a file.

  7. (10 pts) Find and explain the code that implements not writing out a block of zeroes when using compression in ZFS. The code can be found at http://cvs.opensolaris.org/source/.