2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 static char sccsid[] = "@(#)tape.c 8.9 (Berkeley) 5/1/95";
43 static const char rcsid[] =
47 #include <sys/param.h>
53 #include <ufs/ufs/dinode.h>
54 #include <protocols/dumprestore.h>
68 static long fssize = MAXBSIZE;
70 static int pipein = 0;
75 static union u_spcl endoftapemark;
76 static long blksread; /* blocks read since last header */
77 static long tpblksread = 0; /* TP_BSIZE blocks read */
78 static long tapesread;
79 static jmp_buf restart;
80 static int gettingfile = 0; /* restart has a valid frame */
81 static char *host = NULL;
85 static char lnkbuf[MAXPATHLEN + 1];
88 int oldinofmt; /* old inode format conversion required */
89 int Bcvt; /* Swap Bytes (for CCI or sun) */
90 static int Qcvt; /* Swap quads (for sun) */
92 #define FLUSHTAPEBUF() blkcnt = ntrec + 1
94 static void accthdr __P((struct s_spcl *));
95 static int checksum __P((int *));
96 static void findinode __P((struct s_spcl *));
97 static void findtapeblksize __P((void));
98 static int gethead __P((struct s_spcl *));
99 static void readtape __P((char *));
100 static void setdumpnum __P((void));
101 static u_long swabl __P((u_long));
102 static u_char *swablong __P((u_char *, int));
103 static u_char *swabshort __P((u_char *, int));
104 static void terminateinput __P((void));
105 static void xtrfile __P((char *, long));
106 static void xtrlnkfile __P((char *, long));
107 static void xtrlnkskip __P((char *, long));
108 static void xtrmap __P((char *, long));
109 static void xtrmapskip __P((char *, long));
110 static void xtrskip __P((char *, long));
112 static int readmapflag;
115 * Set up an input source
125 newtapebuf(NTREC > HIGHDENSITYTREC ? NTREC : HIGHDENSITYTREC);
129 if (strchr(source, ':')) {
131 source = strchr(host, ':');
133 if (rmthost(host) == 0)
137 if (strcmp(source, "-") == 0) {
139 * Since input is coming from a pipe we must establish
140 * our own connection to the terminal.
142 terminal = fopen(_PATH_TTY, "r");
143 if (terminal == NULL) {
144 (void)fprintf(stderr, "cannot open %s: %s\n",
145 _PATH_TTY, strerror(errno));
146 terminal = fopen(_PATH_DEVNULL, "r");
147 if (terminal == NULL) {
148 (void)fprintf(stderr, "cannot open %s: %s\n",
149 _PATH_DEVNULL, strerror(errno));
155 setuid(getuid()); /* no longer need or want root privileges */
156 magtape = strdup(source);
157 if (magtape == NULL) {
158 fprintf(stderr, "Cannot allocate space for magtape buffer\n");
167 static tapebufsize = -1;
170 if (size <= tapebufsize)
174 tapebuf = malloc(size * TP_BSIZE);
175 if (tapebuf == NULL) {
176 fprintf(stderr, "Cannot allocate space for tape buffer\n");
183 * Verify that the tape drive can be accessed and
184 * that it actually is a dump tape.
192 vprintf(stdout, "Verify tape and initialize maps\n");
195 mt = rmtopen(magtape, 0);
201 mt = open(magtape, O_RDONLY, 0);
203 fprintf(stderr, "%s: %s\n", magtape, strerror(errno));
209 if (!pipein && !bflag)
211 if (gethead(&spcl) == FAIL) {
212 blkcnt--; /* push back this block */
216 if (gethead(&spcl) == FAIL) {
217 fprintf(stderr, "Tape is not a dump tape\n");
220 fprintf(stderr, "Converting to new file system format.\n");
223 endoftapemark.s_spcl.c_magic = cvtflag ? OFS_MAGIC : NFS_MAGIC;
224 endoftapemark.s_spcl.c_type = TS_END;
225 ip = (int *)&endoftapemark;
226 j = sizeof(union u_spcl) / sizeof(int);
231 endoftapemark.s_spcl.c_checksum = CHECKSUM - i;
233 if (vflag || command == 't')
235 dumptime = _time32_to_time(spcl.c_ddate);
236 dumpdate = _time32_to_time(spcl.c_date);
237 if (stat(".", &stbuf) < 0) {
238 fprintf(stderr, "cannot stat .: %s\n", strerror(errno));
241 if (stbuf.st_blksize > 0 && stbuf.st_blksize < TP_BSIZE )
243 if (stbuf.st_blksize >= TP_BSIZE && stbuf.st_blksize <= MAXBSIZE)
244 fssize = stbuf.st_blksize;
245 if (((fssize - 1) & fssize) != 0) {
246 fprintf(stderr, "bad block size %ld\n", fssize);
249 if (spcl.c_volume != 1) {
250 fprintf(stderr, "Tape is not volume 1 of the dump\n");
253 if (gethead(&spcl) == FAIL) {
254 dprintf(stdout, "header read failed at %ld blocks\n", blksread);
255 panic("no header after volume mark!\n");
258 if (spcl.c_type != TS_CLRI) {
259 fprintf(stderr, "Cannot find file removal list\n");
262 maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1;
263 dprintf(stdout, "maxino = %d\n", maxino);
264 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
266 panic("no memory for active inode map\n");
268 curfile.action = USING;
269 getfile(xtrmap, xtrmapskip);
270 if (spcl.c_type != TS_BITS) {
271 fprintf(stderr, "Cannot find file dump list\n");
274 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
275 if (map == (char *)NULL)
276 panic("no memory for file dump list\n");
278 curfile.action = USING;
279 getfile(xtrmap, xtrmapskip);
281 * If there may be whiteout entries on the tape, pretend that the
282 * whiteout inode exists, so that the whiteout entries can be
286 SETINO(WINO, dumpmap);
290 * Prompt user to load a new dump volume.
291 * "Nextvol" is the next suggested volume to use.
292 * This suggested volume is enforced when doing full
293 * or incremental restores, but can be overridden by
294 * the user when only extracting a subset of the files.
300 long newvol, savecnt, savetpcnt, i;
301 union u_spcl tmpspcl;
302 # define tmpbuf tmpspcl.s_spcl
311 panic("Changing volumes on pipe input?\n");
312 /* Avoid looping if we couldn't ask the user. */
313 if (yflag || ferror(terminal) || feof(terminal))
321 savetpcnt = tpblksread;
323 tpblksread = savetpcnt;
325 done(1); /* pipes do not get a second chance */
326 if (command == 'R' || command == 'r' || curfile.action != SKIP)
330 while (newvol <= 0) {
331 if (tapesread == 0) {
332 fprintf(stderr, "%s%s%s%s%s",
333 "You have not read any tapes yet.\n",
334 "Unless you know which volume your",
335 " file(s) are on you should start\n",
336 "with the last volume and work",
337 " towards the first.\n");
339 fprintf(stderr, "You have read volumes");
341 for (i = 1; i < 32; i++)
342 if (tapesread & (1 << i)) {
343 fprintf(stderr, "%s%ld", buf, i);
346 fprintf(stderr, "\n");
349 fprintf(stderr, "Specify next volume #: ");
350 (void) fflush(stderr);
351 if (fgets(buf, BUFSIZ, terminal) == NULL)
353 } while (buf[0] == '\n');
357 "Volume numbers are positive numerics\n");
360 if (newvol == volno) {
361 tapesread |= 1 << volno;
365 fprintf(stderr, "Mount tape volume %ld\n", newvol);
366 fprintf(stderr, "Enter ``none'' if there are no more tapes\n");
367 fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape);
368 (void) fflush(stderr);
369 if (fgets(buf, BUFSIZ, terminal) == NULL)
371 if (!strcmp(buf, "none\n")) {
375 if (buf[0] != '\n') {
376 (void) strcpy(magtape, buf);
377 magtape[strlen(magtape) - 1] = '\0';
381 mt = rmtopen(magtape, 0);
384 mt = open(magtape, O_RDONLY, 0);
387 fprintf(stderr, "Cannot open %s\n", magtape);
395 if (gethead(&tmpbuf) == FAIL) {
396 dprintf(stdout, "header read failed at %ld blocks\n", blksread);
397 fprintf(stderr, "tape is not dump tape\n");
401 if (tmpbuf.c_volume != volno) {
402 fprintf(stderr, "Wrong volume (%ld)\n", tmpbuf.c_volume);
406 if (_time32_to_time(tmpbuf.c_date) != dumpdate ||
407 _time32_to_time(tmpbuf.c_ddate) != dumptime) {
408 time_t t = _time32_to_time(tmpbuf.c_date);
409 fprintf(stderr, "Wrong dump date\n\tgot: %s", ctime(&t));
410 fprintf(stderr, "\twanted: %s", ctime(&dumpdate));
414 tapesread |= 1 << volno;
417 * If continuing from the previous volume, skip over any
418 * blocks read already at the end of the previous volume.
420 * If coming to this volume at random, skip to the beginning
421 * of the next record.
423 dprintf(stdout, "read %ld recs, tape starts with %ld\n",
424 tpblksread, tmpbuf.c_firstrec);
425 if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) {
426 if (curfile.action != USING) {
427 tpblksread = tmpbuf.c_firstrec;
429 * XXX Dump incorrectly sets c_count to 1 in the
430 * volume header of the first tape, so ignore
431 * c_count when volno == 1.
434 for (i = tmpbuf.c_count; i > 0; i--)
436 } else if (tmpbuf.c_firstrec > 0 &&
437 tmpbuf.c_firstrec < tpblksread - 1) {
439 * -1 since we've read the volume header
441 i = tpblksread - tmpbuf.c_firstrec - 1;
442 dprintf(stderr, "Skipping %ld duplicate record%s.\n",
443 i, i > 1 ? "s" : "");
448 if (curfile.action == USING) {
450 panic("active file into volume 1\n");
453 (void) gethead(&spcl);
462 * Handle unexpected EOF.
468 if (gettingfile && curfile.action == USING) {
469 printf("Warning: %s %s\n",
470 "End-of-input encountered while extracting", curfile.name);
472 curfile.name = "<name unknown>";
473 curfile.action = UNKNOWN;
475 curfile.ino = maxino;
483 * handle multiple dumps per tape by skipping forward to the
491 if (dumpnum == 1 || volno != 1)
494 fprintf(stderr, "Cannot have multiple dumps on pipe input\n");
498 tcom.mt_count = dumpnum - 1;
501 rmtioctl(MTFSF, dumpnum - 1);
504 if (ioctl(mt, MTIOCTOP, (char *)&tcom) < 0)
505 fprintf(stderr, "ioctl MTFSF: %s\n", strerror(errno));
512 t = _time32_to_time(spcl.c_date);
513 fprintf(stdout, "Dump date: %s", ctime(&t));
514 t = _time32_to_time(spcl.c_ddate);
515 fprintf(stdout, "Dumped from: %s",
516 (spcl.c_ddate == 0) ? "the epoch\n" : ctime(&t));
517 if (spcl.c_host[0] == '\0')
519 fprintf(stderr, "Level %ld dump of %s on %s:%s\n",
520 spcl.c_level, spcl.c_filesys, spcl.c_host, spcl.c_dev);
521 fprintf(stderr, "Label: %s\n", spcl.c_label);
530 struct timeval timep[2];
534 curfile.action = USING;
535 timep[0].tv_sec = curfile.dip->di_atime;
536 timep[0].tv_usec = curfile.dip->di_atimensec / 1000;
537 timep[1].tv_sec = curfile.dip->di_mtime;
538 timep[1].tv_usec = curfile.dip->di_mtimensec / 1000;
539 mode = curfile.dip->di_mode;
540 flags = curfile.dip->di_flags;
541 switch (mode & IFMT) {
544 fprintf(stderr, "%s: unknown file mode 0%o\n", name, mode);
549 vprintf(stdout, "skipped socket %s\n", name);
555 ep = lookupname(name);
556 if (ep == NULL || ep->e_flags & EXTRACT)
557 panic("unextracted directory %s\n", name);
561 vprintf(stdout, "extract file %s\n", name);
562 return (genliteraldir(name, curfile.ino));
567 getfile(xtrlnkfile, xtrlnkskip);
570 "%s: zero length symbolic link (ignored)\n", name);
573 return (linkit(lnkbuf, name, SYMLINK));
576 vprintf(stdout, "extract fifo %s\n", name);
583 if (mkfifo(name, mode) < 0) {
584 fprintf(stderr, "%s: cannot create fifo: %s\n",
585 name, strerror(errno));
589 (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
590 (void) chmod(name, mode);
592 (void) chflags(name, flags);
598 vprintf(stdout, "extract special file %s\n", name);
605 if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) {
606 fprintf(stderr, "%s: cannot create special file: %s\n",
607 name, strerror(errno));
611 (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
612 (void) chmod(name, mode);
614 (void) chflags(name, flags);
619 vprintf(stdout, "extract file %s\n", name);
626 if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
628 fprintf(stderr, "%s: cannot create file: %s\n",
629 name, strerror(errno));
633 (void) fchown(ofile, curfile.dip->di_uid, curfile.dip->di_gid);
634 (void) fchmod(ofile, mode);
635 getfile(xtrfile, xtrskip);
638 (void) chflags(name, flags);
645 * skip over bit maps on the tape
651 while (spcl.c_type == TS_BITS || spcl.c_type == TS_CLRI)
656 * skip over a file on the tape
662 curfile.action = SKIP;
663 getfile(xtrnull, xtrnull);
667 * Extract a file from the tape.
668 * When an allocated block is found it is passed to the fill function;
669 * when an unallocated block (hole) is found, a zeroed buffer is passed
670 * to the skip function.
674 void (*fill) __P((char *, long));
675 void (*skip) __P((char *, long));
679 quad_t size = spcl.c_dinode.di_size;
680 static char clearedbuf[MAXBSIZE];
681 char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE];
684 if (spcl.c_type == TS_END)
685 panic("ran off end of tape\n");
686 if (spcl.c_magic != NFS_MAGIC)
687 panic("not at beginning of a file\n");
688 if (!gettingfile && setjmp(restart) != 0)
692 for (i = 0; i < spcl.c_count; i++) {
693 if (readmapflag || spcl.c_addr[i]) {
694 readtape(&buf[curblk++][0]);
695 if (curblk == fssize / TP_BSIZE) {
696 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
697 fssize : (curblk - 1) * TP_BSIZE + size));
702 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
704 (curblk - 1) * TP_BSIZE + size));
707 (*skip)(clearedbuf, (long)(size > TP_BSIZE ?
710 if ((size -= TP_BSIZE) <= 0) {
711 for (i++; i < spcl.c_count; i++)
712 if (readmapflag || spcl.c_addr[i])
717 if (gethead(&spcl) == GOOD && size > 0) {
718 if (spcl.c_type == TS_ADDR)
721 "Missing address (header) block for %s at %ld blocks\n",
722 curfile.name, blksread);
725 (*fill)((char *)buf, (long)((curblk * TP_BSIZE) + size));
731 * Write out the next block of a file.
741 if (write(ofile, buf, (int) size) == -1) {
743 "write error extracting inode %d, name %s\nwrite: %s\n",
744 curfile.ino, curfile.name, strerror(errno));
749 * Skip over a hole in a file.
758 if (lseek(ofile, size, SEEK_CUR) == -1) {
760 "seek error extracting inode %d, name %s\nlseek: %s\n",
761 curfile.ino, curfile.name, strerror(errno));
767 * Collect the next block of a symbolic link.
770 xtrlnkfile(buf, size)
776 if (pathlen > MAXPATHLEN) {
777 fprintf(stderr, "symbolic link name: %s->%s%s; too long %d\n",
778 curfile.name, lnkbuf, buf, pathlen);
781 (void) strcat(lnkbuf, buf);
785 * Skip over a hole in a symbolic link (should never happen).
789 xtrlnkskip(buf, size)
794 fprintf(stderr, "unallocated block in symbolic link %s\n",
800 * Collect the next block of a bit map.
808 memmove(map, buf, size);
813 * Skip over a hole in a bit map (should never happen).
817 xtrmapskip(buf, size)
822 panic("hole in map\n");
827 * Noop, when an extraction function is not needed.
840 * Read TP_BSIZE blocks from the input.
841 * Handle read errors, and end of media.
848 int cnt, seek_failed;
850 if (blkcnt < numtrec) {
851 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
856 for (i = 0; i < ntrec; i++)
857 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
860 cnt = ntrec * TP_BSIZE;
865 i = rmtread(&tapebuf[rd], cnt);
868 i = read(mt, &tapebuf[rd], cnt);
870 * Check for mid-tape short read error.
871 * If found, skip rest of buffer and start with the next.
873 if (!pipein && numtrec < ntrec && i > 0) {
874 dprintf(stdout, "mid-media short read error.\n");
878 * Handle partial block read.
880 if (pipein && i == 0 && rd > 0)
882 else if (i > 0 && i != ntrec * TP_BSIZE) {
891 * Short read. Process the blocks read.
893 if (i % TP_BSIZE != 0)
895 "partial block read: %ld should be %ld\n",
896 i, ntrec * TP_BSIZE);
897 numtrec = i / TP_BSIZE;
904 fprintf(stderr, "Tape read error while ");
905 switch (curfile.action) {
907 fprintf(stderr, "trying to set up tape\n");
910 fprintf(stderr, "trying to resynchronize\n");
913 fprintf(stderr, "restoring %s\n", curfile.name);
916 fprintf(stderr, "skipping over inode %d\n",
920 if (!yflag && !reply("continue"))
922 i = ntrec * TP_BSIZE;
923 memset(tapebuf, 0, i);
926 seek_failed = (rmtseek(i, 1) < 0);
929 seek_failed = (lseek(mt, i, SEEK_CUR) == (off_t)-1);
933 "continuation failed: %s\n", strerror(errno));
938 * Handle end of tape.
941 vprintf(stdout, "End-of-tape encountered\n");
950 if (rd % TP_BSIZE != 0)
951 panic("partial block read: %d should be %d\n",
952 rd, ntrec * TP_BSIZE);
954 memmove(&tapebuf[rd], &endoftapemark, (long)TP_BSIZE);
957 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
967 for (i = 0; i < ntrec; i++)
968 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
972 i = rmtread(tapebuf, ntrec * TP_BSIZE);
975 i = read(mt, tapebuf, ntrec * TP_BSIZE);
978 fprintf(stderr, "tape read error: %s\n", strerror(errno));
981 if (i % TP_BSIZE != 0) {
982 fprintf(stderr, "Tape block size (%ld) %s (%d)\n",
983 i, "is not a multiple of dump block size", TP_BSIZE);
986 ntrec = i / TP_BSIZE;
988 vprintf(stdout, "Tape block size is %ld\n", ntrec);
1006 * Read the next block from the tape.
1007 * Check to see if it is one of several vintage headers.
1008 * If it is an old style header, convert it to a new style header.
1009 * If it is not any valid header, return an error.
1021 char dummy[TP_BSIZE];
1032 unsigned short odi_mode;
1049 readtape((char *)buf);
1050 if (buf->c_magic != NFS_MAGIC) {
1051 if (swabl(buf->c_magic) != NFS_MAGIC)
1054 vprintf(stdout, "Note: Doing Byte swapping\n");
1058 if (checksum((int *)buf) == FAIL)
1061 swabst((u_char *)"8l4s31l", (u_char *)buf);
1062 swabst((u_char *)"l",(u_char *) &buf->c_level);
1063 swabst((u_char *)"2l",(u_char *) &buf->c_flags);
1067 readtape((char *)(&u_ospcl.s_ospcl));
1068 memset(buf, 0, (long)TP_BSIZE);
1069 buf->c_type = u_ospcl.s_ospcl.c_type;
1070 buf->c_date = u_ospcl.s_ospcl.c_date;
1071 buf->c_ddate = u_ospcl.s_ospcl.c_ddate;
1072 buf->c_volume = u_ospcl.s_ospcl.c_volume;
1073 buf->c_tapea = u_ospcl.s_ospcl.c_tapea;
1074 buf->c_inumber = u_ospcl.s_ospcl.c_inumber;
1075 buf->c_checksum = u_ospcl.s_ospcl.c_checksum;
1076 buf->c_magic = u_ospcl.s_ospcl.c_magic;
1077 buf->c_dinode.di_mode = u_ospcl.s_ospcl.c_dinode.odi_mode;
1078 buf->c_dinode.di_nlink = u_ospcl.s_ospcl.c_dinode.odi_nlink;
1079 buf->c_dinode.di_uid = u_ospcl.s_ospcl.c_dinode.odi_uid;
1080 buf->c_dinode.di_gid = u_ospcl.s_ospcl.c_dinode.odi_gid;
1081 buf->c_dinode.di_size = u_ospcl.s_ospcl.c_dinode.odi_size;
1082 buf->c_dinode.di_rdev = u_ospcl.s_ospcl.c_dinode.odi_rdev;
1083 buf->c_dinode.di_atime = u_ospcl.s_ospcl.c_dinode.odi_atime;
1084 buf->c_dinode.di_mtime = u_ospcl.s_ospcl.c_dinode.odi_mtime;
1085 buf->c_dinode.di_ctime = u_ospcl.s_ospcl.c_dinode.odi_ctime;
1086 buf->c_count = u_ospcl.s_ospcl.c_count;
1087 memmove(buf->c_addr, u_ospcl.s_ospcl.c_addr, (long)256);
1088 if (u_ospcl.s_ospcl.c_magic != OFS_MAGIC ||
1089 checksum((int *)(&u_ospcl.s_ospcl)) == FAIL)
1091 buf->c_magic = NFS_MAGIC;
1094 if ((buf->c_dinode.di_size == 0 || buf->c_dinode.di_size > 0xfffffff) &&
1095 (buf->c_dinode.di_mode & IFMT) == IFDIR && Qcvt == 0) {
1096 qcvt.qval = buf->c_dinode.di_size;
1097 if (qcvt.val[0] || qcvt.val[1]) {
1098 printf("Note: Doing Quad swapping\n");
1103 qcvt.qval = buf->c_dinode.di_size;
1105 qcvt.val[1] = qcvt.val[0];
1107 buf->c_dinode.di_size = qcvt.qval;
1111 switch (buf->c_type) {
1116 * Have to patch up missing information in bit map headers
1119 buf->c_dinode.di_size = buf->c_count * TP_BSIZE;
1120 if (buf->c_count > TP_NINDIR)
1123 for (i = 0; i < buf->c_count; i++)
1128 if ((buf->c_flags & DR_NEWINODEFMT) == 0)
1140 panic("gethead: unknown inode type %d\n", buf->c_type);
1144 * If we are restoring a filesystem with old format inodes,
1145 * copy the uid/gid to the new location.
1148 buf->c_dinode.di_uid = buf->c_dinode.di_ouid;
1149 buf->c_dinode.di_gid = buf->c_dinode.di_ogid;
1157 * Check that a header is where it belongs and predict the next header
1161 struct s_spcl *header;
1163 static ino_t previno = 0x7fffffff;
1164 static int prevtype;
1165 static long predict;
1168 if (header->c_type == TS_TAPE) {
1169 fprintf(stderr, "Volume header (%s inode format) ",
1170 oldinofmt ? "old" : "new");
1171 if (header->c_firstrec)
1172 fprintf(stderr, "begins with record %ld",
1173 header->c_firstrec);
1174 fprintf(stderr, "\n");
1175 previno = 0x7fffffff;
1178 if (previno == 0x7fffffff)
1182 fprintf(stderr, "Dumped inodes map header");
1185 fprintf(stderr, "Used inodes map header");
1188 fprintf(stderr, "File header, ino %d", previno);
1191 fprintf(stderr, "File continuation header, ino %d", previno);
1194 fprintf(stderr, "End of tape header");
1197 if (predict != blksread - 1)
1198 fprintf(stderr, "; predicted %ld blocks, got %ld blocks",
1199 predict, blksread - 1);
1200 fprintf(stderr, "\n");
1203 if (header->c_type != TS_END)
1204 for (i = 0; i < header->c_count; i++)
1205 if (readmapflag || header->c_addr[i] != 0)
1209 prevtype = header->c_type;
1210 previno = header->c_inumber;
1214 * Find an inode header.
1215 * Complain if had to skip.
1219 struct s_spcl *header;
1221 static long skipcnt = 0;
1226 curfile.name = "<name unknown>";
1227 curfile.action = UNKNOWN;
1231 if (header->c_magic != NFS_MAGIC) {
1233 while (gethead(header) == FAIL ||
1234 _time32_to_time(header->c_date) != dumpdate)
1237 htype = header->c_type;
1242 * Skip up to the beginning of the next record
1244 for (i = 0; i < header->c_count; i++)
1245 if (header->c_addr[i])
1247 while (gethead(header) == FAIL ||
1248 _time32_to_time(header->c_date) != dumpdate)
1253 curfile.dip = &header->c_dinode;
1254 curfile.ino = header->c_inumber;
1258 curfile.ino = maxino;
1262 curfile.name = "<file removal list>";
1266 curfile.name = "<file dump list>";
1270 panic("unexpected tape header\n");
1274 panic("unknown tape header type %d\n", spcl.c_type);
1278 } while (htype == TS_ADDR);
1280 fprintf(stderr, "resync restore, skipped %ld blocks\n",
1291 j = sizeof(union u_spcl) / sizeof(int);
1298 /* What happens if we want to read restore tapes
1299 for a 16bit int machine??? */
1305 if (i != CHECKSUM) {
1306 fprintf(stderr, "Checksum error %o, inode %d file %s\n", i,
1307 curfile.ino, curfile.name);
1317 #include <varargs.h>
1322 msg(const char *fmt, ...)
1335 (void)vfprintf(stderr, fmt, ap);
1338 #endif /* RRESTORE */
1342 register u_char *sp;
1348 c = sp[0]; sp[0] = sp[1]; sp[1] = c;
1356 register u_char *sp;
1362 c = sp[0]; sp[0] = sp[3]; sp[3] = c;
1363 c = sp[2]; sp[2] = sp[1]; sp[1] = c;
1371 register u_char *cp, *sp;
1377 case '0': case '1': case '2': case '3': case '4':
1378 case '5': case '6': case '7': case '8': case '9':
1379 n = (n * 10) + (*cp++ - '0');
1382 case 's': case 'w': case 'h':
1385 sp = swabshort(sp, n);
1391 sp = swablong(sp, n);
1394 default: /* Any other character, like 'b' counts as byte. */
1409 swabst((u_char *)"l", (u_char *)&x);