aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirk McKusick <mckusick@FreeBSD.org>2020-09-19 20:06:12 +0000
committerKirk McKusick <mckusick@FreeBSD.org>2020-09-19 20:06:12 +0000
commit68d7185b6495e194e399289edc479ab85e5e4f3f (patch)
treed2d2df74ade978b59945997d2866d42852e22183
parent9ad1d357e0db6175124257156f035a043c2ced8c (diff)
downloadsrc-68d7185b6495e194e399289edc479ab85e5e4f3f.tar.gz
src-68d7185b6495e194e399289edc479ab85e5e4f3f.zip
The fsdb(8) utility uses the fsck_ffs(8) disk I/O interfaces, so
switch from using libufs's bread() to using fsck_ffs's getdatablk() when importing tools/diag/prtblnos's prtblknos(). Sponsored by: Netflix
Notes
Notes: svn path=/head/; revision=365912
-rw-r--r--sbin/fsdb/fsdb.c2
-rw-r--r--sbin/fsdb/fsdbutil.c4
-rw-r--r--tools/diag/prtblknos/Makefile2
-rw-r--r--tools/diag/prtblknos/main.c7
-rw-r--r--tools/diag/prtblknos/prtblknos.c36
5 files changed, 33 insertions, 18 deletions
diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c
index 5b179970a08e..ffffa389a206 100644
--- a/sbin/fsdb/fsdb.c
+++ b/sbin/fsdb/fsdb.c
@@ -109,6 +109,8 @@ main(int argc, char *argv[])
sblock_init();
if (!setup(fsys))
errx(1, "cannot set up file system `%s'", fsys);
+ if (fswritefd < 0)
+ nflag++;
printf("%s file system `%s'\nLast Mounted on %s\n",
nflag? "Examining": "Editing", fsys, sblock.fs_fsmnt);
rval = cmdloop();
diff --git a/sbin/fsdb/fsdbutil.c b/sbin/fsdb/fsdbutil.c
index fb7929913209..2c18d9910c6f 100644
--- a/sbin/fsdb/fsdbutil.c
+++ b/sbin/fsdb/fsdbutil.c
@@ -53,7 +53,7 @@ static const char rcsid[] =
#include "fsdb.h"
#include "fsck.h"
-void prtblknos(struct uufsd *disk, union dinode *dp);
+void prtblknos(struct fs *fs, union dinode *dp);
char **
crack(char *line, int *argc)
@@ -236,7 +236,7 @@ printactive(int doblocks)
case IFSOCK:
case IFIFO:
if (doblocks)
- prtblknos(&disk, curinode);
+ prtblknos(&sblock, curinode);
else
printstat("current inode", curinum, curinode);
break;
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);
}
}