Skip to content

Commit

Permalink
Added Gib functionality to userspace Gib.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkie committed Jan 19, 2010
1 parent c9c88a9 commit 83a1e5f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 9 deletions.
Binary file modified build/iso/boot/testapp
Binary file not shown.
3 changes: 2 additions & 1 deletion kernel/mem/gib.d
Expand Up @@ -11,7 +11,8 @@ import architecture.vm;

import kernel.core.kprintf;
import kernel.core.error;
import kernel.core.templates;

import user.templates;

struct Gib {

Expand Down
83 changes: 75 additions & 8 deletions libos/ramfs.d
@@ -1,37 +1,104 @@

module libos.ramfs;

import user.templates;

private import user.syscall;

struct Gib {

ubyte* ptr() {
return _ptr;
return _start;
}

ubyte* pos() {
return _curptr;
return _curpos;
}

void seek(long amount) {
_curpos += amount;
}

void rewind() {
_curpos = _start;
}

// Will read from the current position the data requested.
template read(T) {
uint read(out T buffer) {
size_t length;

static if (IsArray!(T)) {
length = buffer.length * ArrayType!(T).sizeof;
foreach(ref ArrayType!(T) b; buffer) {
ArrayType!(T)* ptr = cast(ArrayType!(T)*)_curpos;
b = *ptr;
_curpos += ArrayType!(T).sizeof;
}
}
else {
length = T.sizeof;
T* ptr = cast(T*)_curpos;
buffer = *ptr;
_curpos += length;
}

return length;
}
}

// Will write to the current position the data requested.
template write(T) {
uint write(T buffer) {
size_t length;

static if (IsArray!(T)) {
length = buffer.length * ArrayType!(T).sizeof;
foreach(ArrayType!(T) b; buffer) {
ArrayType!(T)* ptr = cast(ArrayType!(T)*)_curpos;
*ptr = b;
_curpos += ArrayType!(T).sizeof;
}
}
else {
length = T.sizeof;
T* ptr = cast(T*)_curpos;
*ptr = buffer;
_curpos += length;
}

return length;
}
}

ubyte opIndex(size_t i1) {
return _start[i1];
}

size_t opIndexAssign(ubyte value, size_t i1) {
_start[i1] = value;
return i1;
}

package:
ubyte* _ptr;
ubyte* _curptr;
ubyte* _start;
ubyte* _curpos;
}

class RamFS {
static:

Gib open(char[] name, uint flags) {
Gib ret;
ret._ptr = user.syscall.open(name, flags);
ret._curptr = ret._ptr;
ret._start = user.syscall.open(name, flags);
ret._curpos = ret._start;
return ret;
}

Gib create(char[] name, uint flags) {
Gib ret;
ret._ptr = user.syscall.create(name, flags);
ret._curptr = ret._ptr;
ret._start = user.syscall.create(name, flags);
ret._curpos = ret._start;
return ret;
}
}
Expand Down
File renamed without changes.

0 comments on commit 83a1e5f

Please sign in to comment.