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

[tyndur-devel] [PATCH 1/5] LostIOv1: Trennung von FILE und RPC-Daten



* LostIOv1: FILE war bisher die Datenstruktur, die auch per RPC benutzt
  wurde, um Handles zu übergeben, und die mit Zeug überfrachtet war,
  dass gar nicht durch die Gegend geschickt werden muss. Außerdem gab es
  noch eine andere Datenstruktur, die FILE für interne Zwecke erweitert
  hat.

  Jetzt ist FILE das lokale und io_resource_t das für den RPC.

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/modules/c/shell/cmds/cp.c        |    2 +-
 src/modules/c/shell/cmds/ls.c        |    2 +-
 src/modules/c/shell/cmds/rm.c        |    2 +-
 src/modules/c/shell/completion.c     |    4 +-
 src/modules/cdi/lib/fs/fs.c          |    4 +-
 src/modules/cdi/lib/fs/lostio_if.c   |   16 ++++----
 src/modules/fat/include/fat.h        |    7 ++--
 src/modules/fat/resource.c           |   34 +++++++++---------
 src/modules/include/dir.h            |    8 ++--
 src/modules/include/dirent.h         |    3 +-
 src/modules/include/io_struct.h      |    7 ----
 src/modules/include/lostio.h         |   16 ++++++--
 src/modules/include/stdio.h          |    7 ++--
 src/modules/lib/lost_link.c          |   12 +++---
 src/modules/lib/lostio/client/seek.c |    9 +++--
 src/modules/lib/lostio/handler.c     |    8 ++--
 src/modules/lib/posix/socket.c       |    2 +-
 src/modules/lib/posix/stat.c         |    2 +-
 src/modules/lib/stdlibc/directory.c  |   14 ++++----
 src/modules/lib/stdlibc/file.c       |   62 +++++++++++++++++----------------
 src/modules/servmgr/config.c         |    4 +-
 src/modules/tcpip/lostio_if.c        |    8 ++--
 src/modules/tcpip/tcp_server.c       |    4 +-
 src/modules/tcpip/udp.c              |    4 +-
 src/modules/tmp/main.c               |    4 +-
 25 files changed, 126 insertions(+), 119 deletions(-)

diff --git a/src/modules/c/shell/cmds/cp.c b/src/modules/c/shell/cmds/cp.c
index ad592ee..952d5bc 100644
--- a/src/modules/c/shell/cmds/cp.c
+++ b/src/modules/c/shell/cmds/cp.c
@@ -198,7 +198,7 @@ int cp_recursive(char* src_path, char* dst_path)
         printf("'%s' -> '%s'\n", src_path, dst_path);
     }
     
-    io_resource_t* dir_res = directory_open(src_path);
+    FILE* dir_res = directory_open(src_path);
     char* full_src_path = NULL;
     char* full_dst_path = NULL;
     if (dir_res != NULL) {
diff --git a/src/modules/c/shell/cmds/ls.c b/src/modules/c/shell/cmds/ls.c
index ab6d19f..5828b72 100644
--- a/src/modules/c/shell/cmds/ls.c
+++ b/src/modules/c/shell/cmds/ls.c
@@ -107,7 +107,7 @@ char* format_size(size_t size, bool human_readable);
         if (print_dirnames) {
             printf("%s:\n", dir_path);
         }
-        io_resource_t* dir_res = directory_open(dir_path);
+        FILE* dir_res = directory_open(dir_path);
         if (dir_res != NULL) {
             io_direntry_t* direntry;
             while ((direntry = directory_read(dir_res))) {
diff --git a/src/modules/c/shell/cmds/rm.c b/src/modules/c/shell/cmds/rm.c
index bd3068a..7d41d98 100644
--- a/src/modules/c/shell/cmds/rm.c
+++ b/src/modules/c/shell/cmds/rm.c
@@ -186,7 +186,7 @@ int rm_recursive(char* src_path, bool recurse, bool verbose, int interactive)
 {
     int result = 0;
     char* path = NULL;
-    io_resource_t* dir_res;
+    FILE* dir_res;
     char c;
     struct stat buf;
     if ((stat(src_path, &buf))) {
diff --git a/src/modules/c/shell/completion.c b/src/modules/c/shell/completion.c
index 939d892..58130ee 100644
--- a/src/modules/c/shell/completion.c
+++ b/src/modules/c/shell/completion.c
@@ -153,7 +153,7 @@ static void match_external_cmds(const char* word, list_t* matches_list)
 {
     int word_len = strlen(word);
     char* dir;
-    io_resource_t* dh;
+    FILE* dh;
     io_direntry_t* dentry;
 
     // Wir muessen die Umgebungsvariable kopieren, da strtok den Bereich
@@ -253,7 +253,7 @@ static char** shell_file_matches(const char* word)
     char* filename;
     int dir_len;
     int filename_len;
-    io_resource_t* dir;
+    FILE* dir;
     io_direntry_t* dentry;
     char** matches = NULL;
     list_t* matches_list;
diff --git a/src/modules/cdi/lib/fs/fs.c b/src/modules/cdi/lib/fs/fs.c
index e3adef1..941c961 100644
--- a/src/modules/cdi/lib/fs/fs.c
+++ b/src/modules/cdi/lib/fs/fs.c
@@ -46,9 +46,9 @@
 struct cdi_fs_driver* the_one_and_only_driver = NULL;
 
 bool lostio_not_found_handler(char** path, uint8_t args, pid_t pid,
-    io_resource_t* source);
+    FILE* source);
 bool lostio_pre_open_handler(char** path, uint8_t args, pid_t pid,
-    io_resource_t* source);
+    FILE* source);
 size_t lostio_read_handler(lostio_filehandle_t* fh, void* buf,
     size_t bs, size_t bc);
 size_t lostio_write_handler(lostio_filehandle_t* fh, size_t bs, size_t bc,
diff --git a/src/modules/cdi/lib/fs/lostio_if.c b/src/modules/cdi/lib/fs/lostio_if.c
index 63a354d..8d2d0b7 100644
--- a/src/modules/cdi/lib/fs/lostio_if.c
+++ b/src/modules/cdi/lib/fs/lostio_if.c
@@ -179,7 +179,7 @@ static bool fs_read_tree(struct cdi_fs_filesystem* fs)
     dh->fs = fs;
     dh->res = fs->root_res;
 
-    get_root_path(fs->device, rp);
+    get_root_path(&fs->device->res, rp);
     if ((!vfstree_create_node(rp, LOSTIO_TYPES_DIRECTORY, 0, dh,
         LOSTIO_FLAG_BROWSABLE)) || (!(node = vfstree_get_node_by_path(rp))))
     {
@@ -197,14 +197,14 @@ out_err:
     return false;
 }
 
-static bool fs_mount(io_resource_t* source)
+static bool fs_mount(FILE* source)
 {
     struct cdi_fs_filesystem* fs = malloc(sizeof(*fs));
     struct cdi_fs_driver* drv = the_one_and_only_driver;
 
     // FIXME ;-)
-    fs->device = malloc(sizeof(*source));
-    *((io_resource_t*) fs->device) = *source;
+    fs->device = calloc(1, sizeof(*fs->device));
+    *fs->device = *source;
 
     if (!drv->fs_init(fs)) {
         goto out_err;
@@ -229,7 +229,7 @@ out_err:
  * notwendigen Verzeichnisse geladen sind
  */
 bool lostio_not_found_handler(char** path, uint8_t args, pid_t pid,
-    io_resource_t* source)
+    FILE* source)
 {
     char root_path[ROOT_PATH_SIZE + 1];
     char full_path[FULL_PATH_SIZE(*path) + 1];
@@ -238,8 +238,8 @@ bool lostio_not_found_handler(char** path, uint8_t args, pid_t pid,
 
 
     p();
-    get_root_path(source, root_path);
-    get_full_path(source, *path, full_path);
+    get_root_path(&source->res, root_path);
+    get_full_path(&source->res, *path, full_path);
 
     // Wenn der Knoten nicht existiert muss gemountet werden
     root_node = vfstree_get_node_by_path(root_path);
@@ -367,7 +367,7 @@ out_err:
  * Handler der dazu benutzt wird, die Pfade umzubiegen
  */
 bool lostio_pre_open_handler(char** path, uint8_t args, pid_t pid,
-    io_resource_t* source)
+    FILE* source)
 {
     if ((strcmp(*path, "/") == 0) || (vfstree_get_node_by_path(*path) == NULL))
     {
diff --git a/src/modules/fat/include/fat.h b/src/modules/fat/include/fat.h
index dd207b8..0afc856 100644
--- a/src/modules/fat/include/fat.h
+++ b/src/modules/fat/include/fat.h
@@ -38,6 +38,7 @@
 
 #include <stdint.h>
 #include <stdbool.h>
+#include <stdio.h>
 #include "types.h"
 #include "lostio.h"
 
@@ -192,9 +193,9 @@ fat_directory_entry_t* fat_get_free_directory_entry(lostio_filehandle_t* filehan
 fat_directory_entry_t* fat_get_directory_entry(lostio_filehandle_t* filehandle, fat_res_info_t* res_info, char* filename);
 
 
-lostio_filehandle_t* fat_mount_source(char** path, uint8_t args, pid_t pid, io_resource_t* pipe_source);
-bool fat_res_pre_open_handler(char** path, uint8_t args, pid_t pid, io_resource_t* pipe_source);
-bool fat_res_not_found_handler(char** path, uint8_t args, pid_t pid, io_resource_t* pipe_source);
+lostio_filehandle_t* fat_mount_source(char** path, uint8_t args, pid_t pid, FILE* pipe_source);
+bool fat_res_pre_open_handler(char** path, uint8_t args, pid_t pid, FILE* pipe_source);
+bool fat_res_not_found_handler(char** path, uint8_t args, pid_t pid, FILE* pipe_source);
 void fat_res_post_open_handler(lostio_filehandle_t* filehandle);
 
 int fat_file_seek_handler(lostio_filehandle_t* filehandle, uint64_t offset,
diff --git a/src/modules/fat/resource.c b/src/modules/fat/resource.c
index 8eb97ea..008a51e 100644
--- a/src/modules/fat/resource.c
+++ b/src/modules/fat/resource.c
@@ -47,7 +47,7 @@
 
 
 bool fat_res_not_found_handler(char** path, uint8_t args, pid_t pid, 
-    io_resource_t* pipe_source)
+    FILE* pipe_source)
 {
     if (pipe_source == NULL) {
         return false;
@@ -66,10 +66,10 @@ bool fat_res_not_found_handler(char** path, uint8_t args, pid_t pid,
 
     //FIXME: uint32_t-Cast entferen, sobald asprintf keine Probleme mehr macht
     if (
-        (asprintf(&root_path, "/%d/%d/root",  pipe_source->pid, 
-            (uint32_t)pipe_source->resid) == -1) ||
-        (asprintf(&new_path, "/%d/%d/root%s",  pipe_source->pid, 
-            (uint32_t)pipe_source->resid, *path) == -1))
+        (asprintf(&root_path, "/%d/%d/root",  pipe_source->res.pid, 
+            (uint32_t)pipe_source->res.resid) == -1) ||
+        (asprintf(&new_path, "/%d/%d/root%s",  pipe_source->res.pid, 
+            (uint32_t)pipe_source->res.resid, *path) == -1))
     {
         return false; 
     }
@@ -91,8 +91,8 @@ bool fat_res_not_found_handler(char** path, uint8_t args, pid_t pid,
     } else {
         char* resid_dir;
         filehandle = malloc(sizeof(lostio_filehandle_t));
-        asprintf(&resid_dir, "/%d/%d",  pipe_source->pid, 
-            (uint32_t)pipe_source->resid);
+        asprintf(&resid_dir, "/%d/%d",  pipe_source->res.pid, 
+            (uint32_t)pipe_source->res.resid);
 
         vfstree_node_t* root_node = vfstree_get_node_by_path(resid_dir);
         free(resid_dir);
@@ -197,7 +197,7 @@ bool fat_res_not_found_handler(char** path, uint8_t args, pid_t pid,
  * Wird bei jedem OPEN von einer Datei/Verzeichnis hier aufgerufen.
  */
 bool fat_res_pre_open_handler(char** path, uint8_t args, pid_t pid, 
-    io_resource_t* pipe_source)
+    FILE* pipe_source)
 {
     bool result = true;
     lostio_filehandle_t* filehandle;
@@ -213,7 +213,7 @@ bool fat_res_pre_open_handler(char** path, uint8_t args, pid_t pid,
 
     filehandle = malloc(sizeof(lostio_filehandle_t));
     char* root_dir;
-    asprintf(&root_dir, "/%d/%d", pipe_source->pid, pipe_source->resid);
+    asprintf(&root_dir, "/%d/%d", pipe_source->res.pid, pipe_source->res.resid);
     vfstree_node_t* root_node = vfstree_get_node_by_path(root_dir);
     free(root_dir);
     filehandle->data = root_node->data;
@@ -252,8 +252,8 @@ void fat_res_post_open_handler(lostio_filehandle_t* filehandle)
 {
     p();
     char* root_dir;
-    asprintf(&root_dir, "/%d/%d", filehandle->source->pid, 
-        filehandle->source->resid);
+    asprintf(&root_dir, "/%d/%d", filehandle->source->res.pid, 
+        filehandle->source->res.resid);
 
     vfstree_node_t* root_node = vfstree_get_node_by_path(root_dir);
     free(root_dir);
@@ -275,7 +275,7 @@ void fat_res_post_open_handler(lostio_filehandle_t* filehandle)
 /**
  * Einbinden einer neuen Quelle
  */
-lostio_filehandle_t* fat_mount_source(char** path, uint8_t args, pid_t pid, io_resource_t* pipe_source)
+lostio_filehandle_t* fat_mount_source(char** path, uint8_t args, pid_t pid, FILE* pipe_source)
 {
     if (pipe_source == NULL) {
         return NULL;
@@ -290,12 +290,12 @@ lostio_filehandle_t* fat_mount_source(char** path, uint8_t args, pid_t pid, io_r
     
     if(
         (pipe_source == NULL) ||
-        (asprintf(&pid_dir, "/%d", pipe_source->pid) == -1) ||
-        (asprintf(&resid_dir, "/%d/%d", pipe_source->pid, pipe_source->resid) == -1) ||
-        (asprintf(&root_dir, "/%d/%d/root", pipe_source->pid, pipe_source->resid) == -1)||
-        (asprintf(&bpb_path, "/%d/%d/root/bpb", pipe_source->pid, pipe_source->resid) == -1) ||
+        (asprintf(&pid_dir, "/%d", pipe_source->res.pid) == -1) ||
+        (asprintf(&resid_dir, "/%d/%d", pipe_source->res.pid, pipe_source->res.resid) == -1) ||
+        (asprintf(&root_dir, "/%d/%d/root", pipe_source->res.pid, pipe_source->res.resid) == -1)||
+        (asprintf(&bpb_path, "/%d/%d/root/bpb", pipe_source->res.pid, pipe_source->res.resid) == -1) ||
         //FIXME: uint32_t-Cast entferen, sobald asprintf keine Probleme mehr macht
-        (asprintf(&new_path, "/%d/%d/root%s", pipe_source->pid, (uint32_t)pipe_source->resid, *path) == -1)
+        (asprintf(&new_path, "/%d/%d/root%s", pipe_source->res.pid, (uint32_t)pipe_source->res.resid, *path) == -1)
     )
     {
         return NULL;
diff --git a/src/modules/include/dir.h b/src/modules/include/dir.h
index e578ddd..d825a55 100644
--- a/src/modules/include/dir.h
+++ b/src/modules/include/dir.h
@@ -32,10 +32,10 @@
 #include "stdio.h"
 #include "io.h"
 
-io_resource_t* directory_open(const char* dirname);
-int directory_close(io_resource_t* io_res);
-io_direntry_t* directory_read(io_resource_t* io_res);
-int directory_seek(io_resource_t* io_res, long int offset, int origin);
+FILE* directory_open(const char* dirname);
+int directory_close(FILE* io_res);
+io_direntry_t* directory_read(FILE* io_res);
+int directory_seek(FILE* io_res, long int offset, int origin);
 bool directory_create(const char* dirname);
 bool is_directory(const char* dirname);
 
diff --git a/src/modules/include/dirent.h b/src/modules/include/dirent.h
index 2cdf69a..8e86e46 100644
--- a/src/modules/include/dirent.h
+++ b/src/modules/include/dirent.h
@@ -29,13 +29,14 @@
 #define _DIRENT_H_
 #include <io_struct.h>
 #include <limits.h>
+#include <lostio.h>
 
 struct dirent {
     unsigned short d_reclen;
     char d_name[MAX_FILENAME_LEN + 1];
 };
 
-typedef io_resource_t DIR;
+typedef struct lostio_internal_file DIR;
 
 
 #ifdef __cplusplus
diff --git a/src/modules/include/io_struct.h b/src/modules/include/io_struct.h
index e4d872f..813fa5d 100644
--- a/src/modules/include/io_struct.h
+++ b/src/modules/include/io_struct.h
@@ -52,13 +52,6 @@ typedef struct
     pid_t               pid;
     io_resource_id_t    resid;
 
-    void*               buffer_ptr;
-    size_t              buffer_size;
-    size_t              buffer_pos;
-    uint8_t             buffer_mode;
-
-    size_t              ungetc_count;
-    uint8_t*            ungetc_buffer;
 } __attribute__ ((packed)) io_resource_t;
 #endif //ifndef _IO_STRUCT_H_
 
diff --git a/src/modules/include/lostio.h b/src/modules/include/lostio.h
index b8b752e..3579bf4 100644
--- a/src/modules/include/lostio.h
+++ b/src/modules/include/lostio.h
@@ -77,12 +77,13 @@ typedef struct vfstree_node_t
 
 
 ///Handle fuer eine geoeffnete Datei
+struct lostio_internal_file;
 typedef struct
 {
     uint32_t        id;
     pid_t           pid;
     uint32_t        flags;
-    io_resource_t*  source;
+    struct lostio_internal_file*           source;
     uint64_t        pos;
     
     ///Modulspezifische Daten
@@ -104,8 +105,8 @@ typedef struct
 typedef struct
 {
     typeid_t        id;
-    bool            (*not_found)(char**, uint8_t, pid_t,io_resource_t*);
-    bool            (*pre_open)(char**, uint8_t, pid_t,io_resource_t*);
+    bool            (*not_found)(char**, uint8_t, pid_t,struct lostio_internal_file*);
+    bool            (*pre_open)(char**, uint8_t, pid_t,struct lostio_internal_file*);
     void            (*post_open)(lostio_filehandle_t*);
 
     size_t          (*read)(lostio_filehandle_t*,void*,size_t,size_t);
@@ -121,6 +122,13 @@ typedef struct
 /// Geoeffnete Datei auf Clientseite (Wrapper fuer FILE)
 struct lostio_internal_file {
     io_resource_t res;
+    size_t        ungetc_count;
+    uint8_t*      ungetc_buffer;
+
+    void*         buffer_ptr;
+    size_t        buffer_size;
+    size_t        buffer_pos;
+    uint8_t       buffer_mode;
     bool          free_buffer;
 };
 
@@ -183,7 +191,7 @@ void lostio_type_directory_use_as(typeid_t id);
 
 
 /// Stream-Position setzen
-bool lio_seek(io_resource_t* res, uint64_t off, int whence);
+bool lio_seek(struct lostio_internal_file* io_res, uint64_t offset, int origin);
 
 /** @}  */
 
diff --git a/src/modules/include/stdio.h b/src/modules/include/stdio.h
index a3be896..3cc139f 100644
--- a/src/modules/include/stdio.h
+++ b/src/modules/include/stdio.h
@@ -32,6 +32,7 @@
 #include <stdarg.h>
 #include <lost/config.h>
 #include <io_struct.h>
+#include <lostio.h>
 
 
 #define SEEK_SET 0
@@ -49,7 +50,7 @@
 
 #define P_tmpdir "file:/tmp"
 
-typedef io_resource_t FILE;
+typedef struct lostio_internal_file FILE;
 
 extern FILE* stdin;
 extern FILE* stdout;
@@ -115,8 +116,8 @@ int ferror(FILE* io_res);
 void clearerr(FILE* io_res);
 void rewind(FILE* io_res);
 
-int fflush(io_resource_t* io_res);
-int fpurge(io_resource_t* io_res);
+int fflush(FILE* io_res);
+int fpurge(FILE* io_res);
 int setvbuf(FILE* io_res, char* buffer, int mode, size_t size);
 int setbuf(FILE* io_res, char* buffer);
 int setbuffer(FILE* io_res, char* buffer, size_t size);
diff --git a/src/modules/lib/lost_link.c b/src/modules/lib/lost_link.c
index c377f93..688088a 100644
--- a/src/modules/lib/lost_link.c
+++ b/src/modules/lib/lost_link.c
@@ -96,7 +96,7 @@ int io_create_link(const char* target_path, const char* link_path,
     
     // Wenn die Beiden nicht im Selben Treiber liegen, ist der Fall eh
     // erledigt.
-    if (link_dir->pid != target_file->pid) {
+    if (link_dir->res.pid != target_file->res.pid) {
         errno = EXDEV;
         result = -1;
         goto end_close_dir;
@@ -118,11 +118,11 @@ int io_create_link(const char* target_path, const char* link_path,
         memcpy(request->name, link_filename, link_len);
     
         // Ziel eintragen
-        request->target_id = target_file->id;
-        request->dir_id = link_dir->id;
+        request->target_id = target_file->res.id;
+        request->dir_id = link_dir->res.id;
 
         // RPC durchfuehren und auf Ergebnis warten
-        result = rpc_get_int(target_file->pid, "IO_LINK ", size, buffer);
+        result = rpc_get_int(target_file->res.pid, "IO_LINK ", size, buffer);
         switch (result) {
             // Ziel oder Verzeichnis nicht in Ordnung
             case -1:
@@ -208,10 +208,10 @@ int io_remove_link(const char* link_path)
         memcpy(request->name, link_filename, link_len);
     
         // Verzeichnis eintragen
-        request->dir_id = link_dir->id;
+        request->dir_id = link_dir->res.id;
 
         // RPC durchfuehren und auf Ergebnis warten
-        result = rpc_get_int(link_dir->pid, "IO_ULINK", size, buffer);
+        result = rpc_get_int(link_dir->res.pid, "IO_ULINK", size, buffer);
         switch (result) {
             // Ziel oder Verzeichnis nicht in Ordnung
             case -1:
diff --git a/src/modules/lib/lostio/client/seek.c b/src/modules/lib/lostio/client/seek.c
index 3e75f1b..bcda4bf 100644
--- a/src/modules/lib/lostio/client/seek.c
+++ b/src/modules/lib/lostio/client/seek.c
@@ -27,6 +27,7 @@
  */
 #include <io.h>
 #include <lostio.h>
+#include <stdio.h>
 #include <rpc.h>
 #include <stdint.h>
 
@@ -42,20 +43,20 @@
  *
  * @return true wenn die Position erfolgreich gesetzt wurde, sonst false
  */
-bool lio_seek(io_resource_t* io_res, uint64_t offset, int origin)
+bool lio_seek(FILE* io_res, uint64_t offset, int origin)
 {
     io_seek_request_t seek_request;
     
     // Ungueltige Handles abfangen
-    if ((io_res == NULL) || (io_res->pid == 0)) {
+    if ((io_res == NULL) || (io_res->res.pid == 0)) {
         return false;
     }
 
-    seek_request.id = io_res->id;
+    seek_request.id = io_res->res.id;
     seek_request.offset = offset;
     seek_request.origin = origin;
 
-    return (rpc_get_dword(io_res->pid, "IO_SEEK ", sizeof(io_seek_request_t),
+    return (rpc_get_dword(io_res->res.pid, "IO_SEEK ", sizeof(io_seek_request_t),
         (char*) &seek_request) == 0);
 }
 
diff --git a/src/modules/lib/lostio/handler.c b/src/modules/lib/lostio/handler.c
index 1c23d3d..66b7d31 100644
--- a/src/modules/lib/lostio/handler.c
+++ b/src/modules/lib/lostio/handler.c
@@ -42,7 +42,7 @@
 
 
 ///Handler zum oeffnen einer Datei
-static lostio_filehandle_t* lostio_open(char* path, uint8_t attr, pid_t pid, io_resource_t* io_source);
+static lostio_filehandle_t* lostio_open(char* path, uint8_t attr, pid_t pid, FILE* io_source);
 
 ///Handler zum Schliessen einer Datei
 static bool lostio_close(uint32_t id, pid_t pid);
@@ -66,7 +66,7 @@ void rpc_io_open(pid_t pid, uint32_t correlation_id, size_t data_size, void* dat
     io_resource_t* io_source = (io_resource_t*) ((uint32_t)data + 1 + sizeof(pid_t));
 
     // FIXME
-    struct lostio_internal_file* int_source = malloc(sizeof(*int_source));
+    struct lostio_internal_file* int_source = calloc(1, sizeof(*int_source));
     int_source->res = *io_source;
     int_source->free_buffer = false;
     io_source = &int_source->res;
@@ -80,7 +80,7 @@ void rpc_io_open(pid_t pid, uint32_t correlation_id, size_t data_size, void* dat
     }
     io_res.pid = my_pid;
     
-    lostio_filehandle_t* filehandle = lostio_open(path, *attr, *caller_pid, io_source);;
+    lostio_filehandle_t* filehandle = lostio_open(path, *attr, *caller_pid, int_source);;
     
     if(filehandle == NULL)
     {
@@ -488,7 +488,7 @@ void rpc_io_unlink(pid_t pid, uint32_t correlation_id, size_t data_size, void* d
  *
  * @return Die ID des Handles oder 0 wenn ein Fehler aufgetreten ist.
  */
-static lostio_filehandle_t* lostio_open(char* path, uint8_t attr, pid_t pid, io_resource_t* io_source)
+static lostio_filehandle_t* lostio_open(char* path, uint8_t attr, pid_t pid, FILE* io_source)
 { 
     vfstree_node_t* node = vfstree_get_node_by_path(path);
     typehandle_t* typehandle;
diff --git a/src/modules/lib/posix/socket.c b/src/modules/lib/posix/socket.c
index 1179a67..ebc29a2 100644
--- a/src/modules/lib/posix/socket.c
+++ b/src/modules/lib/posix/socket.c
@@ -73,7 +73,7 @@ static int create_socket(struct socket* socket)
         sockets = tree_create(struct socket, tinfo, id);
     }
 
-    socket->id = fileno(&socket->conn.res);
+    socket->id = fileno(&socket->conn);
     tree_insert(sockets, socket);
     return socket->id;
 }
diff --git a/src/modules/lib/posix/stat.c b/src/modules/lib/posix/stat.c
index 5bd876b..d5440ae 100644
--- a/src/modules/lib/posix/stat.c
+++ b/src/modules/lib/posix/stat.c
@@ -125,7 +125,7 @@ int stat(const char* filename, struct stat* stat_buf)
     // Wenn die Datei nicht geoeffnet werden kann, koennte es sich um ein
     // Verzeichnis handeln, falls nicht wird sofort abgebrochen
     if (file == NULL) {
-        io_resource_t* dir = directory_open(filename);
+        FILE* dir = directory_open(filename);
         if (dir == NULL) {
             errno = ENOENT;
             return -1;
diff --git a/src/modules/lib/stdlibc/directory.c b/src/modules/lib/stdlibc/directory.c
index d0574ae..6a32ddf 100644
--- a/src/modules/lib/stdlibc/directory.c
+++ b/src/modules/lib/stdlibc/directory.c
@@ -32,19 +32,19 @@
 #include "stdlib.h"
 #include "dir.h"
 
-io_resource_t* directory_open(const char* dirname)
+FILE* directory_open(const char* dirname)
 {
     return fopen(dirname, "rd");
 }
 
 
-int directory_close(io_resource_t* io_res)
+int directory_close(FILE* io_res)
 {
-    return fclose((FILE*)io_res);
+    return fclose(io_res);
 }
 
 
-io_direntry_t* directory_read(io_resource_t* io_res)
+io_direntry_t* directory_read(FILE* io_res)
 {
     if ((io_res == NULL) || (feof(io_res) != 0)) {
         return NULL;
@@ -58,9 +58,9 @@ io_direntry_t* directory_read(io_resource_t* io_res)
 }
 
 
-int directory_seek(io_resource_t* io_res, long int offset, int origin)
+int directory_seek(FILE* io_res, long int offset, int origin)
 {
-    return fseek((FILE*)io_res, offset, origin);
+    return fseek(io_res, offset, origin);
 }
 
 bool directory_create(const char* dirname)
@@ -78,7 +78,7 @@ bool directory_create(const char* dirname)
 
 bool is_directory(const char* dirname)
 {
-    io_resource_t* dir = directory_open(dirname);
+    FILE* dir = directory_open(dirname);
     if (dir != NULL) {
         directory_close(dir);
         return true;
diff --git a/src/modules/lib/stdlibc/file.c b/src/modules/lib/stdlibc/file.c
index 45e24f2..fa20680 100644
--- a/src/modules/lib/stdlibc/file.c
+++ b/src/modules/lib/stdlibc/file.c
@@ -130,33 +130,35 @@ FILE* fopen (const char* filename, const char* mode)
     //weren.
     free(full_path);
 
-    FILE* io_res = (io_resource_t*) resp->data;
+    FILE* int_res;
+    io_resource_t* io_res = (io_resource_t*) resp->data;
+
     //Wenn ein Fehler beim oeffnen aufgetreten ist, wird NULL zurueck gegeben.
     if ((io_res == NULL) || (io_res->pid == 0) || (resp->data_length == 0)) {
-        io_res = NULL;
+        int_res = NULL;
     } else {
-        io_res->buffer_mode = IO_BUFFER_MODE_NONE;
-        io_res->buffer_ptr = NULL;
-        io_res->buffer_size = 0;
-        io_res->buffer_pos = 0;
 
         // Pfad im Handle hinterlegen
         io_res->path = malloc(strlen(filename) + 1);
         strcpy(io_res->path, filename);
 
 
-        struct lostio_internal_file* int_res = malloc(sizeof(*int_res));
+        int_res = calloc(1, sizeof(*int_res));
         int_res->res = *io_res;
+
+        int_res->buffer_mode = IO_BUFFER_MODE_NONE;
+        int_res->buffer_ptr = NULL;
+        int_res->buffer_size = 0;
+        int_res->buffer_pos = 0;
         int_res->free_buffer = false;
-        setvbuf(&int_res->res, malloc(BUFSIZ), _IOFBF, BUFSIZ);
+        setvbuf(int_res, malloc(BUFSIZ), _IOFBF, BUFSIZ);
         int_res->free_buffer = true;
 
         free(io_res);
-        io_res = &int_res->res;
     }
     free(resp);
     
-    return io_res;
+    return int_res;
 }
 
 /**
@@ -197,7 +199,7 @@ int fclose (FILE* io_res)
 {
     uint32_t result;
     
-    if((io_res == NULL) || (io_res->pid == 0))
+    if((io_res == NULL) || (io_res->res.pid == 0))
     {
         return EOF;
     }
@@ -205,8 +207,8 @@ int fclose (FILE* io_res)
     fflush(io_res);
     setvbuf(io_res, NULL, _IONBF, 0);
 
-    result = rpc_get_dword(io_res->pid, "IO_CLOSE", sizeof(io_resource_id_t),
-        (char*) &(io_res->id));
+    result = rpc_get_dword(io_res->res.pid, "IO_CLOSE", sizeof(io_resource_id_t),
+        (char*) &(io_res->res.id));
     free(io_res);
 
     return result;
@@ -225,7 +227,7 @@ int fclose (FILE* io_res)
  */
 size_t fread(void* dest, size_t blocksize, size_t blockcount, FILE* io_res)
 {
-    if ((io_res == NULL) || (io_res->pid == 0)) {
+    if ((io_res == NULL) || (io_res->res.pid == 0)) {
         return 0;
     }
     
@@ -262,7 +264,7 @@ size_t fread(void* dest, size_t blocksize, size_t blockcount, FILE* io_res)
     }
     
     io_read_request_t read_request;
-    read_request.id = io_res->id;
+    read_request.id = io_res->res.id;
     read_request.blocksize = blocksize;
     read_request.blockcount = blockcount;
 
@@ -272,7 +274,7 @@ size_t fread(void* dest, size_t blocksize, size_t blockcount, FILE* io_res)
         get_shm(blocksize * blockcount);
         read_request.shared_mem_id = shm_id;
 
-        response_t* resp = rpc_get_response(io_res->pid, "IO_READ ",
+        response_t* resp = rpc_get_response(io_res->res.pid, "IO_READ ",
             sizeof(read_request), (char*) &(read_request));
         size_t size = *((size_t*) resp->data);
         
@@ -295,7 +297,7 @@ size_t fread(void* dest, size_t blocksize, size_t blockcount, FILE* io_res)
         // Daten gelesen werden.
         fflush(io_res);
 
-        response_t* resp = rpc_get_response(io_res->pid, "IO_READ ", 
+        response_t* resp = rpc_get_response(io_res->res.pid, "IO_READ ", 
             sizeof(read_request), (char*) &(read_request));
         size_t size = resp->data_length;
     
@@ -430,7 +432,7 @@ static size_t io_write(const void* src, size_t blocksize, size_t blockcount,
     uint8_t request[request_size];
 
     io_write_request_t* write_request = (io_write_request_t*) request;    
-    write_request->id = io_res->id;
+    write_request->id = io_res->res.id;
     write_request->blocksize = blocksize;
     write_request->blockcount = blockcount;
 
@@ -445,7 +447,7 @@ static size_t io_write(const void* src, size_t blocksize, size_t blockcount,
         memcpy(data, src, data_size);
     }
     
-    size_t resp = rpc_get_dword(io_res->pid, "IO_WRITE",
+    size_t resp = rpc_get_dword(io_res->res.pid, "IO_WRITE",
         request_size, (char*) request);
     
     if (data_size >= 1024) {
@@ -468,7 +470,7 @@ size_t fwrite(const void* data, size_t blocksize, size_t blockcount,
 {
    	size_t data_size = blocksize * blockcount;
 	
-    if ((io_res == NULL) || (io_res->pid == 0)) {
+    if ((io_res == NULL) || (io_res->res.pid == 0)) {
         return 0;
     }
 
@@ -589,7 +591,7 @@ int fputs(const char *str, FILE *io_res)
 int fseek (FILE* io_res, long int offset, int origin)
 {
     // Ungueltige Handles abfangen
-    if ((io_res == NULL) || (io_res->pid == 0)) {
+    if ((io_res == NULL) || (io_res->res.pid == 0)) {
         return -1;
     }
 
@@ -615,20 +617,20 @@ int fseek (FILE* io_res, long int offset, int origin)
 long ftell(FILE* io_res)
 {
     //Ungueltige Handles abfangen
-    if ((io_res == NULL) || (io_res->pid == 0)) {
+    if ((io_res == NULL) || (io_res->res.pid == 0)) {
         return EOF;
     }
         
     io_tell_request_t tell_request;
     long result;
-    tell_request.id = io_res->id;
+    tell_request.id = io_res->res.id;
     
     //Sonst könnte die Angabe falsch sein
     fflush(io_res);
 
     //Da fuer qwords keine Funktion existiert um sie direkt uber RPC zu
     // empfangen, muss hier ein kleiner Umweg gemacht werden.
-    response_t* resp = rpc_get_response(io_res->pid, "IO_TELL ",
+    response_t* resp = rpc_get_response(io_res->res.pid, "IO_TELL ",
         sizeof(io_tell_request_t), (char*) &(tell_request));
     memcpy(&result, resp->data, sizeof(long));
 
@@ -650,7 +652,7 @@ long ftell(FILE* io_res)
 int feof(FILE* io_res)
 {
     //Ungueltige Handles abfangen
-    if ((io_res == NULL) || (io_res->pid == 0)) {
+    if ((io_res == NULL) || (io_res->res.pid == 0)) {
         return EOF;
     }
 
@@ -660,12 +662,12 @@ int feof(FILE* io_res)
     }
     
     io_eof_request_t eof_request;
-    eof_request.id = io_res->id;
+    eof_request.id = io_res->res.id;
     
     //Auch hier könnte mit Daten im Buffer ein falsches Ergebnis rauskommen
     fflush(io_res);
 
-    return rpc_get_dword(io_res->pid, "IO_EOF  ", sizeof(io_eof_request_t),
+    return rpc_get_dword(io_res->res.pid, "IO_EOF  ", sizeof(io_eof_request_t),
         (char*) &eof_request);
 }
 
@@ -715,10 +717,10 @@ void rewind(FILE* io_res)
  * 
  * @return 0 wenn kein Fehler aufgetreten ist, sonst EOF
  */
-int fflush(io_resource_t* io_res)
+int fflush(FILE* io_res)
 {
     //Ungueltige Handles abfangen
-    if ((io_res == NULL) || (io_res->pid == 0)) {
+    if ((io_res == NULL) || (io_res->res.pid == 0)) {
         return EOF;
     }
     
@@ -750,7 +752,7 @@ int fflush(io_resource_t* io_res)
  * 
  * @return 0 wenn kein Fehler aufgetreten ist, sonst EOF
  */
-int fpurge(io_resource_t* io_res)
+int fpurge(FILE* io_res)
 {
 	io_res->buffer_pos = 0;
     return 0;
diff --git a/src/modules/servmgr/config.c b/src/modules/servmgr/config.c
index fbe7684..ec33c22 100644
--- a/src/modules/servmgr/config.c
+++ b/src/modules/servmgr/config.c
@@ -216,7 +216,7 @@ static void config_parse_conf(const char* path,
  *
  * @return true wenn erfolgreich abgeschlossen wurde, false sonst.
  */
-static bool config_dir_parse(io_resource_t* dir)
+static bool config_dir_parse(FILE* dir)
 {
     io_direntry_t* entry;
     struct config_service* conf_serv;
@@ -278,7 +278,7 @@ static bool config_dir_parse(io_resource_t* dir)
 bool config_read()
 {
     const char* config_path = "/config/servmgr";
-    io_resource_t* dir;
+    FILE* dir;
     bool result;
     int ires;
 
diff --git a/src/modules/tcpip/lostio_if.c b/src/modules/tcpip/lostio_if.c
index 96c62cd..6269da9 100644
--- a/src/modules/tcpip/lostio_if.c
+++ b/src/modules/tcpip/lostio_if.c
@@ -76,8 +76,8 @@ typehandle_t typehandle;
 typehandle_t typehandle2;
 typehandle_t typehandle3;
 
-bool   lostio_tcp_not_found(char**, uint8_t, pid_t,io_resource_t*);
-bool   lostio_tcp_pre_open(char**, uint8_t, pid_t,io_resource_t*);
+bool   lostio_tcp_not_found(char**, uint8_t, pid_t,FILE*);
+bool   lostio_tcp_pre_open(char**, uint8_t, pid_t,FILE*);
 size_t lostio_tcp_read(lostio_filehandle_t*,void*,size_t,size_t);
 size_t lostio_tcp_write(lostio_filehandle_t*,size_t,size_t,void*);
 int    lostio_tcp_close(lostio_filehandle_t*);
@@ -170,7 +170,7 @@ void lostio_add_device(struct device *device)
 }
 
 bool lostio_tcp_not_found(char** path, uint8_t flags, pid_t pid,
-    io_resource_t* ps)
+    FILE* ps)
 {
     DEBUG_MSG("Knoten anlegen");
 
@@ -207,7 +207,7 @@ bool lostio_tcp_not_found(char** path, uint8_t flags, pid_t pid,
 }
 
 bool lostio_tcp_pre_open(char** path, uint8_t flags, pid_t pid,
-    io_resource_t* ps)
+    FILE* ps)
 {
     DEBUG_MSG("pre_open");
     
diff --git a/src/modules/tcpip/tcp_server.c b/src/modules/tcpip/tcp_server.c
index 2be827f..b2fd6bc 100644
--- a/src/modules/tcpip/tcp_server.c
+++ b/src/modules/tcpip/tcp_server.c
@@ -59,7 +59,7 @@ static void do_nothing(void) {}
  * zugegriffen werden soll
  */
 static bool lio_server_dir_not_found(char** path, uint8_t flags, pid_t pid,
-    io_resource_t* ps)
+    FILE* ps)
 {
     return vfstree_create_node(*path, LOSTIO_TYPES_SERVER, 0, NULL, 0);
 }
@@ -70,7 +70,7 @@ static bool lio_server_dir_not_found(char** path, uint8_t flags, pid_t pid,
  * Oeffnen der Verbindung ausgegeben
  */
 static bool lio_server_pre_open(char** path, uint8_t flags, pid_t pid,
-    io_resource_t* ps)
+    FILE* ps)
 {
     char* s;
     char* port;
diff --git a/src/modules/tcpip/udp.c b/src/modules/tcpip/udp.c
index b093137..eae34f7 100644
--- a/src/modules/tcpip/udp.c
+++ b/src/modules/tcpip/udp.c
@@ -115,7 +115,7 @@ static int parse_connection(const char* filename, int* sport,
  * zugegriffen werden soll
  */
 static bool lio_udp_dir_not_found(char** path, uint8_t flags, pid_t pid,
-    io_resource_t* ps)
+    FILE* ps)
 {
     int ret;
 
@@ -134,7 +134,7 @@ static bool lio_udp_dir_not_found(char** path, uint8_t flags, pid_t pid,
  * Oeffnen der Verbindung ausgegeben
  */
 static bool lio_udp_pre_open(char** path, uint8_t flags, pid_t pid,
-    io_resource_t* ps)
+    FILE* ps)
 {
     struct udp_socket* s;
     vfstree_node_t* node;
diff --git a/src/modules/tmp/main.c b/src/modules/tmp/main.c
index 138a4c3..e80598a 100644
--- a/src/modules/tmp/main.c
+++ b/src/modules/tmp/main.c
@@ -50,7 +50,7 @@
 //#define DEBUG_MSG(s) printf("[  TMP  ] debug: '%s'\n", s)
 #define DEBUG_MSG(s) //
 
-bool create_handler(char** path, uint8_t args, pid_t pid,io_resource_t* source);
+bool create_handler(char** path, uint8_t args, pid_t pid,FILE* source);
 
 size_t current_id = 0;
 
@@ -77,7 +77,7 @@ int main(int argc, char* argv[])
 }
 
 
-bool create_handler(char** path, uint8_t args, pid_t pid,io_resource_t* source)
+bool create_handler(char** path, uint8_t args, pid_t pid,FILE* source)
 {
     current_id++;
     char* new_path;
-- 
1.6.0.2