Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Apr 2023 23:13:59 GMT
From:      Kirk McKusick <mckusick@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 7636973c68f1 - main - Add `chdb' command to fsdb(8) to set direct block numbers.
Message-ID:  <202304182313.33INDxJW095369@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by mckusick:

URL: https://cgit.FreeBSD.org/src/commit/?id=7636973c68f15419a71bc8e4253b2fbae3258025

commit 7636973c68f15419a71bc8e4253b2fbae3258025
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2023-04-18 05:42:32 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2023-04-18 23:13:26 +0000

    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 a7d3a439b6b3..887a77dbb8cb 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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202304182313.33INDxJW095369>