1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate *
26*7c478bd9Sstevel@tonic-gate * ramdiskadm - administer ramdisk(7d). Allows creation and deletion of
27*7c478bd9Sstevel@tonic-gate * ramdisks, and display status. All the ioctls are private between
28*7c478bd9Sstevel@tonic-gate * ramdisk and ramdiskadm, and so are very simple - device information is
29*7c478bd9Sstevel@tonic-gate * communicated via a name or a minor number.
30*7c478bd9Sstevel@tonic-gate */
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/ramdisk.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
40*7c478bd9Sstevel@tonic-gate #include <libdevinfo.h>
41*7c478bd9Sstevel@tonic-gate #include <stdio.h>
42*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
43*7c478bd9Sstevel@tonic-gate #include <locale.h>
44*7c478bd9Sstevel@tonic-gate #include <string.h>
45*7c478bd9Sstevel@tonic-gate #include <errno.h>
46*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
47*7c478bd9Sstevel@tonic-gate #include <unistd.h>
48*7c478bd9Sstevel@tonic-gate #include <stropts.h>
49*7c478bd9Sstevel@tonic-gate #include <ctype.h>
50*7c478bd9Sstevel@tonic-gate #include "utils.h"
51*7c478bd9Sstevel@tonic-gate
52*7c478bd9Sstevel@tonic-gate #define RD_BLOCK_DEV_PFX "/dev/" RD_BLOCK_NAME "/"
53*7c478bd9Sstevel@tonic-gate #define RD_CHAR_DEV_PFX "/dev/" RD_CHAR_NAME "/"
54*7c478bd9Sstevel@tonic-gate
55*7c478bd9Sstevel@tonic-gate #define HEADING "%-*.*s %20s %-10s\n"
56*7c478bd9Sstevel@tonic-gate #define FORMAT "%-*.*s %20llu %s\n"
57*7c478bd9Sstevel@tonic-gate #define FW (sizeof (RD_BLOCK_DEV_PFX) - 1 + RD_NAME_LEN)
58*7c478bd9Sstevel@tonic-gate
59*7c478bd9Sstevel@tonic-gate static char *pname;
60*7c478bd9Sstevel@tonic-gate
61*7c478bd9Sstevel@tonic-gate static void
usage(void)62*7c478bd9Sstevel@tonic-gate usage(void)
63*7c478bd9Sstevel@tonic-gate {
64*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
65*7c478bd9Sstevel@tonic-gate gettext("Usage: %s [ -a <name> <size>[g|m|k|b] | -d <name> ]\n"),
66*7c478bd9Sstevel@tonic-gate pname);
67*7c478bd9Sstevel@tonic-gate exit(E_USAGE);
68*7c478bd9Sstevel@tonic-gate }
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate /*
71*7c478bd9Sstevel@tonic-gate * This might be the first time we've used this minor device. If so,
72*7c478bd9Sstevel@tonic-gate * it might also be that the /dev links are in the process of being created
73*7c478bd9Sstevel@tonic-gate * by devfsadmd (or that they'll be created "soon"). We cannot return
74*7c478bd9Sstevel@tonic-gate * until they're there or the invoker of ramdiskadm might try to use them
75*7c478bd9Sstevel@tonic-gate * and not find them. This can happen if a shell script is running on
76*7c478bd9Sstevel@tonic-gate * an MP.
77*7c478bd9Sstevel@tonic-gate */
78*7c478bd9Sstevel@tonic-gate static void
wait_until_dev_complete(char * name)79*7c478bd9Sstevel@tonic-gate wait_until_dev_complete(char *name)
80*7c478bd9Sstevel@tonic-gate {
81*7c478bd9Sstevel@tonic-gate di_devlink_handle_t hdl;
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate hdl = di_devlink_init(RD_DRIVER_NAME, DI_MAKE_LINK);
84*7c478bd9Sstevel@tonic-gate if (hdl == NULL) {
85*7c478bd9Sstevel@tonic-gate die(gettext("couldn't create device link for\"%s\""), name);
86*7c478bd9Sstevel@tonic-gate }
87*7c478bd9Sstevel@tonic-gate (void) di_devlink_fini(&hdl);
88*7c478bd9Sstevel@tonic-gate }
89*7c478bd9Sstevel@tonic-gate
90*7c478bd9Sstevel@tonic-gate /*
91*7c478bd9Sstevel@tonic-gate * Create a named ramdisk.
92*7c478bd9Sstevel@tonic-gate */
93*7c478bd9Sstevel@tonic-gate static void
alloc_ramdisk(int ctl_fd,char * name,uint64_t size)94*7c478bd9Sstevel@tonic-gate alloc_ramdisk(int ctl_fd, char *name, uint64_t size)
95*7c478bd9Sstevel@tonic-gate {
96*7c478bd9Sstevel@tonic-gate struct rd_ioctl ri;
97*7c478bd9Sstevel@tonic-gate
98*7c478bd9Sstevel@tonic-gate (void) strlcpy(ri.ri_name, name, sizeof (ri.ri_name));
99*7c478bd9Sstevel@tonic-gate ri.ri_size = size;
100*7c478bd9Sstevel@tonic-gate
101*7c478bd9Sstevel@tonic-gate if (ioctl(ctl_fd, RD_CREATE_DISK, &ri) == -1) {
102*7c478bd9Sstevel@tonic-gate die(gettext("couldn't create ramdisk \"%s\""), name);
103*7c478bd9Sstevel@tonic-gate }
104*7c478bd9Sstevel@tonic-gate wait_until_dev_complete(name);
105*7c478bd9Sstevel@tonic-gate
106*7c478bd9Sstevel@tonic-gate (void) printf(RD_BLOCK_DEV_PFX "%s\n", name);
107*7c478bd9Sstevel@tonic-gate }
108*7c478bd9Sstevel@tonic-gate
109*7c478bd9Sstevel@tonic-gate /*
110*7c478bd9Sstevel@tonic-gate * Delete a named ramdisk.
111*7c478bd9Sstevel@tonic-gate */
112*7c478bd9Sstevel@tonic-gate static void
delete_ramdisk(int ctl_fd,char * name)113*7c478bd9Sstevel@tonic-gate delete_ramdisk(int ctl_fd, char *name)
114*7c478bd9Sstevel@tonic-gate {
115*7c478bd9Sstevel@tonic-gate struct rd_ioctl ri;
116*7c478bd9Sstevel@tonic-gate
117*7c478bd9Sstevel@tonic-gate (void) strlcpy(ri.ri_name, name, sizeof (ri.ri_name));
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate if (ioctl(ctl_fd, RD_DELETE_DISK, &ri) == -1) {
120*7c478bd9Sstevel@tonic-gate die(gettext("couldn't delete ramdisk \"%s\""), name);
121*7c478bd9Sstevel@tonic-gate }
122*7c478bd9Sstevel@tonic-gate }
123*7c478bd9Sstevel@tonic-gate
124*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
125*7c478bd9Sstevel@tonic-gate static int
di_callback(di_node_t node,di_minor_t minor,void * arg)126*7c478bd9Sstevel@tonic-gate di_callback(di_node_t node, di_minor_t minor, void *arg)
127*7c478bd9Sstevel@tonic-gate {
128*7c478bd9Sstevel@tonic-gate static boolean_t heading_done = B_FALSE;
129*7c478bd9Sstevel@tonic-gate boolean_t obp_ramdisk;
130*7c478bd9Sstevel@tonic-gate char *name;
131*7c478bd9Sstevel@tonic-gate char devnm[MAXNAMELEN];
132*7c478bd9Sstevel@tonic-gate uint64_t *sizep;
133*7c478bd9Sstevel@tonic-gate char blkpath[MAXPATHLEN];
134*7c478bd9Sstevel@tonic-gate
135*7c478bd9Sstevel@tonic-gate /*
136*7c478bd9Sstevel@tonic-gate * Only consider block nodes bound to the ramdisk driver.
137*7c478bd9Sstevel@tonic-gate */
138*7c478bd9Sstevel@tonic-gate if (strcmp(di_driver_name(node), RD_DRIVER_NAME) == 0 &&
139*7c478bd9Sstevel@tonic-gate di_minor_spectype(minor) == S_IFBLK) {
140*7c478bd9Sstevel@tonic-gate /*
141*7c478bd9Sstevel@tonic-gate * Determine whether this ramdisk is pseudo or OBP-created.
142*7c478bd9Sstevel@tonic-gate */
143*7c478bd9Sstevel@tonic-gate obp_ramdisk = (di_nodeid(node) == DI_PROM_NODEID);
144*7c478bd9Sstevel@tonic-gate
145*7c478bd9Sstevel@tonic-gate /*
146*7c478bd9Sstevel@tonic-gate * If this is an OBP-created ramdisk use the node name, having
147*7c478bd9Sstevel@tonic-gate * first stripped the "ramdisk-" prefix. For pseudo ramdisks
148*7c478bd9Sstevel@tonic-gate * use the minor name, having first stripped any ",raw" suffix.
149*7c478bd9Sstevel@tonic-gate */
150*7c478bd9Sstevel@tonic-gate if (obp_ramdisk) {
151*7c478bd9Sstevel@tonic-gate RD_STRIP_PREFIX(name, di_node_name(node));
152*7c478bd9Sstevel@tonic-gate (void) strlcpy(devnm, name, sizeof (devnm));
153*7c478bd9Sstevel@tonic-gate } else {
154*7c478bd9Sstevel@tonic-gate (void) strlcpy(devnm, di_minor_name(minor),
155*7c478bd9Sstevel@tonic-gate sizeof (devnm));
156*7c478bd9Sstevel@tonic-gate RD_STRIP_SUFFIX(devnm);
157*7c478bd9Sstevel@tonic-gate }
158*7c478bd9Sstevel@tonic-gate
159*7c478bd9Sstevel@tonic-gate /*
160*7c478bd9Sstevel@tonic-gate * Get the size of the ramdisk.
161*7c478bd9Sstevel@tonic-gate */
162*7c478bd9Sstevel@tonic-gate if (di_prop_lookup_int64(di_minor_devt(minor), node,
163*7c478bd9Sstevel@tonic-gate "Size", (int64_t **)&sizep) == -1) {
164*7c478bd9Sstevel@tonic-gate die(gettext("couldn't obtain size of ramdisk"));
165*7c478bd9Sstevel@tonic-gate }
166*7c478bd9Sstevel@tonic-gate
167*7c478bd9Sstevel@tonic-gate /*
168*7c478bd9Sstevel@tonic-gate * Print information about the ramdisk. Prepend a heading
169*7c478bd9Sstevel@tonic-gate * if this is the first/only one.
170*7c478bd9Sstevel@tonic-gate */
171*7c478bd9Sstevel@tonic-gate if (!heading_done) {
172*7c478bd9Sstevel@tonic-gate (void) printf(HEADING, FW, FW, gettext("Block Device"),
173*7c478bd9Sstevel@tonic-gate gettext("Size"), gettext("Removable"));
174*7c478bd9Sstevel@tonic-gate heading_done = B_TRUE;
175*7c478bd9Sstevel@tonic-gate }
176*7c478bd9Sstevel@tonic-gate (void) snprintf(blkpath, sizeof (blkpath),
177*7c478bd9Sstevel@tonic-gate RD_BLOCK_DEV_PFX "%s", devnm);
178*7c478bd9Sstevel@tonic-gate (void) printf(FORMAT, FW, FW, blkpath, *sizep,
179*7c478bd9Sstevel@tonic-gate obp_ramdisk ? gettext("No") : gettext("Yes"));
180*7c478bd9Sstevel@tonic-gate }
181*7c478bd9Sstevel@tonic-gate
182*7c478bd9Sstevel@tonic-gate return (DI_WALK_CONTINUE);
183*7c478bd9Sstevel@tonic-gate }
184*7c478bd9Sstevel@tonic-gate
185*7c478bd9Sstevel@tonic-gate /*
186*7c478bd9Sstevel@tonic-gate * Print the list of all the ramdisks, their size, and whether they
187*7c478bd9Sstevel@tonic-gate * are removeable (i.e. non-OBP ramdisks).
188*7c478bd9Sstevel@tonic-gate */
189*7c478bd9Sstevel@tonic-gate static void
print_ramdisk(void)190*7c478bd9Sstevel@tonic-gate print_ramdisk(void)
191*7c478bd9Sstevel@tonic-gate {
192*7c478bd9Sstevel@tonic-gate di_node_t root;
193*7c478bd9Sstevel@tonic-gate
194*7c478bd9Sstevel@tonic-gate /*
195*7c478bd9Sstevel@tonic-gate * Create a snapshot of the device tree, then walk it looking
196*7c478bd9Sstevel@tonic-gate * for, and printing information about, ramdisk nodes.
197*7c478bd9Sstevel@tonic-gate */
198*7c478bd9Sstevel@tonic-gate if ((root = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
199*7c478bd9Sstevel@tonic-gate die(gettext("couldn't create device tree snapshot"));
200*7c478bd9Sstevel@tonic-gate }
201*7c478bd9Sstevel@tonic-gate
202*7c478bd9Sstevel@tonic-gate if (di_walk_minor(root, DDI_PSEUDO, 0, NULL, di_callback) == -1) {
203*7c478bd9Sstevel@tonic-gate di_fini(root);
204*7c478bd9Sstevel@tonic-gate die(gettext("device tree walk failure"));
205*7c478bd9Sstevel@tonic-gate }
206*7c478bd9Sstevel@tonic-gate
207*7c478bd9Sstevel@tonic-gate di_fini(root);
208*7c478bd9Sstevel@tonic-gate }
209*7c478bd9Sstevel@tonic-gate
210*7c478bd9Sstevel@tonic-gate int
main(int argc,char * argv[])211*7c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
212*7c478bd9Sstevel@tonic-gate {
213*7c478bd9Sstevel@tonic-gate int c;
214*7c478bd9Sstevel@tonic-gate char *name = NULL;
215*7c478bd9Sstevel@tonic-gate int allocflag = 0;
216*7c478bd9Sstevel@tonic-gate int deleteflag = 0;
217*7c478bd9Sstevel@tonic-gate int errflag = 0;
218*7c478bd9Sstevel@tonic-gate char *suffix;
219*7c478bd9Sstevel@tonic-gate uint64_t size;
220*7c478bd9Sstevel@tonic-gate int openflag;
221*7c478bd9Sstevel@tonic-gate int ctl_fd = 0;
222*7c478bd9Sstevel@tonic-gate static char rd_ctl[] = "/dev/" RD_CTL_NAME;
223*7c478bd9Sstevel@tonic-gate
224*7c478bd9Sstevel@tonic-gate pname = getpname(argv[0]);
225*7c478bd9Sstevel@tonic-gate
226*7c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
227*7c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
228*7c478bd9Sstevel@tonic-gate
229*7c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "a:d:")) != EOF) {
230*7c478bd9Sstevel@tonic-gate switch (c) {
231*7c478bd9Sstevel@tonic-gate case 'a':
232*7c478bd9Sstevel@tonic-gate allocflag = 1;
233*7c478bd9Sstevel@tonic-gate name = optarg;
234*7c478bd9Sstevel@tonic-gate
235*7c478bd9Sstevel@tonic-gate if (((argc - optind) <= 0) || (*argv[optind] == '-')) {
236*7c478bd9Sstevel@tonic-gate warn(gettext("<size> missing\n"));
237*7c478bd9Sstevel@tonic-gate usage();
238*7c478bd9Sstevel@tonic-gate /*NOTREACHED*/
239*7c478bd9Sstevel@tonic-gate }
240*7c478bd9Sstevel@tonic-gate size = strtoll(argv[optind], &suffix, 0);
241*7c478bd9Sstevel@tonic-gate if (strcmp(suffix, "b") == 0) {
242*7c478bd9Sstevel@tonic-gate size *= 512;
243*7c478bd9Sstevel@tonic-gate ++suffix;
244*7c478bd9Sstevel@tonic-gate } else if (strcmp(suffix, "k") == 0) {
245*7c478bd9Sstevel@tonic-gate size *= 1024;
246*7c478bd9Sstevel@tonic-gate ++suffix;
247*7c478bd9Sstevel@tonic-gate } else if (strcmp(suffix, "m") == 0) {
248*7c478bd9Sstevel@tonic-gate size *= (1024 * 1024);
249*7c478bd9Sstevel@tonic-gate ++suffix;
250*7c478bd9Sstevel@tonic-gate } else if (strcmp(suffix, "g") == 0) {
251*7c478bd9Sstevel@tonic-gate size *= (1024 * 1024 * 1024);
252*7c478bd9Sstevel@tonic-gate ++suffix;
253*7c478bd9Sstevel@tonic-gate }
254*7c478bd9Sstevel@tonic-gate if (size == 0 || *suffix != '\0') {
255*7c478bd9Sstevel@tonic-gate warn(gettext("Illegal <size> \"%s\"\n"),
256*7c478bd9Sstevel@tonic-gate argv[optind]);
257*7c478bd9Sstevel@tonic-gate usage();
258*7c478bd9Sstevel@tonic-gate /*NOTREACHED*/
259*7c478bd9Sstevel@tonic-gate }
260*7c478bd9Sstevel@tonic-gate ++optind;
261*7c478bd9Sstevel@tonic-gate break;
262*7c478bd9Sstevel@tonic-gate case 'd':
263*7c478bd9Sstevel@tonic-gate deleteflag = 1;
264*7c478bd9Sstevel@tonic-gate name = optarg;
265*7c478bd9Sstevel@tonic-gate break;
266*7c478bd9Sstevel@tonic-gate default:
267*7c478bd9Sstevel@tonic-gate errflag = 1;
268*7c478bd9Sstevel@tonic-gate break;
269*7c478bd9Sstevel@tonic-gate }
270*7c478bd9Sstevel@tonic-gate }
271*7c478bd9Sstevel@tonic-gate if (errflag || (allocflag && deleteflag) || (argc - optind) > 0) {
272*7c478bd9Sstevel@tonic-gate usage();
273*7c478bd9Sstevel@tonic-gate /*NOTREACHED*/
274*7c478bd9Sstevel@tonic-gate }
275*7c478bd9Sstevel@tonic-gate
276*7c478bd9Sstevel@tonic-gate if (allocflag || deleteflag) {
277*7c478bd9Sstevel@tonic-gate boolean_t nameok = B_TRUE;
278*7c478bd9Sstevel@tonic-gate char *p;
279*7c478bd9Sstevel@tonic-gate
280*7c478bd9Sstevel@tonic-gate /*
281*7c478bd9Sstevel@tonic-gate * Strip off any leading "/dev/{r}ramdisk/" prefix.
282*7c478bd9Sstevel@tonic-gate */
283*7c478bd9Sstevel@tonic-gate if (strncmp(name, RD_BLOCK_DEV_PFX,
284*7c478bd9Sstevel@tonic-gate sizeof (RD_BLOCK_DEV_PFX)-1) == 0) {
285*7c478bd9Sstevel@tonic-gate name += sizeof (RD_BLOCK_DEV_PFX)-1;
286*7c478bd9Sstevel@tonic-gate } else if (strncmp(name, RD_CHAR_DEV_PFX,
287*7c478bd9Sstevel@tonic-gate sizeof (RD_CHAR_DEV_PFX)-1) == 0) {
288*7c478bd9Sstevel@tonic-gate name += sizeof (RD_CHAR_DEV_PFX)-1;
289*7c478bd9Sstevel@tonic-gate }
290*7c478bd9Sstevel@tonic-gate
291*7c478bd9Sstevel@tonic-gate /*
292*7c478bd9Sstevel@tonic-gate * Check that name isn't too long, and that it only contains
293*7c478bd9Sstevel@tonic-gate * valid characters, i.e. [a-zA-Z0-9_][a-zA-Z0-9_-]*
294*7c478bd9Sstevel@tonic-gate */
295*7c478bd9Sstevel@tonic-gate if (name[0] == '-') { /* permit only within name */
296*7c478bd9Sstevel@tonic-gate nameok = B_FALSE;
297*7c478bd9Sstevel@tonic-gate } else {
298*7c478bd9Sstevel@tonic-gate for (p = name; *p != '\0'; p++) {
299*7c478bd9Sstevel@tonic-gate if (!isalnum(*p) && *p != '_' && *p != '-') {
300*7c478bd9Sstevel@tonic-gate nameok = B_FALSE;
301*7c478bd9Sstevel@tonic-gate break;
302*7c478bd9Sstevel@tonic-gate }
303*7c478bd9Sstevel@tonic-gate }
304*7c478bd9Sstevel@tonic-gate }
305*7c478bd9Sstevel@tonic-gate if (!nameok || (p - name) > RD_NAME_LEN) {
306*7c478bd9Sstevel@tonic-gate warn(gettext("illegal <name> \"%s\"\n"), name);
307*7c478bd9Sstevel@tonic-gate usage();
308*7c478bd9Sstevel@tonic-gate /*NOTREACHED*/
309*7c478bd9Sstevel@tonic-gate }
310*7c478bd9Sstevel@tonic-gate }
311*7c478bd9Sstevel@tonic-gate
312*7c478bd9Sstevel@tonic-gate /*
313*7c478bd9Sstevel@tonic-gate * Now do the real work.
314*7c478bd9Sstevel@tonic-gate */
315*7c478bd9Sstevel@tonic-gate openflag = O_EXCL;
316*7c478bd9Sstevel@tonic-gate if (allocflag || deleteflag)
317*7c478bd9Sstevel@tonic-gate openflag |= O_RDWR;
318*7c478bd9Sstevel@tonic-gate else
319*7c478bd9Sstevel@tonic-gate openflag |= O_RDONLY;
320*7c478bd9Sstevel@tonic-gate ctl_fd = open(rd_ctl, openflag);
321*7c478bd9Sstevel@tonic-gate if (ctl_fd == -1) {
322*7c478bd9Sstevel@tonic-gate if ((errno == EPERM) || (errno == EACCES)) {
323*7c478bd9Sstevel@tonic-gate die(gettext("you do not have permission to perform "
324*7c478bd9Sstevel@tonic-gate "that operation.\n"));
325*7c478bd9Sstevel@tonic-gate } else {
326*7c478bd9Sstevel@tonic-gate die("%s", rd_ctl);
327*7c478bd9Sstevel@tonic-gate }
328*7c478bd9Sstevel@tonic-gate /*NOTREACHED*/
329*7c478bd9Sstevel@tonic-gate }
330*7c478bd9Sstevel@tonic-gate
331*7c478bd9Sstevel@tonic-gate if (allocflag) {
332*7c478bd9Sstevel@tonic-gate alloc_ramdisk(ctl_fd, name, size);
333*7c478bd9Sstevel@tonic-gate } else if (deleteflag) {
334*7c478bd9Sstevel@tonic-gate delete_ramdisk(ctl_fd, name);
335*7c478bd9Sstevel@tonic-gate } else {
336*7c478bd9Sstevel@tonic-gate print_ramdisk();
337*7c478bd9Sstevel@tonic-gate }
338*7c478bd9Sstevel@tonic-gate
339*7c478bd9Sstevel@tonic-gate return (E_SUCCESS);
340*7c478bd9Sstevel@tonic-gate }
341