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

scsi_device_class_device.c

00001 /***************************************************************************
00002  * CVSID: $Id: scsi_device_class_device.c,v 1.6 2004/04/12 20:11:51 joe Exp $
00003  *
00004  * SCSI device device class
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 #include <limits.h>
00039 
00040 #include "../logger.h"
00041 #include "../device_store.h"
00042 #include "class_device.h"
00043 #include "common.h"
00044 
00053 static void 
00054 scsi_device_class_pre_process (ClassDeviceHandler *self,
00055                    HalDevice *d,
00056                    const char *sysfs_path,
00057                    struct sysfs_class_device *class_device)
00058 {
00059     const char *last_elem;
00060     int host_num, bus_num, target_num, lun_num;
00061 
00062     /* Sets last_elem to 1:2:3:4 in 
00063      * path=/sys/class/scsi_host/host23/1:2:3:4 
00064      */
00065     last_elem = get_last_element (sysfs_path);
00066     sscanf (last_elem, "%d:%d:%d:%d",
00067         &host_num, &bus_num, &target_num, &lun_num);
00068     hal_device_property_set_int (d, "scsi_device.host", host_num);
00069     hal_device_property_set_int (d, "scsi_device.bus", bus_num);
00070     hal_device_property_set_int (d, "scsi_device.target", target_num);
00071     hal_device_property_set_int (d, "scsi_device.lun", lun_num);
00072 
00073     /* guestimate product name */
00074     hal_device_property_set_string (d, "info.product", "SCSI Device");
00075 
00076     /* this is a virtual device */
00077     hal_device_property_set_bool (d, "info.virtual", TRUE);
00078 }
00079 
00080 static char *
00081 scsi_device_class_compute_udi (HalDevice * d, int append_num)
00082 {
00083     const char *format;
00084     static char buf[256];
00085 
00086     if (append_num == -1)
00087         format =
00088             "/org/freedesktop/Hal/devices/scsi_device_%d_%d_%d_%d";
00089     else
00090         format =
00091             "/org/freedesktop/Hal/devices/scsi_device_%d_%d_%d_%d-%d";
00092 
00093     snprintf (buf, 256, format,
00094           hal_device_property_get_int (d, "scsi_device.host"),
00095           hal_device_property_get_int (d, "scsi_device.bus"),
00096           hal_device_property_get_int (d, "scsi_device.target"),
00097           hal_device_property_get_int (d, "scsi_device.lun"),
00098           append_num);
00099 
00100     return buf;
00101 }
00102 
00104 ClassDeviceHandler scsi_device_class_handler = {
00105     class_device_init,                  
00106     class_device_detection_done,        
00107     class_device_shutdown,              
00108     class_device_tick,                  
00109     class_device_accept,                
00110     class_device_visit,                 
00111     class_device_removed,               
00112     class_device_udev_event,            
00113     class_device_get_device_file_target,
00114     scsi_device_class_pre_process,      
00115     class_device_post_merge,            
00116     class_device_got_udi,               
00117     scsi_device_class_compute_udi,      
00118     "scsi_device",                      
00119     "scsi_device",                      
00120     FALSE,                              
00121     FALSE                               
00122 };
00123 

Generated on Sat Apr 24 19:57:45 2004 for HAL by doxygen 1.3.6-20040222