Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::filesystem::partition::MSDOSPartition Class Reference

Handles mounting of partitions documented in an MSDOS partition table. More...

#include <msdos.h>

Static Public Member Functions

static void mount_partitions (drivers::disk::Disk *disk)
 read the partition table of a given hard disk
 

Detailed Description

Handles mounting of partitions documented in an MSDOS partition table.

Todo:
Abstract some of this into a base class and use it for GPT and other partition tables

Definition at line 350 of file msdos.h.

Member Function Documentation

◆ mount_partitions()

void MSDOSPartition::mount_partitions ( drivers::disk::Disk disk)
static

read the partition table of a given hard disk

Parameters
diskThe hard disk to read the partition table from

Definition at line 23 of file msdos.cpp.

23 {
24
25 // Read the MBR from the hard disk
28 disk->read(0, &mbr_buffer);
29
30 // Check if the magic number is correct
31 if (mbr.magic != 0xAA55) {
32 Logger::WARNING() << "Could not find valid MBR on disk 0x" << (uint64_t) disk << "\n";
33 return;
34 }
35
36 // Get the VFS
38
39 // Loop through the primary partitions
40 for (auto &entry: mbr.primary_partition) {
41
42 // Empty entry
43 if (entry.type == 0)
44 continue;
45
46 Logger::DEBUG() << "Partition 0x" << (uint64_t) entry.type << " at 0x" << (uint64_t) entry.start_LBA << ": ";
47
48 // Create a file system for the partition
49 switch ((PartitionType) entry.type) {
50 case PartitionType::EMPTY:
51 Logger::Out() << "Empty partition\n";
52 break;
53
54 case PartitionType::FAT32:
55 Logger::Out() << "FAT32 partition\n";
56 vfs->mount_filesystem(new Fat32FileSystem(disk, entry.start_LBA));
57 break;
58
59 case PartitionType::LINUX_EXT2:
60 Logger::Out() << "EXT2 partition\n";
61 vfs->mount_filesystem(new ext2::Ext2FileSystem(disk, entry.start_LBA));
62 break;
63
64 default:
65 Logger::Out() << "Unknown or unimplemented partition type: 0x" << (uint64_t) entry.type << "\n";
66
67 }
68 }
69}
static Logger DEBUG()
Gets active logger set to DEBUG level.
Definition logger.cpp:193
static Logger & Out()
Gets the active logger.
Definition logger.cpp:149
static Logger WARNING()
Gets active logger set to WARNING level.
Definition logger.cpp:205
Wrapper class for a region of bytes in memor in an attempt to add some memory safety....
Definition buffer.h:25
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
void read(uint32_t sector, common::buffer_t *data_buffer)
read data from the disk into a buffer (max capacity 512 bytes)
Definition disk.cpp:26
Combines all the filesystems across the partitions on each disk into a single filesystems and exposes...
Definition vfs.h:25
static VirtualFileSystem * current_file_system()
Get the active virtual file system.
Definition vfs.cpp:46
Handles the FAT32 filesystem operations.
Definition fat32.h:286
Handles the ext2 filesystem operations.
Definition ext2.h:456
PartitionType
Credit: http://www.osdever.net/documents/pdf/partitiontypes.pdf.
Definition msdos.h:22
Stores information about the master boot record.
Definition msdos.h:331

References MaxOS::filesystem::VirtualFileSystem::current_file_system(), MaxOS::Logger::DEBUG(), MaxOS::Logger::Out(), MaxOS::drivers::disk::Disk::read(), and MaxOS::Logger::WARNING().

Referenced by MaxOS::drivers::disk::IntegratedDriveElectronicsController::activate().


The documentation for this class was generated from the following files: