/* * dp.c * Copyright 2017 Peter Jones * * Distributed under terms of the GPLv3 license. */ #include #include #define packed_ __attribute__((__packed__)) #define offsetof(a, b) __builtin_offsetof(a, b) typedef struct { uint8_t type; uint8_t subtype; uint16_t length; } efidp_header; typedef struct { uint8_t type; uint8_t subtype; uint16_t length; } packed_ efidp_header_packed; typedef struct { uint32_t partition_number; uint64_t start; uint64_t size; uint8_t signature[16]; uint8_t format; uint8_t signature_type; } efidp_hd_payload; typedef struct { uint32_t partition_number; uint64_t start; uint64_t size; uint8_t signature[16]; uint8_t format; uint8_t signature_type; } packed_ efidp_hd_payload_packed; typedef struct { efidp_header header; efidp_hd_payload payload; } efidp_hd_unpacked; typedef struct { efidp_header_packed header; efidp_hd_payload payload; } efidp_hd_packed_header; typedef struct { efidp_header header; efidp_hd_payload packed_ payload; } efidp_hd_packed_payload; typedef struct { efidp_header header; efidp_hd_payload payload; } packed_ efidp_hd_packed_struct; typedef struct { efidp_header_packed header; efidp_hd_payload_packed payload; } efidp_hd_packed_both; typedef struct { efidp_header_packed header; efidp_hd_payload_packed payload; } packed_ efidp_hd_packed; int main(void) { printf("unpacked:\n"); printf(" offsetof(efidp_hd_unpacked, header.type): %zd\n", offsetof(efidp_hd_unpacked, header.type)); printf(" offsetof(efidp_hd_unpacked, payload.partition_number): %zd\n", offsetof(efidp_hd_unpacked, payload.partition_number)); printf(" offsetof(efidp_hd_unpacked, payload.start): %zd\n", offsetof(efidp_hd_unpacked, payload.start)); printf(" offsetof(efidp_hd_unpacked, payload.size): %zd\n", offsetof(efidp_hd_unpacked, payload.size)); printf(" offsetof(efidp_hd_unpacked, payload.signature): %zd\n", offsetof(efidp_hd_unpacked, payload.signature)); printf(" offsetof(efidp_hd_unpacked, payload.format): %zd\n", offsetof(efidp_hd_unpacked, payload.format)); printf(" offsetof(efidp_hd_unpacked, payload.signature_type): %zd\n", offsetof(efidp_hd_unpacked, payload.signature_type)); printf("packed_header:\n"); printf(" offsetof(efidp_hd_packed_header, header.type): %zd\n", offsetof(efidp_hd_packed_header, header.type)); printf(" offsetof(efidp_hd_packed_header, payload.partition_number): %zd\n", offsetof(efidp_hd_packed_header, payload.partition_number)); printf(" offsetof(efidp_hd_packed_header, payload.start): %zd\n", offsetof(efidp_hd_packed_header, payload.start)); printf(" offsetof(efidp_hd_packed_header, payload.size): %zd\n", offsetof(efidp_hd_packed_header, payload.size)); printf(" offsetof(efidp_hd_packed_header, payload.signature): %zd\n", offsetof(efidp_hd_packed_header, payload.signature)); printf(" offsetof(efidp_hd_packed_header, payload.format): %zd\n", offsetof(efidp_hd_packed_header, payload.format)); printf(" offsetof(efidp_hd_packed_header, payload.signature_type): %zd\n", offsetof(efidp_hd_packed_header, payload.signature_type)); printf("packed_payload:\n"); printf(" offsetof(efidp_hd_packed_payload, header.type): %zd\n", offsetof(efidp_hd_packed_payload, header.type)); printf(" offsetof(efidp_hd_packed_payload, payload.partition_number): %zd\n", offsetof(efidp_hd_packed_payload, payload.partition_number)); printf(" offsetof(efidp_hd_packed_payload, payload.start): %zd\n", offsetof(efidp_hd_packed_payload, payload.start)); printf(" offsetof(efidp_hd_packed_payload, payload.size): %zd\n", offsetof(efidp_hd_packed_payload, payload.size)); printf(" offsetof(efidp_hd_packed_payload, payload.signature): %zd\n", offsetof(efidp_hd_packed_payload, payload.signature)); printf(" offsetof(efidp_hd_packed_payload, payload.format): %zd\n", offsetof(efidp_hd_packed_payload, payload.format)); printf(" offsetof(efidp_hd_packed_payload, payload.signature_type): %zd\n", offsetof(efidp_hd_packed_payload, payload.signature_type)); printf("packed_struct:\n"); printf(" offsetof(efidp_hd_packed_struct, header.type): %zd\n", offsetof(efidp_hd_packed_struct, header.type)); printf(" offsetof(efidp_hd_packed_struct, payload.partition_number): %zd\n", offsetof(efidp_hd_packed_struct, payload.partition_number)); printf(" offsetof(efidp_hd_packed_struct, payload.start): %zd\n", offsetof(efidp_hd_packed_struct, payload.start)); printf(" offsetof(efidp_hd_packed_struct, payload.size): %zd\n", offsetof(efidp_hd_packed_struct, payload.size)); printf(" offsetof(efidp_hd_packed_struct, payload.signature): %zd\n", offsetof(efidp_hd_packed_struct, payload.signature)); printf(" offsetof(efidp_hd_packed_struct, payload.format): %zd\n", offsetof(efidp_hd_packed_struct, payload.format)); printf(" offsetof(efidp_hd_packed_struct, payload.signature_type): %zd\n", offsetof(efidp_hd_packed_struct, payload.signature_type)); printf("packed_both:\n"); printf(" offsetof(efidp_hd_packed_both, header.type): %zd\n", offsetof(efidp_hd_packed_both, header.type)); printf(" offsetof(efidp_hd_packed_both, payload.partition_number): %zd\n", offsetof(efidp_hd_packed_both, payload.partition_number)); printf(" offsetof(efidp_hd_packed_both, payload.start): %zd\n", offsetof(efidp_hd_packed_both, payload.start)); printf(" offsetof(efidp_hd_packed_both, payload.size): %zd\n", offsetof(efidp_hd_packed_both, payload.size)); printf(" offsetof(efidp_hd_packed_both, payload.signature): %zd\n", offsetof(efidp_hd_packed_both, payload.signature)); printf(" offsetof(efidp_hd_packed_both, payload.format): %zd\n", offsetof(efidp_hd_packed_both, payload.format)); printf(" offsetof(efidp_hd_packed_both, payload.signature_type): %zd\n", offsetof(efidp_hd_packed_both, payload.signature_type)); printf("packed:\n"); printf(" offsetof(efidp_hd_packed, header.type): %zd\n", offsetof(efidp_hd_packed, header.type)); printf(" offsetof(efidp_hd_packed, payload.partition_number): %zd\n", offsetof(efidp_hd_packed, payload.partition_number)); printf(" offsetof(efidp_hd_packed, payload.start): %zd\n", offsetof(efidp_hd_packed, payload.start)); printf(" offsetof(efidp_hd_packed, payload.size): %zd\n", offsetof(efidp_hd_packed, payload.size)); printf(" offsetof(efidp_hd_packed, payload.signature): %zd\n", offsetof(efidp_hd_packed, payload.signature)); printf(" offsetof(efidp_hd_packed, payload.format): %zd\n", offsetof(efidp_hd_packed, payload.format)); printf(" offsetof(efidp_hd_packed, payload.signature_type): %zd\n", offsetof(efidp_hd_packed, payload.signature_type)); return 0; } // vim:fenc=utf-8:tw=75