[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 4/4] kernel2: Fehlercodes zurückgeben in lio_mkfile/dir/symlink



* kernel2: lio_mkfile/dir/symlink können jetzt einen Fehlercode
  zurückgeben statt nur NULL (woraus immer -EIO wurde)

+ kernel2: EEXIST zurückgeben, wenn lio_mkfile/dir/symlink mit einem
  Dateinamen aufgerufen wird, den es im Verzeichnis schon gibt

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/kernel2/include/lostio/client.h  | 10 +++++----
 src/kernel2/src/lostio/client.c      | 41 ++++++++++++++++++++++++++----------
 src/kernel2/src/lostio/modules/tmp.c |  3 ++-
 src/kernel2/src/syscalls/lostio.c    | 21 ++++++++++--------
 4 files changed, 50 insertions(+), 25 deletions(-)

diff --git a/src/kernel2/include/lostio/client.h b/src/kernel2/include/lostio/client.h
index 8880e62..12bfb09 100644
--- a/src/kernel2/include/lostio/client.h
+++ b/src/kernel2/include/lostio/client.h
@@ -172,14 +172,16 @@ ssize_t lio_read_dir(struct lio_resource* dir, size_t start, size_t num,
     struct lio_dir_entry* buf);
 
 /** Erstellt eine neue Datei */
-struct lio_resource* lio_mkfile(struct lio_resource* parent, const char* name);
+int lio_mkfile(struct lio_resource* parent, const char* name,
+               struct lio_resource** res);
 
 /** Erstellt ein neues Verzeichnis */
-struct lio_resource* lio_mkdir(struct lio_resource* parent, const char* name);
+int lio_mkdir(struct lio_resource* parent, const char* name,
+               struct lio_resource** res);
 
 /** Erstellt einen neuen Symlink */
-struct lio_resource* lio_mksymlink(struct lio_resource* parent,
-    const char* name, const char* target);
+int lio_mksymlink(struct lio_resource* parent, const char* name,
+                  const char* target, struct lio_resource** res);
 
 /**
  * Gibt Informationen zu einer Ressource zurueck
diff --git a/src/kernel2/src/lostio/client.c b/src/kernel2/src/lostio/client.c
index 770b675..015516e 100644
--- a/src/kernel2/src/lostio/client.c
+++ b/src/kernel2/src/lostio/client.c
@@ -132,7 +132,9 @@ static int get_node_in_dir(struct lio_resource* dir, const char* name,
     // Passendes Kind raussuchen
     for (i = 0; (n = list_get_element_at(dir->children, i)); i++) {
         if (strcmp(n->name, name) == 0) {
-            *node = n;
+            if (node) {
+                *node = n;
+            }
             return 0;
         }
     }
@@ -708,34 +710,51 @@ ssize_t lio_read_dir(struct lio_resource* dir, size_t start, size_t num,
 }
 
 /** Erstellt eine neue Datei */
-struct lio_resource* lio_mkfile(struct lio_resource* parent, const char* name)
+int lio_mkfile(struct lio_resource* parent, const char* name,
+               struct lio_resource** res)
 {
     if (!parent->tree->service->lio_ops.make_file || !parent->changeable) {
-        return NULL;
+        return -EACCES;
     }
 
-    return parent->tree->service->lio_ops.make_file(parent, name);
+    if (get_node_in_dir(parent, name, NULL) == 0) {
+        return -EEXIST;
+    }
+
+    *res = parent->tree->service->lio_ops.make_file(parent, name);
+    return *res ? 0 : -EIO;
 }
 
 /** Erstellt ein neues Verzeichnis */
-struct lio_resource* lio_mkdir(struct lio_resource* parent, const char* name)
+int lio_mkdir(struct lio_resource* parent, const char* name,
+               struct lio_resource** res)
 {
     if (!parent->tree->service->lio_ops.make_dir || !parent->changeable) {
-        return NULL;
+        return -EACCES;
     }
 
-    return parent->tree->service->lio_ops.make_dir(parent, name);
+    if (get_node_in_dir(parent, name, NULL) == 0) {
+        return -EEXIST;
+    }
+
+    *res = parent->tree->service->lio_ops.make_dir(parent, name);
+    return *res ? 0 : -EIO;
 }
 
 /** Erstellt einen neuen Symlink */
-struct lio_resource* lio_mksymlink(struct lio_resource* parent,
-    const char* name, const char* target)
+int lio_mksymlink(struct lio_resource* parent, const char* name,
+                  const char* target, struct lio_resource** res)
 {
     if (!parent->tree->service->lio_ops.make_symlink || !parent->changeable) {
-        return NULL;
+        return -EACCES;
+    }
+
+    if (get_node_in_dir(parent, name, NULL) == 0) {
+        return -EEXIST;
     }
 
-    return parent->tree->service->lio_ops.make_symlink(parent, name, target);
+    *res = parent->tree->service->lio_ops.make_symlink(parent, name, target);
+    return *res ? 0 : -EIO;
 }
 
 /**
diff --git a/src/kernel2/src/lostio/modules/tmp.c b/src/kernel2/src/lostio/modules/tmp.c
index 9c22911..5919ad5 100644
--- a/src/kernel2/src/lostio/modules/tmp.c
+++ b/src/kernel2/src/lostio/modules/tmp.c
@@ -255,6 +255,7 @@ void lio_init_tmp(void)
     lio_add_service(&dev_service);
     dev_root = lio_get_resource("dev:/", false);
     if (dev_root != NULL) {
-        lio_mkdir(dev_root, "fs");
+        struct lio_resource* dev_fs_res;
+        lio_mkdir(dev_root, "fs", &dev_fs_res);
     }
 }
diff --git a/src/kernel2/src/syscalls/lostio.c b/src/kernel2/src/syscalls/lostio.c
index 47c2f8c..01d49c5 100644
--- a/src/kernel2/src/syscalls/lostio.c
+++ b/src/kernel2/src/syscalls/lostio.c
@@ -293,6 +293,7 @@ void syscall_lio_mkfile(lio_usp_resource_t* parent, const char* name,
 {
     struct lio_resource* parentres;
     struct lio_resource* res;
+    int ret;
 
     parentres = lio_usp_get_resource(*parent);
     if (parentres == NULL) {
@@ -307,9 +308,9 @@ void syscall_lio_mkfile(lio_usp_resource_t* parent, const char* name,
     }
 
     // TODO: is_userspace
-    res = lio_mkfile(parentres, name);
-    if (res == NULL) {
-        *result = -EIO; // FIXME
+    ret = lio_mkfile(parentres, name, &res);
+    if (ret < 0) {
+        *result = ret;
         return;
     }
 
@@ -322,6 +323,7 @@ void syscall_lio_mkdir(lio_usp_resource_t* parent, const char* name,
 {
     struct lio_resource* parentres;
     struct lio_resource* res;
+    int ret;
 
     parentres = lio_usp_get_resource(*parent);
     if (parentres == NULL) {
@@ -336,9 +338,9 @@ void syscall_lio_mkdir(lio_usp_resource_t* parent, const char* name,
     }
 
     // TODO: is_userspace
-    res = lio_mkdir(parentres, name);
-    if (res == NULL) {
-        *result = -EIO; // FIXME
+    ret = lio_mkdir(parentres, name, &res);
+    if (ret < 0) {
+        *result = ret;
         return;
     }
 
@@ -352,6 +354,7 @@ void syscall_lio_mksymlink(lio_usp_resource_t* parent, const char* name,
 {
     struct lio_resource* parentres;
     struct lio_resource* res;
+    int ret;
 
     parentres = lio_usp_get_resource(*parent);
     if (parentres == NULL) {
@@ -371,9 +374,9 @@ void syscall_lio_mksymlink(lio_usp_resource_t* parent, const char* name,
         return;
     }
 
-    res = lio_mksymlink(parentres, name, target);
-    if (res == NULL) {
-        *result = -EIO; // FIXME
+    ret = lio_mksymlink(parentres, name, target, &res);
+    if (ret < 0) {
+        *result = ret;
         return;
     }
     *result = lio_usp_get_id(res);
-- 
2.1.4