Homework 5

Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted
Points: 100

UNIX System

  1. (10 points) I want to make the file libprog.a in my home directory available to everyone so they can copy it, but I do not want anyone to be able to see any other files in my home directory. How should I set the "other" bits of my directory's protection mask to do this?
  2. (10 points) What command would you use to remove columns from a file??

C Programming

  1. (50 points) Write a program called fileinfo that prints the following information about the files named on the command line:
    • file name
    • device inode number resides on
    • file inode number
    • file type; if symbolic link, name of file the link points to
    • owner (as both login name if known and UID)
    • group (as both group name if known and GID)
    • owner rights (as "read", "write", "execute")
    • group rights (as "read", "write", "execute")
    • world rights (as "read", "write", "execute")
    • other sttributes ("setuid", "setgid", "sticky")
    • size in bytes
    • size in blocks (1 block = 1024 bytes; any leftover bytes counts as 1 block)
    • time of last access (in human-readable form)
    • time of last modification (in human-readable form)
    • time of inode creation (st_ctime; in human-readable form)
    Hint: Look at the manual page for stat(2) to see how to get this information. Use ctime(3) to convert the dates from internal to human-readable form; use readlink(2) to figure out to which file a symbolic link points
  2. (30 points) Consider an array of characters. Let bits 0-7 be the bits of array element 0, bits 8-15 the bits of array element 1, and so forth. The bits for each character are numbered high-to-low, so the character "e" (hexadecimal 65) has bit 7 set to 0, bit 6 set to 1, bit 5 set to 1, bit 4 set to 0, bit 3 set to 0, bit 2 set to 1, bit 1 set to 0, and bit 0 set to 1. Write C preprocessor macros to do the following:
    1. Set the nth bit of char array buf to val:
      SET_BIT(buf, n, val)
    2. Get the value of the nth bit of char array buf:
      GET_BIT(buf, n)

Extra Credit

  1. (10 points) Modify the program you wrote in problem 3 to take an argument, -L. If this argument is given and the file is a smbolic link, print information about the file named by the symbolic link.

ECS 30-A, Introduction to Programming
Spring Quarter 2002
Email: cs30a@cs.ucdavis.edu