예제 #1
0
    def ls(self, line):
        arguments = splitArguments(line)

        if len(arguments) == 0:
            self.lastCommandFailed("A 'block file' is required.")
        else:
            block_file = arguments[0]
            pattern = None if len(arguments) == 1 else arguments[1]

            if not os.path.isfile(block_file):
                self.lastCommandFailed("The path: '%s' is not a file." % block_file)
            else:
                if not UTIL_LIB.block_fs_is_mount(block_file):
                    _, filename = os.path.split(block_file)
                    self.lastCommandFailed("The file: '%s' is not a block mount file." % filename)
                else:
                    block_fs = UTIL_LIB.block_fs_mount(block_file, 1, 0, 1, 0, False, True, False)
                    files = UTIL_LIB.block_fs_alloc_filelist(block_fs, pattern, OFFSET_SORT, False)

                    file_count = UTIL_LIB.vector_get_size(files)

                    if file_count > 0:
                        fmt = " %-40s %10d %10d"
                        print(" %-40s %10s %10s" % ("Keyword", "Size", "Offset"))

                        for index in range(file_count):
                            node = UTIL_LIB.vector_iget_const(files, index)
                            node_filename = UTIL_LIB.user_file_node_get_filename(node)
                            node_size = UTIL_LIB.user_file_node_get_data_size(node)
                            node_offset = UTIL_LIB.user_file_node_get_node_offset(node)
                            print(fmt % (node_filename, node_size, node_offset))

                    UTIL_LIB.vector_free(files)
                    UTIL_LIB.block_fs_close(block_fs)