From 19fd5bbc4f64cc8bf735f7c2c0bb864876998cf4 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Fri, 17 May 2013 22:50:12 -0500 Subject: [PATCH 1/1] Make padded structures work properly with MinGW --- Makefile.am | 5 +++++ src/dentry.c | 8 ++++++++ src/header.c | 3 ++- src/lookup_table.c | 6 ++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 75ed9716..45a85af8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/src/dentry.c b/src/dentry.c index 47a6175d..f986f9df 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -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"); diff --git a/src/header.c b/src/header.c index 5a665fc2..5b164161 100644 --- a/src/header.c +++ b/src/header.c @@ -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)); diff --git a/src/lookup_table.c b/src/lookup_table.c index f3d8c537..a24cf688 100644 --- a/src/lookup_table.c +++ b/src/lookup_table.c @@ -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; -- 2.43.0