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
This commit is contained in:
parent
9ad1d357e0
commit
68d7185b64
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -11,6 +11,8 @@ LIBADD+=ufs
|
||||
|
||||
WARNS?= 3
|
||||
|
||||
CFLAGS+=-DPRTBLKNOS
|
||||
|
||||
test: ${PROG}
|
||||
./${PROG} > a
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user