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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)tape.c 8.9 (Berkeley) 5/1/95
35 * $FreeBSD: src/sbin/restore/tape.c,v 1.16.2.8 2002/06/30 22:57:52 iedowse Exp $
36 * $DragonFly: src/sbin/restore/tape.c,v 1.9 2005/11/06 12:49:25 swildner Exp $
39 #include <sys/param.h>
45 #include <vfs/ufs/dinode.h>
46 #include <protocols/dumprestore.h>
60 static long fssize = MAXBSIZE;
62 static int pipein = 0;
67 static union u_spcl endoftapemark;
68 static long blksread; /* blocks read since last header */
69 static long tapeaddr = 0; /* current TP_BSIZE tape record */
70 static long tapesread;
71 static jmp_buf restart;
72 static int gettingfile = 0; /* restart has a valid frame */
73 static char *host = NULL;
77 static char lnkbuf[MAXPATHLEN + 1];
80 int oldinofmt; /* old inode format conversion required */
81 int Bcvt; /* Swap Bytes (for CCI or sun) */
82 static int Qcvt; /* Swap quads (for sun) */
84 #define FLUSHTAPEBUF() blkcnt = ntrec + 1
86 static void accthdr(struct s_spcl *);
87 static int checksum(int *);
88 static void findinode(struct s_spcl *);
89 static void findtapeblksize(void);
90 static int gethead(struct s_spcl *);
91 static void readtape(char *);
92 static void setdumpnum(void);
93 static u_long swabl(u_long);
94 static u_char *swablong(u_char *, int);
95 static u_char *swabshort(u_char *, int);
96 static void terminateinput(void);
97 static void xtrfile(char *, long);
98 static void xtrlnkfile(char *, long);
99 static void xtrlnkskip(char *, long);
100 static void xtrmap(char *, long);
101 static void xtrmapskip(char *, long);
102 static void xtrskip(char *, long);
104 static int readmapflag;
107 * Set up an input source
110 setinput(char *source)
116 newtapebuf(NTREC > HIGHDENSITYTREC ? NTREC : HIGHDENSITYTREC);
120 if (strchr(source, ':')) {
122 source = strchr(host, ':');
124 if (rmthost(host) == 0)
128 if (strcmp(source, "-") == 0) {
130 * Since input is coming from a pipe we must establish
131 * our own connection to the terminal.
133 terminal = fopen(_PATH_TTY, "r");
134 if (terminal == NULL) {
135 fprintf(stderr, "cannot open %s: %s\n",
136 _PATH_TTY, strerror(errno));
137 terminal = fopen(_PATH_DEVNULL, "r");
138 if (terminal == NULL) {
139 fprintf(stderr, "cannot open %s: %s\n",
140 _PATH_DEVNULL, strerror(errno));
146 setuid(getuid()); /* no longer need or want root privileges */
147 magtape = strdup(source);
148 if (magtape == NULL) {
149 fprintf(stderr, "Cannot allocate space for magtape buffer\n");
155 newtapebuf(long size)
157 static long tapebufsize = -1;
160 if (size <= tapebufsize)
164 tapebuf = malloc(size * TP_BSIZE);
165 if (tapebuf == NULL) {
166 fprintf(stderr, "Cannot allocate space for tape buffer\n");
173 * Verify that the tape drive can be accessed and
174 * that it actually is a dump tape.
182 vprintf(stdout, "Verify tape and initialize maps\n");
185 mt = rmtopen(magtape, 0);
191 mt = open(magtape, O_RDONLY, 0);
193 fprintf(stderr, "%s: %s\n", magtape, strerror(errno));
199 if (!pipein && !bflag)
201 if (gethead(&spcl) == FAIL) {
202 blkcnt--; /* push back this block */
205 if (gethead(&spcl) == FAIL) {
206 fprintf(stderr, "Tape is not a dump tape\n");
209 fprintf(stderr, "Converting to new file system format.\n");
212 endoftapemark.s_spcl.c_magic = cvtflag ? OFS_MAGIC : NFS_MAGIC;
213 endoftapemark.s_spcl.c_type = TS_END;
214 ip = (int *)&endoftapemark;
215 j = sizeof(union u_spcl) / sizeof(int);
220 endoftapemark.s_spcl.c_checksum = CHECKSUM - i;
222 if (vflag || command == 't')
224 dumptime = spcl.c_ddate;
225 dumpdate = spcl.c_date;
226 if (stat(".", &stbuf) < 0) {
227 fprintf(stderr, "cannot stat .: %s\n", strerror(errno));
230 if (stbuf.st_blksize > 0 && stbuf.st_blksize < TP_BSIZE )
232 if (stbuf.st_blksize >= TP_BSIZE && stbuf.st_blksize <= MAXBSIZE)
233 fssize = stbuf.st_blksize;
234 if (((fssize - 1) & fssize) != 0) {
235 fprintf(stderr, "bad block size %ld\n", fssize);
238 if (spcl.c_volume != 1) {
239 fprintf(stderr, "Tape is not volume 1 of the dump\n");
242 if (gethead(&spcl) == FAIL) {
243 dprintf(stdout, "header read failed at %ld blocks\n", blksread);
244 panic("no header after volume mark!\n");
247 if (spcl.c_type != TS_CLRI) {
248 fprintf(stderr, "Cannot find file removal list\n");
251 maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1;
252 dprintf(stdout, "maxino = %d\n", maxino);
253 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
255 panic("no memory for active inode map\n");
257 curfile.action = USING;
258 getfile(xtrmap, xtrmapskip);
259 if (spcl.c_type != TS_BITS) {
260 fprintf(stderr, "Cannot find file dump list\n");
263 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
265 panic("no memory for file dump list\n");
267 curfile.action = USING;
268 getfile(xtrmap, xtrmapskip);
270 * If there may be whiteout entries on the tape, pretend that the
271 * whiteout inode exists, so that the whiteout entries can be
275 SETINO(WINO, dumpmap);
276 /* 'r' restores don't call getvol() for tape 1, so mark it as read. */
282 * Prompt user to load a new dump volume.
283 * "Nextvol" is the next suggested volume to use.
284 * This suggested volume is enforced when doing full
285 * or incremental restores, but can be overridden by
286 * the user when only extracting a subset of the files.
291 long newvol = 0, prevtapea, savecnt, i;
292 union u_spcl tmpspcl;
293 # define tmpbuf tmpspcl.s_spcl
300 prevtapea = tapeaddr;
304 panic("Changing volumes on pipe input?\n");
305 /* Avoid looping if we couldn't ask the user. */
306 if (yflag || ferror(terminal) || feof(terminal))
315 done(1); /* pipes do not get a second chance */
316 if (command == 'R' || command == 'r' || curfile.action != SKIP)
320 while (newvol <= 0) {
321 if (tapesread == 0) {
322 fprintf(stderr, "%s%s%s%s%s%s%s",
323 "You have not read any tapes yet.\n",
324 "If you are extracting just a few files,",
325 " start with the last volume\n",
326 "and work towards the first; restore",
327 " can quickly skip tapes that\n",
328 "have no further files to extract.",
329 " Otherwise, begin with volume 1.\n");
331 fprintf(stderr, "You have read volumes");
333 for (i = 0; i < 32; i++)
334 if (tapesread & (1 << i)) {
335 fprintf(stderr, "%s%ld", buf, i + 1);
338 fprintf(stderr, "\n");
341 fprintf(stderr, "Specify next volume #: ");
343 if (fgets(buf, BUFSIZ, terminal) == NULL)
345 } while (buf[0] == '\n');
349 "Volume numbers are positive numerics\n");
352 if (newvol == volno) {
353 tapesread |= 1 << (volno - 1);
357 fprintf(stderr, "Mount tape volume %ld\n", newvol);
358 fprintf(stderr, "Enter ``none'' if there are no more tapes\n");
359 fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape);
361 if (fgets(buf, BUFSIZ, terminal) == NULL)
363 if (!strcmp(buf, "none\n")) {
367 if (buf[0] != '\n') {
368 strcpy(magtape, buf);
369 magtape[strlen(magtape) - 1] = '\0';
373 mt = rmtopen(magtape, 0);
376 mt = open(magtape, O_RDONLY, 0);
379 fprintf(stderr, "Cannot open %s\n", magtape);
387 if (gethead(&tmpbuf) == FAIL) {
388 dprintf(stdout, "header read failed at %ld blocks\n", blksread);
389 fprintf(stderr, "tape is not dump tape\n");
393 if (tmpbuf.c_volume != volno) {
394 fprintf(stderr, "Wrong volume (%ld)\n", (long)tmpbuf.c_volume);
398 if (tmpbuf.c_date != dumpdate || tmpbuf.c_ddate != dumptime) {
399 time_t c_date = tmpbuf.c_date;
400 fprintf(stderr, "Wrong dump date\n\tgot: %s", ctime(&c_date));
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 %ld, tape starts with %ld\n", prevtapea,
415 (long)tmpbuf.c_tapea);
416 if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) {
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");
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));
506 time_t c_date = spcl.c_date;
507 time_t c_ddate = spcl.c_ddate;
509 fprintf(stdout, "Dump date: %s", ctime(&c_date));
510 fprintf(stdout, "Dumped from: %s",
511 (spcl.c_ddate == 0) ? "the epoch\n" : ctime(&c_ddate));
512 if (spcl.c_host[0] == '\0')
514 fprintf(stderr, "Level %ld dump of %s on %s:%s\n",
515 (long)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)
526 struct timeval timep[2];
530 curfile.action = USING;
531 timep[0].tv_sec = curfile.dip->di_atime;
532 timep[0].tv_usec = curfile.dip->di_atimensec / 1000;
533 timep[1].tv_sec = curfile.dip->di_mtime;
534 timep[1].tv_usec = curfile.dip->di_mtimensec / 1000;
535 uid = curfile.dip->di_uid;
536 gid = curfile.dip->di_gid;
537 mode = curfile.dip->di_mode;
538 flags = curfile.dip->di_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 lchown(name, uid, gid);
574 lutimes(name, timep);
580 vprintf(stdout, "extract fifo %s\n", name);
587 if (mkfifo(name, mode) < 0) {
588 fprintf(stderr, "%s: cannot create fifo: %s\n",
589 name, strerror(errno));
593 chown(name, uid, gid);
596 chflags(name, flags);
602 vprintf(stdout, "extract special file %s\n", name);
609 if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) {
610 fprintf(stderr, "%s: cannot create special file: %s\n",
611 name, strerror(errno));
615 chown(name, uid, gid);
618 chflags(name, flags);
623 vprintf(stdout, "extract file %s\n", name);
630 if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
632 fprintf(stderr, "%s: cannot create file: %s\n",
633 name, strerror(errno));
637 fchown(ofile, uid, gid);
639 getfile(xtrfile, xtrskip);
642 chflags(name, flags);
649 * skip over bit maps on the tape
655 while (spcl.c_type == TS_BITS || spcl.c_type == TS_CLRI)
660 * skip over a file on the tape
666 curfile.action = SKIP;
667 getfile(xtrnull, xtrnull);
671 * Extract a file from the tape.
672 * When an allocated block is found it is passed to the fill function;
673 * when an unallocated block (hole) is found, a zeroed buffer is passed
674 * to the skip function.
677 getfile(void (*fill) (char *, long), void (*skip) (char *, long))
681 quad_t size = spcl.c_dinode.di_size;
682 static char clearedbuf[MAXBSIZE];
683 char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE];
686 if (spcl.c_type == TS_END)
687 panic("ran off end of tape\n");
688 if (spcl.c_magic != NFS_MAGIC)
689 panic("not at beginning of a file\n");
690 if (!gettingfile && setjmp(restart) != 0)
694 for (i = 0; i < spcl.c_count; i++) {
695 if (readmapflag || spcl.c_addr[i]) {
696 readtape(&buf[curblk++][0]);
697 if (curblk == fssize / TP_BSIZE) {
698 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
699 fssize : (curblk - 1) * TP_BSIZE + size));
704 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
706 (curblk - 1) * TP_BSIZE + size));
709 (*skip)(clearedbuf, (long)(size > TP_BSIZE ?
712 if ((size -= TP_BSIZE) <= 0) {
713 for (i++; i < spcl.c_count; i++)
714 if (readmapflag || spcl.c_addr[i])
719 if (gethead(&spcl) == GOOD && size > 0) {
720 if (spcl.c_type == TS_ADDR)
723 "Missing address (header) block for %s at %ld blocks\n",
724 curfile.name, blksread);
727 (*fill)((char *)buf, (long)((curblk * TP_BSIZE) + size));
733 * Write out the next block of a file.
736 xtrfile(char *buf, long size)
741 if (write(ofile, buf, (int) size) == -1) {
743 "write error extracting inode %d, name %s\nwrite: %s\n",
744 curfile.ino, curfile.name, strerror(errno));
749 * Skip over a hole in a file.
753 xtrskip(char *buf, long size)
756 if (lseek(ofile, size, SEEK_CUR) == -1) {
758 "seek error extracting inode %d, name %s\nlseek: %s\n",
759 curfile.ino, curfile.name, strerror(errno));
765 * Collect the next block of a symbolic link.
768 xtrlnkfile(char *buf, long size)
772 if (pathlen > MAXPATHLEN) {
773 fprintf(stderr, "symbolic link name: %s->%s%s; too long %d\n",
774 curfile.name, lnkbuf, buf, pathlen);
781 * Skip over a hole in a symbolic link (should never happen).
785 xtrlnkskip(char *buf, long size)
788 fprintf(stderr, "unallocated block in symbolic link %s\n",
794 * Collect the next block of a bit map.
797 xtrmap(char *buf, long size)
800 memmove(map, buf, size);
805 * Skip over a hole in a bit map (should never happen).
809 xtrmapskip(char *buf, long size)
812 panic("hole in map\n");
817 * Noop, when an extraction function is not needed.
821 xtrnull(char *buf, long size)
828 * Read TP_BSIZE blocks from the input.
829 * Handle read errors, and end of media.
835 int cnt, seek_failed;
837 if (blkcnt < numtrec) {
838 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
843 for (i = 0; i < ntrec; i++)
844 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
847 cnt = ntrec * TP_BSIZE;
852 i = rmtread(&tapebuf[rd], cnt);
855 i = read(mt, &tapebuf[rd], cnt);
857 * Check for mid-tape short read error.
858 * If found, skip rest of buffer and start with the next.
860 if (!pipein && numtrec < ntrec && i > 0) {
861 dprintf(stdout, "mid-media short read error.\n");
865 * Handle partial block read.
867 if (pipein && i == 0 && rd > 0)
869 else if (i > 0 && i != ntrec * TP_BSIZE) {
878 * Short read. Process the blocks read.
880 if (i % TP_BSIZE != 0)
882 "partial block read: %ld should be %ld\n",
883 i, ntrec * TP_BSIZE);
884 numtrec = i / TP_BSIZE;
891 fprintf(stderr, "Tape read error while ");
892 switch (curfile.action) {
894 fprintf(stderr, "trying to set up tape\n");
897 fprintf(stderr, "trying to resynchronize\n");
900 fprintf(stderr, "restoring %s\n", curfile.name);
903 fprintf(stderr, "skipping over inode %d\n",
907 if (!yflag && !reply("continue"))
909 i = ntrec * TP_BSIZE;
910 memset(tapebuf, 0, i);
913 seek_failed = (rmtseek(i, 1) < 0);
916 seek_failed = (lseek(mt, i, SEEK_CUR) == (off_t)-1);
920 "continuation failed: %s\n", strerror(errno));
925 * Handle end of tape.
928 vprintf(stdout, "End-of-tape encountered\n");
937 if (rd % TP_BSIZE != 0)
938 panic("partial block read: %d should be %d\n",
939 rd, ntrec * TP_BSIZE);
941 memmove(&tapebuf[rd], &endoftapemark, (long)TP_BSIZE);
944 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
950 findtapeblksize(void)
954 for (i = 0; i < ntrec; i++)
955 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
959 i = rmtread(tapebuf, ntrec * TP_BSIZE);
962 i = read(mt, tapebuf, ntrec * TP_BSIZE);
965 fprintf(stderr, "tape read error: %s\n", strerror(errno));
968 if (i % TP_BSIZE != 0) {
969 fprintf(stderr, "Tape block size (%ld) %s (%d)\n",
970 i, "is not a multiple of dump block size", TP_BSIZE);
973 ntrec = i / TP_BSIZE;
975 vprintf(stdout, "Tape block size is %ld\n", ntrec);
993 * Read the next block from the tape.
994 * Check to see if it is one of several vintage headers.
995 * If it is an old style header, convert it to a new style header.
996 * If it is not any valid header, return an error.
999 gethead(struct s_spcl *buf)
1007 char dummy[TP_BSIZE];
1018 unsigned short odi_mode;
1035 readtape((char *)buf);
1036 if (buf->c_magic != NFS_MAGIC) {
1037 if (swabl(buf->c_magic) != NFS_MAGIC)
1040 vprintf(stdout, "Note: Doing Byte swapping\n");
1044 if (checksum((int *)buf) == FAIL)
1047 swabst((u_char *)"8l4s31l", (u_char *)buf);
1048 swabst((u_char *)"l",(u_char *) &buf->c_level);
1049 swabst((u_char *)"2l",(u_char *) &buf->c_flags);
1053 readtape((char *)(&u_ospcl.s_ospcl));
1054 memset(buf, 0, (long)TP_BSIZE);
1055 buf->c_type = u_ospcl.s_ospcl.c_type;
1056 buf->c_date = u_ospcl.s_ospcl.c_date;
1057 buf->c_ddate = u_ospcl.s_ospcl.c_ddate;
1058 buf->c_volume = u_ospcl.s_ospcl.c_volume;
1059 buf->c_tapea = u_ospcl.s_ospcl.c_tapea;
1060 buf->c_inumber = u_ospcl.s_ospcl.c_inumber;
1061 buf->c_checksum = u_ospcl.s_ospcl.c_checksum;
1062 buf->c_magic = u_ospcl.s_ospcl.c_magic;
1063 buf->c_dinode.di_mode = u_ospcl.s_ospcl.c_dinode.odi_mode;
1064 buf->c_dinode.di_nlink = u_ospcl.s_ospcl.c_dinode.odi_nlink;
1065 buf->c_dinode.di_uid = u_ospcl.s_ospcl.c_dinode.odi_uid;
1066 buf->c_dinode.di_gid = u_ospcl.s_ospcl.c_dinode.odi_gid;
1067 buf->c_dinode.di_size = u_ospcl.s_ospcl.c_dinode.odi_size;
1068 buf->c_dinode.di_rdev = u_ospcl.s_ospcl.c_dinode.odi_rdev;
1069 buf->c_dinode.di_atime = u_ospcl.s_ospcl.c_dinode.odi_atime;
1070 buf->c_dinode.di_mtime = u_ospcl.s_ospcl.c_dinode.odi_mtime;
1071 buf->c_dinode.di_ctime = u_ospcl.s_ospcl.c_dinode.odi_ctime;
1072 buf->c_count = u_ospcl.s_ospcl.c_count;
1073 memmove(buf->c_addr, u_ospcl.s_ospcl.c_addr, (long)256);
1074 if (u_ospcl.s_ospcl.c_magic != OFS_MAGIC ||
1075 checksum((int *)(&u_ospcl.s_ospcl)) == FAIL)
1077 buf->c_magic = NFS_MAGIC;
1080 if ((buf->c_dinode.di_size == 0 || buf->c_dinode.di_size > 0xfffffff) &&
1081 (buf->c_dinode.di_mode & IFMT) == IFDIR && Qcvt == 0) {
1082 qcvt.qval = buf->c_dinode.di_size;
1083 if (qcvt.val[0] || qcvt.val[1]) {
1084 printf("Note: Doing Quad swapping\n");
1089 qcvt.qval = buf->c_dinode.di_size;
1091 qcvt.val[1] = qcvt.val[0];
1093 buf->c_dinode.di_size = qcvt.qval;
1097 switch (buf->c_type) {
1102 * Have to patch up missing information in bit map headers
1105 buf->c_dinode.di_size = buf->c_count * TP_BSIZE;
1106 if (buf->c_count > TP_NINDIR)
1109 for (i = 0; i < buf->c_count; i++)
1114 if ((buf->c_flags & DR_NEWINODEFMT) == 0)
1126 panic("gethead: unknown inode type %d\n", buf->c_type);
1130 * If we are restoring a filesystem with old format inodes,
1131 * copy the uid/gid to the new location.
1134 buf->c_dinode.di_uid = buf->c_dinode.di_ouid;
1135 buf->c_dinode.di_gid = buf->c_dinode.di_ogid;
1137 tapeaddr = buf->c_tapea;
1144 * Check that a header is where it belongs and predict the next header
1147 accthdr(struct s_spcl *header)
1149 static ufs1_ino_t previno = 0x7fffffff;
1150 static int prevtype;
1151 static long predict;
1154 if (header->c_type == TS_TAPE) {
1155 fprintf(stderr, "Volume header (%s inode format) ",
1156 oldinofmt ? "old" : "new");
1157 if (header->c_firstrec)
1158 fprintf(stderr, "begins with record %ld",
1159 (long)header->c_firstrec);
1160 fprintf(stderr, "\n");
1161 previno = 0x7fffffff;
1164 if (previno == 0x7fffffff)
1168 fprintf(stderr, "Dumped inodes map header");
1171 fprintf(stderr, "Used inodes map header");
1174 fprintf(stderr, "File header, ino %d", previno);
1177 fprintf(stderr, "File continuation header, ino %d", previno);
1180 fprintf(stderr, "End of tape header");
1183 if (predict != blksread - 1)
1184 fprintf(stderr, "; predicted %ld blocks, got %ld blocks",
1185 predict, blksread - 1);
1186 fprintf(stderr, "\n");
1189 if (header->c_type != TS_END)
1190 for (i = 0; i < header->c_count; i++)
1191 if (readmapflag || header->c_addr[i] != 0)
1195 prevtype = header->c_type;
1196 previno = header->c_inumber;
1200 * Find an inode header.
1201 * Complain if had to skip.
1204 findinode(struct s_spcl *header)
1206 static long skipcnt = 0;
1211 curfile.name = "<name unknown>";
1212 curfile.action = UNKNOWN;
1216 if (header->c_magic != NFS_MAGIC) {
1218 while (gethead(header) == FAIL ||
1219 header->c_date != dumpdate)
1222 htype = header->c_type;
1227 * Skip up to the beginning of the next record
1229 for (i = 0; i < header->c_count; i++)
1230 if (header->c_addr[i])
1232 while (gethead(header) == FAIL ||
1233 header->c_date != dumpdate)
1238 curfile.dip = &header->c_dinode;
1239 curfile.ino = header->c_inumber;
1243 /* If we missed some tapes, get another volume. */
1244 if (tapesread & (tapesread + 1)) {
1248 curfile.ino = maxino;
1252 curfile.name = "<file removal list>";
1256 curfile.name = "<file dump list>";
1260 panic("unexpected tape header\n");
1264 panic("unknown tape header type %d\n", spcl.c_type);
1268 } while (htype == TS_ADDR);
1270 fprintf(stderr, "resync restore, skipped %ld blocks\n",
1280 j = sizeof(union u_spcl) / sizeof(int);
1287 /* What happens if we want to read restore tapes
1288 for a 16bit int machine??? */
1294 if (i != CHECKSUM) {
1295 fprintf(stderr, "Checksum error %o, inode %d file %s\n", i,
1296 curfile.ino, curfile.name);
1306 msg(const char *fmt, ...)
1310 vfprintf(stderr, fmt, ap);
1313 #endif /* RRESTORE */
1316 swabshort(u_char *sp, int n)
1321 c = sp[0]; sp[0] = sp[1]; sp[1] = c;
1328 swablong(u_char *sp, int n)
1333 c = sp[0]; sp[0] = sp[3]; sp[3] = c;
1334 c = sp[2]; sp[2] = sp[1]; sp[1] = c;
1341 swabst(u_char *cp, u_char *sp)
1347 case '0': case '1': case '2': case '3': case '4':
1348 case '5': case '6': case '7': case '8': case '9':
1349 n = (n * 10) + (*cp++ - '0');
1352 case 's': case 'w': case 'h':
1355 sp = swabshort(sp, n);
1361 sp = swablong(sp, n);
1364 default: /* Any other character, like 'b' counts as byte. */
1378 swabst((u_char *)"l", (u_char *)&x);