Changeset View
Changeset View
Standalone View
Standalone View
sbin/fsdb/fsdb.c
Show First 20 Lines • Show All 225 Lines • ▼ Show 20 Lines | cmdloop(void) | ||||
int cmd_argc, rval = 0, known; | int cmd_argc, rval = 0, known; | ||||
#define scratch known | #define scratch known | ||||
char **cmd_argv; | char **cmd_argv; | ||||
struct cmdtable *cmdp; | struct cmdtable *cmdp; | ||||
History *hist; | History *hist; | ||||
EditLine *elptr; | EditLine *elptr; | ||||
HistEvent he; | HistEvent he; | ||||
curinode = ginode(ROOTINO); | curinode = ginode(UFS_ROOTINO); | ||||
curinum = ROOTINO; | curinum = UFS_ROOTINO; | ||||
printactive(0); | printactive(0); | ||||
hist = history_init(); | hist = history_init(); | ||||
history(hist, &he, H_SETSIZE, 100); /* 100 elt history buffer */ | history(hist, &he, H_SETSIZE, 100); /* 100 elt history buffer */ | ||||
elptr = el_init("fsdb", stdin, stdout, stderr); | elptr = el_init("fsdb", stdin, stdout, stderr); | ||||
el_set(elptr, EL_EDITOR, "emacs"); | el_set(elptr, EL_EDITOR, "emacs"); | ||||
el_set(elptr, EL_PROMPT, prompt); | el_set(elptr, EL_PROMPT, prompt); | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | if (rval) | ||||
history_end(hist); | history_end(hist); | ||||
return rval; | return rval; | ||||
} | } | ||||
union dinode *curinode; | union dinode *curinode; | ||||
ino_t curinum, ocurrent; | ino_t curinum, ocurrent; | ||||
#define GETINUM(ac,inum) inum = strtoul(argv[ac], &cp, 0); \ | #define GETINUM(ac,inum) inum = strtoul(argv[ac], &cp, 0); \ | ||||
if (inum < ROOTINO || inum > maxino || cp == argv[ac] || *cp != '\0' ) { \ | if (inum < UFS_ROOTINO || inum > maxino || cp == argv[ac] || \ | ||||
*cp != '\0' ) { \ | |||||
printf("inode %ju out of range; range is [%ju,%ju]\n", \ | printf("inode %ju out of range; range is [%ju,%ju]\n", \ | ||||
(uintmax_t)inum, (uintmax_t)ROOTINO, (uintmax_t)maxino); \ | (uintmax_t)inum, (uintmax_t)UFS_ROOTINO, (uintmax_t)maxino);\ | ||||
return 1; \ | return 1; \ | ||||
} | } | ||||
/* | /* | ||||
* Focus on given inode number | * Focus on given inode number | ||||
*/ | */ | ||||
CMDFUNCSTART(focus) | CMDFUNCSTART(focus) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | CMDFUNCSTART(findblk) | ||||
* For UFS1 all inodes initialized at the newfs stage. | * For UFS1 all inodes initialized at the newfs stage. | ||||
*/ | */ | ||||
if (is_ufs2) | if (is_ufs2) | ||||
inosused = cgp->cg_initediblk; | inosused = cgp->cg_initediblk; | ||||
else | else | ||||
inosused = sblock.fs_ipg; | inosused = sblock.fs_ipg; | ||||
for (; inosused > 0; inum++, inosused--) { | for (; inosused > 0; inum++, inosused--) { | ||||
/* Skip magic inodes: 0, WINO, ROOTINO. */ | /* Skip magic inodes: 0, UFS_WINO, UFS_ROOTINO. */ | ||||
if (inum < ROOTINO) | if (inum < UFS_ROOTINO) | ||||
continue; | continue; | ||||
/* | /* | ||||
* Check if the block we are looking for is just an inode block. | * Check if the block we are looking for is just an inode block. | ||||
* | * | ||||
* ino_to_fsba() - get block containing inode from its number. | * ino_to_fsba() - get block containing inode from its number. | ||||
* INOPB() - get a number of inodes in one disk block. | * INOPB() - get a number of inodes in one disk block. | ||||
*/ | */ | ||||
if (is_ufs2 ? | if (is_ufs2 ? | ||||
Show All 27 Lines | break; | ||||
else | else | ||||
break; | break; | ||||
} | } | ||||
default: | default: | ||||
continue; | continue; | ||||
} | } | ||||
/* Look through direct data blocks. */ | /* Look through direct data blocks. */ | ||||
if (is_ufs2 ? | if (is_ufs2 ? | ||||
find_blks64(curinode->dp2.di_db, NDADDR, wantedblk64) : | find_blks64(curinode->dp2.di_db, UFS_NDADDR, wantedblk64) : | ||||
find_blks32(curinode->dp1.di_db, NDADDR, wantedblk32)) | find_blks32(curinode->dp1.di_db, UFS_NDADDR, wantedblk32)) | ||||
goto end; | goto end; | ||||
for (i = 0; i < NIADDR; i++) { | for (i = 0; i < UFS_NIADDR; i++) { | ||||
/* | /* | ||||
* Does the block we are looking for belongs to the | * Does the block we are looking for belongs to the | ||||
* indirect blocks? | * indirect blocks? | ||||
*/ | */ | ||||
if (is_ufs2 ? | if (is_ufs2 ? | ||||
compare_blk64(wantedblk64, curinode->dp2.di_ib[i]) : | compare_blk64(wantedblk64, curinode->dp2.di_ib[i]) : | ||||
compare_blk32(wantedblk32, curinode->dp1.di_ib[i])) | compare_blk32(wantedblk32, curinode->dp1.di_ib[i])) | ||||
if (founddatablk(is_ufs2 ? curinode->dp2.di_ib[i] : | if (founddatablk(is_ufs2 ? curinode->dp2.di_ib[i] : | ||||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | CMDFUNCSTART(focusname) | ||||
char *p, *val; | char *p, *val; | ||||
if (!checkactive()) | if (!checkactive()) | ||||
return 1; | return 1; | ||||
ocurrent = curinum; | ocurrent = curinum; | ||||
if (argv[1][0] == '/') { | if (argv[1][0] == '/') { | ||||
curinum = ROOTINO; | curinum = UFS_ROOTINO; | ||||
curinode = ginode(ROOTINO); | curinode = ginode(UFS_ROOTINO); | ||||
} else { | } else { | ||||
if (!checkactivedir()) | if (!checkactivedir()) | ||||
return 1; | return 1; | ||||
} | } | ||||
for (p = argv[1]; p != NULL;) { | for (p = argv[1]; p != NULL;) { | ||||
while ((val = strsep(&p, "/")) != NULL && *val == '\0'); | while ((val = strsep(&p, "/")) != NULL && *val == '\0'); | ||||
if (val) { | if (val) { | ||||
printf("component `%s': ", val); | printf("component `%s': ", val); | ||||
▲ Show 20 Lines • Show All 472 Lines • Show Last 20 Lines |