dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
0b5e55
diff -up util-linux-2.23.2/disk-utils/fsck.c.kzak util-linux-2.23.2/disk-utils/fsck.c
0b5e55
--- util-linux-2.23.2/disk-utils/fsck.c.kzak	2014-03-25 12:52:33.429389852 +0100
0b5e55
+++ util-linux-2.23.2/disk-utils/fsck.c	2014-03-25 12:56:27.126804792 +0100
0b5e55
@@ -79,9 +79,7 @@ static const char *really_wanted[] = {
0b5e55
 	"ext4dev",
0b5e55
 	"jfs",
0b5e55
 	"reiserfs",
0b5e55
-	"xiafs",
0b5e55
-	"xfs",
0b5e55
-	NULL
0b5e55
+	"xiafs"
0b5e55
 };
0b5e55
 
0b5e55
 /*
0b5e55
@@ -167,6 +165,19 @@ static int string_to_int(const char *s)
0b5e55
 		return (int) l;
0b5e55
 }
0b5e55
 
0b5e55
+/* Do we really really want to check this fs? */
0b5e55
+static int fs_check_required(const char *type)
0b5e55
+{
0b5e55
+	size_t i;
0b5e55
+
0b5e55
+	for(i = 0; i < ARRAY_SIZE(really_wanted); i++) {
0b5e55
+		if (strcmp(type, really_wanted[i]) == 0)
0b5e55
+			return 1;
0b5e55
+	}
0b5e55
+
0b5e55
+	return 0;
0b5e55
+}
0b5e55
+
0b5e55
 static int is_mounted(struct libmnt_fs *fs)
0b5e55
 {
0b5e55
 	int rc;
0b5e55
@@ -546,17 +557,17 @@ static void print_stats(struct fsck_inst
0b5e55
  * Execute a particular fsck program, and link it into the list of
0b5e55
  * child processes we are waiting for.
0b5e55
  */
0b5e55
-static int execute(const char *type, struct libmnt_fs *fs, int interactive)
0b5e55
+static int execute(const char *progname, const char *progpath,
0b5e55
+		   const char *type, struct libmnt_fs *fs, int interactive)
0b5e55
 {
0b5e55
-	char *s, *argv[80], prog[80];
0b5e55
+	char *argv[80];
0b5e55
 	int  argc, i;
0b5e55
 	struct fsck_instance *inst, *p;
0b5e55
 	pid_t	pid;
0b5e55
 
0b5e55
 	inst = xcalloc(1, sizeof(*inst));
0b5e55
 
0b5e55
-	sprintf(prog, "fsck.%s", type);
0b5e55
-	argv[0] = xstrdup(prog);
0b5e55
+	argv[0] = xstrdup(progname);
0b5e55
 	argc = 1;
0b5e55
 
0b5e55
 	for (i=0; i 
0b5e55
@@ -583,19 +594,12 @@ static int execute(const char *type, str
0b5e55
 	argv[argc++] = xstrdup(fs_get_device(fs));
0b5e55
 	argv[argc] = 0;
0b5e55
 
0b5e55
-	s = find_fsck(prog);
0b5e55
-	if (s == NULL) {
0b5e55
-		warnx(_("%s: not found"), prog);
0b5e55
-		free(inst);
0b5e55
-		return ENOENT;
0b5e55
-	}
0b5e55
-
0b5e55
 	if (verbose || noexecute) {
0b5e55
 		const char *tgt = mnt_fs_get_target(fs);
0b5e55
 
0b5e55
 		if (!tgt)
0b5e55
 			tgt = fs_get_device(fs);
0b5e55
-		printf("[%s (%d) -- %s] ", s, num_running, tgt);
0b5e55
+		printf("[%s (%d) -- %s] ", progpath, num_running, tgt);
0b5e55
 		for (i=0; i < argc; i++)
0b5e55
 			printf("%s ", argv[i]);
0b5e55
 		printf("\n");
0b5e55
@@ -617,15 +621,15 @@ static int execute(const char *type, str
0b5e55
 	} else if (pid == 0) {
0b5e55
 		if (!interactive)
0b5e55
 			close(0);
0b5e55
-		execv(s, argv);
0b5e55
-		err(FSCK_EX_ERROR, _("%s: execute failed"), s);
0b5e55
+		execv(progpath, argv);
0b5e55
+		err(FSCK_EX_ERROR, _("%s: execute failed"), progpath);
0b5e55
 	}
0b5e55
 
0b5e55
 	for (i=0; i < argc; i++)
0b5e55
 		free(argv[i]);
0b5e55
 
0b5e55
 	inst->pid = pid;
0b5e55
-	inst->prog = xstrdup(prog);
0b5e55
+	inst->prog = xstrdup(progname);
0b5e55
 	inst->type = xstrdup(type);
0b5e55
 	gettimeofday(&inst->start_time, NULL);
0b5e55
 	inst->next = NULL;
0b5e55
@@ -822,6 +826,7 @@ static int wait_many(int flags)
0b5e55
  */
0b5e55
 static int fsck_device(struct libmnt_fs *fs, int interactive)
0b5e55
 {
0b5e55
+	char progname[80], *progpath;
0b5e55
 	const char *type;
0b5e55
 	int retval;
0b5e55
 
0b5e55
@@ -838,15 +843,27 @@ static int fsck_device(struct libmnt_fs
0b5e55
 	else
0b5e55
 		type = DEFAULT_FSTYPE;
0b5e55
 
0b5e55
+	sprintf(progname, "fsck.%s", type);
0b5e55
+	progpath = find_fsck(progname);
0b5e55
+	if (progpath == NULL) {
0b5e55
+		if (fs_check_required(type)) {
0b5e55
+			retval = ENOENT;
0b5e55
+			goto err;
0b5e55
+		}
0b5e55
+		return 0;
0b5e55
+	}
0b5e55
+
0b5e55
 	num_running++;
0b5e55
-	retval = execute(type, fs, interactive);
0b5e55
+	retval = execute(progname, progpath, type, fs, interactive);
0b5e55
 	if (retval) {
0b5e55
-		warnx(_("error %d while executing fsck.%s for %s"),
0b5e55
-			retval, type, fs_get_device(fs));
0b5e55
 		num_running--;
0b5e55
-		return FSCK_EX_ERROR;
0b5e55
+		goto err;
0b5e55
 	}
0b5e55
 	return 0;
0b5e55
+err:
0b5e55
+	warnx(_("error %d (%m) while executing fsck.%s for %s"),
0b5e55
+			retval, type, fs_get_device(fs));
0b5e55
+	return FSCK_EX_ERROR;
0b5e55
 }
0b5e55
 
0b5e55
 
0b5e55
@@ -1014,8 +1031,7 @@ static int fs_ignored_type(struct libmnt
0b5e55
 /* Check if we should ignore this filesystem. */
0b5e55
 static int ignore(struct libmnt_fs *fs)
0b5e55
 {
0b5e55
-	const char **ip, *type;
0b5e55
-	int wanted = 0;
0b5e55
+	const char *type;
0b5e55
 
0b5e55
 	/*
0b5e55
 	 * If the pass number is 0, ignore it.
0b5e55
@@ -1070,16 +1086,11 @@ static int ignore(struct libmnt_fs *fs)
0b5e55
 	if (fs_ignored_type(fs))
0b5e55
 		return 1;
0b5e55
 
0b5e55
-	/* Do we really really want to check this fs? */
0b5e55
-	for(ip = really_wanted; *ip; ip++)
0b5e55
-		if (strcmp(type, *ip) == 0) {
0b5e55
-			wanted = 1;
0b5e55
-			break;
0b5e55
-		}
0b5e55
+
0b5e55
 
0b5e55
 	/* See if the <fsck.fs> program is available. */
0b5e55
 	if (find_fsck(type) == NULL) {
0b5e55
-		if (wanted)
0b5e55
+		if (fs_check_required(type))
0b5e55
 			warnx(_("cannot check %s: fsck.%s not found"),
0b5e55
 				fs_get_device(fs), type);
0b5e55
 		return 1;
0b5e55
@@ -1557,7 +1568,6 @@ int main(int argc, char *argv[])
0b5e55
 			fs = add_dummy_fs(devices[i]);
0b5e55
 		else if (fs_ignored_type(fs))
0b5e55
 			continue;
0b5e55
-
0b5e55
 		if (ignore_mounted && is_mounted(fs))
0b5e55
 			continue;
0b5e55
 		status |= fsck_device(fs, interactive);