]>
git.cameronkatri.com Git - apple_cmds.git/blob - file_cmds/mtree/specspec.c
2 * Copyright (c) 2003 Poul-Henning Kamp
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD: src/usr.sbin/mtree/specspec.c,v 1.6 2005/03/29 11:44:17 tobez Exp $");
30 #include <sys/param.h>
41 #define FF(a, b, c, d) \
42 (((a)->flags & (c)) && ((b)->flags & (c)) && ((a)->d) != ((b)->d))
43 #define FS(a, b, c, d) \
44 (((a)->flags & (c)) && ((b)->flags & (c)) && strcmp((a)->d,(b)->d))
45 #define FM(a, b, c, d) \
46 (((a)->flags & (c)) && ((b)->flags & (c)) && memcmp(&(a)->d,&(b)->d, sizeof (a)->d))
49 shownode(NODE
*n
, int f
, char const *path
)
54 printf("%s%s %s", path
, n
->name
, ftype(n
->type
));
56 printf(" cksum=%lu", n
->cksum
);
58 printf(" gid=%d", n
->st_gid
);
60 gr
= getgrgid(n
->st_gid
);
62 printf(" gid=%d", n
->st_gid
);
64 printf(" gname=%s", gr
->gr_name
);
67 printf(" mode=%o", n
->st_mode
);
69 printf(" nlink=%d", n
->st_nlink
);
71 printf(" size=%jd", (intmax_t)n
->st_size
);
73 printf(" time=%ld.%09ld", n
->st_mtimespec
.tv_sec
, n
->st_mtimespec
.tv_nsec
);
75 printf(" uid=%d", n
->st_uid
);
77 pw
= getpwuid(n
->st_uid
);
79 printf(" uid=%d", n
->st_uid
);
81 printf(" uname=%s", pw
->pw_name
);
84 printf(" md5digest=%s", n
->md5digest
);
86 printf(" sha1digest=%s", n
->sha1digest
);
88 printf(" rmd160digest=%s", n
->rmd160digest
);
90 printf(" sha256digest=%s", n
->sha256digest
);
92 printf(" flags=%s", flags_to_string(n
->st_flags
));
94 printf(" btime=%ld.%09ld", n
->st_birthtimespec
.tv_sec
, n
->st_birthtimespec
.tv_nsec
);
96 printf(" atime=%ld.%09ld", n
->st_atimespec
.tv_sec
, n
->st_atimespec
.tv_nsec
);
98 printf(" ctime=%ld.%09ld", n
->st_ctimespec
.tv_sec
, n
->st_ctimespec
.tv_nsec
);
100 printf(" ptime=%ld.%09ld", n
->st_ptimespec
.tv_sec
, n
->st_ptimespec
.tv_nsec
);
102 printf(" xattrsdigest=%s.%llu", n
->xattrsdigest
, n
->xdstream_priv_id
);
104 printf(" inode=%llu", n
->st_ino
);
106 printf(" acldigest=%s", n
->acldigest
);
108 printf(" siblingid=%llu", n
->sibling_id
);
114 mismatch(NODE
*n1
, NODE
*n2
, int differ
, char const *path
)
118 shownode(n1
, differ
, path
);
123 shownode(n2
, differ
, path
);
126 if (!(differ
& keys
))
129 shownode(n1
, differ
, path
);
131 shownode(n2
, differ
, path
);
136 compare_nodes(NODE
*n1
, NODE
*n2
, char const *path
)
140 if (n1
!= NULL
&& n1
->type
== F_LINK
)
141 n1
->flags
&= ~F_MODE
;
142 if (n2
!= NULL
&& n2
->type
== F_LINK
)
143 n2
->flags
&= ~F_MODE
;
145 if ((n1
== NULL
) && (n2
== NULL
)) {
147 } else if (n1
== NULL
) {
149 RECORD_FAILURE(111, WARN_MISMATCH
);
150 mismatch(n1
, n2
, differs
, path
);
152 } else if (n2
== NULL
) {
154 RECORD_FAILURE(112, WARN_MISMATCH
);
155 mismatch(n1
, n2
, differs
, path
);
157 } else if (n1
->type
!= n2
->type
) {
159 RECORD_FAILURE(113, WARN_MISMATCH
);
160 mismatch(n1
, n2
, differs
, path
);
163 if (FF(n1
, n2
, F_CKSUM
, cksum
))
165 if (FF(n1
, n2
, F_GID
, st_gid
))
167 if (FF(n1
, n2
, F_GNAME
, st_gid
))
169 if (FF(n1
, n2
, F_MODE
, st_mode
))
171 if (FF(n1
, n2
, F_NLINK
, st_nlink
))
173 if (FF(n1
, n2
, F_SIZE
, st_size
))
175 if (FS(n1
, n2
, F_SLINK
, slink
))
177 if (FM(n1
, n2
, F_TIME
, st_mtimespec
))
179 if (FF(n1
, n2
, F_UID
, st_uid
))
181 if (FF(n1
, n2
, F_UNAME
, st_uid
))
183 if (FS(n1
, n2
, F_MD5
, md5digest
))
185 if (FS(n1
, n2
, F_SHA1
, sha1digest
))
187 if (FS(n1
, n2
, F_RMD160
, rmd160digest
))
189 if (FS(n1
, n2
, F_SHA256
, sha256digest
))
191 if (FF(n1
, n2
, F_FLAGS
, st_flags
))
193 if (FM(n1
, n2
, F_BTIME
, st_birthtimespec
))
195 if (FM(n1
, n2
, F_ATIME
, st_atimespec
))
197 if (FM(n1
, n2
, F_CTIME
, st_ctimespec
))
199 if (FM(n1
, n2
, F_PTIME
, st_ptimespec
))
201 if (FS(n1
, n2
, F_XATTRS
, xattrsdigest
))
203 if (FF(n1
, n2
, F_INODE
, st_ino
))
205 if (FS(n1
, n2
, F_ACL
, acldigest
))
207 if (FF(n1
, n2
, F_SIBLINGID
, sibling_id
))
208 differs
|= F_SIBLINGID
;
211 RECORD_FAILURE(114, WARN_MISMATCH
);
212 mismatch(n1
, n2
, differs
, path
);
218 walk_in_the_forest(NODE
*t1
, NODE
*t2
, char const *path
)
221 NODE
*c1
, *c2
, *n1
, *n2
;
234 while (c1
!= NULL
|| c2
!= NULL
) {
240 if (c1
!= NULL
&& c2
!= NULL
) {
241 if (c1
->type
!= F_DIR
&& c2
->type
== F_DIR
) {
244 } else if (c1
->type
== F_DIR
&& c2
->type
!= F_DIR
) {
248 i
= strcmp(c1
->name
, c2
->name
);
258 if (c1
== NULL
&& c2
->type
== F_DIR
) {
259 asprintf(&np
, "%s%s/", path
, c2
->name
);
260 i
= walk_in_the_forest(c1
, c2
, np
);
262 RECORD_FAILURE(115, WARN_MISMATCH
);
265 c
= compare_nodes(c1
, c2
, path
);
267 RECORD_FAILURE(116, WARN_MISMATCH
);
270 } else if (c2
== NULL
&& c1
->type
== F_DIR
) {
271 asprintf(&np
, "%s%s/", path
, c1
->name
);
272 i
= walk_in_the_forest(c1
, c2
, np
);
274 RECORD_FAILURE(117, WARN_MISMATCH
);
277 c
= compare_nodes(c1
, c2
, path
);
279 RECORD_FAILURE(118, WARN_MISMATCH
);
282 } else if (c1
== NULL
|| c2
== NULL
) {
283 i
= compare_nodes(c1
, c2
, path
);
285 RECORD_FAILURE(119, WARN_MISMATCH
);
287 } else if (c1
->type
== F_DIR
&& c2
->type
== F_DIR
) {
288 asprintf(&np
, "%s%s/", path
, c1
->name
);
289 i
= walk_in_the_forest(c1
, c2
, np
);
291 RECORD_FAILURE(120, WARN_MISMATCH
);
294 c
= compare_nodes(c1
, c2
, path
);
296 RECORD_FAILURE(121, WARN_MISMATCH
);
300 i
= compare_nodes(c1
, c2
, path
);
302 RECORD_FAILURE(122, WARN_MISMATCH
);
313 mtree_specspec(FILE *fi
, FILE *fj
)
318 root1
= mtree_readspec(fi
);
319 root2
= mtree_readspec(fj
);
320 rval
= walk_in_the_forest(root1
, root2
, "");
321 rval
+= compare_nodes(root1
, root2
, "");
323 RECORD_FAILURE(123, WARN_MISMATCH
);
324 return (MISMATCHEXIT
);