diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-07-05 20:51:28 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-07-05 20:51:28 +0000 |
commit | 7e384b023b87acba80d4cb452f17d7b563b4ed7d (patch) | |
tree | 6c5fd9e828bee8791ce3690f1a7fe6b8bbae735f /sbin | |
parent | d765b69f80f5f0b56118a607c3e1fc96f05a39f0 (diff) |
vprintf -> Vprintf and dprintf -> Dprintf to avoid confusion
Use err/errx and warn/warnx where it makes sense.
Some sprintf -> snprintf, strcpy -> strncpy, and strcat -> strncat.
Honor $TMPDIR (based on changes from NetBSD)
Use __progname not "restore" (we could be called as rrestore).
Some -Wall happiness.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/restore/Makefile | 5 | ||||
-rw-r--r-- | sbin/restore/dirs.c | 129 | ||||
-rw-r--r-- | sbin/restore/extern.h | 4 | ||||
-rw-r--r-- | sbin/restore/interactive.c | 51 | ||||
-rw-r--r-- | sbin/restore/main.c | 42 | ||||
-rw-r--r-- | sbin/restore/restore.8 | 40 | ||||
-rw-r--r-- | sbin/restore/restore.c | 97 | ||||
-rw-r--r-- | sbin/restore/restore.h | 10 | ||||
-rw-r--r-- | sbin/restore/symtab.c | 50 | ||||
-rw-r--r-- | sbin/restore/tape.c | 238 | ||||
-rw-r--r-- | sbin/restore/utilities.c | 71 |
11 files changed, 351 insertions, 386 deletions
diff --git a/sbin/restore/Makefile b/sbin/restore/Makefile index b4d614196c0..5fe7e6ebcac 100644 --- a/sbin/restore/Makefile +++ b/sbin/restore/Makefile @@ -1,5 +1,6 @@ -# $OpenBSD: Makefile,v 1.3 1996/09/01 15:27:28 deraadt Exp $ -# $NetBSD: Makefile,v 1.14 1995/03/18 14:59:39 cgd Exp $ +# $OpenBSD: Makefile,v 1.4 1997/07/05 20:51:20 millert Exp $ +# $NetBSD: Makefile,v 1.18 1997/06/30 09:47:27 lukem Exp $ +# @(#)Makefile 8.1 (Berkeley) 6/5/93 PROG= restore LINKS= ${BINDIR}/restore ${BINDIR}/rrestore diff --git a/sbin/restore/dirs.c b/sbin/restore/dirs.c index 5284fd6f0d2..c24f25ebd46 100644 --- a/sbin/restore/dirs.c +++ b/sbin/restore/dirs.c @@ -1,5 +1,5 @@ -/* $OpenBSD: dirs.c,v 1.13 1997/04/16 04:07:35 millert Exp $ */ -/* $NetBSD: dirs.c,v 1.16 1995/06/19 00:20:11 cgd Exp $ */ +/* $OpenBSD: dirs.c,v 1.14 1997/07/05 20:51:21 millert Exp $ */ +/* $NetBSD: dirs.c,v 1.26 1997/07/01 05:37:49 lukem Exp $ */ /* * Copyright (c) 1983, 1993 @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)dirs.c 8.5 (Berkeley) 8/31/94"; #else -static char rcsid[] = "$OpenBSD: dirs.c,v 1.13 1997/04/16 04:07:35 millert Exp $"; +static char rcsid[] = "$OpenBSD: dirs.c,v 1.14 1997/07/05 20:51:21 millert Exp $"; #endif #endif /* not lint */ @@ -57,7 +57,7 @@ static char rcsid[] = "$OpenBSD: dirs.c,v 1.13 1997/04/16 04:07:35 millert Exp $ #include <ufs/ufs/dir.h> #include <protocols/dumprestore.h> -#include <errno.h> +#include <err.h> #include <paths.h> #include <stdio.h> #include <stdlib.h> @@ -152,56 +152,52 @@ extractdirs(genmode) struct direct nulldir; int fd; - vprintf(stdout, "Extract directories from tape\n"); - (void) sprintf(dirfile, "%srstdir%d", _PATH_TMP, dumpdate); + Vprintf(stdout, "Extract directories from tape\n"); + (void)snprintf(dirfile, sizeof(dirfile), "%s/rstdir%d", tmpdir, + dumpdate); if (command != 'r' && command != 'R') { - (void *) strcat(dirfile, "-XXXXXX"); + strncat(dirfile, "-XXXXXXXXXX", + sizeof(dirfile) - strlen(dirfile)); fd = mkstemp(dirfile); } else fd = open(dirfile, O_RDWR|O_CREAT|O_EXCL, 0666); if (fd == -1 || (df = fdopen(fd, "w")) == NULL) { if (fd != -1) close(fd); - fprintf(stderr, - "restore: %s - cannot create directory temporary\n", - dirfile); - fprintf(stderr, "fopen: %s\n", strerror(errno)); - exit(1); + err(1, "cannot create directory temporary %s", dirfile); } if (genmode != 0) { - (void) sprintf(modefile, "%srstmode%d", _PATH_TMP, dumpdate); + (void)snprintf(modefile, sizeof(modefile), "%s/rstmode%d", + tmpdir, dumpdate); if (command != 'r' && command != 'R') { - (void *) strcat(modefile, "-XXXXXX"); + strncat(modefile, "-XXXXXXXXXX", + sizeof(modefile) - strlen(modefile)); fd = mkstemp(modefile); } else fd = open(modefile, O_RDWR|O_CREAT|O_EXCL, 0666); if (fd == -1 || (mf = fdopen(fd, "w")) == NULL) { if (fd != -1) close(fd); - fprintf(stderr, - "restore: %s - cannot create modefile \n", - modefile); - fprintf(stderr, "fopen: %s\n", strerror(errno)); - exit(1); + err(1, "cannot create modefile %s", modefile); } } nulldir.d_ino = 0; nulldir.d_type = DT_DIR; nulldir.d_namlen = 1; - (void) strcpy(nulldir.d_name, "/"); + nulldir.d_name[0] = '/'; + nulldir.d_name[1] = '\0'; nulldir.d_reclen = DIRSIZ(0, &nulldir); for (;;) { curfile.name = "<directory file - name unknown>"; curfile.action = USING; ip = curfile.dip; if (ip == NULL || (ip->di_mode & IFMT) != IFDIR) { - (void) fclose(df); + (void)fclose(df); dirp = opendirfile(dirfile); if (dirp == NULL) - fprintf(stderr, "opendirfile: %s\n", - strerror(errno)); + warn("opendirfile"); if (mf != NULL) - (void) fclose(mf); + (void)fclose(mf); i = dirlookup(dot); if (i == 0) panic("Root directory is not on tape\n"); @@ -228,7 +224,7 @@ skipdirs() } /* - * Recursively find names and inumbers of all files in subtree + * Recursively find names and inumbers of all files in subtree * pname and pass them off to be processed. */ void @@ -248,7 +244,7 @@ treescan(pname, ino, todo) /* * Pname is name of a simple file or an unchanged directory. */ - (void) (*todo)(pname, ino, LEAF); + (void)(*todo)(pname, ino, LEAF); return; } /* @@ -260,10 +256,7 @@ treescan(pname, ino, todo) * begin search through the directory * skipping over "." and ".." */ - (void) strncpy(locname, pname, sizeof(locname) - 1); - locname[sizeof(locname) - 1] = '\0'; - (void) strncat(locname, "/", sizeof(locname) - strlen(locname)); - namelen = strlen(locname); + namelen = snprintf(locname, sizeof(locname), "%s/", pname); rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt); dp = rst_readdir(dirp); /* "." */ if (dp != NULL && strcmp(dp->d_name, ".") == 0) @@ -286,7 +279,7 @@ treescan(pname, ino, todo) fprintf(stderr, "%s%s: name exceeds %d char\n", locname, dp->d_name, sizeof(locname) - 1); } else { - (void) strncat(locname, dp->d_name, (int)dp->d_namlen); + (void)strncat(locname, dp->d_name, (int)dp->d_namlen); treescan(locname, dp->d_ino, todo); rst_seekdir(dirp, bpt, itp->t_seekpt); } @@ -312,7 +305,7 @@ pathsearch(pathname) while (*path == '/') path++; dp = NULL; - while ((name = strsep(&path, "/")) != NULL && *name != NULL) { + while ((name = strsep(&path, "/")) != NULL && *name != '\0') { if ((dp = searchdir(ino, name)) == NULL) return (NULL); ino = dp->d_ino; @@ -387,19 +380,19 @@ putdir(buf, size) dp->d_reclen > i || dp->d_reclen < DIRSIZ(0, dp) || dp->d_namlen > NAME_MAX) { - vprintf(stdout, "Mangled directory: "); + Vprintf(stdout, "Mangled directory: "); if ((dp->d_reclen & 0x3) != 0) - vprintf(stdout, + Vprintf(stdout, "reclen not multiple of 4 "); if (dp->d_reclen < DIRSIZ(0, dp)) - vprintf(stdout, + Vprintf(stdout, "reclen less than DIRSIZ (%d < %d) ", dp->d_reclen, DIRSIZ(0, dp)); if (dp->d_namlen > NAME_MAX) - vprintf(stdout, + Vprintf(stdout, "reclen name too big (%d > %d) ", dp->d_namlen, NAME_MAX); - vprintf(stdout, "\n"); + Vprintf(stdout, "\n"); loc += i; continue; } @@ -429,7 +422,7 @@ putent(dp) if (dirloc + dp->d_reclen > DIRBLKSIZ) { ((struct direct *)(dirbuf + prev))->d_reclen = DIRBLKSIZ - prev; - (void) fwrite(dirbuf, 1, DIRBLKSIZ, df); + (void)fwrite(dirbuf, 1, DIRBLKSIZ, df); dirloc = 0; } memcpy(dirbuf + dirloc, dp, (long)dp->d_reclen); @@ -444,7 +437,7 @@ static void flushent() { ((struct direct *)(dirbuf + prev))->d_reclen = DIRBLKSIZ - prev; - (void) fwrite(dirbuf, (int)dirloc, 1, df); + (void)fwrite(dirbuf, (int)dirloc, 1, df); seekpt = ftell(df); dirloc = 0; } @@ -458,7 +451,7 @@ dcvt(odp, ndp) memset(ndp, 0, (size_t)(sizeof *ndp)); ndp->d_ino = odp->d_ino; ndp->d_type = DT_UNKNOWN; - (void) strncpy(ndp->d_name, odp->d_name, ODIRSIZ); + (void)strncpy(ndp->d_name, odp->d_name, ODIRSIZ); ndp->d_namlen = strlen(ndp->d_name); ndp->d_reclen = DIRSIZ(0, ndp); } @@ -480,8 +473,8 @@ rst_seekdir(dirp, loc, base) return; loc -= base; if (loc < 0) - fprintf(stderr, "bad seek pointer to rst_seekdir %d\n", loc); - (void) lseek(dirp->dd_fd, base + (loc & ~(DIRBLKSIZ - 1)), SEEK_SET); + fprintf(stderr, "bad seek pointer to rst_seekdir %ld\n", loc); + (void)lseek(dirp->dd_fd, base + (loc & ~(DIRBLKSIZ - 1)), SEEK_SET); dirp->dd_loc = loc & (DIRBLKSIZ - 1); if (dirp->dd_loc != 0) dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ); @@ -498,10 +491,10 @@ rst_readdir(dirp) for (;;) { if (dirp->dd_loc == 0) { - dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, + dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ); if (dirp->dd_size <= 0) { - dprintf(stderr, "error reading directory\n"); + Dprintf(stderr, "error reading directory\n"); return (NULL); } } @@ -512,7 +505,7 @@ rst_readdir(dirp) dp = (struct direct *)(dirp->dd_buf + dirp->dd_loc); if (dp->d_reclen == 0 || dp->d_reclen > DIRBLKSIZ + 1 - dirp->dd_loc) { - dprintf(stderr, "corrupted directory: bad reclen %d\n", + Dprintf(stderr, "corrupted directory: bad reclen %d\n", dp->d_reclen); return (NULL); } @@ -520,7 +513,7 @@ rst_readdir(dirp) if (dp->d_ino == 0 && strcmp(dp->d_name, "/") == 0) return (NULL); if (dp->d_ino >= maxino) { - dprintf(stderr, "corrupted directory: bad inum %d\n", + Dprintf(stderr, "corrupted directory: bad inum %d\n", dp->d_ino); continue; } @@ -605,24 +598,25 @@ setdirmodes(flags) struct entry *ep; char *cp; - vprintf(stdout, "Set directory mode, owner, and times.\n"); + Vprintf(stdout, "Set directory mode, owner, and times.\n"); if (command == 'r' || command == 'R') - (void) sprintf(modefile, "%srstmode%d", _PATH_TMP, dumpdate); + (void)snprintf(modefile, sizeof(modefile), "%s/rstmode%d", + tmpdir, dumpdate); if (modefile[0] == '#') { panic("modefile not defined\n"); - fprintf(stderr, "directory mode, owner, and times not set\n"); + fputs("directory mode, owner, and times not set\n", stderr); return; } mf = fopen(modefile, "r"); if (mf == NULL) { - fprintf(stderr, "fopen: %s\n", strerror(errno)); + warn("fopen"); fprintf(stderr, "cannot open mode file %s\n", modefile); fprintf(stderr, "directory mode, owner, and times not set\n"); return; } clearerr(mf); for (;;) { - (void) fread((char *)&node, 1, sizeof(struct modeinfo), mf); + (void)fread((char *)&node, 1, sizeof(struct modeinfo), mf); if (feof(mf)) break; ep = lookupino(node.ino); @@ -641,16 +635,16 @@ setdirmodes(flags) panic("cannot find directory inode %d\n", node.ino); } else { cp = myname(ep); - (void) chown(cp, node.uid, node.gid); - (void) chmod(cp, node.mode); - (void) chflags(cp, node.flags); + (void)chown(cp, node.uid, node.gid); + (void)chmod(cp, node.mode); + (void)chflags(cp, node.flags); utimes(cp, node.timep); ep->e_flags &= ~NEW; } } if (ferror(mf)) panic("error setting directory modes\n"); - (void) fclose(mf); + (void)fclose(mf); } /* @@ -669,9 +663,7 @@ genliteraldir(name, ino) if (itp == NULL) panic("Cannot find directory inode %d named %s\n", ino, name); if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) { - fprintf(stderr, "%s: ", name); - (void) fflush(stderr); - fprintf(stderr, "cannot create file: %s\n", strerror(errno)); + warn("%s: cannot create file", name); return (FAIL); } rst_seekdir(dirp, itp->t_seekpt, itp->t_seekpt); @@ -679,22 +671,19 @@ genliteraldir(name, ino) for (i = itp->t_size; i > 0; i -= BUFSIZ) { size = i < BUFSIZ ? i : BUFSIZ; if (read(dp, buf, (int) size) == -1) { - fprintf(stderr, - "write error extracting inode %d, name %s\n", - curfile.ino, curfile.name); - fprintf(stderr, "read: %s\n", strerror(errno)); - exit(1); + warnx("write error extracting inode %d, name %s", + curfile.ino, curfile.name); + err(1, "read"); } if (!Nflag && write(ofile, buf, (int) size) == -1) { fprintf(stderr, "write error extracting inode %d, name %s\n", curfile.ino, curfile.name); - fprintf(stderr, "write: %s\n", strerror(errno)); - exit(1); + err(1, "write"); } } - (void) close(dp); - (void) close(ofile); + (void)close(dp); + (void)close(ofile); return (GOOD); } @@ -744,7 +733,7 @@ allocinotab(ino, dip, seekpt) node.flags = dip->di_flags; node.uid = dip->di_uid; node.gid = dip->di_gid; - (void) fwrite((char *)&node, 1, sizeof(struct modeinfo), mf); + (void)fwrite((char *)&node, 1, sizeof(struct modeinfo), mf); return (itp); } @@ -772,7 +761,7 @@ cleanup() closemt(); if (modefile[0] != '#') - (void) unlink(modefile); + (void)unlink(modefile); if (dirfile[0] != '#') - (void) unlink(dirfile); + (void)unlink(dirfile); } diff --git a/sbin/restore/extern.h b/sbin/restore/extern.h index ec59d73b620..134906612e3 100644 --- a/sbin/restore/extern.h +++ b/sbin/restore/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.2 1996/06/23 14:32:15 deraadt Exp $ */ +/* $OpenBSD: extern.h,v 1.3 1997/07/05 20:51:21 millert Exp $ */ /* $NetBSD: extern.h,v 1.4 1995/03/18 14:59:43 cgd Exp $ */ /*- @@ -38,6 +38,7 @@ struct entry *addentry __P((char *, ino_t, int)); long addfile __P((char *, ino_t, int)); +int addwhiteout __P((char *)); void badentry __P((struct entry *, char *)); void canon __P((char *, char *)); void checkrestore __P((void)); @@ -48,6 +49,7 @@ void createleaves __P((char *)); void createlinks __P((void)); long deletefile __P((char *, ino_t, int)); void deleteino __P((ino_t)); +void delwhiteout __P((struct entry *)); ino_t dirlookup __P((const char *)); void dumpsymtable __P((char *, long)); void extractdirs __P((int)); diff --git a/sbin/restore/interactive.c b/sbin/restore/interactive.c index 69b6657a082..43b49a11699 100644 --- a/sbin/restore/interactive.c +++ b/sbin/restore/interactive.c @@ -1,5 +1,5 @@ -/* $OpenBSD: interactive.c,v 1.3 1996/12/16 17:11:43 deraadt Exp $ */ -/* $NetBSD: interactive.c,v 1.9 1995/03/18 14:59:44 cgd Exp $ */ +/* $OpenBSD: interactive.c,v 1.4 1997/07/05 20:51:22 millert Exp $ */ +/* $NetBSD: interactive.c,v 1.10 1997/03/19 08:42:52 lukem Exp $ */ /* * Copyright (c) 1985, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)interactive.c 8.3 (Berkeley) 9/13/94"; #else -static char rcsid[] = "$OpenBSD: interactive.c,v 1.3 1996/12/16 17:11:43 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: interactive.c,v 1.4 1997/07/05 20:51:22 millert Exp $"; #endif #endif /* not lint */ @@ -156,7 +156,7 @@ loop: fprintf(stderr, "%s: not a directory\n", name); break; } - (void) strcpy(curdir, name); + (void)strcpy(curdir, name); break; /* * Delete elements from the extraction list. @@ -326,13 +326,13 @@ getcmd(curdir, cmd, name, ap) /* * Read a command line and trim off trailing white space. */ - do { - fprintf(stderr, "restore > "); - (void) fflush(stderr); - (void) fgets(input, BUFSIZ, terminal); + do { + (void)fprintf(stderr, "%s > ", __progname); + (void)fflush(stderr); + (void)fgets(input, BUFSIZ, terminal); } while (!feof(terminal) && input[0] == '\n'); if (feof(terminal)) { - (void) strcpy(cmd, "quit"); + (void)strcpy(cmd, "quit"); return; } for (cp = &input[strlen(input) - 2]; *cp == ' ' || *cp == '\t'; cp--) @@ -347,7 +347,7 @@ getcmd(curdir, cmd, name, ap) * If no argument, use curdir as the default. */ if (*cp == '\0') { - (void) strcpy(name, curdir); + (void)strcpy(name, curdir); return; } nextarg = cp; @@ -370,9 +370,9 @@ getnext: * For relative pathnames, prepend the current directory to * it then canonicalize and return it. */ - (void) strcpy(output, curdir); - (void) strcat(output, "/"); - (void) strcat(output, rawname); + (void)strcpy(output, curdir); + (void)strcat(output, "/"); + (void)strcat(output, rawname); canon(output, name); } if (glob(name, GLOB_ALTDIRFUNC, NULL, &ap->glob) < 0) @@ -451,12 +451,12 @@ canon(rawname, canonname) register char *cp, *np; if (strcmp(rawname, ".") == 0 || strncmp(rawname, "./", 2) == 0) - (void) strcpy(canonname, ""); + (void)strcpy(canonname, ""); else if (rawname[0] == '/') - (void) strcpy(canonname, "."); + (void)strcpy(canonname, "."); else - (void) strcpy(canonname, "./"); - (void) strcat(canonname, rawname); + (void)strcpy(canonname, "./"); + (void)strcat(canonname, rawname); /* * Eliminate multiple and trailing '/'s */ @@ -478,14 +478,14 @@ canon(rawname, canonname) np++; if (np - cp == 1 && *cp == '.') { cp--; - (void) strcpy(cp, np); + (void)strcpy(cp, np); np = cp; } if (np - cp == 2 && strncmp(cp, "..", 2) == 0) { cp--; while (cp > &canonname[1] && *--cp != '/') /* find beginning of name */; - (void) strcpy(cp, np); + (void)strcpy(cp, np); np = cp; } } @@ -504,7 +504,7 @@ printlist(name, basename) struct afile single; RST_DIR *dirp; int entries, len, namelen; - char locname[MAXPATHLEN + 1]; + char locname[MAXPATHLEN]; dp = pathsearch(name); if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) || @@ -522,7 +522,7 @@ printlist(name, basename) } } else { entries = 0; - while (dp = rst_readdir(dirp)) + while ((dp = rst_readdir(dirp))) entries++; rst_closedir(dirp); list = (struct afile *)malloc(entries * sizeof(struct afile)); @@ -535,11 +535,8 @@ printlist(name, basename) fprintf(stderr, "%s:\n", name); entries = 0; listp = list; - (void) strncpy(locname, name, MAXPATHLEN); - locname[sizeof locname - 1] = '\0'; - (void) strncat(locname, "/", MAXPATHLEN - strlen(locname)); - namelen = strlen(locname); - while (dp = rst_readdir(dirp)) { + namelen = snprintf(locname, sizeof(locname), "%s/", name); + while ((dp = rst_readdir(dirp))) { if (dp == NULL) break; if (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) @@ -553,7 +550,7 @@ printlist(name, basename) fprintf(stderr, "%s%s: name exceeds %d char\n", locname, dp->d_name, MAXPATHLEN); } else { - (void) strncat(locname, dp->d_name, + (void)strncat(locname, dp->d_name, (int)dp->d_namlen); mkentry(locname, dp, listp++); entries++; diff --git a/sbin/restore/main.c b/sbin/restore/main.c index edc60dcfdf7..ef4b043b8b8 100644 --- a/sbin/restore/main.c +++ b/sbin/restore/main.c @@ -1,5 +1,5 @@ -/* $OpenBSD: main.c,v 1.8 1997/06/25 18:34:30 kstailey Exp $ */ -/* $NetBSD: main.c,v 1.11 1996/03/15 22:39:39 scottr Exp $ */ +/* $OpenBSD: main.c,v 1.9 1997/07/05 20:51:23 millert Exp $ */ +/* $NetBSD: main.c,v 1.13 1997/07/01 05:37:51 lukem Exp $ */ /* * Copyright (c) 1983, 1993 @@ -49,6 +49,7 @@ static char rcsid[] = "$NetBSD: main.c,v 1.11 1996/03/15 22:39:39 scottr Exp $"; #endif /* not lint */ #include <sys/param.h> +#include <sys/stat.h> #include <sys/time.h> #include <ufs/ffs/fs.h> @@ -56,7 +57,6 @@ static char rcsid[] = "$NetBSD: main.c,v 1.11 1996/03/15 22:39:39 scottr Exp $"; #include <protocols/dumprestore.h> #include <err.h> -#include <errno.h> #include <paths.h> #include <signal.h> #include <stdio.h> @@ -78,6 +78,7 @@ ino_t maxino; time_t dumptime; time_t dumpdate; FILE *terminal; +char *tmpdir; static void obsolete __P((int *, char **[])); static void usage __P((void)); @@ -94,13 +95,19 @@ main(argc, argv) char *p, name[MAXPATHLEN]; /* Temp files should *not* be readable. We set permissions later. */ - (void) umask(077); + (void)umask(077); if (argc < 2) usage(); if ((inputdev = getenv("TAPE")) == NULL) inputdev = _PATH_DEFTAPE; + if ((tmpdir = getenv("TMPDIR")) == NULL) + tmpdir = _PATH_TMP; + if ((tmpdir = strdup(tmpdir)) == NULL) + err(1, NULL); + for (p = tmpdir + strlen(tmpdir) - 1; p >= tmpdir && *p == '/'; p--) + ; obsolete(&argc, &argv); while ((ch = getopt(argc, argv, "b:cdf:himNRrs:tvxy")) != -1) switch(ch) { @@ -166,9 +173,9 @@ main(argc, argv) errx(1, "none of i, R, r, t or x options specified"); if (signal(SIGINT, onintr) == SIG_IGN) - (void) signal(SIGINT, SIG_IGN); + (void)signal(SIGINT, SIG_IGN); if (signal(SIGTERM, onintr) == SIG_IGN) - (void) signal(SIGTERM, SIG_IGN); + (void)signal(SIGTERM, SIG_IGN); setlinebuf(stderr); atexit(cleanup); @@ -199,11 +206,11 @@ main(argc, argv) /* * This is an incremental dump tape. */ - vprintf(stdout, "Begin incremental restore\n"); + Vprintf(stdout, "Begin incremental restore\n"); initsymtable(symtbl); extractdirs(1); removeoldleaves(); - vprintf(stdout, "Calculate node updates.\n"); + Vprintf(stdout, "Calculate node updates.\n"); treescan(".", ROOTINO, nodeupdates); findunreflinks(); removeoldnodes(); @@ -211,10 +218,10 @@ main(argc, argv) /* * This is a level zero dump tape. */ - vprintf(stdout, "Begin level 0 restore\n"); + Vprintf(stdout, "Begin level 0 restore\n"); initsymtable(NULL); extractdirs(1); - vprintf(stdout, "Calculate extraction list.\n"); + Vprintf(stdout, "Calculate extraction list.\n"); treescan(".", ROOTINO, nodeupdates); } createleaves(symtbl); @@ -222,7 +229,7 @@ main(argc, argv) setdirmodes(FORCE); checkrestore(); if (dflag) { - vprintf(stdout, "Verify the directory structure\n"); + Vprintf(stdout, "Verify the directory structure\n"); treescan(".", ROOTINO, verifyfile); } dumpsymtable(symtbl, (long)1); @@ -286,11 +293,11 @@ static void usage() { - (void)fprintf(stderr, "usage: restore -i [-chmvy] [-b blocksize] [-f file] [-s fileno]\n"); - (void)fprintf(stderr, " restore -R [-cvy] [-b blocksize] [-f file] [-s fileno]\n"); - (void)fprintf(stderr, " restore -r [-cvy] [-b blocksize] [-f file] [-s fileno]\n"); - (void)fprintf(stderr, " restore -t [-chvy] [-b blocksize] [-f file] [-s fileno] [file ...]\n"); - (void)fprintf(stderr, " restore -x [-chmvy] [-b blocksize] [-f file] [-s fileno] [file ...]\n"); + (void)fprintf(stderr, "usage: %s -i [-chmvy] [-b blocksize] [-f file] [-s fileno]\n", __progname); + (void)fprintf(stderr, " %s -R [-cvy] [-b blocksize] [-f file] [-s fileno]\n", __progname); + (void)fprintf(stderr, " %s -r [-cvy] [-b blocksize] [-f file] [-s fileno]\n", __progname); + (void)fprintf(stderr, " %s -t [-chvy] [-b blocksize] [-f file] [-s fileno] [file ...]\n", __progname); + (void)fprintf(stderr, " %s -x [-chmvy] [-b blocksize] [-f file] [-s fileno] [file ...]\n", __progname); exit(1); } @@ -358,7 +365,8 @@ obsolete(argcp, argvp) } /* Copy remaining arguments. */ - while (*nargv++ = *argv++); + while ((*nargv++ = *argv++)) + ; /* Update argument count. */ *argcp = nargv - *argvp - 1; diff --git a/sbin/restore/restore.8 b/sbin/restore/restore.8 index 2af517062f0..baf20ecf1eb 100644 --- a/sbin/restore/restore.8 +++ b/sbin/restore/restore.8 @@ -1,5 +1,5 @@ -.\" $OpenBSD: restore.8,v 1.6 1997/04/16 04:07:39 millert Exp $ -.\" $NetBSD: restore.8,v 1.11 1996/02/02 22:29:33 phil Exp $ +.\" $OpenBSD: restore.8,v 1.7 1997/07/05 20:51:23 millert Exp $ +.\" $NetBSD: restore.8,v 1.15 1997/07/01 05:37:53 lukem Exp $ .\" .\" Copyright (c) 1985, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -34,39 +34,39 @@ .\" .\" @(#)restore.8 8.3 (Berkeley) 6/1/94 .\" -.Dd June 1, 1994 +.Dd July 1, 1997 .Dt RESTORE 8 .Os BSD 4 .Sh NAME .Nm restore .Nd "restore files or file systems from backups made with dump" .Sh SYNOPSIS -.Nm +.Nm restore .Fl i .Op Fl chmvy .Op Fl b Ar blocksize .Op Fl f Ar file .Op Fl s Ar fileno -.Nm +.Nm restore .Fl R .Op Fl cvy .Op Fl b Ar blocksize .Op Fl f Ar file .Op Fl s Ar fileno -.Nm +.Nm restore .Fl r .Op Fl cvy .Op Fl b Ar blocksize .Op Fl f Ar file .Op Fl s Ar fileno -.Nm +.Nm restore .Fl t .Op Fl chvy .Op Fl b Ar blocksize .Op Fl f Ar file .Op Fl s Ar fileno .Op file ... -.Nm +.Nm restore .Fl x .Op Fl chmvy .Op Fl b Ar blocksize @@ -89,7 +89,7 @@ subsequent incremental backups layered on top of it. Single files and directory subtrees may be restored from full or partial backups. -.Nm Restore +.Nm works across a network; to do this see the .Fl f @@ -141,7 +141,7 @@ those files that are not needed. .It Ic extract All the files that are on the extraction list are extracted from the dump. -.Nm Restore +.Nm will ask which volume the user wishes to mount. The fastest way to extract a few files is to start with the last volume, and work towards the first volume. @@ -175,7 +175,7 @@ It also causes to print out information about each file as it is extracted. .El .It Fl R -.Nm Restore +.Nm requests a particular tape of a multi volume set on which to restart a full restore (see the @@ -216,7 +216,7 @@ restore passes. This file should be removed when the last incremental has been restored. .Pp -.Nm Restore , +.Nm restore , in conjunction with .Xr newfs 8 and @@ -394,6 +394,19 @@ After a dump read error, may have to resynchronize itself. This message lists the number of blocks that were skipped over. .El +.Sh ENVIRONMENT +If the following environment variable exists it will be utilized by +.Nm restore : +.Bl -tag -width "TMPDIR" -compact +.It TMPDIR +The directory given in TMPDIR will be used +instead of +.Pa /tmp +to store temporary files. +Refer to +.Xr environ 7 +for more information. +.El .Sh FILES .Bl -tag -width "./restoresymtable" -compact .It Pa /dev/rst0 @@ -408,12 +421,13 @@ owner, mode, and time stamps for directories. information passed between incremental restores. .El .Sh SEE ALSO +.Xr environ 7 , .Xr dump 8 , .Xr newfs 8 , .Xr mount 8 , .Xr rmt 8 .Sh BUGS -.Nm Restore +.Nm can get confused when doing incremental restores from dumps that were made on active file systems. .Pp diff --git a/sbin/restore/restore.c b/sbin/restore/restore.c index e06d84ccdd6..0a9225f21c5 100644 --- a/sbin/restore/restore.c +++ b/sbin/restore/restore.c @@ -1,5 +1,5 @@ -/* $OpenBSD: restore.c,v 1.3 1997/06/18 01:46:40 millert Exp $ */ -/* $NetBSD: restore.c,v 1.6 1995/03/18 14:59:51 cgd Exp $ */ +/* $OpenBSD: restore.c,v 1.4 1997/07/05 20:51:24 millert Exp $ */ +/* $NetBSD: restore.c,v 1.9 1997/06/18 07:10:16 lukem Exp $ */ /* * Copyright (c) 1983, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)restore.c 8.3 (Berkeley) 9/13/94"; #else -static char rcsid[] = "$OpenBSD: restore.c,v 1.3 1997/06/18 01:46:40 millert Exp $"; +static char rcsid[] = "$OpenBSD: restore.c,v 1.4 1997/07/05 20:51:24 millert Exp $"; #endif #endif /* not lint */ @@ -69,7 +69,7 @@ listfile(name, ino, type) if (TSTINO(ino, dumpmap) == 0) return (descend); - vprintf(stdout, "%s", type == LEAF ? "leaf" : "dir "); + Vprintf(stdout, "%s", type == LEAF ? "leaf" : "dir "); fprintf(stdout, "%10d\t%s\n", ino, name); return (descend); } @@ -89,16 +89,16 @@ addfile(name, ino, type) char buf[100]; if (TSTINO(ino, dumpmap) == 0) { - dprintf(stdout, "%s: not on the tape\n", name); + Dprintf(stdout, "%s: not on the tape\n", name); return (descend); } if (ino == WINO && command == 'i' && !vflag) return (descend); if (!mflag) { - (void) sprintf(buf, "./%u", ino); + (void)snprintf(buf, sizeof(buf), "./%u", ino); name = buf; if (type == NODE) { - (void) genliteraldir(name, ino); + (void)genliteraldir(name, ino); return (descend); } } @@ -143,7 +143,7 @@ deletefile(name, ino, type) return (descend); } -/* +/* * The following four routines implement the incremental * restore algorithm. The first removes old entries, the second * does renames and calculates the extraction list, the third @@ -152,7 +152,7 @@ deletefile(name, ino, type) * * Directories cannot be immediately deleted, as they may have * other files in them which need to be moved out first. As - * directories to be deleted are found, they are put on the + * directories to be deleted are found, they are put on the * following deletion list. After all deletions and renames * are done, this list is actually deleted. */ @@ -169,9 +169,9 @@ removeoldleaves() register struct entry *ep, *nextep; register ino_t i, mydirino; - vprintf(stdout, "Mark entries to be removed.\n"); - if (ep = lookupino(WINO)) { - vprintf(stdout, "Delete whiteouts\n"); + Vprintf(stdout, "Mark entries to be removed.\n"); + if ((ep = lookupino(WINO))) { + Vprintf(stdout, "Delete whiteouts\n"); for ( ; ep != NULL; ep = nextep) { nextep = ep->e_links; mydirino = ep->e_parent->e_ino; @@ -193,7 +193,7 @@ removeoldleaves() if (TSTINO(i, usedinomap)) continue; for ( ; ep != NULL; ep = ep->e_links) { - dprintf(stdout, "%s: REMOVE\n", myname(ep)); + Dprintf(stdout, "%s: REMOVE\n", myname(ep)); if (ep->e_type == LEAF) { removeleaf(ep); freeentry(ep); @@ -233,7 +233,7 @@ nodeupdates(name, ino, type) # define MODECHG 0x8 /* mode of inode changed */ /* - * This routine is called once for each element in the + * This routine is called once for each element in the * directory hierarchy, with a full path name. * The "type" value is incorrectly specified as LEAF for * directories that are not on the dump tape. @@ -286,7 +286,7 @@ nodeupdates(name, ino, type) removeleaf(np); freeentry(np); } else { - dprintf(stdout, "name/inode conflict, mktempname %s\n", + Dprintf(stdout, "name/inode conflict, mktempname %s\n", myname(np)); mktempname(np); } @@ -314,7 +314,7 @@ nodeupdates(name, ino, type) */ case INOFND|NAMEFND: ip->e_flags |= KEEP; - dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, + Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, flagvalues(ip)); break; @@ -350,7 +350,7 @@ nodeupdates(name, ino, type) if (type == NODE) newnode(ep); ep->e_flags |= NEW|KEEP; - dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, + Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, flagvalues(ep)); break; @@ -374,7 +374,7 @@ nodeupdates(name, ino, type) renameit(myname(ip), name); moveentry(ip, name); ip->e_flags |= KEEP; - dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, + Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, flagvalues(ip)); break; } @@ -387,7 +387,7 @@ nodeupdates(name, ino, type) } ep = addentry(name, ino, type|LINK); ep->e_flags |= NEW; - dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name, + Dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name, flagvalues(ep)); break; @@ -404,14 +404,14 @@ nodeupdates(name, ino, type) if (type == NODE) newnode(ep); ep->e_flags |= NEW|KEEP; - dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name, + Dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name, flagvalues(ep)); break; } if (type == LEAF && lookuptype != LINK) np->e_flags |= EXTRACT; np->e_flags |= KEEP; - dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, + Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, flagvalues(np)); break; @@ -424,7 +424,7 @@ nodeupdates(name, ino, type) * that we need to rename, so we delete it from the symbol * table, and put it on the list to be deleted eventually. * Conversely if a directory is to be created, it must be - * done immediately, rather than waiting until the + * done immediately, rather than waiting until the * extraction phase. */ case ONTAPE|INOFND|MODECHG: @@ -437,7 +437,8 @@ nodeupdates(name, ino, type) /* changing from leaf to node */ for ( ; ip != NULL; ip = ip->e_links) { if (ip->e_type != LEAF) - badentry(ip, "NODE and LEAF links to same inode"); + badentry(ip, + "NODE and LEAF links to same inode"); removeleaf(ip); freeentry(ip); } @@ -453,7 +454,7 @@ nodeupdates(name, ino, type) ip = addentry(name, ino, type); } ip->e_flags |= NEW|KEEP; - dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, + Dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, flagvalues(ip)); break; @@ -462,7 +463,7 @@ nodeupdates(name, ino, type) * Ignore it. */ case NAMEFND: - dprintf(stdout, "[%s] %s: Extraneous name\n", keyval(key), + Dprintf(stdout, "[%s] %s: Extraneous name\n", keyval(key), name); descend = FAIL; break; @@ -511,16 +512,16 @@ keyval(key) { static char keybuf[32]; - (void) strcpy(keybuf, "|NIL"); + (void)strcpy(keybuf, "|NIL"); keybuf[0] = '\0'; if (key & ONTAPE) - (void) strcat(keybuf, "|ONTAPE"); + (void)strcat(keybuf, "|ONTAPE"); if (key & INOFND) - (void) strcat(keybuf, "|INOFND"); + (void)strcat(keybuf, "|INOFND"); if (key & NAMEFND) - (void) strcat(keybuf, "|NAMEFND"); + (void)strcat(keybuf, "|NAMEFND"); if (key & MODECHG) - (void) strcat(keybuf, "|MODECHG"); + (void)strcat(keybuf, "|MODECHG"); return (&keybuf[1]); } @@ -533,14 +534,14 @@ findunreflinks() register struct entry *ep, *np; register ino_t i; - vprintf(stdout, "Find unreferenced names.\n"); + Vprintf(stdout, "Find unreferenced names.\n"); for (i = ROOTINO; i < maxino; i++) { ep = lookupino(i); if (ep == NULL || ep->e_type == LEAF || TSTINO(i, dumpmap) == 0) continue; for (np = ep->e_entries; np != NULL; np = np->e_sibling) { if (np->e_flags == 0) { - dprintf(stdout, + Dprintf(stdout, "%s: remove unreferenced name\n", myname(np)); removeleaf(np); @@ -556,7 +557,7 @@ findunreflinks() if (np->e_type == LEAF) { if (np->e_flags != 0) badentry(np, "unreferenced with flags"); - dprintf(stdout, + Dprintf(stdout, "%s: remove unreferenced name\n", myname(np)); removeleaf(np); @@ -581,7 +582,7 @@ removeoldnodes() register struct entry *ep, **prev; long change; - vprintf(stdout, "Remove old nodes (directories).\n"); + Vprintf(stdout, "Remove old nodes (directories).\n"); do { change = 0; prev = &removelist; @@ -613,9 +614,9 @@ createleaves(symtabfile) long curvol; if (command == 'R') { - vprintf(stdout, "Continue extraction of new leaves\n"); + Vprintf(stdout, "Continue extraction of new leaves\n"); } else { - vprintf(stdout, "Extract new leaves.\n"); + Vprintf(stdout, "Extract new leaves.\n"); dumpsymtable(symtabfile, volno); } first = lowerbnd(ROOTINO); @@ -640,7 +641,7 @@ createleaves(symtabfile) /* * If we find files on the tape that have no corresponding * directory entries, then we must have found a file that - * was created while the dump was in progress. Since we have + * was created while the dump was in progress. Since we have * no name for it, we discard it knowing that it will be * on the next incremental tape. */ @@ -664,7 +665,7 @@ createleaves(symtabfile) removeleaf(ep); ep->e_flags &= ~REMOVED; } - (void) extractfile(myname(ep)); + (void)extractfile(myname(ep)); ep->e_flags &= ~(NEW|EXTRACT); /* * We checkpoint the restore after every tape reel, so @@ -691,7 +692,7 @@ createfiles() register struct entry *ep; long curvol; - vprintf(stdout, "Extract requested files\n"); + Vprintf(stdout, "Extract requested files\n"); curfile.action = SKIP; getvol((long)1); skipmaps(); @@ -761,7 +762,7 @@ createfiles() ep = lookupino(next); if (ep == NULL) panic("corrupted symbol table\n"); - (void) extractfile(myname(ep)); + (void)extractfile(myname(ep)); ep->e_flags &= ~NEW; if (volno != curvol) skipmaps(); @@ -779,16 +780,16 @@ createlinks() register ino_t i; char name[BUFSIZ]; - if (ep = lookupino(WINO)) { - vprintf(stdout, "Add whiteouts\n"); + if ((ep = lookupino(WINO))) { + Vprintf(stdout, "Add whiteouts\n"); for ( ; ep != NULL; ep = ep->e_links) { if ((ep->e_flags & NEW) == 0) continue; - (void) addwhiteout(myname(ep)); + (void)addwhiteout(myname(ep)); ep->e_flags &= ~NEW; } } - vprintf(stdout, "Add links\n"); + Vprintf(stdout, "Add links\n"); for (i = ROOTINO; i < maxino; i++) { ep = lookupino(i); if (ep == NULL) @@ -796,11 +797,11 @@ createlinks() for (np = ep->e_links; np != NULL; np = np->e_links) { if ((np->e_flags & NEW) == 0) continue; - (void) strcpy(name, myname(ep)); + (void)strcpy(name, myname(ep)); if (ep->e_type == NODE) { - (void) linkit(name, myname(np), SYMLINK); + (void)linkit(name, myname(np), SYMLINK); } else { - (void) linkit(name, myname(np), HARDLINK); + (void)linkit(name, myname(np), HARDLINK); } np->e_flags &= ~NEW; } @@ -818,7 +819,7 @@ checkrestore() register struct entry *ep; register ino_t i; - vprintf(stdout, "Check the symbol table.\n"); + Vprintf(stdout, "Check the symbol table.\n"); for (i = WINO; i < maxino; i++) { for (ep = lookupino(i); ep != NULL; ep = ep->e_links) { ep->e_flags &= ~KEEP; diff --git a/sbin/restore/restore.h b/sbin/restore/restore.h index a61434da8dc..32b0aa4f5f5 100644 --- a/sbin/restore/restore.h +++ b/sbin/restore/restore.h @@ -1,5 +1,5 @@ -/* $OpenBSD: restore.h,v 1.2 1996/06/23 14:32:18 deraadt Exp $ */ -/* $NetBSD: restore.h,v 1.7 1995/03/18 14:59:53 cgd Exp $ */ +/* $OpenBSD: restore.h,v 1.3 1997/07/05 20:51:25 millert Exp $ */ +/* $NetBSD: restore.h,v 1.8 1997/07/01 05:37:54 lukem Exp $ */ /* * Copyright (c) 1983, 1993 @@ -65,8 +65,10 @@ extern time_t dumptime; /* time that this dump begins */ extern time_t dumpdate; /* time that this dump was made */ extern char command; /* opration being performed */ extern FILE *terminal; /* file descriptor for the terminal input */ +extern char *tmpdir; /* where to store temporary files */ extern int oldinofmt; /* reading tape with old format inodes */ extern int Bcvt; /* need byte swapping on inodes and dirs */ +extern char *__progname; /* from crt0.o */ /* * Each file in the file system is described by one of these entries @@ -135,8 +137,8 @@ typedef struct rstdirdesc RST_DIR; #define SETINO(ino, map) \ map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY) -#define dprintf if (dflag) fprintf -#define vprintf if (vflag) fprintf +#define Dprintf if (dflag) fprintf +#define Vprintf if (vflag) fprintf #define GOOD 1 #define FAIL 0 diff --git a/sbin/restore/symtab.c b/sbin/restore/symtab.c index d877e12cba7..2d56cd5e7fa 100644 --- a/sbin/restore/symtab.c +++ b/sbin/restore/symtab.c @@ -1,5 +1,5 @@ -/* $OpenBSD: symtab.c,v 1.4 1997/02/09 18:55:16 deraadt Exp $ */ -/* $NetBSD: symtab.c,v 1.9 1996/11/30 18:04:47 cgd Exp $ */ +/* $OpenBSD: symtab.c,v 1.5 1997/07/05 20:51:25 millert Exp $ */ +/* $NetBSD: symtab.c,v 1.10 1997/03/19 08:42:54 lukem Exp $ */ /* * Copyright (c) 1983, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)symtab.c 8.2 (Berkeley) 9/13/94"; #else -static char rcsid[] = "$OpenBSD: symtab.c,v 1.4 1997/02/09 18:55:16 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: symtab.c,v 1.5 1997/07/05 20:51:25 millert Exp $"; #endif #endif /* not lint */ @@ -56,7 +56,7 @@ static char rcsid[] = "$OpenBSD: symtab.c,v 1.4 1997/02/09 18:55:16 deraadt Exp #include <ufs/ufs/dinode.h> -#include <errno.h> +#include <err.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> @@ -376,7 +376,7 @@ removeentry(ep) /* * Table of unused string entries, sorted by length. - * + * * Entries are allocated in STRTBLINCR sized pieces so that names * of similar lengths can use the same entry. The value of STRTBLINCR * is chosen so that every entry has at least enough space to hold @@ -419,7 +419,7 @@ savename(name) if (cp == NULL) panic("no space for string table\n"); } - (void) strcpy(cp, name); + (void)strcpy(cp, name); return (cp); } @@ -467,13 +467,13 @@ dumpsymtable(filename, checkpt) FILE *fd; struct symtableheader hdr; - vprintf(stdout, "Check pointing the restore\n"); + Vprintf(stdout, "Check pointing the restore\n"); if (Nflag) return; if ((fd = fopen(filename, "w")) == NULL) { - fprintf(stderr, "fopen: %s\n", strerror(errno)); + warn("fopen"); panic("cannot create save file %s for symbol table\n", - filename); + filename); } clearerr(fd); /* @@ -483,7 +483,7 @@ dumpsymtable(filename, checkpt) for (i = WINO; i <= maxino; i++) { for (ep = lookupino(i); ep != NULL; ep = ep->e_links) { ep->e_index = mynum++; - (void) fwrite(ep->e_name, sizeof(char), + (void)fwrite(ep->e_name, sizeof(char), (int)allocsize(ep->e_namlen), fd); } } @@ -510,7 +510,7 @@ dumpsymtable(filename, checkpt) if (ep->e_next != NULL) tep->e_next = (struct entry *)ep->e_next->e_index; - (void) fwrite((char *)tep, sizeof(struct entry), 1, fd); + (void)fwrite((char *)tep, sizeof(struct entry), 1, fd); } } /* @@ -521,7 +521,7 @@ dumpsymtable(filename, checkpt) tentry = NULL; else tentry = (struct entry *)entry[i]->e_index; - (void) fwrite((char *)&tentry, sizeof(struct entry *), 1, fd); + (void)fwrite((char *)&tentry, sizeof(struct entry *), 1, fd); } hdr.volno = checkpt; hdr.maxino = maxino; @@ -530,13 +530,13 @@ dumpsymtable(filename, checkpt) hdr.dumptime = dumptime; hdr.dumpdate = dumpdate; hdr.ntrec = ntrec; - (void) fwrite((char *)&hdr, sizeof(struct symtableheader), 1, fd); + (void)fwrite((char *)&hdr, sizeof(struct symtableheader), 1, fd); if (ferror(fd)) { - fprintf(stderr, "fwrite: %s\n", strerror(errno)); + warn("fwrite"); panic("output error to file %s writing symbol table\n", - filename); + filename); } - (void) fclose(fd); + (void)fclose(fd); } /* @@ -555,7 +555,7 @@ initsymtable(filename) register long i; int fd; - vprintf(stdout, "Initialize symbol table.\n"); + Vprintf(stdout, "Initialize symbol table.\n"); if (filename == NULL) { entrytblsize = maxino / HASHFACTOR; entry = (struct entry **) @@ -567,11 +567,11 @@ initsymtable(filename) return; } if ((fd = open(filename, O_RDONLY, 0)) < 0) { - fprintf(stderr, "open: %s\n", strerror(errno)); + warn("open"); panic("cannot open symbol table file %s\n", filename); } if (fstat(fd, &stbuf) < 0) { - fprintf(stderr, "stat: %s\n", strerror(errno)); + warn("stat"); panic("cannot stat symbol table file %s\n", filename); } tblsize = stbuf.st_size - sizeof(struct symtableheader); @@ -580,7 +580,7 @@ initsymtable(filename) panic("cannot allocate space for symbol table\n"); if (read(fd, base, (int)tblsize) < 0 || read(fd, (char *)&hdr, sizeof(struct symtableheader)) < 0) { - fprintf(stderr, "read: %s\n", strerror(errno)); + warn("read"); panic("cannot read symbol table file %s\n", filename); } switch (command) { @@ -589,13 +589,9 @@ initsymtable(filename) * For normal continuation, insure that we are using * the next incremental tape */ - if (hdr.dumpdate != dumptime) { - if (hdr.dumpdate < dumptime) - fprintf(stderr, "Incremental tape too low\n"); - else - fprintf(stderr, "Incremental tape too high\n"); - exit(1); - } + if (hdr.dumpdate != dumptime) + errx(1, "Incremental tape too %s", + (hdr.dumpdate < dumptime) ? "low" : "high"); break; case 'R': /* diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c index 17c5b7b7075..eb4d52deef5 100644 --- a/sbin/restore/tape.c +++ b/sbin/restore/tape.c @@ -1,5 +1,5 @@ -/* $OpenBSD: tape.c,v 1.8 1997/04/16 04:07:40 millert Exp $ */ -/* $NetBSD: tape.c,v 1.22 1996/11/30 18:31:29 cgd Exp $ */ +/* $OpenBSD: tape.c,v 1.9 1997/07/05 20:51:26 millert Exp $ */ +/* $NetBSD: tape.c,v 1.26 1997/04/15 07:12:25 lukem Exp $ */ /* * Copyright (c) 1983, 1993 @@ -56,7 +56,7 @@ static char rcsid[] = "$NetBSD: tape.c,v 1.22 1996/11/30 18:31:29 cgd Exp $"; #include <ufs/ufs/dinode.h> #include <protocols/dumprestore.h> -#include <errno.h> +#include <err.h> #include <paths.h> #include <setjmp.h> #include <stdio.h> @@ -141,18 +141,14 @@ setinput(source) */ terminal = fopen(_PATH_TTY, "r"); if (terminal == NULL) { - (void)fprintf(stderr, "cannot open %s: %s\n", - _PATH_TTY, strerror(errno)); + warn("cannot open %s", _PATH_TTY); terminal = fopen(_PATH_DEVNULL, "r"); - if (terminal == NULL) { - (void)fprintf(stderr, "cannot open %s: %s\n", - _PATH_DEVNULL, strerror(errno)); - exit(1); - } + if (terminal == NULL) + err(1, "cannot open %s", _PATH_DEVNULL); } pipein++; } - (void) strcpy(magtape, source); + (void)strcpy(magtape, source); } void @@ -167,10 +163,8 @@ newtapebuf(size) if (tapebuf != NULL) free(tapebuf); tapebuf = malloc(size * TP_BSIZE); - if (tapebuf == NULL) { - fprintf(stderr, "Cannot allocate space for tape buffer\n"); - exit(1); - } + if (tapebuf == NULL) + errx(1, "Cannot allocate space for tape buffer"); tapebufsize = size; } @@ -184,7 +178,7 @@ setup() int i, j, *ip; struct stat stbuf; - vprintf(stdout, "Verify tape and initialize maps\n"); + Vprintf(stdout, "Verify tape and initialize maps\n"); #ifdef RRESTORE if (host) mt = rmtopen(magtape, 0); @@ -194,10 +188,8 @@ setup() mt = 0; else mt = open(magtape, O_RDONLY, 0); - if (mt < 0) { - fprintf(stderr, "%s: %s\n", magtape, strerror(errno)); - exit(1); - } + if (mt < 0) + err(1, magtape); volno = 1; setdumpnum(); FLUSHTAPEBUF(); @@ -208,11 +200,9 @@ setup() blksread--; tpblksread--; cvtflag++; - if (gethead(&spcl) == FAIL) { - fprintf(stderr, "Tape is not a dump tape\n"); - exit(1); - } - fprintf(stderr, "Converting to new file system format.\n"); + if (gethead(&spcl) == FAIL) + errx(1, "Tape is not a dump tape"); + (void)fputs("Converting to new file system format.\n", stderr); } if (pipein) { endoftapemark.s_spcl.c_magic = cvtflag ? OFS_MAGIC : NFS_MAGIC; @@ -229,43 +219,33 @@ setup() printdumpinfo(); dumptime = spcl.c_ddate; dumpdate = spcl.c_date; - if (stat(".", &stbuf) < 0) { - fprintf(stderr, "cannot stat .: %s\n", strerror(errno)); - exit(1); - } + if (stat(".", &stbuf) < 0) + err(1, "cannot stat ."); if (stbuf.st_blksize >= TP_BSIZE && stbuf.st_blksize <= MAXBSIZE) fssize = stbuf.st_blksize; - if (((fssize - 1) & fssize) != 0) { - fprintf(stderr, "bad block size %d\n", fssize); - exit(1); - } - if (spcl.c_volume != 1) { - fprintf(stderr, "Tape is not volume 1 of the dump\n"); - exit(1); - } + if (((fssize - 1) & fssize) != 0) + errx(1, "bad block size %ld", fssize); + if (spcl.c_volume != 1) + errx(1, "Tape is not volume 1 of the dump"); if (gethead(&spcl) == FAIL) { - dprintf(stdout, "header read failed at %d blocks\n", blksread); + Dprintf(stdout, "header read failed at %ld blocks\n", blksread); panic("no header after volume mark!\n"); } findinode(&spcl); - if (spcl.c_type != TS_CLRI) { - fprintf(stderr, "Cannot find file removal list\n"); - exit(1); - } + if (spcl.c_type != TS_CLRI) + errx(1, "Cannot find file removal list"); maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1; - dprintf(stdout, "maxino = %d\n", maxino); + Dprintf(stdout, "maxino = %d\n", maxino); map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY)); if (map == NULL) panic("no memory for active inode map\n"); usedinomap = map; curfile.action = USING; getfile(xtrmap, xtrmapskip); - if (spcl.c_type != TS_BITS) { - fprintf(stderr, "Cannot find file dump list\n"); - exit(1); - } - map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY)); - if (map == (char *)NULL) + if (spcl.c_type != TS_BITS) + errx(1, "Cannot find file dump list"); + map = calloc((size_t)1, (size_t)howmany(maxino, NBBY)); + if (map == NULL) panic("no memory for file dump list\n"); dumpmap = map; curfile.action = USING; @@ -313,7 +293,7 @@ again: if (command == 'R' || command == 'r' || curfile.action != SKIP) { newvol = nextvol; wantnext = 1; - } else { + } else { newvol = 0; wantnext = 0; } @@ -330,15 +310,15 @@ again: strcpy(buf, ": "); for (i = 1; i < 32; i++) if (tapesread & (1 << i)) { - fprintf(stderr, "%s%d", buf, i); + fprintf(stderr, "%s%ld", buf, i); strcpy(buf, ", "); } fprintf(stderr, "\n"); } do { fprintf(stderr, "Specify next volume #: "); - (void) fflush(stderr); - (void) fgets(buf, BUFSIZ, terminal); + (void)fflush(stderr); + (void)fgets(buf, BUFSIZ, terminal); } while (!feof(terminal) && buf[0] == '\n'); if (feof(terminal)) exit(1); @@ -353,11 +333,11 @@ again: return; } closemt(); - fprintf(stderr, "Mount tape volume %d\n", newvol); + fprintf(stderr, "Mount tape volume %ld\n", newvol); fprintf(stderr, "Enter ``none'' if there are no more tapes\n"); fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape); - (void) fflush(stderr); - (void) fgets(buf, BUFSIZ, terminal); + (void)fflush(stderr); + (void)fgets(buf, BUFSIZ, terminal); if (feof(terminal)) exit(1); if (!strcmp(buf, "none\n")) { @@ -365,7 +345,7 @@ again: return; } if (buf[0] != '\n') { - (void) strcpy(magtape, buf); + (void)strcpy(magtape, buf); magtape[strlen(magtape) - 1] = '\0'; } #ifdef RRESTORE @@ -385,7 +365,7 @@ gethdr: setdumpnum(); FLUSHTAPEBUF(); if (gethead(&tmpbuf) == FAIL) { - dprintf(stdout, "header read failed at %d blocks\n", blksread); + Dprintf(stdout, "header read failed at %ld blocks\n", blksread); fprintf(stderr, "tape is not dump tape\n"); volno = 0; goto again; @@ -411,7 +391,7 @@ gethdr: * If coming to this volume at random, skip to the beginning * of the next record. */ - dprintf(stdout, "read %ld recs, tape starts with %ld\n", + Dprintf(stdout, "read %ld recs, tape starts with %d\n", tpblksread, tmpbuf.c_firstrec); if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) { if (!wantnext) { @@ -424,8 +404,8 @@ gethdr: * -1 since we've read the volume header */ i = tpblksread - tmpbuf.c_firstrec - 1; - dprintf(stderr, "Skipping %d duplicate record%s.\n", - i, i > 1 ? "s" : ""); + Dprintf(stderr, "Skipping %ld duplicate record%s.\n", + i, (i == 1) ? "" : "s"); while (--i >= 0) readtape(buf); } @@ -441,7 +421,7 @@ gethdr: if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) for (i = tmpbuf.c_count; i > 0; i--) readtape(buf); - (void) gethead(&spcl); + (void)gethead(&spcl); findinode(&spcl); if (gettingfile) { gettingfile = 0; @@ -481,19 +461,17 @@ setdumpnum() if (dumpnum == 1 || volno != 1) return; - if (pipein) { - fprintf(stderr, "Cannot have multiple dumps on pipe input\n"); - exit(1); - } + if (pipein) + errx(1, "Cannot have multiple dumps on pipe input"); tcom.mt_op = MTFSF; tcom.mt_count = dumpnum - 1; #ifdef RRESTORE if (host) rmtioctl(MTFSF, dumpnum - 1); - else + else #endif if (ioctl(mt, (int)MTIOCTOP, (char *)&tcom) < 0) - fprintf(stderr, "ioctl MTFSF: %s\n", strerror(errno)); + warn("ioctl MTFSF"); } void @@ -534,7 +512,7 @@ extractfile(name) return (FAIL); case IFSOCK: - vprintf(stdout, "skipped socket %s\n", name); + Vprintf(stdout, "skipped socket %s\n", name); skipfile(); return (GOOD); @@ -546,7 +524,7 @@ extractfile(name) skipfile(); return (GOOD); } - vprintf(stdout, "extract file %s\n", name); + Vprintf(stdout, "extract file %s\n", name); return (genliteraldir(name, curfile.ino)); case IFLNK: { @@ -558,74 +536,71 @@ extractfile(name) pathlen = 0; getfile(xtrlnkfile, xtrlnkskip); if (pathlen == 0) { - vprintf(stdout, + Vprintf(stdout, "%s: zero length symbolic link (ignored)\n", name); return (GOOD); } if (linkit(lnkbuf, name, SYMLINK) == FAIL) return (FAIL); - (void) lchown(name, luid, lgid); + (void)lchown(name, luid, lgid); return (GOOD); } case IFCHR: case IFBLK: - vprintf(stdout, "extract special file %s\n", name); + Vprintf(stdout, "extract special file %s\n", name); if (Nflag) { skipfile(); return (GOOD); } if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) { - fprintf(stderr, "%s: cannot create special file: %s\n", - name, strerror(errno)); + warn("%s: cannot create special file", name); skipfile(); return (FAIL); } - (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid); - (void) chmod(name, mode); - (void) chflags(name, flags); + (void)chown(name, curfile.dip->di_uid, curfile.dip->di_gid); + (void)chmod(name, mode); + (void)chflags(name, flags); skipfile(); utimes(name, timep); return (GOOD); case IFIFO: - vprintf(stdout, "extract fifo %s\n", name); + Vprintf(stdout, "extract fifo %s\n", name); if (Nflag) { skipfile(); return (GOOD); } if (mkfifo(name, mode) < 0) { - fprintf(stderr, "%s: cannot create fifo: %s\n", - name, strerror(errno)); + warn("%s: cannot create fifo", name); skipfile(); return (FAIL); } - (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid); - (void) chmod(name, mode); - (void) chflags(name, flags); + (void)chown(name, curfile.dip->di_uid, curfile.dip->di_gid); + (void)chmod(name, mode); + (void)chflags(name, flags); skipfile(); utimes(name, timep); return (GOOD); case IFREG: - vprintf(stdout, "extract file %s\n", name); + Vprintf(stdout, "extract file %s\n", name); if (Nflag) { skipfile(); return (GOOD); } if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) { - fprintf(stderr, "%s: cannot create file: %s\n", - name, strerror(errno)); + warn("%s: cannot create file", name); skipfile(); return (FAIL); } - (void) fchown(ofile, curfile.dip->di_uid, curfile.dip->di_gid); - (void) fchmod(ofile, mode); - (void) fchflags(ofile, flags); + (void)fchown(ofile, curfile.dip->di_uid, curfile.dip->di_gid); + (void)fchmod(ofile, mode); + (void)fchflags(ofile, flags); getfile(xtrfile, xtrskip); - (void) close(ofile); + (void)close(ofile); utimes(name, timep); return (GOOD); } @@ -666,8 +641,8 @@ getfile(fill, skip) void (*skip) __P((char *, long)); { register int i; - int curblk = 0; - long size = spcl.c_dinode.di_size; + volatile int curblk = 0; + volatile long size = spcl.c_dinode.di_size; static char clearedbuf[MAXBSIZE]; char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE]; char junk[TP_BSIZE]; @@ -709,8 +684,8 @@ loop: if (gethead(&spcl) == GOOD && size > 0) { if (spcl.c_type == TS_ADDR) goto loop; - dprintf(stdout, - "Missing address (header) block for %s at %d blocks\n", + Dprintf(stdout, + "Missing address (header) block for %s at %ld blocks\n", curfile.name, blksread); } if (curblk > 0) @@ -730,12 +705,9 @@ xtrfile(buf, size) if (Nflag) return; - if (write(ofile, buf, (int) size) == -1) { - fprintf(stderr, - "write error extracting inode %d, name %s\nwrite: %s\n", - curfile.ino, curfile.name, strerror(errno)); - exit(1); - } + if (write(ofile, buf, (int) size) == -1) + err(1, "write error extracting inode %d, name %s\nwrite", + curfile.ino, curfile.name); } /* @@ -748,12 +720,9 @@ xtrskip(buf, size) long size; { - if (lseek(ofile, size, SEEK_CUR) == -1) { - fprintf(stderr, - "seek error extracting inode %d, name %s\nlseek: %s\n", - curfile.ino, curfile.name, strerror(errno)); - exit(1); - } + if (lseek(ofile, size, SEEK_CUR) == -1) + err(1, "seek error extracting inode %d, name %s\nlseek", + curfile.ino, curfile.name); } /* @@ -766,12 +735,10 @@ xtrlnkfile(buf, size) { pathlen += size; - if (pathlen > MAXPATHLEN) { - fprintf(stderr, "symbolic link name: %s->%s%s; too long %d\n", + if (pathlen > MAXPATHLEN) + errx(1, "symbolic link name: %s->%s%s; too long %d", curfile.name, lnkbuf, buf, pathlen); - exit(1); - } - (void) strcat(lnkbuf, buf); + (void)strcat(lnkbuf, buf); } /* @@ -784,9 +751,7 @@ xtrlnkskip(buf, size) long size; { - fprintf(stderr, "unallocated block in symbolic link %s\n", - curfile.name); - exit(1); + errx(1, "unallocated block in symbolic link %s", curfile.name); } /* @@ -864,7 +829,7 @@ getmore: * If found, skip rest of buffer and start with the next. */ if (!pipein && numtrec < ntrec && i > 0) { - dprintf(stdout, "mid-media short read error.\n"); + Dprintf(stdout, "mid-media short read error.\n"); numtrec = ntrec; } /* @@ -884,8 +849,8 @@ getmore: * Short read. Process the blocks read. */ if (i % TP_BSIZE != 0) - vprintf(stdout, - "partial block read: %d should be %d\n", + Vprintf(stdout, + "partial block read: %ld should be %ld\n", i, ntrec * TP_BSIZE); numtrec = i / TP_BSIZE; } @@ -921,17 +886,14 @@ getmore: #endif seek_failed = (lseek(mt, i, SEEK_CUR) == (off_t)-1); - if (seek_failed) { - fprintf(stderr, - "continuation failed: %s\n", strerror(errno)); - exit(1); - } + if (seek_failed) + err(1, "continuation failed"); } /* * Handle end of tape. */ if (i == 0) { - vprintf(stdout, "End-of-tape encountered\n"); + Vprintf(stdout, "End-of-tape encountered\n"); if (!pipein) { newvol = volno + 1; volno = 0; @@ -967,18 +929,16 @@ findtapeblksize() #endif i = read(mt, tapebuf, ntrec * TP_BSIZE); - if (i <= 0) { - fprintf(stderr, "tape read error: %s\n", strerror(errno)); - exit(1); - } + if (i <= 0) + err(1, "tape read error"); if (i % TP_BSIZE != 0) { - fprintf(stderr, "Tape block size (%d) %s (%d)\n", - i, "is not a multiple of dump block size", TP_BSIZE); - exit(1); + errx(1, + "Tape block size (%ld) is not a multiple of dump block size (%d)", + i, TP_BSIZE); } ntrec = i / TP_BSIZE; numtrec = ntrec; - vprintf(stdout, "Tape block size is %d\n", ntrec); + Vprintf(stdout, "Tape block size is %ld\n", ntrec); } void @@ -992,7 +952,7 @@ closemt() rmtclose(); else #endif - (void) close(mt); + (void)close(mt); } /* @@ -1028,7 +988,7 @@ gethead(buf) u_int16_t odi_gid; int32_t odi_size; int32_t odi_rdev; - char odi_addr[36]; + char odi_addr[36]; int32_t odi_atime; int32_t odi_mtime; int32_t odi_ctime; @@ -1044,7 +1004,7 @@ gethead(buf) if (swabl(buf->c_magic) != NFS_MAGIC) return (FAIL); if (!Bcvt) { - vprintf(stdout, "Note: Doing Byte swapping\n"); + Vprintf(stdout, "Note: Doing Byte swapping\n"); Bcvt = 1; } } @@ -1127,7 +1087,7 @@ good: break; } /* - * If we are restoring a filesystem with old format inodes, + * If we are restoring a filesystem with old format inodes, * copy the uid/gid to the new location. */ if (oldinofmt) { @@ -1181,7 +1141,7 @@ accthdr(header) break; } if (predict != blksread - 1) - fprintf(stderr, "; predicted %d blocks, got %d blocks", + fprintf(stderr, "; predicted %ld blocks, got %ld blocks", predict, blksread - 1); fprintf(stderr, "\n"); newcalc: @@ -1261,7 +1221,7 @@ findinode(header) } } while (header->c_type == TS_ADDR); if (skipcnt > 0) - fprintf(stderr, "resync restore, skipped %d blocks\n", skipcnt); + fprintf(stderr, "resync restore, skipped %ld blocks\n", skipcnt); skipcnt = 0; } @@ -1280,7 +1240,7 @@ checksum(buf) } else { /* What happens if we want to read restore tapes for a 16bit int machine??? */ - do + do i += swabl(*buf++); while (--j); } diff --git a/sbin/restore/utilities.c b/sbin/restore/utilities.c index 4d95aaffcd1..766cc3b2488 100644 --- a/sbin/restore/utilities.c +++ b/sbin/restore/utilities.c @@ -1,5 +1,5 @@ -/* $OpenBSD: utilities.c,v 1.2 1996/06/23 14:32:19 deraadt Exp $ */ -/* $NetBSD: utilities.c,v 1.9 1995/03/18 14:59:59 cgd Exp $ */ +/* $OpenBSD: utilities.c,v 1.3 1997/07/05 20:51:27 millert Exp $ */ +/* $NetBSD: utilities.c,v 1.11 1997/03/19 08:42:56 lukem Exp $ */ /* * Copyright (c) 1983, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)utilities.c 8.4 (Berkeley) 10/18/94"; #else -static char rcsid[] = "$OpenBSD: utilities.c,v 1.2 1996/06/23 14:32:19 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: utilities.c,v 1.3 1997/07/05 20:51:27 millert Exp $"; #endif #endif /* not lint */ @@ -48,7 +48,7 @@ static char rcsid[] = "$OpenBSD: utilities.c,v 1.2 1996/06/23 14:32:19 deraadt E #include <ufs/ufs/dinode.h> #include <ufs/ufs/dir.h> -#include <errno.h> +#include <err.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -98,7 +98,7 @@ mktempname(ep) if (ep->e_flags & TMPNAME) badentry(ep, "mktempname: called with TMPNAME"); ep->e_flags |= TMPNAME; - (void) strcpy(oldname, myname(ep)); + (void)strcpy(oldname, myname(ep)); freename(ep->e_name); ep->e_name = savename(gentempname(ep)); ep->e_namlen = strlen(ep->e_name); @@ -121,7 +121,7 @@ gentempname(ep) i++; if (np == NULL) badentry(ep, "not on ino list"); - (void) sprintf(name, "%s%d%d", TMPHDR, i, ep->e_ino); + (void)snprintf(name, sizeof(name), "%s%ld%d", TMPHDR, i, ep->e_ino); return (name); } @@ -133,11 +133,10 @@ renameit(from, to) char *from, *to; { if (!Nflag && rename(from, to) < 0) { - fprintf(stderr, "warning: cannot rename %s to %s: %s\n", - from, to, strerror(errno)); + warn("cannot rename %s to %s", from, to); return; } - vprintf(stdout, "rename %s to %s\n", from, to); + Vprintf(stdout, "rename %s to %s\n", from, to); } /* @@ -154,10 +153,10 @@ newnode(np) cp = myname(np); if (!Nflag && mkdir(cp, 0777) < 0) { np->e_flags |= EXISTED; - fprintf(stderr, "warning: %s: %s\n", cp, strerror(errno)); + warn(cp); return; } - vprintf(stdout, "Make node %s\n", cp); + Vprintf(stdout, "Make node %s\n", cp); } /* @@ -177,10 +176,10 @@ removenode(ep) ep->e_flags &= ~TMPNAME; cp = myname(ep); if (!Nflag && rmdir(cp) < 0) { - fprintf(stderr, "warning: %s: %s\n", cp, strerror(errno)); + warn(cp); return; } - vprintf(stdout, "Remove node %s\n", cp); + Vprintf(stdout, "Remove node %s\n", cp); } /* @@ -198,10 +197,10 @@ removeleaf(ep) ep->e_flags &= ~TMPNAME; cp = myname(ep); if (!Nflag && unlink(cp) < 0) { - fprintf(stderr, "warning: %s: %s\n", cp, strerror(errno)); + warn(cp); return; } - vprintf(stdout, "Remove leaf %s\n", cp); + Vprintf(stdout, "Remove leaf %s\n", cp); } /* @@ -215,23 +214,21 @@ linkit(existing, new, type) if (type == SYMLINK) { if (!Nflag && symlink(existing, new) < 0) { - fprintf(stderr, - "warning: cannot create symbolic link %s->%s: %s\n", - new, existing, strerror(errno)); + warn("cannot create symbolic link %s->%s", + new, existing); return (FAIL); } } else if (type == HARDLINK) { if (!Nflag && link(existing, new) < 0) { - fprintf(stderr, - "warning: cannot create hard link %s->%s: %s\n", - new, existing, strerror(errno)); + warn("cannot create hard link %s->%s", + new, existing); return (FAIL); } } else { panic("linkit: unknown type %d\n", type); return (FAIL); } - vprintf(stdout, "Create %s link %s->%s\n", + Vprintf(stdout, "Create %s link %s->%s\n", type == SYMLINK ? "symbolic" : "hard", new, existing); return (GOOD); } @@ -245,11 +242,10 @@ addwhiteout(name) { if (!Nflag && mknod(name, S_IFWHT, 0) < 0) { - fprintf(stderr, "warning: cannot create whiteout %s: %s\n", - name, strerror(errno)); + warn("cannot create whiteout %s", name); return (FAIL); } - vprintf(stdout, "Create whiteout %s\n", name); + Vprintf(stdout, "Create whiteout %s\n", name); return (GOOD); } @@ -268,11 +264,10 @@ delwhiteout(ep) ep->e_flags &= ~TMPNAME; name = myname(ep); if (!Nflag && undelete(name) < 0) { - fprintf(stderr, "warning: cannot delete whiteout %s: %s\n", - name, strerror(errno)); + warn("cannot delete whiteout %s", name); return; } - vprintf(stdout, "Delete whiteout %s\n", name); + Vprintf(stdout, "Delete whiteout %s\n", name); } /* @@ -336,7 +331,7 @@ badentry(ep, msg) "next hashchain name: %s\n", myname(ep->e_next)); fprintf(stderr, "entry type: %s\n", ep->e_type == NODE ? "NODE" : "LEAF"); - fprintf(stderr, "inode number: %ld\n", ep->e_ino); + fprintf(stderr, "inode number: %d\n", ep->e_ino); panic("flags: %s\n", flagvalues(ep)); } @@ -349,20 +344,20 @@ flagvalues(ep) { static char flagbuf[BUFSIZ]; - (void) strcpy(flagbuf, "|NIL"); + (void)strcpy(flagbuf, "|NIL"); flagbuf[0] = '\0'; if (ep->e_flags & REMOVED) - (void) strcat(flagbuf, "|REMOVED"); + (void)strcat(flagbuf, "|REMOVED"); if (ep->e_flags & TMPNAME) - (void) strcat(flagbuf, "|TMPNAME"); + (void)strcat(flagbuf, "|TMPNAME"); if (ep->e_flags & EXTRACT) - (void) strcat(flagbuf, "|EXTRACT"); + (void)strcat(flagbuf, "|EXTRACT"); if (ep->e_flags & NEW) - (void) strcat(flagbuf, "|NEW"); + (void)strcat(flagbuf, "|NEW"); if (ep->e_flags & KEEP) - (void) strcat(flagbuf, "|KEEP"); + (void)strcat(flagbuf, "|KEEP"); if (ep->e_flags & EXISTED) - (void) strcat(flagbuf, "|EXISTED"); + (void)strcat(flagbuf, "|EXISTED"); return (&flagbuf[1]); } @@ -375,7 +370,7 @@ dirlookup(name) { struct direct *dp; ino_t ino; - + ino = ((dp = pathsearch(name)) == NULL) ? 0 : dp->d_ino; if (ino == 0 || TSTINO(ino, dumpmap) == 0) @@ -394,7 +389,7 @@ reply(question) do { fprintf(stderr, "%s? [yn] ", question); - (void) fflush(stderr); + (void)fflush(stderr); c = getc(terminal); while (c != '\n' && getc(terminal) != '\n') if (feof(terminal)) |