1*44704f69SBart Van Assche README for sg3_utils 2*44704f69SBart Van Assche ==================== 3*44704f69SBart Van AsscheIntroduction 4*44704f69SBart Van Assche------------ 5*44704f69SBart Van Asschesg3_utils is a package of utilities originally written to send individual 6*44704f69SBart Van AsscheSCSI commands to storage devices that used one of the SCSI command sets. 7*44704f69SBart Van AsscheThese utilities can be divided into three groups: 8*44704f69SBart Van Assche - sg_raw: the user supplies the cdb (command descriptor block) and 9*44704f69SBart Van Assche optionally the size of the data-in and data-out buffers 10*44704f69SBart Van Assche - one command utilities: the majority of the utilities in this package 11*44704f69SBart Van Assche send one SCSI command. Their names start with "sg_" while the 12*44704f69SBart Van Assche remaining part of their name alludes to the command which is sent. For 13*44704f69SBart Van Assche example, "sg_inq" sends the SCSI INQUIRY command. Some utilities in 14*44704f69SBart Van Assche this group send one of a selection of commands, typically those 15*44704f69SBart Van Assche commands have a lot it common (e.g. sg_write_x). 16*44704f69SBart Van Assche - copy type utilities: sg_dd, sgp_dd and sgm_dd use the Unix dd command 17*44704f69SBart Van Assche as a template. sg_xcopy sends the SCSI EXTENDED COPY command which in 18*44704f69SBart Van Assche some cases can do offloaded copies. As well as copying some of these 19*44704f69SBart Van Assche utilities can compare if two data segments held on disks are the same. 20*44704f69SBart Van Assche 21*44704f69SBart Van AsschePlatforms 22*44704f69SBart Van Assche--------- 23*44704f69SBart Van AsscheThese utilities were written on Linux and should work from Linux kernel 24*44704f69SBart Van Assche(lk) 2.4 through to the current series 5. The third group ("copy type") 25*44704f69SBart Van Asscheare only implemented on Linux, but a separate portable package/utility 26*44704f69SBart Van Asschecalled ddpt implements similar functionality. The first two groups are 27*44704f69SBart Van Asscheimplemented (i.e. ported) to Android, FreeBSD, Solaris and Windows. The 28*44704f69SBart Van AsscheWindows port uses either a Cygwin or MinGW (plus Msys) build environment 29*44704f69SBart Van Assche(rather than Visual Studio). 30*44704f69SBart Van Assche 31*44704f69SBart Van AsscheLibrary 32*44704f69SBart Van Assche------- 33*44704f69SBart Van AsscheMany of these utilities share a lot of code (e.g. SCSI error messages) 34*44704f69SBart Van Asscheso a lot of repetition (potentially error prone) is saved by having a 35*44704f69SBart Van Asschelibrary called libsgutils or some variation on that name. Distributions 36*44704f69SBart Van Assche(especially of Linux) have differing policies on how a library (and a 37*44704f69SBart Van Asschepackage) should be named. For that reason this package is sometimes 38*44704f69SBart Van Asscheknown as "sg3-utils" (i.e. the underscore is turned into a hyphen). 39*44704f69SBart Van AsscheVarious other packages use libsgutils. The library interface is not 40*44704f69SBart Van Asschealtered from one package release, to the next, but the library interface 41*44704f69SBart Van Asschemay be expanded. If a utility from one release is used with a libsgutils 42*44704f69SBart Van Asschefrom an earlier release, then the runtime linking may fail. Typically 43*44704f69SBart Van Asschepackage managers take care of these details so that runtime linking 44*44704f69SBart Van Asscheerrors should be rare. 45*44704f69SBart Van Assche 46*44704f69SBart Van AsscheCommand Sets 47*44704f69SBart Van Assche------------ 48*44704f69SBart Van AsscheSCSI command sets are not the only storage command sets in wide use, there 49*44704f69SBart Van Asscheare also ATA and NVMe command sets. There is a SCSI command set to 50*44704f69SBart Van Asschetranslate SCSI commands to ATA commands (called SAT: SCSI to ATA 51*44704f69SBart Van AsscheTranslation). SAT includes an ATA PASS-THROUGH SCSI command and sg_sat_* 52*44704f69SBart Van Asscheutilities (there are four) are examples of using SAT. The SAS transport 53*44704f69SBart Van Assche(Serial Attached SCSI) can convey ATA commands through a SCSI/SAS domain 54*44704f69SBart Van Asschevia its Serial ATA Tunnelled Protocol (STP). 55*44704f69SBart Van Assche 56*44704f69SBart Van AsscheNVMe command sets (e.g. Admin, NVM and MI) are relatively new. There was an 57*44704f69SBart Van Asscheearly paper on a SCSI to NVMe Translation Layer (SNTL) but it hasn't been 58*44704f69SBart Van Asschestandardized. The sg_inq utility will send (and decode the response of) a 59*44704f69SBart Van AsscheSCSI INQUIRY command if the underlying device is a SCSI device. If the 60*44704f69SBart Van Asscheunderlying device is a NVMe controller or namespace, then sg_inq will send 61*44704f69SBart Van Asschea NVMe Admin Identify command and decode the response. The sg_ses utility 62*44704f69SBart Van Assche(for SCSI Enclosure Services) also checks whether its underlying device is 63*44704f69SBart Van AsscheSCSI or NVME. In the NVMe case, sg_ses translates the SCSI SEND DIAGNOSTIC 64*44704f69SBart Van Asscheand READ DIAGNOSTIC RESULTS commands to the NVMe Management Interface (MI) 65*44704f69SBart Van AsscheSES Send and SES Receive commands respectively. The output of the sg_ses 66*44704f69SBart Van Asscheutility should be similar, irrespective of whether the "SES" device is 67*44704f69SBart Van AsscheSCSI or NVMe. 68*44704f69SBart Van Assche 69*44704f69SBart Van AsscheThe sg_raw utility may send NVMe Admin or NVM commands (as well as SCSI 70*44704f69SBart Van Asschecommands). One difficulty with a command-line utility invoking NVME 71*44704f69SBart Van Asschecommands is that those commands contain memory addresses for data-in (from 72*44704f69SBart Van Asschethe storage device) or data-out (toward the storage device) transfers. See 73*44704f69SBart Van Asschethe sg_raw manpage for how this difficulty is addressed. 74*44704f69SBart Van Assche 75*44704f69SBart Van AsscheDocumentation 76*44704f69SBart Van Assche------------- 77*44704f69SBart Van AsscheManual pages ("manpages") are the primary method of utility documentation. 78*44704f69SBart Van AsscheAll utilities and scripts that are installed by this package have a 79*44704f69SBart Van Asschemanpage. There are utilities in the examples, testing and utils 80*44704f69SBart Van Asschedirectories that are not installed and do not have manpages. Nearly 81*44704f69SBart Van Asscheall utilities have runtime help, usually invoked with either the '-h' 82*44704f69SBart Van Asscheshort option or the '--help' long option. There is also an overarching 83*44704f69SBart Van Asschemanpage called "sg3_utils". All manpages are placed in chapter 8 which 84*44704f69SBart Van Asscheis for system administration commands/utilities. 85*44704f69SBart Van Assche 86*44704f69SBart Van AsscheThe sg3_utils package and some more complex utilities have html pages: 87*44704f69SBart Van Assche sg3_utils: https://sg.danny.cz/sg/sg3_utils.html 88*44704f69SBart Van Assche sg_ses: https://sg.danny.cz/sg/sg_ses.html 89*44704f69SBart Van Assche sg_dd: https://sg.danny.cz/sg/sg_dd.html 90*44704f69SBart Van Assche 91*44704f69SBart Van AsscheA tarball (and zip) of all the manpages from the previous release are 92*44704f69SBart Van Asschehere: 93*44704f69SBart Van Assche https://sg.danny.cz/sg/p/sg3_utils_man_html.tgz 94*44704f69SBart Van Assche https://sg.danny.cz/sg/p/sg3_utils_man_html.zip 95*44704f69SBart Van Assche 96*44704f69SBart Van AsscheThere is a html rendering of the sg3_utils manpage in the same directory 97*44704f69SBart Van Asscheas this README file called sg3_utils.man8.html . 98*44704f69SBart Van Assche 99*44704f69SBart Van AsscheThe previous README file is now called README.details plus there are 100*44704f69SBart Van Asschethese OS specific files: README.freebsd , README.solaris , README.tru64 101*44704f69SBart Van Asscheand README.win32 . To know the current state of the package the ChangeLog 102*44704f69SBart Van Asschefile is the good reference. 103*44704f69SBart Van Assche 104*44704f69SBart Van AsscheThe author's primary source code repository uses subversion and is on 105*44704f69SBart Van Asschethe author's equipment (a RPi). One advantage of subversion is its 106*44704f69SBart Van Asscherevision numbers which are simply integers starting at 1 and ascending. 107*44704f69SBart Van AsscheFor this package the current revision is 928 . The subversion repository 108*44704f69SBart Van Asscheis mirrored in git (using "git svn" tools) here: 109*44704f69SBart Van Assche https://github.com/doug-gilbert/sg3_utils 110*44704f69SBart Van Assche 111*44704f69SBart Van Assche 112*44704f69SBart Van AsscheDouglas Gilbert 113*44704f69SBart Van Assche31st December 2021 114