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 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;
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(struct s_spcl *);
95 static int checksum(int *);
96 static void findinode(struct s_spcl *);
97 static void findtapeblksize(void);
98 static int gethead(struct s_spcl *);
99 static void readtape(char *);
100 static void setdumpnum(void);
101 static u_long swabl(u_long);
102 static u_char *swablong(u_char *, int);
103 static u_char *swabshort(u_char *, int);
104 static void terminateinput(void);
105 static void xtrfile(char *, long);
106 static void xtrlnkfile(char *, long);
107 static void xtrlnkskip(char *, long);
108 static void xtrmap(char *, long);
109 static void xtrmapskip(char *, long);
110 static void xtrskip(char *, long);
112 static int readmapflag;
115 * Set up an input source
118 setinput(char *source)
124 newtapebuf(NTREC > HIGHDENSITYTREC ? NTREC : HIGHDENSITYTREC);
128 if (strchr(source, ':')) {
130 source = strchr(host, ':');
132 if (rmthost(host) == 0)
136 if (strcmp(source, "-") == 0) {
138 * Since input is coming from a pipe we must establish
139 * our own connection to the terminal.
141 terminal = fopen(_PATH_TTY, "r");
142 if (terminal == NULL) {
143 (void)fprintf(stderr, "cannot open %s: %s\n",
144 _PATH_TTY, strerror(errno));
145 terminal = fopen(_PATH_DEVNULL, "r");
146 if (terminal == NULL) {
147 (void)fprintf(stderr, "cannot open %s: %s\n",
148 _PATH_DEVNULL, strerror(errno));
154 setuid(getuid()); /* no longer need or want root privileges */
155 magtape = strdup(source);
156 if (magtape == NULL) {
157 fprintf(stderr, "Cannot allocate space for magtape buffer\n");
163 newtapebuf(long size)
165 static int tapebufsize = -1;
168 if (size <= tapebufsize)
172 tapebuf = malloc(size * TP_BSIZE);
173 if (tapebuf == NULL) {
174 fprintf(stderr, "Cannot allocate space for tape buffer\n");
181 * Verify that the tape drive can be accessed and
182 * that it actually is a dump tape.
190 vprintf(stdout, "Verify tape and initialize maps\n");
193 mt = rmtopen(magtape, 0);
199 mt = open(magtape, O_RDONLY, 0);
201 fprintf(stderr, "%s: %s\n", magtape, strerror(errno));
207 if (!pipein && !bflag)
209 if (gethead(&spcl) == FAIL) {
210 blkcnt--; /* push back this block */
213 if (gethead(&spcl) == FAIL) {
214 fprintf(stderr, "Tape is not a dump tape\n");
217 fprintf(stderr, "Converting to new file system format.\n");
220 endoftapemark.s_spcl.c_magic = cvtflag ? OFS_MAGIC : NFS_MAGIC;
221 endoftapemark.s_spcl.c_type = TS_END;
222 ip = (int *)&endoftapemark;
223 j = sizeof(union u_spcl) / sizeof(int);
228 endoftapemark.s_spcl.c_checksum = CHECKSUM - i;
230 if (vflag || command == 't')
232 dumptime = _time32_to_time(spcl.c_ddate);
233 dumpdate = _time32_to_time(spcl.c_date);
234 if (stat(".", &stbuf) < 0) {
235 fprintf(stderr, "cannot stat .: %s\n", strerror(errno));
238 if (stbuf.st_blksize > 0 && stbuf.st_blksize < TP_BSIZE )
240 if (stbuf.st_blksize >= TP_BSIZE && stbuf.st_blksize <= MAXBSIZE)
241 fssize = stbuf.st_blksize;
242 if (((fssize - 1) & fssize) != 0) {
243 fprintf(stderr, "bad block size %ld\n", fssize);
246 if (spcl.c_volume != 1) {
247 fprintf(stderr, "Tape is not volume 1 of the dump\n");
250 if (gethead(&spcl) == FAIL) {
251 dprintf(stdout, "header read failed at %ld blocks\n", blksread);
252 panic("no header after volume mark!\n");
255 if (spcl.c_type != TS_CLRI) {
256 fprintf(stderr, "Cannot find file removal list\n");
259 maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1;
260 dprintf(stdout, "maxino = %d\n", maxino);
261 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
263 panic("no memory for active inode map\n");
265 curfile.action = USING;
266 getfile(xtrmap, xtrmapskip);
267 if (spcl.c_type != TS_BITS) {
268 fprintf(stderr, "Cannot find file dump list\n");
271 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
272 if (map == (char *)NULL)
273 panic("no memory for file dump list\n");
275 curfile.action = USING;
276 getfile(xtrmap, xtrmapskip);
278 * If there may be whiteout entries on the tape, pretend that the
279 * whiteout inode exists, so that the whiteout entries can be
283 SETINO(WINO, dumpmap);
284 /* 'r' restores don't call getvol() for tape 1, so mark it as read. */
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.
299 long newvol, prevtapea, savecnt, i;
300 union u_spcl tmpspcl;
301 # define tmpbuf tmpspcl.s_spcl
308 prevtapea = tapeaddr;
312 panic("Changing volumes on pipe input?\n");
313 /* Avoid looping if we couldn't ask the user. */
314 if (yflag || ferror(terminal) || feof(terminal))
323 done(1); /* pipes do not get a second chance */
324 if (command == 'R' || command == 'r' || curfile.action != SKIP)
328 while (newvol <= 0) {
329 if (tapesread == 0) {
330 fprintf(stderr, "%s%s%s%s%s%s%s",
331 "You have not read any tapes yet.\n",
332 "If you are extracting just a few files,",
333 " start with the last volume\n",
334 "and work towards the first; restore",
335 " can quickly skip tapes that\n",
336 "have no further files to extract.",
337 " Otherwise, begin with volume 1.\n");
339 fprintf(stderr, "You have read volumes");
341 for (i = 0; i < 32; i++)
342 if (tapesread & (1 << i)) {
343 fprintf(stderr, "%s%ld", buf, i + 1);
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 - 1);
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 - 1);
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, "last rec %ld, tape starts with %ld\n", prevtapea,
425 if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) {
426 if (curfile.action != USING) {
428 * XXX Dump incorrectly sets c_count to 1 in the
429 * volume header of the first tape, so ignore
430 * c_count when volno == 1.
433 for (i = tmpbuf.c_count; i > 0; i--)
435 } else if (tmpbuf.c_tapea <= prevtapea) {
437 * Normally the value of c_tapea in the volume
438 * header is the record number of the header itself.
439 * However in the volume header following an EOT-
440 * terminated tape, it is the record number of the
441 * first continuation data block (dump bug?).
443 * The next record we want is `prevtapea + 1'.
445 i = prevtapea + 1 - tmpbuf.c_tapea;
446 dprintf(stderr, "Skipping %ld duplicate record%s.\n",
447 i, i > 1 ? "s" : "");
452 if (curfile.action == USING) {
454 panic("active file into volume 1\n");
457 (void) gethead(&spcl);
466 * Handle unexpected EOF.
472 if (gettingfile && curfile.action == USING) {
473 printf("Warning: %s %s\n",
474 "End-of-input encountered while extracting", curfile.name);
476 curfile.name = "<name unknown>";
477 curfile.action = UNKNOWN;
479 curfile.ino = maxino;
487 * handle multiple dumps per tape by skipping forward to the
495 if (dumpnum == 1 || volno != 1)
498 fprintf(stderr, "Cannot have multiple dumps on pipe input\n");
502 tcom.mt_count = dumpnum - 1;
505 rmtioctl(MTFSF, dumpnum - 1);
508 if (ioctl(mt, MTIOCTOP, (char *)&tcom) < 0)
509 fprintf(stderr, "ioctl MTFSF: %s\n", strerror(errno));
516 t = _time32_to_time(spcl.c_date);
517 fprintf(stdout, "Dump date: %s", ctime(&t));
518 t = _time32_to_time(spcl.c_ddate);
519 fprintf(stdout, "Dumped from: %s",
520 (spcl.c_ddate == 0) ? "the epoch\n" : ctime(&t));
521 if (spcl.c_host[0] == '\0')
523 fprintf(stderr, "Level %ld dump of %s on %s:%s\n",
524 spcl.c_level, spcl.c_filesys, spcl.c_host, spcl.c_dev);
525 fprintf(stderr, "Label: %s\n", spcl.c_label);
529 extractfile(char *name)
533 struct timeval timep[2];
537 curfile.action = USING;
538 timep[0].tv_sec = curfile.dip->di_atime;
539 timep[0].tv_usec = curfile.dip->di_atimensec / 1000;
540 timep[1].tv_sec = curfile.dip->di_mtime;
541 timep[1].tv_usec = curfile.dip->di_mtimensec / 1000;
542 mode = curfile.dip->di_mode;
543 flags = curfile.dip->di_flags;
544 switch (mode & IFMT) {
547 fprintf(stderr, "%s: unknown file mode 0%o\n", name, mode);
552 vprintf(stdout, "skipped socket %s\n", name);
558 ep = lookupname(name);
559 if (ep == NULL || ep->e_flags & EXTRACT)
560 panic("unextracted directory %s\n", name);
564 vprintf(stdout, "extract file %s\n", name);
565 return (genliteraldir(name, curfile.ino));
570 getfile(xtrlnkfile, xtrlnkskip);
573 "%s: zero length symbolic link (ignored)\n", name);
576 return (linkit(lnkbuf, name, SYMLINK));
579 vprintf(stdout, "extract fifo %s\n", name);
586 if (mkfifo(name, mode) < 0) {
587 fprintf(stderr, "%s: cannot create fifo: %s\n",
588 name, strerror(errno));
592 (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
593 (void) chmod(name, mode);
595 (void) chflags(name, flags);
601 vprintf(stdout, "extract special file %s\n", name);
608 if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) {
609 fprintf(stderr, "%s: cannot create special file: %s\n",
610 name, strerror(errno));
614 (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
615 (void) chmod(name, mode);
617 (void) chflags(name, flags);
622 vprintf(stdout, "extract file %s\n", name);
629 if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
631 fprintf(stderr, "%s: cannot create file: %s\n",
632 name, strerror(errno));
636 (void) fchown(ofile, curfile.dip->di_uid, curfile.dip->di_gid);
637 (void) fchmod(ofile, mode);
638 getfile(xtrfile, xtrskip);
641 (void) chflags(name, flags);
648 * skip over bit maps on the tape
654 while (spcl.c_type == TS_BITS || spcl.c_type == TS_CLRI)
659 * skip over a file on the tape
665 curfile.action = SKIP;
666 getfile(xtrnull, xtrnull);
670 * Extract a file from the tape.
671 * When an allocated block is found it is passed to the fill function;
672 * when an unallocated block (hole) is found, a zeroed buffer is passed
673 * to the skip function.
676 getfile(void (*fill)(char *, long), void (*skip)(char *, long))
680 quad_t size = spcl.c_dinode.di_size;
681 static char clearedbuf[MAXBSIZE];
682 char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE];
685 if (spcl.c_type == TS_END)
686 panic("ran off end of tape\n");
687 if (spcl.c_magic != NFS_MAGIC)
688 panic("not at beginning of a file\n");
689 if (!gettingfile && setjmp(restart) != 0)
693 for (i = 0; i < spcl.c_count; i++) {
694 if (readmapflag || spcl.c_addr[i]) {
695 readtape(&buf[curblk++][0]);
696 if (curblk == fssize / TP_BSIZE) {
697 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
698 fssize : (curblk - 1) * TP_BSIZE + size));
703 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
705 (curblk - 1) * TP_BSIZE + size));
708 (*skip)(clearedbuf, (long)(size > TP_BSIZE ?
711 if ((size -= TP_BSIZE) <= 0) {
712 for (i++; i < spcl.c_count; i++)
713 if (readmapflag || spcl.c_addr[i])
718 if (gethead(&spcl) == GOOD && size > 0) {
719 if (spcl.c_type == TS_ADDR)
722 "Missing address (header) block for %s at %ld blocks\n",
723 curfile.name, blksread);
726 (*fill)((char *)buf, (long)((curblk * TP_BSIZE) + size));
732 * Write out the next block of a file.
735 xtrfile(char *buf, long size)
740 if (write(ofile, buf, (int) size) == -1) {
742 "write error extracting inode %d, name %s\nwrite: %s\n",
743 curfile.ino, curfile.name, strerror(errno));
748 * Skip over a hole in a file.
752 xtrskip(char *buf, long size)
755 if (lseek(ofile, size, SEEK_CUR) == -1) {
757 "seek error extracting inode %d, name %s\nlseek: %s\n",
758 curfile.ino, curfile.name, strerror(errno));
764 * Collect the next block of a symbolic link.
767 xtrlnkfile(char *buf, long size)
771 if (pathlen > MAXPATHLEN) {
772 fprintf(stderr, "symbolic link name: %s->%s%s; too long %d\n",
773 curfile.name, lnkbuf, buf, pathlen);
776 (void) strcat(lnkbuf, buf);
780 * Skip over a hole in a symbolic link (should never happen).
784 xtrlnkskip(char *buf, long size)
787 fprintf(stderr, "unallocated block in symbolic link %s\n",
793 * Collect the next block of a bit map.
796 xtrmap(char *buf, long size)
799 memmove(map, buf, size);
804 * Skip over a hole in a bit map (should never happen).
808 xtrmapskip(char *buf, long size)
811 panic("hole in map\n");
816 * Noop, when an extraction function is not needed.
820 xtrnull(char *buf, long size)
827 * Read TP_BSIZE blocks from the input.
828 * Handle read errors, and end of media.
834 int cnt, seek_failed;
836 if (blkcnt < numtrec) {
837 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
842 for (i = 0; i < ntrec; i++)
843 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
846 cnt = ntrec * TP_BSIZE;
851 i = rmtread(&tapebuf[rd], cnt);
854 i = read(mt, &tapebuf[rd], cnt);
856 * Check for mid-tape short read error.
857 * If found, skip rest of buffer and start with the next.
859 if (!pipein && numtrec < ntrec && i > 0) {
860 dprintf(stdout, "mid-media short read error.\n");
864 * Handle partial block read.
866 if (pipein && i == 0 && rd > 0)
868 else if (i > 0 && i != ntrec * TP_BSIZE) {
877 * Short read. Process the blocks read.
879 if (i % TP_BSIZE != 0)
881 "partial block read: %ld should be %ld\n",
882 i, ntrec * TP_BSIZE);
883 numtrec = i / TP_BSIZE;
890 fprintf(stderr, "Tape read error while ");
891 switch (curfile.action) {
893 fprintf(stderr, "trying to set up tape\n");
896 fprintf(stderr, "trying to resynchronize\n");
899 fprintf(stderr, "restoring %s\n", curfile.name);
902 fprintf(stderr, "skipping over inode %d\n",
906 if (!yflag && !reply("continue"))
908 i = ntrec * TP_BSIZE;
909 memset(tapebuf, 0, i);
912 seek_failed = (rmtseek(i, 1) < 0);
915 seek_failed = (lseek(mt, i, SEEK_CUR) == (off_t)-1);
919 "continuation failed: %s\n", strerror(errno));
924 * Handle end of tape.
927 vprintf(stdout, "End-of-tape encountered\n");
936 if (rd % TP_BSIZE != 0)
937 panic("partial block read: %d should be %d\n",
938 rd, ntrec * TP_BSIZE);
940 memmove(&tapebuf[rd], &endoftapemark, (long)TP_BSIZE);
943 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
949 findtapeblksize(void)
953 for (i = 0; i < ntrec; i++)
954 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
958 i = rmtread(tapebuf, ntrec * TP_BSIZE);
961 i = read(mt, tapebuf, ntrec * TP_BSIZE);
964 fprintf(stderr, "tape read error: %s\n", strerror(errno));
967 if (i % TP_BSIZE != 0) {
968 fprintf(stderr, "Tape block size (%ld) %s (%d)\n",
969 i, "is not a multiple of dump block size", TP_BSIZE);
972 ntrec = i / TP_BSIZE;
974 vprintf(stdout, "Tape block size is %ld\n", ntrec);
992 * Read the next block from the tape.
993 * Check to see if it is one of several vintage headers.
994 * If it is an old style header, convert it to a new style header.
995 * If it is not any valid header, return an error.
998 gethead(struct s_spcl *buf)
1006 char dummy[TP_BSIZE];
1017 unsigned short odi_mode;
1034 readtape((char *)buf);
1035 if (buf->c_magic != NFS_MAGIC) {
1036 if (swabl(buf->c_magic) != NFS_MAGIC)
1039 vprintf(stdout, "Note: Doing Byte swapping\n");
1043 if (checksum((int *)buf) == FAIL)
1046 swabst((u_char *)"8l4s31l", (u_char *)buf);
1047 swabst((u_char *)"l",(u_char *) &buf->c_level);
1048 swabst((u_char *)"2l",(u_char *) &buf->c_flags);
1052 readtape((char *)(&u_ospcl.s_ospcl));
1053 memset(buf, 0, (long)TP_BSIZE);
1054 buf->c_type = u_ospcl.s_ospcl.c_type;
1055 buf->c_date = u_ospcl.s_ospcl.c_date;
1056 buf->c_ddate = u_ospcl.s_ospcl.c_ddate;
1057 buf->c_volume = u_ospcl.s_ospcl.c_volume;
1058 buf->c_tapea = u_ospcl.s_ospcl.c_tapea;
1059 buf->c_inumber = u_ospcl.s_ospcl.c_inumber;
1060 buf->c_checksum = u_ospcl.s_ospcl.c_checksum;
1061 buf->c_magic = u_ospcl.s_ospcl.c_magic;
1062 buf->c_dinode.di_mode = u_ospcl.s_ospcl.c_dinode.odi_mode;
1063 buf->c_dinode.di_nlink = u_ospcl.s_ospcl.c_dinode.odi_nlink;
1064 buf->c_dinode.di_uid = u_ospcl.s_ospcl.c_dinode.odi_uid;
1065 buf->c_dinode.di_gid = u_ospcl.s_ospcl.c_dinode.odi_gid;
1066 buf->c_dinode.di_size = u_ospcl.s_ospcl.c_dinode.odi_size;
1067 buf->c_dinode.di_rdev = u_ospcl.s_ospcl.c_dinode.odi_rdev;
1068 buf->c_dinode.di_atime = u_ospcl.s_ospcl.c_dinode.odi_atime;
1069 buf->c_dinode.di_mtime = u_ospcl.s_ospcl.c_dinode.odi_mtime;
1070 buf->c_dinode.di_ctime = u_ospcl.s_ospcl.c_dinode.odi_ctime;
1071 buf->c_count = u_ospcl.s_ospcl.c_count;
1072 memmove(buf->c_addr, u_ospcl.s_ospcl.c_addr, (long)256);
1073 if (u_ospcl.s_ospcl.c_magic != OFS_MAGIC ||
1074 checksum((int *)(&u_ospcl.s_ospcl)) == FAIL)
1076 buf->c_magic = NFS_MAGIC;
1079 if ((buf->c_dinode.di_size == 0 || buf->c_dinode.di_size > 0xfffffff) &&
1080 (buf->c_dinode.di_mode & IFMT) == IFDIR && Qcvt == 0) {
1081 qcvt.qval = buf->c_dinode.di_size;
1082 if (qcvt.val[0] || qcvt.val[1]) {
1083 printf("Note: Doing Quad swapping\n");
1088 qcvt.qval = buf->c_dinode.di_size;
1090 qcvt.val[1] = qcvt.val[0];
1092 buf->c_dinode.di_size = qcvt.qval;
1096 switch (buf->c_type) {
1101 * Have to patch up missing information in bit map headers
1104 buf->c_dinode.di_size = buf->c_count * TP_BSIZE;
1105 if (buf->c_count > TP_NINDIR)
1108 for (i = 0; i < buf->c_count; i++)
1113 if ((buf->c_flags & DR_NEWINODEFMT) == 0)
1125 panic("gethead: unknown inode type %d\n", buf->c_type);
1129 * If we are restoring a filesystem with old format inodes,
1130 * copy the uid/gid to the new location.
1133 buf->c_dinode.di_uid = buf->c_dinode.di_ouid;
1134 buf->c_dinode.di_gid = buf->c_dinode.di_ogid;
1136 tapeaddr = buf->c_tapea;
1143 * Check that a header is where it belongs and predict the next header
1146 accthdr(struct s_spcl *header)
1148 static ino_t previno = 0x7fffffff;
1149 static int prevtype;
1150 static long predict;
1153 if (header->c_type == TS_TAPE) {
1154 fprintf(stderr, "Volume header (%s inode format) ",
1155 oldinofmt ? "old" : "new");
1156 if (header->c_firstrec)
1157 fprintf(stderr, "begins with record %ld",
1158 header->c_firstrec);
1159 fprintf(stderr, "\n");
1160 previno = 0x7fffffff;
1163 if (previno == 0x7fffffff)
1167 fprintf(stderr, "Dumped inodes map header");
1170 fprintf(stderr, "Used inodes map header");
1173 fprintf(stderr, "File header, ino %d", previno);
1176 fprintf(stderr, "File continuation header, ino %d", previno);
1179 fprintf(stderr, "End of tape header");
1182 if (predict != blksread - 1)
1183 fprintf(stderr, "; predicted %ld blocks, got %ld blocks",
1184 predict, blksread - 1);
1185 fprintf(stderr, "\n");
1188 if (header->c_type != TS_END)
1189 for (i = 0; i < header->c_count; i++)
1190 if (readmapflag || header->c_addr[i] != 0)
1194 prevtype = header->c_type;
1195 previno = header->c_inumber;
1199 * Find an inode header.
1200 * Complain if had to skip.
1203 findinode(struct s_spcl *header)
1205 static long skipcnt = 0;
1210 curfile.name = "<name unknown>";
1211 curfile.action = UNKNOWN;
1215 if (header->c_magic != NFS_MAGIC) {
1217 while (gethead(header) == FAIL ||
1218 _time32_to_time(header->c_date) != dumpdate)
1221 htype = header->c_type;
1226 * Skip up to the beginning of the next record
1228 for (i = 0; i < header->c_count; i++)
1229 if (header->c_addr[i])
1231 while (gethead(header) == FAIL ||
1232 _time32_to_time(header->c_date) != dumpdate)
1237 curfile.dip = &header->c_dinode;
1238 curfile.ino = header->c_inumber;
1242 /* If we missed some tapes, get another volume. */
1243 if (tapesread & (tapesread + 1)) {
1247 curfile.ino = maxino;
1251 curfile.name = "<file removal list>";
1255 curfile.name = "<file dump list>";
1259 panic("unexpected tape header\n");
1263 panic("unknown tape header type %d\n", spcl.c_type);
1267 } while (htype == TS_ADDR);
1269 fprintf(stderr, "resync restore, skipped %ld blocks\n",
1279 j = sizeof(union u_spcl) / sizeof(int);
1286 /* What happens if we want to read restore tapes
1287 for a 16bit int machine??? */
1293 if (i != CHECKSUM) {
1294 fprintf(stderr, "Checksum error %o, inode %d file %s\n", i,
1295 curfile.ino, curfile.name);
1305 msg(const char *fmt, ...)
1309 (void)vfprintf(stderr, fmt, ap);
1312 #endif /* RRESTORE */
1315 swabshort(u_char *sp, int n)
1320 c = sp[0]; sp[0] = sp[1]; sp[1] = c;
1327 swablong(u_char *sp, int n)
1332 c = sp[0]; sp[0] = sp[3]; sp[3] = c;
1333 c = sp[2]; sp[2] = sp[1]; sp[1] = c;
1340 swabst(u_char *cp, u_char *sp)
1346 case '0': case '1': case '2': case '3': case '4':
1347 case '5': case '6': case '7': case '8': case '9':
1348 n = (n * 10) + (*cp++ - '0');
1351 case 's': case 'w': case 'h':
1354 sp = swabshort(sp, n);
1360 sp = swablong(sp, n);
1363 default: /* Any other character, like 'b' counts as byte. */
1377 swabst((u_char *)"l", (u_char *)&x);