Supported Calls

File calls:

  • open_file

    input: filename output: -

    The user can specify a file to be opened to perform read/write operations.There is a single parameter passed which is the file name to be opened.If the file exists then the file descriptor is returned(inode index value).If the file does not exist , then a new file is created and its file descriptor is returned. If disk is completely occupied, then an error message is displayed.

    The code has been given below:

    def open_file(path, args):
       location = traverse_disk(path)
       filename = args[0]
       filetype = args[0].split('.')[0]
       inode = check.open(filename)
       if(inode):
           location[filename] = {
               'name': filename,
               'type': filetype,
               'mode': 'rw',
               'rseek': 0,
               'inode': inode
           }
       else:
           print 'Cannot create file.'
    
  • read_file

    input: filename output: contents of file

    The user can specify the filename to be read with a seek value. On success, the content is displayed on the screen. If the file is not found, then either ‘No such file in this directory is displayed’ or ‘Insufficient arguments’ based on the type of error

    def read_file(path, args):
       location = traverse_disk(path)
       try:
           filename = args[0]
           print check.read(filename, location[filename]['rseek'])
       except KeyError:
           print 'No such file in this directory'
       except IndexError:
           print 'Insufficient arguments.'
    
  • write_file

    input: filename, data output: True/ False

    The user can specify the filename to write data to. On success, the changes are reflected in the file. Additional data will be truncated.If an error occurs then ‘No such file in this directory is displayed’ or ‘Insufficient arguments’ are displayed based on the type of error.’

  • append

    input: filename, data output: True/ False

    This function appends data to an existing file.

  • rseek

    input: filename, seekvalue output: True/ False

    This function is used to modify the value of rseek (read pointer of the file.

  • delete_file

    input: filename output: True/ False

    This function deletes the file instance i.e. closes the file.

Directory Calls:

  • mkdir

    This call makes a new directory in the current directory. The command is mkdir 'directoryName'.The results are reflected in the file itself.

  • cd This command is used to change the directory.The command syntax is cd 'newPath'. If the path exists, then this directory becomes the working directory. If the path does not exist, an error message is displayed and the user stays in the original directory.

  • pwd This command gives the path of the current working directory starting from the root folder. It stands for print working directory and does not require any arguments as input.

  • rmdir This command will delete the directory. The command takes the path of the directory as input and deletes this directory regardless of whether it has data or not. If the directory does not exist, an error message is displayed.
  • mvdir This command will is used to move a directory from a source folder to destination folder.
  • ls This commands lists the contents of the entire working folder.The ls commands displays files and directories within the original folder.