Main Page | Modules | Data Structures | File List | Data Fields | Related Pages

linux_ide.c

00001 /***************************************************************************
00002  * CVSID: $Id: linux_ide.c,v 1.5 2004/01/02 12:11:24 david Exp $
00003  *
00004  * hal_ide.c : IDE functions for sysfs-agent on Linux 2.6
00005  *
00006  * Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
00007  *
00008  * Licensed under the Academic Free License version 2.0
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 /* fwd decl */
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     /*printf("ide_host: %s\n", path);*/
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     /*printf("ide_host_number=%d\n", ide_host_number);*/
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     /* guestimate product name */
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     /* Find parent; this happens asynchronously as our parent might
00149      * be added later. If we are probing this can't happen so the
00150      * timeout is set to zero in that event..
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     /* Compute a proper UDI (unique device id) and try to locate a persistent
00185      * unplugged device or simple add this new device...
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 /* fwd decl */
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     /*printf("ide: %s\n", path);*/
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     /*printf("channel=%d, sub_channel=%d\n", channel, sub_channel);*/
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     /* guestimate product name */
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     /* Find parent; this happens asynchronously as our parent might
00244      * be added later. If we are probing this can't happen so the
00245      * timeout is set to zero in that event..
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     /* Compute a proper UDI (unique device id) and try to locate a persistent
00280      * unplugged device or simple add this new device...
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 

Generated on Sat Feb 7 22:11:47 2004 for HAL by doxygen 1.3.5