wimlib_add_image(): Fewer parameters
authorEric Biggers <ebiggers3@gmail.com>
Mon, 27 Aug 2012 04:34:52 +0000 (23:34 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Mon, 27 Aug 2012 04:34:52 +0000 (23:34 -0500)
No more description and flags_element parameters.  There are separate functions
to set those.

programs/imagex.c
src/modify.c
src/ntfs-capture.c
src/wimlib.h
src/wimlib_internal.h
src/xml.c
src/xml.h

index 8afccd1..9bd0ecc 100644 (file)
@@ -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)
index a6d2688..3b321c3 100644 (file)
@@ -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);
 }
index a9ad174..5d8ebcf 100644 (file)
@@ -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 */
index f8471f7..a0b08c0 100644 (file)
@@ -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.
  *
index a8ef2dc..008db34 100644 (file)
@@ -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 *,
index 1c20847..0de179c 100644 (file)
--- 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;
+}
index d1670f8..fb29600 100644 (file)
--- 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);