- }
- 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)
- sprintf(name, "%s", xp->x_name);
- else
- sprintf(name, "%u", xp->x_ino);
- switch (mode & IFMT) {
- default:
- fprintf(stderr, "%s: unknown file type\n");
- xp->x_flags |= XTRACTD;
- xtrcnt--;
- goto skipfile;
- case IFCHR:
- case IFBLK:
- if (vflag)
- fprintf(stderr, "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) {
- if (vflag)
- fprintf(stderr, "extract directory %s\n", name);
- strncat(name, "/.", BUFSIZ);
- checkdir( name );
- xchown(name, spcl.c_dinode.di_uid, spcl.c_dinode.di_gid);
- getfile(null, null, spcl.c_dinode.di_size);
- break;
- }
- /* else fall through */
- case IFREG:
- if (vflag)
- fprintf(stderr, "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, skip, 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 (vflag)
- fprintf(stderr, "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 failed\n");
- }
- }
-}
-#endif
-
-restorfiles(command, argv)
- char command;
- char **argv;
-{
- int rstrfile(), rstrskip();
- register struct dinode *dp;
- register struct inode *ip;
- struct fs *fs;
- int mode;
- char mount[BUFSIZ + 1];
- char *ptr[2];
-
-#ifndef STANDALONE
- mount[0] = '\0';
- strcpy(mount, "MOUNT=");
- strncat(mount, *argv, BUFSIZ);
- ptr[0] = mount;
- ptr[1] = 0;
- xmount(ptr);
- iput(u.u_cdir); /* release root inode */
- iput(u.u_rdir); /* release root inode */
- mounted++;
-#else
- do {
- fprintf(stderr, "Disk? ");
- gets(mount);
- fi = open(mount, 2);
- } while (fi == -1);
-#endif
-#ifndef STANDALONE
- 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');
- fs = getfs(dev);
- maxi = fs->fs_ipg * fs->fs_ncg;
- 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);
- }
- 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);
- for (ino = 1; ino <= maxi; ino++)
- if (BIT(ino, clrimap) == 0) {
- if (!iexist(dev, ino))
- continue;
- ip = iget(dev, ino);
- if (ip == NULL) {
- fprintf(stderr, "can't find inode %u\n", ino);
- done(1);
- }
- ip->i_nlink = 0;
- ip->i_flag |= ICHG;
- iput(ip);
- }
- goto ragain;
- }
- if (checktype(&spcl, TS_BITS) == 1) {
- readbits(dumpmap);
- goto ragain;
- }
- if (checktype(&spcl, TS_INODE) == 0) {
- fprintf(stderr, "Unknown header type\n");
- eflag++;
- gethead(&spcl);
- goto ragain;
- }
- ino = spcl.c_inumber;
- if (eflag)
- fprintf(stderr, "Resynced at inode %u\n", ino);
- eflag = 0;
- if (ino > maxi) {
- fprintf(stderr, "%u: ilist too small\n", ino);
- gethead(&spcl);
- goto ragain;
- }
- if (iexist(dev, ino)) {
- ip = iget(dev, ino);
- if (ip == NULL) {
- fprintf(stderr, "can't find inode %u\n",
- ino);