Exemple #1
0
def cstringObj(c_ptr):
    """The cstringObj function is a convenience function which creates a
    Python string copy, and discards the underlying C allocated storage
    for strings created with *alloc() functions in C.

    This function should not be invoked directly, only indirectly
    through the prototyping of the symbol 'cstring_obj'.

    """
    if c_ptr is not None:
        python_string = ctypes.c_char_p( c_ptr ).value
        UTIL_LIB.free( c_ptr )
        return python_string
    else:
        return None
Exemple #2
0
def cstringObj(c_ptr):
    """The cstringObj function is a convenience function which creates a
    Python string copy, and discards the underlying C allocated storage
    for strings created with *alloc() functions in C.

    This function should not be invoked directly, only indirectly
    through the prototyping of the symbol 'cstring_obj'.

    """
    if c_ptr is not None:
        python_string = ctypes.c_char_p(c_ptr).value
        UTIL_LIB.free(c_ptr)
        return python_string
    else:
        return None
Exemple #3
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)