11558Srgrimes/* 298542Smckusick * Copyright (c) 2002 Networks Associates Technology, Inc. 398542Smckusick * All rights reserved. 498542Smckusick * 598542Smckusick * This software was developed for the FreeBSD Project by Marshall 698542Smckusick * Kirk McKusick and Network Associates Laboratories, the Security 798542Smckusick * Research Division of Network Associates, Inc. under DARPA/SPAWAR 898542Smckusick * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS 9110884Smckusick * research program. 1098542Smckusick * 111558Srgrimes * Copyright (c) 1983, 1989, 1993, 1994 121558Srgrimes * The Regents of the University of California. All rights reserved. 131558Srgrimes * 141558Srgrimes * Redistribution and use in source and binary forms, with or without 151558Srgrimes * modification, are permitted provided that the following conditions 161558Srgrimes * are met: 171558Srgrimes * 1. Redistributions of source code must retain the above copyright 181558Srgrimes * notice, this list of conditions and the following disclaimer. 191558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 201558Srgrimes * notice, this list of conditions and the following disclaimer in the 211558Srgrimes * documentation and/or other materials provided with the distribution. 221558Srgrimes * 4. Neither the name of the University nor the names of its contributors 231558Srgrimes * may be used to endorse or promote products derived from this software 241558Srgrimes * without specific prior written permission. 251558Srgrimes * 261558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 271558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 281558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 291558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 301558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 311558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 321558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 331558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 341558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 351558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 361558Srgrimes * SUCH DAMAGE. 371558Srgrimes */ 381558Srgrimes 39114589Sobrien#if 0 401558Srgrimes#ifndef lint 4137664Scharnierstatic const char copyright[] = 4237664Scharnier"@(#) Copyright (c) 1983, 1989, 1993, 1994\n\ 4337664Scharnier The Regents of the University of California. All rights reserved.\n"; 441558Srgrimes#endif /* not lint */ 451558Srgrimes 461558Srgrimes#ifndef lint 4737664Scharnierstatic char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95"; 48114589Sobrien#endif /* not lint */ 4937664Scharnier#endif 50114589Sobrien#include <sys/cdefs.h> 51114589Sobrien__FBSDID("$FreeBSD: stable/10/sbin/newfs/newfs.c 322860 2017-08-24 21:44:23Z mckusick $"); 521558Srgrimes 531558Srgrimes/* 541558Srgrimes * newfs: friendly front end to mkfs 551558Srgrimes */ 561558Srgrimes#include <sys/param.h> 571558Srgrimes#include <sys/stat.h> 5895357Sphk#include <sys/disk.h> 591558Srgrimes#include <sys/disklabel.h> 601558Srgrimes#include <sys/file.h> 611558Srgrimes#include <sys/mount.h> 621558Srgrimes 6337707Scharnier#include <ufs/ufs/dir.h> 6437707Scharnier#include <ufs/ufs/dinode.h> 651558Srgrimes#include <ufs/ffs/fs.h> 6623682Speter#include <ufs/ufs/ufsmount.h> 671558Srgrimes 681558Srgrimes#include <ctype.h> 6937664Scharnier#include <err.h> 701558Srgrimes#include <errno.h> 71135460Spjd#include <inttypes.h> 721558Srgrimes#include <paths.h> 7393777Sbde#include <stdarg.h> 741558Srgrimes#include <stdio.h> 751558Srgrimes#include <stdlib.h> 761558Srgrimes#include <string.h> 771558Srgrimes#include <syslog.h> 781558Srgrimes#include <unistd.h> 791558Srgrimes 80204654Ssobomax#include <libutil.h> 81204654Ssobomax 8292717Sphk#include "newfs.h" 831558Srgrimes 84174675Sphkint Eflag; /* Erase previous disk contents */ 85110174Sgordonint Lflag; /* add a volume label */ 86102231Strhodesint Nflag; /* run without writing file system */ 87113751Srwatsonint Oflag = 2; /* file system format (1 => UFS1, 2 => UFS2) */ 8892722Sphkint Rflag; /* regression test */ 89102231Strhodesint Uflag; /* enable soft updates for file system */ 90218726Smckusickint jflag; /* enable soft updates journaling for filesys */ 91174675Sphkint Xflag = 0; /* exit in middle of newfs for testing */ 92163842Spjdint Jflag; /* enable gjournal for file system */ 93126254Srwatsonint lflag; /* enable multilabel for file system */ 94140603Swesint nflag; /* do not create .snap directory */ 95216798Skibint tflag; /* enable TRIM */ 96174011Syarintmax_t fssize; /* file system size */ 97242379Straszoff_t mediasize; /* device size */ 98204909Ssobomaxint sectorsize; /* bytes/sector */ 991558Srgrimesint realsectorsize; /* bytes/sector in hardware */ 100204919Ssobomaxint fsize = 0; /* fragment size */ 101204919Ssobomaxint bsize = 0; /* block size */ 102204919Ssobomaxint maxbsize = 0; /* maximum clustering */ 103204919Ssobomaxint maxblkspercg = MAXBLKSPERCG; /* maximum blocks per cylinder group */ 1041558Srgrimesint minfree = MINFREE; /* free space threshold */ 105248623Smckusickint metaspace; /* space held for metadata blocks */ 1061558Srgrimesint opt = DEFAULTOPT; /* optimization preference (space or time) */ 107204919Ssobomaxint density; /* number of bytes per inode */ 108204919Ssobomaxint maxcontig = 0; /* max contiguous blocks to allocate */ 109204919Ssobomaxint maxbpg; /* maximum blocks per file in a cyl group */ 110204919Ssobomaxint avgfilesize = AVFILESIZ;/* expected average file size */ 111204919Ssobomaxint avgfilesperdir = AFPDIR;/* expected number of files per directory */ 112110174Sgordonu_char *volumelabel = NULL; /* volume label for filesystem */ 113110671Sjmallettstruct uufsd disk; /* libufs disk structure */ 1141558Srgrimes 11592763Sphkstatic char device[MAXPATHLEN]; 116185588Sluigistatic u_char bootarea[BBSIZE]; 117185588Sluigistatic int is_file; /* work on a file, not a device */ 118185588Sluigistatic char *dkname; 11993777Sbdestatic char *disktype; 1201558Srgrimes 121174011Syarstatic void getfssize(intmax_t *, const char *p, intmax_t, intmax_t); 12295357Sphkstatic struct disklabel *getdisklabel(char *s); 12393777Sbdestatic void usage(void); 124204909Ssobomaxstatic int expand_number_int(const char *buf, int *num); 12537664Scharnier 126185588Sluigiufs2_daddr_t part_ofs; /* partition offset in blocks, used with files */ 127185588Sluigi 1281558Srgrimesint 12992711Siedowsemain(int argc, char *argv[]) 1301558Srgrimes{ 13192483Sphk struct partition *pp; 13292483Sphk struct disklabel *lp; 1331558Srgrimes struct partition oldpartition; 1341558Srgrimes struct stat st; 13595357Sphk char *cp, *special; 136174011Syar intmax_t reserved; 137204615Ssobomax int ch, i, rval; 138185588Sluigi char part_name; /* partition name, default to full disk */ 1391558Srgrimes 140185588Sluigi part_name = 'c'; 141174011Syar reserved = 0; 14292717Sphk while ((ch = getopt(argc, argv, 143248623Smckusick "EJL:NO:RS:T:UXa:b:c:d:e:f:g:h:i:jk:lm:no:p:r:s:t")) != -1) 1441558Srgrimes switch (ch) { 145122785Swes case 'E': 146174675Sphk Eflag = 1; 147122785Swes break; 148163842Spjd case 'J': 149163842Spjd Jflag = 1; 150163842Spjd break; 151110174Sgordon case 'L': 152110174Sgordon volumelabel = optarg; 153110174Sgordon i = -1; 154320366Smckusick while (isalnum(volumelabel[++i]) || 155320366Smckusick volumelabel[i] == '_'); 156110174Sgordon if (volumelabel[i] != '\0') { 157110174Sgordon errx(1, "bad volume label. Valid characters are alphanumerics."); 158110174Sgordon } 159110174Sgordon if (strlen(volumelabel) >= MAXVOLLEN) { 160110174Sgordon errx(1, "bad volume label. Length is longer than %d.", 161110174Sgordon MAXVOLLEN); 162110174Sgordon } 163110174Sgordon Lflag = 1; 164110174Sgordon break; 1651558Srgrimes case 'N': 1661558Srgrimes Nflag = 1; 1671558Srgrimes break; 16898542Smckusick case 'O': 16998542Smckusick if ((Oflag = atoi(optarg)) < 1 || Oflag > 2) 170102231Strhodes errx(1, "%s: bad file system format value", 17198542Smckusick optarg); 17298542Smckusick break; 17392722Sphk case 'R': 17492722Sphk Rflag = 1; 17592722Sphk break; 1761558Srgrimes case 'S': 177204909Ssobomax rval = expand_number_int(optarg, §orsize); 178204615Ssobomax if (rval < 0 || sectorsize <= 0) 17995357Sphk errx(1, "%s: bad sector size", optarg); 1801558Srgrimes break; 1811558Srgrimes case 'T': 1821558Srgrimes disktype = optarg; 1831558Srgrimes break; 184218726Smckusick case 'j': 185218726Smckusick jflag = 1; 186218726Smckusick /* fall through to enable soft updates */ 18775078Sobrien case 'U': 18875078Sobrien Uflag = 1; 18975078Sobrien break; 190174675Sphk case 'X': 191174675Sphk Xflag++; 192174675Sphk break; 1931558Srgrimes case 'a': 194204919Ssobomax rval = expand_number_int(optarg, &maxcontig); 195204615Ssobomax if (rval < 0 || maxcontig <= 0) 19695357Sphk errx(1, "%s: bad maximum contiguous blocks", 1971558Srgrimes optarg); 1981558Srgrimes break; 1991558Srgrimes case 'b': 200204919Ssobomax rval = expand_number_int(optarg, &bsize); 201204615Ssobomax if (rval < 0) 202204615Ssobomax errx(1, "%s: bad block size", 203204615Ssobomax optarg); 204204615Ssobomax if (bsize < MINBSIZE) 205107412Smckusick errx(1, "%s: block size too small, min is %d", 206107412Smckusick optarg, MINBSIZE); 207107412Smckusick if (bsize > MAXBSIZE) 208107412Smckusick errx(1, "%s: block size too large, max is %d", 209107412Smckusick optarg, MAXBSIZE); 2101558Srgrimes break; 2111558Srgrimes case 'c': 212204919Ssobomax rval = expand_number_int(optarg, &maxblkspercg); 213204615Ssobomax if (rval < 0 || maxblkspercg <= 0) 21498542Smckusick errx(1, "%s: bad blocks per cylinder group", 21598542Smckusick optarg); 2161558Srgrimes break; 21798542Smckusick case 'd': 218204919Ssobomax rval = expand_number_int(optarg, &maxbsize); 219204615Ssobomax if (rval < 0 || maxbsize < MINBSIZE) 22098542Smckusick errx(1, "%s: bad extent block size", optarg); 22198542Smckusick break; 2221558Srgrimes case 'e': 223204919Ssobomax rval = expand_number_int(optarg, &maxbpg); 224204615Ssobomax if (rval < 0 || maxbpg <= 0) 22598542Smckusick errx(1, "%s: bad blocks per file in a cylinder group", 2261558Srgrimes optarg); 2271558Srgrimes break; 2281558Srgrimes case 'f': 229204919Ssobomax rval = expand_number_int(optarg, &fsize); 230204615Ssobomax if (rval < 0 || fsize <= 0) 23195357Sphk errx(1, "%s: bad fragment size", optarg); 2321558Srgrimes break; 23375377Smckusick case 'g': 234204919Ssobomax rval = expand_number_int(optarg, &avgfilesize); 235204615Ssobomax if (rval < 0 || avgfilesize <= 0) 23695357Sphk errx(1, "%s: bad average file size", optarg); 23775377Smckusick break; 23875377Smckusick case 'h': 239204919Ssobomax rval = expand_number_int(optarg, &avgfilesperdir); 240204615Ssobomax if (rval < 0 || avgfilesperdir <= 0) 24198542Smckusick errx(1, "%s: bad average files per dir", optarg); 24275377Smckusick break; 2431558Srgrimes case 'i': 244204919Ssobomax rval = expand_number_int(optarg, &density); 245204615Ssobomax if (rval < 0 || density <= 0) 24695357Sphk errx(1, "%s: bad bytes per inode", optarg); 2471558Srgrimes break; 248126254Srwatson case 'l': 249126254Srwatson lflag = 1; 250126254Srwatson break; 251248623Smckusick case 'k': 252248623Smckusick if ((metaspace = atoi(optarg)) < 0) 253248623Smckusick errx(1, "%s: bad metadata space %%", optarg); 254248623Smckusick if (metaspace == 0) 255248623Smckusick /* force to stay zero in mkfs */ 256248623Smckusick metaspace = -1; 257248623Smckusick break; 2581558Srgrimes case 'm': 2591558Srgrimes if ((minfree = atoi(optarg)) < 0 || minfree > 99) 26095357Sphk errx(1, "%s: bad free space %%", optarg); 2611558Srgrimes break; 262140603Swes case 'n': 263140603Swes nflag = 1; 264140603Swes break; 2651558Srgrimes case 'o': 26677420Sphk if (strcmp(optarg, "space") == 0) 26777420Sphk opt = FS_OPTSPACE; 26877420Sphk else if (strcmp(optarg, "time") == 0) 26977420Sphk opt = FS_OPTTIME; 27077420Sphk else 27195357Sphk errx(1, 27292533Sbde "%s: unknown optimization preference: use `space' or `time'", 27392533Sbde optarg); 2741558Srgrimes break; 275174011Syar case 'r': 276174011Syar errno = 0; 277174011Syar reserved = strtoimax(optarg, &cp, 0); 278174011Syar if (errno != 0 || cp == optarg || 279174011Syar *cp != '\0' || reserved < 0) 280174011Syar errx(1, "%s: bad reserved size", optarg); 281174011Syar break; 282185588Sluigi case 'p': 283185588Sluigi is_file = 1; 284185588Sluigi part_name = optarg[0]; 285185588Sluigi break; 286185588Sluigi 2871558Srgrimes case 's': 288135460Spjd errno = 0; 289174011Syar fssize = strtoimax(optarg, &cp, 0); 290174011Syar if (errno != 0 || cp == optarg || 291174011Syar *cp != '\0' || fssize < 0) 292174011Syar errx(1, "%s: bad file system size", optarg); 2931558Srgrimes break; 294216798Skib case 't': 295216798Skib tflag = 1; 296216798Skib break; 2971558Srgrimes case '?': 2981558Srgrimes default: 2991558Srgrimes usage(); 3001558Srgrimes } 3011558Srgrimes argc -= optind; 3021558Srgrimes argv += optind; 3031558Srgrimes 30495357Sphk if (argc != 1) 3051558Srgrimes usage(); 3061558Srgrimes 3071558Srgrimes special = argv[0]; 308185588Sluigi if (!special[0]) 309185588Sluigi err(1, "empty file/special name"); 31023682Speter cp = strrchr(special, '/'); 3111558Srgrimes if (cp == 0) { 3121558Srgrimes /* 31392533Sbde * No path prefix; try prefixing _PATH_DEV. 3141558Srgrimes */ 31592533Sbde snprintf(device, sizeof(device), "%s%s", _PATH_DEV, special); 3161558Srgrimes special = device; 3171558Srgrimes } 3181558Srgrimes 319185588Sluigi if (is_file) { 320185588Sluigi /* bypass ufs_disk_fillout_blank */ 321185588Sluigi bzero( &disk, sizeof(disk)); 322185588Sluigi disk.d_bsize = 1; 323185588Sluigi disk.d_name = special; 324185588Sluigi disk.d_fd = open(special, O_RDONLY); 325185588Sluigi if (disk.d_fd < 0 || 326185588Sluigi (!Nflag && ufs_disk_write(&disk) == -1)) 327185588Sluigi errx(1, "%s: ", special); 328185588Sluigi } else if (ufs_disk_fillout_blank(&disk, special) == -1 || 329110671Sjmallett (!Nflag && ufs_disk_write(&disk) == -1)) { 330110671Sjmallett if (disk.d_error != NULL) 331110671Sjmallett errx(1, "%s: %s", special, disk.d_error); 332110671Sjmallett else 333110671Sjmallett err(1, "%s", special); 334110671Sjmallett } 335110671Sjmallett if (fstat(disk.d_fd, &st) < 0) 33695357Sphk err(1, "%s", special); 337185588Sluigi if ((st.st_mode & S_IFMT) != S_IFCHR) { 338185588Sluigi warn("%s: not a character-special device", special); 339185588Sluigi is_file = 1; /* assume it is a file */ 340185588Sluigi dkname = special; 341185588Sluigi if (sectorsize == 0) 342185588Sluigi sectorsize = 512; 343185588Sluigi mediasize = st.st_size; 344185588Sluigi /* set fssize from the partition */ 345185588Sluigi } else { 346185588Sluigi if (sectorsize == 0) 347174012Syar if (ioctl(disk.d_fd, DIOCGSECTORSIZE, §orsize) == -1) 348185588Sluigi sectorsize = 0; /* back out on error for safety */ 349185588Sluigi if (sectorsize && ioctl(disk.d_fd, DIOCGMEDIASIZE, &mediasize) != -1) 350174011Syar getfssize(&fssize, special, mediasize / sectorsize, reserved); 351185588Sluigi } 35295357Sphk pp = NULL; 35395357Sphk lp = getdisklabel(special); 35495357Sphk if (lp != NULL) { 355185990Sluigi if (!is_file) /* already set for files */ 356185990Sluigi part_name = special[strlen(special) - 1]; 357185990Sluigi if ((part_name < 'a' || part_name - 'a' >= MAXPARTITIONS) && 358185990Sluigi !isdigit(part_name)) 359185990Sluigi errx(1, "%s: can't figure out file system partition", 360185990Sluigi special); 361185588Sluigi cp = &part_name; 36295360Sphk if (isdigit(*cp)) 36395360Sphk pp = &lp->d_partitions[RAW_PART]; 36495357Sphk else 36595357Sphk pp = &lp->d_partitions[*cp - 'a']; 36695357Sphk oldpartition = *pp; 36795357Sphk if (pp->p_size == 0) 36895357Sphk errx(1, "%s: `%c' partition is unavailable", 36995357Sphk special, *cp); 37095357Sphk if (pp->p_fstype == FS_BOOT) 37195357Sphk errx(1, "%s: `%c' partition overlaps boot program", 37295357Sphk special, *cp); 373174011Syar getfssize(&fssize, special, pp->p_size, reserved); 37495357Sphk if (sectorsize == 0) 37595357Sphk sectorsize = lp->d_secsize; 37695357Sphk if (fsize == 0) 37795357Sphk fsize = pp->p_fsize; 37895357Sphk if (bsize == 0) 37995357Sphk bsize = pp->p_frag * pp->p_fsize; 380185588Sluigi if (is_file) 381185588Sluigi part_ofs = pp->p_offset; 3821558Srgrimes } 38395357Sphk if (sectorsize <= 0) 38495357Sphk errx(1, "%s: no default sector size", special); 38595357Sphk if (fsize <= 0) 38695357Sphk fsize = MAX(DFL_FRAGSIZE, sectorsize); 38795357Sphk if (bsize <= 0) 38895357Sphk bsize = MIN(DFL_BLKSIZE, 8 * fsize); 3891558Srgrimes if (minfree < MINFREE && opt != FS_OPTSPACE) { 3901558Srgrimes fprintf(stderr, "Warning: changing optimization to space "); 3911558Srgrimes fprintf(stderr, "because minfree is less than %d%%\n", MINFREE); 3921558Srgrimes opt = FS_OPTSPACE; 3931558Srgrimes } 3941558Srgrimes realsectorsize = sectorsize; 3951558Srgrimes if (sectorsize != DEV_BSIZE) { /* XXX */ 39620061Ssos int secperblk = sectorsize / DEV_BSIZE; 39720061Ssos 39820061Ssos sectorsize = DEV_BSIZE; 39920061Ssos fssize *= secperblk; 400104308Sphk if (pp != NULL) 40195357Sphk pp->p_size *= secperblk; 40220061Ssos } 40395357Sphk mkfs(pp, special); 404110671Sjmallett ufs_disk_close(&disk); 405218726Smckusick if (!jflag) 406218726Smckusick exit(0); 407218726Smckusick if (execlp("tunefs", "newfs", "-j", "enable", special, NULL) < 0) 408218726Smckusick err(1, "Cannot enable soft updates journaling, tunefs"); 409218726Smckusick /* NOT REACHED */ 4101558Srgrimes} 4111558Srgrimes 412174011Syarvoid 413174011Syargetfssize(intmax_t *fsz, const char *s, intmax_t disksize, intmax_t reserved) 414174011Syar{ 415174011Syar intmax_t available; 416174011Syar 417174011Syar available = disksize - reserved; 418174011Syar if (available <= 0) 419174011Syar errx(1, "%s: reserved not less than device size %jd", 420174011Syar s, disksize); 421174011Syar if (*fsz == 0) 422174011Syar *fsz = available; 423174011Syar else if (*fsz > available) 424174011Syar errx(1, "%s: maximum file system size is %jd", 425174011Syar s, available); 426174011Syar} 427174011Syar 4281558Srgrimesstruct disklabel * 42995357Sphkgetdisklabel(char *s) 4301558Srgrimes{ 4311558Srgrimes static struct disklabel lab; 43295357Sphk struct disklabel *lp; 4331558Srgrimes 434185588Sluigi if (is_file) { 435185588Sluigi if (read(disk.d_fd, bootarea, BBSIZE) != BBSIZE) 436185588Sluigi err(4, "cannot read bootarea"); 437185588Sluigi if (bsd_disklabel_le_dec( 438185588Sluigi bootarea + (0 /* labeloffset */ + 439185588Sluigi 1 /* labelsoffset */ * sectorsize), 440185588Sluigi &lab, MAXPARTITIONS)) 441185588Sluigi errx(1, "no valid label found"); 442185588Sluigi 443185588Sluigi lp = &lab; 444185588Sluigi return &lab; 445185588Sluigi } 446185588Sluigi 44795357Sphk if (disktype) { 44895357Sphk lp = getdiskbyname(disktype); 44995357Sphk if (lp != NULL) 4501558Srgrimes return (lp); 4511558Srgrimes } 45295357Sphk return (NULL); 4531558Srgrimes} 4541558Srgrimes 45537664Scharnierstatic void 456110065Sjmallettusage() 4571558Srgrimes{ 45877420Sphk fprintf(stderr, 45977420Sphk "usage: %s [ -fsoptions ] special-device%s\n", 46095357Sphk getprogname(), 46177420Sphk " [device-type]"); 4621558Srgrimes fprintf(stderr, "where fsoptions are:\n"); 463203534Sdelphij fprintf(stderr, "\t-E Erase previous disk content\n"); 464167179Spjd fprintf(stderr, "\t-J Enable journaling via gjournal\n"); 465110174Sgordon fprintf(stderr, "\t-L volume label to add to superblock\n"); 4661558Srgrimes fprintf(stderr, 467102231Strhodes "\t-N do not create file system, just print out parameters\n"); 468102231Strhodes fprintf(stderr, "\t-O file system format: 1 => UFS1, 2 => UFS2\n"); 469203534Sdelphij fprintf(stderr, "\t-R regression test, suppress random factors\n"); 4701558Srgrimes fprintf(stderr, "\t-S sector size\n"); 4711558Srgrimes fprintf(stderr, "\t-T disktype\n"); 47275078Sobrien fprintf(stderr, "\t-U enable soft updates\n"); 4731558Srgrimes fprintf(stderr, "\t-a maximum contiguous blocks\n"); 4741558Srgrimes fprintf(stderr, "\t-b block size\n"); 47598542Smckusick fprintf(stderr, "\t-c blocks per cylinders group\n"); 47698542Smckusick fprintf(stderr, "\t-d maximum extent size\n"); 4771558Srgrimes fprintf(stderr, "\t-e maximum blocks per file in a cylinder group\n"); 4781558Srgrimes fprintf(stderr, "\t-f frag size\n"); 47975377Smckusick fprintf(stderr, "\t-g average file size\n"); 48075377Smckusick fprintf(stderr, "\t-h average files per directory\n"); 4811558Srgrimes fprintf(stderr, "\t-i number of bytes per inode\n"); 482218726Smckusick fprintf(stderr, "\t-j enable soft updates journaling\n"); 483248623Smckusick fprintf(stderr, "\t-k space to hold for metadata blocks\n"); 484140611Sru fprintf(stderr, "\t-l enable multilabel MAC\n"); 485140611Sru fprintf(stderr, "\t-n do not create .snap directory\n"); 4861558Srgrimes fprintf(stderr, "\t-m minimum free space %%\n"); 4871558Srgrimes fprintf(stderr, "\t-o optimization preference (`space' or `time')\n"); 488185588Sluigi fprintf(stderr, "\t-p partition name (a..h)\n"); 489174011Syar fprintf(stderr, "\t-r reserved sectors at the end of device\n"); 490174011Syar fprintf(stderr, "\t-s file system size (sectors)\n"); 491216798Skib fprintf(stderr, "\t-t enable TRIM\n"); 4921558Srgrimes exit(1); 4931558Srgrimes} 494204909Ssobomax 495204909Ssobomaxstatic int 496204909Ssobomaxexpand_number_int(const char *buf, int *num) 497204909Ssobomax{ 498204909Ssobomax int64_t num64; 499204909Ssobomax int rval; 500204909Ssobomax 501204909Ssobomax rval = expand_number(buf, &num64); 502204919Ssobomax if (rval < 0) 503204909Ssobomax return (rval); 504204919Ssobomax if (num64 > INT_MAX || num64 < INT_MIN) { 505204909Ssobomax errno = ERANGE; 506204909Ssobomax return (-1); 507204909Ssobomax } 508204909Ssobomax *num = (int)num64; 509204909Ssobomax return (0); 510204909Ssobomax} 511