Lab 7: File Systems
Due: 2004
Web posted: Monday April 06, 2004
File Systems
The goal of this lab is to write a simple UNIX-like file system.
The file system you will write make the following simplifying assumptions:
- The file system resides on a disk that is 128KB in size.
- There is only one root directory. No subdirectories are allowed.
- The file system supports a maximum of 16 files.
- The maximum size of a file is 8 blocks; each block is 1KB in size.
- Each file has a unique name, the file name can be no longer than
8 characters.
The layout of your 128 KB disk is as follows
- The first 1KB block is called the super block. It stores
the free block list and index nodes (inode) for each file.
- The remaining 127 1KB blocks store data blocks of the files
on your file system.
- The exact structure of the super block is as follows.
- The first 128 bytes stores the free block list. Each entry in
this list indicates whether the corresponding block is free or
in use (if the i-th byte is 0, it indicates that the block
is free, else it is in use). Initially all blocks except the super
block are free.
- Immediately following the free block list are the 16 index nodes, one for
each file that is allowed in the file system. Initially, all
inode are free. Each inode stores the following information:
char name[8]; //file name
int size; // file size (in number of blocks)
int blockPointers[8]; // direct block pointers
int used; // 0 => inode is free; 1 => in use
Note that each inode is 48 bytes in size; Since you have 16 of these,
the total size of occupied by the inodes is 768 bytes. The free/used
block information (mentioned above) is 128 byes. So the total space
used in the super block is 896 bytes. The remaining bytes are unused.
For more related information, please refer to Lab details.
You need to implement the following operations for your file system.
- create(char name[8], int size): create a new file
with this name and with these many blocks. (We shall assume that
the file size is specified at file creation time and the file
does not grow or shrink from this point on)
- delete(char name[8]): delete the file with this name
- read(char name[8], int blockNum, char buf[1024]): read
the specified block from this file into the specified buffer; blockNum
can range from 0 to 7.
- write(char name[8], int blockNum, char buf[1024]): write
the data in the buffer to the specified block in this file.
- ls(void): list the names of all files in the file system
and their sizes.
Background
An example to mount BFS file system
To enable bfs filesystem in UML, you should create a
second ubd block device and mount it under UML. For example,
the following steps tell you how to mount a bfs filesystem.
- If you have not compiled bfs before, select bfs using make
menuconfig, then recompile UML kernel
- Before you start UML, go the directory where you put
root_fs
- Make a 4M image: dd if=/dev/zero of=bfs_fs count=4 bs=1M
- Go to your source directory and start UML: ./linux
ubd0=../root_fs ubd1=../bfs_fs
- Inside UML, create a new bfs filesystem on the 2nd block
device: mkfs.bfs /dev/ubd/1
- Create a mount point: mkdir /fs
- Mount your bfs filesystem: mount -t bfs /dev/ubd/1
/fs
Other very useful informations :
Submitting Your Assignment
Please submit the following items to lab7 dir on elgate:
- All source codes/files that you have added/modified and the demonstrative results;
- A "README" file that contains the follows :
- Design, for instance, how did you build your file system and make it be recognized by the kernel;
- How did you demonstrate that the file system works;
- Suggestions/lessons and useful materials you found;
- List of all your files you submitted.
- Compiled kernel image with the new changes. Also please notify us which root filesystem you have been using for all labs.
Thank you and have fun!