From: Theodore Ts'o Date: Wed, 1 Dec 2010 23:28:35 +0000 (-0500) Subject: mke2fs: Fail if the requested file system type is not defined in mke2fs.conf X-Git-Tag: v1.41.13~6 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=2ee4544d07af35a6a667400cca35657e37d55c3b;p=tools%2Fe2fsprogs.git mke2fs: Fail if the requested file system type is not defined in mke2fs.conf If the user passes a file system type which is not defined in mke2fs.conf (i.e., mke2fs -t xfs ...) change mke2fs so that it prints a warning and aborts the run. (There is an exception for ext2, since that file system does not need a special definition in the fs_types section of the /etc/mke2fs.conf file.) In addition, print a warning if there are usage types (specified using the -T option) which are not defined in /etc/mke2fs.conf. Addresses-Debian-Bug: #594609 Signed-off-by: "Theodore Ts'o" --- diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 9a7e287..188668e 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -934,6 +934,35 @@ static void print_str_list(char **list) fputc('\n', stdout); } +/* + * Return TRUE if the profile has the given subsection + */ +static int profile_has_subsection(profile_t profile, const char *section, + const char *subsection) +{ + void *state; + const char *names[4]; + char *name; + int ret = 0; + + names[0] = section; + names[1] = subsection; + names[2] = 0; + + if (profile_iterator_create(profile, names, + PROFILE_ITER_LIST_SECTION | + PROFILE_ITER_RELATIONS_ONLY, &state)) + return 0; + + if ((profile_iterator(&state, &name, 0) == 0) && name) { + free(name); + ret = 1; + } + + profile_iterator_free(&state); + return ret; +} + static char **parse_fs_type(const char *fs_type, const char *usage_types, struct ext2_super_block *fs_param, @@ -984,17 +1013,19 @@ static char **parse_fs_type(const char *fs_type, ext_type = "ext3"; } - if (!strcmp(ext_type, "ext3") || !strcmp(ext_type, "ext4") || - !strcmp(ext_type, "ext4dev")) { - profile_get_string(profile, "fs_types", ext_type, "features", - 0, &t); - if (!t) { - printf(_("\nWarning! Your mke2fs.conf file does " - "not define the %s filesystem type.\n"), - ext_type); + + if (!profile_has_subsection(profile, "fs_types", ext_type) && + strcmp(ext_type, "ext2")) { + printf(_("\nYour mke2fs.conf file does not define the " + "%s filesystem type.\n"), ext_type); + if (!strcmp(ext_type, "ext3") || !strcmp(ext_type, "ext4") || + !strcmp(ext_type, "ext4dev")) { printf(_("You probably need to install an updated " "mke2fs.conf file.\n\n")); - sleep(5); + } + if (!force) { + printf(_("Aborting...\n")); + exit(1); } } @@ -1027,8 +1058,15 @@ static char **parse_fs_type(const char *fs_type, if (t) *t = '\0'; - if (*cp) - push_string(&list, cp); + if (*cp) { + if (!profile_has_subsection(profile, "fs_types", cp)) + fprintf(stderr, + _("\nWarning: the fs_type %s is not " + "defined in /etc/mke2fs.conf\n\n"), + cp); + else + push_string(&list, cp); + } if (t) cp = t+1; else {