From owner-svn-src-head@freebsd.org Sat Jan 23 12:10:17 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 918A9A8B0D2; Sat, 23 Jan 2016 12:10:17 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6C6EC162A; Sat, 23 Jan 2016 12:10:17 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u0NCAGXR090225; Sat, 23 Jan 2016 12:10:16 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u0NCAGf4090222; Sat, 23 Jan 2016 12:10:16 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201601231210.u0NCAGf4090222@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Sat, 23 Jan 2016 12:10:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r294624 - head/sbin/kldstat X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Jan 2016 12:10:17 -0000 Author: trasz Date: Sat Jan 23 12:10:16 2016 New Revision: 294624 URL: https://svnweb.freebsd.org/changeset/base/294624 Log: Add "kldstat -h"; showing module sizes in hex is rather weird. Reviewed by: emaste@ (earlier version) MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D4969 Modified: head/sbin/kldstat/Makefile head/sbin/kldstat/kldstat.8 head/sbin/kldstat/kldstat.c Modified: head/sbin/kldstat/Makefile ============================================================================== --- head/sbin/kldstat/Makefile Sat Jan 23 11:46:52 2016 (r294623) +++ head/sbin/kldstat/Makefile Sat Jan 23 12:10:16 2016 (r294624) @@ -29,4 +29,6 @@ PROG= kldstat MAN= kldstat.8 +LIBADD= util + .include Modified: head/sbin/kldstat/kldstat.8 ============================================================================== --- head/sbin/kldstat/kldstat.8 Sat Jan 23 11:46:52 2016 (r294623) +++ head/sbin/kldstat/kldstat.8 Sat Jan 23 12:10:16 2016 (r294624) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 22, 2014 +.Dd January 19, 2016 .Dt KLDSTAT 8 .Os .Sh NAME @@ -33,6 +33,7 @@ .Nd display status of dynamic kernel linker .Sh SYNOPSIS .Nm +.Op Fl h .Op Fl q .Op Fl v .Op Fl i Ar id @@ -48,6 +49,9 @@ kernel. .Pp The following options are available: .Bl -tag -width indentXX +.It Fl h +Display the size field in a human-readable form, using unit suffixes +instead of hex values. .It Fl v Be more verbose. .It Fl i Ar id Modified: head/sbin/kldstat/kldstat.c ============================================================================== --- head/sbin/kldstat/kldstat.c Sat Jan 23 11:46:52 2016 (r294623) +++ head/sbin/kldstat/kldstat.c Sat Jan 23 12:10:16 2016 (r294624) @@ -28,6 +28,7 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include @@ -51,18 +52,27 @@ printmod(int modid) } static void -printfile(int fileid, int verbose) +printfile(int fileid, int verbose, int humanized) { struct kld_file_stat stat; int modid; + char buf[5]; stat.version = sizeof(struct kld_file_stat); - if (kldstat(fileid, &stat) < 0) + if (kldstat(fileid, &stat) < 0) { err(1, "can't stat file id %d", fileid); - else - printf("%2d %4d %p %-8zx %s", - stat.id, stat.refs, stat.address, stat.size, - stat.name); + } else { + if (humanized) { + humanize_number(buf, sizeof(buf), stat.size, + "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE); + + printf("%2d %4d %p %5s %s", + stat.id, stat.refs, stat.address, buf, stat.name); + } else { + printf("%2d %4d %p %-8zx %s", + stat.id, stat.refs, stat.address, stat.size, stat.name); + } + } if (verbose) { printf(" (%s)\n", stat.pathname); @@ -78,7 +88,7 @@ printfile(int fileid, int verbose) static void usage(void) { - fprintf(stderr, "usage: kldstat [-q] [-v] [-i id] [-n filename]\n"); + fprintf(stderr, "usage: kldstat [-h] [-q] [-v] [-i id] [-n filename]\n"); fprintf(stderr, " kldstat [-q] [-m modname]\n"); exit(1); } @@ -87,6 +97,7 @@ int main(int argc, char** argv) { int c; + int humanized = 0; int verbose = 0; int fileid = 0; int quiet = 0; @@ -94,8 +105,11 @@ main(int argc, char** argv) char* modname = NULL; char* p; - while ((c = getopt(argc, argv, "i:m:n:qv")) != -1) + while ((c = getopt(argc, argv, "hi:m:n:qv")) != -1) switch (c) { + case 'h': + humanized = 1; + break; case 'i': fileid = (int)strtoul(optarg, &p, 10); if (*p != '\0') @@ -155,12 +169,15 @@ main(int argc, char** argv) } } - printf("Id Refs Address%*c Size Name\n", POINTER_WIDTH - 7, ' '); + if (humanized) + printf("Id Refs Address%*c Size Name\n", POINTER_WIDTH - 7, ' '); + else + printf("Id Refs Address%*c Size Name\n", POINTER_WIDTH - 7, ' '); if (fileid != 0) - printfile(fileid, verbose); + printfile(fileid, verbose, humanized); else for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) - printfile(fileid, verbose); + printfile(fileid, verbose, humanized); return 0; }