1*6bd0ed17Sjoerg /* $NetBSD: iopctl.c,v 1.22 2011/08/30 19:03:25 joerg Exp $ */
29af5448eSad
39af5448eSad /*-
49af5448eSad * Copyright (c) 2000 The NetBSD Foundation, Inc.
59af5448eSad * All rights reserved.
69af5448eSad *
79af5448eSad * This code is derived from software contributed to The NetBSD Foundation
89af5448eSad * by Andrew Doran.
99af5448eSad *
109af5448eSad * Redistribution and use in source and binary forms, with or without
119af5448eSad * modification, are permitted provided that the following conditions
129af5448eSad * are met:
139af5448eSad * 1. Redistributions of source code must retain the above copyright
149af5448eSad * notice, this list of conditions and the following disclaimer.
159af5448eSad * 2. Redistributions in binary form must reproduce the above copyright
169af5448eSad * notice, this list of conditions and the following disclaimer in the
179af5448eSad * documentation and/or other materials provided with the distribution.
189af5448eSad *
199af5448eSad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
209af5448eSad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
219af5448eSad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
229af5448eSad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
239af5448eSad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
249af5448eSad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
259af5448eSad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
269af5448eSad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
279af5448eSad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
289af5448eSad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
299af5448eSad * POSSIBILITY OF SUCH DAMAGE.
309af5448eSad */
319af5448eSad
329af5448eSad #ifndef lint
339af5448eSad #include <sys/cdefs.h>
34*6bd0ed17Sjoerg __RCSID("$NetBSD: iopctl.c,v 1.22 2011/08/30 19:03:25 joerg Exp $");
359af5448eSad #endif /* not lint */
369af5448eSad
379af5448eSad #include <sys/param.h>
389af5448eSad #include <sys/ioctl.h>
399af5448eSad #include <sys/uio.h>
409af5448eSad
419af5448eSad #include <err.h>
429af5448eSad #include <errno.h>
439af5448eSad #include <fcntl.h>
449af5448eSad #include <stdio.h>
459af5448eSad #include <stdlib.h>
469af5448eSad #include <stdarg.h>
479af5448eSad #include <string.h>
489af5448eSad #include <unistd.h>
499af5448eSad #include <util.h>
509af5448eSad
519af5448eSad #include <dev/i2o/i2o.h>
522b5d9695Sad #include <dev/i2o/iopio.h>
539af5448eSad
54*6bd0ed17Sjoerg static const char *class2str(int);
55*6bd0ed17Sjoerg static void getparam(int, int, void *, int);
56*6bd0ed17Sjoerg static int gettid(char **);
57*6bd0ed17Sjoerg static int show(const char *, const char *, ...) __printflike(2, 3);
58*6bd0ed17Sjoerg static void i2ostrvis(const u_char *, int, char *, int);
59*6bd0ed17Sjoerg static void usage(void) __dead;
609af5448eSad
61*6bd0ed17Sjoerg static void reconfig(char **);
62*6bd0ed17Sjoerg static void showdevid(char **);
63*6bd0ed17Sjoerg static void showddmid(char **);
64*6bd0ed17Sjoerg static void showlct(char **);
65*6bd0ed17Sjoerg static void showstatus(char **);
66*6bd0ed17Sjoerg static void showtidmap(char **);
679af5448eSad
68*6bd0ed17Sjoerg static struct {
699af5448eSad int class;
709af5448eSad const char *caption;
719af5448eSad } const i2oclass[] = {
729af5448eSad { I2O_CLASS_EXECUTIVE, "executive" },
739af5448eSad { I2O_CLASS_DDM, "device driver module" },
749af5448eSad { I2O_CLASS_RANDOM_BLOCK_STORAGE, "random block storage" },
759af5448eSad { I2O_CLASS_SEQUENTIAL_STORAGE, "sequential storage" },
769af5448eSad { I2O_CLASS_LAN, "LAN port" },
779af5448eSad { I2O_CLASS_WAN, "WAN port" },
789af5448eSad { I2O_CLASS_FIBRE_CHANNEL_PORT, "fibrechannel port" },
799af5448eSad { I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL, "fibrechannel peripheral" },
809af5448eSad { I2O_CLASS_SCSI_PERIPHERAL, "SCSI peripheral" },
819af5448eSad { I2O_CLASS_ATE_PORT, "ATE port" },
829af5448eSad { I2O_CLASS_ATE_PERIPHERAL, "ATE peripheral" },
839af5448eSad { I2O_CLASS_FLOPPY_CONTROLLER, "floppy controller" },
849af5448eSad { I2O_CLASS_FLOPPY_DEVICE, "floppy device" },
859af5448eSad { I2O_CLASS_BUS_ADAPTER_PORT, "bus adapter port" },
869af5448eSad };
879af5448eSad
88*6bd0ed17Sjoerg static struct {
899af5448eSad const char *label;
909af5448eSad int takesargs;
919af5448eSad void (*func)(char **);
929af5448eSad } const cmdtab[] = {
939af5448eSad { "reconfig", 0, reconfig },
949af5448eSad { "showddmid", 1, showddmid },
959af5448eSad { "showdevid", 1, showdevid },
969af5448eSad { "showlct", 0, showlct },
979af5448eSad { "showstatus", 0, showstatus },
982b5d9695Sad { "showtidmap", 0, showtidmap },
999af5448eSad };
1009af5448eSad
101*6bd0ed17Sjoerg static int fd;
102*6bd0ed17Sjoerg static char buf[32768];
103*6bd0ed17Sjoerg static struct i2o_status status;
1049af5448eSad
1059af5448eSad int
main(int argc,char ** argv)1069af5448eSad main(int argc, char **argv)
1079af5448eSad {
108778b72dfSlukem int ch;
109778b72dfSlukem size_t i;
1109af5448eSad const char *dv;
1119af5448eSad struct iovec iov;
1129af5448eSad
1139af5448eSad dv = "/dev/iop0";
1149af5448eSad
1159af5448eSad while ((ch = getopt(argc, argv, "f:")) != -1) {
1169af5448eSad switch (ch) {
1179af5448eSad case 'f':
1189af5448eSad dv = optarg;
1199af5448eSad break;
1209af5448eSad default:
1219af5448eSad usage();
1229af5448eSad /* NOTREACHED */
1239af5448eSad }
1249af5448eSad }
1259af5448eSad
1269af5448eSad if (argv[optind] == NULL)
1279af5448eSad usage();
1289af5448eSad
1299af5448eSad if ((fd = open(dv, O_RDWR)) < 0)
1309af5448eSad err(EXIT_FAILURE, "%s", dv);
1319af5448eSad
1329af5448eSad iov.iov_base = &status;
1339af5448eSad iov.iov_len = sizeof(status);
1349af5448eSad if (ioctl(fd, IOPIOCGSTATUS, &iov) < 0)
1359af5448eSad err(EXIT_FAILURE, "IOPIOCGSTATUS");
1369af5448eSad
1379af5448eSad for (i = 0; i < sizeof(cmdtab) / sizeof(cmdtab[0]); i++)
1389af5448eSad if (strcmp(argv[optind], cmdtab[i].label) == 0) {
1399af5448eSad if (cmdtab[i].takesargs == 0 &&
1409af5448eSad argv[optind + 1] != NULL)
1419af5448eSad usage();
1429af5448eSad (*cmdtab[i].func)(argv + optind + 1);
1439af5448eSad break;
1449af5448eSad }
1459af5448eSad
1469af5448eSad if (i == sizeof(cmdtab) / sizeof(cmdtab[0]))
1472b5d9695Sad errx(EXIT_FAILURE, "unknown command ``%s''", argv[optind]);
1489af5448eSad
1499af5448eSad close(fd);
1509af5448eSad exit(EXIT_SUCCESS);
1519af5448eSad /* NOTREACHED */
1529af5448eSad }
1539af5448eSad
154*6bd0ed17Sjoerg static void
usage(void)1559af5448eSad usage(void)
1569af5448eSad {
1579af5448eSad
1589af5448eSad (void)fprintf(stderr, "usage: %s [-f dev] <command> [target]\n",
159c2bdafabScgd getprogname());
1609af5448eSad exit(EXIT_FAILURE);
1619af5448eSad /* NOTREACHED */
1629af5448eSad }
1639af5448eSad
164*6bd0ed17Sjoerg static int
show(const char * hdr,const char * fmt,...)1659af5448eSad show(const char *hdr, const char *fmt, ...)
1669af5448eSad {
1679af5448eSad int i;
1689af5448eSad va_list va;
1699af5448eSad
1709af5448eSad for (i = printf("%s", hdr); i < 25; i++)
1719af5448eSad putchar(' ');
1729af5448eSad va_start(va, fmt);
1739af5448eSad i += vprintf(fmt, va);
1749af5448eSad va_end(va);
1759af5448eSad putchar('\n');
1769af5448eSad return (i);
1779af5448eSad }
1789af5448eSad
179*6bd0ed17Sjoerg static const char *
class2str(int class)1809af5448eSad class2str(int class)
1819af5448eSad {
182778b72dfSlukem size_t i;
1839af5448eSad
1849af5448eSad for (i = 0; i < sizeof(i2oclass) / sizeof(i2oclass[0]); i++)
1859af5448eSad if (class == i2oclass[i].class)
1869af5448eSad return (i2oclass[i].caption);
1879af5448eSad
1889af5448eSad return ("unknown");
1899af5448eSad }
1909af5448eSad
191*6bd0ed17Sjoerg static void
getparam(int tid,int group,void * pbuf,int pbufsize)1929af5448eSad getparam(int tid, int group, void *pbuf, int pbufsize)
1939af5448eSad {
1949af5448eSad struct ioppt pt;
1959af5448eSad struct i2o_util_params_op mb;
1962b5d9695Sad struct i2o_reply *rf;
1979af5448eSad struct {
1989af5448eSad struct i2o_param_op_list_header olh;
1999af5448eSad struct i2o_param_op_all_template oat;
2004d096031Sperry } __packed req;
2019af5448eSad
2029af5448eSad mb.msgflags = I2O_MSGFLAGS(i2o_util_params_op);
2039af5448eSad mb.msgfunc = I2O_MSGFUNC(tid, I2O_UTIL_PARAMS_GET);
2049af5448eSad mb.flags = 0;
2059af5448eSad
2069af5448eSad req.olh.count = htole16(1);
2079af5448eSad req.olh.reserved = htole16(0);
2089af5448eSad req.oat.operation = htole16(I2O_PARAMS_OP_FIELD_GET);
2099af5448eSad req.oat.fieldcount = htole16(0xffff);
2109af5448eSad req.oat.group = htole16(group);
2119af5448eSad
2129af5448eSad pt.pt_msg = &mb;
2139af5448eSad pt.pt_msglen = sizeof(mb);
2149af5448eSad pt.pt_reply = buf;
2159af5448eSad pt.pt_replylen = sizeof(buf);
2169af5448eSad pt.pt_timo = 10000;
2179af5448eSad pt.pt_nbufs = 2;
2189af5448eSad
2199af5448eSad pt.pt_bufs[0].ptb_data = &req;
2209af5448eSad pt.pt_bufs[0].ptb_datalen = sizeof(req);
2219af5448eSad pt.pt_bufs[0].ptb_out = 1;
2229af5448eSad
2239af5448eSad pt.pt_bufs[1].ptb_data = pbuf;
2249af5448eSad pt.pt_bufs[1].ptb_datalen = pbufsize;
2259af5448eSad pt.pt_bufs[1].ptb_out = 0;
2269af5448eSad
2279af5448eSad if (ioctl(fd, IOPIOCPT, &pt) < 0)
2289af5448eSad err(EXIT_FAILURE, "IOPIOCPT");
2299af5448eSad
2302b5d9695Sad rf = (struct i2o_reply *)buf;
23114edc766Sad if ((rf->msgflags & I2O_MSGFLAGS_FAIL) != 0)
23214edc766Sad errx(EXIT_FAILURE, "I2O_UTIL_PARAMS_GET failed (FAIL)");
2332b5d9695Sad if (rf->reqstatus != 0)
2349af5448eSad errx(EXIT_FAILURE, "I2O_UTIL_PARAMS_GET failed (%d)",
2355e788a3aSchristos rf->reqstatus);
2369af5448eSad }
2379af5448eSad
238*6bd0ed17Sjoerg static void
showlct(char ** argv)2399af5448eSad showlct(char **argv)
2409af5448eSad {
2419af5448eSad struct iovec iov;
2429af5448eSad struct i2o_lct *lct;
2439af5448eSad struct i2o_lct_entry *ent;
2449af5448eSad u_int32_t classid, usertid;
2459af5448eSad int i, nent;
2469af5448eSad char ident[sizeof(ent->identitytag) * 4 + 1];
2479af5448eSad
2489af5448eSad iov.iov_base = buf;
2499af5448eSad iov.iov_len = sizeof(buf);
2509af5448eSad
2519af5448eSad if (ioctl(fd, IOPIOCGLCT, &iov) < 0)
2529af5448eSad err(EXIT_FAILURE, "IOPIOCGLCT");
2539af5448eSad
2549af5448eSad lct = (struct i2o_lct *)buf;
2559af5448eSad ent = lct->entry;
2569af5448eSad nent = ((le16toh(lct->tablesize) << 2) -
2579af5448eSad sizeof(struct i2o_lct) + sizeof(struct i2o_lct_entry)) /
2589af5448eSad sizeof(struct i2o_lct_entry);
2599af5448eSad
2606face02dSad show("flags", "0x%x", le16toh(lct->flags));
2616face02dSad show("iop flags", "0x%x", le32toh(lct->iopflags));
2626face02dSad show("lct change indicator", "%d", le32toh(lct->changeindicator));
2636face02dSad printf("\n");
2646face02dSad
2659af5448eSad for (i = 0; i < nent; i++, ent++) {
2669af5448eSad classid = le32toh(ent->classid);
2679af5448eSad usertid = le32toh(ent->usertid);
2689af5448eSad
2699af5448eSad show("lct entry", "%d", i);
2709af5448eSad show("entry size", "%d bytes", le16toh(ent->entrysize) << 2);
2719af5448eSad show("local tid", "%d", le16toh(ent->localtid) & 4095);
2729af5448eSad show("change indicator", "%d", le32toh(ent->changeindicator));
2739af5448eSad show("flags", "%x", le32toh(ent->deviceflags));
2749af5448eSad show("class id", "%x (%s)", classid & 4095,
2759af5448eSad class2str(classid & 4095));
2769af5448eSad show("version", "%x", (classid >> 12) & 15);
2779af5448eSad show("organisation id", "%x", classid >> 16);
2789af5448eSad show("subclass info", "%x", le32toh(ent->subclassinfo));
2799af5448eSad show("user tid", "%d", usertid & 4095);
2809af5448eSad show("parent tid", "%d", (usertid >> 12) & 4095);
2819af5448eSad show("bios info", "%d", (usertid >> 24) & 255);
2829af5448eSad i2ostrvis(ent->identitytag, sizeof(ent->identitytag), ident,
2839af5448eSad sizeof(ident));
2849af5448eSad show("identity tag", "<%s>", ident);
2859af5448eSad show("event caps", "%x", le32toh(ent->eventcaps));
2869af5448eSad
2879af5448eSad if (i != nent - 1)
2889af5448eSad printf("\n");
2899af5448eSad }
2909af5448eSad }
2919af5448eSad
292*6bd0ed17Sjoerg static void
showstatus(char ** argv)2939af5448eSad showstatus(char **argv)
2949af5448eSad {
2959af5448eSad char ident[sizeof(status.productid) + 1];
2969af5448eSad u_int32_t segnumber;
2979af5448eSad
2989af5448eSad i2ostrvis(status.productid, sizeof(status.productid),
2999af5448eSad ident, sizeof(ident));
3009af5448eSad
3019af5448eSad segnumber = le32toh(status.segnumber);
3029af5448eSad show("organization id", "%d", le16toh(status.orgid));
3039af5448eSad show("iop id", "%d", le32toh(status.iopid) & 4095);
3049af5448eSad show("host unit id", "%d", (le32toh(status.iopid) >> 16));
3059af5448eSad show("segment number", "%d", segnumber & 4095);
3069af5448eSad show("i2o version", "%d", (segnumber >> 12) & 15);
3079af5448eSad show("iop state", "%d", (segnumber >> 16) & 255);
3089af5448eSad show("messenger type", "%d", segnumber >> 24);
30957fb7482Smhitch show("inbound frame sz", "%d", le16toh(status.inboundmframesize));
3109af5448eSad show("init code", "%d", status.initcode);
3119af5448eSad show("max inbound queue depth", "%d",
3129af5448eSad le32toh(status.maxinboundmframes));
3139af5448eSad show("inbound queue depth", "%d",
3149af5448eSad le32toh(status.currentinboundmframes));
3159af5448eSad show("max outbound queue depth", "%d",
3169af5448eSad le32toh(status.maxoutboundmframes));
3179af5448eSad show("product id string", "<%s>", ident);
3189af5448eSad show("expected lct size", "%d", le32toh(status.expectedlctsize));
3199af5448eSad show("iop capabilities", "0x%08x", le32toh(status.iopcaps));
3209af5448eSad show("desired priv mem sz", "0x%08x",
3219af5448eSad le32toh(status.desiredprivmemsize));
3229af5448eSad show("current priv mem sz", "0x%08x",
3239af5448eSad le32toh(status.currentprivmemsize));
3249af5448eSad show("current priv mem base", "0x%08x",
3259af5448eSad le32toh(status.currentprivmembase));
3269af5448eSad show("desired priv io sz", "0x%08x",
3279af5448eSad le32toh(status.desiredpriviosize));
3289af5448eSad show("current priv io sz", "0x%08x",
3299af5448eSad le32toh(status.currentpriviosize));
3309af5448eSad show("current priv io base", "0x%08x",
3319af5448eSad le32toh(status.currentpriviobase));
3329af5448eSad }
3339af5448eSad
334*6bd0ed17Sjoerg static void
showddmid(char ** argv)3359af5448eSad showddmid(char **argv)
3369af5448eSad {
3379af5448eSad struct {
3389af5448eSad struct i2o_param_op_results pr;
3399af5448eSad struct i2o_param_read_results prr;
3409af5448eSad struct i2o_param_ddm_identity di;
3414dda75daSad char padding[128];
3424d096031Sperry } __packed p;
3439af5448eSad char ident[128];
3445e788a3aSchristos uint32_t serial[3];
3459af5448eSad
346cc274c12Sad getparam(gettid(argv), I2O_PARAM_DDM_IDENTITY, &p, sizeof(p));
3479af5448eSad
3489af5448eSad show("ddm tid", "%d", le16toh(p.di.ddmtid) & 4095);
3499af5448eSad i2ostrvis(p.di.name, sizeof(p.di.name), ident, sizeof(ident));
3509af5448eSad show("module name", "%s", ident);
3519af5448eSad i2ostrvis(p.di.revlevel, sizeof(p.di.revlevel), ident, sizeof(ident));
3529af5448eSad show("module revision", "%s", ident);
3539af5448eSad show("serial # format", "%d", p.di.snformat);
354c1b04cb4Sdholland __CTASSERT(sizeof(serial) == sizeof(p.di.serialnumber));
3555e788a3aSchristos memcpy(serial, &p.di.serialnumber, sizeof(serial));
3565e788a3aSchristos show("serial #", "%08x%08x%08x", serial[0], serial[1], serial[2]);
3579af5448eSad }
3589af5448eSad
359*6bd0ed17Sjoerg static void
showdevid(char ** argv)3609af5448eSad showdevid(char **argv)
3619af5448eSad {
3629af5448eSad struct {
3639af5448eSad struct i2o_param_op_results pr;
3649af5448eSad struct i2o_param_read_results prr;
3659af5448eSad struct i2o_param_device_identity di;
3664dda75daSad char padding[128];
3674d096031Sperry } __packed p;
3689af5448eSad char ident[128];
3699af5448eSad
370cc274c12Sad getparam(gettid(argv), I2O_PARAM_DEVICE_IDENTITY, &p, sizeof(p));
3719af5448eSad
3729af5448eSad show("class id", "%d (%s)", le32toh(p.di.classid) & 4095,
3739af5448eSad class2str(le32toh(p.di.classid) & 4095));
3749af5448eSad show("owner tid", "%d", le32toh(p.di.ownertid) & 4095);
3759af5448eSad show("parent tid", "%d", le32toh(p.di.parenttid) & 4095);
3769af5448eSad
3779af5448eSad i2ostrvis(p.di.vendorinfo, sizeof(p.di.vendorinfo), ident,
3789af5448eSad sizeof(ident));
3799af5448eSad show("vendor", "<%s>", ident);
3809af5448eSad
3819af5448eSad i2ostrvis(p.di.productinfo, sizeof(p.di.productinfo), ident,
3829af5448eSad sizeof(ident));
3839af5448eSad show("product", "<%s>", ident);
3849af5448eSad
3859af5448eSad i2ostrvis(p.di.description, sizeof(p.di.description), ident,
3869af5448eSad sizeof(ident));
3879af5448eSad show("description", "<%s>", ident);
3889af5448eSad
3899af5448eSad i2ostrvis(p.di.revlevel, sizeof(p.di.revlevel), ident, sizeof(ident));
3909af5448eSad show("revision level", "<%s>", ident);
3919af5448eSad }
3929af5448eSad
393*6bd0ed17Sjoerg static void
reconfig(char ** argv)3949af5448eSad reconfig(char **argv)
3959af5448eSad {
3969af5448eSad
3979af5448eSad if (ioctl(fd, IOPIOCRECONFIG))
3989af5448eSad err(EXIT_FAILURE, "IOPIOCRECONFIG");
3999af5448eSad }
4009af5448eSad
401*6bd0ed17Sjoerg static void
showtidmap(char ** argv)4022b5d9695Sad showtidmap(char **argv)
4032b5d9695Sad {
4042b5d9695Sad struct iovec iov;
4052b5d9695Sad struct iop_tidmap *it;
4062b5d9695Sad int nent;
4072b5d9695Sad
4082b5d9695Sad iov.iov_base = buf;
4092b5d9695Sad iov.iov_len = sizeof(buf);
4102b5d9695Sad
4112b5d9695Sad if (ioctl(fd, IOPIOCGTIDMAP, &iov) < 0)
4122b5d9695Sad err(EXIT_FAILURE, "IOPIOCGTIDMAP");
4132b5d9695Sad
4142b5d9695Sad nent = iov.iov_len / sizeof(*it);
4152b5d9695Sad it = (struct iop_tidmap *)buf;
4162b5d9695Sad
417cc274c12Sad for (; nent-- != 0; it++)
4182b5d9695Sad if ((it->it_flags & IT_CONFIGURED) != 0)
4192b5d9695Sad printf("%s\ttid %d\n", it->it_dvname, it->it_tid);
4202b5d9695Sad }
4212b5d9695Sad
422*6bd0ed17Sjoerg static void
i2ostrvis(const u_char * src,int slen,char * dst,int dlen)4233bf6d599Smrg i2ostrvis(const u_char *src, int slen, char *dst, int dlen)
4249af5448eSad {
4259af5448eSad int hc, lc, i, nit;
4269af5448eSad
4279af5448eSad dlen--;
4289af5448eSad lc = 0;
4299af5448eSad hc = 0;
4309af5448eSad i = 0;
4319af5448eSad
4329af5448eSad /*
4339af5448eSad * DPT use NUL as a space, whereas AMI use it as a terminator. The
4349af5448eSad * spec has nothing to say about it. Since AMI fields are usually
4359af5448eSad * filled with junk after the terminator, ...
4369af5448eSad */
4379af5448eSad nit = (le16toh(status.orgid) != I2O_ORG_DPT);
4389af5448eSad
4399af5448eSad while (slen-- != 0 && dlen-- != 0) {
4409af5448eSad if (nit && *src == '\0')
4419af5448eSad break;
4429af5448eSad else if (*src <= 0x20 || *src >= 0x7f) {
4439af5448eSad if (hc)
4449af5448eSad dst[i++] = ' ';
4459af5448eSad } else {
4469af5448eSad hc = 1;
4479af5448eSad dst[i++] = *src;
4489af5448eSad lc = i;
4499af5448eSad }
4509af5448eSad src++;
4519af5448eSad }
4529af5448eSad
4539af5448eSad dst[lc] = '\0';
4549af5448eSad }
455cc274c12Sad
456*6bd0ed17Sjoerg static int
gettid(char ** argv)457cc274c12Sad gettid(char **argv)
458cc274c12Sad {
459cc274c12Sad char *argp;
460cc274c12Sad int tid;
461cc274c12Sad
462cc274c12Sad if (argv[1] != NULL)
463cc274c12Sad usage();
464cc274c12Sad
465cc274c12Sad tid = (int)strtol(argv[0], &argp, 0);
466cc274c12Sad if (*argp != '\0')
467cc274c12Sad usage();
468cc274c12Sad
469cc274c12Sad return (tid);
470cc274c12Sad }
471