From: Thanos Makatos Subject: [PATCH] blktap3/part: Introduce partition header Date: Fri, 19 Apr 2013 16:36:01 +0100 Message-ID: <1da601a68d77bfb21db0.1366385761@makatos-desktop> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: thanos.makatos@citrix.com List-Id: xen-devel@lists.xenproject.org This patch introduces partition structs and public functions. This file is imported from blktap2.5. I haven't looked thoroughly into this file, it seems to be used by libvhd to access partition tables inside VHD files. Signed-off-by: Thanos Makatos diff --git a/tools/blktap3/part/partition.h b/tools/blktap3/part/partition.h new file mode 100644 --- /dev/null +++ b/tools/blktap3/part/partition.h @@ -0,0 +1,45 @@ +#ifndef _PARTITION_H_ +#define _PARTITION_H_ + +#include + +#define PARTITION_BOOTABLE 0x80 +#define PARTITION_NON_BOOTABLE 0x00 + +#define MBR_SIGNATURE 0xAA55 +#define MBR_START_SECTOR 0x80 + +struct partition_geometry { + unsigned char heads; + unsigned char sectors; + unsigned int cylinders; +}; + +struct partition_chs { + uint8_t chs[3]; +} __attribute__ ((__packed__)); + +struct primary_partition { + uint8_t status; + struct partition_chs chs_first; + uint8_t type; + struct partition_chs chs_last; + uint32_t lba; + uint32_t blocks; +} __attribute__ ((__packed__)); + +struct partition_table { + uint8_t code[0x1b8]; + uint32_t disk_signature; + uint8_t pad[0x2]; + struct primary_partition partitions[4]; + uint16_t mbr_signature; +} __attribute__ ((__packed__)); + +void partition_table_in(struct partition_table *); +void partition_table_out(struct partition_table *); +int partition_table_validate(struct partition_table *); +void partition_table_dump(struct partition_table *); +struct partition_chs lba_to_chs(struct partition_geometry *, uint64_t); + +#endif