summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Coppa <dcoppa@cvs.openbsd.org>2011-05-23 10:56:18 +0000
committerDavid Coppa <dcoppa@cvs.openbsd.org>2011-05-23 10:56:18 +0000
commit91383aaafe79d6390c4b6c16c74982abb6ebe7ad (patch)
treee907f7d5d25e232aa352467f015ec59e446b0839
parent2e59221f81865f06090e6b179b83af560a93cd17 (diff)
Allow specifying k/m/g/... suffixes in newfs(8) -S and -s options.
Useful for mount_mfs, now you can just say: # mount_mfs -s 50m swap /tmp And it will do what you want, taking into account sector size. Old behaviour of -s (specifying count of sectors) is, of course, preserved. All the work was done by Vadim Zhukov (persgray(at)gmail com). OK myself, otto@, thib@
-rw-r--r--sbin/newfs/mkfs.c8
-rw-r--r--sbin/newfs/newfs.830
-rw-r--r--sbin/newfs/newfs.c45
3 files changed, 55 insertions, 28 deletions
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c
index 7671732133f..b211fa555bb 100644
--- a/sbin/newfs/mkfs.c
+++ b/sbin/newfs/mkfs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkfs.c,v 1.74 2010/03/21 09:13:30 otto Exp $ */
+/* $OpenBSD: mkfs.c,v 1.75 2011/05/23 10:56:17 dcoppa Exp $ */
/* $NetBSD: mkfs.c,v 1.25 1995/06/18 21:35:38 cgd Exp $ */
/*
@@ -87,7 +87,7 @@ extern int mfs; /* run as the memory based filesystem */
extern int Nflag; /* run mkfs without writing file system */
extern int Oflag; /* format as an 4.3BSD file system */
extern daddr64_t fssize; /* file system size */
-extern int sectorsize; /* bytes/sector */
+extern long long sectorsize; /* bytes/sector */
extern int fsize; /* fragment size */
extern int bsize; /* block size */
extern int maxfrgspercg; /* maximum fragments per cylinder group */
@@ -404,8 +404,8 @@ mkfs(struct partition *pp, char *fsys, int fi, int fo, mode_t mfsmode,
lastminfpg = roundup(sblock.fs_iblkno +
sblock.fs_ipg / INOPF(&sblock), sblock.fs_frag);
if (sblock.fs_size < lastminfpg)
- errx(28, "file system size %jd < minimum size of %d",
- (intmax_t)sblock.fs_size, lastminfpg);
+ errx(28, "file system size %jd < minimum size of %d "
+ "sectors", (intmax_t)sblock.fs_size, lastminfpg);
if (sblock.fs_size % sblock.fs_fpg >= lastminfpg ||
sblock.fs_size % sblock.fs_fpg == 0)
diff --git a/sbin/newfs/newfs.8 b/sbin/newfs/newfs.8
index e39f590f57a..dc2cd4a53bd 100644
--- a/sbin/newfs/newfs.8
+++ b/sbin/newfs/newfs.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: newfs.8,v 1.69 2011/03/31 11:17:58 sthen Exp $
+.\" $OpenBSD: newfs.8,v 1.70 2011/05/23 10:56:17 dcoppa Exp $
.\" $NetBSD: newfs.8,v 1.12 1995/03/18 14:58:41 cgd Exp $
.\"
.\" Copyright (c) 1983, 1987, 1991, 1993, 1994
@@ -30,7 +30,7 @@
.\"
.\" @(#)newfs.8 8.3 (Berkeley) 3/27/94
.\"
-.Dd $Mdocdate: March 31 2011 $
+.Dd $Mdocdate: May 23 2011 $
.Dt NEWFS 8
.Os
.Sh NAME
@@ -218,6 +218,13 @@ With this option,
will not print extraneous information like superblock backups.
.It Fl S Ar sector-size
The size of a sector in bytes (almost always 512).
+Alternatively
+.Ar sector-size
+may instead use a multiplier, as documented in
+.Xr scan_scaled 3 .
+.Ar sector-size
+should be 512 or a multiple of it because the kernel operates
+512\-byte blocks internally.
A sector is the smallest addressable unit on the physical device.
Changing this is useful only when using
.Nm
@@ -227,14 +234,19 @@ created (for example on a write-once disk).
Note that changing this
from its default will make it impossible for
.Xr fsck 8
-to find the alternate superblocks if the standard superblock is
-lost.
+to find the alternate superblocks automatically if the standard
+superblock is lost.
.It Fl s Ar size
-The size of the file system in sectors.
-This value is multiplied by the number of 512\-byte blocks in a sector
-to yield the size of the file system in 512\-byte blocks, which is the value
-used by the kernel.
-The maximum size of an FFS file system is 2,147,483,647 (2^31 \- 1) of these
+The size of the file system in sectors (see
+.Fl S ) .
+Alternatively
+.Ar size
+may instead use a multiplier, as documented in
+.Xr scan_scaled 3 ,
+to specify size in bytes; in this case
+.Ar size
+is rounded up to the next sector boundary.
+The maximum size of an FFS file system is 2,147,483,647 (2^31 \- 1) of
512\-byte blocks, slightly less than 1 TB.
FFS2 file systems can be as large as 64 PB.
Note however that for
diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c
index ee8954f4f14..82b98261119 100644
--- a/sbin/newfs/newfs.c
+++ b/sbin/newfs/newfs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: newfs.c,v 1.89 2011/04/26 14:02:14 otto Exp $ */
+/* $OpenBSD: newfs.c,v 1.90 2011/05/23 10:56:17 dcoppa Exp $ */
/* $NetBSD: newfs.c,v 1.20 1996/05/16 07:13:03 thorpej Exp $ */
/*
@@ -114,7 +114,7 @@ int mfs; /* run as the memory based filesystem */
int Nflag; /* run without writing file system */
int Oflag = 1; /* 0 = 4.3BSD ffs, 1 = 4.4BSD ffs, 2 = ffs2 */
daddr64_t fssize; /* file system size */
-int sectorsize; /* bytes/sector */
+long long sectorsize; /* bytes/sector */
int fsize = 0; /* fragment size */
int bsize = 0; /* block size */
int maxfrgspercg = INT_MAX; /* maximum fragments per cylinder group */
@@ -169,6 +169,8 @@ main(int argc, char *argv[])
char **saveargv = argv;
int ffsflag = 1;
const char *errstr;
+ long long fssize_input = 0;
+ int fssize_usebytes = 0;
if (strstr(__progname, "mfs"))
mfs = Nflag = quiet = 1;
@@ -192,9 +194,9 @@ main(int argc, char *argv[])
oflagset = 1;
break;
case 'S':
- sectorsize = strtonum(optarg, 1, INT_MAX, &errstr);
- if (errstr)
- fatal("sector size is %s: %s", errstr, optarg);
+ if (scan_scaled(optarg, &sectorsize) == -1 ||
+ sectorsize <= 0 || (sectorsize % DEV_BSIZE))
+ fatal("sector size invalid: %s", optarg);
break;
case 'T':
disktype = optarg;
@@ -265,10 +267,15 @@ main(int argc, char *argv[])
quiet = 1;
break;
case 's':
- fssize = strtonum(optarg, 1, LLONG_MAX, &errstr);
- if (errstr)
- fatal("file system size is %s: %s",
- errstr, optarg);
+ if (scan_scaled(optarg, &fssize_input) == -1 ||
+ fssize_input <= 0)
+ fatal("file system size invalid: %s", optarg);
+ fssize_usebytes = 0; /* in case of multiple -s */
+ for (s1 = optarg; *s1 != '\0'; s1++)
+ if (isalpha(*s1)) {
+ fssize_usebytes = 1;
+ break;
+ }
break;
case 't':
fstype = optarg;
@@ -414,17 +421,25 @@ main(int argc, char *argv[])
argv[0], *cp);
}
havelabel:
- if (fssize == 0)
- fssize = DL_GETPSIZE(pp);
- if (fssize > DL_GETPSIZE(pp) && !mfs)
- fatal("%s: maximum file system size on the `%c' partition is %lld",
- argv[0], *cp, DL_GETPSIZE(pp));
-
if (sectorsize == 0) {
sectorsize = lp->d_secsize;
if (sectorsize <= 0)
fatal("%s: no default sector size", argv[0]);
}
+
+ if (fssize_usebytes) {
+ fssize = (daddr64_t)fssize_input / (daddr64_t)sectorsize;
+ if ((daddr64_t)fssize_input % (daddr64_t)sectorsize != 0)
+ fssize++;
+ } else if (fssize_input == 0)
+ fssize = DL_GETPSIZE(pp);
+ else
+ fssize = (daddr64_t)fssize_input;
+
+ if (fssize > DL_GETPSIZE(pp) && !mfs)
+ fatal("%s: maximum file system size on the `%c' partition is "
+ "%lld sectors", argv[0], *cp, DL_GETPSIZE(pp));
+
fssize *= sectorsize / DEV_BSIZE;
if (oflagset == 0 && fssize >= INT_MAX)
Oflag = 2; /* FFS2 */