Date: Sun, 27 Feb 2022 01:35:18 GMT From: Kirk McKusick <mckusick@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 5f3cd10138a1 - stable/13 - Update fsdb(8) to reflect new structure of fsck_ffs(8). Message-ID: <202202270135.21R1ZI4g017376@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=5f3cd10138a1ab2a25aec92e59cba1754aa37a58 commit 5f3cd10138a1ab2a25aec92e59cba1754aa37a58 Author: Kirk McKusick <mckusick@FreeBSD.org> AuthorDate: 2022-02-23 23:39:52 +0000 Commit: Kirk McKusick <mckusick@FreeBSD.org> CommitDate: 2022-02-26 21:38:48 +0000 Update fsdb(8) to reflect new structure of fsck_ffs(8). (cherry picked from commit c5d476c98c2275966f68c7b81dab2421b143f5a9) --- 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 7c16f9c9737d..45bb279ce374 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 *); @@ -713,44 +712,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 375ba897199a..45662636557d 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++;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202202270135.21R1ZI4g017376>