2 * SPDX-License-Identifier: BSD-3-Clause
5 * The Regents of the University of California. All rights reserved.
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 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 static const char copyright[] =
34 "@(#) Copyright (c) 1993\n\
35 The Regents of the University of California. All rights reserved.\n";
40 static char sccsid[] = "@(#)from: sysctl.c 8.1 (Berkeley) 6/6/93";
42 static const char rcsid[] =
46 #include <sys/param.h>
48 #include <sys/resource.h>
50 #include <sys/sysctl.h>
51 #include <sys/vmmeter.h>
52 #include <dev/evdev/input.h>
56 #include <machine/metadata.h>
59 #if defined(__amd64__) || defined(__i386__)
60 #include <machine/pc/bios.h>
76 static const char *conffile;
78 static int aflag, bflag, Bflag, dflag, eflag, hflag, iflag;
79 static int Nflag, nflag, oflag, qflag, tflag, Tflag, Wflag, xflag;
81 static int oidfmt(int *, int, char *, u_int *);
82 static int parsefile(const char *);
83 static int parse(const char *, int);
84 static int show_var(int *, int);
85 static int sysctl_all(int *oid, int len);
86 static int name2oid(const char *, int *);
88 static int strIKtoi(const char *, char **, const char *);
90 static int ctl_sign[CTLTYPE+1] = {
99 static int ctl_size[CTLTYPE+1] = {
100 [CTLTYPE_INT] = sizeof(int),
101 [CTLTYPE_UINT] = sizeof(u_int),
102 [CTLTYPE_LONG] = sizeof(long),
103 [CTLTYPE_ULONG] = sizeof(u_long),
104 [CTLTYPE_S8] = sizeof(int8_t),
105 [CTLTYPE_S16] = sizeof(int16_t),
106 [CTLTYPE_S32] = sizeof(int32_t),
107 [CTLTYPE_S64] = sizeof(int64_t),
108 [CTLTYPE_U8] = sizeof(uint8_t),
109 [CTLTYPE_U16] = sizeof(uint16_t),
110 [CTLTYPE_U32] = sizeof(uint32_t),
111 [CTLTYPE_U64] = sizeof(uint64_t),
114 static const char *ctl_typename[CTLTYPE+1] = {
115 [CTLTYPE_INT] = "integer",
116 [CTLTYPE_UINT] = "unsigned integer",
117 [CTLTYPE_LONG] = "long integer",
118 [CTLTYPE_ULONG] = "unsigned long",
119 [CTLTYPE_U8] = "uint8_t",
120 [CTLTYPE_U16] = "uint16_t",
121 [CTLTYPE_U32] = "uint32_t",
122 [CTLTYPE_U64] = "uint64_t",
123 [CTLTYPE_S8] = "int8_t",
124 [CTLTYPE_S16] = "int16_t",
125 [CTLTYPE_S32] = "int32_t",
126 [CTLTYPE_S64] = "int64_t",
127 [CTLTYPE_NODE] = "node",
128 [CTLTYPE_STRING] = "string",
129 [CTLTYPE_OPAQUE] = "opaque",
136 (void)fprintf(stderr, "%s\n%s\n",
137 "usage: sysctl [-bdehiNnoqTtWx] [ -B <bufsize> ] [-f filename] name[=value] ...",
138 " sysctl [-bdehNnoqTtWx] [ -B <bufsize> ] -a");
143 main(int argc, char **argv)
148 setlocale(LC_NUMERIC, "");
152 while ((ch = getopt(argc, argv, "AabB:def:hiNnoqtTwWxX")) != -1) {
165 Bflag = strtol(optarg, NULL, 0);
223 if (aflag && argc == 0)
224 exit(sysctl_all(0, 0));
225 if (argc == 0 && conffile == NULL)
229 if (conffile != NULL)
230 warncount += parsefile(conffile);
233 warncount += parse(*argv++, 0);
239 * Parse a single numeric value, append it to 'newbuf', and update
240 * 'newsize'. Returns true if the value was parsed and false if the
241 * value was invalid. Non-numeric types (strings) are handled
242 * directly in parse().
245 parse_numeric(const char *newvalstr, const char *fmt, u_int kind,
246 void **newbufp, size_t *newsizep)
257 unsigned int uintval;
259 unsigned long ulongval;
267 switch (kind & CTLTYPE) {
269 if (strncmp(fmt, "IK", 2) == 0)
270 intval = strIKtoi(newvalstr, &endptr, fmt);
272 intval = (int)strtol(newvalstr, &endptr, 0);
274 valsize = sizeof(intval);
277 uintval = (int) strtoul(newvalstr, &endptr, 0);
279 valsize = sizeof(uintval);
282 longval = strtol(newvalstr, &endptr, 0);
284 valsize = sizeof(longval);
287 ulongval = strtoul(newvalstr, &endptr, 0);
289 valsize = sizeof(ulongval);
292 i8val = (int8_t)strtol(newvalstr, &endptr, 0);
294 valsize = sizeof(i8val);
297 i16val = (int16_t)strtol(newvalstr, &endptr, 0);
299 valsize = sizeof(i16val);
302 i32val = (int32_t)strtol(newvalstr, &endptr, 0);
304 valsize = sizeof(i32val);
307 i64val = strtoimax(newvalstr, &endptr, 0);
309 valsize = sizeof(i64val);
312 u8val = (uint8_t)strtoul(newvalstr, &endptr, 0);
314 valsize = sizeof(u8val);
317 u16val = (uint16_t)strtoul(newvalstr, &endptr, 0);
319 valsize = sizeof(u16val);
322 u32val = (uint32_t)strtoul(newvalstr, &endptr, 0);
324 valsize = sizeof(u32val);
327 u64val = strtoumax(newvalstr, &endptr, 0);
329 valsize = sizeof(u64val);
336 if (errno != 0 || endptr == newvalstr ||
337 (endptr != NULL && *endptr != '\0'))
340 newbuf = realloc(*newbufp, *newsizep + valsize);
342 err(1, "out of memory");
343 memcpy((char *)newbuf + *newsizep, newval, valsize);
345 *newsizep += valsize;
351 * Parse a name into a MIB entry.
352 * Lookup and print out the MIB entry if it exists.
353 * Set a new value if requested.
356 parse(const char *string, int lineno)
360 char *newvalstr = NULL;
362 size_t newsize = Bflag;
363 int mib[CTL_MAXNAME];
364 char *cp, *bufp, buf[BUFSIZ], fmt[BUFSIZ], line[BUFSIZ];
368 snprintf(line, sizeof(line), " at line %d", lineno);
373 if (snprintf(buf, BUFSIZ, "%s", string) >= BUFSIZ) {
374 warnx("oid too long: '%s'%s", string, line);
377 bufp = strsep(&cp, "=:");
379 /* Tflag just lists tunables, do not allow assignment */
380 if (Tflag || Wflag) {
381 warnx("Can't set variables when using -T or -W");
386 /* Strip a pair of " or ' if any. */
390 if (cp[strlen(cp) - 1] == *cp)
391 cp[strlen(cp) - 1] = '\0';
395 newsize = strlen(cp);
398 cp = bufp + strlen(bufp) - 1;
399 while (cp >= bufp && isspace((int)*cp)) {
403 len = name2oid(bufp, mib);
411 if (errno == ENOENT) {
412 warnx("unknown oid '%s'%s", bufp, line);
414 warn("unknown oid '%s'%s", bufp, line);
420 if (oidfmt(mib, len, fmt, &kind)) {
421 warn("couldn't find format of oid '%s'%s", bufp, line);
428 if (newvalstr == NULL || dflag) {
429 if ((kind & CTLTYPE) == CTLTYPE_NODE) {
431 i = show_var(mib, len);
435 sysctl_all(mib, len);
437 i = show_var(mib, len);
442 if ((kind & CTLTYPE) == CTLTYPE_NODE) {
443 warnx("oid '%s' isn't a leaf node%s", bufp, line);
447 if (!(kind & CTLFLAG_WR)) {
448 if (kind & CTLFLAG_TUN) {
449 warnx("oid '%s' is a read only tunable%s", bufp, line);
450 warnx("Tunable values are set in /boot/loader.conf");
452 warnx("oid '%s' is read only%s", bufp, line);
456 switch (kind & CTLTYPE) {
469 if (strlen(newvalstr) == 0) {
470 warnx("empty numeric value");
477 warnx("oid '%s' is type %d,"
478 " cannot set that%s", bufp,
479 kind & CTLTYPE, line);
485 switch (kind & CTLTYPE) {
491 while ((cp = strsep(&newvalstr, " ,")) != NULL) {
494 if (!parse_numeric(cp, fmt, kind, &newbuf,
496 warnx("invalid %s '%s'%s",
497 ctl_typename[kind & CTLTYPE],
507 i = show_var(mib, len);
508 if (sysctl(mib, len, 0, 0, newval, newsize) == -1) {
514 warnx("%s: value is not available%s",
518 warnx("%s: specification is incomplete%s",
522 warnx("%s: type is unknown to this program%s",
526 warn("%s%s", string, line);
535 j = show_var(mib, len);
545 parsefile(const char *filename)
548 char line[BUFSIZ], *p, *pq, *pdq;
549 int warncount = 0, lineno = 0;
551 file = fopen(filename, "r");
553 err(EX_NOINPUT, "%s", filename);
554 while (fgets(line, sizeof(line), file) != NULL) {
557 pq = strchr(line, '\'');
558 pdq = strchr(line, '\"');
559 /* Replace the first # with \0. */
560 while((p = strchr(p, '#')) != NULL) {
561 if (pq != NULL && p > pq) {
562 if ((p = strchr(pq+1, '\'')) != NULL)
565 } else if (pdq != NULL && p > pdq) {
566 if ((p = strchr(pdq+1, '\"')) != NULL)
569 } else if (p == line || *(p-1) != '\\') {
576 p = line + strlen(line) - 1;
577 while (p >= line && isspace((int)*p)) {
582 while (isspace((int)*p))
587 warncount += parse(p, lineno);
594 /* These functions will dump out various interesting structures. */
597 S_clockinfo(size_t l2, void *p)
599 struct clockinfo *ci = (struct clockinfo*)p;
601 if (l2 != sizeof(*ci)) {
602 warnx("S_clockinfo %zu != %zu", l2, sizeof(*ci));
605 printf(hflag ? "{ hz = %'d, tick = %'d, profhz = %'d, stathz = %'d }" :
606 "{ hz = %d, tick = %d, profhz = %d, stathz = %d }",
607 ci->hz, ci->tick, ci->profhz, ci->stathz);
612 S_loadavg(size_t l2, void *p)
614 struct loadavg *tv = (struct loadavg*)p;
616 if (l2 != sizeof(*tv)) {
617 warnx("S_loadavg %zu != %zu", l2, sizeof(*tv));
620 printf(hflag ? "{ %'.2f %'.2f %'.2f }" : "{ %.2f %.2f %.2f }",
621 (double)tv->ldavg[0]/(double)tv->fscale,
622 (double)tv->ldavg[1]/(double)tv->fscale,
623 (double)tv->ldavg[2]/(double)tv->fscale);
628 S_timeval(size_t l2, void *p)
630 struct timeval *tv = (struct timeval*)p;
634 if (l2 != sizeof(*tv)) {
635 warnx("S_timeval %zu != %zu", l2, sizeof(*tv));
638 printf(hflag ? "{ sec = %'jd, usec = %'ld } " :
639 "{ sec = %jd, usec = %ld } ",
640 (intmax_t)tv->tv_sec, tv->tv_usec);
642 p1 = strdup(ctime(&tv_sec));
643 for (p2=p1; *p2 ; p2++)
652 S_vmtotal(size_t l2, void *p)
657 if (l2 != sizeof(*v)) {
658 warnx("S_vmtotal %zu != %zu", l2, sizeof(*v));
663 pageKilo = getpagesize() / 1024;
665 #define pg2k(a) ((uintmax_t)(a) * pageKilo)
666 printf("\nSystem wide totals computed every five seconds:"
667 " (values in kilobytes)\n");
668 printf("===============================================\n");
669 printf("Processes:\t\t(RUNQ: %d Disk Wait: %d Page Wait: "
671 v->t_rq, v->t_dw, v->t_pw, v->t_sl);
672 printf("Virtual Memory:\t\t(Total: %juK Active: %juK)\n",
673 pg2k(v->t_vm), pg2k(v->t_avm));
674 printf("Real Memory:\t\t(Total: %juK Active: %juK)\n",
675 pg2k(v->t_rm), pg2k(v->t_arm));
676 printf("Shared Virtual Memory:\t(Total: %juK Active: %juK)\n",
677 pg2k(v->t_vmshr), pg2k(v->t_avmshr));
678 printf("Shared Real Memory:\t(Total: %juK Active: %juK)\n",
679 pg2k(v->t_rmshr), pg2k(v->t_armshr));
680 printf("Free Memory:\t%juK", pg2k(v->t_free));
685 S_input_id(size_t l2, void *p)
687 struct input_id *id = p;
689 if (l2 != sizeof(*id)) {
690 warnx("S_input_id %zu != %zu", l2, sizeof(*id));
694 printf("{ bustype = 0x%04x, vendor = 0x%04x, "
695 "product = 0x%04x, version = 0x%04x }",
696 id->bustype, id->vendor, id->product, id->version);
701 S_pagesizes(size_t l2, void *p)
708 l = snprintf(buf, sizeof(buf), "{ ");
710 for (i = 0; i * sizeof(*ps) < l2 && ps[i] != 0 && l < sizeof(buf);
712 l += snprintf(&buf[l], sizeof(buf) - l,
713 "%s%lu", i == 0 ? "" : ", ", ps[i]);
716 (void)snprintf(&buf[l], sizeof(buf) - l, " }");
725 S_efi_map(size_t l2, void *p)
727 struct efi_map_header *efihdr;
733 static const char * const types[] = {
734 [EFI_MD_TYPE_NULL] = "Reserved",
735 [EFI_MD_TYPE_CODE] = "LoaderCode",
736 [EFI_MD_TYPE_DATA] = "LoaderData",
737 [EFI_MD_TYPE_BS_CODE] = "BootServicesCode",
738 [EFI_MD_TYPE_BS_DATA] = "BootServicesData",
739 [EFI_MD_TYPE_RT_CODE] = "RuntimeServicesCode",
740 [EFI_MD_TYPE_RT_DATA] = "RuntimeServicesData",
741 [EFI_MD_TYPE_FREE] = "ConventionalMemory",
742 [EFI_MD_TYPE_BAD] = "UnusableMemory",
743 [EFI_MD_TYPE_RECLAIM] = "ACPIReclaimMemory",
744 [EFI_MD_TYPE_FIRMWARE] = "ACPIMemoryNVS",
745 [EFI_MD_TYPE_IOMEM] = "MemoryMappedIO",
746 [EFI_MD_TYPE_IOPORT] = "MemoryMappedIOPortSpace",
747 [EFI_MD_TYPE_PALCODE] = "PalCode",
748 [EFI_MD_TYPE_PERSISTENT] = "PersistentMemory",
752 * Memory map data provided by UEFI via the GetMemoryMap
755 if (l2 < sizeof(*efihdr)) {
756 warnx("S_efi_map length less than header");
760 efisz = (sizeof(struct efi_map_header) + 0xf) & ~0xf;
761 map = (struct efi_md *)((uint8_t *)efihdr + efisz);
763 if (efihdr->descriptor_size == 0)
765 if (l2 != efisz + efihdr->memory_size) {
766 warnx("S_efi_map length mismatch %zu vs %zu", l2, efisz +
767 efihdr->memory_size);
770 ndesc = efihdr->memory_size / efihdr->descriptor_size;
772 printf("\n%23s %12s %12s %8s %4s",
773 "Type", "Physical", "Virtual", "#Pages", "Attr");
775 for (i = 0; i < ndesc; i++,
776 map = efi_next_descriptor(map, efihdr->descriptor_size)) {
778 if (map->md_type < nitems(types))
779 type = types[map->md_type];
782 printf("\n%23s %012jx %12p %08jx ", type,
783 (uintmax_t)map->md_phys, map->md_virt,
784 (uintmax_t)map->md_pages);
785 if (map->md_attr & EFI_MD_ATTR_UC)
787 if (map->md_attr & EFI_MD_ATTR_WC)
789 if (map->md_attr & EFI_MD_ATTR_WT)
791 if (map->md_attr & EFI_MD_ATTR_WB)
793 if (map->md_attr & EFI_MD_ATTR_UCE)
795 if (map->md_attr & EFI_MD_ATTR_WP)
797 if (map->md_attr & EFI_MD_ATTR_RP)
799 if (map->md_attr & EFI_MD_ATTR_XP)
801 if (map->md_attr & EFI_MD_ATTR_RT)
808 #if defined(__amd64__) || defined(__i386__)
810 S_bios_smap_xattr(size_t l2, void *p)
812 struct bios_smap_xattr *smap, *end;
814 if (l2 % sizeof(*smap) != 0) {
815 warnx("S_bios_smap_xattr %zu is not a multiple of %zu", l2,
820 end = (struct bios_smap_xattr *)((char *)p + l2);
821 for (smap = p; smap < end; smap++)
822 printf("\nSMAP type=%02x, xattr=%02x, base=%016jx, len=%016jx",
823 smap->type, smap->xattr, (uintmax_t)smap->base,
824 (uintmax_t)smap->length);
830 strIKtoi(const char *str, char **endptrp, const char *fmt)
841 /* caller already checked this */
845 * A format of "IK" is in deciKelvin. A format of "IK3" is in
846 * milliKelvin. The single digit following IK is log10 of the
847 * multiplying factor to convert Kelvin into the untis of this sysctl,
848 * or the dividing factor to convert the sysctl value to Kelvin. Numbers
849 * larger than 6 will run into precision issues with 32-bit integers.
850 * Characters that aren't ASCII digits after the 'K' are ignored. No
851 * localization is present because this is an interface from the kernel
852 * to this program (eg not an end-user interface), so isdigit() isn't
855 if (fmt[2] != '\0' && fmt[2] >= '0' && fmt[2] <= '9')
860 if (*p == 'C' || *p == 'F' || *p == 'K') {
861 temp = strtof(str, endptrp);
862 if (*endptrp != str && *endptrp == p && errno == 0) {
864 temp = (temp - 32) * 5 / 9;
868 for (i = 0; i < prec; i++)
870 return ((int)(temp + 0.5));
873 /* No unit specified -> treat it as a raw number */
874 kelv = (int)strtol(str, endptrp, 10);
875 if (*endptrp != str && *endptrp == p && errno == 0) {
886 * These functions uses a presently undocumented interface to the kernel
887 * to walk the tree and get the type so it can print the value.
888 * This interface is under work and consideration, and should probably
889 * be killed with a big axe by the first person who can find the time.
890 * (be aware though, that the proper interface isn't as obvious as it
891 * may seem, there are various conflicting requirements.
895 name2oid(const char *name, int *oidp)
904 j = CTL_MAXNAME * sizeof(int);
905 i = sysctl(oid, 2, oidp, &j, name, strlen(name));
913 oidfmt(int *oid, int len, char *fmt, u_int *kind)
915 int qoid[CTL_MAXNAME+2];
922 memcpy(qoid + 2, oid, len * sizeof(int));
925 i = sysctl(qoid, len + 2, buf, &j, 0, 0);
927 err(1, "sysctl fmt %d %zu %d", i, j, errno);
930 *kind = *(u_int *)buf;
933 strcpy(fmt, (char *)(buf + sizeof(u_int)));
938 * This formats and outputs the value of one variable
940 * Returns zero if anything was actually output.
941 * Returns one if didn't know what to do with this.
942 * Return minus one if we had errors.
945 show_var(int *oid, int nlen)
947 u_char buf[BUFSIZ], *val, *oval, *p;
948 char name[BUFSIZ], fmt[BUFSIZ];
949 const char *sep, *sep1, *prntype;
950 int qoid[CTL_MAXNAME+2];
953 int i, hexlen, sign, ctltype;
958 int (*func)(size_t, void *);
962 umv = mv = intlen = 0;
968 memcpy(qoid + 2, oid, nlen * sizeof(int));
972 i = sysctl(qoid, nlen + 2, name, &j, 0, 0);
974 err(1, "sysctl name %d %zu %d", i, j, errno);
976 oidfmt(oid, nlen, fmt, &kind);
977 /* if Wflag then only list sysctls that are writeable and not stats. */
978 if (Wflag && ((kind & CTLFLAG_WR) == 0 || (kind & CTLFLAG_STATS) != 0))
981 /* if Tflag then only list sysctls that are tuneables. */
982 if (Tflag && (kind & CTLFLAG_TUN) == 0)
995 ctltype = (kind & CTLTYPE);
996 if (tflag || dflag) {
998 printf("%s%s", name, sep);
999 if (ctl_typename[ctltype] != NULL)
1000 prntype = ctl_typename[ctltype];
1002 prntype = "unknown";
1004 printf("%s%s", prntype, sep);
1006 printf("%s", prntype);
1011 i = sysctl(qoid, nlen + 2, buf, &j, 0, 0);
1016 /* don't fetch opaques that we don't know how to print */
1017 if (ctltype == CTLTYPE_OPAQUE) {
1018 if (strcmp(fmt, "S,clockinfo") == 0)
1020 else if (strcmp(fmt, "S,timeval") == 0)
1022 else if (strcmp(fmt, "S,loadavg") == 0)
1024 else if (strcmp(fmt, "S,vmtotal") == 0)
1026 else if (strcmp(fmt, "S,input_id") == 0)
1028 else if (strcmp(fmt, "S,pagesizes") == 0)
1031 else if (strcmp(fmt, "S,efi_map_header") == 0)
1034 #if defined(__amd64__) || defined(__i386__)
1035 else if (strcmp(fmt, "S,bios_smap_xattr") == 0)
1036 func = S_bios_smap_xattr;
1040 if (!bflag && !oflag && !xflag)
1045 /* find an estimate of how much we need for this var */
1050 i = sysctl(oid, nlen, 0, &j, 0, 0);
1051 j += j; /* we want to be sure :-) */
1054 val = oval = malloc(j + 1);
1056 warnx("malloc failed");
1060 i = sysctl(oid, nlen, val, &len, 0, 0);
1061 if (i != 0 || (len == 0 && ctltype != CTLTYPE_STRING)) {
1067 fwrite(val, 1, len, stdout);
1073 sign = ctl_sign[ctltype];
1074 intlen = ctl_size[ctltype];
1077 case CTLTYPE_STRING:
1079 printf("%s%s", name, sep);
1080 printf("%.*s", (int)len, p);
1097 printf("%s%s", name, sep);
1098 hexlen = 2 + (intlen * CHAR_BIT + 3) / 4;
1100 while (len >= intlen) {
1101 switch (kind & CTLTYPE) {
1114 umv = *(uint8_t *)p;
1119 umv = *(uint16_t *)p;
1124 umv = *(uint32_t *)p;
1129 umv = *(uint64_t *)p;
1133 fputs(sep1, stdout);
1135 printf("%#0*jx", hexlen, umv);
1137 printf(hflag ? "%'ju" : "%ju", umv);
1138 else if (fmt[1] == 'K') {
1143 * See strIKtoi for details on fmt.
1147 prec = fmt[2] - '0';
1149 for (int i = 0; i < prec; i++)
1151 printf("%.*fC", prec,
1152 (float)mv / base - 273.15);
1155 printf(hflag ? "%'jd" : "%jd", mv);
1163 case CTLTYPE_OPAQUE:
1167 printf("%s%s", name, sep);
1168 i = (*func)(len, p);
1174 if (!oflag && !xflag) {
1179 printf("%s%s", name, sep);
1180 printf("Format:%s Length:%zu Dump:0x", fmt, len);
1181 while (len-- && (xflag || p < val + 16))
1182 printf("%02x", *p++);
1183 if (!xflag && len > 16)
1193 sysctl_all(int *oid, int len)
1195 int name1[22], name2[22];
1203 memcpy(name1+2, oid, len * sizeof(int));
1211 j = sysctl(name1, l1, name2, &l2, 0, 0);
1213 if (errno == ENOENT)
1216 err(1, "sysctl(getnext) %d %zu", j, l2);
1221 if (len < 0 || l2 < (unsigned int)len)
1224 for (i = 0; i < len; i++)
1225 if (name2[i] != oid[i])
1228 i = show_var(name2, l2);
1232 memcpy(name1+2, name2, l2 * sizeof(int));