summaryrefslogtreecommitdiff
path: root/Source/Kernel/FileSystems
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel/FileSystems')
-rw-r--r--Source/Kernel/FileSystems/RamFS/RamDirNode.class.cpp0
-rw-r--r--Source/Kernel/FileSystems/RamFS/RamDirNode.class.h0
-rw-r--r--Source/Kernel/FileSystems/RamFS/RamFS.class.cpp86
-rw-r--r--Source/Kernel/FileSystems/RamFS/RamFS.class.h30
-rw-r--r--Source/Kernel/FileSystems/RamFS/RamFileNode.class.cpp0
-rw-r--r--Source/Kernel/FileSystems/RamFS/RamFileNode.class.h19
6 files changed, 135 insertions, 0 deletions
diff --git a/Source/Kernel/FileSystems/RamFS/RamDirNode.class.cpp b/Source/Kernel/FileSystems/RamFS/RamDirNode.class.cpp
deleted file mode 100644
index e69de29..0000000
--- a/Source/Kernel/FileSystems/RamFS/RamDirNode.class.cpp
+++ /dev/null
diff --git a/Source/Kernel/FileSystems/RamFS/RamDirNode.class.h b/Source/Kernel/FileSystems/RamFS/RamDirNode.class.h
deleted file mode 100644
index e69de29..0000000
--- a/Source/Kernel/FileSystems/RamFS/RamDirNode.class.h
+++ /dev/null
diff --git a/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp b/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp
index e69de29..c8ed27c 100644
--- a/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp
+++ b/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp
@@ -0,0 +1,86 @@
+#include "RamFS.class.h"
+#include <VFS/DirectoryNode.class.h>
+#include "RamFileNode.class.h"
+
+RamFS::RamFS(u32int maxSize) {
+ m_maxSize = maxSize;
+ m_usedSize = 0;
+ m_isWritable = true;
+ m_rootNode = new DirectoryNode("/", this, NULL);
+}
+
+bool RamFS::setName(FSNode* node, String name) { return true; }
+bool RamFS::setPermissions(FSNode* node, u32int permissions) { return true; }
+bool RamFS::setUid(FSNode* node, u32int uid) { return true; }
+bool RamFS::setGid(FSNode* node, u32int gid) { return true; }
+bool RamFS::setParent(FSNode* node, FSNode* parent) {
+ if (parent->getFS() == this) return true;
+ return false;
+}
+
+u32int RamFS::read(FileNode* file, u64int position, u32int max_length, u8int *data) {
+ RamFileNode *node = (RamFileNode*) file;
+ if (file->getLength() <= position) return 0;
+ u32int length = file->getLength() - position;
+ if (length > max_length) length = max_length;
+ memcpy(data, node->m_data + position, length);
+ return length;
+}
+
+bool RamFS::write(FileNode* file, u64int position, u32int length, u8int *data) {
+ if (!m_isWritable) return false;
+ RamFileNode *node = (RamFileNode*) file;
+
+ u32int end = position + length;
+ if (end > node->getLength()) {
+ if (m_usedSize - node->getLength() + end > m_maxSize) return false;
+ m_usedSize -= node->getLength();
+ m_usedSize += end;
+
+ u8int* data = (u8int*)Mem::kalloc(end);
+ if (data == 0) return false; //Invalid pointer
+ if (node->m_data != 0) {
+ memcpy(data, node->m_data, node->getLength());
+ Mem::kfree(node->m_data);
+ }
+ node->m_data = data;
+ node->setLength(end);
+ }
+ memcpy(node->m_data + position, data, length);
+ return true;
+}
+
+bool RamFS::truncate(FileNode* file) {
+ if (!m_isWritable) return false;
+ RamFileNode *node = (RamFileNode*) file;
+
+ Mem::kfree(node->m_data);
+ node->setLength(0);
+ node->m_data = 0;
+
+ return true;
+}
+
+bool RamFS::loadContents(DirectoryNode* dir) { return true; } //Nothing to do.
+
+FileNode* RamFS::createFile(DirectoryNode* parent, String name) {
+ if (!m_isWritable) return NULL;
+ if (parent->getFS() != this) return NULL;
+
+ RamFileNode* n = new RamFileNode(name, this, parent);
+ parent->loadContent();
+ parent->getChildren().push(n);
+
+ return n;
+}
+
+DirectoryNode* RamFS::createDirectory(DirectoryNode* parent, String name) {
+ if (!m_isWritable) return NULL;
+ if (parent->getFS() != this) return NULL;
+
+ DirectoryNode* d = new DirectoryNode(name, this, parent);
+ parent->loadContent();
+ parent->getChildren().push(d);
+
+ return d;
+}
diff --git a/Source/Kernel/FileSystems/RamFS/RamFS.class.h b/Source/Kernel/FileSystems/RamFS/RamFS.class.h
index e69de29..427019c 100644
--- a/Source/Kernel/FileSystems/RamFS/RamFS.class.h
+++ b/Source/Kernel/FileSystems/RamFS/RamFS.class.h
@@ -0,0 +1,30 @@
+#ifndef DEF_RAMFS_CLASS_H
+#define DEF_RAMFS_CLASS_H
+
+#include <VFS/FileSystem.proto.h>
+
+class RamFS : public FileSystem {
+ private:
+ u32int m_maxSize;
+ u32int m_usedSize;
+
+ public:
+ RamFS(u32int maxSize); //Creates an empty RAM file system
+ RamFS(u8int* ptr, u32int maxSize); //Creates a RAM file system from data loaded in memory. format to be defined
+
+ bool setName(FSNode* node, String name);
+ bool setPermissions(FSNode* node, u32int permissions);
+ bool setUid(FSNode* node, u32int uid);
+ bool setGid(FSNode* node, u32int gid);
+ bool setParent(FSNode* node, FSNode* parent);
+
+ u32int read(FileNode* file, u64int position, u32int max_length, u8int *data);
+ bool write(FileNode* file, u64int position, u32int length, u8int *data);
+ bool truncate(FileNode* file);
+
+ bool loadContents(DirectoryNode* dir);
+ FileNode* createFile(DirectoryNode* parent, String name);
+ DirectoryNode* createDirectory(DirectoryNode* parent, String name);
+};
+
+#endif
diff --git a/Source/Kernel/FileSystems/RamFS/RamFileNode.class.cpp b/Source/Kernel/FileSystems/RamFS/RamFileNode.class.cpp
deleted file mode 100644
index e69de29..0000000
--- a/Source/Kernel/FileSystems/RamFS/RamFileNode.class.cpp
+++ /dev/null
diff --git a/Source/Kernel/FileSystems/RamFS/RamFileNode.class.h b/Source/Kernel/FileSystems/RamFS/RamFileNode.class.h
index e69de29..142d763 100644
--- a/Source/Kernel/FileSystems/RamFS/RamFileNode.class.h
+++ b/Source/Kernel/FileSystems/RamFS/RamFileNode.class.h
@@ -0,0 +1,19 @@
+#ifndef DEF_RAMFILENODE_CLASS_H
+#define DEF_RAMFILENODE_CLASS_H
+
+#include <VFS/FileNode.class.h>
+
+class RamFileNode : public FileNode {
+ friend class RamFS;
+
+ private:
+ RamFileNode (String name, FileSystem* fs, FSNode* parent, u32int permissions = 0777,
+ u32int uid = 0, u32int gid = 0) :
+ FileNode(name, fs, parent, 0, permissions, uid, gid), m_data(0) {}
+
+ u8int *m_data;
+
+ void setLength(u32int length) { m_length = length; }
+};
+
+#endif