The branch main has been updated by mckusick:

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

commit c5d476c98c2275966f68c7b81dab2421b143f5a9
Author:     Kirk McKusick <mckus...@freebsd.org>
AuthorDate: 2022-02-23 23:39:52 +0000
Commit:     Kirk McKusick <mckus...@freebsd.org>
CommitDate: 2022-02-23 23:40:58 +0000

    Update fsdb(8) to reflect new structure of fsck_ffs(8).
    
    The cleanup of fsck_ffs(8) in commit c0bfa109b942659f6 broke fsdb(8).
    This commit adds the one-line update needed in fsdb(8) to make it
    work with the new fsck_ffs(8) structure.
    
    Reported by: Chuck Silvers
    Tested by:   Chuck Silvers
    MFC after:   3 days
---
 sbin/fsck_ffs/fsck.h  |  1 +
 sbin/fsck_ffs/main.c  | 39 ---------------------------------------
 sbin/fsck_ffs/setup.c | 39 +++++++++++++++++++++++++++++++++++++++
 sbin/fsdb/fsdb.c      |  2 +-
 4 files changed, 41 insertions(+), 40 deletions(-)

diff --git a/sbin/fsck_ffs/fsck.h b/sbin/fsck_ffs/fsck.h
index 690a98038884..daa346826eff 100644
--- a/sbin/fsck_ffs/fsck.h
+++ b/sbin/fsck_ffs/fsck.h
@@ -490,6 +490,7 @@ struct inostat *inoinfo(ino_t inum);
 void           IOstats(char *what);
 int            linkup(ino_t orphan, ino_t parentdir, char *name);
 int            makeentry(ino_t parent, ino_t ino, const char *name);
+int            openfilesys(char *dev);
 void           panic(const char *fmt, ...) __printflike(1, 2);
 void           pass1(void);
 void           pass1b(void);
diff --git a/sbin/fsck_ffs/main.c b/sbin/fsck_ffs/main.c
index 9ea5f5b91110..2724893a5b9a 100644
--- a/sbin/fsck_ffs/main.c
+++ b/sbin/fsck_ffs/main.c
@@ -76,7 +76,6 @@ static void usage(void) __dead2;
 static intmax_t argtoimax(int flag, const char *req, const char *str, int 
base);
 static int checkfilesys(char *filesys);
 static int setup_bkgrdchk(struct statfs *mntp, int sbrdfailed, char **filesys);
-static int openfilesys(char *dev);
 static int chkdoreload(struct statfs *mntp);
 static struct statfs *getmntpt(const char *);
 
@@ -715,44 +714,6 @@ setup_bkgrdchk(struct statfs *mntp, int sbreadfailed, char 
**filesys)
        return (1);
 }
 
-/*
- * Open a device or file to be checked by fsck.
- */
-static int
-openfilesys(char *dev)
-{
-       struct stat statb;
-       int saved_fsreadfd;
-
-       if (stat(dev, &statb) < 0) {
-               pfatal("CANNOT STAT %s: %s\n", dev, strerror(errno));
-               return (0);
-       }
-       if ((statb.st_mode & S_IFMT) != S_IFCHR &&
-           (statb.st_mode & S_IFMT) != S_IFBLK) {
-               if (bkgrdflag != 0 && (statb.st_flags & SF_SNAPSHOT) == 0) {
-                       pfatal("BACKGROUND FSCK LACKS A SNAPSHOT\n");
-                       exit(EEXIT);
-               }
-               if (bkgrdflag != 0) {
-                       cursnapshot = statb.st_ino;
-               } else {
-                       pfatal("%s IS NOT A DISK DEVICE\n", dev);
-                       if (reply("CONTINUE") == 0)
-                               return (0);
-               }
-       }
-       saved_fsreadfd = fsreadfd;
-       if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
-               fsreadfd = saved_fsreadfd;
-               pfatal("CANNOT OPEN %s: %s\n", dev, strerror(errno));
-               return (0);
-       }
-       if (saved_fsreadfd != -1)
-               close(saved_fsreadfd);
-       return (1);
-}
-
 static int
 chkdoreload(struct statfs *mntp)
 {
diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c
index bbb8a854e999..66f4f59004cb 100644
--- a/sbin/fsck_ffs/setup.c
+++ b/sbin/fsck_ffs/setup.c
@@ -210,6 +210,44 @@ badsb:
        return (0);
 }
 
+/*
+ * Open a device or file to be checked by fsck.
+ */
+int
+openfilesys(char *dev)
+{
+       struct stat statb;
+       int saved_fsreadfd;
+
+       if (stat(dev, &statb) < 0) {
+               pfatal("CANNOT STAT %s: %s\n", dev, strerror(errno));
+               return (0);
+       }
+       if ((statb.st_mode & S_IFMT) != S_IFCHR &&
+           (statb.st_mode & S_IFMT) != S_IFBLK) {
+               if (bkgrdflag != 0 && (statb.st_flags & SF_SNAPSHOT) == 0) {
+                       pfatal("BACKGROUND FSCK LACKS A SNAPSHOT\n");
+                       exit(EEXIT);
+               }
+               if (bkgrdflag != 0) {
+                       cursnapshot = statb.st_ino;
+               } else {
+                       pfatal("%s IS NOT A DISK DEVICE\n", dev);
+                       if (reply("CONTINUE") == 0)
+                               return (0);
+               }
+       }
+       saved_fsreadfd = fsreadfd;
+       if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
+               fsreadfd = saved_fsreadfd;
+               pfatal("CANNOT OPEN %s: %s\n", dev, strerror(errno));
+               return (0);
+       }
+       if (saved_fsreadfd != -1)
+               close(saved_fsreadfd);
+       return (1);
+}
+
 /*
  * Read in the super block and its summary info.
  */
@@ -331,6 +369,7 @@ void
 sblock_init(void)
 {
 
+       fsreadfd = -1;
        fswritefd = -1;
        fsmodified = 0;
        lfdir = 0;
diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c
index 785aeb2b5a75..c935f88952b4 100644
--- a/sbin/fsdb/fsdb.c
+++ b/sbin/fsdb/fsdb.c
@@ -111,7 +111,7 @@ main(int argc, char *argv[])
                fsys = argv[0];
 
        sblock_init();
-       if (!setup(fsys))
+       if (openfilesys(fsys) == 0 || readsb(0) == 0 || setup(fsys) == 0)
                errx(1, "cannot set up file system `%s'", fsys);
        if (fswritefd < 0)
                nflag++;

Reply via email to