From owner-svn-src-all@freebsd.org Fri Feb 9 19:25:26 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 D76F1F1D48E; Fri, 9 Feb 2018 19:25:25 +0000 (UTC) (envelope-from rpokala@mac.com) Received: from mr11p00im-asmtp003.me.com (mr11p00im-asmtp003.me.com [17.110.69.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 777A674566; Fri, 9 Feb 2018 19:25:25 +0000 (UTC) (envelope-from rpokala@mac.com) Received: from process-dkim-sign-daemon.mr11p00im-asmtp003.me.com by mr11p00im-asmtp003.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) id <0P3W00A00DAAYS00@mr11p00im-asmtp003.me.com>; Fri, 09 Feb 2018 19:25:07 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mac.com; s=04042017; t=1518204307; bh=CZHY82/TcgVJFuqKQa4LVQhHhr9QyypElUI+8unqiTc=; h=Date:Subject:From:To:Message-id:MIME-version:Content-type; b=p6885I1sY3En2AaEhMnzxoKRof71K7eGRm7dVfc6xKVOwjTJ8ZwBjb1aYW7ngQDCn SupMwUdJ9OJSvOYxPvTtFZyAGleNLe+lR+TYoSCZ9o8aasFg616bRNh1bCxaHGy7u1 wrez1iVKDBU7tMKhBMEtTxsCTOrpGme2uYkL8jYYVt7iDRyq1D7htiWvh6L1ukh43l L+RdDR5iazf/U7xq3rRav2Nc5mnHSRcbfdREDyVpHYXDHUqqfXUrO9KqDm4L0V2iMZ meq2V489zWfyqzYGRkXrYtWgDwo8NhnppnTFjcAuOgtcgBa+WRt0kuNL3ltsVK9rXk H/ybc4GciC0ow== Received: from icloud.com ([127.0.0.1]) by mr11p00im-asmtp003.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) with ESMTPSA id <0P3W003F7DXS6610@mr11p00im-asmtp003.me.com>; Fri, 09 Feb 2018 19:25:06 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-02-09_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 clxscore=1015 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1802090245 User-Agent: Microsoft-MacOutlook/10.9.0.180116 Date: Fri, 09 Feb 2018 11:25:03 -0800 Subject: Re: svn commit: r329076 - in head/tools/diag: . prtblknos From: Ravi Pokala To: Kirk McKusick , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Message-id: <338960AC-4E8D-455D-A622-937D6D4FAB9B@mac.com> Thread-topic: svn commit: r329076 - in head/tools/diag: . prtblknos References: <201802091910.w19JAksQ018424@repo.freebsd.org> In-reply-to: <201802091910.w19JAksQ018424@repo.freebsd.org> MIME-version: 1.0 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: quoted-printable 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: Fri, 09 Feb 2018 19:25:26 -0000 Neat! But, please define "block". Are you talking about a filesystem block = (i.e. default 32KB on UFS2), are you talking about a disk block (which may v= ary based on the Logical Sector Size of the underlying media)? Thanks, Ravi (rpokala@) =EF=BB=BF-----Original Message----- From: on behalf of Kirk McKusick Date: 2018-02-09, Friday at 11:10 To: , , Subject: svn commit: r329076 - in head/tools/diag: . prtblknos Author: mckusick Date: Fri Feb 9 19:10:46 2018 New Revision: 329076 URL: https://svnweb.freebsd.org/changeset/base/329076 Log: This is a little C-program that can be used to print out the list of blocks used by a requested list of inodes. =20 For example, to list the blocks referenced by your kernel: =20 guest_12 % df / Filesystem 1K-blocks Used Avail Capacity Mounted on /dev/gpt/rootfs 20307196 10707336 7975288 57% / =20 guest_12 % ls -i /boot/kernel/kernel 160603 /boot/kernel/kernel =20 guest_12 % ./prtblknos /dev/gpt/rootfs 160603 160603: lbn 0-7 blkno 3217584-3217647 lbn 8-11 blkno 3217864-3217895 distance 216 First-level indirect, blkno 3217896-3217903 distance 0 lbn 12-19 blkno 3217904-3217967 distance 8 lbn 20-75 blkno 3251816-3252263 distance 33848 lbn 76-83 blkno 3252368-3252431 distance 104 lbn 84-91 blkno 3252464-3252527 distance 32 lbn 92-852 blkno 3252896-3258983 distance 368 =20 Each contiguous range of blocks is printed on a line. The distance metric is the size of the gap from the end of the previous set of blocks to the beginning of the next set of blocks. Short distances are desirable. Added: head/tools/diag/prtblknos/ head/tools/diag/prtblknos/Makefile (contents, props changed) head/tools/diag/prtblknos/README (contents, props changed) head/tools/diag/prtblknos/prtblknos.c (contents, props changed) Modified: head/tools/diag/README Modified: head/tools/diag/README =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/tools/diag/README Fri Feb 9 18:47:00 2018 (r329075) +++ head/tools/diag/README Fri Feb 9 19:10:46 2018 (r329076) @@ -11,4 +11,4 @@ Please make a subdir per program, and add a brief desc dumpvfscache program that can be used to examine the contents of the vfs name cache. localeck check for invalid/incomplete locales=20 - +prtblknos Print out the blocks used by each inode in the list Added: head/tools/diag/prtblknos/Makefile =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/diag/prtblknos/Makefile Fri Feb 9 19:10:46 2018 (r329076) @@ -0,0 +1,10 @@ +# $FreeBSD$ + +PROG=3D prtblknos + +MAN=3D + +test: ${PROG} + ./${PROG} > a + +.include Added: head/tools/diag/prtblknos/README =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/diag/prtblknos/README Fri Feb 9 19:10:46 2018 (r329076) @@ -0,0 +1,31 @@ +# $FreeBSD$ + +This is a little C-program that can be used to print out the list +of blocks used by a requested list of inodes. + +For example, to list the blocks referenced by your kernel: + +guest_12 % df / +Filesystem 1K-blocks Used Avail Capacity Mounted on +/dev/gpt/rootfs 20307196 10707336 7975288 57% / + +guest_12 % ls -i /boot/kernel/kernel +160603 /boot/kernel/kernel + +guest_12 % ./prtblknos /dev/gpt/rootfs 160603 +160603: lbn 0-7 blkno 3217584-3217647 + lbn 8-11 blkno 3217864-3217895 distance 216 +First-level indirect, blkno 3217896-3217903 distance 0 + lbn 12-19 blkno 3217904-3217967 distance 8 + lbn 20-75 blkno 3251816-3252263 distance 33848 + lbn 76-83 blkno 3252368-3252431 distance 104 + lbn 84-91 blkno 3252464-3252527 distance 32 + lbn 92-852 blkno 3252896-3258983 distance 368 + +Each contiguous range of blocks is printed on a line. +The distance metric is the size of the gap from the end of the +previous set of blocks to the beginning of the next set of blocks. +Short distances are desirable. + + Marshall Kirk McKusick + January 19, 2018 Added: head/tools/diag/prtblknos/prtblknos.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/diag/prtblknos/prtblknos.c Fri Feb 9 19:10:46 2018 (r329076= ) @@ -0,0 +1,314 @@ +/* + * Copyright (c) 1998, 2003, 2013, 2018 Marshall Kirk McKusick. + * All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY MARSHALL KIRK MCKUSICK ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP= OSE + * ARE DISCLAIMED. IN NO EVENT SHALL MARSHALL KIRK MCKUSICK BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR= ICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +union dinode { + struct ufs1_dinode *dp1; + struct ufs2_dinode *dp2; +}; +struct fs *sbp; +char *fsname; +int fd; + +void indirprt(int level, int blksperindir, int lbn, ufs2_daddr_t blkno, + int lastlbn); +void printblk(int lbn, ufs2_daddr_t blkno, int numblks, int lastlbn); + +/*=20 + * Possible superblock locations ordered from most to least likely. + */ +static int sblock_try[] =3D SBLOCKSEARCH; + +int +main(argc, argv) + int argc; + char *argv[]; +{ + int i, len, lbn, frags, inonum, numblks, blksperindir; + char sblock[SBLOCKSIZE], ibuf[MAXBSIZE]; + ufs2_daddr_t blkno; + off_t size, offset; + union dinode dp; + + if (argc < 3) { + (void)fprintf(stderr,"usage: prtblknos filesystem inode ...\n"); + exit(1); + } + + fsname =3D *++argv; + + /* get the superblock. */ + if ((fd =3D open(fsname, O_RDONLY, 0)) < 0) + err(1, "%s", fsname); + for (i =3D 0; sblock_try[i] !=3D -1; i++) { + if (lseek(fd, sblock_try[i], SEEK_SET) < 0) + err(1, "lseek: %s", fsname); + if (read(fd, sblock, (long)SBLOCKSIZE) !=3D SBLOCKSIZE) + err(1, "can't read superblock: %s", fsname); + sbp =3D (struct fs *)sblock; + if ((sbp->fs_magic =3D=3D FS_UFS1_MAGIC || + (sbp->fs_magic =3D=3D FS_UFS2_MAGIC && + sbp->fs_sblockloc =3D=3D sblock_try[i])) && + sbp->fs_bsize <=3D MAXBSIZE && + sbp->fs_bsize >=3D sizeof(struct fs)) + break; + } + if (sblock_try[i] =3D=3D -1) + errx(1, "Cannot find file system superblock\n"); + + /* remaining arguments are inode numbers. */ + while (*++argv) { + /* get the inode number. */ + if ((inonum =3D atoi(*argv)) <=3D 0) + errx(1, "%s is not a valid inode number", *argv); + (void)printf("%d:", inonum); + + /* read in the appropriate block. */ + offset =3D ino_to_fsba(sbp, inonum); /* inode to fs blk */ + offset =3D fsbtodb(sbp, offset); /* fs blk disk blk */ + offset *=3D DEV_BSIZE; /* disk blk to bytes */ + + /* seek and read the block */ + if (lseek(fd, offset, SEEK_SET) < 0) + err(1, "%s", fsname); + if (read(fd, ibuf, sbp->fs_bsize) !=3D sbp->fs_bsize) + err(1, "%s", fsname); + + /* get the inode within the block. */ + if (sbp->fs_magic =3D=3D FS_UFS1_MAGIC) { + dp.dp1 =3D &((struct ufs1_dinode *)(ibuf)) + [ino_to_fsbo(sbp, inonum)]; + size =3D dp.dp1->di_size; + } else { + dp.dp2 =3D &((struct ufs2_dinode *)(ibuf)) + [ino_to_fsbo(sbp, inonum)]; + size =3D dp.dp2->di_size; + } + + numblks =3D howmany(size, sbp->fs_bsize); + if (numblks =3D=3D 0) { + printf(" empty file\n"); + continue; + } + len =3D numblks < UFS_NDADDR ? numblks : UFS_NDADDR; + for (i =3D 0; i < len; i++) { + if (i < numblks - 1) + frags =3D sbp->fs_frag; + else + frags =3D howmany(size % sbp->fs_bsize, + sbp->fs_fsize); + if (sbp->fs_magic =3D=3D FS_UFS1_MAGIC) + blkno =3D dp.dp1->di_db[i]; + else + blkno =3D dp.dp2->di_db[i]; + printblk(i, blkno, frags, numblks); + } + + blksperindir =3D 1; + len =3D numblks - UFS_NDADDR; + lbn =3D UFS_NDADDR; + for (i =3D 0; len > 0 && i < UFS_NIADDR; i++) { + if (sbp->fs_magic =3D=3D FS_UFS1_MAGIC) + blkno =3D dp.dp1->di_ib[i]; + else + blkno =3D dp.dp2->di_ib[i]; + indirprt(i, blksperindir, lbn, blkno, numblks); + blksperindir *=3D NINDIR(sbp); + lbn +=3D blksperindir; + len -=3D blksperindir; + } + + /* dummy print to flush out last extent */ + printblk(numblks, 0, frags, 0); + } + (void)close(fd); + exit(0); +} + +void +indirprt(level, blksperindir, lbn, blkno, lastlbn) + int level; + int blksperindir; + int lbn; + ufs2_daddr_t blkno; + int lastlbn; +{ + char indir[MAXBSIZE]; + off_t offset; + int i, last; + + printblk(lbn, blkno, sbp->fs_frag, -level); + /* read in the indirect block. */ + offset =3D fsbtodb(sbp, blkno); /* fs blk disk blk */ + offset *=3D DEV_BSIZE; /* disk blk to bytes */ + if (lseek(fd, offset, SEEK_SET) < 0) + err(1, "%s", fsname); + if (read(fd, indir, sbp->fs_bsize) !=3D sbp->fs_bsize) + err(1, "%s", fsname); + last =3D howmany(lastlbn - lbn, blksperindir) < NINDIR(sbp) ? + howmany(lastlbn - lbn, blksperindir) : NINDIR(sbp); + if (blksperindir =3D=3D 1) { + for (i =3D 0; i < last; i++) { + if (sbp->fs_magic =3D=3D FS_UFS1_MAGIC) + blkno =3D ((ufs1_daddr_t *)indir)[i]; + else + blkno =3D ((ufs2_daddr_t *)indir)[i]; + printblk(lbn + i, blkno, sbp->fs_frag, lastlbn); + } + return; + } + for (i =3D 0; i < last; i++) { + if (sbp->fs_magic =3D=3D FS_UFS1_MAGIC) + blkno =3D ((ufs1_daddr_t *)indir)[i]; + else + blkno =3D ((ufs2_daddr_t *)indir)[i]; + indirprt(level - 1, blksperindir / NINDIR(sbp), + lbn + blksperindir * i, blkno, lastlbn); + } +} + +char * +distance(lastblk, firstblk) + daddr_t lastblk; + daddr_t firstblk; +{ + daddr_t delta; + int firstcg, lastcg; + static char buf[100]; + + if (lastblk =3D=3D 0) + return (""); + delta =3D firstblk - lastblk - 1; + firstcg =3D dtog(sbp, firstblk); + lastcg =3D dtog(sbp, lastblk); + if (firstcg =3D=3D lastcg) { + snprintf(buf, 100, " distance %jd", (intmax_t)delta); + return (&buf[0]); + } + snprintf(buf, 100, " cg %d blk %jd to cg %d blk %jd", + lastcg, dtogd(sbp, lastblk), firstcg, dtogd(sbp, firstblk)); + return (&buf[0]); +} + + +char *indirname[UFS_NIADDR] =3D { "First", "Second", "Third" }; + +void +printblk(lbn, blkno, numblks, lastlbn) + int lbn; + ufs2_daddr_t blkno; + int numblks; + int lastlbn; +{ + static int seq; + static daddr_t lastindirblk, lastblk, firstblk; + + if (lastlbn <=3D 0) + goto flush; + if (seq =3D=3D 0) { + seq =3D 1; + firstblk =3D blkno; + return; + } + if (lbn =3D=3D 0) { + seq =3D 1; + lastblk =3D 0; + firstblk =3D blkno; + lastindirblk =3D 0; + return; + } + if (lbn < lastlbn && ((firstblk =3D=3D 0 && blkno =3D=3D 0) || + (firstblk =3D=3D BLK_NOCOPY && blkno =3D=3D BLK_NOCOPY) || + (firstblk =3D=3D BLK_SNAP && blkno =3D=3D BLK_SNAP) || + blkno =3D=3D firstblk + seq * numblks)) { + seq++; + return; + } +flush: + if (seq =3D=3D 0) + goto prtindir; + if (firstblk <=3D BLK_SNAP) { + if (seq =3D=3D 1) + printf("\tlbn %d %s\n", lbn - seq, + firstblk =3D=3D 0 ? "hole" : + firstblk =3D=3D BLK_NOCOPY ? "nocopy" : + "snapblk"); + else + printf("\tlbn %d-%d %s\n", + lbn - seq, lbn - 1, + firstblk =3D=3D 0 ? "hole" : + firstblk =3D=3D BLK_NOCOPY ? "nocopy" : + "snapblk"); + } else if (seq =3D=3D 1) { + if (numblks =3D=3D 1) + printf("\tlbn %d blkno %jd%s\n", lbn - seq, + (intmax_t)firstblk, distance(lastblk, firstblk)); + else + printf("\tlbn %d blkno %jd-%jd%s\n", lbn - seq, + (intmax_t)firstblk, + (intmax_t)(firstblk + numblks - 1), + distance(lastblk, firstblk)); + lastblk =3D firstblk + numblks - 1; + } else { + printf("\tlbn %d-%d blkno %jd-%jd%s\n", lbn - seq, lbn - 1, + (intmax_t)firstblk, (intmax_t)(firstblk + + (seq - 1) * sbp->fs_frag + numblks - 1), + distance(lastblk, firstblk)); + lastblk =3D firstblk + (seq - 1) * sbp->fs_frag + numblks - 1; + } + if (lastlbn > 0 || blkno =3D=3D 0) { + seq =3D 1; + firstblk =3D blkno; + return; + } +prtindir: + if (seq !=3D 0 && (sbp->fs_metaspace =3D=3D 0 || lastindirblk =3D=3D 0)) + lastindirblk =3D lastblk; + printf("%s-level indirect, blkno %jd-%jd%s\n", indirname[-lastlbn], + (intmax_t)blkno, (intmax_t)(blkno + numblks - 1), + distance(lastindirblk, blkno)); + lastindirblk =3D blkno + numblks - 1; + if (sbp->fs_metaspace =3D=3D 0) + lastblk =3D lastindirblk; + seq =3D 0; +}