{
    "content": [
        {
            "type": "text",
            "text": "# sg_unmap (man)\n\n## NAME\n\nsgunmap - send SCSI UNMAP command (known as 'trim' in ATA specs)\n\n## SYNOPSIS\n\nsgunmap   [--all=ST,RN[,LA]]   [--anchor]   [--dry-run]   [--force]  [--grpnum=GN]  [--help]\n[--in=FILE] [--lba=LBA,LBA...] [--num=NUM,NUM...] [--timeout=TO] [--verbose] [--version]  DE‐\nVICE\n\n## DESCRIPTION\n\nSend a SCSI UNMAP command to DEVICE to unmap one or more logical blocks. This command was in‐\ntroduced in SBC-3 revision 18 under the broad heading of \"logical block provisioning\".  Logi‐\ncal  blocks  may also be unmapped by the SCSI WRITE SAME command; see the sgwritesame util‐\nity. The unmap capability is closely related to the ATA DATA SET MANAGEMENT command with  the\n\"Trim\" bit set.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **OPTIONS** (12 subsections)\n- **NOTES**\n- **EXAMPLES**\n- **EXIT STATUS**\n- **AUTHORS**\n- **REPORTING BUGS**\n- **COPYRIGHT**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "sg_unmap",
        "section": "",
        "mode": "man",
        "summary": "sgunmap - send SCSI UNMAP command (known as 'trim' in ATA specs)",
        "synopsis": "sgunmap   [--all=ST,RN[,LA]]   [--anchor]   [--dry-run]   [--force]  [--grpnum=GN]  [--help]\n[--in=FILE] [--lba=LBA,LBA...] [--num=NUM,NUM...] [--timeout=TO] [--verbose] [--version]  DE‐\nVICE",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [
            {
                "flag": "-A",
                "long": "--all",
                "arg": null,
                "description": "where ST is the starting LBA, RN is the repeat number which is the maximum number of blocks in each SCSI UNMAP command, and LA, if given, is the last LBA to unmap. If LA is not given, then the last LBA on the DEVICE is used. That is obtained by the SCSI READ CAPACITY command."
            },
            {
                "flag": "-a",
                "long": "--anchor",
                "arg": null,
                "description": "sets the 'Anchor' bit in the command (introduced in sbc3r22)."
            },
            {
                "flag": "-d",
                "long": "--dry-run",
                "arg": null,
                "description": "perform all the preparation, including opening DEVICE plus sending a 'standard' SCSI INQUIRY command (and optionally a READ CAPACITY), but exit before performing any SCSI UNMAP commands."
            },
            {
                "flag": "-f",
                "long": "--force",
                "arg": null,
                "description": "bypass the 15 second warning period that occurs before any UNMAP commands are sent."
            },
            {
                "flag": "-g",
                "long": "--grpnum",
                "arg": null,
                "description": "sets the 'Group number' field to GN. Defaults to a value of zero. GN should be a value between 0 and 63."
            },
            {
                "flag": "-h",
                "long": "--help",
                "arg": null,
                "description": "output the usage message then exit."
            },
            {
                "flag": "-I",
                "long": "--in",
                "arg": null,
                "description": "where FILE is a file name containing pairs of values. The first member of each pair is a starting LBA and the second member of the pair is the number of logical blocks to unmap from and including that starting LBA. Values are interpreted as decimal unless indicated otherwise. This option cannot be present with the '--lba=' option."
            },
            {
                "flag": "-l",
                "long": "--lba",
                "arg": null,
                "description": "where LBA,LBA... is a string of comma (or space) separated values that are interpreted as starting logical block addresses. Each number is interpreted as decimal unless pre‐ fixed by '0x' or '0X' (or it has a trailing 'h' or 'H'). An argument that contains any space separators needs to be quoted (or otherwise escaped). When this option is given then the '--num=' option must also be given and they must contain the same number of elements in their arguments."
            },
            {
                "flag": "-n",
                "long": "--num",
                "arg": null,
                "description": "where NUM,NUM... is a string of comma (or space) separated values that are interpreted as a number of logical blocks to unmap. Each number is interpreted as decimal unless prefixed by '0x' or '0X' (or it has a trailing 'h' or 'H'). Note that 0 blocks is ac‐ ceptable. An argument that contains any space separators needs to be quoted (or other‐ wise escaped). When this option is given then the '--lba=' option must also be given and they must contain the same number of elements in their arguments."
            },
            {
                "flag": "-t",
                "long": "--timeout",
                "arg": null,
                "description": "where TO is a timeout value (in seconds) for the UNMAP command. The default value is 60 seconds."
            },
            {
                "flag": "-v",
                "long": "--verbose",
                "arg": null,
                "description": "increase the level of verbosity, (i.e. debug output)."
            },
            {
                "flag": "-V",
                "long": "--version",
                "arg": null,
                "description": "print the version string and then exit."
            }
        ],
        "examples": [
            "In the examples directory of the sg3utils package there is a sgunmapexample.txt file  that",
            "shows the format that the '--in=' option accepts.",
            "To unmap all blocks from and including LBA 0x2000 to the end of the device (e.g. disk or SSD)",
            "with each SCSI UNMAP command given 1024 blocks to unmap:",
            "sgunmap --all=0x2000,1k /dev/sg2",
            "Add '--force' to bypass the 15 seconds of warnings. So '--force'  is  appropriate  for  batch",
            "files."
        ],
        "see_also": [
            {
                "name": "sgwritesame",
                "section": "sg3utils",
                "url": "https://www.chedong.com/phpMan.php/man/sgwritesame/sg3utils/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 32,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 2,
                "subsections": [
                    {
                        "name": "-A --all",
                        "lines": 5,
                        "flag": "-A",
                        "long": "--all"
                    },
                    {
                        "name": "-a --anchor",
                        "lines": 2,
                        "flag": "-a",
                        "long": "--anchor"
                    },
                    {
                        "name": "-d --dry-run",
                        "lines": 4,
                        "flag": "-d",
                        "long": "--dry-run"
                    },
                    {
                        "name": "-f --force",
                        "lines": 2,
                        "flag": "-f",
                        "long": "--force"
                    },
                    {
                        "name": "-g --grpnum",
                        "lines": 3,
                        "flag": "-g",
                        "long": "--grpnum"
                    },
                    {
                        "name": "-h --help",
                        "lines": 2,
                        "flag": "-h",
                        "long": "--help"
                    },
                    {
                        "name": "-I --in",
                        "lines": 5,
                        "flag": "-I",
                        "long": "--in"
                    },
                    {
                        "name": "-l --lba",
                        "lines": 7,
                        "flag": "-l",
                        "long": "--lba"
                    },
                    {
                        "name": "-n --num",
                        "lines": 7,
                        "flag": "-n",
                        "long": "--num"
                    },
                    {
                        "name": "-t --timeout",
                        "lines": 3,
                        "flag": "-t",
                        "long": "--timeout"
                    },
                    {
                        "name": "-v --verbose",
                        "lines": 2,
                        "flag": "-v",
                        "long": "--verbose"
                    },
                    {
                        "name": "-V --version",
                        "lines": 2,
                        "flag": "-V",
                        "long": "--version"
                    }
                ]
            },
            {
                "name": "NOTES",
                "lines": 23,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "EXIT STATUS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "REPORTING BUGS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "sgunmap - send SCSI UNMAP command (known as 'trim' in ATA specs)\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "sgunmap   [--all=ST,RN[,LA]]   [--anchor]   [--dry-run]   [--force]  [--grpnum=GN]  [--help]\n[--in=FILE] [--lba=LBA,LBA...] [--num=NUM,NUM...] [--timeout=TO] [--verbose] [--version]  DE‐\nVICE\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Send a SCSI UNMAP command to DEVICE to unmap one or more logical blocks. This command was in‐\ntroduced in SBC-3 revision 18 under the broad heading of \"logical block provisioning\".  Logi‐\ncal  blocks  may also be unmapped by the SCSI WRITE SAME command; see the sgwritesame util‐\nity. The unmap capability is closely related to the ATA DATA SET MANAGEMENT command with  the\n\"Trim\" bit set.\n\nLogical  blocks to be unmapped can be specified in one of three ways to this utility. One way\nis by supplying the start LBAs to the '--lba=' option and the corresponding number(s) to  un‐\nmap  to the '--num=' option. Another way is by putting start LBA and number to unmap pairs in\na file whose name is given to the '--in=' option. Alternatively a large segment or all  of  a\ndisk  (SSD)  can  be  unmapped with the --all=STRN[,LA] option. All values are assumed to be\ndecimal unless prefixed by \"0x\" (or \"0X\") or have a trailing \"h\" (or \"H\") in which case  they\nare  interpreted  as  hexadecimal.   Suffix multipliers are permitted on decimal values (e.g.\n'--num=1m').\n\nWhen the '--lba=' option is given then the '--num=' option must also be given. If one  has  a\ncomma  separated list as its argument then the other must have the same number of elements in\nits list. The arguments can use a single space as a separator but need to be in quotes or es‐\ncaped to not be misinterpreted by the shell.\n\nWith  the  '--in=FILE'  option  an even number of values must be found and are interpreted as\npairs: the first value in each pair is a starting LBA and the second value is the  number  to\nunmap  from  that  LBA. Everything from and including a \"#\" on a line is ignored as are blank\nlines. Values may be comma, space and tab separated or appear on separate  lines.  Each  line\nshould not exceed 1023 bytes in length.\n\nSince  a lot of data can be lost with this utility, a 15 second \"cooling off\" period is given\nbefore any UNMAP commands are sent. During this period the user is reminded what will happen,\nand  to  which  device, so they can use control-C (or some other technique) to terminate this\nutility before any unmapping takes place. This period can be bypassed with  the  --force  op‐\ntion.\n",
                "subsections": []
            },
            "OPTIONS": {
                "content": "Arguments to long options are mandatory for short options as well.\n",
                "subsections": [
                    {
                        "name": "-A --all",
                        "content": "where  ST  is the starting LBA, RN is the repeat number which is the maximum number of\nblocks in each SCSI UNMAP command, and LA, if given, is the last LBA to unmap.  If  LA\nis  not  given,  then the last LBA on the DEVICE is used. That is obtained by the SCSI\nREAD CAPACITY command.\n",
                        "flag": "-A",
                        "long": "--all"
                    },
                    {
                        "name": "-a --anchor",
                        "content": "sets the 'Anchor' bit in the command (introduced in sbc3r22).\n",
                        "flag": "-a",
                        "long": "--anchor"
                    },
                    {
                        "name": "-d --dry-run",
                        "content": "perform all the preparation, including opening DEVICE plus sending a  'standard'  SCSI\nINQUIRY  command (and optionally a READ CAPACITY), but exit before performing any SCSI\nUNMAP commands.\n",
                        "flag": "-d",
                        "long": "--dry-run"
                    },
                    {
                        "name": "-f --force",
                        "content": "bypass the 15 second warning period that occurs before any UNMAP commands are sent.\n",
                        "flag": "-f",
                        "long": "--force"
                    },
                    {
                        "name": "-g --grpnum",
                        "content": "sets the 'Group number' field to GN. Defaults to a value of  zero.   GN  should  be  a\nvalue between 0 and 63.\n",
                        "flag": "-g",
                        "long": "--grpnum"
                    },
                    {
                        "name": "-h --help",
                        "content": "output the usage message then exit.\n",
                        "flag": "-h",
                        "long": "--help"
                    },
                    {
                        "name": "-I --in",
                        "content": "where FILE is a file name containing pairs of values. The first member of each pair is\na starting LBA and the second member of the pair is the number of  logical  blocks  to\nunmap  from  and including that starting LBA. Values are interpreted as decimal unless\nindicated otherwise. This option cannot be present with the '--lba=' option.\n",
                        "flag": "-I",
                        "long": "--in"
                    },
                    {
                        "name": "-l --lba",
                        "content": "where LBA,LBA... is a string of comma (or space) separated values that are interpreted\nas starting logical block addresses. Each number is interpreted as decimal unless pre‐\nfixed by '0x' or '0X' (or it has a trailing 'h' or 'H'). An argument that contains any\nspace  separators needs to be quoted (or otherwise escaped). When this option is given\nthen the '--num=' option must also be given and they must contain the same  number  of\nelements in their arguments.\n",
                        "flag": "-l",
                        "long": "--lba"
                    },
                    {
                        "name": "-n --num",
                        "content": "where NUM,NUM... is a string of comma (or space) separated values that are interpreted\nas a number of logical blocks to unmap. Each number is interpreted as  decimal  unless\nprefixed  by '0x' or '0X' (or it has a trailing 'h' or 'H'). Note that 0 blocks is ac‐\nceptable. An argument that contains any space separators needs to be quoted (or other‐\nwise  escaped).  When this option is given then the '--lba=' option must also be given\nand they must contain the same number of elements in their arguments.\n",
                        "flag": "-n",
                        "long": "--num"
                    },
                    {
                        "name": "-t --timeout",
                        "content": "where TO is a timeout value (in seconds) for the UNMAP command.  The default value  is\n60 seconds.\n",
                        "flag": "-t",
                        "long": "--timeout"
                    },
                    {
                        "name": "-v --verbose",
                        "content": "increase the level of verbosity, (i.e. debug output).\n",
                        "flag": "-v",
                        "long": "--verbose"
                    },
                    {
                        "name": "-V --version",
                        "content": "print the version string and then exit.\n",
                        "flag": "-V",
                        "long": "--version"
                    }
                ]
            },
            "NOTES": {
                "content": "Some  limits: an LBA can be up to 64 bits, a NUM up to 32 bits (imposed by structure of UNMAP\nSCSI command parameter data). The NUM is further constrained by the MAXIMUM UNMAP  LBA  COUNT\nfield  in the BLOCK LIMITS VPD page (0xb0). The maximum number of LBA,NUM pairs is limited to\n128 by this utility and may be further constrained by  the  MAXIMUM  UNMAP  BLOCK  DESCRIPTOR\nCOUNT field in the BLOCK LIMITS VPD page.\n\nSince it is unclear how long the UNMAP command will take to execute a '--timeout=\" option has\nbeen provided. The default timeout period is 60 seconds. If all the logical blocks on a logi‐\ncal  unit  (e.g.  a disk drive) are to be unmapped then the FORMAT UNIT SCSI command (see the\nsgformat utility) may be considered as an alternative.\n\nSupport for logical block provisioning is indicated by the LBPME bit in the response  to  the\nSCSI READ CAPACITY (16) command (see the sgreadcap utility).\n\nIn  SBC-3 revision 25 the LBPU and ANCSUP bits where added to the Logical Block Provisioning\nVPD page. When LBPU is set it indicates that the device supports the UNMAP command. When  the\nANCSUP bit is set it indicates the device supports anchored LBAs.\n\nThe  SCSI  UNMAP command does the \"right thing\" with respect to command queueing. However its\nATA counterpart: the DATA SET MANAGEMENT command with the \"Trim\" bit set  does  not  interact\nwell with SATA queueing known as NCQ.  To address this problem T13 have introduced a new com‐\nmand called SFQ DATA SET MANAGEMENT which also has a Trim bit.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "In the examples directory of the sg3utils package there is a sgunmapexample.txt file  that\nshows the format that the '--in=' option accepts.\n\nTo unmap all blocks from and including LBA 0x2000 to the end of the device (e.g. disk or SSD)\nwith each SCSI UNMAP command given 1024 blocks to unmap:\n\nsgunmap --all=0x2000,1k /dev/sg2\n\nAdd '--force' to bypass the 15 seconds of warnings. So '--force'  is  appropriate  for  batch\nfiles.\n",
                "subsections": []
            },
            "EXIT STATUS": {
                "content": "The  exit  status  of sgunmap is 0 when it is successful. Otherwise see the sg3utils(8) man\npage.\n",
                "subsections": []
            },
            "AUTHORS": {
                "content": "Written by Douglas Gilbert.\n",
                "subsections": []
            },
            "REPORTING BUGS": {
                "content": "Report bugs to <dgilbert at interlog dot com>.\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright © 2009-2018 Douglas Gilbert\nThis software is distributed under a FreeBSD license. There is NO warranty; not even for MER‐\nCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "sgformat,sggetlbastatus,sgreadcap,sgvpd,sgwritesame(sg3utils)\n\n\n\nsg3utils-1.43                               March 2018                                  SGUNMAP(8)",
                "subsections": []
            }
        }
    }
}