]>
git.saurik.com Git - apple/file_cmds.git/blob - 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>
40 #define FF(a, b, c, d) \
41 (((a)->flags & (c)) && ((b)->flags & (c)) && ((a)->d) != ((b)->d))
42 #define FS(a, b, c, d) \
43 (((a)->flags & (c)) && ((b)->flags & (c)) && strcmp((a)->d,(b)->d))
44 #define FM(a, b, c, d) \
45 (((a)->flags & (c)) && ((b)->flags & (c)) && memcmp(&(a)->d,&(b)->d, sizeof (a)->d))
48 shownode(NODE
*n
, int f
, char const *path
)
53 printf("%s%s %s", path
, n
->name
, ftype(n
->type
));
55 printf(" cksum=%lu", n
->cksum
);
57 printf(" gid=%d", n
->st_gid
);
59 gr
= getgrgid(n
->st_gid
);
61 printf(" gid=%d", n
->st_gid
);
63 printf(" gname=%s", gr
->gr_name
);
66 printf(" mode=%o", n
->st_mode
);
68 printf(" nlink=%d", n
->st_nlink
);
70 printf(" size=%jd", (intmax_t)n
->st_size
);
72 printf(" time=%ld.%09ld", n
->st_mtimespec
.tv_sec
, n
->st_mtimespec
.tv_nsec
);
74 printf(" uid=%d", n
->st_uid
);
76 pw
= getpwuid(n
->st_uid
);
78 printf(" uid=%d", n
->st_uid
);
80 printf(" uname=%s", pw
->pw_name
);
83 printf(" md5digest=%s", n
->md5digest
);
85 printf(" sha1digest=%s", n
->sha1digest
);
87 printf(" rmd160digest=%s", n
->rmd160digest
);
89 printf(" sha256digest=%s", n
->sha256digest
);
91 printf(" flags=%s", flags_to_string(n
->st_flags
));
93 printf(" btime=%ld.%09ld", n
->st_birthtimespec
.tv_sec
, n
->st_birthtimespec
.tv_nsec
);
95 printf(" atime=%ld.%09ld", n
->st_atimespec
.tv_sec
, n
->st_atimespec
.tv_nsec
);
97 printf(" ctime=%ld.%09ld", n
->st_ctimespec
.tv_sec
, n
->st_ctimespec
.tv_nsec
);
99 printf(" ptime=%ld.%09ld", n
->st_ptimespec
.tv_sec
, n
->st_ptimespec
.tv_nsec
);
101 printf(" xattrsdigest=%s", n
->xattrsdigest
);
103 printf(" inode=%llu", n
->st_ino
);
105 printf(" acldigest=%s", n
->acldigest
);
111 mismatch(NODE
*n1
, NODE
*n2
, int differ
, char const *path
)
115 shownode(n1
, differ
, path
);
120 shownode(n2
, differ
, path
);
123 if (!(differ
& keys
))
126 shownode(n1
, differ
, path
);
128 shownode(n2
, differ
, path
);
133 compare_nodes(NODE
*n1
, NODE
*n2
, char const *path
)
137 if (n1
!= NULL
&& n1
->type
== F_LINK
)
138 n1
->flags
&= ~F_MODE
;
139 if (n2
!= NULL
&& n2
->type
== F_LINK
)
140 n2
->flags
&= ~F_MODE
;
142 if ((n1
== NULL
) && (n2
== NULL
)) {
144 } else if (n1
== NULL
) {
146 mismatch(n1
, n2
, differs
, path
);
148 } else if (n2
== NULL
) {
150 mismatch(n1
, n2
, differs
, path
);
152 } else if (n1
->type
!= n2
->type
) {
154 mismatch(n1
, n2
, differs
, path
);
157 if (FF(n1
, n2
, F_CKSUM
, cksum
))
159 if (FF(n1
, n2
, F_GID
, st_gid
))
161 if (FF(n1
, n2
, F_GNAME
, st_gid
))
163 if (FF(n1
, n2
, F_MODE
, st_mode
))
165 if (FF(n1
, n2
, F_NLINK
, st_nlink
))
167 if (FF(n1
, n2
, F_SIZE
, st_size
))
169 if (FS(n1
, n2
, F_SLINK
, slink
))
171 if (FM(n1
, n2
, F_TIME
, st_mtimespec
))
173 if (FF(n1
, n2
, F_UID
, st_uid
))
175 if (FF(n1
, n2
, F_UNAME
, st_uid
))
177 if (FS(n1
, n2
, F_MD5
, md5digest
))
179 if (FS(n1
, n2
, F_SHA1
, sha1digest
))
181 if (FS(n1
, n2
, F_RMD160
, rmd160digest
))
183 if (FS(n1
, n2
, F_SHA256
, sha256digest
))
185 if (FF(n1
, n2
, F_FLAGS
, st_flags
))
187 if (FM(n1
, n2
, F_BTIME
, st_birthtimespec
))
189 if (FM(n1
, n2
, F_ATIME
, st_atimespec
))
191 if (FM(n1
, n2
, F_CTIME
, st_ctimespec
))
193 if (FM(n1
, n2
, F_PTIME
, st_ptimespec
))
195 if (FS(n1
, n2
, F_XATTRS
, xattrsdigest
))
197 if (FF(n1
, n2
, F_INODE
, st_ino
))
199 if (FS(n1
, n2
, F_ACL
, acldigest
))
203 mismatch(n1
, n2
, differs
, path
);
209 walk_in_the_forest(NODE
*t1
, NODE
*t2
, char const *path
)
212 NODE
*c1
, *c2
, *n1
, *n2
;
225 while (c1
!= NULL
|| c2
!= NULL
) {
231 if (c1
!= NULL
&& c2
!= NULL
) {
232 if (c1
->type
!= F_DIR
&& c2
->type
== F_DIR
) {
235 } else if (c1
->type
== F_DIR
&& c2
->type
!= F_DIR
) {
239 i
= strcmp(c1
->name
, c2
->name
);
249 if (c1
== NULL
&& c2
->type
== F_DIR
) {
250 asprintf(&np
, "%s%s/", path
, c2
->name
);
251 i
= walk_in_the_forest(c1
, c2
, np
);
253 i
+= compare_nodes(c1
, c2
, path
);
254 } else if (c2
== NULL
&& c1
->type
== F_DIR
) {
255 asprintf(&np
, "%s%s/", path
, c1
->name
);
256 i
= walk_in_the_forest(c1
, c2
, np
);
258 i
+= compare_nodes(c1
, c2
, path
);
259 } else if (c1
== NULL
|| c2
== NULL
) {
260 i
= compare_nodes(c1
, c2
, path
);
261 } else if (c1
->type
== F_DIR
&& c2
->type
== F_DIR
) {
262 asprintf(&np
, "%s%s/", path
, c1
->name
);
263 i
= walk_in_the_forest(c1
, c2
, np
);
265 i
+= compare_nodes(c1
, c2
, path
);
267 i
= compare_nodes(c1
, c2
, path
);
277 mtree_specspec(FILE *fi
, FILE *fj
)
282 root1
= mtree_readspec(fi
);
283 root2
= mtree_readspec(fj
);
284 rval
= walk_in_the_forest(root1
, root2
, "");
285 rval
+= compare_nodes(root1
, root2
, "");
287 return (MISMATCHEXIT
);