summaryrefslogtreecommitdiff
path: root/Source/Kernel/FileSystems
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-09-13 16:46:15 +0200
committerAlexis211 <alexis211@gmail.com>2009-09-13 16:46:15 +0200
commit708765621ede3541037fb822cc032b9feb2ea43e (patch)
tree12e0e6c936fba8092479baf31d2ac4dc4ea9ed0f /Source/Kernel/FileSystems
parentace1914398633e05970f634ddec297665dfda7c6 (diff)
downloadMelon-708765621ede3541037fb822cc032b9feb2ea43e.tar.gz
Melon-708765621ede3541037fb822cc032b9feb2ea43e.zip
Kernel can now load an Initrd.
Diffstat (limited to 'Source/Kernel/FileSystems')
-rw-r--r--Source/Kernel/FileSystems/RamFS/RamFS.class.cpp55
-rw-r--r--Source/Kernel/FileSystems/RamFS/RamFS.class.h12
2 files changed, 67 insertions, 0 deletions
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 <VFS/FileSystem.proto.h>
+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;