X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fwim.c;h=df8678904dd6d4573e10883af51bfcfda0a3031f;hb=68f23dd879bb5be0ff31f0d4403184703b52ef6d;hp=f06f25f15edd2ffb1461117aeb1ea05be41ded06;hpb=1fcf9333676be806716535d01b38722ee53d52e9;p=wimlib diff --git a/src/wim.c b/src/wim.c index f06f25f1..df867890 100644 --- a/src/wim.c +++ b/src/wim.c @@ -44,9 +44,7 @@ #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 { @@ -90,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? */ @@ -101,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 @@ -110,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 @@ -118,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. */ @@ -184,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; @@ -439,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; @@ -485,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; @@ -576,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