- case 'R':
- restorfiles(command, argv);
- return;
- }
-}
-
-#ifndef STANDALONE
-extractfiles(argc, argv)
- int argc;
- char **argv;
-{
- char *ststore();
- register struct xtrlist *xp;
- struct xtrlist **xpp;
- struct fs *fs;
- ino_t d;
- int xtrfile(), xtrskip(), xtrcvtdir(), xtrcvtskip(), null();
- int mode;
- char name[BUFSIZ + 1];
-
- if (readhdr(&spcl) == 0) {
- fprintf(stderr, "Tape is not a dump tape\n");
- done(1);
- }
- if (checkvol(&spcl, 1) == 0) {
- fprintf(stderr, "Tape is not volume 1 of the dump\n");
- }
- fs = getfs(dev);
- msiz = roundup(howmany(fs->fs_ipg * fs->fs_ncg, NBBY), TP_BSIZE);
- clrimap = (char *)calloc(msiz, sizeof(char));
- dumpmap = (char *)calloc(msiz, sizeof(char));
- pass1(1); /* This sets the various maps on the way by */
- while (argc--) {
- if ((d = psearch(*argv)) == 0 || BIT(d,dumpmap) == 0) {
- fprintf(stdout, "%s: not on tape\n", *argv++);
- continue;
- }
- if (mflag)
- checkdir(*argv);
- if(hflag)
- getleaves(d, *argv++);
- else
- allocxtr(d, *argv++, XINUSE);
- }
- if (dumpnum > 1) {
- /*
- * if this is a multi-dump tape we always start with
- * volume 1, so as to avoid accidentally restoring
- * from a different dump!
- */
- resetmt();
- dumpnum = 1;
- volno = 1;
- readhdr(&spcl);
- goto rbits;
- }
-newvol:
- resetmt();
-getvol:
- fprintf(stderr, "Mount desired tape volume; Specify volume #: ");
- if (gets(tbf) == NULL)
- return;
- volno = atoi(tbf);
- if (volno <= 0) {
- fprintf(stderr, "Volume numbers are positive numerics\n");
- goto getvol;
- }
- if (readhdr(&spcl) == 0) {
- fprintf(stderr, "tape is not dump tape\n");
- goto newvol;
- }
- if (checkvol(&spcl, volno) == 0) {
- fprintf(stderr, "Wrong volume (%d)\n", spcl.c_volume);
- goto newvol;
- }
-rbits:
- while (gethead(&spcl) == 0)
- ;
- if (checktype(&spcl, TS_INODE) == 1) {
- fprintf(stderr, "Can't find inode mask!\n");
- goto newvol;
- }
- if (checktype(&spcl, TS_BITS) == 0)
- goto rbits;
- readbits(dumpmap);
- while (xtrcnt > 0) {
-again:
- if (ishead(&spcl) == 0)
- while(gethead(&spcl) == 0)
- ;
- if (checktype(&spcl, TS_END) == 1) {
- fprintf(stderr, "end of tape\n");
- break;
- }
- if (checktype(&spcl, TS_INODE) == 0) {
- gethead(&spcl);
- goto again;
- }
- d = spcl.c_inumber;
- for (xp = xtrlist[INOHASH(d)]; xp; xp = xp->x_next) {
- if (d != xp->x_ino)
- continue;
- if (xp->x_flags & XLINKED)
- continue;
- xp->x_timep[0] = spcl.c_dinode.di_atime;
- xp->x_timep[1] = spcl.c_dinode.di_mtime;
- mode = spcl.c_dinode.di_mode;
- if (mflag)
- strcpy(name, xp->x_name);
- else
- sprintf(name, "%u", xp->x_ino);
- switch (mode & IFMT) {
- default:
- fprintf(stderr, "%s: unknown file type\n", name);
- xp->x_flags |= XTRACTD;
- xtrcnt--;
- goto skipfile;
- case IFCHR:
- case IFBLK:
- fprintf(stdout, "extract special file %s\n", name);
- if (xmknod(name, mode, spcl.c_dinode.di_rdev)) {
- fprintf(stderr, "%s: cannot create special file\n", name);
- xp->x_flags |= XTRACTD;
- xtrcnt--;
- goto skipfile;
- }
- getfile(null, null, spcl.c_dinode.di_size);
- break;
- case IFDIR:
- if (mflag) {
- fprintf(stdout, "extract directory %s\n", name);
- strncat(name, "/.", BUFSIZ);
- checkdir(name);
- xchown(xp->x_name, spcl.c_dinode.di_uid, spcl.c_dinode.di_gid);
- getfile(null, null, spcl.c_dinode.di_size);
- break;
- }
- fprintf(stdout, "extract file %s\n", name);
- if ((ofile = xcreat(name, 0666)) < 0) {
- fprintf(stderr, "%s: cannot create file\n", name);
- xp->x_flags |= XTRACTD;
- xtrcnt--;
- goto skipfile;
- }
- xchown(name, spcl.c_dinode.di_uid, spcl.c_dinode.di_gid);
- if (cvtdir)
- getfile(xtrcvtdir, xtrcvtskip,
- spcl.c_dinode.di_size);
- else
- getfile(xtrfile, xtrskip,
- spcl.c_dinode.di_size);
- xclose(ofile);
- break;
- case IFREG:
- fprintf(stdout, "extract file %s\n", name);
- if ((ofile = xcreat(name, 0666)) < 0) {
- fprintf(stderr, "%s: cannot create file\n", name);
- xp->x_flags |= XTRACTD;
- xtrcnt--;
- goto skipfile;
- }
- xchown(name, spcl.c_dinode.di_uid, spcl.c_dinode.di_gid);
- getfile(xtrfile, xtrskip, spcl.c_dinode.di_size);
- xclose(ofile);
- break;
- }
- xchmod(name, mode);
- xutime(name, xp->x_timep);
- xp->x_flags |= XTRACTD;
- xtrcnt--;
- goto finished;
- }
-skipfile:
- getfile(null, null, spcl.c_dinode.di_size);
-finished:
- ;
- }
- if (xtrcnt == 0 && !mflag)
- return;
- for (xpp = xtrlist; xpp < &xtrlist[MAXINO]; xpp++) {
- for (xp = *xpp; xp; xp = xp->x_next) {
- if (mflag && (xp->x_flags & XISDIR))
- xutime(xp->x_name, xp->x_timep);
- if (xp->x_flags & XTRACTD)
- continue;
- if ((xp->x_flags & XLINKED) == 0) {
- fprintf(stderr, "cannot find file %s\n",
- xp->x_name);
- continue;
- }
- if (!mflag)
- continue;
- fprintf(stdout, "link %s to %s\n",
- xp->x_linkedto->x_name, xp->x_name);
- if (xlink(xp->x_linkedto->x_name, xp->x_name) < 0)
- fprintf(stderr, "link %s to %s failed\n",
- xp->x_linkedto->x_name, xp->x_name);
- }
- }
-}
-#endif
-
-restorfiles(command, argv)
- char command;
- char **argv;
-{
- int rstrfile(), rstrskip(), rstrcvtdir(), rstrcvtskip();
- register struct dinode *dp;
- register struct inode *ip;
- struct fs *fs;
- int mode, type;
- char mount[BUFSIZ + 1];
- char *ptr[2];
-
- mount[0] = '\0';
- strcpy(mount, "MOUNT=");
-#ifndef STANDALONE
- strncat(mount, *argv, BUFSIZ);
-#else
- fprintf(stderr, "Disk? ");
- gets(&mount[6]);
-#endif
- ptr[0] = mount;
- ptr[1] = 0;
- xmount(ptr);
- mounted++;
- iput(u.u_cdir); /* release root inode */
- iput(u.u_rdir); /* release root inode */
- fs = getfs(dev);
- maxi = fs->fs_ipg * fs->fs_ncg;
-#ifndef STANDALONE
- msiz = roundup(howmany(maxi, NBBY), TP_BSIZE);
- clrimap = (char *)calloc(msiz, sizeof(char));
- dumpmap = (char *)calloc(msiz, sizeof(char));
- if (command == 'R') {
- fprintf(stderr, "Enter starting volume number: ");
- if (gets(tbf) == EOF) {
- volno = 1;
- fprintf(stderr, "\n");
- }
- else
- volno = atoi(tbf);
- }
- else
-#endif
- volno = 1;
- fprintf(stderr, "Last chance before scribbling on %s. ",
-#ifdef STANDALONE
- "disk");
-#else
- *argv);
-#endif
- while (getchar() != '\n');
- if (readhdr(&spcl) == 0) {
- fprintf(stderr, "Missing volume record\n");
- done(1);
- }
- if (checkvol(&spcl, volno) == 0) {
- fprintf(stderr, "Tape is not volume %d\n", volno);
- done(1);
- }
- pass1(0);
- gethead(&spcl); /* volume header already checked above */
- gethead(&spcl);
- for (;;) {
-ragain:
- if (ishead(&spcl) == 0) {
- fprintf(stderr, "Missing header block\n");
- while (gethead(&spcl) == 0)
- ;
- eflag++;
- }
- if (checktype(&spcl, TS_END) == 1) {
- fprintf(stderr, "End of tape\n");
- close(mt);
- return;
- }
- if (checktype(&spcl, TS_CLRI) == 1) {
- readbits(clrimap);