aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/diag/prtblknos/Makefile2
-rw-r--r--tools/diag/prtblknos/main.c7
-rw-r--r--tools/diag/prtblknos/prtblknos.c36
3 files changed, 29 insertions, 16 deletions
diff --git a/tools/diag/prtblknos/Makefile b/tools/diag/prtblknos/Makefile
index a813bb6a2fd0..385692c820ca 100644
--- a/tools/diag/prtblknos/Makefile
+++ b/tools/diag/prtblknos/Makefile
@@ -11,6 +11,8 @@ LIBADD+=ufs
WARNS?= 3
+CFLAGS+=-DPRTBLKNOS
+
test: ${PROG}
./${PROG} > a
diff --git a/tools/diag/prtblknos/main.c b/tools/diag/prtblknos/main.c
index c3abb2babad1..25a717760922 100644
--- a/tools/diag/prtblknos/main.c
+++ b/tools/diag/prtblknos/main.c
@@ -39,14 +39,15 @@ union dinode {
struct ufs2_dinode *dp2;
};
-void prtblknos(struct uufsd *disk, union dinode *dp);
+void prtblknos(struct fs *fs, union dinode *dp);
+
+struct uufsd disk;
int
main(argc, argv)
int argc;
char *argv[];
{
- struct uufsd disk;
union dinodep dp;
struct fs *fs;
struct stat sb;
@@ -102,7 +103,7 @@ main(argc, argv)
warn("Read of inode %jd on %s failed: %s",
(intmax_t)inonum, fsname, disk.d_error);
- prtblknos(&disk, (union dinode *)dp.dp1);
+ prtblknos(fs, (union dinode *)dp.dp1);
}
exit(0);
}
diff --git a/tools/diag/prtblknos/prtblknos.c b/tools/diag/prtblknos/prtblknos.c
index f042bae606f1..771d79e43ec9 100644
--- a/tools/diag/prtblknos/prtblknos.c
+++ b/tools/diag/prtblknos/prtblknos.c
@@ -31,32 +31,37 @@
#include <err.h>
#include <stdio.h>
+#include <string.h>
#include <libufs.h>
+#ifdef PRTBLKNOS
union dinode {
struct ufs1_dinode dp1;
struct ufs2_dinode dp2;
};
+extern struct uufsd disk;
+#else /* used by fsdb */
+#include <fsck.h>
+static struct bufarea *bp;
+#endif
-void prtblknos(struct uufsd *disk, union dinode *dp);
+void prtblknos(struct fs *fs, union dinode *dp);
static const char *distance(struct fs *, ufs2_daddr_t, ufs2_daddr_t);
static void printblk(struct fs *, ufs_lbn_t, ufs2_daddr_t, int, ufs_lbn_t);
-static void indirprt(struct uufsd *, int, ufs_lbn_t, ufs_lbn_t, ufs2_daddr_t,
+static void indirprt(struct fs *, int, ufs_lbn_t, ufs_lbn_t, ufs2_daddr_t,
ufs_lbn_t);
void
-prtblknos(disk, dp)
- struct uufsd *disk;
+prtblknos(fs, dp)
+ struct fs *fs;
union dinode *dp;
{
int i, mode, frags;
ufs_lbn_t lbn, lastlbn, len, blksperindir;
ufs2_daddr_t blkno;
- struct fs *fs;
off_t size;
- fs = (struct fs *)&disk->d_sb;
if (fs->fs_magic == FS_UFS1_MAGIC) {
size = dp->dp1.di_size;
mode = dp->dp1.di_mode;
@@ -138,7 +143,7 @@ prtblknos(disk, dp)
blkno = dp->dp1.di_ib[i];
else
blkno = dp->dp2.di_ib[i];
- indirprt(disk, i, blksperindir, lbn, blkno, lastlbn);
+ indirprt(fs, i, blksperindir, lbn, blkno, lastlbn);
blksperindir *= NINDIR(fs);
lbn += blksperindir;
len -= blksperindir;
@@ -149,8 +154,8 @@ prtblknos(disk, dp)
}
static void
-indirprt(disk, level, blksperindir, lbn, blkno, lastlbn)
- struct uufsd *disk;
+indirprt(fs, level, blksperindir, lbn, blkno, lastlbn)
+ struct fs *fs;
int level;
ufs_lbn_t blksperindir;
ufs_lbn_t lbn;
@@ -158,10 +163,8 @@ indirprt(disk, level, blksperindir, lbn, blkno, lastlbn)
ufs_lbn_t lastlbn;
{
char indir[MAXBSIZE];
- struct fs *fs;
ufs_lbn_t i, last;
- fs = (struct fs *)&disk->d_sb;
if (blkno == 0) {
printblk(fs, lbn, blkno,
blksperindir * NINDIR(fs) * fs->fs_frag, lastlbn);
@@ -169,7 +172,14 @@ 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) {
+#ifdef PRTBLKNOS
+ if (bread(&disk, fsbtodb(fs, blkno), indir, fs->fs_bsize) == -1) {
+#else /* used by fsdb */
+ bp = getdatablk(blkno, fs->fs_bsize, BT_LEVEL1 + level);
+ if (bp->b_errs == 0) {
+ memcpy(indir, bp->b_un.b_buf, fs->fs_bsize);
+ } else {
+#endif
warn("Read of indirect block %jd failed", (intmax_t)blkno);
/* List the unreadable part as a hole */
printblk(fs, lbn, 0,
@@ -193,7 +203,7 @@ indirprt(disk, level, blksperindir, lbn, blkno, lastlbn)
blkno = ((ufs1_daddr_t *)indir)[i];
else
blkno = ((ufs2_daddr_t *)indir)[i];
- indirprt(disk, level - 1, blksperindir / NINDIR(fs),
+ indirprt(fs, level - 1, blksperindir / NINDIR(fs),
lbn + blksperindir * i, blkno, lastlbn);
}
}