Skip to content

Commit

Permalink
The fsdb(8) utility uses the fsck_ffs(8) disk I/O interfaces, so
Browse files Browse the repository at this point in the history
switch from using libufs's bread() to using fsck_ffs's getdatablk()
when importing tools/diag/prtblnos's prtblknos().

Sponsored by: Netflix
  • Loading branch information
Kirk McKusick authored and Kirk McKusick committed Sep 19, 2020
1 parent 9ad1d35 commit 68d7185
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
2 changes: 2 additions & 0 deletions sbin/fsdb/fsdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions sbin/fsdb/fsdbutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions tools/diag/prtblknos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ LIBADD+=ufs

WARNS?= 3

CFLAGS+=-DPRTBLKNOS

test: ${PROG}
./${PROG} > a

Expand Down
7 changes: 4 additions & 3 deletions tools/diag/prtblknos/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
36 changes: 23 additions & 13 deletions tools/diag/prtblknos/prtblknos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -149,27 +154,32 @@ 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;
ufs2_daddr_t blkno;
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);
return;
}
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,
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 68d7185

Please sign in to comment.