1SG_UNMAP(8) SG3_UTILS SG_UNMAP(8)
2
3
4
6 sg_unmap - send SCSI UNMAP command (known as 'trim' in ATA specs)
7
9 sg_unmap [--anchor] [--grpnum=GN] [--help] [--in=FILE]
10 [--lba=LBA,LBA...] [--num=NUM,NUM...] [--timeout=TO] [--verbose]
11 [--version] DEVICE
12
14 Send a SCSI UNMAP command to DEVICE to unmap one or more logical
15 blocks. This command was introduced in SBC-3 revision 18 under the
16 broad heading of "logical block provisioning". Logical blocks may also
17 be unmapped by the SCSI WRITE SAME command; see the sg_write_same util‐
18 ity. The unmap capability is closely related to the ATA DATA SET MAN‐
19 AGEMENT command with the "Trim" bit set.
20
21 Logical blocks to be unmapped can be specified in one of two ways to
22 this utility. One way is by supplying the start LBAs to the '--lba='
23 option and the corresponding number(s) to unmap to the '--num=' option.
24 The other way is by putting start LBA and number to unmap pairs in a
25 file whose name is given to the '--in=' option. All values are assumed
26 to be decimal unless prefixed by "0x" (or "0X") or have a trailing "h"
27 (or "H") in which case they are interpreted as hexadecimal. Suffix mul‐
28 tipliers are permitted on decimal values (e.g. '--num=1m').
29
30 When the '--lba=' option is given then the '--num=' option must also be
31 given. If one has a comma separated list as its argument then the other
32 must have the same number of elements in its list. The arguments can
33 use a single space as a separator but need to be in quotes or escaped
34 to not be misinterpreted by the shell.
35
36 With the '--in=FILE' option an even number of values must be found and
37 are interpreted as pairs: the first value in each pair is a starting
38 LBA and the second value is the number to unmap from that LBA. Every‐
39 thing from and including a "#" on a line is ignored as are blank lines.
40 Values may be comma, space and tab separated or appear on separate
41 lines. Each line should not exceed 1023 bytes in length.
42
44 Arguments to long options are mandatory for short options as well.
45
46 -a, --anchor
47 sets the 'Anchor' bit in the command (introduced in sbc3r22).
48
49 -g, --grpnum=GN
50 sets the 'Group number' field to GN. Defaults to a value of
51 zero. GN should be a value between 0 and 31.
52
53 -h, --help
54 output the usage message then exit.
55
56 -I, --in=FILE
57 where FILE is a file name containing pairs of values. The first
58 member of each pair is a starting LBA and the second member of
59 the pair is the number of logical blocks to unmap from and
60 including that starting LBA. Values are interpreted as decimal
61 unless indicated otherwise. This option cannot be present with
62 the '--lba=' option.
63
64 -l, --lba=LBA,LBA...
65 where LBA,LBA... is a string of comma (or space) separated val‐
66 ues that are interpreted as starting logical block addresses.
67 Each number is interpreted as decimal unless prefixed by '0x' or
68 '0X' (or it has a trailing 'h' or 'H'). An argument that con‐
69 tains any space separators needs to be quoted (or otherwise
70 escaped). When this option is given then the '--num=' option
71 must also be given and they must contain the same number of ele‐
72 ments in their arguments.
73
74 -n, --num=NUM,NUM...
75 where NUM,NUM... is a string of comma (or space) separated val‐
76 ues that are interpreted as a number of logical blocks to unmap.
77 Each number is interpreted as decimal unless prefixed by '0x' or
78 '0X' (or it has a trailing 'h' or 'H'). Note that 0 blocks is
79 acceptable. An argument that contains any space separators needs
80 to be quoted (or otherwise escaped). When this option is given
81 then the '--lba=' option must also be given and they must con‐
82 tain the same number of elements in their arguments.
83
84 -t, --timeout=TO
85 where TO is a timeout value (in seconds) for the UNMAP command.
86 The default value is 60 seconds.
87
88 -v, --verbose
89 increase the level of verbosity, (i.e. debug output).
90
91 -V, --version
92 print the version string and then exit.
93
95 Some limits: an LBA can be up to 64 bits, a NUM up to 32 bits (imposed
96 by structure of UNMAP SCSI command parameter data). The NUM is further
97 constrained by the MAXIMUM UNMAP LBA COUNT field in the BLOCK LIMITS
98 VPD page (0xb0). The maximum number of LBA,NUM pairs is limited to 128
99 by this utility and may be further constrained by the MAXIMUM UNMAP
100 BLOCK DESCRIPTOR COUNT field in the BLOCK LIMITS VPD page.
101
102 Since it is unclear how long the UNMAP command will take to execute a
103 '--timeout=" option has been provided. The default timeout period is 60
104 seconds. If all the logical blocks on a logical unit (e.g. a disk
105 drive) are to be unmapped then the FORMAT UNIT SCSI command (see the
106 sg_format utility) may be considered as an alternative.
107
108 Support for logical block provisioning is indicated by the LBPME bit in
109 the response to the SCSI READ CAPACITY (16) command (see the sg_readcap
110 utility).
111
112 In SBC-3 revision 25 the LBPU and ANC_SUP bits where added to the Logi‐
113 cal Block Provisioning VPD page. When LBPU is set it indicates that the
114 device supports the UNMAP command. When the ANC_SUP bit is set it indi‐
115 cates the device supports anchored LBAs.
116
117 The SCSI UNMAP command does the "right thing" with respect to command
118 queueing. However its ATA counterpart: the DATA SET MANAGEMENT command
119 with the "Trim" bit set does not interact well with SATA queueing known
120 as NCQ. To address this problem T13 have introduced a new command
121 called SFQ DATA SET MANAGEMENT which also has a Trim bit.
122
124 In the examples directory of the sg3_utils package there is a
125 sg_unmap_example.txt file that shows the format that the '--in=' option
126 accepts.
127
129 The exit status of sg_unmap is 0 when it is successful. Otherwise see
130 the sg3_utils(8) man page.
131
133 Written by Douglas Gilbert.
134
136 Report bugs to <dgilbert at interlog dot com>.
137
139 Copyright © 2009-2014 Douglas Gilbert
140 This software is distributed under a FreeBSD license. There is NO war‐
141 ranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
142 POSE.
143
145 sg_format,sg_get_lba_status,sg_readcap,sg_vpd,sg_write_same(sg3_utils)
146
147
148
149sg3_utils-1.39 April 2014 SG_UNMAP(8)