コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
ファイル: lind_fsck.py プロジェクト: Lind-Project/Lind-misc
def check_if_file_exists(filepath):

    #try to open the file specified, if it fails, then it doens't exist
    try:
        lindfd = lind_fs_calls.open_syscall(filepath, O_RDONLY, 0)
        lind_fs_calls.close_syscall(lindfd)
        #file found, return true
        return True
    except lind_fs_calls.SyscallError:
        #file not found, return false
        return False
コード例 #4
0
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
コード例 #5
0
#copy a file into the lind fs
def copy_file(source, path, new_name):

    #try to open the native file, if unsuccessful print an error and return
    try:
        filedata = open(source, 'r')
    except IOError, e:
        print "Could not open the file. Error: %s" % e
        return -1

    #try to open/create the native file. if unsucessful, error and return
    try:
        mode = stat.S_IMODE(os.stat(source).st_mode)
        #print "in copy " + source+ "..." + str(mode) + "..." + str(stat.S_IRWXU)
        lindfd = lind_fs_calls.open_syscall(path + "/" + new_name, O_CREAT | O_RDWR, mode)

    except lind_fs_calls.SyscallError, e:
        print "Could not open the local file. Error: %s" % e
        return -1

    #try to write the file content to the newly file
    try:
        lind_fs_calls.write_syscall(lindfd, filedata.read())
    except lind_fs_calls.SyscallError, e:
        print "Could not write file. Error: %s" % e
        return -1


    lind_fs_calls.close_syscall(lindfd)