Homework 12

22C:50 Section 2, Fall 2000

Due Monday Nov 20 2000, in class

Douglas W. Jones

  1. Do problem 1, 2, 7, and 11 from Chapter 13.

Machine Problem 5

Due Monday Dec 4 2000, in class

Write a program to read and print the contents of the file /space/jones/mp5data.

This file is organized as follows:

    ___________ _____     index:
   |___________|_____|    a sequence of 6 byte records
   |___________|_____|    describing the contents of
   |___________|_____|    the remainder of the file
    _____________________________        the remainder of
   |_________________ ___________|       the file is made
   |_________________|________________   of variable size
   |_____________________ ____________|  data records, as
   |_____________________|____           described by the
   |________________________ _|          index.

Each item in the index is formatted as follows:
    ____ ____ ____ ____ ____ ____
   |msb             lsb|msb   lsb|
   |       start       |  count  |

Each data record in the remainder of the file is described by its starting byte number (32 bits) and a count of the bytes in the item (16 bits). These are stored most significant byte first. The last index entry has a count of zero, indicating the end of the index. No data record in the file is over 256 bytes long.

The data records must be written to standard output in the order of the index entries, with no characters added.

In reading the data file, use the following standard UNIX kernel calls:

   open()  -- to open the file
   lseek() -- to position the file to a particular byte
   read()  -- to read part of the file
For information on these kernel calls, use the man command.