blob: d7588a85643f4b26a1acfabcd2cea9a3059d33b5 [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001#ifndef BLKID_PARTITIONS_DOS_H
2#define BLKID_PARTITIONS_DOS_H
3
4struct dos_partition {
5 unsigned char boot_ind; /* 0x80 - active */
6 unsigned char bh, bs, bc; /* begin CHS */
7 unsigned char sys_type;
8 unsigned char eh, es, ec; /* end CHS */
9 unsigned char start_sect[4];
10 unsigned char nr_sects[4];
11} __attribute__((packed));
12
13#define BLKID_MSDOS_PT_OFFSET 0x1be
14
15/* assemble badly aligned little endian integer */
16static inline unsigned int assemble4le(const unsigned char *p)
17{
18 return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
19}
20
21static inline unsigned int dos_partition_start(struct dos_partition *p)
22{
23 return assemble4le(&(p->start_sect[0]));
24}
25
26static inline unsigned int dos_partition_size(struct dos_partition *p)
27{
28 return assemble4le(&(p->nr_sects[0]));
29}
30
31static inline int is_valid_mbr_signature(const unsigned char *mbr)
32{
33 return mbr[510] == 0x55 && mbr[511] == 0xaa ? 1 : 0;
34}
35
36static inline unsigned int dos_parttable_id(const unsigned char *mbr)
37{
38 return assemble4le(&mbr[440]);
39}
40
41#endif /* BLKID_PARTITIONS_DOS_H */