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 <err.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <sys/stat.h>
 #include <libufs.h>
 
 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) {
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to