diff options
author | Alexis211 <alexis211@gmail.com> | 2009-08-31 21:44:26 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-08-31 21:44:26 +0200 |
commit | df76b24fed5ac3b5af406aad3df277d7f4c347e5 (patch) | |
tree | ea8a0ca4856cce9da63c047eff6e72a58c643159 /Source/Kernel/VFS | |
parent | 6bf215215e1ebaa9613b51500031e6963c12d33b (diff) | |
download | Melon-df76b24fed5ac3b5af406aad3df277d7f4c347e5.tar.gz Melon-df76b24fed5ac3b5af406aad3df277d7f4c347e5.zip |
Now we can read frop floppy drives !!! Next : FAT driver.
Diffstat (limited to 'Source/Kernel/VFS')
-rw-r--r-- | Source/Kernel/VFS/.Part.ns.cpp.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | Source/Kernel/VFS/Part.ns.cpp | 59 | ||||
-rw-r--r-- | Source/Kernel/VFS/Part.ns.h | 18 | ||||
-rw-r--r-- | Source/Kernel/VFS/Partition.class.cpp | 25 | ||||
-rw-r--r-- | Source/Kernel/VFS/Partition.class.h | 28 |
5 files changed, 130 insertions, 0 deletions
diff --git a/Source/Kernel/VFS/.Part.ns.cpp.swp b/Source/Kernel/VFS/.Part.ns.cpp.swp Binary files differnew file mode 100644 index 0000000..3b639ab --- /dev/null +++ b/Source/Kernel/VFS/.Part.ns.cpp.swp 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<BlockDevice*> devices; +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 +} + +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 <Devices/BlockDevice.proto.h> +#include <Library/Vector.class.h> +#include <VFS/Partition.class.h> + +namespace Part { + extern Vector<BlockDevice*> devices; + extern Vector<Partition*> 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 <Devices/BlockDevice.proto.h> + +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 + |