From owner-svn-src-all@freebsd.org Wed Apr 18 23:08:11 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 DFD8CF8A840; Wed, 18 Apr 2018 23:08:10 +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 8DF32781A9; Wed, 18 Apr 2018 23:08:10 +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 83C8A215DD; Wed, 18 Apr 2018 23:08:10 +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 w3IN8AOL067790; Wed, 18 Apr 2018 23:08:10 GMT (envelope-from mckusick@FreeBSD.org) Received: (from mckusick@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3IN8Aro067788; Wed, 18 Apr 2018 23:08:10 GMT (envelope-from mckusick@FreeBSD.org) Message-Id: <201804182308.w3IN8Aro067788@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mckusick set sender to mckusick@FreeBSD.org using -f From: Kirk McKusick Date: Wed, 18 Apr 2018 23:08:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r332742 - head/tools/diag/prtblknos X-SVN-Group: head X-SVN-Commit-Author: mckusick X-SVN-Commit-Paths: head/tools/diag/prtblknos X-SVN-Commit-Revision: 332742 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: Wed, 18 Apr 2018 23:08:11 -0000 Author: mckusick Date: Wed Apr 18 23:08:10 2018 New Revision: 332742 URL: https://svnweb.freebsd.org/changeset/base/332742 Log: In addition to the existing argument format: prtblknos filesystem_device inode ... add an additional argument format: prtblknos file which is more convenient than figuring out the filesystem and inode number for "file". When given a list of multiple inodes, rather than exiting the program on an error with one of them, skip over it and continue with the next one. Submitted by: bde Modified: head/tools/diag/prtblknos/main.c head/tools/diag/prtblknos/prtblknos.c Modified: head/tools/diag/prtblknos/main.c ============================================================================== --- head/tools/diag/prtblknos/main.c Wed Apr 18 22:24:44 2018 (r332741) +++ head/tools/diag/prtblknos/main.c Wed Apr 18 23:08:10 2018 (r332742) @@ -31,6 +31,7 @@ #include #include #include +#include #include union dinode { @@ -48,11 +49,30 @@ main(argc, argv) struct uufsd disk; union dinode *dp; struct fs *fs; + struct stat sb; + struct statfs sfb; + char *xargv[4]; + char ibuf[64]; char *fsname; int inonum, error; + if (argc == 2) { + if (stat(argv[1], &sb) != 0) + err(1, "stat(%s)", argv[1]); + if (statfs(argv[1], &sfb) != 0) + err(1, "statfs(%s)", argv[1]); + xargv[0] = argv[0]; + xargv[1] = sfb.f_mntfromname; + sprintf(ibuf, "%jd", (intmax_t)sb.st_ino); + xargv[2] = ibuf; + xargv[3] = NULL; + argv = xargv; + argc = 3; + } if (argc < 3) { - (void)fprintf(stderr,"usage: prtblknos filesystem inode ...\n"); + (void)fprintf(stderr, "%s\n%s\n", + "usage: prtblknos filename", + " prtblknos filesystem inode ..."); exit(1); } @@ -60,7 +80,7 @@ main(argc, argv) /* get the superblock. */ if ((error = ufs_disk_fillout(&disk, fsname)) < 0) - errx(1, "Cannot find file system superblock on %s\n", fsname); + err(1, "Cannot access file system superblock on %s", fsname); fs = (struct fs *)&disk.d_sb; /* remaining arguments are inode numbers. */ @@ -68,11 +88,11 @@ main(argc, argv) /* get the inode number. */ if ((inonum = atoi(*argv)) <= 0 || inonum >= fs->fs_ipg * fs->fs_ncg) - errx(1, "%s is not a valid inode number", *argv); - (void)printf("%d:", inonum); + warnx("%s is not a valid inode number", *argv); + (void)printf("%d: ", inonum); if ((error = getino(&disk, (void **)&dp, inonum, NULL)) < 0) - err(1, "Read of inode %d on %s failed", inonum, fsname); + warn("Read of inode %d on %s failed", inonum, fsname); prtblknos(&disk, dp); } Modified: head/tools/diag/prtblknos/prtblknos.c ============================================================================== --- head/tools/diag/prtblknos/prtblknos.c Wed Apr 18 22:24:44 2018 (r332741) +++ head/tools/diag/prtblknos/prtblknos.c Wed Apr 18 23:08:10 2018 (r332742) @@ -161,8 +161,13 @@ indirprt(disk, level, blksperindir, lbn, blkno, lastlb } printblk(fs, lbn, blkno, fs->fs_frag, -level); /* read in the indirect block. */ - if (bread(disk, fsbtodb(fs, blkno), indir, fs->fs_bsize) == -1) - err(1, "Read of indirect block %jd failed", (intmax_t)blkno); + if (bread(disk, fsbtodb(fs, blkno), indir, fs->fs_bsize) == -1) { + warn("Read of indirect block %jd failed", (intmax_t)blkno); + /* List the unreadable part as a hole */ + printblk(fs, lbn, 0, + blksperindir * NINDIR(fs) * fs->fs_frag, lastlbn); + return; + } last = howmany(lastlbn - lbn, blksperindir) < NINDIR(fs) ? howmany(lastlbn - lbn, blksperindir) : NINDIR(fs); if (blksperindir == 1) {