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