2 * Copyright (c) 2000 Kelly Yancey <kbyanc@posi.net>
3 * Derived from work done by Julian Elischer <julian@tfs.com,
4 * julian@dialix.oz.au>, 1993, and Peter Dufault <dufault@hda.com>, 1994.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 static const char rcsid[] =
31 "$FreeBSD: src/sbin/camcontrol/modeedit.c,v 1.5.2.2 2003/01/08 17:55:02 njl Exp $";
34 #include <sys/queue.h>
35 #include <sys/types.h>
47 #include <cam/scsi/scsi_all.h>
49 #include <cam/cam_ccb.h>
51 #include "camcontrol.h"
55 #define DEFAULT_SCSI_MODE_DB "/usr/share/misc/scsi_modes"
56 #define DEFAULT_EDITOR "vi"
57 #define MAX_FORMAT_SPEC 4096 /* Max CDB format specifier. */
58 #define MAX_PAGENUM_LEN 10 /* Max characters in page num. */
59 #define MAX_PAGENAME_LEN 64 /* Max characters in page name. */
60 #define PAGEDEF_START '{' /* Page definition delimiter. */
61 #define PAGEDEF_END '}' /* Page definition delimiter. */
62 #define PAGENAME_START '"' /* Page name delimiter. */
63 #define PAGENAME_END '"' /* Page name delimiter. */
64 #define PAGEENTRY_END ';' /* Page entry terminator (optional). */
65 #define MAX_COMMAND_SIZE 255 /* Mode/Log sense data buffer size. */
66 #define PAGE_CTRL_SHIFT 6 /* Bit offset to page control field. */
69 /* Macros for working with mode pages. */
70 #define MODE_PAGE_HEADER(mh) \
71 (struct scsi_mode_page_header *)find_mode_page_6(mh)
73 #define MODE_PAGE_DATA(mph) \
74 (u_int8_t *)(mph) + sizeof(struct scsi_mode_page_header)
78 STAILQ_ENTRY(editentry) link;
88 STAILQ_HEAD(, editentry) editlist; /* List of page entries. */
89 int editlist_changed = 0; /* Whether any entries were changed. */
92 SLIST_ENTRY(pagename) link;
96 SLIST_HEAD(, pagename) namelist; /* Page number to name mappings. */
98 static char format[MAX_FORMAT_SPEC]; /* Buffer for scsi cdb format def. */
100 static FILE *edit_file = NULL; /* File handle for edit file. */
101 static char edit_path[] = "/tmp/camXXXXXX";
104 /* Function prototypes. */
105 static void editentry_create(void *hook, int letter, void *arg,
106 int count, char *name);
107 static void editentry_update(void *hook, int letter, void *arg,
108 int count, char *name);
109 static int editentry_save(void *hook, char *name);
110 static struct editentry *editentry_lookup(char *name);
111 static int editentry_set(char *name, char *newvalue,
113 static void editlist_populate(struct cam_device *device,
114 int modepage, int page_control,
115 int dbd, int retries, int timeout);
116 static void editlist_save(struct cam_device *device, int modepage,
117 int page_control, int dbd, int retries,
119 static void nameentry_create(int pagenum, char *name);
120 static struct pagename *nameentry_lookup(int pagenum);
121 static int load_format(char *pagedb_path, int page);
122 static int modepage_write(FILE *file, int editonly);
123 static int modepage_read(FILE *file);
124 static void modepage_edit(void);
125 static void modepage_dump(struct cam_device *device, int page,
126 int page_control, int dbd, int retries,
128 static void cleanup_editfile(void);
129 void mode_edit(struct cam_device *device, int page,
130 int page_control, int dbd, int edit,
131 int binary, int retry_count, int timeout);
132 void mode_list(struct cam_device *device, int page_control,
133 int dbd, int retry_count, int timeout);
136 #define returnerr(code) do { \
142 #define RTRIM(string) do { \
144 while (isspace(string[_length = strlen(string) - 1])) \
145 string[_length] = '\0'; \
150 editentry_create(void *hook, int letter, void *arg, int count, char *name)
152 struct editentry *newentry; /* Buffer to hold new entry. */
154 /* Allocate memory for the new entry and a copy of the entry name. */
155 if ((newentry = malloc(sizeof(struct editentry))) == NULL ||
156 (newentry->name = strdup(name)) == NULL)
159 /* Trim any trailing whitespace for the entry name. */
160 RTRIM(newentry->name);
162 newentry->editable = (arg != NULL);
163 newentry->type = letter;
164 newentry->size = count; /* Placeholder; not accurate. */
165 newentry->value.svalue = NULL;
167 STAILQ_INSERT_TAIL(&editlist, newentry, link);
171 editentry_update(void *hook, int letter, void *arg, int count, char *name)
173 struct editentry *dest; /* Buffer to hold entry to update. */
175 dest = editentry_lookup(name);
176 assert(dest != NULL);
179 dest->size = count; /* We get the real size now. */
181 switch (dest->type) {
182 case 'i': /* Byte-sized integral type. */
183 case 'b': /* Bit-sized integral types. */
185 dest->value.ivalue = (intptr_t)arg;
188 case 'c': /* Character array. */
189 case 'z': /* Null-padded string. */
190 editentry_set(name, (char *)arg, 0);
198 editentry_save(void *hook, char *name)
200 struct editentry *src; /* Entry value to save. */
202 src = editentry_lookup(name);
206 case 'i': /* Byte-sized integral type. */
207 case 'b': /* Bit-sized integral types. */
209 return (src->value.ivalue);
212 case 'c': /* Character array. */
213 case 'z': /* Null-padded string. */
214 return ((intptr_t)src->value.svalue);
221 return (0); /* This should never happen. */
224 static struct editentry *
225 editentry_lookup(char *name)
227 struct editentry *scan;
229 assert(name != NULL);
231 STAILQ_FOREACH(scan, &editlist, link) {
232 if (strcasecmp(scan->name, name) == 0)
236 /* Not found during list traversal. */
241 editentry_set(char *name, char *newvalue, int editonly)
243 struct editentry *dest; /* Modepage entry to update. */
244 char *cval; /* Pointer to new string value. */
245 char *convertend; /* End-of-conversion pointer. */
246 int ival; /* New integral value. */
247 int resolution; /* Resolution in bits for integer conversion. */
250 * Macro to determine the maximum value of the given size for the current
252 * XXX Lovely x86's optimize out the case of shifting by 32 and gcc doesn't
253 * currently workaround it (even for int64's), so we have to kludge it.
255 #define RESOLUTION_MAX(size) ((resolution * (size) == 32)? \
256 0xffffffff: (1 << (resolution * (size))) - 1)
258 assert(newvalue != NULL);
259 if (*newvalue == '\0')
260 return (0); /* Nothing to do. */
262 if ((dest = editentry_lookup(name)) == NULL)
264 if (!dest->editable && editonly)
267 switch (dest->type) {
268 case 'i': /* Byte-sized integral type. */
269 case 'b': /* Bit-sized integral types. */
271 /* Convert the value string to an integer. */
272 resolution = (dest->type == 'i')? 8: 1;
273 ival = (int)strtol(newvalue, &convertend, 0);
274 if (*convertend != '\0')
276 if (ival > RESOLUTION_MAX(dest->size) || ival < 0) {
277 int newival = (ival < 0)? 0: RESOLUTION_MAX(dest->size);
278 warnx("value %d is out of range for entry %s; clipping "
279 "to %d", ival, name, newival);
282 if (dest->value.ivalue != ival)
283 editlist_changed = 1;
284 dest->value.ivalue = ival;
287 case 'c': /* Character array. */
288 case 'z': /* Null-padded string. */
289 if ((cval = malloc(dest->size + 1)) == NULL)
291 bzero(cval, dest->size + 1);
292 strncpy(cval, newvalue, dest->size);
293 if (dest->type == 'z') {
294 /* Convert trailing spaces to nulls. */
297 for (convertend = cval + dest->size;
298 convertend >= cval; convertend--) {
299 if (*convertend == ' ')
301 else if (*convertend != '\0')
305 if (strncmp(dest->value.svalue, cval, dest->size) == 0) {
306 /* Nothing changed, free the newly allocated string. */
310 if (dest->value.svalue != NULL) {
311 /* Free the current string buffer. */
312 free(dest->value.svalue);
313 dest->value.svalue = NULL;
315 dest->value.svalue = cval;
316 editlist_changed = 1;
324 #undef RESOLUTION_MAX
328 nameentry_create(int pagenum, char *name) {
329 struct pagename *newentry;
331 if (pagenum < 0 || name == NULL || name[0] == '\0')
334 /* Allocate memory for the new entry and a copy of the entry name. */
335 if ((newentry = malloc(sizeof(struct pagename))) == NULL ||
336 (newentry->name = strdup(name)) == NULL)
339 /* Trim any trailing whitespace for the page name. */
340 RTRIM(newentry->name);
342 newentry->pagenum = pagenum;
343 SLIST_INSERT_HEAD(&namelist, newentry, link);
346 static struct pagename *
347 nameentry_lookup(int pagenum) {
348 struct pagename *scan;
350 SLIST_FOREACH(scan, &namelist, link) {
351 if (pagenum == scan->pagenum)
355 /* Not found during list traversal. */
360 load_format(char *pagedb_path, int page)
363 char str_pagenum[MAX_PAGENUM_LEN];
364 char str_pagename[MAX_PAGENAME_LEN];
366 int depth; /* Quoting depth. */
369 enum { LOCATE, PAGENAME, PAGEDEF } state;
372 #define SETSTATE_LOCATE do { \
373 str_pagenum[0] = '\0'; \
374 str_pagename[0] = '\0'; \
379 #define SETSTATE_PAGENAME do { \
380 str_pagename[0] = '\0'; \
384 #define SETSTATE_PAGEDEF do { \
389 #define UPDATE_LINENO do { \
394 #define BUFFERFULL(buffer) (strlen(buffer) + 1 >= sizeof(buffer))
396 if ((pagedb = fopen(pagedb_path, "r")) == NULL)
399 SLIST_INIT(&namelist);
405 while ((c = fgetc(pagedb)) != EOF) {
407 /* Keep a line count to make error messages more useful. */
410 /* Skip over comments anywhere in the mode database. */
414 } while (c != '\n' && c != EOF);
419 /* Strip out newline characters. */
423 /* Keep track of the nesting depth for braces. */
424 if (c == PAGEDEF_START)
426 else if (c == PAGEDEF_END) {
429 errx(EX_OSFILE, "%s:%d: %s", pagedb_path,
430 lineno, "mismatched bracket");
437 * Locate the page the user is interested in, skipping
441 /* Ignore all whitespace between pages. */
443 } else if (depth == 0 && c == PAGEENTRY_END) {
445 * A page entry terminator will reset page
446 * scanning (useful for assigning names to
447 * modes without providing a mode definition).
449 /* Record the name of this page. */
450 pagenum = strtol(str_pagenum, NULL, 0);
451 nameentry_create(pagenum, str_pagename);
453 } else if (depth == 0 && c == PAGENAME_START) {
455 } else if (c == PAGEDEF_START) {
456 pagenum = strtol(str_pagenum, NULL, 0);
458 /* Record the name of this page. */
459 nameentry_create(pagenum, str_pagename);
461 * Only record the format if this is
462 * the page we are interested in.
464 if (page == pagenum && !found)
467 } else if (c == PAGEDEF_END) {
468 /* Reset the processor state. */
470 } else if (depth == 0 && ! BUFFERFULL(str_pagenum)) {
471 strncat(str_pagenum, &c, 1);
472 } else if (depth == 0) {
473 errx(EX_OSFILE, "%s:%d: %s %d %s", pagedb_path,
474 lineno, "page identifier exceeds",
475 sizeof(str_pagenum) - 1, "characters");
480 if (c == PAGENAME_END) {
482 * Return to LOCATE state without resetting the
483 * page number buffer.
486 } else if (! BUFFERFULL(str_pagename)) {
487 strncat(str_pagename, &c, 1);
489 errx(EX_OSFILE, "%s:%d: %s %d %s", pagedb_path,
490 lineno, "page name exceeds",
491 sizeof(str_pagenum) - 1, "characters");
497 * Transfer the page definition into a format buffer
498 * suitable for use with CDB encoding/decoding routines.
503 } else if (! BUFFERFULL(format)) {
504 strncat(format, &c, 1);
506 errx(EX_OSFILE, "%s:%d: %s %d %s", pagedb_path,
507 lineno, "page definition exceeds",
508 sizeof(format) - 1, "characters");
516 /* Repeat processing loop with next character. */
520 err(EX_OSFILE, "%s", pagedb_path);
522 /* Close the SCSI page database. */
525 if (!found) /* Never found a matching page. */
532 editlist_populate(struct cam_device *device, int modepage, int page_control,
533 int dbd, int retries, int timeout)
535 u_int8_t data[MAX_COMMAND_SIZE];/* Buffer to hold sense data. */
536 u_int8_t *mode_pars; /* Pointer to modepage params. */
537 struct scsi_mode_header_6 *mh; /* Location of mode header. */
538 struct scsi_mode_page_header *mph;
540 STAILQ_INIT(&editlist);
542 /* Fetch changeable values; use to build initial editlist. */
543 mode_sense(device, modepage, 1, dbd, retries, timeout, data,
546 mh = (struct scsi_mode_header_6 *)data;
547 mph = MODE_PAGE_HEADER(mh);
548 mode_pars = MODE_PAGE_DATA(mph);
550 /* Decode the value data, creating edit_entries for each value. */
551 buff_decode_visit(mode_pars, mh->data_length, format,
552 editentry_create, 0);
554 /* Fetch the current/saved values; use to set editentry values. */
555 mode_sense(device, modepage, page_control, dbd, retries, timeout, data,
557 buff_decode_visit(mode_pars, mh->data_length, format,
558 editentry_update, 0);
562 editlist_save(struct cam_device *device, int modepage, int page_control,
563 int dbd, int retries, int timeout)
565 u_int8_t data[MAX_COMMAND_SIZE];/* Buffer to hold sense data. */
566 u_int8_t *mode_pars; /* Pointer to modepage params. */
567 struct scsi_mode_header_6 *mh; /* Location of mode header. */
568 struct scsi_mode_page_header *mph;
570 /* Make sure that something changed before continuing. */
571 if (! editlist_changed)
575 * Preload the CDB buffer with the current mode page data.
576 * XXX If buff_encode_visit would return the number of bytes encoded
577 * we *should* use that to build a header from scratch. As it is
578 * now, we need mode_sense to find out the page length.
580 mode_sense(device, modepage, page_control, dbd, retries, timeout, data,
583 /* Initial headers & offsets. */
584 mh = (struct scsi_mode_header_6 *)data;
585 mph = MODE_PAGE_HEADER(mh);
586 mode_pars = MODE_PAGE_DATA(mph);
588 /* Encode the value data to be passed back to the device. */
589 buff_encode_visit(mode_pars, mh->data_length, format,
592 /* Eliminate block descriptors. */
593 bcopy(mph, ((u_int8_t *)mh) + sizeof(*mh),
594 sizeof(*mph) + mph->page_length);
596 /* Recalculate headers & offsets. */
597 mh->blk_desc_len = 0; /* No block descriptors. */
598 mh->dev_spec = 0; /* Clear device-specific parameters. */
599 mph = MODE_PAGE_HEADER(mh);
600 mode_pars = MODE_PAGE_DATA(mph);
602 mph->page_code &= SMS_PAGE_CODE;/* Isolate just the page code. */
603 mh->data_length = 0; /* Reserved for MODE SELECT command. */
606 * Write the changes back to the device. If the user editted control
607 * page 3 (saved values) then request the changes be permanently
611 (page_control << PAGE_CTRL_SHIFT == SMS_PAGE_CTRL_SAVED),
612 retries, timeout, (u_int8_t *)mh,
613 sizeof(*mh) + mh->blk_desc_len + sizeof(*mph) + mph->page_length);
617 modepage_write(FILE *file, int editonly)
619 struct editentry *scan;
622 STAILQ_FOREACH(scan, &editlist, link) {
623 if (scan->editable || !editonly) {
625 if (scan->type == 'c' || scan->type == 'z') {
626 fprintf(file, "%s: %s\n", scan->name,
629 fprintf(file, "%s: %d\n", scan->name,
638 modepage_read(FILE *file)
640 char *buffer; /* Pointer to dynamic line buffer. */
641 char *line; /* Pointer to static fgetln buffer. */
642 char *name; /* Name portion of the line buffer. */
643 char *value; /* Value portion of line buffer. */
644 int length; /* Length of static fgetln buffer. */
646 #define ABORT_READ(message, param) do { \
647 warnx(message, param); \
652 while ((line = fgetln(file, &length)) != NULL) {
653 /* Trim trailing whitespace (including optional newline). */
654 while (length > 0 && isspace(line[length - 1]))
657 /* Allocate a buffer to hold the line + terminating null. */
658 if ((buffer = malloc(length + 1)) == NULL)
660 memcpy(buffer, line, length);
661 buffer[length] = '\0';
663 /* Strip out comments. */
664 if ((value = strchr(buffer, '#')) != NULL)
667 /* The name is first in the buffer. Trim whitespace.*/
670 while (isspace(*name))
673 /* Skip empty lines. */
674 if (strlen(name) == 0)
677 /* The name ends at the colon; the value starts there. */
678 if ((value = strrchr(buffer, ':')) == NULL)
679 ABORT_READ("no value associated with %s", name);
680 *value = '\0'; /* Null-terminate name. */
681 value++; /* Value starts afterwards. */
683 /* Trim leading and trailing whitespace. */
685 while (isspace(*value))
688 /* Make sure there is a value left. */
689 if (strlen(value) == 0)
690 ABORT_READ("no value associated with %s", name);
692 /* Update our in-memory copy of the modepage entry value. */
693 if (editentry_set(name, value, 1) != 0) {
694 if (errno == ENOENT) {
695 /* No entry by the name. */
696 ABORT_READ("no such modepage entry \"%s\"",
698 } else if (errno == EINVAL) {
700 ABORT_READ("Invalid value for entry \"%s\"",
702 } else if (errno == ERANGE) {
703 /* Value out of range for entry type. */
704 ABORT_READ("value out of range for %s", name);
705 } else if (errno == EPERM) {
706 /* Entry is not editable; not fatal. */
707 warnx("modepage entry \"%s\" is read-only; "
714 return (ferror(file)? -1: 0);
727 if (!isatty(fileno(stdin))) {
728 /* Not a tty, read changes from stdin. */
729 modepage_read(stdin);
733 /* Lookup editor to invoke. */
734 if ((editor = getenv("EDITOR")) == NULL)
735 editor = DEFAULT_EDITOR;
737 /* Create temp file for editor to modify. */
738 if ((fd = mkstemp(edit_path)) == -1)
739 errx(EX_CANTCREAT, "mkstemp failed");
741 atexit(cleanup_editfile);
743 if ((edit_file = fdopen(fd, "w")) == NULL)
744 err(EX_NOINPUT, "%s", edit_path);
746 written = modepage_write(edit_file, 1);
752 warnx("no editable entries");
758 * Allocate memory to hold the command line (the 2 extra characters
759 * are to hold the argument separator (a space), and the terminating
762 commandline = malloc(strlen(editor) + strlen(edit_path) + 2);
763 if (commandline == NULL)
765 sprintf(commandline, "%s %s", editor, edit_path);
767 /* Invoke the editor on the temp file. */
768 if (system(commandline) == -1)
769 err(EX_UNAVAILABLE, "could not invoke %s", editor);
772 if ((edit_file = fopen(edit_path, "r")) == NULL)
773 err(EX_NOINPUT, "%s", edit_path);
775 /* Read any changes made to the temp file. */
776 modepage_read(edit_file);
782 modepage_dump(struct cam_device *device, int page, int page_control, int dbd,
783 int retries, int timeout)
785 u_int8_t data[MAX_COMMAND_SIZE];/* Buffer to hold sense data. */
786 u_int8_t *mode_pars; /* Pointer to modepage params. */
787 struct scsi_mode_header_6 *mh; /* Location of mode header. */
788 struct scsi_mode_page_header *mph;
789 int index; /* Index for scanning mode params. */
791 mode_sense(device, page, page_control, dbd, retries, timeout, data,
794 mh = (struct scsi_mode_header_6 *)data;
795 mph = MODE_PAGE_HEADER(mh);
796 mode_pars = MODE_PAGE_DATA(mph);
798 /* Print the raw mode page data with newlines each 8 bytes. */
799 for (index = 0; index < mph->page_length; index++) {
800 printf("%02x%c",mode_pars[index],
801 (((index + 1) % 8) == 0) ? '\n' : ' ');
807 cleanup_editfile(void)
809 if (edit_file == NULL)
811 if (fclose(edit_file) != 0 || unlink(edit_path) != 0)
812 warn("%s", edit_path);
817 mode_edit(struct cam_device *device, int page, int page_control, int dbd,
818 int edit, int binary, int retry_count, int timeout)
820 char *pagedb_path; /* Path to modepage database. */
823 errx(EX_USAGE, "cannot edit in binary mode.");
826 if ((pagedb_path = getenv("SCSI_MODES")) == NULL)
827 pagedb_path = DEFAULT_SCSI_MODE_DB;
829 if (load_format(pagedb_path, page) != 0 && (edit || verbose)) {
830 if (errno == ENOENT) {
831 /* Modepage database file not found. */
832 warn("cannot open modepage database \"%s\"",
834 } else if (errno == ESRCH) {
835 /* Modepage entry not found in database. */
836 warnx("modepage %d not found in database"
837 "\"%s\"", page, pagedb_path);
839 /* We can recover in display mode, otherwise we exit. */
841 warnx("reverting to binary display only");
847 editlist_populate(device, page, page_control, dbd, retry_count,
852 if (page_control << PAGE_CTRL_SHIFT != SMS_PAGE_CTRL_CURRENT &&
853 page_control << PAGE_CTRL_SHIFT != SMS_PAGE_CTRL_SAVED)
854 errx(EX_USAGE, "it only makes sense to edit page 0 "
855 "(current) or page 3 (saved values)");
857 editlist_save(device, page, page_control, dbd, retry_count,
859 } else if (binary || STAILQ_EMPTY(&editlist)) {
860 /* Display without formatting information. */
861 modepage_dump(device, page, page_control, dbd, retry_count,
864 /* Display with format. */
865 modepage_write(stdout, 0);
870 mode_list(struct cam_device *device, int page_control, int dbd,
871 int retry_count, int timeout)
873 u_int8_t data[MAX_COMMAND_SIZE];/* Buffer to hold sense data. */
874 u_int8_t *mode_pars; /* Pointer to modepage params. */
875 struct scsi_mode_header_6 *mh; /* Location of mode header. */
876 struct scsi_mode_page_header *mph;
877 struct pagename *nameentry;
881 if ((pagedb_path = getenv("SCSI_MODES")) == NULL)
882 pagedb_path = DEFAULT_SCSI_MODE_DB;
884 if (load_format(pagedb_path, 0) != 0 && verbose && errno == ENOENT) {
885 /* Modepage database file not found. */
886 warn("cannot open modepage database \"%s\"", pagedb_path);
889 /* Build the list of all mode pages by querying the "all pages" page. */
890 mode_sense(device, SMS_ALL_PAGES_PAGE, page_control, dbd, retry_count,
891 timeout, data, sizeof(data));
893 mh = (struct scsi_mode_header_6 *)data;
894 len = mh->blk_desc_len; /* Skip block descriptors. */
895 /* Iterate through the pages in the reply. */
896 while (len < mh->data_length) {
897 /* Locate the next mode page header. */
898 mph = (struct scsi_mode_page_header *)
899 ((intptr_t)mh + sizeof(*mh) + len);
900 mode_pars = MODE_PAGE_DATA(mph);
902 mph->page_code &= SMS_PAGE_CODE;
903 nameentry = nameentry_lookup(mph->page_code);
905 if (nameentry == NULL || nameentry->name == NULL)
906 printf("0x%02x\n", mph->page_code);
908 printf("0x%02x\t%s\n", mph->page_code,
910 len += mph->page_length + sizeof(*mph);