def deltree_lind(dirname): # took part of the code from _find_all_paths_recursively method below. # It recursively looks at all child dirs # I need to open the dir to use getdents... dirfd = lind_test_server.open_syscall(dirname,0,0) # build a list of all dents. These have an odd format: # [(inode, filename, d_type (DT_DIR, DR_REG, etc.), length of entry), ...] # We only care about the filename and d_type. mydentslist = [] # Note: the length parameter is odd, it's related to data structure space, so # it doesn't map to python cleanly. So long as it's > the largest possible # entry size, this code should work though. thesedents = lind_test_server.getdents_syscall(dirfd,10000) while thesedents: mydentslist += thesedents thesedents = lind_test_server.getdents_syscall(dirfd,10000) lind_test_server.close_syscall(dirfd) for dent in mydentslist: # ignore '.' and '..' because they aren't interesting and we don't want # to loop forever. if dent[1]=='.' or dent[1]=='..': continue thisitem = (dent[0], dirname+'/'+dent[1]) print "deleting",thisitem[1] # if it's a directory, recurse... if dent[2]==DT_DIR: deltree_lind(thisitem[1]) else: lind_test_server.unlink_syscall(thisitem[1]) lind_test_server.rmdir_syscall(dirname) return
def main(): # I can be imported as a module too!!! if len(sys.argv)==1: print_usage() return command = sys.argv[1] args = sys.argv[2:] #help : print this message #usage : print this message if command == 'help' or command == 'usage': print_usage() #cp root file1 [file2...] : copies files from the root into the lindfs. For # example, cp bar /etc/passwd /bin/ls will copy # bar/etc/passwd, bar/bin/ls as /etc/passwd, /bin/ls elif command == 'cp': lind_test_server.load_fs() if len(args)<2: print 'Too few arguments to cp. Must specify root and at least one file' return root = args[0] for filetocp in args[1:]: cp_into_lind(filetocp, rootpath=root) #find [startingpath] : print the names of all files / paths in the fs # This is much like 'find /' elif command == 'find': lind_test_server.load_fs() if len(args)>1: print 'Too many arguments to find. Takes an optional path' return elif len(args) == 0: startingpath = '/' elif len(args)==1: startingpath = args[0] allpathlist = list_all_lind_paths(startingdir=startingpath) # want to print this more cleanly than as a list for thispath in allpathlist: print thispath #format : make a new blank fs, removing the current one. elif command == 'format': lind_test_server._blank_fs_init() #deltree dirname : delete a directory and all it contains elif command == 'deltree': lind_test_server.load_fs() if len(args)!= 1: print 'deltree takes exactly one argument, the dir to remove' return print 'Unimplemented...' #rm file1 [file2...] : delete a file elif command == 'rm': lind_test_server.load_fs() if len(args) == 0: print 'rm takes one or more arguments' return for filename in args: lind_test_server.unlink_syscall(filename) #mkdir dir1 [dir2...] : create a directory elif command == 'mkdir': lind_test_server.load_fs() if len(args) == 0: print 'mkdir takes one or more arguments' return for dirname in args: lind_test_server.mkdir_syscall(dirname,S_IRWXA) #rmdir dir1 [dir2...] : delete a directory elif command == 'rmdir': lind_test_server.load_fs() if len(args) == 0: print 'rmdir takes one or more arguments' return for dirname in args: lind_test_server.rmdir_syscall(dirname) # OTHERWISE? else: print "ERROR: command unknown" print print_usage() return
def rmdir(self, path): log("rmdir", path) try: ret = lind.rmdir_syscall(path) except lind.SyscallError, e: ret = -errno[e[1]]
def main(): # I can be imported as a module too!!! if len(sys.argv)==1: print_usage() return command = sys.argv[1] args = sys.argv[2:] #help : print this message #usage : print this message if command == 'help' or command == 'usage': print_usage() #cp root file1 [file2...] : copies files from the root into the lindfs. For # example, cp bar /etc/passwd /bin/ls will copy # bar/etc/passwd, bar/bin/ls as /etc/passwd, /bin/ls elif command == 'cp': lind_test_server.load_fs() if len(args)<2: print 'Too few arguments to cp. Must specify root and at least one file' return root = args[0] for filetocp in args[1:]: cp_dir_into_lind(filetocp, rootpath=root) #update root file1 [file2...] : copies files from the root into the lindfs if they are different. For # example, cp bar /etc/passwd /bin/ls will copy # bar/etc/passwd, bar/bin/ls as /etc/passwd, /bin/ls elif command == 'update': lind_test_server.load_fs() if len(args)<2: print 'Too few arguments to update. Must specify root and at least one file' return root = args[0] for filetoup in args[1:]: update_dir_into_lind(filetoup, rootpath=root) #find [startingpath] : print the names of all files / paths in the fs # This is much like 'find /' elif command == 'find': lind_test_server.load_fs() if len(args)>1: print 'Too many arguments to find. Takes an optional path' return elif len(args) == 0: startingpath = '/' elif len(args)==1: startingpath = args[0] allpathlist = list_all_lind_paths(startingdir=startingpath) # want to print this more cleanly than as a list #for thispath in allpathlist: # print thispath #format : make a new blank fs, removing the current one. elif command == 'format': lind_test_server._blank_fs_init() #deltree dirname : delete a directory and all it contains elif command == 'deltree': lind_test_server.load_fs() if len(args)!= 1: print 'deltree takes exactly one argument, the dir to remove' return deltree_lind(args[0]) #rm file1 [file2...] : delete a file elif command == 'rm': lind_test_server.load_fs() if len(args) == 0: print 'rm takes one or more arguments' return for filename in args: lind_test_server.unlink_syscall(filename) #mkdir dir1 [dir2...] : create a directory elif command == 'mkdir': lind_test_server.load_fs() if len(args) == 0: print 'mkdir takes one or more arguments' return for dirname in args: lind_test_server.mkdir_syscall(dirname,S_IRWXA) #rmdir dir1 [dir2...] : delete a directory elif command == 'rmdir': lind_test_server.load_fs() if len(args) == 0: print 'rmdir takes one or more arguments' return for dirname in args: lind_test_server.rmdir_syscall(dirname) # OTHERWISE? else: print "ERROR: command unknown" print print_usage() return
import lind_test_server from lind_fs_constants import * # Let's add a few directories to the system and see if it works... lind_test_server._blank_fs_init() lind_test_server.mkdir_syscall('/bar',S_IRWXA) lind_test_server.mkdir_syscall('/bar/baz',S_IRWXA) lind_test_server.access_syscall('/bar/baz',F_OK) # should not be able try: lind_test_server.rmdir_syscall('/bar') except: pass else: print 'could remove directory with items inside!!!' lind_test_server.rmdir_syscall('/bar/baz') try: lind_test_server.access_syscall('/bar/baz',F_OK) except: pass else: print 'error! Directory exists after removal'
import lind_test_server from lind_fs_constants import * # Let's add a few directories to the system and see if it works... lind_test_server._blank_fs_init() lind_test_server.mkdir_syscall('/bar', S_IRWXA) lind_test_server.mkdir_syscall('/bar/baz', S_IRWXA) lind_test_server.access_syscall('/bar/baz', F_OK) # should not be able try: lind_test_server.rmdir_syscall('/bar') except: pass else: print 'could remove directory with items inside!!!' lind_test_server.rmdir_syscall('/bar/baz') try: lind_test_server.access_syscall('/bar/baz', F_OK) except: pass else: print 'error! Directory exists after removal'