Assignment 6, due Mar. 12

Part of the homework for 22C:112, Spring 2010
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated (usually a Friday). The only exceptions to this rule will be by advance arrangement unless there is what insurance companies call "an act of God" - something outside your control. Homework must be turned in on paper and in class! Late work may be turned in to the teaching assistant's mailbox, but see the late work policy. Never push late work under someone's door!

  1. Background: Read the Unix manual pages on the read() and write() system calls (use man 2 write for example, since there is also an irrelevant write shell command in section 1 of the manual.

    Note that, on most Unix systems, the disk sector size is always 512 bytes. In 1970's, some disk vendors sold drives with unusual sector sizes such as 100 bytes. The economics of modern disk drives is such that, if software compatibility were not an issue, we might do better with larger sectors such as 4K bytes.

    a) What is the basic function of the software layer between the read() and write() interface within the operating system and the layer inside the disk driver that actually enqueues disk I/O requests? (0.5 points)

    b) The design of this layer could place it inside the I/O driver, or outside, common to all disk drivers. Explain the impact of the uniformity or non-uniformity of disk sector size on this decision. (0.5 points)

    c) Explain how this layer could also serve as a disk cache. (0.5 points)

  2. Background: Read the Unix manual pages on the lseek() and fseek() commands.

    a) One of these is a system call. Which one. Explain how it relates to your answer to part (a) of problem 1. (0.5 points)

    b) One of these is a part of the middleware in the C standard library. Explain how it relates to the system call. (0.5 points)

  3. Background: When the C programming language was ported to some non-Unix systems -- or rather, to systems having non-Unix file systems, the value returned by the seek routine in the C standard library was changed from an integer byte offset in the file to a magic cookie. This was the first widespread use of the term cookie in the context of computing. When someone invented the web browser cookie, they named it after this older usage.

    A Problem: Explain how a file system that maintains sequential files as linked lists of disk sectors (or some similar organization) would force the seek routine to return a cookie instead of an integer offset. Suggest what you would encode in the cookie if you were writing the library routine. (0.5 points)

Machine Problem 2, due Mar. 25

Modify the example shell from MP1 so that, if the shell input comes from a file, it supports the following new built-in shell command:

loop n
# any number of shell commands
Here, n is an integer (you can use atoi() to convert strings to integers), and the effect is to execute the shell commands between the loop and the endloop commands that number of times. There are at least two ways to do the iteration, one involving creating a temporary file holding the loop body and then repeatedly launching the shell to read that temporary file, and the other involving using either lseek() or fseek() to remember the position in the standard input file at the start of the loop and return to it for each new iteration (use the man command to get documentation).

Your loop implementation must support nested loops.

If run from an interactive terminal, the loop command should output an error message.