What you have to do
You have to implement a very simple disk operating system called TinyDOS which provides the ability to store and retrieve data on a virtual drive and allows inspection of that data using cat or similar commands at any time during the execution of a program which uses the virtual drive.
The TinyDOS system creates files with full pathnames such as /dir1/dir2/file3 . The slashes represent separation into directories. The root directory is / . Each part of the pathname will be no more than 8 characters long.
There are classes you have to implement in order to get your file system working: a volume class is essential, but you probably want to have a directory entry class and possibly others. You also must write a TinyDOS program which the markers will use to pass commands to your implementation.
Drive
The virtual drive is represented by an ordinary file on your computer. The Python code to implement the virtual drive is provided in the drive.py file (see later in the handout if you wish to use a different language). You make a drive by creating a Drive object and calling the format method. This creates the file on the real machine which represents your virtual drive. All of the data on the virtual disk should be stored as readable ASCII so that by opening the real machine file you can easily see the contents of your virtual drive.
The write_block method of the Drive class writes directly to the underlying real file. Similarly the read_block method reads from the real file. Your file system must do all of its work by writing entire blocks to the drive and reading blocks from the drive using only these functions. This is how drives work, they are block addressable devices. In this request a block is always 512 bytes long.
Every virtual drive contains 128 blocks (from 0 to 127).
If you run the following program which creates a drive file and then displays it using cat , you will see the structure of a virtual drive.
1 | import drive |
Initially each block is filled in with 512 spaces. These blocks are separated by a line like:1
** 1 **
where the number is the block number of the block directly above the separator.
Volume
A drive is represented to the operating system as a volume. Formatting a volume means putting extra information on the drive so that it can be recognised and used by the TinyDOS operating system. This is a second format. The drive format is like that performed by a drive manufacturer before shipping a drive. A volume format is like the format you can perform using your operating system.
The only access a volume has to a drive is through the methods in the Drive class.
A volume format should write the following information into block 0 of the drive. Block 0 is the volume info block.
The first 128 bytes of the block represent the bitmap of available blocks on the drive. If a block is free it is represented with the byte corresponding to ‘ - ‘. If the block is used it is ‘ + ‘.
The remaining 384 bytes of block 0 consist of 6 directory entries.
Using a Volume
A s you use a volume to create files you need to make modifications to the volume (which makes modifications to the drive).
To create a file you need to find an empty directory entry in the directory you are creating the file in. All directories except the root directory can grow as needed.
At first this is all a file consists of - a directory entry. When the file gets written to it must be allocated a block for data. Each block is taken from the free blocks indicated in the volume bitmap. The block number is inserted into its correct position in the 12 block numbers of the directory entry. The length of the file also needs to be updated in the directory entry and the block containing the directory entry needs to be written back to the drive, along with any other blocks which have been modified.
Directory
A directory (apart from the one in the volume info block) is just an ordinary file with a file type of “ d: “. Like ordinary files they have a maximum number of 12 blocks of data. Each block allocated to a directory consists of 8 directory entries. When a new block is allocated to a directory you can fill in all the 8 directory entries in that block (initially each should be the same as the default directory entries in the volume info block).
A File
When a file is created it has a size of zero. As data is appended to the file, blocks are allocated to the file and the file length goes up. Writing to a file normally requires reading a block, modifying the contents of the block and writing the updated block back to the drive. It also requires modifying the directory entry for the file and writing that to the drive as well.
To test
In order to test your TinyDOS implementation you need to provide a program which takes commands from stdin (usually the keyboard) and interprets them. You should call this program TinyDOS (e.g. TinyDOS.py , or TinyDOS.java etc.) and give the marker instructions on how to start it (because you might have written it in a variety of languages) in Question 1.
The TinyDOS program quits.
All commands in a command file will be legal. However you should write your program in such a way that all incorrect situations cause an error to be reported to the user, either by printing a message on the screen or by throwing or raising an exception. These exceptions are allowed to terminate the program.
The marker will have a second terminal open when testing your program. In this terminal he/she will be able to call commands such as cat to display the contents of the file which contains your drive information. This way the marker should see the effects of the commands modifying the underlying file. The reason for this is that it is possible to perform many of the commands in memory without using read_block or write_block and the request is to get you to implement a file system only with read_block and write_block.