2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 static char sccsid[] = "@(#)tape.c 8.9 (Berkeley) 5/1/95";
43 static const char rcsid[] =
47 #include <sys/param.h>
53 #include <ufs/ufs/dinode.h>
54 #include <protocols/dumprestore.h>
68 static long fssize = MAXBSIZE;
70 static int pipein = 0;
75 static union u_spcl endoftapemark;
76 static long blksread; /* blocks read since last header */
77 static long tpblksread = 0; /* TP_BSIZE blocks read */
78 static long tapesread;
79 static jmp_buf restart;
80 static int gettingfile = 0; /* restart has a valid frame */
81 static char *host = NULL;
85 static char lnkbuf[MAXPATHLEN + 1];
88 int oldinofmt; /* old inode format conversion required */
89 int Bcvt; /* Swap Bytes (for CCI or sun) */
90 static int Qcvt; /* Swap quads (for sun) */
92 #define FLUSHTAPEBUF() blkcnt = ntrec + 1
94 static void accthdr __P((struct s_spcl *));
95 static int checksum __P((int *));
96 static void findinode __P((struct s_spcl *));
97 static void findtapeblksize __P((void));
98 static int gethead __P((struct s_spcl *));
99 static void readtape __P((char *));
100 static void setdumpnum __P((void));
101 static u_long swabl __P((u_long));
102 static u_char *swablong __P((u_char *, int));
103 static u_char *swabshort __P((u_char *, int));
104 static void terminateinput __P((void));
105 static void xtrfile __P((char *, long));
106 static void xtrlnkfile __P((char *, long));
107 static void xtrlnkskip __P((char *, long));
108 static void xtrmap __P((char *, long));
109 static void xtrmapskip __P((char *, long));
110 static void xtrskip __P((char *, long));
112 static int readmapflag;
115 * Set up an input source
125 newtapebuf(NTREC > HIGHDENSITYTREC ? NTREC : HIGHDENSITYTREC);
129 if (strchr(source, ':')) {
131 source = strchr(host, ':');
133 if (rmthost(host) == 0)
137 if (strcmp(source, "-") == 0) {
139 * Since input is coming from a pipe we must establish
140 * our own connection to the terminal.
142 terminal = fopen(_PATH_TTY, "r");
143 if (terminal == NULL) {
144 (void)fprintf(stderr, "cannot open %s: %s\n",
145 _PATH_TTY, strerror(errno));
146 terminal = fopen(_PATH_DEVNULL, "r");
147 if (terminal == NULL) {
148 (void)fprintf(stderr, "cannot open %s: %s\n",
149 _PATH_DEVNULL, strerror(errno));
155 setuid(getuid()); /* no longer need or want root privileges */
156 magtape = strdup(source);
157 if (magtape == NULL) {
158 fprintf(stderr, "Cannot allocate space for magtape buffer\n");
167 static tapebufsize = -1;
170 if (size <= tapebufsize)
174 tapebuf = malloc(size * TP_BSIZE);
175 if (tapebuf == NULL) {
176 fprintf(stderr, "Cannot allocate space for tape buffer\n");
183 * Verify that the tape drive can be accessed and
184 * that it actually is a dump tape.
192 vprintf(stdout, "Verify tape and initialize maps\n");
195 mt = rmtopen(magtape, 0);
201 mt = open(magtape, O_RDONLY, 0);
203 fprintf(stderr, "%s: %s\n", magtape, strerror(errno));
209 if (!pipein && !bflag)
211 if (gethead(&spcl) == FAIL) {
212 blkcnt--; /* push back this block */
216 if (gethead(&spcl) == FAIL) {
217 fprintf(stderr, "Tape is not a dump tape\n");
220 fprintf(stderr, "Converting to new file system format.\n");
223 endoftapemark.s_spcl.c_magic = cvtflag ? OFS_MAGIC : NFS_MAGIC;
224 endoftapemark.s_spcl.c_type = TS_END;
225 ip = (int *)&endoftapemark;
226 j = sizeof(union u_spcl) / sizeof(int);
231 endoftapemark.s_spcl.c_checksum = CHECKSUM - i;
233 if (vflag || command == 't')
235 dumptime = time32_to_time(spcl.c_ddate);
236 dumpdate = time32_to_time(spcl.c_date);
237 if (stat(".", &stbuf) < 0) {
238 fprintf(stderr, "cannot stat .: %s\n", strerror(errno));
241 if (stbuf.st_blksize > 0 && stbuf.st_blksize < TP_BSIZE )
243 if (stbuf.st_blksize >= TP_BSIZE && stbuf.st_blksize <= MAXBSIZE)
244 fssize = stbuf.st_blksize;
245 if (((fssize - 1) & fssize) != 0) {
246 fprintf(stderr, "bad block size %ld\n", fssize);
249 if (spcl.c_volume != 1) {
250 fprintf(stderr, "Tape is not volume 1 of the dump\n");
253 if (gethead(&spcl) == FAIL) {
254 dprintf(stdout, "header read failed at %ld blocks\n", blksread);
255 panic("no header after volume mark!\n");
258 if (spcl.c_type != TS_CLRI) {
259 fprintf(stderr, "Cannot find file removal list\n");
262 maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1;
263 dprintf(stdout, "maxino = %d\n", maxino);
264 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
266 panic("no memory for active inode map\n");
268 curfile.action = USING;
269 getfile(xtrmap, xtrmapskip);
270 if (spcl.c_type != TS_BITS) {
271 fprintf(stderr, "Cannot find file dump list\n");
274 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
275 if (map == (char *)NULL)
276 panic("no memory for file dump list\n");
278 curfile.action = USING;
279 getfile(xtrmap, xtrmapskip);
281 * If there may be whiteout entries on the tape, pretend that the
282 * whiteout inode exists, so that the whiteout entries can be
286 SETINO(WINO, dumpmap);
290 * Prompt user to load a new dump volume.
291 * "Nextvol" is the next suggested volume to use.
292 * This suggested volume is enforced when doing full
293 * or incremental restores, but can be overridden by
294 * the user when only extracting a subset of the files.
300 long newvol, savecnt, wantnext, i;
301 union u_spcl tmpspcl;
302 # define tmpbuf tmpspcl.s_spcl
311 panic("Changing volumes on pipe input?\n");
312 /* Avoid looping if we couldn't ask the user. */
313 if (yflag || ferror(terminal) || feof(terminal))
323 done(1); /* pipes do not get a second chance */
324 if (command == 'R' || command == 'r' || curfile.action != SKIP) {
331 while (newvol <= 0) {
332 if (tapesread == 0) {
333 fprintf(stderr, "%s%s%s%s%s",
334 "You have not read any tapes yet.\n",
335 "Unless you know which volume your",
336 " file(s) are on you should start\n",
337 "with the last volume and work",
338 " towards the first.\n");
340 fprintf(stderr, "You have read volumes");
342 for (i = 1; i < 32; i++)
343 if (tapesread & (1 << i)) {
344 fprintf(stderr, "%s%ld", buf, i);
347 fprintf(stderr, "\n");
350 fprintf(stderr, "Specify next volume #: ");
351 (void) fflush(stderr);
352 if (fgets(buf, BUFSIZ, terminal) == NULL)
354 } while (buf[0] == '\n');
358 "Volume numbers are positive numerics\n");
361 if (newvol == volno) {
362 tapesread |= 1 << volno;
366 fprintf(stderr, "Mount tape volume %ld\n", newvol);
367 fprintf(stderr, "Enter ``none'' if there are no more tapes\n");
368 fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape);
369 (void) fflush(stderr);
370 if (fgets(buf, BUFSIZ, terminal) == NULL)
372 if (!strcmp(buf, "none\n")) {
376 if (buf[0] != '\n') {
377 (void) strcpy(magtape, buf);
378 magtape[strlen(magtape) - 1] = '\0';
382 mt = rmtopen(magtape, 0);
385 mt = open(magtape, O_RDONLY, 0);
388 fprintf(stderr, "Cannot open %s\n", magtape);
396 if (gethead(&tmpbuf) == FAIL) {
397 dprintf(stdout, "header read failed at %ld blocks\n", blksread);
398 fprintf(stderr, "tape is not dump tape\n");
402 if (tmpbuf.c_volume != volno) {
403 fprintf(stderr, "Wrong volume (%ld)\n", tmpbuf.c_volume);
407 if (time32_to_time(tmpbuf.c_date) != dumpdate ||
408 time32_to_time(tmpbuf.c_ddate) != dumptime) {
409 time_t t = time32_to_time(tmpbuf.c_date);
410 fprintf(stderr, "Wrong dump date\n\tgot: %s", ctime(&t));
411 fprintf(stderr, "\twanted: %s", ctime(&dumpdate));
415 tapesread |= 1 << volno;
418 * If continuing from the previous volume, skip over any
419 * blocks read already at the end of the previous volume.
421 * If coming to this volume at random, skip to the beginning
422 * of the next record.
424 dprintf(stdout, "read %ld recs, tape starts with %ld\n",
425 tpblksread, tmpbuf.c_firstrec);
426 if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) {
428 tpblksread = tmpbuf.c_firstrec;
429 for (i = tmpbuf.c_count; i > 0; i--)
431 } else if (tmpbuf.c_firstrec > 0 &&
432 tmpbuf.c_firstrec < tpblksread - 1) {
434 * -1 since we've read the volume header
436 i = tpblksread - tmpbuf.c_firstrec - 1;
437 dprintf(stderr, "Skipping %ld duplicate record%s.\n",
438 i, i > 1 ? "s" : "");
443 if (curfile.action == USING || curfile.action == SKIP) {
445 panic("active file into volume 1\n");
449 * Skip up to the beginning of the next record
451 if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER))
452 for (i = tmpbuf.c_count; i > 0; i--)
454 (void) gethead(&spcl);
463 * Handle unexpected EOF.
469 if (gettingfile && curfile.action == USING) {
470 printf("Warning: %s %s\n",
471 "End-of-input encountered while extracting", curfile.name);
473 curfile.name = "<name unknown>";
474 curfile.action = UNKNOWN;
476 curfile.ino = maxino;
484 * handle multiple dumps per tape by skipping forward to the
492 if (dumpnum == 1 || volno != 1)
495 fprintf(stderr, "Cannot have multiple dumps on pipe input\n");
499 tcom.mt_count = dumpnum - 1;
502 rmtioctl(MTFSF, dumpnum - 1);
505 if (ioctl(mt, MTIOCTOP, (char *)&tcom) < 0)
506 fprintf(stderr, "ioctl MTFSF: %s\n", strerror(errno));
513 t = time32_to_time(spcl.c_date);
514 fprintf(stdout, "Dump date: %s", ctime(&t));
515 t = time32_to_time(spcl.c_ddate);
516 fprintf(stdout, "Dumped from: %s",
517 (spcl.c_ddate == 0) ? "the epoch\n" : ctime(&t));
518 if (spcl.c_host[0] == '\0')
520 fprintf(stderr, "Level %ld dump of %s on %s:%s\n",
521 spcl.c_level, spcl.c_filesys, spcl.c_host, spcl.c_dev);
522 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 mode = curfile.dip->di_mode;
541 flags = curfile.dip->di_flags;
542 switch (mode & IFMT) {
545 fprintf(stderr, "%s: unknown file mode 0%o\n", name, mode);
550 vprintf(stdout, "skipped socket %s\n", name);
556 ep = lookupname(name);
557 if (ep == NULL || ep->e_flags & EXTRACT)
558 panic("unextracted directory %s\n", name);
562 vprintf(stdout, "extract file %s\n", name);
563 return (genliteraldir(name, curfile.ino));
568 getfile(xtrlnkfile, xtrlnkskip);
571 "%s: zero length symbolic link (ignored)\n", name);
574 return (linkit(lnkbuf, name, SYMLINK));
577 vprintf(stdout, "extract fifo %s\n", name);
584 if (mkfifo(name, mode) < 0) {
585 fprintf(stderr, "%s: cannot create fifo: %s\n",
586 name, strerror(errno));
590 (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
591 (void) chmod(name, mode);
593 (void) chflags(name, flags);
599 vprintf(stdout, "extract special file %s\n", name);
606 if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) {
607 fprintf(stderr, "%s: cannot create special file: %s\n",
608 name, strerror(errno));
612 (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
613 (void) chmod(name, mode);
615 (void) chflags(name, flags);
620 vprintf(stdout, "extract file %s\n", name);
627 if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
629 fprintf(stderr, "%s: cannot create file: %s\n",
630 name, strerror(errno));
634 (void) fchown(ofile, curfile.dip->di_uid, curfile.dip->di_gid);
635 (void) fchmod(ofile, mode);
636 getfile(xtrfile, xtrskip);
639 (void) chflags(name, flags);
646 * skip over bit maps on the tape
652 while (spcl.c_type == TS_BITS || spcl.c_type == TS_CLRI)
657 * skip over a file on the tape
663 curfile.action = SKIP;
664 getfile(xtrnull, xtrnull);
668 * Extract a file from the tape.
669 * When an allocated block is found it is passed to the fill function;
670 * when an unallocated block (hole) is found, a zeroed buffer is passed
671 * to the skip function.
675 void (*fill) __P((char *, long));
676 void (*skip) __P((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.
742 if (write(ofile, buf, (int) size) == -1) {
744 "write error extracting inode %d, name %s\nwrite: %s\n",
745 curfile.ino, curfile.name, strerror(errno));
750 * Skip over a hole in a file.
759 if (lseek(ofile, size, SEEK_CUR) == -1) {
761 "seek error extracting inode %d, name %s\nlseek: %s\n",
762 curfile.ino, curfile.name, strerror(errno));
768 * Collect the next block of a symbolic link.
771 xtrlnkfile(buf, size)
777 if (pathlen > MAXPATHLEN) {
778 fprintf(stderr, "symbolic link name: %s->%s%s; too long %d\n",
779 curfile.name, lnkbuf, buf, pathlen);
782 (void) strcat(lnkbuf, buf);
786 * Skip over a hole in a symbolic link (should never happen).
790 xtrlnkskip(buf, size)
795 fprintf(stderr, "unallocated block in symbolic link %s\n",
801 * Collect the next block of a bit map.
809 memmove(map, buf, size);
814 * Skip over a hole in a bit map (should never happen).
818 xtrmapskip(buf, size)
823 panic("hole in map\n");
828 * Noop, when an extraction function is not needed.
841 * Read TP_BSIZE blocks from the input.
842 * Handle read errors, and end of media.
849 int cnt, seek_failed;
851 if (blkcnt < numtrec) {
852 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
857 for (i = 0; i < ntrec; i++)
858 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
861 cnt = ntrec * TP_BSIZE;
866 i = rmtread(&tapebuf[rd], cnt);
869 i = read(mt, &tapebuf[rd], cnt);
871 * Check for mid-tape short read error.
872 * If found, skip rest of buffer and start with the next.
874 if (!pipein && numtrec < ntrec && i > 0) {
875 dprintf(stdout, "mid-media short read error.\n");
879 * Handle partial block read.
881 if (pipein && i == 0 && rd > 0)
883 else if (i > 0 && i != ntrec * TP_BSIZE) {
892 * Short read. Process the blocks read.
894 if (i % TP_BSIZE != 0)
896 "partial block read: %ld should be %ld\n",
897 i, ntrec * TP_BSIZE);
898 numtrec = i / TP_BSIZE;
905 fprintf(stderr, "Tape read error while ");
906 switch (curfile.action) {
908 fprintf(stderr, "trying to set up tape\n");
911 fprintf(stderr, "trying to resynchronize\n");
914 fprintf(stderr, "restoring %s\n", curfile.name);
917 fprintf(stderr, "skipping over inode %d\n",
921 if (!yflag && !reply("continue"))
923 i = ntrec * TP_BSIZE;
924 memset(tapebuf, 0, i);
927 seek_failed = (rmtseek(i, 1) < 0);
930 seek_failed = (lseek(mt, i, SEEK_CUR) == (off_t)-1);
934 "continuation failed: %s\n", strerror(errno));
939 * Handle end of tape.
942 vprintf(stdout, "End-of-tape encountered\n");
951 if (rd % TP_BSIZE != 0)
952 panic("partial block read: %d should be %d\n",
953 rd, ntrec * TP_BSIZE);
955 memmove(&tapebuf[rd], &endoftapemark, (long)TP_BSIZE);
958 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
968 for (i = 0; i < ntrec; i++)
969 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
973 i = rmtread(tapebuf, ntrec * TP_BSIZE);
976 i = read(mt, tapebuf, ntrec * TP_BSIZE);
979 fprintf(stderr, "tape read error: %s\n", strerror(errno));
982 if (i % TP_BSIZE != 0) {
983 fprintf(stderr, "Tape block size (%ld) %s (%d)\n",
984 i, "is not a multiple of dump block size", TP_BSIZE);
987 ntrec = i / TP_BSIZE;
989 vprintf(stdout, "Tape block size is %ld\n", ntrec);
1007 * Read the next block from the tape.
1008 * Check to see if it is one of several vintage headers.
1009 * If it is an old style header, convert it to a new style header.
1010 * If it is not any valid header, return an error.
1022 char dummy[TP_BSIZE];
1033 unsigned short odi_mode;
1050 readtape((char *)buf);
1051 if (buf->c_magic != NFS_MAGIC) {
1052 if (swabl(buf->c_magic) != NFS_MAGIC)
1055 vprintf(stdout, "Note: Doing Byte swapping\n");
1059 if (checksum((int *)buf) == FAIL)
1062 swabst((u_char *)"8l4s31l", (u_char *)buf);
1063 swabst((u_char *)"l",(u_char *) &buf->c_level);
1064 swabst((u_char *)"2l",(u_char *) &buf->c_flags);
1068 readtape((char *)(&u_ospcl.s_ospcl));
1069 memset(buf, 0, (long)TP_BSIZE);
1070 buf->c_type = u_ospcl.s_ospcl.c_type;
1071 buf->c_date = u_ospcl.s_ospcl.c_date;
1072 buf->c_ddate = u_ospcl.s_ospcl.c_ddate;
1073 buf->c_volume = u_ospcl.s_ospcl.c_volume;
1074 buf->c_tapea = u_ospcl.s_ospcl.c_tapea;
1075 buf->c_inumber = u_ospcl.s_ospcl.c_inumber;
1076 buf->c_checksum = u_ospcl.s_ospcl.c_checksum;
1077 buf->c_magic = u_ospcl.s_ospcl.c_magic;
1078 buf->c_dinode.di_mode = u_ospcl.s_ospcl.c_dinode.odi_mode;
1079 buf->c_dinode.di_nlink = u_ospcl.s_ospcl.c_dinode.odi_nlink;
1080 buf->c_dinode.di_uid = u_ospcl.s_ospcl.c_dinode.odi_uid;
1081 buf->c_dinode.di_gid = u_ospcl.s_ospcl.c_dinode.odi_gid;
1082 buf->c_dinode.di_size = u_ospcl.s_ospcl.c_dinode.odi_size;
1083 buf->c_dinode.di_rdev = u_ospcl.s_ospcl.c_dinode.odi_rdev;
1084 buf->c_dinode.di_atime = u_ospcl.s_ospcl.c_dinode.odi_atime;
1085 buf->c_dinode.di_mtime = u_ospcl.s_ospcl.c_dinode.odi_mtime;
1086 buf->c_dinode.di_ctime = u_ospcl.s_ospcl.c_dinode.odi_ctime;
1087 buf->c_count = u_ospcl.s_ospcl.c_count;
1088 memmove(buf->c_addr, u_ospcl.s_ospcl.c_addr, (long)256);
1089 if (u_ospcl.s_ospcl.c_magic != OFS_MAGIC ||
1090 checksum((int *)(&u_ospcl.s_ospcl)) == FAIL)
1092 buf->c_magic = NFS_MAGIC;
1095 if ((buf->c_dinode.di_size == 0 || buf->c_dinode.di_size > 0xfffffff) &&
1096 (buf->c_dinode.di_mode & IFMT) == IFDIR && Qcvt == 0) {
1097 qcvt.qval = buf->c_dinode.di_size;
1098 if (qcvt.val[0] || qcvt.val[1]) {
1099 printf("Note: Doing Quad swapping\n");
1104 qcvt.qval = buf->c_dinode.di_size;
1106 qcvt.val[1] = qcvt.val[0];
1108 buf->c_dinode.di_size = qcvt.qval;
1112 switch (buf->c_type) {
1117 * Have to patch up missing information in bit map headers
1120 buf->c_dinode.di_size = buf->c_count * TP_BSIZE;
1121 if (buf->c_count > TP_NINDIR)
1124 for (i = 0; i < buf->c_count; i++)
1129 if ((buf->c_flags & DR_NEWINODEFMT) == 0)
1141 panic("gethead: unknown inode type %d\n", buf->c_type);
1145 * If we are restoring a filesystem with old format inodes,
1146 * copy the uid/gid to the new location.
1149 buf->c_dinode.di_uid = buf->c_dinode.di_ouid;
1150 buf->c_dinode.di_gid = buf->c_dinode.di_ogid;
1158 * Check that a header is where it belongs and predict the next header
1162 struct s_spcl *header;
1164 static ino_t previno = 0x7fffffff;
1165 static int prevtype;
1166 static long predict;
1169 if (header->c_type == TS_TAPE) {
1170 fprintf(stderr, "Volume header (%s inode format) ",
1171 oldinofmt ? "old" : "new");
1172 if (header->c_firstrec)
1173 fprintf(stderr, "begins with record %ld",
1174 header->c_firstrec);
1175 fprintf(stderr, "\n");
1176 previno = 0x7fffffff;
1179 if (previno == 0x7fffffff)
1183 fprintf(stderr, "Dumped inodes map header");
1186 fprintf(stderr, "Used inodes map header");
1189 fprintf(stderr, "File header, ino %d", previno);
1192 fprintf(stderr, "File continuation header, ino %d", previno);
1195 fprintf(stderr, "End of tape header");
1198 if (predict != blksread - 1)
1199 fprintf(stderr, "; predicted %ld blocks, got %ld blocks",
1200 predict, blksread - 1);
1201 fprintf(stderr, "\n");
1204 if (header->c_type != TS_END)
1205 for (i = 0; i < header->c_count; i++)
1206 if (readmapflag || header->c_addr[i] != 0)
1210 prevtype = header->c_type;
1211 previno = header->c_inumber;
1215 * Find an inode header.
1216 * Complain if had to skip, and complain is set.
1220 struct s_spcl *header;
1222 static long skipcnt = 0;
1226 curfile.name = "<name unknown>";
1227 curfile.action = UNKNOWN;
1231 if (header->c_magic != NFS_MAGIC) {
1233 while (gethead(header) == FAIL ||
1234 time32_to_time(header->c_date) != dumpdate)
1237 switch (header->c_type) {
1241 * Skip up to the beginning of the next record
1243 for (i = 0; i < header->c_count; i++)
1244 if (header->c_addr[i])
1246 while (gethead(header) == FAIL ||
1247 time32_to_time(header->c_date) != dumpdate)
1252 curfile.dip = &header->c_dinode;
1253 curfile.ino = header->c_inumber;
1257 curfile.ino = maxino;
1261 curfile.name = "<file removal list>";
1265 curfile.name = "<file dump list>";
1269 panic("unexpected tape header\n");
1273 panic("unknown tape header type %d\n", spcl.c_type);
1277 } while (header->c_type == TS_ADDR);
1279 fprintf(stderr, "resync restore, skipped %ld blocks\n",
1290 j = sizeof(union u_spcl) / sizeof(int);
1297 /* What happens if we want to read restore tapes
1298 for a 16bit int machine??? */
1304 if (i != CHECKSUM) {
1305 fprintf(stderr, "Checksum error %o, inode %d file %s\n", i,
1306 curfile.ino, curfile.name);
1316 #include <varargs.h>
1321 msg(const char *fmt, ...)
1334 (void)vfprintf(stderr, fmt, ap);
1337 #endif /* RRESTORE */
1341 register u_char *sp;
1347 c = sp[0]; sp[0] = sp[1]; sp[1] = c;
1355 register u_char *sp;
1361 c = sp[0]; sp[0] = sp[3]; sp[3] = c;
1362 c = sp[2]; sp[2] = sp[1]; sp[1] = c;
1370 register u_char *cp, *sp;
1376 case '0': case '1': case '2': case '3': case '4':
1377 case '5': case '6': case '7': case '8': case '9':
1378 n = (n * 10) + (*cp++ - '0');
1381 case 's': case 'w': case 'h':
1384 sp = swabshort(sp, n);
1390 sp = swablong(sp, n);
1393 default: /* Any other character, like 'b' counts as byte. */
1408 swabst((u_char *)"l", (u_char *)&x);