#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 {
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? */
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
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
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. */
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;
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
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;
if (!wim_compression_type_valid(ctype))
return T("Invalid");
- return wim_ctype_info[ctype].name;
+ return wim_ctype_info[(unsigned)ctype].name;
}
WIMLIBAPI void
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)
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)) {
#ifdef __WIN32__
ret = win32_global_init(init_flags);
if (ret)
- goto out;
+ goto out_unlock;
#endif
iconv_global_init();
init_upcase();
default_ignore_case = true;
lib_initialized = true;
ret = 0;
-out:
+out_unlock:
pthread_mutex_unlock(&lib_initialization_mutex);
+out:
return ret;
}
pthread_mutex_lock(&lib_initialization_mutex);
if (!lib_initialized)
- goto out;
+ goto out_unlock;
libxml_global_cleanup();
iconv_global_cleanup();
wimlib_set_error_file(NULL);
lib_initialized = false;
-out:
+out_unlock:
pthread_mutex_unlock(&lib_initialization_mutex);
}