The goal of this exercise is to design and implement an User-level File System similar to file systems discussed in class (e.g. FAT and UNIX), but relying on a virtual disk instead of a real I/O subsystem.
The virtual disk upon which the user-level file system will be implemented is a standard file on the hosting operating system. The file will be 100 MB in size and will be accessed in chunks (i.e. logical blocks) of 1 KB through the following interface:
int read(int n, void * buf)
n
(first block = 0) from
the virtual disk into the buffer pointed by
buf
. The function returns "0" on success and "-1"
on error.
int write(int n, void * buf)
buf
into the
n
-th block (first block = 0) of the virtual
disk. The function returns "0" on success and "-1" on error.
The User-level File System must implement, at least, the following interface:
int open(const char * pathname, int flags)
pathname
or create
it case it does not exist. Files can be open in tree modes
according to flags
:
O_RDONLY
: read-only;O_WRONLY
: write-only;O_RDWR
: read/write.int close(int fd)
fd
. In case of
success, this function returns "0", otherwise, "-1".
int read(int fd, void * buf, int count)
count
bytes from the file
designated by fd
into the buffer starting at
buf
. On success, the number of bytes read is
returned (zero indicates end of file), and the file position
is advanced by this number. On error, "-1" is returned.
int write(int fd, const void * buf, int count)
count
bytes to the file referenced
by the file descriptor fd
from the buffer
starting at buf
. On success, the number of bytes
written are returned (zero indicates nothing was written). On
error, "-1" is returned.
int stat(const char * pathname, struct stat * buf)
pathname
and returns it as a stat
structure in buf
. In case of success, this
function returns "0", otherwise, "-1".
int mkdir(const char * pathname)
pathname
.
In case of success, this function returns "0", otherwise,
"-1".
int rmdir(const char * pathname)
pathname
. In case of success, this function
returns "0", otherwise, "-1".