def cat_cmd(input_list): """print the contents of all the files""" for filename in input_list: lindfd = lind_fs_calls.open_syscall( filename, O_CREAT | O_RDWR, 0) while True: s = lind_fs_calls.read_syscall(lindfd,4096) print s if len(s) == 0: break
def md5_cmd(input_list): """print the md5 digest of all the files""" for filename in input_list: m = hashlib.md5() lindfd = lind_fs_calls.open_syscall( filename, O_CREAT | O_RDWR, 0) while True: s = lind_fs_calls.read_syscall(lindfd,4096) m.update(s) if len(s) == 0: break print m.hexdigest() + " " + filename
def cpout_cmd(source, dest): try: lindfd = lind_fs_calls.open_syscall(source, O_RDWR, 0) except lind_fs_calls.SyscallError, e: print "Couldnt open local file. Error: %s" %e return -1 try: newfd = open(dest, 'w') except IOError, e: print "Couldnt open native file. Error: %s" % e return -1 try: newfd.write(lind_fs_calls.read_syscall(lindfd, 1000000)) except IOError, e: print "Failed to write to disk. Error: %s" % e return -1 lind_fs_calls.close_syscall(lindfd) #create a new directory def mkdir_cmd(input_list): #create a new argument parser, with 1 argument options (one or more new-directory-names) parser = argparse.ArgumentParser(description='Creates a one or more directories with the specified names') parser.add_argument('directory', metavar='dir', nargs='+', type=str, help='The directory names you want to create') #start off with an empty list mkdir_cmd.args = []