summaryrefslogtreecommitdiff
path: root/src/init
diff options
context:
space:
mode:
authordzwdz2022-07-08 14:40:44 +0200
committerdzwdz2022-07-08 14:40:44 +0200
commit1f7e7501660123ff8f26e8c65e75c2b282b933ef (patch)
tree5ba6cee10ac656b20dcabc9c9f7b079dcd952a45 /src/init
parente567ebeee5ea196128f15adcf30cec5dd1137f90 (diff)
syscall/fs_respond: get the file id from the buf argument
Previously, file ids could only be positive integers, so their range was 31 bits - not enough to represent the entire memory. Now, pointers can be safely used as file ids.
Diffstat (limited to 'src/init')
-rw-r--r--src/init/driver/ansiterm.c2
-rw-r--r--src/init/driver/tmpfs.c21
-rw-r--r--src/init/fs/misc.c14
-rw-r--r--src/init/syscalls.c2
-rw-r--r--src/init/tar.c19
5 files changed, 29 insertions, 29 deletions
diff --git a/src/init/driver/ansiterm.c b/src/init/driver/ansiterm.c
index 4d98972..b7f0b04 100644
--- a/src/init/driver/ansiterm.c
+++ b/src/init/driver/ansiterm.c
@@ -83,7 +83,7 @@ void ansiterm_drv(void) {
break;
}
// TODO check path
- _syscall_fs_respond(NULL, 1, 0);
+ _syscall_fs_respond(NULL, 0, 0);
break;
case VFSOP_WRITE:
diff --git a/src/init/driver/tmpfs.c b/src/init/driver/tmpfs.c
index 4b639da..bbed095 100644
--- a/src/init/driver/tmpfs.c
+++ b/src/init/driver/tmpfs.c
@@ -10,6 +10,7 @@ struct node {
};
struct node *root = NULL;
+static struct node special_root;
static struct node *lookup(const char *path, size_t len) {
for (struct node *iter = root; iter; iter = iter->next) {
@@ -19,18 +20,18 @@ static struct node *lookup(const char *path, size_t len) {
return NULL;
}
-static int tmpfs_open(const char *path, struct fs_wait_response *res) {
- if (res->len == 0) return -1;
+static struct node *tmpfs_open(const char *path, struct fs_wait_response *res) {
+ if (res->len == 0) return NULL;
path++;
res->len--;
- if (res->len == 0) return 0; /* root */
+ if (res->len == 0) return &special_root;
// no directory support (yet)
- if (memchr(path, '/', res->len)) return -1;
+ if (memchr(path, '/', res->len)) return NULL;
if (res->flags & OPEN_CREATE) {
- if (lookup(path, res->len)) return -1; /* already exists */
+ if (lookup(path, res->len)) return NULL; /* already exists */
struct node *new = malloc(sizeof *new);
char *namebuf = malloc(res->len);
memcpy(namebuf, path, res->len);
@@ -38,24 +39,26 @@ static int tmpfs_open(const char *path, struct fs_wait_response *res) {
new->len = res->len;
new->next = root;
root = new;
- return 1;
+ return new;
}
- return lookup(path, res->len) != 0 ? 1 : -1;
+ return lookup(path, res->len);
}
void tmpfs_drv(void) {
// TODO replace all the static allocations in drivers with mallocs
static char buf[512];
struct fs_wait_response res;
+ struct node *ptr;
while (!_syscall_fs_wait(buf, sizeof buf, &res)) {
switch (res.op) {
case VFSOP_OPEN:
- _syscall_fs_respond(NULL, tmpfs_open(buf, &res), 0);
+ ptr = tmpfs_open(buf, &res);
+ _syscall_fs_respond(ptr, ptr ? 0 : -1, 0);
break;
case VFSOP_READ:
- if (res.id != 0) {
+ if (res.id != &special_root) {
// rw unimplemented
_syscall_fs_respond(NULL, -1, 0);
break;
diff --git a/src/init/fs/misc.c b/src/init/fs/misc.c
index b394c26..701db9f 100644
--- a/src/init/fs/misc.c
+++ b/src/init/fs/misc.c
@@ -188,7 +188,7 @@ void fs_dir_inject(const char *path) {
/* if we're making up the opened directory, disallow create */
if (ret < 0 && (res.flags & OPEN_CREATE)) hid = ret;
- _syscall_fs_respond(NULL, hid, 0);
+ _syscall_fs_respond((void*)hid, hid, 0);
} else {
/* not injecting, don't allow opening nonexistent stuff */
@@ -198,16 +198,16 @@ void fs_dir_inject(const char *path) {
break;
case VFSOP_CLOSE:
- if (handles[res.id].delegate >= 0)
- _syscall_close(handles[res.id].delegate);
- handles[res.id].taken = false;
+ if (handles[(int)res.id].delegate >= 0)
+ _syscall_close(handles[(int)res.id].delegate);
+ handles[(int)res.id].taken = false;
_syscall_fs_respond(NULL, 0, 0);
break;
case VFSOP_READ:
- if (handles[res.id].inject) {
+ if (handles[(int)res.id].inject) {
if (res.offset > 0) _syscall_fs_respond(NULL, 0, 0); // TODO working offsets
- struct fs_dir_handle h = handles[res.id];
+ struct fs_dir_handle h = handles[(int)res.id];
int out_len = 0;
while (h.inject[out_len] && h.inject[out_len] != '/')
@@ -232,7 +232,7 @@ void fs_dir_inject(const char *path) {
/* fallthrough */
default: {
- struct fs_dir_handle h = handles[res.id];
+ struct fs_dir_handle h = handles[(int)res.id];
if (h.delegate < 0)
_syscall_fs_respond(NULL, -1, 0);
else
diff --git a/src/init/syscalls.c b/src/init/syscalls.c
index f7e540f..14c0d52 100644
--- a/src/init/syscalls.c
+++ b/src/init/syscalls.c
@@ -42,7 +42,7 @@ int _syscall_fs_wait(char __user *buf, int max_len, struct fs_wait_response __us
return _syscall(_SYSCALL_FS_WAIT, (int)buf, max_len, (int)res, 0);
}
-int _syscall_fs_respond(char __user *buf, int ret, int flags) {
+int _syscall_fs_respond(void __user *buf, int ret, int flags) {
return _syscall(_SYSCALL_FS_RESPOND, (int)buf, ret, flags, 0);
}
diff --git a/src/init/tar.c b/src/init/tar.c
index dfb0396..87236ae 100644
--- a/src/init/tar.c
+++ b/src/init/tar.c
@@ -5,7 +5,7 @@
#define BUF_SIZE 64
-static int tar_open(const char *path, int len, void *base, size_t base_len);
+static void *tar_open(const char *path, int len, void *base, size_t base_len);
static void tar_read(struct fs_wait_response *res, void *base, size_t base_len);
static int tar_size(void *sector);
static void *tar_find(const char *path, size_t path_len, void *base, size_t base_len);
@@ -18,6 +18,7 @@ static const char *root_fakemeta = ""; /* see comment in tar_open */
void tar_driver(void *base) {
static char buf[BUF_SIZE];
struct fs_wait_response res;
+ void *ptr;
while (!_syscall_fs_wait(buf, BUF_SIZE, &res)) {
switch (res.op) {
case VFSOP_OPEN:
@@ -25,7 +26,8 @@ void tar_driver(void *base) {
_syscall_fs_respond(NULL, -1, 0);
break;
}
- _syscall_fs_respond(NULL, tar_open(buf, res.len, base, ~0), 0);
+ ptr = tar_open(buf, res.len, base, ~0);
+ _syscall_fs_respond(ptr, ptr ? 0 : -1, 0);
break;
case VFSOP_READ:
@@ -40,10 +42,8 @@ void tar_driver(void *base) {
_syscall_exit(0);
}
-static int tar_open(const char *path, int len, void *base, size_t base_len) {
- void *ptr;
-
- if (len <= 0) return -1;
+static void *tar_open(const char *path, int len, void *base, size_t base_len) {
+ if (len <= 0) return NULL;
path += 1; // skip the leading slash
len -= 1;
@@ -51,12 +51,9 @@ static int tar_open(const char *path, int len, void *base, size_t base_len) {
* returning a fake one. this isn't a full entry because i'm currently too
* lazy to create a full one - thus, it has to be special cased in tar_read */
if (len == 0)
- return (int)root_fakemeta;
+ return (void*)root_fakemeta;
- ptr = tar_find(path, len, base, base_len);
- if (!ptr) return -1;
- // TODO this won't work if ptr > 0x80000000
- return (int)ptr;
+ return tar_find(path, len, base, base_len);
}
static void tar_read(struct fs_wait_response *res, void *base, size_t base_len) {