-#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);
- /*
- * if throwing away the root inode, must also
- * discard the predefined lost+found directory.
- */
- if (BIT(ROOTINO, clrimap))
- BIS(LOSTFOUNDINO + 1, clrimap);
- for (ino = ROOTINO; 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);
- done(1);
- }
- ip->i_nlink = 0;
- ip->i_flag |= ICHG;
- iput(ip);
- }
- dp = &spcl.c_dinode;
- ip = ialloc(dev, ino, dp->di_mode);
- if (ip == NULL || ip->i_number != ino) {
- fprintf(stderr, "can't create inode %u\n", ino);
- done(1);
- }
- ip->i_mode = mode = dp->di_mode;
- ip->i_nlink = dp->di_nlink;
- ip->i_uid = dp->di_uid;
- ip->i_gid = dp->di_gid;
- ip->i_atime = dp->di_atime;
- ip->i_mtime = dp->di_mtime;
- ip->i_ctime = dp->di_ctime;
- type = ip->i_mode & IFMT;
- if (type == IFCHR || type == IFBLK)
- ip->i_rdev = dp->di_rdev;
- ip->i_size = 0;
- cur_ip = ip;
- u.u_offset = 0;
- u.u_segflg = 1;
- if (cvtdir && type == IFDIR)
- getfile(rstrcvtdir, rstrcvtskip, dp->di_size);
- else
- getfile(rstrfile, rstrskip, dp->di_size);
- ip->i_mode = mode;
- ip->i_flag &= ~(IUPD|IACC);
- ip->i_flag |= ICHG;
- iput(ip);
- }
-}