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