├── .editorconfig ├── AUTHORS ├── COPYING ├── ChangeLog ├── ChangeLog-5.0-6.0 ├── ChangeLog-6.0-7.0 ├── Doxyfile ├── INSTALL ├── Makefile.am ├── NEWS ├── README ├── TODO ├── aacraid.h ├── atacmdnames.cpp ├── atacmdnames.h ├── atacmds.cpp ├── atacmds.h ├── ataidentify.cpp ├── ataidentify.h ├── ataprint.cpp ├── ataprint.h ├── autogen.sh ├── cciss.cpp ├── cciss.h ├── cissio_freebsd.h ├── configure.ac ├── cppcheck.sh ├── csmisas.h ├── dev_areca.cpp ├── dev_areca.h ├── dev_ata_cmd_set.cpp ├── dev_ata_cmd_set.h ├── dev_intelliprop.cpp ├── dev_interface.cpp ├── dev_interface.h ├── dev_jmb39x_raid.cpp ├── dev_legacy.cpp ├── dev_tunnelled.h ├── do_release ├── drivedb.h ├── examplescripts ├── Example1 ├── Example2 ├── Example3 ├── Example4 ├── Example5 ├── Example6 ├── Example7 ├── Example8 └── README ├── farmcmds.cpp ├── farmcmds.h ├── farmprint.cpp ├── farmprint.h ├── freebsd_nvme_ioctl.h ├── getopt ├── bits │ ├── getopt_core.h │ └── getopt_ext.h ├── getopt.c ├── getopt.h ├── getopt1.c └── getopt_int.h ├── getversion.sh ├── json.cpp ├── json.h ├── knowndrives.cpp ├── knowndrives.h ├── linux_nvme_ioctl.h ├── megaraid.h ├── netbsd_nvme_ioctl.h ├── nvmecmds.cpp ├── nvmecmds.h ├── nvmeprint.cpp ├── nvmeprint.h ├── os_darwin.cpp ├── os_darwin.h ├── os_darwin ├── com.smartmontools.smartd.plist.in └── pkg │ ├── Distribution.in │ ├── PackageInfo.in │ ├── installer │ └── README.html │ └── root │ └── usr │ └── local │ └── sbin │ └── smart-pkg-uninstall ├── os_freebsd.cpp ├── os_freebsd.h ├── os_generic.cpp ├── os_generic.h ├── os_linux.cpp ├── os_linux.h ├── os_netbsd.cpp ├── os_netbsd.h ├── os_openbsd.cpp ├── os_openbsd.h ├── os_os2.cpp ├── os_os2.h ├── os_qnxnto.cpp ├── os_qnxnto.h ├── os_solaris.cpp ├── os_win32.cpp ├── os_win32 ├── daemon_win32.cpp ├── daemon_win32.h ├── default.manifest ├── installer.nsi ├── pe32edit.sh ├── popen.h ├── popen_win32.cpp ├── runcmd.c ├── smartd_mailer.conf.sample.ps1 ├── smartd_mailer.ps1 ├── smartd_warning.cmd ├── syslog.h ├── syslog_win32.cpp ├── syslogevt.mc ├── update-smart-drivedb.ps1.in ├── vc16 │ ├── runcmd.vcxproj │ ├── smartctl.vcxproj │ ├── smartctl.vcxproj.filters │ ├── smartd.vcxproj │ ├── smartd.vcxproj.filters │ ├── smartmontools.sln │ └── wtssendmsg.vcxproj ├── vc17 │ ├── runcmd.vcxproj │ ├── smartctl.vcxproj │ ├── smartctl.vcxproj.filters │ ├── smartd.vcxproj │ ├── smartd.vcxproj.filters │ ├── smartmontools.sln │ └── wtssendmsg.vcxproj ├── versioninfo.rc.in ├── wmiquery.cpp ├── wmiquery.h └── wtssendmsg.c ├── popen_as_ugid.cpp ├── popen_as_ugid.h ├── regex ├── regcomp.c ├── regex.c ├── regex.h ├── regex_internal.c ├── regex_internal.h └── regexec.c ├── scsiata.cpp ├── scsicmds.cpp ├── scsicmds.h ├── scsinvme.cpp ├── scsiprint.cpp ├── scsiprint.h ├── sg_unaligned.h ├── smartctl.8.in ├── smartctl.cpp ├── smartctl.h ├── smartd.8.in ├── smartd.conf ├── smartd.conf.5.in ├── smartd.cpp ├── smartd.cygwin.initd.in ├── smartd.freebsd.initd.in ├── smartd.initd.in ├── smartd.service.in ├── smartd_warning.sh.in ├── sssraid.h ├── static_assert.h ├── update-smart-drivedb.8.in ├── update-smart-drivedb.in ├── utility.cpp └── utility.h /.editorconfig: -------------------------------------------------------------------------------- 1 | # smartmontools indent style settings for EditorConfig 2 | # https://editorconfig.org/ 3 | # $Id$ 4 | 5 | # top-most file 6 | root = true 7 | 8 | [*] 9 | indent_style = space 10 | indent_size = 2 11 | tab_width = 8 12 | 13 | [/ChangeLog] 14 | indent_style = tab 15 | indent_size = 8 16 | 17 | [Makefile*] 18 | # Rule recipes require tab characters (spaces are used elsewhere) 19 | indent_style = tab 20 | indent_size = 8 21 | 22 | # TODO: Fix files with other indent styles 23 | [/scsiata.cpp] 24 | # indent_size = 2 and 4 25 | 26 | [/scsicmds.*] 27 | indent_size = 4 28 | 29 | [/scsiprint.cpp] 30 | indent_size = 4 31 | 32 | # Keep indent style of imported files as is 33 | [/*_nvme_ioctl.h] 34 | indent_style = tab 35 | indent_size = 8 36 | 37 | [/csmisas.h] 38 | indent_size = 3 39 | 40 | [/getopt/getopt.*] 41 | indent_style = tab 42 | indent_size = 2 43 | 44 | [/regex/reg*.*] 45 | indent_style = tab 46 | indent_size = 2 47 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | $Id$ 2 | 3 | Developers / Maintainers / Contributors: 4 | 5 | Raghava Aditya <...> 6 | Bruce Allen <...> 7 | Jeremy Bauer 8 | Casey Biemiller 9 | Erik Inge Bolsø <...> 10 | Stanislav Brabec 11 | Peter Cassidy 12 | Praveen Chidambaram 13 | Jonghwan Choi 14 | Michael Cordle 15 | Yuri Dario 16 | Casper Dik <...> 17 | Simon Fairweather 18 | Christian Franke 19 | Guilhem Frézou <...> 20 | Thomas Gatterweh 21 | Douglas Gilbert 22 | Guido Guenther 23 | Jordan Hargrave 24 | Joerg Hering <...> 25 | Geoff Keating 26 | Dr. David Kirkby <...> 27 | Natan Lidukhover 28 | Song Liu 29 | Dan Lukes 30 | Kai Mäkisara 31 | Nidhi Malhotra 32 | Harry Mallon 33 | Eduard Martinescu 34 | Frédéric L. W. Meunier <...> 35 | Kimihiro Nonaka <...> 36 | Gabriele Pohl 37 | Alex Samorukov 38 | Keiji Sawada 39 | Manfred Schwarb 40 | Tomas Smetana 41 | David Snyder 42 | Sergey Svishchev 43 | Tommy Vestermark 44 | Roger Willcocks 45 | Phil Williams <...> 46 | Hank Wu 47 | Shengfeng Zhou 48 | Richard Zybert 49 | 50 | The first smartmontools code was derived from the smartsuite package, 51 | written by Michael Cornwell and Andre Hedrick. 52 | -------------------------------------------------------------------------------- /ChangeLog-5.0-6.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror/smartmontools/4cbc2fc9e68eaacd0cb432f2ca94c128cb598dc2/ChangeLog-5.0-6.0 -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | ========================================================== 2 | smartmontools - S.M.A.R.T. utility toolset for Darwin/Mac 3 | OSX, FreeBSD, Linux, NetBSD, OpenBSD, Solaris, and Windows. 4 | ========================================================== 5 | 6 | $Id$ 7 | 8 | == HOME == 9 | The home for smartmontools is located at: 10 | 11 | http://www.smartmontools.org/ 12 | 13 | Please see this web site for updates, documentation, and for submitting 14 | patches and bug reports. 15 | 16 | You will find a mailing list for support and other questions at: 17 | 18 | https://listi.jpberlin.de/mailman/listinfo/smartmontools-support 19 | 20 | 21 | == COPYING == 22 | Copyright (C) 2002-9 Bruce Allen 23 | Copyright (C) 2004-18 Christian Franke 24 | 25 | This program is free software; you can redistribute it and/or modify it 26 | under the terms of the GNU General Public License as published by the Free 27 | Software Foundation; either version 2, or (at your option) any later 28 | version. 29 | 30 | You should have received a copy of the GNU General Public License (for 31 | example COPYING). If not, see . 32 | 33 | SPDX-License-Identifier: GPL-2.0-or-later 34 | 35 | 36 | == CREDITS == 37 | See AUTHORS file. 38 | 39 | 40 | == OVERVIEW == 41 | smartmontools contains utilities that control and monitor storage 42 | devices using the Self-Monitoring, Analysis and Reporting Technology 43 | (SMART) system build into ATA/SATA and SCSI/SAS hard drives and 44 | solid-state drives. This is used to check the reliability of the 45 | drive and to predict drive failures. 46 | 47 | 48 | == CONTENTS == 49 | The suite contains two utilities: 50 | 51 | smartctl is a command line utility designed to perform S.M.A.R.T. tasks 52 | such as disk self-checks, and to report the S.M.A.R.T. status of 53 | the disk. 54 | 55 | smartd is a daemon that periodically monitors S.M.A.R.T. status and 56 | reports errors and changes in S.M.A.R.T. attributes to syslog. 57 | 58 | 59 | == OBTAINING SMARTMONTOOLS == 60 | 61 | Source tarballs 62 | --------------- 63 | 64 | http://sourceforge.net/projects/smartmontools/files/ 65 | 66 | SVN 67 | --- 68 | 69 | svn co http://svn.code.sf.net/p/smartmontools/code/trunk/smartmontools smartmontools 70 | 71 | This will create a subdirectory called smartmontools containing the code. 72 | 73 | To instead get the 5.38 release: 74 | 75 | svn co http://svn.code.sf.net/p/smartmontools/code/tags/RELEASE_5_38/sm5 smartmontools 76 | 77 | You can see what the different tags are by looking at 78 | http://sourceforge.net/p/smartmontools/code/HEAD/tree/tags/ 79 | 80 | == BUILDING/INSTALLING SMARTMONTOOLS == 81 | 82 | Refer to the "INSTALL" file for detailed installation instructions. 83 | 84 | == GETTING STARTED == 85 | 86 | To examine SMART data from a disk, try: 87 | smartctl -a /dev/sda 88 | See the manual page 'man smartctl' for more information. 89 | 90 | To start automatic monitoring of your disks with the smartd daemon, 91 | try: 92 | smartd -d 93 | to start the daemon in foreground (debug) mode, or 94 | smartd 95 | to start the daemon in background mode. This will log messages to 96 | SYSLOG. If you would like to get email warning messages, please set 97 | up the configuration file smartd.conf with the '-m' mail warning 98 | Directive. See the manual page 'man smartd' for more information. 99 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | $Id$ 2 | 3 | This file is no longer maintained, please use the ticket reports: 4 | http://www.smartmontools.org/report 5 | -------------------------------------------------------------------------------- /aacraid.h: -------------------------------------------------------------------------------- 1 | /* aacraid.h 2 | * Copyright (C) 2014 Raghava Aditya 3 | * Copyright (C) 2015 Nidhi Malhotra 4 | * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | */ 7 | 8 | // Check windows 9 | #if defined(_WIN32) || defined(_WIN64) 10 | #ifdef _WIN64 11 | #define ENVIRONMENT64 12 | #else 13 | #define ENVIRONMENT32 14 | #endif 15 | #endif 16 | 17 | // Check GCC 18 | #if __GNUC__ 19 | #if __x86_64__ || __ppc64__ 20 | #define ENVIRONMENT64 21 | #else 22 | #define ENVIRONMENT32 23 | #endif 24 | #endif 25 | 26 | #define METHOD_BUFFERED 0 27 | #define METHOD_NEITHER 3 28 | 29 | #if defined(_WIN32) || defined(_WIN64) 30 | #define FSAMPCTL_SCSI_BASE IOCTL_SCSI_BASE 31 | #define ARCIOCTL_SEND_RAW_SRB CTL_CODE(FSAMPCTL_SCSI_BASE, 2201, METHOD_BUFFERED, FILE_ANY_ACCESS) 32 | #define AACRAID_SAS_SIGNATURE "ARCSAS" 33 | #define SRB_FLAGS_DATA_IN 0x00000040 34 | #define SRB_FLAGS_DATA_OUT 0x00000080 35 | #define SRB_FLAGS_NO_DATA_TRANSFER 0x00000000 36 | #else 37 | #define CTL_CODE(function, method) ((4<< 16) | ((function) << 2) | (method) ) 38 | 39 | #define FSACTL_SEND_RAW_SRB CTL_CODE(2067, METHOD_BUFFERED) 40 | #endif 41 | #define SRB_FUNCTION_EXECUTE_SCSI 0X00 42 | 43 | #define SRB_DataIn 0x0040 44 | #define SRB_DataOut 0x0080 45 | #define SRB_NoDataXfer 0x0000 46 | 47 | typedef struct { 48 | uint32_t lo32; 49 | uint32_t hi32; 50 | } address64; 51 | 52 | typedef struct { 53 | address64 addr64; 54 | uint32_t length; /* Length. */ 55 | } user_sgentry64; 56 | 57 | typedef struct { 58 | uint32_t addr32; 59 | uint32_t length; 60 | } user_sgentry32; 61 | 62 | typedef struct { 63 | uint32_t count; 64 | user_sgentry64 sg64[1]; 65 | } user_sgmap64; 66 | 67 | typedef struct { 68 | uint32_t count; 69 | user_sgentry32 sg32[1]; 70 | } user_sgmap32; 71 | 72 | #if defined(_WIN32) || defined(_WIN64) 73 | typedef struct _SCSI_REQUEST_BLOCK { 74 | USHORT Length; // offset 0 75 | UCHAR Function; // offset 2 76 | UCHAR SrbStatus; // offset 3 77 | UCHAR ScsiStatus; // offset 4 78 | UCHAR PathId; // offset 5 79 | UCHAR TargetId; // offset 6 80 | UCHAR Lun; // offset 7 81 | UCHAR QueueTag; // offset 8 82 | UCHAR QueueAction; // offset 9 83 | UCHAR CdbLength; // offset a 84 | UCHAR SenseInfoBufferLength; // offset b 85 | ULONG SrbFlags; // offset c 86 | ULONG DataTransferLength; // offset 10 87 | ULONG TimeOutValue; // offset 14 88 | PVOID DataBuffer; // offset 18 89 | PVOID SenseInfoBuffer; // offset 1c 90 | struct _SCSI_REQUEST_BLOCK *NextSrb; // offset 20 91 | PVOID OriginalRequest; // offset 24 92 | PVOID SrbExtension; // offset 28 93 | union { 94 | ULONG InternalStatus; // offset 2c 95 | ULONG QueueSortKey; // offset 2c 96 | }; 97 | 98 | #if defined(_WIN64) 99 | // 100 | // Force PVOID alignment of Cdb 101 | // 102 | ULONG Reserved; 103 | #endif 104 | 105 | UCHAR Cdb[16]; // offset 30 106 | } SCSI_REQUEST_BLOCK, *PSCSI_REQUEST_BLOCK; 107 | 108 | #define SCSI_REQUEST_BLOCK_SIZE sizeof(SCSI_REQUEST_BLOCK) 109 | 110 | #else 111 | typedef struct { 112 | uint32_t function; //SRB_FUNCTION_EXECUTE_SCSI 0x00 113 | uint32_t channel; //bus 114 | uint32_t id; //use the ID number this is wrong 115 | uint32_t lun; //Logical unit number 116 | uint32_t timeout; 117 | uint32_t flags; //Interesting stuff I must say 118 | uint32_t count; // Data xfer size 119 | uint32_t retry_limit; // We shall see 120 | uint32_t cdb_size; // Length of CDB 121 | uint8_t cdb[16]; // The actual cdb command 122 | user_sgmap64 sg64; // pDatabuffer and address of Databuffer 123 | } user_aac_srb64; 124 | 125 | typedef struct { 126 | uint32_t function; //SRB_FUNCTION_EXECUTE_SCSI 0x00 127 | uint32_t channel; //bus 128 | uint32_t id; //use the ID number this is wrong 129 | uint32_t lun; //Logical unit number 130 | uint32_t timeout; 131 | uint32_t flags; //Interesting stuff I must say 132 | uint32_t count; // Data xfer size 133 | uint32_t retry_limit; // We shall see 134 | uint32_t cdb_size; // Length of CDB 135 | uint8_t cdb[16]; // The actual cdb command 136 | user_sgmap32 sg32; // pDatabuffer and address of Databuffer 137 | } user_aac_srb32; 138 | 139 | typedef struct { 140 | uint32_t status; 141 | uint32_t srb_status; 142 | uint32_t scsi_status; 143 | uint32_t data_xfer_length; 144 | uint32_t sense_data_size; 145 | uint8_t sense_data[30]; 146 | } user_aac_reply; 147 | #endif 148 | -------------------------------------------------------------------------------- /atacmdnames.h: -------------------------------------------------------------------------------- 1 | /* 2 | * atacmdnames.h 3 | * 4 | * This module is based on the T13/1532D Volume 1 Revision 3 (ATA/ATAPI-7) 5 | * specification, which is available from http://www.t13.org/#FTP_site 6 | * 7 | * Home page of code is: http://www.smartmontools.org 8 | * 9 | * Copyright (C) 2003-8 Philip Williams 10 | * 11 | * SPDX-License-Identifier: GPL-2.0-or-later 12 | */ 13 | 14 | #ifndef ATACMDNAMES_H_ 15 | #define ATACMDNAMES_H_ 16 | 17 | #define ATACMDNAMES_H_CVSID "$Id$\n" 18 | 19 | /* Returns the name of the command (and possibly sub-command) with the given 20 | command code and feature register values. */ 21 | const char *look_up_ata_command(unsigned char c_code, unsigned char f_reg); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /ataidentify.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ataidentify.h 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2012 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef ATAIDENTIFY_H 12 | #define ATAIDENTIFY_H 13 | 14 | #define ATAIDENTIFY_H_CVSID "$Id$" 15 | 16 | void ata_print_identify_data(const void * id, bool all_words, int bit_level); 17 | 18 | #endif // ATAIDENTIFY_H 19 | -------------------------------------------------------------------------------- /ataprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ataprint.h 3 | * 4 | * Home page of code is: https://www.smartmontools.org 5 | * 6 | * Copyright (C) 2002-09 Bruce Allen 7 | * Copyright (C) 2008-23 Christian Franke 8 | * Copyright (C) 1999-2000 Michael Cornwell 9 | * 10 | * SPDX-License-Identifier: GPL-2.0-or-later 11 | */ 12 | 13 | #ifndef ATAPRINT_H_ 14 | #define ATAPRINT_H_ 15 | 16 | #define ATAPRINT_H_CVSID "$Id$\n" 17 | 18 | #include 19 | 20 | // Request to dump a GP or SMART log 21 | struct ata_log_request 22 | { 23 | bool gpl = false; // false: SMART, true: GP 24 | unsigned char logaddr = 0; // Log address 25 | unsigned page = 0; // First page (sector) 26 | unsigned nsectors = 0; // # Sectors 27 | }; 28 | 29 | // Options for ataPrintMain 30 | struct ata_print_options 31 | { 32 | bool a_option = false; // true if '-a' is specified, used to suggest '-x' 33 | bool drive_info = false; 34 | int identify_word_level = -1, identify_bit_level = -1; 35 | bool smart_check_status = false; 36 | bool smart_general_values = false; 37 | bool smart_vendor_attrib = false; 38 | bool smart_error_log = false; 39 | bool smart_selftest_log = false; 40 | bool smart_selective_selftest_log = false; 41 | 42 | bool gp_logdir = false, smart_logdir = false; 43 | unsigned smart_ext_error_log = 0; 44 | unsigned smart_ext_selftest_log = 0; 45 | bool retry_error_log = false, retry_selftest_log = false; 46 | 47 | std::vector log_requests; 48 | 49 | bool devstat_all_pages = false, devstat_ssd_page = false; 50 | std::vector devstat_pages; 51 | 52 | unsigned pending_defects_log = 0; 53 | 54 | bool sct_temp_sts = false, sct_temp_hist = false; 55 | int sct_erc_get = 0; // get(1), get_power_on(2) 56 | int sct_erc_set = 0; // set(1), set_power_on(2), mfg_default(3) 57 | unsigned sct_erc_readtime = 0, sct_erc_writetime = 0; 58 | bool sataphy = false, sataphy_reset = false; 59 | 60 | bool smart_disable = false, smart_enable = false; 61 | bool smart_auto_offl_disable = false, smart_auto_offl_enable = false; 62 | bool smart_auto_save_disable = false, smart_auto_save_enable = false; 63 | 64 | int smart_selftest_type = -1; // OFFLINE_FULL_SCAN, ..., see atacmds.h. -1 for no test 65 | bool smart_selftest_force = false; // Ignore already running test 66 | ata_selective_selftest_args smart_selective_args; // Extra args for selective self-test 67 | 68 | unsigned sct_temp_int = 0; 69 | bool sct_temp_int_pers = false; 70 | 71 | enum { FMT_BRIEF = 0x01, FMT_HEX_ID = 0x02, FMT_HEX_VAL = 0x04 }; 72 | unsigned char output_format = 0; // FMT_* flags 73 | 74 | firmwarebug_defs firmwarebugs; // -F options 75 | bool fix_swapped_id = false; // Fix swapped ID strings returned by some buggy drivers 76 | 77 | ata_vendor_attr_defs attribute_defs; // -v options 78 | 79 | bool ignore_presets = false; // Ignore presets from drive database 80 | bool show_presets = false; // Show presets and exit 81 | unsigned char powermode = 0; // Skip check, if disk in idle or standby mode 82 | unsigned char powerexit = 0; // exit() code for low power mode 83 | int powerexit_unsup = -1; // exit() code for unsupported power mode or -1 to ignore 84 | 85 | bool get_set_used = false; // true if any get/set command is used 86 | bool get_aam = false; // print Automatic Acoustic Management status 87 | int set_aam = 0; // disable(-1), enable(1..255->0..254) Automatic Acoustic Management 88 | bool get_apm = false; // print Advanced Power Management status 89 | int set_apm = 0; // disable(-1), enable(2..255->1..254) Advanced Power Management 90 | bool get_lookahead = false; // print read look-ahead status 91 | int set_lookahead = 0; // disable(-1), enable(1) read look-ahead 92 | int set_standby = 0; // set(1..255->0..254) standby timer 93 | bool set_standby_now = false; // set drive to standby 94 | bool get_security = false; // print ATA security status 95 | bool set_security_freeze = false; // Freeze ATA security 96 | bool get_wcache = false; // print write cache status 97 | int set_wcache = 0; // disable(-1), enable(1) write cache 98 | bool sct_wcache_reorder_get = false; // print write cache reordering status 99 | int sct_wcache_reorder_set = 0; // disable(-1), enable(1) write cache reordering 100 | bool sct_wcache_reorder_set_pers = false; 101 | bool sct_wcache_sct_get = false; // print SCT Feature Control of write cache status 102 | int sct_wcache_sct_set = 0; // determined by ata set features command(1), force enable(2), force disable(3) 103 | bool sct_wcache_sct_set_pers = false; // persistent or volatile 104 | bool get_dsn = false; // print DSN status 105 | int set_dsn = 0; // disable(02h), enable(01h) DSN 106 | 107 | bool farm_log = false; // Seagate Field Access Reliability Metrics log (FARM) for ATA 108 | bool farm_log_suggest = false; // If -x/-xall or -a/-all is run, suggests FARM log if supported 109 | }; 110 | 111 | int ataPrintMain(ata_device * device, const ata_print_options & options); 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # $Id$ 3 | # 4 | # Generate ./configure from configure.ac and Makefile.in from Makefile.am. 5 | # This also adds files like missing,depcomp,install-sh to the source 6 | # directory. To update these files at a later date use: 7 | # autoreconf -f -i -v 8 | 9 | force=; warnings= 10 | while [ $# -gt 0 ]; do case $1 in 11 | --force) force=$1; shift ;; 12 | --warnings=?*) warnings="${warnings} $1"; shift ;; 13 | *) echo "Usage: $0 [--force] [--warnings=CATEGORY ...]"; exit 1 ;; 14 | esac; done 15 | 16 | # Cygwin? 17 | test -x /usr/bin/uname && /usr/bin/uname | grep -i CYGWIN >/dev/null && 18 | { 19 | # Check for Unix text file type 20 | echo > dostest.tmp 21 | test "`wc -c < dostest.tmp`" -eq 1 || 22 | echo "Warning: DOS text file type set, 'make dist' and related targets will not work." 23 | rm -f dostest.tmp 24 | } 25 | 26 | # Find automake 27 | if [ -n "$AUTOMAKE" ]; then 28 | ver=$("$AUTOMAKE" --version) || exit 1 29 | else 30 | maxver= 31 | for v in 1.16 1.15 1.14 1.13; do 32 | minver=$v; test -n "$maxver" || maxver=$v 33 | ver=$(automake-$v --version 2>/dev/null) || continue 34 | AUTOMAKE="automake-$v" 35 | break 36 | done 37 | if [ -z "$AUTOMAKE" ]; then 38 | echo "GNU Automake $minver (up to $maxver) is required to bootstrap smartmontools from SVN." 39 | exit 1 40 | fi 41 | fi 42 | 43 | ver=$(echo "$ver" | sed -n '1s,^.*[^.0-9]\([12]\.[0-9][-.0-9pl]*\).*$,\1,p') 44 | if [ -z "$ver" ]; then 45 | echo "$AUTOMAKE: Unable to determine automake version." 46 | exit 1 47 | fi 48 | 49 | # Check aclocal 50 | if [ -z "$ACLOCAL" ]; then 51 | ACLOCAL="aclocal$(echo "$AUTOMAKE" | sed -n 's,^.*automake\(-[.0-9]*\),\1,p')" 52 | fi 53 | 54 | "$ACLOCAL" --version >/dev/null || exit 1 55 | 56 | # Warn if Automake version was not tested 57 | amwarnings=$warnings 58 | case "$ver" in 59 | 1.[0-9]|1.[0-9].*|1.1[0-2]|1.1[0-2].*) 60 | echo "GNU Automake $ver is not supported."; exit 1 61 | ;; 62 | 63 | 1.13.[34]) 64 | # OK 65 | ;; 66 | 67 | 1.14|1.14.1|1.15|1.15.1|1.16|1.16.[1-5]) 68 | # TODO: Enable 'subdir-objects' in configure.ac 69 | # For now, suppress 'subdir-objects' forward-incompatibility warning 70 | test -n "$warnings" || amwarnings="--warnings=no-unsupported" 71 | ;; 72 | 73 | *) 74 | echo "Note: GNU Automake version ${ver} was not tested by the developers." 75 | echo "Please report success/failure to the smartmontools-support mailing list." 76 | esac 77 | 78 | set -e # stops on error status 79 | 80 | test -z "$warnings" || set -x 81 | 82 | ${ACLOCAL} -I m4 --install $force $warnings 83 | autoheader $force $warnings 84 | ${AUTOMAKE} --add-missing --copy ${force:+--force-missing} $amwarnings 85 | autoconf $force $warnings 86 | -------------------------------------------------------------------------------- /cciss.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cciss.h 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2007 Sergey Svishchev 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef CCISS_H_ 12 | #define CCISS_H_ 13 | 14 | #define CCISS_H_CVSID "$Id$" 15 | 16 | int cciss_io_interface(int device, int target, 17 | struct scsi_cmnd_io * iop, int report); 18 | 19 | #endif /* CCISS_H_ */ 20 | -------------------------------------------------------------------------------- /cissio_freebsd.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2001 Michael Smith 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * $FreeBSD: src/sys/dev/ciss/cissio.h,v 1.6.2.1.6.1 2010/12/21 17:09:25 kensmith Exp $ 27 | */ 28 | 29 | /* 30 | * Driver ioctl interface. 31 | * 32 | * Note that this interface is API-compatible with the Linux implementation 33 | * except as noted, and thus this header bears a striking resemblance to 34 | * the Linux driver's cciss_ioctl.h. 35 | * 36 | */ 37 | 38 | #include 39 | 40 | #pragma pack(1) 41 | 42 | typedef struct 43 | { 44 | u_int8_t bus; 45 | u_int8_t dev_fn; 46 | u_int32_t board_id; 47 | } cciss_pci_info_struct; 48 | 49 | typedef struct 50 | { 51 | u_int32_t delay; 52 | u_int32_t count; 53 | } cciss_coalint_struct; 54 | 55 | typedef char NodeName_type[16]; 56 | typedef u_int32_t Heartbeat_type; 57 | 58 | #define CISS_PARSCSIU2 0x0001 59 | #define CISS_PARCSCIU3 0x0002 60 | #define CISS_FIBRE1G 0x0100 61 | #define CISS_FIBRE2G 0x0200 62 | typedef u_int32_t BusTypes_type; 63 | 64 | typedef char FirmwareVer_type[4]; 65 | typedef u_int32_t DriverVer_type; 66 | 67 | /* passthrough command definitions */ 68 | #define SENSEINFOBYTES 32 69 | #define CISS_MAX_LUN 16 70 | #define LEVEL2LUN 1 71 | #define LEVEL3LUN 0 72 | 73 | /* command status value */ 74 | #define CMD_SUCCESS 0x0000 75 | #define CMD_TARGET_STATUS 0x0001 76 | #define CMD_DATA_UNDERRUN 0x0002 77 | #define CMD_DATA_OVERRUN 0x0003 78 | #define CMD_INVALID 0x0004 79 | #define CMD_PROTOCOL_ERR 0x0005 80 | #define CMD_HARDWARE_ERR 0x0006 81 | #define CMD_CONNECTION_LOST 0x0007 82 | #define CMD_ABORTED 0x0008 83 | #define CMD_ABORT_FAILED 0x0009 84 | #define CMD_UNSOLICITED_ABORT 0x000A 85 | #define CMD_TIMEOUT 0x000B 86 | #define CMD_UNABORTABLE 0x000C 87 | 88 | /* transfer direction */ 89 | #define XFER_NONE 0x00 90 | #define XFER_WRITE 0x01 91 | #define XFER_READ 0x02 92 | #define XFER_RSVD 0x03 93 | 94 | /* task attribute */ 95 | #define ATTR_UNTAGGED 0x00 96 | #define ATTR_SIMPLE 0x04 97 | #define ATTR_HEADOFQUEUE 0x05 98 | #define ATTR_ORDERED 0x06 99 | #define ATTR_ACA 0x07 100 | 101 | /* CDB type */ 102 | #define TYPE_CMD 0x00 103 | #define TYPE_MSG 0x01 104 | 105 | /* command list structure */ 106 | typedef union { 107 | struct { 108 | u_int8_t Dev; 109 | u_int8_t Bus:6; 110 | u_int8_t Mode:2; 111 | } __packed PeripDev; 112 | struct { 113 | u_int8_t DevLSB; 114 | u_int8_t DevMSB:6; 115 | u_int8_t Mode:2; 116 | } __packed LogDev; 117 | struct { 118 | u_int8_t Dev:5; 119 | u_int8_t Bus:3; 120 | u_int8_t Targ:6; 121 | u_int8_t Mode:2; 122 | } __packed LogUnit; 123 | } SCSI3Addr_struct; 124 | 125 | typedef struct { 126 | u_int32_t TargetId:24; 127 | u_int32_t Bus:6; 128 | u_int32_t Mode:2; 129 | SCSI3Addr_struct Target[2]; 130 | } __packed PhysDevAddr_struct; 131 | 132 | typedef struct { 133 | u_int32_t VolId:30; 134 | u_int32_t Mode:2; 135 | u_int8_t reserved[4]; 136 | } __packed LogDevAddr_struct; 137 | 138 | typedef union { 139 | u_int8_t LunAddrBytes[8]; 140 | SCSI3Addr_struct SCSI3Lun[4]; 141 | PhysDevAddr_struct PhysDev; 142 | LogDevAddr_struct LogDev; 143 | } __packed LUNAddr_struct; 144 | 145 | typedef struct { 146 | u_int8_t CDBLen; 147 | struct { 148 | u_int8_t Type:3; 149 | u_int8_t Attribute:3; 150 | u_int8_t Direction:2; 151 | } __packed Type; 152 | u_int16_t Timeout; 153 | u_int8_t CDB[16]; 154 | } __packed RequestBlock_struct; 155 | 156 | typedef union { 157 | struct { 158 | u_int8_t Reserved[3]; 159 | u_int8_t Type; 160 | u_int32_t ErrorInfo; 161 | } __packed Common_Info; 162 | struct { 163 | u_int8_t Reserved[2]; 164 | u_int8_t offense_size; 165 | u_int8_t offense_num; 166 | u_int32_t offense_value; 167 | } __packed Invalid_Cmd; 168 | } __packed MoreErrInfo_struct; 169 | 170 | typedef struct { 171 | u_int8_t ScsiStatus; 172 | u_int8_t SenseLen; 173 | u_int16_t CommandStatus; 174 | u_int32_t ResidualCnt; 175 | MoreErrInfo_struct MoreErrInfo; 176 | u_int8_t SenseInfo[SENSEINFOBYTES]; 177 | } __packed ErrorInfo_struct; 178 | 179 | typedef struct { 180 | LUNAddr_struct LUN_info; /* 8 */ 181 | RequestBlock_struct Request; /* 20 */ 182 | ErrorInfo_struct error_info; /* 48 */ 183 | u_int16_t buf_size; /* 2 */ 184 | u_int8_t *buf; /* 4 */ 185 | } __packed IOCTL_Command_struct; 186 | 187 | #ifdef __amd64__ 188 | typedef struct { 189 | LUNAddr_struct LUN_info; /* 8 */ 190 | RequestBlock_struct Request; /* 20 */ 191 | ErrorInfo_struct error_info; /* 48 */ 192 | u_int16_t buf_size; /* 2 */ 193 | u_int32_t buf; /* 4 */ 194 | } __packed IOCTL_Command_struct32; 195 | #endif 196 | 197 | /************************************************************************ 198 | * Command queue statistics 199 | */ 200 | 201 | #define CISSQ_FREE 0 202 | #define CISSQ_NOTIFY 1 203 | #define CISSQ_COUNT 2 204 | 205 | struct ciss_qstat { 206 | uint32_t q_length; 207 | uint32_t q_max; 208 | }; 209 | 210 | union ciss_statrequest { 211 | uint32_t cs_item; 212 | struct ciss_qstat cs_qstat; 213 | }; 214 | 215 | /* 216 | * Note that we'd normally pass the struct in directly, but 217 | * this code is trying to be compatible with other drivers. 218 | */ 219 | #define CCISS_GETPCIINFO _IOR ('C', 200, cciss_pci_info_struct) 220 | #define CCISS_GETINTINFO _IOR ('C', 201, cciss_coalint_struct) 221 | #define CCISS_SETINTINFO _IOW ('C', 202, cciss_coalint_struct) 222 | #define CCISS_GETNODENAME _IOR ('C', 203, NodeName_type) 223 | #define CCISS_SETNODENAME _IOW ('C', 204, NodeName_type) 224 | #define CCISS_GETHEARTBEAT _IOR ('C', 205, Heartbeat_type) 225 | #define CCISS_GETBUSTYPES _IOR ('C', 206, BusTypes_type) 226 | #define CCISS_GETFIRMVER _IOR ('C', 207, FirmwareVer_type) 227 | #define CCISS_GETDRIVERVER _IOR ('C', 208, DriverVer_type) 228 | #define CCISS_REVALIDVOLS _IO ('C', 209) 229 | #define CCISS_PASSTHRU _IOWR ('C', 210, IOCTL_Command_struct) 230 | #ifdef __amd64 231 | #define CCISS_PASSTHRU32 _IOWR ('C', 210, IOCTL_Command_struct32) 232 | #endif 233 | #define CCISS_GETQSTATS _IOWR ('C', 211, union ciss_statrequest) 234 | 235 | #pragma pack() 236 | -------------------------------------------------------------------------------- /cppcheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # cppcheck.sh - run cppcheck on smartmontools $srcdir 4 | # 5 | # Home page of code is: https://www.smartmontools.org 6 | # 7 | # Copyright (C) 2019-23 Christian Franke 8 | # 9 | # SPDX-License-Identifier: GPL-2.0-or-later 10 | # 11 | # $Id$ 12 | # 13 | 14 | set -e 15 | 16 | myname=$0 17 | 18 | usage() 19 | { 20 | echo "Usage: $myname [-v|-q] [-c CPPCHECK] [-jJOBS] [--library=CFG] [--platform=TYPE] [FILE ...]" 21 | exit 1 22 | } 23 | 24 | # Parse options 25 | jobs= 26 | v= 27 | cppcheck="cppcheck" 28 | library="--library=posix" 29 | platform="--platform=unix64" 30 | unused_func=",unusedFunction" 31 | 32 | while true; do case $1 in 33 | -c) shift; test -n "$1" || usage; cppcheck=$1 ;; 34 | -j?*) jobs=$1; unused_func= ;; 35 | -q) v="-q" ;; 36 | -v) v="-v" ;; 37 | --platform=*) platform=$1 ;; 38 | --library=*) library=$1 ;; 39 | -*) usage ;; 40 | *) break ;; 41 | esac; shift; done 42 | 43 | # Set file list from command line or $srcdir 44 | if [ $# -ne 0 ]; then 45 | files=$(echo "$@") 46 | files_v=$files 47 | unused_func= 48 | else 49 | srcdir=${myname%/*} 50 | if [ "$srcdir" = "$myname" ]; then 51 | echo "$myname: \$srcdir not found" >&2 52 | exit 1 53 | fi 54 | cd "$srcdir" || exit 1 55 | files_v="*.cpp *.h os_win32/*.cpp os_win32/*.h" 56 | files=$(echo $files_v) 57 | case $files in 58 | *\**) echo "$myname: Not run from \$srcdir" >&2; exit 1 ;; 59 | esac 60 | fi 61 | 62 | # Check cppcheck version 63 | ver=$("$cppcheck" --version) || exit 1 64 | ver=${ver##* } 65 | case $ver in 66 | 1.8[56]|2.[237]|2.1[01]) ;; 67 | *) echo "$myname: cppcheck $ver not tested with this script" ;; 68 | esac 69 | 70 | # Build cppcheck settings 71 | enable="warning,style,performance,portability,information${unused_func}" 72 | 73 | sup_list=" 74 | #warning 75 | syntaxError:drivedb.h 76 | #style 77 | asctime_rCalled:utility.cpp 78 | asctime_sCalled:utility.cpp 79 | cstyleCast:sg_unaligned.h 80 | getgrgidCalled:popen_as_ugid.cpp 81 | getgrnamCalled:popen_as_ugid.cpp 82 | getpwnamCalled:popen_as_ugid.cpp 83 | getpwuidCalled:popen_as_ugid.cpp 84 | readdirCalled 85 | strtokCalled 86 | unusedStructMember 87 | unusedFunction:sg_unaligned.h 88 | unmatchedSuppression 89 | " 90 | 91 | case $ver in 92 | 2.1[1-9]) sup_list="$sup_list 93 | #error 94 | ctuOneDefinitionRuleViolation:cissio_freebsd.h 95 | ctuOneDefinitionRuleViolation:freebsd_nvme_ioctl.h 96 | #information 97 | missingInclude 98 | missingIncludeSystem 99 | " ;; 100 | esac 101 | 102 | suppress= 103 | for s in $sup_list; do 104 | case $s in 105 | \#*) continue ;; 106 | unusedFunction:*) test -n "$unused_func" || continue ;; 107 | unmatchedSuppression) test $# -ne 0 || continue ;; 108 | esac 109 | suppress="${suppress}${suppress:+ }--suppress=${s%%#*}" 110 | done 111 | 112 | # shellcheck disable=SC2089 113 | defs="\ 114 | -U__KERNEL__ 115 | -U__LP64__ 116 | -U__MINGW64_VERSION_STR 117 | -U__VERSION__ 118 | -U_NETWARE 119 | -DBUILD_INFO=\"(...)\" 120 | -UCLOCK_MONOTONIC 121 | -DENOTSUP=1 122 | -DHAVE_ATTR_PACKED 123 | -DHAVE_CONFIG_H 124 | -DPACKAGE_VERSION=\"7.4\" 125 | -DSG_IO=1 126 | -DSMARTMONTOOLS_BUILD_HOST=\"host\" 127 | -DSMARTMONTOOLS_ATTRIBUTELOG=\"/file\" 128 | -DSMARTMONTOOLS_SAVESTATES=\"/file\" 129 | -DSMARTMONTOOLS_DRIVEDBDIR=\"/dir\" 130 | -USMARTMONTOOLS_RELEASE_DATE 131 | -USMARTMONTOOLS_RELEASE_TIME 132 | -USMARTMONTOOLS_SVN_REV 133 | -DSOURCE_DATE_EPOCH=1665402854 134 | -Umakedev 135 | -Ustricmp" 136 | 137 | # Print brief version of command 138 | cat <stderr 151 | # shellcheck disable=SC2090 152 | "$cppcheck" \ 153 | $v \ 154 | $jobs \ 155 | --enable="$enable" \ 156 | --template='{file}:{line}: {severity}: ({id}) {message}' \ 157 | --force \ 158 | --inline-suppr \ 159 | --language=c++ \ 160 | $library \ 161 | $platform \ 162 | $defs \ 163 | $suppress \ 164 | $files \ 165 | 3>&2 2>&1 1>&3 3>&- 166 | -------------------------------------------------------------------------------- /dev_areca.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dev_areca.h 3 | * 4 | * Home page of code is: https://www.smartmontools.org 5 | * 6 | * Copyright (C) 2012 Hank Wu 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef DEV_ARECA_H 12 | #define DEV_ARECA_H 13 | 14 | #define DEV_ARECA_H_CVSID "$Id$" 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | /// Areca RAID support 18 | 19 | /* GENERIC ARECA IO CONTROL CODE*/ 20 | enum _GENERIC_ARCMSR_CMDS 21 | { 22 | ARCMSR_READ_RQBUFFER = 0, 23 | ARCMSR_WRITE_WQBUFFER, 24 | ARCMSR_CLEAR_RQBUFFER, 25 | ARCMSR_CLEAR_WQBUFFER, 26 | ARCMSR_RETURN_CODE_3F, 27 | ARCMSR_CMD_TOTAL 28 | }; 29 | 30 | #define ARECA_SIG_STR "ARCMSR" 31 | 32 | #if defined(_WIN32) || defined(__CYGWIN__) 33 | #define ARCMSR_IOCTL_READ_RQBUFFER 0x90002004 34 | #define ARCMSR_IOCTL_WRITE_WQBUFFER 0x90002008 35 | #define ARCMSR_IOCTL_CLEAR_RQBUFFER 0x9000200C 36 | #define ARCMSR_IOCTL_CLEAR_WQBUFFER 0x90002010 37 | #define ARCMSR_IOCTL_RETURN_CODE_3F 0x90002018 38 | #elif defined(__linux__) 39 | /*DeviceType*/ 40 | #define ARECA_SATA_RAID 0x90000000 41 | /*FunctionCode*/ 42 | #define FUNCTION_READ_RQBUFFER 0x0801 43 | #define FUNCTION_WRITE_WQBUFFER 0x0802 44 | #define FUNCTION_CLEAR_RQBUFFER 0x0803 45 | #define FUNCTION_CLEAR_WQBUFFER 0x0804 46 | #define FUNCTION_RETURN_CODE_3F 0x0806 47 | 48 | /* ARECA IO CONTROL CODE*/ 49 | #define ARCMSR_IOCTL_READ_RQBUFFER (ARECA_SATA_RAID | FUNCTION_READ_RQBUFFER) 50 | #define ARCMSR_IOCTL_WRITE_WQBUFFER (ARECA_SATA_RAID | FUNCTION_WRITE_WQBUFFER) 51 | #define ARCMSR_IOCTL_CLEAR_RQBUFFER (ARECA_SATA_RAID | FUNCTION_CLEAR_RQBUFFER) 52 | #define ARCMSR_IOCTL_CLEAR_WQBUFFER (ARECA_SATA_RAID | FUNCTION_CLEAR_WQBUFFER) 53 | #define ARCMSR_IOCTL_RETURN_CODE_3F (ARECA_SATA_RAID | FUNCTION_RETURN_CODE_3F) 54 | #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) 55 | #include // _IOWR 56 | 57 | /*FunctionCode*/ 58 | #define FUNCTION_READ_RQBUFFER 0x0801 59 | #define FUNCTION_WRITE_WQBUFFER 0x0802 60 | #define FUNCTION_CLEAR_RQBUFFER 0x0803 61 | #define FUNCTION_CLEAR_WQBUFFER 0x0804 62 | #define FUNCTION_RETURN_CODE_3F 0x0806 63 | 64 | /* ARECA IO CONTROL CODE*/ 65 | #define ARCMSR_IOCTL_READ_RQBUFFER _IOWR('F', FUNCTION_READ_RQBUFFER, sSRB_BUFFER) 66 | #define ARCMSR_IOCTL_WRITE_WQBUFFER _IOWR('F', FUNCTION_WRITE_WQBUFFER, sSRB_BUFFER) 67 | #define ARCMSR_IOCTL_CLEAR_RQBUFFER _IOWR('F', FUNCTION_CLEAR_RQBUFFER, sSRB_BUFFER) 68 | #define ARCMSR_IOCTL_CLEAR_WQBUFFER _IOWR('F', FUNCTION_CLEAR_WQBUFFER, sSRB_BUFFER) 69 | #define ARCMSR_IOCTL_RETURN_CODE_3F _IOWR('F', FUNCTION_RETURN_CODE_3F, sSRB_BUFFER) 70 | #endif 71 | 72 | 73 | // The SRB_IO_CONTROL & SRB_BUFFER structures are used to communicate(to/from) to areca driver 74 | typedef struct _ARCMSR_IO_HDR 75 | { 76 | unsigned int HeaderLength; 77 | unsigned char Signature[8]; 78 | unsigned int Timeout; 79 | unsigned int ControlCode; 80 | unsigned int ReturnCode; 81 | unsigned int Length; 82 | } sARCMSR_IO_HDR; 83 | 84 | typedef struct _SRB_BUFFER 85 | { 86 | sARCMSR_IO_HDR srbioctl; 87 | unsigned char ioctldatabuffer[1032]; // the buffer to put the command data to/from firmware 88 | } sSRB_BUFFER; 89 | 90 | class generic_areca_device : 91 | virtual public smart_device 92 | { 93 | public: 94 | generic_areca_device(smart_interface * intf, const char * dev_name, int disknum, int encnum = 1); 95 | ~generic_areca_device(); 96 | 97 | ///////////////////////////////////////////////////////////////////// 98 | // OS-dependent functions 99 | virtual bool arcmsr_lock() = 0; 100 | virtual bool arcmsr_unlock() = 0; 101 | virtual int arcmsr_do_scsi_io(struct scsi_cmnd_io * iop) = 0; 102 | 103 | ///////////////////////////////////////////////////////////////////// 104 | // OS-independent functions 105 | virtual int arcmsr_command_handler(unsigned long arcmsr_cmd, unsigned char *data, int data_len); 106 | virtual int arcmsr_ui_handler(unsigned char *areca_packet, int areca_packet_len, unsigned char *result); 107 | virtual bool arcmsr_probe(); 108 | virtual int arcmsr_get_dev_type(); 109 | virtual int arcmsr_get_controller_type(); 110 | virtual bool arcmsr_scsi_pass_through(scsi_cmnd_io * iop); 111 | virtual bool arcmsr_ata_pass_through(const ata_cmd_in & in, ata_cmd_out & out); 112 | 113 | protected: 114 | generic_areca_device() 115 | : smart_device(never_called), 116 | m_disknum(-1), m_encnum(-1) 117 | { } 118 | 119 | void set_disknum(int disknum) 120 | {m_disknum = disknum;} 121 | 122 | void set_encnum(int encnum) 123 | {m_encnum = encnum;} 124 | 125 | int get_disknum() 126 | {return m_disknum;} 127 | 128 | int get_encnum() 129 | {return m_encnum;} 130 | 131 | private: 132 | int m_disknum; ///< Disk number. 133 | int m_encnum; ///< Enclosure number. 134 | }; 135 | 136 | // SATA(ATA) device behind Areca RAID Controller 137 | class areca_ata_device 138 | : public ata_device, 139 | public generic_areca_device 140 | { 141 | public: 142 | areca_ata_device(smart_interface * intf, const char * dev_name, int disknum, int encnum = 1); 143 | ~areca_ata_device(); 144 | bool arcmsr_lock() override { return true; } 145 | bool arcmsr_unlock() override { return true; } 146 | int arcmsr_do_scsi_io(struct scsi_cmnd_io * /* iop */) override 147 | { 148 | return -1; 149 | } 150 | protected: 151 | areca_ata_device(): smart_device(never_called) 152 | { 153 | } 154 | virtual bool ata_pass_through(const ata_cmd_in & in, ata_cmd_out & out) override; 155 | }; 156 | 157 | // SAS(SCSI) device behind Areca RAID Controller 158 | class areca_scsi_device 159 | : public scsi_device, 160 | public generic_areca_device 161 | { 162 | public: 163 | areca_scsi_device(smart_interface * intf, const char * dev_name, int disknum, int encnum = 1); 164 | ~areca_scsi_device(); 165 | bool arcmsr_lock() override { return true; } 166 | bool arcmsr_unlock() override { return true; } 167 | int arcmsr_do_scsi_io(struct scsi_cmnd_io * /* iop */) override 168 | { 169 | return -1; 170 | } 171 | protected: 172 | areca_scsi_device(): smart_device(never_called) 173 | { 174 | } 175 | virtual bool scsi_pass_through(scsi_cmnd_io * iop) override; 176 | }; 177 | 178 | #endif 179 | -------------------------------------------------------------------------------- /dev_ata_cmd_set.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * dev_ata_cmd_set.cpp 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2008-18 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #include "config.h" 12 | 13 | #include "atacmds.h" 14 | #include "dev_ata_cmd_set.h" 15 | 16 | #include 17 | 18 | const char * dev_ata_cmd_set_cpp_cvsid = "$Id$" 19 | DEV_ATA_CMD_SET_H_CVSID; 20 | 21 | 22 | ///////////////////////////////////////////////////////////////////////////// 23 | // ata_device_with_command_set 24 | 25 | // Adapter routine to implement new ATA pass through with old interface 26 | 27 | bool ata_device_with_command_set::ata_pass_through(const ata_cmd_in & in, ata_cmd_out & out) 28 | { 29 | if (!ata_cmd_is_ok(in, true)) // data_out_support 30 | return false; 31 | 32 | smart_command_set command = (smart_command_set)-1; 33 | int select = 0; 34 | char * data = (char *)in.buffer; 35 | char buffer[512]; 36 | switch (in.in_regs.command) { 37 | case ATA_IDENTIFY_DEVICE: 38 | command = IDENTIFY; 39 | break; 40 | case ATA_IDENTIFY_PACKET_DEVICE: 41 | command = PIDENTIFY; 42 | break; 43 | case ATA_CHECK_POWER_MODE: 44 | command = CHECK_POWER_MODE; 45 | data = buffer; data[0] = 0; 46 | break; 47 | case ATA_SMART_CMD: 48 | switch (in.in_regs.features) { 49 | case ATA_SMART_ENABLE: 50 | command = ENABLE; 51 | break; 52 | case ATA_SMART_READ_VALUES: 53 | command = READ_VALUES; 54 | break; 55 | case ATA_SMART_READ_THRESHOLDS: 56 | command = READ_THRESHOLDS; 57 | break; 58 | case ATA_SMART_READ_LOG_SECTOR: 59 | command = READ_LOG; 60 | select = in.in_regs.lba_low; 61 | break; 62 | case ATA_SMART_WRITE_LOG_SECTOR: 63 | command = WRITE_LOG; 64 | select = in.in_regs.lba_low; 65 | break; 66 | case ATA_SMART_DISABLE: 67 | command = DISABLE; 68 | break; 69 | case ATA_SMART_STATUS: 70 | command = (in.out_needed.lba_high ? STATUS_CHECK : STATUS); 71 | break; 72 | case ATA_SMART_AUTO_OFFLINE: 73 | command = AUTO_OFFLINE; 74 | select = in.in_regs.sector_count; 75 | break; 76 | case ATA_SMART_AUTOSAVE: 77 | command = AUTOSAVE; 78 | select = in.in_regs.sector_count; 79 | break; 80 | case ATA_SMART_IMMEDIATE_OFFLINE: 81 | command = IMMEDIATE_OFFLINE; 82 | select = in.in_regs.lba_low; 83 | break; 84 | default: 85 | return set_err(ENOSYS, "Unknown SMART command"); 86 | } 87 | break; 88 | default: 89 | return set_err(ENOSYS, "Non-SMART commands not implemented"); 90 | } 91 | 92 | clear_err(); errno = 0; 93 | int rc = ata_command_interface(command, select, data); 94 | if (rc < 0) { 95 | if (!get_errno()) 96 | set_err(errno); 97 | return false; 98 | } 99 | 100 | switch (command) { 101 | case CHECK_POWER_MODE: 102 | out.out_regs.sector_count = data[0]; 103 | break; 104 | case STATUS_CHECK: 105 | switch (rc) { 106 | case 0: // Good SMART status 107 | out.out_regs.lba_high = 0xc2; out.out_regs.lba_mid = 0x4f; 108 | break; 109 | case 1: // Bad SMART status 110 | out.out_regs.lba_high = 0x2c; out.out_regs.lba_mid = 0xf4; 111 | break; 112 | } 113 | break; 114 | default: 115 | break; 116 | } 117 | return true; 118 | } 119 | 120 | -------------------------------------------------------------------------------- /dev_ata_cmd_set.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dev_ata_cmd_set.h 3 | * 4 | * Home page of code is: https://www.smartmontools.org 5 | * 6 | * Copyright (C) 2008-21 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef DEV_ATA_CMD_SET_H 12 | #define DEV_ATA_CMD_SET_H 13 | 14 | #define DEV_ATA_CMD_SET_H_CVSID "$Id$" 15 | 16 | #include "atacmds.h" // smart_command_set 17 | #include "dev_interface.h" 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | // ata_device_with_command_set 21 | 22 | /// Adapter class to implement new ATA pass through old interface. 23 | 24 | class ata_device_with_command_set 25 | : public /*implements*/ ata_device 26 | { 27 | public: 28 | /// ATA pass through mapped to ata_command_interface(). 29 | virtual bool ata_pass_through(const ata_cmd_in & in, ata_cmd_out & out) override; 30 | 31 | protected: 32 | /// Old ATA interface called by ata_pass_through() 33 | virtual int ata_command_interface(smart_command_set command, int select, char * data) = 0; 34 | 35 | ata_device_with_command_set() 36 | : smart_device(never_called) { } 37 | }; 38 | 39 | #endif // DEV_ATA_CMD_SET_H 40 | -------------------------------------------------------------------------------- /dev_tunnelled.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dev_tunnelled.h 3 | * 4 | * Home page of code is: https://www.smartmontools.org 5 | * 6 | * Copyright (C) 2008-21 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef DEV_TUNNELLED_H 12 | #define DEV_TUNNELLED_H 13 | 14 | #define DEV_TUNNELLED_H_CVSID "$Id$" 15 | 16 | #include "dev_interface.h" 17 | 18 | ///////////////////////////////////////////////////////////////////////////// 19 | // tunnelled_device_base 20 | 21 | /// Common functionality for all tunnelled_device classes. 22 | 23 | class tunnelled_device_base 24 | : virtual public /*implements*/ smart_device 25 | { 26 | protected: 27 | explicit tunnelled_device_base(smart_device * tunnel_dev); 28 | 29 | public: 30 | virtual ~tunnelled_device_base(); 31 | 32 | virtual bool is_open() const override; 33 | 34 | virtual bool open() override; 35 | 36 | virtual bool close() override; 37 | 38 | virtual bool owns(const smart_device * dev) const override; 39 | 40 | virtual void release(const smart_device * dev) override; 41 | 42 | private: 43 | smart_device * m_tunnel_base_dev; 44 | }; 45 | 46 | 47 | ///////////////////////////////////////////////////////////////////////////// 48 | // tunnelled_device 49 | 50 | /// Implement a device by tunneling through another device 51 | 52 | template 53 | class tunnelled_device 54 | : public BaseDev, 55 | public tunnelled_device_base 56 | { 57 | public: 58 | typedef TunnelDev tunnel_device_type; 59 | 60 | protected: 61 | explicit tunnelled_device(tunnel_device_type * tunnel_dev) 62 | : smart_device(smart_device::never_called), 63 | tunnelled_device_base(tunnel_dev), 64 | m_tunnel_dev(tunnel_dev) 65 | { } 66 | 67 | // For nvme_device 68 | explicit tunnelled_device(tunnel_device_type * tunnel_dev, unsigned nsid) 69 | : smart_device(smart_device::never_called), 70 | BaseDev(nsid), 71 | tunnelled_device_base(tunnel_dev), 72 | m_tunnel_dev(tunnel_dev) 73 | { } 74 | 75 | public: 76 | virtual void release(const smart_device * dev) override 77 | { 78 | if (m_tunnel_dev == dev) 79 | m_tunnel_dev = 0; 80 | tunnelled_device_base::release(dev); 81 | } 82 | 83 | tunnel_device_type * get_tunnel_dev() 84 | { return m_tunnel_dev; } 85 | 86 | const tunnel_device_type * get_tunnel_dev() const 87 | { return m_tunnel_dev; } 88 | 89 | private: 90 | tunnel_device_type * m_tunnel_dev; 91 | }; 92 | 93 | #endif // DEV_TUNNELLED_H 94 | -------------------------------------------------------------------------------- /do_release: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # do a smartmontools release 4 | # (C) 2003-11 Bruce Allen, Guido Guenther 5 | # (C) 2006-22 Christian Franke 6 | # $Id$ 7 | 8 | # Notes on generating releases: 9 | # (1) run with '--checkout' and then 'cd DESTDIR/trunk/smartmontools' 10 | # (2) update NEWS -- put in release date 11 | # (3) update ChangeLog -- put in release date and number 12 | # (4) to test, run without '--commit' 13 | # (5) when satisfied, add option '--commit' 14 | 15 | set -e 16 | 17 | # Smartmontools Signing Key (through 2025) 18 | # 19 | KEYID=0xFF3AEFF5 20 | 21 | myname=$0 22 | 23 | usage() 24 | { 25 | cat < configure.tmp 124 | mv -f configure.tmp configure.ac 125 | 126 | # Review changes 127 | svn diff 128 | echo "===================================================================" 129 | echo ">>> Continuing in 20 seconds ..." 130 | sleep 20 131 | set -v 132 | 133 | # Create tag and commit 134 | if [ "$COMMIT" = "yes" ]; then 135 | svn mkdir $WDROOT/tags/$RELEASE 136 | svn copy ../smartmontools $WDROOT/tags/$RELEASE/smartmontools 137 | svn commit -m "Release $VERSIONRC $RELEASE" $WDROOT 138 | fi 139 | 140 | # Build 141 | ./autogen.sh 142 | 143 | mkdir build 144 | cd build 145 | ../configure 146 | make $DIST || exit 1 147 | make maintainer-clean 148 | cd .. 149 | 150 | TARFILE=smartmontools-$VERSIONRC.tar.gz 151 | 152 | mv -f build/smartmontools-$VERSION.tar.gz $TARFILE 153 | rm -rvf build 154 | 155 | md5sum $TARFILE > $TARFILE.md5 156 | 157 | # Sign tarball 158 | if [ -n "$KEYID" ] && gpg --list-secret-keys $KEYID >/dev/null 2>/dev/null; then 159 | gpg --default-key $KEYID --armor --detach-sign ./smartmontools-$VERSIONRC.tar.gz 160 | fi 161 | 162 | set +v 163 | 164 | # Update configure.ac only after trunk releases 165 | if [ -z "$RC" ] && [ "$DIRPAT" = "trunk" ]; then 166 | # Comment out timestamp 167 | sed -e "s|^smartmontools_release_date=\(.*\)$|smartmontools_release_date= # \1|" \ 168 | -e "s|^smartmontools_release_time=\(.*\)$|smartmontools_release_time= # \1|" \ 169 | configure.ac > configure.tmp 170 | mv -f configure.tmp configure.ac 171 | 172 | # Increase release number 173 | major=${VERSION%.*} 174 | old_minor=${VERSION##*.} 175 | new_minor=$((old_minor+1)) 176 | echo "New Version: $major.$new_minor" 177 | if [ "$COMMIT" = "yes" ]; then 178 | sed "/^AC_INIT(/{s|$major\\.$old_minor|$major.$new_minor|}" configure.ac > configure.tmp 179 | mv -f configure.tmp configure.ac 180 | svn diff 181 | echo "===================================================================" 182 | echo "# TODO:" 183 | echo "svn commit -m 'Bump release number to $major.$new_minor' configure.ac" 184 | fi 185 | fi 186 | -------------------------------------------------------------------------------- /examplescripts/Example1: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # This is a script from the smartmontools examplescripts/ directory. 4 | # It can be used as an argument to the -M exec Directive in 5 | # /etc/smartd.conf, in a line like 6 | # -m root@localhost -M exec /path/to/this/file 7 | # 8 | # Please see man 8 smartd or man 5 smartd.conf for further 9 | # information. 10 | # 11 | # $Id$ 12 | 13 | # Save standard input into a temp file 14 | cat > /root/tempfile 15 | 16 | # Echo command line arguments into temp file 17 | echo "Command line argument 1:" >> /root/tempfile 18 | echo $1 >> /root/tempfile 19 | echo "Command line argument 2:" >> /root/tempfile 20 | echo $2 >> /root/tempfile 21 | echo "Command line argument 3:" >> /root/tempfile 22 | echo $3 >> /root/tempfile 23 | 24 | # Echo environment variables into a temp file 25 | echo "Variables are": >> /root/tempfile 26 | echo "$SMARTD_DEVICE" >> /root/tempfile 27 | echo "$SMARTD_DEVICESTRING" >> /root/tempfile 28 | echo "$SMARTD_DEVICETYPE" >> /root/tempfile 29 | echo "$SMARTD_MESSAGE" >> /root/tempfile 30 | echo "$SMARTD_FULLMESSAGE" >> /root/tempfile 31 | echo "$SMARTD_ADDRESS" >> /root/tempfile 32 | echo "$SMARTD_SUBJECT" >> /root/tempfile 33 | echo "$SMARTD_TFIRST" >> /root/tempfile 34 | echo "$SMARTD_TFIRSTEPOCH" >> /root/tempfile 35 | 36 | # Run smartctl -a and save output in temp file 37 | /usr/sbin/smartctl -a -d $SMARTD_DEVICETYPE $SMARTD_DEVICE >> /root/tempfile 38 | 39 | # Email the contents of the temp file. Solaris and 40 | # other OSes may need to use /usr/bin/mailx below. 41 | /usr/bin/mail -s "SMART errors detected on host: `hostname`" $SMARTD_ADDRESS < /root/tempfile 42 | 43 | # And exit 44 | exit 0 45 | -------------------------------------------------------------------------------- /examplescripts/Example2: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # This is a script from the smartmontools examplescripts/ directory. 4 | # It can be used as an argument to the -M exec Directive in 5 | # /etc/smartd.conf, in a line like 6 | # -m root@localhost -M exec /path/to/this/file 7 | # 8 | # Please see man 8 smartd or man 5 smartd.conf for further 9 | # information. 10 | # 11 | # $Id$ 12 | 13 | # Save the email message (STDIN) to a file: 14 | cat > /root/msg 15 | 16 | # Append the output of smartctl -a to the message: 17 | /usr/sbin/smartctl -a -d $SMARTD_DEVICETYPE $SMARTD_DEVICE >> /root/msg 18 | 19 | # Now email the message to the user. Solaris and 20 | # other OSes may need to use /usr/bin/mailx below. 21 | /usr/bin/mail -s "$SMARTD_SUBJECT" $SMARTD_ADDRESS < /root/msg 22 | 23 | -------------------------------------------------------------------------------- /examplescripts/Example3: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # This is a script from the smartmontools examplescripts/ directory. 4 | # It can be used as an argument to the -M exec Directive in 5 | # /etc/smartd.conf, in a line like 6 | # -m -M exec /path/to/this/file 7 | # 8 | # Please see man 8 smartd or man 5 smartd.conf for further 9 | # information. 10 | # 11 | # $Id$ 12 | 13 | # Warn all users of a problem 14 | wall <Your hard disk drive is failing! 7 | S.M.A.R.T. message: 8 | $SMARTD_MESSAGE" 9 | -------------------------------------------------------------------------------- /examplescripts/Example5: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | tmp=$(tempfile) 4 | cat >$tmp 5 | 6 | run-parts --report --lsbsysinit --arg=$tmp --arg="$1" \ 7 | --arg="$2" --arg="$3" -- /etc/smartmontools/run.d 8 | 9 | rm -f $tmp 10 | 11 | -------------------------------------------------------------------------------- /examplescripts/Example6: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Send mail 4 | if which mail >/dev/null 2>&1 5 | then 6 | echo "$SMARTD_FULLMESSAGE" | mail -s "$SMARTD_SUBJECT" "$SMARTD_ADDRESS" 7 | fi 8 | 9 | # Notify desktop user 10 | MESSAGE="SMART Disk monitor:" 11 | case "$SMARTD_FAILTYPE" in 12 | "EmailTest"|"Health"|"Temperature"|"Usage") 13 | ;; 14 | *) 15 | # "CurrentPendingSector", // 10 16 | # "OfflineUncorrectableSector", // 11 17 | # "FailedReadSmartErrorLog", // 7 18 | # "ErrorCount", // 4 19 | # "FailedReadSmartData", // 6 20 | # "FailedHealthCheck", // 5 21 | # "FailedOpenDevice", // 9 22 | # "SelfTest", // 3 23 | # "FailedReadSmartSelfTestLog", // 8 24 | exit 0 25 | esac 26 | 27 | # direct write to terminals, do not use 'wall', because we don't want its ugly header 28 | for t in $(who | awk '{ print $2; }' | grep -e '^tty' -e '^pts/') 29 | do 30 | echo "$MESSAGE 31 | $SMARTD_MESSAGE" >/dev/$t 2>/dev/null ||: 32 | done 33 | 34 | -------------------------------------------------------------------------------- /examplescripts/Example7: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # This is a script from the smartmontools examplescripts/ directory. 4 | # It can be used as an argument to the -M exec Directive in 5 | # /etc/smartd.conf, in a line like 6 | # ... -m root@localhost -M exec /path/to/this/file 7 | # 8 | # See also: smartd.conf(5), smartd(8). 9 | # 10 | # $Id$ 11 | 12 | if [ $# -lt 3 ] || [ "$1" != "-s" ]; then 13 | echo "Usage: $0 -s SUBJECT ADDRESS... < MESSAGE" 14 | exit 1 15 | fi 16 | 17 | SUBJECT=$2 18 | shift; shift 19 | ADDRESS=$* 20 | 21 | exec /usr/sbin/sendmail $ADDRESS <' is set 13 | test -n "$SMARTD_ADDRESS" || exit 0 14 | 15 | # Try mail[x] 16 | # Note: The 'command -v' builtin requires a POSIX >= 2008 conforming shell 17 | for mailer in \ 18 | $(command -v mail 2>/dev/null) \ 19 | $(command -v mailx 2>/dev/null) \ 20 | /usr/bin/mail \ 21 | /usr/bin/mailx 22 | do 23 | test -f "$mailer" || continue 24 | test -x "$mailer" || continue 25 | exec "$mailer" -s "${SMARTD_SUBJECT-[SMARTD_SUBJECT]}" $SMARTD_ADDRESS <, 24 | and include a brief description to use below. 25 | 26 | The files contained in this directory are: 27 | 28 | Example1: Appends values of $SMARTD_* environment variables and the output 29 | of smartctl -a to the normal email message, and sends that 30 | to the email address listed as the argument to the -m 31 | Directive. 32 | 33 | Example2: Appends output of smartctl -a to the normal email message 34 | and sends that to the email address listed as the argument 35 | to the -m Directive. 36 | 37 | Example3: Uses wall(1) to send a warning message to all users, then powers 38 | down the machine. 39 | 40 | Example4: Uses powersave-notify to issue a desktop neutral warning. 41 | (/etc/smartmontools/run.d/10powersave-notify from Debian package) 42 | 43 | Example5: Uses run-parts(8) to run scripts from /etc/smartmontools/run.d/. 44 | (/usr/share/smartmontools/smartd-runner from Debian package) 45 | 46 | Example6: Sends a warning mail and then notifies the users by direct write 47 | to terminals. 48 | (/usr/libexec/smartmontools/smartdnotify from Fedora package) 49 | 50 | Example7: Sends an email using /usr/sbin/sendmail mail transfer agent. 51 | May be useful if there is no other mail(1) compatible mailer 52 | available. 53 | 54 | Example8: Sends an email using mail, mailx or sendmail mail transfer agent, 55 | whichever is found first. This script uses SMARTD_* environment 56 | variables and could therefore also be used in a run-parts(8) 57 | context like Example5. 58 | -------------------------------------------------------------------------------- /farmprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * farmprint.h 3 | * 4 | * Home page of code is: https://www.smartmontools.org 5 | * 6 | * Copyright (C) 2021 - 2023 Seagate Technology LLC and/or its Affiliates 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef FARMPRINT_H 12 | #define FARMPRINT_H 13 | 14 | #include "farmcmds.h" 15 | 16 | /* 17 | * Prints parsed FARM log (GP Log 0xA6) data from Seagate 18 | * drives already present in ataFarmLog structure 19 | * 20 | * @param farmLog: Constant reference to parsed farm log (const ataFarmLog&) 21 | */ 22 | void ataPrintFarmLog(const ataFarmLog& farmLog); 23 | 24 | /* 25 | * Prints parsed FARM log (SCSI log page 0x3D, sub-page 0x3) data from Seagate 26 | * drives already present in scsiFarmLog structure 27 | * 28 | * @param farmLog: Constant reference to parsed farm log (const scsiFarmLog&) 29 | */ 30 | void scsiPrintFarmLog(const scsiFarmLog& farmLog); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /freebsd_nvme_ioctl.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (C) 2012-2013 Intel Corporation 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * $FreeBSD$ 27 | */ 28 | 29 | 30 | #include 31 | 32 | #define NVME_PASSTHROUGH_CMD _IOWR('n', 0, struct nvme_pt_command) 33 | 34 | #if __FreeBSD_version < 1100110 35 | struct nvme_command 36 | { 37 | /* dword 0 */ 38 | uint16_t opc : 8; /* opcode */ 39 | uint16_t fuse : 2; /* fused operation */ 40 | uint16_t rsvd1 : 6; 41 | uint16_t cid; /* command identifier */ 42 | 43 | /* dword 1 */ 44 | uint32_t nsid; /* namespace identifier */ 45 | 46 | /* dword 2-3 */ 47 | uint32_t rsvd2; 48 | uint32_t rsvd3; 49 | 50 | /* dword 4-5 */ 51 | uint64_t mptr; /* metadata pointer */ 52 | 53 | /* dword 6-7 */ 54 | uint64_t prp1; /* prp entry 1 */ 55 | 56 | /* dword 8-9 */ 57 | uint64_t prp2; /* prp entry 2 */ 58 | 59 | /* dword 10-15 */ 60 | uint32_t cdw10; /* command-specific */ 61 | uint32_t cdw11; /* command-specific */ 62 | uint32_t cdw12; /* command-specific */ 63 | uint32_t cdw13; /* command-specific */ 64 | uint32_t cdw14; /* command-specific */ 65 | uint32_t cdw15; /* command-specific */ 66 | } __packed; 67 | 68 | struct nvme_status { 69 | 70 | uint16_t p : 1; /* phase tag */ 71 | uint16_t sc : 8; /* status code */ 72 | uint16_t sct : 3; /* status code type */ 73 | uint16_t rsvd2 : 2; 74 | uint16_t m : 1; /* more */ 75 | uint16_t dnr : 1; /* do not retry */ 76 | } __packed; 77 | 78 | struct nvme_completion { 79 | 80 | /* dword 0 */ 81 | uint32_t cdw0; /* command-specific */ 82 | 83 | /* dword 1 */ 84 | uint32_t rsvd1; 85 | 86 | /* dword 2 */ 87 | uint16_t sqhd; /* submission queue head pointer */ 88 | uint16_t sqid; /* submission queue identifier */ 89 | 90 | /* dword 3 */ 91 | uint16_t cid; /* command identifier */ 92 | struct nvme_status status; 93 | } __packed; 94 | 95 | struct nvme_pt_command { 96 | 97 | /* 98 | * cmd is used to specify a passthrough command to a controller or 99 | * namespace. 100 | * 101 | * The following fields from cmd may be specified by the caller: 102 | * * opc (opcode) 103 | * * nsid (namespace id) - for admin commands only 104 | * * cdw10-cdw15 105 | * 106 | * Remaining fields must be set to 0 by the caller. 107 | */ 108 | struct nvme_command cmd; 109 | 110 | /* 111 | * cpl returns completion status for the passthrough command 112 | * specified by cmd. 113 | * 114 | * The following fields will be filled out by the driver, for 115 | * consumption by the caller: 116 | * * cdw0 117 | * * status (except for phase) 118 | * 119 | * Remaining fields will be set to 0 by the driver. 120 | */ 121 | struct nvme_completion cpl; 122 | 123 | /* buf is the data buffer associated with this passthrough command. */ 124 | void * buf; 125 | 126 | /* 127 | * len is the length of the data buffer associated with this 128 | * passthrough command. 129 | */ 130 | uint32_t len; 131 | 132 | /* 133 | * is_read = 1 if the passthrough command will read data into the 134 | * supplied buffer from the controller. 135 | * 136 | * is_read = 0 if the passthrough command will write data from the 137 | * supplied buffer to the controller. 138 | */ 139 | uint32_t is_read; 140 | 141 | /* 142 | * driver_lock is used by the driver only. It must be set to 0 143 | * by the caller. 144 | */ 145 | struct mtx * driver_lock; 146 | }; 147 | #else 148 | #include 149 | #endif 150 | 151 | #if __FreeBSD_version < 1200058 152 | #define nvme_completion_is_error(cpl) \ 153 | ((cpl)->status.sc != 0 || (cpl)->status.sct != 0) 154 | #endif 155 | 156 | #define NVME_CTRLR_PREFIX "/dev/nvme" 157 | #define NVME_NS_PREFIX "ns" 158 | -------------------------------------------------------------------------------- /getopt/bits/getopt_core.h: -------------------------------------------------------------------------------- 1 | /* Declarations for getopt (basic, portable features only). 2 | Copyright (C) 1989-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library and is also part of gnulib. 4 | Patches to this file should be submitted to both projects. 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | The GNU C Library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with the GNU C Library; if not, see 18 | . */ 19 | 20 | #ifndef _GETOPT_CORE_H 21 | #define _GETOPT_CORE_H 1 22 | 23 | /* This header should not be used directly; include getopt.h or 24 | unistd.h instead. Unlike most bits headers, it does not have 25 | a protective #error, because the guard macro for getopt.h in 26 | gnulib is not fixed. */ 27 | 28 | __BEGIN_DECLS 29 | 30 | /* For communication from 'getopt' to the caller. 31 | When 'getopt' finds an option that takes an argument, 32 | the argument value is returned here. 33 | Also, when 'ordering' is RETURN_IN_ORDER, 34 | each non-option ARGV-element is returned here. */ 35 | 36 | extern char *optarg; 37 | 38 | /* Index in ARGV of the next element to be scanned. 39 | This is used for communication to and from the caller 40 | and for communication between successive calls to 'getopt'. 41 | 42 | On entry to 'getopt', zero means this is the first call; initialize. 43 | 44 | When 'getopt' returns -1, this is the index of the first of the 45 | non-option elements that the caller should itself scan. 46 | 47 | Otherwise, 'optind' communicates from one call to the next 48 | how much of ARGV has been scanned so far. */ 49 | 50 | extern int optind; 51 | 52 | /* Callers store zero here to inhibit the error message 'getopt' prints 53 | for unrecognized options. */ 54 | 55 | extern int opterr; 56 | 57 | /* Set to an option character which was unrecognized. */ 58 | 59 | extern int optopt; 60 | 61 | /* Get definitions and prototypes for functions to process the 62 | arguments in ARGV (ARGC of them, minus the program name) for 63 | options given in OPTS. 64 | 65 | Return the option character from OPTS just read. Return -1 when 66 | there are no more options. For unrecognized options, or options 67 | missing arguments, 'optopt' is set to the option letter, and '?' is 68 | returned. 69 | 70 | The OPTS string is a list of characters which are recognized option 71 | letters, optionally followed by colons, specifying that that letter 72 | takes an argument, to be placed in 'optarg'. 73 | 74 | If a letter in OPTS is followed by two colons, its argument is 75 | optional. This behavior is specific to the GNU 'getopt'. 76 | 77 | The argument '--' causes premature termination of argument 78 | scanning, explicitly telling 'getopt' that there are no more 79 | options. 80 | 81 | If OPTS begins with '-', then non-option arguments are treated as 82 | arguments to the option '\1'. This behavior is specific to the GNU 83 | 'getopt'. If OPTS begins with '+', or POSIXLY_CORRECT is set in 84 | the environment, then do not permute arguments. 85 | 86 | For standards compliance, the 'argv' argument has the type 87 | char *const *, but this is inaccurate; if argument permutation is 88 | enabled, the argv array (not the strings it points to) must be 89 | writable. */ 90 | 91 | extern int getopt (int ___argc, char *const *___argv, const char *__shortopts) 92 | __THROW __nonnull ((2, 3)); 93 | 94 | __END_DECLS 95 | 96 | #endif /* getopt_core.h */ 97 | -------------------------------------------------------------------------------- /getopt/bits/getopt_ext.h: -------------------------------------------------------------------------------- 1 | /* Declarations for getopt (GNU extensions). 2 | Copyright (C) 1989-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library and is also part of gnulib. 4 | Patches to this file should be submitted to both projects. 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | The GNU C Library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with the GNU C Library; if not, see 18 | . */ 19 | 20 | #ifndef _GETOPT_EXT_H 21 | #define _GETOPT_EXT_H 1 22 | 23 | /* This header should not be used directly; include getopt.h instead. 24 | Unlike most bits headers, it does not have a protective #error, 25 | because the guard macro for getopt.h in gnulib is not fixed. */ 26 | 27 | __BEGIN_DECLS 28 | 29 | /* Describe the long-named options requested by the application. 30 | The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 31 | of 'struct option' terminated by an element containing a name which is 32 | zero. 33 | 34 | The field 'has_arg' is: 35 | no_argument (or 0) if the option does not take an argument, 36 | required_argument (or 1) if the option requires an argument, 37 | optional_argument (or 2) if the option takes an optional argument. 38 | 39 | If the field 'flag' is not NULL, it points to a variable that is set 40 | to the value given in the field 'val' when the option is found, but 41 | left unchanged if the option is not found. 42 | 43 | To have a long-named option do something other than set an 'int' to 44 | a compiled-in constant, such as set a value from 'optarg', set the 45 | option's 'flag' field to zero and its 'val' field to a nonzero 46 | value (the equivalent single-letter option character, if there is 47 | one). For long options that have a zero 'flag' field, 'getopt' 48 | returns the contents of the 'val' field. */ 49 | 50 | struct option 51 | { 52 | const char *name; 53 | /* has_arg can't be an enum because some compilers complain about 54 | type mismatches in all the code that assumes it is an int. */ 55 | int has_arg; 56 | int *flag; 57 | int val; 58 | }; 59 | 60 | /* Names for the values of the 'has_arg' field of 'struct option'. */ 61 | 62 | #define no_argument 0 63 | #define required_argument 1 64 | #define optional_argument 2 65 | 66 | extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv, 67 | const char *__shortopts, 68 | const struct option *__longopts, int *__longind) 69 | __THROW __nonnull ((2, 3)); 70 | extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv, 71 | const char *__shortopts, 72 | const struct option *__longopts, int *__longind) 73 | __THROW __nonnull ((2, 3)); 74 | 75 | __END_DECLS 76 | 77 | #endif /* getopt_ext.h */ 78 | -------------------------------------------------------------------------------- /getopt/getopt.h: -------------------------------------------------------------------------------- 1 | /* Declarations for getopt. 2 | Copyright (C) 1989-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | Unlike the bulk of the getopt implementation, this file is NOT part 5 | of gnulib; gnulib also has a getopt.h but it is different. 6 | 7 | The GNU C Library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | The GNU C Library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with the GNU C Library; if not, see 19 | . */ 20 | 21 | #ifndef _GETOPT_H 22 | #define _GETOPT_H 1 23 | 24 | #ifndef _GETOPT_STANDALONE 25 | #include 26 | #endif 27 | 28 | // From : 29 | #ifndef __BEGIN_DECLS 30 | # ifdef __cplusplus 31 | # define __BEGIN_DECLS extern "C" { 32 | # define __END_DECLS } 33 | # else 34 | # define __BEGIN_DECLS 35 | # define __END_DECLS 36 | # endif 37 | #endif 38 | #ifndef __THROW 39 | # ifdef __cplusplus 40 | # define __THROW throw() 41 | # elif defined(__GNUC__) 42 | # define __THROW __attribute__ ((__nothrow__)) 43 | # else 44 | # define __THROW 45 | # endif 46 | #endif 47 | #ifndef __nonnull 48 | # ifdef __GNUC__ 49 | # define __nonnull(x) __attribute__ ((__nonnull__ x)) 50 | # else 51 | # define __nonnull(x) 52 | # endif 53 | #endif 54 | 55 | /* The type of the 'argv' argument to getopt_long and getopt_long_only 56 | is properly 'char **', since both functions may write to the array 57 | (in order to move all the options to the beginning). However, for 58 | compatibility with old versions of LSB, glibc has to use 'char *const *' 59 | instead. */ 60 | #ifndef __getopt_argv_const 61 | # define __getopt_argv_const const 62 | #endif 63 | 64 | #include 65 | #include 66 | 67 | #endif /* getopt.h */ 68 | -------------------------------------------------------------------------------- /getopt/getopt1.c: -------------------------------------------------------------------------------- 1 | /* getopt_long and getopt_long_only entry points for GNU getopt. 2 | Copyright (C) 1987-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library and is also part of gnulib. 4 | Patches to this file should be submitted to both projects. 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | The GNU C Library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with the GNU C Library; if not, see 18 | . */ 19 | 20 | #if !defined(_LIBC) && !defined(_GETOPT_STANDALONE) 21 | # include 22 | #endif 23 | 24 | #include "getopt.h" 25 | #include "getopt_int.h" 26 | 27 | int 28 | getopt_long (int argc, char *__getopt_argv_const *argv, const char *options, 29 | const struct option *long_options, int *opt_index) 30 | { 31 | return _getopt_internal (argc, (char **) argv, options, long_options, 32 | opt_index, 0, 0); 33 | } 34 | 35 | int 36 | _getopt_long_r (int argc, char **argv, const char *options, 37 | const struct option *long_options, int *opt_index, 38 | struct _getopt_data *d) 39 | { 40 | return _getopt_internal_r (argc, argv, options, long_options, opt_index, 41 | 0, d, 0); 42 | } 43 | 44 | /* Like getopt_long, but '-' as well as '--' can indicate a long option. 45 | If an option that starts with '-' (not '--') doesn't match a long option, 46 | but does match a short option, it is parsed as a short option 47 | instead. */ 48 | 49 | int 50 | getopt_long_only (int argc, char *__getopt_argv_const *argv, 51 | const char *options, 52 | const struct option *long_options, int *opt_index) 53 | { 54 | return _getopt_internal (argc, (char **) argv, options, long_options, 55 | opt_index, 1, 0); 56 | } 57 | 58 | int 59 | _getopt_long_only_r (int argc, char **argv, const char *options, 60 | const struct option *long_options, int *opt_index, 61 | struct _getopt_data *d) 62 | { 63 | return _getopt_internal_r (argc, argv, options, long_options, opt_index, 64 | 1, d, 0); 65 | } 66 | 67 | 68 | #ifdef TEST 69 | 70 | #include 71 | #include 72 | 73 | int 74 | main (int argc, char **argv) 75 | { 76 | int c; 77 | int digit_optind = 0; 78 | 79 | while (1) 80 | { 81 | int this_option_optind = optind ? optind : 1; 82 | int option_index = 0; 83 | static const struct option long_options[] = 84 | { 85 | {"add", 1, 0, 0}, 86 | {"append", 0, 0, 0}, 87 | {"delete", 1, 0, 0}, 88 | {"verbose", 0, 0, 0}, 89 | {"create", 0, 0, 0}, 90 | {"file", 1, 0, 0}, 91 | {0, 0, 0, 0} 92 | }; 93 | 94 | c = getopt_long (argc, argv, "abc:d:0123456789", 95 | long_options, &option_index); 96 | if (c == -1) 97 | break; 98 | 99 | switch (c) 100 | { 101 | case 0: 102 | printf ("option %s", long_options[option_index].name); 103 | if (optarg) 104 | printf (" with arg %s", optarg); 105 | printf ("\n"); 106 | break; 107 | 108 | case '0': 109 | case '1': 110 | case '2': 111 | case '3': 112 | case '4': 113 | case '5': 114 | case '6': 115 | case '7': 116 | case '8': 117 | case '9': 118 | if (digit_optind != 0 && digit_optind != this_option_optind) 119 | printf ("digits occur in two different argv-elements.\n"); 120 | digit_optind = this_option_optind; 121 | printf ("option %c\n", c); 122 | break; 123 | 124 | case 'a': 125 | printf ("option a\n"); 126 | break; 127 | 128 | case 'b': 129 | printf ("option b\n"); 130 | break; 131 | 132 | case 'c': 133 | printf ("option c with value '%s'\n", optarg); 134 | break; 135 | 136 | case 'd': 137 | printf ("option d with value '%s'\n", optarg); 138 | break; 139 | 140 | case '?': 141 | break; 142 | 143 | default: 144 | printf ("?? getopt returned character code 0%o ??\n", c); 145 | } 146 | } 147 | 148 | if (optind < argc) 149 | { 150 | printf ("non-option ARGV-elements: "); 151 | while (optind < argc) 152 | printf ("%s ", argv[optind++]); 153 | printf ("\n"); 154 | } 155 | 156 | exit (0); 157 | } 158 | 159 | #endif /* TEST */ 160 | -------------------------------------------------------------------------------- /getopt/getopt_int.h: -------------------------------------------------------------------------------- 1 | /* Internal declarations for getopt. 2 | Copyright (C) 1989-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library and is also part of gnulib. 4 | Patches to this file should be submitted to both projects. 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | The GNU C Library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with the GNU C Library; if not, see 18 | . */ 19 | 20 | #ifndef _GETOPT_INT_H 21 | #define _GETOPT_INT_H 1 22 | 23 | #include 24 | 25 | extern int _getopt_internal (int ___argc, char **___argv, 26 | const char *__shortopts, 27 | const struct option *__longopts, int *__longind, 28 | int __long_only, int __posixly_correct); 29 | 30 | 31 | /* Reentrant versions which can handle parsing multiple argument 32 | vectors at the same time. */ 33 | 34 | /* Describe how to deal with options that follow non-option ARGV-elements. 35 | 36 | REQUIRE_ORDER means don't recognize them as options; stop option 37 | processing when the first non-option is seen. This is what POSIX 38 | specifies should happen. 39 | 40 | PERMUTE means permute the contents of ARGV as we scan, so that 41 | eventually all the non-options are at the end. This allows options 42 | to be given in any order, even with programs that were not written 43 | to expect this. 44 | 45 | RETURN_IN_ORDER is an option available to programs that were 46 | written to expect options and other ARGV-elements in any order 47 | and that care about the ordering of the two. We describe each 48 | non-option ARGV-element as if it were the argument of an option 49 | with character code 1. 50 | 51 | The special argument '--' forces an end of option-scanning regardless 52 | of the value of 'ordering'. In the case of RETURN_IN_ORDER, only 53 | '--' can cause 'getopt' to return -1 with 'optind' != ARGC. */ 54 | 55 | enum __ord 56 | { 57 | REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER 58 | }; 59 | 60 | /* Data type for reentrant functions. */ 61 | struct _getopt_data 62 | { 63 | /* These have exactly the same meaning as the corresponding global 64 | variables, except that they are used for the reentrant 65 | versions of getopt. */ 66 | int optind; 67 | int opterr; 68 | int optopt; 69 | char *optarg; 70 | 71 | /* Internal members. */ 72 | 73 | /* True if the internal members have been initialized. */ 74 | int __initialized; 75 | 76 | /* The next char to be scanned in the option-element 77 | in which the last option character we returned was found. 78 | This allows us to pick up the scan where we left off. 79 | 80 | If this is zero, or a null string, it means resume the scan 81 | by advancing to the next ARGV-element. */ 82 | char *__nextchar; 83 | 84 | /* See __ord above. */ 85 | enum __ord __ordering; 86 | 87 | /* Handle permutation of arguments. */ 88 | 89 | /* Describe the part of ARGV that contains non-options that have 90 | been skipped. 'first_nonopt' is the index in ARGV of the first 91 | of them; 'last_nonopt' is the index after the last of them. */ 92 | 93 | int __first_nonopt; 94 | int __last_nonopt; 95 | }; 96 | 97 | /* The initializer is necessary to set OPTIND and OPTERR to their 98 | default values and to clear the initialization flag. */ 99 | #define _GETOPT_DATA_INITIALIZER { 1, 1 } 100 | 101 | extern int _getopt_internal_r (int ___argc, char **___argv, 102 | const char *__shortopts, 103 | const struct option *__longopts, int *__longind, 104 | int __long_only, struct _getopt_data *__data, 105 | int __posixly_correct); 106 | 107 | extern int _getopt_long_r (int ___argc, char **___argv, 108 | const char *__shortopts, 109 | const struct option *__longopts, int *__longind, 110 | struct _getopt_data *__data); 111 | 112 | extern int _getopt_long_only_r (int ___argc, char **___argv, 113 | const char *__shortopts, 114 | const struct option *__longopts, 115 | int *__longind, 116 | struct _getopt_data *__data); 117 | 118 | #endif /* getopt_int.h */ 119 | -------------------------------------------------------------------------------- /getversion.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Create svnversion.h file or get package version 4 | # 5 | # Home page of code is: https://www.smartmontools.org 6 | # 7 | # Copyright (C) 2024 Christian Franke 8 | # 9 | # SPDX-License-Identifier: GPL-2.0-or-later 10 | # 11 | # $Id$ 12 | # 13 | 14 | set -e 15 | myname=$0 16 | 17 | usage() 18 | { 19 | cat < svnversion.h] 21 | 22 | -i Print new contents of svnversion.h 23 | -p Print package version from configure.ac 24 | -q Prepend 'pre-' to package version if pre-release (implies -p) 25 | -r Print svn revision (like 'svnversion') 26 | 27 | METHOD... One or more of 'svn', 'ids' or 'git' [default: svn ids git] 28 | EOF 29 | exit 1 30 | } 31 | 32 | error() 33 | { 34 | echo "$myname: $*" >&2 35 | exit 1 36 | } 37 | 38 | i_opt=false; p_opt=false; q_opt=false; r_opt=false 39 | while true; do case $1 in 40 | -i) i_opt=true ;; 41 | -p) p_opt=true ;; 42 | -q) p_opt=true; q_opt=true ;; 43 | -r) r_opt=true ;; 44 | -*) usage ;; 45 | *) break ;; 46 | esac; shift; done 47 | $i_opt || $p_opt || $r_opt || usage 48 | 49 | if [ $# -ne 0 ]; then 50 | methods=$* 51 | for m in $methods; do case $m in 52 | svn|ids|git) ;; 53 | *) usage ;; 54 | esac; done 55 | else 56 | methods="svn ids git" 57 | fi 58 | 59 | srcdir=${myname%/*} 60 | test "$srcdir" != "$myname" || error 'unknown $srcdir' 61 | 62 | files=" 63 | ChangeLog NEWS Makefile.am configure.ac smart*.in 64 | *.cpp *.h os_win32/*.cpp os_win32/*.h 65 | " 66 | (cd "$srcdir" && ls -d $files >/dev/null) || error "sources not found in $srcdir" 67 | 68 | revision_from_svn() 69 | { 70 | local r t 71 | r=$(cd "$srcdir" && svnversion 2>/dev/null) || return 1 72 | case $r in [1-9][0-9]*) ;; *) return 1 ;; esac 73 | t=$(cd "$srcdir" && TZ='' LC_ALL=C svn info 2>/dev/null) || return 1 74 | t=$(echo "$t" | sed -n 's,^.* Date: *\(2[-0-9]*\) \([0-9][:0-9]*\) .*$,\1 \2,p') 75 | test -n "$t" || return 1 76 | svnrev=$r; revdate=${t% *}; revtime=${t#* } 77 | origin="svn info" 78 | } 79 | 80 | revision_from_ids() 81 | { 82 | local x 83 | x=$(cd "$srcdir" && \ 84 | sed -n 's,^.*\$[I][d]: [^ ]* \([0-9][0-9]*\) \([0-9][-0-9]*\) \([0-9][:0-9]*\)Z [^$]*\$.*$,\1 \2 \3,p' $files \ 85 | | sort -n -r | sed -n 1p) 86 | test -n "$x" || return 1 87 | svnrev=${x%% *}; x=${x#* }; revdate=${x% *}; revtime=${x#* } 88 | origin="Id strings" 89 | } 90 | 91 | revision_from_git() 92 | { 93 | local h r t x 94 | x=$(cd "$srcdir" && TZ='' LC_ALL=C git log -1 --date=iso 2>/dev/null) || return 1 95 | h=$(echo "$x" | sed -n 's,^commit \([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]\).*$,\1,p') 96 | t=$(echo "$x" | sed -n 's,^Date: *\(2[-0-9]*\) \([0-9][:0-9]*\) .*$,\1 \2,p') 97 | r=$(echo "$x" | sed -n 's,^.*git-svn-id: [.:/a-z]*/smartmontools/code/trunk@\([1-9][0-9]*\) 4ea69e.*$,\1,p') 98 | test "${h:+y}${r:+y}${t:+y}" = "yyy" || return 1 99 | test -z "$(cd "$srcdir" && git status -s -uno 2>&1)" || r="${r}M" 100 | svnrev=$r; revdate=${t% *}; revtime=${t#* }; githash=$h 101 | origin="git log" 102 | } 103 | 104 | if $i_opt || $r_opt; then 105 | svnrev=; revdate=; revtime=; githash= 106 | origin="missing information" 107 | for m in $methods; do 108 | revision_from_$m || continue 109 | break 110 | done 111 | 112 | if $i_opt; then 113 | cat < 11 | 12 | struct nvme_user_io { 13 | __u8 opcode; 14 | __u8 flags; 15 | __u16 control; 16 | __u16 nblocks; 17 | __u16 rsvd; 18 | __u64 metadata; 19 | __u64 addr; 20 | __u64 slba; 21 | __u32 dsmgmt; 22 | __u32 reftag; 23 | __u16 apptag; 24 | __u16 appmask; 25 | }; 26 | 27 | struct nvme_passthru_cmd { 28 | __u8 opcode; 29 | __u8 flags; 30 | __u16 rsvd1; 31 | __u32 nsid; 32 | __u32 cdw2; 33 | __u32 cdw3; 34 | __u64 metadata; 35 | __u64 addr; 36 | __u32 metadata_len; 37 | __u32 data_len; 38 | __u32 cdw10; 39 | __u32 cdw11; 40 | __u32 cdw12; 41 | __u32 cdw13; 42 | __u32 cdw14; 43 | __u32 cdw15; 44 | __u32 timeout_ms; 45 | __u32 result; 46 | }; 47 | 48 | #define nvme_admin_cmd nvme_passthru_cmd 49 | 50 | #define NVME_IOCTL_ID _IO('N', 0x40) 51 | #define NVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct nvme_admin_cmd) 52 | #define NVME_IOCTL_SUBMIT_IO _IOW('N', 0x42, struct nvme_user_io) 53 | #define NVME_IOCTL_IO_CMD _IOWR('N', 0x43, struct nvme_passthru_cmd) 54 | #define NVME_IOCTL_RESET _IO('N', 0x44) 55 | #define NVME_IOCTL_SUBSYS_RESET _IO('N', 0x45) 56 | #define NVME_IOCTL_RESCAN _IO('N', 0x46) 57 | 58 | #endif /* _UAPI_LINUX_NVME_IOCTL_H */ 59 | -------------------------------------------------------------------------------- /megaraid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * megaraid.h 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2008 Jordan Hargrave 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | int megaraid_io_interface(int device, int target, struct scsi_cmnd_io *, int); 12 | 13 | #undef u32 14 | 15 | #define u8 uint8_t 16 | #define u16 uint16_t 17 | #define u32 uint32_t 18 | #define u64 uint64_t 19 | 20 | /*====================================================== 21 | * PERC2/3/4 Passthrough SCSI Command Interface 22 | * 23 | * Contents from: 24 | * drivers/scsi/megaraid/megaraid_ioctl.h 25 | * drivers/scsi/megaraid/mbox_defs.h 26 | *======================================================*/ 27 | #define MEGAIOC_MAGIC 'm' 28 | #define MEGAIOCCMD _IOWR(MEGAIOC_MAGIC, 0, struct uioctl_t) 29 | 30 | /* Following subopcode work for opcode == 0x82 */ 31 | #define MKADAP(adapno) (MEGAIOC_MAGIC << 8 | adapno) 32 | #define MEGAIOC_QNADAP 'm' 33 | #define MEGAIOC_QDRVRVER 'e' 34 | #define MEGAIOC_QADAPINFO 'g' 35 | 36 | #define MEGA_MBOXCMD_PASSTHRU 0x03 37 | 38 | #define MAX_REQ_SENSE_LEN 0x20 39 | #define MAX_CDB_LEN 10 40 | 41 | typedef struct 42 | { 43 | uint8_t timeout : 3; 44 | uint8_t ars : 1; 45 | uint8_t reserved : 3; 46 | uint8_t islogical : 1; 47 | uint8_t logdrv; 48 | uint8_t channel; 49 | uint8_t target; 50 | uint8_t queuetag; 51 | uint8_t queueaction; 52 | uint8_t cdb[MAX_CDB_LEN]; 53 | uint8_t cdblen; 54 | uint8_t reqsenselen; 55 | uint8_t reqsensearea[MAX_REQ_SENSE_LEN]; 56 | uint8_t numsgelements; 57 | uint8_t scsistatus; 58 | uint32_t dataxferaddr; 59 | uint32_t dataxferlen; 60 | } __attribute__((packed)) mega_passthru; 61 | 62 | typedef struct 63 | { 64 | uint8_t cmd; 65 | uint8_t cmdid; 66 | uint8_t opcode; 67 | uint8_t subopcode; 68 | uint32_t lba; 69 | uint32_t xferaddr; 70 | uint8_t logdrv; 71 | uint8_t resvd[3]; 72 | uint8_t numstatus; 73 | uint8_t status; 74 | } __attribute__((packed)) megacmd_t; 75 | 76 | typedef union { 77 | uint8_t *pointer; 78 | uint8_t pad[8]; 79 | } ptr_t; 80 | 81 | // The above definition assumes sizeof(void*) <= 8. 82 | // This assumption also exists in the linux megaraid device driver. 83 | // So define a macro to check expected size of ptr_t at compile time using 84 | // a dummy typedef. On size mismatch, compiler reports a negative array 85 | // size. If you see an error message of this form, it means that 86 | // you have an unexpected pointer size on your platform and can not 87 | // use megaraid support in smartmontools. 88 | typedef char assert_sizeof_ptr_t[sizeof(ptr_t) == 8 ? 1 : -1]; 89 | 90 | struct uioctl_t 91 | { 92 | uint32_t inlen; 93 | uint32_t outlen; 94 | union { 95 | uint8_t fca[16]; 96 | struct { 97 | uint8_t opcode; 98 | uint8_t subopcode; 99 | uint16_t adapno; 100 | ptr_t buffer; 101 | uint32_t length; 102 | } __attribute__((packed)) fcs; 103 | } __attribute__((packed)) ui; 104 | 105 | megacmd_t mbox; 106 | mega_passthru pthru; 107 | ptr_t data; 108 | } __attribute__((packed)); 109 | 110 | /*=================================================== 111 | * PERC5/6 Passthrough SCSI Command Interface 112 | * 113 | * Contents from: 114 | * drivers/scsi/megaraid/megaraid_sas.h 115 | *===================================================*/ 116 | #define MEGASAS_MAGIC 'M' 117 | #define MEGASAS_IOC_FIRMWARE _IOWR(MEGASAS_MAGIC, 1, struct megasas_iocpacket) 118 | 119 | #define MFI_CMD_PD_SCSI_IO 0x04 120 | #define MFI_CMD_DCMD 0x05 121 | #define MFI_FRAME_SGL64 0x02 122 | #define MFI_STAT_OK 0x00 123 | #define MFI_DCMD_PD_GET_LIST 0x02010000 124 | /* 125 | * Number of mailbox bytes in DCMD message frame 126 | */ 127 | #define MFI_MBOX_SIZE 12 128 | #define MAX_IOCTL_SGE 16 129 | #define MFI_FRAME_DIR_NONE 0x0000 130 | #define MFI_FRAME_DIR_WRITE 0x0008 131 | #define MFI_FRAME_DIR_READ 0x0010 132 | #define MFI_FRAME_DIR_BOTH 0x0018 133 | 134 | #define MAX_SYS_PDS 240 135 | 136 | struct megasas_sge32 { 137 | 138 | u32 phys_addr; 139 | u32 length; 140 | 141 | } __attribute__ ((packed)); 142 | 143 | struct megasas_sge64 { 144 | 145 | u64 phys_addr; 146 | u32 length; 147 | 148 | } __attribute__ ((packed)); 149 | 150 | union megasas_sgl { 151 | 152 | struct megasas_sge32 sge32[1]; 153 | struct megasas_sge64 sge64[1]; 154 | 155 | } __attribute__ ((packed)); 156 | 157 | struct megasas_header { 158 | 159 | u8 cmd; /*00h */ 160 | u8 sense_len; /*01h */ 161 | u8 cmd_status; /*02h */ 162 | u8 scsi_status; /*03h */ 163 | 164 | u8 target_id; /*04h */ 165 | u8 lun; /*05h */ 166 | u8 cdb_len; /*06h */ 167 | u8 sge_count; /*07h */ 168 | 169 | u32 context; /*08h */ 170 | u32 pad_0; /*0Ch */ 171 | 172 | u16 flags; /*10h */ 173 | u16 timeout; /*12h */ 174 | u32 data_xferlen; /*14h */ 175 | 176 | } __attribute__ ((packed)); 177 | 178 | struct megasas_pthru_frame { 179 | 180 | u8 cmd; /*00h */ 181 | u8 sense_len; /*01h */ 182 | u8 cmd_status; /*02h */ 183 | u8 scsi_status; /*03h */ 184 | 185 | u8 target_id; /*04h */ 186 | u8 lun; /*05h */ 187 | u8 cdb_len; /*06h */ 188 | u8 sge_count; /*07h */ 189 | 190 | u32 context; /*08h */ 191 | u32 pad_0; /*0Ch */ 192 | 193 | u16 flags; /*10h */ 194 | u16 timeout; /*12h */ 195 | u32 data_xfer_len; /*14h */ 196 | 197 | u32 sense_buf_phys_addr_lo; /*18h */ 198 | u32 sense_buf_phys_addr_hi; /*1Ch */ 199 | 200 | u8 cdb[16]; /*20h */ 201 | union megasas_sgl sgl; /*30h */ 202 | 203 | } __attribute__ ((packed)); 204 | 205 | struct megasas_dcmd_frame { 206 | 207 | u8 cmd; /*00h */ 208 | u8 reserved_0; /*01h */ 209 | u8 cmd_status; /*02h */ 210 | u8 reserved_1[4]; /*03h */ 211 | u8 sge_count; /*07h */ 212 | 213 | u32 context; /*08h */ 214 | u32 pad_0; /*0Ch */ 215 | 216 | u16 flags; /*10h */ 217 | u16 timeout; /*12h */ 218 | 219 | u32 data_xfer_len; /*14h */ 220 | u32 opcode; /*18h */ 221 | 222 | union { /*1Ch */ 223 | u8 b[12]; 224 | u16 s[6]; 225 | u32 w[3]; 226 | } mbox; 227 | 228 | union megasas_sgl sgl; /*28h */ 229 | 230 | } __attribute__ ((packed)); 231 | 232 | struct megasas_iocpacket { 233 | u16 host_no; 234 | u16 __pad1; 235 | u32 sgl_off; 236 | u32 sge_count; 237 | u32 sense_off; 238 | u32 sense_len; 239 | union { 240 | u8 raw[128]; 241 | struct megasas_header hdr; 242 | struct megasas_pthru_frame pthru; 243 | struct megasas_dcmd_frame dcmd; 244 | } frame; 245 | 246 | struct iovec sgl[MAX_IOCTL_SGE]; 247 | } __attribute__ ((packed)); 248 | 249 | struct megasas_pd_address { 250 | u16 device_id; 251 | u16 encl_device_id; 252 | u8 encl_index; 253 | u8 slot_number; 254 | u8 scsi_dev_type; /* 0 = disk */ 255 | u8 connect_port_bitmap; 256 | u64 sas_addr[2]; 257 | } __attribute__ ((packed)); 258 | 259 | struct megasas_pd_list { 260 | u32 size; 261 | u32 count; 262 | struct megasas_pd_address addr[MAX_SYS_PDS]; 263 | } __attribute__ ((packed)); 264 | 265 | #undef u8 266 | #undef u16 267 | #undef u32 268 | #undef u64 269 | 270 | -------------------------------------------------------------------------------- /netbsd_nvme_ioctl.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: nvmereg.h,v 1.1 2016/05/01 10:21:02 nonaka Exp $ */ 2 | /* $OpenBSD: nvmereg.h,v 1.10 2016/04/14 11:18:32 dlg Exp $ */ 3 | 4 | /* 5 | * Copyright (c) 2014 David Gwynne 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #include 21 | 22 | struct nvme_sge { 23 | uint8_t id; 24 | uint8_t _reserved[15]; 25 | } __packed __aligned(8); 26 | 27 | struct nvme_sqe { 28 | uint8_t opcode; 29 | uint8_t flags; 30 | uint16_t cid; 31 | 32 | uint32_t nsid; 33 | 34 | uint8_t _reserved[8]; 35 | 36 | uint64_t mptr; 37 | 38 | union { 39 | uint64_t prp[2]; 40 | struct nvme_sge sge; 41 | } __packed entry; 42 | 43 | uint32_t cdw10; 44 | uint32_t cdw11; 45 | uint32_t cdw12; 46 | uint32_t cdw13; 47 | uint32_t cdw14; 48 | uint32_t cdw15; 49 | } __packed __aligned(8); 50 | 51 | struct nvme_cqe { 52 | uint32_t cdw0; 53 | 54 | uint32_t _reserved; 55 | 56 | uint16_t sqhd; /* SQ Head Pointer */ 57 | uint16_t sqid; /* SQ Identifier */ 58 | 59 | uint16_t cid; /* Command Identifier */ 60 | uint16_t flags; 61 | #define NVME_CQE_DNR __BIT(15) 62 | #define NVME_CQE_M __BIT(14) 63 | #define NVME_CQE_SCT(_f) ((_f) & (0x07 << 8)) 64 | #define NVME_CQE_SCT_GENERIC (0x00 << 8) 65 | #define NVME_CQE_SCT_COMMAND (0x01 << 8) 66 | #define NVME_CQE_SCT_MEDIAERR (0x02 << 8) 67 | #define NVME_CQE_SCT_VENDOR (0x07 << 8) 68 | #define NVME_CQE_SC(_f) ((_f) & (0x7f << 1)) 69 | #define NVME_CQE_SC_SUCCESS (0x00 << 1) 70 | #define NVME_CQE_SC_INVALID_OPCODE (0x01 << 1) 71 | #define NVME_CQE_SC_INVALID_FIELD (0x02 << 1) 72 | #define NVME_CQE_SC_CID_CONFLICT (0x03 << 1) 73 | #define NVME_CQE_SC_DATA_XFER_ERR (0x04 << 1) 74 | #define NVME_CQE_SC_ABRT_BY_NO_PWR (0x05 << 1) 75 | #define NVME_CQE_SC_INTERNAL_DEV_ERR (0x06 << 1) 76 | #define NVME_CQE_SC_CMD_ABRT_REQD (0x07 << 1) 77 | #define NVME_CQE_SC_CMD_ABDR_SQ_DEL (0x08 << 1) 78 | #define NVME_CQE_SC_CMD_ABDR_FUSE_ERR (0x09 << 1) 79 | #define NVME_CQE_SC_CMD_ABDR_FUSE_MISS (0x0a << 1) 80 | #define NVME_CQE_SC_INVALID_NS (0x0b << 1) 81 | #define NVME_CQE_SC_CMD_SEQ_ERR (0x0c << 1) 82 | #define NVME_CQE_SC_INVALID_LAST_SGL (0x0d << 1) 83 | #define NVME_CQE_SC_INVALID_NUM_SGL (0x0e << 1) 84 | #define NVME_CQE_SC_DATA_SGL_LEN (0x0f << 1) 85 | #define NVME_CQE_SC_MDATA_SGL_LEN (0x10 << 1) 86 | #define NVME_CQE_SC_SGL_TYPE_INVALID (0x11 << 1) 87 | #define NVME_CQE_SC_LBA_RANGE (0x80 << 1) 88 | #define NVME_CQE_SC_CAP_EXCEEDED (0x81 << 1) 89 | #define NVME_CQE_NS_NOT_RDY (0x82 << 1) 90 | #define NVME_CQE_RSV_CONFLICT (0x83 << 1) 91 | #define NVME_CQE_PHASE __BIT(0) 92 | } __packed __aligned(8); 93 | 94 | /*- 95 | * Copyright (C) 2012-2013 Intel Corporation 96 | * All rights reserved. 97 | * 98 | * Redistribution and use in source and binary forms, with or without 99 | * modification, are permitted provided that the following conditions 100 | * are met: 101 | * 1. Redistributions of source code must retain the above copyright 102 | * notice, this list of conditions and the following disclaimer. 103 | * 2. Redistributions in binary form must reproduce the above copyright 104 | * notice, this list of conditions and the following disclaimer in the 105 | * documentation and/or other materials provided with the distribution. 106 | * 107 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 108 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 109 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 110 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 111 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 112 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 113 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 114 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 115 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 116 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 117 | * SUCH DAMAGE. 118 | * 119 | * $FreeBSD$ 120 | */ 121 | 122 | #define NVME_PASSTHROUGH_CMD _IOWR('n', 0, struct nvme_pt_command) 123 | 124 | #define nvme_completion_is_error(cpl) \ 125 | ((NVME_CQE_SC((cpl)->flags) != NVME_CQE_SC_SUCCESS) \ 126 | || (NVME_CQE_SCT((cpl)->flags) != NVME_CQE_SCT_GENERIC)) 127 | 128 | struct nvme_pt_command { 129 | 130 | /* 131 | * cmd is used to specify a passthrough command to a controller or 132 | * namespace. 133 | * 134 | * The following fields from cmd may be specified by the caller: 135 | * * opcode 136 | * * nsid (namespace id) - for admin commands only 137 | * * cdw10-cdw15 138 | * 139 | * Remaining fields must be set to 0 by the caller. 140 | */ 141 | struct nvme_sqe cmd; 142 | 143 | /* 144 | * cpl returns completion status for the passthrough command 145 | * specified by cmd. 146 | * 147 | * The following fields will be filled out by the driver, for 148 | * consumption by the caller: 149 | * * cdw0 150 | * * flags (except for phase) 151 | * 152 | * Remaining fields will be set to 0 by the driver. 153 | */ 154 | struct nvme_cqe cpl; 155 | 156 | /* buf is the data buffer associated with this passthrough command. */ 157 | void *buf; 158 | 159 | /* 160 | * len is the length of the data buffer associated with this 161 | * passthrough command. 162 | */ 163 | uint32_t len; 164 | 165 | /* 166 | * is_read = 1 if the passthrough command will read data into the 167 | * supplied buffer from the controller. 168 | * 169 | * is_read = 0 if the passthrough command will write data from the 170 | * supplied buffer to the controller. 171 | */ 172 | uint32_t is_read; 173 | 174 | /* 175 | * timeout (unit: ms) 176 | * 177 | * 0: use default timeout value 178 | */ 179 | uint32_t timeout; 180 | }; 181 | 182 | #define NVME_PREFIX "/dev/nvme" 183 | #define NVME_NS_PREFIX "ns" 184 | -------------------------------------------------------------------------------- /nvmeprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * nvmeprint.h 3 | * 4 | * Home page of code is: https://www.smartmontools.org 5 | * 6 | * Copyright (C) 2016-22 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef NVMEPRINT_H 12 | #define NVMEPRINT_H 13 | 14 | #define NVMEPRINT_H_CVSID "$Id$" 15 | 16 | #include "nvmecmds.h" 17 | 18 | // options for nvmePrintMain 19 | struct nvme_print_options 20 | { 21 | bool drive_info = false; 22 | bool drive_capabilities = false; 23 | bool smart_check_status = false; 24 | bool smart_vendor_attrib = false; 25 | bool smart_selftest_log = false; 26 | unsigned char smart_selftest_type = 0; // 0 = no test, 1 = short, 2 = extended, 0xf = abort 27 | unsigned error_log_entries = 0; 28 | unsigned char log_page = 0; 29 | unsigned log_page_size = 0; 30 | }; 31 | 32 | int nvmePrintMain(nvme_device * device, const nvme_print_options & options); 33 | 34 | #endif // NVMEPRINT_H 35 | -------------------------------------------------------------------------------- /os_darwin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * os_generic.h 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2004-8 Geoff Keating 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef OS_DARWIN_H_ 12 | #define OS_DARWIN_H_ 13 | 14 | #define OS_DARWIN_H_CVSID "$Id$\n" 15 | 16 | #define kIOATABlockStorageDeviceClass "IOATABlockStorageDevice" 17 | 18 | // Isn't in 10.3.9? 19 | 20 | #ifndef kIOPropertySMARTCapableKey 21 | #define kIOPropertySMARTCapableKey "SMART Capable" 22 | #endif 23 | 24 | // NVMe definitions based on Xcode SDK, see NVMeSMARTLibExternal.h 25 | #define kIOPropertyNVMeSMARTCapableKey "NVMe SMART Capable" 26 | 27 | // Constant to init driver 28 | #define kIONVMeSMARTUserClientTypeID CFUUIDGetConstantUUIDWithBytes(NULL, \ 29 | 0xAA, 0x0F, 0xA6, 0xF9, 0xC2, 0xD6, 0x45, 0x7F, 0xB1, 0x0B, \ 30 | 0x59, 0xA1, 0x32, 0x53, 0x29, 0x2F) 31 | 32 | // Constant to use plugin interface 33 | #define kIONVMeSMARTInterfaceID CFUUIDGetConstantUUIDWithBytes(NULL, \ 34 | 0xcc, 0xd1, 0xdb, 0x19, 0xfd, 0x9a, 0x4d, 0xaf, 0xbf, 0x95, \ 35 | 0x12, 0x45, 0x4b, 0x23, 0xa, 0xb6) 36 | 37 | typedef struct IONVMeSMARTInterface 38 | { 39 | IUNKNOWN_C_GUTS; 40 | 41 | UInt16 version; 42 | UInt16 revision; 43 | 44 | // NVMe smart data, returns nvme_smart_log structure 45 | IOReturn ( *SMARTReadData )( void * interface, 46 | struct nvme_smart_log * NVMeSMARTData ); 47 | 48 | // NVMe IdentifyData, returns nvme_id_ctrl per namespace 49 | IOReturn ( *GetIdentifyData )( void * interface, 50 | struct nvme_id_ctrl * NVMeIdentifyControllerStruct, 51 | unsigned int ns ); 52 | UInt64 reserved0; 53 | UInt64 reserved1; 54 | 55 | // NumDWords Number of dwords for log page data, zero based. 56 | IOReturn ( *GetLogPage )( void * interface, void * data, unsigned int logPageId, unsigned int numDWords); 57 | 58 | UInt64 reserved2; 59 | UInt64 reserved3; 60 | UInt64 reserved4; 61 | UInt64 reserved5; 62 | UInt64 reserved6; 63 | UInt64 reserved7; 64 | UInt64 reserved8; 65 | UInt64 reserved9; 66 | UInt64 reserved10; 67 | UInt64 reserved11; 68 | UInt64 reserved12; 69 | UInt64 reserved13; 70 | UInt64 reserved14; 71 | UInt64 reserved15; 72 | UInt64 reserved16; 73 | UInt64 reserved17; 74 | UInt64 reserved18; 75 | UInt64 reserved19; 76 | 77 | } IONVMeSMARTInterface; 78 | 79 | 80 | #endif /* OS_DARWIN_H_ */ 81 | -------------------------------------------------------------------------------- /os_darwin/com.smartmontools.smartd.plist.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | KeepAlive 6 | 7 | SuccessfulExit 8 | 9 | 10 | Label 11 | com.smartmontools.smartd 12 | ProgramArguments 13 | 14 | /usr/local/sbin/smartd 15 | -n 16 | 17 | RunAtLoad 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /os_darwin/pkg/Distribution.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | S.M.A.R.T. disk monitoring tools 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | @pkgname@ 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /os_darwin/pkg/PackageInfo.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | -------------------------------------------------------------------------------- /os_darwin/pkg/installer/README.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

About this package

4 | The smartmontools package contains two utility programs (smartctl and smartd) to control 5 | and monitor storage systems using the Self-Monitoring, Analysis and Reporting 6 | Technology System (SMART) built into most modern ATA and SCSI harddisks. 7 | In many cases, these utilities will provide advanced warning of disk degradation and failure. 8 |

Installing

9 | To install package click on the smartmontools.pkg icon and follow installation process. Files will be installed to the /usr/local/ directory. 10 |

Usage

11 | If you are having trouble understanding the output of smartctl or smartd, please first read the manual pages installed on your system: 12 |
13 |   man 8 smartctl
14 |   man 8 smartd
15 |   man 8 update-smart-drivedb
16 |   man 5 smartd.conf
17 | 
18 | To use smartmontools with USB drives please download and install 19 | Max OS X kernel driver for providing access to external drive SMART data. SAT SMART Driver is a free open source project (published under Apple Public Source License) by Jarkko Sonninen. 20 | If you are using OS X El Capitan 10.11+ it is recommended to use signed version available from DriveDx web site. 21 |

22 | More information could be found on the www.smartmontools.org website. 23 |

Uninstalling

24 | If you want to uninstall already installed package run 'sudo smart-pkg-uninstall' in the terminal. 25 | 26 | 27 | -------------------------------------------------------------------------------- /os_darwin/pkg/root/usr/local/sbin/smart-pkg-uninstall: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Smartmontools package uninstaller:" 4 | 5 | # check if we are running with root uid 6 | if [[ $EUID -ne 0 ]]; then 7 | echo " Error: this script must be run as root" 8 | exit 1 9 | fi 10 | 11 | # check if package is installed 12 | pkgutil --info com.smartmontools.pkg > /dev/null 2>/dev/null 13 | if [ $? -ne 0 ]; then 14 | echo " Error: smartmontools package is not installed" 15 | exit 1 16 | fi 17 | 18 | # smartmontools pkg could be installed only on system volume, so this should be safe 19 | cd / 20 | 21 | echo " - removing files" 22 | for str in `pkgutil --files com.smartmontools.pkg` 23 | do 24 | if [ -f "$str" ] 25 | then 26 | rm -f "$str" 27 | fi 28 | done 29 | echo " - removing empty directories" 30 | for str in `pkgutil --files com.smartmontools.pkg` 31 | do 32 | if [ -d "$str" ] 33 | then 34 | rmdir -p "$str" 2>/dev/null 35 | fi 36 | done 37 | 38 | echo " - removing package system entry" 39 | pkgutil --forget com.smartmontools.pkg 40 | echo "Done, smartmontolls package removed" 41 | -------------------------------------------------------------------------------- /os_generic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * os_generic.cpp 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) YEAR YOUR_NAME 7 | * Copyright (C) 2003-8 Bruce Allen 8 | * Copyright (C) 2008-18 Christian Franke 9 | * 10 | * SPDX-License-Identifier: GPL-2.0-or-later 11 | */ 12 | 13 | 14 | /* 15 | NOTE: The code in this file is only called when smartmontools has 16 | been compiled on an unrecognized/unsupported platform. This file 17 | can then serve as a "template" to make os_myOS.cpp if you wish to 18 | build support for that platform. 19 | 20 | 21 | PORTING NOTES AND COMMENTS 22 | -------------------------- 23 | 24 | To port smartmontools to the OS of your choice, please: 25 | 26 | [0] Contact smartmontools-support@listi.jpberlin.de to check 27 | that it's not already been done. 28 | 29 | [1] Make copies of os_generic.h and os_generic.cpp called os_myOS.h 30 | and os_myOS.cpp . 31 | 32 | [2] Modify configure.in so that case "${host}" includes myOS. 33 | 34 | [3] Verify that ./autogen.sh && ./configure && make compiles the 35 | code. If not, fix any compilation problems. If your OS lacks 36 | some function that is used elsewhere in the code, then add a 37 | AC_CHECK_FUNCS([missingfunction]) line to configure.in, and 38 | surround uses of the function with: 39 | #ifdef HAVE_MISSINGFUNCTION 40 | ... 41 | #endif 42 | where the macro HAVE_MISSINGFUNCTION is (or is not) defined in 43 | config.h. 44 | 45 | [4] Now that you have a working build environment, you have to 46 | replace the 'stub' function calls provided in this file. 47 | 48 | Provide the functions defined in this file by fleshing out the 49 | skeletons below. 50 | 51 | [5] Contact smartmontools-support@listi.jpberlin.de to see 52 | about checking your code into the smartmontools CVS archive. 53 | */ 54 | 55 | /* 56 | Developer's note: for testing this file, use an unsupported system, 57 | for example: ./configure --build=rs6000-ibm-aix && make 58 | */ 59 | 60 | 61 | // This is needed for the various HAVE_* macros and PROJECT_* macros. 62 | #include "config.h" 63 | 64 | // These are needed to define prototypes and structures for the 65 | // functions defined below 66 | #include "atacmds.h" 67 | #include "utility.h" 68 | 69 | // This is to include whatever structures and prototypes you define in 70 | // os_generic.h 71 | #include "os_generic.h" 72 | 73 | // Needed by '-V' option (CVS versioning) of smartd/smartctl. You 74 | // should have one *_H_CVSID macro appearing below for each file 75 | // appearing with #include "*.h" above. Please list these (below) in 76 | // alphabetic/dictionary order. 77 | const char * os_XXXX_cpp_cvsid="$Id$" 78 | ATACMDS_H_CVSID CONFIG_H_CVSID OS_GENERIC_H_CVSID UTILITY_H_CVSID; 79 | 80 | // This is here to prevent compiler warnings for unused arguments of 81 | // functions. 82 | #define ARGUSED(x) ((void)(x)) 83 | 84 | // print examples for smartctl. You should modify this function so 85 | // that the device paths are sensible for your OS, and to eliminate 86 | // unsupported commands (eg, 3ware controllers). 87 | static void print_smartctl_examples(){ 88 | printf("=================================================== SMARTCTL EXAMPLES =====\n\n" 89 | " smartctl -a /dev/hda (Prints all SMART information)\n\n" 90 | " smartctl --smart=on --offlineauto=on --saveauto=on /dev/hda\n" 91 | " (Enables SMART on first disk)\n\n" 92 | " smartctl -t long /dev/hda (Executes extended disk self-test)\n\n" 93 | " smartctl --attributes --log=selftest --quietmode=errorsonly /dev/hda\n" 94 | " (Prints Self-Test & Attribute errors)\n" 95 | " smartctl -a --device=3ware,2 /dev/sda\n" 96 | " (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)\n" 97 | ); 98 | return; 99 | } 100 | 101 | ///////////////////////////////////////////////////////////////////////////// 102 | 103 | namespace generic { // No need to publish anything, name provided for Doxygen 104 | 105 | class generic_smart_interface 106 | : public /*implements*/ smart_interface 107 | { 108 | public: 109 | #ifdef HAVE_GET_OS_VERSION_STR 110 | virtual const char * get_os_version_str(); 111 | #endif 112 | 113 | virtual std::string get_app_examples(const char * appname); 114 | 115 | virtual bool scan_smart_devices(smart_device_list & devlist, const char * type, 116 | const char * pattern = 0); 117 | 118 | protected: 119 | virtual ata_device * get_ata_device(const char * name, const char * type); 120 | 121 | virtual scsi_device * get_scsi_device(const char * name, const char * type); 122 | 123 | virtual smart_device * autodetect_smart_device(const char * name); 124 | 125 | virtual smart_device * get_custom_smart_device(const char * name, const char * type); 126 | 127 | virtual std::string get_valid_custom_dev_types_str(); 128 | }; 129 | 130 | 131 | ////////////////////////////////////////////////////////////////////// 132 | 133 | #ifdef HAVE_GET_OS_VERSION_STR 134 | /// Return build host and OS version as static string 135 | const char * generic_smart_interface::get_os_version_str() 136 | { 137 | return ::get_os_version_str(); 138 | } 139 | #endif 140 | 141 | std::string generic_smart_interface::get_app_examples(const char * appname) 142 | { 143 | if (!strcmp(appname, "smartctl")) 144 | ::print_smartctl_examples(); // this prints to stdout ... 145 | return ""; // ... so don't print again. 146 | } 147 | 148 | // Return ATA device object for the given device name or NULL 149 | // the type is always set to "ata" 150 | ata_device * generic_smart_interface::get_ata_device(const char * name, const char * type) 151 | { 152 | ARGUSED(name); 153 | ARGUSED(type); 154 | return NULL; 155 | } 156 | 157 | // Return SCSI device object for the given device name or NULL 158 | // the type is always set to "scsi" 159 | scsi_device * generic_smart_interface::get_scsi_device(const char * name, const char * type) 160 | { 161 | ARGUSED(name); 162 | ARGUSED(type); 163 | return NULL; 164 | } 165 | 166 | 167 | // Return device object for the given device name (autodetect the device type) 168 | smart_device * generic_smart_interface::autodetect_smart_device(const char * name) 169 | { 170 | ARGUSED(name); 171 | // for the given name return the appropriate device type 172 | return NULL; 173 | } 174 | 175 | 176 | // Fill devlist with all OS's disk devices of given type that match the pattern 177 | bool generic_smart_interface::scan_smart_devices(smart_device_list & devlist, 178 | const char * type, const char * pattern /*= 0*/) 179 | { 180 | ARGUSED(devlist); 181 | ARGUSED(type); 182 | ARGUSED(pattern); 183 | return false; 184 | } 185 | 186 | 187 | // Return device object of the given type with specified name or NULL 188 | smart_device * generic_smart_interface::get_custom_smart_device(const char * name, const char * type) 189 | { 190 | ARGUSED(name); 191 | ARGUSED(type); 192 | return NULL; 193 | } 194 | 195 | std::string generic_smart_interface::get_valid_custom_dev_types_str() 196 | { 197 | return ""; 198 | } 199 | 200 | } // namespace 201 | 202 | 203 | ///////////////////////////////////////////////////////////////////////////// 204 | /// Initialize platform interface and register with smi() 205 | 206 | void smart_interface::init() 207 | { 208 | static generic::generic_smart_interface the_interface; 209 | smart_interface::set(&the_interface); 210 | } 211 | -------------------------------------------------------------------------------- /os_generic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * os_generic.h 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) YEAR YOUR_NAME 7 | * Copyright (C) 2003-8 Bruce Allen 8 | * 9 | * SPDX-License-Identifier: GPL-2.0-or-later 10 | */ 11 | 12 | // In the three following lines, change 'GENERIC' to your OS name 13 | #ifndef OS_GENERIC_H_ 14 | #define OS_GENERIC_H_ 15 | #define OS_GENERIC_H_CVSID "$Id$\n" 16 | 17 | // Additional material should start here. Note: to keep the '-V' CVS 18 | // reporting option working as intended, you should only #include 19 | // system include files . Local #include files 20 | // <"something.h"> should be #included in os_generic.c 21 | 22 | #endif /* OS_GENERIC_H_ */ 23 | -------------------------------------------------------------------------------- /os_netbsd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * os_netbsd.h 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2003-8 Sergey Svishchev 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef OS_NETBSD_H_ 12 | #define OS_NETBSD_H_ 13 | 14 | #define OS_NETBSD_H_CVSID "$Id$\n" 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #define ata_smart_selftestlog __netbsd_ata_smart_selftestlog 24 | #include 25 | #if HAVE_DEV_ATA_ATAVAR_H 26 | #include 27 | #endif 28 | #include 29 | #undef ata_smart_selftestlog 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #ifndef WDSM_RD_THRESHOLDS /* pre-1.6.2 system */ 36 | #define WDSM_RD_THRESHOLDS 0xd1 37 | #endif 38 | #ifndef WDSMART_CYL 39 | #define WDSMART_CYL 0xc24f 40 | #endif 41 | 42 | #endif /* OS_NETBSD_H_ */ 43 | -------------------------------------------------------------------------------- /os_openbsd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * os_openbsd.h 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2004-8 David Snyder 7 | * 8 | * Derived from os_netbsd.c by Sergey Svishchev, Copyright (C) 2003-8 9 | * 10 | * SPDX-License-Identifier: GPL-2.0-or-later 11 | */ 12 | 13 | #ifndef OS_OPENBSD_H_ 14 | #define OS_OPENBSD_H_ 15 | 16 | #define OS_OPENBSD_H_CVSID "$Id$\n" 17 | 18 | /* from NetBSD: atareg.h,v 1.17, by Manuel Bouyer */ 19 | /* Actually fits _perfectly_ into OBSDs wdcreg.h, but... */ 20 | /* Subcommands for SMART (features register) */ 21 | #define WDSMART_CYL 0xc24f 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #define ata_smart_selftestlog __openbsd_ata_smart_selftestlog 31 | #include 32 | #if HAVE_DEV_ATA_ATAVAR_H 33 | #include 34 | #endif 35 | #include 36 | #undef ata_smart_selftestlog 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #endif /* OS_OPENBSD_H_ */ 44 | -------------------------------------------------------------------------------- /os_os2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * os_os2.c 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2004-8 Yuri Dario 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef OS_OS2_H_ 12 | #define OS_OS2_H_ 13 | 14 | #define OS_XXXX_H_CVSID "$Id$\n" 15 | 16 | // Additional material should start here. Note: to keep the '-V' CVS 17 | // reporting option working as intended, you should only #include 18 | // system include files . Local #include files 19 | // <"something.h"> should be #included in os_generic.c 20 | 21 | #define INCL_DOS 22 | #include 23 | 24 | #include "os_linux.h" 25 | 26 | #pragma pack(1) 27 | 28 | /* IOCTL definitions from s506oem.h (primarily required for SMART calls) */ 29 | #define DSKSP_CAT_SMART 0x80 /* SMART IOCTL category */ 30 | #define DSKSP_SMART_ONOFF 0x20 /* turn SMART on or off */ 31 | #define DSKSP_SMART_AUTOSAVE_ONOFF 0x21 /* turn SMART autosave on or off */ 32 | #define DSKSP_SMART_SAVE 0x22 /* force save of SMART data */ 33 | #define DSKSP_SMART_GETSTATUS 0x23 /* get SMART status (pass/fail) */ 34 | #define DSKSP_SMART_GET_ATTRIBUTES 0x24 /* get SMART attributes table */ 35 | #define DSKSP_SMART_GET_THRESHOLDS 0x25 /* get SMART thresholds table */ 36 | #define DSKSP_SMART_GET_LOG 0x26 /* get SMART log table */ 37 | #define DSKSP_SMART_AUTO_OFFLINE 0x27 /* set SMART offline autosave timer */ 38 | #define DSKSP_SMART_EXEC_OFFLINE 0x28 /* execute SMART immediate offline */ 39 | 40 | #define SMART_CMD_ON 1 /* on value for related SMART functions */ 41 | #define SMART_CMD_OFF 0 /* off value for related SMART functions */ 42 | 43 | #define DSKSP_CAT_GENERIC 0x90 /* generic IOCTL category */ 44 | #define DSKSP_GET_INQUIRY_DATA 0x42 /* get ATA/ATAPI inquiry data */ 45 | 46 | typedef struct _DSKSP_CommandParameters { 47 | BYTE byPhysicalUnit; /* physical unit number 0-n */ 48 | /* 0 = 1st disk, 1 = 2nd disk, ...*/ 49 | /* 0x80 = Pri/Mas, 0x81=Pri/Sla, 0x82=Sec/Mas,*/ 50 | } DSKSP_CommandParameters, *PDSKSP_CommandParameters; 51 | 52 | struct SMART_ParamExt { 53 | UCHAR byPhysicalUnit; // 0=Pri/Mas, 1=Pri/Sla, 2=Sec/Mas, etc. 54 | ULONG LogAddress; // valid values 0-255. See ATA/ATPI standard 55 | // for details 56 | ULONG SectorCount; // valid values 0-255 See ATA/ATPI standard 57 | // for details 58 | ULONG reserved; // reserved. must be set to 0 59 | }; 60 | 61 | const char * danisdev="\\DEV\\IBMS506$"; // DANIS506 62 | const char * danispref="hd"; 63 | const char * ahcidev="\\DEV\\OS2AHCI$"; // OS2AHCI 64 | const char * ahcipref="ahci"; 65 | 66 | #endif /* OS_GENERIC_H_ */ 67 | -------------------------------------------------------------------------------- /os_win32/daemon_win32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * os_win32/daemon_win32.h 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2004-18 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef DAEMON_WIN32_H 12 | #define DAEMON_WIN32_H 13 | 14 | #define DAEMON_WIN32_H_CVSID "$Id$" 15 | 16 | #include 17 | 18 | // Additional non-ANSI signals 19 | #define SIGHUP (NSIG+1) 20 | #define SIGUSR1 (NSIG+2) 21 | #define SIGUSR2 (NSIG+3) 22 | 23 | 24 | // Options for Windows service 25 | typedef struct daemon_winsvc_options_s { 26 | const char * cmd_opt; // argv[1] option for services 27 | // For service "install" command only: 28 | const char * svcname; // Service name 29 | const char * dispname; // Service display name 30 | const char * descript; // Service description 31 | } daemon_winsvc_options; 32 | 33 | 34 | // This function must be called from main() 35 | int daemon_main(const char * ident, const daemon_winsvc_options * svc_opts, 36 | int (*main_func)(int, char **), int argc, char **argv ); 37 | 38 | // exit(code) returned by a service 39 | extern int daemon_winsvc_exitcode; 40 | 41 | // Simulate signal() 42 | void (*daemon_signal(int sig, void (*func)(int)))(int); 43 | const char * daemon_strsignal(int sig); 44 | 45 | // Simulate sleep() 46 | void daemon_sleep(int seconds); 47 | 48 | // Disable/Enable console 49 | void daemon_disable_console(void); 50 | int daemon_enable_console(const char * title); 51 | 52 | // Detach from console 53 | int daemon_detach(const char * ident); 54 | 55 | #endif // DAEMON_WIN32_H 56 | -------------------------------------------------------------------------------- /os_win32/default.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /os_win32/popen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * os_win32/popen.h 3 | * 4 | * Home page of code is: https://www.smartmontools.org 5 | * 6 | * Copyright (C) 2018-21 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef POPEN_H 12 | #define POPEN_H 13 | 14 | #define POPEN_H_CVSID "$Id$" 15 | 16 | #include 17 | 18 | // MinGW defines these to _popen/_pclose 19 | #undef popen 20 | #undef pclose 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | // popen(3) reimplementation for Windows 27 | // 28 | // The _popen() from MSVCRT is not useful as it always opens a new 29 | // console window if parent process has none. 30 | // 31 | // Differences to popen(3): 32 | // - Only modes "r[bt]" are supported 33 | // - stdin and stderr from parent are not inherited to child process 34 | // but redirected to null device 35 | // - Only one child process can be run at a time 36 | 37 | FILE * popen(const char * command, const char * mode); 38 | 39 | int pclose(FILE * f); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | // Enhanced version of popen() with ability to modify the access token. 46 | // If 'restricted' is set, the child process is run with a restricted access 47 | // token. The local Administrator group and most privileges (all except 48 | // SeChangeNotifyPrivilege) are removed. 49 | FILE * popen_as_restr_user(const char * cmd, const char * mode, bool restricted); 50 | 51 | // Check whether the access token of the current user could be effectively 52 | // restricted. 53 | // Returns false if the current user is the local SYSTEM or Administrator account. 54 | bool popen_as_restr_check(); 55 | 56 | // wait(3) macros from 57 | #ifndef WIFEXITED 58 | #define WIFEXITED(status) (((status) & 0xff) == 0x00) 59 | #define WIFSIGNALED(status) (((status) & 0xff) != 0x00) 60 | #define WIFSTOPPED(status) (0) 61 | #define WEXITSTATUS(status) ((status) >> 8) 62 | #define WTERMSIG(status) ((status) & 0xff) 63 | #define WSTOPSIG(status) (0) 64 | #endif // WIFEXITED 65 | 66 | #endif // POPEN_H 67 | -------------------------------------------------------------------------------- /os_win32/runcmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Run console command and wait for user input 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2011 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | char svnid[] = "$Id$"; 12 | 13 | #include 14 | #include 15 | 16 | int main(int argc, char **argv) 17 | { 18 | char * cmd = GetCommandLineA(); 19 | DWORD exitcode; 20 | STARTUPINFOA si = { sizeof(si), }; 21 | PROCESS_INFORMATION pi; 22 | int key; 23 | 24 | if (*cmd == '"') { 25 | cmd++; 26 | while (*cmd && !(*cmd == '"' && cmd[-1] != '\\')) 27 | cmd++; 28 | if (*cmd) 29 | cmd++; 30 | } 31 | else { 32 | while (*cmd && !(*cmd == ' ' || *cmd == '\t')) 33 | cmd++; 34 | } 35 | 36 | while (*cmd == ' ' || *cmd == '\t') 37 | cmd++; 38 | 39 | if (*cmd) { 40 | printf("%s\n\n", cmd); fflush(stdout); 41 | } 42 | 43 | if (!*cmd) { 44 | printf("Usage: %s COMMAND [ARG ...]\n", argv[0]); 45 | exitcode = 1; 46 | } 47 | else if (!CreateProcessA((char *)0, cmd, 48 | (SECURITY_ATTRIBUTES *)0, (SECURITY_ATTRIBUTES *)0, 49 | TRUE/*inherit*/, 0/*no flags*/, (void *)0, (char *)0, &si, &pi) 50 | ) { 51 | DWORD err = GetLastError(); 52 | if (err == ERROR_FILE_NOT_FOUND) 53 | printf("Command not found\n"); 54 | else 55 | printf("CreateProcess() failed with error=%u\n", err); 56 | exitcode = 1; 57 | } 58 | else { 59 | CloseHandle(pi.hThread); 60 | 61 | exitcode = 42; 62 | WaitForSingleObject(pi.hProcess, INFINITE); 63 | GetExitCodeProcess(pi.hProcess, &exitcode); 64 | CloseHandle(pi.hProcess); 65 | 66 | if (exitcode) 67 | printf("\nExitcode: %u (0x%02x)", exitcode, exitcode); 68 | } 69 | 70 | printf("\nType to exit: "); fflush(stdout); 71 | while (!((key = getc(stdin)) == EOF || key == '\n' || key == '\r')) 72 | ; 73 | printf("\n"); 74 | 75 | return exitcode; 76 | } 77 | -------------------------------------------------------------------------------- /os_win32/smartd_mailer.conf.sample.ps1: -------------------------------------------------------------------------------- 1 | # Sample file for smartd_mailer.conf.ps1 2 | # 3 | # Home page of code is: http://www.smartmontools.org 4 | # $Id$ 5 | 6 | # SMTP Server 7 | $smtpServer = "smtp.domain.local" 8 | 9 | # Optional settings [default values in square brackets] 10 | 11 | # Sender address ["smartd daemon "] 12 | #$from = "Administrator " 13 | 14 | # SMTP Port [25] 15 | #$port = 587 16 | 17 | # Use STARTTLS [$false] 18 | #$useSsl = $true 19 | 20 | # SMTP user name [] 21 | #$username = "USER" 22 | 23 | # Plain text SMTP password [] 24 | #$password = "PASSWORD" 25 | 26 | # Encrypted SMTP password [] 27 | # (embedded newlines, tabs and spaces are ignored) 28 | #$passwordEnc = " 29 | # 0123456789abcdef... 30 | # ... 31 | #" 32 | -------------------------------------------------------------------------------- /os_win32/smartd_mailer.ps1: -------------------------------------------------------------------------------- 1 | # 2 | # smartd mailer script 3 | # 4 | # Home page of code is: http://www.smartmontools.org 5 | # 6 | # Copyright (C) 2016 Christian Franke 7 | # 8 | # SPDX-License-Identifier: GPL-2.0-or-later 9 | # 10 | # $Id$ 11 | # 12 | 13 | $ErrorActionPreference = "Stop" 14 | 15 | # Parse command line and check environment 16 | $dryrun = $false 17 | if (($args.Count -eq 1) -and ($args[0] -eq "--dryrun")) { 18 | $dryrun = $true 19 | } 20 | 21 | $toCsv = $env:SMARTD_ADDRCSV 22 | $subject = $env:SMARTD_SUBJECT 23 | $file = $env:SMARTD_FULLMSGFILE 24 | 25 | if (!((($args.Count -eq 0) -or $dryrun) -and $toCsv -and $subject -and $file)) { 26 | echo ` 27 | "smartd mailer script 28 | 29 | Usage: 30 | set SMARTD_ADDRCSV='Comma separated mail addresses' 31 | set SMARTD_SUBJECT='Mail Subject' 32 | set SMARTD_FULLMSGFILE='X:\PATH\TO\Message.txt' 33 | 34 | .\$($MyInvocation.MyCommand.Name) [--dryrun] 35 | " 36 | exit 1 37 | } 38 | 39 | # Set default sender address 40 | if ($env:COMPUTERNAME -match '^[-_A-Za-z0-9]+$') { 41 | $hostname = $env:COMPUTERNAME.ToLower() 42 | } else { 43 | $hostname = "unknown" 44 | } 45 | if ($env:USERDNSDOMAIN -match '^[-._A-Za-z0-9]+$') { 46 | $hostname += ".$($env:USERDNSDOMAIN.ToLower())" 47 | } elseif ( ($env:USERDOMAIN -match '^[-_A-Za-z0-9]+$') ` 48 | -and ($env:USERDOMAIN -ne $env:COMPUTERNAME) ) { 49 | $hostname += ".$($env:USERDOMAIN.ToLower()).local" 50 | } else { 51 | $hostname += ".local" 52 | } 53 | 54 | $from = "smartd daemon " 55 | 56 | # Read configuration 57 | . .\smartd_mailer.conf.ps1 58 | 59 | # Create parameters 60 | $to = $toCsv.Split(",") 61 | $body = Get-Content -Path $file | Out-String 62 | 63 | $parm = @{ 64 | SmtpServer = $smtpServer; From = $from; To = $to 65 | Subject = $subject; Body = $body 66 | } 67 | if ($port) { 68 | $parm += @{ Port = $port } 69 | } 70 | if ($useSsl) { 71 | $parm += @{ useSsl = $true } 72 | } 73 | 74 | if ($username -and ($password -or $passwordEnc)) { 75 | if (!$passwordEnc) { 76 | $secureString = ConvertTo-SecureString -String $password -AsPlainText -Force 77 | } else { 78 | $passwordEnc = $passwordEnc -replace '[\r\n\t ]','' 79 | $secureString = ConvertTo-SecureString -String $passwordEnc 80 | } 81 | $credential = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist $username,$secureString 82 | $parm += @{ Credential = $credential } 83 | } 84 | 85 | # Send mail 86 | if ($dryrun) { 87 | echo "Send-MailMessage" @parm 88 | } else { 89 | Send-MailMessage @parm 90 | } 91 | -------------------------------------------------------------------------------- /os_win32/smartd_warning.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: 3 | :: smartd warning script 4 | :: 5 | :: Home page of code is: http://www.smartmontools.org 6 | :: 7 | :: Copyright (C) 2012-22 Christian Franke 8 | :: 9 | :: SPDX-License-Identifier: GPL-2.0-or-later 10 | :: 11 | :: $Id$ 12 | :: 13 | 14 | verify other 2>nul 15 | setlocal enableextensions enabledelayedexpansion 16 | if errorlevel 1 goto UNSUPPORTED 17 | set err= 18 | 19 | :: Change to script directory (not necessary if run from smartd service) 20 | cd /d %~dp0 21 | if errorlevel 1 goto ERROR 22 | 23 | :: Detect accidental use of '-M exec /path/to/smartd_warning.cmd' 24 | if not "!SMARTD_SUBJECT!" == "" ( 25 | echo smartd_warning.cmd: SMARTD_SUBJECT is already set - possible recursion 26 | goto ERROR 27 | ) 28 | 29 | :: Parse options 30 | set dryrun= 31 | if "%1" == "--dryrun" ( 32 | set dryrun=--dryrun 33 | shift 34 | ) 35 | if not "!dryrun!" == "" echo cd /d !cd! 36 | 37 | if not "%1" == "" ( 38 | echo smartd warning message script 39 | echo. 40 | echo Usage: 41 | echo set SMARTD_MAILER='Path to external script, empty for "blat"' 42 | echo set SMARTD_ADDRESS='Space separated mail addresses, empty if none' 43 | echo set SMARTD_MESSAGE='Error Message' 44 | echo set SMARTD_FAILTYPE='Type of failure, "EMailTest" for tests' 45 | echo set SMARTD_TFIRST='Date of first message sent, empty if none' 46 | echo :: set SMARTD_TFIRSTEPOCH='time_t format of above' 47 | echo set SMARTD_PREVCNT='Number of previous messages, 0 if none' 48 | echo set SMARTD_NEXTDAYS='Number of days until next message, empty if none' 49 | echo set SMARTD_DEVICEINFO='Device identify information' 50 | echo :: set SMARTD_DEVICE='Device name' 51 | echo :: set SMARTD_DEVICESTRING='Annotated device name' 52 | echo :: set SMARTD_DEVICETYPE='Device type from -d directive, "auto" if none' 53 | 54 | echo smartd_warning.cmd [--dryrun] 55 | goto ERROR 56 | ) 57 | 58 | if "!SMARTD_ADDRESS!!SMARTD_MAILER!" == "" ( 59 | echo smartd_warning.cmd: SMARTD_ADDRESS or SMARTD_MAILER must be set 60 | goto ERROR 61 | ) 62 | 63 | :: USERDNSDOMAIN may be unset if running as service 64 | if "!USERDNSDOMAIN!" == "" ( 65 | for /f "delims== tokens=2 usebackq" %%d in (`wmic PATH Win32_Computersystem WHERE "PartOfDomain=TRUE" GET Domain /VALUE ^nul`) do set USERDNSDOMAIN=%%~d 66 | ) 67 | :: Remove possible trailing \r appended by above command (requires %...%) 68 | set USERDNSDOMAIN=%USERDNSDOMAIN% 69 | 70 | :: Format subject 71 | set SMARTD_SUBJECT=SMART error (!SMARTD_FAILTYPE!) detected on host: !COMPUTERNAME! 72 | 73 | :: Temp file for message 74 | if not "!TMP!" == "" set SMARTD_FULLMSGFILE=!TMP!\smartd_warning-!RANDOM!.txt 75 | if "!TMP!" == "" set SMARTD_FULLMSGFILE=smartd_warning-!RANDOM!.txt 76 | 77 | :: Format message 78 | ( 79 | echo This message was generated by the smartd service running on: 80 | echo. 81 | echo. host name: !COMPUTERNAME! 82 | if not "!USERDNSDOMAIN!" == "" echo. DNS domain: !USERDNSDOMAIN! 83 | if "!USERDNSDOMAIN!" == "" echo. DNS domain: [Empty] 84 | if not "!USERDOMAIN!" == "" echo. Win domain: !USERDOMAIN! 85 | echo. 86 | echo The following warning/error was logged by the smartd service: 87 | echo. 88 | if not "!SMARTD_MESSAGE!" == "" echo !SMARTD_MESSAGE! 89 | if "!SMARTD_MESSAGE!" == "" echo [SMARTD_MESSAGE] 90 | echo. 91 | echo Device info: 92 | if not "!SMARTD_DEVICEINFO!" == "" echo !SMARTD_DEVICEINFO! 93 | if "!SMARTD_DEVICEINFO!" == "" echo [SMARTD_DEVICEINFO] 94 | echo. 95 | echo For details see the event log or log file of smartd. 96 | if not "!SMARTD_FAILTYPE!" == "EmailTest" ( 97 | echo. 98 | echo You can also use the smartctl utility for further investigation. 99 | if not "!SMARTD_PREVCNT!" == "0" echo The original message about this issue was sent at !SMARTD_TFIRST! 100 | if "!SMARTD_NEXTDAYS!" == "" ( 101 | echo No additional messages about this problem will be sent. 102 | ) else ( if "!SMARTD_NEXTDAYS!" == "0" ( 103 | echo Another message will be sent upon next check if the problem persists. 104 | ) else ( if "!SMARTD_NEXTDAYS!" == "1" ( 105 | echo Another message will be sent in 24 hours if the problem persists. 106 | ) else ( 107 | echo Another message will be sent in !SMARTD_NEXTDAYS! days if the problem persists. 108 | ))) 109 | ) 110 | ) > "!SMARTD_FULLMSGFILE!" 111 | if errorlevel 1 goto ERROR 112 | 113 | if not "!dryrun!" == "" ( 114 | echo !SMARTD_FULLMSGFILE!: 115 | type "!SMARTD_FULLMSGFILE!" 116 | echo --EOF-- 117 | ) 118 | 119 | :: Check first address 120 | set first= 121 | for /f "tokens=1*" %%a in ("!SMARTD_ADDRESS!") do (set first=%%a) 122 | set wtssend= 123 | if "!first!" == "console" set wtssend=-c 124 | if "!first!" == "active" set wtssend=-a 125 | if "!first!" == "connected" set wtssend=-s 126 | 127 | if not "!wtssend!" == "" ( 128 | :: Show Message box(es) via WTSSendMessage() 129 | if not "!dryrun!" == "" ( 130 | echo call .\wtssendmsg !wtssend! "!SMARTD_SUBJECT!" - ^< "!SMARTD_FULLMSGFILE!" 131 | ) else ( 132 | call .\wtssendmsg !wtssend! "!SMARTD_SUBJECT!" - < "!SMARTD_FULLMSGFILE!" 133 | if errorlevel 1 set err=t 134 | ) 135 | :: Remove first address 136 | for /f "tokens=1*" %%a in ("!SMARTD_ADDRESS!") do (set SMARTD_ADDRESS=%%b) 137 | ) 138 | 139 | :: Make comma separated address list 140 | set SMARTD_ADDRCSV= 141 | if not "!SMARTD_ADDRESS!" == "" set SMARTD_ADDRCSV=!SMARTD_ADDRESS: =,! 142 | 143 | :: Default mailer is smartd_mailer.ps1 (if configured) or blat.exe 144 | if not "!SMARTD_ADDRESS!" == "" if "!SMARTD_MAILER!" == "" ( 145 | if not exist smartd_mailer.conf.ps1 set SMARTD_MAILER=blat 146 | ) 147 | 148 | :: Get mailer extension 149 | set ext= 150 | for /f "delims=" %%f in ("!SMARTD_MAILER!") do (set ext=%%~xf) 151 | 152 | :: Send mail or run command 153 | if "!ext!" == ".ps1" ( 154 | 155 | :: Run PowerShell script 156 | if not "!dryrun!" == "" ( 157 | set esc=^^ 158 | echo PowerShell -NoProfile -ExecutionPolicy Bypass -Command !esc!^& '!SMARTD_MAILER!' ^nul 2>nul 203 | 204 | if not "!err!" == "" goto ERROR 205 | endlocal 206 | exit /b 0 207 | 208 | :ERROR 209 | endlocal 210 | exit /b 1 211 | -------------------------------------------------------------------------------- /os_win32/syslog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * os_win32/syslog.h 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2004-8 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef SYSLOG_H 12 | #define SYSLOG_H 13 | 14 | #define SYSLOG_H_CVSID "$Id$\n" 15 | 16 | #include 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /* EVENTLOG_ERROR_TYPE: */ 23 | #define LOG_EMERG 0 24 | #define LOG_ALERT 1 25 | #define LOG_CRIT 2 26 | #define LOG_ERR 3 27 | /* EVENTLOG_WARNING_TYPE: */ 28 | #define LOG_WARNING 4 29 | /* EVENTLOG_INFORMATION_TYPE: */ 30 | #define LOG_NOTICE 5 31 | #define LOG_INFO 6 32 | #define LOG_DEBUG 7 33 | 34 | /* event log: */ 35 | #define LOG_DAEMON ( 3<<3) 36 | /* ident.log: */ 37 | #define LOG_LOCAL0 (16<<3) 38 | /* ident1-7.log: */ 39 | #define LOG_LOCAL1 (17<<3) 40 | #define LOG_LOCAL2 (18<<3) 41 | #define LOG_LOCAL3 (19<<3) 42 | #define LOG_LOCAL4 (20<<3) 43 | #define LOG_LOCAL5 (21<<3) 44 | #define LOG_LOCAL6 (22<<3) 45 | #define LOG_LOCAL7 (23<<3) 46 | 47 | #define LOG_FACMASK 0x03f8 48 | #define LOG_FAC(f) (((f) & LOG_FACMASK) >> 3) 49 | 50 | #define LOG_PID 0x01 51 | 52 | void openlog(const char * ident, int option, int facility); 53 | 54 | void closelog(void); 55 | 56 | void vsyslog(int priority, const char * message, va_list args); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* SYSLOG_H */ 63 | -------------------------------------------------------------------------------- /os_win32/syslogevt.mc: -------------------------------------------------------------------------------- 1 | ;/* 2 | ; * os_win32/syslogevt.mc 3 | ; * 4 | ; * Home page of code is: http://www.smartmontools.org 5 | ; * 6 | ; * Copyright (C) 2004-10 Christian Franke 7 | ; * 8 | ; * SPDX-License-Identifier: GPL-2.0-or-later 9 | ; */ 10 | ; 11 | ;// $Id$ 12 | ; 13 | ;// Use message compiler "mc" or "windmc" to generate 14 | ;// syslogevt.rc, syslogevt.h, msg00001.bin 15 | ;// from this file. 16 | ;// MSG_SYSLOG in syslogmsg.h must be zero 17 | ;// MSG_SYSLOG_nn must be == nn 18 | ; 19 | ;// MS and binutils message compiler defaults for FacilityNames differ: 20 | ;// mc: Application = 0x000 21 | ;// windmc: Application = 0xfff 22 | FacilityNames = (Application = 0x000) 23 | 24 | MessageId=0x0 25 | Severity=Success 26 | Facility=Application 27 | SymbolicName=MSG_SYSLOG 28 | Language=English 29 | %1 30 | . 31 | ;// 1-10 Line SYSLOG Messages 32 | ;// %1=Ident, %2=PID, %3=Severity, %[4-13]=Line 1-10 33 | MessageId=0x1 34 | Severity=Success 35 | Facility=Application 36 | SymbolicName=MSG_SYSLOG_01 37 | Language=English 38 | %1[%2]:%3: %4 39 | . 40 | MessageId=0x2 41 | Severity=Success 42 | Facility=Application 43 | SymbolicName=MSG_SYSLOG_02 44 | Language=English 45 | %1[%2]:%3%n 46 | %4%n 47 | %5 48 | . 49 | MessageId=0x3 50 | Severity=Success 51 | Facility=Application 52 | SymbolicName=MSG_SYSLOG_03 53 | Language=English 54 | %1[%2]:%3%n 55 | %4%n 56 | %5%n 57 | %6 58 | . 59 | MessageId=0x4 60 | Severity=Success 61 | Facility=Application 62 | SymbolicName=MSG_SYSLOG_04 63 | Language=English 64 | %1[%2]:%3%n 65 | %4%n 66 | %5%n 67 | %6%n 68 | %7 69 | . 70 | MessageId=0x5 71 | Severity=Success 72 | Facility=Application 73 | SymbolicName=MSG_SYSLOG_05 74 | Language=English 75 | %1[%2]:%3%n 76 | %4%n 77 | %5%n 78 | %6%n 79 | %7%n 80 | %8 81 | . 82 | MessageId=0x6 83 | Severity=Success 84 | Facility=Application 85 | SymbolicName=MSG_SYSLOG_06 86 | Language=English 87 | %1[%2]:%3%n 88 | %4%n 89 | %5%n 90 | %6%n 91 | %7%n 92 | %8%n 93 | %9 94 | . 95 | MessageId=0x7 96 | Severity=Success 97 | Facility=Application 98 | SymbolicName=MSG_SYSLOG_07 99 | Language=English 100 | %1[%2]:%3%n 101 | %4%n 102 | %5%n 103 | %6%n 104 | %7%n 105 | %8%n 106 | %9%n 107 | %10 108 | . 109 | MessageId=0x8 110 | Severity=Success 111 | Facility=Application 112 | SymbolicName=MSG_SYSLOG_08 113 | Language=English 114 | %1[%2]:%3%n 115 | %4%n 116 | %5%n 117 | %6%n 118 | %7%n 119 | %8%n 120 | %9%n 121 | %10%n 122 | %11 123 | . 124 | MessageId=0x9 125 | Severity=Success 126 | Facility=Application 127 | SymbolicName=MSG_SYSLOG_09 128 | Language=English 129 | %1[%2]:%3%n 130 | %4%n 131 | %5%n 132 | %6%n 133 | %7%n 134 | %8%n 135 | %9%n 136 | %10%n 137 | %11%n 138 | %12 139 | . 140 | MessageId=0xa 141 | Severity=Success 142 | Facility=Application 143 | SymbolicName=MSG_SYSLOG_10 144 | Language=English 145 | %1[%2]:%3%n 146 | %4%n 147 | %5%n 148 | %6%n 149 | %7%n 150 | %8%n 151 | %9%n 152 | %10%n 153 | %11%n 154 | %12%n 155 | %13 156 | . 157 | -------------------------------------------------------------------------------- /os_win32/vc16/smartmontools.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30517.126 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "smartctl", "smartctl.vcxproj", "{3AFEDCDD-D289-4543-A91D-EFBA6C710247}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "smartd", "smartd.vcxproj", "{C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "runcmd", "runcmd.vcxproj", "{11A4B619-D97B-499F-AF17-CF9F80BF70E8}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wtssendmsg", "wtssendmsg.vcxproj", "{0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Win32 = Debug|Win32 17 | Debug|x64 = Debug|x64 18 | Debug-static|Win32 = Debug-static|Win32 19 | Debug-static|x64 = Debug-static|x64 20 | Release|Win32 = Release|Win32 21 | Release|x64 = Release|x64 22 | Release-static|Win32 = Release-static|Win32 23 | Release-static|x64 = Release-static|x64 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug|Win32.ActiveCfg = Debug|Win32 27 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug|Win32.Build.0 = Debug|Win32 28 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug|x64.ActiveCfg = Debug|x64 29 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug|x64.Build.0 = Debug|x64 30 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug-static|Win32.ActiveCfg = Debug-static|Win32 31 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug-static|Win32.Build.0 = Debug-static|Win32 32 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug-static|x64.ActiveCfg = Debug-static|x64 33 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug-static|x64.Build.0 = Debug-static|x64 34 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release|Win32.ActiveCfg = Release|Win32 35 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release|Win32.Build.0 = Release|Win32 36 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release|x64.ActiveCfg = Release|x64 37 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release|x64.Build.0 = Release|x64 38 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release-static|Win32.ActiveCfg = Release-static|Win32 39 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release-static|Win32.Build.0 = Release-static|Win32 40 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release-static|x64.ActiveCfg = Release-static|x64 41 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release-static|x64.Build.0 = Release-static|x64 42 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug|Win32.ActiveCfg = Debug|Win32 43 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug|Win32.Build.0 = Debug|Win32 44 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug|x64.ActiveCfg = Debug|x64 45 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug|x64.Build.0 = Debug|x64 46 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug-static|Win32.ActiveCfg = Debug-static|Win32 47 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug-static|Win32.Build.0 = Debug-static|Win32 48 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug-static|x64.ActiveCfg = Debug-static|x64 49 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug-static|x64.Build.0 = Debug-static|x64 50 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release|Win32.ActiveCfg = Release|Win32 51 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release|Win32.Build.0 = Release|Win32 52 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release|x64.ActiveCfg = Release|x64 53 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release|x64.Build.0 = Release|x64 54 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release-static|Win32.ActiveCfg = Release-static|Win32 55 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release-static|Win32.Build.0 = Release-static|Win32 56 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release-static|x64.ActiveCfg = Release-static|x64 57 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release-static|x64.Build.0 = Release-static|x64 58 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug|Win32.ActiveCfg = Debug|Win32 59 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug|Win32.Build.0 = Debug|Win32 60 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug|x64.ActiveCfg = Debug|x64 61 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug|x64.Build.0 = Debug|x64 62 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug-static|Win32.ActiveCfg = Debug-static|Win32 63 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug-static|Win32.Build.0 = Debug-static|Win32 64 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug-static|x64.ActiveCfg = Debug-static|x64 65 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug-static|x64.Build.0 = Debug-static|x64 66 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release|Win32.ActiveCfg = Release|Win32 67 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release|Win32.Build.0 = Release|Win32 68 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release|x64.ActiveCfg = Release|x64 69 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release|x64.Build.0 = Release|x64 70 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release-static|Win32.ActiveCfg = Release-static|Win32 71 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release-static|Win32.Build.0 = Release-static|Win32 72 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release-static|x64.ActiveCfg = Release-static|x64 73 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release-static|x64.Build.0 = Release-static|x64 74 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug|Win32.ActiveCfg = Debug|Win32 75 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug|Win32.Build.0 = Debug|Win32 76 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug|x64.ActiveCfg = Debug|x64 77 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug|x64.Build.0 = Debug|x64 78 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug-static|Win32.ActiveCfg = Debug-static|Win32 79 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug-static|Win32.Build.0 = Debug-static|Win32 80 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug-static|x64.ActiveCfg = Debug-static|x64 81 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug-static|x64.Build.0 = Debug-static|x64 82 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release|Win32.ActiveCfg = Release|Win32 83 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release|Win32.Build.0 = Release|Win32 84 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release|x64.ActiveCfg = Release|x64 85 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release|x64.Build.0 = Release|x64 86 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release-static|Win32.ActiveCfg = Release-static|Win32 87 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release-static|Win32.Build.0 = Release-static|Win32 88 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release-static|x64.ActiveCfg = Release-static|x64 89 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release-static|x64.Build.0 = Release-static|x64 90 | EndGlobalSection 91 | GlobalSection(SolutionProperties) = preSolution 92 | HideSolutionNode = FALSE 93 | EndGlobalSection 94 | GlobalSection(ExtensibilityGlobals) = postSolution 95 | SolutionGuid = {A6AC8909-C76F-4E34-B596-3A3420C7E931} 96 | EndGlobalSection 97 | EndGlobal 98 | -------------------------------------------------------------------------------- /os_win32/vc17/smartmontools.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32414.318 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "smartctl", "smartctl.vcxproj", "{3AFEDCDD-D289-4543-A91D-EFBA6C710247}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "smartd", "smartd.vcxproj", "{C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "runcmd", "runcmd.vcxproj", "{11A4B619-D97B-499F-AF17-CF9F80BF70E8}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wtssendmsg", "wtssendmsg.vcxproj", "{0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Win32 = Debug|Win32 17 | Debug|x64 = Debug|x64 18 | Debug-static|Win32 = Debug-static|Win32 19 | Debug-static|x64 = Debug-static|x64 20 | Release|Win32 = Release|Win32 21 | Release|x64 = Release|x64 22 | Release-static|Win32 = Release-static|Win32 23 | Release-static|x64 = Release-static|x64 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug|Win32.ActiveCfg = Debug|Win32 27 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug|Win32.Build.0 = Debug|Win32 28 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug|x64.ActiveCfg = Debug|x64 29 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug|x64.Build.0 = Debug|x64 30 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug-static|Win32.ActiveCfg = Debug-static|Win32 31 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug-static|Win32.Build.0 = Debug-static|Win32 32 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug-static|x64.ActiveCfg = Debug-static|x64 33 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Debug-static|x64.Build.0 = Debug-static|x64 34 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release|Win32.ActiveCfg = Release|Win32 35 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release|Win32.Build.0 = Release|Win32 36 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release|x64.ActiveCfg = Release|x64 37 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release|x64.Build.0 = Release|x64 38 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release-static|Win32.ActiveCfg = Release-static|Win32 39 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release-static|Win32.Build.0 = Release-static|Win32 40 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release-static|x64.ActiveCfg = Release-static|x64 41 | {3AFEDCDD-D289-4543-A91D-EFBA6C710247}.Release-static|x64.Build.0 = Release-static|x64 42 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug|Win32.ActiveCfg = Debug|Win32 43 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug|Win32.Build.0 = Debug|Win32 44 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug|x64.ActiveCfg = Debug|x64 45 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug|x64.Build.0 = Debug|x64 46 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug-static|Win32.ActiveCfg = Debug-static|Win32 47 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug-static|Win32.Build.0 = Debug-static|Win32 48 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug-static|x64.ActiveCfg = Debug-static|x64 49 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Debug-static|x64.Build.0 = Debug-static|x64 50 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release|Win32.ActiveCfg = Release|Win32 51 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release|Win32.Build.0 = Release|Win32 52 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release|x64.ActiveCfg = Release|x64 53 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release|x64.Build.0 = Release|x64 54 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release-static|Win32.ActiveCfg = Release-static|Win32 55 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release-static|Win32.Build.0 = Release-static|Win32 56 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release-static|x64.ActiveCfg = Release-static|x64 57 | {C0762191-C2AC-40B6-A2EB-F1658BBDC4C6}.Release-static|x64.Build.0 = Release-static|x64 58 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug|Win32.ActiveCfg = Debug|Win32 59 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug|Win32.Build.0 = Debug|Win32 60 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug|x64.ActiveCfg = Debug|x64 61 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug|x64.Build.0 = Debug|x64 62 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug-static|Win32.ActiveCfg = Debug-static|Win32 63 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug-static|Win32.Build.0 = Debug-static|Win32 64 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug-static|x64.ActiveCfg = Debug-static|x64 65 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Debug-static|x64.Build.0 = Debug-static|x64 66 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release|Win32.ActiveCfg = Release|Win32 67 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release|Win32.Build.0 = Release|Win32 68 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release|x64.ActiveCfg = Release|x64 69 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release|x64.Build.0 = Release|x64 70 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release-static|Win32.ActiveCfg = Release-static|Win32 71 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release-static|Win32.Build.0 = Release-static|Win32 72 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release-static|x64.ActiveCfg = Release-static|x64 73 | {11A4B619-D97B-499F-AF17-CF9F80BF70E8}.Release-static|x64.Build.0 = Release-static|x64 74 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug|Win32.ActiveCfg = Debug|Win32 75 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug|Win32.Build.0 = Debug|Win32 76 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug|x64.ActiveCfg = Debug|x64 77 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug|x64.Build.0 = Debug|x64 78 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug-static|Win32.ActiveCfg = Debug-static|Win32 79 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug-static|Win32.Build.0 = Debug-static|Win32 80 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug-static|x64.ActiveCfg = Debug-static|x64 81 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Debug-static|x64.Build.0 = Debug-static|x64 82 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release|Win32.ActiveCfg = Release|Win32 83 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release|Win32.Build.0 = Release|Win32 84 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release|x64.ActiveCfg = Release|x64 85 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release|x64.Build.0 = Release|x64 86 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release-static|Win32.ActiveCfg = Release-static|Win32 87 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release-static|Win32.Build.0 = Release-static|Win32 88 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release-static|x64.ActiveCfg = Release-static|x64 89 | {0B6B7D19-07AE-41DD-B70E-2F74362A4EC0}.Release-static|x64.Build.0 = Release-static|x64 90 | EndGlobalSection 91 | GlobalSection(SolutionProperties) = preSolution 92 | HideSolutionNode = FALSE 93 | EndGlobalSection 94 | GlobalSection(ExtensibilityGlobals) = postSolution 95 | SolutionGuid = {A6AC8909-C76F-4E34-B596-3A3420C7E931} 96 | EndGlobalSection 97 | EndGlobal 98 | -------------------------------------------------------------------------------- /os_win32/versioninfo.rc.in: -------------------------------------------------------------------------------- 1 | // 2 | // os_win32/versioninfo.rc.in 3 | // 4 | // $Id$ 5 | // 6 | 7 | 1 VERSIONINFO 8 | FILEVERSION @BINARY_VERSION@ 9 | PRODUCTVERSION @BINARY_VERSION@ 10 | FILEFLAGSMASK 0x0 11 | FILEFLAGS 0x0 12 | FILEOS 0x4 // VOS__WINDOWS32 13 | FILETYPE 0x1 // VFT_APP 14 | FILESUBTYPE 0x0 15 | BEGIN 16 | BLOCK "StringFileInfo" 17 | BEGIN 18 | BLOCK "04090000" 19 | BEGIN 20 | VALUE "CompanyName", "www.smartmontools.org" 21 | VALUE "FileDescription", "@DESC@" 22 | VALUE "FileVersion", "@TEXT_VERSION@" 23 | VALUE "InternalName", "@NAME@" 24 | VALUE "LegalCopyright", "(C) 2002-@YY@, Bruce Allen, Christian Franke, www.smartmontools.org" 25 | VALUE "OriginalFilename", "@NAME@.exe" 26 | VALUE "ProductName", "smartmontools" 27 | VALUE "ProductVersion", "@TEXT_VERSION@" 28 | END 29 | END 30 | BLOCK "VarFileInfo" 31 | BEGIN 32 | VALUE "Translation", 0x0409, 0x0000 33 | END 34 | END 35 | -------------------------------------------------------------------------------- /os_win32/wmiquery.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * os_win32/wmiquery.cpp 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2011-13 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #include "config.h" 12 | #define WINVER 0x0400 13 | #define _WIN32_WINNT WINVER 14 | 15 | #include "wmiquery.h" 16 | 17 | #include 18 | 19 | const char * wmiquery_cpp_cvsid = "$Id$" 20 | WMIQUERY_H_CVSID; 21 | 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // com_bstr 25 | 26 | com_bstr::com_bstr(const char * str) 27 | : m_bstr(0) 28 | { 29 | int sz = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, (LPWSTR)0, 0); 30 | if (sz <= 0) 31 | return; 32 | m_bstr = SysAllocStringLen((OLECHAR*)0, sz-1); 33 | if (!m_bstr) 34 | return; // throw std::bad_alloc 35 | MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, m_bstr, sz); 36 | } 37 | 38 | bool com_bstr::to_str(const BSTR & bstr, std::string & str) 39 | { 40 | if (!bstr) 41 | return false; 42 | int sz = WideCharToMultiByte(CP_ACP, 0, bstr, -1, (LPSTR)0, 0, (LPCSTR)0, (LPBOOL)0); 43 | if (sz <= 0) 44 | return false; 45 | char * buf = new char[sz]; 46 | WideCharToMultiByte(CP_ACP, 0, bstr, -1, buf, sz, (LPCSTR)0, (LPBOOL)0); 47 | str = buf; 48 | delete [] buf; 49 | return true; 50 | } 51 | 52 | 53 | ///////////////////////////////////////////////////////////////////////////// 54 | // wbem_object 55 | 56 | std::string wbem_object::get_str(const char * name) /*const*/ 57 | { 58 | std::string s; 59 | if (!m_intf) 60 | return s; 61 | 62 | VARIANT var; VariantInit(&var); 63 | if (m_intf->Get(com_bstr(name), 0L, &var, (CIMTYPE*)0, (LPLONG)0) /* != WBEM_S_NO_ERROR */) 64 | return s; 65 | 66 | if (var.vt == VT_BSTR) 67 | com_bstr::to_str(var.bstrVal, s); 68 | VariantClear(&var); 69 | return s; 70 | } 71 | 72 | 73 | ///////////////////////////////////////////////////////////////////////////// 74 | // wbem_enumerator 75 | 76 | bool wbem_enumerator::next(wbem_object & obj) 77 | { 78 | if (!m_intf) 79 | return false; 80 | 81 | ULONG n = 0; 82 | HRESULT rc = m_intf->Next(5000 /*5s*/, 1 /*count*/, obj.m_intf.replace(), &n); 83 | if (FAILED(rc) || n != 1) 84 | return false; 85 | return true; 86 | } 87 | 88 | 89 | ///////////////////////////////////////////////////////////////////////////// 90 | // wbem_services 91 | 92 | const CLSID xCLSID_WbemLocator = {0x4590f811, 0x1d3a, 0x11d0, {0x89, 0x1f, 0x00, 0xaa, 0x00, 0x4b, 0x2e, 0x24}}; 93 | const IID xIID_IWbemLocator = {0xdc12a687, 0x737f, 0x11cf, {0x88, 0x4d, 0x00, 0xaa, 0x00, 0x4b, 0x2e, 0x24}}; 94 | 95 | bool wbem_services::connect() 96 | { 97 | // Init COM during first call. 98 | static HRESULT init_rc = -1; 99 | static bool init_tried = false; 100 | if (!init_tried) { 101 | init_tried = true; 102 | init_rc = CoInitialize((LPVOID)0); 103 | } 104 | if (!(init_rc == S_OK || init_rc == S_FALSE)) 105 | return false; 106 | 107 | /// Create locator. 108 | com_intf_ptr locator; 109 | HRESULT rc = CoCreateInstance(xCLSID_WbemLocator, (LPUNKNOWN)0, 110 | CLSCTX_INPROC_SERVER, xIID_IWbemLocator, (LPVOID*)locator.replace()); 111 | if (FAILED(rc)) 112 | return false; 113 | 114 | // Set timeout flag if supported. 115 | long flags = 0; 116 | OSVERSIONINFOA ver; ver.dwOSVersionInfoSize = sizeof(ver); 117 | if (GetVersionExA(&ver) && ver.dwPlatformId == VER_PLATFORM_WIN32_NT 118 | && ( ver.dwMajorVersion >= 6 // Vista 119 | || (ver.dwMajorVersion == 5 && ver.dwMinorVersion >= 1))) // XP 120 | flags = WBEM_FLAG_CONNECT_USE_MAX_WAIT; // return in 2min or less 121 | 122 | // Connect to local server. 123 | rc = locator->ConnectServer(com_bstr("\\\\.\\root\\cimv2"), 124 | (BSTR)0, (BSTR)0, (BSTR)0, // User, Password, Locale 125 | flags, (BSTR)0, (IWbemContext*)0, m_intf.replace()); 126 | if (FAILED(rc)) 127 | return false; 128 | 129 | // Set authentication information, 130 | rc = CoSetProxyBlanket(m_intf.get(), RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, 131 | (OLECHAR*)0, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, 132 | (RPC_AUTH_IDENTITY_HANDLE*)0, EOAC_NONE); 133 | if (FAILED(rc)) { 134 | m_intf.reset(); 135 | return false; 136 | } 137 | 138 | return true; 139 | } 140 | 141 | bool wbem_services::vquery(wbem_enumerator & result, const char * qstr, va_list args) /*const*/ 142 | { 143 | if (!m_intf) 144 | return false; 145 | 146 | char qline[1024]; 147 | vsnprintf(qline, sizeof(qline), qstr, args); 148 | qline[sizeof(qline)-1] = 0; 149 | 150 | HRESULT rc = m_intf->ExecQuery( 151 | com_bstr("WQL"), com_bstr(qline), 152 | WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 153 | (IWbemContext*)0, result.m_intf.replace()); 154 | if (FAILED(rc)) 155 | return false; 156 | 157 | return true; 158 | } 159 | 160 | bool wbem_services::vquery1(wbem_object & obj, const char * qstr, va_list args) /*const*/ 161 | { 162 | wbem_enumerator result; 163 | if (!vquery(result, qstr, args)) 164 | return false; 165 | 166 | if (!result.next(obj)) 167 | return false; 168 | 169 | wbem_object peek; 170 | if (result.next(peek)) 171 | return false; 172 | 173 | return true; 174 | } 175 | 176 | bool wbem_services::query(wbem_enumerator & result, const char * qstr, ...) /*const*/ 177 | { 178 | va_list args; va_start(args, qstr); 179 | bool ok = vquery(result, qstr, args); 180 | va_end(args); 181 | return ok; 182 | } 183 | 184 | bool wbem_services::query1(wbem_object & obj, const char * qstr, ...) /*const*/ 185 | { 186 | va_list args; va_start(args, qstr); 187 | bool ok = vquery1(obj, qstr, args); 188 | va_end(args); 189 | return ok; 190 | } 191 | -------------------------------------------------------------------------------- /os_win32/wmiquery.h: -------------------------------------------------------------------------------- 1 | /* 2 | * os_win32/wmiquery.h 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2011-18 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef WMIQUERY_H 12 | #define WMIQUERY_H 13 | 14 | #define WMIQUERY_H_CVSID "$Id$" 15 | 16 | #include 17 | 18 | #include 19 | 20 | #ifndef __GNUC__ 21 | #define __attribute_format_printf(x, y) /**/ 22 | #elif defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO 23 | // Check format of __mingw_*printf() instead of MSVCRT.DLL:*printf() 24 | #define __attribute_format_printf(x, y) __attribute__((format (gnu_printf, x, y))) 25 | #else 26 | #define __attribute_format_printf(x, y) __attribute__((format (printf, x, y))) 27 | #endif 28 | 29 | ///////////////////////////////////////////////////////////////////////////// 30 | // com_bstr 31 | 32 | /// Wrapper class for COM BSTR 33 | class com_bstr 34 | { 35 | public: 36 | /// Construct from string. 37 | explicit com_bstr(const char * str); 38 | 39 | /// Destructor frees BSTR. 40 | ~com_bstr() 41 | { SysFreeString(m_bstr); } 42 | 43 | /// Implicit conversion to BSTR. 44 | operator BSTR() 45 | { return m_bstr; } 46 | 47 | /// Convert BSTR back to std::string. 48 | static bool to_str(const BSTR & bstr, std::string & str); 49 | 50 | private: 51 | BSTR m_bstr; 52 | 53 | com_bstr(const com_bstr &); 54 | void operator=(const com_bstr &); 55 | }; 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // com_intf_ptr 60 | 61 | /// Wrapper class for COM Interface pointer 62 | template 63 | class com_intf_ptr 64 | { 65 | public: 66 | /// Construct empty object 67 | com_intf_ptr() 68 | : m_ptr(0) { } 69 | 70 | /// Destructor releases the interface. 71 | ~com_intf_ptr() 72 | { reset(); } 73 | 74 | /// Release interface and clear the pointer. 75 | void reset() 76 | { 77 | if (m_ptr) { 78 | m_ptr->Release(); m_ptr = 0; 79 | } 80 | } 81 | 82 | /// Return the pointer. 83 | T * get() 84 | { return m_ptr; } 85 | 86 | /// Pointer dereferencing. 87 | T * operator->() 88 | { return m_ptr; } 89 | 90 | /// Return address of pointer for replacement. 91 | T * * replace() 92 | { reset(); return &m_ptr; } 93 | 94 | /// For (ptr != 0) check. 95 | operator bool() const 96 | { return !!m_ptr; } 97 | 98 | /// For (ptr == 0) check. 99 | bool operator!() const 100 | { return !m_ptr; } 101 | 102 | private: 103 | T * m_ptr; 104 | 105 | com_intf_ptr(const com_intf_ptr &); 106 | void operator=(const com_intf_ptr &); 107 | }; 108 | 109 | 110 | ///////////////////////////////////////////////////////////////////////////// 111 | // wbem_object 112 | 113 | class wbem_enumerator; 114 | 115 | /// Wrapper class for IWbemClassObject 116 | class wbem_object 117 | { 118 | public: 119 | /// Get string representation. 120 | std::string get_str(const char * name) /*const*/; 121 | 122 | private: 123 | /// Contents is set by wbem_enumerator. 124 | friend class wbem_enumerator; 125 | com_intf_ptr m_intf; 126 | }; 127 | 128 | 129 | ///////////////////////////////////////////////////////////////////////////// 130 | // wbem_enumerator 131 | 132 | class wbem_services; 133 | 134 | /// Wrapper class for IEnumWbemClassObject 135 | class wbem_enumerator 136 | { 137 | public: 138 | /// Get next object, return false if none or error. 139 | bool next(wbem_object & obj); 140 | 141 | private: 142 | /// Contents is set by wbem_services. 143 | friend class wbem_services; 144 | com_intf_ptr m_intf; 145 | }; 146 | 147 | 148 | ///////////////////////////////////////////////////////////////////////////// 149 | // wbem_services 150 | 151 | /// Wrapper class for IWbemServices 152 | class wbem_services 153 | { 154 | public: 155 | /// Connect to service, return false on error. 156 | bool connect(); 157 | 158 | /// Execute query, get result list. 159 | /// Return false on error. 160 | bool vquery(wbem_enumerator & result, const char * qstr, va_list args) /*const*/ 161 | __attribute_format_printf(3, 0); 162 | 163 | /// Execute query, get single result object. 164 | /// Return false on error or result size != 1. 165 | bool vquery1(wbem_object & obj, const char * qstr, va_list args) /*const*/ 166 | __attribute_format_printf(3, 0); 167 | 168 | /// Version of vquery() with printf() formatting. 169 | bool query(wbem_enumerator & result, const char * qstr, ...) /*const*/ 170 | __attribute_format_printf(3, 4); 171 | 172 | /// Version of vquery1() with printf() formatting. 173 | bool query1(wbem_object & obj, const char * qstr, ...) /*const*/ 174 | __attribute_format_printf(3, 4); 175 | 176 | private: 177 | com_intf_ptr m_intf; 178 | }; 179 | 180 | #endif // WMIQUERY_H 181 | -------------------------------------------------------------------------------- /os_win32/wtssendmsg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * WTSSendMessage() command line tool 3 | * 4 | * Home page of code is: https://www.smartmontools.org 5 | * 6 | * Copyright (C) 2012-19 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #define WINVER 0x0501 12 | #define _WIN32_WINNT WINVER 13 | 14 | char svnid[] = "$Id$"; 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #define WIN32_LEAN_AND_MEAN 21 | #include 22 | #include 23 | 24 | 25 | static int usage() 26 | { 27 | printf("wtssendmsg $Revision$ - Display a message box on client desktops\n" 28 | "Copyright (C) 2012-19 Christian Franke, www.smartmontools.org\n\n" 29 | "Usage: wtssendmsg [-cas] [-t TIMEOUT] [-w 0..5] [-v] [\"Caption\"] \"Message\"|-\n" 30 | " wtssendmsg -v\n\n" 31 | " -c Console session [default]\n" 32 | " -a Active sessions\n" 33 | " -s Connected sessions\n" 34 | " -t Remove message box after TIMEOUT seconds\n" 35 | " -w Select buttons and wait for response or timeout\n" 36 | " -v List sessions\n" 37 | ); 38 | return 1; 39 | } 40 | 41 | static int getnum(const char * s) 42 | { 43 | char * endp; 44 | int n = strtol(s, &endp, 10); 45 | if (*endp) 46 | return -1; 47 | return n; 48 | } 49 | 50 | int main(int argc, const char **argv) 51 | { 52 | int mode = 0, timeout = 0, buttons = -1, verbose = 0, i; 53 | 54 | for (i = 1; i < argc && argv[i][0] == '-' && argv[i][1]; i++) { 55 | int j; 56 | for (j = 1; argv[i][j]; j++) { 57 | switch (argv[i][j]) { 58 | case 'c': mode = 0; continue; 59 | case 'a': mode = 1; continue; 60 | case 's': mode = 2; continue; 61 | case 't': 62 | if (argv[i][j+1] || ++i >= argc) 63 | return usage(); 64 | timeout = getnum(argv[i]); 65 | if (timeout < 0) 66 | return usage(); 67 | break; 68 | case 'w': 69 | if (argv[i][j+1] || ++i >= argc) 70 | return usage(); 71 | buttons = getnum(argv[i]); 72 | if (!(MB_OK <= buttons && buttons <= MB_RETRYCANCEL)) // 0..5 73 | return usage(); 74 | break; 75 | case 'v': verbose = 1; continue; 76 | default: return usage(); 77 | } 78 | break; 79 | } 80 | } 81 | 82 | const char * message = 0, * caption = ""; 83 | char msgbuf[1024]; 84 | if (i < argc) { 85 | if (i+1 < argc) 86 | caption = argv[i++]; 87 | 88 | message = argv[i++]; 89 | if (i < argc) 90 | return usage(); 91 | 92 | if (!strcmp(message, "-")) { 93 | // Read message from stdin 94 | // The message is also written to a Windows event log entry, so 95 | // don't convert '\r\n' to '\n' (the MessageBox works with both) 96 | i = 0; 97 | DWORD size = 0; 98 | do 99 | if (!ReadFile(GetStdHandle(STD_INPUT_HANDLE), 100 | msgbuf+i, sizeof(msgbuf)-1-i, &size, (OVERLAPPED*)0)) 101 | break; // May fail with ERROR_BROKEN_PIPE instead of EOF 102 | while (size > 0 && (i += size) < (int)sizeof(msgbuf)-1); 103 | msgbuf[i] = 0; 104 | message = msgbuf; 105 | } 106 | } 107 | else { 108 | if (!verbose) 109 | return usage(); 110 | } 111 | 112 | // Get session list 113 | WTS_SESSION_INFOA * sessions; DWORD count; 114 | if (!WTSEnumerateSessionsA(WTS_CURRENT_SERVER_HANDLE, 0, 1, &sessions, &count)) { 115 | fprintf(stderr, "WTSEnumerateSessions() failed\n"); 116 | return 1; 117 | } 118 | 119 | int status = 0; 120 | for (i = 0; i < (int)count; i++) { 121 | 122 | if (verbose) { 123 | printf("Session %d (\"%s\", State=%d)%s", 124 | i, sessions[i].pWinStationName, sessions[i].State, 125 | (!message ? "\n" : ": ")); 126 | if (!message) 127 | continue; // List sessions only 128 | fflush(stdout); 129 | } 130 | 131 | // Check session state 132 | if (!( !strcmpi(sessions[i].pWinStationName, "Console") 133 | || (mode >= 1 && sessions[i].State == WTSActive) 134 | || (mode >= 2 && sessions[i].State == WTSConnected))) { 135 | if (verbose) 136 | printf("ignored\n"); 137 | continue; 138 | } 139 | 140 | // Send Message 141 | DWORD response = ~0; 142 | if (!WTSSendMessageA(WTS_CURRENT_SERVER_HANDLE, sessions[i].SessionId, 143 | (char *)caption, strlen(caption), 144 | (char *)message, strlen(message), 145 | (buttons <= MB_OK ? MB_OK|MB_ICONEXCLAMATION 146 | : buttons|MB_DEFBUTTON2|MB_ICONQUESTION ), 147 | timeout, &response, (buttons >= MB_OK) /*Wait?*/ )) { 148 | status |= 0x01; 149 | if (verbose) 150 | printf("WTSSendMessage() failed with error=%d\n", (int)GetLastError()); 151 | else 152 | fprintf(stderr, "Session %d (\"%s\", State=%d): WTSSendMessage() failed with error=%d\n", 153 | i, sessions[i].pWinStationName, sessions[i].State, (int)GetLastError()); 154 | continue; 155 | } 156 | 157 | if (buttons >= MB_OK) { 158 | switch (response) { 159 | case IDOK: 160 | case IDYES: case IDABORT: status |= 0x02; break; 161 | case IDNO: case IDRETRY: status |= 0x04; break; 162 | case IDCANCEL: case IDIGNORE: status |= 0x08; break; 163 | case IDTIMEOUT: status |= 0x10; break; 164 | default: status |= 0x01; break; 165 | } 166 | if (verbose) 167 | printf("response = %d, status = 0x%02x\n", (int)response, status); 168 | } 169 | else { 170 | // response == IDASYNC 171 | if (verbose) 172 | printf("message sent\n"); 173 | } 174 | } 175 | 176 | WTSFreeMemory(sessions); 177 | 178 | return status; 179 | } 180 | -------------------------------------------------------------------------------- /popen_as_ugid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * popen_as_ugid.h 3 | * 4 | * Home page of code is: https://www.smartmontools.org 5 | * 6 | * Copyright (C) 2021 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef POPEN_AS_UGID_H_CVSID 12 | #define POPEN_AS_UGID_H_CVSID "$Id$" 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | // Wrapper for popen(3) which prevents that unneeded file descriptors 20 | // are inherited to the command run by popen() and optionally drops 21 | // privileges of root user: 22 | // If uid != 0, popen() is run as this user. 23 | // If gid != 0, popen() is run as this group and no supplemental groups. 24 | // Only mode "r" is supported. Only one open stream at a time is supported. 25 | FILE * popen_as_ugid(const char * cmd, const char * mode, uid_t uid, gid_t gid); 26 | 27 | // Call corresponding pclose(3) and return its result. 28 | int pclose_as_ugid(FILE * f); 29 | 30 | // Parse "USER[:GROUP]" string and set uid, gid, uname and gname accordingly. 31 | // USER and GROUP may be specified as numeric ids or names. 32 | // If a numeric id is used and the corresponding user (or group) does not 33 | // exist, the function succeeds but leaves uname (or gname) unchanged. 34 | // If no GROUP is specified, the default group of USER is used instead. 35 | // Returns nullptr on success or a message string on error. 36 | const char * parse_ugid(const char * s, uid_t & uid, gid_t & gid, 37 | std::string & uname, std::string & gname ); 38 | 39 | #endif // POPEN_AS_UGID_H_CVSID 40 | -------------------------------------------------------------------------------- /regex/regex.c: -------------------------------------------------------------------------------- 1 | /* Extended regular expression matching and search library. 2 | Copyright (C) 2002-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | Contributed by Isamu Hasegawa . 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | The GNU C Library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with the GNU C Library; if not, see 18 | . */ 19 | 20 | #if !defined(_LIBC) && !defined(_REGEX_STANDALONE) 21 | # include 22 | 23 | # if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ 24 | # pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" 25 | # endif 26 | # if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ 27 | # pragma GCC diagnostic ignored "-Wold-style-definition" 28 | # pragma GCC diagnostic ignored "-Wtype-limits" 29 | # endif 30 | #endif 31 | 32 | /* Make sure no one compiles this code with a C++ compiler. */ 33 | #if defined __cplusplus && defined _LIBC 34 | # error "This is C code, use a C compiler" 35 | #endif 36 | 37 | #ifdef _LIBC 38 | /* We have to keep the namespace clean. */ 39 | # define regfree(preg) __regfree (preg) 40 | # define regexec(pr, st, nm, pm, ef) __regexec (pr, st, nm, pm, ef) 41 | # define regcomp(preg, pattern, cflags) __regcomp (preg, pattern, cflags) 42 | # define regerror(errcode, preg, errbuf, errbuf_size) \ 43 | __regerror(errcode, preg, errbuf, errbuf_size) 44 | # define re_set_registers(bu, re, nu, st, en) \ 45 | __re_set_registers (bu, re, nu, st, en) 46 | # define re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop) \ 47 | __re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop) 48 | # define re_match(bufp, string, size, pos, regs) \ 49 | __re_match (bufp, string, size, pos, regs) 50 | # define re_search(bufp, string, size, startpos, range, regs) \ 51 | __re_search (bufp, string, size, startpos, range, regs) 52 | # define re_compile_pattern(pattern, length, bufp) \ 53 | __re_compile_pattern (pattern, length, bufp) 54 | # define re_set_syntax(syntax) __re_set_syntax (syntax) 55 | # define re_search_2(bufp, st1, s1, st2, s2, startpos, range, regs, stop) \ 56 | __re_search_2 (bufp, st1, s1, st2, s2, startpos, range, regs, stop) 57 | # define re_compile_fastmap(bufp) __re_compile_fastmap (bufp) 58 | 59 | # include "../locale/localeinfo.h" 60 | #endif 61 | 62 | /* On some systems, limits.h sets RE_DUP_MAX to a lower value than 63 | GNU regex allows. Include it before , which correctly 64 | #undefs RE_DUP_MAX and sets it to the right value. */ 65 | #include 66 | 67 | #include 68 | #include "regex_internal.h" 69 | 70 | #include "regex_internal.c" 71 | #include "regcomp.c" 72 | #include "regexec.c" 73 | 74 | /* Binary backward compatibility. */ 75 | #if _LIBC 76 | # include 77 | # if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3) 78 | link_warning (re_max_failures, "the 're_max_failures' variable is obsolete and will go away.") 79 | int re_max_failures = 2000; 80 | # endif 81 | #endif 82 | -------------------------------------------------------------------------------- /scsiprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * scsiprint.h 3 | * 4 | * Home page of code is: https://www.smartmontools.org 5 | * 6 | * Copyright (C) 2002-9 Bruce Allen 7 | * Copyright (C) 2000 Michael Cornwell 8 | * 9 | * Additional SCSI work: 10 | * Copyright (C) 2003-2023 Douglas Gilbert 11 | * 12 | * SPDX-License-Identifier: GPL-2.0-or-later 13 | */ 14 | 15 | 16 | #ifndef SCSI_PRINT_H_ 17 | #define SCSI_PRINT_H_ 18 | 19 | #define SCSIPRINT_H_CVSID "$Id$\n" 20 | 21 | // Options for scsiPrintMain 22 | struct scsi_print_options 23 | { 24 | bool drive_info = false; 25 | bool smart_check_status = false; 26 | bool smart_vendor_attrib = false; 27 | bool smart_error_log = false; 28 | bool smart_selftest_log = false; 29 | bool smart_background_log = false; 30 | bool smart_ss_media_log = false; 31 | 32 | bool smart_disable = false, smart_enable = false; 33 | bool smart_auto_save_disable = false, smart_auto_save_enable = false; 34 | 35 | bool smart_default_selftest = false; 36 | bool smart_short_selftest = false, smart_short_cap_selftest = false; 37 | bool smart_extend_selftest = false, smart_extend_cap_selftest = false; 38 | bool smart_selftest_abort = false; 39 | bool smart_selftest_force = false; // Ignore already running test 40 | bool scsi_pending_defects = false; 41 | bool general_stats_and_perf = false; 42 | 43 | bool smart_env_rep = false; 44 | 45 | bool sasphy = false, sasphy_reset = false; 46 | 47 | bool tape_device_stats = false; 48 | bool tape_alert = false; 49 | 50 | bool zoned_device_stats = false; 51 | 52 | bool get_wce = false, get_rcd = false; 53 | short int set_wce = 0, set_rcd = 0; // disable(-1), enable(1) cache 54 | 55 | unsigned char powermode = 0; // Enhancement Skip check, if disk in idle or standby mode 56 | unsigned char powerexit = 0; // exit() code for low power mode 57 | 58 | int set_standby = 0; // set(1..255->0..254) standby timer 59 | bool set_standby_now = false; // set drive to standby 60 | bool set_active = false; // set drive to active 61 | 62 | int health_opt_count = 0; // TapeAlert log page only read if this value > 1 63 | 64 | bool farm_log = false; // Seagate Field Access Reliability Metrics log (FARM) for SCSI 65 | bool farm_log_suggest = false; // If -x/-xall or -a/-all is run, suggests FARM log if supported 66 | }; 67 | 68 | int scsiPrintMain(scsi_device * device, const scsi_print_options & options); 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /smartctl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * smartctl.h 3 | * 4 | * Home page of code is: https://www.smartmontools.org 5 | * 6 | * Copyright (C) 2002-10 Bruce Allen 7 | * Copyright (C) 2008-21 Christian Franke 8 | * Copyright (C) 2000 Michael Cornwell 9 | * 10 | * SPDX-License-Identifier: GPL-2.0-or-later 11 | */ 12 | 13 | #ifndef SMARTCTL_H_ 14 | #define SMARTCTL_H_ 15 | 16 | #define SMARTCTL_H_CVSID "$Id$\n" 17 | 18 | // Return codes (bitmask) 19 | 20 | // command line did not parse, or internal error occurred in smartctl 21 | #define FAILCMD (0x01<<0) 22 | 23 | // device open failed 24 | #define FAILDEV (0x01<<1) 25 | 26 | // device is in low power mode and -n option requests to exit 27 | #define FAILPOWER (0x01<<1) 28 | 29 | // read device identity (ATA only) failed 30 | #define FAILID (0x01<<1) 31 | 32 | // smart command failed, or ATA identify device structure missing information 33 | #define FAILSMART (0x01<<2) 34 | 35 | // SMART STATUS returned FAILURE 36 | #define FAILSTATUS (0x01<<3) 37 | 38 | // Attributes found <= threshold with prefail=1 39 | #define FAILATTR (0x01<<4) 40 | 41 | // SMART STATUS returned GOOD but age attributes failed or prefail 42 | // attributes have failed in the past 43 | #define FAILAGE (0x01<<5) 44 | 45 | // Device had Errors in the error log 46 | #define FAILERR (0x01<<6) 47 | 48 | // Device had Errors in the self-test log 49 | #define FAILLOG (0x01<<7) 50 | 51 | // Classes of SMART commands. Here 'mandatory' means "Required by the 52 | // ATA/ATAPI-5 Specification if the device implements the S.M.A.R.T. 53 | // command set." The 'mandatory' S.M.A.R.T. commands are: (1) 54 | // Enable/Disable Attribute Autosave, (2) Enable/Disable S.M.A.R.T., 55 | // and (3) S.M.A.R.T. Return Status. All others are optional. 56 | enum failure_type { 57 | OPTIONAL_CMD, 58 | MANDATORY_CMD, 59 | }; 60 | 61 | // Globals to set failuretest() policy 62 | extern bool failuretest_conservative; 63 | extern unsigned char failuretest_permissive; 64 | 65 | // Compares failure type to policy in effect, and either exits or 66 | // simply returns to the calling routine. 67 | void failuretest(failure_type type, int returnvalue); 68 | 69 | // Globals to control printing 70 | extern bool printing_is_switchable; 71 | extern bool printing_is_off; 72 | 73 | // Printing control functions 74 | inline void print_on() 75 | { 76 | if (printing_is_switchable) 77 | printing_is_off = false; 78 | } 79 | inline void print_off() 80 | { 81 | if (printing_is_switchable) 82 | printing_is_off = true; 83 | } 84 | 85 | // The singleton global JSON object 86 | #include "json.h" 87 | extern json jglb; 88 | 89 | #include "utility.h" // __attribute_format_printf() 90 | // TODO: move this to a new include file? 91 | 92 | // Version of pout() for items already included in JSON output 93 | void jout(const char *fmt, ...) 94 | __attribute_format_printf(1, 2); 95 | // Version of pout() for info/warning/error messages 96 | void jinf(const char *fmt, ...) 97 | __attribute_format_printf(1, 2); 98 | void jwrn(const char *fmt, ...) 99 | __attribute_format_printf(1, 2); 100 | void jerr(const char *fmt, ...) 101 | __attribute_format_printf(1, 2); 102 | 103 | // Print smartctl start-up date and time and timezone 104 | void jout_startup_datetime(const char *prefix); 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /smartd.conf: -------------------------------------------------------------------------------- 1 | # Sample configuration file for smartd. See man smartd.conf. 2 | 3 | # Home page is: https://www.smartmontools.org 4 | 5 | # smartd will re-read the configuration file if it receives a HUP 6 | # signal 7 | 8 | # The file gives a list of devices to monitor using smartd, with one 9 | # device per line. Text after a hash (#) is ignored, and you may use 10 | # spaces and tabs for white space. You may use '\' to continue lines. 11 | 12 | # The word DEVICESCAN will cause any remaining lines in this 13 | # configuration file to be ignored: it tells smartd to scan for all 14 | # ATA and SCSI devices. DEVICESCAN may be followed by any of the 15 | # Directives listed below, which will be applied to all devices that 16 | # are found. Most users should comment out DEVICESCAN and explicitly 17 | # list the devices that they wish to monitor. 18 | DEVICESCAN 19 | 20 | # Alternative setting to ignore temperature and power-on hours reports 21 | # in syslog. 22 | #DEVICESCAN -I 194 -I 231 -I 9 23 | 24 | # Alternative setting to report more useful raw temperature in syslog. 25 | #DEVICESCAN -R 194 -R 231 -I 9 26 | 27 | # Alternative setting to report raw temperature changes >= 5 Celsius 28 | # and min/max temperatures. 29 | #DEVICESCAN -I 194 -I 231 -I 9 -W 5 30 | 31 | # First ATA/SATA or SCSI/SAS disk. Monitor all attributes, enable 32 | # automatic online data collection, automatic Attribute autosave, and 33 | # start a short self-test every day between 2-3am, and a long self test 34 | # Saturdays between 3-4am. 35 | #/dev/sda -a -o on -S on -s (S/../.././02|L/../../6/03) 36 | 37 | # Monitor SMART status, ATA Error Log, Self-test log, and track 38 | # changes in all attributes except for attribute 194 39 | #/dev/sdb -H -l error -l selftest -t -I 194 40 | 41 | # Monitor all attributes except normalized Temperature (usually 194), 42 | # but track Temperature changes >= 4 Celsius, report Temperatures 43 | # >= 45 Celsius and changes in Raw value of Reallocated_Sector_Ct (5). 44 | # Send mail on SMART failures or when Temperature is >= 55 Celsius. 45 | #/dev/sdc -a -I 194 -W 4,45,55 -R 5 -m admin@example.com 46 | 47 | # An ATA disk may appear as a SCSI device to the OS. If a SCSI to 48 | # ATA Translation (SAT) layer is between the OS and the device then 49 | # this can be flagged with the '-d sat' option. 50 | #/dev/sda -a -d sat 51 | 52 | # A very silent check. Only report SMART health status if it fails 53 | # But send an email in this case 54 | #/dev/sdc -H -C 0 -U 0 -m admin@example.com 55 | 56 | # First two SCSI disks. This will monitor everything that smartd can 57 | # monitor. Start extended self-tests Wednesdays between 6-7pm and 58 | # Sundays between 1-2 am 59 | #/dev/sda -d scsi -s L/../../3/18 60 | #/dev/sdb -d scsi -s L/../../7/01 61 | 62 | # Monitor 2 SATA (not SAS) disks connected to a 3ware 9000 controller which 63 | # uses the 3w-sas driver (Linux). Start long self-tests Tuesdays 64 | # between 1-2 and 3-4 am. 65 | # On FreeBSD /dev/tws0 should be used instead 66 | #/dev/twl0 -d 3ware,0 -a -s L/../../2/01 67 | #/dev/twl0 -d 3ware,1 -a -s L/../../2/03 68 | 69 | # Monitor 2 disks connected to the first HP SmartArray controller which uses 70 | # the Linux cciss driver. Start long self-tests on Sunday nights and short 71 | # self-tests every night and send errors to root. 72 | #/dev/sda -d cciss,0 -a -s (L/../../7/02|S/../.././02) -m root 73 | #/dev/sda -d cciss,1 -a -s (L/../../7/03|S/../.././03) -m root 74 | 75 | # Monitor 3 ATA disks directly connected to a HighPoint RocketRAID. Start long 76 | # self-tests Sundays between 1-2, 2-3, and 3-4 am. 77 | #/dev/sdd -d hpt,1/1 -a -s L/../../7/01 78 | #/dev/sdd -d hpt,1/2 -a -s L/../../7/02 79 | #/dev/sdd -d hpt,1/3 -a -s L/../../7/03 80 | 81 | # Monitor 2 ATA disks connected to the same PMPort which connected to the 82 | # HighPoint RocketRAID. Start long self-tests Tuesdays between 1-2 and 3-4 am 83 | #/dev/sdd -d hpt,1/4/1 -a -s L/../../2/01 84 | #/dev/sdd -d hpt,1/4/2 -a -s L/../../2/03 85 | 86 | # HERE IS A LIST OF DIRECTIVES FOR THIS CONFIGURATION FILE. 87 | # PLEASE SEE THE smartd.conf MAN PAGE FOR DETAILS 88 | # 89 | # -d TYPE Set the device type: ata, scsi[+TYPE], nvme[,NSID], 90 | # sat[,auto][,N][+TYPE], usbcypress[,X], usbjmicron[,p][,x][,N], 91 | # usbprolific, usbsunplus, sntasmedia, sntjmicron[,NSID], sntrealtek, 92 | # ... (platform specific) 93 | # -T TYPE Set the tolerance to one of: normal, permissive 94 | # -o VAL Enable/disable automatic offline tests (on/off) 95 | # -S VAL Enable/disable attribute autosave (on/off) 96 | # -n MODE No check if: never, sleep[,N][,q], standby[,N][,q], idle[,N][,q] 97 | # -H Monitor SMART Health Status, report if failed 98 | # -s REG Do Self-Test at time(s) given by regular expression REG 99 | # -l TYPE Monitor SMART log or self-test status: 100 | # error, selftest, xerror, offlinests[,ns], selfteststs[,ns] 101 | # -l scterc,R,W Set SCT Error Recovery Control 102 | # -e Change device setting: aam,[N|off], apm,[N|off], dsn,[on|off], 103 | # lookahead,[on|off], security-freeze, standby,[N|off], wcache,[on|off] 104 | # -f Monitor 'Usage' Attributes, report failures 105 | # -m ADD Send email warning to address ADD 106 | # -M TYPE Modify email warning behavior (see man page) 107 | # -p Report changes in 'Prefailure' Attributes 108 | # -u Report changes in 'Usage' Attributes 109 | # -t Equivalent to -p and -u Directives 110 | # -r ID Also report Raw values of Attribute ID with -p, -u or -t 111 | # -R ID Track changes in Attribute ID Raw value with -p, -u or -t 112 | # -i ID Ignore Attribute ID for -f Directive 113 | # -I ID Ignore Attribute ID for -p, -u or -t Directive 114 | # -C ID[+] Monitor [increases of] Current Pending Sectors in Attribute ID 115 | # -U ID[+] Monitor [increases of] Offline Uncorrectable Sectors in Attribute ID 116 | # -W D,I,C Monitor Temperature D)ifference, I)nformal limit, C)ritical limit 117 | # -v N,ST Modifies labeling of Attribute N (see man page) 118 | # -P TYPE Drive-specific presets: use, ignore, show, showall 119 | # -a Default: -H -f -t -l error -l selftest -l selfteststs -C 197 -U 198 120 | # -F TYPE Use firmware bug workaround: 121 | # none, nologdir, samsung, samsung2, samsung3, xerrorlba 122 | # -c i=N Set interval between disk checks to N seconds 123 | # # Comment: text after a hash sign is ignored 124 | # \ Line continuation character 125 | # Attribute ID is a decimal integer 1 <= ID <= 255 126 | # except for -C and -U, where ID = 0 turns them off. 127 | -------------------------------------------------------------------------------- /smartd.cygwin.initd.in: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # smartmontools initd file for Cygwin smartd 4 | # 5 | # Home page of code is: http://www.smartmontools.org 6 | # 7 | # Copyright (C) 2004-17 Christian Franke 8 | # 9 | # SPDX-License-Identifier: GPL-2.0-or-later 10 | # 11 | # $Id$ 12 | # 13 | 14 | SMARTD_BIN=/usr/local/sbin/smartd 15 | 16 | # The following settings may be changed by the configuration file below 17 | # Service Name (must be unique) 18 | smartd_svcname=smartd 19 | # Service display name 20 | smartd_svcdisp="CYGWIN smartd" 21 | # Service description 22 | smartd_svcdesc="\ 23 | Controls and monitors storage devices using the Self-Monitoring, \ 24 | Analysis and Reporting Technology System (SMART) built into \ 25 | ATA/SATA and SCSI/SAS hard drives and solid-state drives. \ 26 | www.smartmontools.org" 27 | 28 | # Source configuration file. 29 | [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools 30 | 31 | PID_FILE=/var/run/smartd.pid 32 | RETVAL=0 33 | 34 | # Note: "[ -r $PID_FILE ]" is not used here. On Cygwin, this command may 35 | # return success even if the file is present but cannot be read by current user. 36 | # If smartd is running as service, smartd.pid is owned by local system account 37 | # which is different from any user ever executing this script. 38 | 39 | case "$1" in 40 | start) 41 | if cygrunsrv -L 2>/dev/null | grep "^${smartd_svcname}$" >/dev/null 2>&1; then 42 | echo -n "Starting service $smartd_svcname: " 43 | cygrunsrv -S "$smartd_svcname" 44 | else 45 | echo -n "Starting smartd as daemon: " 46 | $SMARTD_BIN -p $PID_FILE $smartd_opts 47 | fi 48 | RETVAL=$? 49 | ;; 50 | stop) 51 | echo -n "Shutting down smartd: " 52 | pid="`cat $PID_FILE 2>/dev/null`" && kill "$pid" 53 | RETVAL=$? 54 | ;; 55 | reload) 56 | echo -n "Reloading smartd configuration: " 57 | pid="`cat $PID_FILE 2>/dev/null`" && kill -HUP "$pid" 58 | RETVAL=$? 59 | ;; 60 | report) 61 | echo -n "Checking SMART devices now: " 62 | pid="`cat $PID_FILE 2>/dev/null`" && kill -USR1 "$pid" 63 | RETVAL=$? 64 | ;; 65 | restart) 66 | $0 stop 67 | sleep 1 68 | $0 start 69 | exit $? 70 | ;; 71 | install) 72 | shift 73 | [ $# -eq 0 ] || smartd_opts="$*" 74 | dep=; dep2= 75 | if cygrunsrv -L 2>/dev/null | grep "^syslogd$" >/dev/null 2>&1; then 76 | dep="syslogd" 77 | fi 78 | if cygrunsrv -L 2>/dev/null | grep "^syslog-ng" >/dev/null 2>&1; then 79 | dep2="syslog-ng" 80 | fi 81 | if [ -z "$dep" ]; then 82 | if [ -z "$dep2" ]; then 83 | echo "Warning: no syslog service installed, smartd will write to windows event log."; 84 | else 85 | dep="$dep2" 86 | fi 87 | else 88 | if [ -z "$dep2" ]; then 89 | : 90 | else 91 | dep= 92 | echo "Warning: both syslogd and syslog-ng installed, dependency not set." 93 | fi 94 | fi 95 | echo "Installing service ${smartd_svcname}${dep:+ (depending on '$dep')}${smartd_opts:+ with options '$smartd_opts'}:" 96 | cygrunsrv -I "$smartd_svcname" -d "$smartd_svcdisp" -f "$smartd_svcdesc" ${dep:+-y} $dep \ 97 | -e CYGWIN="$CYGWIN" -p $SMARTD_BIN -a "-n -p ${PID_FILE}${smartd_opts:+ }$smartd_opts" 98 | RETVAL=$? 99 | ;; 100 | remove) 101 | echo "Removing service $smartd_svcname:" 102 | cygrunsrv -R "$smartd_svcname" 103 | RETVAL=$? 104 | ;; 105 | status) 106 | echo -n "Checking smartd status: " 107 | if cygrunsrv -L 2>/dev/null | grep "^${smartd_svcname}$" >/dev/null 2>&1; then 108 | if cygrunsrv -Q "$smartd_svcname" 2>/dev/null | grep "State *: Running" >/dev/null 2>&1; then 109 | echo "running as service '$smartd_svcname'." 110 | elif ps -e 2>/dev/null | grep " ${SMARTD_BIN}$" >/dev/null 2>&1; then 111 | echo "installed as service '$smartd_svcname' but running as daemon." 112 | else 113 | echo "installed as service '$smartd_svcname' but not running." 114 | RETVAL=1 115 | fi 116 | elif ps -e 2>/dev/null | grep " ${SMARTD_BIN}$" >/dev/null 2>&1; then 117 | echo "running as daemon." 118 | else 119 | echo "not running." 120 | RETVAL=1 121 | fi 122 | exit $RETVAL 123 | ;; 124 | *) 125 | echo "Usage: $0 {start|stop|restart|reload|report|status}" 126 | echo " $0 {install [options]|remove}" 127 | exit 1 128 | esac 129 | 130 | if [ "$RETVAL" -eq 0 ]; then echo "done"; else echo "ERROR"; fi 131 | exit $RETVAL 132 | -------------------------------------------------------------------------------- /smartd.freebsd.initd.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # $FreeBSD: ports/sysutils/smartmontools/files/smartd.in,v 1.4 2012/02/15 08:46:57 dougb Exp $ 4 | # 5 | # PROVIDE: smartd 6 | # REQUIRE: LOGIN 7 | # KEYWORD: shutdown nojail 8 | # 9 | # Define these smartd_* variables in one of these files: 10 | # /etc/rc.conf 11 | # /etc/rc.conf.local 12 | # /etc/rc.conf.d/smartd 13 | # 14 | # DO NOT CHANGE THESE DEFAULT VALUES HERE 15 | 16 | . /etc/rc.subr 17 | 18 | name=smartd 19 | rcvar=smartd_enable 20 | 21 | load_rc_config smartd 22 | 23 | : ${smartd_enable:="NO"} 24 | 25 | required_files=${smartd_config:="/usr/local/etc/smartd.conf"} 26 | pidfile=${smartd_pidfile:="/var/run/smartd.pid"} 27 | 28 | command="/usr/local/sbin/smartd" 29 | command_args="-c ${required_files} -p ${pidfile}" 30 | 31 | extra_commands="reload report" 32 | reload_cmd="smartd_reload" 33 | report_cmd="smartd_report" 34 | 35 | start_precmd=smartd_prestart 36 | 37 | smartd_prestart() 38 | { 39 | case "${smartd_flags}" in 40 | -p*|*-p*) 41 | err 1 'smartd_flags includes the -p option, use smartd_pidfile instead' 42 | ;; 43 | esac 44 | } 45 | 46 | smartd_reload() 47 | { 48 | local status 49 | 50 | if ! status=`run_rc_command status 2>&1`; then 51 | echo $status 52 | return 1 53 | fi 54 | echo 'Reloading smartd.' 55 | kill -HUP $rc_pid 56 | } 57 | 58 | smartd_report() 59 | { 60 | local status 61 | 62 | if ! status=`run_rc_command status 2>&1`; then 63 | echo $status 64 | return 1 65 | fi 66 | echo 'Checking SMART devices now.' 67 | kill -USR1 $rc_pid 68 | } 69 | 70 | run_rc_command "$1" 71 | -------------------------------------------------------------------------------- /smartd.service.in: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Self Monitoring and Reporting Technology (SMART) Daemon 3 | Documentation=man:smartd(8) man:smartd.conf(5) 4 | 5 | # Typically physical storage devices are managed by the host physical machine 6 | # Override it if you are using PCI/USB passthrough 7 | ConditionVirtualization=no 8 | 9 | [Service] 10 | Type=notify 11 | EnvironmentFile=-/usr/local/etc/sysconfig/smartmontools 12 | ExecStart=/usr/local/sbin/smartd -n $smartd_opts 13 | ExecReload=/bin/kill -HUP $MAINPID 14 | 15 | [Install] 16 | WantedBy=multi-user.target 17 | -------------------------------------------------------------------------------- /sssraid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sssraid.h 3 | * 4 | * Home page of code is: http://www.smartmontools.org 5 | * 6 | * Copyright (C) 2022 3SNIC Inc. 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef _SSSRAID_H_ 12 | #define _SSSRAID_H_ 13 | #include 14 | #define u8 uint8_t 15 | #define u16 uint16_t 16 | #define u32 uint32_t 17 | #define u64 uint64_t 18 | #define ADM_MAX_DATA_SIZE 0x1000U // 4096 19 | #define ADM_SCSI_CDB_MAX_LEN 32 20 | #define ADM_SCSI_CDB_SENSE_MAX_LEN 96 21 | #define ADM_SCSI_CDB_SENSE_LEN32 32 22 | #define ADM_CMD_SHOW_PDLIST 0x502 // 1282 23 | #define ADM_CMD_SCSI_PASSTHROUGH 0x51e // 1310 24 | #define BSG_APPEND_TIMEOUT_MS 600000 25 | #define DEFAULT_CONMMAND_TIMEOUT_MS 180000 26 | #define ADM_BSG_MSGCODE_SCSI_PTHRU 1 27 | 28 | #define ADM_RAID_SET 0xc0 29 | #define ADM_RAID_WRITE 0xc1 30 | #define ADM_RAID_READ 0xc2 31 | #define ADM_RAID_PARAM_WRITE 0xc3 32 | #define ADM_RAID_READ_FROM_CQE 0xc4 33 | 34 | // pdlist device type interface 35 | enum adm_pdlist_intf { 36 | ADM_DEVICE_TYPE_SAS = 1, 37 | ADM_DEVICE_TYPE_EXP = 2, 38 | ADM_DEVICE_TYPE_SATA = 8, 39 | ADM_DEVICE_TYPE_PLANE = 9, 40 | ADM_DEVICE_TYPE_NVME = 10, 41 | ADM_DEVICE_TYPE_UNKNOW, 42 | ADM_DEVICE_TYPE_BUTT 43 | }; 44 | 45 | struct cmd_pdlist_idx { 46 | u16 start_idx; 47 | u16 count; 48 | u32 rsvd; 49 | }; 50 | 51 | struct cmd_pdlist_entry { 52 | u16 enc_id; 53 | u16 slot_id; 54 | u8 interface; 55 | u8 media_type; 56 | u8 logi_type; 57 | u8 logi_status; 58 | u32 reserve[26]; 59 | }; 60 | #define CMD_PDS_MAX_NUM 256U 61 | #define CMD_PDLIST_ONCE_NUM ((ADM_MAX_DATA_SIZE - 64) / sizeof(struct cmd_pdlist_entry)) 62 | 63 | struct cmd_show_pdlist { 64 | u16 num; 65 | u16 rsvd0; 66 | u32 rsvd1[15]; 67 | struct cmd_pdlist_entry disks[CMD_PDLIST_ONCE_NUM]; 68 | }; 69 | 70 | struct multi_disk_location { 71 | u16 enc_id; 72 | u16 slot_id; 73 | u16 did; 74 | u8 flag; 75 | u8 rsvd; 76 | }; 77 | 78 | struct cmd_scsi_passthrough { 79 | struct multi_disk_location loc; 80 | u8 lun; 81 | u8 cdb_len; 82 | u8 sense_buffer_len; 83 | u8 rsvd0; 84 | u8 cdb[32]; 85 | u32 rsvd1; 86 | u8 *sense_buffer; 87 | }; 88 | 89 | struct sssraid_passthru_common_cmd { 90 | u8 opcode; 91 | u8 flags; 92 | u16 rsvd0; 93 | u32 nsid; 94 | union { 95 | struct { 96 | u16 subopcode; 97 | u16 rsvd1; 98 | } info_0; 99 | u32 cdw2; 100 | }; 101 | union { 102 | struct { 103 | u16 data_len; 104 | u16 param_len; 105 | } info_1; 106 | u32 cdw3; 107 | }; 108 | u64 metadata; 109 | 110 | u64 addr; 111 | u32 metadata_len; 112 | u32 data_len; 113 | 114 | u32 cdw10; 115 | u32 cdw11; 116 | u32 cdw12; 117 | u32 cdw13; 118 | u32 cdw14; 119 | u32 cdw15; 120 | u32 timeout_ms; 121 | u32 result0; 122 | u32 result1; 123 | }; 124 | 125 | struct sssraid_ioq_passthru_cmd { 126 | u8 opcode; 127 | u8 flags; 128 | u16 rsvd0; 129 | u32 nsid; 130 | union { 131 | struct { 132 | u16 res_sense_len; 133 | u8 cdb_len; 134 | u8 rsvd0; 135 | } info_0; 136 | u32 cdw2; 137 | }; 138 | union { 139 | struct { 140 | u16 subopcode; 141 | u16 rsvd1; 142 | } info_1; 143 | u32 cdw3; 144 | }; 145 | union { 146 | struct { 147 | u16 rsvd; 148 | u16 param_len; 149 | } info_2; 150 | u32 cdw4; 151 | }; 152 | u32 cdw5; 153 | u64 addr; 154 | u64 prp2; 155 | union { 156 | struct { 157 | u16 eid; 158 | u16 sid; 159 | } info_3; 160 | u32 cdw10; 161 | }; 162 | union { 163 | struct { 164 | u16 did; 165 | u8 did_flag; 166 | u8 rsvd2; 167 | } info_4; 168 | u32 cdw11; 169 | }; 170 | u32 cdw12; 171 | u32 cdw13; 172 | u32 cdw14; 173 | u32 data_len; 174 | u32 cdw16; 175 | u32 cdw17; 176 | u32 cdw18; 177 | u32 cdw19; 178 | u32 cdw20; 179 | u32 cdw21; 180 | u32 cdw22; 181 | u32 cdw23; 182 | u64 sense_addr; 183 | u32 cdw26[4]; 184 | u32 timeout_ms; 185 | u32 result0; 186 | u32 result1; 187 | }; 188 | 189 | struct bsg_ioctl_cmd { 190 | u32 msgcode; 191 | u32 control; 192 | union { 193 | struct sssraid_passthru_common_cmd ioctl_r64; 194 | struct sssraid_ioq_passthru_cmd ioctl_pthru; 195 | }; 196 | }; 197 | 198 | #endif // _SSSRAID_H 199 | -------------------------------------------------------------------------------- /static_assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * static_assert.h 3 | * 4 | * Home page of code is: https://www.smartmontools.org 5 | * 6 | * Copyright (C) 2019 Christian Franke 7 | * 8 | * SPDX-License-Identifier: GPL-2.0-or-later 9 | */ 10 | 11 | #ifndef STATIC_ASSERT_H 12 | #define STATIC_ASSERT_H 13 | 14 | #define STATIC_ASSERT_H_CVSID "$Id$" 15 | 16 | #if __cplusplus >= 201103 || _MSVC_LANG >= 201103 17 | #define STATIC_ASSERT(x) static_assert((x), #x) 18 | #elif __STDC_VERSION__ >= 201112 19 | #define STATIC_ASSERT(x) _Static_assert((x), #x) 20 | #elif __GNUC__ >= 4 21 | #define STATIC_ASSERT(x) typedef char static_assertion[(x) ? 1 : -1] \ 22 | __attribute__((unused)) 23 | #else 24 | #define STATIC_ASSERT(x) typedef char static_assertion[(x) ? 1 : -1] 25 | #endif 26 | 27 | #endif // STATIC_ASSERT_H 28 | -------------------------------------------------------------------------------- /update-smart-drivedb.8.in: -------------------------------------------------------------------------------- 1 | .ig 2 | Copyright (C) 2013 Hannes von Haugwitz 3 | Copyright (C) 2014-23 Christian Franke 4 | 5 | SPDX-License-Identifier: GPL-2.0-or-later 6 | 7 | $Id$ 8 | 9 | .. 10 | .\" Macros borrowed from pages generated with Pod::Man 11 | .de Sp \" Vertical space (when we can't use .PP) 12 | .if t .sp 0.4v 13 | .if n .sp 14 | .. 15 | .de Vb \" Begin verbatim text 16 | .if t .ft CW 17 | .if n .ft R 18 | .nf 19 | .ne \\$1 20 | .. 21 | .de Ve \" End verbatim text 22 | .ft R 23 | .fi 24 | .. 25 | .\" Use groff extension \(aq (apostrophe quote, ASCII 0x27) if possible 26 | .ie \n(.g .ds Aq \(aq 27 | .el .ds Aq ' 28 | .TH UPDATE-SMART-DRIVEDB 8 "CURRENT_SVN_DATE" "CURRENT_SVN_VERSION" "SMART Monitoring Tools" 29 | .SH NAME 30 | update-smart-drivedb \- update smartmontools drive database 31 | .Sp 32 | .SH "SYNOPSIS" 33 | .B update-smart-drivedb 34 | .RI [ OPTIONS ] 35 | .RI [ DESTFILE ] 36 | .Sp 37 | .SH "DESCRIPTION" 38 | .\" %IF NOT OS ALL 39 | .\"! [This man page is generated for the OS_MAN_FILTER version of smartmontools. 40 | .\"! It does not contain info specific to other platforms.] 41 | .\"! .PP 42 | .\" %ENDIF NOT OS ALL 43 | .B update-smart-drivedb 44 | updates 45 | .B /usr/local/var/lib/smartmontools/drivedb.h 46 | or 47 | .I DESTFILE 48 | from branches/RELEASE_6_0_DRIVEDB of smartmontools SVN repository. 49 | .PP 50 | The tools used for downloading are either 51 | .BR curl (1), 52 | .BR wget (1), 53 | .BR lynx (1), 54 | .\" %IF OS FreeBSD 55 | .BR fetch (1) 56 | [FreeBSD only], 57 | .\" %ENDIF OS FreeBSD 58 | .\" %IF OS OpenBSD 59 | .BR ftp (1) 60 | [OpenBSD only], 61 | .\" %ENDIF OS OpenBSD 62 | or 63 | .BR svn (1). 64 | .PP 65 | The downloaded file is verified with OpenPGP/GPG key ID 721042C5. 66 | The public key block is included in the script. 67 | .PP 68 | The old file is kept if the downloaded file is identical (ignoring 69 | the differences in Id string) otherwise it is moved to 70 | .BR drivedb.h.old . 71 | .PP 72 | The old file is also kept if the downloaded file reports an older version 73 | on the same branch. 74 | This could be overridden with the \*(Aq\-\-force\*(Aq option. 75 | If the branch version differs, the file is always updated. 76 | .Sp 77 | .SH "OPTIONS" 78 | .TP 79 | .B \-s SMARTCTL, \-\-smartctl SMARTCTL 80 | Use the 81 | .BR smartctl (8) 82 | executable at path SMARTCTL for drive database syntax check. 83 | The form \*(Aq\-s \-\*(Aq disables the syntax check. 84 | The default is 85 | .BR /usr/local/sbin/smartctl . 86 | .TP 87 | .B \-t [DIR/]TOOL, \-\-tool [DIR/]TOOL 88 | Use TOOL for download. 89 | TOOL is one of: 90 | .I curl wget lynx 91 | .\" %IF OS FreeBSD 92 | .I fetch 93 | .\" %ENDIF OS FreeBSD 94 | .\" %IF OS OpenBSD 95 | .I ftp 96 | .\" %ENDIF OS OpenBSD 97 | .IR svn . 98 | The default is the first one found in PATH. 99 | If a DIR is also specified, the plain TOOL name must begin with any of the 100 | above names. 101 | .TP 102 | .B \-u LOCATION, \-\-url\-of LOCATION 103 | Use URL of LOCATION for download. 104 | LOCATION is one of: 105 | .br 106 | .I github 107 | (GitHub mirror of SVN repository), 108 | .br 109 | .I sf 110 | (Sourceforge code browser), 111 | .br 112 | .I svn 113 | (SVN repository), 114 | .br 115 | .I svni 116 | (SVN repository via HTTP instead of HTTPS), 117 | .br 118 | .I trac 119 | (Trac code browser). 120 | .br 121 | The default is 122 | .IR svn . 123 | .TP 124 | .B \-\-url URL 125 | Download from URL. 126 | A valid OpenPGP/GPG signature with \*(Aq.raw.asc\*(Aq extension must also 127 | exist unless \*(Aq\-\-no\-verify\*(Aq is also specified. 128 | .TP 129 | .B \-\-file FILE 130 | Copy from local FILE. 131 | A valid OpenPGP/GPG signature \*(AqFILE.raw.asc\*(Aq must also exist 132 | unless \*(Aq\-\-no\-verify\*(Aq is also specified. 133 | .\" %IF ENABLE_DB_INSTALL 134 | .TP 135 | .B \-\-install 136 | Copy from originally installed drive database file. 137 | This is the same as: 138 | .br 139 | \*(Aq\-\-no\-verify \-\-file /usr/local/share/smartmontools/drivedb.h\*(Aq 140 | .\" %ENDIF ENABLE_DB_INSTALL 141 | .TP 142 | .B \-\-trunk 143 | Download from SVN trunk. 144 | This requires \*(Aq\-\-no\-verify\*(Aq because the trunk versions are not 145 | signed. 146 | .TP 147 | .B \-\-branch X.Y 148 | Download from branches/RELEASE_\fBX\fP_\fBY\fP_DRIVEDB. 149 | This also selects the OpenPGP/GPG key for older branches 150 | (5.40 to 6.6: Key ID DFD22559). 151 | .TP 152 | .B \-\-cacert FILE 153 | Use CA certificates from FILE to verify the peer. 154 | .TP 155 | .B \-\-capath DIR 156 | Use CA certificate files from DIR to verify the peer. 157 | .TP 158 | .B \-\-insecure 159 | Don't abort download if certificate verification fails. 160 | This option is also required if a HTTP URL is selected with \*(Aq\-u\*(Aq 161 | option. 162 | .TP 163 | .B \-\-no\-verify 164 | Don't verify signature with GnuPG. 165 | .TP 166 | .B \-\-force 167 | Allow downgrades. 168 | By default, the database is not replaced with an older version of the 169 | same branch. 170 | .TP 171 | .B \-\-export\-key 172 | Print the OpenPGP/GPG public key block. 173 | .TP 174 | .B \-\-dryrun 175 | Print download commands only. 176 | .TP 177 | .B \-q, \-\-quiet 178 | Suppress info messages. 179 | .TP 180 | .B \-v, \-\-verbose 181 | Verbose output. 182 | .TP 183 | .B \-h, \-\-help 184 | Print help text. 185 | .Sp 186 | .SH "EXAMPLES" 187 | Regular update: 188 | .Vb 2 189 | # update-smart-drivedb 190 | /usr/local/var/lib/smartmontools/drivedb.h 7.2/5225 updated to 7.2/5237 191 | .Ve 192 | .PP 193 | Revert to previous version: 194 | .Vb 2 195 | # update-smart-drivedb --force \e 196 | --file /usr/local/var/lib/smartmontools/drivedb.h.old 197 | /usr/local/var/lib/smartmontools/drivedb.h 7.2/5237 downgraded to 7.2/5225 198 | .Ve 199 | .PP 200 | Download the database from SVN trunk to current directory: 201 | .Vb 2 202 | $ update-smart-drivedb --trunk --no-verify -s - -u trac drivedb-trunk.h 203 | drivedb-trunk.h 7.3/5254 newly installed (NOT VERIFIED) 204 | .Ve 205 | .Sp 206 | .SH "EXIT STATUS" 207 | The exit status is 0 if the database has been successfully updated or is 208 | already up to date. 209 | If an error occurs the exit status is 1. 210 | .Sp 211 | .SH FILES 212 | .TP 213 | .B /usr/local/sbin/update-smart-drivedb 214 | full path of this script. 215 | .TP 216 | .B /usr/local/sbin/smartctl 217 | used to check syntax of new drive database. 218 | .\" %IF ENABLE_DB_INSTALL 219 | .TP 220 | .B /usr/local/share/smartmontools/drivedb.h 221 | originally installed drive database. 222 | .\" %ENDIF ENABLE_DB_INSTALL 223 | .TP 224 | .B /usr/local/var/lib/smartmontools/drivedb.h 225 | current drive database. 226 | .TP 227 | .B /usr/local/var/lib/smartmontools/drivedb.h.raw 228 | current drive database with unexpanded SVN Id string. 229 | .TP 230 | .B /usr/local/var/lib/smartmontools/drivedb.h.raw.asc 231 | signature file. 232 | .TP 233 | .B /usr/local/var/lib/smartmontools/drivedb.h.*old* 234 | previous files. 235 | .TP 236 | .B /usr/local/var/lib/smartmontools/drivedb.h.*error* 237 | new files if rejected due to errors. 238 | .TP 239 | .B /usr/local/var/lib/smartmontools/drivedb.h.lastcheck 240 | empty file created if downloaded file was identical. 241 | .Sp 242 | .SH AUTHORS 243 | \fBChristian Franke\fP. 244 | .br 245 | This manual page was originally written by 246 | .BR "Hannes von Haugwitz " . 247 | .Sp 248 | .SH REPORTING BUGS 249 | To submit a bug report, create a ticket in smartmontools wiki: 250 | .br 251 | <\fBhttps://www.smartmontools.org/\fP>. 252 | .br 253 | Alternatively send the info to the smartmontools support mailing list: 254 | .br 255 | <\fBhttps://listi.jpberlin.de/mailman/listinfo/smartmontools-support\fB>. 256 | .Sp 257 | .SH SEE ALSO 258 | \fBsmartctl\fP(8), \fBsmartd\fP(8). 259 | .Sp 260 | .SH PACKAGE VERSION 261 | CURRENT_SVN_VERSION CURRENT_SVN_DATE CURRENT_SVN_REV 262 | .br 263 | $Id$ 264 | --------------------------------------------------------------------------------