diff options
Diffstat (limited to 'mkfs')
-rw-r--r-- | mkfs/mkfs.c | 24 | ||||
-rw-r--r-- | mkfs/mkfs.h | 5 | ||||
-rw-r--r-- | mkfs/options.c | 59 |
3 files changed, 14 insertions, 74 deletions
diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c index 371c578..e72b669 100644 --- a/mkfs/mkfs.c +++ b/mkfs/mkfs.c @@ -117,11 +117,16 @@ int main(int argc, char **argv) process_command_line(&opt, argc, argv); - if (sqfs_super_init(&super, opt.blksz, opt.def_mtime, opt.compressor)) + if (fstree_init(&fs, opt.blksz, opt.fs_defaults)) return EXIT_FAILURE; + if (sqfs_super_init(&super, opt.blksz, fs.defaults.st_mtime, + opt.compressor)) { + goto out_fstree; + } + if (id_table_init(&idtbl)) - return EXIT_FAILURE; + goto out_fstree; outfd = open(opt.outfile, opt.outmode, 0644); if (outfd < 0) { @@ -132,25 +137,20 @@ int main(int argc, char **argv) if (sqfs_super_write(&super, outfd)) goto out_outfd; - if (fstree_init(&fs, opt.blksz, opt.def_mtime, opt.def_mode, - opt.def_uid, opt.def_gid)) { - goto out_outfd; - } - if (read_fstree(&fs, &opt)) - goto out_fstree; + goto out_outfd; tree_node_sort_recursive(fs.root); if (fstree_gen_inode_table(&fs)) - goto out_fstree; + goto out_outfd; super.inode_count = fs.inode_tbl_size - 2; #ifdef WITH_SELINUX if (opt.selinux != NULL) { if (fstree_relabel_selinux(&fs, opt.selinux)) - goto out_fstree; + goto out_outfd; } #endif @@ -202,11 +202,11 @@ out_data: data_writer_destroy(data); out_cmp: cmp->destroy(cmp); -out_fstree: - fstree_cleanup(&fs); out_outfd: close(outfd); out_idtbl: id_table_cleanup(&idtbl); +out_fstree: + fstree_cleanup(&fs); return status; } diff --git a/mkfs/mkfs.h b/mkfs/mkfs.h index 4a39eb5..4031c74 100644 --- a/mkfs/mkfs.h +++ b/mkfs/mkfs.h @@ -24,11 +24,8 @@ #include <ctype.h> typedef struct { - unsigned int def_uid; - unsigned int def_gid; - unsigned int def_mode; - unsigned int def_mtime; E_SQFS_COMPRESSOR compressor; + char *fs_defaults; int outmode; int blksz; int devblksz; diff --git a/mkfs/options.c b/mkfs/options.c index e298a6c..8d724a8 100644 --- a/mkfs/options.c +++ b/mkfs/options.c @@ -24,21 +24,6 @@ static const char *short_opts = "s:F:D:X:c:b:B:d:fqhV"; static const char *short_opts = "F:D:X:c:b:B:d:fqhV"; #endif -enum { - DEF_UID = 0, - DEF_GID, - DEF_MODE, - DEF_MTIME, -}; - -static const char *defaults[] = { - [DEF_UID] = "uid", - [DEF_GID] = "gid", - [DEF_MODE] = "mode", - [DEF_MTIME] = "mtime", - NULL -}; - extern char *__progname; static const char *help_string = @@ -142,53 +127,11 @@ static long read_number(const char *name, const char *str, long min, long max) return result; } -static void process_defaults(options_t *opt, char *subopts) -{ - char *value; - int i; - - while (*subopts != '\0') { - i = getsubopt(&subopts, (char *const *)defaults, &value); - - if (value == NULL) { - fprintf(stderr, "Missing value for option %s\n", - defaults[i]); - exit(EXIT_FAILURE); - } - - switch (i) { - case DEF_UID: - opt->def_uid = read_number("Default user ID", value, - 0, 0xFFFFFFFF); - break; - case DEF_GID: - opt->def_gid = read_number("Default group ID", value, - 0, 0xFFFFFFFF); - break; - case DEF_MODE: - opt->def_mode = read_number("Default permissions", - value, 0, 0xFFFFFFFF); - break; - case DEF_MTIME: - opt->def_mtime = read_number("Default mtime", value, - 0, 0xFFFFFFFF); - break; - default: - fprintf(stderr, "Unknown option '%s'\n", value); - exit(EXIT_FAILURE); - } - } -} - void process_command_line(options_t *opt, int argc, char **argv) { bool have_compressor; int i; - opt->def_uid = 0; - opt->def_gid = 0; - opt->def_mode = 0755; - opt->def_mtime = 0; opt->outmode = O_WRONLY | O_CREAT | O_EXCL; opt->compressor = compressor_get_default(); opt->blksz = SQFS_DEFAULT_BLOCK_SIZE; @@ -230,7 +173,7 @@ void process_command_line(options_t *opt, int argc, char **argv) 4096, 0xFFFFFFFF); break; case 'd': - process_defaults(opt, optarg); + opt->fs_defaults = optarg; break; case 'f': opt->outmode = O_WRONLY | O_CREAT | O_TRUNC; |