diff options
author | Alexis211 <alexis211@gmail.com> | 2009-09-13 16:46:15 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-09-13 16:46:15 +0200 |
commit | 708765621ede3541037fb822cc032b9feb2ea43e (patch) | |
tree | 12e0e6c936fba8092479baf31d2ac4dc4ea9ed0f /Source/Kernel | |
parent | ace1914398633e05970f634ddec297665dfda7c6 (diff) | |
download | Melon-708765621ede3541037fb822cc032b9feb2ea43e.tar.gz Melon-708765621ede3541037fb822cc032b9feb2ea43e.zip |
Kernel can now load an Initrd.
Diffstat (limited to 'Source/Kernel')
-rw-r--r-- | Source/Kernel/Core/kmain.wtf.cpp | 12 | ||||
-rw-r--r-- | Source/Kernel/FileSystems/RamFS/RamFS.class.cpp | 55 | ||||
-rw-r--r-- | Source/Kernel/FileSystems/RamFS/RamFS.class.h | 12 | ||||
-rw-r--r-- | Source/Kernel/Library/Vector.class.cpp | 9 | ||||
-rwxr-xr-x | Source/Kernel/Melon.ke | bin | 127392 -> 131870 bytes | |||
-rw-r--r-- | Source/Kernel/Ressources/Welcome.txt | 1 |
6 files changed, 82 insertions, 7 deletions
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp index 19888c9..6806411 100644 --- a/Source/Kernel/Core/kmain.wtf.cpp +++ b/Source/Kernel/Core/kmain.wtf.cpp @@ -110,14 +110,14 @@ void kmain(multiboot_info_t* mbd, u32int magic) { PROCESSING(kvt, "Detecting floppy drives..."); FloppyController::detect(); OK(kvt); - asm volatile("sti"); - - FileSystem* fs = new RamFS(1024 * 1024); + FileSystem* fs = new RamFS((u8int*)mods[0].mod_start, 1024 * 1024); DirectoryNode* rd; rd = fs->getRootNode(); - FileNode* f; + /*FileNode* f; f = rd->createFile(String("test")); - f->write(0, 4, (u8int*)"plop"); + f->write(0, 4, (u8int*)"plop"); */ + + asm volatile("sti"); while(1) { kvt->setColor(0); @@ -146,7 +146,7 @@ void kmain(multiboot_info_t* mbd, u32int magic) { Mem::kfree(d); *kvt << "\n"; } else if (n->type() == NT_DIRECTORY) { - *kvt << "Found directory " << n->getName() << " :\n"; + *kvt << "Found directory " << n->getName() << ", " << (s32int)n->getLength() << " items.\n"; } } } else if (tmp == "reboot") { 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; diff --git a/Source/Kernel/Library/Vector.class.cpp b/Source/Kernel/Library/Vector.class.cpp index d0c71a4..91196b8 100644 --- a/Source/Kernel/Library/Vector.class.cpp +++ b/Source/Kernel/Library/Vector.class.cpp @@ -2,18 +2,22 @@ using namespace CMem; //strlen and memcpy template <typename T> Vector<T>::Vector() { + //DEBUG_HEX((u32int)this); DEBUG(" NEW EMPTY"); + //DEBUG_HEX(sizeof(T)); DEBUG(" sizeof(T)"); m_data = 0; m_size = 0; } template <typename T> Vector<T>::Vector(u32int size) { + //DEBUG_HEX((u32int)this); DEBUG(" NEW ZERO"); m_data = new T[size]; m_size = size; } template <typename T> Vector<T>::Vector(u32int size, T value) { + //DEBUG_HEX((u32int)this); DEBUG(" NEW FILLED"); //m_data = (T*)Mem::kalloc(size * sizeof(T)); m_data = new T[size](value); m_size = size; @@ -24,6 +28,7 @@ Vector<T>::Vector(u32int size, T value) { template <typename T> Vector<T>::Vector(const Vector<T> &other) { + //DEBUG_HEX((u32int)this); DEBUG(" COPY REF"); m_size = other.m_size; m_data = (T*)Mem::kalloc(m_size * sizeof(T)); for (u32int i = 0; i < m_size; i++) { @@ -33,6 +38,7 @@ Vector<T>::Vector(const Vector<T> &other) { template <typename T> Vector<T>& Vector<T>::operator= (const Vector<T> &other) { + //DEBUG_HEX((u32int)this); DEBUG(" COPY EQ"); if (m_data != 0) delete[] m_data; m_size = other.m_size; m_data = (T*)Mem::kalloc(m_size * sizeof(T)); @@ -43,6 +49,7 @@ Vector<T>& Vector<T>::operator= (const Vector<T> &other) { template <typename T> Vector<T>::~Vector() { + //DEBUG_HEX((u32int)this); DEBUG(" DELETE"); if (m_data != 0) delete[] m_data; } @@ -107,7 +114,7 @@ bool Vector<T>::empty() { template <typename T> void Vector<T>::clear() { if (empty()) return; - Mem::kfree(m_data); + delete [] m_data; m_data = 0; m_size = 0; } diff --git a/Source/Kernel/Melon.ke b/Source/Kernel/Melon.ke Binary files differindex 89d3f81..c9d56ba 100755 --- a/Source/Kernel/Melon.ke +++ b/Source/Kernel/Melon.ke diff --git a/Source/Kernel/Ressources/Welcome.txt b/Source/Kernel/Ressources/Welcome.txt new file mode 100644 index 0000000..97d6755 --- /dev/null +++ b/Source/Kernel/Ressources/Welcome.txt @@ -0,0 +1 @@ +Hi, this is a file located on an InitRD ! éàç... |