aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--doc/sg_unmap.846
-rw-r--r--doc/sg_write_same.878
-rw-r--r--src/sg_format.c8
4 files changed, 102 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index 59d63d0a..10b13e5f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,7 @@ Each utility has its own version number, date of last change and
some description at the top of its ".c" file. All utilities in the main
directory have their own "man" pages. There is also a sg3_utils man page.
-Changelog for sg3_utils-1.33 [20111117] [svn: r427]
+Changelog for sg3_utils-1.33 [20111125] [svn: r428]
- win: change DataBufferOffset type per MSDN; caused
problem with 64 bit machines (buffered interface)
- sg_inq, sg_vpd: sync with spc4r33
diff --git a/doc/sg_unmap.8 b/doc/sg_unmap.8
index f729b151..2eebe287 100644
--- a/doc/sg_unmap.8
+++ b/doc/sg_unmap.8
@@ -1,4 +1,4 @@
-.TH SG_UNMAP "8" "October 2010" "sg3_utils\-1.30" SG3_UTILS
+.TH SG_UNMAP "8" "November 2011" "sg3_utils\-1.33" SG3_UTILS
.SH NAME
sg_unmap \- sends a SCSI UNMAP command
.SH SYNOPSIS
@@ -11,31 +11,30 @@ sg_unmap \- sends a SCSI UNMAP command
.PP
Send a SCSI UNMAP command to \fIDEVICE\fR to unmap one or more logical
blocks. This command was introduced in SBC\-3 revision 18 under the broad
-heading of "logical block provisioning".
-Logical blocks may also be unmapped by the SCSI WRITE SAME command; see
-sg_write_same. The unmap capability is closely related to the ATA DATA SET
-MANAGEMENT command with the "Trim" bit set.
+heading of "logical block provisioning". Logical blocks may also be unmapped
+by the SCSI WRITE SAME command; see the sg_write_same utility. The unmap
+capability is closely related to the ATA DATA SET MANAGEMENT command with
+the "Trim" bit set.
.PP
Logical blocks to be unmapped can be specified in one of two ways to this
-utility. One way is by supplying the (start) LBAs to the '\-\-lba=' option
+utility. One way is by supplying the start LBAs to the '\-\-lba=' option
and the corresponding number(s) to unmap to the '\-\-num=' option. The
-other way is by putting (start) LBA and number pairs in a file whose name
-is given to the '\-\-in=' option. All values are assumed to be decimal
+other way is by putting start LBA and number to unmap pairs in a file whose
+name is given to the '\-\-in=' option. All values are assumed to be decimal
unless prefixed by "0x" (or "0X") or have a trailing "h" (or "H") in which
case they are interpreted as hexadecimal.
.PP
-When the '\-\-lba=' option is given then the '\-\-num=' option must
-also be given. If one has a comma separated list as its argument then
-the other must have the same number of elements in its list. The
-arguments can use a single space as a separator but need to be in quotes
-or escaped to not be misinterpreted by the shell.
+When the '\-\-lba=' option is given then the '\-\-num=' option must also be
+given. If one has a comma separated list as its argument then the other must
+have the same number of elements in its list. The arguments can use a single
+space as a separator but need to be in quotes or escaped to not be
+misinterpreted by the shell.
.PP
-With the '\-\-in=FILE' option an even number of values must be found
-and are interpreted as pairs: the first value in each pair is a
-starting LBA and the second value is the number to unmap from that
-LBA. Everything from and including a "#" on a line is ignored as
-are blank lines. Values may be comma, space and tab separated or appear
-on separate lines.
+With the '\-\-in=FILE' option an even number of values must be found and are
+interpreted as pairs: the first value in each pair is a starting LBA and the
+second value is the number to unmap from that LBA. Everything from and
+including a "#" on a line is ignored as are blank lines. Values may be
+comma, space and tab separated or appear on separate lines.
.SH OPTIONS
Arguments to long options are mandatory for short options as well.
.TP
@@ -101,6 +100,11 @@ the sg_format utility) may be considered as an alternative.
Support for logical block provisioning is indicated by the LBPME bit in the
response to the SCSI READ CAPACITY (16) command (see the sg_readcap utility).
.PP
+In SBC\-3 revision 25 the LBPU and ANC_SUP bits where added to the
+Logical Block Provisioning VPD page. When LBPU is set it indicates that
+the device supports the UNMAP command. When the ANC_SUP bit is set it
+indicates the device supports anchored LBAs.
+.SH EXAMPLES
In the examples directory of the sg3_utils package there is a
sg_unmap_example.txt file that shows the format that the '\-\-in='
option accepts.
@@ -112,9 +116,9 @@ Written by Douglas Gilbert.
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 2009\-2010 Douglas Gilbert
+Copyright \(co 2009\-2011 Douglas Gilbert
.br
This software is distributed under a FreeBSD license. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.SH "SEE ALSO"
-.B sg_format,sg_get_lba_status,sg_readcap,sg_write_same(sg3_utils)
+.B sg_format,sg_get_lba_status,sg_readcap,sg_vpd,sg_write_same(sg3_utils)
diff --git a/doc/sg_write_same.8 b/doc/sg_write_same.8
index 5c043fa7..16279a2b 100644
--- a/doc/sg_write_same.8
+++ b/doc/sg_write_same.8
@@ -20,9 +20,9 @@ the \fILEN\fR argument, or the length of the given input file \fIIF\fR,
or by calling READ CAPACITY(16) on \fIDEVICE\fR. The contents of the
block to be written are obtained from the input file \fIIF\fR or
zeroes are used. If READ CAPACITY(16) is called (which implies \fIIF\fR
-was not given) and the PROT_EN bit is set then the last 8 bytes are
-set to 0xff. If READ CAPACITY(16) fails then READ CAPACITY(10) is
-used to determine the block size.
+was not given) and the PROT_EN bit is set then an extra 8 bytes (i.e.
+more than the logical block size) of 0xff are sent. If READ CAPACITY(16)
+fails then READ CAPACITY(10) is used to determine the block size.
.PP
If neither \fI\-\-10\fR, \fI\-\-16\fR nor \fI\-\-32\fR is given then
WRITE SAME(10) is sent unless one of the following conditions is met.
@@ -46,7 +46,7 @@ time, potentially as long as a FORMAT UNIT command. In such situations
the command timeout value \fITO\fR may need to be increased from its
default value of 60 seconds. In SBC\-3 revision 26 the WSNZ (write same
no zero) bit was added to the Block Limits VPD page [0xB0]. If set the
-WRITE SAME commands will not accepts a \fINUM\fR of zero. The same
+WRITE SAME commands will not accept a \fINUM\fR of zero. The same
SBC\-3 revision added the "Maximum Write Same Length" field to the Block
Limits VPD page.
.PP
@@ -165,7 +165,13 @@ fields in the Block Limits VPD page should both be greater than zero. The
READ CAPACITY(16) command response also contains a LBPRZ bit which if set
means that if unmapped blocks are read then zeroes will be returned for the
data (and if protection information is active, 0xff bytes are returned for
-that).
+that). In SBC\-3 revision 27 the same LBPRZ bit was added to the Logical
+Block Provisioning VPD page.
+.PP
+In SBC\-3 revision 25 the LBPU and ANC_SUP bits where added to the
+Logical Block Provisioning VPD page. When LBPU is set it indicates that
+the device supports the UNMAP command (see the sg_unmap utility). When the
+ANC_SUP bit is set it indicates the device supports anchored LBAs.
.PP
When the UNMAP bit is set in the cdb then the data out buffer is also sent.
Additionally the data section of that data out buffer should be full of 0x0
@@ -209,6 +215,66 @@ Note that if the LBPRZ bit in the READ CAPACITY(16) response is set (i.e.
LPPRZ is an acronym for logical block provisioning read zeroes) then these
two examples do the same thing, at least seen from the point of view of
subsequent reads.
+.PP
+This utility can also be used to write protection information (PI) on disks
+formatted with a protection type greater than zero. PI is 8 bytes of extra
+data appended to the user data of a logical block: the first two bytes are a
+CRC (the "guard"), the next two bytes are the "application tag" and the last
+four bytes are the "reference tag". With protection types 1 and 2 if the
+application tag is 0xffff then the guard should not be checked (against the
+user data).
+.PP
+In this example we assume the logical block size (of the user data) is 512
+bytes and the disk has been formatted with protection type 1. Since we are
+going to modify LBA 2468 then we take a copy of it first:
+.PP
+ dd if=/dev/sdb skip=2468 bs=512 of=2468.bin count=1
+.PP
+The following command line sets the user data to zeroes and the PI to 8
+0xFF bytes on LBA 2468:
+.PP
+ sg_write_same --lba=2468 /dev/sdb
+.PP
+Reading back that block should be successful because the application tag
+is 0xffff which suppresses the guard (CRC) check (which would otherwise be
+wrong):
+.PP
+ dd if=/dev/sdb skip=2468 bs=512 of=/dev/null count=1
+.PP
+Now an attempt is made to create a binary file with zeroes in the user data,
+0x0000 in the appliction tag and 0xff bytes in the other two PI fields. It
+is awkward to create 0xff bytes in a file (in Unix) as the "tr" command
+below shows:
+.PP
+ dd if=/dev/zero bs=1 count=512 of=ud.bin
+.br
+ tr "\\000" "\\377" < /dev/zero | dd bs=1 of=ff_s.bin count=8
+.br
+ cat ud.bin ff_s.bin > lb.bin
+.br
+ dd if=/dev/zero bs=1 count=2 seek=514 conv=notrunc of=lb.bin
+.PP
+The resulting file can be viewed with 'hexdump -C lb.bin' and should
+contain 520 bytes. Now that file can be written to LBA 2468 as follows:
+.PP
+ sg_write_same --lba=2468 wrprotect=3 --in=lb.bin /dev/sdb
+.PP
+Note the \fI\-\-wrprotect=3\fR rather than being set to 1, since we want
+the WRITE SAME command to succeed even though the PI data now indicates
+the user data is corrupted. When an attempt is made to read the LBA, an
+erro should occur:
+.PP
+ dd if=/dev/sdb skip=2468 bs=512 of=/dev/null count=1
+.PP
+dd errors are not very expressive, if dmesg is checked there should be
+a line something like this: "[sdb] Add. Sense: Logical block guard check
+failed". The block can be corrected by doing a "sg_write_same --lba=1234
+/dev/sdb" again or restoring the original contents of that LBA:
+.PP
+ dd if=2468.bin bs=512 seek=2468 of=/dev/sdb conv=notrunc count=1
+.PP
+Hopefully the dd command would never try to truncate the output file when
+it is a block device.
.SH AUTHORS
Written by Douglas Gilbert.
.SH "REPORTING BUGS"
@@ -219,4 +285,4 @@ Copyright \(co 2009\-2011 Douglas Gilbert
This software is distributed under a FreeBSD license. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.SH "SEE ALSO"
-.B sg_format,sg_get_lba_status,sg_readcap,sg_unmap(sg3_utils)
+.B sg_format,sg_get_lba_status,sg_readcap,sg_vpd,sg_unmap(sg3_utils)
diff --git a/src/sg_format.c b/src/sg_format.c
index 791cc276..c26d1cac 100644
--- a/src/sg_format.c
+++ b/src/sg_format.c
@@ -139,12 +139,12 @@ usage()
" --pie=PIE|-q PIE Protection Information Exponent "
"(default: 0)\n"
" --pinfo|-p set upper bit of FMTPINFO field\n"
- " (deprecated use '--fmtpinfo=FPI' "
+ " (deprecated, use '--fmtpinfo=FPI' "
"instead)\n"
" --poll=PT|-x PT PT is poll type, 0 for test unit "
"ready\n"
- " 1 for request sense (def: 0 (will "
- "be 1))\n");
+ " 1 for request sense (def: 0 (in "
+ "future will be 1))\n");
printf(" --resize|-r resize (rather than format) to COUNT "
"value\n"
" --rto_req|-R set lower bit of FMTPINFO field\n"
@@ -166,7 +166,7 @@ usage()
" (default: set IMMED=1 and poll with "
"Test Unit Ready)\n\n"
"\tExample: sg_format --format /dev/sdc\n\n"
- "This utility formats or resizes SCSI disks.\n");
+ "This utility formats or resizes a SCSI disk.\n");
printf("WARNING: This utility will destroy all the data on "
"DEVICE when\n\t '--format' is given. Check that you "
"have the correct DEVICE.\n");