xref: /titanic_41/usr/src/cmd/bart/bart.h (revision a970c705050f9e90c4b6d7982a9b3211719353fb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef	_BART_H
26 #define	_BART_H
27 
28 #ifdef	__cplusplus
29 extern "C" {
30 #endif
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <ctype.h>
35 #include <limits.h>
36 #include <sys/stat.h>
37 #include <strings.h>
38 #include <errno.h>
39 #include <fcntl.h>
40 #include <sys/types.h>
41 #include <md5.h>
42 #include <ftw.h>
43 #include <libintl.h>
44 #include "msgs.h"
45 
46 #define	EXIT		0
47 #define	WARNING_EXIT	1
48 #define	FATAL_EXIT	2
49 
50 #define	NO_EXCLUDE	0
51 #define	EXCLUDE_SKIP	1
52 #define	EXCLUDE_PRUNE	2
53 
54 #define	CHECK		0
55 #define	NOCHECK		1
56 
57 #define	CHECK_KEYWORD(s)	(strcmp(s, "CHECK") == 0)
58 #define	IGNORE_KEYWORD(s)	(strcmp(s, "IGNORE") == 0)
59 
60 #define	ALL_KEYWORD		"all"
61 #define	CONTENTS_KEYWORD	"contents"
62 #define	TYPE_KEYWORD		"type"
63 #define	SIZE_KEYWORD		"size"
64 #define	MODE_KEYWORD		"mode"
65 #define	ACL_KEYWORD		"acl"
66 #define	UID_KEYWORD		"uid"
67 #define	GID_KEYWORD		"gid"
68 #define	MTIME_KEYWORD		"mtime"
69 #define	LNMTIME_KEYWORD		"lnmtime"
70 #define	DIRMTIME_KEYWORD	"dirmtime"
71 #define	DEST_KEYWORD		"dest"
72 #define	DEVNODE_KEYWORD		"devnode"
73 #define	ADD_KEYWORD		"add"
74 #define	DELETE_KEYWORD		"delete"
75 
76 #define	MANIFEST_VER	"! Version 1.0\n"
77 #define	FORMAT_STR	"# Format:\n\
78 #fname D size mode acl dirmtime uid gid\n\
79 #fname P size mode acl mtime uid gid\n\
80 #fname S size mode acl mtime uid gid\n\
81 #fname F size mode acl mtime uid gid contents\n\
82 #fname L size mode acl lnmtime uid gid dest\n\
83 #fname B size mode acl mtime uid gid devnode\n\
84 #fname C size mode acl mtime uid gid devnode\n"
85 
86 /*
87  * size of buffer - used in several places
88  */
89 #define	BUF_SIZE	65536
90 
91 /*
92  * size of ACL buffer - used in several places
93  */
94 #define	ACL_SIZE	1024
95 
96 /*
97  * size of MISC buffer - used in several places
98  */
99 #define	MISC_SIZE	20
100 
101 /*
102  * size of TYPE buffer - used in several places
103  */
104 #define	TYPE_SIZE	2
105 
106 struct tree_modifier {
107 	char			*mod_str;
108 	boolean_t		include;
109 	boolean_t		is_dir;
110 	struct tree_modifier	*next;
111 };
112 
113 struct attr_keyword {
114 	char    *ak_name;
115 	int	ak_flags;
116 };
117 
118 
119 #define	ATTR_ALL ((uint_t)~0)
120 #define	ATTR_CONTENTS 0x0001
121 #define	ATTR_TYPE 0x0002
122 #define	ATTR_SIZE 0x0004
123 #define	ATTR_MODE 0x0008
124 #define	ATTR_UID 0x0010
125 #define	ATTR_GID 0x0020
126 #define	ATTR_ACL 0x0040
127 #define	ATTR_DEST 0x0080
128 #define	ATTR_DEVNODE 0x0100
129 #define	ATTR_MTIME 0x0200
130 #define	ATTR_LNMTIME 0x0400
131 #define	ATTR_DIRMTIME 0x0800
132 #define	ATTR_ADD 0x1000
133 #define	ATTR_DELETE 0x2000
134 
135 struct rule {
136 	char			subtree[PATH_MAX];
137 	uint_t			attr_list;
138 	struct tree_modifier	*modifiers;
139 	struct rule		*next;
140 	struct rule		*prev;
141 };
142 
143 struct dir_component {
144 	char			dirname[PATH_MAX];
145 	struct dir_component	*next;
146 };
147 
148 
149 struct attr_keyword *attr_keylookup(char *);
150 void usage(void);
151 int bart_create(int, char **);
152 int bart_compare(int, char **);
153 struct rule *check_rules(const char *, char);
154 int exclude_fname(const char *, char, struct rule *);
155 struct rule *get_first_subtree(void);
156 struct rule *get_next_subtree(struct rule *);
157 void process_glob_ignores(char *, uint_t *);
158 void *safe_calloc(size_t);
159 char *safe_strdup(char *);
160 int read_rules(FILE *, char *, uint_t, int);
161 int read_line(FILE *, char *, int, int, char **, char *);
162 #ifdef	__cplusplus
163 }
164 #endif
165 
166 #endif	/* _BART_H */
167