|
|
This assignment is about a file system. I have provided a file vdev.c which imitates a simple block device. You have to design and implement a file system (the simpler the better) which provides the layer between this virtual device and a user level program. You should test your file system with a couple of test programs testvfs.c and testvfs2.c.
The header file vfs.h needs to be included by any program which is to use your file system. This file has the interfaces for all of the routines which your file system provides.
(You will be able to find all relevent files, including a makefile, via my home page: http://www.cs.auckland.ac.nz/~robert-s/)
Write a file vfs.c which provides all the services necessary to enable the test files and similar files* to produce output like that below. The only access your program is allowed to have to the virtual device is via the routines you can access by including vdev.h. All of your file system routines must carefully check for errors so that the output from the test programs is similar to that given. You may provide different error messages if you want to, however each error message should be specific and appropriate.
There is a special routine called vfs_display which must show what the blocks on the device are being used for by your file system. That is what the funny lines with s's, f's, a's and -'s mean. An s means the block is used by the system. An f means the block is used for file data. An a means the block holds file attribute information (you determine what the attributes are). And a - means the block is free. I do not expect your file system to use the device in exactly the same way as in the example output. Please do not waste any time trying to work out how the example file system was structured.
(produced by linking testvfs.c and testvfs2.c with my vfs.c and vdev.c)
Script started on Sun Aug 4 19:09:08 1996
[robert@mars Ass2]$ ./testvfs
Welcome to the virtual file system tester program.
|s---------------------------------------------------------------|
ERROR - Bad file name: Creating empty file name
ERROR - File already exists: Creating "First file" the second time
|s--------------------------------------------------------------a|
ERROR - File already open: Opening "First file" the second time
|s-------------------------------------------------------------aa|
ERROR - File not open for writing: Writing to "Second file" before opening
|s------------------------------------------------------------faa|
ERROR - No room left on the file system: Writing oversized buffer
|s------------------------------------------------------------faa|
|sf-----------------------------------------------------------faa|
|sff----------------------------------------------------------faa|
|sffa---------------------------------------------------------faa|
ERROR - No room left on the file system: Writing lots to file3
|sffaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa|
ERROR - File not open for writing: Adding another character to "Second file"
ERROR - File not open: Closing "Second file" again
[robert@mars Ass2]$ ./testvfs2
Welcome to the second virtual file system tester program.
|sffaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa|
ERROR - File not open for reading: Reading from "First file" before opening
Hello
ERROR - Not enough data: Reading oversized buffer
A line of exactly 64 characters, --- four of these fills a blockA line of exactly 64 characters, --- four of these fills a blockA line of exactly 64 characters, --- four of these fills a blockA line of exactly 64 characters, --- four of these fills a blockx
[robert@mars Ass2]$ exit
Script done on Sun Aug 4
19:09:26 1996
Organise the system blocks any way you like. The system blocks must hold enough information to make the virtual file system usable. The virtual device is simply a file which is stored on the normal UNIX file system. Enough information must remain stored on the virtual device to enable a test program to restore the file system to the state it was in when the previous test program finished.
This is a list of the functions which your vfs.c file must provide, along with a brief description. All functions return an indication of success (VFSOK) or an error value if unsuccessful (except the two void functions).
int vfs_init()
Resets the file system. If the file system already exists all information is lost.
int vfs_reconnect()
Restores the file system from the information saved in the virtual device.
void vfs_error(const char *message)
Prints the message and an error message corresponding to the most recent error within the file system.
void vfs_display()
Shows the type of contents for each block in the virtual device (as described above).
int vfs_create(char *filename, int filetype)
Creates a file. At the moment the only necessary filetype is ORDINARY.
int vfs_open(char *filename, int access)
Opens the already created file. The access can be READ or WRITE.
int vfs_write(char *filename, char *buffer, int length)
Writes from the buffer to the file the number of bytes specified by the length parameter.
int vfs_read(char *filename, char *buffer, int length)
Reads from the file to the buffer the number of bytes specified by the length parameter.
int vfs_close(char *filename)
Closes the file.
1. What limitations does your file system have? e.g. What size device can it work with without having to be changed?
2. Describe how your system keeps track of free blocks on the device.
3. What is the smallest number of bytes which need to be corrupted on your system in order to lose information about the free space on the system? Explain your answer.
4. What is the smallest number of bytes which need to be corrupted on your system in order to lose a significant part of a file? Explain your answer.
5. What is the smallest number of bytes which need to be corrupted on your system in order to make it completely unusable (no files can be read at all)? Explain your answer.
6. Describe the data stored in your system blocks on the disk.
7. Describe the data stored in the attribute blocks on the disk.
8. Does your system ever completely clear a block (replace with zeros or garbage) on the virtual device? If so, when and why?
Some of the semantics of the given file operations leave a lot to be desired.
9. What is wrong with using the file name in all operations which deal with the file?
10. What other file operations need to be added to make it truly usable?
You are not to change vdev.c, vdev.h or vfs.h at all.
There is not much time to do this assignment. Unless you carefully design your file system before starting to implement it, you will not finish the assignment in time.
Submit your vfs.c file electronically.
Hand in paper versions of the vfs.c file, output from your program with the test files, and answers to the questions
Robert Sheehan