1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
/***************************************************************************
*
* osspec.c : Solaris HAL backend entry points
*
* Copyright 2011 Andrew Stormont <andyjstormont@gmail.com>
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Licensed under the Academic Free License version 2.1
*
**************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <unistd.h>
#include <strings.h>
#include <port.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/mntent.h>
#include <sys/mnttab.h>
#include "../osspec.h"
#include "../logger.h"
#include "../hald.h"
#include "../hald_dbus.h"
#include "../device_info.h"
#include "../util.h"
#include "../ids.h"
#include "osspec_solaris.h"
#include "hotplug.h"
#include "sysevent.h"
#include "devinfo.h"
#include "devinfo_storage.h"
static void mnttab_event_init ();
static gboolean mnttab_event (GIOChannel *channel, GIOCondition cond, gpointer user_data);
void
osspec_privileged_init (void)
{
}
void
osspec_init (void)
{
ids_init ();
sysevent_init ();
mnttab_event_init ();
}
void
hotplug_queue_now_empty (void)
{
if (hald_is_initialising) {
osspec_probe_done ();
}
}
void
osspec_probe (void)
{
/* add entire device tree */
devinfo_add (NULL, "/");
/* start processing events */
hotplug_event_process_queue ();
}
gboolean
osspec_device_rescan (HalDevice *d)
{
return (devinfo_device_rescan (d));
}
gboolean
osspec_device_reprobe (HalDevice *d)
{
return FALSE;
}
DBusHandlerResult
osspec_filter_function (DBusConnection *connection, DBusMessage *message, void *user_data)
{
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
/** Find the closest ancestor by looking at devfs paths
*
* @param devfs_path Path into devfs, e.g. /pci@0,0/pci1025,57@10,2/storage@1
* @return Parent Hal Device Object or #NULL if there is none
*/
HalDevice *
hal_util_find_closest_ancestor (const gchar *devfs_path, gchar **ancestor_devfs_path, gchar **hotplug_devfs_path)
{
gchar buf[512];
gchar c;
HalDevice *parent;
parent = NULL;
strncpy (buf, devfs_path, sizeof (buf));
do {
char *p;
p = strrchr (buf, '/');
if (p == NULL)
break;
c = *p;
*p = '\0';
parent = hal_device_store_match_key_value_string (hald_get_gdl (),
"solaris.devfs_path",
buf);
if (parent != NULL) {
if (ancestor_devfs_path != NULL) {
*ancestor_devfs_path = g_strdup (buf);
}
if (hotplug_devfs_path != NULL) {
*p = c;
*hotplug_devfs_path = g_strdup (buf);
}
break;
}
} while (TRUE);
return parent;
}
char *
dsk_to_rdsk(char *dsk)
{
int len, pos;
char *p;
char *rdsk;
if ((len = strlen (dsk)) < sizeof ("/dev/dsk/cN") - 1) {
return (strdup(""));
}
if ((p = strstr (dsk, "/dsk/")) == NULL) {
if ((p = strstr (dsk, "/lofi/")) == NULL) {
p = strstr (dsk, "/diskette");
}
}
if (p == NULL) {
return (strdup(""));
}
pos = (uintptr_t)p - (uintptr_t)dsk;
if ((rdsk = (char *)calloc (len + 2, 1)) != NULL) {
strncpy (rdsk, dsk, pos + 1);
rdsk[pos + 1] = 'r';
strcpy (rdsk + pos + 2, dsk + pos + 1);
}
return (rdsk);
}
/*
* Setup to watch mnttab changes
*
* When mnttab changes, POLLRDBAND is set. However, glib does not
* support POLLRDBAND, so we use Solaris ports (see port_create(3C))
* to "map" POLLRDBAND to POLLIN:
*
* - create a port
* - associate the port with mnttab file descriptor and POLLRDBAND
* - now polling for POLLIN on the port descriptor will unblock when
* the associated file descriptor receives POLLRDBAND
*/
static int mnttab_fd;
static int mnttab_port;
static GIOChannel *mnttab_channel;
static void
mnttab_event_init ()
{
char buf[81];
if ((mnttab_fd = open (MNTTAB, O_RDONLY)) < 0) {
return;
}
if ((mnttab_port = port_create ()) < 0) {
(void) close (mnttab_fd);
return;
}
if (port_associate (mnttab_port, PORT_SOURCE_FD, mnttab_fd, POLLRDBAND,
NULL) != 0) {
(void) close (mnttab_port);
(void) close (mnttab_fd);
return;
}
/* suppress initial event */
(void) read(mnttab_fd, buf, (size_t)(sizeof (buf) - 1));
(void) lseek(mnttab_fd, 0, SEEK_SET);
mnttab_channel = g_io_channel_unix_new (mnttab_port);
g_io_add_watch (mnttab_channel, G_IO_IN, mnttab_event, NULL);
}
static gboolean
mnttab_event (GIOChannel *channel, GIOCondition cond, gpointer user_data)
{
port_event_t pe;
timespec_t timeout;
char buf[81];
/* if (cond & ~G_IO_ERR)
return TRUE;
*/
HAL_INFO (("mnttab event"));
/* we have to re-associate port with fd every time */
timeout.tv_sec = timeout.tv_nsec = 0;
(void) port_get(mnttab_port, &pe, &timeout);
(void) port_associate(mnttab_port, PORT_SOURCE_FD,
mnttab_fd, POLLRDBAND, NULL);
if (!hald_is_initialising) {
devinfo_storage_mnttab_event (NULL);
}
(void) lseek(mnttab_fd, 0, SEEK_SET);
(void) read(mnttab_fd, buf, (size_t)(sizeof (buf) - 1));
return TRUE;
}
void
osspec_refresh_mount_state_for_block_device (HalDevice *d)
{
devinfo_storage_mnttab_event (d);
}
static HalFileMonitor *file_monitor = NULL;
HalFileMonitor *
osspec_get_file_monitor (void)
{
return file_monitor;
}
guint
hal_file_monitor_add_notify (HalFileMonitor *monitor,
const char *path,
int mask,
HalFileMonitorNotifyFunc notify_func,
gpointer data)
{
return 0;
}
|