17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California.
37c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
47c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
57c478bd9Sstevel@tonic-gate */
67c478bd9Sstevel@tonic-gate
77c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
87c478bd9Sstevel@tonic-gate /* All Rights Reserved */
97c478bd9Sstevel@tonic-gate
107c478bd9Sstevel@tonic-gate /*
11294baf98Sbatschul * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
127c478bd9Sstevel@tonic-gate * Use is subject to license terms.
137c478bd9Sstevel@tonic-gate */
147c478bd9Sstevel@tonic-gate
157c478bd9Sstevel@tonic-gate #include <setjmp.h>
167c478bd9Sstevel@tonic-gate #include "restore.h"
177c478bd9Sstevel@tonic-gate #include <byteorder.h>
187c478bd9Sstevel@tonic-gate #include <rmt.h>
197c478bd9Sstevel@tonic-gate #include <sys/mtio.h>
207c478bd9Sstevel@tonic-gate #include <utime.h>
217c478bd9Sstevel@tonic-gate #include <sys/errno.h>
227c478bd9Sstevel@tonic-gate #include <sys/fdio.h>
237c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> /* for expdev */
247c478bd9Sstevel@tonic-gate #include <assert.h>
257c478bd9Sstevel@tonic-gate #include <limits.h>
267c478bd9Sstevel@tonic-gate #include <priv_utils.h>
2749f0e518Smarks #include <aclutils.h>
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #define MAXINO 65535 /* KLUDGE */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #define MAXTAPES 128
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate static size_t fssize = MAXBSIZE; /* preferred size of writes to filesystem */
347c478bd9Sstevel@tonic-gate int mt = -1;
357c478bd9Sstevel@tonic-gate static int continuemap = 0;
367c478bd9Sstevel@tonic-gate char magtape[BUFSIZ];
377c478bd9Sstevel@tonic-gate int pipein = 0;
387c478bd9Sstevel@tonic-gate char *host; /* used in dumprmt.c */
397c478bd9Sstevel@tonic-gate daddr32_t rec_position;
407c478bd9Sstevel@tonic-gate static char *archivefile; /* used in metamucil.c */
417c478bd9Sstevel@tonic-gate static int bct; /* block # index into tape record buffer */
427c478bd9Sstevel@tonic-gate static int numtrec; /* # of logical blocks in current tape record */
437c478bd9Sstevel@tonic-gate static char *tbf = NULL;
447c478bd9Sstevel@tonic-gate static size_t tbfsize = 0;
457c478bd9Sstevel@tonic-gate static int recsread;
46*e0dfa398SToomas Soome union u_spcl u_spcl;
477c478bd9Sstevel@tonic-gate static union u_spcl endoftapemark;
487c478bd9Sstevel@tonic-gate static struct s_spcl dumpinfo;
497c478bd9Sstevel@tonic-gate static long blksread; /* # of logical blocks actually read/touched */
507c478bd9Sstevel@tonic-gate static long tapea; /* current logical block # on tape */
517c478bd9Sstevel@tonic-gate static uchar_t tapesread[MAXTAPES];
527c478bd9Sstevel@tonic-gate static jmp_buf restart;
537c478bd9Sstevel@tonic-gate static int gettingfile = 0; /* restart has a valid frame */
547c478bd9Sstevel@tonic-gate static int ofile;
557c478bd9Sstevel@tonic-gate static char *map, *beginmap;
567c478bd9Sstevel@tonic-gate static char *endmap;
577c478bd9Sstevel@tonic-gate static char lnkbuf[MAXPATHLEN + 2];
587c478bd9Sstevel@tonic-gate static int pathlen;
597c478bd9Sstevel@tonic-gate static int inodeinfo; /* Have starting volume information */
607c478bd9Sstevel@tonic-gate static int hostinfo; /* Have dump host information */
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate static int autoload_tape(void);
637c478bd9Sstevel@tonic-gate static void setdumpnum(void);
647c478bd9Sstevel@tonic-gate static void metacheck(struct s_spcl *);
657c478bd9Sstevel@tonic-gate static void xtrmeta(char *, size_t);
667c478bd9Sstevel@tonic-gate static void metaskip(char *, size_t);
677c478bd9Sstevel@tonic-gate static void xtrfile(char *, size_t);
687c478bd9Sstevel@tonic-gate static void xtrskip(char *, size_t);
697c478bd9Sstevel@tonic-gate static void xtrlnkfile(char *, size_t);
707c478bd9Sstevel@tonic-gate static void xtrlnkskip(char *, size_t);
717c478bd9Sstevel@tonic-gate static void xtrmap(char *, size_t);
727c478bd9Sstevel@tonic-gate static void xtrmapskip(char *, size_t);
737c478bd9Sstevel@tonic-gate static void readtape(char *);
747c478bd9Sstevel@tonic-gate static int checkvol(struct s_spcl *, int);
757c478bd9Sstevel@tonic-gate static void accthdr(struct s_spcl *);
767c478bd9Sstevel@tonic-gate static int ishead(struct s_spcl *);
77fe0e7ec4Smaheshvs static int checktype(struct s_spcl *, int);
787c478bd9Sstevel@tonic-gate static void metaset(char *name);
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate * Set up an input source
827c478bd9Sstevel@tonic-gate */
837c478bd9Sstevel@tonic-gate void
setinput(char * source,char * archive)84fe0e7ec4Smaheshvs setinput(char *source, char *archive)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate flsht();
887c478bd9Sstevel@tonic-gate archivefile = archive;
897c478bd9Sstevel@tonic-gate if (bflag == 0) {
907c478bd9Sstevel@tonic-gate ntrec = ((CARTRIDGETREC > HIGHDENSITYTREC) ?
917c478bd9Sstevel@tonic-gate (NTREC > CARTRIDGETREC ? NTREC : CARTRIDGETREC) :
927c478bd9Sstevel@tonic-gate (NTREC > HIGHDENSITYTREC ? NTREC : HIGHDENSITYTREC));
937c478bd9Sstevel@tonic-gate saved_ntrec = (ntrec * (tp_bsize/DEV_BSIZE));
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate newtapebuf(ntrec);
967c478bd9Sstevel@tonic-gate terminal = stdin;
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate if (source == NULL) {
997c478bd9Sstevel@tonic-gate /* A can't-happen */
1007c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
1017c478bd9Sstevel@tonic-gate gettext("Internal consistency check failed.\n"));
1027c478bd9Sstevel@tonic-gate done(1);
1037c478bd9Sstevel@tonic-gate }
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate if (strchr(source, ':')) {
1067c478bd9Sstevel@tonic-gate char *tape;
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate host = source;
1097c478bd9Sstevel@tonic-gate tape = strchr(host, ':');
1107c478bd9Sstevel@tonic-gate *tape++ = '\0';
1117c478bd9Sstevel@tonic-gate if (strlen(tape) > (sizeof (magtape) - 1)) {
1127c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Tape name too long\n"));
1137c478bd9Sstevel@tonic-gate done(1);
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate (void) strcpy(magtape, tape);
1167c478bd9Sstevel@tonic-gate if (rmthost(host, ntrec) == 0)
1177c478bd9Sstevel@tonic-gate done(1);
1187c478bd9Sstevel@tonic-gate } else {
1197c478bd9Sstevel@tonic-gate if (strlen(source) > (sizeof (magtape) - 1)) {
1207c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Tape name too long\n"));
1217c478bd9Sstevel@tonic-gate done(1);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate /* Not remote, no need for privileges */
1247c478bd9Sstevel@tonic-gate __priv_relinquish();
1257c478bd9Sstevel@tonic-gate host = NULL;
1267c478bd9Sstevel@tonic-gate if (strcmp(source, "-") == 0) {
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate * Since input is coming from a pipe we must establish
1297c478bd9Sstevel@tonic-gate * our own connection to the terminal.
1307c478bd9Sstevel@tonic-gate */
1317c478bd9Sstevel@tonic-gate terminal = fopen("/dev/tty", "r");
1327c478bd9Sstevel@tonic-gate if (terminal == NULL) {
1337c478bd9Sstevel@tonic-gate int saverr = errno;
1347c478bd9Sstevel@tonic-gate char *msg =
1352720c984Svk gettext("Cannot open(\"/dev/tty\")");
1367c478bd9Sstevel@tonic-gate errno = saverr;
1377c478bd9Sstevel@tonic-gate perror(msg);
1387c478bd9Sstevel@tonic-gate terminal = fopen("/dev/null", "r");
1397c478bd9Sstevel@tonic-gate if (terminal == NULL) {
1407c478bd9Sstevel@tonic-gate saverr = errno;
1417c478bd9Sstevel@tonic-gate msg = gettext(
1427c478bd9Sstevel@tonic-gate "Cannot open(\"/dev/null\")");
1437c478bd9Sstevel@tonic-gate errno = saverr;
1447c478bd9Sstevel@tonic-gate perror(msg);
1457c478bd9Sstevel@tonic-gate done(1);
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate pipein++;
1497c478bd9Sstevel@tonic-gate if (archive) {
1507c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
1517c478bd9Sstevel@tonic-gate "Cannot specify an archive file when reading from a pipe\n"));
1527c478bd9Sstevel@tonic-gate done(1);
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate (void) strcpy(magtape, source);
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate void
newtapebuf(size_t size)160fe0e7ec4Smaheshvs newtapebuf(size_t size)
1617c478bd9Sstevel@tonic-gate {
1627c478bd9Sstevel@tonic-gate size_t nsize;
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate nsize = size * tp_bsize;
1657c478bd9Sstevel@tonic-gate ntrec = size;
1667c478bd9Sstevel@tonic-gate if (nsize <= tbfsize)
1677c478bd9Sstevel@tonic-gate return;
1687c478bd9Sstevel@tonic-gate if (tbf != NULL)
1697c478bd9Sstevel@tonic-gate free(tbf);
1707c478bd9Sstevel@tonic-gate tbf = (char *)malloc(nsize);
1717c478bd9Sstevel@tonic-gate if (tbf == NULL) {
1727c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
1737c478bd9Sstevel@tonic-gate gettext("Cannot allocate space for buffer\n"));
1747c478bd9Sstevel@tonic-gate done(1);
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate tbfsize = nsize;
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate * Verify that the tape drive can be accessed and
1817c478bd9Sstevel@tonic-gate * that it actually is a dump tape.
1827c478bd9Sstevel@tonic-gate */
1837c478bd9Sstevel@tonic-gate void
setup(void)1847c478bd9Sstevel@tonic-gate setup(void)
1857c478bd9Sstevel@tonic-gate {
1867c478bd9Sstevel@tonic-gate int i, j;
1877c478bd9Sstevel@tonic-gate int32_t *ip;
1887c478bd9Sstevel@tonic-gate struct stat stbuf;
1897c478bd9Sstevel@tonic-gate size_t mapsize;
1907c478bd9Sstevel@tonic-gate char *syment = RESTORESYMTABLE;
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate vprintf(stdout, gettext("Verify volume and initialize maps\n"));
1937c478bd9Sstevel@tonic-gate if (archivefile) {
1947c478bd9Sstevel@tonic-gate mt = open(archivefile, O_RDONLY|O_LARGEFILE);
1957c478bd9Sstevel@tonic-gate if (mt < 0) {
1967c478bd9Sstevel@tonic-gate perror(archivefile);
1977c478bd9Sstevel@tonic-gate done(1);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate volno = 0;
2007c478bd9Sstevel@tonic-gate } else if (host) {
2017c478bd9Sstevel@tonic-gate if ((mt = rmtopen(magtape, O_RDONLY)) < 0) {
2027c478bd9Sstevel@tonic-gate perror(magtape);
2037c478bd9Sstevel@tonic-gate done(1);
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate volno = 1;
2067c478bd9Sstevel@tonic-gate } else {
2077c478bd9Sstevel@tonic-gate if (pipein)
2087c478bd9Sstevel@tonic-gate mt = 0;
2097c478bd9Sstevel@tonic-gate else if ((mt = open(magtape, O_RDONLY|O_LARGEFILE)) < 0) {
2107c478bd9Sstevel@tonic-gate perror(magtape);
2117c478bd9Sstevel@tonic-gate done(1);
2127c478bd9Sstevel@tonic-gate }
2137c478bd9Sstevel@tonic-gate volno = 1;
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate setdumpnum();
2167c478bd9Sstevel@tonic-gate flsht();
2177c478bd9Sstevel@tonic-gate if (!pipein && !bflag)
2187c478bd9Sstevel@tonic-gate if (archivefile)
2197c478bd9Sstevel@tonic-gate findtapeblksize(ARCHIVE_FILE);
2207c478bd9Sstevel@tonic-gate else
2217c478bd9Sstevel@tonic-gate findtapeblksize(TAPE_FILE);
2227c478bd9Sstevel@tonic-gate if (bflag == 1) {
2237c478bd9Sstevel@tonic-gate tape_rec_size = saved_ntrec * DEV_BSIZE;
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate /*
2277c478bd9Sstevel@tonic-gate * Get the first header. If c_magic is NOT NFS_MAGIC or if
2287c478bd9Sstevel@tonic-gate * the checksum is in error, it will fail. The magic could then
2297c478bd9Sstevel@tonic-gate * be either OFS_MAGIC or MTB_MAGIC. If OFS_MAGIC, assume we
2307c478bd9Sstevel@tonic-gate * have an old dump, and try to convert it. If it is MTB_MAGIC, we
2317c478bd9Sstevel@tonic-gate * procees this after.
2327c478bd9Sstevel@tonic-gate */
2337c478bd9Sstevel@tonic-gate if ((gethead(&spcl) == FAIL) && (spcl.c_magic != MTB_MAGIC)) {
2347c478bd9Sstevel@tonic-gate bct--; /* push back this block */
2357c478bd9Sstevel@tonic-gate blksread--;
2367c478bd9Sstevel@tonic-gate tapea--;
2377c478bd9Sstevel@tonic-gate cvtflag++;
2387c478bd9Sstevel@tonic-gate if (gethead(&spcl) == FAIL) {
2397c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
2407c478bd9Sstevel@tonic-gate gettext("Volume is not in dump format\n"));
2417c478bd9Sstevel@tonic-gate done(1);
2427c478bd9Sstevel@tonic-gate }
2437c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
2447c478bd9Sstevel@tonic-gate gettext("Converting to new file system format.\n"));
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate /*
2477c478bd9Sstevel@tonic-gate * The above gethead will have failed if the magic is
2487c478bd9Sstevel@tonic-gate * MTB_MAGIC. If that is true, we need to adjust tp_bsize.
2497c478bd9Sstevel@tonic-gate * We have assumed to this time that tp_bsize was 1024, if
2507c478bd9Sstevel@tonic-gate * this is a newer dump, get the real tp_bsize from the header,
2517c478bd9Sstevel@tonic-gate * and recalculate ntrec, numtrec.
2527c478bd9Sstevel@tonic-gate */
2537c478bd9Sstevel@tonic-gate if (spcl.c_magic == MTB_MAGIC) {
2547c478bd9Sstevel@tonic-gate tp_bsize = spcl.c_tpbsize;
2557c478bd9Sstevel@tonic-gate if ((tp_bsize % TP_BSIZE_MIN != 0) ||
2567c478bd9Sstevel@tonic-gate (tp_bsize > TP_BSIZE_MAX)) {
2577c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
2587c478bd9Sstevel@tonic-gate gettext("Volume is not in dump format\n"));
2597c478bd9Sstevel@tonic-gate done(1);
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate ntrec = (tape_rec_size/tp_bsize);
2627c478bd9Sstevel@tonic-gate numtrec = ntrec;
2637c478bd9Sstevel@tonic-gate newtapebuf(ntrec);
2647c478bd9Sstevel@tonic-gate bct--; /* push back this block */
2657c478bd9Sstevel@tonic-gate blksread--;
2667c478bd9Sstevel@tonic-gate tapea--;
2677c478bd9Sstevel@tonic-gate /* we have to re-do this in case checksum is wrong */
2687c478bd9Sstevel@tonic-gate if (gethead(&spcl) == FAIL) {
2697c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
2707c478bd9Sstevel@tonic-gate gettext("Volume is not in dump format\n"));
2717c478bd9Sstevel@tonic-gate done(1);
2727c478bd9Sstevel@tonic-gate }
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate if (vflag)
2757c478bd9Sstevel@tonic-gate byteorder_banner(byteorder, stdout);
2767c478bd9Sstevel@tonic-gate if (pipein) {
2777c478bd9Sstevel@tonic-gate endoftapemark.s_spcl.c_magic = cvtflag ? OFS_MAGIC :
2787c478bd9Sstevel@tonic-gate ((tp_bsize == TP_BSIZE_MIN) ? NFS_MAGIC : MTB_MAGIC);
2797c478bd9Sstevel@tonic-gate endoftapemark.s_spcl.c_type = TS_END;
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate /*
2827c478bd9Sstevel@tonic-gate * include this since the `resync' loop in findinode
2837c478bd9Sstevel@tonic-gate * expects to find a header with the c_date field
2847c478bd9Sstevel@tonic-gate * filled in.
2857c478bd9Sstevel@tonic-gate */
2867c478bd9Sstevel@tonic-gate endoftapemark.s_spcl.c_date = spcl.c_date;
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate ip = (int32_t *)&endoftapemark;
2897c478bd9Sstevel@tonic-gate /*LINTED [assertion always true]*/
2907c478bd9Sstevel@tonic-gate assert((sizeof (endoftapemark) % sizeof (int32_t)) == 0);
2917c478bd9Sstevel@tonic-gate j = sizeof (endoftapemark) / sizeof (int32_t);
2927c478bd9Sstevel@tonic-gate i = 0;
2937c478bd9Sstevel@tonic-gate do
2947c478bd9Sstevel@tonic-gate i += *ip++;
295294baf98Sbatschul while (--j)
296294baf98Sbatschul ;
2977c478bd9Sstevel@tonic-gate endoftapemark.s_spcl.c_checksum = CHECKSUM - i;
2987c478bd9Sstevel@tonic-gate }
2997c478bd9Sstevel@tonic-gate if (vflag && command != 't')
3007c478bd9Sstevel@tonic-gate printdumpinfo();
3017c478bd9Sstevel@tonic-gate dumptime = spcl.c_ddate;
3027c478bd9Sstevel@tonic-gate dumpdate = spcl.c_date;
3037c478bd9Sstevel@tonic-gate if (stat(".", &stbuf) < 0) {
3047c478bd9Sstevel@tonic-gate perror(gettext("cannot stat ."));
3057c478bd9Sstevel@tonic-gate done(1);
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate if (stbuf.st_blksize >= tp_bsize && stbuf.st_blksize <= MAXBSIZE) {
3087c478bd9Sstevel@tonic-gate /* LINTED: value fits in a size_t */
3097c478bd9Sstevel@tonic-gate fssize = stbuf.st_blksize;
310294baf98Sbatschul } else {
311294baf98Sbatschul fssize = MAXBSIZE;
3127c478bd9Sstevel@tonic-gate }
313294baf98Sbatschul
3147c478bd9Sstevel@tonic-gate if (checkvol(&spcl, 1) == FAIL) {
3157c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
3167c478bd9Sstevel@tonic-gate gettext("This is not volume 1 of the dump\n"));
3177c478bd9Sstevel@tonic-gate done(1);
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate if (readhdr(&spcl) == FAIL)
3207c478bd9Sstevel@tonic-gate panic(gettext("no header after volume mark!\n"));
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate findinode(&spcl); /* sets curfile, resyncs the tape if need be */
3237c478bd9Sstevel@tonic-gate if (checktype(&spcl, TS_CLRI) == FAIL) {
3247c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
3257c478bd9Sstevel@tonic-gate gettext("Cannot find file removal list\n"));
3267c478bd9Sstevel@tonic-gate done(1);
3277c478bd9Sstevel@tonic-gate }
3287c478bd9Sstevel@tonic-gate maxino = (unsigned)((spcl.c_count * tp_bsize * NBBY) + 1);
3297c478bd9Sstevel@tonic-gate dprintf(stdout, "maxino = %lu\n", maxino);
3307c478bd9Sstevel@tonic-gate /*
3317c478bd9Sstevel@tonic-gate * Allocate space for at least MAXINO inodes to allow us
3327c478bd9Sstevel@tonic-gate * to restore partial dump tapes written before dump was
3337c478bd9Sstevel@tonic-gate * fixed to write out the entire inode map.
3347c478bd9Sstevel@tonic-gate */
3357c478bd9Sstevel@tonic-gate if (maxino > ULONG_MAX) {
3367c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
3377c478bd9Sstevel@tonic-gate gettext("file system too large\n"));
3387c478bd9Sstevel@tonic-gate done(1);
3397c478bd9Sstevel@tonic-gate }
3407c478bd9Sstevel@tonic-gate /* LINTED maxino size-checked above */
3417c478bd9Sstevel@tonic-gate mapsize = (size_t)d_howmany(maxino > MAXINO ? maxino : MAXINO, NBBY);
3427c478bd9Sstevel@tonic-gate beginmap = map = calloc((size_t)1, mapsize);
3437c478bd9Sstevel@tonic-gate if (map == (char *)NIL) {
3447c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
3457c478bd9Sstevel@tonic-gate gettext("no memory for file removal list\n"));
3467c478bd9Sstevel@tonic-gate done(1);
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate endmap = map + mapsize;
3497c478bd9Sstevel@tonic-gate clrimap = map;
3507c478bd9Sstevel@tonic-gate curfile.action = USING;
3517c478bd9Sstevel@tonic-gate continuemap = 1;
3527c478bd9Sstevel@tonic-gate getfile(xtrmap, xtrmapskip);
3537c478bd9Sstevel@tonic-gate if (MAXINO > maxino)
3547c478bd9Sstevel@tonic-gate maxino = MAXINO;
3557c478bd9Sstevel@tonic-gate if (checktype(&spcl, TS_BITS) == FAIL) {
3567c478bd9Sstevel@tonic-gate /* if we have TS_CLRI then no TS_BITS then a TS_END */
3577c478bd9Sstevel@tonic-gate /* then we have an empty dump file */
358294baf98Sbatschul if (gethead(&spcl) == GOOD &&
359294baf98Sbatschul checktype(&spcl, TS_END) == GOOD) {
3607c478bd9Sstevel@tonic-gate if ((command == 'r') || (command == 'R')) {
3617c478bd9Sstevel@tonic-gate initsymtable(syment);
3627c478bd9Sstevel@tonic-gate dumpsymtable(syment, volno);
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate done(0);
3657c478bd9Sstevel@tonic-gate }
3667c478bd9Sstevel@tonic-gate /* otherwise we have an error */
3677c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Cannot find file dump list\n"));
3687c478bd9Sstevel@tonic-gate done(1);
3697c478bd9Sstevel@tonic-gate }
3707c478bd9Sstevel@tonic-gate /* LINTED maxino size-checked above */
3717c478bd9Sstevel@tonic-gate mapsize = (size_t)d_howmany(maxino, NBBY);
3727c478bd9Sstevel@tonic-gate beginmap = map = calloc((size_t)1, mapsize);
3737c478bd9Sstevel@tonic-gate if (map == (char *)NULL) {
3747c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
3757c478bd9Sstevel@tonic-gate gettext("no memory for file dump list\n"));
3767c478bd9Sstevel@tonic-gate done(1);
3777c478bd9Sstevel@tonic-gate }
3787c478bd9Sstevel@tonic-gate endmap = map + mapsize;
3797c478bd9Sstevel@tonic-gate dumpmap = map;
3807c478bd9Sstevel@tonic-gate curfile.action = USING;
3817c478bd9Sstevel@tonic-gate continuemap = 1;
3827c478bd9Sstevel@tonic-gate getfile(xtrmap, xtrmapskip);
3837c478bd9Sstevel@tonic-gate continuemap = 0;
3847c478bd9Sstevel@tonic-gate }
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate /*
3877c478bd9Sstevel@tonic-gate * Initialize fssize variable for 'R' command to work.
3887c478bd9Sstevel@tonic-gate */
3897c478bd9Sstevel@tonic-gate void
setupR(void)3907c478bd9Sstevel@tonic-gate setupR(void)
3917c478bd9Sstevel@tonic-gate {
3927c478bd9Sstevel@tonic-gate struct stat stbuf;
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate if (stat(".", &stbuf) < 0) {
3957c478bd9Sstevel@tonic-gate perror(gettext("cannot stat ."));
3967c478bd9Sstevel@tonic-gate done(1);
3977c478bd9Sstevel@tonic-gate }
3987c478bd9Sstevel@tonic-gate if (stbuf.st_blksize >= tp_bsize && stbuf.st_blksize <= MAXBSIZE) {
3997c478bd9Sstevel@tonic-gate /* LINTED: value fits in a size_t */
4007c478bd9Sstevel@tonic-gate fssize = stbuf.st_blksize;
401294baf98Sbatschul } else {
402294baf98Sbatschul fssize = MAXBSIZE;
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate }
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate /*
4077c478bd9Sstevel@tonic-gate * Prompt user to load a new dump volume.
4087c478bd9Sstevel@tonic-gate * "Nextvol" is the next suggested volume to use.
4097c478bd9Sstevel@tonic-gate * This suggested volume is enforced when doing full
4107c478bd9Sstevel@tonic-gate * or incremental restores, but can be overrridden by
4117c478bd9Sstevel@tonic-gate * the user when only extracting a subset of the files.
4127c478bd9Sstevel@tonic-gate *
4137c478bd9Sstevel@tonic-gate * first_time is used with archive files and can have 1 of 3 states:
4147c478bd9Sstevel@tonic-gate * FT_STATE_1 Tape has not been read yet
4157c478bd9Sstevel@tonic-gate * FT_STATE_2 Tape has been read but not positioned past directory
4167c478bd9Sstevel@tonic-gate * information
4177c478bd9Sstevel@tonic-gate * FT_STATE_3 Tape has been read and is reading file information
4187c478bd9Sstevel@tonic-gate */
4197c478bd9Sstevel@tonic-gate #define FT_STATE_1 1
4207c478bd9Sstevel@tonic-gate #define FT_STATE_2 2
4217c478bd9Sstevel@tonic-gate #define FT_STATE_3 3
4227c478bd9Sstevel@tonic-gate
4237c478bd9Sstevel@tonic-gate void
getvol(int nextvol)424fe0e7ec4Smaheshvs getvol(int nextvol)
4257c478bd9Sstevel@tonic-gate {
4267c478bd9Sstevel@tonic-gate int newvol;
4277c478bd9Sstevel@tonic-gate long savecnt, savetapea, wantnext;
4287c478bd9Sstevel@tonic-gate long i;
4297c478bd9Sstevel@tonic-gate union u_spcl tmpspcl;
4307c478bd9Sstevel@tonic-gate #define tmpbuf tmpspcl.s_spcl
4317c478bd9Sstevel@tonic-gate char buf[TP_BSIZE_MAX];
4327c478bd9Sstevel@tonic-gate static int first_time = FT_STATE_1;
4337c478bd9Sstevel@tonic-gate
4347c478bd9Sstevel@tonic-gate if (tbf == NULL) {
4357c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
4367c478bd9Sstevel@tonic-gate "Internal consistency failure in getvol: tbf is NULL\n"));
4377c478bd9Sstevel@tonic-gate done(1);
4387c478bd9Sstevel@tonic-gate }
4397c478bd9Sstevel@tonic-gate
4407c478bd9Sstevel@tonic-gate if (nextvol == 1) {
4417c478bd9Sstevel@tonic-gate for (i = 0; i < MAXTAPES; i++)
4427c478bd9Sstevel@tonic-gate tapesread[i] = 0;
4437c478bd9Sstevel@tonic-gate gettingfile = 0;
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate if (pipein) {
4467c478bd9Sstevel@tonic-gate if (nextvol != 1)
4477c478bd9Sstevel@tonic-gate panic(gettext("changing volumes on pipe input\n"));
4487c478bd9Sstevel@tonic-gate if (volno == 1)
4497c478bd9Sstevel@tonic-gate return;
4507c478bd9Sstevel@tonic-gate goto gethdr;
4517c478bd9Sstevel@tonic-gate }
4527c478bd9Sstevel@tonic-gate savecnt = blksread; /* ignore volume verification tape i/o */
4537c478bd9Sstevel@tonic-gate savetapea = tapea;
4547c478bd9Sstevel@tonic-gate again:
4557c478bd9Sstevel@tonic-gate if (pipein)
4567c478bd9Sstevel@tonic-gate done(1); /* pipes do not get a second chance */
4577c478bd9Sstevel@tonic-gate if (command == 'R' || command == 'r' || curfile.action != SKIP) {
4587c478bd9Sstevel@tonic-gate wantnext = 1;
4597c478bd9Sstevel@tonic-gate newvol = nextvol;
4607c478bd9Sstevel@tonic-gate } else {
4617c478bd9Sstevel@tonic-gate wantnext = 0;
4627c478bd9Sstevel@tonic-gate newvol = 0;
4637c478bd9Sstevel@tonic-gate }
4647c478bd9Sstevel@tonic-gate
4657c478bd9Sstevel@tonic-gate if (autoload) {
4667c478bd9Sstevel@tonic-gate if ((volno == 1) && (nextvol == 1)) {
4677c478bd9Sstevel@tonic-gate tapesread[volno-1]++;
4687c478bd9Sstevel@tonic-gate return;
4697c478bd9Sstevel@tonic-gate }
4707c478bd9Sstevel@tonic-gate if (autoload_tape()) {
4712720c984Svk wantnext = 1;
4722720c984Svk newvol = nextvol;
4737c478bd9Sstevel@tonic-gate goto gethdr;
4747c478bd9Sstevel@tonic-gate }
4757c478bd9Sstevel@tonic-gate }
4767c478bd9Sstevel@tonic-gate
4777c478bd9Sstevel@tonic-gate while (newvol <= 0) {
4787c478bd9Sstevel@tonic-gate int n = 0;
4797c478bd9Sstevel@tonic-gate
4807c478bd9Sstevel@tonic-gate for (i = 0; i < MAXTAPES; i++)
4817c478bd9Sstevel@tonic-gate if (tapesread[i])
4827c478bd9Sstevel@tonic-gate n++;
4837c478bd9Sstevel@tonic-gate if (n == 0) {
4847c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s", gettext(
4857c478bd9Sstevel@tonic-gate "You have not read any volumes yet.\n\
4867c478bd9Sstevel@tonic-gate Unless you know which volume your file(s) are on you should start\n\
4877c478bd9Sstevel@tonic-gate with the last volume and work towards the first.\n"));
4887c478bd9Sstevel@tonic-gate } else {
4897c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
4907c478bd9Sstevel@tonic-gate gettext("You have read volumes"));
4917c478bd9Sstevel@tonic-gate (void) strcpy(tbf, ": ");
4927c478bd9Sstevel@tonic-gate for (i = 0; i < MAXTAPES; i++)
4937c478bd9Sstevel@tonic-gate if (tapesread[i]) {
4947c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s%ld",
4957c478bd9Sstevel@tonic-gate tbf, i+1);
4967c478bd9Sstevel@tonic-gate (void) strcpy(tbf, ", ");
4977c478bd9Sstevel@tonic-gate }
4987c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\n");
4997c478bd9Sstevel@tonic-gate }
5007c478bd9Sstevel@tonic-gate do {
5017c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
5027c478bd9Sstevel@tonic-gate gettext("Specify next volume #: "));
5037c478bd9Sstevel@tonic-gate (void) fflush(stderr);
5047c478bd9Sstevel@tonic-gate /* LINTED tbfsize is limited to a few MB */
5057c478bd9Sstevel@tonic-gate (void) fgets(tbf, (int)tbfsize, terminal);
5067c478bd9Sstevel@tonic-gate } while (!feof(terminal) && tbf[0] == '\n');
5077c478bd9Sstevel@tonic-gate if (feof(terminal))
5087c478bd9Sstevel@tonic-gate done(1);
5097c478bd9Sstevel@tonic-gate newvol = atoi(tbf);
5107c478bd9Sstevel@tonic-gate if (newvol <= 0) {
5117c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
5127c478bd9Sstevel@tonic-gate "Volume numbers are positive numerics\n"));
5137c478bd9Sstevel@tonic-gate }
5147c478bd9Sstevel@tonic-gate if (newvol > MAXTAPES) {
5157c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
5167c478bd9Sstevel@tonic-gate "This program can only deal with %d volumes\n"),
5177c478bd9Sstevel@tonic-gate MAXTAPES);
5187c478bd9Sstevel@tonic-gate newvol = 0;
5197c478bd9Sstevel@tonic-gate }
5207c478bd9Sstevel@tonic-gate }
5217c478bd9Sstevel@tonic-gate if (newvol == volno) {
5227c478bd9Sstevel@tonic-gate tapesread[volno-1]++;
5237c478bd9Sstevel@tonic-gate return;
5247c478bd9Sstevel@tonic-gate }
52533a5e6b2Srm closemt(ALLOW_OFFLINE);
5267c478bd9Sstevel@tonic-gate /*
5277c478bd9Sstevel@tonic-gate * XXX: if we are switching devices, we should probably try
5287c478bd9Sstevel@tonic-gate * the device once without prompting to enable unattended
5297c478bd9Sstevel@tonic-gate * operation.
5307c478bd9Sstevel@tonic-gate */
5317c478bd9Sstevel@tonic-gate if (host)
5327c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
5337c478bd9Sstevel@tonic-gate "Mount volume %d\nthen enter volume name on host %s (default: %s) "),
5347c478bd9Sstevel@tonic-gate newvol, host, magtape);
5357c478bd9Sstevel@tonic-gate else
5367c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
5377c478bd9Sstevel@tonic-gate "Mount volume %d\nthen enter volume name (default: %s) "),
5387c478bd9Sstevel@tonic-gate newvol, magtape);
5397c478bd9Sstevel@tonic-gate (void) fflush(stderr);
5407c478bd9Sstevel@tonic-gate /* LINTED tbfsize is limited to a few MB */
5417c478bd9Sstevel@tonic-gate (void) fgets(tbf, (int)tbfsize, terminal);
5427c478bd9Sstevel@tonic-gate if (feof(terminal))
5437c478bd9Sstevel@tonic-gate done(1);
5447c478bd9Sstevel@tonic-gate /*
5457c478bd9Sstevel@tonic-gate * XXX We don't allow rotating among tape hosts, just drives.
5467c478bd9Sstevel@tonic-gate */
5477c478bd9Sstevel@tonic-gate if (tbf[0] != '\n') {
5487c478bd9Sstevel@tonic-gate (void) strncpy(magtape, tbf, sizeof (magtape));
5497c478bd9Sstevel@tonic-gate magtape[sizeof (magtape) - 1] = '\0';
5507c478bd9Sstevel@tonic-gate /* LINTED unsigned -> signed conversion ok */
5517c478bd9Sstevel@tonic-gate i = (int)strlen(magtape);
5527c478bd9Sstevel@tonic-gate if (magtape[i - 1] == '\n')
5537c478bd9Sstevel@tonic-gate magtape[i - 1] = '\0';
5547c478bd9Sstevel@tonic-gate }
5557c478bd9Sstevel@tonic-gate if ((host != NULL && (mt = rmtopen(magtape, O_RDONLY)) == -1) ||
5567c478bd9Sstevel@tonic-gate (host == NULL &&
5572720c984Svk (mt = open(magtape, O_RDONLY|O_LARGEFILE)) == -1)) {
5587c478bd9Sstevel@tonic-gate int error = errno;
5597c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Cannot open %s: %s\n"),
5607c478bd9Sstevel@tonic-gate magtape, strerror(error));
5617c478bd9Sstevel@tonic-gate volno = -1;
5627c478bd9Sstevel@tonic-gate goto again;
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate gethdr:
5657c478bd9Sstevel@tonic-gate volno = newvol;
5667c478bd9Sstevel@tonic-gate setdumpnum();
5677c478bd9Sstevel@tonic-gate flsht();
5687c478bd9Sstevel@tonic-gate if (!pipein && !bflag && archivefile && (first_time == FT_STATE_1)) {
5697c478bd9Sstevel@tonic-gate first_time = FT_STATE_2;
5707c478bd9Sstevel@tonic-gate findtapeblksize(TAPE_FILE);
5717c478bd9Sstevel@tonic-gate }
5727c478bd9Sstevel@tonic-gate if (readhdr(&tmpbuf) == FAIL) {
5737c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
5747c478bd9Sstevel@tonic-gate gettext("volume is not in dump format\n"));
5757c478bd9Sstevel@tonic-gate volno = 0;
5767c478bd9Sstevel@tonic-gate goto again;
5777c478bd9Sstevel@tonic-gate }
5787c478bd9Sstevel@tonic-gate if (checkvol(&tmpbuf, volno) == FAIL) {
5797c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Wrong volume (%d)\n"),
5807c478bd9Sstevel@tonic-gate tmpbuf.c_volume);
5817c478bd9Sstevel@tonic-gate volno = 0;
5827c478bd9Sstevel@tonic-gate goto again;
5837c478bd9Sstevel@tonic-gate }
5847c478bd9Sstevel@tonic-gate
5857c478bd9Sstevel@tonic-gate if (((time_t)(tmpbuf.c_date) != dumpdate) ||
5867c478bd9Sstevel@tonic-gate ((time_t)(tmpbuf.c_ddate) != dumptime)) {
5877c478bd9Sstevel@tonic-gate char *tmp_ct;
5887c478bd9Sstevel@tonic-gate time_t lc_date = (time_t)tmpbuf.c_date;
5897c478bd9Sstevel@tonic-gate
5907c478bd9Sstevel@tonic-gate /*
5917c478bd9Sstevel@tonic-gate * This is used to save the return value from lctime(),
5927c478bd9Sstevel@tonic-gate * since that's volatile across lctime() invocations.
5937c478bd9Sstevel@tonic-gate */
5947c478bd9Sstevel@tonic-gate tmp_ct = strdup(lctime(&lc_date));
5957c478bd9Sstevel@tonic-gate if (tmp_ct == (char *)0) {
5967c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
5977c478bd9Sstevel@tonic-gate "Cannot allocate space for time string\n"));
5987c478bd9Sstevel@tonic-gate done(1);
5997c478bd9Sstevel@tonic-gate }
6007c478bd9Sstevel@tonic-gate
6017c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
6027c478bd9Sstevel@tonic-gate gettext("Wrong dump date\n\tgot: %s\twanted: %s"),
6037c478bd9Sstevel@tonic-gate tmp_ct, lctime(&dumpdate));
6047c478bd9Sstevel@tonic-gate volno = 0;
6057c478bd9Sstevel@tonic-gate free(tmp_ct);
6067c478bd9Sstevel@tonic-gate goto again;
6077c478bd9Sstevel@tonic-gate }
6087c478bd9Sstevel@tonic-gate tapesread[volno-1]++;
6097c478bd9Sstevel@tonic-gate blksread = savecnt;
6107c478bd9Sstevel@tonic-gate tapea = savetapea;
6117c478bd9Sstevel@tonic-gate /*
6127c478bd9Sstevel@tonic-gate * If continuing from the previous volume, skip over any
6137c478bd9Sstevel@tonic-gate * blocks read already at the end of the previous volume.
6147c478bd9Sstevel@tonic-gate *
6157c478bd9Sstevel@tonic-gate * If coming to this volume at random, skip to the beginning
6167c478bd9Sstevel@tonic-gate * of the next record.
6177c478bd9Sstevel@tonic-gate */
6187c478bd9Sstevel@tonic-gate if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) {
6197c478bd9Sstevel@tonic-gate if (!wantnext) {
6207c478bd9Sstevel@tonic-gate if (archivefile && first_time == FT_STATE_2) {
6217c478bd9Sstevel@tonic-gate first_time = FT_STATE_3;
6227c478bd9Sstevel@tonic-gate }
6237c478bd9Sstevel@tonic-gate recsread = tmpbuf.c_firstrec;
6247c478bd9Sstevel@tonic-gate tapea = tmpbuf.c_tapea;
6257c478bd9Sstevel@tonic-gate dprintf(stdout,
6267c478bd9Sstevel@tonic-gate "restore skipping %d records\n",
6277c478bd9Sstevel@tonic-gate tmpbuf.c_count);
6287c478bd9Sstevel@tonic-gate for (i = tmpbuf.c_count; i > 0; i--)
6297c478bd9Sstevel@tonic-gate readtape(buf);
6307c478bd9Sstevel@tonic-gate } else if (tmpbuf.c_firstrec != 0) {
6317c478bd9Sstevel@tonic-gate savecnt = blksread;
6327c478bd9Sstevel@tonic-gate savetapea = tapea;
6337c478bd9Sstevel@tonic-gate
6347c478bd9Sstevel@tonic-gate if (archivefile && first_time == FT_STATE_2) {
6357c478bd9Sstevel@tonic-gate /*
6367c478bd9Sstevel@tonic-gate * subtract 2, 1 for archive file's TS_END
6377c478bd9Sstevel@tonic-gate * and 1 for tape's TS_TAPE
6387c478bd9Sstevel@tonic-gate */
6397c478bd9Sstevel@tonic-gate first_time = FT_STATE_3;
6407c478bd9Sstevel@tonic-gate i = tapea - tmpbuf.c_tapea - 2;
6417c478bd9Sstevel@tonic-gate } else {
6427c478bd9Sstevel@tonic-gate i = tapea - tmpbuf.c_tapea;
6437c478bd9Sstevel@tonic-gate }
6447c478bd9Sstevel@tonic-gate if (i > 0)
6457c478bd9Sstevel@tonic-gate dprintf(stdout, gettext(
6467c478bd9Sstevel@tonic-gate "restore skipping %d duplicate records\n"),
6472720c984Svk i);
6487c478bd9Sstevel@tonic-gate else if (i < 0)
6497c478bd9Sstevel@tonic-gate dprintf(stdout, gettext(
6507c478bd9Sstevel@tonic-gate "restore duplicate record botch (%d)\n"),
6512720c984Svk i);
6527c478bd9Sstevel@tonic-gate while (--i >= 0)
6537c478bd9Sstevel@tonic-gate readtape(buf);
6547c478bd9Sstevel@tonic-gate blksread = savecnt;
6557c478bd9Sstevel@tonic-gate tapea = savetapea + 1; /* <= (void) gethead() below */
6567c478bd9Sstevel@tonic-gate }
6577c478bd9Sstevel@tonic-gate }
6587c478bd9Sstevel@tonic-gate if (curfile.action == USING) {
6597c478bd9Sstevel@tonic-gate if (volno == 1)
6607c478bd9Sstevel@tonic-gate panic(gettext("active file into volume 1\n"));
6617c478bd9Sstevel@tonic-gate return;
6627c478bd9Sstevel@tonic-gate }
6637c478bd9Sstevel@tonic-gate (void) gethead(&spcl);
6647c478bd9Sstevel@tonic-gate findinode(&spcl); /* do we always restart files in full? */
6657c478bd9Sstevel@tonic-gate if (gettingfile) { /* i.e. will we lose metadata? */
6667c478bd9Sstevel@tonic-gate gettingfile = 0;
6677c478bd9Sstevel@tonic-gate longjmp(restart, 1); /* will this set f1 & f2? */
6687c478bd9Sstevel@tonic-gate }
6697c478bd9Sstevel@tonic-gate }
6707c478bd9Sstevel@tonic-gate
6717c478bd9Sstevel@tonic-gate /*
6727c478bd9Sstevel@tonic-gate * handle multiple dumps per tape by skipping forward to the
6737c478bd9Sstevel@tonic-gate * appropriate one. Note we don't use absolute positioning,
6747c478bd9Sstevel@tonic-gate * as that may take a very long time.
6757c478bd9Sstevel@tonic-gate */
6767c478bd9Sstevel@tonic-gate static void
setdumpnum(void)6777c478bd9Sstevel@tonic-gate setdumpnum(void)
6787c478bd9Sstevel@tonic-gate {
6797c478bd9Sstevel@tonic-gate struct mtop tcom;
6807c478bd9Sstevel@tonic-gate int retval;
6817c478bd9Sstevel@tonic-gate
6827c478bd9Sstevel@tonic-gate if (dumpnum == 1 || volno != 1)
6837c478bd9Sstevel@tonic-gate return;
6847c478bd9Sstevel@tonic-gate if (pipein) {
6857c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
6867c478bd9Sstevel@tonic-gate gettext("Cannot have multiple dumps on pipe input\n"));
6877c478bd9Sstevel@tonic-gate done(1);
6887c478bd9Sstevel@tonic-gate }
6897c478bd9Sstevel@tonic-gate tcom.mt_op = MTFSF;
6907c478bd9Sstevel@tonic-gate tcom.mt_count = dumpnum - 1;
6917c478bd9Sstevel@tonic-gate if (host)
6927c478bd9Sstevel@tonic-gate retval = rmtioctl(MTFSF, dumpnum - 1);
6937c478bd9Sstevel@tonic-gate else
6947c478bd9Sstevel@tonic-gate retval = ioctl(mt, (int)MTIOCTOP, (char *)&tcom);
6957c478bd9Sstevel@tonic-gate if (retval < 0)
6967c478bd9Sstevel@tonic-gate perror("ioctl MTFSF");
6977c478bd9Sstevel@tonic-gate }
6987c478bd9Sstevel@tonic-gate
6997c478bd9Sstevel@tonic-gate void
printdumpinfo(void)7007c478bd9Sstevel@tonic-gate printdumpinfo(void)
7017c478bd9Sstevel@tonic-gate {
7027c478bd9Sstevel@tonic-gate int i;
7037c478bd9Sstevel@tonic-gate time_t date;
7047c478bd9Sstevel@tonic-gate static char *epoch = NULL;
7057c478bd9Sstevel@tonic-gate
7067c478bd9Sstevel@tonic-gate if (epoch == NULL) {
7077c478bd9Sstevel@tonic-gate epoch = strdup(gettext("the epoch\n"));
7087c478bd9Sstevel@tonic-gate if (epoch == NULL) {
7097c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Out of memory\n"));
7107c478bd9Sstevel@tonic-gate return;
7117c478bd9Sstevel@tonic-gate }
7127c478bd9Sstevel@tonic-gate }
7137c478bd9Sstevel@tonic-gate
7147c478bd9Sstevel@tonic-gate date = (time_t)dumpinfo.c_date;
7157c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
7167c478bd9Sstevel@tonic-gate gettext("Dump date: %s"), lctime(&date));
7177c478bd9Sstevel@tonic-gate
7187c478bd9Sstevel@tonic-gate date = (time_t)dumpinfo.c_ddate;
7197c478bd9Sstevel@tonic-gate (void) fprintf(stdout, gettext("Dumped from: %s"),
7207c478bd9Sstevel@tonic-gate (dumpinfo.c_ddate == 0) ? epoch : lctime(&date));
7217c478bd9Sstevel@tonic-gate if (hostinfo) {
7227c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
7237c478bd9Sstevel@tonic-gate gettext("Level %d dump of %s on %.*s:%s\n"),
7247c478bd9Sstevel@tonic-gate dumpinfo.c_level, dumpinfo.c_filesys,
7257c478bd9Sstevel@tonic-gate sizeof (dumpinfo.c_host), dumpinfo.c_host, dumpinfo.c_dev);
7267c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
7277c478bd9Sstevel@tonic-gate gettext("Label: %.*s\n"),
7287c478bd9Sstevel@tonic-gate sizeof (dumpinfo.c_label), dumpinfo.c_label);
7297c478bd9Sstevel@tonic-gate }
7307c478bd9Sstevel@tonic-gate if (inodeinfo) {
7317c478bd9Sstevel@tonic-gate (void) fprintf(stdout,
7327c478bd9Sstevel@tonic-gate gettext("Starting inode numbers by volume:\n"));
7337c478bd9Sstevel@tonic-gate for (i = 1; i <= dumpinfo.c_volume; i++)
7347c478bd9Sstevel@tonic-gate (void) fprintf(stdout, gettext("\tVolume %d: %6d\n"),
7357c478bd9Sstevel@tonic-gate i, dumpinfo.c_inos[i]);
7367c478bd9Sstevel@tonic-gate }
7377c478bd9Sstevel@tonic-gate }
7387c478bd9Sstevel@tonic-gate
739fe0e7ec4Smaheshvs int
extractfile(char * name)740fe0e7ec4Smaheshvs extractfile(char *name)
7417c478bd9Sstevel@tonic-gate {
7427c478bd9Sstevel@tonic-gate static int complained_chown = 0;
7437c478bd9Sstevel@tonic-gate static int complained_lchown = 0;
7447c478bd9Sstevel@tonic-gate static int complained_chmod = 0;
7457c478bd9Sstevel@tonic-gate static int complained_utime = 0;
7467c478bd9Sstevel@tonic-gate static int complained_mknod = 0;
7477c478bd9Sstevel@tonic-gate mode_t mode;
7487c478bd9Sstevel@tonic-gate time_t timep[2];
7497c478bd9Sstevel@tonic-gate struct entry *ep;
7507c478bd9Sstevel@tonic-gate uid_t uid;
7517c478bd9Sstevel@tonic-gate gid_t gid;
7527c478bd9Sstevel@tonic-gate char *errmsg;
7537c478bd9Sstevel@tonic-gate int result, saverr;
7547c478bd9Sstevel@tonic-gate dev_t full_dev;
7557c478bd9Sstevel@tonic-gate int dfd;
7567c478bd9Sstevel@tonic-gate char *rname;
7577c478bd9Sstevel@tonic-gate
7587c478bd9Sstevel@tonic-gate curfile.name = name;
7597c478bd9Sstevel@tonic-gate curfile.action = USING;
7607c478bd9Sstevel@tonic-gate timep[0] = (time_t)curfile.dip->di_atime;
7617c478bd9Sstevel@tonic-gate timep[1] = (time_t)curfile.dip->di_mtime;
7627c478bd9Sstevel@tonic-gate mode = curfile.dip->di_mode;
7637c478bd9Sstevel@tonic-gate
7647c478bd9Sstevel@tonic-gate uid = curfile.dip->di_suid == UID_LONG ?
7652720c984Svk curfile.dip->di_uid : (uid_t)curfile.dip->di_suid;
7667c478bd9Sstevel@tonic-gate gid = curfile.dip->di_sgid == GID_LONG ?
7672720c984Svk curfile.dip->di_gid : (gid_t)curfile.dip->di_sgid;
7687c478bd9Sstevel@tonic-gate
7697c478bd9Sstevel@tonic-gate resolve(name, &dfd, &rname);
7707c478bd9Sstevel@tonic-gate if (dfd != AT_FDCWD) {
7717c478bd9Sstevel@tonic-gate if (fchdir(dfd) < 0) {
7727c478bd9Sstevel@tonic-gate saverr = errno;
7737c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
7742720c984Svk "%s: unable to set attribute context: %s\n"),
7752720c984Svk rname, strerror(saverr));
7767c478bd9Sstevel@tonic-gate skipfile();
7777c478bd9Sstevel@tonic-gate (void) close(dfd);
7787c478bd9Sstevel@tonic-gate return (FAIL);
7797c478bd9Sstevel@tonic-gate }
7807c478bd9Sstevel@tonic-gate }
7817c478bd9Sstevel@tonic-gate
7827c478bd9Sstevel@tonic-gate switch (mode & IFMT) {
7837c478bd9Sstevel@tonic-gate
7847c478bd9Sstevel@tonic-gate default:
7857c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: unknown file mode 0%lo\n"),
7867c478bd9Sstevel@tonic-gate rname, (ulong_t)(mode&IFMT));
7877c478bd9Sstevel@tonic-gate skipfile();
7887c478bd9Sstevel@tonic-gate result = FAIL;
7897c478bd9Sstevel@tonic-gate break;
7907c478bd9Sstevel@tonic-gate
7917c478bd9Sstevel@tonic-gate case IFSOCK:
7927c478bd9Sstevel@tonic-gate vprintf(stdout, gettext("skipped socket %s\n"), rname);
7937c478bd9Sstevel@tonic-gate skipfile();
7947c478bd9Sstevel@tonic-gate result = GOOD;
7957c478bd9Sstevel@tonic-gate break;
7967c478bd9Sstevel@tonic-gate
7977c478bd9Sstevel@tonic-gate case IFDIR:
7987c478bd9Sstevel@tonic-gate if (mflag) {
7997c478bd9Sstevel@tonic-gate ep = lookupname(name);
8007c478bd9Sstevel@tonic-gate if (ep == NIL || ep->e_flags & EXTRACT) {
8017c478bd9Sstevel@tonic-gate panic(gettext(
8027c478bd9Sstevel@tonic-gate "directory %s was not restored\n"),
8037c478bd9Sstevel@tonic-gate rname);
8047c478bd9Sstevel@tonic-gate skipfile();
8057c478bd9Sstevel@tonic-gate result = FAIL;
8067c478bd9Sstevel@tonic-gate break;
8077c478bd9Sstevel@tonic-gate }
8087c478bd9Sstevel@tonic-gate skipfile();
8097c478bd9Sstevel@tonic-gate result = GOOD;
8107c478bd9Sstevel@tonic-gate break;
8117c478bd9Sstevel@tonic-gate }
8127c478bd9Sstevel@tonic-gate vprintf(stdout, gettext("extract file %s\n"), rname);
8137c478bd9Sstevel@tonic-gate result = genliteraldir(rname, curfile.ino);
8147c478bd9Sstevel@tonic-gate break;
8157c478bd9Sstevel@tonic-gate
8167c478bd9Sstevel@tonic-gate case IFLNK:
8177c478bd9Sstevel@tonic-gate lnkbuf[0] = '\0';
8187c478bd9Sstevel@tonic-gate pathlen = 0;
8197c478bd9Sstevel@tonic-gate getfile(xtrlnkfile, xtrlnkskip);
8207c478bd9Sstevel@tonic-gate if (pathlen == 0) {
8217c478bd9Sstevel@tonic-gate vprintf(stdout, gettext(
8222720c984Svk "%s: zero length symbolic link (ignored)\n"),
8232720c984Svk rname);
8247c478bd9Sstevel@tonic-gate result = GOOD;
8257c478bd9Sstevel@tonic-gate break;
8267c478bd9Sstevel@tonic-gate }
8277c478bd9Sstevel@tonic-gate if ((result = lf_linkit(lnkbuf, rname, SYMLINK)) != GOOD)
8287c478bd9Sstevel@tonic-gate break;
8297c478bd9Sstevel@tonic-gate
8307c478bd9Sstevel@tonic-gate /* 1254700: set uid/gid (previously missing) */
8317c478bd9Sstevel@tonic-gate if (lchown(rname, uid, gid) < 0 && !complained_lchown) {
8327c478bd9Sstevel@tonic-gate /* Just a warning */
8337c478bd9Sstevel@tonic-gate saverr = errno;
8347c478bd9Sstevel@tonic-gate errmsg = gettext(
8357c478bd9Sstevel@tonic-gate "Unable to restore ownership of symlink %s: %s\n");
8367c478bd9Sstevel@tonic-gate (void) fprintf(stderr, errmsg,
8377c478bd9Sstevel@tonic-gate rname, strerror(saverr));
8387c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
8397c478bd9Sstevel@tonic-gate "Additional such failures will be ignored.\n"));
8407c478bd9Sstevel@tonic-gate complained_lchown = 1;
8417c478bd9Sstevel@tonic-gate }
8427c478bd9Sstevel@tonic-gate metaset(rname);
8437c478bd9Sstevel@tonic-gate result = GOOD;
8447c478bd9Sstevel@tonic-gate break;
8457c478bd9Sstevel@tonic-gate
8467c478bd9Sstevel@tonic-gate case IFCHR:
8477c478bd9Sstevel@tonic-gate case IFBLK:
8487c478bd9Sstevel@tonic-gate case IFIFO:
8497c478bd9Sstevel@tonic-gate vprintf(stdout, gettext("extract special file %s\n"), rname);
8507c478bd9Sstevel@tonic-gate /* put device rdev into dev_t expanded format */
8517c478bd9Sstevel@tonic-gate /* XXX does this always do the right thing? */
8527c478bd9Sstevel@tonic-gate /* XXX does dump do the right thing? */
8537c478bd9Sstevel@tonic-gate if (((curfile.dip->di_ordev & 0xFFFF0000) == 0) ||
8547c478bd9Sstevel@tonic-gate ((curfile.dip->di_ordev & 0xFFFF0000) == 0xFFFF0000)) {
8557c478bd9Sstevel@tonic-gate full_dev = expdev((unsigned)(curfile.dip->di_ordev));
8567c478bd9Sstevel@tonic-gate } else {
8577c478bd9Sstevel@tonic-gate /* LINTED sign extension ok */
8587c478bd9Sstevel@tonic-gate full_dev = (unsigned)(curfile.dip->di_ordev);
8597c478bd9Sstevel@tonic-gate }
8607c478bd9Sstevel@tonic-gate
861fe0e7ec4Smaheshvs if (mknod(rname, mode, full_dev) < 0) {
8627c478bd9Sstevel@tonic-gate struct stat64 s[1];
8637c478bd9Sstevel@tonic-gate
8647c478bd9Sstevel@tonic-gate saverr = errno;
8657c478bd9Sstevel@tonic-gate if ((stat64(rname, s)) ||
8667c478bd9Sstevel@tonic-gate ((s->st_mode & S_IFMT) != (mode & S_IFMT)) ||
8677c478bd9Sstevel@tonic-gate (s->st_rdev != full_dev)) {
8687c478bd9Sstevel@tonic-gate if (saverr != EPERM || !complained_mknod) {
8697c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: ", rname);
8707c478bd9Sstevel@tonic-gate (void) fflush(stderr);
8717c478bd9Sstevel@tonic-gate errno = saverr;
8727c478bd9Sstevel@tonic-gate perror(gettext(
8737c478bd9Sstevel@tonic-gate "cannot create special file"));
8747c478bd9Sstevel@tonic-gate if (saverr == EPERM) {
8757c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
8767c478bd9Sstevel@tonic-gate "Additional such failures will be ignored.\n"));
8777c478bd9Sstevel@tonic-gate complained_mknod = 1;
8787c478bd9Sstevel@tonic-gate }
8797c478bd9Sstevel@tonic-gate }
8807c478bd9Sstevel@tonic-gate skipfile();
8817c478bd9Sstevel@tonic-gate result = FAIL;
8827c478bd9Sstevel@tonic-gate break;
8837c478bd9Sstevel@tonic-gate }
8847c478bd9Sstevel@tonic-gate }
8857c478bd9Sstevel@tonic-gate if (chown(rname, uid, gid) < 0 && !complained_chown) {
8867c478bd9Sstevel@tonic-gate /* Just a warning */
8877c478bd9Sstevel@tonic-gate saverr = errno;
8887c478bd9Sstevel@tonic-gate errmsg = gettext(
8897c478bd9Sstevel@tonic-gate "Unable to restore ownership of %s: %s\n");
8907c478bd9Sstevel@tonic-gate (void) fprintf(stderr, errmsg,
8917c478bd9Sstevel@tonic-gate rname, strerror(saverr));
8927c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
8937c478bd9Sstevel@tonic-gate "Additional such failures will be ignored.\n"));
8947c478bd9Sstevel@tonic-gate complained_chown = 1;
8957c478bd9Sstevel@tonic-gate }
8967c478bd9Sstevel@tonic-gate if (chmod(rname, mode) < 0 && !complained_chmod) {
8977c478bd9Sstevel@tonic-gate saverr = errno;
8987c478bd9Sstevel@tonic-gate errmsg = gettext(
8997c478bd9Sstevel@tonic-gate "Unable to restore permissions on %s: %s\n");
9007c478bd9Sstevel@tonic-gate (void) fprintf(stderr, errmsg,
9017c478bd9Sstevel@tonic-gate rname, strerror(saverr));
9027c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
9037c478bd9Sstevel@tonic-gate "Additional such failures will be ignored.\n"));
9047c478bd9Sstevel@tonic-gate complained_chmod = 1;
9057c478bd9Sstevel@tonic-gate }
9067c478bd9Sstevel@tonic-gate skipfile();
9077c478bd9Sstevel@tonic-gate metaset(rname); /* skipfile() got the metadata, if any */
9087c478bd9Sstevel@tonic-gate if (utime(rname, (struct utimbuf *)timep) < 0 &&
9097c478bd9Sstevel@tonic-gate !complained_utime) {
9107c478bd9Sstevel@tonic-gate saverr = errno;
9117c478bd9Sstevel@tonic-gate errmsg = gettext(
9127c478bd9Sstevel@tonic-gate "Unable to restore times on %s: %s\n");
9137c478bd9Sstevel@tonic-gate (void) fprintf(stderr, errmsg,
9147c478bd9Sstevel@tonic-gate rname, strerror(saverr));
9157c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
9167c478bd9Sstevel@tonic-gate "Additional such failures will be ignored.\n"));
9177c478bd9Sstevel@tonic-gate complained_utime = 1;
9187c478bd9Sstevel@tonic-gate }
9197c478bd9Sstevel@tonic-gate result = GOOD;
9207c478bd9Sstevel@tonic-gate break;
9217c478bd9Sstevel@tonic-gate
9227c478bd9Sstevel@tonic-gate case IFREG:
9237c478bd9Sstevel@tonic-gate vprintf(stdout, gettext("extract file %s\n"), rname);
924294baf98Sbatschul
925294baf98Sbatschul /*
926294baf98Sbatschul * perform a restrictive creat(2) initally, we'll
927294baf98Sbatschul * fchmod(2) according to the archive later after
928294baf98Sbatschul * we've written the blocks.
929294baf98Sbatschul */
930294baf98Sbatschul ofile = creat64(rname, 0600);
9317c478bd9Sstevel@tonic-gate
9327c478bd9Sstevel@tonic-gate if (ofile < 0) {
9337c478bd9Sstevel@tonic-gate saverr = errno;
9347c478bd9Sstevel@tonic-gate errmsg = gettext("cannot create file");
9357c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: ", rname);
9367c478bd9Sstevel@tonic-gate (void) fflush(stderr);
9377c478bd9Sstevel@tonic-gate errno = saverr;
9387c478bd9Sstevel@tonic-gate perror(errmsg);
9397c478bd9Sstevel@tonic-gate skipfile();
9407c478bd9Sstevel@tonic-gate result = FAIL;
9417c478bd9Sstevel@tonic-gate break;
9427c478bd9Sstevel@tonic-gate }
9437c478bd9Sstevel@tonic-gate if (fchown(ofile, uid, gid) < 0 && !complained_chown) {
9447c478bd9Sstevel@tonic-gate /* Just a warning */
9457c478bd9Sstevel@tonic-gate saverr = errno;
9467c478bd9Sstevel@tonic-gate errmsg = gettext(
9477c478bd9Sstevel@tonic-gate "Unable to restore ownership of %s: %s\n");
9487c478bd9Sstevel@tonic-gate (void) fprintf(stderr, errmsg,
9497c478bd9Sstevel@tonic-gate rname, strerror(saverr));
9507c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
9517c478bd9Sstevel@tonic-gate "Additional such failures will be ignored.\n"));
9527c478bd9Sstevel@tonic-gate complained_chown = 1;
9537c478bd9Sstevel@tonic-gate }
954294baf98Sbatschul
955294baf98Sbatschul getfile(xtrfile, xtrskip);
956294baf98Sbatschul metaset(rname);
957294baf98Sbatschul
958294baf98Sbatschul /*
959294baf98Sbatschul * the fchmod(2) has to come after getfile() as some POSIX
960294baf98Sbatschul * implementations clear the S_ISUID and S_ISGID bits of the
961294baf98Sbatschul * file after every write(2).
962294baf98Sbatschul */
9637c478bd9Sstevel@tonic-gate if (fchmod(ofile, mode) < 0 && !complained_chmod) {
9647c478bd9Sstevel@tonic-gate saverr = errno;
9657c478bd9Sstevel@tonic-gate errmsg = gettext(
9667c478bd9Sstevel@tonic-gate "Unable to restore permissions on %s: %s\n");
9677c478bd9Sstevel@tonic-gate (void) fprintf(stderr, errmsg,
9687c478bd9Sstevel@tonic-gate rname, strerror(saverr));
9697c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
9707c478bd9Sstevel@tonic-gate "Additional such failures will be ignored.\n"));
9717c478bd9Sstevel@tonic-gate complained_chmod = 1;
9727c478bd9Sstevel@tonic-gate }
9737c478bd9Sstevel@tonic-gate
9747c478bd9Sstevel@tonic-gate /*
9757c478bd9Sstevel@tonic-gate * Some errors don't get reported until we close(2), so
9767c478bd9Sstevel@tonic-gate * check for them.
9777c478bd9Sstevel@tonic-gate * XXX unlink the file if an error is reported?
9787c478bd9Sstevel@tonic-gate */
9797c478bd9Sstevel@tonic-gate if (close(ofile) < 0) {
9807c478bd9Sstevel@tonic-gate saverr = errno;
9817c478bd9Sstevel@tonic-gate errmsg = gettext("error closing file");
9827c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: ", rname);
9837c478bd9Sstevel@tonic-gate (void) fflush(stderr);
9847c478bd9Sstevel@tonic-gate errno = saverr;
9857c478bd9Sstevel@tonic-gate perror(errmsg);
9867c478bd9Sstevel@tonic-gate result = FAIL;
9877c478bd9Sstevel@tonic-gate break;
9887c478bd9Sstevel@tonic-gate }
9897c478bd9Sstevel@tonic-gate if (utime(rname, (struct utimbuf *)timep) < 0 &&
9907c478bd9Sstevel@tonic-gate !complained_utime) {
9917c478bd9Sstevel@tonic-gate saverr = errno;
9927c478bd9Sstevel@tonic-gate errmsg = gettext(
9937c478bd9Sstevel@tonic-gate "Unable to restore times on %s: %s\n");
9947c478bd9Sstevel@tonic-gate (void) fprintf(stderr, errmsg,
9957c478bd9Sstevel@tonic-gate rname, strerror(saverr));
9967c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
9977c478bd9Sstevel@tonic-gate "Additional such failures will be ignored.\n"));
9987c478bd9Sstevel@tonic-gate complained_utime = 1;
9997c478bd9Sstevel@tonic-gate }
10007c478bd9Sstevel@tonic-gate
10017c478bd9Sstevel@tonic-gate result = GOOD;
10027c478bd9Sstevel@tonic-gate break;
10037c478bd9Sstevel@tonic-gate }
10047c478bd9Sstevel@tonic-gate if (dfd != AT_FDCWD) {
10057c478bd9Sstevel@tonic-gate fchdir(savepwd);
10067c478bd9Sstevel@tonic-gate (void) close(dfd);
10077c478bd9Sstevel@tonic-gate }
10087c478bd9Sstevel@tonic-gate return (result);
10097c478bd9Sstevel@tonic-gate }
10107c478bd9Sstevel@tonic-gate
10117c478bd9Sstevel@tonic-gate /*
10127c478bd9Sstevel@tonic-gate * skip over bit maps on the tape
10137c478bd9Sstevel@tonic-gate */
10147c478bd9Sstevel@tonic-gate void
skipmaps(void)10157c478bd9Sstevel@tonic-gate skipmaps(void)
10167c478bd9Sstevel@tonic-gate {
10177c478bd9Sstevel@tonic-gate continuemap = 1;
10187c478bd9Sstevel@tonic-gate while (checktype(&spcl, TS_CLRI) == GOOD ||
10197c478bd9Sstevel@tonic-gate checktype(&spcl, TS_BITS) == GOOD)
10207c478bd9Sstevel@tonic-gate skipfile();
10217c478bd9Sstevel@tonic-gate continuemap = 0;
10227c478bd9Sstevel@tonic-gate }
10237c478bd9Sstevel@tonic-gate
10247c478bd9Sstevel@tonic-gate /*
10257c478bd9Sstevel@tonic-gate * skip over a file on the tape
10267c478bd9Sstevel@tonic-gate */
10277c478bd9Sstevel@tonic-gate void
skipfile(void)10287c478bd9Sstevel@tonic-gate skipfile(void)
10297c478bd9Sstevel@tonic-gate {
10307c478bd9Sstevel@tonic-gate curfile.action = SKIP;
10317c478bd9Sstevel@tonic-gate getfile(null, null);
10327c478bd9Sstevel@tonic-gate }
10337c478bd9Sstevel@tonic-gate /*
10347c478bd9Sstevel@tonic-gate * Do the file extraction, calling the supplied functions
10357c478bd9Sstevel@tonic-gate * with the blocks
10367c478bd9Sstevel@tonic-gate */
10377c478bd9Sstevel@tonic-gate void
getfile(void (* f1)(),void (* f2)())1038fe0e7ec4Smaheshvs getfile(void (*f1)(), void (*f2)())
10397c478bd9Sstevel@tonic-gate {
10407c478bd9Sstevel@tonic-gate int i;
10417c478bd9Sstevel@tonic-gate size_t curblk = 0;
10427c478bd9Sstevel@tonic-gate offset_t size = (offset_t)spcl.c_dinode.di_size;
10437c478bd9Sstevel@tonic-gate static char clearedbuf[MAXBSIZE];
10447c478bd9Sstevel@tonic-gate char buf[TP_BSIZE_MAX];
10457c478bd9Sstevel@tonic-gate char *bufptr;
10467c478bd9Sstevel@tonic-gate char junk[TP_BSIZE_MAX];
10477c478bd9Sstevel@tonic-gate
10487c478bd9Sstevel@tonic-gate assert(MAXBSIZE >= tp_bsize);
10497c478bd9Sstevel@tonic-gate
10507c478bd9Sstevel@tonic-gate metaset(NULL); /* flush old metadata */
10517c478bd9Sstevel@tonic-gate if (checktype(&spcl, TS_END) == GOOD) {
10527c478bd9Sstevel@tonic-gate panic(gettext("ran off end of volume\n"));
10537c478bd9Sstevel@tonic-gate return;
10547c478bd9Sstevel@tonic-gate }
10557c478bd9Sstevel@tonic-gate if (ishead(&spcl) == FAIL) {
10567c478bd9Sstevel@tonic-gate panic(gettext("not at beginning of a file\n"));
10577c478bd9Sstevel@tonic-gate return;
10587c478bd9Sstevel@tonic-gate }
10597c478bd9Sstevel@tonic-gate metacheck(&spcl); /* check for metadata in header */
10607c478bd9Sstevel@tonic-gate if (!gettingfile && setjmp(restart) != 0) {
10617c478bd9Sstevel@tonic-gate gettingfile = 0; /* paranoia; longjmp'er should do */
10627c478bd9Sstevel@tonic-gate return;
10637c478bd9Sstevel@tonic-gate }
10647c478bd9Sstevel@tonic-gate gettingfile++;
10657c478bd9Sstevel@tonic-gate loop:
10667c478bd9Sstevel@tonic-gate if ((spcl.c_dinode.di_mode & IFMT) == IFSHAD) {
10677c478bd9Sstevel@tonic-gate f1 = xtrmeta;
10687c478bd9Sstevel@tonic-gate f2 = metaskip;
10697c478bd9Sstevel@tonic-gate }
10707c478bd9Sstevel@tonic-gate for (i = 0, bufptr = buf; i < spcl.c_count; i++) {
10717c478bd9Sstevel@tonic-gate if ((i >= TP_NINDIR) || (spcl.c_addr[i])) {
10727c478bd9Sstevel@tonic-gate readtape(bufptr);
10737c478bd9Sstevel@tonic-gate bufptr += tp_bsize;
10747c478bd9Sstevel@tonic-gate curblk++;
10757c478bd9Sstevel@tonic-gate if (curblk == (fssize / tp_bsize)) {
10767c478bd9Sstevel@tonic-gate (*f1)(buf, size > tp_bsize ?
10777c478bd9Sstevel@tonic-gate (size_t)(fssize) :
10787c478bd9Sstevel@tonic-gate /* LINTED size <= tp_bsize */
10797c478bd9Sstevel@tonic-gate (curblk - 1) * tp_bsize + (size_t)size);
10807c478bd9Sstevel@tonic-gate curblk = 0;
10817c478bd9Sstevel@tonic-gate bufptr = buf;
10827c478bd9Sstevel@tonic-gate }
10837c478bd9Sstevel@tonic-gate } else {
10847c478bd9Sstevel@tonic-gate if (curblk > 0) {
10857c478bd9Sstevel@tonic-gate (*f1)(buf, size > tp_bsize ?
10867c478bd9Sstevel@tonic-gate (size_t)(curblk * tp_bsize) :
10877c478bd9Sstevel@tonic-gate /* LINTED size <= tp_bsize */
10887c478bd9Sstevel@tonic-gate (curblk - 1) * tp_bsize + (size_t)size);
10897c478bd9Sstevel@tonic-gate curblk = 0;
10907c478bd9Sstevel@tonic-gate bufptr = buf;
10917c478bd9Sstevel@tonic-gate }
10927c478bd9Sstevel@tonic-gate (*f2)(clearedbuf, size > tp_bsize ?
10937c478bd9Sstevel@tonic-gate /* LINTED size <= tp_bsize */
10942720c984Svk (long)tp_bsize : (size_t)size);
10957c478bd9Sstevel@tonic-gate }
10967c478bd9Sstevel@tonic-gate if ((size -= tp_bsize) <= 0) {
10977c478bd9Sstevel@tonic-gate for (i++; i < spcl.c_count; i++)
10987c478bd9Sstevel@tonic-gate if ((i >= TP_NINDIR) || (spcl.c_addr[i]))
10997c478bd9Sstevel@tonic-gate readtape(junk);
11007c478bd9Sstevel@tonic-gate break;
11017c478bd9Sstevel@tonic-gate }
11027c478bd9Sstevel@tonic-gate }
11037c478bd9Sstevel@tonic-gate if (curblk > 0) {
11047c478bd9Sstevel@tonic-gate /*
11057c478bd9Sstevel@tonic-gate * Ok to cast size to size_t here. The above for loop reads
11067c478bd9Sstevel@tonic-gate * data into the buffer then writes it to the output file. The
11077c478bd9Sstevel@tonic-gate * call to f1 here is to write out the data that's in the
11087c478bd9Sstevel@tonic-gate * buffer that has not yet been written to the file.
11097c478bd9Sstevel@tonic-gate * This will be less than N-KB of data, since the
11107c478bd9Sstevel@tonic-gate * above loop writes to the file in filesystem-
11117c478bd9Sstevel@tonic-gate * blocksize chunks.
11127c478bd9Sstevel@tonic-gate */
11137c478bd9Sstevel@tonic-gate /* LINTED: size fits into a size_t at this point */
11147c478bd9Sstevel@tonic-gate (*f1)(buf, (curblk * tp_bsize) + (size_t)size);
11157c478bd9Sstevel@tonic-gate
11167c478bd9Sstevel@tonic-gate curblk = 0;
11177c478bd9Sstevel@tonic-gate bufptr = buf;
11187c478bd9Sstevel@tonic-gate }
11197c478bd9Sstevel@tonic-gate if ((readhdr(&spcl) == GOOD) && (checktype(&spcl, TS_ADDR) == GOOD)) {
11207c478bd9Sstevel@tonic-gate if (continuemap)
11217c478bd9Sstevel@tonic-gate size = (offset_t)spcl.c_count * tp_bsize;
11227c478bd9Sstevel@tonic-gate /* big bitmap */
11237c478bd9Sstevel@tonic-gate else if ((size <= 0) &&
11247c478bd9Sstevel@tonic-gate ((spcl.c_dinode.di_mode & IFMT) == IFSHAD)) {
11257c478bd9Sstevel@tonic-gate /* LINTED unsigned to signed conversion ok */
11267c478bd9Sstevel@tonic-gate size = spcl.c_dinode.di_size;
11277c478bd9Sstevel@tonic-gate }
11287c478bd9Sstevel@tonic-gate if (size > 0)
11297c478bd9Sstevel@tonic-gate goto loop;
11307c478bd9Sstevel@tonic-gate }
11317c478bd9Sstevel@tonic-gate if (size > 0)
11327c478bd9Sstevel@tonic-gate dprintf(stdout,
11337c478bd9Sstevel@tonic-gate gettext("Missing address (header) block for %s\n"),
11347c478bd9Sstevel@tonic-gate curfile.name);
11357c478bd9Sstevel@tonic-gate findinode(&spcl);
11367c478bd9Sstevel@tonic-gate gettingfile = 0;
11377c478bd9Sstevel@tonic-gate }
11387c478bd9Sstevel@tonic-gate
11397c478bd9Sstevel@tonic-gate /*
11407c478bd9Sstevel@tonic-gate * The next routines are called during file extraction to
11417c478bd9Sstevel@tonic-gate * put the data into the right form and place.
11427c478bd9Sstevel@tonic-gate */
11437c478bd9Sstevel@tonic-gate static void
xtrfile(char * buf,size_t size)1144fe0e7ec4Smaheshvs xtrfile(char *buf, size_t size)
11457c478bd9Sstevel@tonic-gate {
11467c478bd9Sstevel@tonic-gate if (write(ofile, buf, (size_t)size) == -1) {
11477c478bd9Sstevel@tonic-gate int saverr = errno;
11487c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
11497c478bd9Sstevel@tonic-gate gettext("write error extracting inode %d, name %s\n"),
11507c478bd9Sstevel@tonic-gate curfile.ino, curfile.name);
11517c478bd9Sstevel@tonic-gate errno = saverr;
11527c478bd9Sstevel@tonic-gate perror("write");
11537c478bd9Sstevel@tonic-gate done(1);
11547c478bd9Sstevel@tonic-gate }
11557c478bd9Sstevel@tonic-gate }
11567c478bd9Sstevel@tonic-gate
11577c478bd9Sstevel@tonic-gate /*
11587c478bd9Sstevel@tonic-gate * Even though size is a size_t, it's seeking to a relative
11597c478bd9Sstevel@tonic-gate * offset. Thus, the seek could go beyond 2 GB, so lseek64 is needed.
11607c478bd9Sstevel@tonic-gate */
11617c478bd9Sstevel@tonic-gate
11627c478bd9Sstevel@tonic-gate /*ARGSUSED*/
11637c478bd9Sstevel@tonic-gate static void
xtrskip(char * buf,size_t size)1164fe0e7ec4Smaheshvs xtrskip(char *buf, size_t size)
11657c478bd9Sstevel@tonic-gate {
11667c478bd9Sstevel@tonic-gate if (lseek64(ofile, (offset_t)size, 1) == -1) {
11677c478bd9Sstevel@tonic-gate int saverr = errno;
11687c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
11697c478bd9Sstevel@tonic-gate gettext("seek error extracting inode %d, name %s\n"),
11707c478bd9Sstevel@tonic-gate curfile.ino, curfile.name);
11717c478bd9Sstevel@tonic-gate errno = saverr;
11727c478bd9Sstevel@tonic-gate perror("lseek64");
11737c478bd9Sstevel@tonic-gate done(1);
11747c478bd9Sstevel@tonic-gate }
11757c478bd9Sstevel@tonic-gate }
11767c478bd9Sstevel@tonic-gate
11777c478bd9Sstevel@tonic-gate /* these are local to the next five functions */
11787c478bd9Sstevel@tonic-gate static char *metadata = NULL;
11797c478bd9Sstevel@tonic-gate static size_t metasize = 0;
11807c478bd9Sstevel@tonic-gate
11817c478bd9Sstevel@tonic-gate static void
metacheck(struct s_spcl * head)1182fe0e7ec4Smaheshvs metacheck(struct s_spcl *head)
11837c478bd9Sstevel@tonic-gate {
11847c478bd9Sstevel@tonic-gate if (! (head->c_flags & DR_HASMETA))
11857c478bd9Sstevel@tonic-gate return;
11867c478bd9Sstevel@tonic-gate if ((metadata = malloc(metasize = (size_t)sizeof (head->c_shadow)))
11877c478bd9Sstevel@tonic-gate == NULL) {
11887c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
11897c478bd9Sstevel@tonic-gate gettext("Cannot malloc for metadata\n"));
11907c478bd9Sstevel@tonic-gate done(1);
11917c478bd9Sstevel@tonic-gate }
11927c478bd9Sstevel@tonic-gate bcopy(&(head->c_shadow), metadata, metasize);
11937c478bd9Sstevel@tonic-gate }
11947c478bd9Sstevel@tonic-gate
11957c478bd9Sstevel@tonic-gate static void
xtrmeta(char * buf,size_t size)1196fe0e7ec4Smaheshvs xtrmeta(char *buf, size_t size)
11977c478bd9Sstevel@tonic-gate {
11987c478bd9Sstevel@tonic-gate if ((metadata == NULL) && ((spcl.c_dinode.di_mode & IFMT) != IFSHAD))
11997c478bd9Sstevel@tonic-gate return;
12007c478bd9Sstevel@tonic-gate if ((metadata = realloc(metadata, metasize + size)) == NULL) {
12017c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
12027c478bd9Sstevel@tonic-gate gettext("Cannot malloc for metadata\n"));
12037c478bd9Sstevel@tonic-gate done(1);
12047c478bd9Sstevel@tonic-gate }
12057c478bd9Sstevel@tonic-gate bcopy(buf, metadata + metasize, size);
12067c478bd9Sstevel@tonic-gate metasize += size;
12077c478bd9Sstevel@tonic-gate }
12087c478bd9Sstevel@tonic-gate
12097c478bd9Sstevel@tonic-gate /* ARGSUSED */
12107c478bd9Sstevel@tonic-gate static void
metaskip(char * buf,size_t size)1211fe0e7ec4Smaheshvs metaskip(char *buf, size_t size)
12127c478bd9Sstevel@tonic-gate {
12137c478bd9Sstevel@tonic-gate if (metadata == NULL)
12147c478bd9Sstevel@tonic-gate return;
12157c478bd9Sstevel@tonic-gate if ((metadata = realloc(metadata, metasize + size)) == NULL) {
12167c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
12177c478bd9Sstevel@tonic-gate gettext("Cannot malloc for metadata\n"));
12187c478bd9Sstevel@tonic-gate done(1);
12197c478bd9Sstevel@tonic-gate }
12207c478bd9Sstevel@tonic-gate bzero(metadata + metasize, size);
12217c478bd9Sstevel@tonic-gate metasize += size;
12227c478bd9Sstevel@tonic-gate }
12237c478bd9Sstevel@tonic-gate
12247c478bd9Sstevel@tonic-gate static void
metaset(char * name)1225fe0e7ec4Smaheshvs metaset(char *name)
12267c478bd9Sstevel@tonic-gate {
12277c478bd9Sstevel@tonic-gate if (metadata == NULL)
12287c478bd9Sstevel@tonic-gate return;
12297c478bd9Sstevel@tonic-gate if (name != NULL)
12307c478bd9Sstevel@tonic-gate metaproc(name, metadata, metasize);
12317c478bd9Sstevel@tonic-gate (void) free(metadata);
12327c478bd9Sstevel@tonic-gate metadata = NULL;
12337c478bd9Sstevel@tonic-gate metasize = 0;
12347c478bd9Sstevel@tonic-gate }
12357c478bd9Sstevel@tonic-gate
12367c478bd9Sstevel@tonic-gate void
metaget(char ** data,size_t * size)1237*e0dfa398SToomas Soome metaget(char **data, size_t *size)
12387c478bd9Sstevel@tonic-gate {
12397c478bd9Sstevel@tonic-gate *data = metadata;
12407c478bd9Sstevel@tonic-gate *size = metasize;
12417c478bd9Sstevel@tonic-gate }
12427c478bd9Sstevel@tonic-gate
12437c478bd9Sstevel@tonic-gate static void
fsd_acl(char * name,char * aclp,unsigned size)1244*e0dfa398SToomas Soome fsd_acl(char *name, char *aclp, unsigned size)
12457c478bd9Sstevel@tonic-gate {
12467c478bd9Sstevel@tonic-gate static aclent_t *aclent = NULL;
12477c478bd9Sstevel@tonic-gate ufs_acl_t *diskacl;
12487c478bd9Sstevel@tonic-gate static int n = 0;
124949f0e518Smarks acl_t *set_aclp;
12507c478bd9Sstevel@tonic-gate uint_t i;
12517c478bd9Sstevel@tonic-gate int saverr, j;
12527c478bd9Sstevel@tonic-gate
12537c478bd9Sstevel@tonic-gate if (aclp == NULL) {
12547c478bd9Sstevel@tonic-gate if (aclent != NULL)
12557c478bd9Sstevel@tonic-gate free(aclent);
12567c478bd9Sstevel@tonic-gate aclent = NULL;
12577c478bd9Sstevel@tonic-gate n = 0;
12587c478bd9Sstevel@tonic-gate return;
12597c478bd9Sstevel@tonic-gate }
12607c478bd9Sstevel@tonic-gate
12617c478bd9Sstevel@tonic-gate /*LINTED [aclp is malloc'd]*/
12627c478bd9Sstevel@tonic-gate diskacl = (ufs_acl_t *)aclp;
12637c478bd9Sstevel@tonic-gate /* LINTED: result fits in an int */
12647c478bd9Sstevel@tonic-gate j = size / sizeof (*diskacl);
12657c478bd9Sstevel@tonic-gate normacls(byteorder, diskacl, j);
12667c478bd9Sstevel@tonic-gate
12677c478bd9Sstevel@tonic-gate i = n;
12687c478bd9Sstevel@tonic-gate n += j;
12697c478bd9Sstevel@tonic-gate aclent = realloc(aclent, n * (size_t)sizeof (*aclent));
12707c478bd9Sstevel@tonic-gate if (aclent == NULL) {
12717c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Cannot malloc acl list\n"));
12727c478bd9Sstevel@tonic-gate done(1);
12737c478bd9Sstevel@tonic-gate }
12747c478bd9Sstevel@tonic-gate
12757c478bd9Sstevel@tonic-gate j = 0;
12767c478bd9Sstevel@tonic-gate while (i < n) {
12777c478bd9Sstevel@tonic-gate aclent[i].a_type = diskacl[j].acl_tag;
12787c478bd9Sstevel@tonic-gate aclent[i].a_id = diskacl[j].acl_who;
12797c478bd9Sstevel@tonic-gate aclent[i].a_perm = diskacl[j].acl_perm;
12807c478bd9Sstevel@tonic-gate ++i;
12817c478bd9Sstevel@tonic-gate ++j;
12827c478bd9Sstevel@tonic-gate }
12837c478bd9Sstevel@tonic-gate
128449f0e518Smarks set_aclp = acl_to_aclp(ACLENT_T, aclent, n);
128549f0e518Smarks if (set_aclp == NULL) {
128649f0e518Smarks (void) fprintf(stderr, gettext("Cannot build acl_t\n"));
128749f0e518Smarks done(1);
128849f0e518Smarks }
128949f0e518Smarks
129049f0e518Smarks if (acl_set(name, set_aclp) == -1) {
12917c478bd9Sstevel@tonic-gate static int once = 0;
12927c478bd9Sstevel@tonic-gate
12937c478bd9Sstevel@tonic-gate /*
12947c478bd9Sstevel@tonic-gate * Treat some errors from the acl subsystem specially to
12957c478bd9Sstevel@tonic-gate * avoid being too noisy:
12967c478bd9Sstevel@tonic-gate *
12977c478bd9Sstevel@tonic-gate * ENOSYS - ACLs not supported on this file system
12987c478bd9Sstevel@tonic-gate * EPERM - not the owner or not privileged
12997c478bd9Sstevel@tonic-gate *
13007c478bd9Sstevel@tonic-gate * The following is also supported for backwards compat.
13017c478bd9Sstevel@tonic-gate * since acl(2) used to return the wrong errno:
13027c478bd9Sstevel@tonic-gate *
13037c478bd9Sstevel@tonic-gate * EINVAL - not the owner of the object
13047c478bd9Sstevel@tonic-gate */
13057c478bd9Sstevel@tonic-gate if (errno == ENOSYS || errno == EPERM || errno == EINVAL) {
13067c478bd9Sstevel@tonic-gate if (once == 0) {
13077c478bd9Sstevel@tonic-gate saverr = errno;
13087c478bd9Sstevel@tonic-gate ++once;
13097c478bd9Sstevel@tonic-gate fprintf(stderr,
13107c478bd9Sstevel@tonic-gate gettext("setacl failed: %s\n"),
13117c478bd9Sstevel@tonic-gate strerror(saverr));
13127c478bd9Sstevel@tonic-gate }
13137c478bd9Sstevel@tonic-gate } else {
13147c478bd9Sstevel@tonic-gate saverr = errno;
13157c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("setacl on %s failed: %s\n"),
13167c478bd9Sstevel@tonic-gate name, strerror(saverr));
13177c478bd9Sstevel@tonic-gate }
13187c478bd9Sstevel@tonic-gate }
131949f0e518Smarks acl_free(set_aclp);
13207c478bd9Sstevel@tonic-gate }
13217c478bd9Sstevel@tonic-gate
13227c478bd9Sstevel@tonic-gate static struct fsdtypes {
13237c478bd9Sstevel@tonic-gate int type;
13247c478bd9Sstevel@tonic-gate void (*function)();
13257c478bd9Sstevel@tonic-gate } fsdtypes[] = {
13267c478bd9Sstevel@tonic-gate {FSD_ACL, fsd_acl},
13277c478bd9Sstevel@tonic-gate {FSD_DFACL, fsd_acl},
13287c478bd9Sstevel@tonic-gate {0, NULL}
13297c478bd9Sstevel@tonic-gate };
13307c478bd9Sstevel@tonic-gate
13317c478bd9Sstevel@tonic-gate void
metaproc(char * name,char * mdata,size_t msize)1332fe0e7ec4Smaheshvs metaproc(char *name, char *mdata, size_t msize)
13337c478bd9Sstevel@tonic-gate {
13347c478bd9Sstevel@tonic-gate struct fsdtypes *fsdtype;
13357c478bd9Sstevel@tonic-gate ufs_fsd_t *fsd;
13367c478bd9Sstevel@tonic-gate char *c;
13377c478bd9Sstevel@tonic-gate
13387c478bd9Sstevel@tonic-gate /*
13397c478bd9Sstevel@tonic-gate * for the whole shadow inode, dispatch each piece
13407c478bd9Sstevel@tonic-gate * to the appropriate function.
13417c478bd9Sstevel@tonic-gate */
13427c478bd9Sstevel@tonic-gate c = mdata;
13437c478bd9Sstevel@tonic-gate /* LINTED (c - mdata) fits into a size_t */
13447c478bd9Sstevel@tonic-gate while ((size_t)(c - mdata) < msize) {
13457c478bd9Sstevel@tonic-gate /*LINTED [mdata is malloc'd]*/
13467c478bd9Sstevel@tonic-gate fsd = (ufs_fsd_t *)c;
13477c478bd9Sstevel@tonic-gate assert((fsd->fsd_size % 4) == 0);
13487c478bd9Sstevel@tonic-gate /* LINTED: lint thinks pointers are signed */
13497c478bd9Sstevel@tonic-gate c += FSD_RECSZ(fsd, fsd->fsd_size);
13507c478bd9Sstevel@tonic-gate if ((fsd->fsd_type == FSD_FREE) ||
13517c478bd9Sstevel@tonic-gate ((unsigned)(fsd->fsd_size) <= sizeof (ufs_fsd_t)) ||
13527c478bd9Sstevel@tonic-gate (c > (mdata + msize)))
13537c478bd9Sstevel@tonic-gate break;
13547c478bd9Sstevel@tonic-gate for (fsdtype = fsdtypes; fsdtype->type; fsdtype++)
13557c478bd9Sstevel@tonic-gate if (fsdtype->type == fsd->fsd_type)
13567c478bd9Sstevel@tonic-gate (*fsdtype->function)(name, fsd->fsd_data,
13577c478bd9Sstevel@tonic-gate (unsigned)(fsd->fsd_size) -
13587c478bd9Sstevel@tonic-gate sizeof (fsd->fsd_type) -
13597c478bd9Sstevel@tonic-gate sizeof (fsd->fsd_size));
13607c478bd9Sstevel@tonic-gate /* ^^^ be sure to change if fsd ever changes ^^^ */
13617c478bd9Sstevel@tonic-gate }
13627c478bd9Sstevel@tonic-gate
13637c478bd9Sstevel@tonic-gate /* reset the state of all the functions */
13647c478bd9Sstevel@tonic-gate for (fsdtype = fsdtypes; fsdtype->type; fsdtype++)
13657c478bd9Sstevel@tonic-gate (*fsdtype->function)(NULL, NULL, 0);
13667c478bd9Sstevel@tonic-gate }
13677c478bd9Sstevel@tonic-gate
13687c478bd9Sstevel@tonic-gate static void
xtrlnkfile(char * buf,size_t size)1369fe0e7ec4Smaheshvs xtrlnkfile(char *buf, size_t size)
13707c478bd9Sstevel@tonic-gate {
13717c478bd9Sstevel@tonic-gate /* LINTED: signed/unsigned mix ok */
13727c478bd9Sstevel@tonic-gate pathlen += size;
13737c478bd9Sstevel@tonic-gate if (pathlen > MAXPATHLEN) {
13747c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
13757c478bd9Sstevel@tonic-gate gettext("symbolic link name: %s->%s%s; too long %d\n"),
13767c478bd9Sstevel@tonic-gate curfile.name, lnkbuf, buf, pathlen);
13777c478bd9Sstevel@tonic-gate done(1);
13787c478bd9Sstevel@tonic-gate }
13797c478bd9Sstevel@tonic-gate buf[size] = '\0';
13807c478bd9Sstevel@tonic-gate (void) strcat(lnkbuf, buf);
13817c478bd9Sstevel@tonic-gate /* add an extra NULL to make this a legal complex string */
13827c478bd9Sstevel@tonic-gate lnkbuf[pathlen+1] = '\0';
13837c478bd9Sstevel@tonic-gate }
13847c478bd9Sstevel@tonic-gate
13857c478bd9Sstevel@tonic-gate /*ARGSUSED*/
13867c478bd9Sstevel@tonic-gate static void
xtrlnkskip(char * buf,size_t size)1387fe0e7ec4Smaheshvs xtrlnkskip(char *buf, size_t size)
13887c478bd9Sstevel@tonic-gate {
13897c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
13907c478bd9Sstevel@tonic-gate gettext("unallocated block in symbolic link %s\n"),
13917c478bd9Sstevel@tonic-gate curfile.name);
13927c478bd9Sstevel@tonic-gate done(1);
13937c478bd9Sstevel@tonic-gate }
13947c478bd9Sstevel@tonic-gate
13957c478bd9Sstevel@tonic-gate static void
xtrmap(char * buf,size_t size)1396fe0e7ec4Smaheshvs xtrmap(char *buf, size_t size)
13977c478bd9Sstevel@tonic-gate {
13987c478bd9Sstevel@tonic-gate if ((map+size) > endmap) {
13997c478bd9Sstevel@tonic-gate int64_t mapsize, increment;
14007c478bd9Sstevel@tonic-gate int64_t diff;
14017c478bd9Sstevel@tonic-gate
14027c478bd9Sstevel@tonic-gate if (spcl.c_type != TS_ADDR) {
14037c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
14047c478bd9Sstevel@tonic-gate gettext("xtrmap: current record not TS_ADDR\n"));
14057c478bd9Sstevel@tonic-gate done(1);
14067c478bd9Sstevel@tonic-gate }
14077c478bd9Sstevel@tonic-gate if ((spcl.c_count < 0) || (spcl.c_count > TP_NINDIR)) {
14087c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
14097c478bd9Sstevel@tonic-gate gettext("xtrmap: illegal c_count field (%d)\n"),
14107c478bd9Sstevel@tonic-gate spcl.c_count);
14117c478bd9Sstevel@tonic-gate done(1);
14127c478bd9Sstevel@tonic-gate }
14137c478bd9Sstevel@tonic-gate
14147c478bd9Sstevel@tonic-gate increment = d_howmany(
14152720c984Svk ((spcl.c_count * tp_bsize * NBBY) + 1), NBBY);
14167c478bd9Sstevel@tonic-gate mapsize = endmap - beginmap + increment;
14177c478bd9Sstevel@tonic-gate if (mapsize > UINT_MAX) {
14187c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
14197c478bd9Sstevel@tonic-gate gettext("xtrmap: maximum bitmap size exceeded"));
14207c478bd9Sstevel@tonic-gate done(1);
14217c478bd9Sstevel@tonic-gate }
14227c478bd9Sstevel@tonic-gate
14237c478bd9Sstevel@tonic-gate diff = map - beginmap;
14247c478bd9Sstevel@tonic-gate /* LINTED mapsize checked above */
14257c478bd9Sstevel@tonic-gate beginmap = realloc(beginmap, (size_t)mapsize);
14267c478bd9Sstevel@tonic-gate if (beginmap == NULL) {
14277c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
14287c478bd9Sstevel@tonic-gate gettext("xtrmap: realloc failed\n"));
14297c478bd9Sstevel@tonic-gate done(1);
14307c478bd9Sstevel@tonic-gate }
14317c478bd9Sstevel@tonic-gate map = beginmap + diff;
14327c478bd9Sstevel@tonic-gate endmap = beginmap + mapsize;
14337c478bd9Sstevel@tonic-gate /* LINTED endmap - map cannot exceed 32 bits */
14347c478bd9Sstevel@tonic-gate bzero(map, (size_t)(endmap - map));
14357c478bd9Sstevel@tonic-gate maxino = NBBY * mapsize + 1;
14367c478bd9Sstevel@tonic-gate }
14377c478bd9Sstevel@tonic-gate
14387c478bd9Sstevel@tonic-gate bcopy(buf, map, size);
14397c478bd9Sstevel@tonic-gate /* LINTED character pointers aren't signed */
14407c478bd9Sstevel@tonic-gate map += size;
14417c478bd9Sstevel@tonic-gate }
14427c478bd9Sstevel@tonic-gate
14437c478bd9Sstevel@tonic-gate /*ARGSUSED*/
14447c478bd9Sstevel@tonic-gate static void
xtrmapskip(char * buf,size_t size)1445fe0e7ec4Smaheshvs xtrmapskip(char *buf, size_t size)
14467c478bd9Sstevel@tonic-gate {
14477c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("hole in map\n"));
14487c478bd9Sstevel@tonic-gate done(1);
14497c478bd9Sstevel@tonic-gate }
14507c478bd9Sstevel@tonic-gate
14517c478bd9Sstevel@tonic-gate /*ARGSUSED*/
14527c478bd9Sstevel@tonic-gate void
null(char * buf,size_t size)1453fe0e7ec4Smaheshvs null(char *buf, size_t size)
14547c478bd9Sstevel@tonic-gate {
14557c478bd9Sstevel@tonic-gate }
14567c478bd9Sstevel@tonic-gate
14577c478bd9Sstevel@tonic-gate /*
14587c478bd9Sstevel@tonic-gate * Do the tape i/o, dealing with volume changes
14597c478bd9Sstevel@tonic-gate * etc..
14607c478bd9Sstevel@tonic-gate */
14617c478bd9Sstevel@tonic-gate static void
readtape(char * b)1462fe0e7ec4Smaheshvs readtape(char *b)
14637c478bd9Sstevel@tonic-gate {
14647c478bd9Sstevel@tonic-gate int i;
14657c478bd9Sstevel@tonic-gate int rd, newvol;
14667c478bd9Sstevel@tonic-gate int cnt;
14677c478bd9Sstevel@tonic-gate struct s_spcl *sp;
14687c478bd9Sstevel@tonic-gate int32_t expected_magic;
14697c478bd9Sstevel@tonic-gate
14707c478bd9Sstevel@tonic-gate if (tbf == NULL) {
14717c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
14727c478bd9Sstevel@tonic-gate "Internal consistency failure in readtape: tbf is NULL\n"));
14737c478bd9Sstevel@tonic-gate done(1);
14747c478bd9Sstevel@tonic-gate }
14757c478bd9Sstevel@tonic-gate expected_magic = ((tp_bsize == TP_BSIZE_MIN) ? NFS_MAGIC : MTB_MAGIC);
14767c478bd9Sstevel@tonic-gate
14777c478bd9Sstevel@tonic-gate top:
14787c478bd9Sstevel@tonic-gate if (bct < numtrec) {
14797c478bd9Sstevel@tonic-gate /*
14807c478bd9Sstevel@tonic-gate * check for old-dump floppy EOM -- it may appear in
14817c478bd9Sstevel@tonic-gate * the middle of a buffer. The Dflag used to be used for
14827c478bd9Sstevel@tonic-gate * this, but since it doesn't hurt to always do this we
14837c478bd9Sstevel@tonic-gate * got rid of the Dflag.
14847c478bd9Sstevel@tonic-gate */
14857c478bd9Sstevel@tonic-gate /*LINTED [tbf = malloc()]*/
14867c478bd9Sstevel@tonic-gate sp = &((union u_spcl *)&tbf[bct*tp_bsize])->s_spcl;
14877c478bd9Sstevel@tonic-gate if (sp->c_magic == expected_magic && sp->c_type == TS_EOM &&
14887c478bd9Sstevel@tonic-gate (time_t)(sp->c_date) == dumpdate &&
14897c478bd9Sstevel@tonic-gate (time_t)(sp->c_ddate) == dumptime) {
14907c478bd9Sstevel@tonic-gate for (i = 0; i < ntrec; i++)
14917c478bd9Sstevel@tonic-gate /*LINTED [tbf = malloc()]*/
14927c478bd9Sstevel@tonic-gate ((struct s_spcl *)
14932720c984Svk &tbf[i*tp_bsize])->c_magic = 0;
14947c478bd9Sstevel@tonic-gate bct = 0;
14957c478bd9Sstevel@tonic-gate rd = 0;
14967c478bd9Sstevel@tonic-gate i = 0;
14977c478bd9Sstevel@tonic-gate goto nextvol;
14987c478bd9Sstevel@tonic-gate }
14997c478bd9Sstevel@tonic-gate bcopy(&tbf[(bct++*tp_bsize)], b, (size_t)tp_bsize);
15007c478bd9Sstevel@tonic-gate blksread++;
15017c478bd9Sstevel@tonic-gate tapea++;
15027c478bd9Sstevel@tonic-gate return;
15037c478bd9Sstevel@tonic-gate }
15047c478bd9Sstevel@tonic-gate /*LINTED [assertion always true]*/
15057c478bd9Sstevel@tonic-gate assert(sizeof (union u_spcl) == TP_BSIZE_MAX);
15067c478bd9Sstevel@tonic-gate for (i = 0; i < ntrec; i++)
15077c478bd9Sstevel@tonic-gate /*LINTED [tbf = malloc()]*/
15087c478bd9Sstevel@tonic-gate ((struct s_spcl *)&tbf[i*sizeof (struct s_spcl)])->c_magic = 0;
15097c478bd9Sstevel@tonic-gate if (numtrec == 0) {
15107c478bd9Sstevel@tonic-gate /* LINTED unsigned/signed assignment ok */
15117c478bd9Sstevel@tonic-gate numtrec = ntrec;
15127c478bd9Sstevel@tonic-gate }
15137c478bd9Sstevel@tonic-gate /* LINTED unsigned/signed assignment ok */
15147c478bd9Sstevel@tonic-gate cnt = ntrec*tp_bsize;
15157c478bd9Sstevel@tonic-gate rd = 0;
15167c478bd9Sstevel@tonic-gate getmore:
15177c478bd9Sstevel@tonic-gate if (host)
15187c478bd9Sstevel@tonic-gate i = rmtread(&tbf[rd], cnt);
15197c478bd9Sstevel@tonic-gate else
15207c478bd9Sstevel@tonic-gate i = read(mt, &tbf[rd], cnt);
15217c478bd9Sstevel@tonic-gate /*
15227c478bd9Sstevel@tonic-gate * Check for mid-tape short read error.
15237c478bd9Sstevel@tonic-gate * If found, return rest of buffer.
15247c478bd9Sstevel@tonic-gate */
15257c478bd9Sstevel@tonic-gate if (numtrec < ntrec && i != 0) {
15267c478bd9Sstevel@tonic-gate /* LINTED unsigned/signed assignment ok */
15277c478bd9Sstevel@tonic-gate numtrec = ntrec;
15287c478bd9Sstevel@tonic-gate goto top;
15297c478bd9Sstevel@tonic-gate }
15307c478bd9Sstevel@tonic-gate /*
15317c478bd9Sstevel@tonic-gate * Handle partial block read.
15327c478bd9Sstevel@tonic-gate */
15337c478bd9Sstevel@tonic-gate if (i > 0 && i != ntrec*tp_bsize) {
15347c478bd9Sstevel@tonic-gate if (pipein) {
15357c478bd9Sstevel@tonic-gate rd += i;
15367c478bd9Sstevel@tonic-gate cnt -= i;
15377c478bd9Sstevel@tonic-gate if (cnt > 0)
15387c478bd9Sstevel@tonic-gate goto getmore;
15397c478bd9Sstevel@tonic-gate i = rd;
15407c478bd9Sstevel@tonic-gate } else {
15417c478bd9Sstevel@tonic-gate if (i % tp_bsize != 0)
15427c478bd9Sstevel@tonic-gate panic(gettext(
15437c478bd9Sstevel@tonic-gate "partial block read: %d should be %d\n"),
15442720c984Svk i, ntrec * tp_bsize);
15457c478bd9Sstevel@tonic-gate numtrec = i / tp_bsize;
15467c478bd9Sstevel@tonic-gate if (numtrec == 0)
15477c478bd9Sstevel@tonic-gate /*
15487c478bd9Sstevel@tonic-gate * it's possible to read only 512 bytes
15497c478bd9Sstevel@tonic-gate * from a QIC device...
15507c478bd9Sstevel@tonic-gate */
15517c478bd9Sstevel@tonic-gate i = 0;
15527c478bd9Sstevel@tonic-gate }
15537c478bd9Sstevel@tonic-gate }
15547c478bd9Sstevel@tonic-gate /*
15557c478bd9Sstevel@tonic-gate * Handle read error.
15567c478bd9Sstevel@tonic-gate */
15577c478bd9Sstevel@tonic-gate if (i < 0) {
15587c478bd9Sstevel@tonic-gate switch (curfile.action) {
15597c478bd9Sstevel@tonic-gate default:
15607c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
15617c478bd9Sstevel@tonic-gate "Read error while trying to set up volume\n"));
15627c478bd9Sstevel@tonic-gate break;
15637c478bd9Sstevel@tonic-gate case UNKNOWN:
15647c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
15657c478bd9Sstevel@tonic-gate "Read error while trying to resynchronize\n"));
15667c478bd9Sstevel@tonic-gate break;
15677c478bd9Sstevel@tonic-gate case USING:
15687c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
15697c478bd9Sstevel@tonic-gate "Read error while restoring %s\n"),
15707c478bd9Sstevel@tonic-gate curfile.name);
15717c478bd9Sstevel@tonic-gate break;
15727c478bd9Sstevel@tonic-gate case SKIP:
15737c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
15747c478bd9Sstevel@tonic-gate "Read error while skipping over inode %d\n"),
15757c478bd9Sstevel@tonic-gate curfile.ino);
15767c478bd9Sstevel@tonic-gate break;
15777c478bd9Sstevel@tonic-gate }
15787c478bd9Sstevel@tonic-gate if (!yflag && !reply(gettext("continue")))
15797c478bd9Sstevel@tonic-gate done(1);
15807c478bd9Sstevel@tonic-gate /* LINTED: unsigned->signed conversion ok */
15817c478bd9Sstevel@tonic-gate i = (int)(ntrec*tp_bsize);
15827c478bd9Sstevel@tonic-gate bzero(tbf, (size_t)i);
15837c478bd9Sstevel@tonic-gate if ((host != 0 && rmtseek(i, 1) < 0) ||
15847c478bd9Sstevel@tonic-gate (host == 0 && (lseek64(mt, (offset_t)i, 1) ==
15857c478bd9Sstevel@tonic-gate (off64_t)-1))) {
15867c478bd9Sstevel@tonic-gate perror(gettext("continuation failed"));
15877c478bd9Sstevel@tonic-gate done(1);
15887c478bd9Sstevel@tonic-gate }
15897c478bd9Sstevel@tonic-gate }
15907c478bd9Sstevel@tonic-gate /*
15917c478bd9Sstevel@tonic-gate * Handle end of tape. The Dflag used to be used, but since it doesn't
15927c478bd9Sstevel@tonic-gate * hurt to always check we got rid if it.
15937c478bd9Sstevel@tonic-gate */
15947c478bd9Sstevel@tonic-gate
15957c478bd9Sstevel@tonic-gate /*
15967c478bd9Sstevel@tonic-gate * if the first record in the buffer just read is EOM,
15977c478bd9Sstevel@tonic-gate * change volumes.
15987c478bd9Sstevel@tonic-gate */
15997c478bd9Sstevel@tonic-gate /*LINTED [tbf = malloc()]*/
16007c478bd9Sstevel@tonic-gate sp = &((union u_spcl *)tbf)->s_spcl;
16017c478bd9Sstevel@tonic-gate if (i != 0 && sp->c_magic == expected_magic && sp->c_type == TS_EOM &&
16027c478bd9Sstevel@tonic-gate (time_t)(sp->c_date) == dumpdate &&
16037c478bd9Sstevel@tonic-gate (time_t)(sp->c_ddate) == dumptime) {
16047c478bd9Sstevel@tonic-gate i = 0;
16057c478bd9Sstevel@tonic-gate }
16067c478bd9Sstevel@tonic-gate nextvol:
16077c478bd9Sstevel@tonic-gate if (i == 0) {
16087c478bd9Sstevel@tonic-gate if (!pipein) {
16097c478bd9Sstevel@tonic-gate newvol = volno + 1;
16107c478bd9Sstevel@tonic-gate volno = 0;
16117c478bd9Sstevel@tonic-gate numtrec = 0;
16127c478bd9Sstevel@tonic-gate getvol(newvol);
16137c478bd9Sstevel@tonic-gate readtape(b); /* XXX tail recursion, not goto top? */
16147c478bd9Sstevel@tonic-gate return;
16157c478bd9Sstevel@tonic-gate }
16167c478bd9Sstevel@tonic-gate /* XXX if panic returns, should we round rd up? */
16177c478bd9Sstevel@tonic-gate /* XXX if we do, then we should zero the intervening space */
16187c478bd9Sstevel@tonic-gate if (rd % tp_bsize != 0)
16197c478bd9Sstevel@tonic-gate panic(gettext("partial block read: %d should be %d\n"),
16202720c984Svk rd, ntrec * tp_bsize);
16217c478bd9Sstevel@tonic-gate bcopy((char *)&endoftapemark, &tbf[rd], (size_t)tp_bsize);
16227c478bd9Sstevel@tonic-gate }
16237c478bd9Sstevel@tonic-gate bct = 0;
16247c478bd9Sstevel@tonic-gate bcopy(&tbf[(bct++*tp_bsize)], b, (size_t)tp_bsize);
16257c478bd9Sstevel@tonic-gate blksread++;
16267c478bd9Sstevel@tonic-gate recsread++;
16277c478bd9Sstevel@tonic-gate tapea++;
16287c478bd9Sstevel@tonic-gate rec_position++;
16297c478bd9Sstevel@tonic-gate }
16307c478bd9Sstevel@tonic-gate
16317c478bd9Sstevel@tonic-gate void
findtapeblksize(int arfile)16327c478bd9Sstevel@tonic-gate findtapeblksize(int arfile)
16337c478bd9Sstevel@tonic-gate {
16347c478bd9Sstevel@tonic-gate int i;
16357c478bd9Sstevel@tonic-gate
16367c478bd9Sstevel@tonic-gate if (tbf == NULL) {
16377c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
16387c478bd9Sstevel@tonic-gate "Internal consistency failure in findtapeblksize: "
16397c478bd9Sstevel@tonic-gate "tbf is NULL\n"));
16407c478bd9Sstevel@tonic-gate assert(tbf != NULL);
16417c478bd9Sstevel@tonic-gate done(1);
16427c478bd9Sstevel@tonic-gate }
16437c478bd9Sstevel@tonic-gate
16447c478bd9Sstevel@tonic-gate for (i = 0; i < ntrec; i++)
16457c478bd9Sstevel@tonic-gate /*LINTED [tbf = malloc()]*/
16467c478bd9Sstevel@tonic-gate ((struct s_spcl *)&tbf[i * tp_bsize])->c_magic = 0;
16477c478bd9Sstevel@tonic-gate bct = 0;
16487c478bd9Sstevel@tonic-gate if (host && arfile == TAPE_FILE)
16497c478bd9Sstevel@tonic-gate tape_rec_size = rmtread(tbf, ntrec * tp_bsize);
16507c478bd9Sstevel@tonic-gate else
16517c478bd9Sstevel@tonic-gate tape_rec_size = read(mt, tbf, ntrec * tp_bsize);
16527c478bd9Sstevel@tonic-gate recsread++;
16537c478bd9Sstevel@tonic-gate rec_position++;
16547c478bd9Sstevel@tonic-gate if (tape_rec_size == (ssize_t)-1) {
16557c478bd9Sstevel@tonic-gate int saverr = errno;
16567c478bd9Sstevel@tonic-gate char *errmsg = gettext("Media read error");
16577c478bd9Sstevel@tonic-gate errno = saverr;
16587c478bd9Sstevel@tonic-gate perror(errmsg);
16597c478bd9Sstevel@tonic-gate done(1);
16607c478bd9Sstevel@tonic-gate }
16617c478bd9Sstevel@tonic-gate if (tape_rec_size % tp_bsize != 0) {
16627c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
16637c478bd9Sstevel@tonic-gate "Record size (%d) is not a multiple of dump block size (%d)\n"),
16647c478bd9Sstevel@tonic-gate tape_rec_size, tp_bsize);
16657c478bd9Sstevel@tonic-gate done(1);
16667c478bd9Sstevel@tonic-gate }
16677c478bd9Sstevel@tonic-gate ntrec = (int)tape_rec_size / tp_bsize;
16687c478bd9Sstevel@tonic-gate /* LINTED unsigned/signed assignment ok */
16697c478bd9Sstevel@tonic-gate numtrec = ntrec;
16707c478bd9Sstevel@tonic-gate vprintf(stdout, gettext("Media block size is %d\n"), ntrec*2);
16717c478bd9Sstevel@tonic-gate }
16727c478bd9Sstevel@tonic-gate
16737c478bd9Sstevel@tonic-gate void
flsht(void)16747c478bd9Sstevel@tonic-gate flsht(void)
16757c478bd9Sstevel@tonic-gate {
16767c478bd9Sstevel@tonic-gate /* LINTED unsigned/signed assignment ok */
16777c478bd9Sstevel@tonic-gate bct = ntrec+1;
16787c478bd9Sstevel@tonic-gate }
16797c478bd9Sstevel@tonic-gate
16807c478bd9Sstevel@tonic-gate void
closemt(int mode)1681fe0e7ec4Smaheshvs closemt(int mode)
16827c478bd9Sstevel@tonic-gate {
168333a5e6b2Srm /*
168433a5e6b2Srm * If mode == FORCE_OFFLINE then we're not done but
168533a5e6b2Srm * we need to change tape. So, rewind and unload current
168633a5e6b2Srm * tape before loading the new one.
168733a5e6b2Srm */
168833a5e6b2Srm
16897c478bd9Sstevel@tonic-gate static struct mtop mtop = { MTOFFL, 0 };
16907c478bd9Sstevel@tonic-gate
16917c478bd9Sstevel@tonic-gate if (mt < 0)
16927c478bd9Sstevel@tonic-gate return;
169333a5e6b2Srm if (offline || mode == FORCE_OFFLINE)
16947c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Rewinding tape\n"));
16957c478bd9Sstevel@tonic-gate if (host) {
169633a5e6b2Srm if (offline || mode == FORCE_OFFLINE)
16977c478bd9Sstevel@tonic-gate (void) rmtioctl(MTOFFL, 1);
16987c478bd9Sstevel@tonic-gate rmtclose();
16997c478bd9Sstevel@tonic-gate } else if (pipein) {
17007c478bd9Sstevel@tonic-gate char buffy[MAXBSIZE];
17017c478bd9Sstevel@tonic-gate
17027c478bd9Sstevel@tonic-gate while (read(mt, buffy, sizeof (buffy)) > 0) {
17037c478bd9Sstevel@tonic-gate continue;
17047c478bd9Sstevel@tonic-gate /*LINTED [assertion always true]*/
17057c478bd9Sstevel@tonic-gate }
17067c478bd9Sstevel@tonic-gate (void) close(mt);
17077c478bd9Sstevel@tonic-gate } else {
17087c478bd9Sstevel@tonic-gate /*
17097c478bd9Sstevel@tonic-gate * Only way to tell if this is a floppy is to issue an ioctl
17107c478bd9Sstevel@tonic-gate * but why waste one - if the eject fails, tough!
17117c478bd9Sstevel@tonic-gate */
171233a5e6b2Srm if (offline || mode == FORCE_OFFLINE)
17137c478bd9Sstevel@tonic-gate (void) ioctl(mt, MTIOCTOP, &mtop);
17147c478bd9Sstevel@tonic-gate (void) ioctl(mt, FDEJECT, 0);
17157c478bd9Sstevel@tonic-gate (void) close(mt);
17167c478bd9Sstevel@tonic-gate }
17177c478bd9Sstevel@tonic-gate mt = -1;
17187c478bd9Sstevel@tonic-gate }
17197c478bd9Sstevel@tonic-gate
17207c478bd9Sstevel@tonic-gate static int
checkvol(struct s_spcl * b,int t)1721fe0e7ec4Smaheshvs checkvol(struct s_spcl *b, int t)
17227c478bd9Sstevel@tonic-gate {
17237c478bd9Sstevel@tonic-gate
17247c478bd9Sstevel@tonic-gate if (b->c_volume != t)
17257c478bd9Sstevel@tonic-gate return (FAIL);
17267c478bd9Sstevel@tonic-gate return (GOOD);
17277c478bd9Sstevel@tonic-gate }
17287c478bd9Sstevel@tonic-gate
1729fe0e7ec4Smaheshvs int
readhdr(struct s_spcl * b)1730fe0e7ec4Smaheshvs readhdr(struct s_spcl *b)
17317c478bd9Sstevel@tonic-gate {
17327c478bd9Sstevel@tonic-gate
17337c478bd9Sstevel@tonic-gate if (gethead(b) == FAIL) {
17347c478bd9Sstevel@tonic-gate dprintf(stdout, gettext("readhdr fails at %ld blocks\n"),
17352720c984Svk blksread);
17367c478bd9Sstevel@tonic-gate return (FAIL);
17377c478bd9Sstevel@tonic-gate }
17387c478bd9Sstevel@tonic-gate return (GOOD);
17397c478bd9Sstevel@tonic-gate }
17407c478bd9Sstevel@tonic-gate
17417c478bd9Sstevel@tonic-gate /*
17427c478bd9Sstevel@tonic-gate * read the tape into buf, then return whether or
17437c478bd9Sstevel@tonic-gate * or not it is a header block.
17447c478bd9Sstevel@tonic-gate */
1745fe0e7ec4Smaheshvs int
gethead(struct s_spcl * buf)1746fe0e7ec4Smaheshvs gethead(struct s_spcl *buf)
17477c478bd9Sstevel@tonic-gate {
17487c478bd9Sstevel@tonic-gate int i;
17497c478bd9Sstevel@tonic-gate union u_ospcl {
17507c478bd9Sstevel@tonic-gate char dummy[TP_BSIZE_MIN];
17517c478bd9Sstevel@tonic-gate struct s_ospcl {
17527c478bd9Sstevel@tonic-gate int32_t c_type;
17537c478bd9Sstevel@tonic-gate int32_t c_date;
17547c478bd9Sstevel@tonic-gate int32_t c_ddate;
17557c478bd9Sstevel@tonic-gate int32_t c_volume;
17567c478bd9Sstevel@tonic-gate int32_t c_tapea;
17577c478bd9Sstevel@tonic-gate ushort_t c_inumber;
17587c478bd9Sstevel@tonic-gate int32_t c_magic;
17597c478bd9Sstevel@tonic-gate int32_t c_checksum;
17607c478bd9Sstevel@tonic-gate struct odinode {
17617c478bd9Sstevel@tonic-gate unsigned short odi_mode;
17627c478bd9Sstevel@tonic-gate ushort_t odi_nlink;
17637c478bd9Sstevel@tonic-gate ushort_t odi_uid;
17647c478bd9Sstevel@tonic-gate ushort_t odi_gid;
17657c478bd9Sstevel@tonic-gate int32_t odi_size;
17667c478bd9Sstevel@tonic-gate int32_t odi_rdev;
17677c478bd9Sstevel@tonic-gate char odi_addr[36];
17687c478bd9Sstevel@tonic-gate int32_t odi_atime;
17697c478bd9Sstevel@tonic-gate int32_t odi_mtime;
17707c478bd9Sstevel@tonic-gate int32_t odi_ctime;
17717c478bd9Sstevel@tonic-gate } c_dinode;
17727c478bd9Sstevel@tonic-gate int32_t c_count;
17737c478bd9Sstevel@tonic-gate char c_baddr[256];
17747c478bd9Sstevel@tonic-gate } s_ospcl;
17757c478bd9Sstevel@tonic-gate } u_ospcl;
17767c478bd9Sstevel@tonic-gate
17777c478bd9Sstevel@tonic-gate if (cvtflag) {
17787c478bd9Sstevel@tonic-gate readtape((char *)(&u_ospcl.s_ospcl));
17797c478bd9Sstevel@tonic-gate bzero((char *)buf, (size_t)TP_BSIZE_MIN);
17807c478bd9Sstevel@tonic-gate buf->c_type = u_ospcl.s_ospcl.c_type;
17817c478bd9Sstevel@tonic-gate buf->c_date = u_ospcl.s_ospcl.c_date;
17827c478bd9Sstevel@tonic-gate buf->c_ddate = u_ospcl.s_ospcl.c_ddate;
17837c478bd9Sstevel@tonic-gate buf->c_volume = u_ospcl.s_ospcl.c_volume;
17847c478bd9Sstevel@tonic-gate buf->c_tapea = u_ospcl.s_ospcl.c_tapea;
17857c478bd9Sstevel@tonic-gate buf->c_inumber = u_ospcl.s_ospcl.c_inumber;
17867c478bd9Sstevel@tonic-gate buf->c_checksum = u_ospcl.s_ospcl.c_checksum;
17877c478bd9Sstevel@tonic-gate buf->c_magic = u_ospcl.s_ospcl.c_magic;
17887c478bd9Sstevel@tonic-gate buf->c_dinode.di_mode = u_ospcl.s_ospcl.c_dinode.odi_mode;
17897c478bd9Sstevel@tonic-gate /* LINTED: unsigned/signed combination ok */
17907c478bd9Sstevel@tonic-gate buf->c_dinode.di_nlink = u_ospcl.s_ospcl.c_dinode.odi_nlink;
17917c478bd9Sstevel@tonic-gate buf->c_dinode.di_size =
17927c478bd9Sstevel@tonic-gate (unsigned)(u_ospcl.s_ospcl.c_dinode.odi_size);
17937c478bd9Sstevel@tonic-gate buf->c_dinode.di_uid = u_ospcl.s_ospcl.c_dinode.odi_uid;
17947c478bd9Sstevel@tonic-gate buf->c_dinode.di_gid = u_ospcl.s_ospcl.c_dinode.odi_gid;
17957c478bd9Sstevel@tonic-gate buf->c_dinode.di_suid = UID_LONG;
17967c478bd9Sstevel@tonic-gate buf->c_dinode.di_sgid = GID_LONG;
17977c478bd9Sstevel@tonic-gate buf->c_dinode.di_ordev = u_ospcl.s_ospcl.c_dinode.odi_rdev;
17987c478bd9Sstevel@tonic-gate buf->c_dinode.di_atime = u_ospcl.s_ospcl.c_dinode.odi_atime;
17997c478bd9Sstevel@tonic-gate buf->c_dinode.di_mtime = u_ospcl.s_ospcl.c_dinode.odi_mtime;
18007c478bd9Sstevel@tonic-gate buf->c_dinode.di_ctime = u_ospcl.s_ospcl.c_dinode.odi_ctime;
18017c478bd9Sstevel@tonic-gate buf->c_count = u_ospcl.s_ospcl.c_count;
18027c478bd9Sstevel@tonic-gate bcopy(u_ospcl.s_ospcl.c_baddr, buf->c_addr,
18037c478bd9Sstevel@tonic-gate sizeof (u_ospcl.s_ospcl.c_baddr));
18047c478bd9Sstevel@tonic-gate
18057c478bd9Sstevel@tonic-gate /*CONSTANTCONDITION*/
18067c478bd9Sstevel@tonic-gate assert(sizeof (u_ospcl.s_ospcl) < sizeof (union u_spcl));
18077c478bd9Sstevel@tonic-gate
18087c478bd9Sstevel@tonic-gate /* we byte-swap the new spclrec, but checksum the old */
18097c478bd9Sstevel@tonic-gate /* (see comments in normspcl()) */
18107c478bd9Sstevel@tonic-gate if (normspcl(byteorder, buf,
18117c478bd9Sstevel@tonic-gate (int *)(&u_ospcl.s_ospcl), sizeof (u_ospcl.s_ospcl),
18127c478bd9Sstevel@tonic-gate OFS_MAGIC))
18137c478bd9Sstevel@tonic-gate return (FAIL);
18147c478bd9Sstevel@tonic-gate buf->c_magic =
18157c478bd9Sstevel@tonic-gate ((tp_bsize == TP_BSIZE_MIN) ? NFS_MAGIC : MTB_MAGIC);
18167c478bd9Sstevel@tonic-gate } else {
18177c478bd9Sstevel@tonic-gate readtape((char *)buf);
18187c478bd9Sstevel@tonic-gate if (normspcl(byteorder, buf, (int *)buf, tp_bsize,
18197c478bd9Sstevel@tonic-gate ((tp_bsize == TP_BSIZE_MIN) ? NFS_MAGIC : MTB_MAGIC)))
18207c478bd9Sstevel@tonic-gate return (FAIL);
18217c478bd9Sstevel@tonic-gate }
18227c478bd9Sstevel@tonic-gate
18237c478bd9Sstevel@tonic-gate switch (buf->c_type) {
18247c478bd9Sstevel@tonic-gate
18257c478bd9Sstevel@tonic-gate case TS_CLRI:
18267c478bd9Sstevel@tonic-gate case TS_BITS:
18277c478bd9Sstevel@tonic-gate /*
18287c478bd9Sstevel@tonic-gate * Have to patch up missing information in bit map headers
18297c478bd9Sstevel@tonic-gate */
18307c478bd9Sstevel@tonic-gate buf->c_inumber = 0;
18317c478bd9Sstevel@tonic-gate buf->c_dinode.di_size = (offset_t)buf->c_count * tp_bsize;
18327c478bd9Sstevel@tonic-gate for (i = 0; i < buf->c_count && i < TP_NINDIR; i++)
18337c478bd9Sstevel@tonic-gate buf->c_addr[i] = 1;
18347c478bd9Sstevel@tonic-gate break;
18357c478bd9Sstevel@tonic-gate
18367c478bd9Sstevel@tonic-gate case TS_TAPE:
18377c478bd9Sstevel@tonic-gate case TS_END:
18387c478bd9Sstevel@tonic-gate if (dumpinfo.c_date == 0) {
18397c478bd9Sstevel@tonic-gate dumpinfo.c_date = spcl.c_date;
18407c478bd9Sstevel@tonic-gate dumpinfo.c_ddate = spcl.c_ddate;
18417c478bd9Sstevel@tonic-gate }
18427c478bd9Sstevel@tonic-gate if (!hostinfo && spcl.c_host[0] != '\0') {
18437c478bd9Sstevel@tonic-gate bcopy(spcl.c_label, dumpinfo.c_label,
18447c478bd9Sstevel@tonic-gate sizeof (spcl.c_label));
18457c478bd9Sstevel@tonic-gate bcopy(spcl.c_filesys, dumpinfo.c_filesys,
18467c478bd9Sstevel@tonic-gate sizeof (spcl.c_filesys));
18477c478bd9Sstevel@tonic-gate bcopy(spcl.c_dev, dumpinfo.c_dev,
18487c478bd9Sstevel@tonic-gate sizeof (spcl.c_dev));
18497c478bd9Sstevel@tonic-gate bcopy(spcl.c_host, dumpinfo.c_host,
18507c478bd9Sstevel@tonic-gate sizeof (spcl.c_host));
18517c478bd9Sstevel@tonic-gate dumpinfo.c_level = spcl.c_level;
18527c478bd9Sstevel@tonic-gate hostinfo++;
18537c478bd9Sstevel@tonic-gate if (c_label != NULL &&
18547c478bd9Sstevel@tonic-gate strncmp(c_label, spcl.c_label,
18552720c984Svk sizeof (spcl.c_label))
18567c478bd9Sstevel@tonic-gate != 0) {
18577c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
18587c478bd9Sstevel@tonic-gate "Incorrect tape label. Expected `%s', got `%.*s'\n"),
18597c478bd9Sstevel@tonic-gate c_label,
18607c478bd9Sstevel@tonic-gate sizeof (spcl.c_label), spcl.c_label);
18617c478bd9Sstevel@tonic-gate done(1);
18627c478bd9Sstevel@tonic-gate }
18637c478bd9Sstevel@tonic-gate }
18647c478bd9Sstevel@tonic-gate if (!inodeinfo && (spcl.c_flags & DR_INODEINFO)) {
18657c478bd9Sstevel@tonic-gate dumpinfo.c_volume = spcl.c_volume;
18667c478bd9Sstevel@tonic-gate bcopy(spcl.c_inos, dumpinfo.c_inos,
18677c478bd9Sstevel@tonic-gate sizeof (spcl.c_inos));
18687c478bd9Sstevel@tonic-gate inodeinfo++;
18697c478bd9Sstevel@tonic-gate }
18707c478bd9Sstevel@tonic-gate buf->c_inumber = 0;
18717c478bd9Sstevel@tonic-gate break;
18727c478bd9Sstevel@tonic-gate
18737c478bd9Sstevel@tonic-gate case TS_INODE:
18747c478bd9Sstevel@tonic-gate case TS_ADDR:
18757c478bd9Sstevel@tonic-gate break;
18767c478bd9Sstevel@tonic-gate
18777c478bd9Sstevel@tonic-gate default:
18787c478bd9Sstevel@tonic-gate panic(gettext("%s: unknown inode type %d\n"),
18792720c984Svk "gethead", buf->c_type);
18807c478bd9Sstevel@tonic-gate return (FAIL);
18817c478bd9Sstevel@tonic-gate }
18827c478bd9Sstevel@tonic-gate if (dflag)
18837c478bd9Sstevel@tonic-gate accthdr(buf);
18847c478bd9Sstevel@tonic-gate return (GOOD);
18857c478bd9Sstevel@tonic-gate }
18867c478bd9Sstevel@tonic-gate
18877c478bd9Sstevel@tonic-gate /*
18887c478bd9Sstevel@tonic-gate * Check that a header is where it belongs and predict the next header
18897c478bd9Sstevel@tonic-gate */
18907c478bd9Sstevel@tonic-gate static void
accthdr(struct s_spcl * header)1891fe0e7ec4Smaheshvs accthdr(struct s_spcl *header)
18927c478bd9Sstevel@tonic-gate {
18937c478bd9Sstevel@tonic-gate static ino_t previno = (ino_t)(unsigned)-1;
18947c478bd9Sstevel@tonic-gate static int prevtype;
18957c478bd9Sstevel@tonic-gate static long predict;
18967c478bd9Sstevel@tonic-gate int blks, i;
18977c478bd9Sstevel@tonic-gate
18987c478bd9Sstevel@tonic-gate if (header->c_type == TS_TAPE) {
18997c478bd9Sstevel@tonic-gate if (header->c_firstrec)
19007c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
19017c478bd9Sstevel@tonic-gate gettext("Volume header begins with record %d"),
19027c478bd9Sstevel@tonic-gate header->c_firstrec);
19037c478bd9Sstevel@tonic-gate else
19047c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Volume header"));
19057c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\n");
19067c478bd9Sstevel@tonic-gate previno = (ino_t)(unsigned)-1;
19077c478bd9Sstevel@tonic-gate return;
19087c478bd9Sstevel@tonic-gate }
19097c478bd9Sstevel@tonic-gate if (previno == (ino_t)(unsigned)-1)
19107c478bd9Sstevel@tonic-gate goto newcalc;
19117c478bd9Sstevel@tonic-gate switch (prevtype) {
19127c478bd9Sstevel@tonic-gate case TS_BITS:
19137c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Dump mask header"));
19147c478bd9Sstevel@tonic-gate break;
19157c478bd9Sstevel@tonic-gate case TS_CLRI:
19167c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Remove mask header"));
19177c478bd9Sstevel@tonic-gate break;
19187c478bd9Sstevel@tonic-gate case TS_INODE:
19197c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
19207c478bd9Sstevel@tonic-gate gettext("File header, ino %d at record %d"),
19217c478bd9Sstevel@tonic-gate previno, rec_position);
19227c478bd9Sstevel@tonic-gate break;
19237c478bd9Sstevel@tonic-gate case TS_ADDR:
19247c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
19257c478bd9Sstevel@tonic-gate gettext("File continuation header, ino %d"),
19267c478bd9Sstevel@tonic-gate previno);
19277c478bd9Sstevel@tonic-gate break;
19287c478bd9Sstevel@tonic-gate case TS_END:
19297c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("End of media header"));
19307c478bd9Sstevel@tonic-gate break;
19317c478bd9Sstevel@tonic-gate }
19327c478bd9Sstevel@tonic-gate if (predict != blksread - 1)
19337c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
19347c478bd9Sstevel@tonic-gate gettext("; predicted %ld blocks, got %ld blocks"),
19357c478bd9Sstevel@tonic-gate predict, blksread - 1);
19367c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\n");
19377c478bd9Sstevel@tonic-gate newcalc:
19387c478bd9Sstevel@tonic-gate blks = 0;
19397c478bd9Sstevel@tonic-gate if (header->c_type != TS_END)
19407c478bd9Sstevel@tonic-gate for (i = 0; i < header->c_count; i++)
19417c478bd9Sstevel@tonic-gate if ((i >= TP_NINDIR) || (header->c_addr[i] != 0))
19427c478bd9Sstevel@tonic-gate blks++;
19437c478bd9Sstevel@tonic-gate predict = blks;
19447c478bd9Sstevel@tonic-gate blksread = 0;
19457c478bd9Sstevel@tonic-gate prevtype = header->c_type;
19467c478bd9Sstevel@tonic-gate previno = header->c_inumber;
19477c478bd9Sstevel@tonic-gate }
19487c478bd9Sstevel@tonic-gate
19497c478bd9Sstevel@tonic-gate /*
19507c478bd9Sstevel@tonic-gate * Try to determine which volume a file resides on.
19517c478bd9Sstevel@tonic-gate */
1952fe0e7ec4Smaheshvs int
volnumber(ino_t inum)1953fe0e7ec4Smaheshvs volnumber(ino_t inum)
19547c478bd9Sstevel@tonic-gate {
19557c478bd9Sstevel@tonic-gate int i;
19567c478bd9Sstevel@tonic-gate
19577c478bd9Sstevel@tonic-gate if (inodeinfo == 0)
19587c478bd9Sstevel@tonic-gate return (0);
19597c478bd9Sstevel@tonic-gate for (i = 1; i <= dumpinfo.c_volume; i++)
19607c478bd9Sstevel@tonic-gate if (inum < (ino_t)(unsigned)(dumpinfo.c_inos[i]))
19617c478bd9Sstevel@tonic-gate break;
19627c478bd9Sstevel@tonic-gate return (i - 1);
19637c478bd9Sstevel@tonic-gate }
19647c478bd9Sstevel@tonic-gate
19657c478bd9Sstevel@tonic-gate /*
19667c478bd9Sstevel@tonic-gate * Find an inode header.
19677c478bd9Sstevel@tonic-gate * Note that *header must be stable storage, as curfile will end up with
19687c478bd9Sstevel@tonic-gate * pointers into it.
19697c478bd9Sstevel@tonic-gate */
19707c478bd9Sstevel@tonic-gate void
findinode(struct s_spcl * header)1971fe0e7ec4Smaheshvs findinode(struct s_spcl *header)
19727c478bd9Sstevel@tonic-gate {
19737c478bd9Sstevel@tonic-gate long skipcnt = 0;
19747c478bd9Sstevel@tonic-gate int i;
19757c478bd9Sstevel@tonic-gate char buf[TP_BSIZE_MAX];
19767c478bd9Sstevel@tonic-gate
19777c478bd9Sstevel@tonic-gate curfile.name = gettext("<name unknown>");
19787c478bd9Sstevel@tonic-gate curfile.action = UNKNOWN;
19797c478bd9Sstevel@tonic-gate curfile.dip = (struct dinode *)NULL;
19807c478bd9Sstevel@tonic-gate curfile.ino = 0;
19817c478bd9Sstevel@tonic-gate curfile.ts = 0;
19827c478bd9Sstevel@tonic-gate if (ishead(header) == FAIL) {
19837c478bd9Sstevel@tonic-gate skipcnt++;
19847c478bd9Sstevel@tonic-gate while (gethead(header) == FAIL ||
19857c478bd9Sstevel@tonic-gate (time_t)(header->c_date) != dumpdate)
19867c478bd9Sstevel@tonic-gate skipcnt++;
19877c478bd9Sstevel@tonic-gate }
19887c478bd9Sstevel@tonic-gate for (;;) {
19897c478bd9Sstevel@tonic-gate if (checktype(header, TS_ADDR) == GOOD) {
19907c478bd9Sstevel@tonic-gate /*
19917c478bd9Sstevel@tonic-gate * Skip up to the beginning of the next record
19927c478bd9Sstevel@tonic-gate */
19937c478bd9Sstevel@tonic-gate for (i = 0; i < header->c_count; i++)
19947c478bd9Sstevel@tonic-gate if ((i >= TP_NINDIR) || (header->c_addr[i]))
19957c478bd9Sstevel@tonic-gate readtape(buf);
19967c478bd9Sstevel@tonic-gate (void) gethead(header);
19977c478bd9Sstevel@tonic-gate continue;
19987c478bd9Sstevel@tonic-gate }
19997c478bd9Sstevel@tonic-gate if (checktype(header, TS_INODE) == GOOD) {
20007c478bd9Sstevel@tonic-gate curfile.dip = &header->c_dinode;
20017c478bd9Sstevel@tonic-gate if (curfile.dip->di_suid != UID_LONG)
20027c478bd9Sstevel@tonic-gate curfile.dip->di_uid = curfile.dip->di_suid;
20037c478bd9Sstevel@tonic-gate if (curfile.dip->di_sgid != GID_LONG)
20047c478bd9Sstevel@tonic-gate curfile.dip->di_gid = curfile.dip->di_sgid;
20057c478bd9Sstevel@tonic-gate curfile.ino = header->c_inumber;
20067c478bd9Sstevel@tonic-gate curfile.ts = TS_INODE;
20077c478bd9Sstevel@tonic-gate break;
20087c478bd9Sstevel@tonic-gate }
20097c478bd9Sstevel@tonic-gate if (checktype(header, TS_END) == GOOD) {
20107c478bd9Sstevel@tonic-gate curfile.ino = maxino;
20117c478bd9Sstevel@tonic-gate curfile.ts = TS_END;
20127c478bd9Sstevel@tonic-gate break;
20137c478bd9Sstevel@tonic-gate }
20147c478bd9Sstevel@tonic-gate if (checktype(header, TS_CLRI) == GOOD) {
20157c478bd9Sstevel@tonic-gate curfile.name = gettext("<file removal list>");
20167c478bd9Sstevel@tonic-gate curfile.ts = TS_CLRI;
20177c478bd9Sstevel@tonic-gate break;
20187c478bd9Sstevel@tonic-gate }
20197c478bd9Sstevel@tonic-gate if (checktype(header, TS_BITS) == GOOD) {
20207c478bd9Sstevel@tonic-gate curfile.name = gettext("<file dump list>");
20217c478bd9Sstevel@tonic-gate curfile.ts = TS_BITS;
20227c478bd9Sstevel@tonic-gate break;
20237c478bd9Sstevel@tonic-gate }
20247c478bd9Sstevel@tonic-gate while (gethead(header) == FAIL)
20257c478bd9Sstevel@tonic-gate skipcnt++;
20267c478bd9Sstevel@tonic-gate }
20277c478bd9Sstevel@tonic-gate if (skipcnt > 0)
20287c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
20297c478bd9Sstevel@tonic-gate gettext("resync restore, skipped %d blocks\n"),
20307c478bd9Sstevel@tonic-gate skipcnt);
20317c478bd9Sstevel@tonic-gate }
20327c478bd9Sstevel@tonic-gate
20337c478bd9Sstevel@tonic-gate /*
20347c478bd9Sstevel@tonic-gate * return whether or not the buffer contains a header block
20357c478bd9Sstevel@tonic-gate */
20367c478bd9Sstevel@tonic-gate static int
ishead(struct s_spcl * buf)2037fe0e7ec4Smaheshvs ishead(struct s_spcl *buf)
20387c478bd9Sstevel@tonic-gate {
20397c478bd9Sstevel@tonic-gate if (buf->c_magic !=
20407c478bd9Sstevel@tonic-gate ((tp_bsize == TP_BSIZE_MIN) ? NFS_MAGIC : MTB_MAGIC))
20417c478bd9Sstevel@tonic-gate return (FAIL);
20427c478bd9Sstevel@tonic-gate return (GOOD);
20437c478bd9Sstevel@tonic-gate }
20447c478bd9Sstevel@tonic-gate
2045fe0e7ec4Smaheshvs static int
checktype(struct s_spcl * b,int t)2046fe0e7ec4Smaheshvs checktype(struct s_spcl *b, int t)
20477c478bd9Sstevel@tonic-gate {
20487c478bd9Sstevel@tonic-gate if (b->c_type != t)
20497c478bd9Sstevel@tonic-gate return (FAIL);
20507c478bd9Sstevel@tonic-gate return (GOOD);
20517c478bd9Sstevel@tonic-gate }
20527c478bd9Sstevel@tonic-gate
20537c478bd9Sstevel@tonic-gate /*
20547c478bd9Sstevel@tonic-gate * If autoloading is enabled, attempt to do it. If we succeed,
20557c478bd9Sstevel@tonic-gate * return non-zero.
20567c478bd9Sstevel@tonic-gate */
20577c478bd9Sstevel@tonic-gate static int
autoload_tape(void)20587c478bd9Sstevel@tonic-gate autoload_tape(void)
20597c478bd9Sstevel@tonic-gate {
20607c478bd9Sstevel@tonic-gate int result = 0; /* assume failure */
20617c478bd9Sstevel@tonic-gate int tries;
20627c478bd9Sstevel@tonic-gate int fd;
20637c478bd9Sstevel@tonic-gate
20647c478bd9Sstevel@tonic-gate if (autoload) {
20657c478bd9Sstevel@tonic-gate /*
20667c478bd9Sstevel@tonic-gate * Wait for the tape to autoload. Note that the delay
20677c478bd9Sstevel@tonic-gate * period doesn't take into account however long it takes
20687c478bd9Sstevel@tonic-gate * for the open to fail (measured at 21 seconds for an
20697c478bd9Sstevel@tonic-gate * Exabyte 8200 under 2.7 on an Ultra 2).
20707c478bd9Sstevel@tonic-gate */
207133a5e6b2Srm
207233a5e6b2Srm /* rewind tape and offline drive before loading new tape */
207333a5e6b2Srm closemt(FORCE_OFFLINE);
20747c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
20757c478bd9Sstevel@tonic-gate gettext("Attempting to autoload next volume\n"));
20767c478bd9Sstevel@tonic-gate for (tries = 0; tries < autoload_tries; tries++) {
20777c478bd9Sstevel@tonic-gate if (host) {
20787c478bd9Sstevel@tonic-gate if (rmtopen(magtape, O_RDONLY) >= 0) {
20797c478bd9Sstevel@tonic-gate rmtclose();
20807c478bd9Sstevel@tonic-gate result = 1;
20817c478bd9Sstevel@tonic-gate break;
20827c478bd9Sstevel@tonic-gate }
20837c478bd9Sstevel@tonic-gate } else {
20847c478bd9Sstevel@tonic-gate if ((fd = open(magtape, O_RDONLY|O_LARGEFILE,
20857c478bd9Sstevel@tonic-gate 0600)) >= 0) {
20867c478bd9Sstevel@tonic-gate (void) close(fd);
20877c478bd9Sstevel@tonic-gate result = 1;
20887c478bd9Sstevel@tonic-gate break;
20897c478bd9Sstevel@tonic-gate }
20907c478bd9Sstevel@tonic-gate }
20917c478bd9Sstevel@tonic-gate (void) sleep(autoload_period);
20927c478bd9Sstevel@tonic-gate }
20937c478bd9Sstevel@tonic-gate if (result == 0) {
20947c478bd9Sstevel@tonic-gate /* Assume caller will deal with manual change-over */
20957c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
20967c478bd9Sstevel@tonic-gate gettext("Autoload timed out\n"));
20977c478bd9Sstevel@tonic-gate } else {
20987c478bd9Sstevel@tonic-gate if ((host != NULL &&
20997c478bd9Sstevel@tonic-gate (mt = rmtopen(magtape, O_RDONLY)) == -1) ||
21007c478bd9Sstevel@tonic-gate (host == NULL &&
21017c478bd9Sstevel@tonic-gate (mt = open(magtape, O_RDONLY|O_LARGEFILE)) == -1)) {
21027c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
21037c478bd9Sstevel@tonic-gate "Autoload could not re-open tape\n"));
21047c478bd9Sstevel@tonic-gate result = 0;
21057c478bd9Sstevel@tonic-gate } else {
21067c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
21077c478bd9Sstevel@tonic-gate "Tape loaded\n"));
21087c478bd9Sstevel@tonic-gate }
21097c478bd9Sstevel@tonic-gate }
21107c478bd9Sstevel@tonic-gate }
21117c478bd9Sstevel@tonic-gate
21127c478bd9Sstevel@tonic-gate return (result);
21137c478bd9Sstevel@tonic-gate }
2114