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
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
* mknode_dir.c
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
#include "config.h"
#include "fstree.h"
#include <stdlib.h>
#include <assert.h>
#include <string.h>
int main(void)
{
tree_node_t *root, *a, *b;
struct stat sb;
fstree_t fs;
memset(&fs, 0, sizeof(fs));
memset(&sb, 0, sizeof(sb));
sb.st_mode = S_IFDIR | 0654;
sb.st_uid = 123;
sb.st_gid = 456;
sb.st_rdev = 789;
sb.st_size = 4096;
root = fstree_mknode(NULL, "rootdir", 7, NULL, &sb);
assert(root->uid == sb.st_uid);
assert(root->gid == sb.st_gid);
assert(root->mode == sb.st_mode);
assert(root->link_count == 2);
assert((char *)root->name >= (char *)root->payload);
assert(root->name >= (char *)root->payload);
assert(strcmp(root->name, "rootdir") == 0);
assert(root->data.dir.children == NULL);
assert(root->parent == NULL);
assert(root->next == NULL);
a = fstree_mknode(root, "adir", 4, NULL, &sb);
assert(a->parent == root);
assert(a->next == NULL);
assert(a->link_count == 2);
assert(root->link_count == 3);
assert(root->data.dir.children == a);
assert(root->parent == NULL);
assert(root->next == NULL);
b = fstree_mknode(root, "bdir", 4, NULL, &sb);
assert(a->parent == root);
assert(b->parent == root);
assert(b->link_count == 2);
assert(root->data.dir.children == b);
assert(root->link_count == 4);
assert(b->next == a);
assert(a->next == NULL);
assert(root->parent == NULL);
assert(root->next == NULL);
free(root);
free(a);
free(b);
return EXIT_SUCCESS;
}
|