The Mini File System (MiniFS)


  • Home

  • homescreen

    The first screen of running the mini file system is shown. There are all the commands help displayed to help guide user to input the appropriate command. At the very beginning, the file system is initialized to contain only an empty directory dir1 under the root (/) directory.

  • Dir

  • dir

    When dir is called, the system shows the contents of the current working directory, which is the root. Here, there are 3 subdirectories with dir2 and dir3 being empty, while dir1 has 10 KB size. The file size and creation time of each components are also listed accordingly.

  • CreateFile

  • createFile

    We try to create a file in the file system using the createFile command. The system is also able to prevent input exceptions from the user. If there is anything wrong with the path for the file or the size of the file (strictly integer from 1 to 351), then the command will not work. As for all other commands as well, if there is no space between the “command” and the path, then it is an unrecognized command to the file system as shown below.

    createFile

    Otherwise, if the command is successful, then a new file will be created at the specified absolute path in the file system. The current working directory will also jump to the parent directory where the file was created. From this directory, the user can use dir to check if the new file has been successfully created and listed under the current working directory.

    createFile
  • ChangeDir

  • In addition, the size of the parent directory where the new file is created will also be updated to include the size of the new file. In order to show this, the user can use changeDir command to change the current working directory to root or the direct parent directory of the directory with the new file.

    changeDir

    Then from this parent directory, dir command can be used to list all of its contents, which in this case will show that the dir1 file size is now updated to 20 KB from 10 KB, after accounting for its new myFile content which has 10 KB size. The same thing will happen even if there are more than 1 layer of nested directories. All the corresponding directories sizes will be updated according to their contents.

  • Sum

  • sum

    The sum command is used to show the usage of the storage space in the file system. This command will display the use of the storage space in terms of MB, as well as in percentage. The number of used and unused blocks are also displayed.

  • Cat

  • cat

    For the newly created file myFile, the user can also print out its content into the terminal by using the cat command. A correct absolute path to myFile is needed to perform the operation. After displaying the content of myFile, which are random strings according to the size of the file (as explained in Implementation section), cat will also change the current working directory to the direct parent directory of the file whose contents are being printed. This is to follow the logic that in order to “open” and display the contents of a file, one needs to be inside the directory where the said file is located firstly. Only then the file can be “opened” and its contents displayed. The same logic applies for all other commands which can switch the current working directory accordingly.

  • Cp

  • cp

    Next command to be tested is the cp command, where it simply copies a file into a new file in the same directory. After using the cp command, the dir command can be used to check if there is indeed a new file created, which is supposed to be the copy of the previous original file. As with all other commands, cp can also handle input exceptions by canceling its operation and notifying the user if there is an input exception. For simplicity and to prevent duplication, this input exception handling will not be shown here.

    cp

    We can also further check that myFile_copy is indeed the copy of myFile by displaying the content of both files using the cat command and compare the random strings. Since the files are a copy of another, both will have the same contents printed out in the terminal.

  • CreateDir

  • createDir

    In order to create a directory, createDir command is used. The file system also supports nested-directory structure. A new subdirectory under subdir1 is created. This new directory subsub1 is the subdirectory of subdir1 which is the subdirectory of dir1. The new directory also means that there is one less free blocks in the file system.

  • DeleteDir

  • deleteDir

    We can also use the deleteDir command to delete a directory with its whole contents, including its subdirectories. This will also free up the used blocks accordingly and released the used i-nodes. However, the current working directory as well as all its connected parents and the root are not allowed to be deleted.

    deleteDir

    Hence, in order to delete a directory, it is better to firstly change the current working directory to the root directory or any other directory that is not the descendants of the directory to be deleted. The deleteFile command also works like deleteDir, except that it deletes a file only.

  • Exit

  • exit

    Lastly, if we exit the file system at this stage, the data will be saved in the hard disk and retrieved back on the next run of the file system. In order to exit the file system, the command exit is used. Upon rerunning the file system, the contents of the memory will be retrieved from the disk for re-loading into the file system. All of the previous state of the file system before exiting will still exist in the file system.

© 2018 JustKenny. Updated 2025. All rights reserved. Hopefully.