summaryrefslogtreecommitdiffstats
path: root/squashfs-tools/action.h
blob: 183daaacdf72bc38a24b6c81036fd515f1e30a70 (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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#ifndef ACTION_H
#define ACTION_H
/*
 * Create a squashfs filesystem.  This is a highly compressed read only
 * filesystem.
 *
 * Copyright (c) 2011, 2012, 2013, 2014, 2021, 2022
 * Phillip Lougher <phillip@squashfs.org.uk>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * action.h
 */

/*
 * Lexical analyser definitions
 */
#define TOK_OPEN_BRACKET	0
#define TOK_CLOSE_BRACKET	1
#define TOK_AND			2
#define TOK_OR			3
#define TOK_NOT			4
#define TOK_COMMA		5
#define TOK_AT			6
#define TOK_WHITE_SPACE		7
#define TOK_STRING		8
#define TOK_EOF			9

#define TOK_TO_STR(OP, S) ({ \
	char *s; \
	switch(OP) { \
	case TOK_EOF: \
		s = "EOF"; \
		break; \
	case TOK_STRING: \
		s = S; \
		break; \
	default: \
		s = token_table[OP].string; \
		break; \
	} \
	s; \
})


struct token_entry {
	char *string;
	int token;
	int size;
};

/*
 * Expression parser definitions
 */
#define OP_TYPE			0
#define ATOM_TYPE		1
#define UNARY_TYPE		2

#define SYNTAX_ERROR(S, ARGS...) { \
	char *src = strdup(source); \
	src[cur_ptr - source] = '\0'; \
	fprintf(stderr, "Failed to parse action \"%s\"\n", source); \
	fprintf(stderr, "Syntax error: "S, ##ARGS); \
	fprintf(stderr, "Got here \"%s\"\n", src); \
	free(src); \
}

#define TEST_SYNTAX_ERROR(TEST, ARG, S, ARGS...) { \
	char *src = strdup(source); \
	src[cur_ptr - source] = '\0'; \
	fprintf(stderr, "Failed to parse action \"%s\"\n", source); \
	fprintf(stderr, "Syntax error in \"%s()\", arg %d: "S, TEST->name, \
			 ARG, ##ARGS); \
	fprintf(stderr, "Got here \"%s\"\n", src); \
	free(src); \
}

struct expr;

struct expr_op {
	struct expr *lhs;
	struct expr *rhs;
	int op;
};


struct atom {
	struct test_entry *test;
	int args;
	char **argv;
	void *data;
};


struct unary_op {
	struct expr *expr;
	int op;
};


struct expr {
	int type;
	union {
		struct atom atom;
		struct expr_op expr_op;
		struct unary_op unary_op;
	};
};

/*
 * Test operation definitions
 */
#define NUM_EQ		1
#define NUM_LESS	2
#define NUM_GREATER	3

struct test_number_arg {
	long long size;
	int range;
};

struct test_range_args {
	long long start;
	long long end;
};

struct action;
struct action_data;

struct test_entry {
	char *name;
	int args;
	int (*fn)(struct atom *, struct action_data *);
	int (*parse_args)(struct test_entry *, struct atom *);
	int exclude_ok;
	int handle_logging;
};


/*
 * Type test specific definitions
 */
struct type_entry {
	int value;
	char type;
};


/*
 * Action definitions
 */
#define FRAGMENT_ACTION		0
#define EXCLUDE_ACTION		1
#define FRAGMENTS_ACTION	2
#define NO_FRAGMENTS_ACTION	3
#define ALWAYS_FRAGS_ACTION	4
#define NO_ALWAYS_FRAGS_ACTION	5
#define COMPRESSED_ACTION	6
#define UNCOMPRESSED_ACTION	7
#define UID_ACTION		8
#define GID_ACTION		9
#define GUID_ACTION		10
#define MODE_ACTION		11
#define EMPTY_ACTION		12
#define MOVE_ACTION		13
#define PRUNE_ACTION		14
#define NOOP_ACTION		15
#define XATTR_EXC_ACTION	16
#define XATTR_INC_ACTION	17
#define XATTR_ADD_ACTION	18

/*
 * Define what file types each action operates over
 */
#define ACTION_DIR 1
#define ACTION_REG 2
#define ACTION_ALL_LNK 3
#define ACTION_ALL 4
#define ACTION_LNK 5


/*
 * Action logging requested, specified by the various
 * -action, -true-action, -false-action and -verbose-action
 * options
 */
#define ACTION_LOG_NONE	0
#define ACTION_LOG_TRUE 1
#define ACTION_LOG_FALSE 2
#define ACTION_LOG_VERBOSE ACTION_LOG_TRUE | ACTION_LOG_FALSE

struct action_entry {
	char *name;
	int type;
	int args;
	int file_types;
	int (*parse_args)(struct action_entry *, int, char **, void **);
	void (*run_action)(struct action *, struct dir_ent *);
};


struct action_data {
	unsigned int depth;
	char *name;
	char *pathname;
	char *subpath;
	struct stat *buf;
	struct dir_ent *dir_ent;
	struct dir_info *root;
};


struct action {
	int type;
	struct action_entry *action;
	int args;
	char **argv;
	struct expr *expr;
	void *data;
	int verbose;
};


/*
 * Uid/gid action specific definitions
 */
struct uid_info {
	uid_t uid;
};

struct gid_info {
	gid_t gid;
};

struct guid_info {
	uid_t uid;
	gid_t gid;
};


/*
 * Mode action specific definitions
 */
#define ACTION_MODE_SET 0
#define ACTION_MODE_ADD 1
#define ACTION_MODE_REM 2
#define ACTION_MODE_OCT 3

struct mode_data {
	struct mode_data *next;
	int operation;
	int mode;
	unsigned int mask;
	char X;
};


/*
 * Empty action specific definitions
 */
#define EMPTY_ALL 0
#define EMPTY_SOURCE 1
#define EMPTY_EXCLUDED 2

struct empty_data {
	int val;
};


/*
 * Move action specific definitions
 */
#define ACTION_MOVE_RENAME 1
#define ACTION_MOVE_MOVE 2

struct move_ent {
	int ops;
	struct dir_ent *dir_ent;
	char *name;
	struct dir_info *dest;
	struct move_ent *next;
};


/*
 * Xattr action specific definitions
 */
struct xattr_data {
	regex_t			preg;
	struct xattr_data	*next;
};


/*
 * Perm test function specific definitions
 */
#define PERM_ALL 1
#define PERM_ANY 2
#define PERM_EXACT 3

struct perm_data {
	int op;
	int mode;
};


/*
 * External function definitions
 */
extern int parse_action(char *, int verbose);
extern void dump_actions();
extern void *eval_frag_actions(struct dir_info *, struct dir_ent *, int);
extern void *get_frag_action(void *);
extern int eval_exclude_actions(char *, char *, char *, struct stat *,
					unsigned int, struct dir_ent *);
extern void eval_actions(struct dir_info *, struct dir_ent *);
extern int eval_empty_actions(struct dir_info *, struct dir_ent *dir_ent);
extern void eval_move_actions(struct dir_info *, struct dir_ent *);
extern int eval_prune_actions(struct dir_info *, struct dir_ent *);
extern struct xattr_data *eval_xattr_exc_actions(struct dir_info *,
							struct dir_ent *);
extern int match_xattr_exc_actions(struct xattr_data *, char *);
extern struct xattr_data *eval_xattr_inc_actions(struct dir_info *,
							struct dir_ent *);
extern int match_xattr_inc_actions(struct xattr_data *, char *);
extern struct xattr_add *eval_xattr_add_actions(struct dir_info *root,
					struct dir_ent *dir_ent, int *items);
extern void do_move_actions();
extern long long read_bytes(int, void *, long long);
extern int any_actions();
extern int actions();
extern int move_actions();
extern int empty_actions();
extern int read_action_file(char *, int);
extern int exclude_actions();
extern int prune_actions();
extern int xattr_exc_actions();
extern int xattr_add_actions();
#endif