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);
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 *);
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)
{
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.
*/
sblock_init(void)
{
+ fsreadfd = -1;
fswritefd = -1;
fsmodified = 0;
lfdir = 0;
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++;