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 #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
00063
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
00074 hal_device_property_set_string (d, "info.product", "SCSI Device");
00075
00076
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