File System

The file manager is usually the largest part of an OS but usually not the most complex. In this assignment you'll be implementing a simple file system and exploring the UNIX system calls relating to file system.

File system implementation

File systems are implemented on disks. We can abstract the disk operation by the following API. All the disk operations are performed on the file disk.
#define BLOCKSIZE 64
#define NUMBLOCKS 1024
The disk is abstracted as a sequence of blocks. The blocks are numbered 0, 1, 2, ..., NUMBLOCKS-1. Each block is identified by its number.
int diskInit(void);
/* perform initialization on the disk if required. This returns 1 if the file
"disk" exists. Returns 0 otherwise. */

int diskRead(int addr, char *buf);
/* reads the block "addr" into "buf". "buf" should be at least BLOCKSIZE
bytes in size. Returns 1 on success, 0 on failure */

int diskWrite(int addr, char *buf);
/* writes BLOCKSIZE bytes from "buf" to the disk block "addr". Returns 1 on
success, 0 on failure */
The complete file system is stored in the file disk. You can use the system calls open, lseek, read, write, etc. for implementing the above API.

Using this disk API, implement the following file system API.

void fileSystemInit(void);
/* initialize the file system data structures. If file "disk" exists,
initialize the file system using its contents. Otherwise, start a fresh file
system. */

int fileRead(char *fName, char *buf, int n);

/* read the contents of the file "fName" into "buf". Read either the complete
file contents or "n" bytes, whichever is smaller. On success, return the
number of bytes read. Return -1 on failure (file does not exist, etc.) */

int fileWrite(char *fName, char *buf, int n);

/* write "n" bytes of "buf" into the disk. The name of the file written
is "fName". If the file does not exist, it is created. If it exists, it is
overwritten. Return 1 on success. Return -1 on failure (no disk space, etc.). */

int mkDir(char *dName);

/* create a directory with name "dName". Return 1 on success, 0 on failure */

void ls(void);

/* List the contents of the directory in the following format
     fileName fileSize
     dirName  DIR
*/
Please note.
  1. This file system has only one directory. Your program should create subdirectories, but cd operation, creating files in subdirectories, etc. need not implemented. (A minimal implementation keeps an attribute with each directory entry. For directories, a bit is set in the attributes, for example.)
  2. The file system should be persistent. After one program write a file and terminates, another program should be able to read it.
You can assume that
  1. The maximum size of file names is 10 characters.
  2. The maximum file size is 1K.
  3. The maximum number of files and directories is 100.
You can use the driver programs in public/p4/ to test your implementation.

UNIX system calls

The above implementation is minimal. A full implementation should support more operations. As an example, we'll consider UNIX system calls.

You should write a program fsTraverse.c which traverses the file system starting from the directory supplied. For each directory it lists the files present, their type, and their size. It also prints the total number of bytes used by the files and directories (except . and ..) in the directory. It finally prints the grand total of the sizes.

A sample executable can be found in public/p4/. Test your program on ., .., /dev, /devices, etc..

You'll be using UNIX system calls for this program. A sample program which uses some of these calls to list the contents of one directory is also available in public/code.

Submission

The names of your files should be
disk.h, disk.c
disk API implementation
fs.h, fs.c
file system API implementation
fsTraverse.c
file system traversal program
Tar all your source files to fs.tar and use bundleP4 to submit it before 11:59 PM on Jun 02, 2000.

There is no report for this assignment.