Added a driver to parse the Sortix init ramdisk.

This commit is contained in:
Jonas 'Sortie' Termansen 2011-08-27 17:41:35 +02:00
parent fa7834b5d6
commit d9c0c8d0cd
3 changed files with 75 additions and 1 deletions

View File

@ -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

69
sortix/initrd.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
initrd.cpp
Declares the structure of the Sortix ramdisk.
******************************************************************************/
#include "platform.h"
#include "initrd.h"
#include <libmaxsi/string.h>
#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;
}
}
}

View File

@ -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
}
}