X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fdelete_image.c;h=2ad5a27a8f0d4e95962968dc90852e6e5631f190;hb=9ca5c20853d3be06378fb985aa75c75df280d1e2;hp=c95819e980d787ecd0d3996176f5e1688bf9f65a;hpb=13c6ce3160fce7c40008d1d182325c8b42450d1e;p=wimlib diff --git a/src/delete_image.c b/src/delete_image.c index c95819e9..2ad5a27a 100644 --- a/src/delete_image.c +++ b/src/delete_image.c @@ -21,32 +21,30 @@ * along with wimlib; if not, see http://www.gnu.org/licenses/. */ -#include "wimlib_internal.h" -#include "xml.h" -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -/* - * Deletes an image from the WIM. - */ +#include "wimlib.h" +#include "wimlib/error.h" +#include "wimlib/metadata.h" +#include "wimlib/util.h" +#include "wimlib/wim.h" +#include "wimlib/xml.h" + +/* API function documented in wimlib.h */ WIMLIBAPI int -wimlib_delete_image(WIMStruct *w, int image) +wimlib_delete_image(WIMStruct *wim, int image) { int ret; int first, last; - if (w->hdr.total_parts != 1) { - ERROR("Deleting an image from a split WIM is not supported."); - return WIMLIB_ERR_SPLIT_UNSUPPORTED; - } - - if (!w->all_images_verified) { - ret = wim_run_full_verifications(w); - if (ret) - return ret; - } + ret = can_delete_from_wim(wim); + if (ret) + return ret; if (image == WIMLIB_ALL_IMAGES) { - last = w->hdr.image_count; + last = wim->hdr.image_count; first = 1; } else { last = image; @@ -59,35 +57,34 @@ wimlib_delete_image(WIMStruct *w, int image) /* Even if the dentry tree is not allocated, we must select it (and * therefore allocate it) so that we can decrement the reference counts * in the lookup table. */ - ret = select_wim_image(w, image); + ret = select_wim_image(wim, image); if (ret) return ret; /* Unless the image metadata is shared by another WIMStruct, free the * dentry tree, any lookup table entries that have their refcnt * decremented to 0, and the security data. */ - put_image_metadata(w->image_metadata[image - 1], w->lookup_table); + put_image_metadata(wim->image_metadata[image - 1], wim->lookup_table); /* Get rid of the empty slot in the image metadata array. */ - memmove(w->image_metadata[image - 1], - &w->image_metadata[image], - (w->hdr.image_count - image) * sizeof(w->image_metadata[0])); + for (int i = image - 1; i < wim->hdr.image_count - 1; i++) + wim->image_metadata[i] = wim->image_metadata[i + 1]; /* Decrement the image count. */ - --w->hdr.image_count; + --wim->hdr.image_count; /* Fix the boot index. */ - if (w->hdr.boot_idx == image) - w->hdr.boot_idx = 0; - else if (w->hdr.boot_idx > image) - w->hdr.boot_idx--; + if (wim->hdr.boot_idx == image) + wim->hdr.boot_idx = 0; + else if (wim->hdr.boot_idx > image) + wim->hdr.boot_idx--; - w->current_image = WIMLIB_NO_IMAGE; + wim->current_image = WIMLIB_NO_IMAGE; /* Remove the image from the XML information. */ - xml_delete_image(&w->wim_info, image); + xml_delete_image(&wim->wim_info, image); - w->deletion_occurred = 1; + wim->deletion_occurred = 1; } return 0; }