comparison usr/src/cmd/filesync/database.h @ 0:c9caec207d52 b86

Initial porting based on b86
author Koji Uno <koji.uno@sun.com>
date Tue, 02 Jun 2009 18:56:50 +0900
parents
children 1a15d5aaf794
comparison
equal deleted inserted replaced
-1:000000000000 0:c9caec207d52
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, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved
24 *
25 * module:
26 * database.h
27 *
28 * purpose:
29 * definition of the baseline and rules data structures
30 */
31
32 #ifndef _DATABASE_H
33 #define _DATABASE_H
34
35 #pragma ident "@(#)database.h 1.11 05/06/08 SMI"
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 #include <sys/stat.h>
42 #include <sys/acl.h>
43
44 #define ACL_UID_BUG 1 /* acl:SETACL sets owner to be caller */
45
46 /*
47 * flag bits describing what we know about an individual file, or in
48 * some cases an entire base pair. These flags are found in the
49 * base and file stuctures.
50 */
51 typedef int fflags_t; /* type for file flags */
52
53 #define F_NEW 0x01 /* newly allocated */
54 #define F_IN_BASELINE 0x02 /* file found in baseline */
55 #define F_IN_SOURCE 0x04 /* file found in source tree */
56 #define F_IN_DEST 0x08 /* file found in dest tree */
57 #define F_EVALUATE 0x10 /* include in analysis */
58 #define F_SPARSE 0x20 /* don't walk this directory */
59 #define F_REMOVE 0x40 /* remove from baseline */
60 #define F_CONFLICT 0x80 /* unresolvable conflict */
61 #define F_LISTED 0x100 /* file came from LIST */
62 #define F_STAT_ERROR 0x200 /* unable to stat file */
63
64 #define F_WHEREFOUND (F_IN_BASELINE|F_IN_SOURCE|F_IN_DEST)
65
66 /*
67 * a base is a pair of directories to be kept in sync
68 * all rules and baseline data is stored beneath some base
69 */
70 struct base {
71 struct base *b_next; /* pointer to next base */
72 fflags_t b_flags; /* what I know about this base */
73 int b_ident; /* base sequence # (DBG) */
74 char *b_src_spec; /* spec name of source dir */
75 char *b_dst_spec; /* spec name of dest dir */
76 char *b_src_name; /* expanded name of source dir */
77 char *b_dst_name; /* expanded name of dest dir */
78
79 struct rule *b_includes; /* chain of include rules */
80 struct rule *b_excludes; /* chain of exclude rules */
81 struct rule *b_restrictions; /* chain of restrictions */
82
83 struct file *b_files; /* chain of files */
84
85 /* statistics for wrap-up summary */
86 int b_totfiles; /* total files found in tree */
87 int b_src_copies; /* files copied to source */
88 int b_src_deletes; /* files deleted from source */
89 int b_src_misc; /* ownership changes on source */
90 int b_dst_copies; /* files copied to dest */
91 int b_dst_deletes; /* files deleted from dest */
92 int b_dst_misc; /* ownership changes on source */
93 int b_unresolved; /* unresolved conflicts */
94 };
95
96 /*
97 * flag bits describing what we know about a particular rule.
98 * These flags are found in the rule structure
99 */
100 typedef int rflags_t; /* type for rule flags */
101
102 #define R_NEW 0x01 /* newly added rule (=OPT_NEW) */
103 #define R_PROGRAM 0x02 /* program (vs literal names) */
104 #define R_IGNORE 0x04 /* IGNORE (vs INCLUDE) */
105 #define R_RESTRICT 0x08 /* restriction (-r argument) */
106 #define R_WILD 0x10 /* name involves wild cards */
107 #define R_BOGUS 0x20 /* fabricated rule */
108
109 /*
110 * a rule describes files to be included or excluded
111 * they are stored under bases
112 */
113 struct rule {
114 struct rule *r_next; /* pointer to next rule in base */
115 rflags_t r_flags; /* flags associated with rule */
116 char *r_file; /* file for this rule */
117 };
118
119
120 /*
121 * this is the information we keep track of for a file
122 */
123 struct fileinfo {
124 ino_t f_ino; /* inode number of this file */
125 long f_d_maj; /* maj dev on which it lives */
126 long f_d_min; /* minj dev on which it lives */
127
128 int f_type; /* file/dir/special ... */
129 int f_mode; /* protection */
130 int f_nlink; /* number of links to file */
131
132 uid_t f_uid; /* owning UID */
133 gid_t f_gid; /* owning GID */
134
135 off_t f_size; /* length in bytes */
136 long f_modtime; /* last modification time */
137 long f_modns; /* low order bits of modtime */
138
139 long f_rd_maj; /* major dev for specials */
140 long f_rd_min; /* minor dev for specials */
141
142 int f_numacls; /* number of entries in acls */
143 aclent_t *f_acls; /* acl list (if any) */
144 };
145
146 /*
147 * flag bits describing the differences we have detected between a file
148 * and the last time it was in sync (based on the baseline).
149 * These flags are used in the srcdiffs and dstdiffs fields of the
150 * file structure
151 */
152 typedef int diffmask_t; /* type for difference masks */
153
154 #define D_CREATE 0x01 /* file has been created */
155 #define D_DELETE 0x02 /* file has been deleted */
156 #define D_MTIME 0x04 /* file has been modified */
157 #define D_SIZE 0x08 /* file has changed size */
158 #define D_UID 0x10 /* file has changed user id */
159 #define D_GID 0x20 /* file has changed group id */
160 #define D_PROT 0x40 /* file has changed protection */
161 #define D_LINKS 0x80 /* file has changed link count */
162 #define D_TYPE 0x100 /* file has changed type */
163 #define D_FACLS 0x200 /* file has changed facls */
164 #define D_RENAME_TO 0x400 /* file came from a rename */
165 #define D_RENAME_FROM 0x800 /* file has been renamed */
166
167 /*
168 * these masks are used to determine how important potential changes are.
169 *
170 * D_CONTENTS there may be changes to the file's contents
171 * D_ADMIN there may be changes to the ownership and protection
172 * D_IMPORTANT there may be changes that should block a deletion
173 *
174 * Note:
175 * I am torn on whether or not to include modtime in D_IMPORTANT.
176 * Experience suggests that deleting one of many links affects the
177 * file modification time.
178 */
179 #define D_ADMIN (D_UID|D_GID|D_PROT|D_FACLS)
180 #define D_CONTENTS (D_SIZE|D_TYPE|D_CREATE|D_MTIME)
181 #define D_IMPORTANT (D_SIZE|D_TYPE|D_CREATE|D_MTIME|D_ADMIN)
182
183 /*
184 * a file is an instance that follows (under a base) from a rule
185 * (for that base). A file structure may exist because of any
186 * combination of a file under the source, destination, in a
187 * baseline for historical reasons, or merely because a rule
188 * calls it out (whether it exists or not).
189 */
190 struct file {
191 struct file *f_next; /* pointer to next file in base */
192 struct file *f_files; /* pointer to files in subdir */
193 struct base *f_base; /* pointer to owning base */
194 fflags_t f_flags; /* flags associated with file */
195 int f_depth; /* directory depth for file */
196 char *f_name; /* name of this file */
197
198 /*
199 * these fields capture information, gleaned from the baseline
200 * that is side-specific, and should not be expected to be in
201 * agreement between the two sides. As a result, this info can
202 * not be properly captured in f_info[OPT_BASE] and needs to
203 * be kept somewhere else.
204 */
205 long f_s_modtime; /* baseline source mod time */
206 ino_t f_s_inum; /* baseline source inode # */
207 long f_s_nlink; /* baseline source link count */
208 long f_s_maj; /* baseline source dev maj */
209 long f_s_min; /* baseline source dev min */
210 long f_d_modtime; /* baseline target mod time */
211 ino_t f_d_inum; /* baseline target inode # */
212 long f_d_nlink; /* baseline target link count */
213 long f_d_maj; /* baseline target dev maj */
214 long f_d_min; /* baseline target dev min */
215
216 /* stat information from baseline file and evaluation */
217 struct fileinfo f_info[3]; /* baseline, source, dest */
218
219 /* summary of changes discovered in analysis */
220 diffmask_t f_srcdiffs; /* changes on source side */
221 diffmask_t f_dstdiffs; /* changes on dest side */
222
223 /* this field is only valid for a renamed file */
224 struct file * f_previous; /* node for previous filename */
225
226 /*
227 * these fields are only valid for a file that has been added
228 * to the reconciliation list
229 */
230 struct file *f_rnext; /* reconciliation chain ptr */
231 char *f_fullname; /* full name for reconciling */
232 long f_modtime; /* modtime for ordering purpose */
233 long f_modns; /* low order modtime */
234
235 /* this field is only valid for a file with a hard conflict */
236 char *f_problem; /* description of conflict */
237 };
238
239 /*
240 * globals
241 */
242 extern struct base omnibase; /* base for global rules */
243 extern struct base *bases; /* base for the main list */
244 extern int inum_changes; /* LISTed dirs with i# changes */
245
246 /* routines to manage base nodes, file nodes, and file infor */
247 errmask_t read_baseline(char *);
248 errmask_t write_baseline(char *);
249 struct file *add_file_to_base(struct base *, const char *);
250 struct file *add_file_to_dir(struct file *, const char *);
251 struct base *add_base(const char *src, const char *dst);
252 void note_info(struct file *, const struct stat *, side_t);
253 void update_info(struct file *, side_t);
254
255 /* routines to manage rules */
256 errmask_t read_rules(char *);
257 errmask_t write_rules(char *);
258 errmask_t add_include(struct base *, char *);
259 errmask_t add_ignore(struct base *, char *);
260
261 /* routines to manage and querry restriction lists */
262 errmask_t add_restr(char *);
263 bool_t check_restr(struct base *, const char *);
264
265 /* routines for dealing with ignore lists */
266 void ignore_reset();
267 void ignore_pgm(const char *);
268 void ignore_expr(const char *);
269 void ignore_file(const char *);
270 bool_t ignore_check(const char *);
271
272 /* database processing routines for the primary passes */
273 errmask_t evaluate(struct base *, side_t, bool_t);
274 errmask_t analyze(void);
275 errmask_t find_renames(struct file *);
276 errmask_t reconcile(struct file *);
277 int prune(void);
278 void summary(void);
279 char *full_name(struct file *, side_t, side_t);
280
281 /* routines in action.c to carry out reconciliation */
282 errmask_t do_copy(struct file *, side_t);
283 errmask_t do_remove(struct file *, side_t);
284 errmask_t do_rename(struct file *, side_t);
285 errmask_t do_like(struct file *, side_t, bool_t);
286
287 /* routines to deal with links in the reconciliation list */
288 struct file *find_link(struct file *, side_t);
289 void link_update(struct file *, side_t);
290 bool_t has_other_links(struct file *, side_t);
291
292 /* maintain a name stack during directory tree traversal */
293 void push_name(const char *);
294 void pop_name();
295 char *get_name(struct file *);
296
297 /* acl manipulation functions */
298 int get_acls(const char *, struct fileinfo *);
299 int set_acls(const char *, struct fileinfo *);
300 int cmp_acls(struct fileinfo *, struct fileinfo *);
301 char *show_acls(int, aclent_t *);
302
303 #ifdef __cplusplus
304 }
305 #endif
306
307 #endif /* _DATABASE_H */