From e2bc2608477392685affc2d8e0a46088a8e1ef1c Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 26 Aug 2012 23:34:52 -0500 Subject: [PATCH] wimlib_add_image(): Fewer parameters No more description and flags_element parameters. There are separate functions to set those. --- programs/imagex.c | 63 ++++++++++++++++++++++++++++++------------- src/modify.c | 10 +++---- src/ntfs-capture.c | 7 ++--- src/wimlib.h | 11 ++++---- src/wimlib_internal.h | 1 - src/xml.c | 36 ++++++++++++++++++------- src/xml.h | 3 +-- 7 files changed, 82 insertions(+), 49 deletions(-) diff --git a/programs/imagex.c b/programs/imagex.c index 8afccd1d..9bd0ecc6 100644 --- a/programs/imagex.c +++ b/programs/imagex.c @@ -125,11 +125,12 @@ static const struct option common_options[] = { }; static const struct option append_options[] = { - {"boot", no_argument, NULL, 'b'}, - {"check", no_argument, NULL, 'c'}, - {"flags", required_argument, NULL, 'f'}, - {"dereference", no_argument, NULL, 'L'}, - {"config", required_argument, NULL, 'C'}, + {"boot", no_argument, NULL, 'b'}, + {"check", no_argument, NULL, 'c'}, + {"flags", required_argument, NULL, 'f'}, + {"verbose", no_argument, NULL, 'v'}, + {"dereference", no_argument, NULL, 'L'}, + {"config", required_argument, NULL, 'C'}, {NULL, 0, NULL, 0}, }; static const struct option apply_options[] = { @@ -140,13 +141,13 @@ static const struct option apply_options[] = { {NULL, 0, NULL, 0}, }; static const struct option capture_options[] = { - {"boot", no_argument, NULL, 'b'}, - {"check", no_argument, NULL, 'c'}, - {"compress", optional_argument, NULL, 'x'}, - {"flags", required_argument, NULL, 'f'}, - {"verbose", no_argument, NULL,'v'}, - {"dereference", no_argument, NULL, 'L'}, - {"config", required_argument, NULL, 'C'}, + {"boot", no_argument, NULL, 'b'}, + {"check", no_argument, NULL, 'c'}, + {"compress", optional_argument, NULL, 'x'}, + {"flags", required_argument, NULL, 'f'}, + {"verbose", no_argument, NULL, 'v'}, + {"dereference", no_argument, NULL, 'L'}, + {"config", required_argument, NULL, 'C'}, {NULL, 0, NULL, 0}, }; static const struct option delete_options[] = { @@ -352,6 +353,7 @@ static int imagex_append(int argc, const char **argv) size_t config_len = 0; WIMStruct *w; int ret; + int cur_image; for_opt(c, append_options) { switch (c) { @@ -371,6 +373,9 @@ static int imagex_append(int argc, const char **argv) case 'L': add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE; break; + case 'v': + add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_VERBOSE; + break; default: usage(APPEND); return -1; @@ -407,8 +412,7 @@ static int imagex_append(int argc, const char **argv) printf("Capturing WIM image NTFS filesystem on `%s'\n", ntfs_device); ret = wimlib_add_image_from_ntfs_volume(w, ntfs_device, - name, desc, - flags_element, + name, config_str, config_len, add_image_flags); @@ -419,13 +423,23 @@ static int imagex_append(int argc, const char **argv) imagex_error_with_errno("Failed to stat `%s'", dir); } #endif - ret = wimlib_add_image(w, dir, name, desc, - flags_element, config_str, config_len, + ret = wimlib_add_image(w, dir, name, config_str, config_len, add_image_flags); out_write: if (ret != 0) goto out; + cur_image = wimlib_get_num_images(w); + if (desc) { + ret = wimlib_set_image_descripton(w, cur_image, desc); + if (ret != 0) + goto out; + } + if (flags_element) { + ret = wimlib_set_image_flags(w, cur_image, flags_element); + if (ret != 0) + goto out; + } ret = wimlib_overwrite(w, write_flags); out: wimlib_free(w); @@ -542,6 +556,7 @@ static int imagex_capture(int argc, const char **argv) const char *config_str = NULL; size_t config_len = 0; WIMStruct *w; + int cur_image; int ret; for_opt(c, capture_options) { @@ -607,8 +622,7 @@ static int imagex_capture(int argc, const char **argv) printf("Capturing WIM image NTFS filesystem on `%s'\n", ntfs_device); ret = wimlib_add_image_from_ntfs_volume(w, ntfs_device, - name, desc, - flags_element, + name, config_str, config_len, add_image_flags); @@ -619,7 +633,7 @@ static int imagex_capture(int argc, const char **argv) imagex_error_with_errno("Failed to stat `%s'", dir); } #endif - ret = wimlib_add_image(w, dir, name, desc, flags_element, config_str, + ret = wimlib_add_image(w, dir, name, config_str, config_len, add_image_flags); out_write: @@ -627,6 +641,17 @@ out_write: imagex_error("Failed to add the image `%s'", dir); goto out; } + cur_image = wimlib_get_num_images(w); + if (desc) { + ret = wimlib_set_image_descripton(w, cur_image, desc); + if (ret != 0) + goto out; + } + if (flags_element) { + ret = wimlib_set_image_flags(w, cur_image, flags_element); + if (ret != 0) + goto out; + } ret = wimlib_write(w, wimfile, WIM_ALL_IMAGES, write_flags); if (ret != 0) diff --git a/src/modify.c b/src/modify.c index a6d26884..3b321c37 100644 --- a/src/modify.c +++ b/src/modify.c @@ -727,7 +727,6 @@ bool exclude_path(const char *path, const struct capture_config *config, int do_add_image(WIMStruct *w, const char *dir, const char *name, - const char *description, const char *flags_element, const char *config_str, size_t config_len, int flags, int (*capture_tree)(struct dentry **, const char *, @@ -810,7 +809,7 @@ int do_add_image(WIMStruct *w, const char *dir, const char *name, if (flags & WIMLIB_ADD_IMAGE_FLAG_BOOT) wimlib_set_boot_idx(w, w->hdr.image_count); - ret = xml_add_image(w, root_dentry, name, description, flags_element); + ret = xml_add_image(w, root_dentry, name); if (ret != 0) goto out_destroy_imd; @@ -833,12 +832,9 @@ out_destroy_config: * Adds an image to a WIM file from a directory tree on disk. */ WIMLIBAPI int wimlib_add_image(WIMStruct *w, const char *dir, - const char *name, const char *description, - const char *flags_element, - const char *config_str, + const char *name, const char *config_str, size_t config_len, int flags) { - return do_add_image(w, dir, name, description, flags_element, - config_str, config_len, flags, + return do_add_image(w, dir, name, config_str, config_len, flags, build_dentry_tree, NULL); } diff --git a/src/ntfs-capture.c b/src/ntfs-capture.c index a9ad174a..5d8ebcf8 100644 --- a/src/ntfs-capture.c +++ b/src/ntfs-capture.c @@ -581,8 +581,6 @@ out: WIMLIBAPI int wimlib_add_image_from_ntfs_volume(WIMStruct *w, const char *device, const char *name, - const char *description, - const char *flags_element, const char *config_str, size_t config_len, int flags) @@ -591,9 +589,8 @@ WIMLIBAPI int wimlib_add_image_from_ntfs_volume(WIMStruct *w, ERROR("Cannot dereference files when capturing directly from NTFS"); return WIMLIB_ERR_INVALID_PARAM; } - return do_add_image(w, device, name, description, flags_element, - config_str, config_len, flags, build_dentry_tree_ntfs, - &w->ntfs_vol); + return do_add_image(w, device, name, config_str, config_len, flags, + build_dentry_tree_ntfs, &w->ntfs_vol); } #else /* WITH_NTFS_3G */ diff --git a/src/wimlib.h b/src/wimlib.h index f8471f78..a0b08c07 100644 --- a/src/wimlib.h +++ b/src/wimlib.h @@ -405,15 +405,11 @@ enum wimlib_error_code { * */ extern int wimlib_add_image(WIMStruct *wim, const char *dir, - const char *name, const char *description, - const char *flags_element, - const char *config, size_t config_len, - int flags); + const char *name, const char *config, + size_t config_len, int flags); extern int wimlib_add_image_from_ntfs_volume(WIMStruct *w, const char *device, const char *name, - const char *description, - const char *flags_element, const char *config, size_t config_len, int flags); @@ -1126,6 +1122,9 @@ extern int wimlib_set_boot_idx(WIMStruct *wim, int boot_idx); extern int wimlib_set_image_descripton(WIMStruct *wim, int image, const char *description); +extern int wimlib_set_image_flags(WIMStruct *w, int image, + const char *flags); + /** * Changes the name of an image in the WIM. * diff --git a/src/wimlib_internal.h b/src/wimlib_internal.h index a8ef2dc1..008db34b 100644 --- a/src/wimlib_internal.h +++ b/src/wimlib_internal.h @@ -356,7 +356,6 @@ extern bool exclude_path(const char *path, const struct capture_config *config, bool exclude_prefix); extern int do_add_image(WIMStruct *w, const char *dir, const char *name, - const char *description, const char *flags_element, const char *config_str, size_t config_len, int flags, int (*capture_tree)(struct dentry **, const char *, diff --git a/src/xml.c b/src/xml.c index 1c208479..0de179c4 100644 --- a/src/xml.c +++ b/src/xml.c @@ -981,16 +981,14 @@ void xml_update_image_info(WIMStruct *w, int image) } /* Adds an image to the XML information. */ -int xml_add_image(WIMStruct *w, struct dentry *root_dentry, const char *name, - const char *description, const char *flags_element) +int xml_add_image(WIMStruct *w, struct dentry *root_dentry, const char *name) { struct wim_info *wim_info; struct image_info *image_info; wimlib_assert(name); - DEBUG("Adding image: name = %s, description = %s, flags_element = %s", - name, description, flags_element); + DEBUG("Adding image: name = %s", name); /* If this is the first image, allocate the struct wim_info. Otherwise * use the existing struct wim_info. */ @@ -1013,11 +1011,6 @@ int xml_add_image(WIMStruct *w, struct dentry *root_dentry, const char *name, if (!(image_info->name = STRDUP(name))) goto out_destroy_image_info; - if (description && !(image_info->description = STRDUP(description))) - goto out_destroy_image_info; - if (flags_element && !(image_info->flags = STRDUP(flags_element))) - goto out_destroy_image_info; - w->wim_info = wim_info; image_info->index = wim_info->num_images; image_info->creation_time = get_wim_timestamp(); @@ -1414,3 +1407,28 @@ WIMLIBAPI int wimlib_set_image_descripton(WIMStruct *w, int image, w->wim_info->images[image - 1].description = p; return 0; } + +WIMLIBAPI int wimlib_set_image_flags(WIMStruct *w, int image, + const char *flags) +{ + char *p; + + DEBUG("Setting the flags of image %d to %s", image, flags); + + if (image < 1 || image > w->hdr.image_count) { + ERROR("%d is not a valid image", image); + return WIMLIB_ERR_INVALID_IMAGE; + } + if (flags) { + p = STRDUP(flags); + if (!p) { + ERROR("Out of memory"); + return WIMLIB_ERR_NOMEM; + } + } else { + p = NULL; + } + FREE(w->wim_info->images[image - 1].flags); + w->wim_info->images[image - 1].flags = p; + return 0; +} diff --git a/src/xml.h b/src/xml.h index d1670f87..fb296000 100644 --- a/src/xml.h +++ b/src/xml.h @@ -25,8 +25,7 @@ extern void xml_update_image_info(WIMStruct *w, int image); extern void xml_delete_image(struct wim_info **wim_info_p, int image); extern int xml_add_image(WIMStruct *w, struct dentry *root_dentry, - const char *name, const char *description, - const char *flags); + const char *name); extern void free_wim_info(struct wim_info *info); -- 2.43.0