Code Monkey home page Code Monkey logo

fs's Introduction

CMPUT379: A Trivial UNIX File System

Jeanna Somoza

Design

For this assignment, we are tasked to write a file system simulator, which will reside on a 128KB disk. Our implementation should be able to handle 10 commands given in a text file with a specified format. To run the simulator, an input file with the list of commands is passed as an argument.
The ten commands our file system is able to handle are:
  • M [disk name]
    This command calls the fs_mount function which takes a disk name as the input and performs six consistency checks before mounting the disk. In performing the consistency checks, I first loaded the superblock of the disk and checked its free block list against its inodes. To check uniqueness of filenames, I maintained a map of directory names and a vector of the indeces of its children. This also helps a lot in other functions. It is only after passing the consistency checks do I load the superblock and set the current working directory to root, which is represented as a variable cwd storing the integer of the inode of the current working directory (127 for root).

  • C [file name] [size]
    This command calls the fs_create function which takes a file name and its size (in blocks) as the input. If the specified size is 0, that means a directory is to be created. The main challenge to this implementation is finding contiguous blocks which can accomodate a file of that size. I found this was easier done by checking the free block list. The first available inode is used, which is done by iterating through the superblock's inode list. From there, the inode attributes are updated based on the start block, parent directory (which is the current working directory), file size, file type, and of course name and state. The free block list and map of parent directory names are also updated.

  • D [file name]
    This command calls the fs_delete function deletes the given file or directory if it exists in the current working directory. To achieve this, the map of directory names and its children are checked. In fact, for most commands involving files located in the current working directory, this map is often referred to. If the file/directory exists, its inode and data blocks are cleared. The free block list and directory map are updated.

  • R [file name] [block number]
    This command calls the fs_read reads from the nth block of a file and writes the data into a 1KB buffer used by the entire file system for holding data for read/write operations. Once again, the file name is checked against the files in the current working directory using the directory map.

  • W [file name] [block number]
    This command calls the fs_write function which, similar to the R command, uses the system-wide data buffer to write into the nth block of the file (both given as arguments). The file name must also exist in the current working directory.

  • B [new buffer characters]
    This command calls fs_buff which does not interact directly with disk data. It populates the data buffer with the characters provided as arguments.

  • L
    This command calls the fs_ls function which is similar to ls command in that it prints out the files and directories located in the current working directory. Files would display their file size and directories would display the number of files/directories they contain. The map of parent directories is once again very useful for this. The directories '.' and '..' are also included.

  • E [file name] [new size]
    This command calls the fs_resize function which changes the size of the file to the specified new size. If the new size is less than the current size, the last blocks are cleared to reduce the size. If the size is increased, it searches for contiguous free blocks of that size to hold the file. If no contiguous blocks are found, the file cannot be resized. Finding the free blocks are achieved by checking the free block list, similar to how files were created. The old data blocks are then moved and the inode's attributes (used size and start block) are updated.

  • O
    This command calls the fs_defrag function, which reorganizes the disk's data blocks to clear out free blocks between used blocks. I first sorted the file inodes by start block, moving ones with the lower start blocks first. I would then go through the free block list, update the inode's start block to the first available data block found. Similar to the resize function, I would move the data blocks, update the inode attributes (only the start block this time) and update the free block list.

  • Y [directory name]
    This command calls the fs_cd function, which is similar to the cd command in that it changes the current working directory to the directory named passed as an argument to this command. First, the directory name is checked against the directories that exist within the current directory. The arguments '.' and '..' are also considered. The variable cwd which holds the inode index of the current directory is updated.

Testing

For testing and debugging, I made use of the four sample test cases, as well as the consistency checks made available to us on eClass. All of the test cases have passed.

Sources

  • Class notes and slides on file systems and their implementation
  • C++ Reference Page
  • Various StackOverflow pages for debugging
  • eClass Discussion Board

fs's People

Contributors

jmsomoza avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.