diff options
Diffstat (limited to 'sys/cam/cam.c')
-rw-r--r-- | sys/cam/cam.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/sys/cam/cam.c b/sys/cam/cam.c index 939dd76c3068..1f627ef1e63c 100644 --- a/sys/cam/cam.c +++ b/sys/cam/cam.c @@ -157,6 +157,56 @@ cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen) *dst = '\0'; } +void +cam_strvis_sbuf(struct sbuf *sb, const u_int8_t *src, int srclen, + uint32_t flags) +{ + + /* Trim leading/trailing spaces, nulls. */ + while (srclen > 0 && src[0] == ' ') + src++, srclen--; + while (srclen > 0 + && (src[srclen-1] == ' ' || src[srclen-1] == '\0')) + srclen--; + + while (srclen > 0) { + if (*src < 0x20 || *src >= 0x80) { + /* SCSI-II Specifies that these should never occur. */ + /* non-printable character */ + switch (flags & CAM_STRVIS_FLAG_NONASCII_MASK) { + case CAM_STRVIS_FLAG_NONASCII_ESC: + sbuf_printf(sb, "\\%c%c%c", + ((*src & 0300) >> 6) + '0', + ((*src & 0070) >> 3) + '0', + ((*src & 0007) >> 0) + '0'); + break; + case CAM_STRVIS_FLAG_NONASCII_RAW: + /* + * If we run into a NUL, just transform it + * into a space. + */ + if (*src != 0x00) + sbuf_putc(sb, *src); + else + sbuf_putc(sb, ' '); + break; + case CAM_STRVIS_FLAG_NONASCII_SPC: + sbuf_putc(sb, ' '); + break; + case CAM_STRVIS_FLAG_NONASCII_TRIM: + default: + break; + } + } else { + /* normal character */ + sbuf_putc(sb, *src); + } + src++; + srclen--; + } +} + + /* * Compare string with pattern, returning 0 on match. * Short pattern matches trailing blanks in name, |