aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apps/init/main.c39
-rw-r--r--src/common/libalgo/btree.c2
-rw-r--r--src/kernel/core/idt.c2
-rw-r--r--src/kernel/core/kmain.c4
-rw-r--r--src/kernel/include/sct.h (renamed from src/kernel/include/syscall.h)2
-rw-r--r--src/kernel/user/nullfs.c58
-rw-r--r--src/kernel/user/syscall.c4
7 files changed, 66 insertions, 45 deletions
diff --git a/src/apps/init/main.c b/src/apps/init/main.c
index 02fd9df..af69e78 100644
--- a/src/apps/init/main.c
+++ b/src/apps/init/main.c
@@ -11,26 +11,28 @@ int main(int argc, char **argv) {
dbg_print_region_info();
- dbg_printf("Doing malloc test...\n");
- const int m = 200;
- uint16_t** ptr = malloc(m * sizeof(uint32_t));
- for (int i = 0; i < m; i++) {
- size_t s = 1 << ((i * 7) % 11 + 2);
- ptr[i] = (uint16_t*)malloc(s);
- ASSERT((size_t)ptr[i] >= 0x40000000 && (size_t)ptr[i] < 0xB0000000);
- *ptr[i] = ((i * 211) % 1024);
- }
- dbg_printf("Fully allocated.\n");
- dbg_print_region_info();
- for (int i = 0; i < m; i++) {
- for (int j = i; j < m; j++) {
- ASSERT(*ptr[j] == (j * 211) % 1024);
+ for (int iter = 0; iter < 4; iter++) {
+ dbg_printf("Doing malloc test #%d...\n", iter + 1);
+ const int m = 200;
+ uint16_t** ptr = malloc(m * sizeof(uint32_t));
+ for (int i = 0; i < m; i++) {
+ size_t s = 1 << ((i * 7) % 11 + 2);
+ ptr[i] = (uint16_t*)malloc(s);
+ ASSERT((size_t)ptr[i] >= 0x40000000 && (size_t)ptr[i] < 0xB0000000);
+ *ptr[i] = ((i * 211) % 1024);
}
- free(ptr[i]);
+ dbg_printf("Fully allocated.\n");
+ dbg_print_region_info();
+ for (int i = 0; i < m; i++) {
+ for (int j = i; j < m; j++) {
+ ASSERT(*ptr[j] == (j * 211) % 1024);
+ }
+ free(ptr[i]);
+ }
+ free(ptr);
+ dbg_printf("malloc test OK.\n");
+ dbg_print_region_info();
}
- free(ptr);
- dbg_printf("malloc test OK.\n");
- dbg_print_region_info();
fd_t f = open("dev:/", FM_READDIR);
dbg_printf("openned /: %d\n", f);
@@ -46,6 +48,7 @@ int main(int argc, char **argv) {
if (ff != 0) {
dbg_printf("ok, open as %d\n", ff);
char* cont = malloc(x.st.size + 1);
+ dbg_print_region_info();
read(ff, 0, x.st.size, cont);
cont[x.st.size] = 0;
dbg_printf(" %s\n", cont);
diff --git a/src/common/libalgo/btree.c b/src/common/libalgo/btree.c
index d3a030a..9ea4a15 100644
--- a/src/common/libalgo/btree.c
+++ b/src/common/libalgo/btree.c
@@ -216,7 +216,7 @@ void btree_remove_v(btree_t *t, const void* key, const void* val) {
} else if (c > 0) {
i->right = remove_aux(t, i->right, key, val);
return equilibrate(i);
- } else if (i->val == i) {
+ } else if (i->val == val) {
// remove item i
btree_item_t *new_i;
diff --git a/src/kernel/core/idt.c b/src/kernel/core/idt.c
index 0459a21..abab3cc 100644
--- a/src/kernel/core/idt.c
+++ b/src/kernel/core/idt.c
@@ -4,7 +4,7 @@
#include <string.h>
#include <dbglog.h>
#include <thread.h>
-#include <syscall.h>
+#include <sct.h>
struct idt_entry {
uint16_t base_lo; //Low part of address to jump to
diff --git a/src/kernel/core/kmain.c b/src/kernel/core/kmain.c
index 9b9a050..73f7610 100644
--- a/src/kernel/core/kmain.c
+++ b/src/kernel/core/kmain.c
@@ -17,7 +17,7 @@
#include <nullfs.h>
#include <process.h>
#include <elf.h>
-#include <syscall.h>
+#include <sct.h>
#include <slab_alloc.h>
#include <string.h>
@@ -102,7 +102,7 @@ void kmain(multiboot_info_t *mbd, int32_t mb_magic) {
dbg_printf("Kernel malloc setup ok.\n");
TEST_PLACEHOLDER_AFTER_KMALLOC;
- setup_syscalls();
+ setup_syscall_table();
dbg_printf("System calls setup ok.\n");
// enter multi-threading mode
diff --git a/src/kernel/include/syscall.h b/src/kernel/include/sct.h
index 045205f..2d6acd5 100644
--- a/src/kernel/include/syscall.h
+++ b/src/kernel/include/sct.h
@@ -3,7 +3,7 @@
#include <idt.h>
#include <syscallproto.h>
-void setup_syscalls();
+void setup_syscall_table();
void syscall_handler(registers_t *regs);
diff --git a/src/kernel/user/nullfs.c b/src/kernel/user/nullfs.c
index 3065192..50baeff 100644
--- a/src/kernel/user/nullfs.c
+++ b/src/kernel/user/nullfs.c
@@ -102,14 +102,15 @@ typedef struct {
nullfs_item_t *items_list;
hashtbl_t *items_idx;
- mutex_t lock; // always locked when open (cannot create/delete/move)
+ mutex_t lock;
nullfs_t *fs;
} nullfs_dir_t;
typedef struct {
- nullfs_item_t *it;
nullfs_dir_t *d;
+ int nitems, i;
+ dirent_t *items;
} nullfs_dh_t;
typedef struct {
@@ -118,7 +119,7 @@ typedef struct {
bool own_data;
int ok_modes;
- mutex_t lock;
+ mutex_t lock; // locked on open
} nullfs_file_t;
// No nullfs_file_handle_t struct, we don't need it. The handle's data
@@ -241,19 +242,45 @@ bool nullfs_d_open(fs_node_ptr n, int mode, fs_handle_t *s) {
if (!got_lock) return false;
nullfs_dh_t *h = (nullfs_dh_t*)malloc(sizeof(nullfs_dh_t));
- if (h == 0) {
- mutex_unlock(&d->lock);
- return false;
+ if (h == 0) goto fail;
+
+ h->nitems = hashtbl_count(d->items_idx);
+ if (h->nitems > 0) {
+ h->items = (dirent_t*)malloc(h->nitems * sizeof(dirent_t));
+ if (h->nitems == 0) goto fail;
+
+ int i = 0;
+ for (nullfs_item_t *it = d->items_list; it != 0; it = it->next) {
+ strncpy(h->items[i].name, it->name, DIR_MAX);
+ h->items[i].name[DIR_MAX-1] = 0; // make sur it's null-terminated
+ if (it->ops->stat) {
+ it->ops->stat(it->data, &h->items[i].st);
+ } else {
+ // no stat operation : should we do something else ?
+ memset(&h->items[i].st, 0, sizeof(stat_t));
+ }
+
+ i++;
+ }
+ ASSERT(i == h->nitems);
}
- h->it = d->items_list;
h->d = d;
+ h->i = 0;
s->data = h;
s->ops = &nullfs_dh_ops;
s->mode = FM_READDIR;
+ mutex_unlock(&d->lock);
+
return true;
+
+fail:
+ mutex_unlock(&d->lock);
+ if (h && h->items) free(h->items);
+ if (h) free(h);
+ return false;
}
bool nullfs_d_stat(fs_node_ptr n, stat_t *st) {
@@ -445,19 +472,11 @@ void nullfs_d_dispose(fs_node_ptr n) {
bool nullfs_dh_readdir(fs_handle_ptr f, dirent_t *d) {
nullfs_dh_t *h = (nullfs_dh_t*)f;
- if (h->it == 0) {
+ if (h->i >= h->nitems) {
return false;
} else {
- strncpy(d->name, h->it->name, DIR_MAX);
- d->name[DIR_MAX-1] = 0; // make sur it's null-terminated
- if (h->it->ops->stat) {
- h->it->ops->stat(h->it->data, &d->st);
- } else {
- // no stat operation : should we do something else ?
- memset(&d->st, 0, sizeof(stat_t));
- }
- h->it = h->it->next;
-
+ memcpy(d, &h->items[h->i], sizeof(dirent_t));
+ h->i++;
return true;
}
}
@@ -465,8 +484,7 @@ bool nullfs_dh_readdir(fs_handle_ptr f, dirent_t *d) {
void nullfs_dh_close(fs_handle_ptr f) {
nullfs_dh_t *h = (nullfs_dh_t*)f;
- mutex_unlock(&h->d->lock);
-
+ if (h->items) free(h->items);
free(h);
}
diff --git a/src/kernel/user/syscall.c b/src/kernel/user/syscall.c
index eee65d6..8a2cf18 100644
--- a/src/kernel/user/syscall.c
+++ b/src/kernel/user/syscall.c
@@ -2,7 +2,7 @@
#include <process.h>
#include <vfs.h>
-#include <syscall.h>
+#include <sct.h>
typedef struct {
uint32_t sc_id, a, b, c, d, e; // a: ebx, b: ecx, c: edx, d: esi, e: edi
@@ -274,7 +274,7 @@ static uint32_t get_mode_sc(sc_args_t args) {
// SYSCALLS SETUP ROUTINE //
// ====================== //
-void setup_syscalls() {
+void setup_syscall_table() {
sc_handlers[SC_EXIT] = exit_sc;
sc_handlers[SC_YIELD] = yield_sc;
sc_handlers[SC_DBG_PRINT] = dbg_print_sc;