From 2f522e306497a85c97fef585c276aa38064e9baf Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 17 Mar 2025 13:52:40 +0100 Subject: Refactor check_ide_smart --- plugins/Makefile.am | 1 + plugins/check_ide_smart.c | 155 ++++++++++++++++++++----------------- plugins/check_ide_smart.d/config.h | 15 ++++ 3 files changed, 101 insertions(+), 70 deletions(-) create mode 100644 plugins/check_ide_smart.d/config.h diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 30ca63d1..8983f25c 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -55,6 +55,7 @@ EXTRA_DIST = t \ check_hpjd.d \ check_game.d \ check_radius.d \ + check_ide_smart.d \ check_time.d \ check_nagios.d \ check_dbi.d \ diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c index 16fe3d01..b13c7101 100644 --- a/plugins/check_ide_smart.c +++ b/plugins/check_ide_smart.c @@ -39,6 +39,8 @@ const char *email = "devel@monitoring-plugins.org"; #include "common.h" #include "utils.h" +#include "check_ide_smart.d/config.h" +#include "states.h" static void print_help(void); void print_usage(void); @@ -46,6 +48,7 @@ void print_usage(void); #include #include #include + #ifdef __linux__ # include # include @@ -133,25 +136,20 @@ enum SmartCommand { SMART_CMD_AUTO_OFFLINE }; -static char *get_offline_text(int); -static int smart_read_values(int, values_t *); -static int nagios(values_t *, thresholds_t *); -static void print_value(value_t *, threshold_t *); -static void print_values(values_t *, thresholds_t *); -static int smart_cmd_simple(int, enum SmartCommand, uint8_t, bool); -static int smart_read_thresholds(int, thresholds_t *); -static bool verbose = false; - -int main(int argc, char *argv[]) { - char *device = NULL; - int o; - int longindex; - int retval = 0; - - thresholds_t thresholds; - values_t values; - int fd; - +static char *get_offline_text(int /*status*/); +static int smart_read_values(int /*fd*/, values_t * /*values*/); +static mp_state_enum compare_values_and_thresholds(values_t * /*p*/, thresholds_t * /*t*/); +static void print_value(value_t * /*p*/, threshold_t * /*t*/); +static void print_values(values_t * /*p*/, thresholds_t * /*t*/); +static mp_state_enum smart_cmd_simple(int /*fd*/, enum SmartCommand /*command*/, uint8_t /*val0*/, bool /*show_error*/); +static int smart_read_thresholds(int /*fd*/, thresholds_t * /*thresholds*/); +static int verbose = 0; + +typedef struct { + int errorcode; + check_ide_smart_config config; +} check_ide_smart_config_wrapper; +static check_ide_smart_config_wrapper process_arguments(int argc, char **argv) { static struct option longopts[] = {{"device", required_argument, 0, 'd'}, {"immediate", no_argument, 0, 'i'}, {"quiet-check", no_argument, 0, 'q'}, @@ -162,24 +160,22 @@ int main(int argc, char *argv[]) { {"version", no_argument, 0, 'V'}, {0, 0, 0, 0}}; - /* Parse extra opts if any */ - argv = np_extra_opts(&argc, argv, progname); - - setlocale(LC_ALL, ""); - bindtextdomain(PACKAGE, LOCALEDIR); - textdomain(PACKAGE); + check_ide_smart_config_wrapper result = { + .errorcode = OK, + .config = check_ide_smart_init(), + }; while (true) { + int longindex = 0; + int option_index = getopt_long(argc, argv, "+d:iq10nhVv", longopts, &longindex); - o = getopt_long(argc, argv, "+d:iq10nhVv", longopts, &longindex); - - if (o == -1 || o == EOF || o == 1) { + if (option_index == -1 || option_index == EOF || option_index == 1) { break; } - switch (o) { + switch (option_index) { case 'd': - device = optarg; + result.config.device = optarg; break; case 'q': fprintf(stderr, "%s\n", _("DEPRECATION WARNING: the -q switch (quiet output) is no longer \"quiet\".")); @@ -189,63 +185,82 @@ int main(int argc, char *argv[]) { case '1': case '0': printf("%s\n", _("SMART commands are broken and have been disabled (See Notes in --help).")); - return STATE_CRITICAL; + result.errorcode = ERROR; + return result; break; case 'n': fprintf(stderr, "%s\n", _("DEPRECATION WARNING: the -n switch (Nagios-compatible output) is now the")); fprintf(stderr, "%s\n", _("default and will be removed from future releases.")); break; case 'v': /* verbose */ - verbose = true; + verbose++; break; case 'h': print_help(); - return STATE_UNKNOWN; + exit(STATE_UNKNOWN); case 'V': print_revision(progname, NP_VERSION); - return STATE_UNKNOWN; + exit(STATE_UNKNOWN); default: usage5(); } - } + if (optind < argc) { + result.config.device = argv[optind]; + } - if (optind < argc) { - device = argv[optind]; + if (!result.config.device) { + print_help(); + exit(STATE_UNKNOWN); + } } + return result; +} - if (!device) { - print_help(); - return STATE_UNKNOWN; +int main(int argc, char *argv[]) { + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + + /* Parse extra opts if any */ + argv = np_extra_opts(&argc, argv, progname); + + check_ide_smart_config_wrapper tmp_config = process_arguments(argc, argv); + + if (tmp_config.errorcode != OK) { + die(STATE_UNKNOWN, _("Failed to parse commandline")); } - fd = open(device, OPEN_MODE); + check_ide_smart_config config = tmp_config.config; - if (fd < 0) { - printf(_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror(errno)); + int device_file_descriptor = open(config.device, OPEN_MODE); + + if (device_file_descriptor < 0) { + printf(_("CRITICAL - Couldn't open device %s: %s\n"), config.device, strerror(errno)); return STATE_CRITICAL; } - if (smart_cmd_simple(fd, SMART_CMD_ENABLE, 0, false)) { + if (smart_cmd_simple(device_file_descriptor, SMART_CMD_ENABLE, 0, false)) { printf(_("CRITICAL - SMART_CMD_ENABLE\n")); return STATE_CRITICAL; } - smart_read_values(fd, &values); - smart_read_thresholds(fd, &thresholds); - retval = nagios(&values, &thresholds); + values_t values; + smart_read_values(device_file_descriptor, &values); + thresholds_t thresholds; + smart_read_thresholds(device_file_descriptor, &thresholds); + mp_state_enum retval = compare_values_and_thresholds(&values, &thresholds); if (verbose) { print_values(&values, &thresholds); } - close(fd); + close(device_file_descriptor); return retval; } char *get_offline_text(int status) { - int i; - for (i = 0; offline_status_text[i].text; i++) { - if (offline_status_text[i].value == status) { - return offline_status_text[i].text; + for (int index = 0; offline_status_text[index].text; index++) { + if (offline_status_text[index].value == status) { + return offline_status_text[index].text; } } return "UNKNOWN"; @@ -253,16 +268,16 @@ char *get_offline_text(int status) { int smart_read_values(int fd, values_t *values) { #ifdef __linux__ - int e; + int errno_storage; uint8_t args[4 + 512]; args[0] = WIN_SMART; args[1] = 0; args[2] = SMART_READ_VALUES; args[3] = 1; if (ioctl(fd, HDIO_DRIVE_CMD, &args)) { - e = errno; + errno_storage = errno; printf(_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror(errno)); - return e; + return errno_storage; } memcpy(values, args + 4, 512); #endif /* __linux__ */ @@ -298,7 +313,7 @@ int smart_read_values(int fd, values_t *values) { return 0; } -int nagios(values_t *p, thresholds_t *t) { +mp_state_enum compare_values_and_thresholds(values_t *p, thresholds_t *t) { value_t *value = p->values; threshold_t *threshold = t->thresholds; int status = OPERATIONAL; @@ -307,8 +322,7 @@ int nagios(values_t *p, thresholds_t *t) { int failed = 0; int passed = 0; int total = 0; - int i; - for (i = 0; i < NR_ATTRIBUTES; i++) { + for (int i = 0; i < NR_ATTRIBUTES; i++) { if (value->id && threshold->id && value->id == threshold->id) { if (value->value < threshold->threshold) { ++failed; @@ -327,6 +341,7 @@ int nagios(values_t *p, thresholds_t *t) { ++value; ++threshold; } + switch (status) { case PREFAILURE: printf(_("CRITICAL - %d Harddrive PreFailure%cDetected! %d/%d tests failed.\n"), prefailure, prefailure > 1 ? 's' : ' ', failed, @@ -371,8 +386,8 @@ void print_values(values_t *p, thresholds_t *t) { p->smart_capability & 1 ? "SaveOnStandBy" : "", p->smart_capability & 2 ? "AutoSave" : ""); } -int smart_cmd_simple(int fd, enum SmartCommand command, uint8_t val0, bool show_error) { - int e = STATE_UNKNOWN; +mp_state_enum smart_cmd_simple(int fd, enum SmartCommand command, uint8_t val0, bool show_error) { + mp_state_enum result = STATE_UNKNOWN; #ifdef __linux__ uint8_t args[4]; args[0] = WIN_SMART; @@ -380,12 +395,12 @@ int smart_cmd_simple(int fd, enum SmartCommand command, uint8_t val0, bool show_ args[2] = smart_command[command].value; args[3] = 0; if (ioctl(fd, HDIO_DRIVE_CMD, &args)) { - e = STATE_CRITICAL; + result = STATE_CRITICAL; if (show_error) { printf(_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror(errno)); } } else { - e = STATE_OK; + result = STATE_OK; if (show_error) { printf(_("OK - Command sent (%s)\n"), smart_command[command].text); } @@ -413,33 +428,33 @@ int smart_cmd_simple(int fd, enum SmartCommand command, uint8_t val0, bool show_ } if (errno != 0) { - e = STATE_CRITICAL; + result = STATE_CRITICAL; if (show_error) { printf(_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror(errno)); } } else { - e = STATE_OK; + result = STATE_OK; if (show_error) { printf(_("OK - Command sent (%s)\n"), smart_command[command].text); } } #endif /* __NetBSD__ */ - return e; + return result; } int smart_read_thresholds(int fd, thresholds_t *thresholds) { #ifdef __linux__ - int e; + int errno_storage; uint8_t args[4 + 512]; args[0] = WIN_SMART; args[1] = 0; args[2] = SMART_READ_THRESHOLDS; args[3] = 1; if (ioctl(fd, HDIO_DRIVE_CMD, &args)) { - e = errno; + errno_storage = errno; printf(_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror(errno)); - return e; + return errno_storage; } memcpy(thresholds, args + 4, 512); #endif /* __linux__ */ @@ -465,9 +480,9 @@ int smart_read_thresholds(int fd, thresholds_t *thresholds) { } if (errno != 0) { - int e = errno; + int errno_storage = errno; printf(_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror(errno)); - return e; + return errno_storage; } (void)memcpy(thresholds, inbuf, 512); diff --git a/plugins/check_ide_smart.d/config.h b/plugins/check_ide_smart.d/config.h new file mode 100644 index 00000000..36899abe --- /dev/null +++ b/plugins/check_ide_smart.d/config.h @@ -0,0 +1,15 @@ +#pragma once + +#include "../../config.h" +#include + +typedef struct { + char *device; +} check_ide_smart_config; + +check_ide_smart_config check_ide_smart_init() { + check_ide_smart_config tmp = { + .device = NULL, + }; + return tmp; +} -- cgit v1.2.3-74-g34f1 From 7ff3c488f6e5c5f7384279daff0256b7ca988167 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 17 Mar 2025 14:12:10 +0100 Subject: check_ide_smart: Fix positional arguments logic --- plugins/check_ide_smart.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c index b13c7101..dd88e124 100644 --- a/plugins/check_ide_smart.c +++ b/plugins/check_ide_smart.c @@ -204,15 +204,17 @@ static check_ide_smart_config_wrapper process_arguments(int argc, char **argv) { default: usage5(); } - if (optind < argc) { - result.config.device = argv[optind]; - } + } - if (!result.config.device) { - print_help(); - exit(STATE_UNKNOWN); - } + if (optind < argc) { + result.config.device = argv[optind]; + } + + if (result.config.device == NULL) { + print_help(); + exit(STATE_UNKNOWN); } + return result; } -- cgit v1.2.3-74-g34f1 From b09a8b530df8a23610889d0b89b148f22db3568a Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 17 Mar 2025 17:31:15 +0100 Subject: check_ide_smart: small improvements in readability --- plugins/check_ide_smart.c | 134 ++++++++++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 64 deletions(-) diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c index dd88e124..c1325cf9 100644 --- a/plugins/check_ide_smart.c +++ b/plugins/check_ide_smart.c @@ -80,30 +80,30 @@ void print_usage(void); #define OPERATIONAL 0 #define UNKNOWN -1 -typedef struct threshold_s { +typedef struct { uint8_t id; uint8_t threshold; uint8_t reserved[10]; -} __attribute__((packed)) threshold_t; +} __attribute__((packed)) smart_threshold; -typedef struct thresholds_s { +typedef struct { uint16_t revision; - threshold_t thresholds[NR_ATTRIBUTES]; + smart_threshold thresholds[NR_ATTRIBUTES]; uint8_t reserved[18]; uint8_t vendor[131]; uint8_t checksum; -} __attribute__((packed)) thresholds_t; +} __attribute__((packed)) smart_thresholds; -typedef struct value_s { +typedef struct { uint8_t id; uint16_t status; uint8_t value; uint8_t vendor[8]; -} __attribute__((packed)) value_t; +} __attribute__((packed)) smart_value; -typedef struct values_s { +typedef struct { uint16_t revision; - value_t values[NR_ATTRIBUTES]; + smart_value values[NR_ATTRIBUTES]; uint8_t offline_status; uint8_t vendor1; uint16_t offline_timeout; @@ -113,7 +113,7 @@ typedef struct values_s { uint8_t reserved[16]; uint8_t vendor[125]; uint8_t checksum; -} __attribute__((packed)) values_t; +} __attribute__((packed)) smart_values; static struct { uint8_t value; @@ -137,12 +137,12 @@ enum SmartCommand { }; static char *get_offline_text(int /*status*/); -static int smart_read_values(int /*fd*/, values_t * /*values*/); -static mp_state_enum compare_values_and_thresholds(values_t * /*p*/, thresholds_t * /*t*/); -static void print_value(value_t * /*p*/, threshold_t * /*t*/); -static void print_values(values_t * /*p*/, thresholds_t * /*t*/); +static int smart_read_values(int /*fd*/, smart_values * /*values*/); +static mp_state_enum compare_values_and_thresholds(smart_values * /*p*/, smart_thresholds * /*t*/); +static void print_value(smart_value * /*p*/, smart_threshold * /*t*/); +static void print_values(smart_values * /*p*/, smart_thresholds * /*t*/); static mp_state_enum smart_cmd_simple(int /*fd*/, enum SmartCommand /*command*/, uint8_t /*val0*/, bool /*show_error*/); -static int smart_read_thresholds(int /*fd*/, thresholds_t * /*thresholds*/); +static int smart_read_thresholds(int /*fd*/, smart_thresholds * /*thresholds*/); static int verbose = 0; typedef struct { @@ -246,9 +246,9 @@ int main(int argc, char *argv[]) { return STATE_CRITICAL; } - values_t values; + smart_values values; smart_read_values(device_file_descriptor, &values); - thresholds_t thresholds; + smart_thresholds thresholds; smart_read_thresholds(device_file_descriptor, &thresholds); mp_state_enum retval = compare_values_and_thresholds(&values, &thresholds); if (verbose) { @@ -268,22 +268,20 @@ char *get_offline_text(int status) { return "UNKNOWN"; } -int smart_read_values(int fd, values_t *values) { +int smart_read_values(int file_descriptor, smart_values *values) { #ifdef __linux__ - int errno_storage; uint8_t args[4 + 512]; args[0] = WIN_SMART; args[1] = 0; args[2] = SMART_READ_VALUES; args[3] = 1; - if (ioctl(fd, HDIO_DRIVE_CMD, &args)) { - errno_storage = errno; + if (ioctl(file_descriptor, HDIO_DRIVE_CMD, &args)) { + int errno_storage = errno; printf(_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror(errno)); return errno_storage; } memcpy(values, args + 4, 512); -#endif /* __linux__ */ -#ifdef __NetBSD__ +#elif defined __NetBSD__ struct atareq req; unsigned char inbuf[DEV_BSIZE]; @@ -298,26 +296,30 @@ int smart_read_values(int fd, values_t *values) { req.datalen = sizeof(inbuf); req.cylinder = WDSMART_CYL; - if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { + if (ioctl(file_descriptor, ATAIOCCOMMAND, &req) == 0) { if (req.retsts != ATACMD_OK) { errno = ENODEV; } } if (errno != 0) { - int e = errno; + int errno_storage = errno; printf(_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror(errno)); - return e; + return errno_storage; } (void)memcpy(values, inbuf, 512); -#endif /* __NetBSD__ */ +#else // __linux__ || __NetBSD__ +# error Not implemented for this OS +#endif + return 0; } -mp_state_enum compare_values_and_thresholds(values_t *p, thresholds_t *t) { - value_t *value = p->values; - threshold_t *threshold = t->thresholds; +mp_state_enum compare_values_and_thresholds(smart_values *values, smart_thresholds *thresholds) { + smart_value *value = values->values; + smart_threshold *threshold = thresholds->thresholds; + int status = OPERATIONAL; int prefailure = 0; int advisory = 0; @@ -366,37 +368,39 @@ mp_state_enum compare_values_and_thresholds(values_t *p, thresholds_t *t) { return status; } -void print_value(value_t *p, threshold_t *t) { - printf("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n", p->id, p->status, p->status & 1 ? "PreFailure" : "Advisory ", - p->status & 2 ? "OnLine " : "OffLine", p->value, t->threshold, p->value >= t->threshold ? "Passed" : "Failed"); +void print_value(smart_value *value_pointer, smart_threshold *threshold_pointer) { + printf("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n", value_pointer->id, value_pointer->status, + value_pointer->status & 1 ? "PreFailure" : "Advisory ", value_pointer->status & 2 ? "OnLine " : "OffLine", + value_pointer->value, threshold_pointer->threshold, value_pointer->value >= threshold_pointer->threshold ? "Passed" : "Failed"); } -void print_values(values_t *p, thresholds_t *t) { - value_t *value = p->values; - threshold_t *threshold = t->thresholds; - int i; - for (i = 0; i < NR_ATTRIBUTES; i++) { +void print_values(smart_values *values, smart_thresholds *thresholds) { + smart_value *value = values->values; + smart_threshold *threshold = thresholds->thresholds; + for (int i = 0; i < NR_ATTRIBUTES; i++) { if (value->id && threshold->id && value->id == threshold->id) { print_value(value++, threshold++); } } - printf(_("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n"), p->offline_status, - get_offline_text(p->offline_status & 0x7f), (p->offline_status & 0x80 ? "Yes" : "No"), p->offline_timeout / 60); - printf(_("OffLineCapability=%d {%s %s %s}\n"), p->offline_capability, p->offline_capability & 1 ? "Immediate" : "", - p->offline_capability & 2 ? "Auto" : "", p->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd"); - printf(_("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n"), p->revision, p->checksum, p->smart_capability, - p->smart_capability & 1 ? "SaveOnStandBy" : "", p->smart_capability & 2 ? "AutoSave" : ""); + printf(_("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n"), values->offline_status, + get_offline_text(values->offline_status & 0x7f), (values->offline_status & 0x80 ? "Yes" : "No"), values->offline_timeout / 60); + printf(_("OffLineCapability=%d {%s %s %s}\n"), values->offline_capability, values->offline_capability & 1 ? "Immediate" : "", + values->offline_capability & 2 ? "Auto" : "", values->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd"); + printf(_("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n"), values->revision, values->checksum, values->smart_capability, + values->smart_capability & 1 ? "SaveOnStandBy" : "", values->smart_capability & 2 ? "AutoSave" : ""); } -mp_state_enum smart_cmd_simple(int fd, enum SmartCommand command, uint8_t val0, bool show_error) { +mp_state_enum smart_cmd_simple(int file_descriptor, enum SmartCommand command, uint8_t val0, bool show_error) { mp_state_enum result = STATE_UNKNOWN; #ifdef __linux__ - uint8_t args[4]; - args[0] = WIN_SMART; - args[1] = val0; - args[2] = smart_command[command].value; - args[3] = 0; - if (ioctl(fd, HDIO_DRIVE_CMD, &args)) { + uint8_t args[4] = { + WIN_SMART, + val0, + smart_command[command].value, + 0, + }; + + if (ioctl(file_descriptor, HDIO_DRIVE_CMD, &args)) { result = STATE_CRITICAL; if (show_error) { printf(_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror(errno)); @@ -408,8 +412,7 @@ mp_state_enum smart_cmd_simple(int fd, enum SmartCommand command, uint8_t val0, } } -#endif /* __linux__ */ -#ifdef __NetBSD__ +#elif defined __NetBSD__ struct atareq req; memset(&req, 0, sizeof(req)); @@ -420,7 +423,7 @@ mp_state_enum smart_cmd_simple(int fd, enum SmartCommand command, uint8_t val0, req.cylinder = WDSMART_CYL; req.sec_count = val0; - if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { + if (ioctl(file_descriptor, ATAIOCCOMMAND, &req) == 0) { if (req.retsts != ATACMD_OK) { errno = ENODEV; } @@ -440,32 +443,32 @@ mp_state_enum smart_cmd_simple(int fd, enum SmartCommand command, uint8_t val0, printf(_("OK - Command sent (%s)\n"), smart_command[command].text); } } - +#else +# error Not implemented for this OS #endif /* __NetBSD__ */ + return result; } -int smart_read_thresholds(int fd, thresholds_t *thresholds) { +int smart_read_thresholds(int file_descriptor, smart_thresholds *thresholds) { #ifdef __linux__ - int errno_storage; uint8_t args[4 + 512]; args[0] = WIN_SMART; args[1] = 0; args[2] = SMART_READ_THRESHOLDS; args[3] = 1; - if (ioctl(fd, HDIO_DRIVE_CMD, &args)) { - errno_storage = errno; + if (ioctl(file_descriptor, HDIO_DRIVE_CMD, &args)) { + int errno_storage = errno; printf(_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror(errno)); return errno_storage; } memcpy(thresholds, args + 4, 512); -#endif /* __linux__ */ -#ifdef __NetBSD__ +#elif defined __NetBSD__ struct atareq req; - unsigned char inbuf[DEV_BSIZE]; - memset(&req, 0, sizeof(req)); req.timeout = 1000; + + unsigned char inbuf[DEV_BSIZE]; memset(&inbuf, 0, sizeof(inbuf)); req.flags = ATACMD_READ; @@ -475,7 +478,7 @@ int smart_read_thresholds(int fd, thresholds_t *thresholds) { req.datalen = sizeof(inbuf); req.cylinder = WDSMART_CYL; - if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { + if (ioctl(file_descriptor, ATAIOCCOMMAND, &req) == 0) { if (req.retsts != ATACMD_OK) { errno = ENODEV; } @@ -488,7 +491,10 @@ int smart_read_thresholds(int fd, thresholds_t *thresholds) { } (void)memcpy(thresholds, inbuf, 512); +#else +# error Not implemented for this OS #endif /* __NetBSD__ */ + return 0; } -- cgit v1.2.3-74-g34f1