[dc76f4a] | 1 | /*
|
---|
| 2 | * Copyright (c) 2009 Jiri Svoboda
|
---|
| 3 | * Copyright (c) 2011, 2012, 2013 Dominik Taborsky
|
---|
| 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | /** @addtogroup libmbr
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #ifndef LIBMBR_MBR_H_
|
---|
| 37 | #define LIBMBR_MBR_H_
|
---|
| 38 |
|
---|
| 39 | #include <sys/types.h>
|
---|
| 40 |
|
---|
| 41 | /** Number of primary partition records */
|
---|
| 42 | #define N_PRIMARY 4
|
---|
| 43 |
|
---|
| 44 | /** Boot record signature */
|
---|
| 45 | #define BR_SIGNATURE 0xAA55
|
---|
| 46 |
|
---|
| 47 | enum {
|
---|
| 48 | /** Non-bootable */
|
---|
| 49 | B_INACTIVE = 0x00,
|
---|
| 50 | /** Bootable */
|
---|
| 51 | B_ACTIVE = 0x80,
|
---|
| 52 | /** Anything else means invalid */
|
---|
| 53 | };
|
---|
| 54 |
|
---|
| 55 | enum {
|
---|
| 56 | /** Unused partition entry */
|
---|
| 57 | PT_UNUSED = 0x00,
|
---|
| 58 | /** Extended partition */
|
---|
| 59 | PT_EXTENDED = 0x05,
|
---|
| 60 | /** Extended partition with LBA */
|
---|
| 61 | PT_EXTENDED_LBA = 0x0F,
|
---|
| 62 | /** GPT Protective partition */
|
---|
| 63 | PT_GPT = 0xEE,
|
---|
| 64 | };
|
---|
| 65 |
|
---|
| 66 | /** Structure of a partition table entry */
|
---|
| 67 | typedef struct {
|
---|
| 68 | uint8_t status;
|
---|
| 69 | /** CHS of fist block in partition */
|
---|
| 70 | uint8_t first_chs[3];
|
---|
| 71 | /** Partition type */
|
---|
| 72 | uint8_t ptype;
|
---|
| 73 | /** CHS of last block in partition */
|
---|
| 74 | uint8_t last_chs[3];
|
---|
| 75 | /** LBA of first block in partition */
|
---|
| 76 | uint32_t first_lba;
|
---|
| 77 | /** Number of blocks in partition */
|
---|
| 78 | uint32_t length;
|
---|
| 79 | } __attribute__((packed)) pt_entry_t;
|
---|
| 80 |
|
---|
| 81 | /** Structure of a boot-record block */
|
---|
| 82 | typedef struct {
|
---|
| 83 | /** Area for boot code */
|
---|
| 84 | uint8_t code_area[440];
|
---|
| 85 | /** Optional media ID */
|
---|
| 86 | uint32_t media_id;
|
---|
| 87 | /** Padding */
|
---|
| 88 | uint16_t pad0;
|
---|
| 89 | /** Partition table entries */
|
---|
| 90 | pt_entry_t pte[N_PRIMARY];
|
---|
| 91 | /** Boot record block signature (@c BR_SIGNATURE) */
|
---|
| 92 | uint16_t signature;
|
---|
| 93 | } __attribute__((packed)) br_block_t;
|
---|
| 94 |
|
---|
| 95 | #endif
|
---|
| 96 |
|
---|