- 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);
- 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 = dp->di_mode;
- ip->i_nlink = dp->di_nlink;
- ip->i_uid = dp->di_uid;
- ip->i_gid = dp->di_gid;
- ip->i_size = dp->di_size;
- ip->i_atime = dp->di_atime;
- ip->i_mtime = dp->di_mtime;
- ip->i_ctime = dp->di_ctime;
- cur_ip = ip;
- u.u_offset = 0;
- u.u_segflg = 1;
- getfile(rstrfile, rstrskip, dp->di_size);
- ip->i_flag |= ICHG;
- iput(ip);
- }
- }
-}
-
-/*
- * 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) {
- fprintf(stderr, "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(putdir, null, spcl.c_dinode.di_size);
- putent("\000\000/");
- }
-}
-#endif
-
-/*
- * Do the file extraction, calling the supplied functions
- * with the blocks
- */
-getfile(f1, f2, size)
- int (*f2)(), (*f1)();
- long size;
-{
- register i;
- struct spcl addrblock;
- char buf[BSIZE];
-
- addrblock = spcl;
- for (;;) {
- for (i = 0; i < addrblock.c_count; i++) {
- if (addrblock.c_addr[i]) {
- readtape(buf);
- (*f1)(buf, size > BSIZE ? (long) BSIZE : size);
- }
- else {
- (*f2)(clearedbuf, size > BSIZE ? (long) BSIZE : size);
- }
- if ((size -= BSIZE) <= 0) {
-eloop:
- while (gethead(&spcl) == 0)
- ;
- if (checktype(&spcl, TS_ADDR) == 1)
- goto eloop;
- return;
- }
- }
- if (gethead(&addrblock) == 0) {
- fprintf(stderr, "Missing address (header) block\n");
- goto eloop;
- }
- if (checktype(&addrblock, TS_ADDR) == 0) {
- spcl = addrblock;
- 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) {
- perror("Tape read error");
- eflag++;
- done(1);
- }
- if (i == 0) {
- bct = NTREC + 1;
- volno++;
-loop:
- flsht();
- close(mt);
- fprintf(stderr, "Mount volume %d\n", volno);
- while (getchar() != '\n')
- ;
- if ((mt = open(magtape, 0)) == -1) {
- fprintf(stderr, "Cannot open tape!\n");
- goto loop;
- }
- if (readhdr(&tmpbuf) == 0) {
- fprintf(stderr, "Not a dump tape.Try again\n");
- goto loop;
- }
- if (checkvol(&tmpbuf, volno) == 0) {
- fprintf(stderr, "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;