- default:
- printf("Bad key character %c\n", *cp);
- goto usage;
- }
- }
- if (command == 'x') {
- if (signal(SIGINT, done) == SIG_IGN)
- signal(SIGINT, SIG_IGN);
- if (signal(SIGTERM, done) == SIG_IGN)
- signal(SIGTERM, SIG_IGN);
-
- df = creat(dirfile, 0666);
- if (df < 0) {
- printf("restor: %s - cannot create directory temporary\n", dirfile);
- exit(1);
- }
- close(df);
- df = open(dirfile, 2);
- }
- doit(command, argc, argv);
- if (command == 'x')
- unlink(dirfile);
- exit(0);
-#else
- magtape = "tape";
- doit('r', 1, 0);
-#endif
-}
-
-doit(command, argc, argv)
-char command;
-int argc;
-char *argv[];
-{
- extern char *ctime();
- char *ststore();
- register k;
- ino_t d;
-#ifndef STANDALONE
- int xtrfile(), skip(), null();
-#endif
- int rstrfile(), rstrskip();
- struct dinode *ip, *ip1;
-
-#ifndef STANDALONE
- getxtrlist();
- if ((mt = open(magtape, 0)) < 0) {
- printf("%s: cannot open tape\n", magtape);
- exit(1);
- }
- if(dumpnum != 1) {
- tcom.mt_op = MTFSF;
- tcom.mt_count = dumpnum -1;
- if( ioctl(mt,MTIOCTOP,&tcom) < 0)
- perror("ioctl MTFSF");
- }
-#else
- do {
- printf("Tape? ");
- gets(mbuf);
- mt = open(mbuf, 0);
- } while (mt == -1);
- magtape = mbuf;
-#endif
- switch(command) {
-#ifndef STANDALONE
- case 't':
- if (readhdr(&spcl) == 0) {
- printf("Tape is not a dump tape\n");
- exit(1);
- }
- printf("Dump date: %s", ctime(&spcl.c_date));
- printf("Dumped from: %s", ctime(&spcl.c_ddate));
- return;
- case 'x':
- if (readhdr(&spcl) == 0) {
- printf("Tape is not a dump tape\n");
- exit(1);
- }
- if (checkvol(&spcl, 1) == 0) {
- printf("Tape is not volume 1 of the dump\n");
- }
- pass1(); /* This sets the various maps on the way by */
- i = 0;
- while( argc-- ) {
- if(hflag)
- getleaves( *argv++ );
- else {
- if( (d = psearch(*argv)) == 0 ||
- BIT(d,dumpmap) == 0 ) {
- printf( "%s: not on tape\n", *argv++ );
- continue;
- }
- xtrlist[i].x_ino = d;
- xtrlist[i].x_flags |= XINUSE;
- if( mflag )
- xtrlist[i].x_name = ststore( *argv );
- printf( "%s: inode %u\n", *argv, d );
- argv++;
- if( ++i >= xsize ) getxtrlist();
- }
- }
-
-
- if(dumpnum > 1)
- tcom.mt_op = MTBSF;
- else tcom.mt_op = MTREW;
- tcom.mt_count = 1;
-
-newvol:
- flsht();
- ioctl(mt,MTIOCTOP,&tcom);
- if( dumpnum > 1 ) {
- tcom.mt_op = MTFSF;
- tcom.mt_count = 1;
- ioctl(mt,MTIOCTOP,&tcom);
- }
-
-
-getvol:
- printf("Mount desired tape volume: Specify volume #: ");
- if (gets(tbf) == NULL)
- return;
- volno = atoi(tbf);
- if (volno <= 0) {
- printf("Volume numbers are positive numerics\n");
- goto getvol;
- }
- if (readhdr(&spcl) == 0) {
- printf("tape is not dump tape\n");
- goto newvol;
- }
- if (checkvol(&spcl, volno) == 0) {
- printf("Wrong volume (%d)\n", spcl.c_volume);
- goto newvol;
- }
-rbits:
- while (gethead(&spcl) == 0)
- ;
- if (checktype(&spcl, TS_INODE) == 1) {
- printf("Can't find inode mask!\n");
- goto newvol;
- }
- if (checktype(&spcl, TS_BITS) == 0)
- goto rbits;
- readbits(dumpmap);
- i = 0;
- for (k = 0; xtrlist[k].x_flags; k++) {
- if (BIT(xtrlist[k].x_ino, dumpmap)) {
- xtrlist[k].x_flags |= ONTAPE;
- i++;
- }
- }
- while (i > 0) {
-again:
- if (ishead(&spcl) == 0)
- while(gethead(&spcl) == 0)
- ;
- if (checktype(&spcl, TS_END) == 1) {
- printf("end of tape\n");
-checkdone:
- for (k = 0; xtrlist[k].x_flags; k++)
- if ((xtrlist[k].x_flags&XTRACTD) == 0) {
- /* get next tape */
- tcom.mt_op = MTREW;
-
- goto newvol;
- }
- return;
- }
- if (checktype(&spcl, TS_INODE) == 0) {
- gethead(&spcl);
- goto again;
- }
- d = spcl.c_inumber;
- for (k = 0; xtrlist[k].x_flags; k++) {
- if (d == xtrlist[k].x_ino) {
- if( mflag ) {
- sprintf(name, "%s", xtrlist[k].x_name);
- printf("extract file %s\n",name);
- checkdir( name );
- }
- else {
- printf("extract file %u\n", xtrlist[k].x_ino );
- sprintf(name, "%u", xtrlist[k].x_ino);
- }
- if ((ofile = creat(name, 0666)) < 0) {
- printf("%s: cannot create file\n", name);
- i--;
- continue;
- }
- chown(name, spcl.c_dinode.di_uid, spcl.c_dinode.di_gid);
- getfile(ino, xtrfile, skip, spcl.c_dinode.di_size);
- i--;
- xtrlist[k].x_flags |= XTRACTD;
- close(ofile);
- goto done;
- }
- }
- getfile(d, null, null, spcl.c_dinode.di_size);
-done:
- ;
- }
- goto checkdone;
-#endif
- case 'r':
- case 'R':
-#ifndef STANDALONE
- if ((fi = open(*argv, 2)) < 0) {
- printf("%s: cannot open\n", *argv);
- exit(1);
- }
-#else
- do {
- char charbuf[50];
-
- printf("Disk? ");
- gets(charbuf);
- fi = open(charbuf, 2);
- } while (fi == -1);
-#endif
-#ifndef STANDALONE
- if (command == 'R') {
- printf("Enter starting volume number: ");
- if (gets(tbf) == EOF) {
- volno = 1;
- printf("\n");
- }
- else
- volno = atoi(tbf);
- }
- else
-#endif
- volno = 1;
- printf("Last chance before scribbling on %s. ",
-#ifdef STANDALONE
- "disk");
-#else
- *argv);
-#endif
- while (getchar() != '\n');
- dread((daddr_t)1, (char *)&sblock, sizeof(sblock));
- maxi = (sblock.s_isize-2)*INOPB;
- if (readhdr(&spcl) == 0) {
- printf("Missing volume record\n");
- exit(1);
- }
- if (checkvol(&spcl, volno) == 0) {
- printf("Tape is not volume %d\n", volno);
- exit(1);
- }
- gethead(&spcl);
- for (;;) {
-ragain:
- if (ishead(&spcl) == 0) {
- printf("Missing header block\n");
- while (gethead(&spcl) == 0)
- ;
- eflag++;
- }
- if (checktype(&spcl, TS_END) == 1) {
- printf("End of tape\n");
- close(mt);
- dwrite( (daddr_t) 1, (char *) &sblock);
- return;
- }
- if (checktype(&spcl, TS_CLRI) == 1) {
- readbits(clrimap);
- for (ino = 1; ino <= maxi; ino++)
- if (BIT(ino, clrimap) == 0) {
- getdino(ino, &tino);
- if (tino.di_mode == 0)
- continue;
- itrunc(&tino);
- clri(&tino);
- putdino(ino, &tino);
- }
- dwrite( (daddr_t) 1, (char *) &sblock);
- goto ragain;
- }
- if (checktype(&spcl, TS_BITS) == 1) {
- readbits(dumpmap);
- goto ragain;
- }
- if (checktype(&spcl, TS_INODE) == 0) {
- printf("Unknown header type\n");
- eflag++;
- gethead(&spcl);
- goto ragain;
- }
- ino = spcl.c_inumber;
- if (eflag)
- printf("Resynced at inode %u\n", ino);
- eflag = 0;
- if (ino > maxi) {
- printf("%u: ilist too small\n", ino);
- gethead(&spcl);
- goto ragain;
- }
- dino = spcl.c_dinode;
- getdino(ino, &tino);
- curbno = 0;
- itrunc(&tino);
- clri(&tino);
- for (i = 0; i < NADDR; i++)
- taddr[i] = 0;
- l3tol(taddr, dino.di_addr, 1);
- getfile(d, rstrfile, rstrskip, dino.di_size);
- ip = &tino;
- ltol3(ip->di_addr, taddr, NADDR);
- ip1 = &dino;
- ip->di_mode = ip1->di_mode;
- ip->di_nlink = ip1->di_nlink;
- ip->di_uid = ip1->di_uid;
- ip->di_gid = ip1->di_gid;
- ip->di_size = ip1->di_size;
- ip->di_atime = ip1->di_atime;
- ip->di_mtime = ip1->di_mtime;
- ip->di_ctime = ip1->di_ctime;
- putdino(ino, &tino);
- }
- }
-}
-
-/*
- * Read the tape, bulding up a directory structure for extraction
- * by name
- */
-#ifndef STANDALONE
-pass1()
-{
- register i;
- struct dinode *ip;
- int putdir(), null();
-
- while (gethead(&spcl) == 0) {
- printf("Can't find directory header!\n");
- }
- for (;;) {
- if (checktype(&spcl, TS_BITS) == 1) {
- readbits(dumpmap);
- continue;
- }
- if (checktype(&spcl, TS_CLRI) == 1) {
- readbits(clrimap);
- continue;
- }
- if (checktype(&spcl, TS_INODE) == 0) {
-finish:
- flsh();
-/*
- close(mt);
-*/
- return;
- }
- ip = &spcl.c_dinode;
- i = ip->di_mode & IFMT;
- if (i != IFDIR) {
- goto finish;
- }
- inotab[ipos].t_ino = spcl.c_inumber;
- inotab[ipos++].t_seekpt = seekpt;
- getfile(spcl.c_inumber, putdir, null, spcl.c_dinode.di_size);
- putent("\000\000/");
- }
-}
-#endif
-
-/*
- * Do the file extraction, calling the supplied functions
- * with the blocks
- */
-getfile(n, f1, f2, size)
-ino_t n;
-int (*f2)(), (*f1)();
-long size;
-{
- register i;
- struct spcl addrblock;
- char buf[BSIZE];
-
- addrblock = spcl;
- curino = n;
- goto start;
- for (;;) {
- if (gethead(&addrblock) == 0) {
- printf("Missing address (header) block\n");
- goto eloop;
- }
- if (checktype(&addrblock, TS_ADDR) == 0) {
- spcl = addrblock;
- curino = 0;
- curino = 0;
- return;
- }
-start:
- for (i = 0; i < addrblock.c_count; i++) {
- if (addrblock.c_addr[i]) {
- readtape(buf);
- (*f1)(buf, size > BSIZE ? (long) BSIZE : size);
- }
- else {
- clearbuf(buf);
- (*f2)(buf, size > BSIZE ? (long) BSIZE : size);
- }
- if ((size -= BSIZE) <= 0) {
-eloop:
- while (gethead(&spcl) == 0)
- ;
- if (checktype(&spcl, TS_ADDR) == 1)
- goto eloop;
- curino = 0;
- return;
- }
- }
- }
-}
-
-/*
- * Do the tape i\/o, dealling with volume changes
- * etc..
- */
-readtape(b)
-char *b;
-{
- register i;
- struct spcl tmpbuf;
-
- if (bct >= NTREC) {
- for (i = 0; i < NTREC; i++)
- ((struct spcl *)&tbf[i*BSIZE])->c_magic = 0;
- bct = 0;
- if ((i = read(mt, tbf, NTREC*BSIZE)) < 0) {
- printf("Tape read error: inode %u\n", curino);
- eflag++;
- exit(1);
- }
- if (i == 0) {
- bct = NTREC + 1;
- volno++;
-loop:
- flsht();
- close(mt);
- printf("Mount volume %d\n", volno);
- while (getchar() != '\n')
- ;
- if ((mt = open(magtape, 0)) == -1) {
- printf("Cannot open tape!\n");
- goto loop;
- }
- if (readhdr(&tmpbuf) == 0) {
- printf("Not a dump tape.Try again\n");
- goto loop;
- }
- if (checkvol(&tmpbuf, volno) == 0) {
- printf("Wrong tape. Try again\n");
- goto loop;
- }
- readtape(b);
- return;
- }
- }
- copy(&tbf[(bct++*BSIZE)], b, BSIZE);
-}
-
-flsht()
-{
- bct = NTREC+1;
-}
-
-copy(f, t, s)
-register char *f, *t;
-{
- register i;
-
- i = s;
- do
- *t++ = *f++;
- while (--i);
-}
-
-clearbuf(cp)
-register char *cp;
-{
- register i;
-
- i = BSIZE;
- do
- *cp++ = 0;
- while (--i);
-}
-
-/*
- * Put and get the directory entries from the compressed
- * directory file
- */
-#ifndef STANDALONE
-putent(cp)
-char *cp;
-{
- register i;
-
- for (i = 0; i < sizeof(ino_t); i++)
- writec(*cp++);
- for (i = 0; i < DIRSIZ; i++) {
- writec(*cp);
- if (*cp++ == 0)
- return;
- }
- return;
-}
-
-getent(bf)
-register char *bf;
-{
- register i;
-
- for (i = 0; i < sizeof(ino_t); i++)
- *bf++ = readc();
- for (i = 0; i < DIRSIZ; i++)
- if ((*bf++ = readc()) == 0)
- return;
- return;
-}
-
-/*
- * read/write te directory file
- */
-writec(c)
-char c;
-{
- drblock[bpt++] = c;
- seekpt++;
- if (bpt >= BSIZE) {
- bpt = 0;
- write(df, drblock, BSIZE);
- }
-}
-
-readc()
-{
- if (bpt >= BSIZE) {
- nread = read(df, drblock, BSIZE);
- bpt = 0;
- }
- return(drblock[bpt++]);
-}
-
-mseek(pt)
-daddr_t pt;
-{
- bpt = BSIZE;
- lseek(df, pt, 0);
-}
-
-flsh()
-{
- write(df, drblock, bpt+1);
-}
-
-/*
- * search the directory inode ino
- * looking for entry cp
- */
-ino_t
-search(inum, cp)
-ino_t inum;
-char *cp;
-{
- register i;
-
- for (i = 0; i < MAXINO; i++)
- if (inotab[i].t_ino == inum) {
- goto found;
- }
- return(0);
-found:
- mseek(inotab[i].t_seekpt);
- do {
- getent((char *)&dir);
- if (direq(dir.d_name, "/"))
- return(0);
- } while (direq(dir.d_name, cp) == 0);
- return(dir.d_ino);
-}
-
-/*
- * Search the directory tree rooted at inode 2
- * for the path pointed at by n
- */
-psearch(n)
-char *n;
-{
- register char *cp, *cp1;
- char c;
-
- ino = 2;
- if (*(cp = n) == '/')
- cp++;
-next:
- cp1 = cp + 1;
- while (*cp1 != '/' && *cp1)
- cp1++;
- c = *cp1;
- *cp1 = 0;
- ino = search(ino, cp);
- if (ino == 0) {
- *cp1 = c;
- return(0);
- }
- *cp1 = c;
- if (c == '/') {
- cp = cp1+1;
- goto next;
- }
- return(ino);
-}
-
-direq(s1, s2)
-register char *s1, *s2;
-{
- register i;
-
- for (i = 0; i < DIRSIZ; i++)
- if (*s1++ == *s2) {
- if (*s2++ == 0)
- return(1);
- } else
- return(0);
- return(1);
-}
-#endif
-
-/*
- * read/write a disk block, be sure to update the buffer
- * cache if needed.
- */
-dwrite(bno, b)
-daddr_t bno;
-char *b;
-{
- register i;
-
- for (i = 0; i < NCACHE; i++) {
- if (cache[i].c_bno == bno) {
- copy(b, cache[i].c_block, BSIZE);
- cache[i].c_time = 0;