summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sbin/mount_vnd/mount_vnd.828
-rw-r--r--sbin/mount_vnd/mount_vnd.c33
-rw-r--r--sys/dev/vnd.c23
-rw-r--r--sys/dev/vndioctl.h4
4 files changed, 51 insertions, 37 deletions
diff --git a/sbin/mount_vnd/mount_vnd.8 b/sbin/mount_vnd/mount_vnd.8
index a44c76af947..f71c47ac223 100644
--- a/sbin/mount_vnd/mount_vnd.8
+++ b/sbin/mount_vnd/mount_vnd.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mount_vnd.8,v 1.14 2008/08/14 17:10:29 jsing Exp $
+.\" $OpenBSD: mount_vnd.8,v 1.15 2008/09/03 23:24:25 krw Exp $
.\"
.\" Copyright (c) 1993 University of Utah.
.\" Copyright (c) 1980, 1989, 1991, 1993
@@ -49,7 +49,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: August 14 2008 $
+.Dd $Mdocdate: September 3 2008 $
.Dt MOUNT_VND 8
.Os
.Sh NAME
@@ -63,7 +63,7 @@
.Op Fl K Ar rounds
.Op Fl o Ar options
.Op Fl S Ar saltfile
-.Op Fl s Ar secsize
+.Op Fl t Ar disktype
.Ar image
.Ar vnd_dev
.Ek
@@ -72,7 +72,7 @@
.Op Fl ckluv
.Op Fl K Ar rounds
.Op Fl S Ar saltfile
-.Op Fl s Ar secsize
+.Op Fl t Ar disktype
.Ar vnd_dev
.Ar image
.Ek
@@ -210,12 +210,19 @@ If the salt filename is not specified using
.Fl S ,
it defaults to
.Ar image Ns .slt .
-.It Fl s Ar secsize
-Specify the sector size, in bytes, to be used by the device.
-The default sector size is 512 bytes.
-If specified
-.Ar secsize
-must be a multiple of 512 bytes and cannot exceed 65536 bytes.
+.It Fl t Ar disktype
+Specify a
+.Ar disktype
+entry from the
+.Xr disktab 5
+database.
+The
+.Ar vnd_dev
+will have the sector size, sectors per track, and tracks per cylinder values
+of the specified
+.Ar disktype .
+The defaults are 512-byte sectors, 100 sectors per track and 1 track per
+cylinder.
.It Fl u
.Nm vnconfig
only.
@@ -300,6 +307,7 @@ is not possible, because the image to be configured to a vnd itself
resides on a file system that first has to be checked and mounted.
.Sh SEE ALSO
.Xr vnd 4 ,
+.Xr disktab 5 ,
.Xr fstab 5 ,
.Xr mount 8 ,
.Xr swapon 8 ,
diff --git a/sbin/mount_vnd/mount_vnd.c b/sbin/mount_vnd/mount_vnd.c
index 1da332ba57c..361123f088a 100644
--- a/sbin/mount_vnd/mount_vnd.c
+++ b/sbin/mount_vnd/mount_vnd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mount_vnd.c,v 1.7 2008/08/15 14:41:21 jsing Exp $ */
+/* $OpenBSD: mount_vnd.c,v 1.8 2008/09/03 23:24:25 krw Exp $ */
/*
* Copyright (c) 1993 University of Utah.
* Copyright (c) 1990, 1993
@@ -41,6 +41,7 @@
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/stat.h>
+#include <sys/disklabel.h>
#include <dev/vndioctl.h>
@@ -67,7 +68,8 @@ int verbose = 0;
int run_mount_vnd = 0;
__dead void usage(void);
-int config(char *, char *, int, size_t, char *, size_t);
+int config(char *, char *, int, struct disklabel *, char *,
+ size_t);
int getinfo(const char *);
char *get_pkcs_key(char *, char *);
@@ -76,9 +78,10 @@ main(int argc, char **argv)
{
int ch, rv, action, opt_c, opt_k, opt_K, opt_l, opt_u;
char *key, *mntopts, *rounds, *saltopt;
- size_t keylen = 0, secsize = 0;
+ size_t keylen = 0;
const char *errstr;
extern char *__progname;
+ struct disklabel *dp = NULL;
if (strcasecmp(__progname, "mount_vnd") == 0)
run_mount_vnd = 1;
@@ -87,7 +90,7 @@ main(int argc, char **argv)
key = mntopts = rounds = saltopt = NULL;
action = VND_CONFIG;
- while ((ch = getopt(argc, argv, "ckK:lo:s:S:uv")) != -1) {
+ while ((ch = getopt(argc, argv, "ckK:lo:S:t:uv")) != -1) {
switch (ch) {
case 'c':
opt_c = 1;
@@ -108,10 +111,10 @@ main(int argc, char **argv)
case 'S':
saltopt = optarg;
break;
- case 's':
- secsize = strtonum(optarg, 512, 65536, &errstr);
- if (errstr || (secsize & 0x1ff) != 0)
- errx(1, "invalid sector size: %s", optarg);
+ case 't':
+ dp = getdiskbyname(optarg);
+ if (dp == NULL)
+ errx(1, "unknown disk type: %s", optarg);
break;
case 'u':
opt_u = 1;
@@ -162,10 +165,10 @@ main(int argc, char **argv)
ind_raw = 0;
ind_reg = 1;
}
- rv = config(argv[ind_raw], argv[ind_reg], action, secsize, key,
+ rv = config(argv[ind_raw], argv[ind_reg], action, dp, key,
keylen);
} else if (action == VND_UNCONFIG && argc == 1)
- rv = config(argv[0], NULL, action, 0, NULL, 0);
+ rv = config(argv[0], NULL, action, NULL, NULL, 0);
else if (action == VND_GET)
rv = getinfo(argc ? argv[0] : NULL);
else
@@ -281,7 +284,7 @@ query:
}
int
-config(char *dev, char *file, int action, size_t secsize, char *key,
+config(char *dev, char *file, int action, struct disklabel *dp, char *key,
size_t keylen)
{
struct vnd_ioctl vndio;
@@ -297,7 +300,9 @@ config(char *dev, char *file, int action, size_t secsize, char *key,
goto out;
}
vndio.vnd_file = file;
- vndio.vnd_secsize = secsize;
+ vndio.vnd_secsize = (dp && dp->d_secsize) ? dp->d_secsize : DEV_BSIZE;
+ vndio.vnd_nsectors = (dp && dp->d_nsectors) ? dp->d_nsectors : 100;
+ vndio.vnd_ntracks = (dp && dp->d_ntracks) ? dp->d_ntracks : 1;
vndio.vnd_key = (u_char *)key;
vndio.vnd_keylen = keylen;
@@ -339,12 +344,12 @@ usage(void)
if (run_mount_vnd)
(void)fprintf(stderr,
"usage: mount_vnd [-k] [-K rounds] [-o options] "
- "[-S saltfile] [-s secsize]\n"
+ "[-S saltfile] [-t disktype]\n"
"\t\t image vnd_dev\n");
else
(void)fprintf(stderr,
"usage: %s [-ckluv] [-K rounds] [-S saltfile] "
- "[-s secsize] vnd_dev image\n", __progname);
+ "[-t disktype] vnd_dev image\n", __progname);
exit(1);
}
diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c
index fe4c9d3115b..d1540534f7b 100644
--- a/sys/dev/vnd.c
+++ b/sys/dev/vnd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vnd.c,v 1.89 2008/08/14 17:10:29 jsing Exp $ */
+/* $OpenBSD: vnd.c,v 1.90 2008/09/03 23:24:25 krw Exp $ */
/* $NetBSD: vnd.c,v 1.26 1996/03/30 23:06:11 christos Exp $ */
/*
@@ -130,6 +130,8 @@ struct vnd_softc {
int sc_flags; /* flags */
size_t sc_size; /* size of vnd in sectors */
size_t sc_secsize; /* sector size in bytes */
+ size_t sc_nsectors; /* # of sectors per track */
+ size_t sc_ntracks; /* # of tracks per cylinder */
struct vnode *sc_vp; /* vnode */
struct ucred *sc_cred; /* credentials */
struct buf sc_tab; /* transfer queue */
@@ -307,10 +309,10 @@ vndgetdisklabel(dev_t dev, struct vnd_softc *sc, struct disklabel *lp,
bzero(lp, sizeof(struct disklabel));
lp->d_secsize = sc->sc_secsize;
- lp->d_ntracks = 1;
- lp->d_nsectors = 100;
- lp->d_ncylinders = sc->sc_size / 100;
- lp->d_secpercyl = 100; /* lp->d_ntracks * lp->d_nsectors */
+ lp->d_nsectors = sc->sc_nsectors;
+ lp->d_ntracks = sc->sc_ntracks;
+ lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
+ lp->d_ncylinders = sc->sc_size / lp->d_secpercyl;
strncpy(lp->d_typename, "vnd device", sizeof(lp->d_typename));
lp->d_type = DTYPE_VND;
@@ -790,13 +792,10 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
return(ENXIO);
}
- /* Set sector size for device, if specified. */
- if (vio->vnd_secsize == 0)
- vnd->sc_secsize = DEV_BSIZE;
- else if (vio->vnd_secsize % DEV_BSIZE == 0)
- vnd->sc_secsize = vio->vnd_secsize;
- else
- return (EINVAL);
+ /* Set geometry for device. */
+ vnd->sc_secsize = vio->vnd_secsize;
+ vnd->sc_ntracks = vio->vnd_ntracks;
+ vnd->sc_nsectors = vio->vnd_nsectors;
/*
* Open for read and write first. This lets vn_open() weed out
diff --git a/sys/dev/vndioctl.h b/sys/dev/vndioctl.h
index 6995d80ba21..f792977efa0 100644
--- a/sys/dev/vndioctl.h
+++ b/sys/dev/vndioctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: vndioctl.h,v 1.7 2008/08/14 17:10:29 jsing Exp $ */
+/* $OpenBSD: vndioctl.h,v 1.8 2008/09/03 23:24:25 krw Exp $ */
/* $NetBSD: vndioctl.h,v 1.5 1995/01/25 04:46:30 cgd Exp $ */
/*
@@ -50,6 +50,8 @@
struct vnd_ioctl {
char *vnd_file; /* pathname of file to mount */
size_t vnd_secsize; /* sector size in bytes */
+ size_t vnd_nsectors; /* number of sectors in a track */
+ size_t vnd_ntracks; /* number of tracks per cylinder (i.e. heads) */
off_t vnd_size; /* (returned) size of disk */
u_char *vnd_key;
int vnd_keylen;