2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <card@Linux.EU.Org>, 1994-1997
5 * Stelian Pop <stelian@popies.net>, 1999-2000
6 * Stelian Pop <stelian@popies.net> - AlcĂ´ve <www.alcove.com>, 2000-2002
10 * Copyright (c) 1983, 1993
11 * The Regents of the University of California. All rights reserved.
12 * (c) UNIX System Laboratories, Inc.
13 * All or some portions of this file are derived from material licensed
14 * to the University of California by American Telephone and Telegraph
15 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
16 * the permission of UNIX System Laboratories, Inc.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 3. Neither the name of the University nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 static const char rcsid[] =
45 "$Id: tape.c,v 1.81 2004/05/25 10:39:31 stelian Exp $";
49 #include <compatlfs.h>
50 #include <sys/types.h>
52 #include <compaterr.h>
60 #include <sys/param.h>
68 #ifdef HAVE_EXT2FS_EXT2_FS_H
69 #include <ext2fs/ext2_fs.h>
71 #include <linux/ext2_fs.h>
73 #include <ext2fs/ext2fs.h>
74 #include <bsdcompat.h>
77 #define quad_t int64_t
79 #include <sys/fcntl.h>
80 #include <bsdcompat.h>
82 #include <ufs/ufs/dinode.h>
84 #endif /* __linux__ */
88 #include <protocols/dumprestore.h>
92 #endif /* HAVE_ZLIB */
96 #endif /* HAVE_BZLIB */
100 #endif /* HAVE_LZO */
104 #include "pathnames.h"
107 int noresyncmesg = 0;
109 static long fssize = MAXBSIZE;
112 static int magtapein = 0; /* input is from magtape */
113 static char magtape[MAXPATHLEN];
114 static char magtapeprefix[MAXPATHLEN];
117 static char *tapebuf; /* input buffer for read */
118 static int bufsize; /* buffer size without prefix */
119 static char *tbufptr = NULL; /* active tape buffer */
120 #if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO)
121 static char *comprbuf; /* uncompress work buf */
122 static size_t comprlen; /* size including prefix */
124 static union u_spcl endoftapemark;
125 static long blksread; /* blocks read since last header */
126 static long tpblksread = 0; /* TP_BSIZE blocks read */
127 static long tapesread;
128 static sigjmp_buf restart;
129 static int gettingfile = 0; /* restart has a valid frame */
134 static char lnkbuf[MAXPATHLEN + 1];
137 int oldinofmt; /* old inode format conversion required */
138 int Bcvt; /* Swap Bytes (for CCI or sun) */
139 static int Qcvt; /* Swap quads (for sun) */
141 #define FLUSHTAPEBUF() blkcnt = ntrec + 1
143 static void accthdr __P((struct s_spcl *));
144 static int checksum __P((int *));
145 static void findinode __P((struct s_spcl *));
146 static void findtapeblksize __P((void));
147 static int gethead __P((struct s_spcl *));
148 static int converthead __P((struct s_spcl *));
149 static void converttapebuf __P((struct tapebuf *));
150 static void readtape __P((char *));
151 static void setdumpnum __P((void));
153 static void xtrfilefinderinfo __P((char *, size_t));
156 static u_int swabi __P((u_int));
158 static u_long swabl __P((u_long));
160 static u_char *swab64 __P((u_char *, int));
161 static u_char *swab32 __P((u_char *, int));
162 static u_char *swab16 __P((u_char *, int));
163 static void terminateinput __P((void));
164 static void xtrfile __P((char *, size_t));
165 static void xtrlnkfile __P((char *, size_t));
166 static void xtrlnkskip __P((char *, size_t));
167 static void xtrmap __P((char *, size_t));
168 static void xtrmapskip __P((char *, size_t));
169 static void xtrskip __P((char *, size_t));
170 static void setmagtapein __P((void));
172 #if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO)
173 static void newcomprbuf __P((int));
174 static void (*readtape_func) __P((char *));
175 static void readtape_set __P((char *));
176 static void readtape_uncompr __P((char *));
177 static void readtape_comprfile __P((char *));
178 static void readtape_comprtape __P((char *));
179 static char *decompress_tapebuf __P((struct tapebuf *, int));
180 static void msg_read_error __P((char *));
182 static int read_a_block __P((int, char *, size_t, long *));
183 #define PREFIXSIZE sizeof(struct tapebuf)
185 #define COMPARE_ONTHEFLY 1
188 static int ifile; /* input file for compare */
189 static int cmperror; /* compare error */
190 static void xtrcmpfile __P((char *, size_t));
191 static void xtrcmpskip __P((char *, size_t));
194 static int readmapflag;
195 static int readingmaps; /* set to 1 while reading the maps */
198 static DumpFinderInfo gFndrInfo;
202 * Set up an input source. This is called from main.c before setup() is.
205 setinput(char *source)
214 newtapebuf(NTREC > HIGHDENSITYTREC ? NTREC : HIGHDENSITYTREC);
218 if ((n = strchr(source, ':'))) {
219 for (i = 0; i < (n - source); i++) {
220 if (source[i] == '/')
223 if (source[i] != '/') {
225 source = strchr(host, ':');
227 if (rmthost(host) == 0)
232 if (strcmp(source, "-") == 0) {
234 * Since input is coming from a pipe we must establish
235 * our own connection to the terminal.
237 terminal = fopen(_PATH_TTY, "r");
238 if (terminal == NULL) {
239 warn("cannot open %s", _PATH_TTY);
240 terminal = fopen(_PATH_DEVNULL, "r");
241 if (terminal == NULL)
242 err(1, "cannot open %s", _PATH_DEVNULL);
246 setuid(getuid()); /* no longer need or want root privileges */
248 strncpy(magtapeprefix, source, MAXPATHLEN);
249 magtapeprefix[MAXPATHLEN-1] = '\0';
250 snprintf(magtape, MAXPATHLEN, "%s%03d", source, 1);
253 strncpy(magtape, source, MAXPATHLEN);
254 magtape[MAXPATHLEN - 1] = '\0';
258 newtapebuf(long size)
260 static int tapebufsize = -1;
263 bufsize = ntrec * TP_BSIZE;
264 if (size <= tapebufsize)
268 tapebuf = malloc(size * TP_BSIZE + sizeof(struct tapebuf));
270 errx(1, "Cannot allocate space for tape buffer");
274 #if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO)
276 newcomprbuf(int size)
278 size_t buf_size = (size+1) * TP_BSIZE + sizeof(struct tapebuf);
279 if (buf_size <= comprlen)
282 if (comprbuf != NULL)
284 comprbuf = malloc(comprlen);
285 if (comprbuf == NULL)
286 errx(1, "Cannot allocate space for decompress buffer");
288 #endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */
291 * Verify that the tape drive can be accessed and
292 * that it actually is a dump tape.
297 int i, j, *ip, bot_code;
301 Vprintf(stdout, "Verify tape and initialize maps\n");
302 if (Afile == NULL && bot_script) {
303 msg("Launching %s\n", bot_script);
304 bot_code = system_command(bot_script, magtape, 1);
305 if (bot_code != 0 && bot_code != 1) {
306 msg("Restore aborted by the beginning of tape script\n");
318 mt = rmtopen(temptape, O_RDONLY);
324 mt = OPEN(temptape, O_RDONLY, 0);
326 err(1, "%s", temptape);
332 #if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO)
333 readtape_func = readtape_set;
334 #if defined(HAVE_LZO)
335 if (lzo_init() != LZO_E_OK) {
336 msg("internal error - lzo_init failed \n");
343 if (gethead(&spcl) == FAIL) {
344 blkcnt--; /* push back this block */
348 if (gethead(&spcl) == FAIL)
349 errx(1, "Tape is not a dump tape");
350 fprintf(stderr, "Converting to new file system format.\n");
354 fprintf(stderr, "Dump tape is compressed.\n");
355 #if !defined(HAVE_ZLIB) && !defined(HAVE_BZLIB) && !defined(HAVE_LZO)
356 errx(1,"This restore version doesn't support decompression");
357 #endif /* !HAVE_ZLIB && !HAVE_BZLIB */
360 endoftapemark.s_spcl.c_magic = cvtflag ? OFS_MAGIC : NFS_MAGIC;
361 endoftapemark.s_spcl.c_type = TS_END;
362 ip = (int *)&endoftapemark;
363 j = sizeof(union u_spcl) / sizeof(int);
368 endoftapemark.s_spcl.c_checksum = CHECKSUM - i;
370 if (vflag || command == 't' || command == 'C')
373 if (tapeposflag && (unsigned long)spcl.c_date != qfadumpdate)
374 errx(1, "different QFA/dumpdates detected\n");
376 if (filesys[0] == '\0') {
378 strncpy(filesys, spcl.c_filesys, NAMELEN);
379 filesys[NAMELEN - 1] = '\0';
380 dirptr = strstr(filesys, " (dir");
384 dumptime = spcl.c_ddate;
385 dumpdate = spcl.c_date;
386 if (STAT(".", &stbuf) < 0)
387 err(1, "cannot stat .");
388 if (stbuf.st_blksize > 0 && stbuf.st_blksize < TP_BSIZE )
390 if (stbuf.st_blksize >= TP_BSIZE && stbuf.st_blksize <= MAXBSIZE)
391 fssize = stbuf.st_blksize;
392 if (((fssize - 1) & fssize) != 0)
393 errx(1, "bad block size %ld", fssize);
394 if (spcl.c_volume != 1)
395 errx(1, "Tape is not volume 1 of the dump");
396 if (gethead(&spcl) == FAIL) {
397 Dprintf(stdout, "header read failed at %ld blocks\n", (long)blksread);
398 panic("no header after volume mark!\n");
402 if (spcl.c_type != TS_CLRI)
403 errx(1, "Cannot find file removal list");
404 maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1;
405 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
407 errx(1, "no memory for active inode map");
409 curfile.action = USING;
410 getfile(xtrmap, xtrmapskip);
411 while (spcl.c_type == TS_ADDR) {
412 /* Recompute maxino and the map */
413 dump_ino_t oldmaxino = maxino;
414 maxino += (spcl.c_count * TP_BSIZE * NBBY) + 1;
415 resizemaps(oldmaxino, maxino);
418 spcl.c_dinode.di_size = spcl.c_count * TP_BSIZE;
419 getfile(xtrmap, xtrmapskip);
421 Dprintf(stdout, "maxino = %lu\n", (unsigned long)maxino);
422 if (spcl.c_type != TS_BITS) {
423 if (spcl.c_type == TS_END) {
424 msg("Cannot find file dump list, assuming empty tape\n");
427 errx(1, "Cannot find file dump list");
429 map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
430 if (map == (char *)NULL)
431 errx(1, "no memory for file dump list");
433 curfile.action = USING;
434 getfile(xtrmap, xtrmapskip);
435 while (spcl.c_type == TS_ADDR) {
436 spcl.c_dinode.di_size = spcl.c_count * TP_BSIZE;
437 getfile(xtrmap, xtrmapskip);
440 * If there may be whiteout entries on the tape, pretend that the
441 * whiteout inode exists, so that the whiteout entries can be
445 SETINO(WINO, dumpmap);
451 * Prompt user to load a new dump volume.
452 * "Nextvol" is the next suggested volume to use.
453 * This suggested volume is enforced when doing full
454 * or incremental restores, but can be overridden by
455 * the user when only extracting a subset of the files.
460 long newvol = 0, wantnext = 0, i;
461 long saved_blksread = 0, saved_tpblksread = 0;
462 union u_spcl tmpspcl;
463 # define tmpbuf tmpspcl.s_spcl
465 int haderror = 0, bot_code = 1;
475 panic("Changing volumes on pipe input?\n");
480 saved_blksread = blksread;
481 saved_tpblksread = tpblksread;
482 #if defined(USE_QFA) && defined(sunos)
483 if (createtapeposflag || tapeposflag)
488 exit(1); /* pipes do not get a second chance */
489 if (aflag || curfile.action != SKIP) {
496 while (newvol <= 0) {
497 if (tapesread == 0) {
498 fprintf(stderr, "%s%s%s%s%s",
499 "You have not read any volumes yet.\n",
500 "Unless you know which volume your",
501 " file(s) are on you should start\n",
502 "with the last volume and work",
503 " towards the first.\n");
505 fprintf(stderr, "You have read volumes");
507 for (i = 1; i < 32; i++)
508 if (tapesread & (1 << i)) {
509 fprintf(stderr, "%s%ld", buf, (long)i);
512 fprintf(stderr, "\n");
515 fprintf(stderr, "Specify next volume # (none if no more volumes): ");
516 (void) fflush(stderr);
517 (void) fgets(buf, TP_BSIZE, terminal);
518 } while (!feof(terminal) && buf[0] == '\n');
521 if (!strcmp(buf, "none\n")) {
528 "Volume numbers are positive numerics\n");
531 if (newvol == volno) {
532 tapesread |= 1 << volno;
533 #if defined(USE_QFA) && defined(sunos)
534 if (createtapeposflag || tapeposflag) {
535 if (OpenSMTCmt(magtape) < 0) {
547 * if using an archive file, reset its name so readtape()
548 * could properly use remote access.
553 snprintf(magtape, MAXPATHLEN, "%s%03ld", magtapeprefix, newvol);
554 magtape[MAXPATHLEN - 1] = '\0';
556 if (bot_script && !haderror) {
557 msg("Launching %s\n", bot_script);
558 bot_code = system_command(bot_script, magtape, newvol);
559 if (bot_code != 0 && bot_code != 1) {
560 msg("Restore aborted by the beginning of tape script\n");
564 if (haderror || (bot_code && !Mflag)) {
567 fprintf(stderr, "Mount volume %ld\n", (long)newvol);
569 fprintf(stderr, "Mount tape volume %ld\n", (long)newvol);
571 fprintf(stderr, "Enter ``none'' if there are no more tapes\n");
573 fprintf(stderr, "then enter volume name (default: %s) ", magtape);
575 fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape);
577 (void) fflush(stderr);
578 (void) fgets(buf, TP_BSIZE, terminal);
581 if (!strcmp(buf, "none\n")) {
585 if (buf[0] != '\n') {
587 (void) strncpy(magtape, buf, sizeof(magtape));
588 magtape[sizeof(magtape) - 1] = '\0';
589 if ((pos = strchr(magtape, '\n')))
590 magtape[pos - magtape] = '\0';
593 #if defined(USE_QFA) && defined(sunos)
594 if (createtapeposflag || tapeposflag) {
595 if (OpenSMTCmt(magtape) < 0) {
604 mt = rmtopen(magtape, O_RDONLY);
607 mt = OPEN(magtape, O_RDONLY, 0);
610 fprintf(stderr, "Cannot open %s\n", magtape);
617 #if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO)
618 readtape_func = readtape_set;
624 if (gethead(&tmpbuf) == FAIL) {
625 Dprintf(stdout, "header read failed at %ld blocks\n", (long)blksread);
626 fprintf(stderr, "tape is not dump tape\n");
629 blksread = saved_blksread;
630 tpblksread = saved_tpblksread;
633 if (tmpbuf.c_volume != volno) {
634 fprintf(stderr, "Wrong volume (%d)\n", tmpbuf.c_volume);
637 blksread = saved_blksread;
638 tpblksread = saved_tpblksread;
641 if (tmpbuf.c_date != dumpdate || tmpbuf.c_ddate != dumptime) {
642 fprintf(stderr, "Wrong dump date\n\tgot: %s",
644 ctime(&tmpbuf.c_date));
646 ctime4(&tmpbuf.c_date));
648 fprintf(stderr, "\twanted: %s", ctime(&dumpdate));
651 blksread = saved_blksread;
652 tpblksread = saved_tpblksread;
655 tapesread |= 1 << volno;
657 * If continuing from the previous volume, skip over any
658 * blocks read already at the end of the previous volume.
660 * If coming to this volume at random, skip to the beginning
661 * of the next record.
664 fprintf(stderr, "Dump tape is compressed.\n");
665 #if !defined(HAVE_ZLIB) && !defined(HAVE_BZLIB) && !defined(HAVE_LZO)
666 errx(1,"This restore version doesn't support decompression");
667 #endif /* !HAVE_ZLIB && !HAVE_BZLIB */
669 Dprintf(stdout, "read %ld recs, tape starts with %ld\n",
670 tpblksread - 1, (long)tmpbuf.c_firstrec);
671 if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) {
673 tpblksread = tmpbuf.c_firstrec + 1;
674 for (i = tmpbuf.c_count; i > 0; i--)
676 } else if (tmpbuf.c_firstrec > 0 &&
677 tmpbuf.c_firstrec < tpblksread - 1) {
679 * -1 since we've read the volume header
681 i = tpblksread - tmpbuf.c_firstrec - 1;
682 Dprintf(stderr, "Skipping %ld duplicate record%s.\n",
683 (long)i, i > 1 ? "s" : "");
688 if (curfile.action == USING) {
690 panic("active file into volume 1\n");
694 * Skip up to the beginning of the next record
696 if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER))
697 for (i = tmpbuf.c_count; i > 0; i--)
699 (void) gethead(&spcl);
703 siglongjmp(restart, 1);
708 * Handle unexpected EOF.
714 if (gettingfile && curfile.action == USING) {
715 printf("Warning: %s %s\n",
716 "End-of-input encountered while extracting", curfile.name);
718 curfile.name = "<name unknown>";
719 curfile.action = UNKNOWN;
721 curfile.ino = maxino;
724 siglongjmp(restart, 1);
729 * handle multiple dumps per tape by skipping forward to the
737 if (dumpnum == 1 || volno != 1)
740 errx(1, "Cannot have multiple dumps on pipe input");
742 tcom.mt_count = dumpnum - 1;
745 if (rmtioctl(MTFSF, dumpnum - 1) < 0) {
746 fprintf(stderr, "rmtioctl MTFSF: %s\n", strerror(errno));
751 if (ioctl(mt, (int)MTIOCTOP, (char *)&tcom) < 0) {
752 fprintf(stderr, "rmtioctl MTFSF: %s\n", strerror(errno));
754 /* warn("ioctl MTFSF"); */
762 Vprintf(stdout, "Dump date: %s", ctime(&spcl.c_date));
763 Vprintf(stdout, "Dumped from: %s",
764 (spcl.c_ddate == 0) ? "the epoch\n" : ctime(&spcl.c_ddate));
765 if (spcl.c_host[0] == '\0')
767 Vprintf(stdout, "Level %d dump of %s on %s:%s\n",
768 spcl.c_level, spcl.c_filesys, spcl.c_host, spcl.c_dev);
769 Vprintf(stdout, "Label: %s\n", spcl.c_label);
771 fprintf(stdout, "Dump date: %s", ctime4(&spcl.c_date));
772 fprintf(stdout, "Dumped from: %s",
773 (spcl.c_ddate == 0) ? "the epoch\n" : ctime4(&spcl.c_ddate));
774 if (spcl.c_host[0] == '\0')
776 fprintf(stdout, "Level %d dump of %s on %s:%s\n",
777 spcl.c_level, spcl.c_filesys, spcl.c_host, spcl.c_dev);
778 fprintf(stdout, "Label: %s\n", spcl.c_label);
787 if (volinfo[1] == ROOTINO) {
788 printf("Starting inode numbers by volume:\n");
789 for (i = 1; i < (int)TP_NINOS && volinfo[i] != 0; ++i)
790 printf("\tVolume %d: %lu\n", i, (unsigned long)volinfo[i]);
796 extractfile(struct entry *ep, int doremove)
800 struct timeval timep[2];
801 char *name = myname(ep);
803 /* If removal is requested (-r mode) do remove it unless
804 * we are extracting a metadata only inode */
805 if (spcl.c_flags & DR_METAONLY) {
806 Vprintf(stdout, "file %s is metadata only\n", name);
811 ep->e_flags &= ~REMOVED;
816 curfile.action = USING;
817 #if defined(__linux__) || defined(sunos)
818 timep[0].tv_sec = curfile.dip->di_atime.tv_sec;
819 timep[0].tv_usec = curfile.dip->di_atime.tv_usec;
820 timep[1].tv_sec = curfile.dip->di_mtime.tv_sec;
821 timep[1].tv_usec = curfile.dip->di_mtime.tv_usec;
822 #else /* __linux__ || sunos */
823 timep[0].tv_sec = curfile.dip->di_atime;
824 timep[0].tv_usec = curfile.dip->di_atimensec / 1000;
825 timep[1].tv_sec = curfile.dip->di_mtime;
826 timep[1].tv_usec = curfile.dip->di_mtimensec / 1000;
827 #endif /* __linux__ */
828 mode = curfile.dip->di_mode;
829 flags = curfile.dip->di_flags;
830 switch (mode & IFMT) {
833 fprintf(stderr, "%s: unknown file mode 0%o\n", name, mode);
838 Vprintf(stdout, "skipped socket %s\n", name);
844 if (ep == NULL || ep->e_flags & EXTRACT)
845 panic("unextracted directory %s\n", name);
849 Vprintf(stdout, "extract file %s\n", name);
850 return (genliteraldir(name, curfile.ino));
855 uid_t luid = curfile.dip->di_uid;
856 gid_t lgid = curfile.dip->di_gid;
858 if (! (spcl.c_flags & DR_METAONLY)) {
861 getfile(xtrlnkfile, xtrlnkskip);
864 "%s: zero length symbolic link (ignored)\n", name);
867 if (linkit(lnkbuf, name, SYMLINK) == FAIL)
874 (void) lchown(name, luid, lgid);
880 Vprintf(stdout, "extract fifo %s\n", name);
885 if (! (spcl.c_flags & DR_METAONLY)) {
888 if (mkfifo(name, mode) < 0) {
889 warn("%s: cannot create fifo", name);
894 (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
895 (void) chmod(name, mode);
898 (void) fsetflags(name, flags);
902 warn("%s: cannot call chflags", name);
903 /* (void) chflags(name, flags); */
906 (void) chflags(name, flags);
915 Vprintf(stdout, "extract special file %s\n", name);
920 if (! (spcl.c_flags & DR_METAONLY)) {
923 if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) {
924 warn("%s: cannot create special file", name);
929 (void) chown(name, curfile.dip->di_uid, curfile.dip->di_gid);
930 (void) chmod(name, mode);
934 warn("%s: fsetflags called on a special file", name);
935 (void) fsetflags(name, flags);
940 warn("%s: cannot call chflags on a special file", name);
941 /* (void) chflags(name, flags); */
945 warn("%s: chflags called on a special file", name);
946 (void) chflags(name, flags);
956 uid_t luid = curfile.dip->di_uid;
957 gid_t lgid = curfile.dip->di_gid;
959 Vprintf(stdout, "extract file %s\n", name);
964 if (! (spcl.c_flags & DR_METAONLY)) {
967 if ((ofile = OPEN(name, O_WRONLY | O_CREAT | O_TRUNC,
969 warn("%s: cannot create file", name);
973 getfile(xtrfile, xtrskip);
978 (void) chown(name, luid, lgid);
979 (void) chmod(name, mode);
982 (void) fsetflags(name, flags);
986 warn("%s: cannot call chflags", name);
987 /* (void) chflags(name, flags); */
990 (void) chflags(name, flags);
1002 extractfinderinfoufs(char *name)
1005 char oFileRsrc[MAXPATHLEN];
1008 struct timeval timep[2];
1011 char path[MAXPATHLEN], fname[MAXPATHLEN];
1014 curfile.name = name;
1015 curfile.action = USING;
1016 timep[0].tv_sec = curfile.dip->di_atime.tv_sec;
1017 timep[0].tv_usec = curfile.dip->di_atime.tv_usec;
1018 timep[1].tv_sec = curfile.dip->di_mtime.tv_sec;
1019 timep[1].tv_usec = curfile.dip->di_mtime.tv_usec;
1020 mode = curfile.dip->di_mode;
1021 flags = curfile.dip->di_flags;
1022 uid = curfile.dip->di_uid;
1023 gid = curfile.dip->di_gid;
1025 switch (mode & IFMT) {
1028 fprintf(stderr, "%s: (extr. finfoufs) unknown file mode 0%o\n", name, mode);
1033 fprintf(stderr, "%s: (extr. finfoufs[IFDIR]) unknown file mode 0%o\n", name, mode);
1042 Vprintf(stdout, "extract finderinfo file %s\n", name);
1047 getfile(xtrfilefinderinfo, xtrskip);
1049 GetPathFile(name, path, fname);
1050 strcpy(oFileRsrc, path);
1051 strcat(oFileRsrc, "._");
1052 strcat(oFileRsrc, fname);
1054 if ((err = CreateAppleDoubleFileRes(oFileRsrc, &gFndrInfo.fndrinfo,
1055 mode, flags, timep, uid, gid)) != 0) {
1056 fprintf(stderr, "%s: cannot create finderinfo: %s\n",
1057 name, strerror(errno));
1068 extractresourceufs(char *name)
1070 char oFileRsrc[MAXPATHLEN];
1073 struct timeval timep[2];
1074 char path[MAXPATHLEN], fname[MAXPATHLEN];
1084 curfile.name = name;
1085 curfile.action = USING;
1086 timep[0].tv_sec = curfile.dip->di_atime.tv_sec;
1087 timep[0].tv_usec = curfile.dip->di_atime.tv_usec;
1088 timep[1].tv_sec = curfile.dip->di_mtime.tv_sec;
1089 timep[1].tv_usec = curfile.dip->di_mtime.tv_usec;
1090 mode = curfile.dip->di_mode;
1091 flags = curfile.dip->di_flags;
1092 uid = curfile.dip->di_uid;
1093 gid = curfile.dip->di_gid;
1094 di_size = curfile.dip->di_size;
1096 switch (mode & IFMT) {
1099 fprintf(stderr, "%s: (extr. resufs) unknown file mode 0%o\n", name, mode);
1104 fprintf(stderr, "%s: (extr. resufs [IFDIR]) unknown file mode 0%o\n", name, mode);
1113 Vprintf(stdout, "extract resource file %s\n", name);
1119 GetPathFile(name, path, fname);
1120 strcpy(oFileRsrc, path);
1121 strcat(oFileRsrc, "._");
1122 strcat(oFileRsrc, fname);
1124 if ((ofile = open(oFileRsrc, O_RDONLY, 0)) < 0) {
1125 fprintf(stderr, "%s: cannot read finderinfo: %s\n",
1126 name, strerror(errno));
1130 read(ofile, buf, 70);
1131 (void) close(ofile);
1133 hp = (ASDHeaderPtr)p;
1136 p += sizeof(ASDHeader) - CORRECT;
1137 ep = (ASDEntryPtr)p;
1138 /* the finderinfo entry */
1139 ep->offset += sizeof(ASDEntry);
1142 p += sizeof(ASDEntry);
1143 /* the finderinfo data */
1144 bcopy(p, p + sizeof(ASDEntry), INFOLEN);
1145 ep = (ASDEntryPtr)p;
1146 /* the new resourcefork entry */
1147 ep->entryID = EntryRSRCFork;
1148 ep->offset = loff + INFOLEN;
1150 /* write the new appledouble entries to the file */
1151 if ((ofile = open(oFileRsrc, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
1152 fprintf(stderr, "%s: cannot create resource file: %s\n",
1153 name, strerror(errno));
1157 write(ofile, buf, 70 + sizeof(ASDEntry));
1158 /* and add the resource data from tape */
1159 getfile(xtrfile, xtrskip);
1161 (void) fchown(ofile, uid, gid);
1162 (void) fchmod(ofile, mode);
1163 (void) close(ofile);
1164 (void) fsetflags(oFileRsrc, flags);
1165 utimes(oFileRsrc, timep);
1170 #endif /* DUMP_MACOSX */
1173 * skip over bit maps on the tape
1179 while (spcl.c_type == TS_BITS || spcl.c_type == TS_CLRI)
1184 * skip over a file on the tape
1190 curfile.action = SKIP;
1191 getfile(xtrnull, xtrnull);
1195 * Extract a file from the tape.
1196 * When an allocated block is found it is passed to the fill function;
1197 * when an unallocated block (hole) is found, a zeroed buffer is passed
1198 * to the skip function.
1201 getfile(void (*fill) __P((char *, size_t)), void (*skip) __P((char *, size_t)))
1204 volatile int curblk = 0;
1205 volatile quad_t size = spcl.c_dinode.di_size;
1206 volatile int last_write_was_hole = 0;
1207 quad_t origsize = size;
1208 static char clearedbuf[MAXBSIZE];
1209 char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE];
1210 char junk[TP_BSIZE];
1212 if (spcl.c_type == TS_END)
1213 panic("ran off end of tape\n");
1214 if (spcl.c_magic != NFS_MAGIC)
1215 panic("not at beginning of a file\n");
1216 if (!gettingfile && setjmp(restart) != 0)
1220 for (i = 0; i < spcl.c_count; i++) {
1221 if (readmapflag || spcl.c_addr[i]) {
1222 readtape(&buf[curblk++][0]);
1223 if (curblk == fssize / TP_BSIZE) {
1224 (*fill)((char *)buf, (size_t)(size > TP_BSIZE ?
1225 fssize : (curblk - 1) * TP_BSIZE + size));
1227 last_write_was_hole = 0;
1231 (*fill)((char *)buf, (size_t)(size > TP_BSIZE ?
1233 (curblk - 1) * TP_BSIZE + size));
1236 (*skip)(clearedbuf, (long)(size > TP_BSIZE ?
1238 last_write_was_hole = 1;
1240 if ((size -= TP_BSIZE) <= 0) {
1241 for (i++; i < spcl.c_count; i++)
1242 if (readmapflag || spcl.c_addr[i])
1247 if (gethead(&spcl) == GOOD && size > 0) {
1248 if (spcl.c_type == TS_ADDR)
1251 "Missing address (header) block for %s at %ld blocks\n",
1252 curfile.name, (long)blksread);
1255 (*fill)((char *)buf, (size_t)((curblk * TP_BSIZE) + size));
1256 last_write_was_hole = 0;
1259 fprintf(stderr, "Missing blocks at the end of %s, assuming hole\n", curfile.name);
1261 size_t skp = size > TP_BSIZE ? TP_BSIZE : size;
1262 (*skip)(clearedbuf, skp);
1265 last_write_was_hole = 1;
1267 if (last_write_was_hole) {
1268 FTRUNCATE(ofile, origsize);
1276 * Write out the next block of a file.
1279 xtrfile(char *buf, size_t size)
1284 if (write(ofile, buf, (int) size) == -1)
1285 err(1, "write error extracting inode %lu, name %s\nwrite",
1286 (unsigned long)curfile.ino, curfile.name);
1291 xtrfilefinderinfo(char *buf, size_t size)
1295 bcopy(buf, &gFndrInfo, size);
1297 #endif /* DUMP_MACOSX */
1300 * Skip over a hole in a file.
1304 xtrskip(UNUSED(char *buf), size_t size)
1307 if (LSEEK(ofile, (OFF_T)size, SEEK_CUR) == -1)
1308 err(1, "seek error extracting inode %lu, name %s\nlseek",
1309 (unsigned long)curfile.ino, curfile.name);
1313 * Collect the next block of a symbolic link.
1316 xtrlnkfile(char *buf, size_t size)
1320 if (pathlen > MAXPATHLEN)
1321 errx(1, "symbolic link name: %s->%s%s; too long %d",
1322 curfile.name, lnkbuf, buf, pathlen);
1323 (void) strcat(lnkbuf, buf);
1327 * Skip over a hole in a symbolic link (should never happen).
1331 xtrlnkskip(UNUSED(char *buf), UNUSED(size_t size))
1334 errx(1, "unallocated block in symbolic link %s", curfile.name);
1338 * Collect the next block of a bit map.
1341 xtrmap(char *buf, size_t size)
1344 memmove(map, buf, size);
1349 * Skip over a hole in a bit map (should never happen).
1353 xtrmapskip(UNUSED(char *buf), size_t size)
1356 panic("hole in map\n");
1361 * Noop, when an extraction function is not needed.
1365 xtrnull(UNUSED(char *buf), UNUSED(size_t size))
1371 #if COMPARE_ONTHEFLY
1373 * Compare the next block of a file.
1376 xtrcmpfile(char *buf, size_t size)
1378 static char cmpbuf[MAXBSIZE];
1383 if (read(ifile, cmpbuf, size) != (ssize_t)size) {
1384 fprintf(stderr, "%s: size has changed.\n",
1390 if (memcmp(buf, cmpbuf, size) != 0) {
1391 fprintf(stderr, "%s: tape and disk copies are different\n",
1399 * Skip over a hole in a file.
1402 xtrcmpskip(UNUSED(char *buf), size_t size)
1404 static char cmpbuf[MAXBSIZE];
1410 if (read(ifile, cmpbuf, size) != (ssize_t)size) {
1411 fprintf(stderr, "%s: size has changed.\n",
1417 for (i = 0; i < (int)size; ++i)
1418 if (cmpbuf[i] != '\0') {
1419 fprintf(stderr, "%s: tape and disk copies are different\n",
1425 #endif /* COMPARE_ONTHEFLY */
1427 #if !COMPARE_ONTHEFLY
1429 do_cmpfiles(int fd_tape, int fd_disk, long size)
1431 static char buf_tape[BUFSIZ];
1432 static char buf_disk[BUFSIZ];
1437 if ((n_tape = read(fd_tape, buf_tape, sizeof(buf_tape))) < 1) {
1438 close(fd_tape), close(fd_disk);
1439 panic("do_cmpfiles: unexpected EOF[1]");
1441 if ((n_disk = read(fd_disk, buf_disk, sizeof(buf_tape))) < 1) {
1442 close(fd_tape), close(fd_disk);
1443 panic("do_cmpfiles: unexpected EOF[2]");
1445 if (n_tape != n_disk) {
1446 close(fd_tape), close(fd_disk);
1447 panic("do_cmpfiles: sizes different!");
1449 if (memcmp(buf_tape, buf_disk, (size_t)n_tape) != 0) return (1);
1455 /* for debugging compare problems */
1456 #undef COMPARE_FAIL_KEEP_FILE
1459 #ifdef COMPARE_FAIL_KEEP_FILE
1460 /* return true if tapefile should be unlinked after compare */
1465 cmpfiles(char *tapefile, char *diskfile, struct STAT *sbuf_disk)
1467 struct STAT sbuf_tape;
1468 int fd_tape, fd_disk;
1470 if (STAT(tapefile, &sbuf_tape) != 0) {
1471 panic("Can't lstat tmp file %s: %s\n", tapefile,
1476 if (sbuf_disk->st_size != sbuf_tape.st_size) {
1478 "%s: size changed from %ld to %ld.\n",
1479 diskfile, (long)sbuf_tape.st_size, (long)sbuf_disk->st_size);
1481 #ifdef COMPARE_FAIL_KEEP_FILE
1488 if ((fd_tape = OPEN(tapefile, O_RDONLY)) < 0) {
1489 panic("Can't open %s: %s\n", tapefile, strerror(errno));
1492 if ((fd_disk = OPEN(diskfile, O_RDONLY)) < 0) {
1494 panic("Can't open %s: %s\n", diskfile, strerror(errno));
1498 if (do_cmpfiles(fd_tape, fd_disk, sbuf_tape.st_size)) {
1499 fprintf(stderr, "%s: tape and disk copies are different\n",
1504 #ifdef COMPARE_FAIL_KEEP_FILE
1505 /* rename the file to live in /tmp */
1506 /* rename `tapefile' to /tmp/<basename of diskfile> */
1508 char *p = strrchr(diskfile, '/');
1509 char newname[MAXPATHLEN];
1511 panic("can't find / in %s\n", diskfile);
1513 snprintf(newname, sizeof(newname), "%s/debug/%s", tmpdir, p + 1);
1514 if (rename(tapefile, newname)) {
1515 panic("rename from %s to %s failed: %s\n",
1519 fprintf(stderr, "*** %s saved to %s\n",
1524 /* don't unlink the file (it's not there anymore */
1533 #ifdef COMPARE_FAIL_KEEP_FILE
1537 #endif /* !COMPARE_ONTHEFLY */
1539 #if !COMPARE_ONTHEFLY
1540 static char tmpfilename[MAXPATHLEN];
1544 comparefile(char *name)
1549 #if !COMPARE_ONTHEFLY
1550 static char *tmpfile = NULL;
1554 curfile.name = name;
1555 curfile.action = USING;
1556 mode = curfile.dip->di_mode;
1558 if ((mode & IFMT) == IFSOCK) {
1559 Vprintf(stdout, "skipped socket %s\n", name);
1564 if ((r = LSTAT(name, &sb)) != 0) {
1565 warn("%s: does not exist (%d)", name, r);
1571 Vprintf(stdout, "comparing %s (size: %ld, mode: 0%o)\n", name,
1572 (long)sb.st_size, mode);
1574 if (sb.st_mode != mode) {
1575 fprintf(stderr, "%s: mode changed from 0%o to 0%o.\n",
1576 name, mode & 07777, sb.st_mode & 07777);
1579 if (spcl.c_flags & DR_METAONLY) {
1583 switch (mode & IFMT) {
1597 char lbuf[MAXPATHLEN + 1];
1600 if (!(sb.st_mode & S_IFLNK)) {
1601 fprintf(stderr, "%s: is no longer a symbolic link\n",
1608 getfile(xtrlnkfile, xtrlnkskip);
1611 "%s: zero length symbolic link (ignored)\n",
1616 if ((lsize = readlink(name, lbuf, MAXPATHLEN)) < 0) {
1617 panic("readlink of %s failed: %s", name,
1622 if (strcmp(lbuf, lnkbuf) != 0) {
1624 "%s: symbolic link changed from %s to %s.\n",
1625 name, lnkbuf, lbuf);
1634 if (!(sb.st_mode & (S_IFCHR|S_IFBLK))) {
1635 fprintf(stderr, "%s: no longer a special file\n",
1642 if (sb.st_rdev != (dev_t)curfile.dip->di_rdev) {
1644 "%s: device changed from %d,%d to %d,%d.\n",
1646 major(curfile.dip->di_rdev),
1647 minor(curfile.dip->di_rdev),
1656 #if COMPARE_ONTHEFLY
1657 if ((ifile = OPEN(name, O_RDONLY)) < 0) {
1658 panic("Can't open %s: %s\n", name, strerror(errno));
1664 getfile(xtrcmpfile, xtrcmpskip);
1667 if (read(ifile, &c, 1) != 0) {
1668 fprintf(stderr, "%s: size has changed.\n",
1678 if (tmpfile == NULL) {
1679 /* argument to mktemp() must not be in RO space: */
1680 snprintf(tmpfilename, sizeof(tmpfilename), "%s/restoreCXXXXXX", tmpdir);
1681 tmpfile = mktemp(&tmpfilename[0]);
1683 if ((STAT(tmpfile, &stemp) == 0) && (unlink(tmpfile) != 0)) {
1684 panic("cannot delete tmp file %s: %s\n",
1685 tmpfile, strerror(errno));
1687 if ((ofile = OPEN(tmpfile, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0) {
1688 panic("cannot create file temp file %s: %s\n",
1689 name, strerror(errno));
1691 getfile(xtrfile, xtrskip);
1692 (void) close(ofile);
1693 #ifdef COMPARE_FAIL_KEEP_FILE
1694 if (cmpfiles(tmpfile, name, &sb))
1697 cmpfiles(tmpfile, name, &sb);
1700 #endif /* COMPARE_ONTHEFLY */
1706 #if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO)
1707 static void (*readtape_func)(char *) = readtape_set;
1710 * Read TP_BSIZE blocks from the input.
1711 * Handle read errors, and end of media.
1712 * Decompress compressed blocks.
1717 (*readtape_func)(buf); /* call the actual processing routine */
1721 * Set function pointer for readtape() routine. zflag and magtapein must
1722 * be correctly set before the first call to readtape().
1725 readtape_set(char *buf)
1728 readtape_func = readtape_uncompr;
1732 readtape_func = readtape_comprtape;
1734 readtape_func = readtape_comprfile;
1739 #endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */
1742 * This is the original readtape(), it's used for reading uncompressed input.
1743 * Read TP_BSIZE blocks from the input.
1744 * Handle read errors, and end of media.
1747 #if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO)
1748 readtape_uncompr(char *buf)
1753 ssize_t rd, newvol, i;
1754 int cnt, seek_failed;
1756 if (blkcnt < numtrec) {
1757 memmove(buf, &tbufptr[(blkcnt++ * TP_BSIZE)], TP_BSIZE);
1763 for (i = 0; i < ntrec; i++)
1764 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
1767 cnt = ntrec * TP_BSIZE;
1770 if (createtapeposflag)
1771 (void)GetTapePos(&curtapepos);
1776 i = rmtread(&tapebuf[rd], cnt);
1779 i = read(mt, &tapebuf[rd], cnt);
1782 * Check for mid-tape short read error.
1783 * If found, skip rest of buffer and start with the next.
1785 if (!pipein && numtrec < ntrec && i > 0) {
1786 Dprintf(stdout, "mid-media short read error.\n");
1790 * Handle partial block read.
1792 if (pipein && i == 0 && rd > 0)
1794 else if (i > 0 && i != ntrec * TP_BSIZE) {
1803 * Short read. Process the blocks read.
1805 if (i % TP_BSIZE != 0)
1807 "partial block read: %ld should be %ld\n",
1808 (long)i, ntrec * TP_BSIZE);
1809 numtrec = i / TP_BSIZE;
1813 * Handle read error.
1816 fprintf(stderr, "Tape read error while ");
1817 switch (curfile.action) {
1819 fprintf(stderr, "trying to set up tape\n");
1822 fprintf(stderr, "trying to resynchronize\n");
1825 fprintf(stderr, "restoring %s\n", curfile.name);
1828 fprintf(stderr, "skipping over inode %lu\n",
1829 (unsigned long)curfile.ino);
1832 if (!yflag && !reply("continue"))
1834 i = ntrec * TP_BSIZE;
1835 memset(tapebuf, 0, (size_t)i);
1838 seek_failed = (rmtseek(i, 1) < 0);
1841 seek_failed = (LSEEK(mt, i, SEEK_CUR) == (OFF_T)-1);
1844 warn("continuation failed");
1845 if (!yflag && !reply("assume end-of-tape and continue"))
1851 * Handle end of tape.
1854 Vprintf(stdout, "End-of-tape encountered\n");
1863 if (rd % TP_BSIZE != 0)
1864 panic("partial block read: %d should be %d\n",
1865 rd, ntrec * TP_BSIZE);
1867 memmove(&tapebuf[rd], &endoftapemark, TP_BSIZE);
1870 memmove(buf, &tbufptr[(blkcnt++ * TP_BSIZE)], TP_BSIZE);
1875 #if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO)
1878 * Read a compressed format block from a file or pipe and uncompress it.
1879 * Attempt to handle read errors, and end of file.
1882 readtape_comprfile(char *buf)
1884 long rl, size, i, ret;
1886 struct tapebuf *tpb;
1888 if (blkcnt < numtrec) {
1889 memmove(buf, &tbufptr[(blkcnt++ * TP_BSIZE)], TP_BSIZE);
1894 /* need to read the next block */
1896 for (i = 0; i < ntrec; i++)
1897 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
1899 tpb = (struct tapebuf *) tapebuf;
1901 /* read the block prefix */
1902 ret = read_a_block(mt, tapebuf, PREFIXSIZE, &rl);
1903 converttapebuf(tpb);
1905 if (Vflag && (ret == 0 || rl < (int)PREFIXSIZE || tpb->length == 0))
1912 if (size > bufsize) {
1913 /* something's wrong */
1914 Vprintf(stdout, "Prefix size error, max size %d, got %ld\n",
1917 tpb->length = bufsize;
1919 ret = read_a_block(mt, tpb->buf, size, &rl);
1923 tbufptr = decompress_tapebuf(tpb, rl + PREFIXSIZE);
1924 if (tbufptr == NULL) {
1925 msg_read_error("File decompression error while");
1926 if (!yflag && !reply("continue"))
1928 memset(tapebuf, 0, bufsize);
1933 memmove(buf, &tbufptr[(blkcnt++ * TP_BSIZE)], TP_BSIZE);
1939 /* Errors while reading from a file or pipe are catastrophic. Since
1940 * there are no block boundaries, it's impossible to bypass the
1941 * block in error and find the start of the next block.
1944 /* It's possible to have multiple input files using -M
1945 * and -f file1,file2...
1947 Vprintf(stdout, "End-of-File encountered\n");
1957 msg_read_error("Read error while");
1958 /* if (!yflag && !reply("continue")) */
1963 * Read compressed data from a tape and uncompress it.
1964 * Handle read errors, and end of media.
1965 * Since a tape consists of separate physical blocks, we try
1966 * to recover from errors by repositioning the tape to the next
1970 readtape_comprtape(char *buf)
1974 struct tapebuf *tpb;
1977 if (blkcnt < numtrec) {
1978 memmove(buf, &tbufptr[(blkcnt++ * TP_BSIZE)], TP_BSIZE);
1983 /* need to read the next block */
1985 for (i = 0; i < ntrec; i++)
1986 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
1988 tpb = (struct tapebuf *) tapebuf;
1990 /* read the block */
1991 size = bufsize + PREFIXSIZE;
1992 ret = read_a_block(mt, tapebuf, size, &rl);
1996 converttapebuf(tpb);
1997 tbufptr = decompress_tapebuf(tpb, rl);
1998 if (tbufptr == NULL) {
1999 msg_read_error("Tape decompression error while");
2000 if (!yflag && !reply("continue"))
2002 memset(tapebuf, 0, PREFIXSIZE + bufsize);
2008 /* Handle errors: EOT switches to the next volume, other errors
2009 * attempt to position the tape to the next block.
2012 Vprintf(stdout, "End-of-tape encountered\n");
2021 msg_read_error("Tape read error while");
2022 if (!yflag && !reply("continue"))
2024 memset(tapebuf, 0, PREFIXSIZE + bufsize);
2029 rl = rmtioctl(MTFSR, 1);
2035 rl = ioctl(mt, MTIOCTOP, &tcom);
2039 warn("continuation failed");
2040 if (!yflag && !reply("assume end-of-tape and continue"))
2042 ret = 0; /* end of tape */
2048 memmove(buf, &tbufptr[(blkcnt++ * TP_BSIZE)], TP_BSIZE);
2054 * Decompress a struct tapebuf into a buffer. readsize is the size read
2055 * from the tape/file and is used for error messages. Returns a pointer
2056 * to the location of the uncompressed buffer or NULL on errors.
2057 * Adjust numtrec and complain for a short block.
2060 decompress_tapebuf(struct tapebuf *tpbin, int readsize)
2062 /* If zflag is on, all blocks have a struct tapebuf prefix */
2063 /* zflag gets set in setup() from the dump header */
2064 int cresult, blocklen;
2065 unsigned long worklen;
2066 char *output = NULL,*reason = NULL, *lengtherr = NULL;
2068 /* build a length error message */
2069 blocklen = tpbin->length;
2070 if (readsize < blocklen + (int)PREFIXSIZE)
2071 lengtherr = "short";
2073 if (readsize > blocklen + (int)PREFIXSIZE)
2078 if (tpbin->compressed) {
2079 /* uncompress whatever we read, if it fails, complain later */
2080 if (tpbin->flags == COMPRESS_ZLIB) {
2082 errx(1,"This restore version doesn't support zlib decompression");
2084 cresult = uncompress(comprbuf, &worklen,
2085 tpbin->buf, blocklen);
2091 reason = "not enough memory";
2094 reason = "buffer too small";
2097 reason = "data error";
2102 if (cresult == Z_OK)
2106 #endif /* HAVE_ZLIB */
2108 if (tpbin->flags == COMPRESS_BZLIB) {
2110 errx(1,"This restore version doesn't support bzlib decompression");
2112 unsigned int worklen2 = worklen;
2113 cresult = BZ2_bzBuffToBuffDecompress(
2114 comprbuf, &worklen2,
2115 tpbin->buf, blocklen, 0, 0);
2122 reason = "not enough memory";
2124 case BZ_OUTBUFF_FULL:
2125 reason = "buffer too small";
2128 case BZ_DATA_ERROR_MAGIC:
2129 case BZ_UNEXPECTED_EOF:
2130 reason = "data error";
2135 if (cresult == BZ_OK)
2139 #endif /* HAVE_BZLIB */
2141 if (tpbin->flags == COMPRESS_LZO) {
2143 errx(1,"This restore version doesn't support lzo decompression");
2145 lzo_uint worklen2 = worklen;
2146 cresult = lzo1x_decompress(tpbin->buf, blocklen,
2147 comprbuf, &worklen2, NULL);
2154 case LZO_E_EOF_NOT_FOUND:
2155 reason = "data error";
2160 if (cresult == LZO_E_OK)
2164 #endif /* HAVE_LZO */
2168 output = tpbin->buf;
2172 numtrec = worklen / TP_BSIZE;
2173 if (worklen % TP_BSIZE != 0)
2174 reason = "length mismatch";
2178 fprintf(stderr, "%s compressed block: %d expected: %u\n",
2179 lengtherr, readsize, tpbin->length + PREFIXSIZE);
2180 fprintf(stderr, "decompression error, block %ld: %s\n",
2181 tpblksread+1, reason);
2189 * Print an error message for a read error.
2190 * This was exteracted from the original readtape().
2193 msg_read_error(char *m)
2195 switch (curfile.action) {
2197 fprintf(stderr, "%s trying to set up tape\n", m);
2200 fprintf(stderr, "%s trying to resynchronize\n", m);
2203 fprintf(stderr, "%s restoring %s\n", m, curfile.name);
2206 fprintf(stderr, "%s skipping over inode %lu\n", m,
2207 (unsigned long)curfile.ino);
2211 #endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */
2214 * Read the first block and get the blocksize from it. Test
2215 * for a compressed dump tape/file. setup() will make the final
2216 * determination by checking the compressed flag if gethead()
2217 * finds a valid header. The test here is necessary to offset the buffer
2218 * by the size of the compressed prefix. zflag is set here so that
2219 * readtape_set can set the correct function pointer for readtape().
2220 * Note that the first block of each tape/file is not compressed
2221 * and does not have a prefix.
2224 findtapeblksize(void)
2228 struct tapebuf *tpb = (struct tapebuf *) tapebuf;
2229 struct s_spcl spclpt;
2231 for (i = 0; i < ntrec; i++)
2232 ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
2236 * For a pipe or file, read in the first record. For a tape, read
2239 len = magtapein ? ntrec * TP_BSIZE : TP_BSIZE;
2241 if (read_a_block(mt, tapebuf, len, &i) <= 0)
2242 errx(1, "Tape read error on first record");
2244 memcpy(&spclpt, tapebuf, TP_BSIZE);
2245 if (converthead(&spclpt) == FAIL) {
2247 if (converthead(&spclpt) == FAIL) {
2248 /* Special case for old compressed tapes with prefix */
2249 if (magtapein && (i % TP_BSIZE != 0))
2251 errx(1, "Tape is not a dump tape");
2253 fprintf(stderr, "Converting to new file system format.\n");
2256 * If the input is from a file or a pipe, we read TP_BSIZE
2257 * bytes looking for a dump header. If the dump is compressed
2258 * we need to read in the rest of the block, as determined
2259 * by c_ntrec in the dump header. The first block of the
2260 * dump is not compressed and does not have a prefix.
2263 if (spclpt.c_type == TS_TAPE
2264 && spclpt.c_flags & DR_COMPRESSED) {
2265 /* It's a compressed dump file, read in the */
2266 /* rest of the block based on spclpt.c_ntrec. */
2267 if (spclpt.c_ntrec > ntrec)
2268 errx(1, "Tape blocksize is too large, use "
2269 "\'-b %d\' ", spclpt.c_ntrec);
2270 ntrec = spclpt.c_ntrec;
2271 len = (ntrec - 1) * TP_BSIZE;
2275 /* read in the rest of the block based on bufsize */
2276 len = bufsize - TP_BSIZE;
2278 if (read_a_block(mt, tapebuf+TP_BSIZE, len, &i) < 0
2279 || (i != (long)len && i % TP_BSIZE != 0))
2280 errx(1,"Error reading dump file header");
2283 Vprintf(stdout, "Input block size is %ld\n", ntrec);
2285 } /* if (!magtapein) */
2288 * If the input is a tape, we tried to read ntrec * TP_BSIZE bytes.
2289 * If the value of ntrec is too large, we read less than
2290 * what we asked for; adjust the value of ntrec and test for
2291 * a compressed dump tape.
2293 if (i % TP_BSIZE != 0) {
2295 /* may be old format compressed dump tape with a prefix */
2296 memcpy(&spclpt, tpb->buf, TP_BSIZE);
2298 if (converthead(&spclpt) == FAIL) {
2300 if (converthead(&spclpt) == FAIL)
2301 errx(1, "Tape is not a dump tape");
2302 fprintf(stderr, "Converting to new file system format.\n");
2304 if (i % TP_BSIZE == PREFIXSIZE
2305 && tpb->compressed == 0
2306 && spclpt.c_type == TS_TAPE
2307 && spclpt.c_flags & DR_COMPRESSED) {
2310 if (tpb->length > bufsize)
2311 errx(1, "Tape blocksize is too large, use "
2312 "\'-b %d\' ", tpb->length / TP_BSIZE);
2315 errx(1, "Tape block size (%ld) is not a multiple of dump block size (%d)",
2318 ntrec = i / TP_BSIZE;
2319 if (spclpt.c_type == TS_TAPE) {
2320 if (spclpt.c_flags & DR_COMPRESSED)
2322 if (spclpt.c_ntrec > ntrec)
2323 errx(1, "Tape blocksize is too large, use "
2324 "\'-b %d\' ", spclpt.c_ntrec);
2327 Vprintf(stdout, "Tape block size is %ld\n", ntrec);
2331 * Read a block of data handling all of the messy details.
2333 static int read_a_block(int fd, char *buf, size_t len, long *lengthread)
2341 i = rmtread(buf, size);
2344 i = read(fd, buf, size);
2347 break; /* EOD or error */
2350 break; /* block at a time for mt */
2353 *lengthread = len - size;
2372 setmagtapein(void) {
2373 struct mtget mt_stat;
2374 static int done = 0;
2379 /* need to know if input is really from a tape */
2385 magtapein = ioctl(mt, MTIOCGET, (char *)&mt_stat) == 0;
2388 Vprintf(stdout,"Input is from a %s %s\n",
2389 host ? "remote" : "local",
2390 magtapein ? "tape" :
2391 Vflag ? "multi-volume (no tape)" : "file/pipe");
2395 * Read the next block from the tape.
2396 * Check to see if it is one of several vintage headers.
2397 * If it is an old style header, convert it to a new style header.
2398 * If it is not any valid header, return an error.
2401 gethead(struct s_spcl *buf)
2403 readtape((char *)buf);
2404 return converthead(buf);
2408 converthead(struct s_spcl *buf)
2416 char dummy[TP_BSIZE];
2423 u_int16_t c_inumber;
2428 u_int16_t odi_nlink;
2444 if (buf->c_magic != NFS_MAGIC) {
2445 if (swabi(buf->c_magic) != NFS_MAGIC)
2448 Vprintf(stdout, "Note: Doing Byte swapping\n");
2452 if (checksum((int *)buf) == FAIL)
2455 swabst((u_char *)"8i4s31i528bi192b3i", (u_char *)buf);
2458 memcpy(&u_ospcl.s_ospcl, buf, TP_BSIZE);
2459 if (checksum((int *)(&u_ospcl.s_ospcl)) == FAIL)
2461 if (u_ospcl.s_ospcl.c_magic == OFS_MAGIC) {
2462 memset((char *)buf, 0, (long)TP_BSIZE);
2463 buf->c_type = u_ospcl.s_ospcl.c_type;
2464 buf->c_date = u_ospcl.s_ospcl.c_date;
2465 buf->c_ddate = u_ospcl.s_ospcl.c_ddate;
2466 buf->c_volume = u_ospcl.s_ospcl.c_volume;
2467 buf->c_tapea = u_ospcl.s_ospcl.c_tapea;
2468 buf->c_inumber = u_ospcl.s_ospcl.c_inumber;
2469 buf->c_checksum = u_ospcl.s_ospcl.c_checksum;
2470 buf->c_magic = u_ospcl.s_ospcl.c_magic;
2471 buf->c_dinode.di_mode = u_ospcl.s_ospcl.c_dinode.odi_mode;
2472 buf->c_dinode.di_nlink = u_ospcl.s_ospcl.c_dinode.odi_nlink;
2473 buf->c_dinode.di_uid = u_ospcl.s_ospcl.c_dinode.odi_uid;
2474 buf->c_dinode.di_gid = u_ospcl.s_ospcl.c_dinode.odi_gid;
2475 buf->c_dinode.di_size = u_ospcl.s_ospcl.c_dinode.odi_size;
2476 buf->c_dinode.di_rdev = u_ospcl.s_ospcl.c_dinode.odi_rdev;
2477 #if defined(__linux__) || defined(sunos)
2478 buf->c_dinode.di_atime.tv_sec = u_ospcl.s_ospcl.c_dinode.odi_atime;
2479 buf->c_dinode.di_mtime.tv_sec = u_ospcl.s_ospcl.c_dinode.odi_mtime;
2480 buf->c_dinode.di_ctime.tv_sec = u_ospcl.s_ospcl.c_dinode.odi_ctime;
2481 #else /* __linux__ || sunos */
2482 buf->c_dinode.di_atime = u_ospcl.s_ospcl.c_dinode.odi_atime;
2483 buf->c_dinode.di_mtime = u_ospcl.s_ospcl.c_dinode.odi_mtime;
2484 buf->c_dinode.di_ctime = u_ospcl.s_ospcl.c_dinode.odi_ctime;
2485 #endif /* __linux__ || sunos */
2486 buf->c_count = u_ospcl.s_ospcl.c_count;
2487 memmove(buf->c_addr, u_ospcl.s_ospcl.c_fill, (long)256);
2489 else if (u_ospcl.s_ospcl.c_magic == FS_UFS2_MAGIC) {
2490 buf->c_date = (int32_t)(*(int64_t *)&u_ospcl.dummy[896]);
2491 buf->c_ddate = (int32_t)(*(int64_t *)&u_ospcl.dummy[904]);
2492 buf->c_tapea = (int32_t)(*(int64_t *)&u_ospcl.dummy[912]);
2493 buf->c_firstrec = (int32_t)(*(int64_t *)&u_ospcl.dummy[920]);
2495 buf->c_extattributes = 0;
2496 buf->c_flags |= DR_NEWINODEFMT;
2501 buf->c_magic = NFS_MAGIC;
2504 if ((buf->c_dinode.di_size == 0 || buf->c_dinode.di_size > 0xfffffff) &&
2505 (buf->c_dinode.di_mode & IFMT) == IFDIR && Qcvt == 0) {
2506 qcvt.qval = buf->c_dinode.di_size;
2507 if (qcvt.val[0] || qcvt.val[1]) {
2508 Vprintf(stdout, "Note: Doing Quad swapping\n");
2513 qcvt.qval = buf->c_dinode.di_size;
2515 qcvt.val[1] = qcvt.val[0];
2517 buf->c_dinode.di_size = qcvt.qval;
2521 switch (buf->c_type) {
2526 * Have to patch up missing information in bit map headers
2529 buf->c_dinode.di_size = buf->c_count * TP_BSIZE;
2530 if (buf->c_count > TP_NINDIR)
2533 for (i = 0; i < buf->c_count; i++)
2538 if ((buf->c_flags & DR_NEWINODEFMT) == 0)
2543 if (buf->c_flags & DR_INODEINFO) {
2544 memcpy(volinfo, buf->c_inos, TP_NINOS * sizeof(dump_ino_t));
2546 swabst((u_char *)"128i", (u_char *)volinfo);
2555 panic("gethead: unknown inode type %d\n", buf->c_type);
2559 * If we are restoring a filesystem with old format inodes,
2560 * copy the uid/gid to the new location.
2563 buf->c_dinode.di_uid = buf->c_dinode.di_ouid;
2564 buf->c_dinode.di_gid = buf->c_dinode.di_ogid;
2572 converttapebuf(struct tapebuf *tpb)
2576 unsigned int length:28;
2577 unsigned int flags:3;
2578 unsigned int compressed:1;
2580 swabst((u_char *)"i", (u_char *)tpb);
2581 memcpy(&tb, tpb, 4);
2582 tpb->length = tb.length;
2583 tpb->flags = tb.flags;
2584 tpb->compressed = tb.compressed;
2589 * Check that a header is where it belongs and predict the next header
2592 accthdr(struct s_spcl *header)
2594 static dump_ino_t previno = 0x7fffffff;
2595 static int prevtype;
2596 static long predict;
2599 if (header->c_type == TS_TAPE) {
2600 fprintf(stderr, "Volume header (%s inode format) ",
2601 oldinofmt ? "old" : "new");
2602 if (header->c_firstrec)
2603 fprintf(stderr, "begins with record %d",
2604 header->c_firstrec);
2605 fprintf(stderr, "\n");
2606 previno = 0x7fffffff;
2609 if (previno == 0x7fffffff)
2613 fprintf(stderr, "Dumped inodes map header");
2616 fprintf(stderr, "Used inodes map header");
2619 fprintf(stderr, "File header, ino %lu", (unsigned long)previno);
2622 fprintf(stderr, "File continuation header, ino %ld", (long)previno);
2625 fprintf(stderr, "End of tape header");
2628 if (predict != blksread - 1)
2629 fprintf(stderr, "; predicted %ld blocks, got %ld blocks",
2630 predict, blksread - 1);
2631 fprintf(stderr, "\n");
2634 if (header->c_type != TS_END)
2635 for (i = 0; i < header->c_count; i++)
2636 if (readmapflag || header->c_addr[i] != 0)
2640 prevtype = header->c_type;
2641 previno = header->c_inumber;
2645 * Find an inode header.
2646 * Complain if had to skip, and complain is set.
2649 findinode(struct s_spcl *header)
2651 static long skipcnt = 0;
2655 curfile.name = "<name unknown>";
2656 curfile.action = UNKNOWN;
2660 if (header->c_magic != NFS_MAGIC) {
2662 while (gethead(header) == FAIL ||
2663 header->c_date != dumpdate)
2666 switch (header->c_type) {
2670 * Skip up to the beginning of the next record
2672 for (i = 0; i < header->c_count; i++)
2673 if (header->c_addr[i])
2675 while (gethead(header) == FAIL ||
2676 header->c_date != dumpdate)
2681 curfile.dip = &header->c_dinode;
2682 curfile.ino = header->c_inumber;
2686 curfile.ino = maxino;
2690 curfile.name = "<file removal list>";
2694 curfile.name = "<file dump list>";
2698 panic("unexpected tape header\n");
2702 panic("unknown tape header type %d\n", spcl.c_type);
2706 } while (header->c_type == TS_ADDR);
2711 fprintf(stderr, "resync restore, skipped %ld blocks\n",
2721 j = sizeof(union u_spcl) / sizeof(int);
2728 /* What happens if we want to read restore tapes
2729 for a 16bit int machine??? */
2735 if (i != CHECKSUM) {
2736 fprintf(stderr, "Checksum error %o, inode %lu file %s\n", i,
2737 (unsigned long)curfile.ino, curfile.name);
2747 #include <varargs.h>
2752 msg(const char *fmt, ...)
2765 (void)vfprintf(stderr, fmt, ap);
2768 #endif /* RRESTORE */
2771 swab16(u_char *sp, int n)
2776 c = sp[0]; sp[0] = sp[1]; sp[1] = c;
2783 swab32(u_char *sp, int n)
2788 c = sp[0]; sp[0] = sp[3]; sp[3] = c;
2789 c = sp[1]; sp[1] = sp[2]; sp[2] = c;
2796 swab64(u_char *sp, int n)
2801 c = sp[0]; sp[0] = sp[7]; sp[7] = c;
2802 c = sp[1]; sp[1] = sp[6]; sp[6] = c;
2803 c = sp[2]; sp[2] = sp[5]; sp[5] = c;
2804 c = sp[3]; sp[3] = sp[4]; sp[4] = c;
2811 swabst(u_char *cp, u_char *sp)
2817 case '0': case '1': case '2': case '3': case '4':
2818 case '5': case '6': case '7': case '8': case '9':
2819 n = (n * 10) + (*cp++ - '0');
2822 case 's': case 'w': case 'h':
2840 default: /* Any other character, like 'b' counts as byte. */
2854 swabst((u_char *)"i", (u_char *)&x);
2862 swabst((u_char *)"l", (u_char *)&x);
2868 RequestVol(long tnum)
2879 int uscsi_flags; /* read, write, etc. see below */
2880 short uscsi_status; /* resulting status */
2881 short uscsi_timeout; /* Command Timeout */
2882 caddr_t uscsi_cdb; /* cdb to send to target */
2883 caddr_t uscsi_bufaddr; /* i/o source/destination */
2884 u_int uscsi_buflen; /* size of i/o to take place */
2885 u_int uscsi_resid; /* resid from i/o operation */
2886 u_char uscsi_cdblen; /* # of valid cdb bytes */
2887 u_char uscsi_rqlen; /* size of uscsi_rqbuf */
2888 u_char uscsi_rqstatus; /* status of request sense cmd */
2889 u_char uscsi_rqresid; /* resid of request sense cmd */
2890 caddr_t uscsi_rqbuf; /* request sense buffer */
2891 void *uscsi_reserved_5; /* Reserved for Future Use */
2894 #define CDB_GROUP0 6 /* 6-byte cdb's */
2895 #define CDB_GROUP1 10 /* 10-byte cdb's */
2896 #define CDB_GROUP2 10 /* 10-byte cdb's */
2897 #define CDB_GROUP3 0 /* reserved */
2898 #define CDB_GROUP4 16 /* 16-byte cdb's */
2899 #define CDB_GROUP5 12 /* 12-byte cdb's */
2900 #define CDB_GROUP6 0 /* reserved */
2901 #define CDB_GROUP7 0 /* reserved */
2903 #define USCSI_WRITE 0x00000 /* send data to device */
2904 #define USCSI_SILENT 0x00001 /* no error messages */
2905 #define USCSI_DIAGNOSE 0x00002 /* fail if any error occurs */
2906 #define USCSI_ISOLATE 0x00004 /* isolate from normal commands */
2907 #define USCSI_READ 0x00008 /* get data from device */
2908 #define USCSI_RESET 0x04000 /* Reset target */
2909 #define USCSI_RESET_ALL 0x08000 /* Reset all targets */
2910 #define USCSI_RQENABLE 0x10000 /* Enable Request Sense extensions */
2912 #define USCSIIOC (0x04 << 8)
2913 #define USCSICMD (USCSIIOC|201) /* user scsi command */
2915 #define USCSI_TIMEOUT 30
2916 #define USCSI_SHORT_TIMEOUT 900
2917 #define USCSI_LONG_TIMEOUT 14000
2919 #define B(s,i) ((unsigned char)((s) >> i))
2920 #define B1(s) ((unsigned char)(s))
2922 #define MSB4(s,v) *(s)=B(v,24),(s)[1]=B(v,16), (s)[2]=B(v,8), (s)[3]=B1(v)
2926 GetTapePos(long long *pos)
2929 struct uscsi_cmd scmd;
2934 (void)memset((void *)buf, 0, sizeof(buf));
2935 (void)memset((void *)&scmd, 0, sizeof(scmd));
2936 scmd.uscsi_flags = USCSI_READ|USCSI_SILENT;
2937 scmd.uscsi_timeout = USCSI_TIMEOUT;
2938 scmd.uscsi_cdb = buf;
2939 scmd.uscsi_cdblen = CDB_GROUP1;
2940 buf[0] = 0x34; /* read position */
2942 (void)memset((void *)parm, 0, 512);
2943 scmd.uscsi_bufaddr = parm;
2944 scmd.uscsi_buflen = 56;
2945 if (ioctl(fdsmtc, USCSICMD, &scmd) == -1) {
2949 (void)memcpy(&lpos, &parm[4], sizeof(long));
2955 GotoTapePos(long long pos)
2958 struct uscsi_cmd scmd;
2961 long lpos = (long)pos;
2963 (void)memset((void *)buf, 0, sizeof(buf));
2964 (void)memset((void *)&scmd, 0, sizeof(scmd));
2965 scmd.uscsi_flags = USCSI_WRITE|USCSI_SILENT;
2966 scmd.uscsi_timeout = 360; /* 5 Minutes */
2967 scmd.uscsi_cdb = buf;
2968 scmd.uscsi_cdblen = CDB_GROUP1;
2969 buf[0] = 0x2b; /* locate */
2971 MSB4(&buf[3], lpos);
2972 (void)memset((void *)parm, 0, 512);
2973 scmd.uscsi_bufaddr = NULL;
2974 scmd.uscsi_buflen = 0;
2975 if (ioctl(fdsmtc, USCSICMD, &scmd) == -1) {
2983 #define LSEEK_GET_TAPEPOS 10
2984 #define LSEEK_GO2_TAPEPOS 11
2987 typedef struct mt_pos {
2990 } MTPosRec, *MTPosPtr;
2994 * get the current position of the tape
2997 GetTapePos(long long *pos)
3003 *pos = (long long) rmtseek((OFF_T)0, (int)LSEEK_GET_TAPEPOS);
3012 err = (ioctl(mt, MTIOCPOS, &mtpos) < 0);
3013 *pos = (long long)mtpos;
3016 *pos = LSEEK(mt, 0, SEEK_CUR);
3022 fprintf(stdout, "[%ld] error: %d (getting tapepos: %lld)\n",
3023 (unsigned long)getpid(), err, *pos);
3030 * go to specified position on tape
3033 GotoTapePos(long long pos)
3039 err = (rmtseek((OFF_T)pos, (int)LSEEK_GO2_TAPEPOS) < 0);
3046 buf.mt_count = (int) pos;
3047 err = (ioctl(mt, MTIOCTOP, &buf) < 0);
3050 pos = LSEEK(mt, pos, SEEK_SET);
3056 fprintf(stdout, "[%ld] error: %d (setting tapepos: %lld)\n",
3057 (unsigned long)getpid(), err, pos);
3062 #endif /* __linux__ */
3065 * read next data from tape to re-sync
3068 ReReadFromTape(void)
3072 if (gethead(&spcl) == FAIL) {
3074 fprintf(stdout, "DEBUG 1 gethead failed\n");
3082 ReReadInodeFromTape(dump_ino_t theino)
3091 } while (!(spcl.c_inumber == theino && spcl.c_type == TS_INODE && spcl.c_date == dumpdate));
3093 fprintf(stderr, "DEBUG: %ld reads\n", cntloop);
3094 fprintf(stderr, "DEBUG: bufsize %ld\n", bufsize);
3095 fprintf(stderr, "DEBUG: ntrec %ld\n", ntrec);
3096 fprintf(stderr, "DEBUG: %ld reads\n", cntloop);
3104 OpenSMTCmt(char *themagtape)
3106 if (GetSCSIIDFromPath(themagtape, &scsiid)) {
3107 fprintf(stderr, "can't get SCSI-ID for %s\n", themagtape);
3111 fprintf(stderr, "can't get SCSI-ID for %s\n", themagtape);
3114 sprintf(smtcpath, "/dev/rsmtc%ld,0", scsiid);
3115 if ((fdsmtc = open(smtcpath, O_RDWR)) == -1) {
3116 fprintf(stderr, "can't open smtc device: %s, %d\n", smtcpath, errno);
3122 #endif /* USE_QFA */