xref: /titanic_50/usr/src/cmd/bart/bart.h (revision e07d9cb85217949d497b02d7211de8a197d2f2eb)
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 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_BART_H
27 #define	_BART_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <ctype.h>
38 #include <limits.h>
39 #include <sys/stat.h>
40 #include <strings.h>
41 #include <errno.h>
42 #include <fcntl.h>
43 #include <sys/types.h>
44 #include <md5.h>
45 #include <ftw.h>
46 #include <libintl.h>
47 #include "msgs.h"
48 
49 #define	EXIT		0
50 #define	WARNING_EXIT	1
51 #define	FATAL_EXIT	2
52 
53 #define	CHECK		0
54 #define	NOCHECK		1
55 
56 #define	CHECK_KEYWORD(s)	(strcmp(s, "CHECK") == 0)
57 #define	IGNORE_KEYWORD(s)	(strcmp(s, "IGNORE") == 0)
58 
59 #define	ALL_KEYWORD		"all"
60 #define	CONTENTS_KEYWORD	"contents"
61 #define	TYPE_KEYWORD		"type"
62 #define	SIZE_KEYWORD		"size"
63 #define	MODE_KEYWORD		"mode"
64 #define	ACL_KEYWORD		"acl"
65 #define	UID_KEYWORD		"uid"
66 #define	GID_KEYWORD		"gid"
67 #define	MTIME_KEYWORD		"mtime"
68 #define	LNMTIME_KEYWORD		"lnmtime"
69 #define	DIRMTIME_KEYWORD	"dirmtime"
70 #define	DEST_KEYWORD		"dest"
71 #define	DEVNODE_KEYWORD		"devnode"
72 #define	ADD_KEYWORD		"add"
73 #define	DELETE_KEYWORD		"delete"
74 
75 #define	MANIFEST_VER	"! Version 1.0\n"
76 #define	FORMAT_STR	"# Format:\n\
77 #fname D size mode acl dirmtime uid gid\n\
78 #fname P size mode acl mtime uid gid\n\
79 #fname S size mode acl mtime uid gid\n\
80 #fname F size mode acl mtime uid gid contents\n\
81 #fname L size mode acl lnmtime uid gid dest\n\
82 #fname B size mode acl mtime uid gid devnode\n\
83 #fname C size mode acl mtime uid gid devnode\n"
84 
85 /*
86  * size of buffer - used in several places
87  */
88 #define	BUF_SIZE	65536
89 
90 /*
91  * size of ACL buffer - used in several places
92  */
93 #define	ACL_SIZE	1024
94 
95 /*
96  * size of MISC buffer - used in several places
97  */
98 #define	MISC_SIZE	20
99 
100 /*
101  * size of TYPE buffer - used in several places
102  */
103 #define	TYPE_SIZE	2
104 
105 struct tree_modifier {
106 	char			*mod_str;
107 	int			include;
108 	struct tree_modifier	*next;
109 };
110 
111 struct attr_keyword {
112 	char    *ak_name;
113 	int	ak_flags;
114 };
115 
116 
117 #define	ATTR_ALL ((uint_t)~0)
118 #define	ATTR_CONTENTS 0x0001
119 #define	ATTR_TYPE 0x0002
120 #define	ATTR_SIZE 0x0004
121 #define	ATTR_MODE 0x0008
122 #define	ATTR_UID 0x0010
123 #define	ATTR_GID 0x0020
124 #define	ATTR_ACL 0x0040
125 #define	ATTR_DEST 0x0080
126 #define	ATTR_DEVNODE 0x0100
127 #define	ATTR_MTIME 0x0200
128 #define	ATTR_LNMTIME 0x0400
129 #define	ATTR_DIRMTIME 0x0800
130 #define	ATTR_ADD 0x1000
131 #define	ATTR_DELETE 0x2000
132 
133 struct rule {
134 	char			subtree[PATH_MAX];
135 	uint_t			attr_list;
136 	struct tree_modifier	*modifiers;
137 	struct rule		*next;
138 	struct rule		*prev;
139 };
140 
141 struct dir_component {
142 	char			dirname[PATH_MAX];
143 	struct dir_component	*next;
144 };
145 
146 
147 struct attr_keyword *attr_keylookup(char *);
148 void usage(void);
149 int bart_create(int, char **);
150 int bart_compare(int, char **);
151 struct rule *check_rules(const char *, char);
152 int exclude_fname(const char *, char, struct rule *);
153 struct rule *get_first_subtree(void);
154 struct rule *get_next_subtree(struct rule *);
155 void process_glob_ignores(char *, uint_t *);
156 void *safe_calloc(size_t);
157 char *safe_strdup(char *);
158 int read_rules(FILE *, char *, uint_t, int);
159 int read_line(FILE *, char *, int, int, char **, char *);
160 #ifdef	__cplusplus
161 }
162 #endif
163 
164 #endif	/* _BART_H */
165