summaryrefslogtreecommitdiff
path: root/include/fstree.h
blob: 68bbc7d96fab5970fedb969780d81bbd5aa74880 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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 */