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
38 * @(#)tape.c 8.9 (Berkeley) 5/1/95
39 * $FreeBSD: src/sbin/restore/tape.c,v 1.16.2.8 2002/06/30 22:57:52 iedowse Exp $
40 * $DragonFly: src/sbin/restore/tape.c,v 1.3 2003/08/08 04:18:40 dillon Exp $
43 #include <sys/param.h>
49 #include <vfs/ufs/dinode.h>
50 #include <protocols/dumprestore.h>
64 static long fssize = MAXBSIZE;
66 static int pipein = 0;
71 static union u_spcl endoftapemark;
72 static long blksread; /* blocks read since last header */
73 static long tapeaddr = 0; /* current TP_BSIZE tape record */
74 static long tapesread;
75 static jmp_buf restart;
76 static int gettingfile = 0; /* restart has a valid frame */
77 static char *host = NULL;
81 static char lnkbuf[MAXPATHLEN + 1];
84 int oldinofmt; /* old inode format conversion required */
85 int Bcvt; /* Swap Bytes (for CCI or sun) */
86 static int Qcvt; /* Swap quads (for sun) */
88 #define FLUSHTAPEBUF() blkcnt = ntrec + 1
90 static void accthdr __P((struct s_spcl *));
91 static int checksum __P((int *));
92 static void findinode __P((struct s_spcl *));
93 static void findtapeblksize __P((void));
94 static int gethead __P((struct s_spcl *));
95 static void readtape __P((char *));
96 static void setdumpnum __P((void));
97 static u_long swabl __P((u_long));
98 static u_char *swablong __P((u_char *, int));
99 static u_char *swabshort __P((u_char *, int));
100 static void terminateinput __P((void));
101 static void xtrfile __P((char *, long));
102 static void xtrlnkfile __P((char *, long));
103 static void xtrlnkskip __P((char *, long));
104 static void xtrmap __P((char *, long));
105 static void xtrmapskip __P((char *, long));
106 static void xtrskip __P((char *, long));
108 static int readmapflag;
111 * Set up an input 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");
163 static tapebufsize = -1;
166 if (size <= tapebufsize)
170 tapebuf = malloc(size * TP_BSIZE);
171 if (tapebuf == NULL) {
172 fprintf(stderr, "Cannot allocate space for tape buffer\n");
179 * Verify that the tape drive can be accessed and
180 * that it actually is a dump tape.
188 vprintf(stdout, "Verify tape and initialize maps\n");
191 mt = rmtopen(magtape, 0);
197 mt = open(magtape, O_RDONLY, 0);
199 fprintf(stderr, "%s: %s\n", magtape, strerror(errno));
205 if (!pipein && !bflag)
207 if (gethead(&spcl) == FAIL) {
208 blkcnt--; /* push back this block */
211 if (gethead(&spcl) == FAIL) {
212 fprintf(stderr, "Tape is not a dump tape\n");
215 fprintf(stderr, "Converting to new file system format.\n");
218 endoftapemark.s_spcl.c_magic = cvtflag ? OFS_MAGIC : NFS_MAGIC;
219 endoftapemark.s_spcl.c_type = TS_END;
220 ip = (int *)&endoftapemark;
221 j = sizeof(union u_spcl) / sizeof(int);
226 endoftapemark.s_spcl.c_checksum = CHECKSUM - i;
228 if (vflag || command == 't')
230 dumptime = spcl.c_ddate;
231 dumpdate = spcl.c_date;
232 if (stat(".", &stbuf) < 0) {
233 fprintf(stderr, "cannot stat .: %s\n", strerror(errno));
236 if (stbuf.st_blksize > 0 && stbuf.st_blksize < TP_BSIZE )
238 if (stbuf.st_blksize >= TP_BSIZE && stbuf.st_blksize <= MAXBSIZE)
239 fssize = stbuf.st_blksize;
240 if (((fssize - 1) & fssize) != 0) {
241 fprintf(stderr, "bad block size %ld\n", fssize);
244 if (spcl.c_volume != 1) {
245 fprintf(stderr, "Tape is not volume 1 of the dump\n");
248 if (gethead(&spcl) == FAIL) {
249 dprintf(stdout, "header read failed at %ld blocks\n", blksread);
250 panic("no header after volume mark!\n");
253 if (spcl.c_type != TS_CLRI) {
254 fprintf(stderr, "Cannot find file removal list\n");
257 maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1;
258 dprintf(stdout, "maxino = %d\n", maxino);
259 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
261 panic("no memory for active inode map\n");
263 curfile.action = USING;
264 getfile(xtrmap, xtrmapskip);
265 if (spcl.c_type != TS_BITS) {
266 fprintf(stderr, "Cannot find file dump list\n");
269 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
270 if (map == (char *)NULL)
271 panic("no memory for file dump list\n");
273 curfile.action = USING;
274 getfile(xtrmap, xtrmapskip);
276 * If there may be whiteout entries on the tape, pretend that the
277 * whiteout inode exists, so that the whiteout entries can be
281 SETINO(WINO, dumpmap);
282 /* 'r' restores don't call getvol() for tape 1, so mark it as read. */
288 * Prompt user to load a new dump volume.
289 * "Nextvol" is the next suggested volume to use.
290 * This suggested volume is enforced when doing full
291 * or incremental restores, but can be overridden by
292 * the user when only extracting a subset of the files.
298 long newvol, prevtapea, savecnt, i;
299 union u_spcl tmpspcl;
300 # define tmpbuf tmpspcl.s_spcl
307 prevtapea = tapeaddr;
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))
322 done(1); /* pipes do not get a second chance */
323 if (command == 'R' || command == 'r' || curfile.action != SKIP)
327 while (newvol <= 0) {
328 if (tapesread == 0) {
329 fprintf(stderr, "%s%s%s%s%s%s%s",
330 "You have not read any tapes yet.\n",
331 "If you are extracting just a few files,",
332 " start with the last volume\n",
333 "and work towards the first; restore",
334 " can quickly skip tapes that\n",
335 "have no further files to extract.",
336 " Otherwise, begin with volume 1.\n");
338 fprintf(stderr, "You have read volumes");
340 for (i = 0; i < 32; i++)
341 if (tapesread & (1 << i)) {
342 fprintf(stderr, "%s%ld", buf, i + 1);
345 fprintf(stderr, "\n");
348 fprintf(stderr, "Specify next volume #: ");
349 (void) fflush(stderr);
350 if (fgets(buf, BUFSIZ, terminal) == NULL)
352 } while (buf[0] == '\n');
356 "Volume numbers are positive numerics\n");
359 if (newvol == volno) {
360 tapesread |= 1 << (volno - 1);
364 fprintf(stderr, "Mount tape volume %ld\n", newvol);
365 fprintf(stderr, "Enter ``none'' if there are no more tapes\n");
366 fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape);
367 (void) fflush(stderr);
368 if (fgets(buf, BUFSIZ, terminal) == NULL)
370 if (!strcmp(buf, "none\n")) {
374 if (buf[0] != '\n') {
375 (void) strcpy(magtape, buf);
376 magtape[strlen(magtape) - 1] = '\0';
380 mt = rmtopen(magtape, 0);
383 mt = open(magtape, O_RDONLY, 0);
386 fprintf(stderr, "Cannot open %s\n", magtape);
394 if (gethead(&tmpbuf) == FAIL) {
395 dprintf(stdout, "header read failed at %ld blocks\n", blksread);
396 fprintf(stderr, "tape is not dump tape\n");
400 if (tmpbuf.c_volume != volno) {
401 fprintf(stderr, "Wrong volume (%ld)\n", tmpbuf.c_volume);
405 if (tmpbuf.c_date != dumpdate || tmpbuf.c_ddate != dumptime) {
406 fprintf(stderr, "Wrong dump date\n\tgot: %s",
407 ctime(&tmpbuf.c_date));
408 fprintf(stderr, "\twanted: %s", ctime(&dumpdate));
412 tapesread |= 1 << (volno - 1);
415 * If continuing from the previous volume, skip over any
416 * blocks read already at the end of the previous volume.
418 * If coming to this volume at random, skip to the beginning
419 * of the next record.
421 dprintf(stdout, "last rec %ld, tape starts with %ld\n", prevtapea,
423 if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) {
424 if (curfile.action != USING) {
426 * XXX Dump incorrectly sets c_count to 1 in the
427 * volume header of the first tape, so ignore
428 * c_count when volno == 1.
431 for (i = tmpbuf.c_count; i > 0; i--)
433 } else if (tmpbuf.c_tapea <= prevtapea) {
435 * Normally the value of c_tapea in the volume
436 * header is the record number of the header itself.
437 * However in the volume header following an EOT-
438 * terminated tape, it is the record number of the
439 * first continuation data block (dump bug?).
441 * The next record we want is `prevtapea + 1'.
443 i = prevtapea + 1 - tmpbuf.c_tapea;
444 dprintf(stderr, "Skipping %ld duplicate record%s.\n",
445 i, i > 1 ? "s" : "");
450 if (curfile.action == USING) {
452 panic("active file into volume 1\n");
455 (void) gethead(&spcl);
464 * Handle unexpected EOF.
470 if (gettingfile && curfile.action == USING) {
471 printf("Warning: %s %s\n",
472 "End-of-input encountered while extracting", curfile.name);
474 curfile.name = "<name unknown>";
475 curfile.action = UNKNOWN;
477 curfile.ino = maxino;
485 * handle multiple dumps per tape by skipping forward to the
493 if (dumpnum == 1 || volno != 1)
496 fprintf(stderr, "Cannot have multiple dumps on pipe input\n");
500 tcom.mt_count = dumpnum - 1;
503 rmtioctl(MTFSF, dumpnum - 1);
506 if (ioctl(mt, MTIOCTOP, (char *)&tcom) < 0)
507 fprintf(stderr, "ioctl MTFSF: %s\n", strerror(errno));
513 fprintf(stdout, "Dump date: %s", ctime(&spcl.c_date));
514 fprintf(stdout, "Dumped from: %s",
515 (spcl.c_ddate == 0) ? "the epoch\n" : ctime(&spcl.c_ddate));
516 if (spcl.c_host[0] == '\0')
518 fprintf(stderr, "Level %ld dump of %s on %s:%s\n",
519 spcl.c_level, spcl.c_filesys, spcl.c_host, spcl.c_dev);
520 fprintf(stderr, "Label: %s\n", spcl.c_label);
531 struct timeval timep[2];
535 curfile.action = USING;
536 timep[0].tv_sec = curfile.dip->di_atime;
537 timep[0].tv_usec = curfile.dip->di_atimensec / 1000;
538 timep[1].tv_sec = curfile.dip->di_mtime;
539 timep[1].tv_usec = curfile.dip->di_mtimensec / 1000;
540 uid = curfile.dip->di_uid;
541 gid = curfile.dip->di_gid;
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 if (linkit(lnkbuf, name, SYMLINK) == GOOD) {
577 (void) lchown(name, uid, gid);
578 (void) lchmod(name, mode);
579 (void) lutimes(name, timep);
585 vprintf(stdout, "extract fifo %s\n", name);
592 if (mkfifo(name, mode) < 0) {
593 fprintf(stderr, "%s: cannot create fifo: %s\n",
594 name, strerror(errno));
598 (void) chown(name, uid, gid);
599 (void) chmod(name, mode);
600 (void) utimes(name, timep);
601 (void) chflags(name, flags);
607 vprintf(stdout, "extract special file %s\n", name);
614 if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) {
615 fprintf(stderr, "%s: cannot create special file: %s\n",
616 name, strerror(errno));
620 (void) chown(name, uid, gid);
621 (void) chmod(name, mode);
622 (void) utimes(name, timep);
623 (void) chflags(name, flags);
628 vprintf(stdout, "extract file %s\n", name);
635 if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
637 fprintf(stderr, "%s: cannot create file: %s\n",
638 name, strerror(errno));
642 (void) fchown(ofile, uid, gid);
643 (void) fchmod(ofile, mode);
644 getfile(xtrfile, xtrskip);
647 (void) chflags(name, flags);
654 * skip over bit maps on the tape
660 while (spcl.c_type == TS_BITS || spcl.c_type == TS_CLRI)
665 * skip over a file on the tape
671 curfile.action = SKIP;
672 getfile(xtrnull, xtrnull);
676 * Extract a file from the tape.
677 * When an allocated block is found it is passed to the fill function;
678 * when an unallocated block (hole) is found, a zeroed buffer is passed
679 * to the skip function.
683 void (*fill) __P((char *, long));
684 void (*skip) __P((char *, long));
688 quad_t size = spcl.c_dinode.di_size;
689 static char clearedbuf[MAXBSIZE];
690 char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE];
693 if (spcl.c_type == TS_END)
694 panic("ran off end of tape\n");
695 if (spcl.c_magic != NFS_MAGIC)
696 panic("not at beginning of a file\n");
697 if (!gettingfile && setjmp(restart) != 0)
701 for (i = 0; i < spcl.c_count; i++) {
702 if (readmapflag || spcl.c_addr[i]) {
703 readtape(&buf[curblk++][0]);
704 if (curblk == fssize / TP_BSIZE) {
705 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
706 fssize : (curblk - 1) * TP_BSIZE + size));
711 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
713 (curblk - 1) * TP_BSIZE + size));
716 (*skip)(clearedbuf, (long)(size > TP_BSIZE ?
719 if ((size -= TP_BSIZE) <= 0) {
720 for (i++; i < spcl.c_count; i++)
721 if (readmapflag || spcl.c_addr[i])
726 if (gethead(&spcl) == GOOD && size > 0) {
727 if (spcl.c_type == TS_ADDR)
730 "Missing address (header) block for %s at %ld blocks\n",
731 curfile.name, blksread);
734 (*fill)((char *)buf, (long)((curblk * TP_BSIZE) + size));
740 * Write out the next block of a file.
750 if (write(ofile, buf, (int) size) == -1) {
752 "write error extracting inode %d, name %s\nwrite: %s\n",
753 curfile.ino, curfile.name, strerror(errno));
758 * Skip over a hole in a file.
767 if (lseek(ofile, size, SEEK_CUR) == -1) {
769 "seek error extracting inode %d, name %s\nlseek: %s\n",
770 curfile.ino, curfile.name, strerror(errno));
776 * Collect the next block of a symbolic link.
779 xtrlnkfile(buf, size)
785 if (pathlen > MAXPATHLEN) {
786 fprintf(stderr, "symbolic link name: %s->%s%s; too long %d\n",
787 curfile.name, lnkbuf, buf, pathlen);
790 (void) strcat(lnkbuf, buf);
794 * Skip over a hole in a symbolic link (should never happen).
798 xtrlnkskip(buf, size)
803 fprintf(stderr, "unallocated block in symbolic link %s\n",
809 * Collect the next block of a bit map.
817 memmove(map, buf, size);
822 * Skip over a hole in a bit map (should never happen).
826 xtrmapskip(buf, size)
831 panic("hole in map\n");
836 * Noop, when an extraction function is not needed.
849 * Read TP_BSIZE blocks from the input.
850 * Handle read errors, and end of media.
857 int cnt, seek_failed;
859 if (blkcnt < numtrec) {
860 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
865 for (i = 0; i < ntrec; i++)
866 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
869 cnt = ntrec * TP_BSIZE;
874 i = rmtread(&tapebuf[rd], cnt);
877 i = read(mt, &tapebuf[rd], cnt);
879 * Check for mid-tape short read error.
880 * If found, skip rest of buffer and start with the next.
882 if (!pipein && numtrec < ntrec && i > 0) {
883 dprintf(stdout, "mid-media short read error.\n");
887 * Handle partial block read.
889 if (pipein && i == 0 && rd > 0)
891 else if (i > 0 && i != ntrec * TP_BSIZE) {
900 * Short read. Process the blocks read.
902 if (i % TP_BSIZE != 0)
904 "partial block read: %ld should be %ld\n",
905 i, ntrec * TP_BSIZE);
906 numtrec = i / TP_BSIZE;
913 fprintf(stderr, "Tape read error while ");
914 switch (curfile.action) {
916 fprintf(stderr, "trying to set up tape\n");
919 fprintf(stderr, "trying to resynchronize\n");
922 fprintf(stderr, "restoring %s\n", curfile.name);
925 fprintf(stderr, "skipping over inode %d\n",
929 if (!yflag && !reply("continue"))
931 i = ntrec * TP_BSIZE;
932 memset(tapebuf, 0, i);
935 seek_failed = (rmtseek(i, 1) < 0);
938 seek_failed = (lseek(mt, i, SEEK_CUR) == (off_t)-1);
942 "continuation failed: %s\n", strerror(errno));
947 * Handle end of tape.
950 vprintf(stdout, "End-of-tape encountered\n");
959 if (rd % TP_BSIZE != 0)
960 panic("partial block read: %d should be %d\n",
961 rd, ntrec * TP_BSIZE);
963 memmove(&tapebuf[rd], &endoftapemark, (long)TP_BSIZE);
966 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
976 for (i = 0; i < ntrec; i++)
977 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
981 i = rmtread(tapebuf, ntrec * TP_BSIZE);
984 i = read(mt, tapebuf, ntrec * TP_BSIZE);
987 fprintf(stderr, "tape read error: %s\n", strerror(errno));
990 if (i % TP_BSIZE != 0) {
991 fprintf(stderr, "Tape block size (%ld) %s (%d)\n",
992 i, "is not a multiple of dump block size", TP_BSIZE);
995 ntrec = i / TP_BSIZE;
997 vprintf(stdout, "Tape block size is %ld\n", ntrec);
1015 * Read the next block from the tape.
1016 * Check to see if it is one of several vintage headers.
1017 * If it is an old style header, convert it to a new style header.
1018 * If it is not any valid header, return an error.
1030 char dummy[TP_BSIZE];
1041 unsigned short odi_mode;
1058 readtape((char *)buf);
1059 if (buf->c_magic != NFS_MAGIC) {
1060 if (swabl(buf->c_magic) != NFS_MAGIC)
1063 vprintf(stdout, "Note: Doing Byte swapping\n");
1067 if (checksum((int *)buf) == FAIL)
1070 swabst((u_char *)"8l4s31l", (u_char *)buf);
1071 swabst((u_char *)"l",(u_char *) &buf->c_level);
1072 swabst((u_char *)"2l",(u_char *) &buf->c_flags);
1076 readtape((char *)(&u_ospcl.s_ospcl));
1077 memset(buf, 0, (long)TP_BSIZE);
1078 buf->c_type = u_ospcl.s_ospcl.c_type;
1079 buf->c_date = u_ospcl.s_ospcl.c_date;
1080 buf->c_ddate = u_ospcl.s_ospcl.c_ddate;
1081 buf->c_volume = u_ospcl.s_ospcl.c_volume;
1082 buf->c_tapea = u_ospcl.s_ospcl.c_tapea;
1083 buf->c_inumber = u_ospcl.s_ospcl.c_inumber;
1084 buf->c_checksum = u_ospcl.s_ospcl.c_checksum;
1085 buf->c_magic = u_ospcl.s_ospcl.c_magic;
1086 buf->c_dinode.di_mode = u_ospcl.s_ospcl.c_dinode.odi_mode;
1087 buf->c_dinode.di_nlink = u_ospcl.s_ospcl.c_dinode.odi_nlink;
1088 buf->c_dinode.di_uid = u_ospcl.s_ospcl.c_dinode.odi_uid;
1089 buf->c_dinode.di_gid = u_ospcl.s_ospcl.c_dinode.odi_gid;
1090 buf->c_dinode.di_size = u_ospcl.s_ospcl.c_dinode.odi_size;
1091 buf->c_dinode.di_rdev = u_ospcl.s_ospcl.c_dinode.odi_rdev;
1092 buf->c_dinode.di_atime = u_ospcl.s_ospcl.c_dinode.odi_atime;
1093 buf->c_dinode.di_mtime = u_ospcl.s_ospcl.c_dinode.odi_mtime;
1094 buf->c_dinode.di_ctime = u_ospcl.s_ospcl.c_dinode.odi_ctime;
1095 buf->c_count = u_ospcl.s_ospcl.c_count;
1096 memmove(buf->c_addr, u_ospcl.s_ospcl.c_addr, (long)256);
1097 if (u_ospcl.s_ospcl.c_magic != OFS_MAGIC ||
1098 checksum((int *)(&u_ospcl.s_ospcl)) == FAIL)
1100 buf->c_magic = NFS_MAGIC;
1103 if ((buf->c_dinode.di_size == 0 || buf->c_dinode.di_size > 0xfffffff) &&
1104 (buf->c_dinode.di_mode & IFMT) == IFDIR && Qcvt == 0) {
1105 qcvt.qval = buf->c_dinode.di_size;
1106 if (qcvt.val[0] || qcvt.val[1]) {
1107 printf("Note: Doing Quad swapping\n");
1112 qcvt.qval = buf->c_dinode.di_size;
1114 qcvt.val[1] = qcvt.val[0];
1116 buf->c_dinode.di_size = qcvt.qval;
1120 switch (buf->c_type) {
1125 * Have to patch up missing information in bit map headers
1128 buf->c_dinode.di_size = buf->c_count * TP_BSIZE;
1129 if (buf->c_count > TP_NINDIR)
1132 for (i = 0; i < buf->c_count; i++)
1137 if ((buf->c_flags & DR_NEWINODEFMT) == 0)
1149 panic("gethead: unknown inode type %d\n", buf->c_type);
1153 * If we are restoring a filesystem with old format inodes,
1154 * copy the uid/gid to the new location.
1157 buf->c_dinode.di_uid = buf->c_dinode.di_ouid;
1158 buf->c_dinode.di_gid = buf->c_dinode.di_ogid;
1160 tapeaddr = buf->c_tapea;
1167 * Check that a header is where it belongs and predict the next header
1171 struct s_spcl *header;
1173 static ino_t previno = 0x7fffffff;
1174 static int prevtype;
1175 static long predict;
1178 if (header->c_type == TS_TAPE) {
1179 fprintf(stderr, "Volume header (%s inode format) ",
1180 oldinofmt ? "old" : "new");
1181 if (header->c_firstrec)
1182 fprintf(stderr, "begins with record %ld",
1183 header->c_firstrec);
1184 fprintf(stderr, "\n");
1185 previno = 0x7fffffff;
1188 if (previno == 0x7fffffff)
1192 fprintf(stderr, "Dumped inodes map header");
1195 fprintf(stderr, "Used inodes map header");
1198 fprintf(stderr, "File header, ino %d", previno);
1201 fprintf(stderr, "File continuation header, ino %d", previno);
1204 fprintf(stderr, "End of tape header");
1207 if (predict != blksread - 1)
1208 fprintf(stderr, "; predicted %ld blocks, got %ld blocks",
1209 predict, blksread - 1);
1210 fprintf(stderr, "\n");
1213 if (header->c_type != TS_END)
1214 for (i = 0; i < header->c_count; i++)
1215 if (readmapflag || header->c_addr[i] != 0)
1219 prevtype = header->c_type;
1220 previno = header->c_inumber;
1224 * Find an inode header.
1225 * Complain if had to skip.
1229 struct s_spcl *header;
1231 static long skipcnt = 0;
1236 curfile.name = "<name unknown>";
1237 curfile.action = UNKNOWN;
1241 if (header->c_magic != NFS_MAGIC) {
1243 while (gethead(header) == FAIL ||
1244 header->c_date != dumpdate)
1247 htype = header->c_type;
1252 * Skip up to the beginning of the next record
1254 for (i = 0; i < header->c_count; i++)
1255 if (header->c_addr[i])
1257 while (gethead(header) == FAIL ||
1258 header->c_date != dumpdate)
1263 curfile.dip = &header->c_dinode;
1264 curfile.ino = header->c_inumber;
1268 /* If we missed some tapes, get another volume. */
1269 if (tapesread & (tapesread + 1)) {
1273 curfile.ino = maxino;
1277 curfile.name = "<file removal list>";
1281 curfile.name = "<file dump list>";
1285 panic("unexpected tape header\n");
1289 panic("unknown tape header type %d\n", spcl.c_type);
1293 } while (htype == TS_ADDR);
1295 fprintf(stderr, "resync restore, skipped %ld blocks\n",
1306 j = sizeof(union u_spcl) / sizeof(int);
1313 /* What happens if we want to read restore tapes
1314 for a 16bit int machine??? */
1320 if (i != CHECKSUM) {
1321 fprintf(stderr, "Checksum error %o, inode %d file %s\n", i,
1322 curfile.ino, curfile.name);
1332 #include <varargs.h>
1337 msg(const char *fmt, ...)
1350 (void)vfprintf(stderr, fmt, ap);
1353 #endif /* RRESTORE */
1357 register u_char *sp;
1363 c = sp[0]; sp[0] = sp[1]; sp[1] = c;
1371 register u_char *sp;
1377 c = sp[0]; sp[0] = sp[3]; sp[3] = c;
1378 c = sp[2]; sp[2] = sp[1]; sp[1] = c;
1386 register u_char *cp, *sp;
1392 case '0': case '1': case '2': case '3': case '4':
1393 case '5': case '6': case '7': case '8': case '9':
1394 n = (n * 10) + (*cp++ - '0');
1397 case 's': case 'w': case 'h':
1400 sp = swabshort(sp, n);
1406 sp = swablong(sp, n);
1409 default: /* Any other character, like 'b' counts as byte. */
1424 swabst((u_char *)"l", (u_char *)&x);