X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fwim.c;h=1c0e6efdf96ae5576b53de16161973010535ffef;hb=53b75051f0e9cde007101eeca37cbe3884e03f18;hp=e7025daf03e0badcf094cdcc1f33e48df1e85231;hpb=3071e89c11d1be71cf45b694432e5908e0c4ded9;p=wimlib diff --git a/src/wim.c b/src/wim.c index e7025daf..1c0e6efd 100644 --- a/src/wim.c +++ b/src/wim.c @@ -24,6 +24,8 @@ #endif #include "wimlib.h" +#include "wimlib/assert.h" +#include "wimlib/bitops.h" #include "wimlib/dentry.h" #include "wimlib/encoding.h" #include "wimlib/file_io.h" @@ -36,7 +38,6 @@ #include "wimlib/security.h" #include "wimlib/wim.h" #include "wimlib/xml.h" -#include "wimlib/version.h" #ifdef __WIN32__ # include "wimlib/win32.h" /* for realpath() replacement */ @@ -96,7 +97,7 @@ wim_chunk_size_valid(u32 chunk_size, int ctype) /* Chunk size must be power of 2. */ if (chunk_size == 0) return false; - order = bsr32(chunk_size); + order = fls32(chunk_size); if (chunk_size != 1U << order) return false; @@ -203,7 +204,6 @@ wimlib_create_new_wim(int ctype, WIMStruct **wim_ret) goto out_free_wim; } wim->lookup_table = table; - wim->refcnts_ok = 1; wim->compression_type = ctype; wim->out_compression_type = ctype; wim->chunk_size = wim->hdr.chunk_size; @@ -356,7 +356,7 @@ select_wim_image(WIMStruct *wim, int image) if (imd->root_dentry || imd->modified) { ret = 0; } else { - ret = read_metadata_resource(wim, imd); + ret = read_metadata_resource(imd); if (ret) wim->current_image = WIMLIB_NO_IMAGE; } @@ -472,14 +472,16 @@ wimlib_get_wim_info(WIMStruct *wim, struct wimlib_wim_info *info) WIMLIBAPI int wimlib_set_wim_info(WIMStruct *wim, const struct wimlib_wim_info *info, int which) { - int ret; - if (which & ~(WIMLIB_CHANGE_READONLY_FLAG | WIMLIB_CHANGE_GUID | WIMLIB_CHANGE_BOOT_INDEX | WIMLIB_CHANGE_RPFIX_FLAG)) return WIMLIB_ERR_INVALID_PARAM; + if ((which & WIMLIB_CHANGE_BOOT_INDEX) && + info->boot_index > wim->hdr.image_count) + return WIMLIB_ERR_INVALID_IMAGE; + if (which & WIMLIB_CHANGE_READONLY_FLAG) { if (info->is_marked_readonly) wim->hdr.flags |= WIM_HDR_FLAG_READONLY; @@ -487,21 +489,11 @@ wimlib_set_wim_info(WIMStruct *wim, const struct wimlib_wim_info *info, int whic wim->hdr.flags &= ~WIM_HDR_FLAG_READONLY; } - if ((which & ~WIMLIB_CHANGE_READONLY_FLAG) == 0) - return 0; - - ret = can_modify_wim(wim); - if (ret) - return ret; - if (which & WIMLIB_CHANGE_GUID) memcpy(wim->hdr.guid, info->guid, WIM_GUID_LEN); - if (which & WIMLIB_CHANGE_BOOT_INDEX) { - if (info->boot_index > wim->hdr.image_count) - return WIMLIB_ERR_INVALID_IMAGE; + if (which & WIMLIB_CHANGE_BOOT_INDEX) wim->hdr.boot_idx = info->boot_index; - } if (which & WIMLIB_CHANGE_RPFIX_FLAG) { if (info->has_rpfix) @@ -872,33 +864,6 @@ can_modify_wim(WIMStruct *wim) return 0; } -/* - * can_delete_from_wim - Check if files or images can be deleted from a given - * WIM file. - * - * This theoretically should be exactly the same as can_modify_wim(), but - * unfortunately, due to bugs in Microsoft's software that generate incorrect - * reference counts for some WIM resources, we need to run expensive - * verifications to make sure the reference counts are correct on all WIM - * resources. Otherwise we might delete a WIM resource whose reference count - * has fallen to 0, but is actually still referenced somewhere. - */ -int -can_delete_from_wim(WIMStruct *wim) -{ - int ret; - - ret = can_modify_wim(wim); - if (ret) - return ret; - if (!wim->refcnts_ok) { - ret = wim_recalculate_refcnts(wim); - if (ret) - return ret; - } - return 0; -} - /* API function documented in wimlib.h */ WIMLIBAPI void wimlib_free(WIMStruct *wim) @@ -952,7 +917,9 @@ test_locale_ctype_utf8(void) WIMLIBAPI u32 wimlib_get_version(void) { - return WIMLIB_VERSION_CODE; + return (WIMLIB_MAJOR_VERSION << 20) | + (WIMLIB_MINOR_VERSION << 10) | + WIMLIB_PATCH_VERSION; } static bool lib_initialized = false;