[systemd-devel] [PATCH] make fsck fix mode a kernel command line option

Robert Schiele rschiele at gmail.com
Fri Sep 6 05:53:42 PDT 2013


In some situations it is desirable to set the fsck fix level from "-a"
to "-y".  This for instance might be a reasonable decision on embedded
systems where a user dealing with emergency mode is not available and
we prefer the risk of destroying the file system by an incorrect fsck
action over the risk of hanging in unhandled file system
inconsistencies that could be fixed.

The fix introduces a new kernel command line option
"fsck.fix=auto|yes|no" with "auto" being the default and thus not
changing default behavior to previous behavior. "auto" maps to the
fsck option "-a", "yes" maps to "-y", and "no" maps to "-n".
---
I was choosing the interface described above since according to my
observation this seems closest to how interfaces were constructed in
this area before.  I am open to suggestions though for better
interfaces if someone comes up with one.  Additionally I was not sure
whether the "no" option is practically useful but since it doesn't
seem completely out of place for me I included it for completeness.

Robert

 src/fsck/fsck.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c
index f298cf7..0beddb1 100644
--- a/src/fsck/fsck.c
+++ b/src/fsck/fsck.c
@@ -40,6 +40,11 @@
 static bool arg_skip = false;
 static bool arg_force = false;
 static bool arg_show_progress = false;
+static enum {
+        FSCK_FIX_AUTO,
+        FSCK_FIX_YES,
+        FSCK_FIX_NO
+} arg_fixmode = FSCK_FIX_AUTO;
 
 static void start_target(const char *target) {
         DBusMessage *m = NULL, *reply = NULL;
@@ -122,6 +127,12 @@ static int parse_proc_cmdline(void) {
                         arg_force = true;
                 else if (strneq(w, "fsck.mode=skip", l))
                         arg_skip = true;
+                else if (strneq(w, "fsck.fix=auto", l))
+                        arg_fixmode = FSCK_FIX_AUTO;
+                else if (strneq(w, "fsck.fix=yes", l))
+                        arg_fixmode = FSCK_FIX_YES;
+                else if (strneq(w, "fsck.fix=no", l))
+                        arg_fixmode = FSCK_FIX_NO;
                 else if (startswith(w, "fsck"))
                         log_warning("Invalid fsck parameter. Ignoring.");
 #ifdef HAVE_SYSV_COMPAT
@@ -326,7 +337,17 @@ int main(int argc, char *argv[]) {
                 }
 
         cmdline[i++] = "/sbin/fsck";
-        cmdline[i++] = "-a";
+        switch (arg_fixmode) {
+        case FSCK_FIX_AUTO:
+                cmdline[i++] = "-a";
+                break;
+        case FSCK_FIX_YES:
+                cmdline[i++] = "-y";
+                break;
+        case FSCK_FIX_NO:
+                cmdline[i++] = "-n";
+                break;
+        }
         cmdline[i++] = "-T";
         cmdline[i++] = "-l";
 
-- 
1.8.1.4


More information about the systemd-devel mailing list