diff options
Diffstat (limited to 'Source/Kernel/VFS')
-rw-r--r-- | Source/Kernel/VFS/Part.ns.cpp | 25 | ||||
-rw-r--r-- | Source/Kernel/VFS/Part.ns.h | 13 | ||||
-rw-r--r-- | Source/Kernel/VFS/Partition.class.cpp | 4 |
3 files changed, 34 insertions, 8 deletions
diff --git a/Source/Kernel/VFS/Part.ns.cpp b/Source/Kernel/VFS/Part.ns.cpp index 9ead6b5..415a150 100644 --- a/Source/Kernel/VFS/Part.ns.cpp +++ b/Source/Kernel/VFS/Part.ns.cpp @@ -1,5 +1,7 @@ #include "Part.ns.h" +#include <VTManager/SimpleVT.class.h> + namespace Part { Vector<BlockDevice*> devices; @@ -7,6 +9,21 @@ Vector<Partition*> partitions; void readPartitionTable(BlockDevice *dev) { //TODO : read partition table from device partitions.push(new Partition(dev, 0, 0, dev->blocks())); //Insert whole device as a partition + + u8int* mbr = (u8int*)Mem::alloc(dev->blockSize()); + if (!dev->readBlocks(0, 1, mbr)) return; + + mbr_entry_t* entries = (mbr_entry_t*)((u32int)mbr + 0x1BE); + + for (u32int i = 0; i < 4; i++) { + if ((entries[i].bootable == 0 or entries[i].bootable == 0x80) and entries[i].id != 0 + and entries[i].s_lba != 0 and entries[i].size != 0 + and entries[i].s_lba < dev->blocks() and entries[i].size < dev->blocks()) { + partitions.push(new Partition(dev, i + 1, entries[i].s_lba, entries[i].size)); + } + } + + Mem::free(mbr); } void registerDevice(BlockDevice *dev) { @@ -73,12 +90,8 @@ BlockDevice* dev(String _class, u32int idx) { Partition* part(BlockDevice* dev, u32int idx) { for (u32int i = 0; i < partitions.size(); i++) { - if (partitions[i]->getDevice() == dev) { - if (idx == 0) { - return partitions[i]; - } else { - idx--; - } + if (partitions[i]->getDevice() == dev && partitions[i]->getPartNumber() == idx) { + return partitions[i]; } } return NULL; diff --git a/Source/Kernel/VFS/Part.ns.h b/Source/Kernel/VFS/Part.ns.h index 992f6f3..e6a358c 100644 --- a/Source/Kernel/VFS/Part.ns.h +++ b/Source/Kernel/VFS/Part.ns.h @@ -6,6 +6,19 @@ #include <VFS/Partition.class.h> namespace Part { + struct mbr_entry_t { + u8int bootable; /* 0 = no, 0x80 = bootable */ + u8int s_head; /* Starting head */ + u16int s_sector : 6; /* Starting sector */ + u16int s_cyl : 10; /* Starting cylinder */ + u8int id; /* System ID */ + u8int e_head; /* Ending head */ + u16int e_sector : 6; /* Ending sector */ + u16int e_cyl : 10; /* Ending cylinder */ + u32int s_lba; /* Starting sector (LBA value) */ + u32int size; /* Total sector number */ + } __attribute__ ((packed)); + extern Vector<BlockDevice*> devices; extern Vector<Partition*> partitions; diff --git a/Source/Kernel/VFS/Partition.class.cpp b/Source/Kernel/VFS/Partition.class.cpp index 8d7de9b..9da3461 100644 --- a/Source/Kernel/VFS/Partition.class.cpp +++ b/Source/Kernel/VFS/Partition.class.cpp @@ -13,12 +13,12 @@ Partition::Partition(BlockDevice* dev, u8int partnumber, u64int startblock, u64i bool Partition::readBlocks(u64int startblock, u32int count, u8int *data) { if (startblock + count > m_startblock + m_blockcount) return false; - return m_cache.readBlocks(startblock - m_startblock, count, data); + return m_cache.readBlocks(startblock + m_startblock, count, data); } bool Partition::writeBlocks(u64int startblock, u32int count, u8int *data) { if (startblock + count > m_startblock + m_blockcount) return false; - return m_cache.writeBlocks(startblock - m_startblock, count, data); + return m_cache.writeBlocks(startblock + m_startblock, count, data); } bool Partition::read(u64int start, u32int length, u8int *data) { |