17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*d1a180b0Smaheshvs * Common Development and Distribution License (the "License").
6*d1a180b0Smaheshvs * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
226451fdbcSvsakar * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
317c478bd9Sstevel@tonic-gate * The Regents of the University of California
327c478bd9Sstevel@tonic-gate * All Rights Reserved
337c478bd9Sstevel@tonic-gate *
347c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
357c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
367c478bd9Sstevel@tonic-gate * contributors.
377c478bd9Sstevel@tonic-gate */
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate #include <sys/param.h>
427c478bd9Sstevel@tonic-gate #include <signal.h>
437c478bd9Sstevel@tonic-gate #include <sys/types.h>
447c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
457c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
467c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fsdir.h>
477c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_inode.h>
487c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h>
497c478bd9Sstevel@tonic-gate #include <sys/stat.h>
507c478bd9Sstevel@tonic-gate #include <sys/statvfs.h>
517c478bd9Sstevel@tonic-gate #include <fcntl.h>
527c478bd9Sstevel@tonic-gate #include <stdio.h>
537c478bd9Sstevel@tonic-gate #include <unistd.h>
547c478bd9Sstevel@tonic-gate #include <stdlib.h>
557c478bd9Sstevel@tonic-gate #include <errno.h>
567c478bd9Sstevel@tonic-gate #include <signal.h>
577c478bd9Sstevel@tonic-gate #include <stdarg.h>
587c478bd9Sstevel@tonic-gate #include <sys/errno.h>
597c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
607c478bd9Sstevel@tonic-gate #include <sys/ipc.h>
617c478bd9Sstevel@tonic-gate #include <sys/sem.h>
627c478bd9Sstevel@tonic-gate #include <sys/shm.h>
637c478bd9Sstevel@tonic-gate #include <archives.h>
647c478bd9Sstevel@tonic-gate #include "volcopy.h"
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate #include <locale.h>
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate * main I/O information structure, contains information for the
707c478bd9Sstevel@tonic-gate * source and destination files.
717c478bd9Sstevel@tonic-gate */
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate struct file_info {
747c478bd9Sstevel@tonic-gate char *f_dev_p, /* name of device */
757c478bd9Sstevel@tonic-gate *f_vol_p; /* volume name */
767c478bd9Sstevel@tonic-gate int f_bsize, /* size to buffer I/O to */
777c478bd9Sstevel@tonic-gate f_des, /* file descriptor */
787c478bd9Sstevel@tonic-gate f_dev; /* device type (generic I/O library) */
797c478bd9Sstevel@tonic-gate } In, Out;
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate int Sem_id[BUFCNT], /* semaphore ids for controlling shared memory */
837c478bd9Sstevel@tonic-gate Shm_id[BUFCNT], /* shared memory identifier */
847c478bd9Sstevel@tonic-gate *Cnts[BUFCNT]; /* an array of byte counts for shared memory */
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate char Empty[BLKSIZ], /* empty memory used to clear sections of memory */
877c478bd9Sstevel@tonic-gate *Buf[BUFCNT]; /* buffer pointers (possibly to shared memory) */
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate struct sembuf Sem_buf, /* semaphore operation buffer */
907c478bd9Sstevel@tonic-gate Rstsem_buf; /* semaphore reset operation buffer */
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate typedef union {
937c478bd9Sstevel@tonic-gate char dummy[SBSIZE];
947c478bd9Sstevel@tonic-gate struct fs sblk;
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate } sb_un;
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate sb_un isup, osup, tsup;
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate #define Isup isup.sblk
1017c478bd9Sstevel@tonic-gate #define Osup osup.sblk
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate struct fs *Sptr = (struct fs *)&tsup.sblk; /* super-block pointer */
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate char *Ifname, *Ifpack, *Ofname, *Ofpack;
1067c478bd9Sstevel@tonic-gate struct volcopy_label V_labl;
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate char From_vol[VVOLLEN + 1],
1097c478bd9Sstevel@tonic-gate To_vol[VVOLLEN + 1],
1107c478bd9Sstevel@tonic-gate *Fsys_p;
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate static char *nolabel = ""; /* used when there is no room for label */
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate int Blk_cnt = 1, /* Do I/O in (Blk_cnt * BLKSIZ) byte blocks */
1157c478bd9Sstevel@tonic-gate Blocks = 0, /* Number of blocks transferred */
1167c478bd9Sstevel@tonic-gate Bpi = 0,
1177c478bd9Sstevel@tonic-gate Bufcnt,
1187c478bd9Sstevel@tonic-gate Bufflg = 0,
1197c478bd9Sstevel@tonic-gate Bufsz = BLKSIZ,
1207c478bd9Sstevel@tonic-gate Disk_cnt = 1, /* Disk I/O (Disk_cnt * Blk_cnt * BLKSIZ) byte blocks */
1217c478bd9Sstevel@tonic-gate Drive_typ = 0, /* Flag for special tape drive types */
1227c478bd9Sstevel@tonic-gate Eomflg = 0,
1237c478bd9Sstevel@tonic-gate Ipc = 0,
1247c478bd9Sstevel@tonic-gate Itape,
1257c478bd9Sstevel@tonic-gate M3b15 = 0, /* Machine types, set to 1 for the machine */
1267c478bd9Sstevel@tonic-gate M3b2 = 0, /* the command is executing on */
1277c478bd9Sstevel@tonic-gate Otape,
1287c478bd9Sstevel@tonic-gate Pid = -1,
1297c478bd9Sstevel@tonic-gate R_blks = 0, /* Number of blocks per tape reel */
1307c478bd9Sstevel@tonic-gate R_cur = 1, /* Current tape reel being processed */
1317c478bd9Sstevel@tonic-gate R_len = 0, /* Length in feet of tape reels */
1327c478bd9Sstevel@tonic-gate R_num = 0, /* Number of tape reels to be processed */
1337c478bd9Sstevel@tonic-gate Shell_esc = 1, /* Allow shell after delete -nosh (3b15) can disable */
1347c478bd9Sstevel@tonic-gate Yesflg = 0;
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate void (*singal())();
1377c478bd9Sstevel@tonic-gate long Fs,
1387c478bd9Sstevel@tonic-gate Fstype;
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate time_t Tvec;
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate FILE *Devtty;
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate static void getinfs(),
1457c478bd9Sstevel@tonic-gate getoutfs();
1467c478bd9Sstevel@tonic-gate
147*d1a180b0Smaheshvs static char *getfslabel(struct fs *);
148*d1a180b0Smaheshvs static char *getvolabel(struct fs *);
149*d1a180b0Smaheshvs static void prompt(int, const char *, ...);
150*d1a180b0Smaheshvs static void perr(int, const char *, ...);
151*d1a180b0Smaheshvs static void mklabel(void);
152*d1a180b0Smaheshvs static void get_mach_type(void);
153*d1a180b0Smaheshvs static void mem_setup(void);
154*d1a180b0Smaheshvs static void rprt(void);
155*d1a180b0Smaheshvs static void chgreel(struct file_info *, int);
156*d1a180b0Smaheshvs static void parent_copy(void);
157*d1a180b0Smaheshvs static void copy(void);
158*d1a180b0Smaheshvs static void flush_bufs(int);
159*d1a180b0Smaheshvs static void cleanup(void);
160*d1a180b0Smaheshvs
161*d1a180b0Smaheshvs #ifdef LOG
162*d1a180b0Smaheshvs static int fslog(void);
163*d1a180b0Smaheshvs #endif /* LOG */
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate /*
1667c478bd9Sstevel@tonic-gate * g_init(), g_read(), g_write() originally came from libgenIO,
1677c478bd9Sstevel@tonic-gate * a totally obsolete device interface library, now deleted.
1687c478bd9Sstevel@tonic-gate * volcopy should be deleted too, since it doesn't work.
1697c478bd9Sstevel@tonic-gate */
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate #define G_TM_TAPE 1 /* Tapemaster controller */
1727c478bd9Sstevel@tonic-gate #define G_XY_DISK 3 /* xy disks */
1737c478bd9Sstevel@tonic-gate #define G_SD_DISK 7 /* scsi sd disk */
1747c478bd9Sstevel@tonic-gate #define G_XT_TAPE 8 /* xt tapes */
1757c478bd9Sstevel@tonic-gate #define G_SF_FLOPPY 9 /* sf floppy */
1767c478bd9Sstevel@tonic-gate #define G_XD_DISK 10 /* xd disks */
1777c478bd9Sstevel@tonic-gate #define G_ST_TAPE 11 /* scsi tape */
1787c478bd9Sstevel@tonic-gate #define G_NS 12 /* noswap pseudo-dev */
1797c478bd9Sstevel@tonic-gate #define G_RAM 13 /* ram pseudo-dev */
1807c478bd9Sstevel@tonic-gate #define G_FT 14 /* tftp */
1817c478bd9Sstevel@tonic-gate #define G_HD 15 /* 386 network disk */
1827c478bd9Sstevel@tonic-gate #define G_FD 16 /* 386 AT disk */
1837c478bd9Sstevel@tonic-gate #define G_FILE 28 /* file, not a device */
1847c478bd9Sstevel@tonic-gate #define G_NO_DEV 29 /* device does not require special treatment */
1857c478bd9Sstevel@tonic-gate #define G_DEV_MAX 30 /* last valid device type */
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate * g_init: Determine the device being accessed, set the buffer size,
1897c478bd9Sstevel@tonic-gate * and perform any device specific initialization. Since at this point
1907c478bd9Sstevel@tonic-gate * Sun has no system call to read the configuration, the major numbers
1917c478bd9Sstevel@tonic-gate * are assumed to be static and types are figured out as such. However,
1927c478bd9Sstevel@tonic-gate * as a rough estimate, the buffer size for all types is set to 512
1937c478bd9Sstevel@tonic-gate * as a default.
1947c478bd9Sstevel@tonic-gate */
1957c478bd9Sstevel@tonic-gate static int
g_init(int * devtype,int * fdes)1967c478bd9Sstevel@tonic-gate g_init(int *devtype, int *fdes)
1977c478bd9Sstevel@tonic-gate {
1987c478bd9Sstevel@tonic-gate major_t maj;
1997c478bd9Sstevel@tonic-gate int bufsize;
2007c478bd9Sstevel@tonic-gate struct stat64 st_buf;
2017c478bd9Sstevel@tonic-gate struct statvfs64 stfs_buf;
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate *devtype = G_NO_DEV;
2047c478bd9Sstevel@tonic-gate if (fstat64(*fdes, &st_buf) == -1)
2057c478bd9Sstevel@tonic-gate return (-1);
2064bc0a2efScasper if (!S_ISCHR(st_buf.st_mode) && !S_ISBLK(st_buf.st_mode)) {
2074bc0a2efScasper if (S_ISFIFO(st_buf.st_mode))
2087c478bd9Sstevel@tonic-gate bufsize = 512;
2097c478bd9Sstevel@tonic-gate else {
2107c478bd9Sstevel@tonic-gate /* find block size for this file system */
2117c478bd9Sstevel@tonic-gate *devtype = G_FILE;
2127c478bd9Sstevel@tonic-gate if (fstatvfs64(*fdes, &stfs_buf) < 0) {
2137c478bd9Sstevel@tonic-gate bufsize = -1;
2147c478bd9Sstevel@tonic-gate errno = ENODEV;
2157c478bd9Sstevel@tonic-gate } else {
2167c478bd9Sstevel@tonic-gate bufsize = stfs_buf.f_bsize;
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate return (bufsize);
2207c478bd9Sstevel@tonic-gate }
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate return (512);
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate /*
2267c478bd9Sstevel@tonic-gate * g_read: Read nbytes of data from fdes (of type devtype) and place
2277c478bd9Sstevel@tonic-gate * data in location pointed to by buf. In case of end of medium,
2287c478bd9Sstevel@tonic-gate * translate (where necessary) device specific EOM indications into
2297c478bd9Sstevel@tonic-gate * the generic EOM indication of rv = -1, errno = ENOSPC.
2307c478bd9Sstevel@tonic-gate */
2317c478bd9Sstevel@tonic-gate /* ARGSUSED */
2327c478bd9Sstevel@tonic-gate static ssize_t
g_read(int devtype,int fdes,void * buf,size_t nbytes)2337c478bd9Sstevel@tonic-gate g_read(int devtype, int fdes, void *buf, size_t nbytes)
2347c478bd9Sstevel@tonic-gate {
2357c478bd9Sstevel@tonic-gate ssize_t rv;
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate rv = read(fdes, buf, nbytes);
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate /* st devices return 0 when no space left */
2407c478bd9Sstevel@tonic-gate if ((rv == 0 && errno == 0) || (rv == -1 && errno == EIO)) {
2417c478bd9Sstevel@tonic-gate errno = ENOSPC;
2427c478bd9Sstevel@tonic-gate rv = -1;
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate return (rv);
2467c478bd9Sstevel@tonic-gate }
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate /*
2497c478bd9Sstevel@tonic-gate * g_write: Write nbytes of data to fdes (of type devtype) from
2507c478bd9Sstevel@tonic-gate * the location pointed to by buf. In case of end of medium,
2517c478bd9Sstevel@tonic-gate * translate (where necessary) device specific EOM indications into
2527c478bd9Sstevel@tonic-gate * the generic EOM indication of rv = -1, errno = ENOSPC.
2537c478bd9Sstevel@tonic-gate */
2547c478bd9Sstevel@tonic-gate /* ARGSUSED */
2557c478bd9Sstevel@tonic-gate static ssize_t
g_write(int devtype,int fdes,void * buf,size_t nbytes)2567c478bd9Sstevel@tonic-gate g_write(int devtype, int fdes, void *buf, size_t nbytes)
2577c478bd9Sstevel@tonic-gate {
2587c478bd9Sstevel@tonic-gate ssize_t rv;
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate rv = write(fdes, buf, nbytes);
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate /* st devices return 0 when no more space left */
2637c478bd9Sstevel@tonic-gate if ((rv == 0 && errno == 0) || (rv == -1 && errno == EIO)) {
2647c478bd9Sstevel@tonic-gate errno = ENOSPC;
2657c478bd9Sstevel@tonic-gate rv = -1;
2667c478bd9Sstevel@tonic-gate }
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate return (rv);
2697c478bd9Sstevel@tonic-gate }
2707c478bd9Sstevel@tonic-gate
2717c478bd9Sstevel@tonic-gate /*
2727c478bd9Sstevel@tonic-gate * filesystem copy with propagation of volume ID and filesystem name:
2737c478bd9Sstevel@tonic-gate *
2747c478bd9Sstevel@tonic-gate * volcopy [-options] filesystem /dev/from From_vol /dev/to To_vol
2757c478bd9Sstevel@tonic-gate *
2767c478bd9Sstevel@tonic-gate * options are:
2777c478bd9Sstevel@tonic-gate * -feet - length of tape
2787c478bd9Sstevel@tonic-gate * -bpi - recording density
2797c478bd9Sstevel@tonic-gate * -reel - reel number (if not starting from beginning)
2807c478bd9Sstevel@tonic-gate * -buf - use double buffered i/o (if dens >= 1600 bpi)
2817c478bd9Sstevel@tonic-gate * -block - Set the transfer block size to NUM physical blocks (512
2827c478bd9Sstevel@tonic-gate * bytes on 3B2 and 3B15). Note that an arbitrary block size might
2837c478bd9Sstevel@tonic-gate * or might not work on a given system. Also, the block size
2847c478bd9Sstevel@tonic-gate * read from the header of an input tape silently overrides this.
2857c478bd9Sstevel@tonic-gate * -nosh - Don't offer the user a shell after hitting break or delete.
2867c478bd9Sstevel@tonic-gate * -r - Read NUM transfer blocks from the disk at once and write it
2877c478bd9Sstevel@tonic-gate * to the output device one block at a time. Intended only to
2887c478bd9Sstevel@tonic-gate * boost the 3B15 EDFC disk to tape performance. Disabled on 3B2.
2897c478bd9Sstevel@tonic-gate * -a - ask "y or n" instead of "DEL if wrong"
2907c478bd9Sstevel@tonic-gate * -s - inverse of -a, from/to devices are printed followed by `?'.
2917c478bd9Sstevel@tonic-gate * User has 10 seconds to DEL if mistaken!
2927c478bd9Sstevel@tonic-gate * -y - assume "yes" response to all questions
2937c478bd9Sstevel@tonic-gate *
2947c478bd9Sstevel@tonic-gate * Examples:
2957c478bd9Sstevel@tonic-gate *
2967c478bd9Sstevel@tonic-gate * volcopy root /dev/rdsk/0s2 pk5 /dev/rdsk/1s2 pk12
2977c478bd9Sstevel@tonic-gate *
2987c478bd9Sstevel@tonic-gate * volcopy u3 /dev/rdsk/1s5 pk1 /dev/rmt/0m tp123
2997c478bd9Sstevel@tonic-gate *
3007c478bd9Sstevel@tonic-gate * volcopy u5 /dev/rmt/0m - /dev/rdsk/1s5 -
3017c478bd9Sstevel@tonic-gate */
3027c478bd9Sstevel@tonic-gate
303*d1a180b0Smaheshvs int
main(int argc,char * argv[])304*d1a180b0Smaheshvs main(int argc, char *argv[])
3057c478bd9Sstevel@tonic-gate {
306*d1a180b0Smaheshvs char c;
307*d1a180b0Smaheshvs int lfdes, altflg = 0, result, verify;
308*d1a180b0Smaheshvs long dist;
3097c478bd9Sstevel@tonic-gate char *align();
3107c478bd9Sstevel@tonic-gate void sigalrm(), sigint();
3117c478bd9Sstevel@tonic-gate struct stat stbuf;
3127c478bd9Sstevel@tonic-gate int cnt;
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
3157c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
3167c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
3177c478bd9Sstevel@tonic-gate #endif
3187c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate (void) get_mach_type();
3217c478bd9Sstevel@tonic-gate (void) signal(SIGINT, sigint);
3227c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, sigalrm);
3237c478bd9Sstevel@tonic-gate In.f_bsize = Out.f_bsize = BLKSIZ;
3247c478bd9Sstevel@tonic-gate while (argc > 1 && argv[1][0] == '-') {
3257c478bd9Sstevel@tonic-gate if (EQ(argv[1], "-a", 2)) {
3267c478bd9Sstevel@tonic-gate altflg |= MINUSA;
3277c478bd9Sstevel@tonic-gate } else if (EQ(argv[1], "-e", 2)) {
3287c478bd9Sstevel@tonic-gate Eomflg = 1;
3297c478bd9Sstevel@tonic-gate } else if (EQ(argv[1], "-s", 2)) {
3307c478bd9Sstevel@tonic-gate altflg |= MINUSS;
3317c478bd9Sstevel@tonic-gate } else if (EQ(argv[1], "-y", 2)) {
3327c478bd9Sstevel@tonic-gate Yesflg++;
3337c478bd9Sstevel@tonic-gate } else if (EQ(argv[1], "-buf", 4)) {
3347c478bd9Sstevel@tonic-gate Bufflg++;
3357c478bd9Sstevel@tonic-gate } else if (EQ(argv[1], "-bpi", 4)) {
3367c478bd9Sstevel@tonic-gate if ((c = argv[1][4]) >= '0' && c <= '9')
3377c478bd9Sstevel@tonic-gate Bpi = getbpi(&argv[1][4]);
3387c478bd9Sstevel@tonic-gate else {
3397c478bd9Sstevel@tonic-gate ++argv;
3407c478bd9Sstevel@tonic-gate --argc;
3417c478bd9Sstevel@tonic-gate Bpi = getbpi(&argv[1][0]);
3427c478bd9Sstevel@tonic-gate }
3437c478bd9Sstevel@tonic-gate } else if (EQ(argv[1], "-feet", 5)) {
3447c478bd9Sstevel@tonic-gate if ((c = argv[1][5]) >= '0' && c <= '9')
3457c478bd9Sstevel@tonic-gate R_len = atoi(&argv[1][5]);
3467c478bd9Sstevel@tonic-gate else {
3477c478bd9Sstevel@tonic-gate ++argv;
3487c478bd9Sstevel@tonic-gate --argc;
3497c478bd9Sstevel@tonic-gate R_len = atoi(&argv[1][0]);
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate } else if (EQ(argv[1], "-reel", 5)) {
3527c478bd9Sstevel@tonic-gate if ((c = argv[1][5]) >= '0' && c <= '9')
3537c478bd9Sstevel@tonic-gate R_cur = atoi(&argv[1][5]);
3547c478bd9Sstevel@tonic-gate else {
3557c478bd9Sstevel@tonic-gate ++argv;
3567c478bd9Sstevel@tonic-gate --argc;
3577c478bd9Sstevel@tonic-gate R_cur = atoi(&argv[1][0]);
3587c478bd9Sstevel@tonic-gate }
3597c478bd9Sstevel@tonic-gate } else if (EQ(argv[1], "-r", 2)) { /* 3b15 only */
3607c478bd9Sstevel@tonic-gate if ((c = argv[1][2]) >= '0' && c <= '9')
3617c478bd9Sstevel@tonic-gate Disk_cnt = atoi(&argv[1][2]);
3627c478bd9Sstevel@tonic-gate else {
3637c478bd9Sstevel@tonic-gate ++argv;
3647c478bd9Sstevel@tonic-gate --argc;
3657c478bd9Sstevel@tonic-gate Disk_cnt = atoi(&argv[1][0]);
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate if (Disk_cnt == 0)
3687c478bd9Sstevel@tonic-gate perr(1, "volcopy: Need a non-zero value for the -r option\n");
3697c478bd9Sstevel@tonic-gate } else if (EQ(argv[1], "-block", 6)) { /* 3b15 only */
3707c478bd9Sstevel@tonic-gate if ((c = argv[1][6]) >= '0' && c <= '9')
3717c478bd9Sstevel@tonic-gate Blk_cnt = atoi(&argv[1][6]);
3727c478bd9Sstevel@tonic-gate else {
3737c478bd9Sstevel@tonic-gate ++argv;
3747c478bd9Sstevel@tonic-gate --argc;
3757c478bd9Sstevel@tonic-gate Blk_cnt = atoi(&argv[1][0]);
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate if (Blk_cnt == 0)
3787c478bd9Sstevel@tonic-gate perr(1, "volcopy: Need a non-zero value for the -block option\n");
3797c478bd9Sstevel@tonic-gate } else if (EQ(argv[1], "-nosh", 5)) { /* 3b15 only */
3807c478bd9Sstevel@tonic-gate Shell_esc = 0;
3817c478bd9Sstevel@tonic-gate } else
3827c478bd9Sstevel@tonic-gate perr(1, "<%s> invalid option\n", argv[1]);
3837c478bd9Sstevel@tonic-gate ++argv;
3847c478bd9Sstevel@tonic-gate --argc;
3857c478bd9Sstevel@tonic-gate } /* argv[1][0] == '-' */
3867c478bd9Sstevel@tonic-gate
3877c478bd9Sstevel@tonic-gate Devtty = fopen("/dev/tty", "r");
3887c478bd9Sstevel@tonic-gate if ((Devtty == NULL) && !isatty(0))
3897c478bd9Sstevel@tonic-gate Devtty = stdin;
3907c478bd9Sstevel@tonic-gate time(&Tvec);
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate if (Eomflg && R_len)
3937c478bd9Sstevel@tonic-gate perr(9, "volcopy: -e and -feet are mutually exclusive\n");
3947c478bd9Sstevel@tonic-gate if ((altflg & MINUSA) && (altflg & MINUSS))
3957c478bd9Sstevel@tonic-gate perr(9, "volcopy: -a and -s are mutually exclusive\n");
3967c478bd9Sstevel@tonic-gate if (argc != 6) /* if mandatory fields not present */
3977c478bd9Sstevel@tonic-gate perr(9, "ufs usage: volcopy [-F ufs] [generic options] \
3987c478bd9Sstevel@tonic-gate fsname /devfrom volfrom /devto volto\n");
3997c478bd9Sstevel@tonic-gate if (!(altflg & MINUSA)) /* -a was not specified, use default (-s) */
4007c478bd9Sstevel@tonic-gate altflg |= MINUSS;
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate In.f_dev_p = argv[DEV_IN];
4037c478bd9Sstevel@tonic-gate Out.f_dev_p = argv[DEV_OUT];
4047c478bd9Sstevel@tonic-gate strncpy(To_vol, argv[VOL_OUT], VVOLLEN);
4057c478bd9Sstevel@tonic-gate To_vol[VVOLLEN] = '\0';
4067c478bd9Sstevel@tonic-gate Out.f_vol_p = &To_vol[0];
4077c478bd9Sstevel@tonic-gate strncpy(From_vol, argv[VOL_IN], VVOLLEN);
4087c478bd9Sstevel@tonic-gate From_vol[VVOLLEN] = '\0';
4097c478bd9Sstevel@tonic-gate In.f_vol_p = &From_vol[0];
4107c478bd9Sstevel@tonic-gate Fsys_p = argv[FIL_SYS];
4117c478bd9Sstevel@tonic-gate
4127c478bd9Sstevel@tonic-gate if ((In.f_des = open(In.f_dev_p, O_RDONLY)) < 1)
4137c478bd9Sstevel@tonic-gate perr(10, "%s: cannot open\n", In.f_dev_p);
4147c478bd9Sstevel@tonic-gate if ((Out.f_des = open(Out.f_dev_p, O_RDONLY)) < 1)
4157c478bd9Sstevel@tonic-gate perr(10, "%s: cannot open\n", Out.f_dev_p);
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate if (fstat(In.f_des, &stbuf) < 0 || (stbuf.st_mode & S_IFMT) != S_IFCHR)
4187c478bd9Sstevel@tonic-gate perr(10, "From device not character-special\n");
4197c478bd9Sstevel@tonic-gate if (fstat(Out.f_des, &stbuf) < 0 || (stbuf.st_mode & S_IFMT) != S_IFCHR)
4207c478bd9Sstevel@tonic-gate perr(10, "To device not character-special\n");
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate if ((Itape = tapeck(&In, INPUT)) == 1)
4237c478bd9Sstevel@tonic-gate R_blks = V_labl.v_reelblks;
4247c478bd9Sstevel@tonic-gate Otape = tapeck(&Out, OUTPUT);
4257c478bd9Sstevel@tonic-gate if (Otape && Itape)
4267c478bd9Sstevel@tonic-gate perr(10, "Use dd(1) command to copy tapes\n");
4277c478bd9Sstevel@tonic-gate (void) mem_setup();
4287c478bd9Sstevel@tonic-gate if (Bufflg && !Ipc)
4297c478bd9Sstevel@tonic-gate perr(1, "The -buf option requires ipc\n");
4307c478bd9Sstevel@tonic-gate if (!Itape && !Otape)
4317c478bd9Sstevel@tonic-gate R_cur = 1;
4327c478bd9Sstevel@tonic-gate if (R_cur == 1 || !Itape) {
4337c478bd9Sstevel@tonic-gate /* read in superblock */
4347c478bd9Sstevel@tonic-gate verify = 0;
4357c478bd9Sstevel@tonic-gate (void) getinfs(In.f_dev, In.f_des, Sptr);
4367c478bd9Sstevel@tonic-gate
4377c478bd9Sstevel@tonic-gate if ((Sptr->fs_magic != FS_MAGIC) &&
4387c478bd9Sstevel@tonic-gate (Sptr->fs_magic != MTB_UFS_MAGIC))
4397c478bd9Sstevel@tonic-gate perr(10, "File System type unknown--get help\n");
4407c478bd9Sstevel@tonic-gate
4416451fdbcSvsakar if (Sptr->fs_magic == FS_MAGIC &&
4426451fdbcSvsakar (Sptr->fs_version != UFS_EFISTYLE4NONEFI_VERSION_2 &&
4436451fdbcSvsakar Sptr->fs_version != UFS_VERSION_MIN))
4446451fdbcSvsakar perr(10, "Unrecognized version of UFS--get help\n");
4456451fdbcSvsakar
4467c478bd9Sstevel@tonic-gate if (Sptr->fs_magic == MTB_UFS_MAGIC &&
4477c478bd9Sstevel@tonic-gate (Sptr->fs_version > MTB_UFS_VERSION_1 ||
4487c478bd9Sstevel@tonic-gate Sptr->fs_version < MTB_UFS_VERSION_MIN))
4497c478bd9Sstevel@tonic-gate perr(10, "Unrecognized version of UFS--get help\n");
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate (void) memcpy(&Isup, Sptr, Sptr->fs_sbsize);
4527c478bd9Sstevel@tonic-gate Ifname = getfslabel(&Isup);
4537c478bd9Sstevel@tonic-gate Ifpack = getvolabel(&Isup);
4547c478bd9Sstevel@tonic-gate Fs = Sptr->fs_size * Sptr->fs_nspf;
4557c478bd9Sstevel@tonic-gate } /* R_cur == 1 || !Itape */
4567c478bd9Sstevel@tonic-gate
4577c478bd9Sstevel@tonic-gate /* read in superblock */
4587c478bd9Sstevel@tonic-gate verify = !Otape || (altflg & MINUSS);
4597c478bd9Sstevel@tonic-gate (void) getoutfs(Out.f_dev, Out.f_des, Sptr, verify);
4607c478bd9Sstevel@tonic-gate
4617c478bd9Sstevel@tonic-gate if ((Sptr->fs_magic == FS_MAGIC) || (Sptr->fs_magic == MTB_UFS_MAGIC)) {
4627c478bd9Sstevel@tonic-gate (void) memcpy(&Osup, Sptr, Sptr->fs_sbsize);
4637c478bd9Sstevel@tonic-gate Ofname = getfslabel(&Osup);
4647c478bd9Sstevel@tonic-gate Ofpack = getvolabel(&Osup);
4657c478bd9Sstevel@tonic-gate } else {
4667c478bd9Sstevel@tonic-gate int i;
4677c478bd9Sstevel@tonic-gate
4687c478bd9Sstevel@tonic-gate /* out vol does not contain a ufs file system */
4697c478bd9Sstevel@tonic-gate /* stuff let over from Isup */
4707c478bd9Sstevel@tonic-gate (void) memcpy(&Osup, &Isup, Isup.fs_sbsize);
4717c478bd9Sstevel@tonic-gate Ofname = getfslabel(&Osup);
4727c478bd9Sstevel@tonic-gate Ofpack = getvolabel(&Osup);
4737c478bd9Sstevel@tonic-gate /* wipe out the fs name and pack name for warning purposes */
4747c478bd9Sstevel@tonic-gate for (i = 0; i < 6; i++) Ofname[i] = ' ';
4757c478bd9Sstevel@tonic-gate for (i = 0; i < 6; i++) Ofpack[i] = ' ';
4767c478bd9Sstevel@tonic-gate }
4777c478bd9Sstevel@tonic-gate
4787c478bd9Sstevel@tonic-gate if (Itape) {
4797c478bd9Sstevel@tonic-gate if (R_cur != 1) {
4807c478bd9Sstevel@tonic-gate (void) printf(gettext(
4817c478bd9Sstevel@tonic-gate "\nvolcopy: IF REEL 1 HAS NOT BEEN RESTORED,"));
4827c478bd9Sstevel@tonic-gate (void) printf(gettext(
4837c478bd9Sstevel@tonic-gate " STOP NOW AND START OVER ***\07\n"));
4847c478bd9Sstevel@tonic-gate if (!ask(" Continue? ")) {
4857c478bd9Sstevel@tonic-gate cleanup();
4867c478bd9Sstevel@tonic-gate exit(31+9);
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate strncpy(Ifname, Fsys_p, 6);
4897c478bd9Sstevel@tonic-gate strncpy(Ifpack, In.f_vol_p, 6);
4907c478bd9Sstevel@tonic-gate }
4917c478bd9Sstevel@tonic-gate if (V_labl.v_reel != R_cur || V_labl.v_reels != R_num)
4927c478bd9Sstevel@tonic-gate prompt(1, "Tape disagrees: Reel %d of %d : looking for %d of %d\n",
4937c478bd9Sstevel@tonic-gate V_labl.v_reel, V_labl.v_reels, R_cur, R_num);
4947c478bd9Sstevel@tonic-gate } else if (Otape) {
4957c478bd9Sstevel@tonic-gate strncpy(V_labl.v_volume, Out.f_vol_p, 6);
4967c478bd9Sstevel@tonic-gate strncpy(Ofpack, Out.f_vol_p, 6);
4977c478bd9Sstevel@tonic-gate strncpy(Ofname, Fsys_p, 6);
4987c478bd9Sstevel@tonic-gate if (!Eomflg) {
4997c478bd9Sstevel@tonic-gate R_num = Fs / R_blks + ((Fs % R_blks) ? 1 : 0);
5007c478bd9Sstevel@tonic-gate (void) printf(gettext(
5017c478bd9Sstevel@tonic-gate "You will need %d reels.\n"), R_num);
5027c478bd9Sstevel@tonic-gate (void) printf(gettext(
5037c478bd9Sstevel@tonic-gate "(\tThe same size and density is expected for all reels)\n"));
5047c478bd9Sstevel@tonic-gate }
5057c478bd9Sstevel@tonic-gate }
5067c478bd9Sstevel@tonic-gate if (NOT_EQ(Fsys_p, Ifname, 6)) {
5077c478bd9Sstevel@tonic-gate verify = !Otape || (altflg & MINUSS);
5087c478bd9Sstevel@tonic-gate prompt(verify,
5097c478bd9Sstevel@tonic-gate "arg. (%.6s) doesn't agree with from fs. (%.6s)\n",
5107c478bd9Sstevel@tonic-gate Fsys_p, Ifname);
5117c478bd9Sstevel@tonic-gate }
5127c478bd9Sstevel@tonic-gate if (NOT_EQ(In.f_vol_p, "-", 6) && NOT_EQ(In.f_vol_p, Ifpack, 6)) {
5137c478bd9Sstevel@tonic-gate verify = !Otape || (altflg & MINUSS);
5147c478bd9Sstevel@tonic-gate prompt(verify, "arg. (%.6s) doesn't agree with from vol.(%.6s)\n",
5157c478bd9Sstevel@tonic-gate In.f_vol_p, Ifpack);
5167c478bd9Sstevel@tonic-gate }
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gate if (*In.f_vol_p == '-')
5197c478bd9Sstevel@tonic-gate In.f_vol_p = Ifpack;
5207c478bd9Sstevel@tonic-gate if (*Out.f_vol_p == '-')
5217c478bd9Sstevel@tonic-gate Out.f_vol_p = Ofpack;
5227c478bd9Sstevel@tonic-gate
5237c478bd9Sstevel@tonic-gate if (R_cur == 1 && (Osup.fs_time + _2_DAYS) > Isup.fs_time) {
5247c478bd9Sstevel@tonic-gate time_t t;
5257c478bd9Sstevel@tonic-gate
5267c478bd9Sstevel@tonic-gate verify = altflg & MINUSS;
5277c478bd9Sstevel@tonic-gate t = (time_t)Osup.fs_time;
5287c478bd9Sstevel@tonic-gate prompt(verify, "%s less than 48 hours older than %s\n"
5297c478bd9Sstevel@tonic-gate "To filesystem dated: %s",
5307c478bd9Sstevel@tonic-gate Out.f_dev_p, In.f_dev_p, ctime(&t));
5317c478bd9Sstevel@tonic-gate }
5327c478bd9Sstevel@tonic-gate if (NOT_EQ(Out.f_vol_p, Ofpack, 6)) {
5337c478bd9Sstevel@tonic-gate prompt(1, "arg.(%.6s) doesn't agree with to vol.(%.6s)\n",
5347c478bd9Sstevel@tonic-gate Out.f_vol_p, Ofpack);
5357c478bd9Sstevel@tonic-gate strncpy(Ofpack, Out.f_vol_p, 6);
5367c478bd9Sstevel@tonic-gate }
5377c478bd9Sstevel@tonic-gate if (Isup.fs_size > Osup.fs_size && !Otape)
5387c478bd9Sstevel@tonic-gate prompt(1, "from fs larger than to fs\n");
5397c478bd9Sstevel@tonic-gate if (!Otape && NOT_EQ(Ifname, Ofname, 6)) {
5407c478bd9Sstevel@tonic-gate verify = altflg & MINUSS;
5417c478bd9Sstevel@tonic-gate prompt(verify, "warning! from fs(%.6s) differs from to fs(%.6s)\n",
5427c478bd9Sstevel@tonic-gate Ifname, Ofname);
5437c478bd9Sstevel@tonic-gate }
5447c478bd9Sstevel@tonic-gate
5457c478bd9Sstevel@tonic-gate (void) printf(gettext("From: %s, to: %s? "), In.f_dev_p, Out.f_dev_p);
5467c478bd9Sstevel@tonic-gate if (!(altflg & MINUSA)) {
5477c478bd9Sstevel@tonic-gate (void) printf(gettext("(DEL if wrong)\n"));
5487c478bd9Sstevel@tonic-gate sleep(10);
5497c478bd9Sstevel@tonic-gate } else if (!ask("(y or n) "))
5507c478bd9Sstevel@tonic-gate perr(10, "\nvolcopy: STOP\n");
5517c478bd9Sstevel@tonic-gate close(In.f_des);
5527c478bd9Sstevel@tonic-gate close(Out.f_des);
5537c478bd9Sstevel@tonic-gate sync();
5547c478bd9Sstevel@tonic-gate In.f_des = open(In.f_dev_p, O_RDONLY);
5557c478bd9Sstevel@tonic-gate Out.f_des = open(Out.f_dev_p, O_WRONLY);
5567c478bd9Sstevel@tonic-gate errno = 0;
5577c478bd9Sstevel@tonic-gate if (g_init(&In.f_dev, &In.f_des) < 0 ||
5587c478bd9Sstevel@tonic-gate g_init(&Out.f_dev, &Out.f_des) < 0)
5597c478bd9Sstevel@tonic-gate perr(1, "volcopy: Error %d during initialization\n", errno);
5607c478bd9Sstevel@tonic-gate if (Itape) {
5617c478bd9Sstevel@tonic-gate errno = 0;
5627c478bd9Sstevel@tonic-gate if (g_read(In.f_dev, In.f_des, &V_labl, sizeof (V_labl)) <
5637c478bd9Sstevel@tonic-gate sizeof (V_labl))
5647c478bd9Sstevel@tonic-gate perr(10, "Error while reading label\n");
5657c478bd9Sstevel@tonic-gate } else if (Otape) {
5667c478bd9Sstevel@tonic-gate V_labl.v_reels = R_num;
5677c478bd9Sstevel@tonic-gate V_labl.v_reel = R_cur;
5687c478bd9Sstevel@tonic-gate V_labl.v_time = Tvec;
5697c478bd9Sstevel@tonic-gate V_labl.v_reelblks = R_blks;
5707c478bd9Sstevel@tonic-gate V_labl.v_blksize = BLKSIZ * Blk_cnt;
5717c478bd9Sstevel@tonic-gate V_labl.v_nblocks = Blk_cnt;
5727c478bd9Sstevel@tonic-gate V_labl.v_offset = 0L;
5737c478bd9Sstevel@tonic-gate V_labl.v_type = T_TYPE;
5747c478bd9Sstevel@tonic-gate errno = 0;
5757c478bd9Sstevel@tonic-gate if (g_write(Out.f_dev, Out.f_des, &V_labl, sizeof (V_labl)) <
5767c478bd9Sstevel@tonic-gate sizeof (V_labl))
5777c478bd9Sstevel@tonic-gate perr(10, "Error while writing label\n");
5787c478bd9Sstevel@tonic-gate }
5797c478bd9Sstevel@tonic-gate if (R_cur > 1) {
5807c478bd9Sstevel@tonic-gate if (!Eomflg) {
5817c478bd9Sstevel@tonic-gate Fs = (R_cur - 1) * actual_blocks();
5827c478bd9Sstevel@tonic-gate lfdes = Otape ? In.f_des : Out.f_des;
5837c478bd9Sstevel@tonic-gate dist = (long)(Fs * BLKSIZ);
5847c478bd9Sstevel@tonic-gate } else { /* Eomflg */
5857c478bd9Sstevel@tonic-gate if (Otape)
5867c478bd9Sstevel@tonic-gate perr(1, "Cannot use -reel with -e when copying to tape\n");
5877c478bd9Sstevel@tonic-gate lfdes = Out.f_des;
5887c478bd9Sstevel@tonic-gate dist = (long)(V_labl.v_offset * BLKSIZ);
5897c478bd9Sstevel@tonic-gate Fs = V_labl.v_offset;
5907c478bd9Sstevel@tonic-gate }
5917c478bd9Sstevel@tonic-gate if (lseek(lfdes, dist, 0) < 0)
5927c478bd9Sstevel@tonic-gate perr(1, "Cannot lseek()\n");
5937c478bd9Sstevel@tonic-gate Sptr = Otape ? &Isup : &Osup;
5947c478bd9Sstevel@tonic-gate if ((Sptr -> fs_magic != FS_MAGIC) &&
5957c478bd9Sstevel@tonic-gate (Sptr -> fs_magic != MTB_UFS_MAGIC))
5967c478bd9Sstevel@tonic-gate perr(10, "File System type unknown--get help!\n");
5977c478bd9Sstevel@tonic-gate
5986451fdbcSvsakar if (Sptr->fs_magic == FS_MAGIC &&
5996451fdbcSvsakar (Sptr->fs_version != UFS_EFISTYLE4NONEFI_VERSION_2 &&
6006451fdbcSvsakar Sptr->fs_version != UFS_VERSION_MIN))
6016451fdbcSvsakar perr(10, "Unrecognized version of UFS--get help\n");
6026451fdbcSvsakar
6037c478bd9Sstevel@tonic-gate if (Sptr->fs_magic == MTB_UFS_MAGIC &&
6047c478bd9Sstevel@tonic-gate (Sptr->fs_version > MTB_UFS_VERSION_1 ||
6057c478bd9Sstevel@tonic-gate Sptr->fs_version < MTB_UFS_VERSION_MIN))
6067c478bd9Sstevel@tonic-gate perr(10, "Unrecognized version of UFS--get help\n");
6077c478bd9Sstevel@tonic-gate
6087c478bd9Sstevel@tonic-gate Fs = (Sptr->fs_size * Sptr->fs_nspf) - Fs;
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate if (Itape || Otape)
6117c478bd9Sstevel@tonic-gate rprt();
6127c478bd9Sstevel@tonic-gate
6137c478bd9Sstevel@tonic-gate if (Ipc) {
6147c478bd9Sstevel@tonic-gate parent_copy();
6157c478bd9Sstevel@tonic-gate (void) cleanup();
6167c478bd9Sstevel@tonic-gate } else
6177c478bd9Sstevel@tonic-gate copy();
6187c478bd9Sstevel@tonic-gate (void) printf(gettext(" END: %ld blocks.\n"), Blocks);
6197c478bd9Sstevel@tonic-gate
6207c478bd9Sstevel@tonic-gate #ifdef LOG
6217c478bd9Sstevel@tonic-gate fslog();
6227c478bd9Sstevel@tonic-gate #endif
6237c478bd9Sstevel@tonic-gate if (Blocks)
624*d1a180b0Smaheshvs return (0);
625*d1a180b0Smaheshvs return (31+1); /* failed.. 0 blocks */
6267c478bd9Sstevel@tonic-gate }
6277c478bd9Sstevel@tonic-gate
6287c478bd9Sstevel@tonic-gate /*
6297c478bd9Sstevel@tonic-gate * sigalrm: catch alarm signals.
6307c478bd9Sstevel@tonic-gate */
6317c478bd9Sstevel@tonic-gate
6327c478bd9Sstevel@tonic-gate void
sigalrm()6337c478bd9Sstevel@tonic-gate sigalrm()
6347c478bd9Sstevel@tonic-gate {
6357c478bd9Sstevel@tonic-gate void (*signal())();
6367c478bd9Sstevel@tonic-gate
6377c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, sigalrm);
6387c478bd9Sstevel@tonic-gate }
6397c478bd9Sstevel@tonic-gate
6407c478bd9Sstevel@tonic-gate /*
6417c478bd9Sstevel@tonic-gate * sigsys: catch illegal system calls to determine if IPC is available.
6427c478bd9Sstevel@tonic-gate */
6437c478bd9Sstevel@tonic-gate
6447c478bd9Sstevel@tonic-gate void
sigsys()6457c478bd9Sstevel@tonic-gate sigsys()
6467c478bd9Sstevel@tonic-gate {
6477c478bd9Sstevel@tonic-gate
6487c478bd9Sstevel@tonic-gate Ipc = 0;
6497c478bd9Sstevel@tonic-gate }
6507c478bd9Sstevel@tonic-gate
6517c478bd9Sstevel@tonic-gate /*
6527c478bd9Sstevel@tonic-gate * sigint: catch interrupts and prompt user for shell or to quit.
6537c478bd9Sstevel@tonic-gate */
6547c478bd9Sstevel@tonic-gate
6557c478bd9Sstevel@tonic-gate void
sigint()6567c478bd9Sstevel@tonic-gate sigint()
6577c478bd9Sstevel@tonic-gate {
6587c478bd9Sstevel@tonic-gate void (*signal())();
6597c478bd9Sstevel@tonic-gate extern char **environ;
660*d1a180b0Smaheshvs int tmpflg, i = 0, ps1 = -1, ps2 = -1;
6617c478bd9Sstevel@tonic-gate
6627c478bd9Sstevel@tonic-gate tmpflg = Yesflg; /* override yesflag for duration of interrupt */
6637c478bd9Sstevel@tonic-gate Yesflg = 0;
6647c478bd9Sstevel@tonic-gate if (Shell_esc && ask("Want Shell? ")) {
6657c478bd9Sstevel@tonic-gate if (!fork()) {
6667c478bd9Sstevel@tonic-gate /* both PS1 and PS2 must be exported */
6677c478bd9Sstevel@tonic-gate while (environ[i]) {
6687c478bd9Sstevel@tonic-gate if (EQ(environ[i], "PS1", 3))
6697c478bd9Sstevel@tonic-gate ps1 = i;
6707c478bd9Sstevel@tonic-gate if (EQ(environ[i], "PS2", 3))
6717c478bd9Sstevel@tonic-gate ps2 = i;
6727c478bd9Sstevel@tonic-gate i++;
6737c478bd9Sstevel@tonic-gate }
6747c478bd9Sstevel@tonic-gate if (ps1 >= 0 && ps2 >= 0)
6757c478bd9Sstevel@tonic-gate environ[ps1] = environ[ps2];
6767c478bd9Sstevel@tonic-gate (void) signal(SIGINT, SIG_DFL);
6777c478bd9Sstevel@tonic-gate execl("/usr/bin/sh", "/usr/bin/sh", 0);
6787c478bd9Sstevel@tonic-gate } else { /* parent */
6797c478bd9Sstevel@tonic-gate (void) signal(SIGINT, SIG_IGN);
6807c478bd9Sstevel@tonic-gate wait((int *)0);
6817c478bd9Sstevel@tonic-gate }
6827c478bd9Sstevel@tonic-gate } else if (ask("Want to quit? ")) {
6837c478bd9Sstevel@tonic-gate if (Pid > 0)
6847c478bd9Sstevel@tonic-gate kill(Pid, 9);
6857c478bd9Sstevel@tonic-gate (void) cleanup(); /* ipc */
6867c478bd9Sstevel@tonic-gate exit(31+2);
6877c478bd9Sstevel@tonic-gate }
6887c478bd9Sstevel@tonic-gate (void) signal(SIGINT, sigint);
6897c478bd9Sstevel@tonic-gate Yesflg = tmpflg; /* reset Yesflg */
6907c478bd9Sstevel@tonic-gate }
6917c478bd9Sstevel@tonic-gate
6927c478bd9Sstevel@tonic-gate /*
6937c478bd9Sstevel@tonic-gate * actual_blocks: Calculate the actual number of blocks written to
6947c478bd9Sstevel@tonic-gate * the tape (will differ from V_labl.v_reelblks if v_reelblks is not
6957c478bd9Sstevel@tonic-gate * an even multiple of the blocking factor Blk_cnt).
6967c478bd9Sstevel@tonic-gate */
6977c478bd9Sstevel@tonic-gate
6987c478bd9Sstevel@tonic-gate int
actual_blocks()6997c478bd9Sstevel@tonic-gate actual_blocks()
7007c478bd9Sstevel@tonic-gate {
7017c478bd9Sstevel@tonic-gate
7027c478bd9Sstevel@tonic-gate if (R_blks % Blk_cnt)
7037c478bd9Sstevel@tonic-gate return (((R_blks / Blk_cnt) + 1) * Blk_cnt);
7047c478bd9Sstevel@tonic-gate else
7057c478bd9Sstevel@tonic-gate return (R_blks);
7067c478bd9Sstevel@tonic-gate }
7077c478bd9Sstevel@tonic-gate
7087c478bd9Sstevel@tonic-gate /*
7097c478bd9Sstevel@tonic-gate * get_mach_type: Determine what machine this is executing on.
7107c478bd9Sstevel@tonic-gate */
7117c478bd9Sstevel@tonic-gate
712*d1a180b0Smaheshvs static void
get_mach_type(void)713*d1a180b0Smaheshvs get_mach_type(void)
7147c478bd9Sstevel@tonic-gate {
7157c478bd9Sstevel@tonic-gate struct utsname utsinfo;
7167c478bd9Sstevel@tonic-gate
7177c478bd9Sstevel@tonic-gate errno = 0;
7187c478bd9Sstevel@tonic-gate if (uname(&utsinfo) < 0)
7197c478bd9Sstevel@tonic-gate perr(1, "Unable to determine machine type\n");
7207c478bd9Sstevel@tonic-gate if (strcmp(utsinfo.machine, "3B2") == 0)
7217c478bd9Sstevel@tonic-gate M3b2 = 1;
7227c478bd9Sstevel@tonic-gate else if (strcmp(utsinfo.machine, "3B15") == 0)
7237c478bd9Sstevel@tonic-gate M3b15 = 1;
7247c478bd9Sstevel@tonic-gate }
7257c478bd9Sstevel@tonic-gate
7267c478bd9Sstevel@tonic-gate /*
7277c478bd9Sstevel@tonic-gate * mem_setup: Determine memory needs and check for IPC. If IPC is available,
7287c478bd9Sstevel@tonic-gate * used shared memory and semaphores to increase performance. If no IPC,
7297c478bd9Sstevel@tonic-gate * get normal memory and only use one process.
7307c478bd9Sstevel@tonic-gate */
7317c478bd9Sstevel@tonic-gate
732*d1a180b0Smaheshvs static void
mem_setup(void)733*d1a180b0Smaheshvs mem_setup(void)
7347c478bd9Sstevel@tonic-gate {
7357c478bd9Sstevel@tonic-gate void (*signal())();
736*d1a180b0Smaheshvs int cnt, num, size;
7377c478bd9Sstevel@tonic-gate char *align();
7387c478bd9Sstevel@tonic-gate
7397c478bd9Sstevel@tonic-gate union semun {
7407c478bd9Sstevel@tonic-gate int val;
7417c478bd9Sstevel@tonic-gate struct semid_ds *buf;
7427c478bd9Sstevel@tonic-gate ushort_t *array;
7437c478bd9Sstevel@tonic-gate } sem_arg;
7447c478bd9Sstevel@tonic-gate
7457c478bd9Sstevel@tonic-gate if (Blk_cnt == 1) {
7467c478bd9Sstevel@tonic-gate switch (Drive_typ) {
7477c478bd9Sstevel@tonic-gate case A_DRIVE:
7487c478bd9Sstevel@tonic-gate Blk_cnt = 32;
7497c478bd9Sstevel@tonic-gate break;
7507c478bd9Sstevel@tonic-gate case C_DRIVE:
7517c478bd9Sstevel@tonic-gate Blk_cnt = 10;
7527c478bd9Sstevel@tonic-gate break;
7537c478bd9Sstevel@tonic-gate case K_DRIVE:
7547c478bd9Sstevel@tonic-gate Blk_cnt = 4;
7557c478bd9Sstevel@tonic-gate break;
7567c478bd9Sstevel@tonic-gate case T_DRIVE:
7577c478bd9Sstevel@tonic-gate if (Bpi == 6250)
7587c478bd9Sstevel@tonic-gate Blk_cnt = 50;
7597c478bd9Sstevel@tonic-gate else
7607c478bd9Sstevel@tonic-gate Blk_cnt = 10;
7617c478bd9Sstevel@tonic-gate break;
7627c478bd9Sstevel@tonic-gate default:
7637c478bd9Sstevel@tonic-gate if (M3b15) {
7647c478bd9Sstevel@tonic-gate if (Itape || Otape)
7657c478bd9Sstevel@tonic-gate Blk_cnt = 16;
7667c478bd9Sstevel@tonic-gate } else {
7677c478bd9Sstevel@tonic-gate if (Otape || Itape) {
7687c478bd9Sstevel@tonic-gate if (Bpi == 6250)
7697c478bd9Sstevel@tonic-gate Blk_cnt = 50;
7707c478bd9Sstevel@tonic-gate else
7717c478bd9Sstevel@tonic-gate Blk_cnt = 10;
7727c478bd9Sstevel@tonic-gate }
7737c478bd9Sstevel@tonic-gate }
7747c478bd9Sstevel@tonic-gate break;
7757c478bd9Sstevel@tonic-gate } /* Drive_typ */
7767c478bd9Sstevel@tonic-gate } /* Blk_cnt == 1 */
7777c478bd9Sstevel@tonic-gate if (Blk_cnt > 1) /* user overrode g_init */
7787c478bd9Sstevel@tonic-gate In.f_bsize = Out.f_bsize = Blk_cnt * BLKSIZ;
7797c478bd9Sstevel@tonic-gate In.f_bsize = (!Itape) ? Disk_cnt * In.f_bsize : In.f_bsize;
7807c478bd9Sstevel@tonic-gate Out.f_bsize = (!Otape) ? Disk_cnt * Out.f_bsize : Out.f_bsize;
7817c478bd9Sstevel@tonic-gate Bufsz = find_lcm(In.f_bsize, Out.f_bsize);
7827c478bd9Sstevel@tonic-gate num = _128K / (Bufsz + sizeof (int));
7837c478bd9Sstevel@tonic-gate Bufsz *= num;
7847c478bd9Sstevel@tonic-gate size = Bufsz + sizeof (int);
7857c478bd9Sstevel@tonic-gate /* test to see if ipc is available, the shmat should fail with EINVAL */
7867c478bd9Sstevel@tonic-gate (void) signal(SIGSYS, sigsys);
7877c478bd9Sstevel@tonic-gate errno = 0;
7887c478bd9Sstevel@tonic-gate if (Ipc) {
7897c478bd9Sstevel@tonic-gate if ((int)shmat(0, (char *)NULL, 0) < 0 && errno != EINVAL)
7907c478bd9Sstevel@tonic-gate Ipc = 0; /* something went wrong */
7917c478bd9Sstevel@tonic-gate }
7927c478bd9Sstevel@tonic-gate if (Ipc) { /* ipc is available */
7937c478bd9Sstevel@tonic-gate Bufcnt = 2;
7947c478bd9Sstevel@tonic-gate sem_arg.val = 0;
7957c478bd9Sstevel@tonic-gate for (cnt = 0; cnt < BUFCNT; cnt++) {
7967c478bd9Sstevel@tonic-gate errno = 0;
7977c478bd9Sstevel@tonic-gate if ((Sem_id[cnt] = semget(IPC_PRIVATE, 1, 0)) < 0)
7987c478bd9Sstevel@tonic-gate perr(1, "Error allocating semaphores: %d",
7997c478bd9Sstevel@tonic-gate errno);
8007c478bd9Sstevel@tonic-gate if (semctl(Sem_id[cnt], 0, SETVAL, sem_arg) < 0)
8017c478bd9Sstevel@tonic-gate perr(1, "Error setting semaphores: %d", errno);
8027c478bd9Sstevel@tonic-gate if ((Shm_id[cnt] = shmget(IPC_PRIVATE, size, 0)) < 0)
8037c478bd9Sstevel@tonic-gate perr(1, "Error allocating shared memory: %d",
8047c478bd9Sstevel@tonic-gate errno);
8057c478bd9Sstevel@tonic-gate if ((Buf[cnt] = shmat(Shm_id[cnt], 0, 0)) == (void *)-1)
8067c478bd9Sstevel@tonic-gate perr(1, "Error attaching shared memory: %d",
8077c478bd9Sstevel@tonic-gate errno);
8087c478bd9Sstevel@tonic-gate if (shmctl(Shm_id[cnt], SHM_LOCK, 0) < 0)
8097c478bd9Sstevel@tonic-gate perr(0, "Error locking in shared memory: %d",
8107c478bd9Sstevel@tonic-gate errno);
8117c478bd9Sstevel@tonic-gate Cnts[cnt] = (int *)(Buf[cnt] + Bufsz);
8127c478bd9Sstevel@tonic-gate }
8137c478bd9Sstevel@tonic-gate } else { /* ipc is not available */
8147c478bd9Sstevel@tonic-gate Bufcnt = 1;
8157c478bd9Sstevel@tonic-gate if ((Buf[0] = align(size)) == (char *)NULL)
8167c478bd9Sstevel@tonic-gate perr(1, "Out of memory\n");
8177c478bd9Sstevel@tonic-gate Cnts[0] = (int *)(Buf[0] + Bufsz);
8187c478bd9Sstevel@tonic-gate *Cnts[0] = 0;
8197c478bd9Sstevel@tonic-gate }
8207c478bd9Sstevel@tonic-gate }
8217c478bd9Sstevel@tonic-gate
8227c478bd9Sstevel@tonic-gate /*
8237c478bd9Sstevel@tonic-gate * prompt: Prompt the user for verification.
8247c478bd9Sstevel@tonic-gate */
8257c478bd9Sstevel@tonic-gate
8267c478bd9Sstevel@tonic-gate static void
prompt(int verify,const char * fmt,...)8277c478bd9Sstevel@tonic-gate prompt(int verify, const char *fmt, ...)
8287c478bd9Sstevel@tonic-gate {
8297c478bd9Sstevel@tonic-gate va_list ap;
8307c478bd9Sstevel@tonic-gate
8317c478bd9Sstevel@tonic-gate va_start(ap, fmt);
8327c478bd9Sstevel@tonic-gate if (fmt != NULL)
8337c478bd9Sstevel@tonic-gate (void) vfprintf(stdout, gettext(fmt), ap);
8347c478bd9Sstevel@tonic-gate va_end(ap);
8357c478bd9Sstevel@tonic-gate if (verify) {
8367c478bd9Sstevel@tonic-gate (void) fprintf(stdout, gettext("Type 'y' to override: "));
8377c478bd9Sstevel@tonic-gate if (!ask("")) {
8387c478bd9Sstevel@tonic-gate cleanup();
8397c478bd9Sstevel@tonic-gate exit(31+9);
8407c478bd9Sstevel@tonic-gate }
8417c478bd9Sstevel@tonic-gate }
8427c478bd9Sstevel@tonic-gate }
8437c478bd9Sstevel@tonic-gate
8447c478bd9Sstevel@tonic-gate /*
8457c478bd9Sstevel@tonic-gate * ask: Ask the user a question and get the answer.
8467c478bd9Sstevel@tonic-gate */
8477c478bd9Sstevel@tonic-gate
848*d1a180b0Smaheshvs int
ask(char * s)849*d1a180b0Smaheshvs ask(char *s)
8507c478bd9Sstevel@tonic-gate {
8517c478bd9Sstevel@tonic-gate char ans[12];
8527c478bd9Sstevel@tonic-gate
8537c478bd9Sstevel@tonic-gate (void) printf(gettext(s));
8547c478bd9Sstevel@tonic-gate if (Yesflg) {
8557c478bd9Sstevel@tonic-gate (void) printf(gettext("YES\n"));
8567c478bd9Sstevel@tonic-gate return (1);
8577c478bd9Sstevel@tonic-gate }
8587c478bd9Sstevel@tonic-gate ans[0] = '\0';
8597c478bd9Sstevel@tonic-gate fgets(ans, 10, Devtty);
8607c478bd9Sstevel@tonic-gate for (;;) {
8617c478bd9Sstevel@tonic-gate switch (ans[0]) {
8627c478bd9Sstevel@tonic-gate case 'a':
8637c478bd9Sstevel@tonic-gate case 'A':
8647c478bd9Sstevel@tonic-gate if (Pid > 0) /* parent with a child */
8657c478bd9Sstevel@tonic-gate kill(Pid, 9);
8667c478bd9Sstevel@tonic-gate cleanup();
8677c478bd9Sstevel@tonic-gate exit(31+1);
8687c478bd9Sstevel@tonic-gate case 'y':
8697c478bd9Sstevel@tonic-gate case 'Y':
8707c478bd9Sstevel@tonic-gate return (1);
8717c478bd9Sstevel@tonic-gate case 'n':
8727c478bd9Sstevel@tonic-gate case 'N':
8737c478bd9Sstevel@tonic-gate return (0);
8747c478bd9Sstevel@tonic-gate default:
8757c478bd9Sstevel@tonic-gate (void) printf(gettext("\n(y or n)?"));
8767c478bd9Sstevel@tonic-gate fgets(ans, 10, Devtty);
8777c478bd9Sstevel@tonic-gate }
8787c478bd9Sstevel@tonic-gate }
8797c478bd9Sstevel@tonic-gate }
8807c478bd9Sstevel@tonic-gate
8817c478bd9Sstevel@tonic-gate /*
8827c478bd9Sstevel@tonic-gate * align: Align a malloc'd memory section on a page boundry.
8837c478bd9Sstevel@tonic-gate */
8847c478bd9Sstevel@tonic-gate
8857c478bd9Sstevel@tonic-gate char *
align(int size)886*d1a180b0Smaheshvs align(int size)
8877c478bd9Sstevel@tonic-gate {
888*d1a180b0Smaheshvs int pad;
8897c478bd9Sstevel@tonic-gate
8907c478bd9Sstevel@tonic-gate if ((pad = ((int)malloc(0) & (PAGESIZE-1))) > 0) {
8917c478bd9Sstevel@tonic-gate pad = PAGESIZE - pad;
8927c478bd9Sstevel@tonic-gate if (malloc(pad) == (char *)NULL)
8937c478bd9Sstevel@tonic-gate return ((char *)NULL);
8947c478bd9Sstevel@tonic-gate }
8957c478bd9Sstevel@tonic-gate return (malloc((unsigned)size));
8967c478bd9Sstevel@tonic-gate }
8977c478bd9Sstevel@tonic-gate
8987c478bd9Sstevel@tonic-gate /*
8997c478bd9Sstevel@tonic-gate * child_copy: Using IPC, this child process reads from shared memory
9007c478bd9Sstevel@tonic-gate * and writes to the destination file system.
9017c478bd9Sstevel@tonic-gate */
9027c478bd9Sstevel@tonic-gate
9037c478bd9Sstevel@tonic-gate int
child_copy()9047c478bd9Sstevel@tonic-gate child_copy()
9057c478bd9Sstevel@tonic-gate {
906*d1a180b0Smaheshvs int rv, cur_buf, left, have, tpcnt;
907*d1a180b0Smaheshvs char *c_p;
9087c478bd9Sstevel@tonic-gate
9097c478bd9Sstevel@tonic-gate (void) signal(SIGINT, SIG_IGN);
9107c478bd9Sstevel@tonic-gate Sem_buf.sem_op = -1;
9117c478bd9Sstevel@tonic-gate (void) close(In.f_des);
9127c478bd9Sstevel@tonic-gate if (Otape && !Eomflg)
9137c478bd9Sstevel@tonic-gate tpcnt = actual_blocks() * BLKSIZ;
9147c478bd9Sstevel@tonic-gate cur_buf = 0;
9157c478bd9Sstevel@tonic-gate for (;;) {
9167c478bd9Sstevel@tonic-gate if (semop(Sem_id[cur_buf], &Sem_buf, 1) < 0)
9177c478bd9Sstevel@tonic-gate perr(1, "semaphore operation error %d\n", errno);
9187c478bd9Sstevel@tonic-gate left = *Cnts[cur_buf];
9197c478bd9Sstevel@tonic-gate if (!left)
9207c478bd9Sstevel@tonic-gate break;
9217c478bd9Sstevel@tonic-gate c_p = Buf[cur_buf];
9227c478bd9Sstevel@tonic-gate rv = 0;
9237c478bd9Sstevel@tonic-gate while (left) {
9247c478bd9Sstevel@tonic-gate have = (left < Out.f_bsize) ? left : Out.f_bsize;
9257c478bd9Sstevel@tonic-gate if (!Eomflg && Otape) {
9267c478bd9Sstevel@tonic-gate if (!tpcnt) {
9277c478bd9Sstevel@tonic-gate (void) chgreel(&Out, OUTPUT);
9287c478bd9Sstevel@tonic-gate tpcnt = actual_blocks() * BLKSIZ;
9297c478bd9Sstevel@tonic-gate }
9307c478bd9Sstevel@tonic-gate have = (tpcnt < have) ? tpcnt : have;
9317c478bd9Sstevel@tonic-gate }
9327c478bd9Sstevel@tonic-gate errno = 0;
9337c478bd9Sstevel@tonic-gate if ((rv = g_write(Out.f_dev, Out.f_des, c_p, have)) <
9347c478bd9Sstevel@tonic-gate 0) {
9357c478bd9Sstevel@tonic-gate if (Eomflg && errno == ENOSPC) {
9367c478bd9Sstevel@tonic-gate (void) chgreel(&Out, OUTPUT);
9377c478bd9Sstevel@tonic-gate continue;
9387c478bd9Sstevel@tonic-gate } else
9397c478bd9Sstevel@tonic-gate perr(1, "I/O error %d on write\n",
9407c478bd9Sstevel@tonic-gate errno);
9417c478bd9Sstevel@tonic-gate }
9427c478bd9Sstevel@tonic-gate left -= rv;
9437c478bd9Sstevel@tonic-gate c_p += rv;
9447c478bd9Sstevel@tonic-gate V_labl.v_offset += rv;
9457c478bd9Sstevel@tonic-gate if (!Eomflg && Otape)
9467c478bd9Sstevel@tonic-gate tpcnt -= rv;
9477c478bd9Sstevel@tonic-gate }
9487c478bd9Sstevel@tonic-gate if (semop(Sem_id[cur_buf], &Sem_buf, 1) < 0)
9497c478bd9Sstevel@tonic-gate perr(2, "semaphore operation error %d\n", errno);
9507c478bd9Sstevel@tonic-gate cur_buf = (cur_buf + 1) % BUFCNT;
9517c478bd9Sstevel@tonic-gate }
9527c478bd9Sstevel@tonic-gate exit(0);
9537c478bd9Sstevel@tonic-gate }
9547c478bd9Sstevel@tonic-gate
9557c478bd9Sstevel@tonic-gate /*
9567c478bd9Sstevel@tonic-gate * parent_copy: Using shared memory, the parent process reads fromt the
9577c478bd9Sstevel@tonic-gate * source file system and writes to shared memory.
9587c478bd9Sstevel@tonic-gate */
9597c478bd9Sstevel@tonic-gate
960*d1a180b0Smaheshvs static void
parent_copy(void)961*d1a180b0Smaheshvs parent_copy(void)
9627c478bd9Sstevel@tonic-gate {
963*d1a180b0Smaheshvs int rv, left, have, tpcnt, cur_buf;
964*d1a180b0Smaheshvs char *c_p;
9657c478bd9Sstevel@tonic-gate int eom = 0, xfer_cnt = Fs * BLKSIZ;
9667c478bd9Sstevel@tonic-gate
9677c478bd9Sstevel@tonic-gate Sem_buf.sem_num = 0;
9687c478bd9Sstevel@tonic-gate Sem_buf.sem_flg = 0;
9697c478bd9Sstevel@tonic-gate if ((Pid = fork()) == 0)
9707c478bd9Sstevel@tonic-gate child_copy(); /* child does not return */
9717c478bd9Sstevel@tonic-gate (void) close(Out.f_des);
9727c478bd9Sstevel@tonic-gate Rstsem_buf.sem_num = 0;
9737c478bd9Sstevel@tonic-gate Rstsem_buf.sem_flg = 0;
9747c478bd9Sstevel@tonic-gate Rstsem_buf.sem_op = 2;
9757c478bd9Sstevel@tonic-gate Sem_buf.sem_op = 0;
9767c478bd9Sstevel@tonic-gate cur_buf = 0;
9777c478bd9Sstevel@tonic-gate if (Itape && !Eomflg)
9787c478bd9Sstevel@tonic-gate tpcnt = actual_blocks() * BLKSIZ;
9797c478bd9Sstevel@tonic-gate while (xfer_cnt) {
9807c478bd9Sstevel@tonic-gate if (semop(Sem_id[cur_buf], &Sem_buf, 1) < 0)
9817c478bd9Sstevel@tonic-gate perr(1, "Semaphore operation error %d\n", errno);
9827c478bd9Sstevel@tonic-gate c_p = Buf[cur_buf];
9837c478bd9Sstevel@tonic-gate left = Bufsz;
9847c478bd9Sstevel@tonic-gate rv = 0;
9857c478bd9Sstevel@tonic-gate while (left >= In.f_bsize && xfer_cnt) {
9867c478bd9Sstevel@tonic-gate have = (xfer_cnt < In.f_bsize) ? xfer_cnt : In.f_bsize;
9877c478bd9Sstevel@tonic-gate if (!Eomflg && Itape) {
9887c478bd9Sstevel@tonic-gate if (!tpcnt) {
9897c478bd9Sstevel@tonic-gate *Cnts[cur_buf] = Bufsz - left;
9907c478bd9Sstevel@tonic-gate (void) flush_bufs(cur_buf);
9917c478bd9Sstevel@tonic-gate (void) chgreel(&In, INPUT);
9927c478bd9Sstevel@tonic-gate tpcnt = actual_blocks() * BLKSIZ;
9937c478bd9Sstevel@tonic-gate cur_buf = (cur_buf == 0) ? 1 : 0;
9947c478bd9Sstevel@tonic-gate eom = 1;
9957c478bd9Sstevel@tonic-gate break;
9967c478bd9Sstevel@tonic-gate }
9977c478bd9Sstevel@tonic-gate have = (tpcnt < have) ? tpcnt : have;
9987c478bd9Sstevel@tonic-gate }
9997c478bd9Sstevel@tonic-gate errno = 0;
10007c478bd9Sstevel@tonic-gate if ((rv = g_read(In.f_dev, In.f_des, c_p, have)) < 0) {
10017c478bd9Sstevel@tonic-gate if (Eomflg && errno == ENOSPC) {
10027c478bd9Sstevel@tonic-gate *Cnts[cur_buf] = Bufsz - left;
10037c478bd9Sstevel@tonic-gate (void) flush_bufs(cur_buf);
10047c478bd9Sstevel@tonic-gate (void) chgreel(&In, INPUT);
10057c478bd9Sstevel@tonic-gate cur_buf = (cur_buf == 0) ? 1 : 0;
10067c478bd9Sstevel@tonic-gate eom = 1;
10077c478bd9Sstevel@tonic-gate break;
10087c478bd9Sstevel@tonic-gate } else
10097c478bd9Sstevel@tonic-gate perr(1, "I/O error %d on read\n",
10107c478bd9Sstevel@tonic-gate errno);
10117c478bd9Sstevel@tonic-gate }
10127c478bd9Sstevel@tonic-gate left -= rv;
10137c478bd9Sstevel@tonic-gate c_p += rv;
10147c478bd9Sstevel@tonic-gate xfer_cnt -= rv;
10157c478bd9Sstevel@tonic-gate if (!Eomflg && Itape)
10167c478bd9Sstevel@tonic-gate tpcnt -= rv;
10177c478bd9Sstevel@tonic-gate }
10187c478bd9Sstevel@tonic-gate if (eom > 0) {
10197c478bd9Sstevel@tonic-gate eom = 0;
10207c478bd9Sstevel@tonic-gate if (Eomflg)
10217c478bd9Sstevel@tonic-gate xfer_cnt -= rv;
10227c478bd9Sstevel@tonic-gate else if (Itape)
10237c478bd9Sstevel@tonic-gate tpcnt -= rv;
10247c478bd9Sstevel@tonic-gate continue;
10257c478bd9Sstevel@tonic-gate }
10267c478bd9Sstevel@tonic-gate *Cnts[cur_buf] = Bufsz - left;
10277c478bd9Sstevel@tonic-gate Blocks += *Cnts[cur_buf];
10287c478bd9Sstevel@tonic-gate if (semop(Sem_id[cur_buf], &Rstsem_buf, 1) < 0)
10297c478bd9Sstevel@tonic-gate perr(2, "Semaphore operation error %d\n", errno);
10307c478bd9Sstevel@tonic-gate cur_buf = (cur_buf == 0) ? 1 : 0;
10317c478bd9Sstevel@tonic-gate }
10327c478bd9Sstevel@tonic-gate if (semop(Sem_id[cur_buf], &Sem_buf, 1) < 0)
10337c478bd9Sstevel@tonic-gate perr(3, "Semaphore operation error %d\n", errno);
10347c478bd9Sstevel@tonic-gate *Cnts[cur_buf] = 0;
10357c478bd9Sstevel@tonic-gate if (semop(Sem_id[cur_buf], &Rstsem_buf, 1) < 0)
10367c478bd9Sstevel@tonic-gate perr(4, "Semaphore operation error %d\n", errno);
10377c478bd9Sstevel@tonic-gate wait((int *)NULL);
10387c478bd9Sstevel@tonic-gate Blocks /= BLKSIZ;
10397c478bd9Sstevel@tonic-gate }
10407c478bd9Sstevel@tonic-gate
10417c478bd9Sstevel@tonic-gate /*
10427c478bd9Sstevel@tonic-gate * copy: Copy without shared memory. The process reads from the source
10437c478bd9Sstevel@tonic-gate * filesystem and writes to the destination filesystem.
10447c478bd9Sstevel@tonic-gate */
10457c478bd9Sstevel@tonic-gate
1046*d1a180b0Smaheshvs static void
copy(void)1047*d1a180b0Smaheshvs copy(void)
10487c478bd9Sstevel@tonic-gate {
1049*d1a180b0Smaheshvs int rv, left, have, tpcnt = 1, xfer_cnt = Fs * BLKSIZ;
1050*d1a180b0Smaheshvs char *c_p;
10517c478bd9Sstevel@tonic-gate
10527c478bd9Sstevel@tonic-gate if ((Itape || Otape) && !Eomflg)
10537c478bd9Sstevel@tonic-gate tpcnt = actual_blocks() * BLKSIZ;
10547c478bd9Sstevel@tonic-gate while (xfer_cnt) {
10557c478bd9Sstevel@tonic-gate c_p = (char *)(Buf[0] + *Cnts[0]);
10567c478bd9Sstevel@tonic-gate left = Bufsz - *Cnts[0];
10577c478bd9Sstevel@tonic-gate rv = 0;
10587c478bd9Sstevel@tonic-gate while (left >= In.f_bsize && xfer_cnt) {
10597c478bd9Sstevel@tonic-gate have = (xfer_cnt < In.f_bsize) ? xfer_cnt : In.f_bsize;
10607c478bd9Sstevel@tonic-gate if (!Eomflg && Itape) {
10617c478bd9Sstevel@tonic-gate if (!tpcnt) {
10627c478bd9Sstevel@tonic-gate *Cnts[0] = Bufsz - left;
10637c478bd9Sstevel@tonic-gate (void) chgreel(&In, INPUT);
10647c478bd9Sstevel@tonic-gate tpcnt = actual_blocks() * BLKSIZ;
10657c478bd9Sstevel@tonic-gate break;
10667c478bd9Sstevel@tonic-gate }
10677c478bd9Sstevel@tonic-gate have = (tpcnt < have) ? tpcnt : have;
10687c478bd9Sstevel@tonic-gate }
10697c478bd9Sstevel@tonic-gate errno = 0;
10707c478bd9Sstevel@tonic-gate if ((rv = g_read(In.f_dev, In.f_des, c_p, have)) < 0) {
10717c478bd9Sstevel@tonic-gate if (Eomflg && errno == ENOSPC) {
10727c478bd9Sstevel@tonic-gate (void) chgreel(&In, INPUT);
10737c478bd9Sstevel@tonic-gate break;
10747c478bd9Sstevel@tonic-gate } else
10757c478bd9Sstevel@tonic-gate perr(1, "I/O error %d on read\n",
10767c478bd9Sstevel@tonic-gate errno);
10777c478bd9Sstevel@tonic-gate }
10787c478bd9Sstevel@tonic-gate left -= rv;
10797c478bd9Sstevel@tonic-gate c_p += rv;
10807c478bd9Sstevel@tonic-gate xfer_cnt -= rv;
10817c478bd9Sstevel@tonic-gate if (!Eomflg && Itape)
10827c478bd9Sstevel@tonic-gate tpcnt -= rv;
10837c478bd9Sstevel@tonic-gate } /* left >= In.f_bsize && xfer_cnt */
10847c478bd9Sstevel@tonic-gate *Cnts[0] = Bufsz - left;
10857c478bd9Sstevel@tonic-gate Blocks += *Cnts[0];
10867c478bd9Sstevel@tonic-gate c_p = Buf[0];
10877c478bd9Sstevel@tonic-gate left = *Cnts[0];
10887c478bd9Sstevel@tonic-gate rv = 0;
10897c478bd9Sstevel@tonic-gate while (left >= Out.f_bsize || (left > 0 && !xfer_cnt)) {
10907c478bd9Sstevel@tonic-gate have = (left < Out.f_bsize) ? left : Out.f_bsize;
10917c478bd9Sstevel@tonic-gate if (!Eomflg && Otape) {
10927c478bd9Sstevel@tonic-gate if (!tpcnt) {
10937c478bd9Sstevel@tonic-gate (void) chgreel(&Out, OUTPUT);
10947c478bd9Sstevel@tonic-gate tpcnt = actual_blocks() * BLKSIZ;
10957c478bd9Sstevel@tonic-gate }
10967c478bd9Sstevel@tonic-gate have = (tpcnt < have) ? tpcnt : have;
10977c478bd9Sstevel@tonic-gate }
10987c478bd9Sstevel@tonic-gate errno = 0;
10997c478bd9Sstevel@tonic-gate if ((rv = g_write(Out.f_dev, Out.f_des, c_p, have)) <
11007c478bd9Sstevel@tonic-gate 0) {
11017c478bd9Sstevel@tonic-gate if (Eomflg && errno == ENOSPC) {
11027c478bd9Sstevel@tonic-gate (void) chgreel(&Out, OUTPUT);
11037c478bd9Sstevel@tonic-gate continue;
11047c478bd9Sstevel@tonic-gate } else
11057c478bd9Sstevel@tonic-gate perr(1, "I/O error %d on write\n",
11067c478bd9Sstevel@tonic-gate errno);
11077c478bd9Sstevel@tonic-gate }
11087c478bd9Sstevel@tonic-gate left -= rv;
11097c478bd9Sstevel@tonic-gate c_p += rv;
11107c478bd9Sstevel@tonic-gate V_labl.v_offset += rv;
11117c478bd9Sstevel@tonic-gate if (!Eomflg && Otape)
11127c478bd9Sstevel@tonic-gate tpcnt -= rv;
11137c478bd9Sstevel@tonic-gate } /* left >= Out.f_bsize */
11147c478bd9Sstevel@tonic-gate if (left) {
11157c478bd9Sstevel@tonic-gate (void) memcpy(Buf[0], c_p, left);
11167c478bd9Sstevel@tonic-gate Blocks -= left;
11177c478bd9Sstevel@tonic-gate }
11187c478bd9Sstevel@tonic-gate *Cnts[0] = left;
11197c478bd9Sstevel@tonic-gate } /* xfer_cnt */
11207c478bd9Sstevel@tonic-gate Blocks /= BLKSIZ;
11217c478bd9Sstevel@tonic-gate }
11227c478bd9Sstevel@tonic-gate
11237c478bd9Sstevel@tonic-gate /*
11247c478bd9Sstevel@tonic-gate * flush_bufs: Permit child to read the remaining data from the
11257c478bd9Sstevel@tonic-gate * buffer before prompting user for end-of-media.
11267c478bd9Sstevel@tonic-gate */
11277c478bd9Sstevel@tonic-gate
1128*d1a180b0Smaheshvs static void
flush_bufs(int buffer)1129*d1a180b0Smaheshvs flush_bufs(int buffer)
11307c478bd9Sstevel@tonic-gate {
11317c478bd9Sstevel@tonic-gate
11327c478bd9Sstevel@tonic-gate Blocks += *Cnts[buffer];
11337c478bd9Sstevel@tonic-gate if (semop(Sem_id[buffer], &Rstsem_buf, 1) < 0)
11347c478bd9Sstevel@tonic-gate perr(5, "Semaphore operation error %d\n", errno);
11357c478bd9Sstevel@tonic-gate if (semop(Sem_id[buffer], &Sem_buf, 1) < 0)
11367c478bd9Sstevel@tonic-gate perr(6, "Semaphore operation error %d\n", errno);
11377c478bd9Sstevel@tonic-gate }
11387c478bd9Sstevel@tonic-gate
11397c478bd9Sstevel@tonic-gate /*
11407c478bd9Sstevel@tonic-gate * cleanup: Clean up shared memory and semaphore resources.
11417c478bd9Sstevel@tonic-gate */
11427c478bd9Sstevel@tonic-gate
1143*d1a180b0Smaheshvs static void
cleanup(void)1144*d1a180b0Smaheshvs cleanup(void)
11457c478bd9Sstevel@tonic-gate {
1146*d1a180b0Smaheshvs int cnt;
11477c478bd9Sstevel@tonic-gate
11487c478bd9Sstevel@tonic-gate if (Ipc) {
11497c478bd9Sstevel@tonic-gate for (cnt = 0; cnt < BUFCNT; cnt++) {
11507c478bd9Sstevel@tonic-gate (void) semctl(Sem_id[cnt], IPC_RMID, 0);
11517c478bd9Sstevel@tonic-gate (void) shmctl(Shm_id[cnt], IPC_RMID, 0);
11527c478bd9Sstevel@tonic-gate }
11537c478bd9Sstevel@tonic-gate }
11547c478bd9Sstevel@tonic-gate }
11557c478bd9Sstevel@tonic-gate
11567c478bd9Sstevel@tonic-gate /*
11577c478bd9Sstevel@tonic-gate * find_lcm: Find the lowest common multiple of two numbers. This is used
11587c478bd9Sstevel@tonic-gate * to determine the buffer size that should be malloc(3)'d such that the
11597c478bd9Sstevel@tonic-gate * input and output data blocks can both fit evenly into the buffer.
11607c478bd9Sstevel@tonic-gate */
11617c478bd9Sstevel@tonic-gate
11627c478bd9Sstevel@tonic-gate int
find_lcm(int sz1,int sz2)1163*d1a180b0Smaheshvs find_lcm(int sz1, int sz2)
11647c478bd9Sstevel@tonic-gate {
1165*d1a180b0Smaheshvs int inc, lcm, small;
11667c478bd9Sstevel@tonic-gate
11677c478bd9Sstevel@tonic-gate if (sz1 < sz2) {
11687c478bd9Sstevel@tonic-gate lcm = inc = sz2;
11697c478bd9Sstevel@tonic-gate small = sz1;
11707c478bd9Sstevel@tonic-gate } else { /* sz1 >= sz2 */
11717c478bd9Sstevel@tonic-gate lcm = inc = sz1;
11727c478bd9Sstevel@tonic-gate small = sz2;
11737c478bd9Sstevel@tonic-gate }
11747c478bd9Sstevel@tonic-gate while (lcm % small != 0)
11757c478bd9Sstevel@tonic-gate lcm += inc;
11767c478bd9Sstevel@tonic-gate return (lcm);
11777c478bd9Sstevel@tonic-gate }
11787c478bd9Sstevel@tonic-gate
11797c478bd9Sstevel@tonic-gate /*
11807c478bd9Sstevel@tonic-gate * Determine bpi information from drive names.
11817c478bd9Sstevel@tonic-gate */
11827c478bd9Sstevel@tonic-gate
1183*d1a180b0Smaheshvs int
getbpi(char * inp)1184*d1a180b0Smaheshvs getbpi(char *inp)
11857c478bd9Sstevel@tonic-gate {
11867c478bd9Sstevel@tonic-gate
11877c478bd9Sstevel@tonic-gate /*
11887c478bd9Sstevel@tonic-gate * Kludge to recognize Accellerated Tape Controller usage from
11897c478bd9Sstevel@tonic-gate * letter 'a' or 'A' following density given by user.
11907c478bd9Sstevel@tonic-gate *
11917c478bd9Sstevel@tonic-gate * Kludge to recognize 3B15 Compatibility Mode from
11927c478bd9Sstevel@tonic-gate * letter 'c' or 'C' following density given by user.
11937c478bd9Sstevel@tonic-gate */
11947c478bd9Sstevel@tonic-gate if (M3b15) {
11957c478bd9Sstevel@tonic-gate if (inp[4] == 'a' || inp[4] == 'A') {
11967c478bd9Sstevel@tonic-gate Drive_typ = A_DRIVE;
11977c478bd9Sstevel@tonic-gate inp[4] = '\0';
11987c478bd9Sstevel@tonic-gate }
11997c478bd9Sstevel@tonic-gate if (inp[4] == 'c' || inp[4] == 'C') {
12007c478bd9Sstevel@tonic-gate Drive_typ = C_DRIVE;
12017c478bd9Sstevel@tonic-gate inp[4] = '\0';
12027c478bd9Sstevel@tonic-gate }
12037c478bd9Sstevel@tonic-gate }
12047c478bd9Sstevel@tonic-gate return (atoi(inp));
12057c478bd9Sstevel@tonic-gate }
12067c478bd9Sstevel@tonic-gate
12077c478bd9Sstevel@tonic-gate /*
12087c478bd9Sstevel@tonic-gate * blks_per_ft: Determine the number of blocks per foot of tape.
12097c478bd9Sstevel@tonic-gate * Inter-block gap (dgap) is 0.3 in.
12107c478bd9Sstevel@tonic-gate */
12117c478bd9Sstevel@tonic-gate
12127c478bd9Sstevel@tonic-gate int
blks_per_ft(double disc)1213*d1a180b0Smaheshvs blks_per_ft(double disc)
12147c478bd9Sstevel@tonic-gate {
1215*d1a180b0Smaheshvs double dcnt = Blk_cnt, dBpi = Bpi, dsiz = BLKSIZ, dgap = 0.3;
12167c478bd9Sstevel@tonic-gate
12177c478bd9Sstevel@tonic-gate return ((int)(dcnt / (((dcnt * dsiz / dBpi) + dgap) / 12.0) * disc));
12187c478bd9Sstevel@tonic-gate }
12197c478bd9Sstevel@tonic-gate
12207c478bd9Sstevel@tonic-gate /*
12217c478bd9Sstevel@tonic-gate * tapeck: Arbitrary block size. Determine the number of physical blocks per
12227c478bd9Sstevel@tonic-gate * foot of tape, including the inter-block gap, and the possibility of a short
12237c478bd9Sstevel@tonic-gate * tape. Assume the usable portion of a tape is 85% of its length for small
12247c478bd9Sstevel@tonic-gate * block sizes and 88% for large block sizes.
12257c478bd9Sstevel@tonic-gate */
12267c478bd9Sstevel@tonic-gate
1227*d1a180b0Smaheshvs int
tapeck(struct file_info * f_p,int dir)1228*d1a180b0Smaheshvs tapeck(struct file_info *f_p, int dir)
12297c478bd9Sstevel@tonic-gate {
1230*d1a180b0Smaheshvs int again = 1, verify, old_style, new_style;
12317c478bd9Sstevel@tonic-gate char resp[16];
12327c478bd9Sstevel@tonic-gate
12337c478bd9Sstevel@tonic-gate errno = 0;
12347c478bd9Sstevel@tonic-gate if ((f_p->f_bsize = g_init(&f_p->f_dev, &f_p->f_des)) < 0)
12357c478bd9Sstevel@tonic-gate perr(1, "volcopy: Error %d during initialization\n", errno);
12367c478bd9Sstevel@tonic-gate if ((f_p->f_dev != G_TM_TAPE) && (f_p->f_dev != G_XT_TAPE) &&
12377c478bd9Sstevel@tonic-gate (f_p->f_dev != G_ST_TAPE))
12387c478bd9Sstevel@tonic-gate return (0);
12397c478bd9Sstevel@tonic-gate V_labl.v_magic[0] = '\0'; /* scribble on old data */
12407c478bd9Sstevel@tonic-gate alarm(5);
12417c478bd9Sstevel@tonic-gate if (g_read(f_p->f_dev, f_p->f_des, &V_labl, sizeof (V_labl)) <= 0) {
12427c478bd9Sstevel@tonic-gate if (dir == INPUT)
12437c478bd9Sstevel@tonic-gate perror("input tape");
12447c478bd9Sstevel@tonic-gate else
12457c478bd9Sstevel@tonic-gate perror("output tape");
12467c478bd9Sstevel@tonic-gate }
12477c478bd9Sstevel@tonic-gate alarm(0);
12487c478bd9Sstevel@tonic-gate if (V_labl.v_reel == (char)NULL && dir == INPUT)
12497c478bd9Sstevel@tonic-gate perr(9, "Input tape is empty\n");
12507c478bd9Sstevel@tonic-gate else {
12517c478bd9Sstevel@tonic-gate old_style = strncmp(V_labl.v_magic, "Volcopy", 7) == 0;
12527c478bd9Sstevel@tonic-gate new_style = strncmp(V_labl.v_magic, "VOLCOPY", 7) == 0;
12537c478bd9Sstevel@tonic-gate if (!old_style && !new_style) {
12547c478bd9Sstevel@tonic-gate verify = (dir == INPUT) ? 0 : 1;
12557c478bd9Sstevel@tonic-gate prompt(verify, "Not a labeled tape\n");
12567c478bd9Sstevel@tonic-gate if (dir == INPUT)
12577c478bd9Sstevel@tonic-gate perr(10, "Input tape not made by volcopy\n");
12587c478bd9Sstevel@tonic-gate mklabel();
12597c478bd9Sstevel@tonic-gate strncpy(V_labl.v_volume, f_p->f_vol_p, 6);
12607c478bd9Sstevel@tonic-gate Osup.fs_time = 0;
12617c478bd9Sstevel@tonic-gate } else if (new_style) {
12627c478bd9Sstevel@tonic-gate Eomflg = (dir == INPUT) ? 1 : Eomflg;
12637c478bd9Sstevel@tonic-gate if (!Eomflg)
12647c478bd9Sstevel@tonic-gate strncpy(V_labl.v_magic, "Volcopy", 7);
12657c478bd9Sstevel@tonic-gate }
12667c478bd9Sstevel@tonic-gate }
12677c478bd9Sstevel@tonic-gate if (*f_p->f_vol_p == '-')
12687c478bd9Sstevel@tonic-gate strncpy(f_p->f_vol_p, V_labl.v_volume, 6);
12697c478bd9Sstevel@tonic-gate else if (NOT_EQ(V_labl.v_volume, f_p->f_vol_p, 6)) {
12707c478bd9Sstevel@tonic-gate prompt(1, "Header volume(%.6s) does not match (%s)\n",
12717c478bd9Sstevel@tonic-gate V_labl.v_volume, f_p->f_vol_p);
12727c478bd9Sstevel@tonic-gate strncpy(V_labl.v_volume, f_p->f_vol_p, 6);
12737c478bd9Sstevel@tonic-gate }
12747c478bd9Sstevel@tonic-gate if (dir == INPUT) {
12757c478bd9Sstevel@tonic-gate Bpi = V_labl.v_dens;
12767c478bd9Sstevel@tonic-gate if (!Eomflg) {
12777c478bd9Sstevel@tonic-gate R_len = V_labl.v_length;
12787c478bd9Sstevel@tonic-gate R_num = V_labl.v_reels;
12797c478bd9Sstevel@tonic-gate }
12807c478bd9Sstevel@tonic-gate if (M3b15) {
12817c478bd9Sstevel@tonic-gate if (V_labl.v_type == T_TYPE) {
12827c478bd9Sstevel@tonic-gate if (V_labl.v_nblocks == 0) {
12837c478bd9Sstevel@tonic-gate Blk_cnt = 10;
12847c478bd9Sstevel@tonic-gate Drive_typ = C_DRIVE;
12857c478bd9Sstevel@tonic-gate } else
12867c478bd9Sstevel@tonic-gate Blk_cnt = V_labl.v_nblocks;
12877c478bd9Sstevel@tonic-gate if (V_labl.v_nblocks == 32)
12887c478bd9Sstevel@tonic-gate Drive_typ = A_DRIVE;
12897c478bd9Sstevel@tonic-gate else
12907c478bd9Sstevel@tonic-gate Drive_typ = 0;
12917c478bd9Sstevel@tonic-gate } else {
12927c478bd9Sstevel@tonic-gate Drive_typ = 0;
12937c478bd9Sstevel@tonic-gate Blk_cnt = 10;
12947c478bd9Sstevel@tonic-gate Drive_typ = C_DRIVE;
12957c478bd9Sstevel@tonic-gate }
12967c478bd9Sstevel@tonic-gate }
12977c478bd9Sstevel@tonic-gate }
12987c478bd9Sstevel@tonic-gate while (!Eomflg && (R_len <= 0 || R_len > 3600)) {
12997c478bd9Sstevel@tonic-gate (void) printf(gettext(
13007c478bd9Sstevel@tonic-gate "Enter size of reel in feet for <%s>: "),
13017c478bd9Sstevel@tonic-gate f_p->f_vol_p);
13027c478bd9Sstevel@tonic-gate fgets(resp, 10, Devtty);
13037c478bd9Sstevel@tonic-gate R_len = atoi(resp);
13047c478bd9Sstevel@tonic-gate if (R_len > 0 && R_len <= 3600)
13057c478bd9Sstevel@tonic-gate break;
13067c478bd9Sstevel@tonic-gate perr(0, "Size of reel must be > 0, <= 3600\n");
13077c478bd9Sstevel@tonic-gate }
13087c478bd9Sstevel@tonic-gate while (!Eomflg && again) {
13097c478bd9Sstevel@tonic-gate again = 0;
13107c478bd9Sstevel@tonic-gate if (!Bpi) {
13117c478bd9Sstevel@tonic-gate (void) printf(gettext(
13127c478bd9Sstevel@tonic-gate "Tape density? (i.e., 800 | 1600 | 6250)? "));
13137c478bd9Sstevel@tonic-gate fgets(resp, 10, Devtty);
13147c478bd9Sstevel@tonic-gate Bpi = getbpi(resp);
13157c478bd9Sstevel@tonic-gate }
13167c478bd9Sstevel@tonic-gate switch (Bpi) {
13177c478bd9Sstevel@tonic-gate case 800:
13187c478bd9Sstevel@tonic-gate R_blks = Ft800x10 * R_len;
13197c478bd9Sstevel@tonic-gate break;
13207c478bd9Sstevel@tonic-gate case 1600:
13217c478bd9Sstevel@tonic-gate if (M3b15) {
13227c478bd9Sstevel@tonic-gate switch (Blk_cnt) {
13237c478bd9Sstevel@tonic-gate case 1: /* Writing a new tape */
13247c478bd9Sstevel@tonic-gate if (Drive_typ == A_DRIVE)
13257c478bd9Sstevel@tonic-gate R_blks = Ft1600x32 * R_len;
13267c478bd9Sstevel@tonic-gate else if (Drive_typ == C_DRIVE)
13277c478bd9Sstevel@tonic-gate R_blks = Ft1600x10 * R_len;
13287c478bd9Sstevel@tonic-gate else
13297c478bd9Sstevel@tonic-gate R_blks = Ft1600x16 * R_len;
13307c478bd9Sstevel@tonic-gate break;
13317c478bd9Sstevel@tonic-gate case 10:
13327c478bd9Sstevel@tonic-gate R_blks = Ft1600x10 * R_len;
13337c478bd9Sstevel@tonic-gate break;
13347c478bd9Sstevel@tonic-gate case 16:
13357c478bd9Sstevel@tonic-gate R_blks = Ft1600x16 * R_len;
13367c478bd9Sstevel@tonic-gate break;
13377c478bd9Sstevel@tonic-gate case 32:
13387c478bd9Sstevel@tonic-gate R_blks = Ft1600x32 * R_len;
13397c478bd9Sstevel@tonic-gate break;
13407c478bd9Sstevel@tonic-gate default:
13417c478bd9Sstevel@tonic-gate if (Blk_cnt < 32)
13427c478bd9Sstevel@tonic-gate R_blks = blks_per_ft(0.85);
13437c478bd9Sstevel@tonic-gate else
13447c478bd9Sstevel@tonic-gate R_blks = blks_per_ft(0.88);
13457c478bd9Sstevel@tonic-gate R_blks *= R_len;
13467c478bd9Sstevel@tonic-gate } /* Blk_cnt */
13477c478bd9Sstevel@tonic-gate } else
13487c478bd9Sstevel@tonic-gate R_blks = Ft1600x10 * R_len;
13497c478bd9Sstevel@tonic-gate break;
13507c478bd9Sstevel@tonic-gate case 6250:
13517c478bd9Sstevel@tonic-gate if (M3b15) {
13527c478bd9Sstevel@tonic-gate switch (Blk_cnt) {
13537c478bd9Sstevel@tonic-gate case 1: /* Writing a new tape */
13547c478bd9Sstevel@tonic-gate if (Drive_typ == A_DRIVE)
13557c478bd9Sstevel@tonic-gate R_blks = Ft6250x32 * R_len;
13567c478bd9Sstevel@tonic-gate else if (Drive_typ == C_DRIVE)
13577c478bd9Sstevel@tonic-gate R_blks = Ft6250x10 * R_len;
13587c478bd9Sstevel@tonic-gate else
13597c478bd9Sstevel@tonic-gate R_blks = Ft6250x16 * R_len;
13607c478bd9Sstevel@tonic-gate break;
13617c478bd9Sstevel@tonic-gate case 10:
13627c478bd9Sstevel@tonic-gate R_blks = Ft6250x10 * R_len;
13637c478bd9Sstevel@tonic-gate break;
13647c478bd9Sstevel@tonic-gate case 16:
13657c478bd9Sstevel@tonic-gate R_blks = Ft6250x16 * R_len;
13667c478bd9Sstevel@tonic-gate break;
13677c478bd9Sstevel@tonic-gate case 32:
13687c478bd9Sstevel@tonic-gate R_blks = Ft6250x32 * R_len;
13697c478bd9Sstevel@tonic-gate break;
13707c478bd9Sstevel@tonic-gate default:
13717c478bd9Sstevel@tonic-gate if (Blk_cnt < 32)
13727c478bd9Sstevel@tonic-gate R_blks = blks_per_ft(0.85);
13737c478bd9Sstevel@tonic-gate else
13747c478bd9Sstevel@tonic-gate R_blks = blks_per_ft(0.88);
13757c478bd9Sstevel@tonic-gate R_blks *= R_len;
13767c478bd9Sstevel@tonic-gate }
13777c478bd9Sstevel@tonic-gate } else
13787c478bd9Sstevel@tonic-gate R_blks = Ft6250x50 * R_len;
13797c478bd9Sstevel@tonic-gate break;
13807c478bd9Sstevel@tonic-gate default:
13817c478bd9Sstevel@tonic-gate perr(0, "Bpi must be 800, 1600, or 6250\n");
13827c478bd9Sstevel@tonic-gate Bpi = 0;
13837c478bd9Sstevel@tonic-gate again = 1;
13847c478bd9Sstevel@tonic-gate } /* Bpi */
13857c478bd9Sstevel@tonic-gate } /* again */
13867c478bd9Sstevel@tonic-gate (void) printf(gettext("\nReel %.6s"), V_labl.v_volume);
13877c478bd9Sstevel@tonic-gate if (!Eomflg) {
13887c478bd9Sstevel@tonic-gate V_labl.v_length = R_len;
13897c478bd9Sstevel@tonic-gate V_labl.v_dens = Bpi;
13907c478bd9Sstevel@tonic-gate (void) printf(gettext(", %d feet, %d BPI\n"), R_len, Bpi);
13917c478bd9Sstevel@tonic-gate } else
13927c478bd9Sstevel@tonic-gate (void) printf(gettext(", ? feet\n"));
13937c478bd9Sstevel@tonic-gate return (1);
13947c478bd9Sstevel@tonic-gate }
13957c478bd9Sstevel@tonic-gate
13967c478bd9Sstevel@tonic-gate /*
13977c478bd9Sstevel@tonic-gate * hdrck: Look for and validate a volcopy style tape label.
13987c478bd9Sstevel@tonic-gate */
13997c478bd9Sstevel@tonic-gate
1400*d1a180b0Smaheshvs int
hdrck(int dev,int fd,char * tvol)1401*d1a180b0Smaheshvs hdrck(int dev, int fd, char *tvol)
14027c478bd9Sstevel@tonic-gate {
1403*d1a180b0Smaheshvs int verify;
14047c478bd9Sstevel@tonic-gate struct volcopy_label tlabl;
14057c478bd9Sstevel@tonic-gate
14067c478bd9Sstevel@tonic-gate alarm(15); /* don't scan whole tape for label */
14077c478bd9Sstevel@tonic-gate errno = 0;
14087c478bd9Sstevel@tonic-gate if (g_read(dev, fd, &tlabl, sizeof (tlabl)) != sizeof (tlabl)) {
14097c478bd9Sstevel@tonic-gate alarm(0);
14107c478bd9Sstevel@tonic-gate verify = Otape;
14117c478bd9Sstevel@tonic-gate prompt(verify, "Cannot read header\n");
14127c478bd9Sstevel@tonic-gate if (Itape)
14137c478bd9Sstevel@tonic-gate close(fd);
14147c478bd9Sstevel@tonic-gate else
14157c478bd9Sstevel@tonic-gate strncpy(V_labl.v_volume, tvol, 6);
14167c478bd9Sstevel@tonic-gate return (verify);
14177c478bd9Sstevel@tonic-gate }
14187c478bd9Sstevel@tonic-gate alarm(0);
14197c478bd9Sstevel@tonic-gate V_labl.v_reel = tlabl.v_reel;
14207c478bd9Sstevel@tonic-gate if (NOT_EQ(tlabl.v_volume, tvol, 6)) {
14217c478bd9Sstevel@tonic-gate perr(0, "Volume is <%.6s>, not <%s>.\n", tlabl.v_volume, tvol);
14227c478bd9Sstevel@tonic-gate if (ask("Want to override? ")) {
14237c478bd9Sstevel@tonic-gate if (Otape)
14247c478bd9Sstevel@tonic-gate strncpy(V_labl.v_volume, tvol, 6);
14257c478bd9Sstevel@tonic-gate else
14267c478bd9Sstevel@tonic-gate strncpy(tvol, tlabl.v_volume, 6);
14277c478bd9Sstevel@tonic-gate return (1);
14287c478bd9Sstevel@tonic-gate }
14297c478bd9Sstevel@tonic-gate return (0);
14307c478bd9Sstevel@tonic-gate }
14317c478bd9Sstevel@tonic-gate return (1);
14327c478bd9Sstevel@tonic-gate }
14337c478bd9Sstevel@tonic-gate
14347c478bd9Sstevel@tonic-gate /*
14357c478bd9Sstevel@tonic-gate * mklabel: Zero out and initialize a volcopy label.
14367c478bd9Sstevel@tonic-gate */
14377c478bd9Sstevel@tonic-gate
1438*d1a180b0Smaheshvs static void
mklabel(void)1439*d1a180b0Smaheshvs mklabel(void)
14407c478bd9Sstevel@tonic-gate {
14417c478bd9Sstevel@tonic-gate
14427c478bd9Sstevel@tonic-gate (void) memcpy(&V_labl, Empty, sizeof (V_labl));
14437c478bd9Sstevel@tonic-gate if (!Eomflg)
14447c478bd9Sstevel@tonic-gate (void) strcpy(V_labl.v_magic, "Volcopy");
14457c478bd9Sstevel@tonic-gate else
14467c478bd9Sstevel@tonic-gate (void) strcpy(V_labl.v_magic, "VOLCOPY");
14477c478bd9Sstevel@tonic-gate }
14487c478bd9Sstevel@tonic-gate
14497c478bd9Sstevel@tonic-gate /*
14507c478bd9Sstevel@tonic-gate * rprt: Report activity to user.
14517c478bd9Sstevel@tonic-gate */
14527c478bd9Sstevel@tonic-gate
1453*d1a180b0Smaheshvs static void
rprt(void)1454*d1a180b0Smaheshvs rprt(void)
14557c478bd9Sstevel@tonic-gate {
14567c478bd9Sstevel@tonic-gate
14577c478bd9Sstevel@tonic-gate if (Itape)
14587c478bd9Sstevel@tonic-gate (void) printf(gettext("\nReading "));
14597c478bd9Sstevel@tonic-gate else /* Otape */
14607c478bd9Sstevel@tonic-gate (void) printf(gettext("\nWriting "));
14617c478bd9Sstevel@tonic-gate if (!Eomflg)
14627c478bd9Sstevel@tonic-gate (void) printf(gettext(
14637c478bd9Sstevel@tonic-gate "REEL %d of %d VOL = %.6s\n"),
14647c478bd9Sstevel@tonic-gate R_cur, R_num, In.f_vol_p);
14657c478bd9Sstevel@tonic-gate else
14667c478bd9Sstevel@tonic-gate (void) printf(gettext(
14677c478bd9Sstevel@tonic-gate "REEL %d of ? VOL = %.6s\n"), R_cur, In.f_vol_p);
14687c478bd9Sstevel@tonic-gate }
14697c478bd9Sstevel@tonic-gate
14707c478bd9Sstevel@tonic-gate #ifdef LOG
14717c478bd9Sstevel@tonic-gate /*
14727c478bd9Sstevel@tonic-gate * fslog: Log current activity.
14737c478bd9Sstevel@tonic-gate */
14747c478bd9Sstevel@tonic-gate
1475*d1a180b0Smaheshvs static int
fslog(void)1476*d1a180b0Smaheshvs fslog(void)
14777c478bd9Sstevel@tonic-gate {
14787c478bd9Sstevel@tonic-gate FILE *fp = NULL;
14797c478bd9Sstevel@tonic-gate
14807c478bd9Sstevel@tonic-gate fp = fopen("/var/adm/filesave.log", "a");
14817c478bd9Sstevel@tonic-gate if (fp == NULL) {
14827c478bd9Sstevel@tonic-gate perr(1, "volcopy: cannot open /var/adm/filesave.log\n");
14837c478bd9Sstevel@tonic-gate }
14847c478bd9Sstevel@tonic-gate
14857c478bd9Sstevel@tonic-gate fprintf(fp, "%s%c%.6s%c%.6s -> %s%c%.6s%c%.6s on %.24s\n",
14867c478bd9Sstevel@tonic-gate In.f_dev_p, ';', Ifname, ';', Ifpack, Out.f_dev_p,
14877c478bd9Sstevel@tonic-gate ';', Ofname, ';', Ofpack, ctime(&Tvec));
14887c478bd9Sstevel@tonic-gate fclose(fp);
1489*d1a180b0Smaheshvs return (0);
14907c478bd9Sstevel@tonic-gate }
14917c478bd9Sstevel@tonic-gate #endif /* LOG */
14927c478bd9Sstevel@tonic-gate
14937c478bd9Sstevel@tonic-gate /*
14947c478bd9Sstevel@tonic-gate * getname: Get device name.
14957c478bd9Sstevel@tonic-gate */
14967c478bd9Sstevel@tonic-gate
1497*d1a180b0Smaheshvs void
getname(char * nam_p)1498*d1a180b0Smaheshvs getname(char *nam_p)
14997c478bd9Sstevel@tonic-gate {
1500*d1a180b0Smaheshvs int lastchar;
15017c478bd9Sstevel@tonic-gate char nam_buf[21];
15027c478bd9Sstevel@tonic-gate
15037c478bd9Sstevel@tonic-gate nam_buf[0] = '\0';
15047c478bd9Sstevel@tonic-gate (void) printf(gettext("Changing drives? (type RETURN for no,\n"));
15057c478bd9Sstevel@tonic-gate (void) printf(gettext("\t`/dev/rmt/??\' or `/dev/rtp/??\' for yes: "));
15067c478bd9Sstevel@tonic-gate fgets(nam_buf, 20, Devtty);
15077c478bd9Sstevel@tonic-gate nam_buf[20] = '\0';
15087c478bd9Sstevel@tonic-gate lastchar = strlen(nam_buf) - 1;
15097c478bd9Sstevel@tonic-gate if (nam_buf[lastchar] == '\n')
15107c478bd9Sstevel@tonic-gate nam_buf[lastchar] = '\0'; /* remove it */
15117c478bd9Sstevel@tonic-gate if (nam_buf[0] != '\0')
15127c478bd9Sstevel@tonic-gate (void) strcpy(nam_p, nam_buf);
15137c478bd9Sstevel@tonic-gate }
15147c478bd9Sstevel@tonic-gate
15157c478bd9Sstevel@tonic-gate /*
15167c478bd9Sstevel@tonic-gate * chgreel: Change reel on end-of-media.
15177c478bd9Sstevel@tonic-gate */
15187c478bd9Sstevel@tonic-gate
1519*d1a180b0Smaheshvs static void
chgreel(struct file_info * f_p,int dir)1520*d1a180b0Smaheshvs chgreel(struct file_info *f_p, int dir)
15217c478bd9Sstevel@tonic-gate {
1522*d1a180b0Smaheshvs int again = 1, lastchar, temp;
15237c478bd9Sstevel@tonic-gate char vol_tmp[11];
15247c478bd9Sstevel@tonic-gate
15257c478bd9Sstevel@tonic-gate R_cur++;
15267c478bd9Sstevel@tonic-gate while (again) {
15277c478bd9Sstevel@tonic-gate again = 0;
15287c478bd9Sstevel@tonic-gate errno = 0;
15297c478bd9Sstevel@tonic-gate (void) close(f_p->f_des);
15307c478bd9Sstevel@tonic-gate (void) getname(f_p->f_dev_p);
15317c478bd9Sstevel@tonic-gate (void) printf(gettext(
15327c478bd9Sstevel@tonic-gate "Mount tape %d\nType volume-ID when ready: "), R_cur);
15337c478bd9Sstevel@tonic-gate vol_tmp[0] = '\0';
15347c478bd9Sstevel@tonic-gate fgets(vol_tmp, 10, Devtty);
15357c478bd9Sstevel@tonic-gate vol_tmp[10] = '\0';
15367c478bd9Sstevel@tonic-gate lastchar = strlen(vol_tmp) - 1;
15377c478bd9Sstevel@tonic-gate if (vol_tmp[lastchar] == '\n')
15387c478bd9Sstevel@tonic-gate vol_tmp[lastchar] = '\0'; /* remove it */
15397c478bd9Sstevel@tonic-gate if (vol_tmp[0] != '\0') { /* if null string, use old vol-id */
15407c478bd9Sstevel@tonic-gate strncpy(f_p->f_vol_p, vol_tmp, 6);
15417c478bd9Sstevel@tonic-gate strncpy(V_labl.v_volume, vol_tmp, 6);
15427c478bd9Sstevel@tonic-gate }
15437c478bd9Sstevel@tonic-gate errno = 0;
15447c478bd9Sstevel@tonic-gate f_p->f_des = open(f_p->f_dev_p, 0);
15457c478bd9Sstevel@tonic-gate if (f_p->f_des <= 0 || f_p->f_des > 10) {
15467c478bd9Sstevel@tonic-gate if (dir == INPUT)
15477c478bd9Sstevel@tonic-gate perror("input ERR");
15487c478bd9Sstevel@tonic-gate else
15497c478bd9Sstevel@tonic-gate perror("output ERR");
15507c478bd9Sstevel@tonic-gate }
15517c478bd9Sstevel@tonic-gate errno = 0;
15527c478bd9Sstevel@tonic-gate if (g_init(&(f_p->f_dev), &(f_p->f_des)) < 0)
15537c478bd9Sstevel@tonic-gate perr(0, "Initialization error %d\n", errno);
15547c478bd9Sstevel@tonic-gate if ((f_p->f_dev != G_TM_TAPE) && (f_p->f_dev != G_XT_TAPE) &&
15557c478bd9Sstevel@tonic-gate (f_p->f_dev != G_ST_TAPE)) {
15567c478bd9Sstevel@tonic-gate (void) printf(gettext(
15577c478bd9Sstevel@tonic-gate "\n'%s' is not a valid device"), f_p->f_dev_p);
15587c478bd9Sstevel@tonic-gate (void) printf(gettext(
15597c478bd9Sstevel@tonic-gate "\n\tenter device name `/dev/rmt/??\' or `/dev/rtp/??\' :"));
15607c478bd9Sstevel@tonic-gate again = 1;
15617c478bd9Sstevel@tonic-gate continue;
15627c478bd9Sstevel@tonic-gate }
15637c478bd9Sstevel@tonic-gate if (!hdrck(f_p->f_dev, f_p->f_des, f_p->f_vol_p)) {
15647c478bd9Sstevel@tonic-gate again = 1;
15657c478bd9Sstevel@tonic-gate continue;
15667c478bd9Sstevel@tonic-gate }
15677c478bd9Sstevel@tonic-gate switch (dir) {
15687c478bd9Sstevel@tonic-gate case INPUT:
15697c478bd9Sstevel@tonic-gate if (V_labl.v_reel != R_cur) {
15707c478bd9Sstevel@tonic-gate perr(0, "Need reel %d, label says reel %d\n",
15717c478bd9Sstevel@tonic-gate R_cur, V_labl.v_reel);
15727c478bd9Sstevel@tonic-gate again = 1;
15737c478bd9Sstevel@tonic-gate continue;
15747c478bd9Sstevel@tonic-gate }
15757c478bd9Sstevel@tonic-gate break;
15767c478bd9Sstevel@tonic-gate case OUTPUT:
15777c478bd9Sstevel@tonic-gate V_labl.v_reel = R_cur;
15787c478bd9Sstevel@tonic-gate temp = V_labl.v_offset;
15797c478bd9Sstevel@tonic-gate V_labl.v_offset /= BUFSIZ;
15807c478bd9Sstevel@tonic-gate close(f_p->f_des);
15817c478bd9Sstevel@tonic-gate sleep(2);
15827c478bd9Sstevel@tonic-gate errno = 0;
15837c478bd9Sstevel@tonic-gate f_p->f_des = open(f_p->f_dev_p, 1);
15847c478bd9Sstevel@tonic-gate if (f_p->f_des <= 0 || f_p->f_des > 10)
15857c478bd9Sstevel@tonic-gate perror("output ERR");
15867c478bd9Sstevel@tonic-gate errno = 0;
15877c478bd9Sstevel@tonic-gate if (g_init(&(f_p->f_dev), &(f_p->f_des)) < 0)
15887c478bd9Sstevel@tonic-gate perr(1, "Initialization error %d\n", errno);
15897c478bd9Sstevel@tonic-gate errno = 0;
15907c478bd9Sstevel@tonic-gate if (g_write(f_p->f_dev, f_p->f_des, &V_labl,
15917c478bd9Sstevel@tonic-gate sizeof (V_labl)) < 0) {
15927c478bd9Sstevel@tonic-gate perr(0, "Cannot re-write header -Try again!\n");
15937c478bd9Sstevel@tonic-gate again = 1;
15947c478bd9Sstevel@tonic-gate V_labl.v_offset = temp;
15957c478bd9Sstevel@tonic-gate continue;
15967c478bd9Sstevel@tonic-gate }
15977c478bd9Sstevel@tonic-gate V_labl.v_offset = temp;
15987c478bd9Sstevel@tonic-gate break;
15997c478bd9Sstevel@tonic-gate default:
16007c478bd9Sstevel@tonic-gate perr(1, "Impossible case\n");
16017c478bd9Sstevel@tonic-gate } /* dir */
16027c478bd9Sstevel@tonic-gate } /* again */
16037c478bd9Sstevel@tonic-gate rprt();
16047c478bd9Sstevel@tonic-gate }
16057c478bd9Sstevel@tonic-gate
16067c478bd9Sstevel@tonic-gate /*
16077c478bd9Sstevel@tonic-gate * perr: Print error messages.
16087c478bd9Sstevel@tonic-gate */
16097c478bd9Sstevel@tonic-gate
16107c478bd9Sstevel@tonic-gate static void
perr(int severity,const char * fmt,...)16117c478bd9Sstevel@tonic-gate perr(int severity, const char *fmt, ...)
16127c478bd9Sstevel@tonic-gate {
16137c478bd9Sstevel@tonic-gate va_list ap;
16147c478bd9Sstevel@tonic-gate
16157c478bd9Sstevel@tonic-gate va_start(ap, fmt);
16167c478bd9Sstevel@tonic-gate (void) fflush(stdout);
16177c478bd9Sstevel@tonic-gate (void) fflush(stderr);
16187c478bd9Sstevel@tonic-gate if (severity == 10) {
16197c478bd9Sstevel@tonic-gate (void) vfprintf(stdout, gettext(fmt), ap);
16207c478bd9Sstevel@tonic-gate (void) fprintf(stdout, gettext(
16217c478bd9Sstevel@tonic-gate "\t%d reel(s) completed\n"), --R_cur);
16227c478bd9Sstevel@tonic-gate (void) fflush(stdout);
16237c478bd9Sstevel@tonic-gate (void) fflush(stderr);
16247c478bd9Sstevel@tonic-gate cleanup();
16257c478bd9Sstevel@tonic-gate exit(31+9);
16267c478bd9Sstevel@tonic-gate }
16277c478bd9Sstevel@tonic-gate (void) vfprintf(stderr, gettext(fmt), ap);
16287c478bd9Sstevel@tonic-gate (void) fflush(stderr);
16297c478bd9Sstevel@tonic-gate va_end(ap);
16307c478bd9Sstevel@tonic-gate if (severity > 0) {
16317c478bd9Sstevel@tonic-gate (void) cleanup();
16327c478bd9Sstevel@tonic-gate exit(31+severity);
16337c478bd9Sstevel@tonic-gate }
16347c478bd9Sstevel@tonic-gate }
16357c478bd9Sstevel@tonic-gate
16367c478bd9Sstevel@tonic-gate
16377c478bd9Sstevel@tonic-gate static void
getinfs(int dev,int fd,char * buf)1638*d1a180b0Smaheshvs getinfs(int dev, int fd, char *buf)
16397c478bd9Sstevel@tonic-gate {
16407c478bd9Sstevel@tonic-gate int cnt;
16417c478bd9Sstevel@tonic-gate int i;
16427c478bd9Sstevel@tonic-gate
16437c478bd9Sstevel@tonic-gate if (lseek(fd, SBLOCK * DEV_BSIZE, 0) != SBLOCK * DEV_BSIZE) {
16447c478bd9Sstevel@tonic-gate perr(10, "Unable to lseek on input\n");
16457c478bd9Sstevel@tonic-gate }
16467c478bd9Sstevel@tonic-gate cnt = SBSIZE/DEV_BSIZE;
16477c478bd9Sstevel@tonic-gate for (i = 0; i < cnt; i++) {
16487c478bd9Sstevel@tonic-gate if (g_read(dev, fd, (char *)buf + i*DEV_BSIZE, DEV_BSIZE)
16497c478bd9Sstevel@tonic-gate != DEV_BSIZE) {
16507c478bd9Sstevel@tonic-gate perr(10, "Unable to read on input\n");
16517c478bd9Sstevel@tonic-gate }
16527c478bd9Sstevel@tonic-gate }
16537c478bd9Sstevel@tonic-gate }
16547c478bd9Sstevel@tonic-gate
16557c478bd9Sstevel@tonic-gate static void
getoutfs(int dev,int fd,char * buf,int verify)1656*d1a180b0Smaheshvs getoutfs(int dev, int fd, char *buf, int verify)
16577c478bd9Sstevel@tonic-gate {
16587c478bd9Sstevel@tonic-gate int cnt;
16597c478bd9Sstevel@tonic-gate int i;
16607c478bd9Sstevel@tonic-gate
16617c478bd9Sstevel@tonic-gate errno = 0;
16627c478bd9Sstevel@tonic-gate if (lseek(fd, SBLOCK * DEV_BSIZE, 0) != SBLOCK * DEV_BSIZE) {
16637c478bd9Sstevel@tonic-gate prompt(verify, "Unable to lseek on output\n", errno);
16647c478bd9Sstevel@tonic-gate }
16657c478bd9Sstevel@tonic-gate cnt = SBSIZE/DEV_BSIZE;
16667c478bd9Sstevel@tonic-gate for (i = 0; i < cnt; i++) {
16677c478bd9Sstevel@tonic-gate if (g_read(dev, fd, (char *)buf + i*DEV_BSIZE, DEV_BSIZE)
16687c478bd9Sstevel@tonic-gate != DEV_BSIZE) {
16697c478bd9Sstevel@tonic-gate prompt(verify, "Unable to read on output\n", errno);
16707c478bd9Sstevel@tonic-gate }
16717c478bd9Sstevel@tonic-gate }
16727c478bd9Sstevel@tonic-gate }
16737c478bd9Sstevel@tonic-gate
16747c478bd9Sstevel@tonic-gate static char *
getfslabel(struct fs * sb)1675*d1a180b0Smaheshvs getfslabel(struct fs *sb)
16767c478bd9Sstevel@tonic-gate {
16777c478bd9Sstevel@tonic-gate int i;
16787c478bd9Sstevel@tonic-gate int blk;
16797c478bd9Sstevel@tonic-gate
16807c478bd9Sstevel@tonic-gate /*
16817c478bd9Sstevel@tonic-gate * is there room for label?
16827c478bd9Sstevel@tonic-gate */
16837c478bd9Sstevel@tonic-gate
16847c478bd9Sstevel@tonic-gate if (sb->fs_cpc <= 0)
16857c478bd9Sstevel@tonic-gate return (nolabel);
16867c478bd9Sstevel@tonic-gate
16877c478bd9Sstevel@tonic-gate /*
16887c478bd9Sstevel@tonic-gate * calculate the available blocks for each rotational position
16897c478bd9Sstevel@tonic-gate */
16907c478bd9Sstevel@tonic-gate blk = sb->fs_spc * sb->fs_cpc / sb->fs_nspf;
16917c478bd9Sstevel@tonic-gate for (i = 0; i < blk; i += sb->fs_frag)
16927c478bd9Sstevel@tonic-gate /* void */;
16937c478bd9Sstevel@tonic-gate i -= sb->fs_frag;
16947c478bd9Sstevel@tonic-gate blk = i / sb->fs_frag;
16957c478bd9Sstevel@tonic-gate
16967c478bd9Sstevel@tonic-gate return ((char *)&(fs_rotbl(sb)[blk]));
16977c478bd9Sstevel@tonic-gate }
16987c478bd9Sstevel@tonic-gate
16997c478bd9Sstevel@tonic-gate static char *
getvolabel(struct fs * sb)1700*d1a180b0Smaheshvs getvolabel(struct fs *sb)
17017c478bd9Sstevel@tonic-gate {
17027c478bd9Sstevel@tonic-gate char *p;
17037c478bd9Sstevel@tonic-gate int i;
17047c478bd9Sstevel@tonic-gate
17057c478bd9Sstevel@tonic-gate p = getfslabel(sb);
17067c478bd9Sstevel@tonic-gate
17077c478bd9Sstevel@tonic-gate if (p == nolabel || p == NULL)
17087c478bd9Sstevel@tonic-gate return (nolabel);
17097c478bd9Sstevel@tonic-gate
17107c478bd9Sstevel@tonic-gate for (i = 0; *p && i < 6; p++, i++)
17117c478bd9Sstevel@tonic-gate ;
17127c478bd9Sstevel@tonic-gate p++;
17137c478bd9Sstevel@tonic-gate return (p);
17147c478bd9Sstevel@tonic-gate }
1715