4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
28 #include <sys/types.h>
38 #include <sys/syscall.h>
40 #include <dbus/dbus.h>
41 #include <dbus/dbus-glib.h>
42 #include <dbus/dbus-glib-lowlevel.h>
45 #include <rmm_common.h>
49 static boolean_t d_opt
, l_opt
, o_opt
, u_opt
, eject_opt
,
50 closetray_opt
, query_opt
;
59 (void) fprintf(stderr
,
60 "%s: [-dlu] [-o options] [nickname | device] "
61 "[mount_point]\n", progname
);
63 (void) fprintf(stderr
,
64 "%s: [-dl] [nickname | device]\n", progname
);
69 rmmount(int argc
, char **argv
)
73 LibHalContext
*hal_ctx
;
75 rmm_error_t rmm_error
;
78 const char *default_name
;
81 char *mountpoint
= NULL
;
86 progname
= basename(argv
[0]);
88 if (strcmp(progname
, "rmumount") == 0) {
92 if (getenv("RMMOUNT_DEBUG") != NULL
) {
96 while ((c
= getopt(argc
, argv
, "?dlo:u")) != -1) {
106 if ((opts
= g_strsplit(optarg
, ",", 10)) == NULL
) {
109 for (num_opts
= 0, p
= &opts
[0]; *p
!= NULL
; p
++) {
127 } else if (closetray_opt
) {
129 } else if (eject_opt
) {
135 if ((hal_ctx
= rmm_hal_init(0, 0, 0, 0, &error
, &rmm_error
)) == NULL
) {
136 (void) fprintf(stderr
, gettext("warning: %s\n"),
137 rmm_strerror(&error
, rmm_error
));
138 rmm_dbus_error_free(&error
);
139 if ((rmm_error
== RMM_EDBUS_CONNECT
) ||
140 (rmm_error
== RMM_EHAL_CONNECT
)) {
148 /* -d: print default name and exit */
149 if ((d
= rmm_hal_volume_find_default(hal_ctx
, &error
,
150 &default_name
, &volumes
)) == NULL
) {
151 default_name
= "nothing inserted";
153 rmm_volumes_free(volumes
);
154 libhal_drive_free(d
);
156 (void) printf(gettext("Default device is: %s\n"), default_name
);
158 /* -l: list volumes and exit */
159 print_mask
= RMM_PRINT_MOUNTABLE
;
161 print_mask
|= RMM_PRINT_EJECTABLE
;
163 rmm_print_volume_nicknames(hal_ctx
, &error
, print_mask
);
164 } else if (optind
== argc
) {
165 /* no name provided, use default */
166 if ((d
= rmm_hal_volume_find_default(hal_ctx
, &error
,
167 &default_name
, &volumes
)) == NULL
) {
168 (void) fprintf(stderr
,
169 gettext("No default media available\n"));
172 rmm_volumes_free(volumes
);
173 libhal_drive_free(d
);
176 ret
= rmm_rescan(hal_ctx
, default_name
,
179 ret
= rmm_action(hal_ctx
, default_name
, action
,
184 if (argc
- optind
> 1) {
185 mountpoint
= argv
[optind
+ 1];
188 ret
= rmm_rescan(hal_ctx
, argv
[optind
],
191 ret
= rmm_action(hal_ctx
, argv
[optind
], action
,
192 0, opts
, num_opts
, mountpoint
) ? 0 : 1;
196 rmm_dbus_error_free(&error
);
197 rmm_hal_fini(hal_ctx
);
203 rmumount(int argc
, char **argv
)
205 return (rmmount(argc
, argv
));
209 eject(int argc
, char **argv
)
211 if (getenv("EJECT_CLOSETRAY") != NULL
) {
212 closetray_opt
= B_TRUE
;
213 } else if (getenv("EJECT_QUERY") != NULL
) {
218 return (rmmount(argc
, argv
));
224 (void) fprintf(stderr
, gettext("%s: Out of memory\n"), progname
);
230 * get the name by which this program was called
233 get_progname(char *path
)
238 if ((s
= strdup(path
)) == NULL
) {
252 main(int argc
, char **argv
)
256 vold_init(argc
, argv
);
258 progname
= get_progname(argv
[0]);
260 if (strcmp(progname
, "rmmount") == 0) {
261 if ((getenv("VOLUME_ACTION") != NULL
) &&
262 (getenv("VOLUME_PATH") != NULL
)) {
263 ret
= vold_rmmount(argc
, argv
);
265 ret
= rmmount(argc
, argv
);
267 } else if (strcmp(progname
, "rmumount") == 0) {
268 ret
= rmumount(argc
, argv
);
269 } else if (strcmp(progname
, "eject") == 0) {
270 ret
= eject(argc
, argv
);
272 (void) fprintf(stderr
, "rmmount: invalid program name\n");