mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 05:22:48 +07:00
Allow fsck for read-only mounted filesystems
When starting up a system booted from initramfs / may already be mounted (read-only), so we can safely fsck it before proceeding to remount it as read-write later (possibly). Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
+8
-5
@@ -115,8 +115,8 @@ static int fsck(int pass)
|
||||
}
|
||||
}
|
||||
|
||||
if (fismnt(fs->fs_file)) {
|
||||
_d("Skipping fsck of %s, already mounted on %s.", fs->fs_spec, fs->fs_file);
|
||||
if (ismnt("/proc/mounts", fs->fs_file, "rw")) {
|
||||
_d("Skipping fsck of %s, already mounted rw on %s.", fs->fs_spec, fs->fs_file);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -288,8 +288,8 @@ int main(int argc, char *argv[])
|
||||
.delay = 1000
|
||||
};
|
||||
uev_ctx_t loop;
|
||||
char *path;
|
||||
char cmd[256];
|
||||
char *path;
|
||||
|
||||
/*
|
||||
* finit/init/telinit client tool uses /dev/initctl pipe
|
||||
@@ -376,8 +376,11 @@ int main(int argc, char *argv[])
|
||||
* Check file filesystems in /etc/fstab
|
||||
*/
|
||||
for (int pass = 1; pass < 10 && !rescue; pass++) {
|
||||
if (fsck(pass))
|
||||
if (fsck(pass)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -406,7 +409,7 @@ int main(int argc, char *argv[])
|
||||
* the /etc/fstab file already.
|
||||
*/
|
||||
makedir("/dev/shm", 0755);
|
||||
if (!fismnt("/dev/shm") && !ismnt("/etc/fstab", "/dev/shm"))
|
||||
if (!fismnt("/dev/shm") && !ismnt("/etc/fstab", "/dev/shm", NULL))
|
||||
mount("shm", "/dev/shm", "tmpfs", 0, "mode=0777");
|
||||
|
||||
/*
|
||||
|
||||
+24
-5
@@ -429,12 +429,28 @@ void endfsent(void)
|
||||
}
|
||||
#endif /* HAVE_GETFSENT */
|
||||
|
||||
static int hasopt(char *opts, char *opt)
|
||||
{
|
||||
char buf[strlen(opts) + 1];
|
||||
char *ptr;
|
||||
|
||||
int ismnt(char *file, char *dir)
|
||||
memcpy(buf, opts, sizeof(buf));
|
||||
ptr = strtok(buf, ",");
|
||||
while (ptr) {
|
||||
if (!strcmp(ptr, opt))
|
||||
return 1;
|
||||
|
||||
ptr = strtok(NULL, ",");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ismnt(char *file, char *dir, char *mode)
|
||||
{
|
||||
FILE *fp;
|
||||
int found = 0;
|
||||
struct mntent *mnt;
|
||||
int found = 0;
|
||||
FILE *fp;
|
||||
|
||||
fp = setmntent(file, "r");
|
||||
if (!fp)
|
||||
@@ -442,7 +458,10 @@ int ismnt(char *file, char *dir)
|
||||
|
||||
while ((mnt = getmntent(fp))) {
|
||||
if (!strcmp(mnt->mnt_dir, dir)) {
|
||||
found = 1;
|
||||
if (mode && hasopt(mnt->mnt_opts, mode))
|
||||
found = 1;
|
||||
else
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -454,7 +473,7 @@ int ismnt(char *file, char *dir)
|
||||
/* Requires /proc to be mounted */
|
||||
int fismnt(char *dir)
|
||||
{
|
||||
return ismnt("/proc/mounts", dir);
|
||||
return ismnt("/proc/mounts", dir, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ static inline int create(char *path, mode_t mode, uid_t uid, gid_t gid)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ismnt (char *file, char *dir);
|
||||
int ismnt (char *file, char *dir, char *mode);
|
||||
int fismnt (char *dir);
|
||||
|
||||
#endif /* FINIT_HELPERS_H_ */
|
||||
|
||||
Reference in New Issue
Block a user