From a40fe1166ab1db972a8ca0380d603c4d90eede62 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Wed, 25 Nov 2009 18:42:44 +0100 Subject: Re-organized file system stuff. --- Source/Kernel/VFS/File.class.cpp | 3 ++- Source/Kernel/VFS/Part.ns.cpp | 27 +++++++++++++++++++++++++++ Source/Kernel/VFS/Part.ns.h | 3 +++ 3 files changed, 32 insertions(+), 1 deletion(-) (limited to 'Source/Kernel/VFS') diff --git a/Source/Kernel/VFS/File.class.cpp b/Source/Kernel/VFS/File.class.cpp index c5ddcd6..84561a5 100644 --- a/Source/Kernel/VFS/File.class.cpp +++ b/Source/Kernel/VFS/File.class.cpp @@ -33,7 +33,7 @@ bool File::open(String filename, u8int mode, FSNode* start, bool vrfyperm) { if (node == NULL){ if (mode == FM_READ) return false; node = VFS::createFile(filename, start, vrfyperm); - if (node == 0) return false; + if (node == NULL) return false; } if (node->type() != NT_FILE) return false; @@ -137,6 +137,7 @@ bool File::seek(u64int count, u8int mode) { } bool File::eof() { + if (!m_valid) return false; return m_position == m_file->getLength(); } diff --git a/Source/Kernel/VFS/Part.ns.cpp b/Source/Kernel/VFS/Part.ns.cpp index 6408dbd..7184f90 100644 --- a/Source/Kernel/VFS/Part.ns.cpp +++ b/Source/Kernel/VFS/Part.ns.cpp @@ -56,4 +56,31 @@ u32int getDeviceID(BlockDevice* dev) { return (u32int) - 1; } +BlockDevice* dev(String _class, u32int idx) { + for (u32int i = 0; i < devices.size(); i++) { + String devclass = devices[i]->getClass(); + if (devclass == _class or (devclass.size() > _class.size() and devclass.substr(0, _class.size()) == _class)) { + if (idx == 0) { + return devices[i]; + } else { + idx--; + } + } + } + return NULL; +} + +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--; + } + } + } + return NULL; +} + } diff --git a/Source/Kernel/VFS/Part.ns.h b/Source/Kernel/VFS/Part.ns.h index 40a0fb2..4373a2d 100644 --- a/Source/Kernel/VFS/Part.ns.h +++ b/Source/Kernel/VFS/Part.ns.h @@ -13,6 +13,9 @@ namespace Part { void unregisterDevice(BlockDevice* dev); u32int getDeviceID(BlockDevice* dev); + + BlockDevice* dev(String _class, u32int idx); + Partition* part(BlockDevice* dev, u32int idx); } #endif -- cgit v1.2.3