git: 4b08a62ed441 - main - When running fsck_ffs(8) in background ensure that a superblock has been read.

From: Kirk McKusick <mckusick_at_FreeBSD.org>
Date: Fri, 26 May 2023 01:59:38 UTC
The branch main has been updated by mckusick:

URL: https://cgit.FreeBSD.org/src/commit/?id=4b08a62ed441668c103f834f5fe756ece5a8d9b3

commit 4b08a62ed441668c103f834f5fe756ece5a8d9b3
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2023-05-26 01:56:22 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2023-05-26 01:59:16 +0000

    When running fsck_ffs(8) in background ensure that a superblock has been read.
    
    Reported by:  Mikhail T.
    PR:           271352
    MFC after:    1 week
    Sponsored by: The FreeBSD Foundation
---
 sbin/fsck_ffs/main.c  | 5 ++++-
 sbin/fsck_ffs/setup.c | 8 ++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/sbin/fsck_ffs/main.c b/sbin/fsck_ffs/main.c
index 566fbe5ccd15..60a542785541 100644
--- a/sbin/fsck_ffs/main.c
+++ b/sbin/fsck_ffs/main.c
@@ -711,7 +711,10 @@ setup_bkgrdchk(struct statfs *mntp, int sbreadfailed, char **filesys)
 	}
 	free(sblock.fs_csp);
 	free(sblock.fs_si);
-	havesb = 0;
+	if (readsb() == 0) {
+		pwarn("CANNOT READ SNAPSHOT SUPERBLOCK\n");
+		return (0);
+	}
 	*filesys = snapname;
 	cmd.version = FFS_CMD_VERSION;
 	cmd.handle = fsreadfd;
diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c
index 1d62a733c2f6..fbcf069c9c97 100644
--- a/sbin/fsck_ffs/setup.c
+++ b/sbin/fsck_ffs/setup.c
@@ -88,8 +88,12 @@ setup(char *dev)
 	 * We are expected to have an open file descriptor and a superblock.
 	 */
 	if (fsreadfd < 0 || havesb == 0) {
-		if (debug)
-			printf("setup: bad fsreadfd or missing superblock\n");
+		if (debug) {
+			if (fsreadfd < 0)
+				printf("setup: missing fsreadfd\n");
+			else
+				printf("setup: missing superblock\n");
+		}
 		return (0);
 	}
 	if (preen == 0)