Home | History | Annotate | Line # | Download | only in mdconfig
mdconfig.c revision 1.1
      1 /*	$NetBSD: mdconfig.c,v 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 <sys/mman.h>
     43 #include <sys/param.h>
     44 
     45 #include <dev/ramdisk.h>
     46 
     47 main(argc, argv)
     48 	int argc;
     49 	char **argv;
     50 {
     51 	struct rd_conf rd;
     52 	int nblks, fd, error;
     53 
     54 	if (argc <= 2) {
     55 		fprintf(stderr, "usage: rdconfig <device> <%d-byte-blocks>\n",
     56 				DEV_BSIZE);
     57 		exit(1);
     58 	}
     59 
     60 	nblks = atoi(argv[2]);
     61 	if (nblks <= 0) {
     62 		fprintf(stderr, "invalid number of blocks\n");
     63 		exit(1);
     64 	}
     65 	rd.rd_size = nblks << DEV_BSHIFT;
     66 
     67 	fd = open(argv[1], O_RDWR, 0);
     68 	if (fd < 0) {
     69 		perror(argv[1]);
     70 		exit(1);
     71 	}
     72 
     73 	rd.rd_addr = mmap(NULL, rd.rd_size,
     74 				PROT_READ | PROT_WRITE,
     75 				MAP_ANON | MAP_PRIVATE,
     76 				-1, 0);
     77 	if (rd.rd_addr == (caddr_t)-1) {
     78 		perror("mmap");
     79 		exit(1);
     80 	}
     81 
     82 	/* Become server! */
     83 	rd.rd_type = RD_UMEM_SERVER;
     84 	if (ioctl(fd, RD_SETCONF, &rd)) {
     85 		perror("ioctl");
     86 		exit(1);
     87 	}
     88 
     89 	exit(0);
     90 }
     91