From 394240ceca86d02b0219f84aead0483209db12fd Mon Sep 17 00:00:00 2001 From: Stelian Pop Date: Mon, 22 Nov 1999 21:39:42 +0000 Subject: [PATCH] 'M' multi-volume added in restore. --- restore/main.c | 19 ++++++++++------- restore/restore.h | 3 ++- restore/tape.c | 54 +++++++++++++++++++++++++++++++---------------- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/restore/main.c b/restore/main.c index 61ad4e6..624d4fa 100644 --- a/restore/main.c +++ b/restore/main.c @@ -40,7 +40,7 @@ #ifndef lint static const char rcsid[] = - "$Id: main.c,v 1.6 1999/10/13 09:57:21 stelian Exp $"; + "$Id: main.c,v 1.7 1999/11/22 21:39:42 tiniou Exp $"; #endif /* not lint */ #include @@ -125,9 +125,9 @@ main(int argc, char *argv[]) ; obsolete(&argc, &argv); #ifdef KERBEROS -#define optlist "b:CcdD:f:hikmNRrs:tT:uvxy" +#define optlist "b:CcdD:f:hikmMNRrs:tT:uvxy" #else -#define optlist "b:CcdD:f:himNRrs:tT:uvxy" +#define optlist "b:CcdD:f:himMNRrs:tT:uvxy" #endif while ((ch = getopt(argc, argv, optlist)) != -1) switch(ch) { @@ -178,6 +178,9 @@ main(int argc, char *argv[]) case 'm': mflag = 0; break; + case 'M': + Mflag = 1; + break; case 'N': Nflag = 1; break; @@ -360,11 +363,11 @@ usage(void) "%s %s\n", __progname, _DUMP_VERSION); (void)fprintf(stderr, "usage:\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n", - __progname, " -i [-ch" kerbflag "muvy] [-b blocksize] [-f file] [-s fileno]", - __progname, " -r [-c" kerbflag "uvy] [-b blocksize] [-f file] [-s fileno]", - __progname, " -R [-c" kerbflag "uvy] [-b blocksize] [-f file] [-s fileno]", - __progname, " -x [-ch" kerbflag "muvy] [-b blocksize] [-f file] [-s fileno] [file ...]", - __progname, " -t [-ch" kerbflag "kuvy] [-b blocksize] [-f file] [-s fileno] [file ...]"); + __progname, " -i [-ch" kerbflag "mMuvy] [-b blocksize] [-f file] [-s fileno]", + __progname, " -r [-c" kerbflag "Muvy] [-b blocksize] [-f file] [-s fileno]", + __progname, " -R [-c" kerbflag "Muvy] [-b blocksize] [-f file] [-s fileno]", + __progname, " -x [-ch" kerbflag "mMuvy] [-b blocksize] [-f file] [-s fileno] [file ...]", + __progname, " -t [-ch" kerbflag "Muvy] [-b blocksize] [-f file] [-s fileno] [file ...]"); exit(1); } diff --git a/restore/restore.h b/restore/restore.h index d6c4d99..a9aff91 100644 --- a/restore/restore.h +++ b/restore/restore.h @@ -4,7 +4,7 @@ * Remy Card , 1994-1997 * Stelian Pop , 1999 * - * $Id: restore.h,v 1.5 1999/10/13 09:57:21 stelian Exp $ + * $Id: restore.h,v 1.6 1999/11/22 21:39:42 tiniou Exp $ */ /* @@ -53,6 +53,7 @@ extern int bflag; /* set input block size */ extern int dflag; /* print out debugging info */ extern int hflag; /* restore heirarchies */ extern int mflag; /* restore by name instead of inode number */ +extern int Mflag; /* multi-volume restore */ extern int Nflag; /* do not write the disk */ extern int uflag; /* unlink symlink targets */ extern int vflag; /* print out actions taken */ diff --git a/restore/tape.c b/restore/tape.c index ba772a7..8edca63 100644 --- a/restore/tape.c +++ b/restore/tape.c @@ -45,7 +45,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.8 1999/11/11 16:14:01 tiniou Exp $"; + "$Id: tape.c,v 1.9 1999/11/22 21:39:42 tiniou Exp $"; #endif /* not lint */ #include @@ -81,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[NAME_MAX]; +static char magtapeprefix[NAME_MAX]; static int blkcnt; static int numtrec; static char *tapebuf; @@ -163,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, NAME_MAX); + magtapeprefix[NAME_MAX-1] = '\0'; + snprintf(magtape, NAME_MAX, "%s%03d", source, 1); + } + else + strncpy(magtape, source, NAME_MAX); + magtape[NAME_MAX - 1] = '\0'; } void @@ -294,6 +300,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; @@ -353,20 +360,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, NAME_MAX, "%s%03ld", magtapeprefix, newvol); + magtape[NAME_MAX - 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) @@ -378,6 +392,7 @@ again: if (mt == -1) { fprintf(stderr, "Cannot open %s\n", magtape); volno = -1; + haderror = 1; goto again; } gethdr: @@ -388,11 +403,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) { @@ -406,6 +423,7 @@ gethdr: fprintf(stderr, "\twanted: %s", ctime(&dumpdate)); #endif volno = 0; + haderror = 1; goto again; } tapesread |= 1 << volno; -- 2.39.5