1 /* $NetBSD: rdconfig.c,v 1.1.1.1 1995/10/08 22:40:41 gwr 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 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 * 4. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Gordon W. Ross
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * This program exists for the sole purpose of providing
35 * user-space memory for the new RAM-disk driver (rd).
36 * The job done by this is similar to mount_mfs.
37 * (But this design allows any filesystem format!)
38 */
39
40 #include <fcntl.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <sys/mman.h>
44 #include <sys/param.h>
45 #include <sys/ioctl.h>
46
47 #include <dev/ramdisk.h>
48
49 int
main(int argc,char * argv[])50 main(int argc, char *argv[])
51 {
52 struct rd_conf rd;
53 int nblks, fd, error;
54
55 if (argc <= 2) {
56 fprintf(stderr, "usage: rdconfig <device> <%d-byte-blocks>\n",
57 DEV_BSIZE);
58 exit(1);
59 }
60
61 nblks = atoi(argv[2]);
62 if (nblks <= 0) {
63 fprintf(stderr, "invalid number of blocks\n");
64 exit(1);
65 }
66 rd.rd_size = nblks << DEV_BSHIFT;
67
68 fd = open(argv[1], O_RDWR, 0);
69 if (fd < 0) {
70 perror(argv[1]);
71 exit(1);
72 }
73
74 rd.rd_addr = mmap(NULL, rd.rd_size, PROT_READ | PROT_WRITE,
75 MAP_ANON | MAP_PRIVATE, -1, 0);
76 if (rd.rd_addr == MAP_FAILED) {
77 perror("mmap");
78 exit(1);
79 }
80
81 /* Become server! */
82 rd.rd_type = RD_UMEM_SERVER;
83 if (ioctl(fd, RD_SETCONF, &rd)) {
84 perror("ioctl");
85 exit(1);
86 }
87
88 exit(0);
89 }
90