def _cp_dir_into_lind(fullfilename, rootpath='.', createmissingdirs=True): # check for the file. posixfn = os.path.join(rootpath, fullfilename) if not os.path.exists(posixfn): raise IOError("Cannot locate dire on POSIX FS: '" + posixfn + "'") if os.path.isfile(posixfn): raise IOError("POSIX FS path is not a directory: '" + posixfn + "'") # now, we should check / make intermediate dirs if needed... # we will walk through the components of the dir and look for them... # this removes '.', '///', and similar. # BUG: On Windows, this converts '/' -> '\'. I don't think lind FS handles # '\'... normalizedlindfn = os.path.normpath(fullfilename) # go through the directories and check if they are there, possibly creating # needed ones... currentdir = '' # NOT os.path.split! I want each dir!!! for thisdir in normalizedlindfn.split('/'): currentdir += thisdir + '/' try: # check if this is a directory that exists if IS_DIR(lind_test_server.stat_syscall(currentdir)[2]): # all is well continue # otherwise, it exists, but isn't a dir... raise IOError("LIND FS path exists and isn't a dir: '" + currentdir + "'") except lind_test_server.SyscallError, e: # must be missing dir or else let the caller see this! if e[1] != "ENOENT": raise # okay, do I create it? if not createmissingdirs: raise IOError( "LIND FS path does not exist but should not be created: '" + currentdir + "'") # otherwise, make it ... lind_test_server.mkdir_syscall(currentdir, S_IRWXA) # and copy over the perms, etc. _mirror_stat_data(os.path.join(rootpath, currentdir), currentdir)
def _cp_dir_into_lind(fullfilename, rootpath='.', createmissingdirs=True): # check for the file. posixfn = os.path.join(rootpath, fullfilename) if not os.path.exists(posixfn): raise IOError("Cannot locate dire on POSIX FS: '" + posixfn + "'") if os.path.isfile(posixfn): raise IOError("POSIX FS path is not a directory: '" + posixfn + "'") # now, we should check / make intermediate dirs if needed... # we will walk through the components of the dir and look for them... # this removes '.', '///', and similar. # BUG: On Windows, this converts '/' -> '\'. I don't think lind FS handles # '\'... normalizedlindfn = os.path.normpath(fullfilename) # go through the directories and check if they are there, possibly creating # needed ones... currentdir = '' # NOT os.path.split! I want each dir!!! for thisdir in normalizedlindfn.split('/'): currentdir += thisdir + '/' try: # check if this is a directory that exists if IS_DIR(lind_test_server.stat_syscall(currentdir)[2]): # all is well continue # otherwise, it exists, but isn't a dir... raise IOError("LIND FS path exists and isn't a dir: '" + currentdir + "'") except lind_test_server.SyscallError, e: # must be missing dir or else let the caller see this! if e[1] != "ENOENT": raise # okay, do I create it? if not createmissingdirs: raise IOError("LIND FS path does not exist but should not be created: '" + currentdir + "'") # otherwise, make it ... lind_test_server.mkdir_syscall(currentdir,S_IRWXA) # and copy over the perms, etc. _mirror_stat_data(os.path.join(rootpath, currentdir), currentdir)
import lind_test_server from lind_fs_constants import * # Let's add a few files, etc. to the system and see if it works... lind_test_server._blank_fs_init() myfd = lind_test_server.open_syscall('/foo', O_CREAT | O_EXCL | O_WRONLY, S_IRWXA) stat_result = lind_test_server.stat_syscall('/foo') # ensure the mode is a regular file with all bits on. assert (stat_result[2] == S_IRWXA | S_IFREG) # create a file with no perms... myfd2 = lind_test_server.open_syscall('/foo2', O_CREAT | O_EXCL | O_WRONLY, 0) stat_result2 = lind_test_server.stat_syscall('/foo2') # ensure the mode is a regular file with all bits off. assert (stat_result2[2] == S_IFREG) stat_result = lind_test_server.stat_syscall('.')
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 getattr(self, path): log("getattr", path) try: stats = lind.stat_syscall(path) except lind.SyscallError, e: return -errno[e[1]]
import lind_test_server from lind_fs_constants import * # Let's add a few files, etc. to the system and see if it works... lind_test_server._blank_fs_init() myfd = lind_test_server.open_syscall('/foo',O_CREAT | O_EXCL | O_WRONLY,S_IRWXA) # write should succeed assert(lind_test_server.write_syscall(myfd,'hi') == 2) stat_result = lind_test_server.stat_syscall('/foo') # ensure the file has size 2 assert(stat_result[7] == 2) # ensure the link count is 1 assert(stat_result[3] == 1) # create a file with no perms... lind_test_server.link_syscall('/foo','/foo2') stat_result = lind_test_server.stat_syscall('/foo') stat_result2 = lind_test_server.stat_syscall('/foo2') # ensure they are the same now... assert(stat_result2 == stat_result) # and that the link count is 2
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) stat_result = lind_test_server.stat_syscall('/bar') # ensure the mode is a dir with all bits on. assert(stat_result[2] == S_IRWXA | S_IFDIR) # create a dir with no perms... lind_test_server.mkdir_syscall('/bar2',0) stat_result = lind_test_server.stat_syscall('/bar2') # ensure the mode is a dir with all bits on. assert(stat_result[2] == S_IFDIR)
def cp_into_lind(fullfilename, rootpath='.', createmissingdirs=True): """ <Purpose> Copies a file from POSIX into the Lind FS. It takes the abs path to the file ('/etc/passwd') and looks for it in the POSIX FS off of the root path. For example, rootpath = '/foo' -> '/foo/etc/passwd'. If the file exists, it is overwritten... <Arguments> fullfilename: The location the file should live in the Lind FS. This must be an absolute path (from the root). rootpath: The directory in the POSIX fs to start looking for that file. Note: it must be in the directory structure specified by fullfilename createmissingdirs: Should missing dirs in the path be created? <Exceptions> IOError: If the file does not exist, the directory can't be created (for example, if there is a file of the same name), or createmissingdirs is False, but the path is invalid. <Side Effects> The obvious file IO operations <Returns> None """ # check for the file. posixfn = os.path.join(rootpath,fullfilename) if not os.path.exists(posixfn): raise IOError("Cannot locate file on POSIX FS: '"+posixfn+"'") if not os.path.isfile(posixfn): raise IOError("POSIX FS path is not a file: '"+posixfn+"'") # now, we should check / make intermediate dirs if needed... # we will walk through the components of the dir and look for them... # this removes '.', '///', and similar. # BUG: On Windows, this converts '/' -> '\'. I don't think lind FS handles # '\'... normalizedlindfn = os.path.normpath(fullfilename) normalizedlinddirname = os.path.dirname(normalizedlindfn) # go through the directories and check if they are there, possibly creating # needed ones... currentdir = '' # NOT os.path.split! I want each dir!!! for thisdir in normalizedlinddirname.split('/'): currentdir +=thisdir + '/' try: # check if this is a directory that exists if IS_DIR(lind_test_server.stat_syscall(currentdir)[2]): # all is well continue # otherwise, it exists, but isn't a dir... raise IOError("LIND FS path exists and isn't a dir: '"+currentdir+"'") except lind_test_server.SyscallError, e: # must be missing dir or else let the caller see this! if e[1] != "ENOENT": raise # okay, do I create it? if not createmissingdirs: raise IOError("LIND FS path does not exist but should not be created: '"+currentdir+"'") # otherwise, make it ... lind_test_server.mkdir_syscall(currentdir,S_IRWXA) # and copy over the perms, etc. _mirror_stat_data(os.path.join(rootpath,currentdir),currentdir)
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) stat_result = lind_test_server.stat_syscall('/bar') # ensure the mode is a dir with all bits on. assert (stat_result[2] == S_IRWXA | S_IFDIR) # create a dir with no perms... lind_test_server.mkdir_syscall('/bar2', 0) stat_result = lind_test_server.stat_syscall('/bar2') # ensure the mode is a dir with all bits on. assert (stat_result[2] == S_IFDIR)
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.mkdir_syscall('/bar/baz/yaargh',0) stat_result = lind_test_server.stat_syscall('/bar/baz') # ensure the mode is a dir with all bits on. assert(stat_result[2] == S_IRWXA | S_IFDIR) stat_result = lind_test_server.stat_syscall('/bar/baz/yaargh') # ensure the mode is a dir with all bits on. assert(stat_result[2] == S_IFDIR)
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 * # 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.mkdir_syscall('/bar/baz/yaargh', 0) stat_result = lind_test_server.stat_syscall('/bar/baz') # ensure the mode is a dir with all bits on. assert (stat_result[2] == S_IRWXA | S_IFDIR) stat_result = lind_test_server.stat_syscall('/bar/baz/yaargh') # ensure the mode is a dir with all bits on. assert (stat_result[2] == S_IFDIR)
import lind_test_server from lind_fs_constants import * lind_test_server._blank_fs_init() # / should exist. lind_test_server.access_syscall("/", F_OK) # / should be read / executable by other lind_test_server.access_syscall("/", X_OK | R_OK) stat_result = lind_test_server.stat_syscall("/") # ensure there are 2 hard links to the root of an empty fs assert stat_result[3] == 2 # ensure there is no associated size assert stat_result[7] == 0
def _cp_file_into_lind(fullfilename, rootpath='.', createmissingdirs=True): """ <Purpose> Copies a file from POSIX into the Lind FS. It takes the abs path to the file ('/etc/passwd') and looks for it in the POSIX FS off of the root path. For example, rootpath = '/foo' -> '/foo/etc/passwd'. If the file exists, it is overwritten... <Arguments> fullfilename: The location the file should live in the Lind FS. This must be an absolute path (from the root). rootpath: The directory in the POSIX fs to start looking for that file. Note: it must be in the directory structure specified by fullfilename createmissingdirs: Should missing dirs in the path be created? <Exceptions> IOError: If the file does not exist, the directory can't be created (for example, if there is a file of the same name), or createmissingdirs is False, but the path is invalid. <Side Effects> The obvious file IO operations <Returns> None """ # check for the file. posixfn = os.path.join(rootpath, fullfilename) if not os.path.exists(posixfn): raise IOError("Cannot locate file on POSIX FS: '" + posixfn + "'") if not os.path.isfile(posixfn): raise IOError("POSIX FS path is not a file: '" + posixfn + "'") # now, we should check / make intermediate dirs if needed... # we will walk through the components of the dir and look for them... # this removes '.', '///', and similar. # BUG: On Windows, this converts '/' -> '\'. I don't think lind FS handles # '\'... normalizedlindfn = os.path.normpath(fullfilename) normalizedlinddirname = os.path.dirname(normalizedlindfn) # go through the directories and check if they are there, possibly creating # needed ones... currentdir = '' # NOT os.path.split! I want each dir!!! for thisdir in normalizedlinddirname.split('/'): currentdir += thisdir + '/' try: # check if this is a directory that exists if IS_DIR(lind_test_server.stat_syscall(currentdir)[2]): # all is well continue # otherwise, it exists, but isn't a dir... raise IOError("LIND FS path exists and isn't a dir: '" + currentdir + "'") except lind_test_server.SyscallError, e: # must be missing dir or else let the caller see this! if e[1] != "ENOENT": raise # okay, do I create it? if not createmissingdirs: raise IOError("LIND FS path does not exist but should not be created: '" + currentdir + "'") # otherwise, make it ... lind_test_server.mkdir_syscall(currentdir, S_IRWXA) # and copy over the perms, etc. _mirror_stat_data(os.path.join(rootpath, currentdir), currentdir)
if not os.path.isfile(posixfn): print posixfn+" is not regular file, skipping" return try: host_statinfo = os.stat(posixfn) except OSError, e: print e return else: host_time = host_statinfo.st_mtime host_size = host_statinfo.st_size try: lind_statinfo = lind_test_server.stat_syscall(fullfilename) except lind_test_server.SyscallError, e: print e else: lind_exists = True lind_time = lind_statinfo[12] lind_isfile = IS_REG(lind_statinfo[2]) lind_size = lind_statinfo[7] #always false because lind uses fake time if host_time<=lind_time: print "lind file is newer than host file, skipping" return if lind_exists and not lind_isfile: print fullfilename+" on lind file system is not a regular file, skipping"
import lind_test_server from lind_fs_constants import * # Let's add a few files, etc. to the system and see if it works... lind_test_server._blank_fs_init() filefd = lind_test_server.open_syscall('/foo',O_CREAT | O_EXCL | O_WRONLY,\ S_IRWXA) assert lind_test_server.stat_syscall('/foo')[2] == S_IRWXA | S_IFREG, \ "Failed to have full access to all users." lind_test_server.chmod_syscall('/foo', S_IRUSR | S_IRGRP) assert lind_test_server.stat_syscall('/foo')[2] == S_IRUSR | S_IRGRP | S_IFREG\ , "Failed to set Read access to user and group." lind_test_server.chmod_syscall('/foo', S_IRWXA) assert lind_test_server.stat_syscall('/foo')[2] == S_IRWXA | S_IFREG, \ "Failed to set back full access to all users." lind_test_server.close_syscall(filefd)