X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fdelete_image.c;h=2ad5a27a8f0d4e95962968dc90852e6e5631f190;hb=92502e53658f09310d67118a0bbc18fa83a1b6f0;hp=862fb66e53e2efb1f0623aef17ce894d8c746f0f;hpb=e8c3ca2d1d0cac3d64985b45a9f654d2029a7518;p=wimlib diff --git a/src/delete_image.c b/src/delete_image.c index 862fb66e..2ad5a27a 100644 --- a/src/delete_image.c +++ b/src/delete_image.c @@ -32,28 +32,19 @@ #include "wimlib/wim.h" #include "wimlib/xml.h" -/* - * Deletes an image from the WIM. - */ +/* 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; @@ -66,34 +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. */ - for (int i = image - 1; i < w->hdr.image_count - 1; i++) - w->image_metadata[i] = w->image_metadata[i + 1]; + 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; }