From owner-svn-src-all@freebsd.org Sun Apr 8 07:06:12 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C649DF892E0; Sun, 8 Apr 2018 07:06:12 +0000 (UTC) (envelope-from mckusick@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7AA497DBC9; Sun, 8 Apr 2018 07:06:12 +0000 (UTC) (envelope-from mckusick@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 758844858; Sun, 8 Apr 2018 07:06:12 +0000 (UTC) (envelope-from mckusick@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3876CEr008777; Sun, 8 Apr 2018 07:06:12 GMT (envelope-from mckusick@FreeBSD.org) Received: (from mckusick@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3876Cmv008775; Sun, 8 Apr 2018 07:06:12 GMT (envelope-from mckusick@FreeBSD.org) Message-Id: <201804080706.w3876Cmv008775@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mckusick set sender to mckusick@FreeBSD.org using -f From: Kirk McKusick Date: Sun, 8 Apr 2018 07:06:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r332267 - head/sbin/fsdb X-SVN-Group: head X-SVN-Commit-Author: mckusick X-SVN-Commit-Paths: head/sbin/fsdb X-SVN-Commit-Revision: 332267 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Apr 2018 07:06:13 -0000 Author: mckusick Date: Sun Apr 8 07:06:12 2018 New Revision: 332267 URL: https://svnweb.freebsd.org/changeset/base/332267 Log: When using the fsdb `blocks' command, replace the long and ugly list of blocks with the much more concise and readable block list shown by the prtblknos() function imported from tools/diag/prtblknos. Modified: head/sbin/fsdb/Makefile head/sbin/fsdb/fsdbutil.c Modified: head/sbin/fsdb/Makefile ============================================================================== --- head/sbin/fsdb/Makefile Sun Apr 8 06:59:42 2018 (r332266) +++ head/sbin/fsdb/Makefile Sun Apr 8 07:06:12 2018 (r332267) @@ -7,10 +7,11 @@ PROG= fsdb MAN= fsdb.8 SRCS= fsdb.c fsdbutil.c \ dir.c ea.c fsutil.c inode.c pass1.c pass1b.c pass2.c pass3.c pass4.c \ - pass5.c setup.c utilities.c ffs_subr.c ffs_tables.c globs.c + pass5.c setup.c utilities.c ffs_subr.c ffs_tables.c globs.c prtblknos.c CFLAGS+= -I${.CURDIR:H}/fsck_ffs WARNS?= 2 LIBADD= edit ufs -.PATH: ${.CURDIR:H}/fsck_ffs ${SRCTOP}/sys/ufs/ffs +.PATH: ${.CURDIR:H}/fsck_ffs ${SRCTOP}/sys/ufs/ffs \ + ${SRCTOP}/tools/diag/prtblknos .include Modified: head/sbin/fsdb/fsdbutil.c ============================================================================== --- head/sbin/fsdb/fsdbutil.c Sun Apr 8 06:59:42 2018 (r332266) +++ head/sbin/fsdb/fsdbutil.c Sun Apr 8 07:06:12 2018 (r332267) @@ -53,9 +53,7 @@ static const char rcsid[] = #include "fsdb.h" #include "fsck.h" -static int charsperline(void); -static void printindir(ufs2_daddr_t blk, int level, char *bufp); -static void printblocks(ino_t inum, union dinode *dp); +void prtblknos(struct uufsd *disk, union dinode *dp); char ** crack(char *line, int *argc) @@ -200,127 +198,6 @@ printstat(const char *cp, ino_t inum, union dinode *dp } -/* - * Determine the number of characters in a - * single line. - */ - -static int -charsperline(void) -{ - int columns; - char *cp; - struct winsize ws; - - columns = 0; - if (ioctl(0, TIOCGWINSZ, &ws) != -1) - columns = ws.ws_col; - if (columns == 0 && (cp = getenv("COLUMNS"))) - columns = atoi(cp); - if (columns == 0) - columns = 80; /* last resort */ - return (columns); -} - - -/* - * Recursively print a list of indirect blocks. - */ -static void -printindir(ufs2_daddr_t blk, int level, char *bufp) -{ - struct bufarea buf, *bp; - char tempbuf[32]; /* enough to print an ufs2_daddr_t */ - int i, j, cpl, charssofar; - ufs2_daddr_t blkno; - - if (blk == 0) - return; - printf("%jd (%d) =>\n", (intmax_t)blk, level); - if (level == 0) { - /* for the final indirect level, don't use the cache */ - bp = &buf; - bp->b_un.b_buf = bufp; - initbarea(bp, BT_UNKNOWN); - - getblk(bp, blk, sblock.fs_bsize); - } else - bp = getdatablk(blk, sblock.fs_bsize, BT_UNKNOWN); - - cpl = charsperline(); - for (i = charssofar = 0; i < NINDIR(&sblock); i++) { - if (sblock.fs_magic == FS_UFS1_MAGIC) - blkno = bp->b_un.b_indir1[i]; - else - blkno = bp->b_un.b_indir2[i]; - if (blkno == 0) - continue; - j = sprintf(tempbuf, "%jd", (intmax_t)blkno); - if (level == 0) { - charssofar += j; - if (charssofar >= cpl - 2) { - putchar('\n'); - charssofar = j; - } - } - fputs(tempbuf, stdout); - if (level == 0) { - printf(", "); - charssofar += 2; - } else { - printf(" =>\n"); - printindir(blkno, level - 1, bufp); - printf("\n"); - charssofar = 0; - } - } - if (level == 0) - putchar('\n'); - return; -} - - -/* - * Print the block pointers for one inode. - */ -static void -printblocks(ino_t inum, union dinode *dp) -{ - char *bufp; - int i, nfrags; - long ndb, offset; - ufs2_daddr_t blkno; - - printf("Blocks for inode %ju:\n", (uintmax_t)inum); - printf("Direct blocks:\n"); - ndb = howmany(DIP(dp, di_size), sblock.fs_bsize); - for (i = 0; i < UFS_NDADDR && i < ndb; i++) { - if (i > 0) - printf(", "); - blkno = DIP(dp, di_db[i]); - printf("%jd", (intmax_t)blkno); - } - if (ndb <= UFS_NDADDR) { - offset = blkoff(&sblock, DIP(dp, di_size)); - if (offset != 0) { - nfrags = numfrags(&sblock, fragroundup(&sblock, offset)); - printf(" (%d frag%s)", nfrags, nfrags > 1? "s": ""); - } - } - putchar('\n'); - if (ndb <= UFS_NDADDR) - return; - - bufp = malloc((unsigned int)sblock.fs_bsize); - if (bufp == NULL) - errx(EEXIT, "cannot allocate indirect block buffer"); - printf("Indirect blocks:\n"); - for (i = 0; i < UFS_NIADDR; i++) - printindir(DIP(dp, di_ib[i]), i, bufp); - free(bufp); -} - - int checkactive(void) { @@ -359,7 +236,7 @@ printactive(int doblocks) case IFSOCK: case IFIFO: if (doblocks) - printblocks(curinum, curinode); + prtblknos(&disk, curinode); else printstat("current inode", curinum, curinode); break;