Module Name: src
Committed By: christos
Date: Mon May 2 19:18:29 UTC 2016
Modified Files:
src/sys/dev/ata: ld_ataraid.c
src/sys/dev/ic: ahcisata_core.c mpt_netbsd.c mvsata.c nvme.c siisata.c
src/sys/dev/pci: arcmsr.c mpii.c
src/sys/dev/scsipi: atapi_wdc.c scsiconf.c scsipiconf.c scsipiconf.h
src/sys/dev/usb: umass_scsipi.c
src/sys/lib/libkern: Makefile.libkern libkern.h
Added Files:
src/sys/lib/libkern: strnvisx.c
Log Message:
move scsipi_strvis -> libkern:strnvisx()
change the prototype to match userland
fix sizes of strings passed to it
To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/dev/ata/ld_ataraid.c
cvs rdiff -u -r1.55 -r1.56 src/sys/dev/ic/ahcisata_core.c
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/ic/mpt_netbsd.c
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/ic/mvsata.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/ic/nvme.c
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/ic/siisata.c
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/pci/arcmsr.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/pci/mpii.c
cvs rdiff -u -r1.121 -r1.122 src/sys/dev/scsipi/atapi_wdc.c
cvs rdiff -u -r1.273 -r1.274 src/sys/dev/scsipi/scsiconf.c
cvs rdiff -u -r1.40 -r1.41 src/sys/dev/scsipi/scsipiconf.c
cvs rdiff -u -r1.122 -r1.123 src/sys/dev/scsipi/scsipiconf.h
cvs rdiff -u -r1.50 -r1.51 src/sys/dev/usb/umass_scsipi.c
cvs rdiff -u -r1.38 -r1.39 src/sys/lib/libkern/Makefile.libkern
cvs rdiff -u -r1.121 -r1.122 src/sys/lib/libkern/libkern.h
cvs rdiff -u -r0 -r1.1 src/sys/lib/libkern/strnvisx.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/ata/ld_ataraid.c
diff -u src/sys/dev/ata/ld_ataraid.c:1.40 src/sys/dev/ata/ld_ataraid.c:1.41
--- src/sys/dev/ata/ld_ataraid.c:1.40 Mon Apr 13 12:33:24 2015
+++ src/sys/dev/ata/ld_ataraid.c Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: ld_ataraid.c,v 1.40 2015/04/13 16:33:24 riastradh Exp $ */
+/* $NetBSD: ld_ataraid.c,v 1.41 2016/05/02 19:18:29 christos Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@@ -47,7 +47,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_ataraid.c,v 1.40 2015/04/13 16:33:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_ataraid.c,v 1.41 2016/05/02 19:18:29 christos Exp $");
#include "bio.h"
@@ -698,12 +698,12 @@ ld_ataraid_biodisk(struct ld_ataraid_sof
strlcpy(bd->bd_procdev, device_xname(adi->adi_dev),
sizeof(bd->bd_procdev));
- scsipi_strvis(serial, sizeof(serial), wd->sc_params.atap_serial,
- sizeof(wd->sc_params.atap_serial));
- scsipi_strvis(model, sizeof(model), wd->sc_params.atap_model,
- sizeof(wd->sc_params.atap_model));
- scsipi_strvis(rev, sizeof(rev), wd->sc_params.atap_revision,
- sizeof(wd->sc_params.atap_revision));
+ strnvisx(serial, sizeof(serial), wd->sc_params.atap_serial,
+ sizeof(wd->sc_params.atap_serial), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(model, sizeof(model), wd->sc_params.atap_model,
+ sizeof(wd->sc_params.atap_model), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(rev, sizeof(rev), wd->sc_params.atap_revision,
+ sizeof(wd->sc_params.atap_revision), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
snprintf(bd->bd_vendor, sizeof(bd->bd_vendor), "%s %s", model, rev);
strlcpy(bd->bd_serial, serial, sizeof(bd->bd_serial));
Index: src/sys/dev/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.55 src/sys/dev/ic/ahcisata_core.c:1.56
--- src/sys/dev/ic/ahcisata_core.c:1.55 Tue Nov 10 21:43:09 2015
+++ src/sys/dev/ic/ahcisata_core.c Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: ahcisata_core.c,v 1.55 2015/11/11 02:43:09 jakllsch Exp $ */
+/* $NetBSD: ahcisata_core.c,v 1.56 2016/05/02 19:18:29 christos Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.55 2015/11/11 02:43:09 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.56 2016/05/02 19:18:29 christos Exp $");
#include <sys/types.h>
#include <sys/malloc.h>
@@ -1846,11 +1846,12 @@ ahci_atapi_probe_device(struct atapibus_
sa.sa_inqbuf.type = ATAPI_CFG_TYPE(id->atap_config);
sa.sa_inqbuf.removable = id->atap_config & ATAPI_CFG_REMOV ?
T_REMOV : T_FIXED;
- scsipi_strvis((u_char *)model, 40, id->atap_model, 40);
- scsipi_strvis((u_char *)serial_number, 20, id->atap_serial,
- 20);
- scsipi_strvis((u_char *)firmware_revision, 8,
- id->atap_revision, 8);
+ strnvisx(model, sizeof(model), id->atap_model, 40,
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(serial_number, sizeof(serial_number), id->atap_serial,
+ 20, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(firmware_revision, sizeof(firmware_revision),
+ id->atap_revision, 8, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
sa.sa_inqbuf.vendor = model;
sa.sa_inqbuf.product = serial_number;
sa.sa_inqbuf.revision = firmware_revision;
Index: src/sys/dev/ic/mpt_netbsd.c
diff -u src/sys/dev/ic/mpt_netbsd.c:1.32 src/sys/dev/ic/mpt_netbsd.c:1.33
--- src/sys/dev/ic/mpt_netbsd.c:1.32 Wed Jul 22 04:33:51 2015
+++ src/sys/dev/ic/mpt_netbsd.c Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: mpt_netbsd.c,v 1.32 2015/07/22 08:33:51 hannken Exp $ */
+/* $NetBSD: mpt_netbsd.c,v 1.33 2016/05/02 19:18:29 christos Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mpt_netbsd.c,v 1.32 2015/07/22 08:33:51 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpt_netbsd.c,v 1.33 2016/05/02 19:18:29 christos Exp $");
#include "bio.h"
@@ -1857,12 +1857,15 @@ mpt_bio_ioctl_vol(mpt_softc_t *mpt, stru
memset(&inqbuf, 0, sizeof(inqbuf));
if (scsipi_inquire(periph, &inqbuf,
XS_CTL_DISCOVERY | XS_CTL_SILENT) == 0) {
- scsipi_strvis(vendor, sizeof(vendor),
- inqbuf.vendor, sizeof(inqbuf.vendor));
- scsipi_strvis(product, sizeof(product),
- inqbuf.product, sizeof(inqbuf.product));
- scsipi_strvis(revision, sizeof(revision),
- inqbuf.revision, sizeof(inqbuf.revision));
+ strnvisx(vendor, sizeof(vendor),
+ inqbuf.vendor, sizeof(inqbuf.vendor),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(product, sizeof(product),
+ inqbuf.product, sizeof(inqbuf.product),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(revision, sizeof(revision),
+ inqbuf.revision, sizeof(inqbuf.revision),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
snprintf(bv->bv_vendor, sizeof(bv->bv_vendor),
"%s %s %s", vendor, product, revision);
@@ -1927,13 +1930,16 @@ mpt_bio_ioctl_disk_common(mpt_softc_t *m
if (phys == NULL)
return;
- scsipi_strvis(vendor_id, sizeof(vendor_id),
- phys->InquiryData.VendorID, sizeof(phys->InquiryData.VendorID));
- scsipi_strvis(product_id, sizeof(product_id),
- phys->InquiryData.ProductID, sizeof(phys->InquiryData.ProductID));
- scsipi_strvis(product_rev_level, sizeof(product_rev_level),
+ strnvisx(vendor_id, sizeof(vendor_id),
+ phys->InquiryData.VendorID, sizeof(phys->InquiryData.VendorID),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(product_id, sizeof(product_id),
+ phys->InquiryData.ProductID, sizeof(phys->InquiryData.ProductID),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(product_rev_level, sizeof(product_rev_level),
phys->InquiryData.ProductRevLevel,
- sizeof(phys->InquiryData.ProductRevLevel));
+ sizeof(phys->InquiryData.ProductRevLevel),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
snprintf(bd->bd_vendor, sizeof(bd->bd_vendor), "%s %s %s",
vendor_id, product_id, product_rev_level);
Index: src/sys/dev/ic/mvsata.c
diff -u src/sys/dev/ic/mvsata.c:1.34 src/sys/dev/ic/mvsata.c:1.35
--- src/sys/dev/ic/mvsata.c:1.34 Fri Jan 2 14:42:07 2015
+++ src/sys/dev/ic/mvsata.c Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: mvsata.c,v 1.34 2015/01/02 19:42:07 christos Exp $ */
+/* $NetBSD: mvsata.c,v 1.35 2016/05/02 19:18:29 christos Exp $ */
/*
* Copyright (c) 2008 KIYOHARA Takashi
* All rights reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.34 2015/01/02 19:42:07 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35 2016/05/02 19:18:29 christos Exp $");
#include "opt_mvsata.h"
@@ -888,10 +888,12 @@ mvsata_atapi_probe_device(struct atapibu
sa.sa_inqbuf.type = ATAPI_CFG_TYPE(id->atap_config);
sa.sa_inqbuf.removable = id->atap_config & ATAPI_CFG_REMOV ?
T_REMOV : T_FIXED;
- scsipi_strvis((u_char *)model, 40, id->atap_model, 40);
- scsipi_strvis((u_char *)serial_number, 20, id->atap_serial, 20);
- scsipi_strvis((u_char *)firmware_revision, 8, id->atap_revision,
- 8);
+ strnvisx(model, sizeof(model), id->atap_model, 40,
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(serial_number, sizeof(serial_number), id->atap_serial,
+ 20, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(firmware_revision, sizeof(firmware_revision),
+ id->atap_revision, 8, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
sa.sa_inqbuf.vendor = model;
sa.sa_inqbuf.product = serial_number;
sa.sa_inqbuf.revision = firmware_revision;
Index: src/sys/dev/ic/nvme.c
diff -u src/sys/dev/ic/nvme.c:1.1 src/sys/dev/ic/nvme.c:1.2
--- src/sys/dev/ic/nvme.c:1.1 Sun May 1 06:21:02 2016
+++ src/sys/dev/ic/nvme.c Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: nvme.c,v 1.1 2016/05/01 10:21:02 nonaka Exp $ */
+/* $NetBSD: nvme.c,v 1.2 2016/05/02 19:18:29 christos Exp $ */
/* $OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
/*
@@ -18,7 +18,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.1 2016/05/01 10:21:02 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.2 2016/05/02 19:18:29 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -95,8 +95,6 @@ static void nvme_ns_sync_fill(struct nvm
static void nvme_ns_sync_done(struct nvme_queue *, struct nvme_ccb *,
struct nvme_cqe *);
-static void nvme_strvis(u_char *, int, const u_char *, int);
-
#define nvme_read4(_s, _r) \
bus_space_read_4((_s)->sc_iot, (_s)->sc_ioh, (_r))
#define nvme_write4(_s, _r, _v) \
@@ -900,9 +898,12 @@ nvme_identify(struct nvme_softc *sc, u_i
identify = NVME_DMA_KVA(mem);
- nvme_strvis(sn, sizeof(sn), identify->sn, sizeof(identify->sn));
- nvme_strvis(mn, sizeof(mn), identify->mn, sizeof(identify->mn));
- nvme_strvis(fr, sizeof(fr), identify->fr, sizeof(identify->fr));
+ strnvisx(sn, sizeof(sn), (const char *)identify->sn,
+ sizeof(identify->sn), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(mn, sizeof(mn), (const char *)identify->mn,
+ sizeof(identify->mn), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(fr, sizeof(fr), (const char *)identify->fr,
+ sizeof(identify->fr), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
aprint_normal_dev(sc->sc_dev, "%s, firmware %s, serial %s\n", mn, fr,
sn);
@@ -1288,46 +1289,3 @@ nvme_dmamem_free(struct nvme_softc *sc,
bus_dmamap_destroy(sc->sc_dmat, ndm->ndm_map);
kmem_free(ndm, sizeof(*ndm));
}
-
-/*
- * Copy of sys/dev/scsipi/scsipiconf.c:scsipi_strvis()
- */
-static void
-nvme_strvis(u_char *dst, int dlen, const u_char *src, int slen)
-{
-
-#define STRVIS_ISWHITE(x) ((x) == ' ' || (x) == '\0' || (x) == (u_char)'\377')
- /* Trim leading and trailing blanks and NULs. */
- while (slen > 0 && STRVIS_ISWHITE(src[0]))
- ++src, --slen;
- while (slen > 0 && STRVIS_ISWHITE(src[slen - 1]))
- --slen;
-
- while (slen > 0) {
- if (*src < 0x20 || *src >= 0x80) {
- /* non-printable characters */
- dlen -= 4;
- if (dlen < 1)
- break;
- *dst++ = '\\';
- *dst++ = ((*src & 0300) >> 6) + '0';
- *dst++ = ((*src & 0070) >> 3) + '0';
- *dst++ = ((*src & 0007) >> 0) + '0';
- } else if (*src == '\\') {
- /* quote characters */
- dlen -= 2;
- if (dlen < 1)
- break;
- *dst++ = '\\';
- *dst++ = '\\';
- } else {
- /* normal characters */
- if (--dlen < 1)
- break;
- *dst++ = *src;
- }
- ++src, --slen;
- }
-
- *dst++ = 0;
-}
Index: src/sys/dev/ic/siisata.c
diff -u src/sys/dev/ic/siisata.c:1.27 src/sys/dev/ic/siisata.c:1.28
--- src/sys/dev/ic/siisata.c:1.27 Thu Aug 8 13:38:56 2013
+++ src/sys/dev/ic/siisata.c Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.27 2013/08/08 17:38:56 bouyer Exp $ */
+/* $NetBSD: siisata.c,v 1.28 2016/05/02 19:18:29 christos Exp $ */
/* from ahcisata_core.c */
@@ -79,7 +79,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.27 2013/08/08 17:38:56 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.28 2016/05/02 19:18:29 christos Exp $");
#include <sys/types.h>
#include <sys/malloc.h>
@@ -1459,11 +1459,12 @@ siisata_atapi_probe_device(struct atapib
sa.sa_inqbuf.type = ATAPI_CFG_TYPE(id->atap_config);
sa.sa_inqbuf.removable = id->atap_config & ATAPI_CFG_REMOV ?
T_REMOV : T_FIXED;
- scsipi_strvis((u_char *)model, 40, id->atap_model, 40);
- scsipi_strvis((u_char *)serial_number, 20,
- id->atap_serial, 20);
- scsipi_strvis((u_char *)firmware_revision, 8,
- id->atap_revision, 8);
+ strnvisx(model, sizeof(model), id->atap_model, 40,
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(serial_number, sizeof(serial_number),
+ id->atap_serial, 20, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(firmware_revision, sizeof(firmware_revision),
+ id->atap_revision, 8, VIS_TRIM|VIS_SAFE|VIS_OCTAL);
sa.sa_inqbuf.vendor = model;
sa.sa_inqbuf.product = serial_number;
sa.sa_inqbuf.revision = firmware_revision;
Index: src/sys/dev/pci/arcmsr.c
diff -u src/sys/dev/pci/arcmsr.c:1.32 src/sys/dev/pci/arcmsr.c:1.33
--- src/sys/dev/pci/arcmsr.c:1.32 Thu Mar 12 11:33:10 2015
+++ src/sys/dev/pci/arcmsr.c Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: arcmsr.c,v 1.32 2015/03/12 15:33:10 christos Exp $ */
+/* $NetBSD: arcmsr.c,v 1.33 2016/05/02 19:18:29 christos Exp $ */
/* $OpenBSD: arc.c,v 1.68 2007/10/27 03:28:27 dlg Exp $ */
/*
@@ -21,7 +21,7 @@
#include "bio.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: arcmsr.c,v 1.32 2015/03/12 15:33:10 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arcmsr.c,v 1.33 2016/05/02 19:18:29 christos Exp $");
#include <sys/param.h>
#include <sys/buf.h>
@@ -635,15 +635,18 @@ arc_query_firmware(device_t self)
DNPRINTF(ARC_D_INIT, "%s: sata_ports: %d\n",
device_xname(self), htole32(fwinfo.sata_ports));
- scsipi_strvis(string, 81, fwinfo.vendor, sizeof(fwinfo.vendor));
+ strnvisx(string, sizeof(string), fwinfo.vendor, sizeof(fwinfo.vendor),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
DNPRINTF(ARC_D_INIT, "%s: vendor: \"%s\"\n",
device_xname(self), string);
- scsipi_strvis(string, 17, fwinfo.model, sizeof(fwinfo.model));
+ strnvisx(string, sizeof(string), fwinfo.model, sizeof(fwinfo.model),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
aprint_normal_dev(self, "Areca %s Host Adapter RAID controller\n",
string);
- scsipi_strvis(string, 33, fwinfo.fw_version, sizeof(fwinfo.fw_version));
+ strnvisx(string, sizeof(string), fwinfo.fw_version,
+ sizeof(fwinfo.fw_version), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
DNPRINTF(ARC_D_INIT, "%s: version: \"%s\"\n",
device_xname(self), string);
@@ -1328,8 +1331,8 @@ arc_bio_vol(struct arc_softc *sc, struct
bv->bv_nodisk = volinfo->member_disks;
bv->bv_stripe_size = volinfo->stripe_size / 2;
snprintf(bv->bv_dev, sizeof(bv->bv_dev), "sd%d", bv->bv_volid);
- scsipi_strvis(bv->bv_vendor, sizeof(bv->bv_vendor), volinfo->set_name,
- sizeof(volinfo->set_name));
+ strnvisx(bv->bv_vendor, sizeof(bv->bv_vendor), volinfo->set_name,
+ sizeof(volinfo->set_name), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
out:
kmem_free(volinfo, sizeof(*volinfo));
@@ -1417,10 +1420,12 @@ arc_bio_disk_filldata(struct arc_softc *
blocks += (uint64_t)htole32(diskinfo->capacity);
bd->bd_size = blocks * ARC_BLOCKSIZE; /* XXX */
- scsipi_strvis(model, 81, diskinfo->model, sizeof(diskinfo->model));
- scsipi_strvis(serial, 41, diskinfo->serial, sizeof(diskinfo->serial));
- scsipi_strvis(rev, 17, diskinfo->firmware_rev,
- sizeof(diskinfo->firmware_rev));
+ strnvisx(model, sizeof(model), diskinfo->model,
+ sizeof(diskinfo->model), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(serial, sizeof(serial), diskinfo->serial,
+ sizeof(diskinfo->serial), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(rev, sizeof(rev), diskinfo->firmware_rev,
+ sizeof(diskinfo->firmware_rev), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
snprintf(bd->bd_vendor, sizeof(bd->bd_vendor), "%s %s", model, rev);
strlcpy(bd->bd_serial, serial, sizeof(bd->bd_serial));
Index: src/sys/dev/pci/mpii.c
diff -u src/sys/dev/pci/mpii.c:1.7 src/sys/dev/pci/mpii.c:1.8
--- src/sys/dev/pci/mpii.c:1.7 Mon Feb 8 11:27:51 2016
+++ src/sys/dev/pci/mpii.c Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: mpii.c,v 1.7 2016/02/08 16:27:51 christos Exp $ */
+/* $NetBSD: mpii.c,v 1.8 2016/05/02 19:18:29 christos Exp $ */
/* OpenBSD: mpii.c,v 1.51 2012/04/11 13:29:14 naddy Exp */
/*
* Copyright (c) 2010 Mike Belopuhov <[email protected]>
@@ -20,7 +20,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mpii.c,v 1.7 2016/02/08 16:27:51 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpii.c,v 1.8 2016/05/02 19:18:29 christos Exp $");
#include "bio.h"
@@ -5398,14 +5398,16 @@ mpii_bio_disk(struct mpii_softc *sc, str
bd->bd_size = le64toh(ppg->dev_max_lba) * le16toh(ppg->block_size);
- scsipi_strvis(bd->bd_vendor, sizeof(bd->bd_vendor),
- ppg->vendor_id, sizeof(ppg->vendor_id));
+ strnvisx(bd->bd_vendor, sizeof(bd->bd_vendor),
+ ppg->vendor_id, sizeof(ppg->vendor_id),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
len = strlen(bd->bd_vendor);
bd->bd_vendor[len] = ' ';
- scsipi_strvis(&bd->bd_vendor[len + 1], sizeof(ppg->vendor_id) - len - 1,
- ppg->product_id, sizeof(ppg->product_id));
- scsipi_strvis(bd->bd_serial, sizeof(bd->bd_serial),
- ppg->serial, sizeof(ppg->serial));
+ strnvisx(&bd->bd_vendor[len + 1], sizeof(ppg->vendor_id) - len - 1,
+ ppg->product_id, sizeof(ppg->product_id),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(bd->bd_serial, sizeof(bd->bd_serial),
+ ppg->serial, sizeof(ppg->serial), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
free(ppg, M_TEMP);
return (0);
Index: src/sys/dev/scsipi/atapi_wdc.c
diff -u src/sys/dev/scsipi/atapi_wdc.c:1.121 src/sys/dev/scsipi/atapi_wdc.c:1.122
--- src/sys/dev/scsipi/atapi_wdc.c:1.121 Sun Mar 20 06:29:12 2016
+++ src/sys/dev/scsipi/atapi_wdc.c Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: atapi_wdc.c,v 1.121 2016/03/20 10:29:12 tsutsui Exp $ */
+/* $NetBSD: atapi_wdc.c,v 1.122 2016/05/02 19:18:29 christos Exp $ */
/*
* Copyright (c) 1998, 2001 Manuel Bouyer.
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atapi_wdc.c,v 1.121 2016/03/20 10:29:12 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atapi_wdc.c,v 1.122 2016/05/02 19:18:29 christos Exp $");
#ifndef ATADEBUG
#define ATADEBUG
@@ -298,11 +298,14 @@ wdc_atapi_probe_device(struct atapibus_s
sa.sa_inqbuf.type = ATAPI_CFG_TYPE(id->atap_config);
sa.sa_inqbuf.removable = id->atap_config & ATAPI_CFG_REMOV ?
T_REMOV : T_FIXED;
- scsipi_strvis((u_char *)model, 40, id->atap_model, 40);
- scsipi_strvis((u_char *)serial_number, 20, id->atap_serial,
- 20);
- scsipi_strvis((u_char *)firmware_revision, 8,
- id->atap_revision, 8);
+ strnvisx(model, sizeof(model), id->atap_model,
+ sizeof(id->atap_model), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(serial_number, sizeof(serial_number),
+ id->atap_serial, sizeof(id->atap_serial),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(firmware_revision, sizeof(firmware_revision),
+ id->atap_revision, sizeof(id->atap_revision),
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
sa.sa_inqbuf.vendor = model;
sa.sa_inqbuf.product = serial_number;
sa.sa_inqbuf.revision = firmware_revision;
Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.273 src/sys/dev/scsipi/scsiconf.c:1.274
--- src/sys/dev/scsipi/scsiconf.c:1.273 Fri Jul 25 04:10:38 2014
+++ src/sys/dev/scsipi/scsiconf.c Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: scsiconf.c,v 1.273 2014/07/25 08:10:38 dholland Exp $ */
+/* $NetBSD: scsiconf.c,v 1.274 2016/05/02 19:18:29 christos Exp $ */
/*-
* Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.273 2014/07/25 08:10:38 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.274 2016/05/02 19:18:29 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -493,9 +493,12 @@ scsibusprint(void *aux, const char *pnp)
dtype = scsipi_dtype(type);
- scsipi_strvis(vendor, 33, inqbuf->vendor, 8);
- scsipi_strvis(product, 65, inqbuf->product, 16);
- scsipi_strvis(revision, 17, inqbuf->revision, 4);
+ strnvisx(vendor, sizeof(vendor), inqbuf->vendor, 8,
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(product, sizeof(product), inqbuf->product, 16,
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(revision, sizeof(revision), inqbuf->revision, 4,
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
aprint_normal(" target %d lun %d: <%s, %s, %s> %s %s",
target, lun, vendor, product, revision, dtype,
Index: src/sys/dev/scsipi/scsipiconf.c
diff -u src/sys/dev/scsipi/scsipiconf.c:1.40 src/sys/dev/scsipi/scsipiconf.c:1.41
--- src/sys/dev/scsipi/scsipiconf.c:1.40 Sat Aug 21 09:18:36 2010
+++ src/sys/dev/scsipi/scsipiconf.c Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: scsipiconf.c,v 1.40 2010/08/21 13:18:36 pgoyette Exp $ */
+/* $NetBSD: scsipiconf.c,v 1.41 2016/05/02 19:18:29 christos Exp $ */
/*-
* Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsipiconf.c,v 1.40 2010/08/21 13:18:36 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipiconf.c,v 1.41 2016/05/02 19:18:29 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -61,7 +61,6 @@ __KERNEL_RCSID(0, "$NetBSD: scsipiconf.c
#include <dev/scsipi/scsipiconf.h>
#include <dev/scsipi/scsipi_base.h>
-#define STRVIS_ISWHITE(x) ((x) == ' ' || (x) == '\0' || (x) == (u_char)'\377')
/* Function pointers and stub routines for scsiverbose module */
int (*scsipi_print_sense)(struct scsipi_xfer *, int) = scsipi_print_sense_stub;
@@ -256,42 +255,3 @@ scsipi_dtype(int type)
}
return (dtype);
}
-
-void
-scsipi_strvis(u_char *dst, int dlen, const u_char *src, int slen)
-{
-
- /* Trim leading and trailing blanks and NULs. */
- while (slen > 0 && STRVIS_ISWHITE(src[0]))
- ++src, --slen;
- while (slen > 0 && STRVIS_ISWHITE(src[slen - 1]))
- --slen;
-
- while (slen > 0) {
- if (*src < 0x20 || *src >= 0x80) {
- /* non-printable characters */
- dlen -= 4;
- if (dlen < 1)
- break;
- *dst++ = '\\';
- *dst++ = ((*src & 0300) >> 6) + '0';
- *dst++ = ((*src & 0070) >> 3) + '0';
- *dst++ = ((*src & 0007) >> 0) + '0';
- } else if (*src == '\\') {
- /* quote characters */
- dlen -= 2;
- if (dlen < 1)
- break;
- *dst++ = '\\';
- *dst++ = '\\';
- } else {
- /* normal characters */
- if (--dlen < 1)
- break;
- *dst++ = *src;
- }
- ++src, --slen;
- }
-
- *dst++ = 0;
-}
Index: src/sys/dev/scsipi/scsipiconf.h
diff -u src/sys/dev/scsipi/scsipiconf.h:1.122 src/sys/dev/scsipi/scsipiconf.h:1.123
--- src/sys/dev/scsipi/scsipiconf.h:1.122 Sun Jul 13 13:12:23 2014
+++ src/sys/dev/scsipi/scsipiconf.h Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: scsipiconf.h,v 1.122 2014/07/13 17:12:23 dholland Exp $ */
+/* $NetBSD: scsipiconf.h,v 1.123 2016/05/02 19:18:29 christos Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000, 2004 The NetBSD Foundation, Inc.
@@ -642,7 +642,6 @@ void scsipi_create_completion_thread(voi
const void *scsipi_inqmatch(struct scsipi_inquiry_pattern *, const void *,
size_t, size_t, int *);
const char *scsipi_dtype(int);
-void scsipi_strvis(u_char *, int, const u_char *, int);
int scsipi_execute_xs(struct scsipi_xfer *);
int scsipi_test_unit_ready(struct scsipi_periph *, int);
int scsipi_prevent(struct scsipi_periph *, int, int);
Index: src/sys/dev/usb/umass_scsipi.c
diff -u src/sys/dev/usb/umass_scsipi.c:1.50 src/sys/dev/usb/umass_scsipi.c:1.51
--- src/sys/dev/usb/umass_scsipi.c:1.50 Sat Apr 23 06:15:32 2016
+++ src/sys/dev/usb/umass_scsipi.c Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: umass_scsipi.c,v 1.50 2016/04/23 10:15:32 skrll Exp $ */
+/* $NetBSD: umass_scsipi.c,v 1.51 2016/05/02 19:18:29 christos Exp $ */
/*
* Copyright (c) 2001, 2003, 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.50 2016/04/23 10:15:32 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.51 2016/05/02 19:18:29 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -555,9 +555,12 @@ umass_atapi_probe_device(struct atapibus
return;
}
- scsipi_strvis(vendor, 33, inqbuf.vendor, 8);
- scsipi_strvis(product, 65, inqbuf.product, 16);
- scsipi_strvis(revision, 17, inqbuf.revision, 4);
+ strnvisx(vendor, sizeof(vendor), inqbuf.vendor, 8,
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(product, sizeof(product), inqbuf.product, 16,
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
+ strnvisx(revision, sizeof(revision), inqbuf.revision, 4,
+ VIS_TRIM|VIS_SAFE|VIS_OCTAL);
sa.sa_periph = periph;
sa.sa_inqbuf.type = inqbuf.device;
Index: src/sys/lib/libkern/Makefile.libkern
diff -u src/sys/lib/libkern/Makefile.libkern:1.38 src/sys/lib/libkern/Makefile.libkern:1.39
--- src/sys/lib/libkern/Makefile.libkern:1.38 Wed Apr 15 15:13:47 2015
+++ src/sys/lib/libkern/Makefile.libkern Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.libkern,v 1.38 2015/04/15 19:13:47 mrg Exp $
+# $NetBSD: Makefile.libkern,v 1.39 2016/05/02 19:18:29 christos Exp $
#
# Variable definitions for libkern.
@@ -74,6 +74,7 @@ SRCS+= memset.c
SRCS+= popcount32.c popcount64.c
SRCS+= strtoul.c strtoll.c strtoull.c strtoimax.c strtoumax.c
SRCS+= strtoi.c strtou.c
+SRCS+= strnvisx.c
SRCS+= scanc.c skpc.c
SRCS+= random.c
Index: src/sys/lib/libkern/libkern.h
diff -u src/sys/lib/libkern/libkern.h:1.121 src/sys/lib/libkern/libkern.h:1.122
--- src/sys/lib/libkern/libkern.h:1.121 Sun Aug 30 03:55:45 2015
+++ src/sys/lib/libkern/libkern.h Mon May 2 15:18:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: libkern.h,v 1.121 2015/08/30 07:55:45 uebayasi Exp $ */
+/* $NetBSD: libkern.h,v 1.122 2016/05/02 19:18:29 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -464,6 +464,10 @@ unsigned int popcount64(uint64_t) __cons
void *explicit_memset(void *, int, size_t);
int consttime_memequal(const void *, const void *, size_t);
+int strnvisx(char *, size_t, const char *, size_t, int);
+#define VIS_OCTAL 0x01
+#define VIS_SAFE 0x20
+#define VIS_TRIM 0x40
#ifdef notyet
/*
Added files:
Index: src/sys/lib/libkern/strnvisx.c
diff -u /dev/null src/sys/lib/libkern/strnvisx.c:1.1
--- /dev/null Mon May 2 15:18:30 2016
+++ src/sys/lib/libkern/strnvisx.c Mon May 2 15:18:29 2016
@@ -0,0 +1,87 @@
+/* $NetBSD: strnvisx.c,v 1.1 2016/05/02 19:18:29 christos Exp $ */
+
+/*-
+ * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum; by Jason R. Thorpe of the Numerical Aerospace
+ * Simulation Facility, NASA Ames Research Center.
+ *
+ * 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.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 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 DAMAGE.
+ */
+
+/*
+ * from scsipiconf.c...
+ */
+#include <lib/libkern/libkern.h>
+
+#define STRVIS_ISWHITE(x) ((x) == ' ' || (x) == '\0' || (x) == '\377')
+
+int
+strnvisx(char *dst, size_t dlen, const char *src, size_t slen, int flags)
+{
+ if (dlen == 0)
+ return -1;
+
+ if (flags & VIS_TRIM) {
+ /* Trim leading and trailing blanks and NULs. */
+ while (slen > 0 && STRVIS_ISWHITE(src[0]))
+ ++src, --slen;
+ while (slen > 0 && STRVIS_ISWHITE(src[slen - 1]))
+ --slen;
+ }
+
+ while (slen > 0) {
+ if ((flags & VIS_SAFE) && (*src < 0x20 || (*src & 0x80))) {
+ /* non-printable characters */
+ if (dlen < 4)
+ goto out;
+ dlen -= 4;
+ *dst++ = '\\';
+ *dst++ = ((*src & 0300) >> 6) + '0';
+ *dst++ = ((*src & 0070) >> 3) + '0';
+ *dst++ = ((*src & 0007) >> 0) + '0';
+ } else if (*src == '\\') {
+ /* quote characters */
+ if (dlen < 2)
+ goto out;
+ dlen -= 2;
+ *dst++ = '\\';
+ *dst++ = '\\';
+ } else {
+ /* normal characters */
+ if (dlen < 1)
+ goto out;
+ *dst++ = *src;
+ }
+ ++src, --slen;
+ }
+out:
+ if (dlen > 0) {
+ *dst++ = '\0';
+ return slen ? -1 : 0;
+ } else {
+ *--dst = '\0';
+ return -1;
+ }
+}