From b808b613a5c7e0b6c6c45b28f7f0169dc13afaa2 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 13 Sep 2009 13:09:10 +0200 Subject: Created some files --- Source/Kernel/FileSystems/RamFS/RamDirNode.class.cpp | 0 Source/Kernel/FileSystems/RamFS/RamDirNode.class.h | 0 Source/Kernel/FileSystems/RamFS/RamFS.class.cpp | 0 Source/Kernel/FileSystems/RamFS/RamFS.class.h | 0 Source/Kernel/FileSystems/RamFS/RamFileNode.class.cpp | 0 Source/Kernel/FileSystems/RamFS/RamFileNode.class.h | 0 6 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Source/Kernel/FileSystems/RamFS/RamDirNode.class.cpp create mode 100644 Source/Kernel/FileSystems/RamFS/RamDirNode.class.h create mode 100644 Source/Kernel/FileSystems/RamFS/RamFS.class.cpp create mode 100644 Source/Kernel/FileSystems/RamFS/RamFS.class.h create mode 100644 Source/Kernel/FileSystems/RamFS/RamFileNode.class.cpp create mode 100644 Source/Kernel/FileSystems/RamFS/RamFileNode.class.h (limited to 'Source/Kernel/FileSystems') diff --git a/Source/Kernel/FileSystems/RamFS/RamDirNode.class.cpp b/Source/Kernel/FileSystems/RamFS/RamDirNode.class.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Source/Kernel/FileSystems/RamFS/RamDirNode.class.h b/Source/Kernel/FileSystems/RamFS/RamDirNode.class.h new file mode 100644 index 0000000..e69de29 diff --git a/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp b/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Source/Kernel/FileSystems/RamFS/RamFS.class.h b/Source/Kernel/FileSystems/RamFS/RamFS.class.h new file mode 100644 index 0000000..e69de29 diff --git a/Source/Kernel/FileSystems/RamFS/RamFileNode.class.cpp b/Source/Kernel/FileSystems/RamFS/RamFileNode.class.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Source/Kernel/FileSystems/RamFS/RamFileNode.class.h b/Source/Kernel/FileSystems/RamFS/RamFileNode.class.h new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 0b760a50b5aee05f1f34c1599b547c8b78d1d737 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 13 Sep 2009 15:14:13 +0200 Subject: Ram file system seems to work \o/ --- .../Kernel/FileSystems/RamFS/RamDirNode.class.cpp | 0 Source/Kernel/FileSystems/RamFS/RamDirNode.class.h | 0 Source/Kernel/FileSystems/RamFS/RamFS.class.cpp | 86 ++++++++++++++++++++++ Source/Kernel/FileSystems/RamFS/RamFS.class.h | 30 ++++++++ .../Kernel/FileSystems/RamFS/RamFileNode.class.cpp | 0 .../Kernel/FileSystems/RamFS/RamFileNode.class.h | 19 +++++ 6 files changed, 135 insertions(+) delete mode 100644 Source/Kernel/FileSystems/RamFS/RamDirNode.class.cpp delete mode 100644 Source/Kernel/FileSystems/RamFS/RamDirNode.class.h delete mode 100644 Source/Kernel/FileSystems/RamFS/RamFileNode.class.cpp (limited to 'Source/Kernel/FileSystems') 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 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 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 +#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 + +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 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 + +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 -- cgit v1.2.3 From ace1914398633e05970f634ddec297665dfda7c6 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 13 Sep 2009 15:36:39 +0200 Subject: RamFS creatable but not loadable yet --- Source/Kernel/FileSystems/RamFS/RamFS.class.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Kernel/FileSystems') diff --git a/Source/Kernel/FileSystems/RamFS/RamFS.class.h b/Source/Kernel/FileSystems/RamFS/RamFS.class.h index 427019c..822dc39 100644 --- a/Source/Kernel/FileSystems/RamFS/RamFS.class.h +++ b/Source/Kernel/FileSystems/RamFS/RamFS.class.h @@ -10,7 +10,7 @@ class RamFS : public FileSystem { 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 + RamFS(u8int* ptr, u32int maxSize, bool writable = true); //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); -- cgit v1.2.3 From 708765621ede3541037fb822cc032b9feb2ea43e Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 13 Sep 2009 16:46:15 +0200 Subject: Kernel can now load an Initrd. --- Source/Kernel/FileSystems/RamFS/RamFS.class.cpp | 55 +++++++++++++++++++++++++ Source/Kernel/FileSystems/RamFS/RamFS.class.h | 12 ++++++ 2 files changed, 67 insertions(+) (limited to 'Source/Kernel/FileSystems') diff --git a/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp b/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp index c8ed27c..f5a502f 100644 --- a/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp +++ b/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp @@ -9,6 +9,61 @@ RamFS::RamFS(u32int maxSize) { m_rootNode = new DirectoryNode("/", this, NULL); } +RamFS::RamFS(u8int *ptr, u32int maxSize, bool writable) { + m_maxSize = maxSize; + m_usedSize = 0; + m_isWritable = true; + m_rootNode = new DirectoryNode("/", this, NULL); + + union { + u8int* c; + initrd_header* i; + initrd_file_header* f; + } curr; + curr.c = ptr; + + if (curr.i->magic != INITRD_MAGIC) return; + u32int files = curr.i->files; + curr.i++; //Increment pointer of size of initrd header + DEBUG_HEX(files); DEBUG(" is initrd file count."); + for (u32int i = 0; i < files; i++) { + initrd_file_header h = *(curr.f); + curr.f++; //Increment pointer of size of file header + if (h.name_length != 0 or h.file_length != 0) { + String name((const char*)(curr.c)); + curr.c += h.name_length + 1; //Increment pointer of length of name + + //Find out a vector conaining parent directories, and set name to the effective file name + if (name[0] == WChar("/")) name = name.substr(1, name.size() - 1); + + //Find node for parent directory + String mname = ""; + DirectoryNode* parent = m_rootNode; + for (u32int i = 0; i < name.size(); i++) { + if (name[i] == WChar("/")) { + FSNode* n = parent->getChild(mname); + if (n == NULL) break; + if (n->type() != NT_DIRECTORY) break; + parent = (DirectoryNode*)n; + mname.clear(); + } else { + mname += name[i]; + } + } + name = mname; + + //Add new node + if (h.file_length == 0) { + parent->createDirectory(name); + } else { + FileNode* file = parent->createFile(name); + file->write(0, h.file_length, curr.c); + curr.c += h.file_length; + } + } + } +} + 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; } diff --git a/Source/Kernel/FileSystems/RamFS/RamFS.class.h b/Source/Kernel/FileSystems/RamFS/RamFS.class.h index 822dc39..034a948 100644 --- a/Source/Kernel/FileSystems/RamFS/RamFS.class.h +++ b/Source/Kernel/FileSystems/RamFS/RamFS.class.h @@ -3,6 +3,18 @@ #include +struct initrd_header { + unsigned int magic; + unsigned int files; +}; + +struct initrd_file_header { + unsigned int name_length; + unsigned int file_length; +}; + +#define INITRD_MAGIC 0x1337BEEF + class RamFS : public FileSystem { private: u32int m_maxSize; -- cgit v1.2.3 From 668bbfdaea7e8cba8233ebffe2a9d46a66e257cd Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 13 Sep 2009 18:27:42 +0200 Subject: We now can navigate in the VFS using the integrated shell. --- Source/Kernel/FileSystems/RamFS/RamFS.class.cpp | 2 ++ Source/Kernel/FileSystems/RamFS/RamFS.class.h | 1 + Source/Kernel/FileSystems/RamFS/RamFileNode.class.h | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) (limited to 'Source/Kernel/FileSystems') diff --git a/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp b/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp index f5a502f..7e29e08 100644 --- a/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp +++ b/Source/Kernel/FileSystems/RamFS/RamFS.class.cpp @@ -139,3 +139,5 @@ DirectoryNode* RamFS::createDirectory(DirectoryNode* parent, String name) { return d; } + +bool RamFS::remove(DirectoryNode* parent, FSNode* node) { return true; } diff --git a/Source/Kernel/FileSystems/RamFS/RamFS.class.h b/Source/Kernel/FileSystems/RamFS/RamFS.class.h index 034a948..0a3f0c4 100644 --- a/Source/Kernel/FileSystems/RamFS/RamFS.class.h +++ b/Source/Kernel/FileSystems/RamFS/RamFS.class.h @@ -37,6 +37,7 @@ class RamFS : public FileSystem { bool loadContents(DirectoryNode* dir); FileNode* createFile(DirectoryNode* parent, String name); DirectoryNode* createDirectory(DirectoryNode* parent, String name); + bool remove(DirectoryNode* parent, FSNode* node); }; #endif diff --git a/Source/Kernel/FileSystems/RamFS/RamFileNode.class.h b/Source/Kernel/FileSystems/RamFS/RamFileNode.class.h index 142d763..d600630 100644 --- a/Source/Kernel/FileSystems/RamFS/RamFileNode.class.h +++ b/Source/Kernel/FileSystems/RamFS/RamFileNode.class.h @@ -11,7 +11,7 @@ class RamFileNode : public FileNode { u32int uid = 0, u32int gid = 0) : FileNode(name, fs, parent, 0, permissions, uid, gid), m_data(0) {} - u8int *m_data; + u8int *m_data; //We don't take care of allocation/freeing here, RamFS:: does that for us void setLength(u32int length) { m_length = length; } }; -- cgit v1.2.3