128 |
|
#ifdef ALLBSD |
129 |
|
nummnt=getmntinfo(&mp , MNT_LOCAL); |
130 |
|
if (nummnt<=0){ |
131 |
+ |
sg_set_error(SG_ERROR_GETMNTINFO, NULL); |
132 |
|
return NULL; |
133 |
|
} |
134 |
|
for(;nummnt--; mp++){ |
137 |
|
|
138 |
|
#if defined(LINUX) || defined(CYGWIN) |
139 |
|
if ((f=setmntent("/etc/mtab", "r" ))==NULL){ |
140 |
+ |
sg_set_error(SG_ERROR_SETMNTENT, NULL); |
141 |
|
return NULL; |
142 |
|
} |
143 |
|
|
151 |
|
|
152 |
|
#ifdef SOLARIS |
153 |
|
if ((f=fopen("/etc/mnttab", "r" ))==NULL){ |
154 |
+ |
sg_set_error(SG_ERROR_OPEN, "/etc/mnttab"); |
155 |
|
return NULL; |
156 |
|
} |
157 |
|
while((getmntent(f, &mp)) == 0){ |
253 |
|
|
254 |
|
} |
255 |
|
|
256 |
+ |
int sg_fs_compare_device_name(const void *va, const void *vb) { |
257 |
+ |
const sg_fs_stats *a = (const sg_fs_stats *)va; |
258 |
+ |
const sg_fs_stats *b = (const sg_fs_stats *)vb; |
259 |
+ |
|
260 |
+ |
return strcmp(a->device_name, b->device_name); |
261 |
+ |
} |
262 |
+ |
|
263 |
+ |
int sg_fs_compare_mnt_point(const void *va, const void *vb) { |
264 |
+ |
const sg_fs_stats *a = (const sg_fs_stats *)va; |
265 |
+ |
const sg_fs_stats *b = (const sg_fs_stats *)vb; |
266 |
+ |
|
267 |
+ |
return strcmp(a->mnt_point, b->mnt_point); |
268 |
+ |
} |
269 |
+ |
|
270 |
|
static void diskio_stat_init(sg_disk_io_stats *d) { |
271 |
|
d->disk_name = NULL; |
272 |
|
} |
344 |
|
|
345 |
|
size = sizeof(diskcount); |
346 |
|
if (sysctl(mib, MIBSIZE, &diskcount, &size, NULL, 0) < 0) { |
347 |
+ |
sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKCOUNT"); |
348 |
|
return NULL; |
349 |
|
} |
350 |
|
|
352 |
|
mib[1] = HW_DISKNAMES; |
353 |
|
|
354 |
|
if (sysctl(mib, MIBSIZE, NULL, &size, NULL, 0) < 0) { |
355 |
+ |
sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKNAMES"); |
356 |
|
return NULL; |
357 |
|
} |
358 |
|
|
362 |
|
} |
363 |
|
|
364 |
|
if (sysctl(mib, MIBSIZE, disknames, &size, NULL, 0) < 0) { |
365 |
+ |
sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKNAMES"); |
366 |
|
return NULL; |
367 |
|
} |
368 |
|
|
381 |
|
#endif |
382 |
|
|
383 |
|
if (sysctl(mib, MIBSIZE, NULL, &size, NULL, 0) < 0) { |
384 |
+ |
sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKSTATS"); |
385 |
|
return NULL; |
386 |
|
} |
387 |
|
|
397 |
|
} |
398 |
|
|
399 |
|
if (sysctl(mib, MIBSIZE, stats, &size, NULL, 0) < 0) { |
400 |
+ |
sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKSTATS"); |
401 |
|
return NULL; |
402 |
|
} |
403 |
|
|
410 |
|
rbytes = stats[i].dk_rbytes; |
411 |
|
wbytes = stats[i].dk_wbytes; |
412 |
|
#else |
413 |
< |
/* Before 1.7, NetBSD merged reads and writes. */ |
413 |
> |
/* Before 2.0, NetBSD merged reads and writes. */ |
414 |
|
rbytes = wbytes = stats[i].dk_bytes; |
415 |
|
#endif |
416 |
|
#else |
417 |
+ |
#ifdef HAVE_DS_RBYTES |
418 |
+ |
rbytes = stats[i].ds_rbytes; |
419 |
+ |
wbytes = stats[i].ds_wbytes; |
420 |
+ |
#else |
421 |
+ |
/* Before 3.5, OpenBSD merged reads and writes */ |
422 |
|
rbytes = wbytes = stats[i].ds_bytes; |
423 |
|
#endif |
424 |
+ |
#endif |
425 |
|
|
426 |
|
/* Don't keep stats for disks that have never been used. */ |
427 |
|
if (rbytes == 0 && wbytes == 0) { |
463 |
|
stats_init = 1; |
464 |
|
} |
465 |
|
#ifdef FREEBSD5 |
466 |
< |
if ((devstat_getdevs(NULL, &stats)) < 0) return NULL; |
466 |
> |
if ((devstat_getdevs(NULL, &stats)) < 0) { |
467 |
> |
sg_set_error(SG_ERROR_DEVSTAT_GETDEVS, NULL); |
468 |
> |
return NULL; |
469 |
> |
} |
470 |
|
/* Not aware of a get all devices, so i said 999. If we ever |
471 |
|
* find a machine with more than 999 disks, then i'll change |
472 |
|
* this number :) |
473 |
|
*/ |
474 |
< |
if (devstat_selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, stats.dinfo->generation, stats.dinfo->devices, stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, 999, 1) < 0) return NULL; |
474 |
> |
if (devstat_selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, stats.dinfo->generation, stats.dinfo->devices, stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, 999, 1) < 0) { |
475 |
> |
sg_set_error(SG_ERROR_DEVSTAT_SELECTDEVS, NULL); |
476 |
> |
return NULL; |
477 |
> |
} |
478 |
|
#else |
479 |
< |
if ((getdevs(&stats)) < 0) return NULL; |
479 |
> |
if ((getdevs(&stats)) < 0) { |
480 |
> |
sg_set_error(SG_ERROR_DEVSTAT_GETDEVS, NULL); |
481 |
> |
return NULL; |
482 |
> |
} |
483 |
|
/* Not aware of a get all devices, so i said 999. If we ever |
484 |
|
* find a machine with more than 999 disks, then i'll change |
485 |
|
* this number :) |
486 |
|
*/ |
487 |
< |
if (selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, stats.dinfo->generation, stats.dinfo->devices, stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, 999, 1) < 0) return NULL; |
487 |
> |
if (selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, stats.dinfo->generation, stats.dinfo->devices, stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, 999, 1) < 0) { |
488 |
> |
sg_set_error(SG_ERROR_DEVSTAT_SELECTDEVS, NULL); |
489 |
> |
return NULL; |
490 |
> |
} |
491 |
|
#endif |
492 |
|
|
493 |
|
for(counter=0;counter<stats.dinfo->numdevs;counter++){ |
517 |
|
#endif |
518 |
|
if(diskio_stats_ptr->disk_name!=NULL) free(diskio_stats_ptr->disk_name); |
519 |
|
if (asprintf((&diskio_stats_ptr->disk_name), "%s%d", dev_ptr->device_name, dev_ptr->unit_number) == -1) { |
520 |
+ |
sg_set_error(SG_ERROR_ASPRINTF, NULL); |
521 |
|
return NULL; |
522 |
|
} |
523 |
|
diskio_stats_ptr->systime=time(NULL); |
529 |
|
#endif |
530 |
|
#ifdef SOLARIS |
531 |
|
if ((kc = kstat_open()) == NULL) { |
532 |
+ |
sg_set_error(SG_ERROR_KSTAT_OPEN, NULL); |
533 |
|
return NULL; |
534 |
|
} |
535 |
|
|
698 |
|
#endif |
699 |
|
|
700 |
|
#ifdef CYGWIN |
701 |
+ |
sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin"); |
702 |
|
return NULL; |
703 |
|
#endif |
704 |
|
|
769 |
|
|
770 |
|
*entries = diff_count; |
771 |
|
return diff; |
772 |
+ |
} |
773 |
+ |
|
774 |
+ |
int sg_disk_io_compare_name(const void *va, const void *vb) { |
775 |
+ |
const sg_disk_io_stats *a = (const sg_disk_io_stats *)va; |
776 |
+ |
const sg_disk_io_stats *b = (const sg_disk_io_stats *)vb; |
777 |
+ |
|
778 |
+ |
return strcmp(a->disk_name, b->disk_name); |
779 |
|
} |
780 |
|
|