def main(): global LOGGING if "-v" in sys.argv or "--verbose" in sys.argv: LOGGING = True usage = """ Lind Fuse File System. """ + Fuse.fusage lind.load_fs() gotlock = runonce.getprocesslock('lind_fuse') if gotlock == True: pass else: if gotlock: print "\n\n#########################################################" print "[Warning] Another Process (pid: " + str(gotlock) + ") already in use." print "#########################################################\n\n" else: print "[Warning] Another Process is running" server = LindFuseFS(version="%prog " + fuse.__version__, usage=usage, dash_s_do='setsingle') server.multithreaded = False # if this is true, better add some locks! server.parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="print extra information about which system" " calls are being called.") server.parser.add_option(mountopt="root", metavar="PATH", default='/', help="mirror filesystem from under PATH " "[default: %default]") server.parse(values=server, errex=1) server.main() lind.persist_metadata("lind.metadata")
def main(): usage = """ Lind Fuse File System. """ + Fuse.fusage lind.load_fs() server = LindFuseFS(version="%prog " + fuse.__version__, usage=usage, dash_s_do='setsingle') server.multithreaded = False # if this is true, better add some locks! server.parser.add_option(mountopt="root", metavar="PATH", default='/', help="mirror filesystem from under PATH [default: %default]") server.parse(values=server, errex=1) server.main() lind.persist_metadata("lind.metadata")
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
import lind_test_server as server from lind_fs_constants import * # This will load the filesystem and the special character files # It checks if the metadata is already present, if so it will # load up the metadata. server.load_fs() server.stat_syscall("/dev") # Check If the special files have been created... assert (server.stat_syscall("/dev/null")[6] == (1, 3)) assert (server.stat_syscall("/dev/random")[6] == (1, 8)) assert (server.stat_syscall("/dev/urandom")[6] == (1, 9))
import lind_test_server from lind_fs_constants import * # this is very similar to the stat complex test, I had to remove the links # though # Let's add a few files, etc. to the system and see if it works... lind_test_server.load_fs() myfd = lind_test_server.open_syscall('/foo',O_CREAT | O_WRONLY,S_IRWXA) # write should succeed assert(lind_test_server.write_syscall(myfd,'hi') == 2) stat_result = lind_test_server.fstat_syscall(myfd) # ensure the file has size 2 assert(stat_result[7] == 2) # ensure the link count is 1 assert(stat_result[3] == 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 * # this is very similar to the stat complex test, I had to remove the links # though # Let's add a few files, etc. to the system and see if it works... lind_test_server.load_fs() myfd = lind_test_server.open_syscall('/foo', O_CREAT | O_WRONLY, S_IRWXA) # write should succeed assert (lind_test_server.write_syscall(myfd, 'hi') == 2) stat_result = lind_test_server.fstat_syscall(myfd) # ensure the file has size 2 assert (stat_result[7] == 2) # ensure the link count is 1 assert (stat_result[3] == 1)
import lind_test_server as server from lind_fs_constants import * # This will load the filesystem and the special character files # It checks if the metadata is already present, if so it will # load up the metadata. server.load_fs() server.stat_syscall("/dev") # Check If the special files have been created... assert(server.stat_syscall("/dev/null")[6] == (1, 3)) assert(server.stat_syscall("/dev/random")[6] == (1, 8)) assert(server.stat_syscall("/dev/urandom")[6] == (1, 9))
def main(): lind_test_server.load_fs() inter = 0 no_args = 1 # with no arguments we go into interactive mode if len(sys.argv) == 1: inter = 1 else: # with 2 args we may want to do a copy if len(sys.argv) == 3: # if the args dont start with a '-' we want to do a copy if not ('-' == sys.argv[1][0] or '-' == sys.argv[2][0]): cp_cmd(sys.argv[1], sys.argv[2]) return # we are done now # iterate over the args in a non pythonish way # so we can jump around when we need to i = 1 while i<len(sys.argv): arg = sys.argv[i] # interactive mode specified if (arg == '-i' or arg == '-interactive'): inter = 1 # we want to copy some files so get the source and dest elif (arg == '-cp' or arg == '-copy'): no_args = 0 if (i+2 < len(sys.argv)): cp_cmd(sys.argv[i+1], sys.argv[i+2]) i += 1 # move one forward so after the loop we have moved 2 args else: print_help("cp") # we want to ls something elif (arg == '-ls'): no_args = 0 num_args = get_num_args(sys.argv[i+1:]) if num_args: ls_cmd(sys.argv[i+1:i+num_args+1]) # num_args+1 as its [inclusive:exclusive] else: ls_cmd(lind_test_server.fs_calls_context['currentworkingdirectory']) i += num_args # we want to read some files elif (arg == '-cat'): no_args = 0 num_args = get_num_args(sys.argv[i+1:]) if num_args: print num_args cat_cmd(sys.argv[i+1:i+num_args+1]) i += num_args else: print_help("cat") # we want to do an md5 sum elif (arg == '-md5' or arg == '-md5sum'): no_args = 0 num_args = get_num_args(sys.argv[i+1:]) if num_args: md5_cmd(sys.argv[i+1:i+num_args+1]) i += num_args else: print_help("md5") # we want to wipe the filesystem elif (arg == '-w' or arg == '-wipe'): no_args = 0 wipe_cmd() # we want some help! elif (arg == '-h' or arg == '-help'): no_args = 0 print_help(ALL_ARGS + " inter cmd") # next arg i += 1 # we now enter interactive mode if specified if inter: no_args = 0 print "interactive mode, type 'exit' to exit" #request user input (the command they want to type) input_value = raw_input(lind_test_server.fs_calls_context['currentworkingdirectory'] +": ") #loop until the user hits exit, prompting them to enter a command at each iteration while((not input_value == "exit")): parse_input(input_value) input_value = raw_input(lind_test_server.fs_calls_context['currentworkingdirectory'] +": ") # if we didnt find any usable args print usage if no_args: print_help(ALL_ARGS + " inter cmd") lind_test_server.persist_metadata("lind.metadata")