CS 351 File System Exercise


Barney Maccabe Last modified: Tue Oct 5 09:45:53 MDT 1999

Introduction

The goal of this exercise is to expose students to reference counts and to introduce the structures used in file systems.

Due Date: Thursday October 28, 1999 at the start of class

Description

You are to write a file systems that only supports directory files and links (i.e., no data files). For this exercise, directory names must be composed of (upper and lower case) letters (i.e., no punctuation or special characters). Pathnames may also include the special characters "/" and ".".

Commands

Each file system command will be read from standard input and will appear on a single line. Blank lines and lines starting with the "#" should be ignored. Normal output from commands should be written to standard output.

The specific commands that you must support are:

Create

cr pathname
Create a new directory with the path name pathname.

Link

ln oldpath newpath
Create a new link with the path name newpath that links to the directory identified by the path name oldpath.

List

ls pathname
ls
List the contents of pathname or the current directory. The names of subdirectories along with their reference counts (in parentheses) should be listed one per line. For example, the output might look like:
    xxx(4)
    yyy(1)
    zzz(2)
    

Remove

rm pathname
Remove the link with the path name pathname.

Change Directory

cd pathname
Set the current directory to pathname. The current directory is used in relative pathnames and in the ls command.

Pathnames

Pathnames should be interpreted as that are in Unix-like systems. That is, "/" is the directory separator; absolute pathnames start with "/"; "." refers to the current directory; and ".." refers to the parent directory.

Error Checking

You should check for valid command names and valid pathnames. Any errors should be written to standard error.

Approach

You should start by implementing the commands cr, ln, rm, and ls using only absolute pathnames (i.e., pathnames that start with '/') without "." and "..". After you get this part of the code working, add in support for relative pathnames and the cd command. Finally, add in support for "." and "..".