FAT File System

 

Project 4 : File System

ECS 150: Project #4 - File System Implementation

Implementation:

  • File system

File system

File system is consist of the functionality of mounting/unmounting, file creation/deletion, file descriptor operations and file write and read. We have data structure for SuperBlock, FAT_Entry, FAT File Descriptor to holding the info. The library operates around the global variables and data structures: superblock, array of fatIdx, array of file entries and array of file descriptors. Since the file header in the file system require specific format, the type of varible is critical. We choose “unsigned” instead of “signed” varible. Also using uint16_t uint32_t uint8_t instead of int to present the specific layout. In order to preserve the layout, we also need _attribute((packed))_ to prevent the compiler changing it during the optimization.

File Mounting/unmounting:

The mounting function effectively initiates the library by creating all the essential global variables that are needed for the other functionalities. It reads the disk block file with the usage of functions in disk.c, namely block_disk_open and block_read. The unmounting function on the other hand reset almost all the global variables to null. Along the way it also finish off modifying the disk block file with the disk.c api.

File creation/deletion

creating file is a process of reserving a file entry for the file that is going to be written. It is more of a modification of the metadata rather then modifying the data itself. The function searches for the first available entry space, reserving it with the name of the file. Then it set the next available entry space as the end of file space. Deletion is a similiar process, it searches for the file name reservation, then clears the entry off the file name and its content.

File read/write

This is the hardest part of this program. The mapping between the memory and disk is critical. We first check if the write/read is needed if it is needed then we keep running this function. We divide the file into block and changing its offset and size during the read/write process accordingly. We memcpy different section of data according to the offset and size and read/write from/into different block when the data is large than the block and update them correspondingly. Then we can keep tracking the file offset in read and also size in write.

Testing:

We first using fs_make.x to create serval virtual disk. Then create serval test file which to be added into those disks. We wrote a shell script to automatically diff the output between our program test_fs.x and given ref_fs.x. We tested the info ls cat stat, which results are matched.

Reference:

  • [how to write file system by youself] (https://ggaaooppeenngg.github.io/zh-CN/2016/01/04/aufs-如何自己编写一个文件系统/)
  • [write the file system] (http://blog.csdn.net/hytgxljh/article/details/52483919)
  • [Operating System] (https://books.google.com/books?id=iwqzV9vTuY4C&pg=PA282&lpg=PA282&dq=自己编文 件系统&source=bl&ots=44mK2Fspji&sig=f2weM8Z5R88RkeA5eL9DtOkGXDE&hl=zh-CN&sa =X&ved=0ahUKEwiR4JCRzaDUAhUP5WMKHdDhDXo4ChDoAQhIMAc#v=onepage&q=自己编写文件系 统&f=false)