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* ide_compute_udi(HalDevice* d, int append_num)
00061 {
00062 char* format;
00063 static char buf[256];
00064
00065 if( append_num==-1 )
00066 format = "/org/freedesktop/Hal/devices/ide_%d_%d";
00067 else
00068 format = "/org/freedesktop/Hal/devices/ide_%d_%d-%d";
00069
00070 snprintf(buf, 256, format,
00071 ds_property_get_int(d, "ide.channel"),
00072 ds_property_get_int(d, "ide.sub_channel"),
00073 append_num);
00074 return buf;
00075 }
00076
00077
00087 static char* ide_host_compute_udi(HalDevice* d, int append_num)
00088 {
00089 char* format;
00090 static char buf[256];
00091
00092 if( append_num==-1 )
00093 format = "/org/freedesktop/Hal/devices/ide_host_%d";
00094 else
00095 format = "/org/freedesktop/Hal/devices/ide_host_%d-%d";
00096
00097 snprintf(buf, 256, format,
00098 ds_property_get_int(d, "ide_host.number"),
00099 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 visit_device_ide_host(const char* path, struct sysfs_device *device)
00116 {
00117 HalDevice* d;
00118 int ide_host_number;
00119 char* parent_sysfs_path;
00120
00121
00122 if( sscanf(device->bus_id, "ide%d", &ide_host_number)!=1 )
00123 {
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", "Primary IDE channel");
00140 else if( ide_host_number==1 )
00141 ds_property_set_string(d, "info.product", "Secondary IDE channel");
00142 else
00143 ds_property_set_string(d, "info.product", "IDE channel");
00144
00145
00146 parent_sysfs_path = get_parent_sysfs_path(path);
00147
00148
00149
00150
00151
00152 ds_device_async_find_by_key_value_string("linux.sysfs_path_device",
00153 parent_sysfs_path,
00154 TRUE,
00155 visit_device_ide_host_got_parent,
00156 (void*) d, NULL,
00157 is_probing ? 0 :
00158 HAL_LINUX_HOTPLUG_TIMEOUT);
00159
00160 free(parent_sysfs_path);
00161 }
00162
00170 static void 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 {
00179 ds_property_set_string(d, "info.parent", parent->udi);
00180 find_and_set_physical_device(d);
00181 ds_property_set_bool(d, "info.virtual", TRUE);
00182 }
00183
00184
00185
00186
00187 new_udi = rename_and_merge(d, ide_host_compute_udi, "ide_host");
00188 if( new_udi!=NULL )
00189 {
00190 new_d = ds_device_find(new_udi);
00191 if( new_d!=NULL )
00192 {
00193 ds_gdl_add(new_d);
00194 }
00195 }
00196 }
00197
00198
00199
00200 static void visit_device_ide_got_parent(HalDevice* parent,
00201 void* data1, void* data2);
00202
00211 void visit_device_ide(const char* path, struct sysfs_device *device)
00212 {
00213 HalDevice* d;
00214 int channel;
00215 int sub_channel;
00216 char* parent_sysfs_path;
00217
00218
00219 if( sscanf(device->bus_id, "%d.%d", &channel, &sub_channel)!=2 )
00220 {
00221 HAL_ERROR(("Couldn't find channel and sub_channel in %s\n",
00222 device->bus_id));
00223 return;
00224 }
00225
00226
00227
00228 d = ds_device_new();
00229 ds_property_set_string(d, "info.bus", "ide");
00230 ds_property_set_string(d, "linux.sysfs_path", path);
00231 ds_property_set_string(d, "linux.sysfs_path_device", path);
00232 ds_property_set_int(d, "ide.channel", channel);
00233 ds_property_set_int(d, "ide.sub_channel", sub_channel);
00234
00235
00236 if( sub_channel==0 )
00237 ds_property_set_string(d, "info.product", "Master IDE Interface");
00238 else
00239 ds_property_set_string(d, "info.product", "Slave IDE Interface");
00240
00241 parent_sysfs_path = get_parent_sysfs_path(path);
00242
00243
00244
00245
00246
00247 ds_device_async_find_by_key_value_string("linux.sysfs_path_device",
00248 parent_sysfs_path,
00249 TRUE,
00250 visit_device_ide_got_parent,
00251 (void*) d, NULL,
00252 is_probing ? 0 :
00253 HAL_LINUX_HOTPLUG_TIMEOUT);
00254
00255 free(parent_sysfs_path);
00256 }
00257
00265 static void visit_device_ide_got_parent(HalDevice* parent,
00266 void* data1, void* data2)
00267 {
00268 char* new_udi = NULL;
00269 HalDevice* new_d = NULL;
00270 HalDevice* d = (HalDevice*) data1;
00271
00272 if( parent!=NULL )
00273 {
00274 ds_property_set_string(d, "info.parent", parent->udi);
00275 find_and_set_physical_device(d);
00276 ds_property_set_bool(d, "info.virtual", TRUE);
00277 }
00278
00279
00280
00281
00282 new_udi = rename_and_merge(d, ide_compute_udi, "ide");
00283 if( new_udi!=NULL )
00284 {
00285 new_d = ds_device_find(new_udi);
00286 if( new_d!=NULL )
00287 {
00288 ds_gdl_add(new_d);
00289 }
00290 }
00291 }
00292
00293
00297 void linux_ide_init()
00298 {
00299 }
00300
00305 void linux_ide_detection_done()
00306 {
00307 }
00308
00312 void linux_ide_shutdown()
00313 {
00314 }
00315