summaryrefslogtreecommitdiffstats
path: root/bin/chio
diff options
context:
space:
mode:
authorken <ken@FreeBSD.org>2013-04-19 20:03:51 +0000
committerken <ken@FreeBSD.org>2013-04-19 20:03:51 +0000
commit9a543047eb5c6caa745ab785627c29aa050f3fe6 (patch)
treea42129446c56829e1277cb13ece82f7720559ea6 /bin/chio
parent120125784a1ca698c656c6ef5e21e219df994f64 (diff)
downloadFreeBSD-src-9a543047eb5c6caa745ab785627c29aa050f3fe6.zip
FreeBSD-src-9a543047eb5c6caa745ab785627c29aa050f3fe6.tar.gz
Update chio(1) and ch(4) to support reporting element designators.
This allows mapping a tape drive in a changer (as reported by 'chio status') to a sa(4) driver instance by comparing the serial numbers. The designators can be ASCII (which is printed out directly), binary (which is printed in hex format) or UTF-8, which is printed in either native UTF-8 format if the terminal can support it, or in %XX notation for non-ASCII characters. Thanks to Hiroki Sato <hrs@> for the explaining UTF-8 printing and example UTF-8 printing code. chio.h: Modify the changer_element_status structure to add new fields and definitions from the SMC3r16 spec. Rename the original CHIOGSTATUS ioctl to OCHIOGTATUS and define a new CHIOGSTATUS ioctl. Clean up some tab/space issues. chio.c: For the 'status' subcommand, print the designator field if it is supplied by a device. scsi_ch.h: Add new flags for DVCID and CURDATA to the READ ELEMENT STATUS command structure. Add a read_element_status_device_id structure for the data fields in the new standard. Add new unions, dt_or_obsolete and voltage_devid, to hold and address data from either SCSI-2 or newer devices. scsi_ch.c: Implement support for fetching device IDs with READ ELEMENT STATUS data. Add new arguments to scsi_read_element_status() to allow the user to request the DVCID and CURDATA bits. This isn't compiled into libcam (it's only an internal kernel interface), so we don't need any special handling for the API change. If the user issues the new CHIOGSTATUS ioctl, copy all of the available element status data out. If he issues the OCHIOGSTATUS ioctl, we don't copy the new fields in the structure. Fix a bug in chopen() that would result in the peripheral never getting unheld if chgetparams() failed. Sponsored by: Spectra Logic Submitted by: Po-Li Soong MFC After: 1 week
Diffstat (limited to 'bin/chio')
-rw-r--r--bin/chio/chio.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/bin/chio/chio.c b/bin/chio/chio.c
index 9bb11d7..5a2a7ba 100644
--- a/bin/chio/chio.c
+++ b/bin/chio/chio.c
@@ -54,6 +54,8 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <langinfo.h>
+#include <locale.h>
#include "defs.h"
#include "pathnames.h"
@@ -81,6 +83,7 @@ static int do_status(const char *, int, char **);
static int do_ielem(const char *, int, char **);
static int do_return(const char *, int, char **);
static int do_voltag(const char *, int, char **);
+static void print_designator(const char *, u_int8_t, u_int8_t);
#ifndef CHET_VT
#define CHET_VT 10 /* Completely Arbitrary */
@@ -723,6 +726,10 @@ do_status(const char *cname, int argc, char **argv)
putchar('?');
putchar('>');
}
+ if (ces->ces_designator_length > 0)
+ print_designator(ces->ces_designator,
+ ces->ces_code_set,
+ ces->ces_designator_length);
putchar('\n');
}
@@ -1177,3 +1184,66 @@ usage(void)
"arg1 arg2 [arg3 [...]]\n", getprogname());
exit(1);
}
+
+#define UTF8CODESET "UTF-8"
+
+static void
+print_designator(const char *designator, u_int8_t code_set,
+ u_int8_t designator_length)
+{
+ printf(" serial number: <");
+ switch (code_set) {
+ case CES_CODE_SET_ASCII: {
+ /*
+ * The driver insures that the string is always NUL terminated.
+ */
+ printf("%s", designator);
+ break;
+ }
+ case CES_CODE_SET_UTF_8: {
+ char *cs_native;
+
+ setlocale(LC_ALL, "");
+ cs_native = nl_langinfo(CODESET);
+
+ /* See if we can natively print UTF-8 */
+ if (strcmp(cs_native, UTF8CODESET) == 0)
+ cs_native = NULL;
+
+ if (cs_native == NULL) {
+ /* We can natively print UTF-8, so use printf. */
+ printf("%s", designator);
+ } else {
+ int i;
+
+ /*
+ * We can't natively print UTF-8. We should
+ * convert it to the terminal's codeset, but that
+ * requires iconv(3) and FreeBSD doesn't have
+ * iconv(3) in the base system yet. So we use %XX
+ * notation for non US-ASCII characters instead.
+ */
+ for (i = 0; i < designator_length &&
+ designator[i] != '\0'; i++) {
+ if ((unsigned char)designator[i] < 0x80)
+ printf("%c", designator[i]);
+ else
+ printf("%%%02x",
+ (unsigned char)designator[i]);
+ }
+ }
+ break;
+ }
+ case CES_CODE_SET_BINARY: {
+ int i;
+
+ for (i = 0; i < designator_length; i++)
+ printf("%02X%s", designator[i],
+ (i == designator_length - 1) ? "" : " ");
+ break;
+ }
+ default:
+ break;
+ }
+ printf(">");
+}
OpenPOWER on IntegriCloud