summaryrefslogtreecommitdiff
path: root/lib/sqfshelper/serialize_fstree.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-31 16:59:50 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-31 17:17:23 +0200
commit2ac43d981859bda063e7067371c1cf246c7f81b0 (patch)
treeca289d2b708a60d13e300cc36ae47839389d26cf /lib/sqfshelper/serialize_fstree.c
parent9b3d958fb7c37855a63ed75707281c61dc1d44c4 (diff)
Split libsquashfs.a into low seperate libraries
The idea is to make libsquashfs.a independend of libfstree.a, so it becomes a general purpose squashfs manipulation library. All the high level glue code for libfstree.a and utilites that are overly specific with to tools are moved to a seperate librarby. This commit makes the first step by moving the stuff with dependencies on libfstree to a seperate library. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfshelper/serialize_fstree.c')
-rw-r--r--lib/sqfshelper/serialize_fstree.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/sqfshelper/serialize_fstree.c b/lib/sqfshelper/serialize_fstree.c
new file mode 100644
index 0000000..736744b
--- /dev/null
+++ b/lib/sqfshelper/serialize_fstree.c
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * serialize_fstree.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "meta_writer.h"
+#include "highlevel.h"
+#include "util.h"
+
+#include <unistd.h>
+#include <stdio.h>
+
+int sqfs_serialize_fstree(int outfd, sqfs_super_t *super, fstree_t *fs,
+ compressor_t *cmp, id_table_t *idtbl)
+{
+ meta_writer_t *im, *dm;
+ uint32_t offset;
+ uint64_t block;
+ int ret = -1;
+ size_t i;
+
+ im = meta_writer_create(outfd, cmp, false);
+ if (im == NULL)
+ return -1;
+
+ dm = meta_writer_create(outfd, cmp, true);
+ if (dm == NULL)
+ goto out_im;
+
+ for (i = 2; i < fs->inode_tbl_size; ++i) {
+ if (meta_writer_write_inode(fs, idtbl, im, dm,
+ fs->inode_table[i])) {
+ goto out;
+ }
+ }
+
+ if (meta_writer_flush(im))
+ goto out;
+
+ if (meta_writer_flush(dm))
+ goto out;
+
+ super->root_inode_ref = fs->root->inode_ref;
+
+ meta_writer_get_position(im, &block, &offset);
+ super->inode_table_start = super->bytes_used;
+ super->bytes_used += block;
+
+ meta_writer_get_position(dm, &block, &offset);
+ super->directory_table_start = super->bytes_used;
+ super->bytes_used += block;
+
+ if (meta_write_write_to_file(dm))
+ goto out;
+
+ ret = 0;
+out:
+ meta_writer_destroy(dm);
+out_im:
+ meta_writer_destroy(im);
+ return ret;
+}