SG_WRITE_ATTR(8) | SG3_UTILS | SG_WRITE_ATTR(8) |
sg_write_attr - send SCSI WRITE ATTRIBUTE command
sg_write_attr [--enumerate] [--element=EA] [--help] [--hex] [--in=FN] [--lvn=LVN] [--pn=PN] [--raw] [--wtc] [--verbose] [--version] DEVICE [attribute=value [attribute:value...]]
Sends a SCSI WRITE ATTRIBUTE command to DEVICE among with attribute-value pairs specified in command line arguments or read from the input file. This command was introduced in SPC-3 revision 1 and thus is applicable to all SCSI devices. In practice it is used mainly for tape systems. This utility is based on the SPC-5 draft standard, revision 17 (spc5r17.pdf).
Arguments to long options are mandatory for short options as well.
An attribute-value pair comprised of the attribute identifier and
attribute value, delimited by an equal sign '=' or a colon
':'. Attribute identifier can be specified as a number in decimal,
octal (prefixed by '0') or hexadecimal (prefixed by '0x') representation, or
with an acronym if the attribute provides one. Delimiter sign determines
value representation: an equal sign denotes values in string or numerical
format, or acronym, while a colon sign denotes a hex sequence comprised of
bytes in hexadecimal form separated by a space or comma.
String values can be used with attributes in ASCII or text format, while
numbers and acronyms are suitable for binary attributes. Available acronyms
can be listed by the --enumerate options. Acronyms are
case-insensitive.
For the fixed-length binary attributes, value length must match attribute
length exactly. Maximum binary attribute value in numerical representation
is restricted by the unsigned long long type size on a given platform (8
bytes typically), while hexadecimal sequence can be of arbitrary length.
Values of ASCII format attributes are left aligned padded with spaces to
attribute length.
Empty value (a delimiter followed by nothing) is used to delete a given
attribute in device server.
Attribute-value pairs in command line arguments containing spaces should be
quoted or escaped.
Only tape systems seem to implement the SCSI WRITE ATTRIBUTE
command. The vast majority of its definition is in the SPC standard so other
device types could use it.
Total buffer length for the attribute list in the SCSI WRITE ATTRIBUTE command
payload is 1 MiB (1024 KiB).
Set a tape barcode ASCII attribute specified by acronym and a string value:
# sg_write_attr /dev/sg1 BarCode=BARCODE01
Set a tape barcode ASCII attribute specified by hexadecimal identifier and a string value:
# sg_write_attr /dev/sg1 0x806=BARCODE01
Set a user label text attribute with string value containing spaces in quoted command line argument:
# sg_write_attr /dev/sg1 "UserLabel=User label 1"
Set a user label text attribute with hex sequence value:
# sg_write_attr /dev/sg1
UserLabel:42,41,52,43,4F,44,45,30,32
or
# sg_write_attr /dev/sg1 "0x803:42 41 52 43 4F 44 45 30
32"
Set a locale identifier attribute with values specified by acronyms or numbers:
# sg_write_attr /dev/sg1 LocaleId=ascii
# sg_write_attr /dev/sg1 LocaleId=utf-8
# sg_write_attr /dev/sg1 LocaleId=0x80
# sg_write_attr /dev/sg1 LocaleId:81
# sg_write_attr /dev/sg1 0x805=iso-8859-9
Set multiple attributes specified in command line arguments:
# sg_write_attr /dev/sg1 BarCode=BARCODE01 "UserLabel=My User Label" LocaleId=iso-8859-1
Set variable-length binary attribute with values in numerical or hex sequence formats:
# sg_write_attr /dev/sg1 VCI=1
# sg_write_attr /dev/sg1 VCI=65535
# sg_write_attr /dev/sg1 VCI=0x012345
# sg_write_attr /dev/sg1 VCI=0x0123456789abcdef
# sg_write_attr /dev/sg1
VCI:01,23,45,67,89,ab,cd,ef,20,21,22,23,24,25,26,27,28,29,2a,2b,2c,2d,2e,2f
Set fixed-length binary attribute using value in hex sequence format:
# sg_write_attr /dev/sg1 "MediumGUID:63 38 66 36 62 39 32 32 2d 37 38 38 39 2d 31 31 65 64 2d 38 65 35 31 2d 66 37 36 65 62 32 63 39 38 38 64 31"
Delete an attribute using empty value:
# sg_write_attr /dev/sg1 BarCode=
or
# sg_write_attr /dev/sg1 BarCode:
Delete multiple attributes:
# sg_write_attr /dev/sg1 UserLabel= BarCode= 0x805=
Set attributes specified in the text input file:
# sg_write_attr --in=attrs.txt /dev/sg1
Contents of the "attrs.txt" file:
AppVersion=1.02.15
UserLabel=User Label 1
LastWritten=251120221637
Barcode=BARCODE02
OwningHost=backup_server
MediaPoolName=First Media Pool
PartUserLabel=PART01
LUatPart=1
AppFmtVersion=MTF0125
VCI=0x0123456789abcdef
MediumGUID:62 64 61 36 62 30 35 34 2d 37 38 38 39 2d 31 31 65 64 2d 39 65 64
30 2d 62 37 31 30 63 32 62 63 30 34 30 39
Set attribute list specified in the hexadecimal format input file:
# sg_write_attr --in=attrs_hex.txt --hex /dev/sg1
Contents of the "attrs_hex.txt" file:
00 00 00 25 08 06 01 00 20 42 41 52 43 4f 44 45
2d 30 32 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20
Set attribute list specified in the raw binary input file:
# sg_write_attr --in=attrs_raw.bin --raw /dev/sg1
Contents of the "attrs_raw.bin" file:
$ od -A x -t x1z -v attrs_raw.bin
000000 00 00 00 25 08 06 01 00 20 42 41 52 43 4f 44 45 >...%....
BARCODE<
000010 2d 30 32 20 20 20 20 20 20 20 20 20 20 20 20 20 >-02 <
000020 20 20 20 20 20 20 20 20 20 > <
000029
The exit status of sg_write_attr is 0 when it is successful. Otherwise see the sg3_utils(8) man page.
Written by Douglas Gilbert and Boris Fox.
Report bugs to <dgilbert at interlog dot com>.
Copyright © 2016-2020 Douglas Gilbert, 2022-2023 Boris Fox
This software is distributed under a FreeBSD license. There is NO warranty;
not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
sg_read_attrs(sg3_utils)
January 2023 | sg3_utils-1.48 |