Make it possible to specify the type of file (blk/chr/reg) that a

mapped file (-d) is exposed as within the rump kernel.
This commit is contained in:
pooka 2011-02-17 16:03:05 +00:00
parent 78bedf0f20
commit aaf2cb63d0
2 changed files with 55 additions and 8 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: rump_allserver.1,v 1.12 2011/02/04 20:06:23 pooka Exp $
.\" $NetBSD: rump_allserver.1,v 1.13 2011/02/17 16:03:05 pooka Exp $
.\"
.\" Copyright (c) 2010 Antti Kantee. All rights reserved.
.\"
@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd February 4, 2011
.Dd February 17, 2011
.Dt RUMP_SERVER 1
.Os
.Sh NAME
@ -70,7 +70,7 @@ host.
.It Fl d Ar drivespec
The argument
.Ar drivespec
maps a host file a block device in the rump fs namespace.
maps a host file in the rump fs namespace.
The string
.Ar drivespec
must be of comma-separated
@ -98,8 +98,7 @@ of the mapping.
must contain an existing and valid disklabel within the first 64k.
.El
.Pp
The following specifier is optional and used only if disklabel is
not specified:
The following are optional:
.Bl -tag -width hostpath1234
.It Ar offset
Offset of the mapping.
@ -108,6 +107,17 @@ The window into
therefore is
.Fa [ offset , offset+size ] .
In case this parameter is not given, the default value 0 is used.
.It Ar type
The type of file that
.Ar key
is exposed as within the rump kernel.
The possibilities are
.Dq blk ,
.Dq chr ,
and
.Dq reg
for block device, character device and regular file, respectively.
The default is a block device.
.El
.Pp
In case

View File

@ -1,4 +1,4 @@
/* $NetBSD: rump_allserver.c,v 1.16 2011/02/04 20:06:23 pooka Exp $ */
/* $NetBSD: rump_allserver.c,v 1.17 2011/02/17 16:03:05 pooka Exp $ */
/*-
* Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
@ -27,7 +27,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: rump_allserver.c,v 1.16 2011/02/04 20:06:23 pooka Exp $");
__RCSID("$NetBSD: rump_allserver.c,v 1.17 2011/02/17 16:03:05 pooka Exp $");
#endif /* !lint */
#include <sys/types.h>
@ -87,6 +87,8 @@ static const char *const disktokens[] = {
"offset",
#define DLABEL 4
"disklabel",
#define DTYPE 5
"type",
NULL
};
@ -99,6 +101,15 @@ struct etfsreg {
enum rump_etfs_type type;
};
struct etfstype {
const char *name;
enum rump_etfs_type type;
} etfstypes[] = {
{ "blk", RUMP_ETFS_BLK },
{ "chr", RUMP_ETFS_CHR },
{ "reg", RUMP_ETFS_REG },
};
int
main(int argc, char *argv[])
{
@ -129,10 +140,12 @@ main(int argc, char *argv[])
char *key, *hostpath;
long long flen, foffset;
char partition;
int ftype;
flen = foffset = 0;
partition = 0;
key = hostpath = NULL;
ftype = -1;
options = optarg;
while (*options) {
switch (getsubopt(&options,
@ -192,6 +205,28 @@ main(int argc, char *argv[])
partition = *value;
break;
case DTYPE:
if (ftype != -1) {
fprintf(stderr,
"type already specified\n");
usage();
}
for (i = 0;
i < __arraycount(etfstypes);
i++) {
if (strcmp(etfstypes[i].name,
value) == 0)
break;
}
if (i == __arraycount(etfstypes)) {
fprintf(stderr,
"invalid type %s\n", value);
usage();
}
ftype = etfstypes[i].type;
break;
default:
fprintf(stderr, "invalid dtoken\n");
usage();
@ -204,6 +239,8 @@ main(int argc, char *argv[])
fprintf(stderr, "incomplete drivespec\n");
usage();
}
if (ftype == -1)
ftype = RUMP_ETFS_BLK;
if (netfs - curetfs == 0) {
etfs = realloc(etfs, (netfs+16)*sizeof(*etfs));
@ -217,7 +254,7 @@ main(int argc, char *argv[])
etfs[curetfs].flen = flen;
etfs[curetfs].foffset = foffset;
etfs[curetfs].partition = partition;
etfs[curetfs].type = RUMP_ETFS_BLK;
etfs[curetfs].type = ftype;
curetfs++;
break;