1SG_UNMAP(8)                        SG3_UTILS                       SG_UNMAP(8)
2
3
4

NAME

6       sg_unmap - send SCSI UNMAP command (known as 'trim' in ATA specs)
7

SYNOPSIS

9       sg_unmap  [--all=ST,RN[,LA]]  [--anchor]  [--dry-run] [--force] [--grp‐
10       num=GN]  [--help]  [--in=FILE]  [--lba=LBA,LBA...]   [--num=NUM,NUM...]
11       [--timeout=TO] [--verbose] [--version] DEVICE
12

DESCRIPTION

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 three 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       Another way is by putting start LBA and number to unmap pairs in a file
25       whose name is given to the '--in=' option. Alternatively a  large  seg‐
26       ment  or  all of a disk (SSD) can be unmapped with the --all=ST_RN[,LA]
27       option. All values are assumed to be decimal unless  prefixed  by  "0x"
28       (or "0X") or have a trailing "h" (or "H") in which case they are inter‐
29       preted as hexadecimal.  Suffix multipliers  are  permitted  on  decimal
30       values (e.g. '--num=1m').
31
32       When the '--lba=' option is given then the '--num=' option must also be
33       given. If one has a comma separated list as its argument then the other
34       must  have  the  same number of elements in its list. The arguments can
35       use a single space as a separator but need to be in quotes  or  escaped
36       to not be misinterpreted by the shell.
37
38       With  the '--in=FILE' option an even number of values must be found and
39       are interpreted as pairs: the first value in each pair  is  a  starting
40       LBA  and  the second value is the number to unmap from that LBA. Every‐
41       thing from and including a "#" on a line is ignored as are blank lines.
42       Values  may  be  comma,  space  and tab separated or appear on separate
43       lines. Each line should not exceed 1023 bytes in length.
44
45       Since a lot of data can be lost with this utility, a 15 second "cooling
46       off"  period  is  given before any UNMAP commands are sent. During this
47       period the user is reminded what will happen, and to which  device,  so
48       they  can  use  control-C  (or  some other technique) to terminate this
49       utility before any unmapping takes place. This period can  be  bypassed
50       with the --force option.
51

OPTIONS

53       Arguments to long options are mandatory for short options as well.
54
55       -A, --all=ST,RN[,LA]
56              where  ST  is the starting LBA, RN is the repeat number which is
57              the maximum number of blocks in each SCSI UNMAP command, and LA,
58              if given, is the last LBA to unmap. If LA is not given, then the
59              last LBA on the DEVICE is used. That is  obtained  by  the  SCSI
60              READ CAPACITY command.
61
62       -a, --anchor
63              sets the 'Anchor' bit in the command (introduced in sbc3r22).
64
65       -d, --dry-run
66              perform all the preparation, including opening DEVICE plus send‐
67              ing a 'standard' SCSI INQUIRY command  (and  optionally  a  READ
68              CAPACITY), but exit before performing any SCSI UNMAP commands.
69
70       -f, --force
71              bypass the 15 second warning period that occurs before any UNMAP
72              commands are sent.
73
74       -g, --grpnum=GN
75              sets the 'Group number' field to GN.  Defaults  to  a  value  of
76              zero.  GN should be a value between 0 and 63.
77
78       -h, --help
79              output the usage message then exit.
80
81       -I, --in=FILE
82              where  FILE is a file name containing pairs of values. The first
83              member of each pair is a starting LBA and the second  member  of
84              the  pair  is  the  number  of  logical blocks to unmap from and
85              including that starting LBA. Values are interpreted  as  decimal
86              unless  indicated  otherwise. This option cannot be present with
87              the '--lba=' option.
88
89       -l, --lba=LBA,LBA...
90              where LBA,LBA... is a string of comma (or space) separated  val‐
91              ues  that  are  interpreted as starting logical block addresses.
92              Each number is interpreted as decimal unless prefixed by '0x' or
93              '0X'  (or  it  has a trailing 'h' or 'H'). An argument that con‐
94              tains any space separators needs  to  be  quoted  (or  otherwise
95              escaped).  When  this  option  is given then the '--num=' option
96              must also be given and they must contain the same number of ele‐
97              ments in their arguments.
98
99       -n, --num=NUM,NUM...
100              where  NUM,NUM... is a string of comma (or space) separated val‐
101              ues that are interpreted as a number of logical blocks to unmap.
102              Each number is interpreted as decimal unless prefixed by '0x' or
103              '0X' (or it has a trailing 'h' or 'H'). Note that  0  blocks  is
104              acceptable. An argument that contains any space separators needs
105              to be quoted (or otherwise escaped).  When this option is  given
106              then  the  '--lba=' option must also be given and they must con‐
107              tain the same number of elements in their arguments.
108
109       -t, --timeout=TO
110              where TO is a timeout value (in seconds) for the UNMAP  command.
111              The default value is 60 seconds.
112
113       -v, --verbose
114              increase the level of verbosity, (i.e. debug output).
115
116       -V, --version
117              print the version string and then exit.
118

NOTES

120       Some  limits: an LBA can be up to 64 bits, a NUM up to 32 bits (imposed
121       by structure of UNMAP SCSI command parameter data). The NUM is  further
122       constrained  by  the  MAXIMUM UNMAP LBA COUNT field in the BLOCK LIMITS
123       VPD page (0xb0). The maximum number of LBA,NUM pairs is limited to  128
124       by  this  utility  and  may be further constrained by the MAXIMUM UNMAP
125       BLOCK DESCRIPTOR COUNT field in the BLOCK LIMITS VPD page.
126
127       Since it is unclear how long the UNMAP command will take to  execute  a
128       '--timeout=" option has been provided. The default timeout period is 60
129       seconds. If all the logical blocks on a  logical  unit  (e.g.   a  disk
130       drive)  are  to  be unmapped then the FORMAT UNIT SCSI command (see the
131       sg_format utility) may be considered as an alternative.
132
133       Support for logical block provisioning is indicated by the LBPME bit in
134       the response to the SCSI READ CAPACITY (16) command (see the sg_readcap
135       utility).
136
137       In SBC-3 revision 25 the LBPU and ANC_SUP bits where added to the Logi‐
138       cal Block Provisioning VPD page. When LBPU is set it indicates that the
139       device supports the UNMAP command. When the ANC_SUP bit is set it indi‐
140       cates the device supports anchored LBAs.
141
142       The  SCSI  UNMAP command does the "right thing" with respect to command
143       queueing. However its ATA counterpart: the DATA SET MANAGEMENT  command
144       with the "Trim" bit set does not interact well with SATA queueing known
145       as NCQ.  To address this problem T13  have  introduced  a  new  command
146       called SFQ DATA SET MANAGEMENT which also has a Trim bit.
147

EXAMPLES

149       In  the  examples  directory  of  the  sg3_utils  package  there  is  a
150       sg_unmap_example.txt file that shows the format that the '--in=' option
151       accepts.
152
153       To  unmap  all  blocks  from and including LBA 0x2000 to the end of the
154       device (e.g. disk or SSD) with  each  SCSI  UNMAP  command  given  1024
155       blocks to unmap:
156
157         sg_unmap --all=0x2000,1k /dev/sg2
158
159       Add  '--force'  to  bypass  the 15 seconds of warnings. So '--force' is
160       appropriate for batch files.
161

EXIT STATUS

163       The exit status of sg_unmap is 0 when it is successful.  Otherwise  see
164       the sg3_utils(8) man page.
165

AUTHORS

167       Written by Douglas Gilbert.
168

REPORTING BUGS

170       Report bugs to <dgilbert at interlog dot com>.
171
173       Copyright © 2009-2018 Douglas Gilbert
174       This  software is distributed under a FreeBSD license. There is NO war‐
175       ranty; not even for MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PUR‐
176       POSE.
177

SEE ALSO

179       sg_format,sg_get_lba_status,sg_readcap,sg_vpd,sg_write_same(sg3_utils)
180
181
182
183sg3_utils-1.43                    March 2018                       SG_UNMAP(8)
Impressum