From df76b24fed5ac3b5af406aad3df277d7f4c347e5 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Mon, 31 Aug 2009 21:44:26 +0200 Subject: Now we can read frop floppy drives !!! Next : FAT driver. --- Source/Kernel/VFS/.Part.ns.cpp.swp | Bin 0 -> 12288 bytes Source/Kernel/VFS/Part.ns.cpp | 59 ++++++++++++++++++++++++++++++++++ Source/Kernel/VFS/Part.ns.h | 18 +++++++++++ Source/Kernel/VFS/Partition.class.cpp | 25 ++++++++++++++ Source/Kernel/VFS/Partition.class.h | 28 ++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 Source/Kernel/VFS/.Part.ns.cpp.swp create mode 100644 Source/Kernel/VFS/Part.ns.cpp create mode 100644 Source/Kernel/VFS/Part.ns.h create mode 100644 Source/Kernel/VFS/Partition.class.cpp create mode 100644 Source/Kernel/VFS/Partition.class.h (limited to 'Source/Kernel/VFS') diff --git a/Source/Kernel/VFS/.Part.ns.cpp.swp b/Source/Kernel/VFS/.Part.ns.cpp.swp new file mode 100644 index 0000000..3b639ab Binary files /dev/null and b/Source/Kernel/VFS/.Part.ns.cpp.swp differ diff --git a/Source/Kernel/VFS/Part.ns.cpp b/Source/Kernel/VFS/Part.ns.cpp new file mode 100644 index 0000000..6408dbd --- /dev/null +++ b/Source/Kernel/VFS/Part.ns.cpp @@ -0,0 +1,59 @@ +#include "Part.ns.h" + +namespace Part { + +Vector devices; +Vector 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 +} + +void registerDevice(BlockDevice *dev) { + unregisterDevice(dev); + + asm volatile("cli"); + + readPartitionTable(dev); + + bool inserted = false; + for (u32int i = 0; i < devices.size(); i++) { + if (devices[i] == 0) { + devices[i] = dev; + inserted = true; + break; + } + } + if (!inserted) devices.push(dev); + + asm volatile("sti"); +} + +void unregisterDevice(BlockDevice *dev) { + asm volatile("cli"); + //Unregister && delete partitions + for (u32int i = 0; i < partitions.size(); i++) { + if (partitions[i]->getDevice() == dev) { + delete partitions[i]; + partitions[i] = partitions.back(); + partitions.pop(); + i--; + } + } + //Unregister device + for (u32int i = 0; i < devices.size(); i++) { + if (devices[i] == dev) devices[i] = 0; + } + if (!devices.empty() && devices.back() == 0) devices.pop(); + + asm volatile("sti"); +} + +u32int getDeviceID(BlockDevice* dev) { + for (u32int i = 0; i < devices.size(); i++) { + if (devices[i] == dev) return i; + } + return (u32int) - 1; +} + +} diff --git a/Source/Kernel/VFS/Part.ns.h b/Source/Kernel/VFS/Part.ns.h new file mode 100644 index 0000000..07a45f9 --- /dev/null +++ b/Source/Kernel/VFS/Part.ns.h @@ -0,0 +1,18 @@ +#ifndef DEF_PART_NS_H +#define DEF_PART_NS_H + +#include +#include +#include + +namespace Part { + extern Vector devices; + extern Vector partitions; + + void registerDevice(BlockDevice* dev); + void unregisterDevice(BlockDevice* dev); + + u32int getDeviceID(BlockDevice* dev); +} + +#endif diff --git a/Source/Kernel/VFS/Partition.class.cpp b/Source/Kernel/VFS/Partition.class.cpp new file mode 100644 index 0000000..0c7832b --- /dev/null +++ b/Source/Kernel/VFS/Partition.class.cpp @@ -0,0 +1,25 @@ +#include "Partition.class.h" + +Partition::Partition(BlockDevice* dev, u8int partnumber, u64int startblock, u64int blockcount) { + m_device = dev; + m_partnumber = partnumber; + m_startblock = startblock; + m_blockcount = blockcount; +} + +bool Partition::readBlocks(u64int startblock, u32int count, u8int *data) { + if (startblock + count > m_startblock + m_blockcount) return false; + return m_device->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_device->writeBlocks(startblock - m_startblock, count, data); +} + +//Accessors +BlockDevice* Partition::getDevice() { return m_device; } +u64int Partition::getStartBlock() { return m_startblock; } +u64int Partition::getBlockCount() { return m_blockcount; } +u8int Partition::getPartNumber() { return m_partnumber; } +u32int Partition::getBlockSize() { return m_device->blockSize(); } diff --git a/Source/Kernel/VFS/Partition.class.h b/Source/Kernel/VFS/Partition.class.h new file mode 100644 index 0000000..e9087bf --- /dev/null +++ b/Source/Kernel/VFS/Partition.class.h @@ -0,0 +1,28 @@ +#ifndef DEF_PARTITION_CLASS_H +#define DEF_PARTITION_CLASS_H + +#include + +class Partition { + private: + BlockDevice* m_device; + u64int m_startblock, m_blockcount; + u8int m_partnumber; //Partition number in partition table of device + + public: + Partition(BlockDevice* dev, u8int partnumber, u64int startblock, u64int blockcount); + + bool readBlocks(u64int startblock, u32int count, u8int *data); + bool writeBlocks(u64int startblock, u32int count, u8int *data); + + //Accessors : + BlockDevice* getDevice(); + u64int getStartBlock(); + u64int getBlockCount(); + u8int getPartNumber(); + u32int getBlockSize(); + inline u64int blocks() { return getBlockCount(); } +}; + +#endif + -- cgit v1.2.3