1/*	$NetBSD: mdconfig.c,v 1.4 2005/11/01 01:42:29 chs Exp $	*/
2
3/*
4 * Copyright (c) 1995 Gordon W. Ross
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29#ifndef lint
30__RCSID("$NetBSD: mdconfig.c,v 1.4 2005/11/01 01:42:29 chs Exp $");
31#endif
32
33/*
34 * This program exists for the sole purpose of providing
35 * user-space memory for the new memory-disk driver (md).
36 * The job done by this is similar to mount_mfs.
37 * (But this design allows any filesystem format!)
38 */
39
40#include <sys/types.h>
41#include <sys/ioctl.h>
42#include <sys/mman.h>
43#include <sys/param.h>
44
45#include <dev/md.h>
46
47#include <fcntl.h>
48#include <stdio.h>
49#include <stdlib.h>
50
51int main __P((int, char **));
52
53int
54main(argc, argv)
55	int argc;
56	char **argv;
57{
58	struct md_conf md;
59	size_t nblks;
60	int fd;
61
62	if (argc <= 2) {
63		fprintf(stderr, "usage: mdconfig <device> <%d-byte-blocks>\n",
64				DEV_BSIZE);
65		exit(1);
66	}
67
68	nblks = (size_t)strtoul(argv[2], NULL, 0);
69	if (nblks == 0) {
70		fprintf(stderr, "invalid number of blocks\n");
71		exit(1);
72	}
73	md.md_size = nblks << DEV_BSHIFT;
74
75	fd = open(argv[1], O_RDWR, 0);
76	if (fd < 0) {
77		perror(argv[1]);
78		exit(1);
79	}
80
81	md.md_addr = mmap(NULL, md.md_size,
82				PROT_READ | PROT_WRITE,
83				MAP_ANON | MAP_PRIVATE,
84				-1, 0);
85	if (md.md_addr == MAP_FAILED) {
86		perror("mmap");
87		exit(1);
88	}
89
90	/* Become server! */
91	md.md_type = MD_UMEM_SERVER;
92	if (ioctl(fd, MD_SETCONF, &md)) {
93		perror("ioctl");
94		exit(1);
95	}
96
97	exit(0);
98}
99