aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqfs')
-rw-r--r--lib/sqfs/write_export_table.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/sqfs/write_export_table.c b/lib/sqfs/write_export_table.c
new file mode 100644
index 0000000..eee4e01
--- /dev/null
+++ b/lib/sqfs/write_export_table.c
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+#include "highlevel.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+
+int write_export_table(int outfd, fstree_t *fs, sqfs_super_t *super,
+ compressor_t *cmp)
+{
+ uint64_t *table, start;
+ size_t i;
+ int ret;
+
+ table = malloc(sizeof(uint64_t) * fs->inode_tbl_size);
+
+ if (table == NULL) {
+ perror("Allocating NFS export table");
+ return -1;
+ }
+
+ for (i = 0; i < fs->inode_tbl_size; ++i) {
+ if (fs->inode_table[i] == NULL) {
+ table[i] = 0xFFFFFFFFFFFFFFFF;
+ } else {
+ table[i] = htole64(fs->inode_table[i]->inode_ref);
+ }
+ }
+
+ ret = sqfs_write_table(outfd, super, table, sizeof(table[0]),
+ fs->inode_tbl_size, &start, cmp);
+
+ super->export_table_start = start;
+ super->flags |= SQFS_FLAG_EXPORTABLE;
+ free(table);
+ return ret;
+}