Add `chdb' command to fsdb(8) to set direct block numbers.

Add the ability to set direct blocks numbers in inodes so that manual
corrections can be made. No checking of the values is attempted so
accidental or deliberate bad values can be set.

Submitted by: Chuck Silvers
MFC after:    1 week
This commit is contained in:
Kirk McKusick 2023-04-17 22:42:32 -07:00
parent 238271f4a6
commit 7636973c68

View file

@ -161,6 +161,7 @@ CMDFUNC(chatime); /* Change atime */
CMDFUNC(chinum); /* Change inode # of dirent */
CMDFUNC(chname); /* Change dirname of dirent */
CMDFUNC(chsize); /* Change size */
CMDFUNC(chdb); /* Change direct block pointer */
struct cmdtable cmds[] = {
{ "help", "Print out help", 1, 1, FL_RO, helpfn },
@ -195,6 +196,7 @@ struct cmdtable cmds[] = {
{ "mtime", "Change mtime of current inode to MTIME", 2, 2, FL_WR, chmtime },
{ "ctime", "Change ctime of current inode to CTIME", 2, 2, FL_WR, chctime },
{ "atime", "Change atime of current inode to ATIME", 2, 2, FL_WR, chatime },
{ "chdb", "Change db pointer N of current inode to BLKNO", 3, 3, FL_WR, chdb },
{ "quit", "Exit", 1, 1, FL_RO, quit },
{ "q", "Exit", 1, 1, FL_RO, quit },
{ "exit", "Exit", 1, 1, FL_RO, quit },
@ -1046,6 +1048,36 @@ CMDFUNCSTART(chsize)
return rval;
}
CMDFUNC(chdb)
{
unsigned int idx;
daddr_t bno;
char *cp;
if (!checkactive())
return 1;
idx = strtoull(argv[1], &cp, 0);
if (cp == argv[1] || *cp != '\0') {
warnx("bad pointer idx `%s'", argv[1]);
return 1;
}
bno = strtoll(argv[2], &cp, 0);
if (cp == argv[2] || *cp != '\0') {
warnx("bad block number `%s'", argv[2]);
return 1;
}
if (idx >= UFS_NDADDR) {
warnx("pointer index %d is out of range", idx);
return 1;
}
DIP_SET(curinode, di_db[idx], bno);
inodirty(&curip);
printactive(0);
return 0;
}
CMDFUNCSTART(linkcount)
{
int rval = 1;