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 mtimep[2], ctimep[2];
528 curfile.action = USING;
529 mtimep[0].tv_sec = curfile.atime_sec;
530 mtimep[0].tv_usec = curfile.atime_nsec / 1000;
531 mtimep[1].tv_sec = curfile.mtime_sec;
532 mtimep[1].tv_usec = curfile.mtime_nsec / 1000;
533 ctimep[0].tv_sec = curfile.atime_sec;
534 ctimep[0].tv_usec = curfile.atime_nsec / 1000;
535 ctimep[1].tv_sec = curfile.birthtime_sec;
536 ctimep[1].tv_usec = curfile.birthtime_nsec / 1000;
538 flags = curfile.file_flags;
539 switch (mode & IFMT) {
542 fprintf(stderr, "%s: unknown file mode 0%o\n", name, mode);
547 vprintf(stdout, "skipped socket %s\n", name);
553 ep = lookupname(name);
554 if (ep == NULL || ep->e_flags & EXTRACT)
555 panic("unextracted directory %s\n", name);
559 vprintf(stdout, "extract file %s\n", name);
560 return (genliteraldir(name, curfile.ino));
565 getfile(xtrlnkfile, xtrlnkskip);
568 "%s: zero length symbolic link (ignored)\n", name);
571 if (linkit(lnkbuf, name, SYMLINK) == GOOD) {
572 (void) lchown(name, curfile.uid, curfile.gid);
573 (void) lchmod(name, mode);
574 (void) lutimes(name, ctimep);
575 (void) lutimes(name, mtimep);
581 vprintf(stdout, "extract fifo %s\n", name);
588 if (mkfifo(name, mode) < 0) {
589 fprintf(stderr, "%s: cannot create fifo: %s\n",
590 name, strerror(errno));
594 (void) chown(name, curfile.uid, curfile.gid);
595 (void) chmod(name, mode);
596 (void) utimes(name, ctimep);
597 (void) utimes(name, mtimep);
598 (void) chflags(name, flags);
604 vprintf(stdout, "extract special file %s\n", name);
611 if (mknod(name, mode, (int)curfile.rdev) < 0) {
612 fprintf(stderr, "%s: cannot create special file: %s\n",
613 name, strerror(errno));
617 (void) chown(name, curfile.uid, curfile.gid);
618 (void) chmod(name, mode);
619 (void) utimes(name, ctimep);
620 (void) utimes(name, mtimep);
621 (void) chflags(name, flags);
626 vprintf(stdout, "extract file %s\n", name);
633 if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
635 fprintf(stderr, "%s: cannot create file: %s\n",
636 name, strerror(errno));
640 (void) fchown(ofile, curfile.uid, curfile.gid);
641 (void) fchmod(ofile, mode);
642 getfile(xtrfile, xtrskip);
644 (void) utimes(name, ctimep);
645 (void) utimes(name, mtimep);
646 (void) chflags(name, flags);
653 * skip over bit maps on the tape
659 while (spcl.c_type == TS_BITS || spcl.c_type == TS_CLRI)
664 * skip over a file on the tape
670 curfile.action = SKIP;
671 getfile(xtrnull, xtrnull);
675 * Extract a file from the tape.
676 * When an allocated block is found it is passed to the fill function;
677 * when an unallocated block (hole) is found, a zeroed buffer is passed
678 * to the skip function.
681 getfile(void (*fill)(char *, long), void (*skip)(char *, long))
685 quad_t size = spcl.c_size;
686 static char clearedbuf[MAXBSIZE];
687 char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE];
690 if (spcl.c_type == TS_END)
691 panic("ran off end of tape\n");
692 if (spcl.c_magic != FS_UFS2_MAGIC)
693 panic("not at beginning of a file\n");
694 if (!gettingfile && setjmp(restart) != 0)
698 for (i = 0; i < spcl.c_count; i++) {
699 if (readmapflag || spcl.c_addr[i]) {
700 readtape(&buf[curblk++][0]);
701 if (curblk == fssize / TP_BSIZE) {
702 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
703 fssize : (curblk - 1) * TP_BSIZE + size));
708 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
710 (curblk - 1) * TP_BSIZE + size));
713 (*skip)(clearedbuf, (long)(size > TP_BSIZE ?
716 if ((size -= TP_BSIZE) <= 0) {
717 for (i++; i < spcl.c_count; i++)
718 if (readmapflag || spcl.c_addr[i])
723 if (gethead(&spcl) == GOOD && size > 0) {
724 if (spcl.c_type == TS_ADDR)
727 "Missing address (header) block for %s at %ld blocks\n",
728 curfile.name, blksread);
731 (*fill)((char *)buf, (long)((curblk * TP_BSIZE) + size));
737 * Write out the next block of a file.
740 xtrfile(char *buf, long size)
745 if (write(ofile, buf, (int) size) == -1) {
747 "write error extracting inode %d, name %s\nwrite: %s\n",
748 curfile.ino, curfile.name, strerror(errno));
753 * Skip over a hole in a file.
757 xtrskip(char *buf, long size)
760 if (lseek(ofile, size, SEEK_CUR) == -1) {
762 "seek error extracting inode %d, name %s\nlseek: %s\n",
763 curfile.ino, curfile.name, strerror(errno));
769 * Collect the next block of a symbolic link.
772 xtrlnkfile(char *buf, long 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(char *buf, long size)
792 fprintf(stderr, "unallocated block in symbolic link %s\n",
798 * Collect the next block of a bit map.
801 xtrmap(char *buf, long size)
804 memmove(map, buf, size);
809 * Skip over a hole in a bit map (should never happen).
813 xtrmapskip(char *buf, long size)
816 panic("hole in map\n");
821 * Noop, when an extraction function is not needed.
825 xtrnull(char *buf, long size)
832 * Read TP_BSIZE blocks from the input.
833 * Handle read errors, and end of media.
839 int cnt, seek_failed;
841 if (blkcnt < numtrec) {
842 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
847 for (i = 0; i < ntrec; i++)
848 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
851 cnt = ntrec * TP_BSIZE;
856 i = rmtread(&tapebuf[rd], cnt);
859 i = read(mt, &tapebuf[rd], cnt);
861 * Check for mid-tape short read error.
862 * If found, skip rest of buffer and start with the next.
864 if (!pipein && numtrec < ntrec && i > 0) {
865 dprintf(stdout, "mid-media short read error.\n");
869 * Handle partial block read.
871 if (pipein && i == 0 && rd > 0)
873 else if (i > 0 && i != ntrec * TP_BSIZE) {
882 * Short read. Process the blocks read.
884 if (i % TP_BSIZE != 0)
886 "partial block read: %ld should be %ld\n",
887 i, ntrec * TP_BSIZE);
888 numtrec = i / TP_BSIZE;
895 fprintf(stderr, "Tape read error while ");
896 switch (curfile.action) {
898 fprintf(stderr, "trying to set up tape\n");
901 fprintf(stderr, "trying to resynchronize\n");
904 fprintf(stderr, "restoring %s\n", curfile.name);
907 fprintf(stderr, "skipping over inode %d\n",
911 if (!yflag && !reply("continue"))
913 i = ntrec * TP_BSIZE;
914 memset(tapebuf, 0, i);
917 seek_failed = (rmtseek(i, 1) < 0);
920 seek_failed = (lseek(mt, i, SEEK_CUR) == (off_t)-1);
924 "continuation failed: %s\n", strerror(errno));
929 * Handle end of tape.
932 vprintf(stdout, "End-of-tape encountered\n");
941 if (rd % TP_BSIZE != 0)
942 panic("partial block read: %d should be %d\n",
943 rd, ntrec * TP_BSIZE);
945 memmove(&tapebuf[rd], &endoftapemark, (long)TP_BSIZE);
948 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
954 findtapeblksize(void)
958 for (i = 0; i < ntrec; i++)
959 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
963 i = rmtread(tapebuf, ntrec * TP_BSIZE);
966 i = read(mt, tapebuf, ntrec * TP_BSIZE);
969 fprintf(stderr, "tape read error: %s\n", strerror(errno));
972 if (i % TP_BSIZE != 0) {
973 fprintf(stderr, "Tape block size (%ld) %s (%d)\n",
974 i, "is not a multiple of dump block size", TP_BSIZE);
977 ntrec = i / TP_BSIZE;
979 vprintf(stdout, "Tape block size is %ld\n", ntrec);
997 * Read the next block from the tape.
998 * If it is not any valid header, return an error.
1001 gethead(struct s_spcl *buf)
1005 readtape((char *)buf);
1006 if (buf->c_magic != FS_UFS2_MAGIC && buf->c_magic != NFS_MAGIC) {
1007 if (buf->c_magic == OFS_MAGIC) {
1009 "Format of dump tape is too old. Must use\n");
1011 "a version of restore from before 2002.\n");
1014 if (swabl(buf->c_magic) != FS_UFS2_MAGIC &&
1015 buf->c_magic != NFS_MAGIC) {
1016 if (buf->c_magic == OFS_MAGIC) {
1018 "Format of dump tape is too old. Must use\n");
1020 "a version of restore from before 2002.\n");
1025 vprintf(stdout, "Note: Doing Byte swapping\n");
1029 if (checksum((int *)buf) == FAIL)
1032 swabst((u_char *)"8l4s1q8l2q17l", (u_char *)buf);
1033 swabst((u_char *)"l",(u_char *) &buf->c_level);
1034 swabst((u_char *)"2l4q",(u_char *) &buf->c_flags);
1038 switch (buf->c_type) {
1043 * Have to patch up missing information in bit map headers
1046 buf->c_size = buf->c_count * TP_BSIZE;
1047 if (buf->c_count > TP_NINDIR)
1050 for (i = 0; i < buf->c_count; i++)
1061 * For old dump tapes, have to copy up old fields to
1064 if (buf->c_magic == NFS_MAGIC) {
1065 buf->c_tapea = buf->c_old_tapea;
1066 buf->c_firstrec = buf->c_old_firstrec;
1067 buf->c_date = _time32_to_time(buf->c_old_date);
1068 buf->c_ddate = _time32_to_time(buf->c_old_ddate);
1069 buf->c_atime = _time32_to_time(buf->c_old_atime);
1070 buf->c_mtime = _time32_to_time(buf->c_old_mtime);
1078 panic("gethead: unknown inode type %d\n", buf->c_type);
1081 buf->c_magic = FS_UFS2_MAGIC;
1082 tapeaddr = buf->c_tapea;
1089 * Check that a header is where it belongs and predict the next header
1092 accthdr(struct s_spcl *header)
1094 static ino_t previno = 0x7fffffff;
1095 static int prevtype;
1096 static long predict;
1099 if (header->c_type == TS_TAPE) {
1100 fprintf(stderr, "Volume header ");
1101 if (header->c_firstrec)
1102 fprintf(stderr, "begins with record %qd",
1103 header->c_firstrec);
1104 fprintf(stderr, "\n");
1105 previno = 0x7fffffff;
1108 if (previno == 0x7fffffff)
1112 fprintf(stderr, "Dumped inodes map header");
1115 fprintf(stderr, "Used inodes map header");
1118 fprintf(stderr, "File header, ino %d", previno);
1121 fprintf(stderr, "File continuation header, ino %d", previno);
1124 fprintf(stderr, "End of tape header");
1127 if (predict != blksread - 1)
1128 fprintf(stderr, "; predicted %ld blocks, got %ld blocks",
1129 predict, blksread - 1);
1130 fprintf(stderr, "\n");
1133 if (header->c_type != TS_END)
1134 for (i = 0; i < header->c_count; i++)
1135 if (readmapflag || header->c_addr[i] != 0)
1139 prevtype = header->c_type;
1140 previno = header->c_inumber;
1144 * Find an inode header.
1145 * Complain if had to skip.
1148 findinode(struct s_spcl *header)
1150 static long skipcnt = 0;
1155 curfile.name = "<name unknown>";
1156 curfile.action = UNKNOWN;
1160 htype = header->c_type;
1165 * Skip up to the beginning of the next record
1167 for (i = 0; i < header->c_count; i++)
1168 if (header->c_addr[i])
1170 while (gethead(header) == FAIL ||
1171 _time64_to_time(header->c_date) != dumpdate)
1176 curfile.mode = header->c_mode;
1177 curfile.uid = header->c_uid;
1178 curfile.gid = header->c_gid;
1179 curfile.file_flags = header->c_file_flags;
1180 curfile.rdev = header->c_rdev;
1181 curfile.atime_sec = header->c_atime;
1182 curfile.atime_nsec = header->c_atimensec;
1183 curfile.mtime_sec = header->c_mtime;
1184 curfile.mtime_nsec = header->c_mtimensec;
1185 curfile.birthtime_sec = header->c_birthtime;
1186 curfile.birthtime_nsec = header->c_birthtimensec;
1187 curfile.size = header->c_size;
1188 curfile.ino = header->c_inumber;
1192 /* If we missed some tapes, get another volume. */
1193 if (tapesread & (tapesread + 1)) {
1197 curfile.ino = maxino;
1201 curfile.name = "<file removal list>";
1205 curfile.name = "<file dump list>";
1209 panic("unexpected tape header\n");
1213 panic("unknown tape header type %d\n", spcl.c_type);
1217 } while (htype == TS_ADDR);
1219 fprintf(stderr, "resync restore, skipped %ld blocks\n",
1229 j = sizeof(union u_spcl) / sizeof(int);
1236 /* What happens if we want to read restore tapes
1237 for a 16bit int machine??? */
1243 if (i != CHECKSUM) {
1244 fprintf(stderr, "Checksum error %o, inode %d file %s\n", i,
1245 curfile.ino, curfile.name);
1255 msg(const char *fmt, ...)
1259 (void)vfprintf(stderr, fmt, ap);
1262 #endif /* RRESTORE */
1265 swabshort(u_char *sp, int n)
1270 c = sp[0]; sp[0] = sp[1]; sp[1] = c;
1277 swablong(u_char *sp, int n)
1282 c = sp[0]; sp[0] = sp[3]; sp[3] = c;
1283 c = sp[2]; sp[2] = sp[1]; sp[1] = c;
1290 swabquad(u_char *sp, int n)
1295 c = sp[0]; sp[0] = sp[7]; sp[7] = c;
1296 c = sp[1]; sp[1] = sp[6]; sp[6] = c;
1297 c = sp[2]; sp[2] = sp[5]; sp[5] = c;
1298 c = sp[3]; sp[3] = sp[4]; sp[4] = c;
1305 swabst(u_char *cp, u_char *sp)
1311 case '0': case '1': case '2': case '3': case '4':
1312 case '5': case '6': case '7': case '8': case '9':
1313 n = (n * 10) + (*cp++ - '0');
1316 case 's': case 'w': case 'h':
1319 sp = swabshort(sp, n);
1325 sp = swablong(sp, n);
1331 sp = swabquad(sp, n);
1341 fprintf(stderr, "Unknown conversion character: %c\n",
1354 swabst((u_char *)"l", (u_char *)&x);