aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-10 11:24:51 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-10 11:25:57 +0200
commit49c2c4a8c8a8eb32a7d5fdbf4b1eba24bb23efe7 (patch)
treef6b3b9c5222edf76137a2a227919ca98614d41e1
parent5367faefd2490e09abed41f655c3db55d36752ad (diff)
API cleanup: eliminate boolean arguments
Replace them with flag fields which can be extended in the future without breaking the ABI. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/sqfs/meta_writer.h26
-rw-r--r--lib/sqfs/meta_writer.c14
-rw-r--r--lib/sqfs/write_table.c2
-rw-r--r--lib/sqfshelper/serialize_fstree.c5
-rw-r--r--lib/sqfshelper/write_xattr.c2
5 files changed, 35 insertions, 14 deletions
diff --git a/include/sqfs/meta_writer.h b/include/sqfs/meta_writer.h
index c1b2383..4351f70 100644
--- a/include/sqfs/meta_writer.h
+++ b/include/sqfs/meta_writer.h
@@ -46,6 +46,23 @@
* compressing the blocks and pre-pending a header.
*/
+/**
+ * @enum E_SQFS_META_WRITER_FLAGS
+ *
+ * @brief Possible flags for @ref sqfs_meta_writer_create.
+ */
+typedef enum {
+ /**
+ * @brief If set, keep finished blocks in memory.
+ *
+ * To write them to disk, explicitly call
+ * @ref sqfs_meta_write_write_to_file.
+ */
+ SQFS_META_WRITER_KEEP_IN_MEMORY = 0x01,
+
+ SQFS_META_WRITER_ALL_FLAGS = 0x01,
+} E_SQFS_META_WRITER_FLAGS;
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -61,15 +78,14 @@ extern "C" {
*
* @param file An output file to write the data to.
* @param cmp A compressor to use.
- * @param keep_in_memory Set to true to store the compressed blocks
- * internally until they are explicilty told
- * to write them to disk.
+ * @param flags A combination of @ref E_SQFS_META_WRITER_FLAGS.
*
- * @return A pointer to a meta writer on success, NULL on allocation failure.
+ * @return A pointer to a meta writer on success, NULL on allocation failure
+ * or if an unknown flag was set.
*/
SQFS_API sqfs_meta_writer_t *sqfs_meta_writer_create(sqfs_file_t *file,
sqfs_compressor_t *cmp,
- bool keep_in_mem);
+ int flags);
/**
* @brief Destroy a meta data writer and free all memory used by it.
diff --git a/lib/sqfs/meta_writer.c b/lib/sqfs/meta_writer.c
index 29fa183..4dd87a5 100644
--- a/lib/sqfs/meta_writer.c
+++ b/lib/sqfs/meta_writer.c
@@ -41,7 +41,7 @@ struct sqfs_meta_writer_t {
/* The raw data chunk that data is appended to */
uint8_t data[SQFS_META_BLOCK_SIZE];
- bool keep_in_mem;
+ int flags;
meta_block_t *list;
meta_block_t *list_end;
};
@@ -56,16 +56,20 @@ static int write_block(sqfs_file_t *file, meta_block_t *outblk)
sqfs_meta_writer_t *sqfs_meta_writer_create(sqfs_file_t *file,
sqfs_compressor_t *cmp,
- bool keep_in_mem)
+ int flags)
{
- sqfs_meta_writer_t *m = calloc(1, sizeof(*m));
+ sqfs_meta_writer_t *m;
+ if (flags & ~SQFS_META_WRITER_ALL_FLAGS)
+ return NULL;
+
+ m = calloc(1, sizeof(*m));
if (m == NULL)
return NULL;
m->cmp = cmp;
m->file = file;
- m->keep_in_mem = keep_in_mem;
+ m->flags = flags;
return m;
}
@@ -113,7 +117,7 @@ int sqfs_meta_writer_flush(sqfs_meta_writer_t *m)
ret = 0;
- if (m->keep_in_mem) {
+ if (m->flags & SQFS_META_WRITER_KEEP_IN_MEMORY) {
if (m->list == NULL) {
m->list = outblk;
} else {
diff --git a/lib/sqfs/write_table.c b/lib/sqfs/write_table.c
index 3c718ea..bef576d 100644
--- a/lib/sqfs/write_table.c
+++ b/lib/sqfs/write_table.c
@@ -36,7 +36,7 @@ int sqfs_write_table(sqfs_file_t *file, sqfs_compressor_t *cmp,
return SQFS_ERROR_ALLOC;
/* Write actual data */
- m = sqfs_meta_writer_create(file, cmp, false);
+ m = sqfs_meta_writer_create(file, cmp, 0);
if (m == NULL) {
ret = SQFS_ERROR_ALLOC;
goto out_idx;
diff --git a/lib/sqfshelper/serialize_fstree.c b/lib/sqfshelper/serialize_fstree.c
index 1953e8d..78f7d13 100644
--- a/lib/sqfshelper/serialize_fstree.c
+++ b/lib/sqfshelper/serialize_fstree.c
@@ -52,11 +52,12 @@ int sqfs_serialize_fstree(sqfs_file_t *file, sqfs_super_t *super, fstree_t *fs,
int ret = -1;
size_t i;
- im = sqfs_meta_writer_create(file, cmp, false);
+ im = sqfs_meta_writer_create(file, cmp, 0);
if (im == NULL)
return -1;
- dm = sqfs_meta_writer_create(file, cmp, true);
+ dm = sqfs_meta_writer_create(file, cmp,
+ SQFS_META_WRITER_KEEP_IN_MEMORY);
if (dm == NULL)
goto out_im;
diff --git a/lib/sqfshelper/write_xattr.c b/lib/sqfshelper/write_xattr.c
index 8103e29..8faa9ff 100644
--- a/lib/sqfshelper/write_xattr.c
+++ b/lib/sqfshelper/write_xattr.c
@@ -185,7 +185,7 @@ int write_xattr(sqfs_file_t *file, fstree_t *fs, sqfs_super_t *super,
if (ool_locations == NULL)
return -1;
- mw = sqfs_meta_writer_create(file, cmp, false);
+ mw = sqfs_meta_writer_create(file, cmp, 0);
if (mw == NULL)
goto fail_ool;