X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=restore%2Ftape.c;h=4bce13d97400c9bf9a1ba34e83cbd00c604b87f2;hp=ab0513a919573bf06e0e31b63059c8bc4b098791;hb=0d7af9c5f2cc7d4a97e934692ea8665e09fd5500;hpb=8d4197bb9ba5bbcef21409231ed8903b0cac353a diff --git a/restore/tape.c b/restore/tape.c index ab0513a..4bce13d 100644 --- a/restore/tape.c +++ b/restore/tape.c @@ -2,8 +2,7 @@ * Ported to Linux's Second Extended File System as part of the * dump and restore backup suit * Remy Card , 1994-1997 - * Stelian Pop , 1999 - * + * Stelian Pop , 1999-2000 */ /* @@ -45,11 +44,8 @@ */ #ifndef lint -#if 0 -static char sccsid[] = "@(#)tape.c 8.9 (Berkeley) 5/1/95"; -#endif static const char rcsid[] = - "$Id: tape.c,v 1.4 1999/10/11 13:08:10 stelian Exp $"; + "$Id: tape.c,v 1.13 2000/03/02 11:34:51 stelian Exp $"; #endif /* not lint */ #include @@ -85,7 +81,8 @@ static const char rcsid[] = static long fssize = MAXBSIZE; static int mt = -1; static int pipein = 0; -static char *magtape; +static char magtape[MAXPATHLEN]; +static char magtapeprefix[MAXPATHLEN]; static int blkcnt; static int numtrec; static char *tapebuf; @@ -167,9 +164,14 @@ setinput(char *source) pipein++; } setuid(getuid()); /* no longer need or want root privileges */ - magtape = strdup(source); - if (magtape == NULL) - errx(1, "Cannot allocate space for magtape buffer"); + if (Mflag) { + strncpy(magtapeprefix, source, MAXPATHLEN); + magtapeprefix[MAXPATHLEN-1] = '\0'; + snprintf(magtape, MAXPATHLEN, "%s%03d", source, 1); + } + else + strncpy(magtape, source, MAXPATHLEN); + magtape[MAXPATHLEN - 1] = '\0'; } void @@ -237,8 +239,17 @@ setup(void) } if (vflag || command == 't' || command == 'C') printdumpinfo(); - if (filesys == NULL) { - filesys = spcl.c_filesys; + if (filesys[0] == '\0') { + char *dirptr; +printf("spcl.c_filesys = %s\n", spcl.c_filesys); + strncpy(filesys, spcl.c_filesys, NAMELEN); + filesys[NAMELEN - 1] = '\0'; + dirptr = strstr(filesys, " (dir"); +printf("dirptr = %s\n", dirptr); + if (dirptr != NULL) + *dirptr = '\0'; +printf("dirptr = %s\n", dirptr); +printf("filesys = %s\n", filesys); } dumptime = spcl.c_ddate; dumpdate = spcl.c_date; @@ -260,7 +271,7 @@ setup(void) if (spcl.c_type != TS_CLRI) errx(1, "Cannot find file removal list"); maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1; - Dprintf(stdout, "maxino = %ld\n", maxino); + Dprintf(stdout, "maxino = %ld\n", (long)maxino); map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY)); if (map == NULL) panic("no memory for active inode map\n"); @@ -298,6 +309,7 @@ getvol(long nextvol) union u_spcl tmpspcl; # define tmpbuf tmpspcl.s_spcl char buf[TP_BSIZE]; + int haderror = 0; if (nextvol == 1) { tapesread = 0; @@ -357,20 +369,27 @@ again: return; } closemt(); - fprintf(stderr, "Mount tape volume %ld\n", (long)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); - if (feof(terminal)) - exit(1); - if (!strcmp(buf, "none\n")) { - terminateinput(); - return; + if (Mflag) { + snprintf(magtape, MAXPATHLEN, "%s%03ld", magtapeprefix, newvol); + magtape[MAXPATHLEN - 1] = '\0'; } - if (buf[0] != '\n') { - (void) strcpy(magtape, buf); - magtape[strlen(magtape) - 1] = '\0'; + if (!Mflag || haderror) { + haderror = 0; + fprintf(stderr, "Mount tape volume %ld\n", (long)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); + if (feof(terminal)) + exit(1); + if (!strcmp(buf, "none\n")) { + terminateinput(); + return; + } + if (buf[0] != '\n') { + (void) strcpy(magtape, buf); + magtape[strlen(magtape) - 1] = '\0'; + } } #ifdef RRESTORE if (host) @@ -382,6 +401,7 @@ again: if (mt == -1) { fprintf(stderr, "Cannot open %s\n", magtape); volno = -1; + haderror = 1; goto again; } gethdr: @@ -392,11 +412,13 @@ gethdr: Dprintf(stdout, "header read failed at %ld blocks\n", (long)blksread); fprintf(stderr, "tape is not dump tape\n"); volno = 0; + haderror = 1; goto again; } if (tmpbuf.c_volume != volno) { fprintf(stderr, "Wrong volume (%d)\n", tmpbuf.c_volume); volno = 0; + haderror = 1; goto again; } if (tmpbuf.c_date != dumpdate || tmpbuf.c_ddate != dumptime) { @@ -410,6 +432,7 @@ gethdr: fprintf(stderr, "\twanted: %s", ctime(&dumpdate)); #endif volno = 0; + haderror = 1; goto again; } tapesread |= 1 << volno; @@ -570,9 +593,11 @@ extractfile(char *name) return (genliteraldir(name, curfile.ino)); case IFLNK: - { uid_t luid = curfile.dip->di_uid; + { +#ifdef HAVE_LCHOWN + uid_t luid = curfile.dip->di_uid; gid_t lgid = curfile.dip->di_gid; - +#endif lnkbuf[0] = '\0'; pathlen = 0; getfile(xtrlnkfile, xtrlnkskip); @@ -583,7 +608,9 @@ extractfile(char *name) } if (linkit(lnkbuf, name, SYMLINK) == FAIL) return (FAIL); - (void) chown(name, luid, lgid); +#ifdef HAVE_LCHOWN + (void) lchown(name, luid, lgid); +#endif return (GOOD); } @@ -1421,7 +1448,7 @@ accthdr(struct s_spcl *header) fprintf(stderr, "File header, ino %lu", (unsigned long)previno); break; case TS_ADDR: - fprintf(stderr, "File continuation header, ino %ld", previno); + fprintf(stderr, "File continuation header, ino %ld", (long)previno); break; case TS_END: fprintf(stderr, "End of tape header");