1Introduction 2============ 3The win32 port of sg3_utils contains those utilities that are _not_ specific 4to Linux. One utility for listing available devices, sg_scan, has a 5Windows-specific version for this port. 6 7The dd variants from the sg3_utils package (e.g. sg_dd) rely on too many 8Linux idiosyncrasies to be easily ported. A new package called 'ddpt' 9contains a utility with similar functionality to sg_dd and is available 10for Windows. 11 12The Windows port uses the Microsoft SCSI Pass Through (SPT) interface. 13It has two variants: "SPT" where data is double buffered; and "SPTD" 14where data pointers to the user space are passed to the OS. Only Windows 152000 and later (i.e. not 95, 98 or ME) support SPT. 16 17Two build environments are catered for: cygwin (see www.cygwin.com) and 18MinGW ("Minimalist GNU for Windows", see www.mingw.org). Both are based in 19the gcc compiler (although other C compilers should have little problem with 20the source code). Cygwin is a more sophisticated, commercial product that 21results in executables that depend on cygwin1.dll . No licensing is required 22since sg3_utils is open source (with either BSD or GPL licenses) but users 23will need to fetch that dll. On the other hand MinGW (and its companion MSYS 24shell) builds freestanding console executables. The Unix library support is 25not as advanced with MinGW which has led to some timing functions being 26compiled out when sg3_utils is built for MinGW. 27 28In later versions of Windows these utilities may need to be "run as 29Administrator" for disks and other devices to be seen. If not those devices 30will simply not be found as calls to query them fail with access permission 31problems. 32 33Supported Utilities 34=================== 35Here is a list of utilities that have been ported: 36 sg_bg_ctl 37 sg_compare_and_write 38 sg_decode_sense 39 sg_format 40 sg_get_config 41 sg_get_elem_status 42 sg_get_lba_status 43 sg_ident 44 sg_inq [dropped ATA IDENTIFY DEVICE capability] 45 sg_logs 46 sg_luns 47 sg_modes 48 sg_opcodes 49 sg_persist 50 sg_prevent 51 sg_raw 52 sg_rdac 53 sg_read_attr 54 sg_read_block_limits 55 sg_read_buffer 56 sg_read_long 57 sg_readcap 58 sg_reassign 59 sg_referrals 60 sg_rep_pip 61 sg_rep_zones 62 sg_requests 63 sg_reset_wp 64 sg_rmsn 65 sg_rtpg 66 sg_safte 67 sg_sanitize 68 sg_sat_identify 69 sg_sat_phy_event 70 sg_sat_read_gplog 71 sg_sat_set_features 72 sg_scan [this is Windows specific] 73 sg_seek 74 sg_senddiag 75 sg_ses 76 sg_ses_microcode 77 sg_start 78 sg_stpg 79 sg_stream_ctl 80 sg_sync 81 sg_timestamp 82 sg_turs 83 sg_unmap 84 sg_verify 85 sg_vpd 86 sg_wr_mode 87 sg_write_buffer 88 sg_write_long 89 sg_write_same 90 sg_write_verify 91 sg_write_x 92 sg_zone 93 94Most utility names are indicative of the main SCSI command that they execute. 95Some utilities are slightly higher level, for example sg_ses fetches SCSI 96Enclosure Services (SES) status pages and can send control pages. Each 97utility has a man page (placed in section 8). There is summary of the mapping 98between utility names and the SCSI commands they execute in the COVERAGE 99file. An overview of sg3_utils can be found at: 100https://sg.danny.cz/sg/sg3_utils.html . 101A copy of the "sg3_utils.html" file is in the "doc" subdirectory. 102 103Some man pages have examples which use Linux device names which hopefully 104will not confuse Windows users. 105 106Two pass-through variants 107========================= 108The sg_pt_win32.c file uses the Windows SCSI Pass Through interface. 109That is often shortened to SPT or SPTI. There are two DeviceIoControl() 110ioctl variants provided: IOCTL_SCSI_PASS_THROUGH and 111IOCTL_SCSI_PASS_THROUGH_DIRECT. The former involves double handling of 112data (and perhaps an upper limit on the data length associated with 113one SCSI command; MS documentation mentions 16 KB). The "direct" 114variant passes a pointer from the user space and to be faster looks 115and more versatile. 116 117However the "direct" variant has potentially (unquantified) alignment 118requirements and may not be (well) implemented by the hardware driver. 119In practice some users have reported errors (e.g. 1117: a non-descript 120IO error) when the direct variant is used. 121 122Hence the non-direct variant is the default. The default size limit 123on the data buffer is set at 16 KB but if the user asks for more 124the data buffer will be extended. The OS or the hardware drivers 125may reject the extended data buffer but we tried. 126 127The package can be built using the direct variant with: 128 ./configure --enable-win32-spt-direct 129rather than: 130 ./configure 131prior to the 'make' call. 132 133In sg3_utils version 1.31 run-time selection of the direct or indirect 134interface was added with the scsi_pt_win32_direct(int state_direct) 135function declared in sg_pt.h. The default is indirect unless 136'./configure --enable-win32-spt-direct' was used in the build. If 137'state_direct' is 1 then the direct interface is used and if it is 0 138the indirect interface is used. 139 140Both sg_read_buffer and sg_write_buffer can transfer buffers larger 141than 16 KB. So in sg3_utils version 1.31, they use this new function 142to set direct interface mode. This is regardless of whether or 143not "--enable-win32-spt-direct" is given to ./configure . 144 145Details 146======= 147Most of the ported utilities listed above use SCSI command functions 148declared in sg_cmds_*.h headers . Those SCSI command functions are 149implemented in the corresponding ".c" files. The ".c" files pass SCSI 150commands to the host operating system via an interface declared in sg_pt.h . 151There are currently five implementations of that interface depending on 152the host operating system: 153 - sg_pt_linux.c 154 - sg_pt_freebsd.c 155 - sg_pt_osf1.c [Tru64] 156 - sg_pt_solaris.c 157 - sg_pt_win32.c 158 159The ASPI32 interface which requires a dll from Adaptec is not supported. 160 161The sg_scan utility is a special version for Windows and it attempts to show 162the various available storage device names, one per line. Here is an example 163of sg_scan's output: 164 165# sg_scan 166PD0 [C] FUJITSU MHY2160BH 0000 167PD1 [DF] WD 2500BEV External 1.05 WD-WXE90 168CDROM0 [E] MATSHITA DVD/CDRW UJDA775 CB03 169 170Here is an example with added bus type: 171 172# sg_scan -b 173PD0 [C] <Ata > FUJITSU MHY2160BH 0000 174PD1 [DF] <Usb > WD 2500BEV External 1.05 WD-WXE90 175CDROM0 [E] <Atapi> MATSHITA DVD/CDRW UJDA775 CB03 176 177Here is an example with added SCSI adapter scan: 178 179# sg_scan -b -s 180PD0 [C] <Ata > ST380011A 8.01 181PD1 <Scsi > SEAGATE ST373455SS 2189 182PD2 <Scsi > ATA ST3160812AS D 183PD3 <Scsi > SEAGATE ST336754SS 0003 184CDROM0 [F] <Atapi> HL-DT-ST DVDRAM GSA-4163B A103 185TAPE0 <Scsi > SONY SDT-7000 0192 186 187SCSI0:0,0,0 claimed=1 pdt=0h dubious ST380011 A 8.01 188SCSI1:0,0,0 claimed=1 pdt=5h HL-DT-ST DVDRAM GSA-4163B A103 189SCSI2:0,6,0 claimed=1 pdt=1h SONY SDT-7000 0192 190SCSI5:0,17,0 claimed=1 pdt=0h SEAGATE ST373455SS 2189 191SCSI5:0,19,0 claimed=1 pdt=0h ATA ST3160812AS D 192SCSI5:0,21,0 claimed=1 pdt=0h SEAGATE ST336754SS 0003 193SCSI5:0,112,0 claimed=0 pdt=10h LSI PSEUDO DEVICE 2.34 194 195The storage devices scanned are PhysicalDrive<n> (shortened form PD<n> used), 196CDROM<n> (which includes DVD and BD drives) and TAPE<n>. There is also an 197optional SCSI adapter scan with device names of the form SCSI<n>:<b>:<t>:<l> . 198These only come into play for devices that are not claimed by one of the 199storage class drivers. The "LSI PSEUDO DEVICE" device above is an example 200of an unclaimed device. The SCSI adapter scan does not show USB and IEEE 2011394 connected devices. 202 203Volume names (e.g. "C:") that match a storage device (or perhaps a 204partition within that device) are shown in brackets. Notice there can be 205zero, one or more volume names for each storage device. Up to four volume 206names are listed in brackets, if there are more a "+" is added after the 207fourth. 208 209Several utilities have conditional compilation sections based on 210the SG_LIB_MINGW define. For those who want to try native C compilers 211on Windows setting the SG_LIB_MINGW define may help. 212 213Build environments 214================== 215This package uses autotools infrastructure with the now common 216"./configure ; make ; make install" sequence needed to build and install 217from the source found in the tarball. Two Windows environments for building 218Unix code are supported: cygwin and MinGW. If the "./configure" sequence 219fails try using the ./autogen.sh prior to that sequence. The executables 220produced are console applications that can be executed in either a cygwin, 221MSYS or "cmd" shell. Various build options are available by giving 222command line options to "./configure", see the INSTALL file for generic 223information about the build infrastructure. 224 225MinGW can be used to cross built on some Redhat (Linux) platforms. After 226loading the cross build packages, the ./configure call in the normal 227autotools sequence should be replaced by either mingw32-configure or 228mingw64-configure. These scripts will set up the environment for 229the cross build and then call ./configure (so this invocation should be 230made in the top level of the untarred source). Options given to either 231script (e.g. --enable-win32-spt-direct) will be passed through to 232./configure . 233 234Binary and Text files 235===================== 236A problem has been reported with binary output being written in a MinGW 237environment (or executables build by MinGW). Windows has a concept of text 238and binary files which is not found in Unix. Recent versions of MinGW 239default to opening files in text mode. This can lead to binary output 240(such as when the '--raw' option is given) having 0xa (i.e. LF) translated 241to 0xd,0xa (i.e. CR,LF). sg3_utils version 1.26 attempts to fix this 242problem by changing what it knows to be binary output files to "binary 243mode" with the setmode() Windows command. 244 245 246Douglas Gilbert 2476th June 2020 248