static void unknown(char opt, char *s);
static int ispow2(unsigned int i);
+static long long cvtnum(unsigned int blocksize,
+ unsigned int sectorsize, const char *s);
+
/*
* option tables for getsubopt calls
*/
}
+long long
+getnum(
+ const char *str,
+ unsigned int blocksize,
+ unsigned int sectorsize,
+ bool convert)
+{
+ long long i;
+ char *sp;
+
+ if (convert)
+ return cvtnum(blocksize, sectorsize, str);
+
+ i = strtoll(str, &sp, 0);
+ if (i == 0 && sp == str)
+ return -1LL;
+ if (*sp != '\0')
+ return -1LL; /* trailing garbage */
+ return i;
+}
+
+
int
main(
int argc,
blflag = bsflag = slflag = ssflag = lslflag = lssflag = 0;
blocklog = blocksize = 0;
- sectorlog = lsectorlog = XFS_MIN_SECTORSIZE_LOG;
- sectorsize = lsectorsize = XFS_MIN_SECTORSIZE;
+ sectorlog = lsectorlog = 0;
+ sectorsize = lsectorsize = 0;
agsize = daflag = dasize = dblocks = 0;
ilflag = imflag = ipflag = isflag = 0;
liflag = laflag = lsflag = lsuflag = lsunitflag = ldflag = lvflag = 0;
if (bsflag)
conflict('b', bopts, B_SIZE,
B_LOG);
- blocklog = atoi(value);
+ blocklog = getnum(value, 0, 0, false);
if (blocklog <= 0)
illegal(value, "b log");
blocksize = 1 << blocklog;
if (blflag)
conflict('b', bopts, B_LOG,
B_SIZE);
- blocksize = cvtnum(
- blocksize, sectorsize, value);
+ blocksize = getnum(value, blocksize,
+ sectorsize, true);
if (blocksize <= 0 ||
!ispow2(blocksize))
illegal(value, "b size");
reqval('d', dopts, D_AGCOUNT);
if (daflag)
respec('d', dopts, D_AGCOUNT);
- agcount = (__uint64_t)
- strtoul(value, NULL, 10);
+ agcount = getnum(value, 0, 0, false);
if ((__int64_t)agcount <= 0)
illegal(value, "d agcount");
daflag = 1;
reqval('d', dopts, D_AGSIZE);
if (dasize)
respec('d', dopts, D_AGSIZE);
- agsize = cvtnum(
- blocksize, sectorsize, value);
+ agsize = getnum(value, blocksize,
+ sectorsize, true);
+ if ((__int64_t)agsize <= 0)
+ illegal(value, "d agsize");
dasize = 1;
break;
case D_FILE:
if (!value || *value == '\0')
value = "1";
- xi.disfile = atoi(value);
+ xi.disfile = getnum(value, 0, 0, false);
if (xi.disfile < 0 || xi.disfile > 1)
illegal(value, "d file");
if (xi.disfile && !Nflag)
if (nodsflag)
conflict('d', dopts, D_NOALIGN,
D_SUNIT);
- if (!isdigits(value)) {
- fprintf(stderr,
- _("%s: Specify data sunit in 512-byte blocks, no unit suffix\n"),
- progname);
- exit(1);
- }
- dsunit = cvtnum(0, 0, value);
+ dsunit = getnum(value, 0, 0, false);
+ if (dsunit < 0)
+ illegal(value, "d sunit");
break;
case D_SWIDTH:
if (!value || *value == '\0')
if (nodsflag)
conflict('d', dopts, D_NOALIGN,
D_SWIDTH);
- if (!isdigits(value)) {
- fprintf(stderr,
- _("%s: Specify data swidth in 512-byte blocks, no unit suffix\n"),
- progname);
- exit(1);
- }
- dswidth = cvtnum(0, 0, value);
+ dswidth = getnum(value, 0, 0, false);
+ if (dswidth < 0)
+ illegal(value, "d swidth");
break;
case D_SU:
if (!value || *value == '\0')
if (nodsflag)
conflict('d', dopts, D_NOALIGN,
D_SU);
- dsu = cvtnum(
- blocksize, sectorsize, value);
+ dsu = getnum(value, blocksize,
+ sectorsize, true);
+ if (dsu < 0)
+ illegal(value, "d su");
break;
case D_SW:
if (!value || *value == '\0')
if (nodsflag)
conflict('d', dopts, D_NOALIGN,
D_SW);
- if (!isdigits(value)) {
- fprintf(stderr,
- _("%s: Specify data sw as multiple of su, no unit suffix\n"),
- progname);
- exit(1);
- }
- dsw = cvtnum(0, 0, value);
+ dsw = getnum(value, 0, 0, false);
+ if (dsw < 0)
+ illegal(value, "d sw");
break;
case D_NOALIGN:
if (dsu)
if (ssflag)
conflict('d', dopts, D_SECTSIZE,
D_SECTLOG);
- sectorlog = atoi(value);
+ sectorlog = getnum(value, 0, 0, false);
if (sectorlog <= 0)
illegal(value, "d sectlog");
sectorsize = 1 << sectorlog;
if (slflag)
conflict('d', dopts, D_SECTLOG,
D_SECTSIZE);
- sectorsize = cvtnum(
- blocksize, sectorsize, value);
+ sectorsize = getnum(value, blocksize,
+ sectorsize, true);
if (sectorsize <= 0 ||
!ispow2(sectorsize))
illegal(value, "d sectsize");
case I_ALIGN:
if (!value || *value == '\0')
value = "1";
- c = atoi(value);
+ c = getnum(value, 0, 0, false);
if (c < 0 || c > 1)
illegal(value, "i align");
sb_feat.inode_align = c ? true : false;
if (isflag)
conflict('i', iopts, I_SIZE,
I_LOG);
- inodelog = atoi(value);
+ inodelog = getnum(value, 0, 0, false);
if (inodelog <= 0)
illegal(value, "i log");
isize = 1 << inodelog;
reqval('i', iopts, I_MAXPCT);
if (imflag)
respec('i', iopts, I_MAXPCT);
- imaxpct = atoi(value);
+ imaxpct = getnum(value, 0, 0, false);
if (imaxpct < 0 || imaxpct > 100)
illegal(value, "i maxpct");
imflag = 1;
if (isflag)
conflict('i', iopts, I_SIZE,
I_PERBLOCK);
- inopblock = atoi(value);
+ inopblock = getnum(value, 0, 0, false);
if (inopblock <
XFS_MIN_INODE_PERBLOCK ||
!ispow2(inopblock))
I_SIZE);
if (isflag)
respec('i', iopts, I_SIZE);
- isize = cvtnum(0, 0, value);
+ isize = getnum(value, 0, 0, true);
if (isize <= 0 || !ispow2(isize))
illegal(value, "i size");
inodelog = libxfs_highbit32(isize);
case I_ATTR:
if (!value || *value == '\0')
reqval('i', iopts, I_ATTR);
- c = atoi(value);
+ c = getnum(value, 0, 0, false);
if (c < 0 || c > 2)
illegal(value, "i attr");
sb_feat.attr_version = c;
case I_PROJID32BIT:
if (!value || *value == '\0')
value = "0";
- c = atoi(value);
+ c = getnum(value, 0, 0, false);
if (c < 0 || c > 1)
illegal(value, "i projid32bit");
sb_feat.projid16bit = c ? false : true;
respec('l', lopts, L_AGNUM);
if (ldflag)
conflict('l', lopts, L_AGNUM, L_DEV);
- logagno = atoi(value);
+ logagno = getnum(value, 0, 0, false);
+ if ((__int64_t)logagno < 0)
+ illegal(value, "l agno");
laflag = 1;
break;
case L_FILE:
if (loginternal)
conflict('l', lopts, L_INTERNAL,
L_FILE);
- xi.lisfile = atoi(value);
+ xi.lisfile = getnum(value, 0, 0, false);
if (xi.lisfile < 0 || xi.lisfile > 1)
illegal(value, "l file");
if (xi.lisfile)
L_INTERNAL);
if (liflag)
respec('l', lopts, L_INTERNAL);
- loginternal = atoi(value);
+ loginternal = getnum(value, 0, 0, false);
if (loginternal < 0 || loginternal > 1)
illegal(value, "l internal");
liflag = 1;
reqval('l', lopts, L_SU);
if (lsu)
respec('l', lopts, L_SU);
- lsu = cvtnum(
- blocksize, sectorsize, value);
+ lsu = getnum(value, blocksize,
+ sectorsize, true);
+ if (lsu < 0)
+ illegal(value, "l su");
lsuflag = 1;
break;
case L_SUNIT:
reqval('l', lopts, L_SUNIT);
if (lsunit)
respec('l', lopts, L_SUNIT);
- if (!isdigits(value)) {
- fprintf(stderr,
- _("Specify log sunit in 512-byte blocks, no size suffix\n"));
- usage();
- }
- lsunit = cvtnum(0, 0, value);
+ lsunit = getnum(value, 0, 0, false);
+ if (lsunit < 0)
+ illegal(value, "l sunit");
lsunitflag = 1;
break;
case L_NAME:
reqval('l', lopts, L_VERSION);
if (lvflag)
respec('l', lopts, L_VERSION);
- c = atoi(value);
+ c = getnum(value, 0, 0, false);
if (c < 1 || c > 2)
illegal(value, "l version");
sb_feat.log_version = c;
if (lssflag)
conflict('l', lopts, L_SECTSIZE,
L_SECTLOG);
- lsectorlog = atoi(value);
+ lsectorlog = getnum(value, 0, 0, false);
if (lsectorlog <= 0)
illegal(value, "l sectlog");
lsectorsize = 1 << lsectorlog;
if (lslflag)
conflict('l', lopts, L_SECTLOG,
L_SECTSIZE);
- lsectorsize = cvtnum(
- blocksize, sectorsize, value);
+ lsectorsize = getnum(value, blocksize,
+ sectorsize, true);
if (lsectorsize <= 0 ||
!ispow2(lsectorsize))
illegal(value, "l sectsize");
if (!value || *value == '\0')
reqval('l', lopts,
L_LAZYSBCNTR);
- c = atoi(value);
+ c = getnum(value, 0, 0, false);
if (c < 0 || c > 1)
illegal(value, "l lazy-count");
sb_feat.lazy_sb_counters = c ? true
case M_CRC:
if (!value || *value == '\0')
reqval('m', mopts, M_CRC);
- c = atoi(value);
+ c = getnum(value, 0, 0, false);
if (c < 0 || c > 1)
illegal(value, "m crc");
sb_feat.crcs_enabled = c ? true : false;
if (nsflag)
conflict('n', nopts, N_SIZE,
N_LOG);
- dirblocklog = atoi(value);
+ dirblocklog = getnum(value, 0, 0, false);
if (dirblocklog <= 0)
illegal(value, "n log");
dirblocksize = 1 << dirblocklog;
if (nlflag)
conflict('n', nopts, N_LOG,
N_SIZE);
- dirblocksize = cvtnum(
- blocksize, sectorsize, value);
+ dirblocksize = getnum(value, blocksize,
+ sectorsize, true);
if (dirblocksize <= 0 ||
!ispow2(dirblocksize))
illegal(value, "n size");
/* ASCII CI mode */
sb_feat.nci = true;
} else {
- c = atoi(value);
+ c = getnum(value, 0, 0, false);
if (c != 2)
illegal(value,
"n version");
reqval('n', nopts, N_FTYPE);
if (nftype)
respec('n', nopts, N_FTYPE);
- c = atoi(value);
+ c = getnum(value, 0, 0, false);
if (c < 0 || c > 1)
illegal(value, "n ftype");
sb_feat.dirftype = c ? true : false;
case R_FILE:
if (!value || *value == '\0')
value = "1";
- xi.risfile = atoi(value);
+ xi.risfile = getnum(value, 0, 0, false);
if (xi.risfile < 0 || xi.risfile > 1)
illegal(value, "r file");
if (xi.risfile)
if (ssflag || lssflag)
conflict('s', sopts, S_SECTSIZE,
S_SECTLOG);
- sectorlog = atoi(value);
+ sectorlog = getnum(value, 0, 0, false);
if (sectorlog <= 0)
illegal(value, "s sectlog");
lsectorlog = sectorlog;
if (slflag || lslflag)
conflict('s', sopts, S_SECTLOG,
S_SECTSIZE);
- sectorsize = cvtnum(
- blocksize, sectorsize, value);
+ sectorsize = getnum(value, blocksize,
+ sectorsize, true);
if (sectorsize <= 0 ||
!ispow2(sectorsize))
illegal(value, "s sectsize");
usage();
}
+ if (!slflag && !ssflag) {
+ sectorlog = XFS_MIN_SECTORSIZE_LOG;
+ sectorsize = XFS_MIN_SECTORSIZE;
+ }
+ if (!lslflag && !lssflag) {
+ lsectorlog = sectorlog;
+ lsectorsize = sectorsize;
+ }
+
memset(&ft, 0, sizeof(ft));
get_topology(&xi, &ft, force_overwrite);
if (dsize) {
__uint64_t dbytes;
- dbytes = cvtnum(blocksize, sectorsize, dsize);
+ dbytes = getnum(dsize, blocksize, sectorsize, true);
+ if ((__int64_t)dbytes < 0)
+ illegal(dsize, "d size");
if (dbytes % XFS_MIN_BLOCKSIZE) {
fprintf(stderr,
_("illegal data length %lld, not a multiple of %d\n"),
if (logsize) {
__uint64_t logbytes;
- logbytes = cvtnum(blocksize, sectorsize, logsize);
+ logbytes = getnum(logsize, blocksize, sectorsize, true);
+ if ((__int64_t)logbytes < 0)
+ illegal(logsize, "l size");
if (logbytes % XFS_MIN_BLOCKSIZE) {
fprintf(stderr,
_("illegal log length %lld, not a multiple of %d\n"),
if (rtsize) {
__uint64_t rtbytes;
- rtbytes = cvtnum(blocksize, sectorsize, rtsize);
+ rtbytes = getnum(rtsize, blocksize, sectorsize, true);
+ if ((__int64_t)rtbytes < 0)
+ illegal(rtsize, "r size");
if (rtbytes % XFS_MIN_BLOCKSIZE) {
fprintf(stderr,
_("illegal rt length %lld, not a multiple of %d\n"),
if (rtextsize) {
__uint64_t rtextbytes;
- rtextbytes = cvtnum(blocksize, sectorsize, rtextsize);
+ rtextbytes = getnum(rtextsize, blocksize, sectorsize, true);
+ if ((__int64_t)rtextbytes < 0)
+ illegal(rtsize, "r extsize");
if (rtextbytes % blocksize) {
fprintf(stderr,
_("illegal rt extent size %lld, not a multiple of %d\n"),
usage();
}
-/*
- * isdigits -- returns 1 if string contains nothing but [0-9], 0 otherwise
- */
-int
-isdigits(
- char *str)
-{
- int i;
- int n = strlen(str);
-
- for (i = 0; i < n; i++) {
- if (!isdigit((int)str[i]))
- return 0;
- }
- return 1;
-}
-
long long
cvtnum(
unsigned int blocksize,
unsigned int sectorsize,
- char *s)
+ const char *s)
{
long long i;
char *sp;
if (*sp == '\0')
return i;
- if (*sp == 'b' && sp[1] == '\0') {
- if (blocksize)
- return i * blocksize;
- fprintf(stderr, _("blocksize not available yet.\n"));
- usage();
- }
- if (*sp == 's' && sp[1] == '\0') {
- if (sectorsize)
- return i * sectorsize;
- return i * BBSIZE;
- }
+ if (*sp == 'b' && sp[1] == '\0')
+ return i * blocksize;
+ if (*sp == 's' && sp[1] == '\0')
+ return i * sectorsize;
+
if (*sp == 'k' && sp[1] == '\0')
return 1024LL * i;
if (*sp == 'm' && sp[1] == '\0')