CITS2002 Systems Programming | |
|
Project 2 2019 - a single instance file-systemModern operating systems support programs to archive the contents of file-systems. These programs typically support their own specific file-formats (examples include the tar and zip formats), or store a whole file-system image inside a single file on your operating system (examples include the ISO and Apple's dmg disk-image formats). Whereas the zip archive format attempts to reduce its space requirements by compressing its contents, an alternate approach termed single-instance storage attempts to reduce space requirements by identifying multiple copies of the same content, and replacing it by a single shared copy. Thus, if multiple copies of the same file are archived, possibly from different directories, then only a single instance of the files' content will appear in the archive. Storing files' contents only once, can also reduce internal-fragmentation.
The Single Instance File System (SIFS) volume formatOur SIFS volumes are of a fixed size - once created they can neither grow nor shrink. Similarly, files on a volume are immutable - once a file has been added to a volume it can neither grow nor shrink, though it may be deleted. Volumes consist of three sections, whose concrete implementation is defined in the provided C99 header file sifs-internal.h :
The SIFS Application Programming Interface (API)User-level programs do not directly interact with the contents of a SIFS volume. Instead, they call functions from your SIFS library to make and initialise new volumes; make or remove directories; list the contents of directories; and add, read, or remove files from directories. Without exposing the concrete implementation of the file-system, the library provides an Application Programming Interface (API) to the file-system. Although the functions in your SIFS library execute in the same address space as your own programs, you can consider the functions as if they are new system-calls provided to support a new type of file-system on an existing operating system. Many of the library's functions need to perform the same actions, such as opening a volume, and so additional ''hidden'' functions within the library will be necessary. The prototypes of the required library functions, declared in the provided C99 header file sifs.h, are:// make a new volume int SIFS_mkvolume(const char *volumename, size_t blocksize, uint32_t nblocks); // make a new directory within an existing volume int SIFS_mkdir(const char *volumename, const char *pathname); // remove an existing directory from an existing volume int SIFS_rmdir(const char *volumename, const char *pathname); // add a copy of a new file to an existing volume int SIFS_writefile(const char *volumename, const char *pathname, void *data, size_t nbytes); // read the contents of an existing file from an existing volume int SIFS_readfile(const char *volumename, const char *pathname, void **data, size_t *nbytes); // remove an existing file from an existing volume int SIFS_rmfile(const char *volumename, const char *pathname); // get information about a requested directory int SIFS_dirinfo(const char *volumename, const char *pathname, char ***entrynames, uint32_t *nentries, time_t *modtime); // get information about a requested file int SIFS_fileinfo(const char *volumename, const char *pathname, size_t *length, time_t *modtime);Each of the library's functions returns 0 on success, and 1 on failure. Each failed library call also sets the global integer variable SIFS_errno to describe the cause of the error. All possible values of SIFS_errno are defined in provided C99 header file sifs.h. Examples of useThis project requires a library of functions, named libsifs.a , to be developed. The library does not contain a main() function and so, by itelf, it is not an executable program. Instead, other programs requiring access to a SIFS volume and its contents will be linked with the libsifs.a library and, when executed, will call the SIFS API functions and check their return value(s). For example, imagine we have a simple program, named sifs_put to copy a file from the current directory to a SIFS volume. We could compile and link such a program with:prompt> cc -std=c99 -Wall -Werror -pedantic -o sifs_put sifs_put.c -lsifs -lm and then execute the program with:prompt> ./sifs_put myvolumename myfilename where the program's argument myvolumename provides the name of the SIFS volume (a large single file holding the archive) and myfilename provides the name of the (local) file to be stored on the volume. As a convenience, the sifs_put program could obtain the desired SIFS volume name from an environment variable, and then not require it on the command-line:prompt> export SIFS_VOLUME=/Users/chris/sifs-1 prompt> ./sifs_put myfilename Remembering that, once created, a SIFS volume has a fixed size, and that its role is to store only a single copy of duplicate file content, then the following commands will store two (identical) files but not require any additional space:prompt> ./sifs_put myfilename prompt> cp myfilename myfilename-today prompt> ./sifs_put myfilename-today Notes
Good luck! Chris McDonald. |