
The disk space should be used to allocate disk data structures of the file system as well the files. Let your CCdisk have N disk sectors with each sector having a size of M bytes. Therefore, the data you store in the CCdisk is persistent across program invocations. The CCdisk is implemented as a file on the actual file system. You can randomly access any given sector for reading or writing. This CCdisk can be considered as an array of sectors (blocks of fixed size). The disk emulator given to you provides a constant-cost disk (CCdisk). The sfs_read() function returns the number of bytes actually read from the disk. Int sfs_read(int fileID, char *buf, int length) The test program expects the following return values for the functions of the SFS API. This information is necessary to access the file. Also, the disk data structures indicate where a file is allocated.

This in effect increases the size of the file by “length” bytes.Ī file system is somewhat different from other components because it maintains data structures in memory as well as disk! The disk data structures are important to manage the space in disk and allocate and de-allocate the disk space in an intelligent manner. The sfs_write() - writes length bytes of buffered data in buf onto the open file, starting from the current file pointer. The sfs_close() - closes a file, i.e., removes the entry from the open file descriptor table. If file does not exist, create the new file and set size to 0. The sfs_open() - opens a file and returns the index on the file descriptor table. The sfs_ls() - will list the contents of the directory in details, i.e., including the information stored in the file control blocks. This persistence is IMPORTANT so that reusing existing data or creating a new file sytem is possible. If flag is false, the file system is opened from the disk (i.e., assumes that a valid file system is already there in the filesystem.

The mksfs() has a fresh flag to signal that the file system should be created from scratch.

The mksfs() - will format the virtual disk for your own file system, i.e., create necessary disk resident data structures and initialize them. All the files will be in a single root directory. No need not implement support for hierarchy of directories. The file system should be as simple as possible. Int sfs_read(int fileID, char *buf, int length) // read characters from disk into buf Int sfs_write(int fileID, char *buf, int length) // write buf characters into disk Int sfs_close(int fileID) // closes the given file Int sfs_open(char *name) // opens the given file Void sfs_ls() // lists files in the root directory Void mksfs(int fresh) // creates the file system
