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 int64_t tapeaddr = 0; /* current TP_BSIZE tape record */
78 static long tapesread;
79 static jmp_buf restart;
80 static int gettingfile = 0; /* restart has a valid frame */
81 static char *host = NULL;
82 static int readmapflag;
86 static char lnkbuf[MAXPATHLEN + 1];
89 int Bcvt; /* Swap Bytes */
91 #define FLUSHTAPEBUF() blkcnt = ntrec + 1
93 static void accthdr(struct s_spcl *);
94 static int checksum(int *);
95 static void findinode(struct s_spcl *);
96 static void findtapeblksize(void);
97 static int gethead(struct s_spcl *);
98 static void readtape(char *);
99 static void setdumpnum(void);
100 static u_long swabl(u_long);
101 static u_char *swablong(u_char *, int);
102 static u_char *swabshort(u_char *, int);
103 static void terminateinput(void);
104 static void xtrfile(char *, long);
105 static void xtrlnkfile(char *, long);
106 static void xtrlnkskip(char *, long);
107 static void xtrmap(char *, long);
108 static void xtrmapskip(char *, long);
109 static void xtrskip(char *, long);
112 * Set up an input source
115 setinput(char *source)
121 newtapebuf(NTREC > HIGHDENSITYTREC ? NTREC : HIGHDENSITYTREC);
125 if (strchr(source, ':')) {
127 source = strchr(host, ':');
129 if (rmthost(host) == 0)
133 if (strcmp(source, "-") == 0) {
135 * Since input is coming from a pipe we must establish
136 * our own connection to the terminal.
138 terminal = fopen(_PATH_TTY, "r");
139 if (terminal == NULL) {
140 (void)fprintf(stderr, "cannot open %s: %s\n",
141 _PATH_TTY, strerror(errno));
142 terminal = fopen(_PATH_DEVNULL, "r");
143 if (terminal == NULL) {
144 (void)fprintf(stderr, "cannot open %s: %s\n",
145 _PATH_DEVNULL, strerror(errno));
151 setuid(getuid()); /* no longer need or want root privileges */
152 magtape = strdup(source);
153 if (magtape == NULL) {
154 fprintf(stderr, "Cannot allocate space for magtape buffer\n");
160 newtapebuf(long size)
162 static int tapebufsize = -1;
165 if (size <= tapebufsize)
169 tapebuf = malloc(size * TP_BSIZE);
170 if (tapebuf == NULL) {
171 fprintf(stderr, "Cannot allocate space for tape buffer\n");
178 * Verify that the tape drive can be accessed and
179 * that it actually is a dump tape.
187 vprintf(stdout, "Verify tape and initialize maps\n");
190 mt = rmtopen(magtape, 0);
196 mt = open(magtape, O_RDONLY, 0);
198 fprintf(stderr, "%s: %s\n", magtape, strerror(errno));
204 if (!pipein && !bflag)
206 if (gethead(&spcl) == FAIL) {
207 fprintf(stderr, "Tape is not a dump tape\n");
211 endoftapemark.s_spcl.c_magic = FS_UFS2_MAGIC;
212 endoftapemark.s_spcl.c_type = TS_END;
213 ip = (int *)&endoftapemark;
214 j = sizeof(union u_spcl) / sizeof(int);
219 endoftapemark.s_spcl.c_checksum = CHECKSUM - i;
221 if (vflag || command == 't')
223 dumptime = _time64_to_time(spcl.c_ddate);
224 dumpdate = _time64_to_time(spcl.c_date);
225 if (stat(".", &stbuf) < 0) {
226 fprintf(stderr, "cannot stat .: %s\n", strerror(errno));
229 if (stbuf.st_blksize > 0 && stbuf.st_blksize < TP_BSIZE )
231 if (stbuf.st_blksize >= TP_BSIZE && stbuf.st_blksize <= MAXBSIZE)
232 fssize = stbuf.st_blksize;
233 if (((fssize - 1) & fssize) != 0) {
234 fprintf(stderr, "bad block size %ld\n", fssize);
237 if (spcl.c_volume != 1) {
238 fprintf(stderr, "Tape is not volume 1 of the dump\n");
241 if (gethead(&spcl) == FAIL) {
242 dprintf(stdout, "header read failed at %ld blocks\n", blksread);
243 panic("no header after volume mark!\n");
246 if (spcl.c_type != TS_CLRI) {
247 fprintf(stderr, "Cannot find file removal list\n");
250 maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1;
251 dprintf(stdout, "maxino = %d\n", maxino);
252 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
254 panic("no memory for active inode map\n");
256 curfile.action = USING;
257 getfile(xtrmap, xtrmapskip);
258 if (spcl.c_type != TS_BITS) {
259 fprintf(stderr, "Cannot find file dump list\n");
262 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
263 if (map == (char *)NULL)
264 panic("no memory for file dump list\n");
266 curfile.action = USING;
267 getfile(xtrmap, xtrmapskip);
269 * If there may be whiteout entries on the tape, pretend that the
270 * whiteout inode exists, so that the whiteout entries can be
273 SETINO(WINO, dumpmap);
274 /* 'r' restores don't call getvol() for tape 1, so mark it as read. */
280 * Prompt user to load a new dump volume.
281 * "Nextvol" is the next suggested volume to use.
282 * This suggested volume is enforced when doing full
283 * or incremental restores, but can be overridden by
284 * the user when only extracting a subset of the files.
290 long i, newvol, savecnt;
291 union u_spcl tmpspcl;
292 # define tmpbuf tmpspcl.s_spcl
299 prevtapea = tapeaddr;
303 panic("Changing volumes on pipe input?\n");
304 /* Avoid looping if we couldn't ask the user. */
305 if (yflag || ferror(terminal) || feof(terminal))
314 done(1); /* pipes do not get a second chance */
315 if (command == 'R' || command == 'r' || curfile.action != SKIP)
319 while (newvol <= 0) {
320 if (tapesread == 0) {
321 fprintf(stderr, "%s%s%s%s%s%s%s",
322 "You have not read any tapes yet.\n",
323 "If you are extracting just a few files,",
324 " start with the last volume\n",
325 "and work towards the first; restore",
326 " can quickly skip tapes that\n",
327 "have no further files to extract.",
328 " Otherwise, begin with volume 1.\n");
330 fprintf(stderr, "You have read volumes");
332 for (i = 0; i < 32; i++)
333 if (tapesread & (1 << i)) {
334 fprintf(stderr, "%s%ld", buf, i + 1);
337 fprintf(stderr, "\n");
340 fprintf(stderr, "Specify next volume #: ");
341 (void) fflush(stderr);
342 if (fgets(buf, BUFSIZ, terminal) == NULL)
344 } while (buf[0] == '\n');
348 "Volume numbers are positive numerics\n");
351 if (newvol == volno) {
352 tapesread |= 1 << (volno - 1);
356 fprintf(stderr, "Mount tape volume %ld\n", newvol);
357 fprintf(stderr, "Enter ``none'' if there are no more tapes\n");
358 fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape);
359 (void) fflush(stderr);
360 if (fgets(buf, BUFSIZ, terminal) == NULL)
362 if (!strcmp(buf, "none\n")) {
366 if (buf[0] != '\n') {
367 (void) strcpy(magtape, buf);
368 magtape[strlen(magtape) - 1] = '\0';
372 mt = rmtopen(magtape, 0);
375 mt = open(magtape, O_RDONLY, 0);
378 fprintf(stderr, "Cannot open %s\n", magtape);
386 if (gethead(&tmpbuf) == FAIL) {
387 dprintf(stdout, "header read failed at %ld blocks\n", blksread);
388 fprintf(stderr, "tape is not dump tape\n");
392 if (tmpbuf.c_volume != volno) {
393 fprintf(stderr, "Wrong volume (%ld)\n", tmpbuf.c_volume);
397 if (_time64_to_time(tmpbuf.c_date) != dumpdate ||
398 _time64_to_time(tmpbuf.c_ddate) != dumptime) {
399 time_t t = _time64_to_time(tmpbuf.c_date);
400 fprintf(stderr, "Wrong dump date\n\tgot: %s", ctime(&t));
401 fprintf(stderr, "\twanted: %s", ctime(&dumpdate));
405 tapesread |= 1 << (volno - 1);
408 * If continuing from the previous volume, skip over any
409 * blocks read already at the end of the previous volume.
411 * If coming to this volume at random, skip to the beginning
412 * of the next record.
414 dprintf(stdout, "last rec %qd, tape starts with %qd\n", prevtapea,
416 if (tmpbuf.c_type == TS_TAPE) {
417 if (curfile.action != USING) {
419 * XXX Dump incorrectly sets c_count to 1 in the
420 * volume header of the first tape, so ignore
421 * c_count when volno == 1.
424 for (i = tmpbuf.c_count; i > 0; i--)
426 } else if (tmpbuf.c_tapea <= prevtapea) {
428 * Normally the value of c_tapea in the volume
429 * header is the record number of the header itself.
430 * However in the volume header following an EOT-
431 * terminated tape, it is the record number of the
432 * first continuation data block (dump bug?).
434 * The next record we want is `prevtapea + 1'.
436 i = prevtapea + 1 - tmpbuf.c_tapea;
437 dprintf(stderr, "Skipping %ld duplicate record%s.\n",
438 i, i > 1 ? "s" : "");
443 if (curfile.action == USING) {
445 panic("active file into volume 1\n");
448 (void) gethead(&spcl);
457 * Handle unexpected EOF.
463 if (gettingfile && curfile.action == USING) {
464 printf("Warning: %s %s\n",
465 "End-of-input encountered while extracting", curfile.name);
467 curfile.name = "<name unknown>";
468 curfile.action = UNKNOWN;
470 curfile.ino = maxino;
478 * handle multiple dumps per tape by skipping forward to the
486 if (dumpnum == 1 || volno != 1)
489 fprintf(stderr, "Cannot have multiple dumps on pipe input\n");
493 tcom.mt_count = dumpnum - 1;
496 rmtioctl(MTFSF, dumpnum - 1);
499 if (ioctl(mt, MTIOCTOP, (char *)&tcom) < 0)
500 fprintf(stderr, "ioctl MTFSF: %s\n", strerror(errno));
507 t = _time64_to_time(spcl.c_date);
508 fprintf(stdout, "Dump date: %s", ctime(&t));
509 t = _time64_to_time(spcl.c_ddate);
510 fprintf(stdout, "Dumped from: %s",
511 (spcl.c_ddate == 0) ? "the epoch\n" : ctime(&t));
512 if (spcl.c_host[0] == '\0')
514 fprintf(stderr, "Level %ld dump of %s on %s:%s\n",
515 spcl.c_level, spcl.c_filesys, spcl.c_host, spcl.c_dev);
516 fprintf(stderr, "Label: %s\n", spcl.c_label);
520 extractfile(char *name)
524 struct timeval timep[2];
528 curfile.action = USING;
529 timep[0].tv_sec = curfile.atime_sec;
530 timep[0].tv_usec = curfile.atime_nsec / 1000;
531 timep[1].tv_sec = curfile.mtime_sec;
532 timep[1].tv_usec = curfile.mtime_nsec / 1000;
534 flags = curfile.file_flags;
535 switch (mode & IFMT) {
538 fprintf(stderr, "%s: unknown file mode 0%o\n", name, mode);
543 vprintf(stdout, "skipped socket %s\n", name);
549 ep = lookupname(name);
550 if (ep == NULL || ep->e_flags & EXTRACT)
551 panic("unextracted directory %s\n", name);
555 vprintf(stdout, "extract file %s\n", name);
556 return (genliteraldir(name, curfile.ino));
561 getfile(xtrlnkfile, xtrlnkskip);
564 "%s: zero length symbolic link (ignored)\n", name);
567 if (linkit(lnkbuf, name, SYMLINK) == GOOD) {
568 (void) lchown(name, curfile.uid, curfile.gid);
569 (void) lchmod(name, mode);
570 (void) lutimes(name, timep);
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.uid, curfile.gid);
590 (void) chmod(name, mode);
591 (void) utimes(name, timep);
592 (void) chflags(name, flags);
598 vprintf(stdout, "extract special file %s\n", name);
605 if (mknod(name, mode, (int)curfile.rdev) < 0) {
606 fprintf(stderr, "%s: cannot create special file: %s\n",
607 name, strerror(errno));
611 (void) chown(name, curfile.uid, curfile.gid);
612 (void) chmod(name, mode);
613 (void) utimes(name, timep);
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.uid, curfile.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.
673 getfile(void (*fill)(char *, long), void (*skip)(char *, long))
677 quad_t size = spcl.c_size;
678 static char clearedbuf[MAXBSIZE];
679 char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE];
682 if (spcl.c_type == TS_END)
683 panic("ran off end of tape\n");
684 if (spcl.c_magic != FS_UFS2_MAGIC)
685 panic("not at beginning of a file\n");
686 if (!gettingfile && setjmp(restart) != 0)
690 for (i = 0; i < spcl.c_count; i++) {
691 if (readmapflag || spcl.c_addr[i]) {
692 readtape(&buf[curblk++][0]);
693 if (curblk == fssize / TP_BSIZE) {
694 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
695 fssize : (curblk - 1) * TP_BSIZE + size));
700 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
702 (curblk - 1) * TP_BSIZE + size));
705 (*skip)(clearedbuf, (long)(size > TP_BSIZE ?
708 if ((size -= TP_BSIZE) <= 0) {
709 for (i++; i < spcl.c_count; i++)
710 if (readmapflag || spcl.c_addr[i])
715 if (gethead(&spcl) == GOOD && size > 0) {
716 if (spcl.c_type == TS_ADDR)
719 "Missing address (header) block for %s at %ld blocks\n",
720 curfile.name, blksread);
723 (*fill)((char *)buf, (long)((curblk * TP_BSIZE) + size));
729 * Write out the next block of a file.
732 xtrfile(char *buf, long size)
737 if (write(ofile, buf, (int) size) == -1) {
739 "write error extracting inode %d, name %s\nwrite: %s\n",
740 curfile.ino, curfile.name, strerror(errno));
745 * Skip over a hole in a file.
749 xtrskip(char *buf, long size)
752 if (lseek(ofile, size, SEEK_CUR) == -1) {
754 "seek error extracting inode %d, name %s\nlseek: %s\n",
755 curfile.ino, curfile.name, strerror(errno));
761 * Collect the next block of a symbolic link.
764 xtrlnkfile(char *buf, long size)
768 if (pathlen > MAXPATHLEN) {
769 fprintf(stderr, "symbolic link name: %s->%s%s; too long %d\n",
770 curfile.name, lnkbuf, buf, pathlen);
773 (void) strcat(lnkbuf, buf);
777 * Skip over a hole in a symbolic link (should never happen).
781 xtrlnkskip(char *buf, long size)
784 fprintf(stderr, "unallocated block in symbolic link %s\n",
790 * Collect the next block of a bit map.
793 xtrmap(char *buf, long size)
796 memmove(map, buf, size);
801 * Skip over a hole in a bit map (should never happen).
805 xtrmapskip(char *buf, long size)
808 panic("hole in map\n");
813 * Noop, when an extraction function is not needed.
817 xtrnull(char *buf, long size)
824 * Read TP_BSIZE blocks from the input.
825 * Handle read errors, and end of media.
831 int cnt, seek_failed;
833 if (blkcnt < numtrec) {
834 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
839 for (i = 0; i < ntrec; i++)
840 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
843 cnt = ntrec * TP_BSIZE;
848 i = rmtread(&tapebuf[rd], cnt);
851 i = read(mt, &tapebuf[rd], cnt);
853 * Check for mid-tape short read error.
854 * If found, skip rest of buffer and start with the next.
856 if (!pipein && numtrec < ntrec && i > 0) {
857 dprintf(stdout, "mid-media short read error.\n");
861 * Handle partial block read.
863 if (pipein && i == 0 && rd > 0)
865 else if (i > 0 && i != ntrec * TP_BSIZE) {
874 * Short read. Process the blocks read.
876 if (i % TP_BSIZE != 0)
878 "partial block read: %ld should be %ld\n",
879 i, ntrec * TP_BSIZE);
880 numtrec = i / TP_BSIZE;
887 fprintf(stderr, "Tape read error while ");
888 switch (curfile.action) {
890 fprintf(stderr, "trying to set up tape\n");
893 fprintf(stderr, "trying to resynchronize\n");
896 fprintf(stderr, "restoring %s\n", curfile.name);
899 fprintf(stderr, "skipping over inode %d\n",
903 if (!yflag && !reply("continue"))
905 i = ntrec * TP_BSIZE;
906 memset(tapebuf, 0, i);
909 seek_failed = (rmtseek(i, 1) < 0);
912 seek_failed = (lseek(mt, i, SEEK_CUR) == (off_t)-1);
916 "continuation failed: %s\n", strerror(errno));
921 * Handle end of tape.
924 vprintf(stdout, "End-of-tape encountered\n");
933 if (rd % TP_BSIZE != 0)
934 panic("partial block read: %d should be %d\n",
935 rd, ntrec * TP_BSIZE);
937 memmove(&tapebuf[rd], &endoftapemark, (long)TP_BSIZE);
940 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
946 findtapeblksize(void)
950 for (i = 0; i < ntrec; i++)
951 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
955 i = rmtread(tapebuf, ntrec * TP_BSIZE);
958 i = read(mt, tapebuf, ntrec * TP_BSIZE);
961 fprintf(stderr, "tape read error: %s\n", strerror(errno));
964 if (i % TP_BSIZE != 0) {
965 fprintf(stderr, "Tape block size (%ld) %s (%d)\n",
966 i, "is not a multiple of dump block size", TP_BSIZE);
969 ntrec = i / TP_BSIZE;
971 vprintf(stdout, "Tape block size is %ld\n", ntrec);
989 * Read the next block from the tape.
990 * If it is not any valid header, return an error.
993 gethead(struct s_spcl *buf)
997 readtape((char *)buf);
998 if (buf->c_magic != FS_UFS2_MAGIC && buf->c_magic != NFS_MAGIC) {
999 if (buf->c_magic == OFS_MAGIC) {
1001 "Format of dump tape is too old. Must use\n");
1003 "a version of restore from before 2002.\n");
1006 if (swabl(buf->c_magic) != FS_UFS2_MAGIC &&
1007 buf->c_magic != NFS_MAGIC) {
1008 if (buf->c_magic == OFS_MAGIC) {
1010 "Format of dump tape is too old. Must use\n");
1012 "a version of restore from before 2002.\n");
1017 vprintf(stdout, "Note: Doing Byte swapping\n");
1021 if (checksum((int *)buf) == FAIL)
1024 swabst((u_char *)"8l4s1q8l2q17l", (u_char *)buf);
1025 swabst((u_char *)"l",(u_char *) &buf->c_level);
1026 swabst((u_char *)"2l4q",(u_char *) &buf->c_flags);
1030 switch (buf->c_type) {
1035 * Have to patch up missing information in bit map headers
1038 buf->c_size = buf->c_count * TP_BSIZE;
1039 if (buf->c_count > TP_NINDIR)
1042 for (i = 0; i < buf->c_count; i++)
1053 * For old dump tapes, have to copy up old fields to
1056 if (buf->c_magic == NFS_MAGIC) {
1057 buf->c_tapea = buf->c_old_tapea;
1058 buf->c_firstrec = buf->c_old_firstrec;
1059 buf->c_date = _time32_to_time(buf->c_old_date);
1060 buf->c_ddate = _time32_to_time(buf->c_old_ddate);
1061 buf->c_atime = _time32_to_time(buf->c_old_atime);
1062 buf->c_mtime = _time32_to_time(buf->c_old_mtime);
1070 panic("gethead: unknown inode type %d\n", buf->c_type);
1073 buf->c_magic = FS_UFS2_MAGIC;
1074 tapeaddr = buf->c_tapea;
1081 * Check that a header is where it belongs and predict the next header
1084 accthdr(struct s_spcl *header)
1086 static ino_t previno = 0x7fffffff;
1087 static int prevtype;
1088 static long predict;
1091 if (header->c_type == TS_TAPE) {
1092 fprintf(stderr, "Volume header ");
1093 if (header->c_firstrec)
1094 fprintf(stderr, "begins with record %qd",
1095 header->c_firstrec);
1096 fprintf(stderr, "\n");
1097 previno = 0x7fffffff;
1100 if (previno == 0x7fffffff)
1104 fprintf(stderr, "Dumped inodes map header");
1107 fprintf(stderr, "Used inodes map header");
1110 fprintf(stderr, "File header, ino %d", previno);
1113 fprintf(stderr, "File continuation header, ino %d", previno);
1116 fprintf(stderr, "End of tape header");
1119 if (predict != blksread - 1)
1120 fprintf(stderr, "; predicted %ld blocks, got %ld blocks",
1121 predict, blksread - 1);
1122 fprintf(stderr, "\n");
1125 if (header->c_type != TS_END)
1126 for (i = 0; i < header->c_count; i++)
1127 if (readmapflag || header->c_addr[i] != 0)
1131 prevtype = header->c_type;
1132 previno = header->c_inumber;
1136 * Find an inode header.
1137 * Complain if had to skip.
1140 findinode(struct s_spcl *header)
1142 static long skipcnt = 0;
1147 curfile.name = "<name unknown>";
1148 curfile.action = UNKNOWN;
1152 htype = header->c_type;
1157 * Skip up to the beginning of the next record
1159 for (i = 0; i < header->c_count; i++)
1160 if (header->c_addr[i])
1162 while (gethead(header) == FAIL ||
1163 _time64_to_time(header->c_date) != dumpdate)
1168 curfile.mode = header->c_mode;
1169 curfile.uid = header->c_uid;
1170 curfile.gid = header->c_gid;
1171 curfile.file_flags = header->c_file_flags;
1172 curfile.rdev = header->c_rdev;
1173 curfile.atime_sec = header->c_atime;
1174 curfile.atime_nsec = header->c_atimensec;
1175 curfile.mtime_sec = header->c_mtime;
1176 curfile.mtime_nsec = header->c_mtimensec;
1177 curfile.size = header->c_size;
1178 curfile.ino = header->c_inumber;
1182 /* If we missed some tapes, get another volume. */
1183 if (tapesread & (tapesread + 1)) {
1187 curfile.ino = maxino;
1191 curfile.name = "<file removal list>";
1195 curfile.name = "<file dump list>";
1199 panic("unexpected tape header\n");
1203 panic("unknown tape header type %d\n", spcl.c_type);
1207 } while (htype == TS_ADDR);
1209 fprintf(stderr, "resync restore, skipped %ld blocks\n",
1219 j = sizeof(union u_spcl) / sizeof(int);
1226 /* What happens if we want to read restore tapes
1227 for a 16bit int machine??? */
1233 if (i != CHECKSUM) {
1234 fprintf(stderr, "Checksum error %o, inode %d file %s\n", i,
1235 curfile.ino, curfile.name);
1245 msg(const char *fmt, ...)
1249 (void)vfprintf(stderr, fmt, ap);
1252 #endif /* RRESTORE */
1255 swabshort(u_char *sp, int n)
1260 c = sp[0]; sp[0] = sp[1]; sp[1] = c;
1267 swablong(u_char *sp, int n)
1272 c = sp[0]; sp[0] = sp[3]; sp[3] = c;
1273 c = sp[2]; sp[2] = sp[1]; sp[1] = c;
1280 swabquad(u_char *sp, int n)
1285 c = sp[0]; sp[0] = sp[7]; sp[7] = c;
1286 c = sp[1]; sp[1] = sp[6]; sp[6] = c;
1287 c = sp[2]; sp[2] = sp[5]; sp[5] = c;
1288 c = sp[3]; sp[3] = sp[4]; sp[4] = c;
1295 swabst(u_char *cp, u_char *sp)
1301 case '0': case '1': case '2': case '3': case '4':
1302 case '5': case '6': case '7': case '8': case '9':
1303 n = (n * 10) + (*cp++ - '0');
1306 case 's': case 'w': case 'h':
1309 sp = swabshort(sp, n);
1315 sp = swablong(sp, n);
1321 sp = swabquad(sp, n);
1331 fprintf(stderr, "Unknown conversion character: %c\n",
1344 swabst((u_char *)"l", (u_char *)&x);