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.
28
29 When the '--lba=' option is given then the '--num=' option must also be
30 given. If one has a comma separated list as its argument then the other
31 must have the same number of elements in its list. The arguments can
32 use a single space as a separator but need to be in quotes or escaped
33 to not be misinterpreted by the shell.
34
35 With the '--in=FILE' option an even number of values must be found and
36 are interpreted as pairs: the first value in each pair is a starting
37 LBA and the second value is the number to unmap from that LBA. Every‐
38 thing from and including a "#" on a line is ignored as are blank lines.
39 Values may be comma, space and tab separated or appear on separate
40 lines.
41
43 Arguments to long options are mandatory for short options as well.
44
45 -a, --anchor
46 sets the 'Anchor' bit in the command (introduced in sbc3r22).
47
48 -g, --grpnum=GN
49 sets the 'Group number' field to GN. Defaults to a value of
50 zero. GN should be a value between 0 and 31.
51
52 -h, --help
53 output the usage message then exit.
54
55 -I, --in=FILE
56 where FILE is a file name containing pairs of values. The first
57 member of each pair is a starting LBA and the second member of
58 the pair is the number of logical blocks to unmap from and
59 including that starting LBA. Values are interpreted as decimal
60 unless indicated otherwise. This option cannot be present with
61 the '--lba=' option.
62
63 -l, --lba=LBA,LBA...
64 where LBA,LBA... is a string of comma (or space) separated val‐
65 ues that are interpreted as starting logical block addresses.
66 Each number is interpreted as decimal unless prefixed by '0x' or
67 '0X' (or it has a trailing 'h' or 'H'). An argument that con‐
68 tains any space separators needs to be quoted (or otherwise
69 escaped). When this option is given then the '--num=' option
70 must also be given and they must contain the same number of ele‐
71 ments in their arguments.
72
73 -n, --num=NUM,NUM...
74 where NUM,NUM... is a string of comma (or space) separated val‐
75 ues that are interpreted as a number of logical blocks to unmap.
76 Each number is interpreted as decimal unless prefixed by '0x' or
77 '0X' (or it has a trailing 'h' or 'H'). Note that 0 blocks is
78 acceptable. An argument that contains any space separators needs
79 to be quoted (or otherwise escaped). When this option is given
80 then the '--lba=' option must also be given and they must con‐
81 tain the same number of elements in their arguments.
82
83 -t, --timeout=TO
84 where TO is a timeout value (in seconds) for the UNMAP command.
85 The default value is 60 seconds.
86
87 -v, --verbose
88 increase the level of verbosity, (i.e. debug output).
89
90 -V, --version
91 print the version string and then exit.
92
94 Some limits: an LBA can be up to 64 bits, a NUM up to 32 bits (imposed
95 by structure of UNMAP SCSI command parameter data). The NUM is further
96 constrained by the MAXIMUM UNMAP LBA COUNT field in the BLOCK LIMITS
97 VPD page (0xb0). The maximum number of LBA,NUM pairs is limited to 128
98 by this utility and may be further constrained by the MAXIMUM UNMAP
99 BLOCK DESCRIPTOR COUNT field in the BLOCK LIMITS VPD page.
100
101 Since it is unclear how long the UNMAP command will take to execute a
102 '--timeout=" option has been provided. The default timeout period is 60
103 seconds. If all the logical blocks on a logical unit (e.g. a disk
104 drive) are to be unmapped then the FORMAT UNIT SCSI command (see the
105 sg_format utility) may be considered as an alternative.
106
107 Support for logical block provisioning is indicated by the LBPME bit in
108 the response to the SCSI READ CAPACITY (16) command (see the sg_readcap
109 utility).
110
111 In SBC-3 revision 25 the LBPU and ANC_SUP bits where added to the Logi‐
112 cal Block Provisioning VPD page. When LBPU is set it indicates that the
113 device supports the UNMAP command. When the ANC_SUP bit is set it indi‐
114 cates the device supports anchored LBAs.
115
117 In the examples directory of the sg3_utils package there is a
118 sg_unmap_example.txt file that shows the format that the '--in=' option
119 accepts.
120
122 The exit status of sg_unmap is 0 when it is successful. Otherwise see
123 the sg3_utils(8) man page.
124
126 Written by Douglas Gilbert.
127
129 Report bugs to <dgilbert at interlog dot com>.
130
132 Copyright © 2009-2011 Douglas Gilbert
133 This software is distributed under a FreeBSD license. There is NO war‐
134 ranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
135 POSE.
136
138 sg_format,sg_get_lba_status,sg_readcap,sg_vpd,sg_write_same(sg3_utils)
139
140
141
142sg3_utils-1.35 November 2012 SG_UNMAP(8)