summaryrefslogtreecommitdiffstats
path: root/include/pt-mbr.h
diff options
context:
space:
mode:
authorKarel Zak2013-06-18 15:03:26 +0200
committerKarel Zak2013-09-16 16:47:02 +0200
commitf917738efaa60bd1390482d2959986393cea4737 (patch)
tree8a34b741b6c64776197376feb26ea4118a8ad45e /include/pt-mbr.h
parentfdisk: (dos) rename struct partition to dos_partition (diff)
downloadkernel-qcow2-util-linux-f917738efaa60bd1390482d2959986393cea4737.tar.gz
kernel-qcow2-util-linux-f917738efaa60bd1390482d2959986393cea4737.tar.xz
kernel-qcow2-util-linux-f917738efaa60bd1390482d2959986393cea4737.zip
libblkid: move MBR definitions to include/pt-mbr.h
Diffstat (limited to 'include/pt-mbr.h')
-rw-r--r--include/pt-mbr.h37
1 files changed, 37 insertions, 0 deletions
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,