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

linux_ide.c

00001 /***************************************************************************
00002  * CVSID: $Id: linux_ide.c,v 1.6 2004/03/03 17:56:56 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 *
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 /* fwd decl */
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     /*printf("ide_host: %s\n", path); */
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     /*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",
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     /* Find parent; this happens asynchronously as our parent might
00151      * be added later. If we are probing this can't happen so the
00152      * timeout is set to zero in that event..
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     /* Compute a proper UDI (unique device id) and try to locate a
00184      * persistent unplugged device or simple add this new device...
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 /* fwd decl */
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     /*printf("ide: %s\n", path); */
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     /*printf("channel=%d, sub_channel=%d\n", channel, sub_channel); */
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     /* guestimate product name */
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     /* Find parent; this happens asynchronously as our parent might
00243      * be added later. If we are probing this can't happen so the
00244      * timeout is set to zero in that event..
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     /* Compute a proper UDI (unique device id) and try to locate a 
00275      * persistent unplugged device or simple add this new device...
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 

Generated on Thu Mar 11 21:32:22 2004 for HAL by doxygen 1.3.6-20040222