summaryrefslogtreecommitdiff
path: root/include/fstree.h
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-04-30 01:24:16 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-04-30 01:31:32 +0200
commitfa7f378bf627ddcfd7a93a000149e4d8c3810bf5 (patch)
treee431943a22bc73395c4cb6a639b4243fc45f7deb /include/fstree.h
Initial commit
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include/fstree.h')
-rw-r--r--include/fstree.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/include/fstree.h b/include/fstree.h
new file mode 100644
index 0000000..68bbc7d
--- /dev/null
+++ b/include/fstree.h
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+#ifndef FSTREE_H
+#define FSTREE_H
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stddef.h>
+
+typedef struct tree_node_t tree_node_t;
+typedef struct file_info_t file_info_t;
+typedef struct dir_info_t dir_info_t;
+typedef struct fstree_t fstree_t;
+
+struct file_info_t {
+ char *input_file;
+ file_info_t *frag_next;
+ uint64_t size;
+ uint64_t startblock;
+ uint32_t fragment;
+ uint32_t fragment_offset;
+ uint32_t blocksizes[];
+};
+
+struct dir_info_t {
+ tree_node_t *children;
+ uint64_t size;
+ uint64_t start_block;
+ uint32_t block_offset;
+ bool created_implicitly;
+};
+
+struct tree_node_t {
+ tree_node_t *next;
+ char *name;
+ uint32_t uid;
+ uint32_t gid;
+ uint16_t mode;
+
+ union {
+ dir_info_t *dir;
+ file_info_t *file;
+ char *slink_target;
+ uint64_t devno;
+ } data;
+
+ uint8_t payload[];
+};
+
+struct fstree_t {
+ uint32_t default_uid;
+ uint32_t default_gid;
+ uint32_t default_mode;
+ uint32_t default_mtime;
+ size_t block_size;
+
+ tree_node_t *root;
+};
+
+int fstree_init(fstree_t *fs, size_t block_size, uint32_t mtime,
+ uint16_t default_mode, uint32_t default_uid,
+ uint32_t default_gid);
+
+void fstree_cleanup(fstree_t *fs);
+
+tree_node_t *fstree_add(fstree_t *fs, const char *path, uint16_t mode,
+ uint32_t uid, uint32_t gid, size_t extra_len);
+
+tree_node_t *fstree_add_file(fstree_t *fs, const char *path, uint16_t mode,
+ uint32_t uid, uint32_t gid, uint64_t filesz,
+ const char *input);
+
+int fstree_from_file(fstree_t *fs, const char *filename);
+
+void fstree_sort(fstree_t *fs);
+
+#endif /* FSTREE_H */