summaryrefslogtreecommitdiff
path: root/lib/sqfs/dir_reader.c
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 /lib/sqfs/dir_reader.c
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 'lib/sqfs/dir_reader.c')
-rw-r--r--lib/sqfs/dir_reader.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/sqfs/dir_reader.c b/lib/sqfs/dir_reader.c
index 4e2a5b8..8e23ddb 100644
--- a/lib/sqfs/dir_reader.c
+++ b/lib/sqfs/dir_reader.c
@@ -45,6 +45,32 @@ static void dir_reader_destroy(sqfs_object_t *obj)
free(rd);
}
+static sqfs_object_t *dir_reader_copy(const sqfs_object_t *obj)
+{
+ const sqfs_dir_reader_t *rd = (const sqfs_dir_reader_t *)obj;
+ sqfs_dir_reader_t *copy = malloc(sizeof(*copy));
+
+ if (copy == NULL)
+ return NULL;
+
+ memcpy(copy, rd, sizeof(*copy));
+
+ copy->meta_inode = sqfs_copy(rd->meta_inode);
+ if (copy->meta_inode == NULL)
+ goto fail_mino;
+
+ copy->meta_dir = sqfs_copy(rd->meta_dir);
+ if (copy->meta_dir == NULL)
+ goto fail_mdir;
+
+ return (sqfs_object_t *)copy;
+fail_mdir:
+ sqfs_destroy(copy->meta_inode);
+fail_mino:
+ free(copy);
+ return NULL;
+}
+
sqfs_dir_reader_t *sqfs_dir_reader_create(const sqfs_super_t *super,
sqfs_compressor_t *cmp,
sqfs_file_t *file)
@@ -83,6 +109,7 @@ sqfs_dir_reader_t *sqfs_dir_reader_create(const sqfs_super_t *super,
}
((sqfs_object_t *)rd)->destroy = dir_reader_destroy;
+ ((sqfs_object_t *)rd)->copy = dir_reader_copy;
rd->super = super;
return rd;
}