xref: /illumos-gate/usr/src/cmd/ramdiskadm/main.c (revision bbf215553c7233fbab8a0afdf1fac74c44781867)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2002-2003 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  *
26*bbf21555SRichard Lowe  * ramdiskadm - administer ramdisk(4D). Allows creation and deletion of
277c478bd9Sstevel@tonic-gate  * ramdisks, and display status. All the ioctls are private between
287c478bd9Sstevel@tonic-gate  * ramdisk and ramdiskadm, and so are very simple - device information is
297c478bd9Sstevel@tonic-gate  * communicated via a name or a minor number.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/param.h>
347c478bd9Sstevel@tonic-gate #include <sys/ramdisk.h>
357c478bd9Sstevel@tonic-gate #include <sys/stat.h>
367c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
377c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
387c478bd9Sstevel@tonic-gate #include <libdevinfo.h>
397c478bd9Sstevel@tonic-gate #include <stdio.h>
407c478bd9Sstevel@tonic-gate #include <fcntl.h>
417c478bd9Sstevel@tonic-gate #include <locale.h>
427c478bd9Sstevel@tonic-gate #include <string.h>
437c478bd9Sstevel@tonic-gate #include <errno.h>
447c478bd9Sstevel@tonic-gate #include <stdlib.h>
457c478bd9Sstevel@tonic-gate #include <unistd.h>
467c478bd9Sstevel@tonic-gate #include <stropts.h>
477c478bd9Sstevel@tonic-gate #include <ctype.h>
487c478bd9Sstevel@tonic-gate #include "utils.h"
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	RD_BLOCK_DEV_PFX	"/dev/" RD_BLOCK_NAME "/"
517c478bd9Sstevel@tonic-gate #define	RD_CHAR_DEV_PFX		"/dev/" RD_CHAR_NAME "/"
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #define	HEADING	"%-*.*s %20s  %-10s\n"
547c478bd9Sstevel@tonic-gate #define	FORMAT	"%-*.*s %20llu    %s\n"
557c478bd9Sstevel@tonic-gate #define	FW	(sizeof (RD_BLOCK_DEV_PFX) - 1 + RD_NAME_LEN)
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate static char *pname;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate static void
usage(void)607c478bd9Sstevel@tonic-gate usage(void)
617c478bd9Sstevel@tonic-gate {
627c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
637c478bd9Sstevel@tonic-gate 	    gettext("Usage: %s [ -a <name> <size>[g|m|k|b] | -d <name> ]\n"),
647c478bd9Sstevel@tonic-gate 	    pname);
657c478bd9Sstevel@tonic-gate 	exit(E_USAGE);
667c478bd9Sstevel@tonic-gate }
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * This might be the first time we've used this minor device. If so,
707c478bd9Sstevel@tonic-gate  * it might also be that the /dev links are in the process of being created
717c478bd9Sstevel@tonic-gate  * by devfsadmd (or that they'll be created "soon"). We cannot return
727c478bd9Sstevel@tonic-gate  * until they're there or the invoker of ramdiskadm might try to use them
737c478bd9Sstevel@tonic-gate  * and not find them. This can happen if a shell script is running on
747c478bd9Sstevel@tonic-gate  * an MP.
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate static void
wait_until_dev_complete(char * name)777c478bd9Sstevel@tonic-gate wait_until_dev_complete(char *name)
787c478bd9Sstevel@tonic-gate {
797c478bd9Sstevel@tonic-gate 	di_devlink_handle_t hdl;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	hdl = di_devlink_init(RD_DRIVER_NAME, DI_MAKE_LINK);
827c478bd9Sstevel@tonic-gate 	if (hdl == NULL) {
837c478bd9Sstevel@tonic-gate 		die(gettext("couldn't create device link for\"%s\""), name);
847c478bd9Sstevel@tonic-gate 	}
857c478bd9Sstevel@tonic-gate 	(void) di_devlink_fini(&hdl);
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * Create a named ramdisk.
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate static void
alloc_ramdisk(int ctl_fd,char * name,uint64_t size)927c478bd9Sstevel@tonic-gate alloc_ramdisk(int ctl_fd, char *name, uint64_t size)
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate 	struct rd_ioctl	ri;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	(void) strlcpy(ri.ri_name, name, sizeof (ri.ri_name));
977c478bd9Sstevel@tonic-gate 	ri.ri_size = size;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	if (ioctl(ctl_fd, RD_CREATE_DISK, &ri) == -1) {
1007c478bd9Sstevel@tonic-gate 		die(gettext("couldn't create ramdisk \"%s\""), name);
1017c478bd9Sstevel@tonic-gate 	}
1027c478bd9Sstevel@tonic-gate 	wait_until_dev_complete(name);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	(void) printf(RD_BLOCK_DEV_PFX "%s\n", name);
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate  * Delete a named ramdisk.
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate static void
delete_ramdisk(int ctl_fd,char * name)1117c478bd9Sstevel@tonic-gate delete_ramdisk(int ctl_fd, char *name)
1127c478bd9Sstevel@tonic-gate {
1137c478bd9Sstevel@tonic-gate 	struct rd_ioctl	ri;
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 	(void) strlcpy(ri.ri_name, name, sizeof (ri.ri_name));
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	if (ioctl(ctl_fd, RD_DELETE_DISK, &ri) == -1) {
1187c478bd9Sstevel@tonic-gate 		die(gettext("couldn't delete ramdisk \"%s\""), name);
1197c478bd9Sstevel@tonic-gate 	}
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1237c478bd9Sstevel@tonic-gate static int
di_callback(di_node_t node,di_minor_t minor,void * arg)1247c478bd9Sstevel@tonic-gate di_callback(di_node_t node, di_minor_t minor, void *arg)
1257c478bd9Sstevel@tonic-gate {
1267c478bd9Sstevel@tonic-gate 	static boolean_t	heading_done = B_FALSE;
1277c478bd9Sstevel@tonic-gate 	boolean_t		obp_ramdisk;
1287c478bd9Sstevel@tonic-gate 	char			*name;
1297c478bd9Sstevel@tonic-gate 	char			devnm[MAXNAMELEN];
1307c478bd9Sstevel@tonic-gate 	uint64_t		*sizep;
1317c478bd9Sstevel@tonic-gate 	char			blkpath[MAXPATHLEN];
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	/*
1347c478bd9Sstevel@tonic-gate 	 * Only consider block nodes bound to the ramdisk driver.
1357c478bd9Sstevel@tonic-gate 	 */
1367c478bd9Sstevel@tonic-gate 	if (strcmp(di_driver_name(node), RD_DRIVER_NAME) == 0 &&
1377c478bd9Sstevel@tonic-gate 	    di_minor_spectype(minor) == S_IFBLK) {
1387c478bd9Sstevel@tonic-gate 		/*
1397c478bd9Sstevel@tonic-gate 		 * Determine whether this ramdisk is pseudo or OBP-created.
1407c478bd9Sstevel@tonic-gate 		 */
1417c478bd9Sstevel@tonic-gate 		obp_ramdisk = (di_nodeid(node) == DI_PROM_NODEID);
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 		/*
1447c478bd9Sstevel@tonic-gate 		 * If this is an OBP-created ramdisk use the node name, having
1457c478bd9Sstevel@tonic-gate 		 * first stripped the "ramdisk-" prefix.  For pseudo ramdisks
1467c478bd9Sstevel@tonic-gate 		 * use the minor name, having first stripped any ",raw" suffix.
1477c478bd9Sstevel@tonic-gate 		 */
1487c478bd9Sstevel@tonic-gate 		if (obp_ramdisk) {
1497c478bd9Sstevel@tonic-gate 			RD_STRIP_PREFIX(name, di_node_name(node));
1507c478bd9Sstevel@tonic-gate 			(void) strlcpy(devnm, name, sizeof (devnm));
1517c478bd9Sstevel@tonic-gate 		} else {
1527c478bd9Sstevel@tonic-gate 			(void) strlcpy(devnm, di_minor_name(minor),
1537c478bd9Sstevel@tonic-gate 			    sizeof (devnm));
1547c478bd9Sstevel@tonic-gate 			RD_STRIP_SUFFIX(devnm);
1557c478bd9Sstevel@tonic-gate 		}
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 		/*
1587c478bd9Sstevel@tonic-gate 		 * Get the size of the ramdisk.
1597c478bd9Sstevel@tonic-gate 		 */
1607c478bd9Sstevel@tonic-gate 		if (di_prop_lookup_int64(di_minor_devt(minor), node,
1617c478bd9Sstevel@tonic-gate 		    "Size", (int64_t **)&sizep) == -1) {
1627c478bd9Sstevel@tonic-gate 			die(gettext("couldn't obtain size of ramdisk"));
1637c478bd9Sstevel@tonic-gate 		}
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 		/*
1667c478bd9Sstevel@tonic-gate 		 * Print information about the ramdisk.  Prepend a heading
1677c478bd9Sstevel@tonic-gate 		 * if this is the first/only one.
1687c478bd9Sstevel@tonic-gate 		 */
1697c478bd9Sstevel@tonic-gate 		if (!heading_done) {
1707c478bd9Sstevel@tonic-gate 			(void) printf(HEADING, FW, FW, gettext("Block Device"),
1717c478bd9Sstevel@tonic-gate 			    gettext("Size"), gettext("Removable"));
1727c478bd9Sstevel@tonic-gate 			heading_done = B_TRUE;
1737c478bd9Sstevel@tonic-gate 		}
1747c478bd9Sstevel@tonic-gate 		(void) snprintf(blkpath, sizeof (blkpath),
1757c478bd9Sstevel@tonic-gate 		    RD_BLOCK_DEV_PFX "%s", devnm);
1767c478bd9Sstevel@tonic-gate 		(void) printf(FORMAT, FW, FW, blkpath, *sizep,
1777c478bd9Sstevel@tonic-gate 		    obp_ramdisk ? gettext("No") : gettext("Yes"));
1787c478bd9Sstevel@tonic-gate 	}
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	return (DI_WALK_CONTINUE);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate /*
1847c478bd9Sstevel@tonic-gate  * Print the list of all the ramdisks, their size, and whether they
1857c478bd9Sstevel@tonic-gate  * are removeable (i.e. non-OBP ramdisks).
1867c478bd9Sstevel@tonic-gate  */
1877c478bd9Sstevel@tonic-gate static void
print_ramdisk(void)1887c478bd9Sstevel@tonic-gate print_ramdisk(void)
1897c478bd9Sstevel@tonic-gate {
1907c478bd9Sstevel@tonic-gate 	di_node_t	root;
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	/*
1937c478bd9Sstevel@tonic-gate 	 * Create a snapshot of the device tree, then walk it looking
1947c478bd9Sstevel@tonic-gate 	 * for, and printing information about, ramdisk nodes.
1957c478bd9Sstevel@tonic-gate 	 */
1967c478bd9Sstevel@tonic-gate 	if ((root = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
1977c478bd9Sstevel@tonic-gate 		die(gettext("couldn't create device tree snapshot"));
1987c478bd9Sstevel@tonic-gate 	}
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	if (di_walk_minor(root, DDI_PSEUDO, 0, NULL, di_callback) == -1) {
2017c478bd9Sstevel@tonic-gate 		di_fini(root);
2027c478bd9Sstevel@tonic-gate 		die(gettext("device tree walk failure"));
2037c478bd9Sstevel@tonic-gate 	}
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	di_fini(root);
2067c478bd9Sstevel@tonic-gate }
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate int
main(int argc,char * argv[])2097c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
2107c478bd9Sstevel@tonic-gate {
2117c478bd9Sstevel@tonic-gate 	int		c;
2127c478bd9Sstevel@tonic-gate 	char		*name = NULL;
2137c478bd9Sstevel@tonic-gate 	int		allocflag = 0;
2147c478bd9Sstevel@tonic-gate 	int		deleteflag = 0;
2157c478bd9Sstevel@tonic-gate 	int		errflag = 0;
2167c478bd9Sstevel@tonic-gate 	char		*suffix;
2177c478bd9Sstevel@tonic-gate 	uint64_t	size;
2187c478bd9Sstevel@tonic-gate 	int		openflag;
2197c478bd9Sstevel@tonic-gate 	int		ctl_fd = 0;
2207c478bd9Sstevel@tonic-gate 	static char	rd_ctl[] = "/dev/" RD_CTL_NAME;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	pname = getpname(argv[0]);
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
2257c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "a:d:")) != EOF) {
2287c478bd9Sstevel@tonic-gate 		switch (c) {
2297c478bd9Sstevel@tonic-gate 		case 'a':
2307c478bd9Sstevel@tonic-gate 			allocflag = 1;
2317c478bd9Sstevel@tonic-gate 			name = optarg;
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 			if (((argc - optind) <= 0) || (*argv[optind] == '-')) {
2347c478bd9Sstevel@tonic-gate 				warn(gettext("<size> missing\n"));
2357c478bd9Sstevel@tonic-gate 				usage();
2367c478bd9Sstevel@tonic-gate 				/*NOTREACHED*/
2377c478bd9Sstevel@tonic-gate 			}
2387c478bd9Sstevel@tonic-gate 			size = strtoll(argv[optind], &suffix, 0);
2397c478bd9Sstevel@tonic-gate 			if (strcmp(suffix, "b") == 0) {
2407c478bd9Sstevel@tonic-gate 				size *= 512;
2417c478bd9Sstevel@tonic-gate 				++suffix;
2427c478bd9Sstevel@tonic-gate 			} else if (strcmp(suffix, "k") == 0) {
2437c478bd9Sstevel@tonic-gate 				size *= 1024;
2447c478bd9Sstevel@tonic-gate 				++suffix;
2457c478bd9Sstevel@tonic-gate 			} else if (strcmp(suffix, "m") == 0) {
2467c478bd9Sstevel@tonic-gate 				size *= (1024 * 1024);
2477c478bd9Sstevel@tonic-gate 				++suffix;
2487c478bd9Sstevel@tonic-gate 			} else if (strcmp(suffix, "g") == 0) {
2497c478bd9Sstevel@tonic-gate 				size *= (1024 * 1024 * 1024);
2507c478bd9Sstevel@tonic-gate 				++suffix;
2517c478bd9Sstevel@tonic-gate 			}
2527c478bd9Sstevel@tonic-gate 			if (size == 0 || *suffix != '\0') {
2537c478bd9Sstevel@tonic-gate 				warn(gettext("Illegal <size> \"%s\"\n"),
2547c478bd9Sstevel@tonic-gate 				    argv[optind]);
2557c478bd9Sstevel@tonic-gate 				usage();
2567c478bd9Sstevel@tonic-gate 				/*NOTREACHED*/
2577c478bd9Sstevel@tonic-gate 			}
2587c478bd9Sstevel@tonic-gate 			++optind;
2597c478bd9Sstevel@tonic-gate 			break;
2607c478bd9Sstevel@tonic-gate 		case 'd':
2617c478bd9Sstevel@tonic-gate 			deleteflag = 1;
2627c478bd9Sstevel@tonic-gate 			name = optarg;
2637c478bd9Sstevel@tonic-gate 			break;
2647c478bd9Sstevel@tonic-gate 		default:
2657c478bd9Sstevel@tonic-gate 			errflag = 1;
2667c478bd9Sstevel@tonic-gate 			break;
2677c478bd9Sstevel@tonic-gate 		}
2687c478bd9Sstevel@tonic-gate 	}
2697c478bd9Sstevel@tonic-gate 	if (errflag || (allocflag && deleteflag) || (argc - optind) > 0) {
2707c478bd9Sstevel@tonic-gate 		usage();
2717c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
2727c478bd9Sstevel@tonic-gate 	}
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	if (allocflag || deleteflag) {
2757c478bd9Sstevel@tonic-gate 		boolean_t	nameok = B_TRUE;
2767c478bd9Sstevel@tonic-gate 		char		*p;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 		/*
2797c478bd9Sstevel@tonic-gate 		 * Strip off any leading "/dev/{r}ramdisk/" prefix.
2807c478bd9Sstevel@tonic-gate 		 */
2817c478bd9Sstevel@tonic-gate 		if (strncmp(name, RD_BLOCK_DEV_PFX,
2827c478bd9Sstevel@tonic-gate 		    sizeof (RD_BLOCK_DEV_PFX)-1) == 0) {
2837c478bd9Sstevel@tonic-gate 			name += sizeof (RD_BLOCK_DEV_PFX)-1;
2847c478bd9Sstevel@tonic-gate 		} else if (strncmp(name, RD_CHAR_DEV_PFX,
2857c478bd9Sstevel@tonic-gate 		    sizeof (RD_CHAR_DEV_PFX)-1) == 0) {
2867c478bd9Sstevel@tonic-gate 			name += sizeof (RD_CHAR_DEV_PFX)-1;
2877c478bd9Sstevel@tonic-gate 		}
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 		/*
2907c478bd9Sstevel@tonic-gate 		 * Check that name isn't too long, and that it only contains
2917c478bd9Sstevel@tonic-gate 		 * valid characters, i.e. [a-zA-Z0-9_][a-zA-Z0-9_-]*
2927c478bd9Sstevel@tonic-gate 		 */
2937c478bd9Sstevel@tonic-gate 		if (name[0] == '-') {		/* permit only within name */
2947c478bd9Sstevel@tonic-gate 			nameok = B_FALSE;
2957c478bd9Sstevel@tonic-gate 		} else {
2967c478bd9Sstevel@tonic-gate 			for (p = name; *p != '\0'; p++) {
2977c478bd9Sstevel@tonic-gate 				if (!isalnum(*p) && *p != '_' && *p != '-') {
2987c478bd9Sstevel@tonic-gate 					nameok = B_FALSE;
2997c478bd9Sstevel@tonic-gate 					break;
3007c478bd9Sstevel@tonic-gate 				}
3017c478bd9Sstevel@tonic-gate 			}
3027c478bd9Sstevel@tonic-gate 		}
3037c478bd9Sstevel@tonic-gate 		if (!nameok || (p - name) > RD_NAME_LEN) {
3047c478bd9Sstevel@tonic-gate 			warn(gettext("illegal <name> \"%s\"\n"), name);
3057c478bd9Sstevel@tonic-gate 			usage();
3067c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
3077c478bd9Sstevel@tonic-gate 		}
3087c478bd9Sstevel@tonic-gate 	}
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	/*
3117c478bd9Sstevel@tonic-gate 	 * Now do the real work.
3127c478bd9Sstevel@tonic-gate 	 */
3137c478bd9Sstevel@tonic-gate 	openflag = O_EXCL;
3147c478bd9Sstevel@tonic-gate 	if (allocflag || deleteflag)
3157c478bd9Sstevel@tonic-gate 		openflag |= O_RDWR;
3167c478bd9Sstevel@tonic-gate 	else
3177c478bd9Sstevel@tonic-gate 		openflag |= O_RDONLY;
3187c478bd9Sstevel@tonic-gate 	ctl_fd = open(rd_ctl, openflag);
3197c478bd9Sstevel@tonic-gate 	if (ctl_fd == -1) {
3207c478bd9Sstevel@tonic-gate 		if ((errno == EPERM) || (errno == EACCES)) {
3217c478bd9Sstevel@tonic-gate 			die(gettext("you do not have permission to perform "
3227c478bd9Sstevel@tonic-gate 			    "that operation.\n"));
3237c478bd9Sstevel@tonic-gate 		} else {
3247c478bd9Sstevel@tonic-gate 			die("%s", rd_ctl);
3257c478bd9Sstevel@tonic-gate 		}
3267c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3277c478bd9Sstevel@tonic-gate 	}
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 	if (allocflag) {
3307c478bd9Sstevel@tonic-gate 		alloc_ramdisk(ctl_fd, name, size);
3317c478bd9Sstevel@tonic-gate 	} else if (deleteflag) {
3327c478bd9Sstevel@tonic-gate 		delete_ramdisk(ctl_fd, name);
3337c478bd9Sstevel@tonic-gate 	} else {
3347c478bd9Sstevel@tonic-gate 		print_ramdisk();
3357c478bd9Sstevel@tonic-gate 	}
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 	return (E_SUCCESS);
3387c478bd9Sstevel@tonic-gate }
339