qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 2/5] block: Virtual Bridges VERDE GOW disk image


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH 2/5] block: Virtual Bridges VERDE GOW disk image format data structures and common MACROs
Date: Fri, 9 Mar 2012 11:02:27 +0000

On Thu, Mar 8, 2012 at 10:14 PM, Leonardo E. Reiter
<address@hidden> wrote:
> +#if defined(BLOCK_GOW1)
> +#define GOW_MAGIC       GOW1_MAGIC
> +#define GOW_MAXBLOCKS   1048576
> +
> +/* GOW1: header is not padded */
> +/* header type, contains map */
> +typedef struct {
> +    uint32_t magic;
> +    uint32_t size;
> +    uint32_t allocated;
> +    uint32_t map[GOW_MAXBLOCKS];
> +} gow_header_t;
> +
> +/* block type, contains data */
> +typedef struct {
> +    uint8_t data[GOW_BLOCKSIZE];
> +} gow_block_t;
> +#else /* GOW2, GOW3 below */
> +
> +
> +/* GOW2: approximately 16MB header size, and up to 256GB image size
> + * GOW3: approximately 32MB header size, and up to 256GB image size */
> +
> +#define GOW_MAXBLOCKS   4194304
> +
> +typedef struct {
> +    uint32_t magic;
> +    uint32_t size;
> +    uint32_t allocated;
> +    uint32_t map[GOW_MAXBLOCKS];
> +} gow2_header_t;
> +
> +typedef struct {
> +    uint32_t magic;
> +    uint32_t size;
> +    uint32_t allocated;
> +    uint32_t map[GOW_MAXBLOCKS];
> +    uint32_t ver[GOW_MAXBLOCKS];
> +    uint32_t carry;
> +    uint8_t  signature[32];
> +    uint32_t maint;
> +} gow3_header_t;
> +
> +/* header is padded to 512-bytes so image can be indexed in sectors */
> +#define GOW2_HEADER_SIZE (((sizeof(gow2_header_t) + 511) >> 9) << 9)
> +#define GOW3_HEADER_SIZE (((sizeof(gow3_header_t) + 511) >> 9) << 9)
> +
> +#endif /* GOW2, GOW3 */
> +
> +#if defined(BLOCK_GOW1)
> +
> +#define GOW_HEADER_SIZE (sizeof(gow_header_t))
> +
> +#elif defined(BLOCK_GOW2)
> +
> +#define GOW_MAGIC       GOW2_MAGIC
> +#define GOW_HEADER_SIZE GOW2_HEADER_SIZE
> +#define gow_header_t gow2_header_t
> +
> +#elif defined(BLOCK_GOW3)
> +
> +#define GOW_MAGIC       GOW3_MAGIC
> +#define gow_header_t gow3_header_t
> +#define GOW_HEADER_SIZE GOW3_HEADER_SIZE
> +
> +#endif

This #ifdef approach is ugly.  All three headers have the same
starting common fields.

I bet you could have clean C code without reincluding this header and
using macro tricks.  Just use the common header fields and
parameterize the size, if needed.

Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]