libsquashfs 1.3.0
A new set of tools and libraries for working with SquashFS images
Loading...
Searching...
No Matches
sqfs_data_reader_t Struct Reference

Abstracts access to data blocks stored in a SquashFS image. More...

#include <data_reader.h>

Inheritance diagram for sqfs_data_reader_t:
Inheritance graph
Collaboration diagram for sqfs_data_reader_t:
Collaboration graph

Public Member Functions

SQFS_API sqfs_data_reader_tsqfs_data_reader_create (sqfs_file_t *file, size_t block_size, sqfs_compressor_t *cmp, sqfs_u32 flags)
 Create a data reader instance.
 
SQFS_API int sqfs_data_reader_load_fragment_table (sqfs_data_reader_t *data, const sqfs_super_t *super)
 Read and decode the fragment table from disk.
 
SQFS_API int sqfs_data_reader_get_fragment (sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, size_t *size, sqfs_u8 **out)
 Get the tail end of a file.
 
SQFS_API int sqfs_data_reader_get_block (sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, size_t index, size_t *size, sqfs_u8 **out)
 Get a full sized data block of a file by block index.
 
SQFS_API sqfs_s32 sqfs_data_reader_read (sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, sqfs_u64 offset, void *buffer, sqfs_u32 size)
 A simple UNIX-read-like function to read data from a file.
 

Additional Inherited Members

- Static Public Member Functions inherited from sqfs_object_t
static SQFS_INLINE void sqfs_destroy (void *obj)
 Destroy an object and free all its memory.
 
static SQFS_INLINE void * sqfs_copy (const void *obj)
 Create a deep copy of an object if possible.
 
- Data Fields inherited from sqfs_object_t
void(* destroy )(struct sqfs_object_t *instance)
 
struct sqfs_object_t *(* copy )(const struct sqfs_object_t *orig)
 

Detailed Description

Abstracts access to data blocks stored in a SquashFS image.

A SquashFS image can contain a series of file data blocks between the super block and the inode table. Blocks may or may not be compressed. Data chunks that are smaller than the block size indicated by the super block (such as the final chunk of a file or an entire file that is smaller than a signle block) can be grouped in a single fragment block.

Regular file inodes referre to the location of the first block and store a sequence of block sizes for all consequitve blocks, as well as a fragment index and fragment offset which is resolved through a fragment table.

The data reader abstracts all of this away in a simple interface that allows reading file data through an inode description and a location in the file.

Member Function Documentation

◆ sqfs_data_reader_create()

SQFS_API sqfs_data_reader_t * sqfs_data_reader_create ( sqfs_file_t file,
size_t  block_size,
sqfs_compressor_t cmp,
sqfs_u32  flags 
)

Create a data reader instance.

Parameters
fileA file interface through which to access the underlying filesystem image.
block_sizeThe data block size from the super block.
cmpA compressor to use for uncompressing blocks read from disk.
flagsCurrently must be 0 or the function will fail.
Returns
A pointer to a new data reader object. NULL means allocation failure.

◆ sqfs_data_reader_get_block()

SQFS_API int sqfs_data_reader_get_block ( sqfs_data_reader_t data,
const sqfs_inode_generic_t inode,
size_t  index,
size_t *  size,
sqfs_u8 **  out 
)

Get a full sized data block of a file by block index.

Parameters
dataA pointer to a data reader object.
inodeA pointer to the inode describing the file.
indexThe block index in the inodes block list.
sizeReturns the size of the data read.
outReturns a pointer to the raw data that must be released using sqfs_free.
Returns
Zero on succcess, an SQFS_ERROR value on failure.

◆ sqfs_data_reader_get_fragment()

SQFS_API int sqfs_data_reader_get_fragment ( sqfs_data_reader_t data,
const sqfs_inode_generic_t inode,
size_t *  size,
sqfs_u8 **  out 
)

Get the tail end of a file.

Parameters
dataA pointer to a data reader object.
inodeA pointer to the inode describing the file.
sizeReturns the size of the data read.
outReturns a pointer to the raw data that must be released using sqfs_free.
Returns
Zero on succcess, an SQFS_ERROR value on failure.

◆ sqfs_data_reader_load_fragment_table()

SQFS_API int sqfs_data_reader_load_fragment_table ( sqfs_data_reader_t data,
const sqfs_super_t super 
)

Read and decode the fragment table from disk.

Parameters
dataA pointer to a data reader object.
superA pointer to the super block.
Returns
Zero on succcess, an SQFS_ERROR value on failure.

◆ sqfs_data_reader_read()

SQFS_API sqfs_s32 sqfs_data_reader_read ( sqfs_data_reader_t data,
const sqfs_inode_generic_t inode,
sqfs_u64  offset,
void *  buffer,
sqfs_u32  size 
)

A simple UNIX-read-like function to read data from a file.

This function acts like the read system call in a Unix-like OS. It takes care of reading accross data blocks and fragment internally, using a data and fragment block cache.

Parameters
dataA pointer to a data reader object.
inodeA pointer to the inode describing the file.
offsetAn arbitrary byte offset into the uncompressed file.
bufferReturns the data read from the file.
sizeThe number of uncompressed bytes to read from the given offset.
Returns
The number of bytes read on succcess, zero if attempting to read past the end of the file and a negative SQFS_ERROR value on failure.

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