00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <assert.h>
00035
00036 #include <stdio.h>
00037 #include <string.h>
00038
00039 #include <discover.h>
00040 #include <discover-conf.h>
00041 #include <discover-xml.h>
00042 #include <sysdep.h>
00043
00044 #include "device.h"
00045 #include "utils.h"
00046
00047
00049 typedef discover_sysdep_data_t *(raw_sysdep_function_t)(void);
00050
00051 static raw_sysdep_function_t *raw_map[] = {
00052 _discover_get_ata_raw,
00053 _discover_get_pci_raw,
00054 _discover_get_pcmcia_raw,
00055 _discover_get_scsi_raw,
00056 _discover_get_usb_raw
00057 };
00058
00059
00060
00061
00062
00063
00065 discover_sysdep_data_t *
00066 _discover_sysdep_data_new(void)
00067 {
00068 discover_sysdep_data_t *node =
00069 _discover_xmalloc(sizeof(discover_sysdep_data_t));
00070 node->busclass = NULL;
00071 node->vendor = NULL;
00072 node->model = NULL;
00073 node->next = NULL;
00074 return node;
00075 }
00076
00078 void
00079 _discover_free_sysdep_data(discover_sysdep_data_t *head)
00080 {
00081 discover_sysdep_data_t *node;
00082
00083 while (head) {
00084 node = head->next;
00085 if (head->vendor) {
00086 free(head->vendor);
00087 }
00088 if (head->model) {
00089 free(head->model);
00090 }
00091 if (head->busclass) {
00092 free(head->busclass);
00093 }
00094 free(head);
00095 head = node;
00096 }
00097 }
00098
00099
00100
00101
00102 static discover_device_t *devices[BUS_COUNT];
00103
00104 discover_device_t *
00105 discover_get_devices(discover_bus_t bus, discover_error_t *status)
00106 {
00107 discover_device_t *device, *last;
00108 discover_device_t *xml_devices;
00109 discover_bus_map_t *busmap;
00110 discover_sysdep_data_t *head, *node;
00111
00112 assert(status);
00113
00114 status->code = DISCOVER_SUCCESS;
00115 device = last = NULL;
00116
00117 busmap = discover_conf_get_bus_map(bus, status);
00118 if (status->code != 0) {
00119 return NULL;
00120 }
00121
00122 if (busmap->scan_never) {
00123 status->code = DISCOVER_EBUSDISABLED;
00124 return NULL;
00125 }
00126
00127 if (devices[bus]) {
00128 return devices[bus];
00129 }
00130
00131 xml_devices = discover_xml_get_devices(bus, status);
00132 if (!xml_devices) {
00133 return NULL;
00134 }
00135
00136
00137
00138
00139 if (busmap->get_raw) {
00140 head = node = busmap->get_raw();
00141 } else {
00142 head = node = raw_map[bus]();
00143 }
00144
00145 while (node) {
00146 device =
00147 discover_xml_get_matching_devices(xml_devices, node->vendor,
00148 node->model, status);
00149
00150 if (!device) {
00151 device = discover_device_new();
00152 device->model_id = strdup(node->model);
00153 device->vendor_id = strdup(node->vendor);
00154 }
00155
00156 if (last) {
00157 last->next = device;
00158 last = device;
00159 } else {
00160 devices[bus] = last = device;
00161 }
00162
00163 node = node->next;
00164 }
00165
00166 _discover_free_sysdep_data(head);
00167
00168 return devices[bus];
00169 }
00170
00171 void
00172 discover_free_devices(void)
00173 {
00174 int i;
00175
00176 for (i = 0; i < BUS_COUNT; i++) {
00177 discover_device_free(devices[i], 0);
00178 devices[i] = NULL;
00179 }
00180 }
00181
00182
00183
00184
00185
00186
00187
00188