libsquashfs 1.3.0
A new set of tools and libraries for working with SquashFS images
|
Abstracts generating of file data and fragment blocks. More...
#include <block_processor.h>
Public Member Functions | |
SQFS_API sqfs_block_processor_t * | sqfs_block_processor_create (size_t max_block_size, sqfs_compressor_t *cmp, unsigned int num_workers, size_t max_backlog, sqfs_block_writer_t *wr, sqfs_frag_table_t *tbl) |
Create a data block processor. | |
SQFS_API int | sqfs_block_processor_create_ex (const sqfs_block_processor_desc_t *desc, sqfs_block_processor_t **out) |
Create a data block processor. | |
SQFS_API int | sqfs_block_processor_begin_file (sqfs_block_processor_t *proc, sqfs_inode_generic_t **inode, void *user, sqfs_u32 flags) |
Start writing a file. | |
SQFS_API int | sqfs_block_processor_append (sqfs_block_processor_t *proc, const void *data, size_t size) |
Append data to the current file. | |
SQFS_API int | sqfs_block_processor_end_file (sqfs_block_processor_t *proc) |
Stop writing the current file and flush everything that is buffered internally. | |
SQFS_API int | sqfs_block_processor_submit_block (sqfs_block_processor_t *proc, void *user, sqfs_u32 flags, const void *data, size_t size) |
Submit a raw block for processing. | |
SQFS_API int | sqfs_block_processor_sync (sqfs_block_processor_t *proc) |
Wait for the in-flight data blocks to finish. | |
SQFS_API int | sqfs_block_processor_finish (sqfs_block_processor_t *proc) |
Wait for the in-flight data blocks to finish and finally flush the current fragment block. | |
SQFS_API const sqfs_block_processor_stats_t * | sqfs_block_processor_get_stats (const sqfs_block_processor_t *proc) |
Get accumulated runtime statistics from a block processor. | |
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) |
Abstracts generating of file data and fragment blocks.
This data structure provides a simple begin/append/end interface to generate file data blocks (see sqfs_block_processor_begin_file, sqfs_block_processor_append and sqfs_block_processor_end respectively).
Internally it takes care of partitioning data in the correct block sizes, adding tail-ens to fragment blocks, compressing the data, deduplicating data and finally writing it to disk.
This object is not copyable, i.e. sqfs_copy will always return NULL.
SQFS_API int sqfs_block_processor_append | ( | sqfs_block_processor_t * | proc, |
const void * | data, | ||
size_t | size | ||
) |
Append data to the current file.
Call this after sqfs_block_processor_begin_file to add data to a file.
proc | A pointer to a data writer object. |
data | A pointer to a buffer to read data from. |
size | How many bytes should be copied out of the given buffer and written to disk. |
SQFS_API int sqfs_block_processor_begin_file | ( | sqfs_block_processor_t * | proc, |
sqfs_inode_generic_t ** | inode, | ||
void * | user, | ||
sqfs_u32 | flags | ||
) |
Start writing a file.
After calling this function, call sqfs_block_processor_append repeatedly to add data to the file. Finally call sqfs_block_processor_end_file when you are done. After writing all files, use sqfs_block_processor_finish to wait until all blocks that are still in flight are done and written to disk.
The specified pointer to an inode pointer is kept internally and updated with the compressed block sizes and final destinations of the file and possible fragment. Since the inode may have to be grown to larger size, the actual inode pointer can change over time. Furthermore, since there can still be blocks in-flight even after calling sqfs_block_processor_end_file, the data in the inode and the value of the pointer may still change. The only point at which the data writer is guaranteed to not touch them anymore is after sqfs_block_processor_sync or sqfs_block_processor_finish has returned.
proc | A pointer to a data writer object. |
inode | An optional pointer to a pointer to an inode. If not NULL, the block processor creates a file inode and stores a pointer to it here and keeps updating the inode as the file grows. |
user | An optional user data pointer that is passed to the the sqfs_block_writer_t for each file data block. |
flags | A combination of SQFS_BLK_FLAGS that can be used to micro manage how the data is processed. |
SQFS_API sqfs_block_processor_t * sqfs_block_processor_create | ( | size_t | max_block_size, |
sqfs_compressor_t * | cmp, | ||
unsigned int | num_workers, | ||
size_t | max_backlog, | ||
sqfs_block_writer_t * | wr, | ||
sqfs_frag_table_t * | tbl | ||
) |
Create a data block processor.
max_block_size | The maximum size of a data block. Required for the internal scratch buffer used for compressing data. |
cmp | A pointer to a compressor. If multiple worker threads are used, the deep copy function of the compressor is used to create several instances that don't interfere with each other. |
num_workers | The number of worker threads to create. |
max_backlog | The maximum number of blocks currently in flight. When trying to add more, enqueueing blocks until the in-flight block count drops below the threshold. |
wr | A block writer to send to finished blocks to. |
tbl | A fragment table to use for storing fragment and fragment block locations. |
SQFS_API int sqfs_block_processor_create_ex | ( | const sqfs_block_processor_desc_t * | desc, |
sqfs_block_processor_t ** | out | ||
) |
Create a data block processor.
desc | A pointer to an extensible structure that holds the description of the block processor. |
out | On success, returns the pointer to the newly created block processor object. |
SQFS_API int sqfs_block_processor_end_file | ( | sqfs_block_processor_t * | proc | ) |
Stop writing the current file and flush everything that is buffered internally.
The counter part to sqfs_block_processor_begin_file.
Even after calling this, there might still be data blocks in-flight. Use sqfs_block_processor_finish when you are done writing files to force the remaining blocks to be processed and written to disk.
proc | A pointer to a data writer object. |
SQFS_API int sqfs_block_processor_finish | ( | sqfs_block_processor_t * | proc | ) |
Wait for the in-flight data blocks to finish and finally flush the current fragment block.
This does essentially the same as sqfs_block_processor_sync, but after syncing, it also flushes the current fragment block, even if it isn't full yet and waits for it to be completed as well.
proc | A pointer to a block processor object. |
SQFS_API const sqfs_block_processor_stats_t * sqfs_block_processor_get_stats | ( | const sqfs_block_processor_t * | proc | ) |
Get accumulated runtime statistics from a block processor.
proc | A pointer to a data writer object. |
SQFS_API int sqfs_block_processor_submit_block | ( | sqfs_block_processor_t * | proc, |
void * | user, | ||
sqfs_u32 | flags, | ||
const void * | data, | ||
size_t | size | ||
) |
Submit a raw block for processing.
This function provides an alternative to the simple file front end to submit raw data blocks to the processor. It will throw an error if called in between sqfs_block_processor_begin_file and sqfs_block_processor_end_file.
The flags aren't sanity checked (besides being a subset of SQFS_BLK_FLAGS_ALL), so in contrast to the simple file API, you can shoot yourself in the foot as hard as you want.
If not specified otherwise through flags, the fragment block/deduplication and fragment consolidation are still in effect and sparse blocks are discarded.
proc | A pointer to a block processor object. |
user | An optional user data pointer stored with the block and passed on to the underlying sqfs_block_writer_t. |
flags | A combination of SQFS_BLK_FLAGS that can be used to micro manage how the data is processed. |
data | The data to write to the block. |
SQFS_API int sqfs_block_processor_sync | ( | sqfs_block_processor_t * | proc | ) |
Wait for the in-flight data blocks to finish.
proc | A pointer to a block processor object. |