2022-01-17 00:58:47 -05:00
|
|
|
#ifndef KERNAUX_INCLUDED_MBR
|
|
|
|
#define KERNAUX_INCLUDED_MBR
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-06-24 19:07:10 -04:00
|
|
|
#include <kernaux/macro.h>
|
|
|
|
|
2022-01-17 01:34:42 -05:00
|
|
|
#include <stdbool.h>
|
2022-01-17 00:58:47 -05:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#define KERNAUX_MBR_SIZE 512
|
2022-01-23 21:50:16 -05:00
|
|
|
#define KERNAUX_MBR_MAGIC 0xaa55
|
2022-01-17 00:58:47 -05:00
|
|
|
#define KERNAUX_MBR_ENTRIES 4
|
|
|
|
|
|
|
|
#define KERNAUX_MBR_BOOTSTRAP_SIZE \
|
|
|
|
(KERNAUX_MBR_SIZE - sizeof(struct KernAux_Mbr_Info))
|
|
|
|
|
2022-06-24 19:07:10 -04:00
|
|
|
#include <kernaux/macro/packing_start.run>
|
|
|
|
|
2022-01-17 00:58:47 -05:00
|
|
|
struct KernAux_Mbr_Entry {
|
|
|
|
uint8_t drive_attributes;
|
2022-01-17 01:22:41 -05:00
|
|
|
unsigned first_sector_chs_addr : 24;
|
2022-01-17 00:58:47 -05:00
|
|
|
uint8_t partition_type;
|
2022-01-17 01:22:41 -05:00
|
|
|
unsigned last_sector_chs_addr : 24;
|
|
|
|
uint32_t first_sector_lba_addr;
|
2022-01-17 00:58:47 -05:00
|
|
|
uint32_t sectors_count;
|
|
|
|
}
|
2022-11-28 20:19:35 -05:00
|
|
|
KERNAUX_PACKED;
|
2022-06-24 19:07:10 -04:00
|
|
|
|
|
|
|
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_Mbr_Entry, 16);
|
2022-01-17 00:58:47 -05:00
|
|
|
|
|
|
|
struct KernAux_Mbr_Info {
|
|
|
|
uint32_t disk_id;
|
|
|
|
uint16_t reserved;
|
|
|
|
struct KernAux_Mbr_Entry entries[KERNAUX_MBR_ENTRIES];
|
|
|
|
uint16_t magic;
|
|
|
|
}
|
2022-11-28 20:19:35 -05:00
|
|
|
KERNAUX_PACKED;
|
2022-06-24 19:07:10 -04:00
|
|
|
|
|
|
|
KERNAUX_STATIC_TEST_STRUCT_SIZE(
|
|
|
|
KernAux_Mbr_Info,
|
|
|
|
8 + KERNAUX_MBR_ENTRIES * sizeof(struct KernAux_Mbr_Entry)
|
|
|
|
);
|
2022-01-17 00:58:47 -05:00
|
|
|
|
|
|
|
struct KernAux_Mbr {
|
|
|
|
uint8_t bootstrap[KERNAUX_MBR_BOOTSTRAP_SIZE];
|
|
|
|
struct KernAux_Mbr_Info info;
|
|
|
|
}
|
2022-11-28 20:19:35 -05:00
|
|
|
KERNAUX_PACKED;
|
2022-06-24 19:07:10 -04:00
|
|
|
|
|
|
|
KERNAUX_STATIC_TEST_STRUCT_SIZE(
|
|
|
|
KernAux_Mbr,
|
|
|
|
KERNAUX_MBR_BOOTSTRAP_SIZE + sizeof(struct KernAux_Mbr_Info)
|
|
|
|
);
|
|
|
|
|
|
|
|
#include <kernaux/macro/packing_end.run>
|
2022-01-17 00:58:47 -05:00
|
|
|
|
2022-01-17 01:34:42 -05:00
|
|
|
bool KernAux_Mbr_is_valid(const struct KernAux_Mbr *mbr);
|
|
|
|
bool KernAux_Mbr_Info_is_valid(const struct KernAux_Mbr_Info *mbr_info);
|
|
|
|
bool KernAux_Mbr_Entry_is_valid(const struct KernAux_Mbr_Entry *mbr_entry);
|
|
|
|
|
2022-01-17 00:58:47 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|