libsqsh v1.5.1
Loading...
Searching...
No Matches
SqshFile Struct Reference

The Inode context. More...

#include <sqsh_file_private.h>

Public Member Functions

SQSH_NO_EXPORT void sqsh__file_set_parent_inode_ref (struct SqshFile *context, uint64_t parent_inode_ref)
 sets the parent inode reference.
 
SQSH_NO_EXPORT uint64_t sqsh__file_parent_inode_ref (struct SqshFile *context, int *err)
 returns the parent inode reference if possible.
 
SQSH_NO_UNUSED struct SqshFilesqsh_open (struct SqshArchive *archive, const char *path, int *err)
 Initialize the file context from a path.
 
SQSH_NO_UNUSED struct SqshFilesqsh_lopen (struct SqshArchive *archive, const char *path, int *err)
 Initialize the file context from a path. This function is identical to sqsh_open() but if the path is a symlink, the symlink target not resolved.
 
SQSH_NO_UNUSED struct SqshFilesqsh_open_by_ref (struct SqshArchive *archive, uint64_t inode_ref, int *err)
 Initializes a file context in heap.
 
bool sqsh_file_is_extended (const struct SqshFile *context)
 returns whether the file is an extended structure.
 
uint32_t sqsh_file_hard_link_count (const struct SqshFile *context)
 Getter for the inode hard link count.
 
uint64_t sqsh_file_size (const struct SqshFile *context)
 Getter for the file size. 0 if the file has no size.
 
uint16_t sqsh_file_permission (const struct SqshFile *context)
 Getter for the permissions of the file.
 
uint32_t sqsh_file_inode (const struct SqshFile *context)
 Getter for the inode number.
 
uint32_t sqsh_file_modified_time (const struct SqshFile *context)
 Getter for the file modification time in seconds since epoch.
 
uint64_t sqsh_file_blocks_start (const struct SqshFile *context)
 Getter for the start block of the file content. This is only internally used and will be used while retrieving the file content.
 
uint32_t sqsh_file_block_count (const struct SqshFile *context)
 Getter for the amount of blocks of the file content. This is only internally used and will be used while retrieving the file content.
 
uint64_t sqsh_file_block_count2 (const struct SqshFile *context)
 Getter for the amount of blocks of the file content. This is only internally used and will be used while retrieving the file content.
 
uint32_t sqsh_file_block_size (const struct SqshFile *context, uint32_t index)
 Getter the size of a block of the file content. This is only internally used and will be used while retrieving the file content.
 
bool sqsh_file_block_is_compressed (const struct SqshFile *context, uint32_t index)
 Checks whether a certain block is compressed.
 
uint32_t sqsh_file_fragment_block_index (const struct SqshFile *context)
 retrieve the fragment block index. This is only internally used
 
uint32_t sqsh_file_fragment_block_offset (const struct SqshFile *context)
 retrieve the fragment block offset. This is only internally used and will be used while retrieving the file content.
 
uint32_t sqsh_file_directory_block_start (const struct SqshFile *context)
 retrieve the directory block start. This is only internally used and will be used while iterating over the directory entries.
 
uint32_t sqsh_file_directory_block_offset (const struct SqshFile *context)
 retrieve the directory block offset. This is only internally used and will be used while iterating over the directory entries.
 
uint16_t sqsh_file_directory_block_offset2 (const struct SqshFile *context)
 retrieve the directory block offset. This is only internally used and will be used while iterating over the directory entries.
 
uint32_t sqsh_file_directory_parent_inode (const struct SqshFile *context)
 retrieve the parent inode of the directory.
 
bool sqsh_file_has_fragment (const struct SqshFile *context)
 returns true if the file has a fragment block.
 
enum SqshFileType sqsh_file_type (const struct SqshFile *context)
 returns the type of the file.
 
int sqsh_file_symlink_resolve (struct SqshFile *context)
 resolves the symlink target. After calling this function the file is in place changed to the target of the symlink.
 
int sqsh_file_symlink_resolve_all (struct SqshFile *context)
 resolves all symlink target targets until a file is hit. This function is similar to sqsh_file_symlink_resolve() but resolves symlinks recursively until a file is hit.
 
const char * sqsh_file_symlink (const struct SqshFile *context)
 returns the target of a symbolic link. Be aware that the returned value is not zero terminated.
 
SQSH_NO_UNUSED char * sqsh_file_symlink_dup (const struct SqshFile *context)
 creates a heap allocated copy of the target of a symbolic link.
 
uint32_t sqsh_file_symlink_size (const struct SqshFile *context)
 returns the length of the target of a symbolic link in bytes.
 
uint32_t sqsh_file_device_id (const struct SqshFile *context)
 returns the device id of the device inode.
 
uint32_t sqsh_file_uid (const struct SqshFile *context)
 returns the owner user id of the file.
 
uint32_t sqsh_file_gid (const struct SqshFile *context)
 returns the owner group id of the file.
 
uint64_t sqsh_file_inode_ref (const struct SqshFile *context)
 returns the inode reference to this file.
 
uint32_t sqsh_file_xattr_index (const struct SqshFile *context)
 returns index of the extended attribute inside of the xattr table.
 
int sqsh_close (struct SqshFile *file)
 cleans up an file context and frees the memory.
 
int sqsh_file_to_stream (const struct SqshFile *file, FILE *stream)
 writes data to a file descriptor.
 
SQSH_NO_UNUSED int sqsh_file_to_stream_mt (const struct SqshFile *file, struct SqshThreadpool *threadpool, FILE *stream, sqsh_file_to_stream_mt_cb cb, void *data)
 writes data to a file descriptor.
 
void sqsh_file_iterator_mt (const struct SqshFile *file, struct SqshThreadpool *threadpool, sqsh_file_iterator_mt_cb cb, void *data)
 creates a file descriptor from a file and calls a callback for each block.
 

Detailed Description

The Inode context.

Definition at line 245 of file sqsh_file_private.h.

Member Function Documentation

◆ sqsh__file_parent_inode_ref()

SQSH_NO_EXPORT uint64_t sqsh__file_parent_inode_ref ( struct SqshFile * context,
int * err )

returns the parent inode reference if possible.

Parameters
[in]contextThe file context.
[out]errPointer to an int where the error code will be stored.
Returns
int 0 on success, less than 0 on error.

◆ sqsh__file_set_parent_inode_ref()

SQSH_NO_EXPORT void sqsh__file_set_parent_inode_ref ( struct SqshFile * context,
uint64_t parent_inode_ref )

sets the parent inode reference.

Parameters
[in]contextThe file context.
[in]parent_inode_refThe inode reference of the parent directory.

◆ sqsh_close()

int sqsh_close ( struct SqshFile * file)

cleans up an file context and frees the memory.

Parameters
[in]fileThe file context.
Returns
int 0 on success, less than 0 on error.

◆ sqsh_file_block_count()

uint32_t sqsh_file_block_count ( const struct SqshFile * context)

Getter for the amount of blocks of the file content. This is only internally used and will be used while retrieving the file content.

Deprecated
Since 1.5.0. Use sqsh_file_blockcount2() instead.
Parameters
[in]contextThe file context.
Returns
the amount of blocks of the file content. If the file is not of of type SQSH_FILE_TYPE_FILE, UINT32_MAX will be returned.

◆ sqsh_file_block_count2()

uint64_t sqsh_file_block_count2 ( const struct SqshFile * context)

Getter for the amount of blocks of the file content. This is only internally used and will be used while retrieving the file content.

Parameters
[in]contextThe file context.
Returns
the amount of blocks of the file content. If the file is not of of type SQSH_FILE_TYPE_FILE, UINT32_MAX will be returned.

◆ sqsh_file_block_is_compressed()

bool sqsh_file_block_is_compressed ( const struct SqshFile * context,
uint32_t index )

Checks whether a certain block is compressed.

Parameters
[in]contextThe file context.
indexThe index of the block.
Returns
true if the block is compressed, false otherwise.

◆ sqsh_file_block_size()

uint32_t sqsh_file_block_size ( const struct SqshFile * context,
uint32_t index )

Getter the size of a block of the file content. This is only internally used and will be used while retrieving the file content.

Parameters
[in]contextThe file context.
indexThe index of the block.
Returns
the size of the block with the index.

◆ sqsh_file_blocks_start()

uint64_t sqsh_file_blocks_start ( const struct SqshFile * context)

Getter for the start block of the file content. This is only internally used and will be used while retrieving the file content.

Parameters
[in]contextThe file context.
Returns
the start block of the file content or UINT64_MAX if the type is not SQSH_FILE_TYPE_FILE.

◆ sqsh_file_device_id()

uint32_t sqsh_file_device_id ( const struct SqshFile * context)

returns the device id of the device inode.

Parameters
[in]contextThe file context.
Returns
the device id of the device inode or 0 if the file is not a device.

◆ sqsh_file_directory_block_offset()

uint32_t sqsh_file_directory_block_offset ( const struct SqshFile * context)

retrieve the directory block offset. This is only internally used and will be used while iterating over the directory entries.

Deprecated
Since 1.3.0. Use sqsh_file_directory_block_offset2() instead.
Parameters
[in]contextThe file context.
Returns
the directory block offset.

◆ sqsh_file_directory_block_offset2()

uint16_t sqsh_file_directory_block_offset2 ( const struct SqshFile * context)

retrieve the directory block offset. This is only internally used and will be used while iterating over the directory entries.

Parameters
[in]contextThe file context.
Returns
the directory block offset.

◆ sqsh_file_directory_block_start()

uint32_t sqsh_file_directory_block_start ( const struct SqshFile * context)

retrieve the directory block start. This is only internally used and will be used while iterating over the directory entries.

Parameters
[in]contextThe file context.
Returns
the directory block start.

◆ sqsh_file_directory_parent_inode()

uint32_t sqsh_file_directory_parent_inode ( const struct SqshFile * context)

retrieve the parent inode of the directory.

Parameters
[in]contextThe file context.
Returns
the directory block offset.

◆ sqsh_file_fragment_block_index()

uint32_t sqsh_file_fragment_block_index ( const struct SqshFile * context)

retrieve the fragment block index. This is only internally used

and will be used while retrieving the file content.

Parameters
[in]contextThe file context.
Returns
the fragment block index.

◆ sqsh_file_fragment_block_offset()

uint32_t sqsh_file_fragment_block_offset ( const struct SqshFile * context)

retrieve the fragment block offset. This is only internally used and will be used while retrieving the file content.

Parameters
[in]contextThe file context.
Returns
the offset inside of the fragment block.

◆ sqsh_file_gid()

uint32_t sqsh_file_gid ( const struct SqshFile * context)

returns the owner group id of the file.

Parameters
[in]contextThe file context.
Returns
the owner gid of the file.

◆ sqsh_file_hard_link_count()

uint32_t sqsh_file_hard_link_count ( const struct SqshFile * context)

Getter for the inode hard link count.

Parameters
[in]contextThe file context.
Returns
the amount of hard links to the inode.

◆ sqsh_file_has_fragment()

bool sqsh_file_has_fragment ( const struct SqshFile * context)

returns true if the file has a fragment block.

Parameters
[in]contextThe file context.
Returns
true if the file has a fragment block, false otherwise.

◆ sqsh_file_inode()

uint32_t sqsh_file_inode ( const struct SqshFile * context)

Getter for the inode number.

Parameters
[in]contextThe file context.
Returns
the inode number.

◆ sqsh_file_inode_ref()

uint64_t sqsh_file_inode_ref ( const struct SqshFile * context)

returns the inode reference to this file.

The owner reference is an encoded physical location of the inode inside of the archive.

To decode this value use the following code:

uint64_t ref = sqsh_file_ref(context);
uint64_t outer_address = ref >> 16;
uint64_t inner_address = ref & 0xffff;

The outer address is the physical location of the metablock within the archive.

The inner address is the physical location of the inode inside of the decompressed metablock.

Parameters
[in]contextThe file context.
Returns
the reference to this file.

◆ sqsh_file_is_extended()

bool sqsh_file_is_extended ( const struct SqshFile * context)

returns whether the file is an extended structure.

Parameters
[in]contextThe file context.
Returns
true if the file is an extended structure.

◆ sqsh_file_iterator_mt()

void sqsh_file_iterator_mt ( const struct SqshFile * file,
struct SqshThreadpool * threadpool,
sqsh_file_iterator_mt_cb cb,
void * data )

creates a file descriptor from a file and calls a callback for each block.

Parameters
[in]fileThe file context.
[in]threadpoolThe threadpool to use.
[in]cbThe callback to call for each block.
[in]dataThe data to pass to the callback.

◆ sqsh_file_modified_time()

uint32_t sqsh_file_modified_time ( const struct SqshFile * context)

Getter for the file modification time in seconds since epoch.

Parameters
[in]contextThe file context.
Returns
the file modification time.

◆ sqsh_file_permission()

uint16_t sqsh_file_permission ( const struct SqshFile * context)

Getter for the permissions of the file.

Parameters
[in]contextThe file context.
Returns
the permissions of the file.

◆ sqsh_file_size()

uint64_t sqsh_file_size ( const struct SqshFile * context)

Getter for the file size. 0 if the file has no size.

Parameters
[in]contextThe file context.
Returns
the file type.

◆ sqsh_file_symlink()

const char * sqsh_file_symlink ( const struct SqshFile * context)

returns the target of a symbolic link. Be aware that the returned value is not zero terminated.

To get the length of the target use sqsh_file_symlink_size().

If you need a zero terminated string use sqsh_file_symlink_dup().

Parameters
[in]contextThe file context.
Returns
the target of a symbolic link, NULL if the file is not a symbolic link.

◆ sqsh_file_symlink_dup()

SQSH_NO_UNUSED char * sqsh_file_symlink_dup ( const struct SqshFile * context)

creates a heap allocated copy of the target of a symbolic link.

The caller is responsible for calling free() on the returned pointer.

The returned string is 0 terminated.

Parameters
[in]contextThe file context.
Returns
the target of a symbolic link, NULL if the file is not a symbolic link.

◆ sqsh_file_symlink_resolve()

int sqsh_file_symlink_resolve ( struct SqshFile * context)

resolves the symlink target. After calling this function the file is in place changed to the target of the symlink.

Parameters
[in]contextThe file context.
Returns
int 0 on success, less than 0 on error.

◆ sqsh_file_symlink_resolve_all()

int sqsh_file_symlink_resolve_all ( struct SqshFile * context)

resolves all symlink target targets until a file is hit. This function is similar to sqsh_file_symlink_resolve() but resolves symlinks recursively until a file is hit.

Parameters
[in]contextThe file context.
Returns
int 0 on success, less than 0 on error.

◆ sqsh_file_symlink_size()

uint32_t sqsh_file_symlink_size ( const struct SqshFile * context)

returns the length of the target of a symbolic link in bytes.

Parameters
[in]contextThe file context.
Returns
the length of the target of a symbolic link in bytes or 0 if the file is not a symbolic link.

◆ sqsh_file_to_stream()

int sqsh_file_to_stream ( const struct SqshFile * file,
FILE * stream )

writes data to a file descriptor.

Parameters
[in]fileThe file context.
[in]streamThe descriptor to write the file contents to.
Returns
The number of bytes read on success, less than 0 on error.

◆ sqsh_file_to_stream_mt()

SQSH_NO_UNUSED int sqsh_file_to_stream_mt ( const struct SqshFile * file,
struct SqshThreadpool * threadpool,
FILE * stream,
sqsh_file_to_stream_mt_cb cb,
void * data )

writes data to a file descriptor.

Parameters
[in]fileThe file context.
[in]threadpoolThe threadpool to use.
[in]streamThe descriptor to write the file contents to.
[in]cbThe callback to call when the operation is done.
[in]dataThe data to pass to the callback.

◆ sqsh_file_type()

enum SqshFileType sqsh_file_type ( const struct SqshFile * context)

returns the type of the file.

Parameters
[in]contextThe file context.
Returns
the type of the file.

◆ sqsh_file_uid()

uint32_t sqsh_file_uid ( const struct SqshFile * context)

returns the owner user id of the file.

Parameters
[in]contextThe file context.
Returns
the owner uid of the file.

◆ sqsh_file_xattr_index()

uint32_t sqsh_file_xattr_index ( const struct SqshFile * context)

returns index of the extended attribute inside of the xattr table.

Parameters
[in]contextThe file context.
Returns
the index of the extended attribute inside of the xattr table.

◆ sqsh_lopen()

SQSH_NO_UNUSED struct SqshFile * sqsh_lopen ( struct SqshArchive * archive,
const char * path,
int * err )

Initialize the file context from a path. This function is identical to sqsh_open() but if the path is a symlink, the symlink target not resolved.

Parameters
[in]archiveThe sqsh archive context.
[in]pathThe path the file or directory.
[out]errPointer to an int where the error code will be stored.
Returns
0 on success, less than 0 on error.

◆ sqsh_open()

SQSH_NO_UNUSED struct SqshFile * sqsh_open ( struct SqshArchive * archive,
const char * path,
int * err )

Initialize the file context from a path.

Parameters
[in]archiveThe sqsh archive context.
[in]pathThe path the file or directory.
[out]errPointer to an int where the error code will be stored.
Returns
0 on success, less than 0 on error.

◆ sqsh_open_by_ref()

SQSH_NO_UNUSED struct SqshFile * sqsh_open_by_ref ( struct SqshArchive * archive,
uint64_t inode_ref,
int * err )

Initializes a file context in heap.

Parameters
archiveThe sqsh context to use.
inode_refThe inode reference to initialize the context with.
[out]errPointer to an int where the error code will be stored.
Returns
a pointer to the sqsh context or NULL if an error occurred.

The documentation for this struct was generated from the following files: