1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved
24*0Sstevel@tonic-gate *
25*0Sstevel@tonic-gate * module:
26*0Sstevel@tonic-gate * base.c
27*0Sstevel@tonic-gate *
28*0Sstevel@tonic-gate * purpose:
29*0Sstevel@tonic-gate * routines to create, traverse, read and write the baseline database
30*0Sstevel@tonic-gate *
31*0Sstevel@tonic-gate * contents:
32*0Sstevel@tonic-gate * manipulation:
33*0Sstevel@tonic-gate * add_base, add_file_to_base, add_file_to_dir
34*0Sstevel@tonic-gate * (static) add_file_to_list
35*0Sstevel@tonic-gate * reading baseline:
36*0Sstevel@tonic-gate * read_baseline
37*0Sstevel@tonic-gate * (static) gettype
38*0Sstevel@tonic-gate * writing baseline:
39*0Sstevel@tonic-gate * write_baseline
40*0Sstevel@tonic-gate * (static) bw_header, bw_base, bw_file, showtype
41*0Sstevel@tonic-gate */
42*0Sstevel@tonic-gate #ident "%W% %E% SMI"
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gate #include <stdlib.h>
45*0Sstevel@tonic-gate #include <stdio.h>
46*0Sstevel@tonic-gate #include <string.h>
47*0Sstevel@tonic-gate #include <time.h>
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate #include "filesync.h"
50*0Sstevel@tonic-gate #include "database.h"
51*0Sstevel@tonic-gate #include "messages.h"
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate #define BASE_MAJOR 1 /* base file format major rev */
54*0Sstevel@tonic-gate #define BASE_MINOR 2 /* base file format minor rev */
55*0Sstevel@tonic-gate #define BASE_TAG "filesync-BaseLine"
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate /*
58*0Sstevel@tonic-gate * globals
59*0Sstevel@tonic-gate */
60*0Sstevel@tonic-gate struct base omnibase; /* dummy to hold global rules */
61*0Sstevel@tonic-gate struct base *bases; /* pointer to the base list */
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate /*
64*0Sstevel@tonic-gate * locals
65*0Sstevel@tonic-gate */
66*0Sstevel@tonic-gate static int num_bases; /* used to generate sequence #s */
67*0Sstevel@tonic-gate static errmask_t bw_header(FILE *); /* write out baseline header */
68*0Sstevel@tonic-gate static errmask_t bw_base(FILE *, struct base *); /* write out one base */
69*0Sstevel@tonic-gate static errmask_t bw_file(FILE *, struct file *, int);
70*0Sstevel@tonic-gate static struct file *add_file_to_list(struct file **, const char *);
71*0Sstevel@tonic-gate static char showtype(int);
72*0Sstevel@tonic-gate static long gettype(int);
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate /*
75*0Sstevel@tonic-gate * routine:
76*0Sstevel@tonic-gate * add_base
77*0Sstevel@tonic-gate *
78*0Sstevel@tonic-gate * purpose:
79*0Sstevel@tonic-gate * to find a base pair in the chain, adding it if necessary
80*0Sstevel@tonic-gate *
81*0Sstevel@tonic-gate * parameters:
82*0Sstevel@tonic-gate * spec for source directory
83*0Sstevel@tonic-gate * spec for dest directory
84*0Sstevel@tonic-gate *
85*0Sstevel@tonic-gate * returns:
86*0Sstevel@tonic-gate * pointer to the base pair
87*0Sstevel@tonic-gate *
88*0Sstevel@tonic-gate */
89*0Sstevel@tonic-gate struct base *
add_base(const char * src,const char * dst)90*0Sstevel@tonic-gate add_base(const char *src, const char *dst)
91*0Sstevel@tonic-gate { struct base *bp, **bpp;
92*0Sstevel@tonic-gate
93*0Sstevel@tonic-gate /* first see if we already have it */
94*0Sstevel@tonic-gate for (bpp = &bases; (bp = *bpp) != 0; bpp = &bp->b_next) {
95*0Sstevel@tonic-gate /* base must match on both src and dst */
96*0Sstevel@tonic-gate if (strcmp(src, bp->b_src_spec))
97*0Sstevel@tonic-gate continue;
98*0Sstevel@tonic-gate if (strcmp(dst, bp->b_dst_spec))
99*0Sstevel@tonic-gate continue;
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gate if (opt_debug & DBG_BASE)
102*0Sstevel@tonic-gate fprintf(stderr, "BASE: FOUND base=%d, src=%s, dst=%s\n",
103*0Sstevel@tonic-gate bp->b_ident, src, dst);
104*0Sstevel@tonic-gate return (bp);
105*0Sstevel@tonic-gate }
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gate /* no joy, so we have to allocate one */
108*0Sstevel@tonic-gate bp = malloc(sizeof (struct base));
109*0Sstevel@tonic-gate if (bp == 0)
110*0Sstevel@tonic-gate nomem("base structure");
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gate /* initialize the new base */
113*0Sstevel@tonic-gate memset((void *) bp, 0, sizeof (struct base));
114*0Sstevel@tonic-gate bp->b_ident = ++num_bases;
115*0Sstevel@tonic-gate bp->b_src_spec = strdup(src);
116*0Sstevel@tonic-gate bp->b_dst_spec = strdup(dst);
117*0Sstevel@tonic-gate
118*0Sstevel@tonic-gate /* names are expanded at run-time, and this is run-time */
119*0Sstevel@tonic-gate if ((bp->b_src_name = expand(bp->b_src_spec)) == 0) {
120*0Sstevel@tonic-gate fprintf(stderr, gettext(ERR_badbase), bp->b_src_spec);
121*0Sstevel@tonic-gate exit(ERR_FILES);
122*0Sstevel@tonic-gate }
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate if ((bp->b_dst_name = expand(bp->b_dst_spec)) == 0) {
125*0Sstevel@tonic-gate fprintf(stderr, gettext(ERR_badbase), bp->b_dst_spec);
126*0Sstevel@tonic-gate exit(ERR_FILES);
127*0Sstevel@tonic-gate }
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate /* chain it in */
130*0Sstevel@tonic-gate *bpp = bp;
131*0Sstevel@tonic-gate
132*0Sstevel@tonic-gate if (opt_debug & DBG_BASE)
133*0Sstevel@tonic-gate fprintf(stderr, "BASE: ADDED base=%d, src=%s, dst=%s\n",
134*0Sstevel@tonic-gate bp->b_ident, src, dst);
135*0Sstevel@tonic-gate
136*0Sstevel@tonic-gate return (bp);
137*0Sstevel@tonic-gate }
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gate /*
140*0Sstevel@tonic-gate * routine:
141*0Sstevel@tonic-gate * add_file_to_list
142*0Sstevel@tonic-gate *
143*0Sstevel@tonic-gate * purpose:
144*0Sstevel@tonic-gate * to find a file on a list, or if necessary add it to the list
145*0Sstevel@tonic-gate *
146*0Sstevel@tonic-gate * this is an internal routine, used only by add_file_to_base
147*0Sstevel@tonic-gate * and add_file_to_dir.
148*0Sstevel@tonic-gate *
149*0Sstevel@tonic-gate * parameters:
150*0Sstevel@tonic-gate * pointer to the list head
151*0Sstevel@tonic-gate *
152*0Sstevel@tonic-gate * returns:
153*0Sstevel@tonic-gate * pointer to a file structure
154*0Sstevel@tonic-gate *
155*0Sstevel@tonic-gate * notes:
156*0Sstevel@tonic-gate *
157*0Sstevel@tonic-gate * list is sorted to provide some search optimization
158*0Sstevel@tonic-gate *
159*0Sstevel@tonic-gate * most files are in the baseline, and so come in in alphabetical
160*0Sstevel@tonic-gate * order. If we keep a guess pointer to the last file we added/found,
161*0Sstevel@tonic-gate * there is a better than even chance that this one should be
162*0Sstevel@tonic-gate * added immediately onto the end of it ... and in so doing we
163*0Sstevel@tonic-gate * can save ourselves the trouble of searching the lists most
164*0Sstevel@tonic-gate * of the time.
165*0Sstevel@tonic-gate *
166*0Sstevel@tonic-gate * this win would be even better if the FTW traversal was sorted,
167*0Sstevel@tonic-gate * but building the baseline is enough of a win to justify the
168*0Sstevel@tonic-gate * feature ... but even without this we run a 60%-70% hit rate.
169*0Sstevel@tonic-gate */
170*0Sstevel@tonic-gate static struct file *
add_file_to_list(struct file ** pp,const char * name)171*0Sstevel@tonic-gate add_file_to_list(struct file **pp, const char *name)
172*0Sstevel@tonic-gate { struct file *fp, *new;
173*0Sstevel@tonic-gate int rslt;
174*0Sstevel@tonic-gate
175*0Sstevel@tonic-gate static struct file **last_list;
176*0Sstevel@tonic-gate static struct file *last_file;
177*0Sstevel@tonic-gate
178*0Sstevel@tonic-gate /*
179*0Sstevel@tonic-gate * start with the guess pointer, we hope to find that
180*0Sstevel@tonic-gate * this request will be satisfied by the next file in
181*0Sstevel@tonic-gate * the list. The two cases we are trying to optimize
182*0Sstevel@tonic-gate * are:
183*0Sstevel@tonic-gate * appending to the list, with appends in alphabetical order
184*0Sstevel@tonic-gate * searches of the list, with searches in alphabetical order
185*0Sstevel@tonic-gate */
186*0Sstevel@tonic-gate if (last_list == pp && (new = last_file) != 0) {
187*0Sstevel@tonic-gate /* we like to think we belong farther down-list */
188*0Sstevel@tonic-gate if (strcmp(name, new->f_name) > 0) {
189*0Sstevel@tonic-gate fp = new->f_next;
190*0Sstevel@tonic-gate /* if we're at the end, we just won */
191*0Sstevel@tonic-gate if (fp == 0) {
192*0Sstevel@tonic-gate pp = &new->f_next;
193*0Sstevel@tonic-gate goto makeit;
194*0Sstevel@tonic-gate }
195*0Sstevel@tonic-gate
196*0Sstevel@tonic-gate /* or if the next one is what we want */
197*0Sstevel@tonic-gate if (strcmp(name, fp->f_name) == 0) {
198*0Sstevel@tonic-gate fp->f_flags &= ~F_NEW;
199*0Sstevel@tonic-gate new = fp;
200*0Sstevel@tonic-gate goto gotit;
201*0Sstevel@tonic-gate }
202*0Sstevel@tonic-gate }
203*0Sstevel@tonic-gate }
204*0Sstevel@tonic-gate
205*0Sstevel@tonic-gate /*
206*0Sstevel@tonic-gate * our guess pointer failed, so it is exhaustive search time
207*0Sstevel@tonic-gate */
208*0Sstevel@tonic-gate last_list = pp;
209*0Sstevel@tonic-gate
210*0Sstevel@tonic-gate for (fp = *pp; fp; pp = &fp->f_next, fp = *pp) {
211*0Sstevel@tonic-gate rslt = strcmp(name, fp->f_name);
212*0Sstevel@tonic-gate
213*0Sstevel@tonic-gate /* see if we got a match */
214*0Sstevel@tonic-gate if (rslt == 0) {
215*0Sstevel@tonic-gate fp->f_flags &= ~F_NEW;
216*0Sstevel@tonic-gate new = fp;
217*0Sstevel@tonic-gate goto gotit;
218*0Sstevel@tonic-gate }
219*0Sstevel@tonic-gate
220*0Sstevel@tonic-gate /* see if we should go no farther */
221*0Sstevel@tonic-gate if (rslt < 0)
222*0Sstevel@tonic-gate break;
223*0Sstevel@tonic-gate }
224*0Sstevel@tonic-gate
225*0Sstevel@tonic-gate makeit:
226*0Sstevel@tonic-gate /*
227*0Sstevel@tonic-gate * we didn't find it:
228*0Sstevel@tonic-gate * pp points at where our pointer should go
229*0Sstevel@tonic-gate * fp points at the node after ours
230*0Sstevel@tonic-gate */
231*0Sstevel@tonic-gate new = (struct file *) malloc(sizeof (*new));
232*0Sstevel@tonic-gate if (new == 0)
233*0Sstevel@tonic-gate nomem("file structure");
234*0Sstevel@tonic-gate
235*0Sstevel@tonic-gate /* initialize the new node */
236*0Sstevel@tonic-gate memset((void *) new, 0, sizeof (struct file));
237*0Sstevel@tonic-gate new->f_name = strdup(name);
238*0Sstevel@tonic-gate new->f_flags = F_NEW;
239*0Sstevel@tonic-gate
240*0Sstevel@tonic-gate /* chain it into the list */
241*0Sstevel@tonic-gate new->f_next = fp;
242*0Sstevel@tonic-gate *pp = new;
243*0Sstevel@tonic-gate
244*0Sstevel@tonic-gate gotit: /* remember this as our next guess pointer */
245*0Sstevel@tonic-gate last_file = new;
246*0Sstevel@tonic-gate return (new);
247*0Sstevel@tonic-gate }
248*0Sstevel@tonic-gate
249*0Sstevel@tonic-gate /*
250*0Sstevel@tonic-gate * routine:
251*0Sstevel@tonic-gate * add_file_to_base
252*0Sstevel@tonic-gate *
253*0Sstevel@tonic-gate * purpose:
254*0Sstevel@tonic-gate * to add a file-node to a baseline
255*0Sstevel@tonic-gate *
256*0Sstevel@tonic-gate * parameters:
257*0Sstevel@tonic-gate * pointer to base
258*0Sstevel@tonic-gate * name of file to be added
259*0Sstevel@tonic-gate *
260*0Sstevel@tonic-gate * returns:
261*0Sstevel@tonic-gate * pointer to file structure
262*0Sstevel@tonic-gate */
263*0Sstevel@tonic-gate struct file *
add_file_to_base(struct base * bp,const char * name)264*0Sstevel@tonic-gate add_file_to_base(struct base *bp, const char *name)
265*0Sstevel@tonic-gate { struct file *fp;
266*0Sstevel@tonic-gate
267*0Sstevel@tonic-gate fp = add_file_to_list(&bp->b_files, name);
268*0Sstevel@tonic-gate fp->f_base = bp;
269*0Sstevel@tonic-gate fp->f_depth = 0;
270*0Sstevel@tonic-gate
271*0Sstevel@tonic-gate if (opt_debug & DBG_LIST)
272*0Sstevel@tonic-gate fprintf(stderr, "LIST: base=%d, %s file=%s\n",
273*0Sstevel@tonic-gate bp->b_ident, (fp->f_flags&F_NEW) ? "NEW" : "FOUND",
274*0Sstevel@tonic-gate name);
275*0Sstevel@tonic-gate
276*0Sstevel@tonic-gate return (fp);
277*0Sstevel@tonic-gate }
278*0Sstevel@tonic-gate
279*0Sstevel@tonic-gate /*
280*0Sstevel@tonic-gate * routine:
281*0Sstevel@tonic-gate * add_file_to_dir
282*0Sstevel@tonic-gate *
283*0Sstevel@tonic-gate * purpose:
284*0Sstevel@tonic-gate * to add a file-node to a directory
285*0Sstevel@tonic-gate *
286*0Sstevel@tonic-gate * parameters:
287*0Sstevel@tonic-gate * pointer to file entry for directory
288*0Sstevel@tonic-gate * name of file to be added
289*0Sstevel@tonic-gate *
290*0Sstevel@tonic-gate * returns:
291*0Sstevel@tonic-gate * pointer to file structure
292*0Sstevel@tonic-gate */
293*0Sstevel@tonic-gate struct file *
add_file_to_dir(struct file * dp,const char * name)294*0Sstevel@tonic-gate add_file_to_dir(struct file *dp, const char *name)
295*0Sstevel@tonic-gate { struct file *fp;
296*0Sstevel@tonic-gate
297*0Sstevel@tonic-gate fp = add_file_to_list(&dp->f_files, name);
298*0Sstevel@tonic-gate fp->f_base = dp->f_base;
299*0Sstevel@tonic-gate fp->f_depth = dp->f_depth + 1;
300*0Sstevel@tonic-gate
301*0Sstevel@tonic-gate if (opt_debug & DBG_LIST)
302*0Sstevel@tonic-gate fprintf(stderr, "LIST: dir=%s, %s file=%s\n",
303*0Sstevel@tonic-gate dp->f_name, (fp->f_flags&F_NEW) ? "NEW" : "FOUND",
304*0Sstevel@tonic-gate name);
305*0Sstevel@tonic-gate
306*0Sstevel@tonic-gate return (fp);
307*0Sstevel@tonic-gate }
308*0Sstevel@tonic-gate
309*0Sstevel@tonic-gate /*
310*0Sstevel@tonic-gate * routine:
311*0Sstevel@tonic-gate * read_baseline
312*0Sstevel@tonic-gate *
313*0Sstevel@tonic-gate * purpose:
314*0Sstevel@tonic-gate * to read in the baseline file
315*0Sstevel@tonic-gate *
316*0Sstevel@tonic-gate * parameters:
317*0Sstevel@tonic-gate * name of baseline file
318*0Sstevel@tonic-gate *
319*0Sstevel@tonic-gate * returns:
320*0Sstevel@tonic-gate * error mask
321*0Sstevel@tonic-gate */
322*0Sstevel@tonic-gate errmask_t
read_baseline(char * name)323*0Sstevel@tonic-gate read_baseline(char *name)
324*0Sstevel@tonic-gate { FILE *file;
325*0Sstevel@tonic-gate errmask_t errs = 0;
326*0Sstevel@tonic-gate
327*0Sstevel@tonic-gate char *s;
328*0Sstevel@tonic-gate char *s1 = 0;
329*0Sstevel@tonic-gate char type;
330*0Sstevel@tonic-gate char *field = "???";
331*0Sstevel@tonic-gate
332*0Sstevel@tonic-gate unsigned long l;
333*0Sstevel@tonic-gate unsigned long long ll; /* intermediate for 64 bit file support */
334*0Sstevel@tonic-gate int level;
335*0Sstevel@tonic-gate int major, minor;
336*0Sstevel@tonic-gate
337*0Sstevel@tonic-gate struct base *bp = 0;
338*0Sstevel@tonic-gate struct file *fp;
339*0Sstevel@tonic-gate struct fileinfo *ip;
340*0Sstevel@tonic-gate aclent_t *ap;
341*0Sstevel@tonic-gate
342*0Sstevel@tonic-gate struct file *dirstack[ MAX_DEPTH ];
343*0Sstevel@tonic-gate
344*0Sstevel@tonic-gate file = fopen(name, "r");
345*0Sstevel@tonic-gate if (file == NULL) {
346*0Sstevel@tonic-gate fprintf(stderr, gettext(ERR_open), gettext(TXT_base),
347*0Sstevel@tonic-gate name);
348*0Sstevel@tonic-gate return (ERR_FILES);
349*0Sstevel@tonic-gate }
350*0Sstevel@tonic-gate lex_linenum = 0;
351*0Sstevel@tonic-gate
352*0Sstevel@tonic-gate if (opt_debug & DBG_FILES)
353*0Sstevel@tonic-gate fprintf(stderr, "FILE: READ BASELINE %s\n", name);
354*0Sstevel@tonic-gate
355*0Sstevel@tonic-gate while (!feof(file)) {
356*0Sstevel@tonic-gate /* find the first token on the line */
357*0Sstevel@tonic-gate s = lex(file);
358*0Sstevel@tonic-gate
359*0Sstevel@tonic-gate /* skip blank lines and comments */
360*0Sstevel@tonic-gate if (s == 0 || *s == 0 || *s == '#' || *s == '*')
361*0Sstevel@tonic-gate continue;
362*0Sstevel@tonic-gate
363*0Sstevel@tonic-gate field = "keyword";
364*0Sstevel@tonic-gate
365*0Sstevel@tonic-gate /* see if the first token is a known keyword */
366*0Sstevel@tonic-gate if (strcmp(s, "VERSION") == 0 || strcmp(s, BASE_TAG) == 0) {
367*0Sstevel@tonic-gate s = lex(0);
368*0Sstevel@tonic-gate field = gettext(TXT_noargs);
369*0Sstevel@tonic-gate if (s == 0)
370*0Sstevel@tonic-gate goto bad;
371*0Sstevel@tonic-gate
372*0Sstevel@tonic-gate major = strtol(s, &s1, 10);
373*0Sstevel@tonic-gate field = gettext(TXT_badver);
374*0Sstevel@tonic-gate if (*s1 != '.')
375*0Sstevel@tonic-gate goto bad;
376*0Sstevel@tonic-gate minor = strtol(&s1[1], 0, 10);
377*0Sstevel@tonic-gate
378*0Sstevel@tonic-gate if (major != BASE_MAJOR || minor > BASE_MINOR) {
379*0Sstevel@tonic-gate fprintf(stderr, gettext(ERR_badver),
380*0Sstevel@tonic-gate major, minor, gettext(TXT_base), name);
381*0Sstevel@tonic-gate errs |= ERR_FILES;
382*0Sstevel@tonic-gate }
383*0Sstevel@tonic-gate s1 = 0;
384*0Sstevel@tonic-gate continue;
385*0Sstevel@tonic-gate }
386*0Sstevel@tonic-gate
387*0Sstevel@tonic-gate if (strcmp(s, "BASE_SRC") == 0) {
388*0Sstevel@tonic-gate s = lex(0);
389*0Sstevel@tonic-gate field = "source directory";
390*0Sstevel@tonic-gate if (s == 0)
391*0Sstevel@tonic-gate goto bad;
392*0Sstevel@tonic-gate s1 = strdup(s);
393*0Sstevel@tonic-gate bp = 0;
394*0Sstevel@tonic-gate continue;
395*0Sstevel@tonic-gate }
396*0Sstevel@tonic-gate
397*0Sstevel@tonic-gate if (strcmp(s, "BASE_DST") == 0) {
398*0Sstevel@tonic-gate s = lex(0);
399*0Sstevel@tonic-gate field = "destination directory";
400*0Sstevel@tonic-gate if (s == 0)
401*0Sstevel@tonic-gate goto bad;
402*0Sstevel@tonic-gate
403*0Sstevel@tonic-gate /* make sure we have a source too */
404*0Sstevel@tonic-gate if (s1 == 0) {
405*0Sstevel@tonic-gate field = "no source directory";
406*0Sstevel@tonic-gate goto bad;
407*0Sstevel@tonic-gate }
408*0Sstevel@tonic-gate
409*0Sstevel@tonic-gate bp = add_base(s1, s);
410*0Sstevel@tonic-gate free(s1);
411*0Sstevel@tonic-gate s1 = 0;
412*0Sstevel@tonic-gate continue;
413*0Sstevel@tonic-gate }
414*0Sstevel@tonic-gate
415*0Sstevel@tonic-gate if (strcmp(s, "FILE") == 0) {
416*0Sstevel@tonic-gate /* make sure we have a base to add to */
417*0Sstevel@tonic-gate if (bp == 0) {
418*0Sstevel@tonic-gate field = "missing base";
419*0Sstevel@tonic-gate goto bad;
420*0Sstevel@tonic-gate }
421*0Sstevel@tonic-gate
422*0Sstevel@tonic-gate s = lex(0); /* level */
423*0Sstevel@tonic-gate field = "level";
424*0Sstevel@tonic-gate if (s == 0 || *s == 0)
425*0Sstevel@tonic-gate goto bad;
426*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
427*0Sstevel@tonic-gate level = l;
428*0Sstevel@tonic-gate
429*0Sstevel@tonic-gate s = lex(0); /* type */
430*0Sstevel@tonic-gate field = "file type";
431*0Sstevel@tonic-gate if (s == 0 || *s == 0)
432*0Sstevel@tonic-gate goto bad;
433*0Sstevel@tonic-gate type = *s;
434*0Sstevel@tonic-gate if (gettype(type) < 0)
435*0Sstevel@tonic-gate goto bad;
436*0Sstevel@tonic-gate
437*0Sstevel@tonic-gate s = lex(0); /* name */
438*0Sstevel@tonic-gate field = "file name";
439*0Sstevel@tonic-gate if (s == 0 || *s == 0)
440*0Sstevel@tonic-gate goto bad;
441*0Sstevel@tonic-gate
442*0Sstevel@tonic-gate /* allocate a file structure for this entry */
443*0Sstevel@tonic-gate if (level == 0)
444*0Sstevel@tonic-gate fp = add_file_to_base(bp, s);
445*0Sstevel@tonic-gate else
446*0Sstevel@tonic-gate fp = add_file_to_dir(dirstack[level-1], s);
447*0Sstevel@tonic-gate
448*0Sstevel@tonic-gate fp->f_flags |= F_IN_BASELINE;
449*0Sstevel@tonic-gate
450*0Sstevel@tonic-gate /* maintain the directory stack */
451*0Sstevel@tonic-gate if (level >= MAX_DEPTH) {
452*0Sstevel@tonic-gate fprintf(stderr, gettext(ERR_deep), s);
453*0Sstevel@tonic-gate exit(ERR_OTHER);
454*0Sstevel@tonic-gate }
455*0Sstevel@tonic-gate
456*0Sstevel@tonic-gate dirstack[ level ] = fp;
457*0Sstevel@tonic-gate
458*0Sstevel@tonic-gate /* get a pointer to the baseline file info structure */
459*0Sstevel@tonic-gate ip = &fp->f_info[ OPT_BASE ];
460*0Sstevel@tonic-gate
461*0Sstevel@tonic-gate ip->f_type = gettype(type); /* note file type */
462*0Sstevel@tonic-gate
463*0Sstevel@tonic-gate s = lex(0); /* modes */
464*0Sstevel@tonic-gate field = "file modes";
465*0Sstevel@tonic-gate if (s == 0 || *s == 0)
466*0Sstevel@tonic-gate goto bad;
467*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
468*0Sstevel@tonic-gate ip->f_mode = l;
469*0Sstevel@tonic-gate
470*0Sstevel@tonic-gate s = lex(0); /* uid */
471*0Sstevel@tonic-gate field = "file UID";
472*0Sstevel@tonic-gate if (s == 0 || *s == 0)
473*0Sstevel@tonic-gate goto bad;
474*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
475*0Sstevel@tonic-gate ip->f_uid = l;
476*0Sstevel@tonic-gate
477*0Sstevel@tonic-gate s = lex(0); /* gid */
478*0Sstevel@tonic-gate field = "file GID";
479*0Sstevel@tonic-gate if (s == 0 || *s == 0)
480*0Sstevel@tonic-gate goto bad;
481*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
482*0Sstevel@tonic-gate ip->f_gid = l;
483*0Sstevel@tonic-gate
484*0Sstevel@tonic-gate s = lex(0); /* source inode */
485*0Sstevel@tonic-gate field = "source i#";
486*0Sstevel@tonic-gate if (s == 0 || *s == 0)
487*0Sstevel@tonic-gate goto bad;
488*0Sstevel@tonic-gate ll = strtoull(s, 0, 0);
489*0Sstevel@tonic-gate fp->f_s_inum = (ino_t) ll;
490*0Sstevel@tonic-gate
491*0Sstevel@tonic-gate s = lex(0); /* source major */
492*0Sstevel@tonic-gate field = "source major";
493*0Sstevel@tonic-gate if (s == 0 || *s == 0)
494*0Sstevel@tonic-gate goto bad;
495*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
496*0Sstevel@tonic-gate fp->f_s_maj = l;
497*0Sstevel@tonic-gate
498*0Sstevel@tonic-gate s = lex(0); /* source minor */
499*0Sstevel@tonic-gate field = "source minor";
500*0Sstevel@tonic-gate if (s == 0 || *s == 0)
501*0Sstevel@tonic-gate goto bad;
502*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
503*0Sstevel@tonic-gate fp->f_s_min = l;
504*0Sstevel@tonic-gate
505*0Sstevel@tonic-gate s = lex(0); /* source nlink */
506*0Sstevel@tonic-gate field = "source nlink";
507*0Sstevel@tonic-gate if (s == 0 || *s == 0)
508*0Sstevel@tonic-gate goto bad;
509*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
510*0Sstevel@tonic-gate fp->f_s_nlink = l;
511*0Sstevel@tonic-gate
512*0Sstevel@tonic-gate s = lex(0); /* source mod */
513*0Sstevel@tonic-gate field = "source modtime";
514*0Sstevel@tonic-gate if (s == 0 || *s == 0)
515*0Sstevel@tonic-gate goto bad;
516*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
517*0Sstevel@tonic-gate fp->f_s_modtime = l;
518*0Sstevel@tonic-gate
519*0Sstevel@tonic-gate s = lex(0); /* dest inode */
520*0Sstevel@tonic-gate field = "destination i#";
521*0Sstevel@tonic-gate if (s == 0 || *s == 0)
522*0Sstevel@tonic-gate goto bad;
523*0Sstevel@tonic-gate ll = strtoull(s, 0, 0);
524*0Sstevel@tonic-gate fp->f_d_inum = (ino_t) ll;
525*0Sstevel@tonic-gate
526*0Sstevel@tonic-gate s = lex(0); /* dest major */
527*0Sstevel@tonic-gate field = "destination major";
528*0Sstevel@tonic-gate if (s == 0 || *s == 0)
529*0Sstevel@tonic-gate goto bad;
530*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
531*0Sstevel@tonic-gate fp->f_d_maj = l;
532*0Sstevel@tonic-gate
533*0Sstevel@tonic-gate s = lex(0); /* dest minor */
534*0Sstevel@tonic-gate field = "destination minor";
535*0Sstevel@tonic-gate if (s == 0 || *s == 0)
536*0Sstevel@tonic-gate goto bad;
537*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
538*0Sstevel@tonic-gate fp->f_d_min = l;
539*0Sstevel@tonic-gate
540*0Sstevel@tonic-gate s = lex(0); /* dest nlink */
541*0Sstevel@tonic-gate field = "dest nlink";
542*0Sstevel@tonic-gate if (s == 0 || *s == 0)
543*0Sstevel@tonic-gate goto bad;
544*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
545*0Sstevel@tonic-gate fp->f_d_nlink = l;
546*0Sstevel@tonic-gate
547*0Sstevel@tonic-gate s = lex(0); /* dest mod */
548*0Sstevel@tonic-gate field = "dest modtime";
549*0Sstevel@tonic-gate if (s == 0 || *s == 0)
550*0Sstevel@tonic-gate goto bad;
551*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
552*0Sstevel@tonic-gate fp->f_d_modtime = l;
553*0Sstevel@tonic-gate
554*0Sstevel@tonic-gate s = lex(0); /* major or size */
555*0Sstevel@tonic-gate
556*0Sstevel@tonic-gate if (type == 'C' || type == 'B') {
557*0Sstevel@tonic-gate field = "rdev major";
558*0Sstevel@tonic-gate if (s == 0 || *s == 0)
559*0Sstevel@tonic-gate goto bad;
560*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
561*0Sstevel@tonic-gate ip->f_rd_maj = l;
562*0Sstevel@tonic-gate
563*0Sstevel@tonic-gate s = lex(0); /* minor */
564*0Sstevel@tonic-gate field = "rdev minor";
565*0Sstevel@tonic-gate if (s == 0 || *s == 0)
566*0Sstevel@tonic-gate goto bad;
567*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
568*0Sstevel@tonic-gate ip->f_rd_min = l;
569*0Sstevel@tonic-gate } else {
570*0Sstevel@tonic-gate field = "file size";
571*0Sstevel@tonic-gate if (s == 0 || *s == 0)
572*0Sstevel@tonic-gate goto bad;
573*0Sstevel@tonic-gate ll = strtoul(s, 0, 0);
574*0Sstevel@tonic-gate ip->f_size = (off_t) ll; /* size */
575*0Sstevel@tonic-gate }
576*0Sstevel@tonic-gate
577*0Sstevel@tonic-gate /*
578*0Sstevel@tonic-gate * all fields after this point were added to the
579*0Sstevel@tonic-gate * 1.0 format and so should be considered optional
580*0Sstevel@tonic-gate */
581*0Sstevel@tonic-gate s = lex(0); /* acl length ? */
582*0Sstevel@tonic-gate field = "acl count";
583*0Sstevel@tonic-gate if (s && *s) {
584*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
585*0Sstevel@tonic-gate ip->f_numacls = l;
586*0Sstevel@tonic-gate ip->f_acls = (aclent_t *) malloc(ip->f_numacls *
587*0Sstevel@tonic-gate sizeof (aclent_t));
588*0Sstevel@tonic-gate if (ip->f_acls == 0)
589*0Sstevel@tonic-gate nomem("Access Control List");
590*0Sstevel@tonic-gate }
591*0Sstevel@tonic-gate
592*0Sstevel@tonic-gate continue;
593*0Sstevel@tonic-gate }
594*0Sstevel@tonic-gate
595*0Sstevel@tonic-gate if (strcmp(s, "ACL") == 0) {
596*0Sstevel@tonic-gate /* make sure there is a place to put the ACL */
597*0Sstevel@tonic-gate if (ip == 0 || ip->f_acls == 0) {
598*0Sstevel@tonic-gate field = "ACL w/o FILE/LIST";
599*0Sstevel@tonic-gate goto bad;
600*0Sstevel@tonic-gate }
601*0Sstevel@tonic-gate
602*0Sstevel@tonic-gate /* acl entry number */
603*0Sstevel@tonic-gate s = lex(0);
604*0Sstevel@tonic-gate field = "acl index";
605*0Sstevel@tonic-gate if (s == 0)
606*0Sstevel@tonic-gate goto bad;
607*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
608*0Sstevel@tonic-gate if (l >= ip->f_numacls)
609*0Sstevel@tonic-gate goto bad;
610*0Sstevel@tonic-gate else
611*0Sstevel@tonic-gate ap = &ip->f_acls[l];
612*0Sstevel@tonic-gate
613*0Sstevel@tonic-gate /* acl entry type */
614*0Sstevel@tonic-gate s = lex(0);
615*0Sstevel@tonic-gate field = "acl type";
616*0Sstevel@tonic-gate if (s == 0)
617*0Sstevel@tonic-gate goto bad;
618*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
619*0Sstevel@tonic-gate ap->a_type = l;
620*0Sstevel@tonic-gate
621*0Sstevel@tonic-gate /* acl entry ID */
622*0Sstevel@tonic-gate s = lex(0);
623*0Sstevel@tonic-gate field = "acl id";
624*0Sstevel@tonic-gate if (s == 0)
625*0Sstevel@tonic-gate goto bad;
626*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
627*0Sstevel@tonic-gate ap->a_id = l;
628*0Sstevel@tonic-gate
629*0Sstevel@tonic-gate /* acl entry perms */
630*0Sstevel@tonic-gate s = lex(0);
631*0Sstevel@tonic-gate field = "acl perm";
632*0Sstevel@tonic-gate if (s == 0)
633*0Sstevel@tonic-gate goto bad;
634*0Sstevel@tonic-gate l = strtoul(s, 0, 0);
635*0Sstevel@tonic-gate ap->a_perm = l;
636*0Sstevel@tonic-gate
637*0Sstevel@tonic-gate continue;
638*0Sstevel@tonic-gate }
639*0Sstevel@tonic-gate
640*0Sstevel@tonic-gate bad: /* log the error and continue processing to find others */
641*0Sstevel@tonic-gate fprintf(stderr, gettext(ERR_badinput), lex_linenum,
642*0Sstevel@tonic-gate field, name);
643*0Sstevel@tonic-gate errs |= ERR_FILES;
644*0Sstevel@tonic-gate }
645*0Sstevel@tonic-gate
646*0Sstevel@tonic-gate (void) fclose(file);
647*0Sstevel@tonic-gate return (errs);
648*0Sstevel@tonic-gate }
649*0Sstevel@tonic-gate
650*0Sstevel@tonic-gate /*
651*0Sstevel@tonic-gate * routine:
652*0Sstevel@tonic-gate * write_baseline
653*0Sstevel@tonic-gate *
654*0Sstevel@tonic-gate * purpose:
655*0Sstevel@tonic-gate * to rewrite the baseline file
656*0Sstevel@tonic-gate *
657*0Sstevel@tonic-gate * parameters:
658*0Sstevel@tonic-gate * name of the new baseline file
659*0Sstevel@tonic-gate *
660*0Sstevel@tonic-gate * returns:
661*0Sstevel@tonic-gate * error mask
662*0Sstevel@tonic-gate */
663*0Sstevel@tonic-gate errmask_t
write_baseline(char * name)664*0Sstevel@tonic-gate write_baseline(char *name)
665*0Sstevel@tonic-gate { FILE *newfile;
666*0Sstevel@tonic-gate errmask_t errs = 0;
667*0Sstevel@tonic-gate struct base *bp;
668*0Sstevel@tonic-gate char tmpname[ MAX_PATH ];
669*0Sstevel@tonic-gate
670*0Sstevel@tonic-gate if (opt_debug & DBG_FILES)
671*0Sstevel@tonic-gate fprintf(stderr, "FILE: WRITE BASELINE %s\n", name);
672*0Sstevel@tonic-gate
673*0Sstevel@tonic-gate /* if no-touch is specified, we don't update files */
674*0Sstevel@tonic-gate if (opt_notouch)
675*0Sstevel@tonic-gate return (0);
676*0Sstevel@tonic-gate
677*0Sstevel@tonic-gate /* create a temporary output file */
678*0Sstevel@tonic-gate sprintf(tmpname, "%s-TMP", name);
679*0Sstevel@tonic-gate
680*0Sstevel@tonic-gate /* create our output file */
681*0Sstevel@tonic-gate newfile = fopen(tmpname, "w+");
682*0Sstevel@tonic-gate if (newfile == NULL) {
683*0Sstevel@tonic-gate fprintf(stderr, gettext(ERR_creat), gettext(TXT_base),
684*0Sstevel@tonic-gate tmpname);
685*0Sstevel@tonic-gate return (ERR_FILES);
686*0Sstevel@tonic-gate }
687*0Sstevel@tonic-gate
688*0Sstevel@tonic-gate errs |= bw_header(newfile);
689*0Sstevel@tonic-gate for (bp = bases; bp; bp = bp->b_next)
690*0Sstevel@tonic-gate errs |= bw_base(newfile, bp);
691*0Sstevel@tonic-gate
692*0Sstevel@tonic-gate if (ferror(newfile)) {
693*0Sstevel@tonic-gate fprintf(stderr, gettext(ERR_write), gettext(TXT_base),
694*0Sstevel@tonic-gate tmpname);
695*0Sstevel@tonic-gate errs |= ERR_FILES;
696*0Sstevel@tonic-gate }
697*0Sstevel@tonic-gate
698*0Sstevel@tonic-gate if (fclose(newfile)) {
699*0Sstevel@tonic-gate fprintf(stderr, gettext(ERR_fclose), gettext(TXT_base),
700*0Sstevel@tonic-gate tmpname);
701*0Sstevel@tonic-gate errs |= ERR_FILES;
702*0Sstevel@tonic-gate }
703*0Sstevel@tonic-gate
704*0Sstevel@tonic-gate /* now switch the new file for the old one */
705*0Sstevel@tonic-gate if (errs == 0)
706*0Sstevel@tonic-gate if (rename(tmpname, name) != 0) {
707*0Sstevel@tonic-gate fprintf(stderr, gettext(ERR_rename),
708*0Sstevel@tonic-gate gettext(TXT_base), tmpname, name);
709*0Sstevel@tonic-gate errs |= ERR_FILES;
710*0Sstevel@tonic-gate }
711*0Sstevel@tonic-gate
712*0Sstevel@tonic-gate return (errs);
713*0Sstevel@tonic-gate }
714*0Sstevel@tonic-gate
715*0Sstevel@tonic-gate /*
716*0Sstevel@tonic-gate * routine:
717*0Sstevel@tonic-gate * bw_header
718*0Sstevel@tonic-gate *
719*0Sstevel@tonic-gate * purpose:
720*0Sstevel@tonic-gate * to write out a baseline header
721*0Sstevel@tonic-gate *
722*0Sstevel@tonic-gate * parameters:
723*0Sstevel@tonic-gate * FILE* for the output file
724*0Sstevel@tonic-gate *
725*0Sstevel@tonic-gate * returns:
726*0Sstevel@tonic-gate * error mask
727*0Sstevel@tonic-gate *
728*0Sstevel@tonic-gate * notes:
729*0Sstevel@tonic-gate */
730*0Sstevel@tonic-gate static errmask_t
bw_header(FILE * file)731*0Sstevel@tonic-gate bw_header(FILE *file)
732*0Sstevel@tonic-gate { time_t now;
733*0Sstevel@tonic-gate struct tm *local;
734*0Sstevel@tonic-gate
735*0Sstevel@tonic-gate /* figure out what time it is */
736*0Sstevel@tonic-gate (void) time(&now);
737*0Sstevel@tonic-gate local = localtime(&now);
738*0Sstevel@tonic-gate
739*0Sstevel@tonic-gate fprintf(file, "%s %d.%d\n", BASE_TAG, BASE_MAJOR, BASE_MINOR);
740*0Sstevel@tonic-gate fprintf(file, "#\n");
741*0Sstevel@tonic-gate fprintf(file, "# filesync baseline, last written by %s, %s",
742*0Sstevel@tonic-gate cuserid((char *) 0), asctime(local));
743*0Sstevel@tonic-gate fprintf(file, "#\n");
744*0Sstevel@tonic-gate
745*0Sstevel@tonic-gate return (0);
746*0Sstevel@tonic-gate }
747*0Sstevel@tonic-gate
748*0Sstevel@tonic-gate /*
749*0Sstevel@tonic-gate * routine:
750*0Sstevel@tonic-gate * bw_base
751*0Sstevel@tonic-gate *
752*0Sstevel@tonic-gate * purpose:
753*0Sstevel@tonic-gate * to write out the summary for one base-pair
754*0Sstevel@tonic-gate *
755*0Sstevel@tonic-gate * parameters:
756*0Sstevel@tonic-gate * FILE * for the output file
757*0Sstevel@tonic-gate *
758*0Sstevel@tonic-gate * returns:
759*0Sstevel@tonic-gate * error mask
760*0Sstevel@tonic-gate *
761*0Sstevel@tonic-gate * notes:
762*0Sstevel@tonic-gate */
763*0Sstevel@tonic-gate static errmask_t
bw_base(FILE * file,struct base * bp)764*0Sstevel@tonic-gate bw_base(FILE *file, struct base *bp)
765*0Sstevel@tonic-gate { struct file *fp;
766*0Sstevel@tonic-gate errmask_t errs = 0;
767*0Sstevel@tonic-gate
768*0Sstevel@tonic-gate /* see if this base is to be dropped from baseline */
769*0Sstevel@tonic-gate if (bp->b_flags & F_REMOVE)
770*0Sstevel@tonic-gate return (0);
771*0Sstevel@tonic-gate
772*0Sstevel@tonic-gate fprintf(file, "\n");
773*0Sstevel@tonic-gate fprintf(file, "BASE_SRC %s\n", noblanks(bp->b_src_spec));
774*0Sstevel@tonic-gate fprintf(file, "BASE_DST %s\n", noblanks(bp->b_dst_spec));
775*0Sstevel@tonic-gate
776*0Sstevel@tonic-gate for (fp = bp->b_files; fp; fp = fp->f_next)
777*0Sstevel@tonic-gate errs |= bw_file(file, fp, 0);
778*0Sstevel@tonic-gate
779*0Sstevel@tonic-gate return (errs);
780*0Sstevel@tonic-gate }
781*0Sstevel@tonic-gate
782*0Sstevel@tonic-gate /*
783*0Sstevel@tonic-gate * routine:
784*0Sstevel@tonic-gate * bw_file
785*0Sstevel@tonic-gate *
786*0Sstevel@tonic-gate * purpose:
787*0Sstevel@tonic-gate * to write a file description out to the baseline
788*0Sstevel@tonic-gate *
789*0Sstevel@tonic-gate * parameters:
790*0Sstevel@tonic-gate * output FILE
791*0Sstevel@tonic-gate * pointer to file description
792*0Sstevel@tonic-gate * recursion depth
793*0Sstevel@tonic-gate *
794*0Sstevel@tonic-gate * returns:
795*0Sstevel@tonic-gate * error mask
796*0Sstevel@tonic-gate *
797*0Sstevel@tonic-gate * notes:
798*0Sstevel@tonic-gate * some of the information we write out is kept separately
799*0Sstevel@tonic-gate * for source and destination files because the values should
800*0Sstevel@tonic-gate * be expected to be different for different systems/copies.
801*0Sstevel@tonic-gate *
802*0Sstevel@tonic-gate * if a file has an unresolved conflict, we want to leave
803*0Sstevel@tonic-gate * the old values in place so that we continue to compare
804*0Sstevel@tonic-gate * files against the last time they agreed.
805*0Sstevel@tonic-gate */
806*0Sstevel@tonic-gate static errmask_t
bw_file(FILE * file,struct file * fp,int depth)807*0Sstevel@tonic-gate bw_file(FILE *file, struct file *fp, int depth)
808*0Sstevel@tonic-gate { struct file *cp;
809*0Sstevel@tonic-gate int i;
810*0Sstevel@tonic-gate errmask_t errs = 0;
811*0Sstevel@tonic-gate long long ll; /* intermediate for 64 bit file support */
812*0Sstevel@tonic-gate struct fileinfo *ip = &fp->f_info[OPT_BASE];
813*0Sstevel@tonic-gate
814*0Sstevel@tonic-gate /* if this file is to be removed from baseline, skip it */
815*0Sstevel@tonic-gate if (fp->f_flags & F_REMOVE)
816*0Sstevel@tonic-gate return (0);
817*0Sstevel@tonic-gate
818*0Sstevel@tonic-gate /*
819*0Sstevel@tonic-gate * if this node is in conflict, or if it has not been
820*0Sstevel@tonic-gate * evaluated this time around, we should just leave the
821*0Sstevel@tonic-gate * baseline file the way it was before. If there is a
822*0Sstevel@tonic-gate * conflict, let the baseline reflect the last agreement.
823*0Sstevel@tonic-gate * If the node wasn't evaluated, let the baseline reflect
824*0Sstevel@tonic-gate * our last knowledge.
825*0Sstevel@tonic-gate */
826*0Sstevel@tonic-gate if (fp->f_flags & F_CONFLICT || (fp->f_flags&F_EVALUATE) == 0) {
827*0Sstevel@tonic-gate fp->f_info[OPT_SRC].f_ino = fp->f_s_inum;
828*0Sstevel@tonic-gate fp->f_info[OPT_SRC].f_nlink = fp->f_s_nlink;
829*0Sstevel@tonic-gate fp->f_info[OPT_SRC].f_d_maj = fp->f_s_maj;
830*0Sstevel@tonic-gate fp->f_info[OPT_SRC].f_d_min = fp->f_s_min;
831*0Sstevel@tonic-gate fp->f_info[OPT_SRC].f_modtime = fp->f_s_modtime;
832*0Sstevel@tonic-gate fp->f_info[OPT_DST].f_ino = fp->f_d_inum;
833*0Sstevel@tonic-gate fp->f_info[OPT_DST].f_nlink = fp->f_d_nlink;
834*0Sstevel@tonic-gate fp->f_info[OPT_DST].f_d_maj = fp->f_d_maj;
835*0Sstevel@tonic-gate fp->f_info[OPT_DST].f_d_min = fp->f_d_min;
836*0Sstevel@tonic-gate fp->f_info[OPT_DST].f_modtime = fp->f_d_modtime;
837*0Sstevel@tonic-gate }
838*0Sstevel@tonic-gate
839*0Sstevel@tonic-gate /* write out the entry for this file */
840*0Sstevel@tonic-gate fprintf(file, "FILE %d %c %-20s 0%04o", depth, showtype(ip->f_type),
841*0Sstevel@tonic-gate noblanks(fp->f_name), ip->f_mode);
842*0Sstevel@tonic-gate fprintf(file, " %6ld %6ld", ip->f_uid, ip->f_gid);
843*0Sstevel@tonic-gate
844*0Sstevel@tonic-gate ll = fp->f_info[OPT_SRC].f_ino;
845*0Sstevel@tonic-gate fprintf(file, "\t%6lld %4ld %4ld %4d 0x%08lx",
846*0Sstevel@tonic-gate ll,
847*0Sstevel@tonic-gate fp->f_info[OPT_SRC].f_d_maj,
848*0Sstevel@tonic-gate fp->f_info[OPT_SRC].f_d_min,
849*0Sstevel@tonic-gate fp->f_info[OPT_SRC].f_nlink,
850*0Sstevel@tonic-gate fp->f_info[OPT_SRC].f_modtime);
851*0Sstevel@tonic-gate
852*0Sstevel@tonic-gate ll = fp->f_info[OPT_DST].f_ino;
853*0Sstevel@tonic-gate fprintf(file, "\t%6lld %4ld %4ld %4d 0x%08lx",
854*0Sstevel@tonic-gate ll,
855*0Sstevel@tonic-gate fp->f_info[OPT_DST].f_d_maj,
856*0Sstevel@tonic-gate fp->f_info[OPT_DST].f_d_min,
857*0Sstevel@tonic-gate fp->f_info[OPT_DST].f_nlink,
858*0Sstevel@tonic-gate fp->f_info[OPT_DST].f_modtime);
859*0Sstevel@tonic-gate
860*0Sstevel@tonic-gate /* last fields are file type specific */
861*0Sstevel@tonic-gate if (S_ISBLK(ip->f_type) || S_ISCHR(ip->f_type))
862*0Sstevel@tonic-gate fprintf(file, "\t%4ld %4ld", ip->f_rd_maj, ip->f_rd_min);
863*0Sstevel@tonic-gate else {
864*0Sstevel@tonic-gate ll = ip->f_size;
865*0Sstevel@tonic-gate fprintf(file, "\t%lld", ll);
866*0Sstevel@tonic-gate }
867*0Sstevel@tonic-gate
868*0Sstevel@tonic-gate /* ACL count goes at the end because it was added */
869*0Sstevel@tonic-gate fprintf(file, "\t%d", ip->f_numacls);
870*0Sstevel@tonic-gate
871*0Sstevel@tonic-gate fprintf(file, "\n");
872*0Sstevel@tonic-gate
873*0Sstevel@tonic-gate /* if this file has ACLs, we have to write them out too */
874*0Sstevel@tonic-gate for (i = 0; i < ip->f_numacls; i++)
875*0Sstevel@tonic-gate fprintf(file, "ACL %d %d %ld %o\n", i, ip->f_acls[i].a_type,
876*0Sstevel@tonic-gate ip->f_acls[i].a_id, ip->f_acls[i].a_perm);
877*0Sstevel@tonic-gate
878*0Sstevel@tonic-gate /* then enumerate all of the children (if any) */
879*0Sstevel@tonic-gate for (cp = fp->f_files; cp; cp = cp->f_next)
880*0Sstevel@tonic-gate errs |= bw_file(file, cp, depth + 1);
881*0Sstevel@tonic-gate
882*0Sstevel@tonic-gate return (errs);
883*0Sstevel@tonic-gate }
884*0Sstevel@tonic-gate
885*0Sstevel@tonic-gate /*
886*0Sstevel@tonic-gate * routines:
887*0Sstevel@tonic-gate * gettype/showtype
888*0Sstevel@tonic-gate *
889*0Sstevel@tonic-gate * purpose:
890*0Sstevel@tonic-gate * to convert between a file type (as found in a mode word)
891*0Sstevel@tonic-gate * and a single character representation
892*0Sstevel@tonic-gate *
893*0Sstevel@tonic-gate * parameters/return
894*0Sstevel@tonic-gate * mode word -> character
895*0Sstevel@tonic-gate * character -> mode word
896*0Sstevel@tonic-gate */
897*0Sstevel@tonic-gate static char types[16] = "-PC?DNB?F?S?s???";
898*0Sstevel@tonic-gate
showtype(int mode)899*0Sstevel@tonic-gate static char showtype(int mode)
900*0Sstevel@tonic-gate {
901*0Sstevel@tonic-gate return (types[ (mode & S_IFMT) >> 12 ]);
902*0Sstevel@tonic-gate }
903*0Sstevel@tonic-gate
gettype(int code)904*0Sstevel@tonic-gate static long gettype(int code)
905*0Sstevel@tonic-gate { int i;
906*0Sstevel@tonic-gate
907*0Sstevel@tonic-gate for (i = 0; i < 16; i++)
908*0Sstevel@tonic-gate if (types[i] == code)
909*0Sstevel@tonic-gate return (i << 12);
910*0Sstevel@tonic-gate
911*0Sstevel@tonic-gate return (-1);
912*0Sstevel@tonic-gate }
913