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
79
80
81
82
83
|
/* 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;
tree_node_t *parent;
char *name;
uint32_t uid;
uint32_t gid;
uint16_t mode;
uint64_t inode_ref;
uint32_t inode_num;
int type;
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 */
|