X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fwim.c;h=ff43ba59e5deda4921dec2d728fb800224d9e13d;hb=377d436d5f3d5e626b2bbe446bdcd871ee53c5b5;hp=f06f25f15edd2ffb1461117aeb1ea05be41ded06;hpb=1fcf9333676be806716535d01b38722ee53d52e9;p=wimlib diff --git a/src/wim.c b/src/wim.c index f06f25f1..ff43ba59 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; + randomize_byte_array(wim->hdr.guid, WIMLIB_GUID_LEN); + 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; @@ -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