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
This commit is contained in:
Kirk McKusick 2018-04-18 23:08:10 +00:00
parent 15e4030e9e
commit c343fa81a8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=332742
2 changed files with 32 additions and 7 deletions

View File

@ -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);
}

View File

@ -161,8 +161,13 @@ indirprt(disk, level, blksperindir, lbn, blkno, lastlbn)
}
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) {