From f917738efaa60bd1390482d2959986393cea4737 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 18 Jun 2013 15:03:26 +0200 Subject: libblkid: move MBR definitions to include/pt-mbr.h --- include/pt-mbr.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'include/pt-mbr.h') diff --git a/include/pt-mbr.h b/include/pt-mbr.h index a02eaa98b..eef940b57 100644 --- a/include/pt-mbr.h +++ b/include/pt-mbr.h @@ -1,6 +1,43 @@ #ifndef UTIL_LINUX_PT_MBR_H #define UTIL_LINUX_PT_MBR_H +struct dos_partition { + unsigned char boot_ind; /* 0x80 - active */ + unsigned char bh, bs, bc; /* begin CHS */ + unsigned char sys_type; + unsigned char eh, es, ec; /* end CHS */ + unsigned char start_sect[4]; + unsigned char nr_sects[4]; +} __attribute__((packed)); + +#define MBR_PT_OFFSET 0x1be + +/* assemble badly aligned little endian integer */ +static inline unsigned int __dos_assemble4le(const unsigned char *p) +{ + return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); +} + +static inline unsigned int dos_partition_start(struct dos_partition *p) +{ + return __dos_assemble4le(&(p->start_sect[0])); +} + +static inline unsigned int dos_partition_size(struct dos_partition *p) +{ + return __dos_assemble4le(&(p->nr_sects[0])); +} + +static inline int is_valid_mbr_signature(const unsigned char *mbr) +{ + return mbr[510] == 0x55 && mbr[511] == 0xaa ? 1 : 0; +} + +static inline unsigned int dos_parttable_id(const unsigned char *mbr) +{ + return __dos_assemble4le(&mbr[440]); +} + enum { MBR_EMPTY_PARTITION = 0x00, MBR_FAT12_PARTITION = 0x01, -- cgit v1.2.3-55-g7522