]>
Commit | Line | Data |
---|---|---|
b390f610 DW |
1 | /* |
2 | * Intel(R) Matrix Storage Manager hardware and firmware support routines | |
3 | * | |
4 | * Copyright (C) 2008 Intel Corporation | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms and conditions of the GNU General Public License, | |
8 | * version 2, as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along with | |
16 | * this program; if not, write to the Free Software Foundation, Inc., | |
17 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | */ | |
19 | #include "mdadm.h" | |
20 | #include "platform-intel.h" | |
21 | #include "probe_roms.h" | |
22 | #include <stdio.h> | |
23 | #include <stdlib.h> | |
24 | #include <string.h> | |
25 | #include <unistd.h> | |
26 | #include <dirent.h> | |
27 | #include <fcntl.h> | |
28 | #include <sys/mman.h> | |
29 | #include <sys/types.h> | |
30 | #include <sys/stat.h> | |
fc13853f LM |
31 | #include <limits.h> |
32 | ||
9c747fa0 LM |
33 | static int devpath_to_ll(const char *dev_path, const char *entry, |
34 | unsigned long long *val); | |
35 | ||
fc13853f | 36 | static __u16 devpath_to_vendor(const char *dev_path); |
b390f610 | 37 | |
9bc4ae77 | 38 | static void free_sys_dev(struct sys_dev **list) |
b390f610 DW |
39 | { |
40 | while (*list) { | |
41 | struct sys_dev *next = (*list)->next; | |
42 | ||
43 | if ((*list)->path) | |
44 | free((*list)->path); | |
45 | free(*list); | |
46 | *list = next; | |
47 | } | |
48 | } | |
49 | ||
50 | struct sys_dev *find_driver_devices(const char *bus, const char *driver) | |
51 | { | |
52 | /* search sysfs for devices driven by 'driver' */ | |
5dbb8c8d | 53 | char path[292]; |
b390f610 DW |
54 | char link[256]; |
55 | char *c; | |
56 | DIR *driver_dir; | |
57 | struct dirent *de; | |
58 | struct sys_dev *head = NULL; | |
59 | struct sys_dev *list = NULL; | |
a8e5382a | 60 | enum sys_dev_type type; |
9c747fa0 | 61 | unsigned long long dev_id; |
6b781d33 | 62 | unsigned long long class; |
a8e5382a LM |
63 | |
64 | if (strcmp(driver, "isci") == 0) | |
65 | type = SYS_DEV_SAS; | |
66 | else if (strcmp(driver, "ahci") == 0) | |
67 | type = SYS_DEV_SATA; | |
68 | else | |
69 | type = SYS_DEV_UNKNOWN; | |
b390f610 DW |
70 | |
71 | sprintf(path, "/sys/bus/%s/drivers/%s", bus, driver); | |
72 | driver_dir = opendir(path); | |
73 | if (!driver_dir) | |
74 | return NULL; | |
75 | for (de = readdir(driver_dir); de; de = readdir(driver_dir)) { | |
5a1920f2 AW |
76 | int n; |
77 | ||
b390f610 DW |
78 | /* is 'de' a device? check that the 'subsystem' link exists and |
79 | * that its target matches 'bus' | |
80 | */ | |
81 | sprintf(path, "/sys/bus/%s/drivers/%s/%s/subsystem", | |
82 | bus, driver, de->d_name); | |
5a1920f2 | 83 | n = readlink(path, link, sizeof(link)); |
f21e18ca | 84 | if (n < 0 || n >= (int)sizeof(link)) |
b390f610 | 85 | continue; |
5a1920f2 | 86 | link[n] = '\0'; |
b390f610 DW |
87 | c = strrchr(link, '/'); |
88 | if (!c) | |
89 | continue; | |
90 | if (strncmp(bus, c+1, strlen(bus)) != 0) | |
91 | continue; | |
92 | ||
a8e5382a LM |
93 | sprintf(path, "/sys/bus/%s/drivers/%s/%s", |
94 | bus, driver, de->d_name); | |
95 | ||
96 | /* if it's not Intel device skip it. */ | |
97 | if (devpath_to_vendor(path) != 0x8086) | |
98 | continue; | |
99 | ||
9c747fa0 LM |
100 | if (devpath_to_ll(path, "device", &dev_id) != 0) |
101 | continue; | |
102 | ||
6b781d33 AP |
103 | if (devpath_to_ll(path, "class", &class) != 0) |
104 | continue; | |
105 | ||
b390f610 DW |
106 | /* start / add list entry */ |
107 | if (!head) { | |
503975b9 | 108 | head = xmalloc(sizeof(*head)); |
b390f610 DW |
109 | list = head; |
110 | } else { | |
503975b9 | 111 | list->next = xmalloc(sizeof(*head)); |
b390f610 DW |
112 | list = list->next; |
113 | } | |
114 | ||
115 | if (!list) { | |
116 | free_sys_dev(&head); | |
117 | break; | |
118 | } | |
119 | ||
9c747fa0 | 120 | list->dev_id = (__u16) dev_id; |
6b781d33 | 121 | list->class = (__u32) class; |
a8e5382a | 122 | list->type = type; |
e3635eee | 123 | list->path = realpath(path, NULL); |
b390f610 | 124 | list->next = NULL; |
a8e5382a LM |
125 | if ((list->pci_id = strrchr(list->path, '/')) != NULL) |
126 | list->pci_id++; | |
b390f610 | 127 | } |
2a17c77b | 128 | closedir(driver_dir); |
b390f610 DW |
129 | return head; |
130 | } | |
131 | ||
9c747fa0 | 132 | static struct sys_dev *intel_devices=NULL; |
9bc4ae77 | 133 | static time_t valid_time = 0; |
9c747fa0 | 134 | |
9c747fa0 LM |
135 | static int devpath_to_ll(const char *dev_path, const char *entry, unsigned long long *val) |
136 | { | |
137 | char path[strlen(dev_path) + strlen(entry) + 2]; | |
138 | int fd; | |
139 | int n; | |
140 | ||
141 | sprintf(path, "%s/%s", dev_path, entry); | |
142 | ||
143 | fd = open(path, O_RDONLY); | |
144 | if (fd < 0) | |
145 | return -1; | |
146 | n = sysfs_fd_get_ll(fd, val); | |
147 | close(fd); | |
148 | return n; | |
149 | } | |
150 | ||
fc13853f | 151 | static __u16 devpath_to_vendor(const char *dev_path) |
b390f610 DW |
152 | { |
153 | char path[strlen(dev_path) + strlen("/vendor") + 1]; | |
154 | char vendor[7]; | |
155 | int fd; | |
156 | __u16 id = 0xffff; | |
157 | int n; | |
158 | ||
159 | sprintf(path, "%s/vendor", dev_path); | |
160 | ||
161 | fd = open(path, O_RDONLY); | |
162 | if (fd < 0) | |
163 | return 0xffff; | |
164 | ||
165 | n = read(fd, vendor, sizeof(vendor)); | |
166 | if (n == sizeof(vendor)) { | |
167 | vendor[n - 1] = '\0'; | |
168 | id = strtoul(vendor, NULL, 16); | |
169 | } | |
170 | close(fd); | |
171 | ||
172 | return id; | |
173 | } | |
174 | ||
a8e5382a | 175 | struct sys_dev *find_intel_devices(void) |
b390f610 | 176 | { |
a8e5382a LM |
177 | struct sys_dev *ahci, *isci; |
178 | ||
9bc4ae77 N |
179 | if (valid_time > time(0) - 10) |
180 | return intel_devices; | |
181 | ||
182 | if (intel_devices) | |
183 | free_sys_dev(&intel_devices); | |
184 | ||
a8e5382a LM |
185 | isci = find_driver_devices("pci", "isci"); |
186 | ahci = find_driver_devices("pci", "ahci"); | |
187 | ||
188 | if (!ahci) { | |
189 | ahci = isci; | |
190 | } else { | |
191 | struct sys_dev *elem = ahci; | |
192 | while (elem->next) | |
193 | elem = elem->next; | |
194 | elem->next = isci; | |
195 | } | |
9bc4ae77 N |
196 | intel_devices = ahci; |
197 | valid_time = time(0); | |
198 | return intel_devices; | |
b390f610 DW |
199 | } |
200 | ||
3c8bfb5d | 201 | /* |
fc13853f | 202 | * PCI Expansion ROM Data Structure Format */ |
3c8bfb5d LM |
203 | struct pciExpDataStructFormat { |
204 | __u8 ver[4]; | |
205 | __u16 vendorID; | |
206 | __u16 deviceID; | |
6b781d33 | 207 | __u16 devListOffset; |
3c8bfb5d LM |
208 | } __attribute__ ((packed)); |
209 | ||
6b781d33 AP |
210 | struct devid_list { |
211 | __u16 devid; | |
212 | struct devid_list *next; | |
213 | }; | |
214 | ||
215 | struct orom_entry { | |
216 | struct imsm_orom orom; | |
217 | struct devid_list *devid_list; | |
218 | }; | |
219 | ||
220 | static struct orom_entry oroms[SYS_DEV_MAX]; | |
221 | ||
222 | const struct imsm_orom *get_orom_by_device_id(__u16 dev_id) | |
223 | { | |
224 | int i; | |
225 | struct devid_list *list; | |
226 | ||
227 | for (i = 0; i < SYS_DEV_MAX; i++) { | |
228 | for (list = oroms[i].devid_list; list; list = list->next) { | |
229 | if (list->devid == dev_id) | |
230 | return &oroms[i].orom; | |
231 | } | |
232 | } | |
233 | return NULL; | |
234 | } | |
235 | ||
236 | static const struct imsm_orom *add_orom(const struct imsm_orom *orom) | |
237 | { | |
238 | int i; | |
239 | ||
240 | for (i = 0; i < SYS_DEV_MAX; i++) { | |
241 | if (&oroms[i].orom == orom) | |
242 | return orom; | |
243 | if (oroms[i].orom.signature[0] == 0) { | |
244 | oroms[i].orom = *orom; | |
245 | return &oroms[i].orom; | |
246 | } | |
247 | } | |
248 | return NULL; | |
249 | } | |
250 | ||
251 | static void add_orom_device_id(const struct imsm_orom *orom, __u16 dev_id) | |
252 | { | |
253 | int i; | |
254 | struct devid_list *list; | |
255 | struct devid_list *prev = NULL; | |
256 | ||
257 | for (i = 0; i < SYS_DEV_MAX; i++) { | |
258 | if (&oroms[i].orom == orom) { | |
259 | for (list = oroms[i].devid_list; list; prev = list, list = list->next) { | |
260 | if (list->devid == dev_id) | |
261 | return; | |
262 | } | |
263 | list = xmalloc(sizeof(struct devid_list)); | |
264 | list->devid = dev_id; | |
265 | list->next = NULL; | |
266 | ||
267 | if (prev == NULL) | |
268 | oroms[i].devid_list = list; | |
269 | else | |
270 | prev->next = list; | |
271 | return; | |
272 | } | |
273 | } | |
274 | } | |
fc13853f | 275 | |
3c8bfb5d | 276 | static int scan(const void *start, const void *end, const void *data) |
b390f610 DW |
277 | { |
278 | int offset; | |
6b781d33 | 279 | const struct imsm_orom *imsm_mem = NULL; |
b390f610 | 280 | int len = (end - start); |
3c8bfb5d LM |
281 | struct pciExpDataStructFormat *ptr= (struct pciExpDataStructFormat *)data; |
282 | ||
9c747fa0 LM |
283 | if (data + 0x18 > end) { |
284 | dprintf("cannot find pciExpDataStruct \n"); | |
285 | return 0; | |
286 | } | |
287 | ||
3c8bfb5d LM |
288 | dprintf("ptr->vendorID: %lx __le16_to_cpu(ptr->deviceID): %lx \n", |
289 | (ulong) __le16_to_cpu(ptr->vendorID), | |
290 | (ulong) __le16_to_cpu(ptr->deviceID)); | |
291 | ||
6b781d33 | 292 | if (__le16_to_cpu(ptr->vendorID) != 0x8086) |
3c8bfb5d | 293 | return 0; |
b390f610 DW |
294 | |
295 | for (offset = 0; offset < len; offset += 4) { | |
6b781d33 AP |
296 | const void *mem = start + offset; |
297 | ||
298 | if ((memcmp(mem, IMSM_OROM_SIGNATURE, 4) == 0)) { | |
299 | imsm_mem = mem; | |
300 | break; | |
b390f610 DW |
301 | } |
302 | } | |
6b781d33 AP |
303 | |
304 | if (!imsm_mem) | |
305 | return 0; | |
306 | ||
307 | const struct imsm_orom *orom = add_orom(imsm_mem); | |
308 | ||
309 | if (ptr->devListOffset) { | |
310 | const __u16 *dev_list = (void *)ptr + ptr->devListOffset; | |
311 | int i; | |
312 | ||
313 | for (i = 0; dev_list[i] != 0; i++) | |
314 | add_orom_device_id(orom, dev_list[i]); | |
315 | } else { | |
316 | add_orom_device_id(orom, __le16_to_cpu(ptr->deviceID)); | |
317 | } | |
318 | ||
b390f610 DW |
319 | return 0; |
320 | } | |
321 | ||
6b781d33 | 322 | const struct imsm_orom *imsm_platform_test(struct sys_dev *hba) |
fc13853f | 323 | { |
6b781d33 AP |
324 | struct imsm_orom orom = { |
325 | .signature = IMSM_OROM_SIGNATURE, | |
326 | .rlc = IMSM_OROM_RLC_RAID0 | IMSM_OROM_RLC_RAID1 | | |
327 | IMSM_OROM_RLC_RAID10 | IMSM_OROM_RLC_RAID5, | |
328 | .sss = IMSM_OROM_SSS_4kB | IMSM_OROM_SSS_8kB | | |
329 | IMSM_OROM_SSS_16kB | IMSM_OROM_SSS_32kB | | |
330 | IMSM_OROM_SSS_64kB | IMSM_OROM_SSS_128kB | | |
331 | IMSM_OROM_SSS_256kB | IMSM_OROM_SSS_512kB | | |
332 | IMSM_OROM_SSS_1MB | IMSM_OROM_SSS_2MB, | |
333 | .dpa = IMSM_OROM_DISKS_PER_ARRAY, | |
334 | .tds = IMSM_OROM_TOTAL_DISKS, | |
335 | .vpa = IMSM_OROM_VOLUMES_PER_ARRAY, | |
336 | .vphba = IMSM_OROM_VOLUMES_PER_HBA | |
337 | }; | |
338 | orom.attr = orom.rlc | IMSM_OROM_ATTR_ChecksumVerify; | |
fc13853f LM |
339 | |
340 | if (check_env("IMSM_TEST_OROM_NORAID5")) { | |
6b781d33 | 341 | orom.rlc = IMSM_OROM_RLC_RAID0 | IMSM_OROM_RLC_RAID1 | |
fc13853f LM |
342 | IMSM_OROM_RLC_RAID10; |
343 | } | |
6b781d33 AP |
344 | if (check_env("IMSM_TEST_AHCI_EFI_NORAID5") && (hba->type == SYS_DEV_SAS)) { |
345 | orom.rlc = IMSM_OROM_RLC_RAID0 | IMSM_OROM_RLC_RAID1 | | |
fc13853f LM |
346 | IMSM_OROM_RLC_RAID10; |
347 | } | |
6b781d33 AP |
348 | if (check_env("IMSM_TEST_SCU_EFI_NORAID5") && (hba->type == SYS_DEV_SATA)) { |
349 | orom.rlc = IMSM_OROM_RLC_RAID0 | IMSM_OROM_RLC_RAID1 | | |
fc13853f | 350 | IMSM_OROM_RLC_RAID10; |
cceebc67 DW |
351 | } |
352 | ||
6b781d33 AP |
353 | const struct imsm_orom *ret = add_orom(&orom); |
354 | ||
355 | add_orom_device_id(ret, hba->dev_id); | |
356 | ||
357 | return ret; | |
fc13853f LM |
358 | } |
359 | ||
6b781d33 | 360 | static const struct imsm_orom *find_imsm_hba_orom(struct sys_dev *hba) |
fc13853f LM |
361 | { |
362 | unsigned long align; | |
363 | ||
6b781d33 AP |
364 | if (check_env("IMSM_TEST_OROM")) |
365 | return imsm_platform_test(hba); | |
fc13853f | 366 | |
fc13853f | 367 | /* return empty OROM capabilities in EFI test mode */ |
6b781d33 | 368 | if (check_env("IMSM_TEST_AHCI_EFI") || check_env("IMSM_TEST_SCU_EFI")) |
fc13853f LM |
369 | return NULL; |
370 | ||
9bc4ae77 | 371 | find_intel_devices(); |
9c747fa0 LM |
372 | |
373 | if (intel_devices == NULL) | |
b390f610 DW |
374 | return NULL; |
375 | ||
376 | /* scan option-rom memory looking for an imsm signature */ | |
969c2555 DW |
377 | if (check_env("IMSM_SAFE_OROM_SCAN")) |
378 | align = 2048; | |
379 | else | |
380 | align = 512; | |
381 | if (probe_roms_init(align) != 0) | |
b390f610 DW |
382 | return NULL; |
383 | probe_roms(); | |
9c747fa0 | 384 | /* ignore return value - True is returned if both adapater roms are found */ |
fc13853f | 385 | scan_adapter_roms(scan); |
b390f610 DW |
386 | probe_roms_exit(); |
387 | ||
6b781d33 | 388 | return get_orom_by_device_id(hba->dev_id); |
fc13853f LM |
389 | } |
390 | ||
1a901471 LM |
391 | #define GUID_STR_MAX 37 /* according to GUID format: |
392 | * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" */ | |
393 | ||
394 | #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \ | |
395 | ((struct efi_guid) \ | |
396 | {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \ | |
397 | (b) & 0xff, ((b) >> 8) & 0xff, \ | |
398 | (c) & 0xff, ((c) >> 8) & 0xff, \ | |
399 | (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }}) | |
fc13853f | 400 | |
5a6baf66 LM |
401 | #define SYS_EFI_VAR_PATH "/sys/firmware/efi/vars" |
402 | #define SCU_PROP "RstScuV" | |
403 | #define AHCI_PROP "RstSataV" | |
404 | ||
405 | #define VENDOR_GUID \ | |
406 | EFI_GUID(0x193dfefa, 0xa445, 0x4302, 0x99, 0xd8, 0xef, 0x3a, 0xad, 0x1a, 0x04, 0xc6) | |
407 | ||
6b781d33 | 408 | #define PCI_CLASS_RAID_CNTRL 0x010400 |
5a6baf66 | 409 | |
aae4c111 | 410 | int read_efi_variable(void *buffer, ssize_t buf_size, char *variable_name, struct efi_guid guid) |
5a6baf66 | 411 | { |
5a6baf66 LM |
412 | char path[PATH_MAX]; |
413 | char buf[GUID_STR_MAX]; | |
aae4c111 HCP |
414 | int dfd; |
415 | ssize_t n, var_data_len; | |
416 | ||
417 | snprintf(path, PATH_MAX, "%s/%s-%s/size", SYS_EFI_VAR_PATH, variable_name, guid_str(buf, guid)); | |
418 | ||
419 | dprintf("EFI VAR: path=%s\n", path); | |
420 | /* get size of variable data */ | |
421 | dfd = open(path, O_RDONLY); | |
422 | if (dfd < 0) | |
423 | return 1; | |
424 | ||
425 | n = read(dfd, &buf, sizeof(buf)); | |
426 | close(dfd); | |
427 | if (n < 0) | |
428 | return 1; | |
429 | buf[n] = '\0'; | |
430 | ||
431 | errno = 0; | |
432 | var_data_len = strtoul(buf, NULL, 16); | |
433 | if ((errno == ERANGE && (var_data_len == LONG_MAX)) | |
5d500228 | 434 | || (errno != 0 && var_data_len == 0)) |
aae4c111 HCP |
435 | return 1; |
436 | ||
437 | /* get data */ | |
438 | snprintf(path, PATH_MAX, "%s/%s-%s/data", SYS_EFI_VAR_PATH, variable_name, guid_str(buf, guid)); | |
439 | ||
440 | dprintf("EFI VAR: path=%s\n", path); | |
441 | dfd = open(path, O_RDONLY); | |
442 | if (dfd < 0) | |
443 | return 1; | |
444 | ||
445 | n = read(dfd, buffer, buf_size); | |
446 | close(dfd); | |
447 | if (n != var_data_len || n < buf_size) { | |
448 | return 1; | |
449 | } | |
450 | ||
451 | return 0; | |
452 | } | |
5a6baf66 | 453 | |
6b781d33 | 454 | const struct imsm_orom *find_imsm_efi(struct sys_dev *hba) |
aae4c111 | 455 | { |
6b781d33 AP |
456 | struct imsm_orom orom; |
457 | const struct imsm_orom *ret; | |
5a6baf66 | 458 | |
6b781d33 AP |
459 | if (check_env("IMSM_TEST_AHCI_EFI") || check_env("IMSM_TEST_SCU_EFI")) |
460 | return imsm_platform_test(hba); | |
5a6baf66 | 461 | |
5a6baf66 | 462 | /* OROM test is set, return that there is no EFI capabilities */ |
aae4c111 | 463 | if (check_env("IMSM_TEST_OROM")) |
5a6baf66 | 464 | return NULL; |
5a6baf66 | 465 | |
6b781d33 | 466 | if (hba->type == SYS_DEV_SATA && hba->class != PCI_CLASS_RAID_CNTRL) |
5a6baf66 | 467 | return NULL; |
aae4c111 | 468 | |
6b781d33 AP |
469 | if (read_efi_variable(&orom, sizeof(orom), hba->type == SYS_DEV_SAS ? SCU_PROP : AHCI_PROP, VENDOR_GUID)) |
470 | return NULL; | |
5a6baf66 | 471 | |
6b781d33 AP |
472 | ret = add_orom(&orom); |
473 | add_orom_device_id(ret, hba->dev_id); | |
474 | ||
475 | return ret; | |
fc13853f LM |
476 | } |
477 | ||
6b781d33 | 478 | const struct imsm_orom *find_imsm_capability(struct sys_dev *hba) |
fc13853f | 479 | { |
6b781d33 AP |
480 | const struct imsm_orom *cap = get_orom_by_device_id(hba->dev_id); |
481 | ||
482 | if (cap) | |
483 | return cap; | |
fc13853f | 484 | |
6b781d33 | 485 | if ((cap = find_imsm_efi(hba)) != NULL) |
5a6baf66 | 486 | return cap; |
6b781d33 | 487 | if ((cap = find_imsm_hba_orom(hba)) != NULL) |
fc13853f | 488 | return cap; |
b390f610 DW |
489 | return NULL; |
490 | } | |
25921536 DW |
491 | |
492 | char *devt_to_devpath(dev_t dev) | |
493 | { | |
37f0e1e0 | 494 | char device[46]; |
25921536 DW |
495 | |
496 | sprintf(device, "/sys/dev/block/%d:%d/device", major(dev), minor(dev)); | |
e3635eee | 497 | return realpath(device, NULL); |
25921536 DW |
498 | } |
499 | ||
a8e5382a | 500 | char *diskfd_to_devpath(int fd) |
25921536 DW |
501 | { |
502 | /* return the device path for a disk, return NULL on error or fd | |
503 | * refers to a partition | |
504 | */ | |
505 | struct stat st; | |
506 | ||
507 | if (fstat(fd, &st) != 0) | |
508 | return NULL; | |
509 | if (!S_ISBLK(st.st_mode)) | |
510 | return NULL; | |
511 | ||
512 | return devt_to_devpath(st.st_rdev); | |
513 | } | |
514 | ||
515 | int path_attached_to_hba(const char *disk_path, const char *hba_path) | |
516 | { | |
517 | int rc; | |
518 | ||
fc13853f LM |
519 | if (check_env("IMSM_TEST_AHCI_DEV") || |
520 | check_env("IMSM_TEST_SCU_DEV")) { | |
521 | return 1; | |
522 | } | |
523 | ||
25921536 DW |
524 | if (!disk_path || !hba_path) |
525 | return 0; | |
a8e5382a | 526 | dprintf("hba: %s - disk: %s\n", hba_path, disk_path); |
25921536 DW |
527 | if (strncmp(disk_path, hba_path, strlen(hba_path)) == 0) |
528 | rc = 1; | |
529 | else | |
530 | rc = 0; | |
531 | ||
532 | return rc; | |
533 | } | |
534 | ||
535 | int devt_attached_to_hba(dev_t dev, const char *hba_path) | |
536 | { | |
537 | char *disk_path = devt_to_devpath(dev); | |
538 | int rc = path_attached_to_hba(disk_path, hba_path); | |
539 | ||
540 | if (disk_path) | |
541 | free(disk_path); | |
542 | ||
543 | return rc; | |
544 | } | |
545 | ||
546 | int disk_attached_to_hba(int fd, const char *hba_path) | |
547 | { | |
548 | char *disk_path = diskfd_to_devpath(fd); | |
549 | int rc = path_attached_to_hba(disk_path, hba_path); | |
550 | ||
551 | if (disk_path) | |
552 | free(disk_path); | |
553 | ||
554 | return rc; | |
555 | } |