fsck.c revision dce818b390a857a11f7dd634684500675cf79833
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <libudev.h>
#include "util.h"
#include "dbus-common.h"
#include "special.h"
#include "bus-errors.h"
#include "virt.h"
static bool arg_skip = false;
static bool arg_force = false;
static bool arg_show_progress = false;
goto finish;
}
if (isolate)
mode = "isolate";
else
mode = "replace";
if (!(m = dbus_message_new_method_call("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartUnitReplace"))) {
log_error("Could not allocate message.");
goto finish;
}
/* Start these units only if we can replace base.target with it */
if (!dbus_message_append_args(m,
log_error("Could not attach target and flag information to message.");
goto finish;
}
/* Don't print a warning if we aren't called during
* startup */
goto finish;
}
if (m)
if (reply)
if (bus) {
}
}
static int parse_proc_cmdline(void) {
int r;
size_t l;
if (detect_container(NULL) > 0)
return 0;
return 0;
}
if (strneq(w, "fsck.mode=auto", l))
else if (strneq(w, "fsck.mode=force", l))
arg_force = true;
else if (strneq(w, "fsck.mode=skip", l))
arg_skip = true;
else if (startswith(w, "fsck.mode"))
log_warning("Invalid fsck.mode= parameter. Ignoring.");
else if (strneq(w, "fastboot", l))
arg_skip = true;
else if (strneq(w, "forcefsck", l))
arg_force = true;
#endif
}
return 0;
}
static void test_files(void) {
arg_skip = true;
arg_force = true;
arg_show_progress = true;
}
/* Values stolen from e2fsck */
static const int pass_table[] = {
0, 70, 90, 92, 95, 100
};
if (pass <= 0)
return 0.0;
return 100.0;
}
static int process_progress(int fd) {
bool locked = false;
int clear = 0;
if (!f) {
return -errno;
}
if (!console) {
fclose(f);
return -ENOMEM;
}
while (!feof(f)) {
int pass, m;
char *device;
double p;
usec_t t;
break;
/* Only show one progress counter at max */
if (!locked) {
continue;
}
locked = true;
}
/* Only update once every 50ms */
t = now(CLOCK_MONOTONIC);
continue;
}
last = t;
if (m > clear)
clear = m;
}
if (clear > 0) {
unsigned j;
for (j = 0; j < (unsigned) clear; j++)
}
fclose(f);
return 0;
}
const char *cmdline[9];
int i = 0, r = EXIT_FAILURE, q;
const char *device;
bool root_directory;
if (argc > 2) {
log_error("This program expects one or no arguments.");
return EXIT_FAILURE;
}
log_open();
umask(0022);
test_files();
return 0;
if (argc > 1) {
root_directory = false;
} else {
/* Find root device */
log_error("Failed to stat() the root directory: %m");
goto finish;
}
/* Virtual root devices don't need an fsck */
return 0;
/* check if we are already writable */
log_info("Root directory is writable, skipping check.");
return 0;
}
log_error("Out of memory");
goto finish;
}
log_error("Failed to detect root device.");
goto finish;
}
log_error("Failed to detect device node of root directory.");
goto finish;
}
root_directory = true;
}
if (arg_show_progress)
if (pipe(progress_pipe) < 0) {
log_error("pipe(): %m");
goto finish;
}
cmdline[i++] = "-a";
cmdline[i++] = "-T";
cmdline[i++] = "-l";
if (!root_directory)
cmdline[i++] = "-M";
if (arg_force)
cmdline[i++] = "-f";
if (progress_pipe[1] >= 0) {
}
if (pid < 0) {
log_error("fork(): %m");
goto finish;
} else if (pid == 0) {
/* Child */
if (progress_pipe[0] >= 0)
}
if (progress_pipe[1] >= 0) {
}
if (progress_pipe[0] >= 0) {
progress_pipe[0] = -1;
}
if (q < 0) {
goto finish;
}
else
log_error("fsck failed due to unknown reason.");
/* System should be rebooted. */
start_target(SPECIAL_REBOOT_TARGET, false);
/* Some other problem */
start_target(SPECIAL_EMERGENCY_TARGET, true);
else {
r = EXIT_SUCCESS;
log_warning("Ignoring error.");
}
} else
r = EXIT_SUCCESS;
touch("/run/systemd/quotacheck");
if (udev_device)
if (udev)
return r;
}