xref: /titanic_41/usr/src/cmd/rmvolmgr/rmm_common.h (revision cde2885fdf538266ee2a3b08dee2d5075ce8fa2b)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_COMMON_H
27 #define	_COMMON_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/types.h>
36 #include <unistd.h>
37 #include <zone.h>
38 
39 #include <glib.h>
40 #include <libhal.h>
41 #include <libhal-storage.h>
42 
43 #include "vold.h"
44 
45 typedef enum {
46 	RMM_EOK = 0,
47 	RMM_EDBUS_CONNECT,	/* cannot connect to DBUS */
48 	RMM_EHAL_CONNECT	/* cannot connect to HAL */
49 } rmm_error_t;
50 
51 enum {
52 	RMM_PRINT_MOUNTABLE	= 0x1,
53 	RMM_PRINT_EJECTABLE	= 0x2
54 };
55 
56 /* D-Bus timeout in milliseconds */
57 enum {
58 	RMM_MOUNT_TIMEOUT	= 60000,
59 	RMM_UNMOUNT_TIMEOUT	= 60000,
60 	RMM_EJECT_TIMEOUT	= 60000,
61 	RMM_CLOSETRAY_TIMEOUT	= 60000
62 };
63 
64 #define	HAL_BRANCH_LOCAL	"/org/freedesktop/Hal/devices/local"
65 
66 #define	NELEM(a)	(sizeof (a) / sizeof (*(a)))
67 
68 extern char *progname;
69 
70 LibHalContext	*rmm_hal_init(LibHalDeviceAdded, LibHalDeviceRemoved,
71 		LibHalDevicePropertyModified, DBusError *, rmm_error_t *);
72 void		rmm_hal_fini(LibHalContext *hal_ctx);
73 
74 LibHalDrive	*rmm_hal_volume_find(LibHalContext *, const char *,
75 		DBusError *, GSList **);
76 LibHalDrive	*rmm_hal_volume_find_default(LibHalContext *, DBusError *,
77 		const char **, GSList **);
78 LibHalDrive	*rmm_hal_volume_findby(LibHalContext *, const char *,
79 		const char *, GSList **);
80 LibHalDrive	*rmm_hal_volume_findby_nickname(LibHalContext *, const char *,
81 		GSList **);
82 void		rmm_print_volume_nicknames(LibHalContext *, DBusError *, int);
83 void		rmm_volumes_free(GSList *);
84 
85 boolean_t	rmm_hal_mount(LibHalContext *, const char *,
86 		char **, int, char *, DBusError *);
87 boolean_t	rmm_hal_unmount(LibHalContext *, const char *, DBusError *);
88 boolean_t	rmm_hal_eject(LibHalContext *, const char *, DBusError *);
89 boolean_t	rmm_hal_closetray(LibHalContext *, const char *, DBusError *);
90 boolean_t	rmm_hal_rescan(LibHalContext *, const char *, DBusError *);
91 boolean_t	rmm_hal_claim_branch(LibHalContext *, const char *);
92 boolean_t	rmm_hal_unclaim_branch(LibHalContext *, const char *);
93 
94 boolean_t	rmm_action(LibHalContext *, const char *name, action_t action,
95 		struct action_arg *aap, char **, int, char *);
96 boolean_t	rmm_rescan(LibHalContext *, const char *, boolean_t);
97 
98 void		rmm_update_vold_mountpoints(LibHalContext *, const char *,
99 		struct action_arg *);
100 
101 boolean_t	rmm_volume_aa_from_prop(LibHalContext *, const char *,
102 		LibHalVolume *, struct action_arg *);
103 void		rmm_volume_aa_update_mountpoint(LibHalContext *, const char *,
104 		struct action_arg *aap);
105 void		rmm_volume_aa_free(struct action_arg *);
106 
107 char		*rmm_get_mnttab_mount_point(const char *);
108 const char	*rmm_strerror(DBusError *, int);
109 void		rmm_dbus_error_free(DBusError *);
110 
111 char		*rmm_vold_convert_volume_label(const char *name, size_t len);
112 int		makepath(char *, mode_t);
113 void		dprintf(const char *, ...);
114 
115 #ifdef	__cplusplus
116 }
117 #endif
118 
119 #endif	/* _COMMON_H */
120