#include "c.h"
#include "closestream.h"
#include "fileutils.h"
+#include "monotonic.h"
#define XALLOC_EXIT_CODE FSCK_EX_ERROR
#include "xalloc.h"
"ext4",
"ext4dev",
"jfs",
- "reiserfs",
- "xiafs"
+ "reiserfs"
};
/*
static char *fstype;
static struct fsck_instance *instance_list;
-static const char fsck_prefix_path[] = FS_SEARCH_PATH;
+#define FSCK_DEFAULT_PATH "/sbin"
static char *fsck_path;
+
/* parsed fstab and mtab */
static struct libmnt_table *fstab, *mtab;
static struct libmnt_cache *mntcache;
device = fs_get_device(fs);
if (device) {
int ambi = 0;
+ char *tp;
+ struct libmnt_cache *cache = mnt_table_get_cache(fstab);
- type = mnt_get_fstype(device, &ambi, mnt_table_get_cache(fstab));
+ tp = mnt_get_fstype(device, &ambi, cache);
if (!ambi)
- mnt_fs_set_fstype(fs, type);
+ mnt_fs_set_fstype(fs, tp);
+ if (!cache)
+ free(tp);
}
}
*/
static void print_stats(struct fsck_instance *inst)
{
- double time_diff;
+ struct timeval delta;
if (!inst || !report_stats || noexecute)
return;
- time_diff = (inst->end_time.tv_sec - inst->start_time.tv_sec)
- + (inst->end_time.tv_usec - inst->start_time.tv_usec) / 1E6;
+ timersub(&inst->end_time, &inst->start_time, &delta);
fprintf(stdout, "%s: status %d, rss %ld, "
- "real %f, user %d.%06d, sys %d.%06d\n",
+ "real %ld.%06ld, user %d.%06d, sys %d.%06d\n",
fs_get_device(inst->fs),
inst->exit_status,
inst->rusage.ru_maxrss,
- time_diff,
+ delta.tv_sec, delta.tv_usec,
(int)inst->rusage.ru_utime.tv_sec,
(int)inst->rusage.ru_utime.tv_usec,
(int)inst->rusage.ru_stime.tv_sec,
inst->pid = pid;
inst->prog = xstrdup(progname);
inst->type = xstrdup(type);
- gettimeofday(&inst->start_time, NULL);
+ gettime_monotonic(&inst->start_time);
inst->next = NULL;
/*
*/
static struct fsck_instance *wait_one(int flags)
{
- int status;
+ int status = 0;
int sig;
struct fsck_instance *inst, *inst2, *prev;
pid_t pid;
inst->exit_status = status;
inst->flags |= FLAG_DONE;
- gettimeofday(&inst->end_time, NULL);
+ gettime_monotonic(&inst->end_time);
memcpy(&inst->rusage, &rusage, sizeof(struct rusage));
if (progress && (inst->flags & FLAG_PROGRESS) &&
fprintf(out, _(" %s [options] -- [fs-options] [<filesystem> ...]\n"),
program_invocation_short_name);
+ fputs(USAGE_SEPARATOR, out);
+ fputs(_("Check and repair a Linux filesystem.\n"), out);
+
fputs(USAGE_OPTIONS, out);
fputs(_(" -A check all filesystems\n"), out);
fputs(_(" -C [<fd>] display progress bar; file descriptor is for GUIs\n"), out);
break;
case 'C':
progress = 1;
- if (arg[j+1]) {
+ if (arg[j+1]) { /* -C<fd> */
progress_fd = string_to_int(arg+j+1);
if (progress_fd < 0)
progress_fd = 0;
else
goto next_arg;
- } else if ((i+1) < argc &&
- !strncmp(argv[i+1], "-", 1) == 0) {
- progress_fd = string_to_int(argv[i]);
+ } else if (i+1 < argc && *argv[i+1] != '-') { /* -C <fd> */
+ progress_fd = string_to_int(argv[i+1]);
if (progress_fd < 0)
progress_fd = 0;
else {
{
int i, status = 0;
int interactive = 0;
- char *oldpath = getenv("PATH");
struct libmnt_fs *fs;
+ const char *path = getenv("PATH");
setvbuf(stdout, NULL, _IONBF, BUFSIZ);
setvbuf(stderr, NULL, _IONBF, BUFSIZ);
load_fs_info();
- /* Update our search path to include uncommon directories. */
- if (oldpath) {
- fsck_path = xmalloc (strlen (fsck_prefix_path) + 1 +
- strlen (oldpath) + 1);
- strcpy (fsck_path, fsck_prefix_path);
- strcat (fsck_path, ":");
- strcat (fsck_path, oldpath);
- } else {
- fsck_path = xstrdup(fsck_prefix_path);
- }
+ fsck_path = xstrdup(path && *path ? path : FSCK_DEFAULT_PATH);
if ((num_devices == 1) || (serialize))
interactive = 1;