CSCI 4320 (Principles of Operating Systems), Fall 2003:
Homework 6

Assigned:
November 19, 2003.

Due:
November 25, 2003, at 5pm. Not accepted past midnight November 25.

Credit:
20 points.

Be sure you have read chapter 6.

Problems

Do the following problems. You may write out your answers by hand or using a word processor or other program, but please submit hard copy, either in class or in my mailbox in the department office.

  1. (5 points) Consider a simple operating system that provides only a single-level directory, but allows the directory to contain as many files as desired, with file names as long as desired. Would it be possible to use this system to simulate something resembling a hierarchical file system? How?

  2. (5 points) Consider a digital camera that records photographs in some non-volatile storage medium (e.g., flash memory). Photographs are recorded in sequence until the medium is full; at that point, the photographs are transferred to a hard disk and the camera's storage is cleared. If you were implementing a file system for the camera's storage, what strategy would you use for file allocation (contiguous, linked-list, etc.) and why?

  3. (5 points) The textbook describes two strategies for keeping track of free blocks in a file system, one using a list of free blocks and one using a bitmap. What would happen if this free list or bitmap was completely lost because of a system crash -- is there a way to recover, or must you hope you have a backup of any critical data? Answer separately for UNIX V7 and MS-DOS FAT-16 filesystems. (Hint: Read the last paragraph of section 6.4.3 carefully.)

  4. (5 points) Consider a UNIX filesystem (as described in section 6.4.5) in which each i-node contains 10 direct entries, one single-direct entry, one double-indirect entry, and one triple-indirect entry. If a block is 1KB (1024 bytes) and a disk addresses is 4 bytes, what is the maximum file size, in KB? (Hint: Use the blocksize and size of disk addresses to determine how many entries each indirect block contain.)

Optional Programming Problem

For extra credit, do the following programming problem. Turn in your code (all files needed) by sending mail to cs4320@cs.trinity.edu, with each of your code files as an attachment. Please use a subject line such as ``homework 6'' or ``hw6''. You can develop your program on any system that provides the needed functionality, but I will test it on one of the department's RedHat 9 Linux machines, so you should probably make sure it works in that environment before turning it in.

  1. (Up to 5 extra-credit points) Write a program that given a directory $ D$, blocksize $ B$, and maximum number of blocks $ M$ as command-line arguments prints out how many files in $ D$ and its subdirectories are of size $ B$ or less, how many are of size between $ B$ and $ 2B$, etc., up to size $ M B$. Include directories and symbolic links (but count the size of the link and not the file/directory it links to). Here is a sample execution:
    [bmassing@Janus01]$ ./filesizes /var/www 512 20
    Unable to open /var/www/HTML-Documents/About/The_Courses/cs3291.java/dcernose/javapres/turnin/COM:  Permission denied
    Unable to open /var/www/HTML-Documents/About/The_Courses/cs3394.hci/dcernose/javapres/turnin/COM:  Permission denied
    Unable to open /var/www/HTML-Documents/apache-documentation/manual/search:  Permission denied
    Results for directory /var/www:
                    2046 files of size          1 blocks
                     461 files of size          2 blocks
                     963 files of size          3 blocks
                    1191 files of size          4 blocks
                    7201 files of size          5 blocks
                    9807 files of size          6 blocks
                    5803 files of size          7 blocks
                    3604 files of size          8 blocks
                    1763 files of size          9 blocks
                     994 files of size         10 blocks
                    1597 files of size         11 blocks
                     697 files of size         12 blocks
                     423 files of size         13 blocks
                     633 files of size         14 blocks
                     493 files of size         15 blocks
                     514 files of size         16 blocks
                     431 files of size         17 blocks
                     298 files of size         18 blocks
                     297 files of size         19 blocks
                     261 files of size         20 blocks
                    6136 files of size         21 blocks or more
    
    (Of course, you won't be able to examine files in directories you don't have access to. That's okay; just print error messages as above.)

    Hints: Read the man pages for opendir, readdir, and lstat. You might also be interested in the man pages for chdir and strerror.



Berna Massingill
2003-11-19