* Copyright (c) 1989 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)mtree.c 5.3 (Berkeley) %G%";
int cflag
, dflag
, eflag
, rflag
, uflag
, xflag
, exitval
;
while ((ch
= getopt(argc
, argv
, "cdef:p:rux")) != EOF
)
if (!(freopen(optarg
, "r", stdin
))) {
"mtree: can't read %s.\n", optarg
);
"usage: mtree [-cderux] [-p path] [-f spec]\n");
"mtree: %s: %s\n", p
, strerror(errno
));
cwalk((ENTRY
*)NULL
, path
+ 1);
(void)fprintf(stderr
, "mtree: root: %s\n",
register struct dirent
*dp
;
if (!(dirp
= opendir("."))) {
(void)fprintf(stderr
, "mtree: %s: %s\n",
level
== root
? "root" : path
, strerror(errno
));
while ((dp
= readdir(dirp
))) {
if (dp
->d_name
[0] == '.' &&
(!dp
->d_name
[1] || dp
->d_name
[1] == '.' && !dp
->d_name
[2]))
bcopy(dp
->d_name
, tail
, dp
->d_namlen
+ 1);
for (ep
= level
; ep
; ep
= ep
->next
)
if (!strcmp(ep
->name
, dp
->d_name
))
if (ep
&& ep
->flags
&F_IGN
) {
if (lstat(dp
->d_name
, &sbuf
)) {
(void)fprintf(stderr
, "mtree: %s: %s\n",
path
+ 2, strerror(errno
));
if (!dflag
|| S_ISDIR(sbuf
.st_mode
))
compare(ep
->name
, &ep
->info
, &sbuf
);
(void)printf("extra: %s%s",
path
+ 2, rflag
? "" : "\n");
(void)printf(", not removed: %s\n",
(void)printf(", removed\n");
if (S_ISDIR(sbuf
.st_mode
) &&
(!xflag
|| device
== sbuf
.st_dev
)) {
(void)fprintf(stderr
, "mtree: %s: %s\n",
path
+ 2, strerror(errno
));
vwalk(ep
? ep
->child
: ep
, tail
+ dp
->d_namlen
);
(void)fprintf(stderr
, "mtree: ..: %s\n",
for (*tail
++ = '/'; level
; level
= level
->next
) {
if (level
->info
.type
!= F_DIR
&&
(dflag
|| level
->flags
&F_VISIT
))
(void)strcpy(tail
, level
->name
);
if (!(level
->flags
&F_VISIT
))
(void)printf("missing: %s%s", path
+ 2,
if (level
->info
.type
!= F_DIR
)
(void)printf(" (not created: %s)\n",
(void)printf(" (created)\n");
register struct stat
*s2
;
"mtree: %s: %s\n", path
, strerror(errno
));
if (s1
->flags
&F_MODE
&& s1
->st_mode
!= (s2
->st_mode
&07777) &&
chmod(path
, s1
->st_mode
))
(void)printf("%s: permissions not set: %s\n",
path
+ 2, strerror(errno
));
if (s1
->flags
&F_OWNER
&& s1
->st_uid
!= s2
->st_uid
&&
chown(path
, s1
->st_uid
, -1))
(void)printf("%s: owner not modified: %s\n",
path
+ 2, strerror(errno
));
if (s1
->flags
&F_GROUP
&& s1
->st_gid
!= s2
->st_gid
&&
chown(path
, -1, s1
->st_gid
))
(void)printf("%s: group not modified: %s\n",
path
+ 2, strerror(errno
));