git: 6dc19a71f70c - main - Add a -b option to fsck(8) to specify an alternative superblock.

From: Kirk McKusick <mckusick_at_FreeBSD.org>
Date: Sat, 21 Nov 2026 01:10:13 UTC
The branch main has been updated by mckusick:

URL: https://cgit.FreeBSD.org/src/commit/?id=6dc19a71f70c99b36e4384aff75b3d71033e71c5

commit 6dc19a71f70c99b36e4384aff75b3d71033e71c5
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2026-11-21 01:09:15 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2026-11-21 01:09:15 +0000

    Add a -b option to fsck(8) to specify an alternative superblock.
    
    Pass the -b flag from the wrapper to the underlying filesystem checker.
    This allows users to specify superblock directly without the need to
    invoke the underlying checker manually.
    
    Reported by: Aadya Chinubhai <aadyachinubhai@gmail.com>
    PR:          27687 (from May 2001)
    MFC after:   1 week
---
 sbin/fsck/fsck.8 | 5 +++++
 sbin/fsck/fsck.c | 9 +++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/sbin/fsck/fsck.8 b/sbin/fsck/fsck.8
index 271ac2843cd3..33c3f1e99513 100644
--- a/sbin/fsck/fsck.8
+++ b/sbin/fsck/fsck.8
@@ -37,6 +37,7 @@
 .Nm
 .Op Fl Cdfnpvy
 .Op Fl B | F
+.Op Fl b Ar block
 .Op Fl T Ar fstype : Ns Ar fsoptions
 .Op Fl t Ar fstype
 .Op Fl c Ar fstab
@@ -123,6 +124,10 @@ to fail with a message that the partition has an unknown file system type.
 .Pp
 The options are as follows:
 .Bl -tag -width indent
+.It Fl b Ar block 
+Use the block number 
+.Ar block
+as the super block for the file system.
 .It Fl C
 Check if the
 .Dq clean
diff --git a/sbin/fsck/fsck.c b/sbin/fsck/fsck.c
index 4c24cc9813e1..8293f2876c88 100644
--- a/sbin/fsck/fsck.c
+++ b/sbin/fsck/fsck.c
@@ -98,7 +98,7 @@ main(int argc, char *argv[])
 	struct fstab *fs;
 	int i, rval = 0;
 	const char *vfstype = NULL;
-	char globopt[3];
+	char globopt[3], bopt[80];
 	const char *etc_fstab;
 
 	globopt[0] = '-';
@@ -108,7 +108,7 @@ main(int argc, char *argv[])
 	TAILQ_INIT(&opthead);
 
 	etc_fstab = NULL;
-	while ((i = getopt(argc, argv, "BCdvpfFnyl:t:T:c:")) != -1)
+	while ((i = getopt(argc, argv, "BCdvpfFnyl:t:T:c:b:")) != -1)
 		switch (i) {
 		case 'B':
 			if (flags & CHECK_BACKGRD)
@@ -169,6 +169,11 @@ main(int argc, char *argv[])
 			etc_fstab = optarg;
 			break;
 
+		case 'b':
+			snprintf(bopt, sizeof(bopt), "-b=%s", optarg);
+			catopt(&options, bopt);
+			break;
+
 		case '?':
 		default:
 			usage();