{
int dirfd = -1, fd = -1, len, ret = 0;
struct stat st;
+ bool cli_specified = false;
*fpath = malloc(PATH_MAX);
if (!*fpath)
/* first try relative to pwd or absolute path to cli configfile */
if (config_file) {
- dft->type = DEFAULTS_CLI_CONFIG;
+ cli_specified = true;
if (strlen(config_file) > PATH_MAX) {
errno = ENAMETOOLONG;
goto out;
}
- memcpy(*fpath, config_file, strlen(config_file));
+ /* Get absolute path to this file */
+ realpath(config_file, *fpath);
fd = openat(AT_FDCWD, config_file, O_NOFOLLOW, O_RDONLY);
}
/* on failure search for cli config or default file in sysconfdir */
if (fd < 0) {
- if (!config_file)
+ if (!cli_specified)
config_file = MKFS_XFS_DEFAULT_CONFIG;
len = snprintf(*fpath, PATH_MAX, "%s/%s", MKFS_XFS_CONF_DIR,
config_file);
fd = openat(dirfd, config_file, O_NOFOLLOW, O_RDONLY);
if (fd < 0)
goto out;
- if (!strcmp(config_file, MKFS_XFS_DEFAULT_CONFIG))
- dft->type = DEFAULTS_CONFIG;
}
ret = fstat(fd, &st);
out:
/* stat check is always fatal; missing is fatal only if cli-specified */
if (ret ||
- (fd < 0 && dft->type == DEFAULTS_CLI_CONFIG)) {
- fprintf(stderr,
-_("Unable to open %s config file: %s : %s\n"),
- default_type_str(dft->type), *fpath,
- strerror(errno));
+ (fd < 0 && cli_specified)) {
+ fprintf(stderr, _("Unable to open config file: %s : %s\n"),
+ *fpath, strerror(errno));
free(*fpath);
exit(1);
}
return -1;
}
- printf(_("config-file=%s\n"), config_file);
-
return 0;
}
bool nortalign;
};
-/*
- * File configuration type settings
- *
- * These are the different possibilities by which you can end up parsing
- * default settings with. DEFAULTS_BUILTIN indicates there was no configuration
- * file parsed and we are using the built-in defaults on this code.
- * DEFAULTS_CONFIG means the default configuration file was found and used.
- * DEFAULTS_CLI_CONFIG means the user asked for a custom configuration type
- * through the command line interface and it was used.
- */
-enum default_params_type {
- DEFAULTS_BUILTIN = 0,
- DEFAULTS_CONFIG,
- DEFAULTS_CLI_CONFIG,
-};
-
/*
* Default filesystem features and configuration values
*
* calculations.
*/
struct mkfs_default_params {
- enum default_params_type type; /* where the defaults came from */
-
int sectorsize;
int blocksize;
struct fsxattr fsx;
};
-static inline const char *default_type_str(enum default_params_type type)
-{
- switch (type) {
- case DEFAULTS_BUILTIN:
- return _("package built-in definitions");
- case DEFAULTS_CONFIG:
- return _("package default config file");
- case DEFAULTS_CLI_CONFIG:
- return _("CLI supplied file");
- }
- return _("Unkown\n");
-}
-
int
open_config_file(
const char *cli_config_file,
/* build time defaults */
struct mkfs_default_params dft = {
- .type = DEFAULTS_BUILTIN,
.sectorsize = XFS_MIN_SECTORSIZE,
.blocksize = 1 << XFS_DFL_BLOCKSIZE_LOG,
.sb_feat = {
ret = parse_defaults_file(fd, &dft, config_file);
if (ret) {
fprintf(stderr,
-_("Error parsing %s config file: %s : %s\n"),
- default_type_str(dft.type),
+_("Error parsing config file: %s : %s\n"),
config_file, strerror(errno));
free(config_file);
close(fd);
exit(1);
}
+ printf(_("Configuration file used for defaults: %s\n"),
+ config_file);
free(config_file);
close(fd);
}
- printf(_("Default configuration sourced from %s\n"),
- default_type_str(dft.type));
/*
* Done parsing defaults now, so memcpy defaults into CLI