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