smartmontools  SVN Rev 4071
Utility to control and monitor storage systems with "S.M.A.R.T."
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions | Variables
os_win32.cpp File Reference
#include "config.h"
#include "int64.h"
#include "atacmds.h"
#include "scsicmds.h"
#include "utility.h"
#include "smartctl.h"
#include "dev_interface.h"
#include "dev_ata_cmd_set.h"
#include "dev_areca.h"
#include "os_win32/wmiquery.h"
#include <errno.h>
#include <stddef.h>
#include <io.h>
#include <ntddscsi.h>
#include <winioctl.h>
#include "csmisas.h"
Include dependency graph for os_win32.cpp:

Go to the source code of this file.

Classes

struct  ATA_PASS_THROUGH
 
struct  _ATA_PASS_THROUGH_EX
 
struct  _STORAGE_DEVICE_DESCRIPTOR
 
struct  _STORAGE_PROPERTY_QUERY
 
struct  _GETVERSIONINPARAMS_EX
 
struct  _SENDCMDINPARAMS_EX
 
class  os_win32::win_smart_device
 
class  os_win32::win_ata_device
 
class  os_win32::win_scsi_device
 
class  os_win32::csmi_device
 
class  os_win32::csmi_ata_device
 
class  os_win32::win_csmi_device
 
class  os_win32::win_tw_cli_device
 
class  os_win32::win_areca_ata_device
 Areca RAID support. More...
 
class  os_win32::win_areca_scsi_device
 
class  os_win32::win_smart_interface
 
union  os_win32::STORAGE_DEVICE_DESCRIPTOR_DATA
 
struct  os_win32::SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER
 

Namespaces

 os_win32
 

Macros

#define WINVER   0x0502
 
#define _WIN32_WINNT   WINVER
 
#define assert(x)   /* */
 
#define WIN32_LEAN_AND_MEAN
 
#define _WIN32
 
#define ATTR_UNUSED
 
#define ASSERT_CONST(c, n)   typedef char assert_const_##c[((c) == (n)) ? 1 : -1] ATTR_UNUSED
 
#define ASSERT_SIZEOF(t, n)   typedef char assert_sizeof_##t[(sizeof(t) == (n)) ? 1 : -1] ATTR_UNUSED
 
#define SELECT_WIN_32_64(x32, x64)   (x32)
 
#define IOCTL_IDE_PASS_THROUGH   CTL_CODE(IOCTL_SCSI_BASE, 0x040A, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
 
#define IOCTL_ATA_PASS_THROUGH   CTL_CODE(IOCTL_SCSI_BASE, 0x040B, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
 
#define ATA_FLAGS_DRDY_REQUIRED   0x01
 
#define ATA_FLAGS_DATA_IN   0x02
 
#define ATA_FLAGS_DATA_OUT   0x04
 
#define ATA_FLAGS_48BIT_COMMAND   0x08
 
#define ATA_FLAGS_USE_DMA   0x10
 
#define ATA_FLAGS_NO_MULTIPLE   0x20
 
#define FILE_DEVICE_SCSI   0x001b
 
#define IOCTL_SCSI_MINIPORT_SMART_VERSION   ((FILE_DEVICE_SCSI << 16) + 0x0500)
 
#define IOCTL_SCSI_MINIPORT_IDENTIFY   ((FILE_DEVICE_SCSI << 16) + 0x0501)
 
#define IOCTL_SCSI_MINIPORT_READ_SMART_ATTRIBS   ((FILE_DEVICE_SCSI << 16) + 0x0502)
 
#define IOCTL_SCSI_MINIPORT_READ_SMART_THRESHOLDS   ((FILE_DEVICE_SCSI << 16) + 0x0503)
 
#define IOCTL_SCSI_MINIPORT_ENABLE_SMART   ((FILE_DEVICE_SCSI << 16) + 0x0504)
 
#define IOCTL_SCSI_MINIPORT_DISABLE_SMART   ((FILE_DEVICE_SCSI << 16) + 0x0505)
 
#define IOCTL_SCSI_MINIPORT_RETURN_STATUS   ((FILE_DEVICE_SCSI << 16) + 0x0506)
 
#define IOCTL_SCSI_MINIPORT_ENABLE_DISABLE_AUTOSAVE   ((FILE_DEVICE_SCSI << 16) + 0x0507)
 
#define IOCTL_SCSI_MINIPORT_SAVE_ATTRIBUTE_VALUES   ((FILE_DEVICE_SCSI << 16) + 0x0508)
 
#define IOCTL_SCSI_MINIPORT_EXECUTE_OFFLINE_DIAGS   ((FILE_DEVICE_SCSI << 16) + 0x0509)
 
#define IOCTL_SCSI_MINIPORT_ENABLE_DISABLE_AUTO_OFFLINE   ((FILE_DEVICE_SCSI << 16) + 0x050a)
 
#define IOCTL_SCSI_MINIPORT_READ_SMART_LOG   ((FILE_DEVICE_SCSI << 16) + 0x050b)
 
#define IOCTL_SCSI_MINIPORT_WRITE_SMART_LOG   ((FILE_DEVICE_SCSI << 16) + 0x050c)
 
#define IOCTL_STORAGE_QUERY_PROPERTY   CTL_CODE(IOCTL_STORAGE_BASE, 0x0500, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
#define SMART_VENDOR_3WARE   0x13C1
 
#define ARECA_MAX_CTLR_NUM   16
 
#define SMART_CYL_LOW   0x4F
 
#define SMART_CYL_HI   0xC2
 
#define SYNCOBJNAME   "Global\\SynIoctlMutex"
 
#define SYNCOBJNAME   "Global\\SynIoctlMutex"
 

Typedefs

typedef struct _ATA_PASS_THROUGH_EX ATA_PASS_THROUGH_EX
 
typedef struct _STORAGE_DEVICE_DESCRIPTOR STORAGE_DEVICE_DESCRIPTOR
 
typedef enum _STORAGE_QUERY_TYPE STORAGE_QUERY_TYPE
 
typedef enum _STORAGE_PROPERTY_ID STORAGE_PROPERTY_ID
 
typedef struct _STORAGE_PROPERTY_QUERY STORAGE_PROPERTY_QUERY
 
typedef struct _GETVERSIONINPARAMS_EX GETVERSIONINPARAMS_EX
 
typedef struct _SENDCMDINPARAMS_EX SENDCMDINPARAMS_EX
 

Enumerations

enum  _STORAGE_QUERY_TYPE { PropertyStandardQuery = 0, PropertyExistsQuery, PropertyMaskQuery, PropertyQueryMaxDefined }
 
enum  _STORAGE_PROPERTY_ID {
  StorageDeviceProperty = 0, StorageAdapterProperty, StorageDeviceIdProperty, StorageDeviceUniqueIdProperty,
  StorageDeviceWriteCacheProperty, StorageMiniportProperty, StorageAccessAlignmentProperty
}
 
enum  os_win32::win_dev_type {
  os_win32::DEV_UNKNOWN = 0, os_win32::DEV_ATA, os_win32::DEV_SCSI, os_win32::DEV_SAT,
  os_win32::DEV_USB
}
 

Functions

 ASSERT_CONST (SMART_GET_VERSION, 0x074080)
 
 ASSERT_CONST (SMART_SEND_DRIVE_COMMAND, 0x07c084)
 
 ASSERT_CONST (SMART_RCV_DRIVE_DATA, 0x07c088)
 
 ASSERT_SIZEOF (GETVERSIONINPARAMS, 24)
 
 ASSERT_SIZEOF (SENDCMDINPARAMS, 32+1)
 
 ASSERT_SIZEOF (SENDCMDOUTPARAMS, 16+1)
 
 ASSERT_CONST (IOCTL_IDE_PASS_THROUGH, 0x04d028)
 
 ASSERT_SIZEOF (ATA_PASS_THROUGH, 12+1)
 
 ASSERT_CONST (IOCTL_ATA_PASS_THROUGH, 0x04d02c)
 
 ASSERT_SIZEOF (ATA_PASS_THROUGH_EX, SELECT_WIN_32_64(40, 48))
 
 ASSERT_CONST (IOCTL_SCSI_PASS_THROUGH, 0x04d004)
 
 ASSERT_CONST (IOCTL_SCSI_PASS_THROUGH_DIRECT, 0x04d014)
 
 ASSERT_SIZEOF (SCSI_PASS_THROUGH, SELECT_WIN_32_64(44, 56))
 
 ASSERT_SIZEOF (SCSI_PASS_THROUGH_DIRECT, SELECT_WIN_32_64(44, 56))
 
 ASSERT_CONST (IOCTL_SCSI_MINIPORT, 0x04d008)
 
 ASSERT_SIZEOF (SRB_IO_CONTROL, 28)
 
 ASSERT_CONST (IOCTL_STORAGE_QUERY_PROPERTY, 0x002d1400)
 
 ASSERT_SIZEOF (STORAGE_DEVICE_DESCRIPTOR, 36+1+3)
 
 ASSERT_SIZEOF (STORAGE_PROPERTY_QUERY, 8+1+3)
 
 ASSERT_CONST (IOCTL_STORAGE_PREDICT_FAILURE, 0x002d1100)
 
 ASSERT_SIZEOF (STORAGE_PREDICT_FAILURE, 4+512)
 
 ASSERT_SIZEOF (GETVERSIONINPARAMS_EX, sizeof(GETVERSIONINPARAMS))
 
 ASSERT_SIZEOF (SENDCMDINPARAMS_EX, sizeof(SENDCMDINPARAMS))
 
 ASSERT_SIZEOF (IOCTL_HEADER, sizeof(SRB_IO_CONTROL))
 
 ASSERT_SIZEOF (CSMI_SAS_DRIVER_INFO_BUFFER, 204)
 
 ASSERT_SIZEOF (CSMI_SAS_PHY_INFO_BUFFER, 2080)
 
 ASSERT_SIZEOF (CSMI_SAS_STP_PASSTHRU_BUFFER, 168)
 
static bool os_win32::is_wow64 ()
 
static win_dev_type os_win32::get_phy_drive_type (int drive)
 
static win_dev_type os_win32::get_phy_drive_type (int drive, GETVERSIONINPARAMS_EX *ata_version_ex)
 
static win_dev_type os_win32::get_log_drive_type (int drive)
 
static bool os_win32::get_usb_id (int drive, unsigned short &vendor_id, unsigned short &product_id)
 
static const char * os_win32::ata_get_def_options (void)
 
static int os_win32::is_permissive ()
 
static int os_win32::drive_letter (const char *s)
 
static const char * os_win32::skipdev (const char *s)
 
static int os_win32::sdxy_to_phydrive (const char(&xy)[2+1])
 
static win_dev_type os_win32::get_dev_type (const char *name, int &phydrive)
 
static void os_win32::print_ide_regs (const IDEREGS *r, int out)
 
static void os_win32::print_ide_regs_io (const IDEREGS *ri, const IDEREGS *ro)
 
static int os_win32::smart_get_version (HANDLE hdevice, GETVERSIONINPARAMS_EX *ata_version_ex=0)
 
static int os_win32::smart_ioctl (HANDLE hdevice, IDEREGS *regs, char *data, unsigned datasize, int port)
 
static int os_win32::ide_pass_through_ioctl (HANDLE hdevice, IDEREGS *regs, char *data, unsigned datasize)
 
static int os_win32::ata_pass_through_ioctl (HANDLE hdevice, IDEREGS *regs, IDEREGS *prev_regs, char *data, int datasize)
 
static int os_win32::ata_via_scsi_miniport_smart_ioctl (HANDLE hdevice, IDEREGS *regs, char *data, int datasize)
 
static int os_win32::ata_via_3ware_miniport_ioctl (HANDLE hdevice, IDEREGS *regs, char *data, int datasize, int port)
 
static int os_win32::update_3ware_devicemap_ioctl (HANDLE hdevice)
 
static int os_win32::get_clipboard (char *data, int datasize)
 
static int os_win32::run_cmd (const char *cmd, char *dataout, int outsize)
 
static const char * os_win32::findstr (const char *str, const char *sub)
 
static void os_win32::copy_swapped (unsigned char *dest, const char *src, int destsize)
 
static int os_win32::storage_query_property_ioctl (HANDLE hdevice, STORAGE_DEVICE_DESCRIPTOR_DATA *data)
 
static int os_win32::storage_predict_failure_ioctl (HANDLE hdevice, char *data=0)
 
static bool os_win32::is_sat (const STORAGE_DEVICE_DESCRIPTOR_DATA *data)
 
static bool os_win32::is_intel_raid_volume (const STORAGE_DEVICE_DESCRIPTOR_DATA *data)
 
static win_dev_type os_win32::get_controller_type (HANDLE hdevice, bool admin, GETVERSIONINPARAMS_EX *ata_version_ex)
 
static win_dev_type os_win32::get_controller_type (const char *path, GETVERSIONINPARAMS_EX *ata_version_ex=0)
 
static int os_win32::get_identify_from_device_property (HANDLE hdevice, ata_identify_device *id)
 
static bool os_win32::get_serial_from_wmi (int drive, ata_identify_device *id)
 
static int os_win32::get_device_power_state (HANDLE hdevice)
 
static long os_win32::scsi_pass_through_indirect (HANDLE h, SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER *sbd)
 
static long os_win32::scsi_pass_through_direct (HANDLE fd, UCHAR targetid, struct scsi_cmnd_io *iop)
 
std::string get_exe_dir ()
 

Variables

const char * os_win32_cpp_cvsid = "$Id: os_win32.cpp 4058 2015-04-18 16:47:36Z chrfranke $"
 

Macro Definition Documentation

#define _WIN32

Definition at line 73 of file os_win32.cpp.

#define _WIN32_WINNT   WINVER

Definition at line 21 of file os_win32.cpp.

#define ARECA_MAX_CTLR_NUM   16
#define assert (   x)    /* */

Definition at line 41 of file os_win32.cpp.

#define ASSERT_CONST (   c,
 
)    typedef char assert_const_##c[((c) == (n)) ? 1 : -1] ATTR_UNUSED

Definition at line 87 of file os_win32.cpp.

#define ASSERT_SIZEOF (   t,
 
)    typedef char assert_sizeof_##t[(sizeof(t) == (n)) ? 1 : -1] ATTR_UNUSED

Definition at line 89 of file os_win32.cpp.

#define ATA_FLAGS_48BIT_COMMAND   0x08

Definition at line 169 of file os_win32.cpp.

#define ATA_FLAGS_DATA_IN   0x02

Definition at line 167 of file os_win32.cpp.

#define ATA_FLAGS_DATA_OUT   0x04

Definition at line 168 of file os_win32.cpp.

#define ATA_FLAGS_DRDY_REQUIRED   0x01

Definition at line 166 of file os_win32.cpp.

#define ATA_FLAGS_NO_MULTIPLE   0x20

Definition at line 171 of file os_win32.cpp.

#define ATA_FLAGS_USE_DMA   0x10

Definition at line 170 of file os_win32.cpp.

#define ATTR_UNUSED

Definition at line 83 of file os_win32.cpp.

#define FILE_DEVICE_SCSI   0x001b

Definition at line 190 of file os_win32.cpp.

#define IOCTL_ATA_PASS_THROUGH   CTL_CODE(IOCTL_SCSI_BASE, 0x040B, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

Definition at line 148 of file os_win32.cpp.

#define IOCTL_IDE_PASS_THROUGH   CTL_CODE(IOCTL_SCSI_BASE, 0x040A, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

Definition at line 125 of file os_win32.cpp.

#define IOCTL_SCSI_MINIPORT_DISABLE_SMART   ((FILE_DEVICE_SCSI << 16) + 0x0505)

Definition at line 200 of file os_win32.cpp.

#define IOCTL_SCSI_MINIPORT_ENABLE_DISABLE_AUTO_OFFLINE   ((FILE_DEVICE_SCSI << 16) + 0x050a)

Definition at line 205 of file os_win32.cpp.

#define IOCTL_SCSI_MINIPORT_ENABLE_DISABLE_AUTOSAVE   ((FILE_DEVICE_SCSI << 16) + 0x0507)

Definition at line 202 of file os_win32.cpp.

#define IOCTL_SCSI_MINIPORT_ENABLE_SMART   ((FILE_DEVICE_SCSI << 16) + 0x0504)

Definition at line 199 of file os_win32.cpp.

#define IOCTL_SCSI_MINIPORT_EXECUTE_OFFLINE_DIAGS   ((FILE_DEVICE_SCSI << 16) + 0x0509)

Definition at line 204 of file os_win32.cpp.

#define IOCTL_SCSI_MINIPORT_IDENTIFY   ((FILE_DEVICE_SCSI << 16) + 0x0501)

Definition at line 196 of file os_win32.cpp.

#define IOCTL_SCSI_MINIPORT_READ_SMART_ATTRIBS   ((FILE_DEVICE_SCSI << 16) + 0x0502)

Definition at line 197 of file os_win32.cpp.

#define IOCTL_SCSI_MINIPORT_READ_SMART_LOG   ((FILE_DEVICE_SCSI << 16) + 0x050b)

Definition at line 206 of file os_win32.cpp.

#define IOCTL_SCSI_MINIPORT_READ_SMART_THRESHOLDS   ((FILE_DEVICE_SCSI << 16) + 0x0503)

Definition at line 198 of file os_win32.cpp.

#define IOCTL_SCSI_MINIPORT_RETURN_STATUS   ((FILE_DEVICE_SCSI << 16) + 0x0506)

Definition at line 201 of file os_win32.cpp.

#define IOCTL_SCSI_MINIPORT_SAVE_ATTRIBUTE_VALUES   ((FILE_DEVICE_SCSI << 16) + 0x0508)

Definition at line 203 of file os_win32.cpp.

#define IOCTL_SCSI_MINIPORT_SMART_VERSION   ((FILE_DEVICE_SCSI << 16) + 0x0500)

Definition at line 195 of file os_win32.cpp.

#define IOCTL_SCSI_MINIPORT_WRITE_SMART_LOG   ((FILE_DEVICE_SCSI << 16) + 0x050c)

Definition at line 207 of file os_win32.cpp.

#define IOCTL_STORAGE_QUERY_PROPERTY   CTL_CODE(IOCTL_STORAGE_BASE, 0x0500, METHOD_BUFFERED, FILE_ANY_ACCESS)

Definition at line 219 of file os_win32.cpp.

#define SELECT_WIN_32_64 (   x32,
  x64 
)    (x32)

Definition at line 93 of file os_win32.cpp.

#define SMART_CYL_HI   0xC2

Definition at line 1119 of file os_win32.cpp.

#define SMART_CYL_LOW   0x4F

Definition at line 1118 of file os_win32.cpp.

#define SMART_VENDOR_3WARE   0x13C1

Definition at line 276 of file os_win32.cpp.

#define SYNCOBJNAME   "Global\\SynIoctlMutex"
#define SYNCOBJNAME   "Global\\SynIoctlMutex"
#define WIN32_LEAN_AND_MEAN

Definition at line 48 of file os_win32.cpp.

#define WINVER   0x0502

Definition at line 20 of file os_win32.cpp.

Typedef Documentation

Enumeration Type Documentation

Enumerator
StorageDeviceProperty 
StorageAdapterProperty 
StorageDeviceIdProperty 
StorageDeviceUniqueIdProperty 
StorageDeviceWriteCacheProperty 
StorageMiniportProperty 
StorageAccessAlignmentProperty 

Definition at line 245 of file os_win32.cpp.

Enumerator
PropertyStandardQuery 
PropertyExistsQuery 
PropertyMaskQuery 
PropertyQueryMaxDefined 

Definition at line 238 of file os_win32.cpp.

Function Documentation

ASSERT_CONST ( SMART_GET_VERSION  ,
0x074080   
)
ASSERT_CONST ( SMART_SEND_DRIVE_COMMAND  ,
0x07c084   
)
ASSERT_CONST ( SMART_RCV_DRIVE_DATA  ,
0x07c088   
)
ASSERT_CONST ( IOCTL_IDE_PASS_THROUGH  ,
0x04d028   
)
ASSERT_CONST ( IOCTL_ATA_PASS_THROUGH  ,
0x04d02c   
)
ASSERT_CONST ( IOCTL_SCSI_PASS_THROUGH  ,
0x04d004   
)
ASSERT_CONST ( IOCTL_SCSI_PASS_THROUGH_DIRECT  ,
0x04d014   
)
ASSERT_CONST ( IOCTL_SCSI_MINIPORT  ,
0x04d008   
)
ASSERT_CONST ( IOCTL_STORAGE_QUERY_PROPERTY  ,
0x002d1400   
)
ASSERT_CONST ( IOCTL_STORAGE_PREDICT_FAILURE  ,
0x002d1100   
)
ASSERT_SIZEOF ( GETVERSIONINPARAMS  ,
24   
)
ASSERT_SIZEOF ( SENDCMDINPARAMS  ,
32+  1 
)
ASSERT_SIZEOF ( SENDCMDOUTPARAMS  ,
16+  1 
)
ASSERT_SIZEOF ( ATA_PASS_THROUGH  ,
12+  1 
)
ASSERT_SIZEOF ( ATA_PASS_THROUGH_EX  ,
SELECT_WIN_32_64(40, 48)   
)
ASSERT_SIZEOF ( SCSI_PASS_THROUGH  ,
SELECT_WIN_32_64(44, 56)   
)
ASSERT_SIZEOF ( SCSI_PASS_THROUGH_DIRECT  ,
SELECT_WIN_32_64(44, 56)   
)
ASSERT_SIZEOF ( SRB_IO_CONTROL  ,
28   
)
ASSERT_SIZEOF ( STORAGE_DEVICE_DESCRIPTOR  ,
36+1+  3 
)
ASSERT_SIZEOF ( STORAGE_PROPERTY_QUERY  ,
8+1+  3 
)
ASSERT_SIZEOF ( STORAGE_PREDICT_FAILURE  ,
4+  512 
)
ASSERT_SIZEOF ( GETVERSIONINPARAMS_EX  ,
sizeof(GETVERSIONINPARAMS)   
)
ASSERT_SIZEOF ( SENDCMDINPARAMS_EX  ,
sizeof(SENDCMDINPARAMS)   
)
ASSERT_SIZEOF ( IOCTL_HEADER  ,
sizeof(SRB_IO_CONTROL)   
)
ASSERT_SIZEOF ( CSMI_SAS_DRIVER_INFO_BUFFER  ,
204   
)
ASSERT_SIZEOF ( CSMI_SAS_PHY_INFO_BUFFER  ,
2080   
)
ASSERT_SIZEOF ( CSMI_SAS_STP_PASSTHRU_BUFFER  ,
168   
)
std::string get_exe_dir ( )

Definition at line 3907 of file os_win32.cpp.

Variable Documentation

const char* os_win32_cpp_cvsid = "$Id: os_win32.cpp 4058 2015-04-18 16:47:36Z chrfranke $"

Definition at line 104 of file os_win32.cpp.