From 7636973c68f15419a71bc8e4253b2fbae3258025 Mon Sep 17 00:00:00 2001 From: Kirk McKusick Date: Mon, 17 Apr 2023 22:42:32 -0700 Subject: [PATCH] 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 --- sbin/fsdb/fsdb.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c index a7d3a439b6b..887a77dbb8c 100644 --- a/sbin/fsdb/fsdb.c +++ b/sbin/fsdb/fsdb.c @@ -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;