00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030 #include <ctype.h>
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 #include <string.h>
00034 #include <getopt.h>
00035 #include <assert.h>
00036 #include <unistd.h>
00037 #include <stdarg.h>
00038
00039 #include "../logger.h"
00040 #include "../device_store.h"
00041 #include "linux_ide.h"
00042
00043
00060 static char *
00061 ide_compute_udi (HalDevice * d, int append_num)
00062 {
00063 char *format;
00064 static char buf[256];
00065
00066 if (append_num == -1)
00067 format = "/org/freedesktop/Hal/devices/ide_%d_%d";
00068 else
00069 format = "/org/freedesktop/Hal/devices/ide_%d_%d-%d";
00070
00071 snprintf (buf, 256, format,
00072 ds_property_get_int (d, "ide.channel"),
00073 ds_property_get_int (d, "ide.sub_channel"), append_num);
00074 return buf;
00075 }
00076
00077
00087 static char *
00088 ide_host_compute_udi (HalDevice * d, int append_num)
00089 {
00090 char *format;
00091 static char buf[256];
00092
00093 if (append_num == -1)
00094 format = "/org/freedesktop/Hal/devices/ide_host_%d";
00095 else
00096 format = "/org/freedesktop/Hal/devices/ide_host_%d-%d";
00097
00098 snprintf (buf, 256, format,
00099 ds_property_get_int (d, "ide_host.number"), append_num);
00100 return buf;
00101 }
00102
00103
00104 static void visit_device_ide_host_got_parent (HalDevice * parent,
00105 void *data1, void *data2);
00106
00115 void
00116 visit_device_ide_host (const char *path, struct sysfs_device *device)
00117 {
00118 HalDevice *d;
00119 int ide_host_number;
00120 char *parent_sysfs_path;
00121
00122
00123 if (sscanf (device->bus_id, "ide%d", &ide_host_number) != 1) {
00124 HAL_ERROR (("Couldn't find ide_host_number in %s\n",
00125 device->bus_id));
00126 return;
00127 }
00128
00129
00130
00131 d = ds_device_new ();
00132 ds_property_set_string (d, "info.bus", "ide_host");
00133 ds_property_set_string (d, "linux.sysfs_path", path);
00134 ds_property_set_string (d, "linux.sysfs_path_device", path);
00135 ds_property_set_int (d, "ide_host.number", ide_host_number);
00136
00137
00138 if (ide_host_number == 0)
00139 ds_property_set_string (d, "info.product",
00140 "Primary IDE channel");
00141 else if (ide_host_number == 1)
00142 ds_property_set_string (d, "info.product",
00143 "Secondary IDE channel");
00144 else
00145 ds_property_set_string (d, "info.product", "IDE channel");
00146
00147
00148 parent_sysfs_path = get_parent_sysfs_path (path);
00149
00150
00151
00152
00153
00154 ds_device_async_find_by_key_value_string
00155 ("linux.sysfs_path_device", parent_sysfs_path, TRUE,
00156 visit_device_ide_host_got_parent, (void *) d, NULL,
00157 is_probing ? 0 : HAL_LINUX_HOTPLUG_TIMEOUT);
00158
00159 free (parent_sysfs_path);
00160 }
00161
00169 static void
00170 visit_device_ide_host_got_parent (HalDevice * parent,
00171 void *data1, void *data2)
00172 {
00173 char *new_udi = NULL;
00174 HalDevice *new_d = NULL;
00175 HalDevice *d = (HalDevice *) data1;
00176
00177 if (parent != NULL) {
00178 ds_property_set_string (d, "info.parent", parent->udi);
00179 find_and_set_physical_device (d);
00180 ds_property_set_bool (d, "info.virtual", TRUE);
00181 }
00182
00183
00184
00185
00186 new_udi = rename_and_merge (d, ide_host_compute_udi, "ide_host");
00187 if (new_udi != NULL) {
00188 new_d = ds_device_find (new_udi);
00189 if (new_d != NULL) {
00190 ds_gdl_add (new_d);
00191 }
00192 }
00193 }
00194
00195
00196
00197 static void visit_device_ide_got_parent (HalDevice * parent,
00198 void *data1, void *data2);
00199
00208 void
00209 visit_device_ide (const char *path, struct sysfs_device *device)
00210 {
00211 HalDevice *d;
00212 int channel;
00213 int sub_channel;
00214 char *parent_sysfs_path;
00215
00216
00217 if (sscanf (device->bus_id, "%d.%d", &channel, &sub_channel) != 2) {
00218 HAL_ERROR (("Couldn't find channel and sub_channel in %s\n",
00219 device->bus_id));
00220 return;
00221 }
00222
00223
00224
00225 d = ds_device_new ();
00226 ds_property_set_string (d, "info.bus", "ide");
00227 ds_property_set_string (d, "linux.sysfs_path", path);
00228 ds_property_set_string (d, "linux.sysfs_path_device", path);
00229 ds_property_set_int (d, "ide.channel", channel);
00230 ds_property_set_int (d, "ide.sub_channel", sub_channel);
00231
00232
00233 if (sub_channel == 0)
00234 ds_property_set_string (d, "info.product",
00235 "Master IDE Interface");
00236 else
00237 ds_property_set_string (d, "info.product",
00238 "Slave IDE Interface");
00239
00240 parent_sysfs_path = get_parent_sysfs_path (path);
00241
00242
00243
00244
00245
00246 ds_device_async_find_by_key_value_string
00247 ("linux.sysfs_path_device", parent_sysfs_path, TRUE,
00248 visit_device_ide_got_parent, (void *) d, NULL,
00249 is_probing ? 0 : HAL_LINUX_HOTPLUG_TIMEOUT);
00250
00251 free (parent_sysfs_path);
00252 }
00253
00261 static void
00262 visit_device_ide_got_parent (HalDevice * parent, void *data1, void *data2)
00263 {
00264 char *new_udi = NULL;
00265 HalDevice *new_d = NULL;
00266 HalDevice *d = (HalDevice *) data1;
00267
00268 if (parent != NULL) {
00269 ds_property_set_string (d, "info.parent", parent->udi);
00270 find_and_set_physical_device (d);
00271 ds_property_set_bool (d, "info.virtual", TRUE);
00272 }
00273
00274
00275
00276
00277 new_udi = rename_and_merge (d, ide_compute_udi, "ide");
00278 if (new_udi != NULL) {
00279 new_d = ds_device_find (new_udi);
00280 if (new_d != NULL) {
00281 ds_gdl_add (new_d);
00282 }
00283 }
00284 }
00285
00286
00290 void
00291 linux_ide_init ()
00292 {
00293 }
00294
00299 void
00300 linux_ide_detection_done ()
00301 {
00302 }
00303
00307 void
00308 linux_ide_shutdown ()
00309 {
00310 }
00311