]> wimlib.net Git - wimlib/commitdiff
Add GUID helper functions
authorEric Biggers <ebiggers3@gmail.com>
Sat, 30 May 2015 20:48:08 +0000 (15:48 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Fri, 5 Jun 2015 03:05:23 +0000 (22:05 -0500)
12 files changed:
Makefile.am
include/wimlib/guid.h [new file with mode: 0644]
include/wimlib/header.h
include/wimlib/wimboot.h
src/blob_table.c
src/extract.c
src/header.c
src/join.c
src/split.c
src/wim.c
src/wimboot.c
src/write.c

index cd67fb2891e93e86e7ae0b643b78fb07350f4fe1..0169882cd1c75c1d395c609468cabb1a9259c32a 100644 (file)
@@ -115,6 +115,7 @@ libwim_la_SOURCES =         \
        include/wimlib/error.h          \
        include/wimlib/file_io.h        \
        include/wimlib/glob.h           \
        include/wimlib/error.h          \
        include/wimlib/file_io.h        \
        include/wimlib/glob.h           \
+       include/wimlib/guid.h           \
        include/wimlib/hc_matchfinder.h \
        include/wimlib/header.h         \
        include/wimlib/inode.h          \
        include/wimlib/hc_matchfinder.h \
        include/wimlib/header.h         \
        include/wimlib/inode.h          \
diff --git a/include/wimlib/guid.h b/include/wimlib/guid.h
new file mode 100644 (file)
index 0000000..be9a10f
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * guid.h
+ *
+ * Utility functions for handling 16-byte globally unique identifiers (GUIDs).
+ */
+
+#ifndef _WIMLIB_GUID_H
+#define _WIMLIB_GUID_H
+
+#include <string.h>
+
+#include "wimlib/util.h"
+
+#define GUID_SIZE    16
+
+static inline void
+copy_guid(u8 dest[GUID_SIZE], const u8 src[GUID_SIZE])
+{
+       memcpy(dest, src, GUID_SIZE);
+}
+
+static inline int
+cmp_guids(const u8 guid1[GUID_SIZE], const u8 guid2[GUID_SIZE])
+{
+       return memcmp(guid1, guid2, GUID_SIZE);
+}
+
+static inline bool
+guids_equal(const u8 guid1[GUID_SIZE], const u8 guid2[GUID_SIZE])
+{
+       return !cmp_guids(guid1, guid2);
+}
+
+static inline void
+generate_guid(u8 guid[GUID_SIZE])
+{
+       return randomize_byte_array(guid, GUID_SIZE);
+}
+
+#endif /* _WIMLIB_GUID_H */
index e696ce51dfe939143cf783f62159b919027210e3..894bd22591897491f2089ce75c4bd0dacb64939f 100644 (file)
@@ -3,12 +3,10 @@
 
 #include <limits.h>
 
 
 #include <limits.h>
 
+#include "wimlib/guid.h"
 #include "wimlib/resource.h"
 #include "wimlib/types.h"
 
 #include "wimlib/resource.h"
 #include "wimlib/types.h"
 
-/* Length of "Globally Unique ID" field in WIM header.  */
-#define WIM_GUID_LEN    16
-
 /* Length of the WIM header on disk.  wimlib currently requires that the header
  * be exactly this size.  */
 #define WIM_HEADER_DISK_SIZE 208
 /* Length of the WIM header on disk.  wimlib currently requires that the header
  * be exactly this size.  */
 #define WIM_HEADER_DISK_SIZE 208
@@ -72,7 +70,7 @@ struct wim_header_disk {
 
        /* +0x18: Globally unique identifier for the WIM file.  Basically a
         * bunch of random bytes.  */
 
        /* +0x18: Globally unique identifier for the WIM file.  Basically a
         * bunch of random bytes.  */
-       u8 guid[WIM_GUID_LEN];
+       u8 guid[GUID_SIZE];
 
        /* +0x28: Number of this WIM part in the split WIM file, indexed from 1,
         * or 1 if the WIM is not split.  */
 
        /* +0x28: Number of this WIM part in the split WIM file, indexed from 1,
         * or 1 if the WIM is not split.  */
@@ -123,7 +121,7 @@ struct wim_header {
        u32 wim_version;
        u32 flags;
        u32 chunk_size;
        u32 wim_version;
        u32 flags;
        u32 chunk_size;
-       u8 guid[WIM_GUID_LEN];
+       u8 guid[GUID_SIZE];
        u16 part_number;
        u16 total_parts;
        u32 image_count;
        u16 part_number;
        u16 total_parts;
        u32 image_count;
index 7dcd85d362169727cb861179a797ebacb9f68777..10857d5b64680be085e6d5afc508613e2092a94d 100644 (file)
@@ -10,7 +10,7 @@ struct blob_descriptor;
 
 extern int
 wimboot_alloc_data_source_id(const wchar_t *wim_path,
 
 extern int
 wimboot_alloc_data_source_id(const wchar_t *wim_path,
-                            const u8 guid[WIM_GUID_LEN], int image,
+                            const u8 guid[GUID_SIZE], int image,
                             const wchar_t *target, u64 *data_source_id_ret,
                             bool *wof_running_ret);
 
                             const wchar_t *target, u64 *data_source_id_ret,
                             bool *wof_running_ret);
 
index d2ece47ba471af1c67f37d62e8371401eeed8d52..3e9f9b4210fd9026ea6a57be840da727a06ee772 100644 (file)
@@ -406,7 +406,7 @@ cmp_blobs_by_sequential_order(const void *p1, const void *p2)
 
                /* Different (possibly split) WIMs?  */
                if (wim1 != wim2) {
 
                /* Different (possibly split) WIMs?  */
                if (wim1 != wim2) {
-                       v = memcmp(wim1->hdr.guid, wim2->hdr.guid, WIM_GUID_LEN);
+                       v = cmp_guids(wim1->hdr.guid, wim2->hdr.guid);
                        if (v)
                                return v;
                }
                        if (v)
                                return v;
                }
index 0aa63f4bf4c17e15ca70f0f3fcf00048ba7746c6..533e8483b9b75476108308c6c81e9416ea5d0843 100644 (file)
@@ -201,7 +201,7 @@ read_blobs_from_pipe(struct apply_ctx *ctx,
        struct wim_resource_descriptor rdesc;
        struct blob_descriptor *blob;
 
        struct wim_resource_descriptor rdesc;
        struct blob_descriptor *blob;
 
-       memcpy(ctx->progress.extract.guid, ctx->wim->hdr.guid, WIM_GUID_LEN);
+       copy_guid(ctx->progress.extract.guid, ctx->wim->hdr.guid);
        ctx->progress.extract.part_number = ctx->wim->hdr.part_number;
        ctx->progress.extract.total_parts = ctx->wim->hdr.total_parts;
        ret = extract_progress(ctx, WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN);
        ctx->progress.extract.part_number = ctx->wim->hdr.part_number;
        ctx->progress.extract.total_parts = ctx->wim->hdr.total_parts;
        ret = extract_progress(ctx, WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN);
@@ -218,10 +218,10 @@ read_blobs_from_pipe(struct apply_ctx *ctx,
 
                        if (part_number == ctx->progress.extract.part_number &&
                            total_parts == ctx->progress.extract.total_parts &&
 
                        if (part_number == ctx->progress.extract.part_number &&
                            total_parts == ctx->progress.extract.total_parts &&
-                           !memcmp(pwm_hdr.guid, ctx->progress.extract.guid, WIM_GUID_LEN))
+                           guids_equal(pwm_hdr.guid, ctx->progress.extract.guid))
                                continue;
 
                                continue;
 
-                       memcpy(ctx->progress.extract.guid, pwm_hdr.guid, WIM_GUID_LEN);
+                       copy_guid(ctx->progress.extract.guid, pwm_hdr.guid);
                        ctx->progress.extract.part_number = part_number;
                        ctx->progress.extract.total_parts = total_parts;
                        ret = extract_progress(ctx, WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN);
                        ctx->progress.extract.part_number = part_number;
                        ctx->progress.extract.total_parts = total_parts;
                        ret = extract_progress(ctx, WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN);
index 0e16e6ca911cbb59af23881ad65f9c3648d7ddb3..37ba6ed260e1d14ab61c1f4edfbe0858bc9eb348 100644 (file)
@@ -121,7 +121,7 @@ read_wim_header(WIMStruct *wim, struct wim_header *hdr)
 
        hdr->flags = le32_to_cpu(disk_hdr.wim_flags);
        hdr->chunk_size = le32_to_cpu(disk_hdr.chunk_size);
 
        hdr->flags = le32_to_cpu(disk_hdr.wim_flags);
        hdr->chunk_size = le32_to_cpu(disk_hdr.chunk_size);
-       memcpy(hdr->guid, disk_hdr.guid, WIM_GUID_LEN);
+       copy_guid(hdr->guid, disk_hdr.guid);
        hdr->part_number = le16_to_cpu(disk_hdr.part_number);
        hdr->total_parts = le16_to_cpu(disk_hdr.total_parts);
 
        hdr->part_number = le16_to_cpu(disk_hdr.part_number);
        hdr->total_parts = le16_to_cpu(disk_hdr.total_parts);
 
@@ -175,7 +175,7 @@ write_wim_header(const struct wim_header *hdr, struct filedes *out_fd,
        disk_hdr.wim_version = cpu_to_le32(hdr->wim_version);
        disk_hdr.wim_flags = cpu_to_le32(hdr->flags);
        disk_hdr.chunk_size = cpu_to_le32(hdr->chunk_size);
        disk_hdr.wim_version = cpu_to_le32(hdr->wim_version);
        disk_hdr.wim_flags = cpu_to_le32(hdr->flags);
        disk_hdr.chunk_size = cpu_to_le32(hdr->chunk_size);
-       memcpy(disk_hdr.guid, hdr->guid, WIM_GUID_LEN);
+       copy_guid(disk_hdr.guid, hdr->guid);
        disk_hdr.part_number = cpu_to_le16(hdr->part_number);
        disk_hdr.total_parts = cpu_to_le16(hdr->total_parts);
        disk_hdr.image_count = cpu_to_le32(hdr->image_count);
        disk_hdr.part_number = cpu_to_le16(hdr->part_number);
        disk_hdr.total_parts = cpu_to_le16(hdr->total_parts);
        disk_hdr.image_count = cpu_to_le32(hdr->image_count);
@@ -249,7 +249,7 @@ wimlib_print_header(const WIMStruct *wim)
 
        tprintf(T("Chunk Size                  = %u\n"), hdr->chunk_size);
        tfputs (T("GUID                        = "), stdout);
 
        tprintf(T("Chunk Size                  = %u\n"), hdr->chunk_size);
        tfputs (T("GUID                        = "), stdout);
-       print_byte_field(hdr->guid, WIM_GUID_LEN, stdout);
+       print_byte_field(hdr->guid, GUID_SIZE, stdout);
        tputchar(T('\n'));
        tprintf(T("Part Number                 = %hu\n"), hdr->part_number);
        tprintf(T("Total Parts                 = %hu\n"), hdr->total_parts);
        tputchar(T('\n'));
        tprintf(T("Part Number                 = %hu\n"), hdr->part_number);
        tprintf(T("Total Parts                 = %hu\n"), hdr->total_parts);
index 7999b683afc5b59ef4ca66ef992d49e929117a22..cca44214041ab6c9fabefd269d59db95e7cfef8e 100644 (file)
@@ -110,7 +110,7 @@ verify_swm_set(WIMStruct *wim, WIMStruct **additional_swms,
                                      "chunk size");
                                return WIMLIB_ERR_SPLIT_INVALID;
                        }
                                      "chunk size");
                                return WIMLIB_ERR_SPLIT_INVALID;
                        }
-                       if (memcmp(guid, swm->hdr.guid, WIM_GUID_LEN) != 0) {
+                       if (!guids_equal(guid, swm->hdr.guid)) {
                                ERROR("The split WIMs do not all have the same "
                                      "GUID");
                                return WIMLIB_ERR_SPLIT_INVALID;
                                ERROR("The split WIMs do not all have the same "
                                      "GUID");
                                return WIMLIB_ERR_SPLIT_INVALID;
index 88f9b2bd0feb844d7294ff499cf39693e3e8f1da..3f4a7d0a87a170805de89b7cf2072962a6396d67 100644 (file)
@@ -69,7 +69,7 @@ write_split_wim(WIMStruct *orig_wim, const tchar *swm_name,
        union wimlib_progress_info progress;
        unsigned part_number;
        int ret;
        union wimlib_progress_info progress;
        unsigned part_number;
        int ret;
-       u8 guid[WIMLIB_GUID_LEN];
+       u8 guid[GUID_SIZE];
 
        swm_name_len = tstrlen(swm_name);
        swm_name_buf = alloca((swm_name_len + 20) * sizeof(tchar));
 
        swm_name_len = tstrlen(swm_name);
        swm_name_buf = alloca((swm_name_len + 20) * sizeof(tchar));
@@ -91,7 +91,7 @@ write_split_wim(WIMStruct *orig_wim, const tchar *swm_name,
                progress.split.total_bytes += swm_info->parts[part_number - 1].size;
        progress.split.total_parts = swm_info->num_parts;
 
                progress.split.total_bytes += swm_info->parts[part_number - 1].size;
        progress.split.total_parts = swm_info->num_parts;
 
-       randomize_byte_array(guid, WIMLIB_GUID_LEN);
+       generate_guid(guid);
 
        for (part_number = 1; part_number <= swm_info->num_parts; part_number++) {
                int part_write_flags;
 
        for (part_number = 1; part_number <= swm_info->num_parts; part_number++) {
                int part_write_flags;
index ff43ba59e5deda4921dec2d728fb800224d9e13d..df8678904dd6d4573e10883af51bfcfda0a3031f 100644 (file)
--- a/src/wim.c
+++ b/src/wim.c
@@ -187,7 +187,7 @@ wimlib_create_new_wim(enum wimlib_compression_type ctype, WIMStruct **wim_ret)
        wim->hdr.wim_version = WIM_VERSION_DEFAULT;
        wim->hdr.flags = 0;
        wim->hdr.chunk_size = 0;
        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);
+       generate_guid(wim->hdr.guid);
        wim->hdr.part_number = 1;
        wim->hdr.total_parts = 1;
        wim->hdr.image_count = 0;
        wim->hdr.part_number = 1;
        wim->hdr.total_parts = 1;
        wim->hdr.image_count = 0;
@@ -448,7 +448,7 @@ WIMLIBAPI int
 wimlib_get_wim_info(WIMStruct *wim, struct wimlib_wim_info *info)
 {
        memset(info, 0, sizeof(struct wimlib_wim_info));
 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;
        info->image_count = wim->hdr.image_count;
        info->boot_index = wim->hdr.boot_idx;
        info->wim_version = wim->hdr.wim_version;
@@ -494,7 +494,7 @@ wimlib_set_wim_info(WIMStruct *wim, const struct wimlib_wim_info *info, int whic
        }
 
        if (which & WIMLIB_CHANGE_GUID)
        }
 
        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;
 
        if (which & WIMLIB_CHANGE_BOOT_INDEX)
                wim->hdr.boot_idx = info->boot_index;
index 351c8e67a016be2dad1cd25d905c96ceadf94783..5e5ae7bc6731dc48bc5a0b31be896dc79adb562f 100644 (file)
@@ -346,7 +346,7 @@ static u8 *
 fill_in_wimoverlay_dat(u8 *buf,
                       const struct WimOverlay_dat_header *old_hdr,
                       const wchar_t *wim_path,
 fill_in_wimoverlay_dat(u8 *buf,
                       const struct WimOverlay_dat_header *old_hdr,
                       const wchar_t *wim_path,
-                      const u8 wim_guid[WIM_GUID_LEN],
+                      const u8 wim_guid[GUID_SIZE],
                       int image,
                       u64 new_data_source_id,
                       const PARTITION_INFORMATION_EX *part_info,
                       int image,
                       u64 new_data_source_id,
                       const PARTITION_INFORMATION_EX *part_info,
@@ -394,8 +394,8 @@ fill_in_wimoverlay_dat(u8 *buf,
        new_entry_1->entry_2_length = new_entry_2_size;
        new_entry_1->wim_type = WIM_BOOT_NOT_OS_WIM;
        new_entry_1->wim_index = image;
        new_entry_1->entry_2_length = new_entry_2_size;
        new_entry_1->wim_type = WIM_BOOT_NOT_OS_WIM;
        new_entry_1->wim_index = image;
-       BUILD_BUG_ON(sizeof(new_entry_1->guid) != WIM_GUID_LEN);
-       memcpy(new_entry_1->guid, wim_guid, WIM_GUID_LEN);
+       BUILD_BUG_ON(sizeof(new_entry_1->guid) != GUID_SIZE);
+       copy_guid(new_entry_1->guid, wim_guid);
 
        p += sizeof(struct WimOverlay_dat_entry_1);
 
 
        p += sizeof(struct WimOverlay_dat_entry_1);
 
@@ -491,7 +491,7 @@ fill_in_wimoverlay_dat(u8 *buf,
 static int
 prepare_wimoverlay_dat(const struct WimOverlay_dat_header *old_hdr,
                       const wchar_t *wim_path,
 static int
 prepare_wimoverlay_dat(const struct WimOverlay_dat_header *old_hdr,
                       const wchar_t *wim_path,
-                      const u8 wim_guid[WIM_GUID_LEN],
+                      const u8 wim_guid[GUID_SIZE],
                       int image,
                       void **new_contents_ret,
                       u32 *new_contents_size_ret,
                       int image,
                       void **new_contents_ret,
                       u32 *new_contents_size_ret,
@@ -790,7 +790,7 @@ out_free_contents:
  */
 static int
 update_wimoverlay_manually(const wchar_t *drive, const wchar_t *wim_path,
  */
 static int
 update_wimoverlay_manually(const wchar_t *drive, const wchar_t *wim_path,
-                          const u8 wim_guid[WIM_GUID_LEN],
+                          const u8 wim_guid[GUID_SIZE],
                           int image, u64 *data_source_id_ret)
 {
        wchar_t path_main[] = L"A:\\System Volume Information\\WimOverlay.dat";
                           int image, u64 *data_source_id_ret)
 {
        wchar_t path_main[] = L"A:\\System Volume Information\\WimOverlay.dat";
@@ -926,7 +926,7 @@ try_to_attach_wof(const wchar_t *drive)
  */
 int
 wimboot_alloc_data_source_id(const wchar_t *wim_path,
  */
 int
 wimboot_alloc_data_source_id(const wchar_t *wim_path,
-                            const u8 wim_guid[WIM_GUID_LEN],
+                            const u8 wim_guid[GUID_SIZE],
                             int image, const wchar_t *target,
                             u64 *data_source_id_ret, bool *wof_running_ret)
 {
                             int image, const wchar_t *target,
                             u64 *data_source_id_ret, bool *wof_running_ret)
 {
index 5bd8db911e1e275b40f5cd236d760fadf395674e..4d5e71651abceb3d411b3549d094705f28693827 100644 (file)
@@ -2751,9 +2751,9 @@ write_wim_part(WIMStruct *wim,
        if (write_flags & WIMLIB_WRITE_FLAG_RETAIN_GUID)
                guid = wim->hdr.guid;
        if (guid)
        if (write_flags & WIMLIB_WRITE_FLAG_RETAIN_GUID)
                guid = wim->hdr.guid;
        if (guid)
-               memcpy(wim->out_hdr.guid, guid, WIMLIB_GUID_LEN);
+               copy_guid(wim->out_hdr.guid, guid);
        else
        else
-               randomize_byte_array(wim->out_hdr.guid, WIMLIB_GUID_LEN);
+               generate_guid(wim->out_hdr.guid);
 
        /* Set the part number and total parts.  */
        wim->out_hdr.part_number = part_number;
 
        /* Set the part number and total parts.  */
        wim->out_hdr.part_number = part_number;