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 __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 */
215 if (gethead(&spcl) == FAIL) {
216 fprintf(stderr, "Tape is not a dump tape\n");
219 fprintf(stderr, "Converting to new file system format.\n");
222 endoftapemark.s_spcl.c_magic = cvtflag ? OFS_MAGIC : NFS_MAGIC;
223 endoftapemark.s_spcl.c_type = TS_END;
224 ip = (int *)&endoftapemark;
225 j = sizeof(union u_spcl) / sizeof(int);
230 endoftapemark.s_spcl.c_checksum = CHECKSUM - i;
232 if (vflag || command == 't')
234 dumptime = _time32_to_time(spcl.c_ddate);
235 dumpdate = _time32_to_time(spcl.c_date);
236 if (stat(".", &stbuf) < 0) {
237 fprintf(stderr, "cannot stat .: %s\n", strerror(errno));
240 if (stbuf.st_blksize > 0 && stbuf.st_blksize < TP_BSIZE )
242 if (stbuf.st_blksize >= TP_BSIZE && stbuf.st_blksize <= MAXBSIZE)
243 fssize = stbuf.st_blksize;
244 if (((fssize - 1) & fssize) != 0) {
245 fprintf(stderr, "bad block size %ld\n", fssize);
248 if (spcl.c_volume != 1) {
249 fprintf(stderr, "Tape is not volume 1 of the dump\n");
252 if (gethead(&spcl) == FAIL) {
253 dprintf(stdout, "header read failed at %ld blocks\n", blksread);
254 panic("no header after volume mark!\n");
257 if (spcl.c_type != TS_CLRI) {
258 fprintf(stderr, "Cannot find file removal list\n");
261 maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1;
262 dprintf(stdout, "maxino = %d\n", maxino);
263 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
265 panic("no memory for active inode map\n");
267 curfile.action = USING;
268 getfile(xtrmap, xtrmapskip);
269 if (spcl.c_type != TS_BITS) {
270 fprintf(stderr, "Cannot find file dump list\n");
273 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
274 if (map == (char *)NULL)
275 panic("no memory for file dump list\n");
277 curfile.action = USING;
278 getfile(xtrmap, xtrmapskip);
280 * If there may be whiteout entries on the tape, pretend that the
281 * whiteout inode exists, so that the whiteout entries can be
285 SETINO(WINO, dumpmap);
286 /* 'r' restores don't call getvol() for tape 1, so mark it as read. */
292 * Prompt user to load a new dump volume.
293 * "Nextvol" is the next suggested volume to use.
294 * This suggested volume is enforced when doing full
295 * or incremental restores, but can be overridden by
296 * the user when only extracting a subset of the files.
302 long newvol, prevtapea, savecnt, i;
303 union u_spcl tmpspcl;
304 # define tmpbuf tmpspcl.s_spcl
311 prevtapea = tapeaddr;
315 panic("Changing volumes on pipe input?\n");
316 /* Avoid looping if we couldn't ask the user. */
317 if (yflag || ferror(terminal) || feof(terminal))
326 done(1); /* pipes do not get a second chance */
327 if (command == 'R' || command == 'r' || curfile.action != SKIP)
331 while (newvol <= 0) {
332 if (tapesread == 0) {
333 fprintf(stderr, "%s%s%s%s%s%s%s",
334 "You have not read any tapes yet.\n",
335 "If you are extracting just a few files,",
336 " start with the last volume\n",
337 "and work towards the first; restore",
338 " can quickly skip tapes that\n",
339 "have no further files to extract.",
340 " Otherwise, begin with volume 1.\n");
342 fprintf(stderr, "You have read volumes");
344 for (i = 0; i < 32; i++)
345 if (tapesread & (1 << i)) {
346 fprintf(stderr, "%s%ld", buf, i + 1);
349 fprintf(stderr, "\n");
352 fprintf(stderr, "Specify next volume #: ");
353 (void) fflush(stderr);
354 if (fgets(buf, BUFSIZ, terminal) == NULL)
356 } while (buf[0] == '\n');
360 "Volume numbers are positive numerics\n");
363 if (newvol == volno) {
364 tapesread |= 1 << (volno - 1);
368 fprintf(stderr, "Mount tape volume %ld\n", newvol);
369 fprintf(stderr, "Enter ``none'' if there are no more tapes\n");
370 fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape);
371 (void) fflush(stderr);
372 if (fgets(buf, BUFSIZ, terminal) == NULL)
374 if (!strcmp(buf, "none\n")) {
378 if (buf[0] != '\n') {
379 (void) strcpy(magtape, buf);
380 magtape[strlen(magtape) - 1] = '\0';
384 mt = rmtopen(magtape, 0);
387 mt = open(magtape, O_RDONLY, 0);
390 fprintf(stderr, "Cannot open %s\n", magtape);
398 if (gethead(&tmpbuf) == FAIL) {
399 dprintf(stdout, "header read failed at %ld blocks\n", blksread);
400 fprintf(stderr, "tape is not dump tape\n");
404 if (tmpbuf.c_volume != volno) {
405 fprintf(stderr, "Wrong volume (%ld)\n", tmpbuf.c_volume);
409 if (_time32_to_time(tmpbuf.c_date) != dumpdate ||
410 _time32_to_time(tmpbuf.c_ddate) != dumptime) {
411 time_t t = _time32_to_time(tmpbuf.c_date);
412 fprintf(stderr, "Wrong dump date\n\tgot: %s", ctime(&t));
413 fprintf(stderr, "\twanted: %s", ctime(&dumpdate));
417 tapesread |= 1 << (volno - 1);
420 * If continuing from the previous volume, skip over any
421 * blocks read already at the end of the previous volume.
423 * If coming to this volume at random, skip to the beginning
424 * of the next record.
426 dprintf(stdout, "last rec %ld, tape starts with %ld\n", prevtapea,
428 if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) {
429 if (curfile.action != USING) {
431 * XXX Dump incorrectly sets c_count to 1 in the
432 * volume header of the first tape, so ignore
433 * c_count when volno == 1.
436 for (i = tmpbuf.c_count; i > 0; i--)
438 } else if (tmpbuf.c_tapea <= prevtapea) {
440 * Normally the value of c_tapea in the volume
441 * header is the record number of the header itself.
442 * However in the volume header following an EOT-
443 * terminated tape, it is the record number of the
444 * first continuation data block (dump bug?).
446 * The next record we want is `prevtapea + 1'.
448 i = prevtapea + 1 - tmpbuf.c_tapea;
449 dprintf(stderr, "Skipping %ld duplicate record%s.\n",
450 i, i > 1 ? "s" : "");
455 if (curfile.action == USING) {
457 panic("active file into volume 1\n");
460 (void) gethead(&spcl);
469 * Handle unexpected EOF.
475 if (gettingfile && curfile.action == USING) {
476 printf("Warning: %s %s\n",
477 "End-of-input encountered while extracting", curfile.name);
479 curfile.name = "<name unknown>";
480 curfile.action = UNKNOWN;
482 curfile.ino = maxino;
490 * handle multiple dumps per tape by skipping forward to the
498 if (dumpnum == 1 || volno != 1)
501 fprintf(stderr, "Cannot have multiple dumps on pipe input\n");
505 tcom.mt_count = dumpnum - 1;
508 rmtioctl(MTFSF, dumpnum - 1);
511 if (ioctl(mt, MTIOCTOP, (char *)&tcom) < 0)
512 fprintf(stderr, "ioctl MTFSF: %s\n", strerror(errno));
519 t = _time32_to_time(spcl.c_date);
520 fprintf(stdout, "Dump date: %s", ctime(&t));
521 t = _time32_to_time(spcl.c_ddate);
522 fprintf(stdout, "Dumped from: %s",
523 (spcl.c_ddate == 0) ? "the epoch\n" : ctime(&t));
524 if (spcl.c_host[0] == '\0')
526 fprintf(stderr, "Level %ld dump of %s on %s:%s\n",
527 spcl.c_level, spcl.c_filesys, spcl.c_host, spcl.c_dev);
528 fprintf(stderr, "Label: %s\n", spcl.c_label);
537 struct timeval timep[2];
541 curfile.action = USING;
542 timep[0].tv_sec = curfile.dip->di_atime;
543 timep[0].tv_usec = curfile.dip->di_atimensec / 1000;
544 timep[1].tv_sec = curfile.dip->di_mtime;
545 timep[1].tv_usec = curfile.dip->di_mtimensec / 1000;
546 mode = curfile.dip->di_mode;
547 flags = curfile.dip->di_flags;
548 switch (mode & IFMT) {
551 fprintf(stderr, "%s: unknown file mode 0%o\n", name, mode);
556 vprintf(stdout, "skipped socket %s\n", name);
562 ep = lookupname(name);
563 if (ep == NULL || ep->e_flags & EXTRACT)
564 panic("unextracted directory %s\n", name);
568 vprintf(stdout, "extract file %s\n", name);
569 return (genliteraldir(name, curfile.ino));
574 getfile(xtrlnkfile, xtrlnkskip);
577 "%s: zero length symbolic link (ignored)\n", name);
580 return (linkit(lnkbuf, name, SYMLINK));
583 vprintf(stdout, "extract fifo %s\n", name);
590 if (mkfifo(name, mode) < 0) {
591 fprintf(stderr, "%s: cannot create fifo: %s\n",
592 name, strerror(errno));
596 (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
597 (void) chmod(name, mode);
599 (void) chflags(name, flags);
605 vprintf(stdout, "extract special file %s\n", name);
612 if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) {
613 fprintf(stderr, "%s: cannot create special file: %s\n",
614 name, strerror(errno));
618 (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
619 (void) chmod(name, mode);
621 (void) chflags(name, flags);
626 vprintf(stdout, "extract file %s\n", name);
633 if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
635 fprintf(stderr, "%s: cannot create file: %s\n",
636 name, strerror(errno));
640 (void) fchown(ofile, curfile.dip->di_uid, curfile.dip->di_gid);
641 (void) fchmod(ofile, mode);
642 getfile(xtrfile, xtrskip);
645 (void) chflags(name, flags);
652 * skip over bit maps on the tape
658 while (spcl.c_type == TS_BITS || spcl.c_type == TS_CLRI)
663 * skip over a file on the tape
669 curfile.action = SKIP;
670 getfile(xtrnull, xtrnull);
674 * Extract a file from the tape.
675 * When an allocated block is found it is passed to the fill function;
676 * when an unallocated block (hole) is found, a zeroed buffer is passed
677 * to the skip function.
681 void (*fill) __P((char *, long));
682 void (*skip) __P((char *, long));
686 quad_t size = spcl.c_dinode.di_size;
687 static char clearedbuf[MAXBSIZE];
688 char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE];
691 if (spcl.c_type == TS_END)
692 panic("ran off end of tape\n");
693 if (spcl.c_magic != NFS_MAGIC)
694 panic("not at beginning of a file\n");
695 if (!gettingfile && setjmp(restart) != 0)
699 for (i = 0; i < spcl.c_count; i++) {
700 if (readmapflag || spcl.c_addr[i]) {
701 readtape(&buf[curblk++][0]);
702 if (curblk == fssize / TP_BSIZE) {
703 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
704 fssize : (curblk - 1) * TP_BSIZE + size));
709 (*fill)((char *)buf, (long)(size > TP_BSIZE ?
711 (curblk - 1) * TP_BSIZE + size));
714 (*skip)(clearedbuf, (long)(size > TP_BSIZE ?
717 if ((size -= TP_BSIZE) <= 0) {
718 for (i++; i < spcl.c_count; i++)
719 if (readmapflag || spcl.c_addr[i])
724 if (gethead(&spcl) == GOOD && size > 0) {
725 if (spcl.c_type == TS_ADDR)
728 "Missing address (header) block for %s at %ld blocks\n",
729 curfile.name, blksread);
732 (*fill)((char *)buf, (long)((curblk * TP_BSIZE) + size));
738 * Write out the next block of a file.
748 if (write(ofile, buf, (int) size) == -1) {
750 "write error extracting inode %d, name %s\nwrite: %s\n",
751 curfile.ino, curfile.name, strerror(errno));
756 * Skip over a hole in a file.
765 if (lseek(ofile, size, SEEK_CUR) == -1) {
767 "seek error extracting inode %d, name %s\nlseek: %s\n",
768 curfile.ino, curfile.name, strerror(errno));
774 * Collect the next block of a symbolic link.
777 xtrlnkfile(buf, size)
783 if (pathlen > MAXPATHLEN) {
784 fprintf(stderr, "symbolic link name: %s->%s%s; too long %d\n",
785 curfile.name, lnkbuf, buf, pathlen);
788 (void) strcat(lnkbuf, buf);
792 * Skip over a hole in a symbolic link (should never happen).
796 xtrlnkskip(buf, size)
801 fprintf(stderr, "unallocated block in symbolic link %s\n",
807 * Collect the next block of a bit map.
815 memmove(map, buf, size);
820 * Skip over a hole in a bit map (should never happen).
824 xtrmapskip(buf, size)
829 panic("hole in map\n");
834 * Noop, when an extraction function is not needed.
847 * Read TP_BSIZE blocks from the input.
848 * Handle read errors, and end of media.
855 int cnt, seek_failed;
857 if (blkcnt < numtrec) {
858 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
863 for (i = 0; i < ntrec; i++)
864 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
867 cnt = ntrec * TP_BSIZE;
872 i = rmtread(&tapebuf[rd], cnt);
875 i = read(mt, &tapebuf[rd], cnt);
877 * Check for mid-tape short read error.
878 * If found, skip rest of buffer and start with the next.
880 if (!pipein && numtrec < ntrec && i > 0) {
881 dprintf(stdout, "mid-media short read error.\n");
885 * Handle partial block read.
887 if (pipein && i == 0 && rd > 0)
889 else if (i > 0 && i != ntrec * TP_BSIZE) {
898 * Short read. Process the blocks read.
900 if (i % TP_BSIZE != 0)
902 "partial block read: %ld should be %ld\n",
903 i, ntrec * TP_BSIZE);
904 numtrec = i / TP_BSIZE;
911 fprintf(stderr, "Tape read error while ");
912 switch (curfile.action) {
914 fprintf(stderr, "trying to set up tape\n");
917 fprintf(stderr, "trying to resynchronize\n");
920 fprintf(stderr, "restoring %s\n", curfile.name);
923 fprintf(stderr, "skipping over inode %d\n",
927 if (!yflag && !reply("continue"))
929 i = ntrec * TP_BSIZE;
930 memset(tapebuf, 0, i);
933 seek_failed = (rmtseek(i, 1) < 0);
936 seek_failed = (lseek(mt, i, SEEK_CUR) == (off_t)-1);
940 "continuation failed: %s\n", strerror(errno));
945 * Handle end of tape.
948 vprintf(stdout, "End-of-tape encountered\n");
957 if (rd % TP_BSIZE != 0)
958 panic("partial block read: %d should be %d\n",
959 rd, ntrec * TP_BSIZE);
961 memmove(&tapebuf[rd], &endoftapemark, (long)TP_BSIZE);
964 memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
974 for (i = 0; i < ntrec; i++)
975 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
979 i = rmtread(tapebuf, ntrec * TP_BSIZE);
982 i = read(mt, tapebuf, ntrec * TP_BSIZE);
985 fprintf(stderr, "tape read error: %s\n", strerror(errno));
988 if (i % TP_BSIZE != 0) {
989 fprintf(stderr, "Tape block size (%ld) %s (%d)\n",
990 i, "is not a multiple of dump block size", TP_BSIZE);
993 ntrec = i / TP_BSIZE;
995 vprintf(stdout, "Tape block size is %ld\n", ntrec);
1013 * Read the next block from the tape.
1014 * Check to see if it is one of several vintage headers.
1015 * If it is an old style header, convert it to a new style header.
1016 * If it is not any valid header, return an error.
1028 char dummy[TP_BSIZE];
1039 unsigned short odi_mode;
1056 readtape((char *)buf);
1057 if (buf->c_magic != NFS_MAGIC) {
1058 if (swabl(buf->c_magic) != NFS_MAGIC)
1061 vprintf(stdout, "Note: Doing Byte swapping\n");
1065 if (checksum((int *)buf) == FAIL)
1068 swabst((u_char *)"8l4s31l", (u_char *)buf);
1069 swabst((u_char *)"l",(u_char *) &buf->c_level);
1070 swabst((u_char *)"2l",(u_char *) &buf->c_flags);
1074 readtape((char *)(&u_ospcl.s_ospcl));
1075 memset(buf, 0, (long)TP_BSIZE);
1076 buf->c_type = u_ospcl.s_ospcl.c_type;
1077 buf->c_date = u_ospcl.s_ospcl.c_date;
1078 buf->c_ddate = u_ospcl.s_ospcl.c_ddate;
1079 buf->c_volume = u_ospcl.s_ospcl.c_volume;
1080 buf->c_tapea = u_ospcl.s_ospcl.c_tapea;
1081 buf->c_inumber = u_ospcl.s_ospcl.c_inumber;
1082 buf->c_checksum = u_ospcl.s_ospcl.c_checksum;
1083 buf->c_magic = u_ospcl.s_ospcl.c_magic;
1084 buf->c_dinode.di_mode = u_ospcl.s_ospcl.c_dinode.odi_mode;
1085 buf->c_dinode.di_nlink = u_ospcl.s_ospcl.c_dinode.odi_nlink;
1086 buf->c_dinode.di_uid = u_ospcl.s_ospcl.c_dinode.odi_uid;
1087 buf->c_dinode.di_gid = u_ospcl.s_ospcl.c_dinode.odi_gid;
1088 buf->c_dinode.di_size = u_ospcl.s_ospcl.c_dinode.odi_size;
1089 buf->c_dinode.di_rdev = u_ospcl.s_ospcl.c_dinode.odi_rdev;
1090 buf->c_dinode.di_atime = u_ospcl.s_ospcl.c_dinode.odi_atime;
1091 buf->c_dinode.di_mtime = u_ospcl.s_ospcl.c_dinode.odi_mtime;
1092 buf->c_dinode.di_ctime = u_ospcl.s_ospcl.c_dinode.odi_ctime;
1093 buf->c_count = u_ospcl.s_ospcl.c_count;
1094 memmove(buf->c_addr, u_ospcl.s_ospcl.c_addr, (long)256);
1095 if (u_ospcl.s_ospcl.c_magic != OFS_MAGIC ||
1096 checksum((int *)(&u_ospcl.s_ospcl)) == FAIL)
1098 buf->c_magic = NFS_MAGIC;
1101 if ((buf->c_dinode.di_size == 0 || buf->c_dinode.di_size > 0xfffffff) &&
1102 (buf->c_dinode.di_mode & IFMT) == IFDIR && Qcvt == 0) {
1103 qcvt.qval = buf->c_dinode.di_size;
1104 if (qcvt.val[0] || qcvt.val[1]) {
1105 printf("Note: Doing Quad swapping\n");
1110 qcvt.qval = buf->c_dinode.di_size;
1112 qcvt.val[1] = qcvt.val[0];
1114 buf->c_dinode.di_size = qcvt.qval;
1118 switch (buf->c_type) {
1123 * Have to patch up missing information in bit map headers
1126 buf->c_dinode.di_size = buf->c_count * TP_BSIZE;
1127 if (buf->c_count > TP_NINDIR)
1130 for (i = 0; i < buf->c_count; i++)
1135 if ((buf->c_flags & DR_NEWINODEFMT) == 0)
1147 panic("gethead: unknown inode type %d\n", buf->c_type);
1151 * If we are restoring a filesystem with old format inodes,
1152 * copy the uid/gid to the new location.
1155 buf->c_dinode.di_uid = buf->c_dinode.di_ouid;
1156 buf->c_dinode.di_gid = buf->c_dinode.di_ogid;
1158 tapeaddr = buf->c_tapea;
1165 * Check that a header is where it belongs and predict the next header
1169 struct s_spcl *header;
1171 static ino_t previno = 0x7fffffff;
1172 static int prevtype;
1173 static long predict;
1176 if (header->c_type == TS_TAPE) {
1177 fprintf(stderr, "Volume header (%s inode format) ",
1178 oldinofmt ? "old" : "new");
1179 if (header->c_firstrec)
1180 fprintf(stderr, "begins with record %ld",
1181 header->c_firstrec);
1182 fprintf(stderr, "\n");
1183 previno = 0x7fffffff;
1186 if (previno == 0x7fffffff)
1190 fprintf(stderr, "Dumped inodes map header");
1193 fprintf(stderr, "Used inodes map header");
1196 fprintf(stderr, "File header, ino %d", previno);
1199 fprintf(stderr, "File continuation header, ino %d", previno);
1202 fprintf(stderr, "End of tape header");
1205 if (predict != blksread - 1)
1206 fprintf(stderr, "; predicted %ld blocks, got %ld blocks",
1207 predict, blksread - 1);
1208 fprintf(stderr, "\n");
1211 if (header->c_type != TS_END)
1212 for (i = 0; i < header->c_count; i++)
1213 if (readmapflag || header->c_addr[i] != 0)
1217 prevtype = header->c_type;
1218 previno = header->c_inumber;
1222 * Find an inode header.
1223 * Complain if had to skip.
1227 struct s_spcl *header;
1229 static long skipcnt = 0;
1234 curfile.name = "<name unknown>";
1235 curfile.action = UNKNOWN;
1239 if (header->c_magic != NFS_MAGIC) {
1241 while (gethead(header) == FAIL ||
1242 _time32_to_time(header->c_date) != dumpdate)
1245 htype = header->c_type;
1250 * Skip up to the beginning of the next record
1252 for (i = 0; i < header->c_count; i++)
1253 if (header->c_addr[i])
1255 while (gethead(header) == FAIL ||
1256 _time32_to_time(header->c_date) != dumpdate)
1261 curfile.dip = &header->c_dinode;
1262 curfile.ino = header->c_inumber;
1266 /* If we missed some tapes, get another volume. */
1267 if (tapesread & (tapesread + 1)) {
1271 curfile.ino = maxino;
1275 curfile.name = "<file removal list>";
1279 curfile.name = "<file dump list>";
1283 panic("unexpected tape header\n");
1287 panic("unknown tape header type %d\n", spcl.c_type);
1291 } while (htype == TS_ADDR);
1293 fprintf(stderr, "resync restore, skipped %ld blocks\n",
1304 j = sizeof(union u_spcl) / sizeof(int);
1311 /* What happens if we want to read restore tapes
1312 for a 16bit int machine??? */
1318 if (i != CHECKSUM) {
1319 fprintf(stderr, "Checksum error %o, inode %d file %s\n", i,
1320 curfile.ino, curfile.name);
1330 #include <varargs.h>
1335 msg(const char *fmt, ...)
1348 (void)vfprintf(stderr, fmt, ap);
1351 #endif /* RRESTORE */
1361 c = sp[0]; sp[0] = sp[1]; sp[1] = c;
1375 c = sp[0]; sp[0] = sp[3]; sp[3] = c;
1376 c = sp[2]; sp[2] = sp[1]; sp[1] = c;
1390 case '0': case '1': case '2': case '3': case '4':
1391 case '5': case '6': case '7': case '8': case '9':
1392 n = (n * 10) + (*cp++ - '0');
1395 case 's': case 'w': case 'h':
1398 sp = swabshort(sp, n);
1404 sp = swablong(sp, n);
1407 default: /* Any other character, like 'b' counts as byte. */
1422 swabst((u_char *)"l", (u_char *)&x);