Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
.github/workflows/ | 03-May-2024 | - | 70 | 64 | ||
debian/ | 03-May-2024 | - | 467 | 293 | ||
doc/ | 03-May-2024 | - | 18,389 | 18,126 | ||
examples/ | 03-May-2024 | - | 4,650 | 3,657 | ||
getopt_long/ | 03-May-2024 | - | 522 | 292 | ||
include/ | 03-May-2024 | - | 4,999 | 2,619 | ||
inhex/ | 03-May-2024 | - | 1,305 | 1,116 | ||
lib/ | 03-May-2024 | - | 28,223 | 23,955 | ||
scripts/ | 03-May-2024 | - | 3,235 | 2,598 | ||
src/ | 03-May-2024 | - | 86,894 | 79,190 | ||
suse/ | 03-May-2024 | - | 520 | 424 | ||
testing/ | 03-May-2024 | - | 23,902 | 20,601 | ||
utils/ | 03-May-2024 | - | 885 | 744 | ||
.gitignore | D | 03-May-2024 | 1.6 KiB | 110 | 108 | |
AUTHORS | D | 03-May-2024 | 114 | 4 | 2 | |
Android.bp | D | 03-May-2024 | 1.9 KiB | 83 | 76 | |
BSD_LICENSE | D | 03-May-2024 | 1.3 KiB | 28 | 21 | |
COPYING | D | 03-May-2024 | 1.4 KiB | 33 | 26 | |
COVERAGE | D | 03-May-2024 | 8.3 KiB | 189 | 176 | |
CREDITS | D | 03-May-2024 | 6.3 KiB | 164 | 114 | |
ChangeLog | D | 03-May-2024 | 92.4 KiB | 1,920 | 1,860 | |
INSTALL | D | 03-May-2024 | 9.4 KiB | 241 | 181 | |
LICENSE | D | 03-May-2024 | 10.7 KiB | 194 | 146 | |
Makefile.am | D | 03-May-2024 | 4 KiB | 185 | 171 | |
Makefile.in | D | 03-May-2024 | 28.9 KiB | 904 | 803 | |
NEWS | D | 03-May-2024 | 24 | 2 | 1 | |
OWNERS | D | 03-May-2024 | 65 | 4 | 3 | |
README | D | 03-May-2024 | 5.7 KiB | 114 | 100 | |
README.details | D | 03-May-2024 | 29.2 KiB | 561 | 477 | |
README.freebsd | D | 03-May-2024 | 5.6 KiB | 165 | 146 | |
README.iscsi | D | 03-May-2024 | 1.3 KiB | 38 | 26 | |
README.sg_start | D | 03-May-2024 | 1.2 KiB | 39 | 30 | |
README.solaris | D | 03-May-2024 | 5.6 KiB | 169 | 147 | |
README.tru64 | D | 03-May-2024 | 2.8 KiB | 98 | 87 | |
README.win32 | D | 03-May-2024 | 9.8 KiB | 248 | 217 | |
aclocal.m4 | D | 03-May-2024 | 370.8 KiB | 10,364 | 9,371 | |
ar-lib | D | 03-May-2024 | 5.7 KiB | 272 | 211 | |
autogen.sh | D | 03-May-2024 | 46.3 KiB | 1,579 | 1,054 | |
build_debian.sh | D | 03-May-2024 | 483 | 16 | 4 | |
compile | D | 03-May-2024 | 7.2 KiB | 349 | 259 | |
config.guess | D | 03-May-2024 | 48.3 KiB | 1,755 | 1,528 | |
config.h.in | D | 03-May-2024 | 4.2 KiB | 178 | 119 | |
config.sub | D | 03-May-2024 | 34.6 KiB | 1,891 | 1,704 | |
configure | D | 03-May-2024 | 462.5 KiB | 16,050 | 13,432 | |
configure.ac | D | 03-May-2024 | 7.5 KiB | 221 | 188 | |
depcomp | D | 03-May-2024 | 23 KiB | 792 | 502 | |
install-sh | D | 03-May-2024 | 15 KiB | 542 | 352 | |
ltmain.sh | D | 03-May-2024 | 325.6 KiB | 11,449 | 8,222 | |
missing | D | 03-May-2024 | 6.7 KiB | 216 | 143 | |
sg3_utils.man8.html | D | 03-May-2024 | 44.7 KiB | 990 | 849 | |
sg3_utils.spec | D | 03-May-2024 | 7.8 KiB | 281 | 213 |
README
1 README for sg3_utils 2 ==================== 3Introduction 4------------ 5sg3_utils is a package of utilities originally written to send individual 6SCSI commands to storage devices that used one of the SCSI command sets. 7These utilities can be divided into three groups: 8 - sg_raw: the user supplies the cdb (command descriptor block) and 9 optionally the size of the data-in and data-out buffers 10 - one command utilities: the majority of the utilities in this package 11 send one SCSI command. Their names start with "sg_" while the 12 remaining part of their name alludes to the command which is sent. For 13 example, "sg_inq" sends the SCSI INQUIRY command. Some utilities in 14 this group send one of a selection of commands, typically those 15 commands have a lot it common (e.g. sg_write_x). 16 - copy type utilities: sg_dd, sgp_dd and sgm_dd use the Unix dd command 17 as a template. sg_xcopy sends the SCSI EXTENDED COPY command which in 18 some cases can do offloaded copies. As well as copying some of these 19 utilities can compare if two data segments held on disks are the same. 20 21Platforms 22--------- 23These utilities were written on Linux and should work from Linux kernel 24(lk) 2.4 through to the current series 5. The third group ("copy type") 25are only implemented on Linux, but a separate portable package/utility 26called ddpt implements similar functionality. The first two groups are 27implemented (i.e. ported) to Android, FreeBSD, Solaris and Windows. The 28Windows port uses either a Cygwin or MinGW (plus Msys) build environment 29(rather than Visual Studio). 30 31Library 32------- 33Many of these utilities share a lot of code (e.g. SCSI error messages) 34so a lot of repetition (potentially error prone) is saved by having a 35library called libsgutils or some variation on that name. Distributions 36(especially of Linux) have differing policies on how a library (and a 37package) should be named. For that reason this package is sometimes 38known as "sg3-utils" (i.e. the underscore is turned into a hyphen). 39Various other packages use libsgutils. The library interface is not 40altered from one package release, to the next, but the library interface 41may be expanded. If a utility from one release is used with a libsgutils 42from an earlier release, then the runtime linking may fail. Typically 43package managers take care of these details so that runtime linking 44errors should be rare. 45 46Command Sets 47------------ 48SCSI command sets are not the only storage command sets in wide use, there 49are also ATA and NVMe command sets. There is a SCSI command set to 50translate SCSI commands to ATA commands (called SAT: SCSI to ATA 51Translation). SAT includes an ATA PASS-THROUGH SCSI command and sg_sat_* 52utilities (there are four) are examples of using SAT. The SAS transport 53(Serial Attached SCSI) can convey ATA commands through a SCSI/SAS domain 54via its Serial ATA Tunnelled Protocol (STP). 55 56NVMe command sets (e.g. Admin, NVM and MI) are relatively new. There was an 57early paper on a SCSI to NVMe Translation Layer (SNTL) but it hasn't been 58standardized. The sg_inq utility will send (and decode the response of) a 59SCSI INQUIRY command if the underlying device is a SCSI device. If the 60underlying device is a NVMe controller or namespace, then sg_inq will send 61a NVMe Admin Identify command and decode the response. The sg_ses utility 62(for SCSI Enclosure Services) also checks whether its underlying device is 63SCSI or NVME. In the NVMe case, sg_ses translates the SCSI SEND DIAGNOSTIC 64and READ DIAGNOSTIC RESULTS commands to the NVMe Management Interface (MI) 65SES Send and SES Receive commands respectively. The output of the sg_ses 66utility should be similar, irrespective of whether the "SES" device is 67SCSI or NVMe. 68 69The sg_raw utility may send NVMe Admin or NVM commands (as well as SCSI 70commands). One difficulty with a command-line utility invoking NVME 71commands is that those commands contain memory addresses for data-in (from 72the storage device) or data-out (toward the storage device) transfers. See 73the sg_raw manpage for how this difficulty is addressed. 74 75Documentation 76------------- 77Manual pages ("manpages") are the primary method of utility documentation. 78All utilities and scripts that are installed by this package have a 79manpage. There are utilities in the examples, testing and utils 80directories that are not installed and do not have manpages. Nearly 81all utilities have runtime help, usually invoked with either the '-h' 82short option or the '--help' long option. There is also an overarching 83manpage called "sg3_utils". All manpages are placed in chapter 8 which 84is for system administration commands/utilities. 85 86The sg3_utils package and some more complex utilities have html pages: 87 sg3_utils: https://sg.danny.cz/sg/sg3_utils.html 88 sg_ses: https://sg.danny.cz/sg/sg_ses.html 89 sg_dd: https://sg.danny.cz/sg/sg_dd.html 90 91A tarball (and zip) of all the manpages from the previous release are 92here: 93 https://sg.danny.cz/sg/p/sg3_utils_man_html.tgz 94 https://sg.danny.cz/sg/p/sg3_utils_man_html.zip 95 96There is a html rendering of the sg3_utils manpage in the same directory 97as this README file called sg3_utils.man8.html . 98 99The previous README file is now called README.details plus there are 100these OS specific files: README.freebsd , README.solaris , README.tru64 101and README.win32 . To know the current state of the package the ChangeLog 102file is the good reference. 103 104The author's primary source code repository uses subversion and is on 105the author's equipment (a RPi). One advantage of subversion is its 106revision numbers which are simply integers starting at 1 and ascending. 107For this package the current revision is 928 . The subversion repository 108is mirrored in git (using "git svn" tools) here: 109 https://github.com/doug-gilbert/sg3_utils 110 111 112Douglas Gilbert 11331st December 2021 114
README.details
1 README.details for sg3_utils 2 ============================ 3Introduction 4============ 5This package contains low level command line utilities for devices that use 6the SCSI command set. Originally the SCSI command set was associated 7exclusively with the SCSI Parallel Interface (SPI) transport. SPI has now 8almost been completely replaced by the Serial Attached SCSI (SAS) transport 9which also accepts the SCSI command set. Additionally many other storage 10related transports use the SCSI command set (amongst others); examples are 11ATAPI devices (CD/DVDs and tapes), USB mass storage devices (including those 12using the newer UAS[P]), Fibre Channel disks, IEEE 1394 storage devices (SBP 13protocol), iSCSI, FCoE and SOP devices. Even NVMe which has its own command 14set accepts SCSI commands in some contexts; one example is for enclosure 15management where NVME-MI has SES Send and SES Receive commands. SES refers 16to the SCSI Enclosure Services command set. 17 18This package originally targeted the Linux SCSI subsystem. Since most 19operating systems contain a SCSI command pass-through mechanism, many 20utilities within this package have been ported. This README mainly 21concentrates on Linux: see the README.freebsd file for the FreeBSD port, 22README.solaris for the Solaris port, the README.tru64 file for the Tru64 23(OSF) port and README.win32 for the Windows ports (of which there are two 24variants). 25 26Most utilities within the sg3_utils package work at the SCSI command level. 27For example the sg_inq utility issues a SCSI INQUIRY command and decodes the 28response. The COVERAGE file has a table containing a row for each SCSI 29command issued by this package; to the right of each row is the utility 30(sometimes more than one) that issue that SCSI command. The COVERAGE file 31has a second table for ATA commands usage. 32 33Some utilities interface at a slightly higher level, for example: sg_dd, 34sgm_dd and sgp_dd. These are closely related to the Unix dd command and 35typically issue a sequence of SCSI READ and WRITE commands to copy data. 36These utilities are relatively tightly bound to Linux and are not ported to 37other Operating Systems. A new utility called ddpt (in a package of the same 38name) is more generic while still allowing a copy to be done in terms of 39SCSI READ and WRITE commands. ddpt has been ported to other OSes. 40 41License 42======= 43All utilities and libraries have either a "2 clause" BSD license or are 44"GPL-2ed". The "2 clause" BSD license is taken from the FreeBSD project but 45drops the last paragraph that directly refers to the "FreeBSD project". 46That BSD license was updated from the "3 clause" to the newer "2 clause" 47version on 20180119. To save space various source code files refer to a 48file called "BSD_LICENSE" in the main, src and lib directories. The author's 49intention is that users may incorporate all or part of the code in their work 50as they please. Attribution is encouraged. Please check the code as other 51contributors (apart from the author) may also have copyright notices. For a 52list of contributors see the CREDITS file. 53 54 55Description 56=========== 57A web site supporting the sg3_utils package can be found at 58https://sg.danny.cz/sg/sg3_utils.html . That page has a table of released 59versions for download. The most recent release or beta of sg3_utils may 60be found on this page: https://sg.danny.cz/sg in the News section. 61 62The predecessor to this package was called sg_utils. It is described in 63https://sg.danny.cz/sg/uu_index.html and old versions can be downloaded 64from the Downloads section of https://sg.danny.cz/sg . 65 66In the Linux 2.4 kernel series these utilities need to use the SCSI generic 67(sg) driver to access SCSI devices. The name of this package (i.e. sg3_utils) 68refers to version 3 of the SCSI generic (sg) driver which was introduced at 69the beginning of the 2.4 Linux kernel series. Significantly this added a new 70SCSI command interface structure (i.e. struct sg_io_hdr) that is more 71flexible than the older "sg_header" structure found in the sg driver in the 722.2 and earlier Linux kernel series. The sg_io_hdr structure is also more 73flexible than the awkward (and limiting) interface to the 74SCSI_IOCTL_SEND_COMMAND ioctl supported by the Linux SCSI mid level. The 75version 3 sg driver also added the SG_IO ioctl that is synchronous (i.e. it 76issues the requested SCSI command and waits for the response (or a timeout) 77before the ioctl returns to the user space program that invoked it). The 78SG_IO ioctl is now supported in other parts of the Linux kernel in the 2.6 79series. 80 81In sg3_utils version 1.27 support has been added for the Linux bsg driver 82which use the sg version 4 interface. There seems no point in renaming 83this package sg4_utils. The existing utilities just silently support either. 84Currently the source build must be able to see the /usr/include/linux/bsg.h 85file. Then at run time the /proc/devices pseudo file needs to have an entry 86for the bsg driver (appeared around lk 2.6.28). With this in place each 87utility at run time checks the device it has been given and if it is a char 88device whose major number matches the bsg entry in /proc/devices then the 89sg v4 interface is used. Otherwise the sg v3 interface is used. 90 91Utilities that wish to use the asynchronous SCSI command interface (i.e. via 92a write() read() sequence) or issue special "commands" (e.g. bus and device 93resets) still need to use the Linux sg driver. Note that various 94drivers (e.g. cdrom/sr) have different open() flag and permissions policies 95that the user may need to take into account. 96 97If users have problems or questions about them please contact the author. 98Documentation for the Linux sg device driver can be found at: 99https://sg.danny.cz/sg/p/sg_v3_ho.html . This is written in DocBook and the 100original xml can be found in the same directory with the ".xml" extension. 101Postscript and pdf renderings are also in that directory. Older documentation 102for the sg version 3 driver can be found at: 103https://sg.danny.cz/sg/p/scsi_generic_v3.txt . 104 105To save the repetition of common code (e.g. SCSI error processing) and 106reduce the size of the executable files, a shared library called 107libsgutils<num>.so (its Linux name) is created during the build process. 108That library is built from the contents of the include and lib 109subdirectories. The header files in the include subdirectory can be seen 110as the API of libsgutils and are commented with that in mind. The SCSI 111pass-through code for the supported operating systems is found in the lib 112subdirectory with names like sg_pt_linux.c and sg_pt_win32.c . 113 114Various distributions (of Linux mainly) distribute sg3_utils as 3 115installable packages. One is a package containing the shared library 116discussed above (e.g. libsgutils2-2_1.33-0.1_i386.deb). A second package 117contains the utilities (e.g. sg3-utils_1.33-0.1_i386.deb) and depends on the 118first package). Finally there is an optional package that contains header 119files and a static library (e.g. libsgutils2-dev_1.33-0.1_i386.deb). This 120final package is only needed to build other packages (e.g. sdparm) that 121wish to use the sg3_utils shared library. 122 123All the utilities in the src subdirectory have "man" pages that are 124placed in the doc subdirectory. There is also a sg3_utils (8) man page that 125summarizes common facilities including exit statuses. Additional 126information (including each utility's version number) can be found towards 127the top of each ".c" file corresponding to the utility name. 128 129The sg driver in Linux can be seen as having 3 distinct versions: 130 131 v1 lk < 2.2.6 sg_header based relatively unchanged since 1992 132 v2 lk >= 2.2.6 enhanced sg_header interface structure [1999/4/16] 133 v3 lk >= 2.4 additional sg_io_hdr interface structure [2001/1/4] 134 v3 lk >= 2.6 same interface as found in lk 2.4 [2.6.0: 2003/12/18] 135 136and the bsg driver supports the sg v4 interface and was added around 137lk 2.6.28 . This package is targeted at "v3" and "v4". Another package called 138"sg_utils" is targeted at "v2" and to a lesser extent "v1". The "sg_utils" 139package has a subset of the utilities found in this package. 140 141In Linux some sg driver ioctls (notably SG_IO) are defined for many block 142devices in lk 2.6 series. In practice this means all SCSI block devices, 143ATAPI block devices (mainly CD, DVD and BD optical devices) but _not_ ATA 144disks, depending on which kernel configuration options, can be accessed by 145the utilities in this package. SATA disks that use the libata kernel library 146(or some other SCSI to ATA Translation (SAT) Layer (SATL)) accept SCSI 147commands and thus are supported. Support for the SG_IO as been added to the 148scsi tape driver (st) in lk 2.6.6 . 149 150In the src directory the bulk of the utilities are written in relatively 151clean POSIX compliant C code with Linux specific system calls and structures 152removed and placed in Linux specific files in the lib directory. A small 153number of utilities in the src directory do contain Linux specific logic 154and are not ported to other OSes (e.g. sg_dd). One utility, sg_scan, has 155two separate implementations, one for Linux (sg_scan_linux.c) and one for 156Windows (sg_scan_win32.c). The src-lib directory split approach allows 157FreeBSD, Solaris, Tru64 and Windows specific code to be isolated to a few 158files in the lib directory whose interfaces match those of the Linux 159specific code. 160 161Darwin is not supported because the Apple folks do not want to give their 162users a pass-through SCSI interface. The author has read about creative 163hackers using a VM containing a real OS to circumvent the Apple restriction. 164 165C standard is C11 166================== 167The C code in this package is written for portability rather than speed. 168It assumes a level of C99 compliance (the C standard prior to C11) and 169favours POSIX system and library calls over OS specific calls. 170 171The C code is written in a C++ friendly way and is checked from time to 172time that it compiles clean with C++. To accommodate C++ certain C99 173constructs such as designated initializers cannot be used. To build 174with C++, C++11 (i.e. the C++ standard from 2011) or later is required. 175Finding a common C and C++ syntax for zeroing stack variables (including 176aggregates) may need to wait until C23 allows this syntax: 177 struct example_t ex1 {}; 178which C++ introduced in C++11. In the meantime the SG_C_CPP_ZERO_INIT 179define (hack) does this. 180 181The author has not seriously attempted to build this code on MSVC (aka 182Visual Studio). There are a few roadblocks (that may be overcome in the 183future) that include MSVC being basically a C++ compiler, not a C/C++ 184compiler. For some reason MSVC only claims C89 compliance (i.e. the first 185C standard from 1989). MSVC 2013 and 2015 are moving closer to C99 186compliance and may be sufficient to compile this package. Another problem 187is the assumption of the availability of basic Unix system calls such as 188open(). Nearly 20 years ago Microsoft indicated (promised ?) that it 189would move in the direction of POSIX compliance, but very little ever 190happened. "Talk is cheap, there should be a tax on it." 191 192Building 193======== 194This package is designed to be built with the usual: 195 "./configure ; make ; make install" 196sequence. In some situations that may need to be prefixed by a call to 197the "./autogen.sh" script which invokes autoconf and automake. That in turn 198may require packages containing those utilities to be installed. The 199libtool utility is also required. Naturally a C compiler is required 200and due to the vagaries of libtool a C++ compiler also. 201 202The "./configure" takes many command line options with the defaults 203being usually sufficient to start with. One quirk is that the location 204of the installation is under the /usr/local directory. So the sg_inq 205utility will be installed at /usr/local/bin/sg_inq . This is controlled 206by the "--prefix=<directory>" option which defaults to 207"--prefix=/usr/local". As an example to install the executables in /usr/bin 208and disable the creation of the shared library (libsgutils<num>.so) this 209invocation could be used: "./configure --prefix=/usr --disable-shared". 210To reduce the size of an executable as well try this: 211"./configure --prefix=/usr --disable-shared --disable-scsistrings". 212Also --disable-shared will produce (relatively) "static" executables in 213the src directory that are easier to debug. And 214"./configure --enable-debug" will compile with more debug type options, 215including more compiler checks and defining "DEBUG" within the src and 216lib source files. Most utilities in the src directory set '-vv' (i.e. 217equivalent to calling "--verbose" twice) when "DEBUG" is set. 218 219In Linux there are package build files for "rpm" based and for "deb" based 220systems. The 'sg3_utils.spec' file in the main directory can be used like 221this: 'rpmbuild -ba sg3_utils.spec' in a rpmbuild tree SPECS directory. 222To cross build or make a more widely distributable package then the --target 223option may be useful: 'rpmbuild --target=i386 -ba sg3_utils.spec' or 224'rpmbuild --target=x86_64 -ba sg3_utils.spec' . The sg3_utils.spec file 225in the main directory targets Red Hat systems, an alternative "spec" file 226for Suse systems has been placed under the 'suse' directory. 227 228The 'build_debian.sh' script should build several "deb" packages and place 229them in the parent directory. In debian based systems doing 230a 'apt-get install build-essential' is one way to get most of build 231environment needed if it has not already been loaded. There are now some 232problems with this script and the superseded Debian 4.0 ("etch"). See 233debian/README.debian4 for a workaround. Amongst other things debian 234builds are sensitive to the value in the debian/compat file. If it 235contains "7" then it works on lenny and gives warning on squeeze (but 236fails on the earlier etch). 237 238Warning 239======= 240Many devices use SCSI command sets over transport protocols not normally 241associated with SCSI (as defined at https://www.t10.org ). Some of these 242devices react poorly (e.g. lock up) when sent SCSI commands that they don't 243support. Even sending a supported SCSI command with a field set to an 244unexpected value can cause problems. [The author is talking about billions 245of USB devices with horrible SCSI implementations.] 246 247For example, all "SCSI" devices must support the INQUIRY command which the 248SCSI-2 standard says should request a 36 byte response. However later SCSI 249standards (e.g. SPC-2) have increased that length but some SCSI devices lock 250up when they receive a request for anything other than a 36 byte response. 251 252Any well implemented "SCSI" device should react sensibly when a utility in 253sg3_utils sends a SCSI command that it doesn't support. Unfortunately this 254cannot be guaranteed. 255 256Prior to lk 2.6.29 USB mass storage limited sense data to 18 bytes which 257caused problems for certain types of descriptor based sense data. An 258example of this is the SCSI ATA PASS-THROUGH command with the CK_COND bit 259set. 260 261 262Utilities 263========= 264Here is list in alphabetical order of utilities found in the 'src' 265subdirectory of the sg3_utils package: 266 sginfo, sg_bt_ctl, sg_compare_and_write, sg_copy_results, sgm_dd, sgp_dd, 267 sg_dd, sg_decode_sense, sg_emc_trespass, sg_format, sg_get_config, 268 sg_get_elem_status, sg_get_lba_status, sg_ident, sg_inq, sg_logs, 269 sg_luns, sg_map, sg_map26, sg_modes, sg_opcodes, sg_persist, sg_prevent, 270 sg_raw, sg_rbuf, sg_rdac, sg_read, sg_read_attr, sg_readcap, 271 sg_read_block_limits, sg_read_buffer, sg_read_long, sg_reassign, 272 sg_referrals, sg_rem_rest_elem, sg_rep_density, sg_rep_pip, sg_rep_zones, 273 sg_request, sg_reset, sg_rmsn, sg_rtpg, sg_safte, sg_sanitize, 274 sg_sat_identify, sg_sat_phy_event, sg_sat_read_gplog, sg_sat_set_features, 275 sg_scan, sg_seek, sg_senddiag, sg_ses, sg_ses_microcode, sg_start, 276 sg_stpg, sg_stream_ctl, sg_sync, sg_test_rwbuff, sg_timestamp, sg_turs, 277 sg_unmap, sg_verify, sg_vpd, sg_write_buffer, sg_write_long, 278 sg_write_same, sg_write_verify, sg_write_x, sg_wr_mode, sg_xcopy, sg_zone, 279 sg_z_act_query 280 281Each of the above utilities depends on header files found in the 'include' 282subdirectory and library code found in the 'lib' subdirectory. Associated 283man pages are found in the 'doc' subdirectory. Additional programs found 284in the 'archive', 'examples' and 'utils' subdirectories in not build by the 285top level build infrastructure. Linux binary distributions of the sg3_utils 286package (e.g. "rpm" and debian packages) typically contain the shared 287library, the utilities found in the 'src' subdirectory, their associated man 288pages and some documentation files (e.g. README, INSTALL, CREDITS, COPYING 289and COVERAGE). See the INSTALL file for generic instructions about building 290with autotools (e.g. ./configure ). 291 292Man pages can be read (without building and installing the package) by 293going to the 'doc' subdirectory and executing something like this: 294 $ man ./sg_dd.8 295 296To see which SCSI commands (and ATA commands) are used by these utilities 297refer to the COVERAGE file. 298 299Here is a list in alphabetical order of utilities found in the 'examples' 300subdirectory: 301 - sg_excl, scsi_inquiry, sg_sat_chk_power, sg__sat_identify, 302 sg__sat_phy_event, sg__sat_set_features, sg_sat_smart_rd_data, 303 sg_simple1, sg_simple2, sg_simple3, sg_simple4, sg_simple5, 304 sg_simple16 305 306Also in that subdirectory is a script to test sg_persist, an example data 307file for sg_persist (called "transport_ids.txt") and an example data file for 308sg_reassign (called "reassign_addr.txt"). There are several scripts 309for 'sg_senddiag -pf -raw=-' that will put some SAS disk phys into 310a "compliant jitter tolerance pattern" (CJTPAT). 311 312The 'testing' subdirectory contains source and a Makefiles to test 313kernel pass-through and associated drivers, mainly for Linux. There is 314both C code (with the extension ".c") and C++ code (with the extension 315".cpp"). There is a "Makefile" to build the C + C++ code. The Makefile 316depends on some object files from the "lib" subdirectory. So a sequence 317like this may be required prior to invoking make: "cd <top_of_package> ; 318./configure ; cd lib ; make ; cd ../testing". 319 320Here is a list in alphabetical order of utilities found in the 'testing' 321subdirectory: 322 - bsg_queue_tst, sgh_dd (C++), sg_iovec_tst, sg_queue_tst, sg_sense_tst, 323 sg_tst_async (C++), sg_tst_context (C++), sg_tst_excl (C++), 324 sg_tst_excl2 (C++), sg_tst_excl3 (C++) 325 326The 'utils' subdirectory contains source and a Makefile to build "hxascdmp" 327which accepts binary data from stdin (or a file on the command line) and 328outputs an ASCII-HEX and ASCII representation of it. It is similar to the 329Unix od command. There is also code to sg_chk_asc.c which checks a given 330text file (typically a copy of https://www.t10.org/lists/asc-num.txt ) and 331checks it against the asc/ascq text strings held in sg_lib_data.c . 332 333The 'doc' subdirectory contains a README file containing the urls of 334various related documents. 335 336The 'scripts' subdirectory contains some Bourne (bash) shell scripts that 337rely on utilities in the main directory. One script uses the sdparm utility. 338These scripts are described in the scripts/README file and have usage 339messages. 340 341 342Notes for utilities without man pages 343===================================== 344These utils are found in the 'examples' subdirectory. 345 346The "scsi_inquiry" program shows the use of the SCSI_IOCTL_SEND_COMMAND 347ioctl to send a SCSI INQUIRY command. That ioctl() is supported by the 348SCSI sub system mid level and so is common to all sd, sr, st and sg devices. 349That ioctl is deprecated in the lk 2.6 series. This program has been placed 350in the "examples" subdirectory. 351 352"sg_simple1" and "sg_simple2" are example programs demonstrating calls 353to the SCSI INQUIRY and TEST UNIT READY commands. They only differ in their 354error processing: sg_simple1 uses sg_lib.[hc] for error processing while 355sg_simple2 does its own more primitive checks. 356 357"sg_simple3" tests out user space scatter gather added to the version 3 358sg driver. 359 360"sg_simple4" shows the INQUIRY command using mmap-ed IO to obtain its 361response buffer. 362 363"sg_simple5" also sends and INQUIRY and TEST UNIT READY commands. It 364uses the generic pass through mechanism based on sg_pt.h . It will 365currently build in Linux and FreeBSD (with "make -f Makefile.freebsd"). 366It has extensive error checking code. 367 368"sg_simple16" attempts to send a 16 byte SCSI command, READ_16, to the 369scsi device. This is only supported for lk >= 2.4.15 and for adapter 370drivers that indicate that they have 16 byte CDB capability (otherwise 371DID_ABORT will appear in the host_status). 372 373"sg_sat_chk_power" attempts to push an ATA CHECK POWER MODE command 374through the SAT-defined ATA PASS_THROUGH (16) SCSI command. That 375ATA command needs to read the "FIS" registers after the command is 376completed which involves using the ATA Status Return (sense data) 377descriptor (as defined in SAT). 378 379"sg_sat_smart_rd_data" attempts to push an ATA SMART/READ DATA command 380through the SAT-defined ATA PASS_THROUGH (16) SCSI command. If 381successful, the 256 word (512 byte) response is output. 382 383"sg_tst_excl" and "sg_tst_excl2" use multiple threads to bombard the 384given device with O_EXCL open flags, so only one should succeed at a 385time. While holding O_EXCL control a thread attempts a double increment 386on an integer in the given LBA. If the integer starts even (after the 387first read) then it should remain even if the O_EXCL flag is doing its job. 388The "sg_tst_excl" variant uses the Linux SG_IO v3 interface while the 389"sg_tst_excl2" uses the more generic sg_pt infrastructure. 390 391"sg_tst_excl3" is a variant of "sg_tst_excl2". "sg_tst_excl3" only does 392the double increment from the first thread, each time using O_EXCL on 393open. The remaining threads check the value is even, each time doing 394an open without the O_EXCL flag. 395 396"bsg_queue_tst" sends an INQUIRY command via the Linux SG_IO v4 interface 397which is used by the bsg driver. So it will take device names like 398"/dev/bsg/6:0:0:0". It tests if sending repeated INQUIRYs with 399the BSG_FLAG_Q_AT_HEAD or BSG_FLAG_Q_AT_TAIL flag makes any difference. 400 401"sg_tst_async" is a test harness for the Linux sg driver. It is multi 402threaded, submitting either TEST UNIT READY, READ(16) or WRITE(16) SCSI 403commands asynchronously. Each thread opens a file descriptor and submits 404those commands up to the queue limit (sg driver has a per file descriptor 405queue limit of 16). Multiple threads doing the same thing act as a 406multiplier to that queue limit. 407 408 409NVME Support 410============ 411Firstly the author has no intention of extending this package to contain 412general purpose NVMe utilities. That leaves the areas where SCSI overlaps 413with NVMe. There was a SCSI to NVMe Translation Layer (SNTL) driver in the 414Linux kernel based on a white paper from NVM Express. Intel has withdrawn 415that driver and T10 (SCSI) and NVM Express have made no further attempts 416to standardize a SNTL. Given the SCSI to ATA Translation Layer (SATL) which 417is standardized by T10, it is pretty clear what a SNTL should do. 418 419The NVMe Management Interface (NVME-MI) committee have decided to use SES-3 420standard from T10 via the newly added SES Send and SES Receive MI commands. 421So the sg_ses utility and this package's library have been extended to use 422these commands when a NVMe device (typically a disk enclosure) is detected. 423This has been tested by a disk vendor who is happy with the results. Other 424user reports are welcome as the author does not have equipment to test 425this. 426 427Other utilities in this package that use the SES Send and Receive commands, 428or the SNTL in the library are sg_senddiag, sg_inq, sg_raw and sg_readcap. 429 430 431Command line processing 432======================= 433These utilities can be divided into 3 groups when their handling of command 434line arguments is considered: 435 - ad hoc, typically in a short form only, sometimes longer (e.g. 436 "sg_logs -pcb /dev/sdc") 437 - inspired by the dd Unix command (e.g. sg_dd, sgm_dd, sgp_dd, sg_read) 438 - recent utilities use "getopt_long" (see "man getopt_long") 439 type command lines. These have short form (starting with "-") 440 and corresponding longer form (starting with "--") options. 441 442The older utilities that use ad hoc options, in alphabetical order: 443 - sg_emc_trespass, sginfo(1/2), sg_inq, sg_logs, sg_map, sg_modes, 444 sg_opcodes, sg_rbuf, sg_rdac, sg_readcap, sg_reset, sg_scan (Linux), 445 sg_senddiag, sg_start, sg_test_rwbuf, sg_turs 446In sg3_utils version 1.23 the following utilities from this group were 447converted to have a dual getopt_long/ad_hoc interface, defaulting to 448the getop_long interface: 449 - sg_inq, sg_logs, sg_modes, sg_opcodes, sg_rbuf, sg_readcap, 450 sg_senddiag, sg_start, sg_turs 451These can be switched back to the older (backward compatible) ad hoc 452interface by defining the SG3_UTILS_OLD_OPTS environment variable 453or using '-O' as the first command line option. 454 455The more recent utilities that use "getopt_long" only are: 456 - sg_bt_ctl, sg_compare_and_write, sg_decode_sense, sg_format, 457 sg_get_config, sg_get_lba_status, sg_ident, sg_luns, sg_map26, 458 sg_persist, sg_prevent, sg_raw, sg_read_attr, sg_read_block_limits, 459 sg_read_buffer, sg_read_long, sg_reassign, sg_referrals, sg_rep_pip, 460 sg_rep_zones, sg_requests, sg_rmsn, sg_rtpg, sg_safte, sg_sanitize, 461 sg_sat_identify, sg_sat_phy_event, sg_sat_read_gplog, 462 sg_sat_set_features, sg_scan(w), sg_seek, sg_ses, sg_ses_microcode, 463 sg_stpg, sg_stream_ctl, sg_sync, sg_test_rwbuf, sg_timestamp, sg_unmap, 464 sg_verify, sg_vpd, sg_write_buffer, sg_write_long, sg_write_same, 465 sg_write_verify, sg_write_x, sg_wr_mode, sg_zone, sg_z_act_query 466 467 468Dangerous code 469============== 470This C code snippet: 471 unsigned char uc = 0x80; 472 uint64_t ull; 473 ull = (uc << 24); 474Somewhat surprisingly sets ull to: 475 ull: 0xffffffff80000000 476This result is due to the 'unary conversion' of uc to a (32 bit signed) 477'int' before the shift. The resultant type from the shift is also an int 478and it has its top bit set so there is sign extension when it is assigned 479into a 64 bit unsigned integer. Making sure there is no conversion to 'int' 480solves the problem. In this case if uc is declared as unsigned int the 481result will be as expected (i.e. 0x80000000). 482 483 484Bypassing the somewhat dangerous shift operators 485================================================ 486The shift operators in C are "<<" and ">>". They can be dangerous (as shown 487in the above section) or tedious and hence error prone to use. However they 488are often needed to cope with the translation of integers on the host OS to 489the corresponding representation within a SCSI command or parameter data 490moved to or from a SCSI device. The Logical Block Address (LBA) is a good 491example; it is either 32 or 64 bits long typically (i.e. 4 or 8 bytes 492respectively). The host machine representation may be big or little endian 493and may prefer or require alignment to a particular memory address boundary 494(e.g. module 4 (or in 'C' code: "(lba % 4) == 0")). For SCSI commands and 495the parameter data moved to or from a SCSI device, the integer 496representation is big endian and it is unaligned. 497 498Recent versions of this package have replaced the explicit use of the C 499shift operators with a group of functions modelled on those found in the 500Linux kernel. These functions contain either "get_unaligned" or 501"put_unaligned" in their names and are found in the asm/unaligned.h 502header. This package contains the sg_unaligned.h header that implements 503a similar set of functions. The current implementation favours correctness 504over speed. The functions in the package use a "sg_" prefix but otherwise 505use the same function name as the Linux kernel for the same action. 506 507An example of the change made to a snippet of sg_write_buffer.c may 508clarify this change. The old code was: 509 510 wbufCmdBlk[3] = (unsigned char)((buffer_offset >> 16) & 0xff); 511 wbufCmdBlk[4] = (unsigned char)((buffer_offset >> 8) & 0xff); 512 wbufCmdBlk[5] = (unsigned char)(buffer_offset & 0xff); 513 514and it has been replaced by: 515 516 sg_put_unaligned_be24(buffer_offset, wbufCmdBlk + 3); 517 518The Linux kernel only supplies "unaligned" functions for 16, 32 and 64 519bit quantities. SCSI commands also have cases of 24 and 48 bit numbers 520so sg_unaligned.h contains support for those plus a variant where the 521byte length is passed as an argument. 522 523The unaligned functions are inlined for speed (at the possible expense of 524space) and now have specializations depending whether the host is big or 525(more likely) little endian. These functions can be broken down to a 526memcpy() and optionally a byte-swap for 16, 32 and 64 bit operations. 527The memcpy() takes care of alignment while the byte-swap (bswap_16(), 528bswap_32() and bswap_64() ) addresses integer endianness. If the host is 529little endian and a little endian variant of the unaligned functions is 530requested, then no byte-swap is required. These specializations can be 531"compiled out" with this configure option: './configure 532--disable-fast-lebe' in which case the classic "C shifting" technique is 533used to implement all the unaligned functions. 534 535Associated with the above change, fixed length integer types seem a better 536fit for SCSI command and parameter integers than the traditional integer 537types in the C language. Fixed length integer types were standardized in 538C99 and require the inclusion of <stdint.h>. For example this means for 539an integer that will represent a 64 bit LBA, to favour using "uint64_t" 540over the "unsigned long long" type. Also "unsigned char" has mostly been 541replaced by "uint8_t" as the 8 bit (unsigned) byte type; "char" is still 542used for ASCII text. 543 544 545Coding Style 546============ 547Everyone has their own C/C++ coding style and the author is no different. 548In terms of the GNU indent command: 549 indent -i4 -il0 -nut -br -npcs -ncs -ce 550is pretty close. That is similar to the Linux kernel coding style but 551with 4 space indentations and no tabs. 552 553 554Other SCSI and storage tools 555============================ 556See https://sg.danny.cz/sg/tools.html 557 558 559Douglas Gilbert dgilbert@interlog.com 56026th August 2022 561
README.freebsd
1Introduction 2============ 3The FreeBSD port of sg3_utils contains those utilities that are _not_ 4specific to Linux. In some cases the FreeBSD camcontrol command supplies 5similar functionality; for example 'sg_map' is similar to 6'camcontrol devlist'. 7 8The dd variants from the sg3_utils package (e.g. sg_dd) rely on too many 9Linux idiosyncrasies to be easily ported. A new package called 'ddpt' 10contains a utility with similar functionality to sg_dd and ddpt is available 11for FreeBSD. 12 13Supported Utilities 14=================== 15Here is a list of utilities that have been ported: 16 sg_bg_ctl 17 sg_compare_and_write 18 sg_decode_sense 19 sg_format 20 sg_get_config 21 sg_get_elem_status 22 sg_get_lba_status 23 sg_ident 24 sg_inq [dropped ATA IDENTIFY DEVICE capability] 25 sg_logs 26 sg_luns 27 sg_modes 28 sg_opcodes 29 sg_persist 30 sg_prevent 31 sg_raw 32 sg_rdac 33 sg_read_block_limits 34 sg_read_buffer 35 sg_read_long 36 sg_readcap 37 sg_reassign 38 sg_referrals 39 sg_rep_pip 40 sg_rep_zones 41 sg_requests 42 sg_rmsn 43 sg_rtpg 44 sg_safte 45 sg_sanitize 46 sg_sat_identify 47 sg_sat_phy_event 48 sg_sat_set_features 49 sg_seek 50 sg_senddiag 51 sg_ses 52 sg_start 53 sg_stpg 54 sg_stream_ctl 55 sg_sync 56 sg_turs 57 sg_verify 58 sg_unmap 59 sg_vpd 60 sg_wr_mode 61 sg_write_buffer 62 sg_write_long 63 sg_write_same 64 sg_write_verify 65 sg_write_x 66 sg_zone 67 68Most utility names are indicative of the main SCSI command 69that they execute. Some utilities are slightly higher level, for 70example sg_ses fetches SCSI Enclosure Services (SES) status pages and 71can send control pages. Each utility has a man page (placed in 72section 8). An overview of sg3_utils can be found at: 73https://sg.danny.cz/sg/sg3_utils.html . 74A copy of the "sg3_utils.html" file is in the "doc" subdirectory. 75 76 77The executables and library can be built from the source code in 78the tarball and installed with the familiar 79"./configure ; make ; make install" sequence. If this fails try 80running the "./autogen.sh" script prior to that sequence. There 81are generic instruction on configure and friend in the INSTALL file. 82 83Some man pages have examples which use Linux device names which 84hopefully will not confuse the FreeBSD users. 85 86Device naming 87============= 88In FreeBSD disks have block names like '/dev/da0' with a corresponding 89pass-through device name like '/dev/pass0'. Use this command: 90"camcontrol devlist" to see that SCSI devices available. To list NVMe 91devices: "nvmecontrol devlist" can be used. Any many, but not all 92contexts, the device name can be used without the '/dev/' prefix. 93FreeBSD is relatively unique in this respect and support for this 94abbreviated form has been broken in this package and fixed in 95sg3_utils release 1.46 . 96 97Device naming for NVMe is a bit more complex. Controllers have names 98like /dev/nvme0 and namespaces /dev/nvme0ns1 . Partitions are not 99supported on /dev/nvme0ns1 type nodes. Instead there are /dev/nvd0 100and /dev/nvd0p<m> where <m> is th partition number starting at 1. 101The nvd driver (written by Intel) is not CAM compatible and has its 102own utility nvmecontrol which has similar capabilities as camcontrol 103has for CAM devices. In FreeBSD release 12 the nda driver was 104introduced with names like /dev/nda0 and /dev/nda0n<m>. The difference 105is that nda is CAM compatible. From the point of view of this package, 106the nda driver is preferred as CAM supports NVMe command timeouts and 107the error processing is more mature. 108 109FreeBSD installation 110==================== 111The traditional './configure ; make ; make install' sequence from the 112top level of the unpacked tarball will work on FreeBSD. But the man pages 113will be placed under the /usr/local/share/man directory which unfortunately 114is not on the standard manpath. One solution is to add this path by 115creating a file with a name like local_share.conf in the 116/usr/local/etc/man.d/ directory and placing this line in it: 117 MANPATH /usr/local/share/man 118 119FreeBSD 9.0 has a "ports" entry for sg3_utils under the 120/usr/ports/sysutils directory. It points to version 1.28 of sg3_utils 121which is now a bit dated. It could be used as a template to point 122to more recent versions. 123 124kFreeBSD 125======== 126sg3_utils can be built into a Debian package for kFreeBSD using the 127./build_debian.sh script in the top level directory. This has been tested 128with Debian 6.0 release. 129 130Details 131======= 132Most of the ported utilities listed above use SCSI command functions 133declared in sg_cmds_*.h headers . Those SCSI command functions are 134implemented in the corresponding ".c" files. The ".c" files pass SCSI 135commands to the host operating system via an interface declared in sg_pt.h . 136There are currently five implementations of that interface depending on 137the host operating system: 138 - sg_pt_linux.c 139 - sg_pt_freebsd.c 140 - sg_pt_osf1.c [Tru64] 141 - sg_pt_win32.c 142 - sg_pt_solaris.c 143 144The sg_pt_freebsd.c file uses the FreeBSD CAM SCSI pass through mechanism. 145Hence only FreeBSD device nodes that support CAM can be used. These can be 146viewed with the "camcontrol devlist" command. To access ATAPI devices (e.g. 147ATAPI DVD drives) the kernel may need to be configured with the "atapicam" 148device. 149 150Attempts to send SCSI commands with data-in or data-out buffers around 64 KB 151and larger failed on a FreeBSD 7.0 with an "argument list too long" error 152message. There is an associated kernel message (viewable with dmesg) that an 153attempt has been made to map <n> bytes which is greater than 154DFLTPHYS(65536). Still a problem in FreeBSD 8.1 . Due to CAM overhead the 155largest power of 2 that can fit through with one command is 32768 bytes (32 156KB). 157 158FreeBSD 9.0 is the most recent version of FreeBSD tested with these 159utilities. 160 161 162 163Douglas Gilbert 1641st May 2021 165
README.iscsi
1iSCSI support for sg3-utils is available from external patches. 2 3To build sg3-utils from sources and activate built-in iSCSI support 4you need both sg3-utils and the external user-space iSCSI library hosted at : 5 6https://github.com/sahlberg/libiscsi 7 8This library provides a client library for accessing remote iSCSI 9devices and also comes with patches to the sg3-utils source code 10distribution to compile a special version of sg3-utils with iSCSI 11support. 12 13No support for iSCSI is provided by the sg3-utils maintainer. 14 15 16 17Once sg3-utils is compiler and installed with libiscsi support, you 18can specify remote iSCSI devices through a special URL format instead 19of the normal /dev/* syntax. 20 21Example: 22 23sg_inq iscsi://ronnie%password@10.1.1.27/iqn.ronnie.test/1 24standard INQUIRY: 25 PQual=0 Device_type=0 RMB=0 version=0x05 [SPC-3] 26 [AERC=0] [TrmTsk=1] NormACA=0 HiSUP=0 Resp_data_format=2 27 SCCS=0 ACC=0 TPGS=0 3PC=0 Protect=0 BQue=0 28 EncServ=0 MultiP=0 [MChngr=0] [ACKREQQ=0] Addr16=0 29 [RelAdr=0] WBus16=0 Sync=0 Linked=0 [TranDis=0] CmdQue=1 30 [SPI: Clocking=0x0 QAS=0 IUS=0] 31 length=66 (0x42) Peripheral device type: disk 32 Vendor identification: IET 33 Product identification: VIRTUAL-DISK 34 Product revision level: 0001 35 Unit serial number: beaf11 36 37 38
README.sg_start
1Hi, 2 3you can use sg_start to start (spin-up, 1) and stop (spin-down, 0) devices. 4I also offers a parameter (-s) to send a synchronize cache command to a 5device, so it should write back its internal buffers to the medium. 6 7Be aware that the Linux SCSI subsystem at this time does not automatically 8starts stopped devices, so stopping a device which is in use may have fatal 9results for you. 10 11So, you should apply with care. 12I use it in my shutdown script at the end (before the poweroff command): 13 14# SG_SHUG_NOS is set in my config file rc.config 15# SG_SHUT_NOS="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" 16if test -x /bin/sg_start; then 17 if test "`basename $command`" = "reboot"; then 18 for no in $SG_SHUT_NOS; 19 do /bin/sg_start /dev/sg$no -s >/dev/null 2>&1; 20 done 21 else 22 for no in $SG_SHUT_NOS; 23 do /bin/sg_start /dev/sg$no -s 0 >/dev/null 2>&1; 24 done 25 fi 26fi 27 28Enjoy! 29Kurt Garloff 30 31 32Postscript 33========== 34sg_start has been reworked to allow a block device (e.g. /dev/sda) in 35addition to the sg device name (e.g. /dev/sg0) in the lk 2.6 series. 36sg_start now has more command line options, see its man page. 37 38 Douglas Gilbert <dgilbert at interlog dot com> 2004/5/8 39
README.solaris
1Please Note: 2>>> Up to and including sg3_utils-1.33 the Solaris code was built 3>>> and tested on an OpenSolaris VM run with VirtualBox on Ubuntu 4>>> 11.10 . Now with Ubuntu 12.04 those VMs crash immediately when 5>>> started with VirtualBox. Further, Oracle (who owns SUN and thus 6>>> Solaris) no longer supports OpenSolaris and its package 7>>> repository has been withdrawn. The author can find no generic VMs 8>>> for Oracle Solaris 11 that run on VirtualBox or VMWare. The author 9>>> is also displeased with the withdrawal of the Open Software 10>>> OS and is disinclined to build a Solaris 11 system just to 11>>> virtualize it. 12>>> So as of sg3_utils-1.34 the Solaris port is provided "as-is" without 13>>> testing on a Solaris platform. 14 15Douglas Gilbert 1613th October 2012 17 18 19 20Introduction 21============ 22The Solaris port of sg3_utils contains those utilities that are 23_not_ specific to Linux. 24 25The dd variants from the sg3_utils package (e.g. sg_dd) rely on too many 26Linux idiosyncrasies to be easily ported. A new package called 'ddpt' 27contains a utility with similar functionality to sg_dd and is available 28for Solaris. 29 30Supported Utilities 31=================== 32Here is a list of utilities that have been ported: 33 sg_bg_ctl 34 sg_compare_and_write 35 sg_decode_sense 36 sg_format 37 sg_get_config 38 sg_get_elem_status 39 sg_get_lba_status 40 sg_ident 41 sg_inq [dropped ATA IDENTIFY DEVICE capability] 42 sg_logs 43 sg_luns 44 sg_modes 45 sg_persist 46 sg_opcodes 47 sg_prevent 48 sg_raw 49 sg_rdac 50 sg_read_block_limts 51 sg_read_buffer 52 sg_read_long 53 sg_readcap 54 sg_reassign 55 sg_referrals 56 sg_rep_pip 57 sg_rep_zones 58 sg_requests 59 sg_rmsn 60 sg_rtpg 61 sg_safte 62 sg_sanitize 63 sg_sat_identify 64 sg_sat_phy_event 65 sg_sat_set_features 66 sg_seek 67 sg_senddiag 68 sg_ses 69 sg_start 70 sg_stpg 71 sg_stream_ctl 72 sg_sync 73 sg_turs 74 sg_unmap 75 sg_verify 76 sg_vpd 77 sg_wr_mode 78 sg_write_buffer 79 sg_write_long 80 sg_write_same 81 sg_write_verify 82 sg_write_x 83 sg_zone 84 85Most utility names are indicative of the main SCSI command 86that they execute. Some utilities are slightly higher level, for 87example sg_ses fetches SCSI Enclosure Services (SES) status pages and 88can send control pages. Each utility has a man page (placed in 89section 8). An overview of sg3_utils can be found at: 90https://sg.danny.cz/sg/sg3_utils.html . 91A copy of the "sg3_utils.html" file is in the "doc" subdirectory. 92 93 94The executables and library can be built from the source code in 95the tarball and installed with the familiar 96"./configure ; make ; make install" sequence. If this fails try 97running the "./autogen.sh" script prior to that sequence. There 98are generic instruction on configure and friend in the INSTALL file. 99 100Some man pages have examples which use Linux device names which 101hopefully will not confuse the Solaris users. 102 103Device naming 104============= 105In Solaris, SCSI device names below the '/dev' directory have a 106form like: c5t4d3s2 where the number following "c" is the controller 107(HBA) number, the number following "t" is the target number (from 108the SCSI parallel interface days) and the number following "d" is 109the LUN. Following the "s" is the slice number which is related to 110a partition and by convention "s2" is the whole disk. 111 112OpenSolaris also has a c5t4d3p2 form where the number following 113the "p" is the partition number apart from "p0" which is the whole 114disk. So a whole disk may be referred to as either: 115 - c5t4d3 116 - c5t4d3s2 117 - c5t4d3p0 118 119And these device names are duplicated in the /dev/dsk and /dev/rdsk 120directories. The former is the block device name and the latter 121is for "raw" (or char device) access which is what sg3_utils needs. 122So in OpenSolaris something of the form: 123 sg_inq /dev/rdsk/c5t4d3p0 124should work. If it doesn't add a '-vvv' option. If that is attempted 125on the /dev/dsk/c5t4d3p0 variant an inappropriate ioctl for device 126error will result. 127 128The device names within the /dev directory are typically symbolic 129links to much longer topological names in the /device directory. 130 131In Solaris cd/dvd/bd players seem to be treated as disks and so are 132found in the /dev/rdsk directory. Tape drives appear in the /dev/rmt 133directory. 134 135There is also a sgen (SCSI generic) driver which by default does not 136attach to any device. See the /kernel/drv/sgen.conf file to control 137what is attached. Any attached device will have a device name of 138the form /dev/scsi/c5t4d3 . 139 140Listing available SCSI devices in Solaris seems to be a challenge. 141"Use the 'format' command" advice works but seems a very dangerous 142way to list devices. [It does prompt again before doing any damage.] 143'devfsadm -Cv' cleans out the clutter in the /dev/rdsk directory, 144only leaving what is "live". The "cfgadm -v" command looks promising. 145 146Details 147======= 148The ported utilities listed above, all use SCSI command functions 149declared in sg_cmds_basic.h and sg_cmds_extra.h . Those SCSI command 150functions are implemented in the corresponding ".c" files. The ".c" 151files pass SCSI commands to the host operating system via an interface 152declared in sg_pt.h . There are currently five implementations of that 153interface depending on the host operating system: 154 - sg_pt_linux.c 155 - sg_pt_freebsd.c 156 - sg_pt_osf1.c [Tru64] 157 - sg_pt_solaris.c 158 - sg_pt_win32.c 159 160The sg_pt_solaris.c file uses the "uscsi" SCSI pass through mechanism. There 161seems to be no corresponding ATA pass through and recent SATA disks do not 162seem to have a SAT layer in front of them (within Solaris). If SAT is 163present (perhaps externally or within a HBA) then that would allow SATA 164disks to accept SCSI commands including the SCSI ATA PASS THROUGH commands. 165 166 167Douglas Gilbert 1685th June 2020 169
README.tru64
1Introduction 2============ 3The Tru64 port of sg3_utils contains those utilities that are _not_ 4specific to Linux. In some cases a utility could be ported but 5requires more work. An example is sg_dd which needs more work 6beyond the SCSI command pass through mechanism. 7 8Supported Utilities 9=================== 10Here is a list of utilities that have been ported: 11 sg_compare_and_write 12 sg_decode_sense 13 sg_format 14 sg_get_config 15 sg_get_lba_status 16 sg_ident 17 sg_inq [dropped ATA IDENTIFY DEVICE capability] 18 sg_logs 19 sg_luns 20 sg_modes 21 sg_opcodes 22 sg_persist 23 sg_prevent 24 sg_raw 25 sg_rdac 26 sg_read_block_limits 27 sg_read_buffer 28 sg_read_long 29 sg_readcap 30 sg_reassign 31 sg_referrals 32 sg_requests 33 sg_rmsn 34 sg_rtpg 35 sg_safte 36 sg_sanitize 37 sg_sat_identify 38 sg_sat_phy_event 39 sg_sat_set_features 40 sg_senddiag 41 sg_ses 42 sg_start 43 sg_stpg 44 sg_sync 45 sg_turs 46 sg_unmap 47 sg_verify 48 sg_vpd 49 sg_wr_mode 50 sg_write_buffer 51 sg_write_long 52 sg_write_same 53 54Most utility names are indicative of the main SCSI command 55that they execute. Some utilities are slightly higher level, for 56example sg_ses fetches SCSI Enclosure Services (SES) status pages and 57can send control pages. Each utility has a man page (placed in 58section 8). An overview of sg3_utils can be found at: 59https://sg.danny.cz/sg/sg3_utils.html . 60A copy of the "sg3_utils.html" file is in the "doc" subdirectory. 61 62This package uses autotools infrastructure with the now common 63"./configure ; make ; make install" sequence needed to build and install 64from the source found in the tarball. If the "./configure" sequence 65fails try using the ./autogen.sh prior to that sequence. 66 67Some man pages have examples which use Linux device names which hopefully 68will not confuse Tru64 users. 69 70 71Details 72======= 73Most of the ported utilities listed above use SCSI command functions 74declared in sg_cmds_*.h headers . Those SCSI command functions are 75implemented in the corresponding ".c" files. The ".c" files pass SCSI 76commands to the host operating system via an interface declared in sg_pt.h . 77There are currently five implementations of that interface depending on 78the host operating system: 79system: 80 - sg_pt_linux.c 81 - sg_pt_osf1.c [Tru64] 82 - sg_pt_freebsd.c 83 - sg_pt_solaris.c 84 - sg_pt_win32.c 85 86The sg_pt_osf1.c file uses the Tru64 CAM SCSI pass through mechanism. 87 88Tru64 does not have general library support for "long" options 89(e.g. "--verbose") which are used extensively by most of the 90utilities in this package. Rather than change all the utilities 91and their man/web pages a local implementation of the missing 92function "getopt_long()" has been placed in the "getopt_long" 93subdirectory. Currently only the Tru64 port uses it. 94 95 96Douglas Gilbert 9714th January 2013 98
README.win32
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