aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-03-03 19:43:54 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-03-04 00:58:53 +0100
commit44c81eeffe9c8820b1009a7a5c728782aa5ebf40 (patch)
tree544eceb6dc5633018e5147c88ca9b07dd0fb54d9 /include
parent6f47796dc0761fac359ec59ce26c7af5154e538d (diff)
Add a generic copying mechanism to sqfs_object_t
This patch adds a deep-copy callback to sqfs_object_t and removes the copying mechanism from sqfs_compressor_t. This is also interesting for other types. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include')
-rw-r--r--include/sqfs/block_processor.h2
-rw-r--r--include/sqfs/block_writer.h2
-rw-r--r--include/sqfs/compressor.h9
-rw-r--r--include/sqfs/dir_writer.h2
-rw-r--r--include/sqfs/io.h5
-rw-r--r--include/sqfs/meta_writer.h2
-rw-r--r--include/sqfs/predef.h20
7 files changed, 33 insertions, 9 deletions
diff --git a/include/sqfs/block_processor.h b/include/sqfs/block_processor.h
index 2ad12c0..d3b6e12 100644
--- a/include/sqfs/block_processor.h
+++ b/include/sqfs/block_processor.h
@@ -43,6 +43,8 @@
* 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. @ref sqfs_copy will always return NULL.
*/
/**
diff --git a/include/sqfs/block_writer.h b/include/sqfs/block_writer.h
index bd1ddfc..674c0e7 100644
--- a/include/sqfs/block_writer.h
+++ b/include/sqfs/block_writer.h
@@ -34,6 +34,8 @@
* @implements sqfs_object_t
*
* @brief Abstracts writing and deduplicating of data and fragment blocks.
+ *
+ * This object is not copyable, i.e. @ref sqfs_copy will always return NULL.
*/
/**
diff --git a/include/sqfs/compressor.h b/include/sqfs/compressor.h
index 4292712..9a3508a 100644
--- a/include/sqfs/compressor.h
+++ b/include/sqfs/compressor.h
@@ -91,15 +91,6 @@ struct sqfs_compressor_t {
*/
sqfs_s32 (*do_block)(sqfs_compressor_t *cmp, const sqfs_u8 *in,
sqfs_u32 size, sqfs_u8 *out, sqfs_u32 outsize);
-
- /**
- * @brief Create an exact copt of agiven compressor
- *
- * @param cmp A pointer to a compressor object.
- *
- * @return A deep copy of the given compressor.
- */
- sqfs_compressor_t *(*create_copy)(sqfs_compressor_t *cmp);
};
/**
diff --git a/include/sqfs/dir_writer.h b/include/sqfs/dir_writer.h
index e4a26c7..dce5a79 100644
--- a/include/sqfs/dir_writer.h
+++ b/include/sqfs/dir_writer.h
@@ -58,6 +58,8 @@
* adding entries. Internally it fills data into a meta data writer and
* generates an index that it can, on request, write to another meta data
* writer used for inodes.
+ *
+ * This object is not copyable, i.e. @ref sqfs_copy will always return NULL.
*/
/**
diff --git a/include/sqfs/io.h b/include/sqfs/io.h
index 578c4fb..18c6810 100644
--- a/include/sqfs/io.h
+++ b/include/sqfs/io.h
@@ -63,6 +63,11 @@ typedef enum {
* @extends sqfs_object_t
*
* @brief Abstracts file I/O to make it easy to embedd SquashFS.
+ *
+ * Files are only copyable if they are read only, i.e. if a file has been
+ * opened with write access, @ref sqfs_copy will always return NULL. The
+ * other data types inside libsquashfs assume this to hold for all
+ * implementations of this interface.
*/
struct sqfs_file_t {
sqfs_object_t base;
diff --git a/include/sqfs/meta_writer.h b/include/sqfs/meta_writer.h
index be151cc..58968f5 100644
--- a/include/sqfs/meta_writer.h
+++ b/include/sqfs/meta_writer.h
@@ -46,6 +46,8 @@
* The main task of the meta data writer is to provide a simple append
* function that transparently takes care of chopping data up into blocks,
* compressing the blocks and pre-pending a header.
+ *
+ * This object is not copyable, i.e. @ref sqfs_copy will always return NULL.
*/
/**
diff --git a/include/sqfs/predef.h b/include/sqfs/predef.h
index 6ca3503..0e81933 100644
--- a/include/sqfs/predef.h
+++ b/include/sqfs/predef.h
@@ -121,6 +121,8 @@ typedef struct sqfs_xattr_id_table_t sqfs_xattr_id_table_t;
*/
typedef struct sqfs_object_t {
void (*destroy)(struct sqfs_object_t *instance);
+
+ struct sqfs_object_t *(*copy)(const struct sqfs_object_t *orig);
} sqfs_object_t;
/**
@@ -135,4 +137,22 @@ static SQFS_INLINE void sqfs_destroy(void *obj)
((sqfs_object_t *)obj)->destroy(obj);
}
+/**
+ * @brief Create a deep copy of an object if possible.
+ *
+ * @memberof sqfs_object_t
+ *
+ * @param obj A pointer to an object
+ *
+ * @return A pointer to a new object, instantiated from the old on success,
+ * NULL on failure.
+ */
+static SQFS_INLINE void *sqfs_copy(const void *obj)
+{
+ if (((sqfs_object_t *)obj)->copy != NULL)
+ return ((sqfs_object_t *)obj)->copy(obj);
+
+ return NULL;
+}
+
#endif /* SQFS_PREDEF_H */