| 1 |
/** @file |
| 2 |
* @brief Master Boot Record |
| 3 |
* |
| 4 |
* Based on http://thestarman.pcministry.com/asm/mbr/PartTables.htm |
| 5 |
*/ |
| 6 |
|
| 7 |
/* |
| 8 |
* Copyright (c) 2014 Flávio J. Saraiva <[email protected]> |
| 9 |
*/ |
| 10 |
|
| 11 |
#ifndef FS_MBR__ |
| 12 |
#define FS_MBR__ |
| 13 |
|
| 14 |
#include "dynamips_common.h" |
| 15 |
|
| 16 |
#define MBR_CYLINDER_MIN 0 |
| 17 |
#define MBR_CYLINDER_MAX 1023 |
| 18 |
#define MBR_HEAD_MIN 0 |
| 19 |
#define MBR_HEAD_MAX 254 |
| 20 |
#define MBR_SECTOR_MIN 1 |
| 21 |
#define MBR_SECTOR_MAX 63 |
| 22 |
|
| 23 |
#define MBR_PARTITION_BOOTABLE 0x80 |
| 24 |
|
| 25 |
#define MBR_PARTITION_TYPE_FAT16 0x04 |
| 26 |
|
| 27 |
#define MBR_SIGNATURE_0 0x55 |
| 28 |
#define MBR_SIGNATURE_1 0xAA |
| 29 |
|
| 30 |
#define MBR_OFFSET 512 - sizeof(struct mbr_data) |
| 31 |
|
| 32 |
/* A partition of the MBR */ |
| 33 |
struct mbr_partition { |
| 34 |
m_uint8_t bootable; |
| 35 |
m_uint8_t first_chs[3]; |
| 36 |
m_uint8_t type; |
| 37 |
m_uint8_t last_chs[3]; |
| 38 |
m_uint32_t lba; |
| 39 |
m_uint32_t nr_sectors; |
| 40 |
} __attribute__((__packed__)); |
| 41 |
|
| 42 |
/* The MBR data */ |
| 43 |
struct mbr_data { |
| 44 |
struct mbr_partition partition[4]; |
| 45 |
m_uint8_t signature[2]; |
| 46 |
} __attribute__((__packed__)); |
| 47 |
|
| 48 |
void mbr_get_chs(m_uint8_t chs[3], m_uint16_t *cyl, m_uint8_t *head, m_uint8_t *sect); |
| 49 |
void mbr_set_chs(m_uint8_t chs[3], m_uint16_t cyl, m_uint8_t head, m_uint8_t sect); |
| 50 |
int mbr_write_fd(int fd, struct mbr_data *mbr); |
| 51 |
int mbr_read_fd(int fd, struct mbr_data *mbr); |
| 52 |
|
| 53 |
#endif |