Home | History | Annotate | Line # | Download | only in mdconfig
mdconfig.c revision 1.3
      1 /*	$NetBSD: mdconfig.c,v 1.3 1997/10/17 10:24:24 lukem 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 #include <sys/cdefs.h>
     34 #ifndef lint
     35 __RCSID("$NetBSD: mdconfig.c,v 1.3 1997/10/17 10:24:24 lukem Exp $");
     36 #endif
     37 
     38 /*
     39  * This program exists for the sole purpose of providing
     40  * user-space memory for the new memory-disk driver (md).
     41  * The job done by this is similar to mount_mfs.
     42  * (But this design allows any filesystem format!)
     43  */
     44 
     45 #include <sys/types.h>
     46 #include <sys/ioctl.h>
     47 #include <sys/mman.h>
     48 #include <sys/param.h>
     49 
     50 #include <dev/md.h>
     51 
     52 #include <fcntl.h>
     53 #include <stdio.h>
     54 #include <stdlib.h>
     55 
     56 int main __P((int, char **));
     57 
     58 int
     59 main(argc, argv)
     60 	int argc;
     61 	char **argv;
     62 {
     63 	struct md_conf md;
     64 	int nblks, fd;
     65 
     66 	if (argc <= 2) {
     67 		fprintf(stderr, "usage: mdconfig <device> <%d-byte-blocks>\n",
     68 				DEV_BSIZE);
     69 		exit(1);
     70 	}
     71 
     72 	nblks = atoi(argv[2]);
     73 	if (nblks <= 0) {
     74 		fprintf(stderr, "invalid number of blocks\n");
     75 		exit(1);
     76 	}
     77 	md.md_size = nblks << DEV_BSHIFT;
     78 
     79 	fd = open(argv[1], O_RDWR, 0);
     80 	if (fd < 0) {
     81 		perror(argv[1]);
     82 		exit(1);
     83 	}
     84 
     85 	md.md_addr = mmap(NULL, md.md_size,
     86 				PROT_READ | PROT_WRITE,
     87 				MAP_ANON | MAP_PRIVATE,
     88 				-1, 0);
     89 	if (md.md_addr == (caddr_t)-1) {
     90 		perror("mmap");
     91 		exit(1);
     92 	}
     93 
     94 	/* Become server! */
     95 	md.md_type = MD_UMEM_SERVER;
     96 	if (ioctl(fd, MD_SETCONF, &md)) {
     97 		perror("ioctl");
     98 		exit(1);
     99 	}
    100 
    101 	exit(0);
    102 }
    103