-
Notifications
You must be signed in to change notification settings - Fork 8
/
initoverlayfs.h
126 lines (110 loc) · 2.75 KB
/
initoverlayfs.h
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <ctype.h>
#include <dirent.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define autofree __attribute__((cleanup(cleanup_free)))
#define autofree_str __attribute__((cleanup(cleanup_free_str)))
#define autofree_conf __attribute__((cleanup(cleanup_free_conf)))
#define autoclose __attribute__((cleanup(cleanup_close)))
#define autofclose __attribute__((cleanup(cleanup_fclose)))
#define autoclosedir __attribute__((cleanup(cleanup_closedir)))
#ifdef __cplusplus
#define typeof decltype
#endif
#define swap(a, b) \
do { \
typeof(a) temp = a; \
a = b; \
b = temp; \
} while (0)
#define print(...) \
do { \
if (kmsg_f) { \
fprintf(kmsg_f, "storage-init: " __VA_ARGS__); \
break; \
} \
\
printf(__VA_ARGS__); \
} while (0)
#if 1
#define DEBUG
#define printd(...) \
do { \
print(__VA_ARGS__); \
} while (0)
#else
#define printd(...)
#endif
static FILE* kmsg_f = 0;
typedef struct str {
char* c_str;
int len;
} str;
typedef struct pair {
str* val;
str* scoped;
} pair;
typedef struct conf {
pair bootfs;
pair bootfs_hint;
pair bootfstype;
pair fs;
pair fstype;
#ifdef SCSI_PROBE
pair scsi_dev;
#endif
} conf;
static inline void cleanup_free_conf(conf* p) {
if (p->bootfs.scoped)
free(p->bootfs.scoped->c_str);
if (p->bootfs_hint.scoped)
free(p->bootfs_hint.scoped->c_str);
if (p->bootfstype.scoped)
free(p->bootfstype.scoped->c_str);
if (p->fs.scoped)
free(p->fs.scoped->c_str);
if (p->fstype.scoped)
free(p->fstype.scoped->c_str);
#ifdef SCSI_PROBE
if (p->scsi_dev.scoped)
free(p->scsi_dev.scoped->c_str);
free(p->scsi_dev.scoped);
free(p->scsi_dev.val);
#endif
free(p->bootfs.scoped);
free(p->bootfs_hint.scoped);
free(p->bootfstype.scoped);
free(p->fs.scoped);
free(p->fstype.scoped);
free(p->bootfs.val);
free(p->bootfs_hint.val);
free(p->bootfstype.val);
free(p->fs.val);
free(p->fstype.val);
}
static inline void cleanup_free(void* p) {
free(*(void**)p);
}
static inline void cleanup_free_str(str** p) {
if (!*p)
return;
free((*p)->c_str);
free(*p);
}
static inline void cleanup_close(const int* fd) {
if (*fd >= 0)
close(*fd);
}
static inline void cleanup_fclose(FILE** stream) {
if (*stream)
fclose(*stream);
}
static inline void cleanup_closedir(DIR** dir) {
if (*dir)
closedir(*dir);
}