From dce63f71c4b901e776686cca351d4ff55badb425 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 20 Oct 2023 11:44:27 +0200 Subject: Cleanup: gensquashfs: merge xattr scanning code The fstree from file and directory xattr scanning code essentially do the same thing now. Except the later also _optionally_ reads xattrs from a directory source. Merge the two code paths. Signed-off-by: David Oberhollenzer --- bin/gensquashfs/src/mkfs.c | 70 +++------------------------------------------- 1 file changed, 4 insertions(+), 66 deletions(-) (limited to 'bin/gensquashfs/src/mkfs.c') diff --git a/bin/gensquashfs/src/mkfs.c b/bin/gensquashfs/src/mkfs.c index 39bc605..f5164ce 100644 --- a/bin/gensquashfs/src/mkfs.c +++ b/bin/gensquashfs/src/mkfs.c @@ -93,66 +93,6 @@ static int pack_files(sqfs_block_processor_t *data, fstree_t *fs, return 0; } -static int relabel_tree_dfs(const char *filename, sqfs_xattr_writer_t *xwr, - tree_node_t *n, void *selinux_handle, - void *xattrmap) -{ - char *path = fstree_get_path(n); - int ret; - - if (path == NULL) { - perror("getting absolute node path for SELinux relabeling"); - return -1; - } - - ret = sqfs_xattr_writer_begin(xwr, 0); - if (ret) { - sqfs_perror(filename, "recording xattr key-value pairs", ret); - return -1; - } - - if (xattrmap != NULL) - ret = xattr_apply_map_file(path, xattrmap, xwr); - - if (ret == 0 && selinux_handle != NULL) - ret = selinux_relable_node(selinux_handle, xwr, n, path); - - free(path); - if (ret == 0) - ret = sqfs_xattr_writer_end(xwr, &n->xattr_idx); - - if (ret) { - sqfs_perror(filename, "flushing completed key-value pairs", - ret); - return -1; - } - - if (S_ISDIR(n->mode)) { - for (n = n->data.children; n != NULL; n = n->next) { - if (relabel_tree_dfs(filename, xwr, n, - selinux_handle, xattrmap)) { - return -1; - } - } - } - - return 0; -} - -static int read_fstree(fstree_t *fs, options_t *opt, sqfs_xattr_writer_t *xwr, - void *selinux_handle, void *xattrmap) -{ - int ret; - - ret = fstree_from_file(fs, opt->infile, opt->packdir); - - if (ret == 0 && (selinux_handle != NULL || xattrmap != NULL)) - ret = relabel_tree_dfs(opt->cfg.filename, xwr, - fs->root, selinux_handle, xattrmap); - - return ret; -} - static void override_owner_dfs(const options_t *opt, tree_node_t *n) { if (opt->force_uid) @@ -219,7 +159,7 @@ int main(int argc, char **argv) if (ret != 0) goto out; } else { - if (read_fstree(&sqfs.fs, &opt, sqfs.xwr, sehnd, xattrmap)) + if (fstree_from_file(&sqfs.fs, opt.infile, opt.packdir)) goto out; } @@ -229,11 +169,9 @@ int main(int argc, char **argv) if (fstree_post_process(&sqfs.fs)) goto out; - if (opt.infile == NULL) { - if (xattrs_from_dir(&sqfs.fs, opt.packdir, sehnd, xattrmap, - sqfs.xwr, opt.scan_xattr)) { - goto out; - } + if (apply_xattrs(&sqfs.fs, opt.packdir, sehnd, xattrmap, + sqfs.xwr, opt.infile == NULL && opt.scan_xattr)) { + goto out; } if (sortfile != NULL) { -- cgit v1.2.3