]> wimlib.net Git - wimlib/commitdiff
Make padded structures work properly with MinGW
authorEric Biggers <ebiggers3@gmail.com>
Sat, 18 May 2013 03:50:12 +0000 (22:50 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 18 May 2013 03:50:12 +0000 (22:50 -0500)
Makefile.am
src/dentry.c
src/header.c
src/lookup_table.c

index 75ed97168a1f8f8c3d4565235aca651541559b22..45a85af82597b50324234a3618e21ecc16d1c9b5 100644 (file)
@@ -7,6 +7,11 @@ AM_CFLAGS      = -std=gnu99 -Wmissing-prototypes -Wstrict-prototypes   \
                  -Werror-implicit-function-declaration                 \
                  -fno-common -Wundef -Wno-pointer-sign
 
+if WINDOWS_NATIVE_BUILD
+# This option is needed to make packed structures work as expected
+# with gcc 4.7+ (mingw) on Windows.
+AM_CFLAGS += -mno-ms-bitfields
+endif
 
 lib_LTLIBRARIES = libwim.la
 
index 47a6175d789bbd3579a2d5ce381d80ddfa8d20b1..f986f9df12fbfe02624b70bbc66dee964565028c 100644 (file)
@@ -70,6 +70,8 @@ struct wim_ads_entry_on_disk {
        utf16lechar stream_name[];
 } _packed_attribute;
 
+#define WIM_ADS_ENTRY_DISK_SIZE 38
+
 /* WIM directory entry (on-disk format) */
 struct wim_dentry_on_disk {
        le64 length;
@@ -105,6 +107,8 @@ struct wim_dentry_on_disk {
        /*utf16lechar short_name[];*/
 } _packed_attribute;
 
+#define WIM_DENTRY_DISK_SIZE 102
+
 /* Calculates the unaligned length, in bytes, of an on-disk WIM dentry that has
  * a file name and short name that take the specified numbers of bytes.  This
  * excludes any alternate data stream entries that may follow the dentry. */
@@ -1387,6 +1391,8 @@ read_ads_entries(const u8 * restrict p, struct wim_inode * restrict inode,
        struct wim_ads_entry *ads_entries;
        int ret;
 
+       BUILD_BUG_ON(sizeof(struct wim_ads_entry_on_disk) != WIM_ADS_ENTRY_DISK_SIZE);
+
        /* Allocate an array for our in-memory representation of the alternate
         * data stream entries. */
        num_ads = inode->i_num_ads;
@@ -1531,6 +1537,8 @@ read_dentry(const u8 * restrict metadata_resource, u64 metadata_resource_len,
        const struct wim_dentry_on_disk *disk_dentry =
                        (const struct wim_dentry_on_disk*)p;
 
+       BUILD_BUG_ON(sizeof(struct wim_dentry_on_disk) != WIM_DENTRY_DISK_SIZE);
+
        if ((uintptr_t)p & 7)
                WARNING("WIM dentry is not 8-byte aligned");
 
index 5a665fc25113db71eec709ca697cd063839c5943..5b164161e82bce404a1e8235f57d72c047a87778 100644 (file)
@@ -120,6 +120,8 @@ read_header(const tchar *filename, int in_fd,
 {
        struct wim_header_disk disk_hdr _aligned_attribute(8);
 
+       BUILD_BUG_ON(sizeof(struct wim_header_disk) != WIM_HEADER_DISK_SIZE);
+
        DEBUG("Reading WIM header from \"%"TS"\"", filename);
 
        if (full_pread(in_fd, &disk_hdr, sizeof(disk_hdr), 0) != sizeof(disk_hdr)) {
@@ -132,7 +134,6 @@ read_header(const tchar *filename, int in_fd,
                return WIMLIB_ERR_NOT_A_WIM_FILE;
        }
 
-       BUILD_BUG_ON(sizeof(struct wim_header_disk) != WIM_HEADER_DISK_SIZE);
        if (le32_to_cpu(disk_hdr.hdr_size) != sizeof(struct wim_header_disk)) {
                ERROR("\"%"TS"\": Header size is invalid (%u bytes)",
                      filename, le32_to_cpu(disk_hdr.hdr_size));
index f3d8c537d4237730d89ca24a56545f2c05225bdb..a24cf68887d40a4246d3a29ad7639e29f67fb506 100644 (file)
@@ -365,6 +365,8 @@ struct wim_lookup_table_entry_disk {
        u8 hash[SHA1_HASH_SIZE];
 } _packed_attribute;
 
+#define WIM_LOOKUP_TABLE_ENTRY_DISK_SIZE 50
+
 /*
  * Reads the lookup table from a WIM file.
  *
@@ -382,6 +384,10 @@ read_lookup_table(WIMStruct *w)
        struct wim_lookup_table_entry_disk
                        table_buf[BUFFER_SIZE / sizeof(struct wim_lookup_table_entry_disk)]
                                _aligned_attribute(8);
+
+       BUILD_BUG_ON(sizeof(struct wim_lookup_table_entry_disk) !=
+                    WIM_LOOKUP_TABLE_ENTRY_DISK_SIZE);
+
        off_t offset;
        size_t buf_entries_remaining;
        const struct wim_lookup_table_entry_disk *disk_entry;