Lab Assignment 3 - File System

Objectives:

The objective of this assignment is to understand the workings of a simple file system.

Assignment:

This laboratory assignment consist of multiple programming assignments defined by tasks. Each task adds more functionality to your file system manager. You should submit only one program with all tasks completed. When you have not completed all tasks, you can still submit your code and earn partial credit. You need to write a report of two pages about your implementation.

Project team:

You are allowed to work on this assignment in a team of at most two students.

Submission of source code and report:

Submit the source codes of the programming assignments to the TA. Use zip or tar formats. Include your name and last four digits of your SSN in all source codes.

Requirements:

You need to be able to write, compile, and debug C++ programs, be familiar with data structures such as linked lists, and STL maps, and have a basic undestanding of file systems as discussed in the textbook Chapters 10 and 11.

Use the man command to access the manual pages. If you cannot access the man pages, add this line to your .tcshrc file and then logoff/logon:

setenv MANPATH /usr/man:/usr/share/man:/usr/local/man:/usr/local/share/man

The examples shown in this document are in C++. However, you also need to get familiar with some C library functions for I/O operations:

You should consult the manual pages to understand these library functions.

Task 1 - Building a Working File System Infrastructure

Download the source code for this project from http://www.cs.fsu.edu/~engelen/courses/pr3.zip. The sources are documented with Doxygen: visit the Project 3 code documentation page.

There are eight types of objects in the file system (see also here):

  1. FS: the file system object that provides the API. It also maintains an open file table.
  2. Volume: associates a volume name with a disk.
  3. Disk: an abstract disk object inherited by RAMDisk and VDisk.
  4. FAT: allocates and manages blocks of a disk object.
  5. Directory: a helper object that copies the directory structure from disk to memory.
  6. FCB: contains file attributes.
  7. FileName: file name restricted to 16 characters (or MAX_FILE_NAME).
  8. OpenFile: used by FS to maintain information about an open file.

The relationships between these objects are illustrated here and here.

Compile the demo program using 'make', then run 'fsdemo' to run a demo of the incomplete file system. You will notice that the program reports a number of 'TODO' items.

For this first task you must complete the file system implementation. Running the 'fsdemo' program should not report any 'TODO' items.

The 'fsdemo' program tests the basic functionality of the file system. You may want to add some of your own tests to verify your implementation (we will also apply a few more tests to check your implementation).

Note that 'fsdemo' generates some debugging messages. You can turn them off and also disable the assertions by modifying the Makefile to enable CFLAGS=-DNDEBUG.

Task 2 - An Interactive Shell for your FS

For this task we will use the shell developed in Project 1 to create an interactive system for file manipulation with your file system.

When your shell starts, it should set up a RAM disk with 100 blocks (each 512 bytes) and a VDisk with 100 blocks (each 1024 bytes). The volume names are "A" and "B", respectively.

The volume names are used to identify RAM disk and VDisk files from local files on the UNIX/Linux file system. For example "A:/" is the root dir of the RAM disk, "B:/foo" is a foo file (or dir) on the VDisk, and "bar/abc" is a local file "abc" in the "bar" dir.

The shell should implement the following commands:

ls volume:path
List the content of volume:path.
rm volume:path/name
Remove a file.
mkdir volume:path/name
Make a directory.
rmdir volume:path/name
Remove a directory.
cp volume:path/name volume:path/name
Copy a file. This command should take care of four different cases to copy local files from/to your FS. Local files are identified by the absence of a volume.
append volume:path/name volume:path/name
Append content of the first file to the second file. Similar to cp, there are four cases to consider.

Note that these commands should also work on regular files (i.e. local files identified by the absence of a volume). To this end, use fork() and execvp() to execute a system command. Be careful not to remove any critical source code files when you test the 'rm' command!

Here is an example:

1> ls A:
Volume A:/ (100 blocks, 98 free)
Name                Size  Type  Created
2> mkdir A:/foo
3> ls A:
Volume A:/ (100 blocks, 96 free)
Name                Size  Type  Created
foo                    0   dir  Tue Mar 21 11:39:28 2006
4> rmdir A:/foo
5> rm A:abc
abc: no such file.
6> cp demo1.txt A:demo.txt
7> append demo2.txt A:demo.txt
8> cp A:demo.txt demo.txt
9> rm A:demo.txt

The file 'demo.txt' in your local directory should now have the content of 'demo1.txt' and 'demo2.txt', assuming you created these before you started the shell.

Task 3 - Bonus: Current Working Directory

You can earn extra credit (5%) for this assignment by implementing a current working directory pointer for each volume and additional commands to set and print the current working directory of a volume:

cd volume:path
Change to a new current working directory for a volume.
pwd volume:
Print the current working directory for a volume.

Here is an example:

1> cd A:/foo
2> pwd A:
/foo
3> pwd B:
/
3> cp A:bar B:bar

This copies A:/foo/bar to B:/bar.

- End -