rust-kernel
Rustbelt: a hobby x86_64 kernel written in Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | //! Partition tables: MBR (1983, max 4 primary partitions, 2 TiB) and GPT
//! (UEFI era, 128 partitions, 64-bit sizes). A [`Partition`] is itself a
//! `BlockDevice` -- a window onto part of the disk -- so a file system on
//! "vda1" doesn't know (or care) that it starts at sector 2048 of "vda".
//!
//! MBR (sector 0): boot code, then 4 entries of 16 bytes at offset 446, then
//! the signature 0x55 0xAA. Each entry: type byte (offset 4), first sector
//! (u32 at 8), sector count (u32 at 12). Type 0xEE = "this disk is GPT, the
//! MBR is just a protective placeholder".
//!
//! GPT: header in sector 1 ("EFI PART"; where the entry array is, how many
//! entries, how big each is), entry array usually in sectors 2-33. Each
//! entry: type GUID (all zero = unused), unique GUID, first/last LBA, flags,
//! UTF-16 name. A backup copy lives at the end of the disk; we don't check
//! it, nor the CRC32 checksums (exercise!). Extended/logical MBR partitions
//! aren't supported either. References: wiki.osdev.org/MBR_(x86),
//! wiki.osdev.org/GPT
use ;
use crateErrno;
use ;
/// What the partition table says about one partition.
/// Read the partition table of `disk`: ("MBR" or "GPT", partitions).
/// Stage 21: the type name of a GPT "Linux root (x86-64)" partition (the
/// GUID from the Discoverable Partitions Specification). fs::mount_disks
/// mounts the first one holding ext2 at "/".
pub const ROOT_TYPE: &str = "Linux root (x86-64)";
/// ...and of a "Microsoft basic data" one (an exFAT one becomes /mnt/share).
pub const BASIC_DATA_TYPE: &str = "Microsoft basic data (FAT/exFAT/NTFS)";
/// GUIDs are stored with their first three fields little-endian, so the
/// bytes look scrambled compared to the usual text form.
/// A partition as a block device: sector numbers are shifted by `start` and
/// checked against `sectors`, so a file system can't scribble outside it.
|