55 struct partition_table_entry
67 struct partition_table
70 struct partition_table_entry partitions[4];
75 struct partition_table *pt;
81 printf (
"%s: Partition table at sector %"PRDSNu" past end of device.\n",
90 PANIC (
"Failed to allocate memory for partition table.");
94 if (pt->signature != 0xaa55)
96 if (primary_extended_sector == 0)
99 printf (
"%s: Invalid extended partition table in sector %"PRDSNu"\n",
106 for (i = 0; i <
sizeof pt->partitions /
sizeof *pt->partitions; i++)
108 struct partition_table_entry *e = &pt->partitions[i];
110 if (e->size == 0 || e->type == 0)
114 else if (e->type == 0x05
134 primary_extended_sector, part_nr);
159 printf (
"%s%d: Partition starts past end of device (sector %"PRDSNu")\n",
172 char extra_info[128];
177 PANIC (
"Failed to allocate memory for partition descriptor");
182 snprintf (extra_info,
sizeof extra_info,
"%s (%02x)",
196 static const char *type_names[256] =
200 [0x02] =
"XENIX root",
201 [0x03] =
"XENIX usr",
202 [0x04] =
"FAT16 <32M",
205 [0x07] =
"HPFS/NTFS",
207 [0x09] =
"AIX bootable",
208 [0x0a] =
"OS/2 Boot Manager",
209 [0x0b] =
"W95 FAT32",
210 [0x0c] =
"W95 FAT32 (LBA)",
211 [0x0e] =
"W95 FAT16 (LBA)",
212 [0x0f] =
"W95 Ext'd (LBA)",
214 [0x11] =
"Hidden FAT12",
215 [0x12] =
"Compaq diagnostics",
216 [0x14] =
"Hidden FAT16 <32M",
217 [0x16] =
"Hidden FAT16",
218 [0x17] =
"Hidden HPFS/NTFS",
219 [0x18] =
"AST SmartSleep",
220 [0x1b] =
"Hidden W95 FAT32",
221 [0x1c] =
"Hidden W95 FAT32 (LBA)",
222 [0x1e] =
"Hidden W95 FAT16 (LBA)",
223 [0x20] =
"Pintos OS kernel",
224 [0x21] =
"Pintos file system",
225 [0x22] =
"Pintos scratch",
226 [0x23] =
"Pintos swap",
229 [0x3c] =
"PartitionMagic recovery",
230 [0x40] =
"Venix 80286",
231 [0x41] =
"PPC PReP Boot",
234 [0x4e] =
"QNX4.x 2nd part",
235 [0x4f] =
"QNX4.x 3rd part",
236 [0x50] =
"OnTrack DM",
237 [0x51] =
"OnTrack DM6 Aux1",
239 [0x53] =
"OnTrack DM6 Aux3",
240 [0x54] =
"OnTrackDM6",
242 [0x56] =
"Golden Bow",
243 [0x5c] =
"Priam Edisk",
244 [0x61] =
"SpeedStor",
245 [0x63] =
"GNU HURD or SysV",
246 [0x64] =
"Novell Netware 286",
247 [0x65] =
"Novell Netware 386",
248 [0x70] =
"DiskSecure Multi-Boot",
250 [0x80] =
"Old Minix",
251 [0x81] =
"Minix / old Linux",
252 [0x82] =
"Linux swap / Solaris",
254 [0x84] =
"OS/2 hidden C: drive",
255 [0x85] =
"Linux extended",
256 [0x86] =
"NTFS volume set",
257 [0x87] =
"NTFS volume set",
258 [0x88] =
"Linux plaintext",
259 [0x8e] =
"Linux LVM",
261 [0x94] =
"Amoeba BBT",
263 [0xa0] =
"IBM Thinkpad hibernation",
267 [0xa8] =
"Darwin UFS",
269 [0xab] =
"Darwin boot",
271 [0xb8] =
"BSDI swap",
272 [0xbb] =
"Boot Wizard hidden",
273 [0xbe] =
"Solaris boot",
275 [0xc1] =
"DRDOS/sec (FAT-12)",
276 [0xc4] =
"DRDOS/sec (FAT-16 < 32M)",
277 [0xc6] =
"DRDOS/sec (FAT-16)",
279 [0xda] =
"Non-FS data",
280 [0xdb] =
"CP/M / CTOS / ...",
281 [0xde] =
"Dell Utility",
283 [0xe1] =
"DOS access",
285 [0xe4] =
"SpeedStor",
288 [0xef] =
"EFI (FAT-12/16/32)",
289 [0xf0] =
"Linux/PA-RISC boot",
290 [0xf1] =
"SpeedStor",
291 [0xf4] =
"SpeedStor",
292 [0xf2] =
"DOS secondary",
293 [0xfd] =
"Linux raid autodetect",
298 return type_names[type] !=
NULL ? type_names[type] :
"Unknown";
struct block * block_register(const char *name, enum block_type type, const char *extra_info, block_sector_t size, const struct block_operations *ops, void *aux)
Registers a new block device with the given NAME.
block_sector_t block_size(struct block *block)
Returns the number of sectors in BLOCK.
void block_read(struct block *block, block_sector_t sector, void *buffer)
Reads sector SECTOR from BLOCK into BUFFER, which must have room for BLOCK_SECTOR_SIZE bytes.
void block_write(struct block *block, block_sector_t sector, const void *buffer)
Write sector SECTOR to BLOCK from BUFFER, which must contain BLOCK_SECTOR_SIZE bytes.
const char * block_name(struct block *block)
Returns BLOCK's name (e.g.
uint32_t block_sector_t
Index of a block device sector.
#define BLOCK_SECTOR_SIZE
Size of a block device sector in bytes.
#define PRDSNu
Format specifier for printf(), e.g.
block_type
Type of a block device.
@ BLOCK_KERNEL
Pintos OS kernel.
@ BLOCK_FILESYS
File system.
@ BLOCK_FOREIGN
Owned by non-Pintos operating system.
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
#define PANIC(...)
Halts the OS, printing the source file name, line number, and function name, plus a user-specific mes...
int snprintf(char *buffer, size_t buf_size, const char *format,...)
Like printf(), except that output is stored into BUFFER, which must have space for BUF_SIZE character...
int printf(const char *format,...)
Writes formatted output to the console.
void * malloc(size_t size)
Obtains and returns a new block of at least SIZE bytes.
void free(void *p)
Frees block P, which must have been previously allocated with malloc(), calloc(), or realloc().
static void partition_write(void *p_, block_sector_t sector, const void *buffer)
Write sector SECTOR to partition P from BUFFER, which must contain BLOCK_SECTOR_SIZE bytes.
static struct block_operations partition_operations
static void partition_read(void *p_, block_sector_t sector, void *buffer)
Reads sector SECTOR from partition P into BUFFER, which must have room for BLOCK_SECTOR_SIZE bytes.
static const char * partition_type_name(uint8_t)
Returns a human-readable name for the given partition TYPE.
static void read_partition_table(struct block *, block_sector_t sector, block_sector_t primary_extended_sector, int *part_nr)
Reads the partition table in the given SECTOR of BLOCK and scans it for partitions of interest to Pin...
static void found_partition(struct block *, uint8_t type, block_sector_t start, block_sector_t size, int part_nr)
We have found a primary or logical partition of the given TYPE on BLOCK, starting at sector START and...
void partition_scan(struct block *block)
Scans BLOCK for partitions of interest to Pintos.
unsigned short int uint16_t
Lower-level interface to block device drivers.
enum block_type type
Type of block device.
A partition of a block device.
block_sector_t start
First sector within device.
struct block * block
Underlying block device.
struct ustar_header PACKED