Supported Calls
File calls:
open_fileinput:
filenameoutput:-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_fileinput:
filenameoutput:contents of fileThe 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_fileinput:
filename, dataoutput:True/ FalseThe 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.’
appendinput:
filename, dataoutput:True/ FalseThis function appends data to an existing file.
rseekinput:
filename, seekvalueoutput:True/ FalseThis function is used to modify the value of rseek (read pointer of the file.
delete_fileinput:
filenameoutput:True/ FalseThis function deletes the file instance i.e. closes the file.
Directory Calls:
mkdirThis call makes a new directory in the current directory. The command is mkdir 'directoryName'.The results are reflected in the file itself.
cdThis 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.pwdThis 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.rmdirThis 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.mvdirThis command will is used to move a directory from a source folder to destination folder.lsThis commands lists the contents of the entire working folder.The ls commands displays files and directories within the original folder.