disk.
#define BLOCKSIZE 64 #define NUMBLOCKS 1024The 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.
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.)
public/p4/ to test
your implementation.
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.
disk.h, disk.c
fs.h, fs.c
fsTraverse.c
fs.tar and use bundleP4
to submit it before 11:59 PM on Jun 02, 2000.
There is no report for this assignment.