[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tyndur-devel] [RFC PATCH 5/5] kernel2: LIOv2-Clientsyscalls implementiert
+ kernel2: Die bestehenden LIOv2-Stubs durch Funktionen ersetzt, die die
richtigen LIOv2-Funktionen aufrufen. Nach diesem Patch sind die
LIOv2-Funktionen zum ersten Mal tatsächlich nutzbar (in tmp:/).
Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
src/kernel2/src/syscalls/lostio.c | 228 ++++++++++++++++++++++++++++++++++---
1 files changed, 212 insertions(+), 16 deletions(-)
diff --git a/src/kernel2/src/syscalls/lostio.c b/src/kernel2/src/syscalls/lostio.c
index b7a3933..35e979b 100644
--- a/src/kernel2/src/syscalls/lostio.c
+++ b/src/kernel2/src/syscalls/lostio.c
@@ -41,72 +41,219 @@
#include "syscall.h"
#include <syscall_structs.h>
+#include "lostio/client.h"
+#include "../lostio/include/lostio_int.h" // FIXME
+
/// Ressource suchen
void syscall_lio_resource(const char* path, size_t path_len, int flags,
lio_usp_resource_t* res_id)
{
- *res_id = -1;
+ struct lio_resource* res;
+
+ // TODO: is_userspace
+ if (path[path_len - 1] != '\0') {
+ *res_id = -EINVAL;
+ return;
+ }
+
+ if (!(res = lio_get_resource(path, flags))) {
+ *res_id = -ENOENT;
+ return;
+ }
+
+ *res_id = lio_usp_get_id(res);
}
/// Informationen über eine Ressource abfragen
int syscall_lio_stat(lio_usp_resource_t* resid, struct lio_stat* sbuf)
{
- return -ENOSYS;
+ struct lio_resource* res;
+
+ // TODO: is_userspace
+ if (!(res = lio_usp_get_resource(*resid))) {
+ return -EINVAL;
+ }
+
+ // TODO: is_userspace
+ return lio_stat(res, sbuf);
}
/// Ressource öffnen
void syscall_lio_open(lio_usp_resource_t* resid, int flags,
lio_usp_stream_t* stream_id)
{
- *stream_id = -1;
+ struct lio_usp_stream* fd;
+ struct lio_stream* stream;
+ struct lio_resource* res;
+
+ // TODO: is_userspace
+ if (!(res = lio_usp_get_resource(*resid))) {
+ *stream_id = -EINVAL;
+ }
+ if (!(stream = lio_open(res, flags))) {
+ *stream_id = -EACCES;
+ return;
+ }
+
+ fd = lio_usp_add_stream(current_process, stream);
+ *stream_id = fd->usp_id;
}
/// Stream schließen
int syscall_lio_close(lio_usp_stream_t* stream_id)
{
- return -ENOSYS;
+ struct lio_usp_stream* fd;
+ struct lio_stream* stream;
+ int ret;
+
+ // TODO: is_userspace
+ if (!(fd= lio_usp_get_stream(current_process, *stream_id))) {
+ return -EBADF;
+ }
+
+ // lio_close gibt stream im Erfolgsfall frei, wir koennen es also nicht
+ // erst hinterher aus dem Baum entfernen. Falls close schiefgeht, muessen
+ // wir es wohl oder uebel wieder eintragen.
+ stream = fd->stream;
+ lio_usp_remove_stream(current_process, fd);
+ ret = lio_close(stream);
+ if (ret < 0) {
+ lio_usp_add_stream(current_process, stream);
+ }
+
+ return ret;
}
/// Aus Stream lesen
void syscall_lio_read(lio_usp_stream_t* stream_id, uint64_t* offset,
size_t bytes, void* buffer, int updatepos, ssize_t* result)
{
- *result = -1;
+ struct lio_usp_stream* fd;
+
+ // TODO: is_userspace
+ if (!(fd = lio_usp_get_stream(current_process, *stream_id))) {
+ *result = -EBADF;
+ return;
+ }
+
+ if (updatepos) {
+ *result = lio_read(fd->stream, bytes, buffer);
+ } else {
+ *result = lio_pread(fd->stream, *offset, bytes, buffer);
+ }
}
/// In Stream schreiben
void syscall_lio_write(lio_usp_stream_t* stream_id, uint64_t* offset,
size_t bytes, const void* buffer, int updatepos, ssize_t* result)
{
- *result = -1;
+ struct lio_usp_stream* fd;
+
+ // TODO: is_userspace
+ if (!(fd = lio_usp_get_stream(current_process, *stream_id))) {
+ *result = -EBADF;
+ return;
+ }
+
+ if (updatepos) {
+ *result = lio_write(fd->stream, bytes, buffer);
+ } else {
+ *result = lio_pwrite(fd->stream, *offset, bytes, buffer);
+ }
}
/// Cursorposition in der Datei ändern
void syscall_lio_seek(lio_usp_stream_t* stream_id, int64_t* offset,
int whence, int64_t* result)
{
- *result = -1;
+ struct lio_usp_stream* fd;
+
+ // TODO: Ein paar is_userspace
+ if (!(fd = lio_usp_get_stream(current_process, *stream_id))) {
+ *result = -EBADF;
+ return;
+ }
+
+ *result = lio_seek(fd->stream, *offset, whence);
}
/// Verzeichnisinhalt auslesen
void syscall_lio_read_dir(lio_usp_resource_t* resid, size_t start, size_t num,
struct lio_usp_dir_entry* buf, ssize_t* result)
{
- *result = -1;
+ // FIXME: Das d00f
+ struct lio_dir_entry* int_buf;
+ struct lio_resource* res;
+ ssize_t i;
+
+ if (!(res = lio_usp_get_resource(*resid))) {
+ *result = -EINVAL;
+ return;
+ }
+
+ int_buf = malloc(num * sizeof(*int_buf));
+ // TODO: is_userspace
+ *result = lio_read_dir(res, start, num, int_buf);
+
+ for (i = 0; i < *result; i++) {
+ buf[i].resource = lio_usp_get_id(int_buf[i].resource);
+ strcpy(buf[i].name, int_buf[i].name);
+ buf[i].stat = int_buf[i].stat;
+ }
+
+ free(int_buf);
}
/// Neue Datei anlegen
void syscall_lio_mkfile(lio_usp_resource_t* parent, const char* name,
size_t name_len, lio_usp_resource_t* result)
{
- *result = -1;
+ struct lio_resource* parentres;
+ struct lio_resource* res;
+
+ if (!(parentres = lio_usp_get_resource(*parent))) {
+ *result = -EINVAL;
+ return;
+ }
+
+ // TODO: is_userspace
+ if (name[name_len - 1] != '\0') {
+ *result = -EINVAL;
+ return;
+ }
+
+ // TODO: is_userspace
+ if (!(res = lio_mkfile(parentres, name))) {
+ *result = -EIO; // FIXME
+ return;
+ }
+ *result = lio_usp_get_id(res);
}
/// Neues Verzeichnis anlegen
void syscall_lio_mkdir(lio_usp_resource_t* parent, const char* name,
size_t name_len, lio_usp_resource_t* result)
{
- *result = -1;
+ struct lio_resource* parentres;
+ struct lio_resource* res;
+
+ if (!(parentres = lio_usp_get_resource(*parent))) {
+ *result = -EINVAL;
+ return;
+ }
+
+ // TODO: is_userspace
+ if (name[name_len - 1] != '\0') {
+ *result = -EINVAL;
+ return;
+ }
+
+ // TODO: is_userspace
+ if (!(res = lio_mkdir(parentres, name))) {
+ *result = -EIO; // FIXME
+ return;
+ }
+ *result = lio_usp_get_id(res);
}
/// Neuen Symlink anlegen
@@ -114,31 +261,80 @@ void syscall_lio_mksymlink(lio_usp_resource_t* parent, const char* name,
size_t name_len, const char* target, size_t target_len,
lio_usp_resource_t* result)
{
- *result = -1;
+ struct lio_resource* parentres;
+ struct lio_resource* res;
+
+ if (!(parentres = lio_usp_get_resource(*parent))) {
+ *result = -EINVAL;
+ return;
+ }
+
+ // TODO: is_userspace
+ if (name[name_len - 1] != '\0') {
+ *result = -EINVAL;
+ return;
+ }
+
+ // TODO: is_userspace
+ if (target[target_len - 1] != '\0') {
+ *result = -EINVAL;
+ return;
+ }
+
+ if (!(res = lio_mksymlink(parentres, name, target))) {
+ *result = -EIO; // FIXME
+ return;
+ }
+ *result = lio_usp_get_id(res);
}
/// Veränderte Blocks schreiben
int syscall_lio_sync(lio_usp_stream_t* stream_id)
{
- return -ENOSYS;
+ struct lio_usp_stream* fd;
+
+ // TODO: is_userspace
+ if (!(fd = lio_usp_get_stream(current_process, *stream_id))) {
+ return -EBADF;
+ }
+
+ return lio_sync(fd->stream);
}
/// Dateigröße ändern
int syscall_lio_truncate(lio_usp_stream_t* stream_id, uint64_t* size)
{
- return -ENOSYS;
+ struct lio_usp_stream* fd;
+
+ // TODO: is_userspace
+ if (!(fd = lio_usp_get_stream(current_process, *stream_id))) {
+ return -EBADF;
+ }
+
+ return lio_truncate(fd->stream, *size);
}
/// Verzeichniseintrag löschen
int syscall_lio_unlink(lio_usp_resource_t* parent, const char* name,
size_t name_len)
{
- return -ENOSYS;
+ struct lio_resource* parentres;
+
+ if (!(parentres = lio_usp_get_resource(*parent))) {
+ return -EINVAL;
+ }
+
+ // TODO: is_userspace
+ if (name[name_len - 1] != '\0') {
+ return -EINVAL;
+ }
+
+ // TODO: is_userspace
+ return lio_unlink(parentres, name);
}
/// Alle veränderten Blocks im Cache rausschreiben
int syscall_lio_sync_all(int soft)
{
- return -ENOSYS;
+ return lio_sync_all(soft);
}
-
--
1.6.0.2