X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fwim.c;h=df8678904dd6d4573e10883af51bfcfda0a3031f;hb=27c2e0401d76095286e5e2e0f81f4ccee3d45df3;hp=98836a584995a39831256097ca483c096a4f23bb;hpb=b6b7a977776c22f3315dbb357863e1a4915d1d7f;p=wimlib diff --git a/src/wim.c b/src/wim.c index 98836a58..df867890 100644 --- a/src/wim.c +++ b/src/wim.c @@ -40,15 +40,11 @@ #include "wimlib/file_io.h" #include "wimlib/integrity.h" #include "wimlib/metadata.h" -#ifdef WITH_NTFS_3G -# include "wimlib/ntfs_3g.h" /* for do_ntfs_umount() */ -#endif +#include "wimlib/ntfs_3g.h" /* for libntfs3g_global_init() */ #include "wimlib/security.h" #include "wimlib/wim.h" #include "wimlib/xml.h" -#ifdef __WIN32__ -# include "wimlib/win32.h" /* for realpath() replacement */ -#endif +#include "wimlib/win32.h" /* Information about the available compression types for the WIM format. */ static const struct { @@ -92,8 +88,8 @@ static const struct { static bool wim_compression_type_valid(enum wimlib_compression_type ctype) { - return ctype >= 0 && ctype < ARRAY_LEN(wim_ctype_info) && - wim_ctype_info[ctype].name != NULL; + return (unsigned)ctype < ARRAY_LEN(wim_ctype_info) && + wim_ctype_info[(unsigned)ctype].name != NULL; } /* Is the specified chunk size valid for the compression type? */ @@ -103,8 +99,8 @@ wim_chunk_size_valid(u32 chunk_size, enum wimlib_compression_type ctype) if (!(chunk_size == 0 || is_power_of_2(chunk_size))) return false; - return chunk_size >= wim_ctype_info[ctype].min_chunk_size && - chunk_size <= wim_ctype_info[ctype].max_chunk_size; + return chunk_size >= wim_ctype_info[(unsigned)ctype].min_chunk_size && + chunk_size <= wim_ctype_info[(unsigned)ctype].max_chunk_size; } /* Return the default chunk size to use for the specified compression type in @@ -112,7 +108,7 @@ wim_chunk_size_valid(u32 chunk_size, enum wimlib_compression_type ctype) static u32 wim_default_nonsolid_chunk_size(enum wimlib_compression_type ctype) { - return wim_ctype_info[ctype].default_nonsolid_chunk_size; + return wim_ctype_info[(unsigned)ctype].default_nonsolid_chunk_size; } /* Return the default chunk size to use for the specified compression type in @@ -120,7 +116,7 @@ wim_default_nonsolid_chunk_size(enum wimlib_compression_type ctype) static u32 wim_default_solid_chunk_size(enum wimlib_compression_type ctype) { - return wim_ctype_info[ctype].default_solid_chunk_size; + return wim_ctype_info[(unsigned)ctype].default_solid_chunk_size; } /* Return the default compression type to use in solid resources. */ @@ -186,12 +182,23 @@ wimlib_create_new_wim(enum wimlib_compression_type ctype, WIMStruct **wim_ret) return WIMLIB_ERR_NOMEM; } - init_wim_header(&wim->hdr, ctype, - wim_default_nonsolid_chunk_size(ctype)); - wim->compression_type = ctype; - wim->out_compression_type = ctype; + /* Fill in wim->hdr with default values */ + wim->hdr.magic = WIM_MAGIC; + wim->hdr.wim_version = WIM_VERSION_DEFAULT; + wim->hdr.flags = 0; + wim->hdr.chunk_size = 0; + generate_guid(wim->hdr.guid); + wim->hdr.part_number = 1; + wim->hdr.total_parts = 1; + wim->hdr.image_count = 0; + wim->hdr.boot_idx = 0; + + wim->compression_type = WIMLIB_COMPRESSION_TYPE_NONE; wim->chunk_size = wim->hdr.chunk_size; - wim->out_chunk_size = wim->hdr.chunk_size; + + /* Set the output compression type */ + wim->out_compression_type = ctype; + wim->out_chunk_size = wim_default_nonsolid_chunk_size(ctype); *wim_ret = wim; return 0; @@ -217,13 +224,7 @@ destroy_image_metadata(struct wim_image_metadata *imd, free_blob_descriptor(blob); } INIT_LIST_HEAD(&imd->unhashed_blobs); - INIT_LIST_HEAD(&imd->inode_list); -#ifdef WITH_NTFS_3G - if (imd->ntfs_vol) { - do_ntfs_umount(imd->ntfs_vol); - imd->ntfs_vol = NULL; - } -#endif + INIT_HLIST_HEAD(&imd->inode_list); } void @@ -260,7 +261,7 @@ new_image_metadata(void) imd = CALLOC(1, sizeof(*imd)); if (imd) { imd->refcnt = 1; - INIT_LIST_HEAD(&imd->inode_list); + INIT_HLIST_HEAD(&imd->inode_list); INIT_LIST_HEAD(&imd->unhashed_blobs); } return imd; @@ -447,7 +448,7 @@ WIMLIBAPI int wimlib_get_wim_info(WIMStruct *wim, struct wimlib_wim_info *info) { memset(info, 0, sizeof(struct wimlib_wim_info)); - memcpy(info->guid, wim->hdr.guid, WIMLIB_GUID_LEN); + copy_guid(info->guid, wim->hdr.guid); info->image_count = wim->hdr.image_count; info->boot_index = wim->hdr.boot_idx; info->wim_version = wim->hdr.wim_version; @@ -493,7 +494,7 @@ wimlib_set_wim_info(WIMStruct *wim, const struct wimlib_wim_info *info, int whic } if (which & WIMLIB_CHANGE_GUID) - memcpy(wim->hdr.guid, info->guid, WIM_GUID_LEN); + copy_guid(wim->hdr.guid, info->guid); if (which & WIMLIB_CHANGE_BOOT_INDEX) wim->hdr.boot_idx = info->boot_index; @@ -584,7 +585,7 @@ wimlib_get_compression_type_string(enum wimlib_compression_type ctype) if (!wim_compression_type_valid(ctype)) return T("Invalid"); - return wim_ctype_info[ctype].name; + return wim_ctype_info[(unsigned)ctype].name; } WIMLIBAPI void @@ -929,16 +930,15 @@ static pthread_mutex_t lib_initialization_mutex = PTHREAD_MUTEX_INITIALIZER; WIMLIBAPI int wimlib_global_init(int init_flags) { - int ret; + int ret = 0; if (lib_initialized) - return 0; + goto out; pthread_mutex_lock(&lib_initialization_mutex); - ret = 0; if (lib_initialized) - goto out; + goto out_unlock; #ifdef ENABLE_ERROR_MESSAGES if (!wimlib_error_file) @@ -952,14 +952,14 @@ wimlib_global_init(int init_flags) WIMLIB_INIT_FLAG_STRICT_APPLY_PRIVILEGES | WIMLIB_INIT_FLAG_DEFAULT_CASE_SENSITIVE | WIMLIB_INIT_FLAG_DEFAULT_CASE_INSENSITIVE)) - goto out; + goto out_unlock; ret = WIMLIB_ERR_INVALID_PARAM; if ((init_flags & (WIMLIB_INIT_FLAG_DEFAULT_CASE_SENSITIVE | WIMLIB_INIT_FLAG_DEFAULT_CASE_INSENSITIVE)) == (WIMLIB_INIT_FLAG_DEFAULT_CASE_SENSITIVE | WIMLIB_INIT_FLAG_DEFAULT_CASE_INSENSITIVE)) - goto out; + goto out_unlock; libxml_global_init(); if (!(init_flags & WIMLIB_INIT_FLAG_ASSUME_UTF8)) { @@ -972,7 +972,7 @@ wimlib_global_init(int init_flags) #ifdef __WIN32__ ret = win32_global_init(init_flags); if (ret) - goto out; + goto out_unlock; #endif iconv_global_init(); init_upcase(); @@ -982,8 +982,9 @@ wimlib_global_init(int init_flags) default_ignore_case = true; lib_initialized = true; ret = 0; -out: +out_unlock: pthread_mutex_unlock(&lib_initialization_mutex); +out: return ret; } @@ -997,7 +998,7 @@ wimlib_global_cleanup(void) pthread_mutex_lock(&lib_initialization_mutex); if (!lib_initialized) - goto out; + goto out_unlock; libxml_global_cleanup(); iconv_global_cleanup(); @@ -1008,6 +1009,6 @@ wimlib_global_cleanup(void) wimlib_set_error_file(NULL); lib_initialized = false; -out: +out_unlock: pthread_mutex_unlock(&lib_initialization_mutex); }