xref: /illumos-gate/usr/src/cmd/fs.d/ufs/newfs/newfs.c (revision 8b7c2cdf)
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
56d24e334Svsakar  * Common Development and Distribution License (the "License").
66d24e334Svsakar  * 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 
227c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
237c478bd9Sstevel@tonic-gate 	/* from UCB 5.2 9/11/85 */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate  * newfs: friendly front end to mkfs
277c478bd9Sstevel@tonic-gate  *
284d594c33Svsakar  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
297c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/param.h>
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <locale.h>
357c478bd9Sstevel@tonic-gate #include <sys/stat.h>
367c478bd9Sstevel@tonic-gate #include <sys/buf.h>
377c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h>
387c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
397c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_inode.h>
407c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include <errno.h>
437c478bd9Sstevel@tonic-gate #include <stdio.h>
447c478bd9Sstevel@tonic-gate #include <string.h>
457c478bd9Sstevel@tonic-gate #include <stdlib.h>
467c478bd9Sstevel@tonic-gate #include <stdarg.h>
477c478bd9Sstevel@tonic-gate #include <stdio.h>
487c478bd9Sstevel@tonic-gate #include <fcntl.h>
497c478bd9Sstevel@tonic-gate #include <unistd.h>
507c478bd9Sstevel@tonic-gate #include <limits.h>
517c478bd9Sstevel@tonic-gate #include <libintl.h>
527c478bd9Sstevel@tonic-gate #include <sys/dkio.h>
537c478bd9Sstevel@tonic-gate #include <sys/vtoc.h>
547c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
557c478bd9Sstevel@tonic-gate #include <sys/efi_partition.h>
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #include <fslib.h>
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate static unsigned int number(char *, char *, int, int);
607c478bd9Sstevel@tonic-gate static int64_t number64(char *, char *, int, int64_t);
617c478bd9Sstevel@tonic-gate static diskaddr_t getdiskbydev(char *);
627c478bd9Sstevel@tonic-gate static int  yes(void);
637c478bd9Sstevel@tonic-gate static int  notrand(char *);
647c478bd9Sstevel@tonic-gate static void usage();
657c478bd9Sstevel@tonic-gate static diskaddr_t get_device_size(int, char *);
667c478bd9Sstevel@tonic-gate static diskaddr_t brute_force_get_device_size(int);
677c478bd9Sstevel@tonic-gate static int validate_size(char *disk, diskaddr_t size);
687c478bd9Sstevel@tonic-gate static void exenv(void);
697c478bd9Sstevel@tonic-gate static struct fs *read_sb(char *);
707c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/
717c478bd9Sstevel@tonic-gate static void fatal(char *fmt, ...);
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #define	EPATH "PATH=/usr/sbin:/sbin:"
747c478bd9Sstevel@tonic-gate #define	CPATH "/sbin"					/* an EPATH element */
757c478bd9Sstevel@tonic-gate #define	MB (1024 * 1024)
767c478bd9Sstevel@tonic-gate #define	GBSEC ((1024 * 1024 * 1024) / DEV_BSIZE)	/* sectors in a GB */
777c478bd9Sstevel@tonic-gate #define	MINFREESEC ((64 * 1024 * 1024) / DEV_BSIZE)	/* sectors in 64 MB */
787c478bd9Sstevel@tonic-gate #define	MINCPG (16)	/* traditional */
797c478bd9Sstevel@tonic-gate #define	MAXDEFDENSITY (8 * 1024)	/* arbitrary */
807c478bd9Sstevel@tonic-gate #define	MINDENSITY (2 * 1024)	/* traditional */
817c478bd9Sstevel@tonic-gate #define	MIN_MTB_DENSITY (1024 * 1024)
827c478bd9Sstevel@tonic-gate #define	POWEROF2(num)	(((num) & ((num) - 1)) == 0)
837c478bd9Sstevel@tonic-gate #define	SECTORS_PER_TERABYTE	(1LL << 31)
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate  * The following constant specifies an upper limit for file system size
867c478bd9Sstevel@tonic-gate  * that is actually a lot bigger than we expect to support with UFS. (Since
877c478bd9Sstevel@tonic-gate  * it's specified in sectors, the file system size would be 2**44 * 512,
887c478bd9Sstevel@tonic-gate  * which is 2**53, which is 8192 Terabytes.)  However, it's useful
897c478bd9Sstevel@tonic-gate  * for checking the basic sanity of a size value that is input on the
907c478bd9Sstevel@tonic-gate  * command line.
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate #define	FS_SIZE_UPPER_LIMIT	0x100000000000LL
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /* For use with number() */
957c478bd9Sstevel@tonic-gate #define	NR_NONE		0
967c478bd9Sstevel@tonic-gate #define	NR_PERCENT	0x01
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate /*
997c478bd9Sstevel@tonic-gate  * The following two constants set the default block and fragment sizes.
1007c478bd9Sstevel@tonic-gate  * Both constants must be a power of 2 and meet the following constraints:
1017c478bd9Sstevel@tonic-gate  *	MINBSIZE <= DESBLKSIZE <= MAXBSIZE
1027c478bd9Sstevel@tonic-gate  *	DEV_BSIZE <= DESFRAGSIZE <= DESBLKSIZE
1037c478bd9Sstevel@tonic-gate  *	DESBLKSIZE / DESFRAGSIZE <= 8
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate #define	DESBLKSIZE	8192
1067c478bd9Sstevel@tonic-gate #define	DESFRAGSIZE	1024
1077c478bd9Sstevel@tonic-gate 
1086d24e334Svsakar #ifdef DEBUG
1096d24e334Svsakar #define	dprintf(x)	printf x
1106d24e334Svsakar #else
1116d24e334Svsakar #define	dprintf(x)
1126d24e334Svsakar #endif
1136451fdbcSvsakar 
1147c478bd9Sstevel@tonic-gate static int	Nflag;		/* run mkfs without writing file system */
1157c478bd9Sstevel@tonic-gate static int	Tflag;		/* set up file system for growth to over 1 TB */
1167c478bd9Sstevel@tonic-gate static int	verbose;	/* show mkfs line before exec */
1177c478bd9Sstevel@tonic-gate static int	fsize = 0;		/* fragment size */
1187c478bd9Sstevel@tonic-gate static int	fsize_flag = 0;	/* fragment size was specified on cmd line */
1197c478bd9Sstevel@tonic-gate static int	bsize;		/* block size */
1207c478bd9Sstevel@tonic-gate static int	ntracks;	/* # tracks/cylinder */
1217c478bd9Sstevel@tonic-gate static int	ntracks_set = 0; /* true if the user specified ntracks */
1227c478bd9Sstevel@tonic-gate static int	optim = FS_OPTTIME;	/* optimization, t(ime) or s(pace) */
1237c478bd9Sstevel@tonic-gate static int	nsectors;	/* # sectors/track */
1247c478bd9Sstevel@tonic-gate static int	cpg;		/* cylinders/cylinder group */
1257c478bd9Sstevel@tonic-gate static int	cpg_set = 0;	/* true if the user specified cpg */
1267c478bd9Sstevel@tonic-gate static int	minfree = -1;	/* free space threshold */
1277c478bd9Sstevel@tonic-gate static int	rpm;		/* revolutions/minute of drive */
1287c478bd9Sstevel@tonic-gate static int	rpm_set = 0;	/* true if the user specified rpm */
1297c478bd9Sstevel@tonic-gate static int	nrpos = 8;	/* # of distinguished rotational positions */
1307c478bd9Sstevel@tonic-gate 				/* 8 is the historical default */
1317c478bd9Sstevel@tonic-gate static int	nrpos_set = 0;	/* true if the user specified nrpos */
1327c478bd9Sstevel@tonic-gate static int	density = 0;	/* number of bytes per inode */
1337c478bd9Sstevel@tonic-gate static int	apc;		/* alternates per cylinder */
1347c478bd9Sstevel@tonic-gate static int	apc_set = 0;	/* true if the user specified apc */
1357c478bd9Sstevel@tonic-gate static int 	rot = -1;	/* rotational delay (msecs) */
1367c478bd9Sstevel@tonic-gate static int	rot_set = 0;	/* true if the user specified rot */
1377c478bd9Sstevel@tonic-gate static int 	maxcontig = -1;	/* maximum number of contig blocks */
138355d6bb5Sswilcox static int	text_sb = 0;	/* no disk changes; just final sb text dump */
139355d6bb5Sswilcox static int	binary_sb = 0;	/* no disk changes; just final sb binary dump */
1407c478bd9Sstevel@tonic-gate static int	label_type;	/* see types below */
1417c478bd9Sstevel@tonic-gate 
1426451fdbcSvsakar /*
1436451fdbcSvsakar  * The variable use_efi_dflts is an indicator of whether to use EFI logic
1446451fdbcSvsakar  * or the geometry logic in laying out the filesystem. This is decided
145d50c8f90Svsakar  * based on the size/type of the disk and is used only for non-EFI labeled
146d50c8f90Svsakar  * disks and removable media.
1476451fdbcSvsakar  */
1486451fdbcSvsakar static int	use_efi_dflts = 0;
149d50c8f90Svsakar static int	isremovable = 0;
150*8b7c2cdfSws static int	ishotpluggable = 0;
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate static char	device[MAXPATHLEN];
1537c478bd9Sstevel@tonic-gate static char	cmd[BUFSIZ];
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate extern	char	*getfullrawname(); /* from libadm */
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate int
1587c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
1597c478bd9Sstevel@tonic-gate {
1607c478bd9Sstevel@tonic-gate 	char *special, *name;
1617c478bd9Sstevel@tonic-gate 	struct stat64 st;
1627c478bd9Sstevel@tonic-gate 	int status;
1637c478bd9Sstevel@tonic-gate 	int option;
1647c478bd9Sstevel@tonic-gate 	struct fs *sbp;	/* Pointer to superblock (if present) */
1657c478bd9Sstevel@tonic-gate 	diskaddr_t actual_fssize;
1667c478bd9Sstevel@tonic-gate 	diskaddr_t max_possible_fssize;
1677c478bd9Sstevel@tonic-gate 	diskaddr_t req_fssize = 0;
1687c478bd9Sstevel@tonic-gate 	diskaddr_t fssize = 0;
1697c478bd9Sstevel@tonic-gate 	char	*req_fssize_str = NULL; /* requested size argument */
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
1747c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN	"SYS_TEST"
1757c478bd9Sstevel@tonic-gate #endif
1767c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	opterr = 0;	/* We print our own errors, disable getopt's message */
179355d6bb5Sswilcox 	while ((option = getopt(argc, argv,
180355d6bb5Sswilcox 	    "vNBSs:C:d:t:o:a:b:f:c:m:n:r:i:T")) != EOF) {
1817c478bd9Sstevel@tonic-gate 		switch (option) {
182355d6bb5Sswilcox 		case 'S':
183355d6bb5Sswilcox 			text_sb++;
184355d6bb5Sswilcox 			break;
185355d6bb5Sswilcox 		case 'B':
186355d6bb5Sswilcox 			binary_sb++;
187355d6bb5Sswilcox 			break;
1887c478bd9Sstevel@tonic-gate 		case 'v':
1897c478bd9Sstevel@tonic-gate 			verbose++;
1907c478bd9Sstevel@tonic-gate 			break;
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 		case 'N':
1937c478bd9Sstevel@tonic-gate 			Nflag++;
1947c478bd9Sstevel@tonic-gate 			break;
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 		case 's':
1977c478bd9Sstevel@tonic-gate 			/*
1987c478bd9Sstevel@tonic-gate 			 * The maximum file system size is a lot smaller
1997c478bd9Sstevel@tonic-gate 			 * than FS_SIZE_UPPER_LIMIT, but until we find out
2007c478bd9Sstevel@tonic-gate 			 * the device size and block size, we don't know
2017c478bd9Sstevel@tonic-gate 			 * what it is.  So save the requested size in a
2027c478bd9Sstevel@tonic-gate 			 * string so that we can print it out later if we
2037c478bd9Sstevel@tonic-gate 			 * determine it's too big.
2047c478bd9Sstevel@tonic-gate 			 */
2057c478bd9Sstevel@tonic-gate 			req_fssize = number64("fssize", optarg, NR_NONE,
2067c478bd9Sstevel@tonic-gate 			    FS_SIZE_UPPER_LIMIT);
2077c478bd9Sstevel@tonic-gate 			if (req_fssize < 1024)
2087c478bd9Sstevel@tonic-gate 				fatal(gettext(
2097c478bd9Sstevel@tonic-gate 				    "%s: fssize must be at least 1024"),
2107c478bd9Sstevel@tonic-gate 				    optarg);
2117c478bd9Sstevel@tonic-gate 			req_fssize_str = strdup(optarg);
2127c478bd9Sstevel@tonic-gate 			if (req_fssize_str == NULL)
2137c478bd9Sstevel@tonic-gate 				fatal(gettext(
2147c478bd9Sstevel@tonic-gate 				    "Insufficient memory for string copy."));
2157c478bd9Sstevel@tonic-gate 			break;
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate 		case 'C':
2187c478bd9Sstevel@tonic-gate 			maxcontig = number("maxcontig", optarg, NR_NONE, -1);
2197c478bd9Sstevel@tonic-gate 			if (maxcontig < 0)
2207c478bd9Sstevel@tonic-gate 				fatal(gettext("%s: bad maxcontig"), optarg);
2217c478bd9Sstevel@tonic-gate 			break;
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 		case 'd':
2247c478bd9Sstevel@tonic-gate 			rot = number("rotdelay", optarg, NR_NONE, 0);
2257c478bd9Sstevel@tonic-gate 			rot_set = 1;
2267c478bd9Sstevel@tonic-gate 			if (rot < 0 || rot > 1000)
2277c478bd9Sstevel@tonic-gate 				fatal(gettext(
2287c478bd9Sstevel@tonic-gate 				    "%s: bad rotational delay"), optarg);
2297c478bd9Sstevel@tonic-gate 			break;
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 		case 't':
2327c478bd9Sstevel@tonic-gate 			ntracks = number("ntrack", optarg, NR_NONE, 16);
2337c478bd9Sstevel@tonic-gate 			ntracks_set = 1;
2347c478bd9Sstevel@tonic-gate 			if ((ntracks < 0) ||
2357c478bd9Sstevel@tonic-gate 			    (ntracks > INT_MAX))
2367c478bd9Sstevel@tonic-gate 				fatal(gettext("%s: bad total tracks"), optarg);
2377c478bd9Sstevel@tonic-gate 			break;
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 		case 'o':
2407c478bd9Sstevel@tonic-gate 			if (strcmp(optarg, "space") == 0)
241d50c8f90Svsakar 				optim = FS_OPTSPACE;
2427c478bd9Sstevel@tonic-gate 			else if (strcmp(optarg, "time") == 0)
243d50c8f90Svsakar 				optim = FS_OPTTIME;
2447c478bd9Sstevel@tonic-gate 			else
245d50c8f90Svsakar 				fatal(gettext(
246d50c8f90Svsakar "%s: bad optimization preference (options are `space' or `time')"), optarg);
2477c478bd9Sstevel@tonic-gate 			break;
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 		case 'a':
2507c478bd9Sstevel@tonic-gate 			apc = number("apc", optarg, NR_NONE, 0);
2517c478bd9Sstevel@tonic-gate 			apc_set = 1;
2527c478bd9Sstevel@tonic-gate 			if (apc < 0 || apc > 32768) /* see mkfs.c */
2537c478bd9Sstevel@tonic-gate 				fatal(gettext(
2547c478bd9Sstevel@tonic-gate 				    "%s: bad alternates per cyl"), optarg);
2557c478bd9Sstevel@tonic-gate 			break;
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 		case 'b':
2587c478bd9Sstevel@tonic-gate 			bsize = number("bsize", optarg, NR_NONE, DESBLKSIZE);
2597c478bd9Sstevel@tonic-gate 			if (bsize < MINBSIZE || bsize > MAXBSIZE)
2607c478bd9Sstevel@tonic-gate 				fatal(gettext(
2617c478bd9Sstevel@tonic-gate 				    "%s: bad block size"), optarg);
2627c478bd9Sstevel@tonic-gate 			break;
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 		case 'f':
2657c478bd9Sstevel@tonic-gate 			fsize = number("fragsize", optarg, NR_NONE,
266d50c8f90Svsakar 			    DESFRAGSIZE);
2677c478bd9Sstevel@tonic-gate 			fsize_flag++;
2687c478bd9Sstevel@tonic-gate 			/* xxx ought to test against bsize for upper limit */
2697c478bd9Sstevel@tonic-gate 			if (fsize < DEV_BSIZE)
2707c478bd9Sstevel@tonic-gate 				fatal(gettext("%s: bad frag size"), optarg);
2717c478bd9Sstevel@tonic-gate 			break;
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 		case 'c':
2747c478bd9Sstevel@tonic-gate 			cpg = number("cpg", optarg, NR_NONE, 16);
2757c478bd9Sstevel@tonic-gate 			cpg_set = 1;
2767c478bd9Sstevel@tonic-gate 			if (cpg < 1)
2777c478bd9Sstevel@tonic-gate 				fatal(gettext("%s: bad cylinders/group"),
2787c478bd9Sstevel@tonic-gate 				    optarg);
2797c478bd9Sstevel@tonic-gate 			break;
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 		case 'm':
2827c478bd9Sstevel@tonic-gate 			minfree = number("minfree", optarg, NR_PERCENT, 10);
2837c478bd9Sstevel@tonic-gate 			if (minfree < 0 || minfree > 99)
2847c478bd9Sstevel@tonic-gate 				fatal(gettext("%s: bad free space %%"), optarg);
2857c478bd9Sstevel@tonic-gate 			break;
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 		case 'n':
2887c478bd9Sstevel@tonic-gate 			nrpos = number("nrpos", optarg, NR_NONE, 8);
2897c478bd9Sstevel@tonic-gate 			nrpos_set = 1;
2907c478bd9Sstevel@tonic-gate 			if (nrpos <= 0)
2917c478bd9Sstevel@tonic-gate 				fatal(gettext(
2927c478bd9Sstevel@tonic-gate 				    "%s: bad number of rotational positions"),
2937c478bd9Sstevel@tonic-gate 				    optarg);
2947c478bd9Sstevel@tonic-gate 			break;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 		case 'r':
2977c478bd9Sstevel@tonic-gate 			rpm = number("rpm", optarg, NR_NONE, 3600);
2987c478bd9Sstevel@tonic-gate 			rpm_set = 1;
2997c478bd9Sstevel@tonic-gate 			if (rpm < 0)
3007c478bd9Sstevel@tonic-gate 				fatal(gettext("%s: bad revs/minute"), optarg);
3017c478bd9Sstevel@tonic-gate 			break;
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 		case 'i':
3047c478bd9Sstevel@tonic-gate 			/* xxx ought to test against fsize */
3057c478bd9Sstevel@tonic-gate 			density = number("nbpi", optarg, NR_NONE, 2048);
3067c478bd9Sstevel@tonic-gate 			if (density < DEV_BSIZE)
3077c478bd9Sstevel@tonic-gate 				fatal(gettext("%s: bad bytes per inode"),
3087c478bd9Sstevel@tonic-gate 				    optarg);
3097c478bd9Sstevel@tonic-gate 			break;
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 		case 'T':
3127c478bd9Sstevel@tonic-gate 			Tflag++;
3137c478bd9Sstevel@tonic-gate 			break;
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate 		default:
3167c478bd9Sstevel@tonic-gate 			usage();
3177c478bd9Sstevel@tonic-gate 			fatal(gettext("-%c: unknown flag"), optopt);
3187c478bd9Sstevel@tonic-gate 		}
3197c478bd9Sstevel@tonic-gate 	}
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	/* At this point, there should only be one argument left:	*/
3227c478bd9Sstevel@tonic-gate 	/* The raw-special-device itself. If not, print usage message.	*/
3237c478bd9Sstevel@tonic-gate 	if ((argc - optind) != 1) {
3247c478bd9Sstevel@tonic-gate 		usage();
3257c478bd9Sstevel@tonic-gate 		exit(1);
3267c478bd9Sstevel@tonic-gate 	}
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 	name = argv[optind];
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	special = getfullrawname(name);
3317c478bd9Sstevel@tonic-gate 	if (special == NULL) {
3327c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("newfs: malloc failed\n"));
3337c478bd9Sstevel@tonic-gate 		exit(1);
3347c478bd9Sstevel@tonic-gate 	}
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 	if (*special == '\0') {
3377c478bd9Sstevel@tonic-gate 		if (strchr(name, '/') != NULL) {
3387c478bd9Sstevel@tonic-gate 			if (stat64(name, &st) < 0) {
3397c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
3407c478bd9Sstevel@tonic-gate 				    gettext("newfs: %s: %s\n"),
3417c478bd9Sstevel@tonic-gate 				    name, strerror(errno));
3427c478bd9Sstevel@tonic-gate 				exit(2);
3437c478bd9Sstevel@tonic-gate 			}
3447c478bd9Sstevel@tonic-gate 			fatal(gettext("%s: not a raw disk device"), name);
3457c478bd9Sstevel@tonic-gate 		}
346db60a39dSvk 		(void) snprintf(device, sizeof (device), "/dev/rdsk/%s", name);
3477c478bd9Sstevel@tonic-gate 		if ((special = getfullrawname(device)) == NULL) {
3487c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
3497c478bd9Sstevel@tonic-gate 			    gettext("newfs: malloc failed\n"));
3507c478bd9Sstevel@tonic-gate 			exit(1);
3517c478bd9Sstevel@tonic-gate 		}
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 		if (*special == '\0') {
354db60a39dSvk 			(void) snprintf(device, sizeof (device), "/dev/%s",
355db60a39dSvk 			    name);
3567c478bd9Sstevel@tonic-gate 			if ((special = getfullrawname(device)) == NULL) {
3577c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
3587c478bd9Sstevel@tonic-gate 				    gettext("newfs: malloc failed\n"));
3597c478bd9Sstevel@tonic-gate 				exit(1);
3607c478bd9Sstevel@tonic-gate 			}
3617c478bd9Sstevel@tonic-gate 			if (*special == '\0')
3627c478bd9Sstevel@tonic-gate 				fatal(gettext(
3637c478bd9Sstevel@tonic-gate 				    "%s: not a raw disk device"), name);
3647c478bd9Sstevel@tonic-gate 		}
3657c478bd9Sstevel@tonic-gate 	}
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	/*
3687c478bd9Sstevel@tonic-gate 	 * getdiskbydev() determines the characteristics of the special
3697c478bd9Sstevel@tonic-gate 	 * device on which the file system will be built.  In the case
3707c478bd9Sstevel@tonic-gate 	 * of devices with SMI labels (that is, non-EFI labels), the
3717c478bd9Sstevel@tonic-gate 	 * following characteristics are set (if they were not already
3727c478bd9Sstevel@tonic-gate 	 * set on the command line, since the command line settings
3737c478bd9Sstevel@tonic-gate 	 * take precedence):
3747c478bd9Sstevel@tonic-gate 	 *
3757c478bd9Sstevel@tonic-gate 	 *	nsectors - sectors per track
3767c478bd9Sstevel@tonic-gate 	 *	ntracks - tracks per cylinder
3777c478bd9Sstevel@tonic-gate 	 *	rpm - disk revolutions per minute
3787c478bd9Sstevel@tonic-gate 	 *
3797c478bd9Sstevel@tonic-gate 	 *	apc is NOT set
3807c478bd9Sstevel@tonic-gate 	 *
3817c478bd9Sstevel@tonic-gate 	 * getdiskbydev() also sets the following quantities for all
3827c478bd9Sstevel@tonic-gate 	 * devices, if not already set:
3837c478bd9Sstevel@tonic-gate 	 *
3847c478bd9Sstevel@tonic-gate 	 *	bsize - file system block size
3857c478bd9Sstevel@tonic-gate 	 *	maxcontig
3867c478bd9Sstevel@tonic-gate 	 *	label_type (efi, vtoc, or other)
3877c478bd9Sstevel@tonic-gate 	 *
3887c478bd9Sstevel@tonic-gate 	 * getdiskbydev() returns the actual size of the device, in
3897c478bd9Sstevel@tonic-gate 	 * sectors.
3907c478bd9Sstevel@tonic-gate 	 */
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 	actual_fssize = getdiskbydev(special);
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate 	if (req_fssize == 0) {
3957c478bd9Sstevel@tonic-gate 		fssize = actual_fssize;
3967c478bd9Sstevel@tonic-gate 	} else {
3977c478bd9Sstevel@tonic-gate 		/*
3987c478bd9Sstevel@tonic-gate 		 * If the user specified a size larger than what we've
3997c478bd9Sstevel@tonic-gate 		 * determined as the actual size of the device, see if the
4007c478bd9Sstevel@tonic-gate 		 * size specified by the user can be read.  If so, use it,
4017c478bd9Sstevel@tonic-gate 		 * since some devices and volume managers may not support
4027c478bd9Sstevel@tonic-gate 		 * the vtoc and EFI interfaces we use to determine device
4037c478bd9Sstevel@tonic-gate 		 * size.
4047c478bd9Sstevel@tonic-gate 		 */
4057c478bd9Sstevel@tonic-gate 		if (req_fssize > actual_fssize &&
4067c478bd9Sstevel@tonic-gate 		    validate_size(special, req_fssize)) {
4077c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
4087c478bd9Sstevel@tonic-gate "Warning: the requested size of this file system\n"
4097c478bd9Sstevel@tonic-gate "(%lld sectors) is greater than the size of the\n"
4107c478bd9Sstevel@tonic-gate "device reported by the driver (%lld sectors).\n"
4117c478bd9Sstevel@tonic-gate "However, a read of the device at the requested size\n"
4127c478bd9Sstevel@tonic-gate "does succeed, so the requested size will be used.\n"),
4137c478bd9Sstevel@tonic-gate 			    req_fssize, actual_fssize);
4147c478bd9Sstevel@tonic-gate 			fssize = req_fssize;
4157c478bd9Sstevel@tonic-gate 		} else {
4167c478bd9Sstevel@tonic-gate 			fssize = MIN(req_fssize, actual_fssize);
4177c478bd9Sstevel@tonic-gate 		}
4187c478bd9Sstevel@tonic-gate 	}
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate 	if (label_type == LABEL_TYPE_VTOC) {
4216d24e334Svsakar 		if (nsectors < 0)
4226d24e334Svsakar 			fatal(gettext("%s: no default #sectors/track"),
4236d24e334Svsakar 			    special);
4246451fdbcSvsakar 		if (!use_efi_dflts) {
4256451fdbcSvsakar 			if (ntracks < 0)
4266451fdbcSvsakar 				fatal(gettext("%s: no default #tracks"),
4276451fdbcSvsakar 				    special);
4286451fdbcSvsakar 		}
4297c478bd9Sstevel@tonic-gate 		if (rpm < 0)
4307c478bd9Sstevel@tonic-gate 			fatal(gettext(
4317c478bd9Sstevel@tonic-gate 			    "%s: no default revolutions/minute value"),
4327c478bd9Sstevel@tonic-gate 			    special);
4337c478bd9Sstevel@tonic-gate 		if (rpm < 60) {
4347c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
4357c478bd9Sstevel@tonic-gate 			    gettext("Warning: setting rpm to 60\n"));
4367c478bd9Sstevel@tonic-gate 			rpm = 60;
4377c478bd9Sstevel@tonic-gate 		}
4387c478bd9Sstevel@tonic-gate 	}
4397c478bd9Sstevel@tonic-gate 	if (label_type == LABEL_TYPE_EFI || label_type == LABEL_TYPE_OTHER) {
4407c478bd9Sstevel@tonic-gate 		if (ntracks_set)
4417c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
4427c478bd9Sstevel@tonic-gate "Warning: ntracks is obsolete for this device and will be ignored.\n"));
4437c478bd9Sstevel@tonic-gate 		if (cpg_set)
4447c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
4457c478bd9Sstevel@tonic-gate "Warning: cylinders/group is obsolete for this device and will be ignored.\n"));
4467c478bd9Sstevel@tonic-gate 		if (rpm_set)
4477c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
4487c478bd9Sstevel@tonic-gate "Warning: rpm is obsolete for this device and will be ignored.\n"));
4497c478bd9Sstevel@tonic-gate 		if (rot_set)
4507c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
4517c478bd9Sstevel@tonic-gate "Warning: rotational delay is obsolete for this device and"
4527c478bd9Sstevel@tonic-gate " will be ignored.\n"));
4537c478bd9Sstevel@tonic-gate 		if (nrpos_set)
4547c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
4557c478bd9Sstevel@tonic-gate "Warning: number of rotational positions is obsolete for this device and\n"
4567c478bd9Sstevel@tonic-gate "will be ignored.\n"));
4577c478bd9Sstevel@tonic-gate 		if (apc_set)
4587c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
4597c478bd9Sstevel@tonic-gate "Warning: number of alternate sectors per cylinder is obsolete for this\n"
4607c478bd9Sstevel@tonic-gate "device and will be ignored.\n"));
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 		/*
4637c478bd9Sstevel@tonic-gate 		 * We need these for the call to mkfs, even though they are
4647c478bd9Sstevel@tonic-gate 		 * meaningless.
4657c478bd9Sstevel@tonic-gate 		 */
4667c478bd9Sstevel@tonic-gate 		rpm = 60;
4677c478bd9Sstevel@tonic-gate 		nrpos = 1;
4687c478bd9Sstevel@tonic-gate 		apc = 0;
4697c478bd9Sstevel@tonic-gate 		rot = -1;
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate 		/*
4727c478bd9Sstevel@tonic-gate 		 * These values are set to produce a file system with
4737c478bd9Sstevel@tonic-gate 		 * a cylinder group size of 48MB.   For disks with
4747c478bd9Sstevel@tonic-gate 		 * non-EFI labels, most geometries result in cylinder
4757c478bd9Sstevel@tonic-gate 		 * groups of around 40 - 50 MB, so we arbitrarily choose
4767c478bd9Sstevel@tonic-gate 		 * 48MB for disks with EFI labels.  mkfs will reduce
4777c478bd9Sstevel@tonic-gate 		 * cylinders per group even further if necessary.
4787c478bd9Sstevel@tonic-gate 		 */
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate 		cpg = 16;
4817c478bd9Sstevel@tonic-gate 		nsectors = 128;
4827c478bd9Sstevel@tonic-gate 		ntracks = 48;
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate 		/*
4857c478bd9Sstevel@tonic-gate 		 * mkfs produces peculiar results for file systems
4867c478bd9Sstevel@tonic-gate 		 * that are smaller than one cylinder so don't allow
4877c478bd9Sstevel@tonic-gate 		 * them to be created (this check is only made for
4887c478bd9Sstevel@tonic-gate 		 * disks with EFI labels.  Eventually, it should probably
4897c478bd9Sstevel@tonic-gate 		 * be enforced for all disks.)
4907c478bd9Sstevel@tonic-gate 		 */
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate 		if (fssize < nsectors * ntracks) {
4937c478bd9Sstevel@tonic-gate 			fatal(gettext(
4947c478bd9Sstevel@tonic-gate 			    "file system size must be at least %d sectors"),
4957c478bd9Sstevel@tonic-gate 			    nsectors * ntracks);
4967c478bd9Sstevel@tonic-gate 		}
4977c478bd9Sstevel@tonic-gate 	}
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate 	if (fssize > INT_MAX)
5007c478bd9Sstevel@tonic-gate 		Tflag = 1;
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 	/*
5037c478bd9Sstevel@tonic-gate 	 * If the user requested that the file system be set up for
5047c478bd9Sstevel@tonic-gate 	 * eventual growth to over a terabyte, or if it's already greater
5057c478bd9Sstevel@tonic-gate 	 * than a terabyte, set the inode density (nbpi) to MIN_MTB_DENSITY
5067c478bd9Sstevel@tonic-gate 	 * (unless the user has specified a larger nbpi), set the frag size
5077c478bd9Sstevel@tonic-gate 	 * equal to the block size, and set the cylinders-per-group value
5087c478bd9Sstevel@tonic-gate 	 * passed to mkfs to -1, which tells mkfs to make cylinder groups
5097c478bd9Sstevel@tonic-gate 	 * as large as possible.
5107c478bd9Sstevel@tonic-gate 	 */
5117c478bd9Sstevel@tonic-gate 	if (Tflag) {
5127c478bd9Sstevel@tonic-gate 		if (density < MIN_MTB_DENSITY)
5137c478bd9Sstevel@tonic-gate 			density = MIN_MTB_DENSITY;
5147c478bd9Sstevel@tonic-gate 		fsize = bsize;
5157c478bd9Sstevel@tonic-gate 		cpg = -1; 	/* says make cyl groups as big as possible */
5167c478bd9Sstevel@tonic-gate 	} else {
5177c478bd9Sstevel@tonic-gate 		if (fsize == 0)
5187c478bd9Sstevel@tonic-gate 			fsize = DESFRAGSIZE;
5197c478bd9Sstevel@tonic-gate 	}
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate 	if (!POWEROF2(fsize)) {
5227c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
5237c478bd9Sstevel@tonic-gate 		    "newfs: fragment size must a power of 2, not %d\n"), fsize);
5247c478bd9Sstevel@tonic-gate 		fsize = bsize/8;
5257c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
5267c478bd9Sstevel@tonic-gate 		    "newfs: fragsize reset to %ld\n"), fsize);
5277c478bd9Sstevel@tonic-gate 	}
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 	/*
5307c478bd9Sstevel@tonic-gate 	 * The file system is limited in size by the fragment size.
5317c478bd9Sstevel@tonic-gate 	 * The number of fragments in the file system must fit into
5327c478bd9Sstevel@tonic-gate 	 * a signed 32-bit quantity, so the number of sectors in the
5337c478bd9Sstevel@tonic-gate 	 * file system is INT_MAX * the number of sectors in a frag.
5347c478bd9Sstevel@tonic-gate 	 */
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 	max_possible_fssize = ((uint64_t)fsize)/DEV_BSIZE * INT_MAX;
5377c478bd9Sstevel@tonic-gate 	if (fssize > max_possible_fssize)
5387c478bd9Sstevel@tonic-gate 		fssize = max_possible_fssize;
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 	/*
5417c478bd9Sstevel@tonic-gate 	 * Now fssize is the final size of the file system (in sectors).
5427c478bd9Sstevel@tonic-gate 	 * If it's less than what the user requested, print a message.
5437c478bd9Sstevel@tonic-gate 	 */
5447c478bd9Sstevel@tonic-gate 	if (fssize < req_fssize) {
5457c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
5467c478bd9Sstevel@tonic-gate 		    "newfs: requested size of %s disk blocks is too large.\n"),
5477c478bd9Sstevel@tonic-gate 		    req_fssize_str);
5487c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
5497c478bd9Sstevel@tonic-gate 		    "newfs: Resetting size to %lld\n"), fssize);
5507c478bd9Sstevel@tonic-gate 	}
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 	/*
5537c478bd9Sstevel@tonic-gate 	 * fssize now equals the size (in sectors) of the file system
5547c478bd9Sstevel@tonic-gate 	 * that will be created.
5557c478bd9Sstevel@tonic-gate 	 */
5567c478bd9Sstevel@tonic-gate 
5577c478bd9Sstevel@tonic-gate 	/* XXX - following defaults are both here and in mkfs */
5587c478bd9Sstevel@tonic-gate 	if (density <= 0) {
5597c478bd9Sstevel@tonic-gate 		if (fssize < GBSEC)
5607c478bd9Sstevel@tonic-gate 			density = MINDENSITY;
5617c478bd9Sstevel@tonic-gate 		else
5627c478bd9Sstevel@tonic-gate 			density = (int)((((longlong_t)fssize + (GBSEC - 1)) /
563d50c8f90Svsakar 			    GBSEC) * MINDENSITY);
5647c478bd9Sstevel@tonic-gate 		if (density <= 0)
5657c478bd9Sstevel@tonic-gate 			density = MINDENSITY;
5667c478bd9Sstevel@tonic-gate 		if (density > MAXDEFDENSITY)
5677c478bd9Sstevel@tonic-gate 			density = MAXDEFDENSITY;
5687c478bd9Sstevel@tonic-gate 	}
5697c478bd9Sstevel@tonic-gate 	if (cpg == 0) {
5707c478bd9Sstevel@tonic-gate 		/*
5717c478bd9Sstevel@tonic-gate 		 * maxcpg calculation adapted from mkfs
5727c478bd9Sstevel@tonic-gate 		 * In the case of disks with EFI labels, cpg has
5737c478bd9Sstevel@tonic-gate 		 * already been set, so we won't enter this code.
5747c478bd9Sstevel@tonic-gate 		 */
5757c478bd9Sstevel@tonic-gate 		long maxcpg, maxipg;
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 		maxipg = roundup(bsize * NBBY / 3,
5787c478bd9Sstevel@tonic-gate 		    bsize / sizeof (struct inode));
5797c478bd9Sstevel@tonic-gate 		maxcpg = (bsize - sizeof (struct cg) - howmany(maxipg, NBBY)) /
5807c478bd9Sstevel@tonic-gate 		    (sizeof (long) + nrpos * sizeof (short) +
581d50c8f90Svsakar 		    nsectors / (MAXFRAG * NBBY));
5827c478bd9Sstevel@tonic-gate 		cpg = (fssize / GBSEC) * 32;
5837c478bd9Sstevel@tonic-gate 		if (cpg > maxcpg)
5847c478bd9Sstevel@tonic-gate 			cpg = maxcpg;
5857c478bd9Sstevel@tonic-gate 		if (cpg <= 0)
5867c478bd9Sstevel@tonic-gate 			cpg = MINCPG;
5877c478bd9Sstevel@tonic-gate 	}
5887c478bd9Sstevel@tonic-gate 	if (minfree < 0) {
589db60a39dSvk 		minfree = (int)(((float)MINFREESEC / fssize) * 100);
5907c478bd9Sstevel@tonic-gate 		if (minfree > 10)
5917c478bd9Sstevel@tonic-gate 			minfree = 10;
5927c478bd9Sstevel@tonic-gate 		if (minfree <= 0)
5937c478bd9Sstevel@tonic-gate 			minfree = 1;
5947c478bd9Sstevel@tonic-gate 	}
5957c478bd9Sstevel@tonic-gate #ifdef i386	/* Bug 1170182 */
5967c478bd9Sstevel@tonic-gate 	if (ntracks > 32 && (ntracks % 16) != 0) {
5977c478bd9Sstevel@tonic-gate 		ntracks -= (ntracks % 16);
5987c478bd9Sstevel@tonic-gate 	}
5997c478bd9Sstevel@tonic-gate #endif
6007c478bd9Sstevel@tonic-gate 	/*
6017c478bd9Sstevel@tonic-gate 	 * Confirmation
6027c478bd9Sstevel@tonic-gate 	 */
6037c478bd9Sstevel@tonic-gate 	if (isatty(fileno(stdin)) && !Nflag) {
6047c478bd9Sstevel@tonic-gate 		/*
6057c478bd9Sstevel@tonic-gate 		 * If we can read a valid superblock, report the mount
6067c478bd9Sstevel@tonic-gate 		 * point on which this filesystem was last mounted.
6077c478bd9Sstevel@tonic-gate 		 */
6087c478bd9Sstevel@tonic-gate 		if (((sbp = read_sb(special)) != 0) &&
6097c478bd9Sstevel@tonic-gate 		    (*sbp->fs_fsmnt != '\0')) {
6107c478bd9Sstevel@tonic-gate 			(void) printf(gettext(
6117c478bd9Sstevel@tonic-gate 			    "newfs: %s last mounted as %s\n"),
6127c478bd9Sstevel@tonic-gate 			    special, sbp->fs_fsmnt);
6137c478bd9Sstevel@tonic-gate 		}
6147c478bd9Sstevel@tonic-gate 		(void) printf(gettext(
6157c478bd9Sstevel@tonic-gate 		    "newfs: construct a new file system %s: (y/n)? "),
6167c478bd9Sstevel@tonic-gate 		    special);
6177c478bd9Sstevel@tonic-gate 		(void) fflush(stdout);
6187c478bd9Sstevel@tonic-gate 		if (!yes())
6197c478bd9Sstevel@tonic-gate 			exit(0);
6207c478bd9Sstevel@tonic-gate 	}
6214d594c33Svsakar 
6226451fdbcSvsakar 	dprintf(("DeBuG newfs : nsect=%d ntrak=%d cpg=%d\n",
623d50c8f90Svsakar 	    nsectors, ntracks, cpg));
6247c478bd9Sstevel@tonic-gate 	/*
6257c478bd9Sstevel@tonic-gate 	 * If alternates-per-cylinder is ever implemented:
6267c478bd9Sstevel@tonic-gate 	 * need to get apc from dp->d_apc if no -a switch???
6277c478bd9Sstevel@tonic-gate 	 */
628db60a39dSvk 	(void) snprintf(cmd, sizeof (cmd), "pfexec mkfs -F ufs "
629db60a39dSvk 	    "%s%s%s%s %lld %d %d %d %d %d %d %d %d %s %d %d %d %d %s",
630355d6bb5Sswilcox 	    Nflag ? "-o N " : "", binary_sb ? "-o calcbinsb " : "",
631355d6bb5Sswilcox 	    text_sb ? "-o calcsb " : "", special,
6327c478bd9Sstevel@tonic-gate 	    fssize, nsectors, ntracks, bsize, fsize, cpg, minfree, rpm/60,
6337c478bd9Sstevel@tonic-gate 	    density, optim == FS_OPTSPACE ? "s" : "t", apc, rot, nrpos,
6347c478bd9Sstevel@tonic-gate 	    maxcontig, Tflag ? "y" : "n");
6357c478bd9Sstevel@tonic-gate 	if (verbose) {
6367c478bd9Sstevel@tonic-gate 		(void) printf("%s\n", cmd);
6377c478bd9Sstevel@tonic-gate 		(void) fflush(stdout);
6387c478bd9Sstevel@tonic-gate 	}
6397c478bd9Sstevel@tonic-gate 	exenv();
6407c478bd9Sstevel@tonic-gate 	if (status = system(cmd))
6417c478bd9Sstevel@tonic-gate 		exit(status >> 8);
6427c478bd9Sstevel@tonic-gate 	if (Nflag)
6437c478bd9Sstevel@tonic-gate 		exit(0);
644db60a39dSvk 	(void) snprintf(cmd, sizeof (cmd), "/usr/sbin/fsirand %s", special);
6457c478bd9Sstevel@tonic-gate 	if (notrand(special) && (status = system(cmd)) != 0)
6467c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
6477c478bd9Sstevel@tonic-gate 		    gettext("%s: failed, status = %d\n"),
6487c478bd9Sstevel@tonic-gate 		    cmd, status);
6497c478bd9Sstevel@tonic-gate 	return (0);
6507c478bd9Sstevel@tonic-gate }
6517c478bd9Sstevel@tonic-gate 
6527c478bd9Sstevel@tonic-gate static void
6537c478bd9Sstevel@tonic-gate exenv(void)
6547c478bd9Sstevel@tonic-gate {
6557c478bd9Sstevel@tonic-gate 	char *epath;				/* executable file path */
6567c478bd9Sstevel@tonic-gate 	char *cpath;				/* current path */
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 	if ((cpath = getenv("PATH")) == NULL) {
6597c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("newfs: no PATH in env\n"));
6607c478bd9Sstevel@tonic-gate 		/*
6617c478bd9Sstevel@tonic-gate 		 * Background: the Bourne shell interpolates "." into
6627c478bd9Sstevel@tonic-gate 		 * the path where said path starts with a colon, ends
6637c478bd9Sstevel@tonic-gate 		 * with a colon, or has two adjacent colons.  Thus,
6647c478bd9Sstevel@tonic-gate 		 * the path ":/sbin::/usr/sbin:" is equivalent to
6657c478bd9Sstevel@tonic-gate 		 * ".:/sbin:.:/usr/sbin:.".  Now, we have no cpath,
6667c478bd9Sstevel@tonic-gate 		 * and epath ends in a colon (to make for easy
6677c478bd9Sstevel@tonic-gate 		 * catenation in the normal case).  By the above, if
6687c478bd9Sstevel@tonic-gate 		 * we use "", then "." becomes part of path.  That's
6697c478bd9Sstevel@tonic-gate 		 * bad, so use CPATH (which is just a duplicate of some
6707c478bd9Sstevel@tonic-gate 		 * element in EPATH).  No point in opening ourselves
6717c478bd9Sstevel@tonic-gate 		 * up to a Trojan horse attack when we don't have to....
6727c478bd9Sstevel@tonic-gate 		 */
6737c478bd9Sstevel@tonic-gate 		cpath = CPATH;
6747c478bd9Sstevel@tonic-gate 	}
6757c478bd9Sstevel@tonic-gate 	if ((epath = malloc(strlen(EPATH) + strlen(cpath) + 1)) == NULL) {
6767c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("newfs: malloc failed\n"));
6777c478bd9Sstevel@tonic-gate 		exit(1);
6787c478bd9Sstevel@tonic-gate 	}
6797c478bd9Sstevel@tonic-gate 	(void) strcpy(epath, EPATH);
6807c478bd9Sstevel@tonic-gate 	(void) strcat(epath, cpath);
6817c478bd9Sstevel@tonic-gate 	if (putenv(epath) < 0) {
6827c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("newfs: putenv failed\n"));
6837c478bd9Sstevel@tonic-gate 		exit(1);
6847c478bd9Sstevel@tonic-gate 	}
6857c478bd9Sstevel@tonic-gate }
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate static int
6887c478bd9Sstevel@tonic-gate yes(void)
6897c478bd9Sstevel@tonic-gate {
6907c478bd9Sstevel@tonic-gate 	int	i, b;
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate 	i = b = getchar();
6937c478bd9Sstevel@tonic-gate 	while (b != '\n' && b != '\0' && b != EOF)
6947c478bd9Sstevel@tonic-gate 		b = getchar();
6957c478bd9Sstevel@tonic-gate 	return (i == 'y');
6967c478bd9Sstevel@tonic-gate }
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate /*
6997c478bd9Sstevel@tonic-gate  * xxx Caller must run fmt through gettext(3) for us, if we ever
7007c478bd9Sstevel@tonic-gate  * xxx go the i18n route....
7017c478bd9Sstevel@tonic-gate  */
7027c478bd9Sstevel@tonic-gate static void
7037c478bd9Sstevel@tonic-gate fatal(char *fmt, ...)
7047c478bd9Sstevel@tonic-gate {
7057c478bd9Sstevel@tonic-gate 	va_list pvar;
7067c478bd9Sstevel@tonic-gate 
7077c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "newfs: ");
7087c478bd9Sstevel@tonic-gate 	va_start(pvar, fmt);
7097c478bd9Sstevel@tonic-gate 	(void) vfprintf(stderr, fmt, pvar);
7107c478bd9Sstevel@tonic-gate 	va_end(pvar);
7117c478bd9Sstevel@tonic-gate 	(void) putc('\n', stderr);
7127c478bd9Sstevel@tonic-gate 	exit(10);
7137c478bd9Sstevel@tonic-gate }
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate static diskaddr_t
7167c478bd9Sstevel@tonic-gate getdiskbydev(char *disk)
7177c478bd9Sstevel@tonic-gate {
7187c478bd9Sstevel@tonic-gate 	struct dk_geom g;
7197c478bd9Sstevel@tonic-gate 	struct dk_cinfo ci;
7207c478bd9Sstevel@tonic-gate 	diskaddr_t actual_size;
7217c478bd9Sstevel@tonic-gate 	int fd;
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate 	if ((fd = open64(disk, 0)) < 0) {
7247c478bd9Sstevel@tonic-gate 		perror(disk);
7257c478bd9Sstevel@tonic-gate 		exit(1);
7267c478bd9Sstevel@tonic-gate 	}
7277c478bd9Sstevel@tonic-gate 
7287c478bd9Sstevel@tonic-gate 	/*
7297c478bd9Sstevel@tonic-gate 	 * get_device_size() determines the actual size of the
7307c478bd9Sstevel@tonic-gate 	 * device, and also the disk's attributes, such as geometry.
7317c478bd9Sstevel@tonic-gate 	 */
7327c478bd9Sstevel@tonic-gate 	actual_size = get_device_size(fd, disk);
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate 	if (label_type == LABEL_TYPE_VTOC) {
735*8b7c2cdfSws 
7364d594c33Svsakar 		/*
737*8b7c2cdfSws 		 * Geometry information does not make sense for removable or
738*8b7c2cdfSws 		 * hotpluggable media anyway, so indicate mkfs to use EFI
739*8b7c2cdfSws 		 * default parameters.
7404d594c33Svsakar 		 */
7414d594c33Svsakar 		if (ioctl(fd, DKIOCREMOVABLE, &isremovable)) {
7424d594c33Svsakar 			dprintf(("DeBuG newfs : Unable to determine if %s is"
7434d594c33Svsakar 			    " Removable Media. Proceeding with system"
7444d594c33Svsakar 			    " determined parameters.\n", disk));
7454d594c33Svsakar 			isremovable = 0;
746*8b7c2cdfSws 		}
747*8b7c2cdfSws 
748*8b7c2cdfSws 		if (ioctl(fd, DKIOCHOTPLUGGABLE, &ishotpluggable)) {
749*8b7c2cdfSws 			dprintf(("DeBuG newfs : Unable to determine if %s is"
750*8b7c2cdfSws 			    " Hotpluggable Media. Proceeding with system"
751*8b7c2cdfSws 			    " determined parameters.\n", disk));
752*8b7c2cdfSws 			ishotpluggable = 0;
753*8b7c2cdfSws 		}
754*8b7c2cdfSws 
755*8b7c2cdfSws 		if ((isremovable || ishotpluggable) && !Tflag)
7564d594c33Svsakar 			use_efi_dflts = 1;
7574d594c33Svsakar 
7587c478bd9Sstevel@tonic-gate 		if (ioctl(fd, DKIOCGGEOM, &g))
7597c478bd9Sstevel@tonic-gate 			fatal(gettext(
7607c478bd9Sstevel@tonic-gate 			    "%s: Unable to read Disk geometry"), disk);
7616451fdbcSvsakar 		if (((g.dkg_ncyl * g.dkg_nhead * g.dkg_nsect) > CHSLIMIT) &&
7626451fdbcSvsakar 		    !Tflag) {
7636451fdbcSvsakar 			use_efi_dflts = 1;
7646451fdbcSvsakar 		}
7654d594c33Svsakar 		dprintf(("DeBuG newfs : geom=%ld, CHSLIMIT=%d "
766*8b7c2cdfSws 		    "isremovable = %d ishotpluggable = %d use_efi_dflts = %d\n",
7674d594c33Svsakar 		    g.dkg_ncyl * g.dkg_nhead * g.dkg_nsect, CHSLIMIT,
768*8b7c2cdfSws 		    isremovable, ishotpluggable, use_efi_dflts));
7696451fdbcSvsakar 		/*
7706d24e334Svsakar 		 * The ntracks that is passed to mkfs is decided here based
7716d24e334Svsakar 		 * on 'use_efi_dflts' and whether ntracks was specified as a
7726d24e334Svsakar 		 * command line parameter to newfs.
7736d24e334Svsakar 		 * If ntracks of -1 is passed to mkfs, mkfs uses DEF_TRACKS_EFI
7746d24e334Svsakar 		 * and DEF_SECTORS_EFI for ntracks and nsectors respectively.
7756451fdbcSvsakar 		 */
7767c478bd9Sstevel@tonic-gate 		if (nsectors == 0)
7776d24e334Svsakar 			nsectors = g.dkg_nsect;
7787c478bd9Sstevel@tonic-gate 		if (ntracks == 0)
7796451fdbcSvsakar 			ntracks = use_efi_dflts ? -1 : g.dkg_nhead;
7807c478bd9Sstevel@tonic-gate 		if (rpm == 0)
7817c478bd9Sstevel@tonic-gate 			rpm = ((int)g.dkg_rpm <= 0) ? 3600: g.dkg_rpm;
7827c478bd9Sstevel@tonic-gate 	}
7837c478bd9Sstevel@tonic-gate 
7847c478bd9Sstevel@tonic-gate 	if (bsize == 0)
7857c478bd9Sstevel@tonic-gate 		bsize = DESBLKSIZE;
7867c478bd9Sstevel@tonic-gate 	/*
7877c478bd9Sstevel@tonic-gate 	 * Adjust maxcontig by the device's maxtransfer. If maxtransfer
7887c478bd9Sstevel@tonic-gate 	 * information is not available, default to the min of a MB and
7897c478bd9Sstevel@tonic-gate 	 * maxphys.
7907c478bd9Sstevel@tonic-gate 	 */
7917c478bd9Sstevel@tonic-gate 	if (maxcontig == -1 && ioctl(fd, DKIOCINFO, &ci) == 0) {
7927c478bd9Sstevel@tonic-gate 		maxcontig = ci.dki_maxtransfer * DEV_BSIZE;
7937c478bd9Sstevel@tonic-gate 		if (maxcontig < 0) {
7947c478bd9Sstevel@tonic-gate 			int	error, gotit, maxphys;
7957c478bd9Sstevel@tonic-gate 			gotit = fsgetmaxphys(&maxphys, &error);
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate 			/*
7987c478bd9Sstevel@tonic-gate 			 * If we cannot get the maxphys value, default
7997c478bd9Sstevel@tonic-gate 			 * to ufs_maxmaxphys (MB).
8007c478bd9Sstevel@tonic-gate 			 */
8017c478bd9Sstevel@tonic-gate 			if (gotit) {
8027c478bd9Sstevel@tonic-gate 				maxcontig = MIN(maxphys, MB);
8037c478bd9Sstevel@tonic-gate 			} else {
8047c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
8057c478bd9Sstevel@tonic-gate "Warning: Could not get system value for maxphys. The value for maxcontig\n"
8067c478bd9Sstevel@tonic-gate "will default to 1MB.\n"));
8077c478bd9Sstevel@tonic-gate 			maxcontig = MB;
8087c478bd9Sstevel@tonic-gate 			}
8097c478bd9Sstevel@tonic-gate 		}
8107c478bd9Sstevel@tonic-gate 		maxcontig /= bsize;
8117c478bd9Sstevel@tonic-gate 	}
8127c478bd9Sstevel@tonic-gate 	(void) close(fd);
8137c478bd9Sstevel@tonic-gate 	return (actual_size);
8147c478bd9Sstevel@tonic-gate }
8157c478bd9Sstevel@tonic-gate 
8167c478bd9Sstevel@tonic-gate /*
8177c478bd9Sstevel@tonic-gate  * Figure out how big the partition we're dealing with is.
8187c478bd9Sstevel@tonic-gate  */
8197c478bd9Sstevel@tonic-gate static diskaddr_t
8207c478bd9Sstevel@tonic-gate get_device_size(int fd, char *name)
8217c478bd9Sstevel@tonic-gate {
8227c478bd9Sstevel@tonic-gate 	struct vtoc vtoc;
8237c478bd9Sstevel@tonic-gate 	dk_gpt_t *efi_vtoc;
8247c478bd9Sstevel@tonic-gate 	diskaddr_t	slicesize;
8257c478bd9Sstevel@tonic-gate 
8267c478bd9Sstevel@tonic-gate 	int index = read_vtoc(fd, &vtoc);
8277c478bd9Sstevel@tonic-gate 
8287c478bd9Sstevel@tonic-gate 	if (index >= 0) {
8297c478bd9Sstevel@tonic-gate 		label_type = LABEL_TYPE_VTOC;
8307c478bd9Sstevel@tonic-gate 	} else {
8317c478bd9Sstevel@tonic-gate 		if (index == VT_ENOTSUP || index == VT_ERROR) {
8327c478bd9Sstevel@tonic-gate 			/* it might be an EFI label */
8337c478bd9Sstevel@tonic-gate 			index = efi_alloc_and_read(fd, &efi_vtoc);
8347c478bd9Sstevel@tonic-gate 			if (index >= 0)
8357c478bd9Sstevel@tonic-gate 				label_type = LABEL_TYPE_EFI;
8367c478bd9Sstevel@tonic-gate 		}
8377c478bd9Sstevel@tonic-gate 	}
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate 	if (index < 0) {
8407c478bd9Sstevel@tonic-gate 		/*
8417c478bd9Sstevel@tonic-gate 		 * Since both attempts to read the label failed, we're
8427c478bd9Sstevel@tonic-gate 		 * going to fall back to a brute force approach to
8437c478bd9Sstevel@tonic-gate 		 * determining the device's size:  see how far out we can
8447c478bd9Sstevel@tonic-gate 		 * perform reads on the device.
8457c478bd9Sstevel@tonic-gate 		 */
8467c478bd9Sstevel@tonic-gate 
8477c478bd9Sstevel@tonic-gate 		slicesize = brute_force_get_device_size(fd);
8487c478bd9Sstevel@tonic-gate 		if (slicesize == 0) {
8497c478bd9Sstevel@tonic-gate 			switch (index) {
8507c478bd9Sstevel@tonic-gate 			case VT_ERROR:
8517c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
8527c478bd9Sstevel@tonic-gate 				    "newfs: %s: %s\n"), name, strerror(errno));
8537c478bd9Sstevel@tonic-gate 				exit(10);
8547c478bd9Sstevel@tonic-gate 				/*NOTREACHED*/
8557c478bd9Sstevel@tonic-gate 			case VT_EIO:
8567c478bd9Sstevel@tonic-gate 				fatal(gettext(
8577c478bd9Sstevel@tonic-gate 				    "%s: I/O error accessing VTOC"), name);
8587c478bd9Sstevel@tonic-gate 				/*NOTREACHED*/
8597c478bd9Sstevel@tonic-gate 			case VT_EINVAL:
8607c478bd9Sstevel@tonic-gate 				fatal(gettext(
8617c478bd9Sstevel@tonic-gate 				    "%s: Invalid field in VTOC"), name);
8627c478bd9Sstevel@tonic-gate 				/*NOTREACHED*/
8637c478bd9Sstevel@tonic-gate 			default:
8647c478bd9Sstevel@tonic-gate 				fatal(gettext(
8657c478bd9Sstevel@tonic-gate 				    "%s: unknown error accessing VTOC"),
8667c478bd9Sstevel@tonic-gate 				    name);
8677c478bd9Sstevel@tonic-gate 				/*NOTREACHED*/
8687c478bd9Sstevel@tonic-gate 			}
8697c478bd9Sstevel@tonic-gate 		} else {
8707c478bd9Sstevel@tonic-gate 			label_type = LABEL_TYPE_OTHER;
8717c478bd9Sstevel@tonic-gate 		}
8727c478bd9Sstevel@tonic-gate 	}
8737c478bd9Sstevel@tonic-gate 
8747c478bd9Sstevel@tonic-gate 	if (label_type == LABEL_TYPE_EFI) {
8757c478bd9Sstevel@tonic-gate 		slicesize = efi_vtoc->efi_parts[index].p_size;
8767c478bd9Sstevel@tonic-gate 		efi_free(efi_vtoc);
8777c478bd9Sstevel@tonic-gate 	} else if (label_type == LABEL_TYPE_VTOC) {
8787c478bd9Sstevel@tonic-gate 		/*
8797c478bd9Sstevel@tonic-gate 		 * In the vtoc struct, p_size is a 32-bit signed quantity.
8807c478bd9Sstevel@tonic-gate 		 * In the dk_gpt struct (efi's version of the vtoc), p_size
8817c478bd9Sstevel@tonic-gate 		 * is an unsigned 64-bit quantity.  By casting the vtoc's
8827c478bd9Sstevel@tonic-gate 		 * psize to an unsigned 32-bit quantity, it will be copied
8837c478bd9Sstevel@tonic-gate 		 * to 'slicesize' (an unsigned 64-bit diskaddr_t) without
8847c478bd9Sstevel@tonic-gate 		 * sign extension.
8857c478bd9Sstevel@tonic-gate 		 */
8867c478bd9Sstevel@tonic-gate 
8877c478bd9Sstevel@tonic-gate 		slicesize = (uint32_t)vtoc.v_part[index].p_size;
8887c478bd9Sstevel@tonic-gate 	}
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate 	return (slicesize);
8917c478bd9Sstevel@tonic-gate }
8927c478bd9Sstevel@tonic-gate 
8937c478bd9Sstevel@tonic-gate /*
8947c478bd9Sstevel@tonic-gate  * brute_force_get_device_size
8957c478bd9Sstevel@tonic-gate  *
8967c478bd9Sstevel@tonic-gate  * Determine the size of the device by seeing how far we can
8977c478bd9Sstevel@tonic-gate  * read.  Doing an llseek( , , SEEK_END) would probably work
8987c478bd9Sstevel@tonic-gate  * in most cases, but we've seen at least one third-party driver
8997c478bd9Sstevel@tonic-gate  * which doesn't correctly support the SEEK_END option when the
9007c478bd9Sstevel@tonic-gate  * the device is greater than a terabyte.
9017c478bd9Sstevel@tonic-gate  */
9027c478bd9Sstevel@tonic-gate 
9037c478bd9Sstevel@tonic-gate static diskaddr_t
9047c478bd9Sstevel@tonic-gate brute_force_get_device_size(int fd)
9057c478bd9Sstevel@tonic-gate {
9067c478bd9Sstevel@tonic-gate 	diskaddr_t	min_fail = 0;
9077c478bd9Sstevel@tonic-gate 	diskaddr_t	max_succeed = 0;
9087c478bd9Sstevel@tonic-gate 	diskaddr_t	cur_db_off;
9097c478bd9Sstevel@tonic-gate 	char 		buf[DEV_BSIZE];
9107c478bd9Sstevel@tonic-gate 
9117c478bd9Sstevel@tonic-gate 	/*
9127c478bd9Sstevel@tonic-gate 	 * First, see if we can read the device at all, just to
9137c478bd9Sstevel@tonic-gate 	 * eliminate errors that have nothing to do with the
9147c478bd9Sstevel@tonic-gate 	 * device's size.
9157c478bd9Sstevel@tonic-gate 	 */
9167c478bd9Sstevel@tonic-gate 
9177c478bd9Sstevel@tonic-gate 	if (((llseek(fd, (offset_t)0, SEEK_SET)) == -1) ||
9187c478bd9Sstevel@tonic-gate 	    ((read(fd, buf, DEV_BSIZE)) == -1))
9197c478bd9Sstevel@tonic-gate 		return (0);  /* can't determine size */
9207c478bd9Sstevel@tonic-gate 
9217c478bd9Sstevel@tonic-gate 	/*
9227c478bd9Sstevel@tonic-gate 	 * Now, go sequentially through the multiples of 4TB
9237c478bd9Sstevel@tonic-gate 	 * to find the first read that fails (this isn't strictly
9247c478bd9Sstevel@tonic-gate 	 * the most efficient way to find the actual size if the
9257c478bd9Sstevel@tonic-gate 	 * size really could be anything between 0 and 2**64 bytes.
9267c478bd9Sstevel@tonic-gate 	 * We expect the sizes to be less than 16 TB for some time,
9277c478bd9Sstevel@tonic-gate 	 * so why do a bunch of reads that are larger than that?
9287c478bd9Sstevel@tonic-gate 	 * However, this algorithm *will* work for sizes of greater
9297c478bd9Sstevel@tonic-gate 	 * than 16 TB.  We're just not optimizing for those sizes.)
9307c478bd9Sstevel@tonic-gate 	 */
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate 	for (cur_db_off = SECTORS_PER_TERABYTE * 4;
9337c478bd9Sstevel@tonic-gate 	    min_fail == 0 && cur_db_off < FS_SIZE_UPPER_LIMIT;
9347c478bd9Sstevel@tonic-gate 	    cur_db_off += 4 * SECTORS_PER_TERABYTE) {
9357c478bd9Sstevel@tonic-gate 		if (((llseek(fd, (offset_t)(cur_db_off * DEV_BSIZE),
9367c478bd9Sstevel@tonic-gate 		    SEEK_SET)) == -1) ||
9377c478bd9Sstevel@tonic-gate 		    ((read(fd, buf, DEV_BSIZE)) != DEV_BSIZE))
9387c478bd9Sstevel@tonic-gate 			min_fail = cur_db_off;
9397c478bd9Sstevel@tonic-gate 		else
9407c478bd9Sstevel@tonic-gate 			max_succeed = cur_db_off;
9417c478bd9Sstevel@tonic-gate 	}
9427c478bd9Sstevel@tonic-gate 
9437c478bd9Sstevel@tonic-gate 	if (min_fail == 0)
9447c478bd9Sstevel@tonic-gate 		return (0);
9457c478bd9Sstevel@tonic-gate 
9467c478bd9Sstevel@tonic-gate 	/*
9477c478bd9Sstevel@tonic-gate 	 * We now know that the size of the device is less than
9487c478bd9Sstevel@tonic-gate 	 * min_fail and greater than or equal to max_succeed.  Now
9497c478bd9Sstevel@tonic-gate 	 * keep splitting the difference until the actual size in
9507c478bd9Sstevel@tonic-gate 	 * sectors in known.  We also know that the difference
9517c478bd9Sstevel@tonic-gate 	 * between max_succeed and min_fail at this time is
9527c478bd9Sstevel@tonic-gate 	 * 4 * SECTORS_PER_TERABYTE, which is a power of two, which
9537c478bd9Sstevel@tonic-gate 	 * simplifies the math below.
9547c478bd9Sstevel@tonic-gate 	 */
9557c478bd9Sstevel@tonic-gate 
9567c478bd9Sstevel@tonic-gate 	while (min_fail - max_succeed > 1) {
9577c478bd9Sstevel@tonic-gate 		cur_db_off = max_succeed + (min_fail - max_succeed)/2;
9587c478bd9Sstevel@tonic-gate 		if (((llseek(fd, (offset_t)(cur_db_off * DEV_BSIZE),
9597c478bd9Sstevel@tonic-gate 		    SEEK_SET)) == -1) ||
9607c478bd9Sstevel@tonic-gate 		    ((read(fd, buf, DEV_BSIZE)) != DEV_BSIZE))
9617c478bd9Sstevel@tonic-gate 			min_fail = cur_db_off;
9627c478bd9Sstevel@tonic-gate 		else
9637c478bd9Sstevel@tonic-gate 			max_succeed = cur_db_off;
9647c478bd9Sstevel@tonic-gate 	}
9657c478bd9Sstevel@tonic-gate 
9667c478bd9Sstevel@tonic-gate 	/* the size is the last successfully read sector offset plus one */
9677c478bd9Sstevel@tonic-gate 	return (max_succeed + 1);
9687c478bd9Sstevel@tonic-gate }
9697c478bd9Sstevel@tonic-gate 
9707c478bd9Sstevel@tonic-gate /*
9717c478bd9Sstevel@tonic-gate  * validate_size
9727c478bd9Sstevel@tonic-gate  *
9737c478bd9Sstevel@tonic-gate  * Return 1 if the device appears to be at least "size" sectors long.
9747c478bd9Sstevel@tonic-gate  * Return 0 if it's shorter or we can't read it.
9757c478bd9Sstevel@tonic-gate  */
9767c478bd9Sstevel@tonic-gate 
9777c478bd9Sstevel@tonic-gate static int
9787c478bd9Sstevel@tonic-gate validate_size(char *disk, diskaddr_t size)
9797c478bd9Sstevel@tonic-gate {
9807c478bd9Sstevel@tonic-gate 	char 		buf[DEV_BSIZE];
9817c478bd9Sstevel@tonic-gate 	int fd, rc;
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate 	if ((fd = open64(disk, O_RDONLY)) < 0) {
9847c478bd9Sstevel@tonic-gate 		perror(disk);
9857c478bd9Sstevel@tonic-gate 		exit(1);
9867c478bd9Sstevel@tonic-gate 	}
9877c478bd9Sstevel@tonic-gate 
9887c478bd9Sstevel@tonic-gate 	if ((llseek(fd, (offset_t)((size - 1) * DEV_BSIZE), SEEK_SET) == -1) ||
9897c478bd9Sstevel@tonic-gate 	    (read(fd, buf, DEV_BSIZE)) != DEV_BSIZE)
9907c478bd9Sstevel@tonic-gate 		rc = 0;
9917c478bd9Sstevel@tonic-gate 	else
9927c478bd9Sstevel@tonic-gate 		rc = 1;
9937c478bd9Sstevel@tonic-gate 	(void) close(fd);
9947c478bd9Sstevel@tonic-gate 	return (rc);
9957c478bd9Sstevel@tonic-gate }
9967c478bd9Sstevel@tonic-gate 
9977c478bd9Sstevel@tonic-gate /*
9987c478bd9Sstevel@tonic-gate  * read_sb(char * rawdev) - Attempt to read the superblock from a raw device
9997c478bd9Sstevel@tonic-gate  *
10007c478bd9Sstevel@tonic-gate  * Returns:
10017c478bd9Sstevel@tonic-gate  *	0 :
10027c478bd9Sstevel@tonic-gate  *		Could not read a valid superblock for a variety of reasons.
10037c478bd9Sstevel@tonic-gate  *		Since 'newfs' handles any fatal conditions, we're not going
10047c478bd9Sstevel@tonic-gate  *		to make any guesses as to why this is failing or what should
10057c478bd9Sstevel@tonic-gate  *		be done about it.
10067c478bd9Sstevel@tonic-gate  *
10077c478bd9Sstevel@tonic-gate  *	struct fs *:
10087c478bd9Sstevel@tonic-gate  *		A pointer to (what we think is) a valid superblock. The
10097c478bd9Sstevel@tonic-gate  *		space for the superblock is static (inside the function)
10107c478bd9Sstevel@tonic-gate  *		since we will only be reading the values from it.
10117c478bd9Sstevel@tonic-gate  */
10127c478bd9Sstevel@tonic-gate 
10137c478bd9Sstevel@tonic-gate struct fs *
10147c478bd9Sstevel@tonic-gate read_sb(char *fsdev)
10157c478bd9Sstevel@tonic-gate {
10167c478bd9Sstevel@tonic-gate 	static struct fs	sblock;
10177c478bd9Sstevel@tonic-gate 	struct stat64		statb;
10187c478bd9Sstevel@tonic-gate 	int			dskfd;
10197c478bd9Sstevel@tonic-gate 	char			*bufp = NULL;
10207c478bd9Sstevel@tonic-gate 	int			bufsz = 0;
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate 	if (stat64(fsdev, &statb) < 0)
10237c478bd9Sstevel@tonic-gate 		return (0);
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate 	if ((dskfd = open64(fsdev, O_RDONLY)) < 0)
10267c478bd9Sstevel@tonic-gate 		return (0);
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 	/*
10297c478bd9Sstevel@tonic-gate 	 * We need a buffer whose size is a multiple of DEV_BSIZE in order
10307c478bd9Sstevel@tonic-gate 	 * to read from a raw device (which we were probably passed).
10317c478bd9Sstevel@tonic-gate 	 */
10327c478bd9Sstevel@tonic-gate 	bufsz = ((sizeof (sblock) / DEV_BSIZE) + 1) * DEV_BSIZE;
10337c478bd9Sstevel@tonic-gate 	if ((bufp = malloc(bufsz)) == NULL) {
10347c478bd9Sstevel@tonic-gate 		(void) close(dskfd);
10357c478bd9Sstevel@tonic-gate 		return (0);
10367c478bd9Sstevel@tonic-gate 	}
10377c478bd9Sstevel@tonic-gate 
10387c478bd9Sstevel@tonic-gate 	if (llseek(dskfd, (offset_t)SBOFF, SEEK_SET) < 0 ||
10397c478bd9Sstevel@tonic-gate 	    read(dskfd, bufp, bufsz) < 0) {
10407c478bd9Sstevel@tonic-gate 		(void) close(dskfd);
10417c478bd9Sstevel@tonic-gate 		free(bufp);
10427c478bd9Sstevel@tonic-gate 		return (0);
10437c478bd9Sstevel@tonic-gate 	}
10447c478bd9Sstevel@tonic-gate 	(void) close(dskfd);	/* Done with the file */
10457c478bd9Sstevel@tonic-gate 
10467c478bd9Sstevel@tonic-gate 	(void) memcpy(&sblock, bufp, sizeof (sblock));
10477c478bd9Sstevel@tonic-gate 	free(bufp);	/* Don't need this anymore */
10487c478bd9Sstevel@tonic-gate 
10497c478bd9Sstevel@tonic-gate 	if (((sblock.fs_magic != FS_MAGIC) &&
10507c478bd9Sstevel@tonic-gate 	    (sblock.fs_magic != MTB_UFS_MAGIC)) ||
10517c478bd9Sstevel@tonic-gate 	    sblock.fs_ncg < 1 || sblock.fs_cpg < 1)
10527c478bd9Sstevel@tonic-gate 		return (0);
10537c478bd9Sstevel@tonic-gate 
10547c478bd9Sstevel@tonic-gate 	if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl ||
10557c478bd9Sstevel@tonic-gate 	    (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl)
10567c478bd9Sstevel@tonic-gate 		return (0);
10577c478bd9Sstevel@tonic-gate 
10587c478bd9Sstevel@tonic-gate 	if (sblock.fs_sbsize < 0 || sblock.fs_sbsize > SBSIZE)
10597c478bd9Sstevel@tonic-gate 		return (0);
10607c478bd9Sstevel@tonic-gate 
10617c478bd9Sstevel@tonic-gate 	return (&sblock);
10627c478bd9Sstevel@tonic-gate }
10637c478bd9Sstevel@tonic-gate 
10647c478bd9Sstevel@tonic-gate /*
10657c478bd9Sstevel@tonic-gate  * Read the UFS file system on the raw device SPECIAL.  If it does not
10667c478bd9Sstevel@tonic-gate  * appear to be a UFS file system, return non-zero, indicating that
10677c478bd9Sstevel@tonic-gate  * fsirand should be called (and it will spit out an error message).
10687c478bd9Sstevel@tonic-gate  * If it is a UFS file system, take a look at the inodes in the first
10697c478bd9Sstevel@tonic-gate  * cylinder group.  If they appear to be randomized (non-zero), return
10707c478bd9Sstevel@tonic-gate  * zero, which will cause fsirand to not be called.  If the inode generation
10717c478bd9Sstevel@tonic-gate  * counts are all zero, then we must call fsirand, so return non-zero.
10727c478bd9Sstevel@tonic-gate  */
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate #define	RANDOMIZED	0
10757c478bd9Sstevel@tonic-gate #define	NOT_RANDOMIZED	1
10767c478bd9Sstevel@tonic-gate 
10777c478bd9Sstevel@tonic-gate static int
10787c478bd9Sstevel@tonic-gate notrand(char *special)
10797c478bd9Sstevel@tonic-gate {
10807c478bd9Sstevel@tonic-gate 	long fsbuf[SBSIZE / sizeof (long)];
10817c478bd9Sstevel@tonic-gate 	struct dinode dibuf[MAXBSIZE/sizeof (struct dinode)];
10827c478bd9Sstevel@tonic-gate 	struct fs *fs;
10837c478bd9Sstevel@tonic-gate 	struct dinode *dip;
10847c478bd9Sstevel@tonic-gate 	offset_t seekaddr;
10857c478bd9Sstevel@tonic-gate 	int bno, inum;
10867c478bd9Sstevel@tonic-gate 	int fd;
10877c478bd9Sstevel@tonic-gate 
10887c478bd9Sstevel@tonic-gate 	fs = (struct fs *)fsbuf;
10897c478bd9Sstevel@tonic-gate 	if ((fd = open64(special, 0)) == -1)
10907c478bd9Sstevel@tonic-gate 		return (NOT_RANDOMIZED);
10917c478bd9Sstevel@tonic-gate 	if (llseek(fd, (offset_t)SBLOCK * DEV_BSIZE, 0) == -1 ||
10927c478bd9Sstevel@tonic-gate 	    read(fd, (char *)fs, SBSIZE) != SBSIZE ||
10937c478bd9Sstevel@tonic-gate 	    ((fs->fs_magic != FS_MAGIC) && (fs->fs_magic != MTB_UFS_MAGIC))) {
10947c478bd9Sstevel@tonic-gate 		(void) close(fd);
10957c478bd9Sstevel@tonic-gate 		return (NOT_RANDOMIZED);
10967c478bd9Sstevel@tonic-gate 	}
10977c478bd9Sstevel@tonic-gate 
10987c478bd9Sstevel@tonic-gate 	/* looks like a UFS file system; read the first cylinder group */
10997c478bd9Sstevel@tonic-gate 	bsize = INOPB(fs) * sizeof (struct dinode);
11007c478bd9Sstevel@tonic-gate 	inum = 0;
11017c478bd9Sstevel@tonic-gate 	while (inum < fs->fs_ipg) {
11027c478bd9Sstevel@tonic-gate 		bno = itod(fs, inum);
11037c478bd9Sstevel@tonic-gate 		seekaddr = (offset_t)fsbtodb(fs, bno) * DEV_BSIZE;
11047c478bd9Sstevel@tonic-gate 		if (llseek(fd, seekaddr, 0) == -1 ||
11057c478bd9Sstevel@tonic-gate 		    read(fd, (char *)dibuf, bsize) != bsize) {
11067c478bd9Sstevel@tonic-gate 			(void) close(fd);
11077c478bd9Sstevel@tonic-gate 			return (NOT_RANDOMIZED);
11087c478bd9Sstevel@tonic-gate 		}
11097c478bd9Sstevel@tonic-gate 		for (dip = dibuf; dip < &dibuf[INOPB(fs)]; dip++) {
11107c478bd9Sstevel@tonic-gate 			if (dip->di_gen != 0) {
11117c478bd9Sstevel@tonic-gate 				(void) close(fd);
11127c478bd9Sstevel@tonic-gate 				return (RANDOMIZED);
11137c478bd9Sstevel@tonic-gate 			}
11147c478bd9Sstevel@tonic-gate 			inum++;
11157c478bd9Sstevel@tonic-gate 		}
11167c478bd9Sstevel@tonic-gate 	}
11177c478bd9Sstevel@tonic-gate 	(void) close(fd);
11187c478bd9Sstevel@tonic-gate 	return (NOT_RANDOMIZED);
11197c478bd9Sstevel@tonic-gate }
11207c478bd9Sstevel@tonic-gate 
11217c478bd9Sstevel@tonic-gate static void
11227c478bd9Sstevel@tonic-gate usage(void)
11237c478bd9Sstevel@tonic-gate {
11247c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
11257c478bd9Sstevel@tonic-gate 	    "usage: newfs [ -v ] [ mkfs-options ] raw-special-device\n"));
11267c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("where mkfs-options are:\n"));
11277c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
11287c478bd9Sstevel@tonic-gate 	    "\t-N do not create file system, just print out parameters\n"));
11297c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
11307c478bd9Sstevel@tonic-gate "\t-T configure file system for eventual growth to over a terabyte\n"));
11317c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("\t-s file system size (sectors)\n"));
11327c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("\t-b block size\n"));
11337c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("\t-f frag size\n"));
11347c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("\t-t tracks/cylinder\n"));
11357c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("\t-c cylinders/group\n"));
11367c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("\t-m minimum free space %%\n"));
11377c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
11387c478bd9Sstevel@tonic-gate 	    "\t-o optimization preference (`space' or `time')\n"));
11397c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("\t-r revolutions/minute\n"));
11407c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("\t-i number of bytes per inode\n"));
11417c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
11427c478bd9Sstevel@tonic-gate 	    "\t-a number of alternates per cylinder\n"));
11437c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("\t-C maxcontig\n"));
11447c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("\t-d rotational delay\n"));
11457c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
11467c478bd9Sstevel@tonic-gate 	    "\t-n number of rotational positions\n"));
1147355d6bb5Sswilcox 	(void) fprintf(stderr, gettext(
1148355d6bb5Sswilcox "\t-S print a textual version of the calculated superblock to stdout\n"));
1149355d6bb5Sswilcox 	(void) fprintf(stderr, gettext(
1150355d6bb5Sswilcox "\t-B dump a binary version of the calculated superblock to stdout\n"));
11517c478bd9Sstevel@tonic-gate }
11527c478bd9Sstevel@tonic-gate 
11537c478bd9Sstevel@tonic-gate /*
11547c478bd9Sstevel@tonic-gate  * Error-detecting version of atoi(3).  Adapted from mkfs' number().
11557c478bd9Sstevel@tonic-gate  */
11567c478bd9Sstevel@tonic-gate static unsigned int
11577c478bd9Sstevel@tonic-gate number(char *param, char *value, int flags, int def_value)
11587c478bd9Sstevel@tonic-gate {
11597c478bd9Sstevel@tonic-gate 	char *cs;
11607c478bd9Sstevel@tonic-gate 	int n;
11617c478bd9Sstevel@tonic-gate 	int cut = INT_MAX / 10;    /* limit to avoid overflow */
11627c478bd9Sstevel@tonic-gate 	int minus = 0;
11637c478bd9Sstevel@tonic-gate 
11647c478bd9Sstevel@tonic-gate 	cs = value;
11657c478bd9Sstevel@tonic-gate 	if (*cs == '-') {
11667c478bd9Sstevel@tonic-gate 		minus = 1;
11677c478bd9Sstevel@tonic-gate 		cs += 1;
11687c478bd9Sstevel@tonic-gate 	}
11697c478bd9Sstevel@tonic-gate 	if ((*cs < '0') || (*cs > '9')) {
11707c478bd9Sstevel@tonic-gate 		goto bail_out;
11717c478bd9Sstevel@tonic-gate 	}
11727c478bd9Sstevel@tonic-gate 	n = 0;
11737c478bd9Sstevel@tonic-gate 	while ((*cs >= '0') && (*cs <= '9') && (n <= cut)) {
11747c478bd9Sstevel@tonic-gate 		n = n*10 + *cs++ - '0';
11757c478bd9Sstevel@tonic-gate 	}
11767c478bd9Sstevel@tonic-gate 	if (minus)
1177d50c8f90Svsakar 		n = -n;
11787c478bd9Sstevel@tonic-gate 	for (;;) {
11797c478bd9Sstevel@tonic-gate 		switch (*cs++) {
11807c478bd9Sstevel@tonic-gate 		case '\0':
11817c478bd9Sstevel@tonic-gate 			return (n);
11827c478bd9Sstevel@tonic-gate 
11837c478bd9Sstevel@tonic-gate 		case '0': case '1': case '2': case '3': case '4':
11847c478bd9Sstevel@tonic-gate 		case '5': case '6': case '7': case '8': case '9':
11857c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
11867c478bd9Sstevel@tonic-gate 			    "newfs: value for %s overflowed, using %d\n"),
11877c478bd9Sstevel@tonic-gate 			    param, def_value);
11887c478bd9Sstevel@tonic-gate 			return (def_value);
11897c478bd9Sstevel@tonic-gate 
11907c478bd9Sstevel@tonic-gate 		case '%':
11917c478bd9Sstevel@tonic-gate 			if (flags & NR_PERCENT)
11927c478bd9Sstevel@tonic-gate 				break;
11937c478bd9Sstevel@tonic-gate 			/* FALLTHROUGH */
11947c478bd9Sstevel@tonic-gate 
11957c478bd9Sstevel@tonic-gate 		default:
11967c478bd9Sstevel@tonic-gate bail_out:
11977c478bd9Sstevel@tonic-gate 			fatal(gettext("bad numeric arg for %s: \"%s\""),
11987c478bd9Sstevel@tonic-gate 			    param, value);
11997c478bd9Sstevel@tonic-gate 
12007c478bd9Sstevel@tonic-gate 		}
12017c478bd9Sstevel@tonic-gate 	}
12027c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
12037c478bd9Sstevel@tonic-gate }
12047c478bd9Sstevel@tonic-gate 
12057c478bd9Sstevel@tonic-gate /*
12067c478bd9Sstevel@tonic-gate  * Error-detecting version of atoi(3).  Adapted from mkfs' number().
12077c478bd9Sstevel@tonic-gate  */
12087c478bd9Sstevel@tonic-gate static int64_t
12097c478bd9Sstevel@tonic-gate number64(char *param, char *value, int flags, int64_t def_value)
12107c478bd9Sstevel@tonic-gate {
12117c478bd9Sstevel@tonic-gate 	char *cs;
12127c478bd9Sstevel@tonic-gate 	int64_t n;
12137c478bd9Sstevel@tonic-gate 	int64_t cut = FS_SIZE_UPPER_LIMIT/ 10;    /* limit to avoid overflow */
12147c478bd9Sstevel@tonic-gate 	int minus = 0;
12157c478bd9Sstevel@tonic-gate 
12167c478bd9Sstevel@tonic-gate 	cs = value;
12177c478bd9Sstevel@tonic-gate 	if (*cs == '-') {
12187c478bd9Sstevel@tonic-gate 		minus = 1;
12197c478bd9Sstevel@tonic-gate 		cs += 1;
12207c478bd9Sstevel@tonic-gate 	}
12217c478bd9Sstevel@tonic-gate 	if ((*cs < '0') || (*cs > '9')) {
12227c478bd9Sstevel@tonic-gate 		goto bail_out;
12237c478bd9Sstevel@tonic-gate 	}
12247c478bd9Sstevel@tonic-gate 	n = 0;
12257c478bd9Sstevel@tonic-gate 	while ((*cs >= '0') && (*cs <= '9') && (n <= cut)) {
12267c478bd9Sstevel@tonic-gate 		n = n*10 + *cs++ - '0';
12277c478bd9Sstevel@tonic-gate 	}
12287c478bd9Sstevel@tonic-gate 	if (minus)
1229d50c8f90Svsakar 		n = -n;
12307c478bd9Sstevel@tonic-gate 	for (;;) {
12317c478bd9Sstevel@tonic-gate 		switch (*cs++) {
12327c478bd9Sstevel@tonic-gate 		case '\0':
12337c478bd9Sstevel@tonic-gate 			return (n);
12347c478bd9Sstevel@tonic-gate 
12357c478bd9Sstevel@tonic-gate 		case '0': case '1': case '2': case '3': case '4':
12367c478bd9Sstevel@tonic-gate 		case '5': case '6': case '7': case '8': case '9':
12377c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
12387c478bd9Sstevel@tonic-gate 			    "newfs: value for %s overflowed, using %d\n"),
12397c478bd9Sstevel@tonic-gate 			    param, def_value);
12407c478bd9Sstevel@tonic-gate 			return (def_value);
12417c478bd9Sstevel@tonic-gate 
12427c478bd9Sstevel@tonic-gate 		case '%':
12437c478bd9Sstevel@tonic-gate 			if (flags & NR_PERCENT)
12447c478bd9Sstevel@tonic-gate 				break;
12457c478bd9Sstevel@tonic-gate 			/* FALLTHROUGH */
12467c478bd9Sstevel@tonic-gate 
12477c478bd9Sstevel@tonic-gate 		default:
12487c478bd9Sstevel@tonic-gate bail_out:
12497c478bd9Sstevel@tonic-gate 			fatal(gettext("bad numeric arg for %s: \"%s\""),
12507c478bd9Sstevel@tonic-gate 			    param, value);
12517c478bd9Sstevel@tonic-gate 
12527c478bd9Sstevel@tonic-gate 		}
12537c478bd9Sstevel@tonic-gate 	}
12547c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
12557c478bd9Sstevel@tonic-gate }
1256