diff --git a/sortix/Makefile b/sortix/Makefile
index 8a472b1d..77a23bea 100644
--- a/sortix/Makefile
+++ b/sortix/Makefile
@@ -44,7 +44,7 @@ DEFINES:=$(DEFINES) -DINITRD
CPPFLAGSRELEASE=-s -O3
CPPFLAGSDEBUG=
CPPFLAGS=-I.. -I. $(CPUDEFINES) $(CPUFLAGS) -std=gnu++0x -Wall -Wextra -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector $(DEFINES) $(CPPFLAGSRELEASE)
-OBJS=$(CPUOBJS) kernel.o descriptor_tables.o isr.o time.o log.o iprintable.o panic.o keyboard.o memorymanagement.o scheduler.o syscall.o application.o pong.o sound.o pci.o uart.o conway.o test.o http.o vgaterminal.o serialterminal.o descriptors.o device.o vga.o elf.o process.o ../libmaxsi/libmaxsi-sortix.a
+OBJS=$(CPUOBJS) kernel.o descriptor_tables.o isr.o time.o log.o iprintable.o panic.o keyboard.o memorymanagement.o scheduler.o syscall.o application.o pong.o sound.o pci.o uart.o conway.o test.o http.o vgaterminal.o serialterminal.o descriptors.o device.o vga.o elf.o process.o initrd.o ../libmaxsi/libmaxsi-sortix.a
JSOBJS:=$(subst .o,-js.o,$(OBJS))
all: sortix.bin
diff --git a/sortix/initrd.cpp b/sortix/initrd.cpp
new file mode 100644
index 00000000..25f3f916
--- /dev/null
+++ b/sortix/initrd.cpp
@@ -0,0 +1,69 @@
+/******************************************************************************
+
+ COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
+
+ This file is part of Sortix.
+
+ Sortix is free software: you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation, either version 3 of the License, or (at your option) any later
+ version.
+
+ Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details.
+
+ You should have received a copy of the GNU General Public License along
+ with Sortix. If not, see .
+
+ initrd.cpp
+ Declares the structure of the Sortix ramdisk.
+
+******************************************************************************/
+
+#include "platform.h"
+#include "initrd.h"
+#include
+
+#include "log.h" // DEBUG
+
+using namespace Maxsi;
+
+namespace Sortix
+{
+ namespace InitRD
+ {
+ byte* initrd;
+ size_t initrdsize;
+
+ void Init(byte* theinitrd, size_t size)
+ {
+ initrd = theinitrd;
+ initrdsize = size;
+ if ( size < sizeof(Header) ) { PanicF("initrd.cpp: initrd is too small"); }
+ Header* header = (Header*) initrd;
+ if ( String::Compare(header->magic, "sortix-initrd-1") != 0 ) { PanicF("initrd.cpp: invalid magic value in the initrd"); }
+ size_t sizeneeded = sizeof(Header) + header->numfiles * sizeof(FileHeader);
+ if ( size < sizeneeded ) { PanicF("initrd.cpp: initrd is too small"); }
+ // TODO: We need to do more validation here!
+ }
+
+ byte* Open(const char* filepath, size_t* size)
+ {
+ Header* header = (Header*) initrd;
+ FileHeader* fhtbl = (FileHeader*) (initrd + sizeof(Header));
+ for ( uint32_t i = 0; i < header->numfiles; i++ )
+ {
+ FileHeader* fileheader = &(fhtbl[i]);
+
+ if ( String::Compare(filepath, fileheader->name) != 0 ) { continue; }
+
+ *size = fileheader->size;
+ return initrd + fileheader->offset;
+ }
+
+ return NULL;
+ }
+ }
+}
diff --git a/sortix/initrd.h b/sortix/initrd.h
index 39171156..5a826a9a 100644
--- a/sortix/initrd.h
+++ b/sortix/initrd.h
@@ -48,6 +48,11 @@ namespace Sortix
uint32_t offset; // where the physical data is located.
char name[128];
};
+
+#ifdef SORTIX_KERNEL
+ void Init(byte* initrd, size_t size);
+ byte* Open(const char* filepath, size_t* size);
+#endif
}
}