kern - More work replacing %D
authorAntonio Huete Jimenez <tuxillo@quantumachine.net>
Sun, 13 Jan 2013 12:25:22 +0000 (13:25 +0100)
committerAntonio Huete Jimenez <tuxillo@quantumachine.net>
Tue, 15 Jan 2013 22:51:36 +0000 (23:51 +0100)
Use hexncpy() for special cases where, for example,
a different separator might be needed.

sys/dev/netif/fe/if_fe.c
sys/dev/raid/aac/aac_debug.c
sys/dev/raid/ciss/ciss.c
sys/dev/raid/mlx/mlx.c
sys/dev/raid/mly/mly.c
sys/kern/uipc_mbuf.c
sys/net/ppp_layer/ppp_tty.c
sys/net/sppp/if_spppsubr.c
sys/net/vlan/if_vlan_ether.c
sys/netinet/if_ether.c
sys/vfs/nfs/bootp_subr.c

index 63b9c31..c45252b 100644 (file)
@@ -376,6 +376,7 @@ fe_read_eeprom_jli (struct fe_softc * sc, u_char * data)
 {
        u_char n, val, bit;
        u_char save16, save17;
+       char hexstr[48];
 
        /* Save the current value of the EEPROM interface registers.  */
        save16 = fe_inb(sc, FE_BMPR16);
@@ -438,8 +439,9 @@ fe_read_eeprom_jli (struct fe_softc * sc, u_char * data)
                int i;
                data -= JLI_EEPROM_SIZE;
                for (i = 0; i < JLI_EEPROM_SIZE; i += 16) {
-                       kprintf("fe%d: EEPROM(JLI):%3x: %16D\n",
-                              sc->sc_unit, i, data + i, " ");
+                       hexncpy(data + i, 16, hexstr, 48, " ");
+                       kprintf("fe%d: EEPROM(JLI):%3x: %s\n",
+                           sc->sc_unit, i, hexstr);
                }
        }
 #endif
@@ -475,6 +477,7 @@ fe_read_eeprom_ssi (struct fe_softc *sc, u_char *data)
        u_char val, bit;
        int n;
        u_char save6, save7, save12;
+       char hexstr[48];
 
        /* Save the current value for the DLCR registers we are about
            to destroy.  */
@@ -554,8 +557,9 @@ fe_read_eeprom_ssi (struct fe_softc *sc, u_char *data)
                int i;
                data -= SSI_EEPROM_SIZE;
                for (i = 0; i < SSI_EEPROM_SIZE; i += 16) {
-                       kprintf("fe%d: EEPROM(SSI):%3x: %16D\n",
-                              sc->sc_unit, i, data + i, " ");
+                       hexncpy(data + i, 16, hexstr, 48, " ");
+                       kprintf("fe%d: EEPROM(SSI):%3x: %s\n",
+                           sc->sc_unit, i, hexstr);
                }
        }
 #endif
@@ -610,6 +614,7 @@ fe_read_eeprom_lnx (struct fe_softc *sc, u_char *data)
        u_char n, bit, val;
        u_char save20;
        u_short reg20 = 0x14;
+       char hexstr[48];
 
        save20 = fe_inb(sc, reg20);
 
@@ -695,8 +700,9 @@ fe_read_eeprom_lnx (struct fe_softc *sc, u_char *data)
        if (bootverbose) {
                data -= LNX_EEPROM_SIZE;
                for (i = 0; i < LNX_EEPROM_SIZE; i += 16) {
-                       kprintf("fe%d: EEPROM(LNX):%3x: %16D\n",
-                              sc->sc_unit, i, data + i, " ");
+                       hexncpy(data + i, 16, hexstr, 48, " ");
+                       kprintf("fe%d: EEPROM(LNX):%3x: %s\n",
+                           sc->sc_unit, i, hexstr);
                }
        }
 #endif
index e1168b7..6bffdc6 100644 (file)
@@ -165,6 +165,8 @@ aac_panic(struct aac_softc *sc, char *reason)
 void
 aac_print_fib(struct aac_softc *sc, struct aac_fib *fib, const char *caller)
 {
+       char hexstr[48];
+
        if (fib == NULL) {
                device_printf(sc->aac_dev,
                              "aac_print_fib called with NULL fib\n");
@@ -246,8 +248,10 @@ aac_print_fib(struct aac_softc *sc, struct aac_fib *fib, const char *caller)
                break;
        }
        default:
-               device_printf(sc->aac_dev, "   %16D\n", fib->data, " ");
-               device_printf(sc->aac_dev, "   %16D\n", fib->data + 16, " ");
+               device_printf(sc->aac_dev, "   %s\n", hexncpy(fib->data, 16,
+                       hexstr, 48, " "));
+               device_printf(sc->aac_dev, "   %s\n", hexncpy(fib->data + 16, 16,
+                       hexstr, 48, " "));
                break;
        }
 }
index 33b129a..dc12405 100644 (file)
@@ -4152,6 +4152,7 @@ ciss_print_request(struct ciss_request *cr)
     struct ciss_softc  *sc;
     struct ciss_command        *cc;
     int                        i;
+    char               hexstr[HEX_NCPYLEN(CISS_CDB_BUFFER_SIZE)];
 
     sc = cr->cr_sc;
     cc = cr->cr_cc;
@@ -4184,7 +4185,8 @@ ciss_print_request(struct ciss_request *cr)
                (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_HEAD_OF_QUEUE) ? "head-of-queue" :
                (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_ORDERED) ? "ordered" :
                (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_AUTO_CONTINGENT) ? "auto-contingent" : "??");
-    ciss_printf(sc, "  %*D\n", cc->cdb.cdb_length, &cc->cdb.cdb[0], " ");
+    ciss_printf(sc, "  %s\n", hexncpy(&cc->cdb.cdb[0], cc->cdb.cdb_length,
+           hexstr, HEX_NCPYLEN(cc->cdb.cdb_length), " "));
 
     if (cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR) {
        /* XXX print error info */
index fe661af..2ca2bb5 100644 (file)
@@ -1241,6 +1241,7 @@ mlx_periodic_eventlog_respond(struct mlx_command *mc)
     struct mlx_softc           *sc = mc->mc_sc;
     struct mlx_eventlog_entry  *el = (struct mlx_eventlog_entry *)mc->mc_data;
     char                       *reason;
+    char                       hexstr[2][12];
 
     debug_called(1);
 
@@ -1278,7 +1279,8 @@ mlx_periodic_eventlog_respond(struct mlx_command *mc)
                    (el->el_asq == 0x02))))) {
                device_printf(sc->mlx_dev, "physical drive %d:%d error log: sense = %d asc = %x asq = %x\n",
                              el->el_channel, el->el_target, el->el_sensekey, el->el_asc, el->el_asq);
-               device_printf(sc->mlx_dev, "  info %4D csi %4D\n", el->el_information, ":", el->el_csi, ":");
+               device_printf(sc->mlx_dev, "  info %s csi %s\n", hexncpy(el->el_information, 4, hexstr[0], 12, ":"),
+                   hexncpy(el->el_csi, 4, hexstr[1], 12, ":"));
            }
            break;
            
index 8a86edd..6daa880 100644 (file)
@@ -1285,7 +1285,7 @@ mly_process_event(struct mly_softc *sc, struct mly_event *me)
     struct scsi_sense_data     *ssd = (struct scsi_sense_data *)&me->sense[0];
     char                       *fp, *tp;
     int                                bus, target, event, class, action;
-
+    char                       hexstr[2][12];
     /* 
      * Errors can be reported using vendor-unique sense data.  In this case, the
      * event code will be 0x1c (Request sense data present), the sense key will
@@ -1346,7 +1346,8 @@ mly_process_event(struct mly_softc *sc, struct mly_event *me)
        mly_printf(sc, "physical device %d:%d %s\n", me->channel, me->target, tp);
        mly_printf(sc, "  sense key %d  asc %02x  ascq %02x\n", 
                      ssd->flags & SSD_KEY, ssd->add_sense_code, ssd->add_sense_code_qual);
-       mly_printf(sc, "  info %4D  csi %4D\n", ssd->info, "", ssd->cmd_spec_info, "");
+       mly_printf(sc, "  info %s csi %s\n", hexncpy(ssd->info, 4, hexstr[0], 12, NULL),
+           hexncpy(ssd->cmd_spec_info, 4, hexstr[1], 12, NULL));
        if (action == 'r')
            sc->mly_btl[me->channel][me->target].mb_flags |= MLY_BTL_RESCAN;
        break;
index c1b4d00..ec7b733 100644 (file)
@@ -2269,14 +2269,18 @@ m_print(const struct mbuf *m)
 {
        int len;
        const struct mbuf *m2;
+       char *hexstr;
 
        len = m->m_pkthdr.len;
        m2 = m;
+       hexstr = kmalloc(HEX_NCPYLEN(len), M_TEMP, M_ZERO | M_WAITOK);
        while (len) {
-               kprintf("%p %*D\n", m2, m2->m_len, (u_char *)m2->m_data, "-");
+               kprintf("%p %s\n", m2, hexncpy(m2->m_data, m2->m_len, hexstr,
+                       HEX_NCPYLEN(m2->m_len), "-"));
                len -= m2->m_len;
                m2 = m2->m_next;
        }
+       kfree(hexstr, M_TEMP);
        return;
 }
 
index c2ba4c4..5cf573d 100644 (file)
@@ -1130,12 +1130,16 @@ pppinput(int c, struct tty *tp)
 static void
 ppplogchar(struct ppp_softc *sc, int c)
 {
+    char *hexstr;
+
     if (c >= 0)
        sc->sc_rawin[sc->sc_rawin_count++] = c;
     if (sc->sc_rawin_count >= sizeof(sc->sc_rawin)
        || (c < 0 && sc->sc_rawin_count > 0)) {
-       kprintf("%s input: %*D", sc->sc_if.if_xname,
-               sc->sc_rawin_count, sc->sc_rawin, " ");
+       hexstr = kmalloc(HEX_NCPYLEN(sc->sc_rawin_count), M_TEMP, M_WAITOK | M_ZERO);
+       kprintf("%s input: %s", sc->sc_if.if_xname, hexncpy(sc->sc_rawin,
+               sc->sc_rawin_count, hexstr, HEX_NCPYLEN(sc->sc_rawin_count), " "));
        sc->sc_rawin_count = 0;
+       kfree(hexstr, M_TEMP);
     }
 }
index 6e915dc..e7cbcf2 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include <sys/param.h>
+#include <sys/libkern.h>
 
 #if defined(__DragonFly__) 
 #include "opt_inet.h"
@@ -5399,8 +5400,9 @@ sppp_proto_name(u_short proto)
 static void
 sppp_print_bytes(const u_char *p, u_short len)
 {
+       char hexstr[len];
        if (len)
-               log(-1, " %*D", len, p, "-");
+               log(-1, " %s", hexncpy(p, len, hexstr, HEX_NCPYLEN(len), "-"));
 }
 
 static void
index 19b12b7..f2de53a 100644 (file)
@@ -50,7 +50,9 @@ vlan_start_dispatch(netmsg_t msg)
        struct mbuf *m;
        struct ifnet *ifp;
        struct altq_pktattr pktattr;
-
+#ifdef DEBUG
+       char hexstr[HEX_NCPYLEN(sizeof(struct ether_vlan_header))];
+#endif
        m = nmp->nm_packet;
        ifp = msg->lmsg.u.ms_resultp;
 
@@ -99,8 +101,8 @@ vlan_start_dispatch(netmsg_t msg)
                evl->evl_encap_proto = htons(ETHERTYPE_VLAN);
                evl->evl_tag = htons(vlantag);
 #ifdef DEBUG
-               kprintf("vlan_start: %*D\n", (int)sizeof *evl,
-                       (unsigned char *)evl, ":");
+               kprintf("vlan_start: %s\n", hexncpy((u_char *)evl, sizeof(*evl),
+                       hexstr, HEX_NCPYLEN(sizeof(*evl)), ":"));
 #endif
                /* Hardware does not need to setup vlan tagging */
                m->m_flags &= ~M_VLANTAG;
index a751bbb..03c0011 100644 (file)
@@ -582,6 +582,7 @@ arpintr(netmsg_t msg)
        struct mbuf *m = msg->packet.nm_packet;
        struct arphdr *ar;
        u_short ar_hrd;
+       char hexstr[6];
 
        if (m->m_len < sizeof(struct arphdr) &&
            (m = m_pullup(m, sizeof(struct arphdr))) == NULL) {
@@ -592,8 +593,9 @@ arpintr(netmsg_t msg)
 
        ar_hrd = ntohs(ar->ar_hrd);
        if (ar_hrd != ARPHRD_ETHER && ar_hrd != ARPHRD_IEEE802) {
-               log(LOG_ERR, "arp: unknown hardware address format (0x%2D)\n",
-                   (unsigned char *)&ar->ar_hrd, "");
+               hexncpy((unsigned char *)&ar->ar_hrd, 2, hexstr, 5, NULL);
+               log(LOG_ERR, "arp: unknown hardware address format (0x%s)\n",
+                   hexstr);
                m_freem(m);
                return;
        }
@@ -677,6 +679,7 @@ arp_update_oncpu(struct mbuf *m, in_addr_t saddr, boolean_t create,
        struct llinfo_arp *la;
        struct sockaddr_dl *sdl;
        struct rtentry *rt;
+       char hexstr[2][64];
 
        la = arplookup(saddr, create, generate_report, FALSE);
        if (la && (rt = la->la_rt) && (sdl = SDL(rt->rt_gateway))) {
@@ -713,12 +716,13 @@ arp_update_oncpu(struct mbuf *m, in_addr_t saddr, boolean_t create,
 
                        if ((log_arp_wrong_iface == 1 && nifp == NULL) ||
                            log_arp_wrong_iface == 2) {
+                               hexncpy((u_char *)ar_sha(ah), ifp->if_addrlen,
+                                   hexstr[0], HEX_NCPYLEN(ifp->if_addrlen), ":");
                                log(LOG_ERR,
                                    "arp: %s is on %s "
-                                   "but got reply from %*D on %s\n",
+                                   "but got reply from %s on %s\n",
                                    inet_ntoa(isaddr),
-                                   rt->rt_ifp->if_xname,
-                                   ifp->if_addrlen, (u_char *)ar_sha(ah), ":",
+                                   rt->rt_ifp->if_xname, hexstr[0],
                                    ifp->if_xname);
                        }
                        if (nifp == NULL)
@@ -736,21 +740,23 @@ arp_update_oncpu(struct mbuf *m, in_addr_t saddr, boolean_t create,
                    bcmp(ar_sha(ah), LLADDR(sdl), sdl->sdl_alen)) {
                        if (rt->rt_expire != 0) {
                                if (dologging && log_arp_movements) {
+                                       hexncpy((u_char *)LLADDR(sdl), ifp->if_addrlen,
+                                           hexstr[0], HEX_NCPYLEN(ifp->if_addrlen), ":");
+                                       hexncpy((u_char *)ar_sha(ah), ifp->if_addrlen,
+                                           hexstr[1], HEX_NCPYLEN(ifp->if_addrlen), ":");
                                        log(LOG_INFO,
-                                       "arp: %s moved from %*D to %*D on %s\n",
-                                       inet_ntoa(isaddr),
-                                       ifp->if_addrlen, (u_char *)LLADDR(sdl),
-                                       ":", ifp->if_addrlen,
-                                       (u_char *)ar_sha(ah), ":",
-                                       ifp->if_xname);
+                                           "arp: %s moved from %s to %s on %s\n",
+                                           inet_ntoa(isaddr), hexstr[0], hexstr[1],
+                                           ifp->if_xname);
                                }
                        } else {
                                if (dologging && log_arp_permanent_modify) {
+                                       hexncpy((u_char *)ar_sha(ah), ifp->if_addrlen,
+                                           hexstr[0], HEX_NCPYLEN(ifp->if_addrlen), ":");
                                        log(LOG_ERR,
-                                       "arp: %*D attempts to modify "
+                                       "arp: %s attempts to modify "
                                        "permanent entry for %s on %s\n",
-                                       ifp->if_addrlen, (u_char *)ar_sha(ah),
-                                       ":", inet_ntoa(isaddr), ifp->if_xname);
+                                       hexstr[0], inet_ntoa(isaddr), ifp->if_xname);
                                }
                                return;
                        }
@@ -761,17 +767,19 @@ arp_update_oncpu(struct mbuf *m, in_addr_t saddr, boolean_t create,
                 * length. -is
                 */
                if (dologging && sdl->sdl_alen && sdl->sdl_alen != ah->ar_hln) {
+                       hexncpy((u_char *)ar_sha(ah), ifp->if_addrlen,
+                           hexstr[0], HEX_NCPYLEN(ifp->if_addrlen), ":");
                        log(LOG_WARNING,
-                           "arp from %*D: new addr len %d, was %d",
-                           ifp->if_addrlen, (u_char *) ar_sha(ah), ":",
-                           ah->ar_hln, sdl->sdl_alen);
+                           "arp from %s: new addr len %d, was %d",
+                           hexstr[0], ah->ar_hln, sdl->sdl_alen);
                }
                if (ifp->if_addrlen != ah->ar_hln) {
                        if (dologging) {
+                               hexncpy((u_char *)ar_sha(ah), ifp->if_addrlen,
+                                   hexstr[0], HEX_NCPYLEN(ifp->if_addrlen), ":");
                                log(LOG_WARNING,
-                               "arp from %*D: addr len: new %d, i/f %d "
-                               "(ignored)",
-                               ifp->if_addrlen, (u_char *) ar_sha(ah), ":",
+                               "arp from %s: addr len: new %d, i/f %d "
+                               "(ignored)", hexstr[0],
                                ah->ar_hln, ifp->if_addrlen);
                        }
                        return;
@@ -849,6 +857,7 @@ in_arpinput(struct mbuf *m)
        uint8_t *enaddr = NULL;
        int op;
        int req_len;
+       char hexstr[64];
 
        req_len = arphdr_len2(ifp->if_addrlen, sizeof(struct in_addr));
        if (m->m_len < req_len && (m = m_pullup(m, req_len)) == NULL) {
@@ -1009,10 +1018,11 @@ match:
                return;
        }
        if (isaddr.s_addr == myaddr.s_addr && myaddr.s_addr != 0) {
+               hexncpy((u_char *)ar_sha(ah), ifp->if_addrlen,
+                   hexstr, HEX_NCPYLEN(ifp->if_addrlen), ":");
                log(LOG_ERR,
-                  "arp: %*D is using my IP address %s!\n",
-                  ifp->if_addrlen, (u_char *)ar_sha(ah), ":",
-                  inet_ntoa(isaddr));
+                  "arp: %s is using my IP address %s!\n",
+                   hexstr, inet_ntoa(isaddr));
                itaddr = myaddr;
                goto reply;
        }
index 29b26d7..47ee5fb 100644 (file)
@@ -584,6 +584,7 @@ bootpc_call(struct bootpc_globalcontext *gctx, struct thread *td)
        int gotrootpath;
        int retry;
        const char *s;
+       char hexstr[64];
        
        /*
         * Create socket and set its recieve timeout.
@@ -711,13 +712,13 @@ bootpc_call(struct bootpc_globalcontext *gctx, struct thread *td)
                                        s = "BOOTP Query";
                                        break;
                                }
+                               hexncpy((u_char *)LLADDR(ifctx->sdl),
+                                   ifctx->sdl->sdl_alen, hexstr,
+                                   HEX_NCPYLEN(ifctx->sdl->sdl_alen), ":");
                                kprintf("Sending %s packet from "
-                                      "interface %s (%*D)\n",
-                                      s,
-                                      ifctx->ireq.ifr_name,
-                                      ifctx->sdl->sdl_alen,
-                                      (unsigned char *) LLADDR(ifctx->sdl),
-                                      ":");
+                                      "interface %s (%s)\n",
+                                      s, ifctx->ireq.ifr_name,
+                                      hexstr);
                                ifctx->sentmsg = 1;
                        }