summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorken <ken@FreeBSD.org>2015-06-16 02:31:11 +0000
committerken <ken@FreeBSD.org>2015-06-16 02:31:11 +0000
commit1d2632e58b4f9b2c6256c2da8cefdd3574d81cde (patch)
treebaa2cc1d59134334453890933ea6c280e7f34eef /sbin
parent9e32ce59f0b80ab53877e923cc05f059e9075435 (diff)
downloadFreeBSD-src-1d2632e58b4f9b2c6256c2da8cefdd3574d81cde.zip
FreeBSD-src-1d2632e58b4f9b2c6256c2da8cefdd3574d81cde.tar.gz
MFC, r284192:
------------------------------------------------------------------------ r284192 | ken | 2015-06-09 15:39:38 -0600 (Tue, 09 Jun 2015) | 102 lines Add support for reading MAM attributes to camcontrol(8) and libcam(3). MAM is Medium Auxiliary Memory and is most commonly found as flash chips on tapes. This includes support for reading attributes and decoding most known attributes, but does not yet include support for writing attributes or reporting attributes in XML format. libsbuf/Makefile: Add subr_prf.c for the new sbuf_hexdump() function. This function is essentially the same function. libsbuf/Symbol.map: Add a new shared library minor version, and include the sbuf_hexdump() function. libsbuf/Version.def: Add version 1.4 of the libsbuf library. libutil/hexdump.3: Document sbuf_hexdump() alongside hexdump(3), since it is essentially the same function. camcontrol/Makefile: Add attrib.c. camcontrol/attrib.c: Implementation of READ ATTRIBUTE support for camcontrol(8). camcontrol/camcontrol.8: Document the new 'camcontrol attrib' subcommand. camcontrol/camcontrol.c: Add the new 'camcontrol attrib' subcommand. camcontrol/camcontrol.h: Add a function prototype for scsiattrib(). share/man/man9/sbuf.9: Document the existence of sbuf_hexdump() and point users to the hexdump(3) man page for more details. sys/cam/scsi/scsi_all.c: Add a table of known attributes, text descriptions and handler functions. Add a new scsi_attrib_sbuf() function along with a number of other related functions that help decode attributes. scsi_attrib_ascii_sbuf() decodes ASCII format attributes. scsi_attrib_int_sbuf() decodes binary format attributes, and will pass them off to scsi_attrib_hexdump_sbuf() if they're bigger than 8 bytes. scsi_attrib_vendser_sbuf() decodes the vendor and drive serial number attribute. scsi_attrib_volcoh_sbuf() decodes the Volume Coherency Information attribute that LTFS writes out. sys/cam/scsi/scsi_all.h: Add a number of attribute-related structure definitions and other defines. Add function prototypes for all of the functions added in scsi_all.c. sys/kern/subr_prf.c: Add a new function, sbuf_hexdump(). This is the same as the existing hexdump(9) function, except that it puts the result in an sbuf. This also changes subr_prf.c so that it can be compiled in userland for includsion in libsbuf. We should work to change this so that the kernel hexdump implementation is a wrapper around sbuf_hexdump() with a statically allocated sbuf with a drain. That will require a drain function that goes to the kernel printf() buffer that can take a non-NUL terminated string as input. That is because an sbuf isn't NUL-terminated until it is finished, and we don't want to finish it while we're still using it. We should also work to consolidate the userland hexdump and kernel hexdump implemenatations, which are currently separate. This would also mean making applications that currently link in libutil link in libsbuf. sys/sys/sbuf.h: Add the prototype for sbuf_hexdump(), and add another copy of the hexdump flag values if they aren't already defined. Ideally the flags should be defined in one place but the implemenation makes it difficult to do properly. (See above.) Sponsored by: Spectra Logic Corporation ------------------------------------------------------------------------
Diffstat (limited to 'sbin')
-rw-r--r--sbin/camcontrol/Makefile2
-rw-r--r--sbin/camcontrol/attrib.c509
-rw-r--r--sbin/camcontrol/camcontrol.8145
-rw-r--r--sbin/camcontrol/camcontrol.c27
-rw-r--r--sbin/camcontrol/camcontrol.h3
5 files changed, 684 insertions, 2 deletions
diff --git a/sbin/camcontrol/Makefile b/sbin/camcontrol/Makefile
index 4f11f19..519ecbf 100644
--- a/sbin/camcontrol/Makefile
+++ b/sbin/camcontrol/Makefile
@@ -3,7 +3,7 @@
PROG= camcontrol
SRCS= camcontrol.c util.c
.if !defined(RELEASE_CRUNCH)
-SRCS+= fwdownload.c modeedit.c persist.c progress.c
+SRCS+= attrib.c fwdownload.c modeedit.c persist.c progress.c
.else
CFLAGS+= -DMINIMALISTIC
.endif
diff --git a/sbin/camcontrol/attrib.c b/sbin/camcontrol/attrib.c
new file mode 100644
index 0000000..62d4b1e
--- /dev/null
+++ b/sbin/camcontrol/attrib.c
@@ -0,0 +1,509 @@
+/*-
+ * Copyright (c) 2014 Spectra Logic Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * substantially similar to the "NO WARRANTY" disclaimer below
+ * ("Disclaimer") and any redistribution must be conditioned upon
+ * including a substantially similar Disclaimer requirement for further
+ * binary redistribution.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * Authors: Ken Merry (Spectra Logic Corporation)
+ */
+/*
+ * SCSI Read and Write Attribute support for camcontrol(8).
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/ioctl.h>
+#include <sys/stdint.h>
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <sys/sbuf.h>
+#include <sys/queue.h>
+#include <sys/chio.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <string.h>
+#include <strings.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <limits.h>
+#include <err.h>
+#include <locale.h>
+
+#include <cam/cam.h>
+#include <cam/cam_debug.h>
+#include <cam/cam_ccb.h>
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_pass.h>
+#include <cam/scsi/scsi_ch.h>
+#include <cam/scsi/scsi_message.h>
+#include <camlib.h>
+#include "camcontrol.h"
+
+#if 0
+struct scsi_attr_desc {
+ int attr_id;
+
+ STAILQ_ENTRY(scsi_attr_desc) links;
+};
+#endif
+
+static struct scsi_nv elem_type_map[] = {
+ { "all", ELEMENT_TYPE_ALL },
+ { "picker", ELEMENT_TYPE_MT },
+ { "slot", ELEMENT_TYPE_ST },
+ { "portal", ELEMENT_TYPE_IE },
+ { "drive", ELEMENT_TYPE_DT },
+};
+
+static struct scsi_nv sa_map[] = {
+ { "attr_values", SRA_SA_ATTR_VALUES },
+ { "attr_list", SRA_SA_ATTR_LIST },
+ { "lv_list", SRA_SA_LOG_VOL_LIST },
+ { "part_list", SRA_SA_PART_LIST },
+ { "supp_attr", SRA_SA_SUPPORTED_ATTRS }
+};
+
+static struct scsi_nv output_format_map[] = {
+ { "text_esc", SCSI_ATTR_OUTPUT_TEXT_ESC },
+ { "text_raw", SCSI_ATTR_OUTPUT_TEXT_RAW },
+ { "nonascii_esc", SCSI_ATTR_OUTPUT_NONASCII_ESC },
+ { "nonascii_trim", SCSI_ATTR_OUTPUT_NONASCII_TRIM },
+ { "nonascii_raw", SCSI_ATTR_OUTPUT_NONASCII_RAW },
+ { "field_all", SCSI_ATTR_OUTPUT_FIELD_ALL },
+ { "field_none", SCSI_ATTR_OUTPUT_FIELD_NONE },
+ { "field_desc", SCSI_ATTR_OUTPUT_FIELD_DESC },
+ { "field_num", SCSI_ATTR_OUTPUT_FIELD_NUM },
+ { "field_size", SCSI_ATTR_OUTPUT_FIELD_SIZE },
+ { "field_rw", SCSI_ATTR_OUTPUT_FIELD_RW },
+};
+
+int
+scsiattrib(struct cam_device *device, int argc, char **argv, char *combinedopt,
+ int retry_count, int timeout, int verbosemode, int err_recover)
+{
+ union ccb *ccb = NULL;
+ int attr_num = -1;
+#if 0
+ int num_attrs = 0;
+#endif
+ int start_attr = 0;
+ int cached_attr = 0;
+ int read_service_action = -1;
+ int read_attr = 0, write_attr = 0;
+ int element_address = 0;
+ int element_type = ELEMENT_TYPE_ALL;
+ int partition = 0;
+ int logical_volume = 0;
+ char *endptr;
+ uint8_t *data_buf = NULL;
+ uint32_t dxfer_len = UINT16_MAX - 1;
+ uint32_t valid_len;
+ uint32_t output_format;
+ STAILQ_HEAD(, scsi_attr_desc) write_attr_list;
+ int error = 0;
+ int c;
+
+ ccb = cam_getccb(device);
+ if (ccb == NULL) {
+ warnx("%s: error allocating CCB", __func__);
+ error = 1;
+ goto bailout;
+ }
+
+ bzero(&(&ccb->ccb_h)[1],
+ sizeof(union ccb) - sizeof(struct ccb_hdr));
+
+ STAILQ_INIT(&write_attr_list);
+
+ /*
+ * By default, when displaying attribute values, we trim out
+ * non-ASCII characters in ASCII fields. We display all fields
+ * (description, attribute number, attribute size, and readonly
+ * status). We default to displaying raw text.
+ *
+ * XXX KDM need to port this to stable/10 and newer FreeBSD
+ * versions that have iconv built in and can convert codesets.
+ */
+ output_format = SCSI_ATTR_OUTPUT_NONASCII_TRIM |
+ SCSI_ATTR_OUTPUT_FIELD_ALL |
+ SCSI_ATTR_OUTPUT_TEXT_RAW;
+
+ data_buf = malloc(dxfer_len);
+ if (data_buf == NULL) {
+ warn("%s: error allocating %u bytes", __func__, dxfer_len);
+ error = 1;
+ goto bailout;
+ }
+
+ while ((c = getopt(argc, argv, combinedopt)) != -1) {
+ switch (c) {
+ case 'a':
+ attr_num = strtol(optarg, &endptr, 0);
+ if (*endptr != '\0') {
+ warnx("%s: invalid attribute number %s",
+ __func__, optarg);
+ error = 1;
+ goto bailout;
+ }
+ start_attr = attr_num;
+ break;
+ case 'c':
+ cached_attr = 1;
+ break;
+ case 'e':
+ element_address = strtol(optarg, &endptr, 0);
+ if (*endptr != '\0') {
+ warnx("%s: invalid element address %s",
+ __func__, optarg);
+ error = 1;
+ goto bailout;
+ }
+ break;
+ case 'F': {
+ scsi_nv_status status;
+ scsi_attrib_output_flags new_outflags;
+ int entry_num = 0;
+ char *tmpstr;
+
+ if (isdigit(optarg[0])) {
+ output_format = strtoul(optarg, &endptr, 0);
+ if (*endptr != '\0') {
+ warnx("%s: invalid numeric output "
+ "format argument %s", __func__,
+ optarg);
+ error = 1;
+ goto bailout;
+ }
+ break;
+ }
+ new_outflags = SCSI_ATTR_OUTPUT_NONE;
+
+ while ((tmpstr = strsep(&optarg, ",")) != NULL) {
+ status = scsi_get_nv(output_format_map,
+ sizeof(output_format_map) /
+ sizeof(output_format_map[0]), tmpstr,
+ &entry_num, SCSI_NV_FLAG_IG_CASE);
+
+ if (status == SCSI_NV_FOUND)
+ new_outflags |=
+ output_format_map[entry_num].value;
+ else {
+ warnx("%s: %s format option %s",
+ __func__,
+ (status == SCSI_NV_AMBIGUOUS) ?
+ "ambiguous" : "invalid", tmpstr);
+ error = 1;
+ goto bailout;
+ }
+ }
+ output_format = new_outflags;
+ break;
+ }
+ case 'p':
+ partition = strtol(optarg, &endptr, 0);
+ if (*endptr != '\0') {
+ warnx("%s: invalid partition number %s",
+ __func__, optarg);
+ error = 1;
+ goto bailout;
+ }
+ break;
+ case 'r': {
+ scsi_nv_status status;
+ int entry_num = 0;
+
+ status = scsi_get_nv(sa_map, sizeof(sa_map) /
+ sizeof(sa_map[0]), optarg, &entry_num,
+ SCSI_NV_FLAG_IG_CASE);
+ if (status == SCSI_NV_FOUND)
+ read_service_action = sa_map[entry_num].value;
+ else {
+ warnx("%s: %s %s option %s", __func__,
+ (status == SCSI_NV_AMBIGUOUS) ?
+ "ambiguous" : "invalid", "service action",
+ optarg);
+ error = 1;
+ goto bailout;
+ }
+ read_attr = 1;
+ break;
+ }
+ case 's':
+ start_attr = strtol(optarg, &endptr, 0);
+ if (*endptr != '\0') {
+ warnx("%s: invalid starting attr argument %s",
+ __func__, optarg);
+ error = 1;
+ goto bailout;
+ }
+ break;
+ case 'T': {
+ scsi_nv_status status;
+ int entry_num = 0;
+
+ status = scsi_get_nv(elem_type_map,
+ sizeof(elem_type_map) / sizeof(elem_type_map[0]),
+ optarg, &entry_num, SCSI_NV_FLAG_IG_CASE);
+ if (status == SCSI_NV_FOUND)
+ element_type = elem_type_map[entry_num].value;
+ else {
+ warnx("%s: %s %s option %s", __func__,
+ (status == SCSI_NV_AMBIGUOUS) ?
+ "ambiguous" : "invalid", "element type",
+ optarg);
+ error = 1;
+ goto bailout;
+ }
+ break;
+ }
+ case 'w':
+ warnx("%s: writing attributes is not implemented yet",
+ __func__);
+ error = 1;
+ goto bailout;
+ break;
+ case 'V':
+ logical_volume = strtol(optarg, &endptr, 0);
+
+ if (*endptr != '\0') {
+ warnx("%s: invalid logical volume argument %s",
+ __func__, optarg);
+ error = 1;
+ goto bailout;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ /*
+ * Default to reading attributes
+ */
+ if (((read_attr == 0) && (write_attr == 0))
+ || ((read_attr != 0) && (write_attr != 0))) {
+ warnx("%s: Must specify either -r or -w", __func__);
+ error = 1;
+ goto bailout;
+ }
+
+ if (read_attr != 0) {
+ scsi_read_attribute(&ccb->csio,
+ /*retries*/ retry_count,
+ /*cbfcnp*/ NULL,
+ /*tag_action*/ MSG_SIMPLE_Q_TAG,
+ /*service_action*/ read_service_action,
+ /*element*/ element_address,
+ /*elem_type*/ element_type,
+ /*logical_volume*/ logical_volume,
+ /*partition*/ partition,
+ /*first_attribute*/ start_attr,
+ /*cache*/ cached_attr,
+ /*data_ptr*/ data_buf,
+ /*length*/ dxfer_len,
+ /*sense_len*/ SSD_FULL_SIZE,
+ /*timeout*/ timeout ? timeout : 60000);
+#if 0
+ } else {
+#endif
+
+ }
+
+ ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
+
+ if (err_recover != 0)
+ ccb->ccb_h.flags |= CAM_PASS_ERR_RECOVER;
+
+ if (cam_send_ccb(device, ccb) < 0) {
+ warn("error sending %s ATTRIBUTE", (read_attr != 0) ?
+ "READ" : "WRITE");
+
+ if (verbosemode != 0) {
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
+ }
+
+ error = 1;
+ goto bailout;
+ }
+
+ if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+ if (verbosemode != 0) {
+ cam_error_print(device, ccb, CAM_ESF_ALL,
+ CAM_EPF_ALL, stderr);
+ }
+ error = 1;
+ goto bailout;
+ }
+
+ if (read_attr == 0)
+ goto bailout;
+
+ valid_len = dxfer_len - ccb->csio.resid;
+
+ switch (read_service_action) {
+ case SRA_SA_ATTR_VALUES: {
+ uint32_t len_left, hdr_len, cur_len;
+ struct scsi_read_attribute_values *hdr;
+ struct scsi_mam_attribute_header *cur_id;
+ char error_str[512];
+ uint8_t *cur_pos;
+ struct sbuf *sb;
+
+ hdr = (struct scsi_read_attribute_values *)data_buf;
+
+ if (valid_len < sizeof(*hdr)) {
+ fprintf(stdout, "No attributes returned.\n");
+ error = 0;
+ goto bailout;
+ }
+
+ sb = sbuf_new_auto();
+ if (sb == NULL) {
+ warn("%s: Unable to allocate sbuf", __func__);
+ error = 1;
+ goto bailout;
+ }
+ /*
+ * XXX KDM grab more data if it is available.
+ */
+ hdr_len = scsi_4btoul(hdr->length);
+
+ for (len_left = MIN(valid_len, hdr_len),
+ cur_pos = &hdr->attribute_0[0]; len_left > sizeof(*cur_id);
+ len_left -= cur_len, cur_pos += cur_len) {
+ int cur_attr_num;
+ cur_id = (struct scsi_mam_attribute_header *)cur_pos;
+ cur_len = scsi_2btoul(cur_id->length) + sizeof(*cur_id);
+ cur_attr_num = scsi_2btoul(cur_id->id);
+
+ if ((attr_num != -1)
+ && (cur_attr_num != attr_num))
+ continue;
+
+ error = scsi_attrib_sbuf(sb, cur_id, len_left,
+ /*user_table*/ NULL, /*num_user_entries*/ 0,
+ /*prefer_user_table*/ 0, output_format, error_str,
+ sizeof(error_str));
+ if (error != 0) {
+ warnx("%s: %s", __func__, error_str);
+ sbuf_delete(sb);
+ error = 1;
+ goto bailout;
+ }
+ if (attr_num != -1)
+ break;
+ }
+
+ sbuf_finish(sb);
+ fprintf(stdout, "%s", sbuf_data(sb));
+ sbuf_delete(sb);
+ break;
+ }
+ case SRA_SA_SUPPORTED_ATTRS:
+ case SRA_SA_ATTR_LIST: {
+ uint32_t len_left, hdr_len;
+ struct scsi_attrib_list_header *hdr;
+ struct scsi_attrib_table_entry *entry = NULL;
+ const char *sa_name = "Supported Attributes";
+ const char *at_name = "Available Attributes";
+ int attr_id;
+ uint8_t *cur_id;
+
+ hdr = (struct scsi_attrib_list_header *)data_buf;
+ if (valid_len < sizeof(*hdr)) {
+ fprintf(stdout, "No %s\n",
+ (read_service_action == SRA_SA_SUPPORTED_ATTRS)?
+ sa_name : at_name);
+ error = 0;
+ goto bailout;
+ }
+ fprintf(stdout, "%s:\n",
+ (read_service_action == SRA_SA_SUPPORTED_ATTRS) ?
+ sa_name : at_name);
+ hdr_len = scsi_4btoul(hdr->length);
+ for (len_left = MIN(valid_len, hdr_len),
+ cur_id = &hdr->first_attr_0[0]; len_left > 1;
+ len_left -= sizeof(uint16_t), cur_id += sizeof(uint16_t)) {
+ attr_id = scsi_2btoul(cur_id);
+
+ if ((attr_num != -1)
+ && (attr_id != attr_num))
+ continue;
+
+ entry = scsi_get_attrib_entry(attr_id);
+ fprintf(stdout, "0x%.4x", attr_id);
+ if (entry == NULL)
+ fprintf(stdout, "\n");
+ else
+ fprintf(stdout, ": %s\n", entry->desc);
+
+ if (attr_num != -1)
+ break;
+ }
+ break;
+ }
+ case SRA_SA_PART_LIST:
+ case SRA_SA_LOG_VOL_LIST: {
+ struct scsi_attrib_lv_list *lv_list;
+ const char *partition_name = "Partition";
+ const char *lv_name = "Logical Volume";
+
+ if (valid_len < sizeof(*lv_list)) {
+ fprintf(stdout, "No %s list returned\n",
+ (read_service_action == SRA_SA_PART_LIST) ?
+ partition_name : lv_name);
+ error = 0;
+ goto bailout;
+ }
+
+ lv_list = (struct scsi_attrib_lv_list *)data_buf;
+
+ fprintf(stdout, "First %s: %d\n",
+ (read_service_action == SRA_SA_PART_LIST) ?
+ partition_name : lv_name,
+ lv_list->first_lv_number);
+ fprintf(stdout, "Number of %ss: %d\n",
+ (read_service_action == SRA_SA_PART_LIST) ?
+ partition_name : lv_name,
+ lv_list->num_logical_volumes);
+ break;
+ }
+ default:
+ break;
+ }
+bailout:
+ if (ccb != NULL)
+ cam_freeccb(ccb);
+
+ free(data_buf);
+
+ return (error);
+}
diff --git a/sbin/camcontrol/camcontrol.8 b/sbin/camcontrol/camcontrol.8
index c3c6b1c..4ee52d1 100644
--- a/sbin/camcontrol/camcontrol.8
+++ b/sbin/camcontrol/camcontrol.8
@@ -298,6 +298,19 @@
.Op Fl T Ar res_type
.Op Fl U
.Nm
+.Ic attrib
+.Op device id
+.Op generic args
+.Aq Fl r Ar action | Fl w Ar attrib
+.Op Fl a Ar attr_num
+.Op Fl c
+.Op Fl e Ar elem_addr
+.Op Fl F Ar form1,form2
+.Op Fl p Ar part
+.Op Fl s Ar start_addr
+.Op Fl T Ar elem_type
+.Op Fl V Ar lv_num
+.Nm
.Ic help
.Sh DESCRIPTION
The
@@ -1823,6 +1836,129 @@ Register and Move request.
This option only applies to the Register and Move service action of the
Persistent Reserve Out command.
.El
+.It Ic attrib
+Issue the
+.Tn SCSI
+READ or WRITE ATTRIBUTE commands.
+These commands are used to read and write attributes in Medium Auxiliary
+Memory (MAM).
+The most common place Medium Auxiliary Memory is found is small flash chips
+included tape cartriges.
+For instance,
+.Tn LTO
+tapes have MAM.
+Either the
+.Fl r
+option or the
+.Fl w
+option must be specified.
+.Bl -tag -width 14n
+.It Fl r Ar action
+Specify the READ ATTRIBUTE service action.
+.Bl -tag -width 11n
+.It attr_values
+Issue the ATTRIBUTE VALUES service action.
+Read and decode the available attributes and their values.
+.It attr_list
+Issue the ATTRIBUTE LIST service action.
+List the attributes that are available to read and write.
+.It lv_list
+Issue the LOGICAL VOLUME LIST service action.
+List the available logical volumes in the MAM.
+.It part_list
+Issue the PARTITION LIST service action.
+List the available partitions in the MAM.
+.It supp_attr
+Issue the SUPPORTED ATTRIBUTES service action.
+List attributes that are supported for reading or writing.
+These attributes may or may not be currently present in the MAM.
+.El
+.It Fl w Ar attr
+Specify an attribute to write to the MAM.
+This option is not yet implemented.
+.It Fl a Ar num
+Specify the attribute number to display.
+This option only works with the attr_values, attr_list and supp_attr
+arguments to
+.Fl r .
+.It Fl c
+Display cached attributes.
+If the device supports this flag, it allows displaying attributes for the
+last piece of media loaded in the drive.
+.It Fl e Ar num
+Specify the element address.
+This is used for specifying which element number in a medium changer to
+access when reading attributes.
+The element number could be for a picker, portal, slot or drive.
+.It Fl F Ar form1,form2
+Specify the output format for the attribute values (attr_val) display as a
+comma separated list of options.
+The default output is currently set to field_all,nonascii_trim,text_raw.
+Once this code is ported to FreeBSD 10, any text fields will be converted
+from their codeset to the user's native codeset with
+.Xr iconv 3 .
+.Pp
+The text options are mutually exclusive; if you specify more than one, you
+will get unpredictable results.
+The nonascii options are also mutually exclusive.
+Most of the field options may be logically ORed together.
+.Bl -tag -width 12n
+.It text_esc
+Print text fields with non-ASCII characters escaped.
+.It text_raw
+Print text fields natively, with no codeset conversion.
+.It nonascii_esc
+If any non-ASCII characters occur in fields that are supposed to be ASCII,
+escape the non-ASCII characters.
+.It nonascii_trim
+If any non-ASCII characters occur in fields that are supposed to be ASCII,
+omit the non-ASCII characters.
+.It nonascii_raw
+If any non-ASCII characters occur in fields that are supposed to be ASCII,
+print them as they are.
+.It field_all
+Print all of the prefix fields: description, attribute number, attribute
+size, and the attribute's readonly status.
+If field_all is specified, specifying any other field options will not have
+an effect.
+.It field_none
+Print none of the prefix fields, and only print out the attribute value.
+If field_none is specified, specifying any other field options will result
+in those fields being printed.
+.It field_desc
+Print out the attribute description.
+.It field_num
+Print out the attribute number.
+.It field_size
+Print out the attribute size.
+.It field_rw
+Print out the attribute's readonly status.
+.El
+.It Fl p Ar part
+Specify the partition.
+When the media has multiple partitions, specifying different partition
+numbers allows seeing the values for each individual partition.
+.It Fl s Ar start_num
+Specify the starting attribute number.
+This requests that the target device return attribute information starting
+at the given number.
+.It Fl T Ar elem_type
+Specify the element type.
+For medium changer devices, this allows specifying the type the element
+referenced in the element address (
+.Fl e ) .
+Valid types are:
+.Dq all ,
+.Dq picker ,
+.Dq slot ,
+.Dq portal ,
+and
+.Dq drive .
+.El
+.It Fl V Ar vol_num
+Specify the number of the logical volume to operate on.
+If the media has multiple logical volumes, this will allow displaying
+or writing attributes on the given logical volume.
.It Ic help
Print out verbose usage information.
.El
@@ -2049,6 +2185,15 @@ current initiator will be unregistered from the target.
The reservation will be moved to relative target port 2 on the target
device.
The registration will persist across power losses.
+.Pp
+.Bd -literal -offset indent
+camcontrol attrib sa0 -v -i attr_values -p 1
+.Ed
+.Pp
+This will read and decode the attribute values from partition 1 on the tape
+in tape drive sa0, and will display any
+.Tn SCSI
+errors that result.
.Sh SEE ALSO
.Xr cam 3 ,
.Xr cam_cdbparse 3 ,
diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c
index c0a1344..072492d 100644
--- a/sbin/camcontrol/camcontrol.c
+++ b/sbin/camcontrol/camcontrol.c
@@ -98,7 +98,8 @@ typedef enum {
CAM_CMD_SANITIZE = 0x0000001f,
CAM_CMD_PERSIST = 0x00000020,
CAM_CMD_APM = 0x00000021,
- CAM_CMD_AAM = 0x00000022
+ CAM_CMD_AAM = 0x00000022,
+ CAM_CMD_ATTRIB = 0x00000023
} cam_cmdmask;
typedef enum {
@@ -224,6 +225,7 @@ static struct camcontrol_opts option_table[] = {
{"security", CAM_CMD_SECURITY, CAM_ARG_NONE, "d:e:fh:k:l:qs:T:U:y"},
{"hpa", CAM_CMD_HPA, CAM_ARG_NONE, "Pflp:qs:U:y"},
{"persist", CAM_CMD_PERSIST, CAM_ARG_NONE, "ai:I:k:K:o:ps:ST:U"},
+ {"attrib", CAM_CMD_ATTRIB, CAM_ARG_NONE, "a:ce:F:p:r:s:T:w:V:"},
#endif /* MINIMALISTIC */
{"help", CAM_CMD_USAGE, CAM_ARG_NONE, NULL},
{"-?", CAM_CMD_USAGE, CAM_ARG_NONE, NULL},
@@ -8118,6 +8120,9 @@ usage(int printlong)
" camcontrol persist [dev_id][generic args] <-i action|-o action>\n"
" [-a][-I tid][-k key][-K sa_key][-p][-R rtp]\n"
" [-s scope][-S][-T type][-U]\n"
+" camcontrol attrib [dev_id][generic args] <-r action|-w attr>\n"
+" [-a attr_num][-c][-e elem][-F form1,form1]\n"
+" [-p part][-s start][-T type][-V vol]\n"
#endif /* MINIMALISTIC */
" camcontrol help\n");
if (!printlong)
@@ -8157,6 +8162,7 @@ usage(int printlong)
"fwdownload program firmware of the named device with the given image\n"
"security report or send ATA security commands to the named device\n"
"persist send the SCSI PERSISTENT RESERVE IN or OUT commands\n"
+"attrib send the SCSI READ or WRITE ATTRIBUTE commands\n"
"help this message\n"
"Device Identifiers:\n"
"bus:target specify the bus and target, lun defaults to 0\n"
@@ -8307,6 +8313,20 @@ usage(int printlong)
"-T res_type specify the reservation type: read_shared, wr_ex, rd_ex,\n"
" ex_ac, wr_ex_ro, ex_ac_ro, wr_ex_ar, ex_ac_ar\n"
"-U unregister the current initiator for register_move\n"
+"attrib arguments:\n"
+"-r action specify attr_values, attr_list, lv_list, part_list, or\n"
+" supp_attr\n"
+"-w attr specify an attribute to write, one -w argument per attr\n"
+"-a attr_num only display this attribute number\n"
+"-c get cached attributes\n"
+"-e elem_addr request attributes for the given element in a changer\n"
+"-F form1,form2 output format, comma separated list: text_esc, text_raw,\n"
+" nonascii_esc, nonascii_trim, nonascii_raw, field_all,\n"
+" field_none, field_desc, field_num, field_size, field_rw\n"
+"-p partition request attributes for the given partition\n"
+"-s start_attr request attributes starting at the given number\n"
+"-T elem_type specify the element type (used with -e)\n"
+"-V logical_vol specify the logical volume ID\n"
);
#endif /* MINIMALISTIC */
}
@@ -8651,6 +8671,11 @@ main(int argc, char **argv)
retry_count, timeout, arglist & CAM_ARG_VERBOSE,
arglist & CAM_ARG_ERR_RECOVER);
break;
+ case CAM_CMD_ATTRIB:
+ error = scsiattrib(cam_dev, argc, argv, combinedopt,
+ retry_count, timeout, arglist & CAM_ARG_VERBOSE,
+ arglist & CAM_ARG_ERR_RECOVER);
+ break;
#endif /* MINIMALISTIC */
case CAM_CMD_USAGE:
usage(1);
diff --git a/sbin/camcontrol/camcontrol.h b/sbin/camcontrol/camcontrol.h
index 7c249bf..582b6a3 100644
--- a/sbin/camcontrol/camcontrol.h
+++ b/sbin/camcontrol/camcontrol.h
@@ -66,6 +66,9 @@ int scsidoinquiry(struct cam_device *device, int argc, char **argv,
int scsipersist(struct cam_device *device, int argc, char **argv,
char *combinedopt, int retry_count, int timeout, int verbose,
int err_recover);
+int scsiattrib(struct cam_device *device, int argc, char **argv,
+ char *combinedopt, int retry_count, int timeout, int verbose,
+ int err_recover);
char *cget(void *hook, char *name);
int iget(void *hook, char *name);
void arg_put(void *hook, int letter, void *arg, int count, char *name);
OpenPOWER on IntegriCloud