From kevin at tyndur.org Sat Dec 3 18:20:48 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 3 Dec 2011 18:20:48 +0100 Subject: [tyndur-devel] [RFC PATCH 0/5] kernel2: LIOv2-Grundlagen Message-ID: <1322932853-21843-1-git-send-email-kevin@tyndur.org> Nach dieser Patchserie ist tmp:/ als LIOv2-Service funktionsfähig. Alles interessante und potentiell problematisch wie der Cache, Userspace-Services oder Pipes ist noch ausgespart. Kevin Wolf (5): kernel2: LIOv2-Grundgerüst kernel2: Zentrale LIOv2-Clientfunktionen kernel2: Ressourcen und Verzeichnisbäume kernel2: LIOv2-Service tmp kernel2: LIOv2-Clientsyscalls implementiert src/include/syscall_structs.h | 3 + src/kernel2/include/lostio/client.h | 188 ++++++++ src/kernel2/include/lostio/core.h | 82 ++++ src/kernel2/include/tasks.h | 4 + src/kernel2/src/arch/i386/Makefile.all | 2 +- src/kernel2/src/init.c | 4 + src/kernel2/src/lostio/client.c | 632 +++++++++++++++++++++++++++ src/kernel2/src/lostio/include/lostio_int.h | 297 +++++++++++++ src/kernel2/src/lostio/lostio.c | 51 +++ src/kernel2/src/lostio/modules/tmp.c | 223 ++++++++++ src/kernel2/src/lostio/tree.c | 365 +++++++++++++++ src/kernel2/src/lostio/userspace.c | 130 ++++++ src/kernel2/src/syscalls/lostio.c | 228 +++++++++- src/kernel2/src/tasks/pm.c | 5 + 14 files changed, 2197 insertions(+), 17 deletions(-) create mode 100644 src/kernel2/include/lostio/client.h create mode 100644 src/kernel2/include/lostio/core.h create mode 100644 src/kernel2/src/lostio/client.c create mode 100644 src/kernel2/src/lostio/include/lostio_int.h create mode 100644 src/kernel2/src/lostio/lostio.c create mode 100644 src/kernel2/src/lostio/modules/tmp.c create mode 100644 src/kernel2/src/lostio/tree.c create mode 100644 src/kernel2/src/lostio/userspace.c From kevin at tyndur.org Sat Dec 3 18:20:49 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 3 Dec 2011 18:20:49 +0100 Subject: [tyndur-devel] =?utf-8?q?=5BRFC_PATCH_1/5=5D_kernel2=3A_LIOv2-Gru?= =?utf-8?b?bmRnZXLDvHN0?= In-Reply-To: <1322932853-21843-1-git-send-email-kevin@tyndur.org> References: <1322932853-21843-1-git-send-email-kevin@tyndur.org> Message-ID: <1322932853-21843-2-git-send-email-kevin@tyndur.org> + kernel2: LIOv2-Datenstrukturen zur Verwaltung von Verzeichnisbäumen + kernel2: Funktionen zur Verwaltung der Userspace-Deskriptoren für LIOv2-Kernelobjekte Signed-off-by: Kevin Wolf --- src/include/syscall_structs.h | 3 + src/kernel2/include/lostio/core.h | 82 +++++++++++++++++ src/kernel2/include/tasks.h | 4 + src/kernel2/src/init.c | 4 + src/kernel2/src/lostio/include/lostio_int.h | 132 +++++++++++++++++++++++++++ src/kernel2/src/lostio/lostio.c | 46 +++++++++ src/kernel2/src/lostio/userspace.c | 130 ++++++++++++++++++++++++++ src/kernel2/src/tasks/pm.c | 5 + 8 files changed, 406 insertions(+), 0 deletions(-) create mode 100644 src/kernel2/include/lostio/core.h create mode 100644 src/kernel2/src/lostio/include/lostio_int.h create mode 100644 src/kernel2/src/lostio/lostio.c create mode 100644 src/kernel2/src/lostio/userspace.c diff --git a/src/include/syscall_structs.h b/src/include/syscall_structs.h index 6ec63a0..ab2ec95 100644 --- a/src/include/syscall_structs.h +++ b/src/include/syscall_structs.h @@ -82,6 +82,9 @@ typedef int64_t lio_usp_stream_t; /** ID einer LostIO-Ressource */ typedef int64_t lio_usp_resource_t; +/** ID eines LostIO-Verzeichnisbaums */ +typedef int64_t lio_usp_tree_t; + /** * Beschreibt als Bitmaske den Modus, in dem ein Stream arbeiten soll. */ diff --git a/src/kernel2/include/lostio/core.h b/src/kernel2/include/lostio/core.h new file mode 100644 index 0000000..b1183b4 --- /dev/null +++ b/src/kernel2/include/lostio/core.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2008 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOSTIO_CORE_H_ +#define _LOSTIO_CORE_H_ + +#include +#include +#include +#include + +struct lio_resource; +struct lio_tree; + +struct lio_stream { + struct lio_resource* res; + + struct lio_resource* res_read; + uint64_t pos_read; + struct lio_resource* res_write; + uint64_t pos_write; + + int flags; + bool eof; +}; + +struct lio_usp_stream { + struct lio_stream* stream; + + /** Id des Streams fuer Userspace-Programme */ + lio_usp_stream_t usp_id; + + /** Sortierung nach usp_id im Baum */ + struct tree_item usp_item; +}; + +struct lio_node { + struct lio_resource* res; + + // Fuer den Wurzelknoten eines Baums ist der Name der Pfad der Quelle und + // hoert mit einem / auf (z.B. ata:/ata00p0|ext2:/) + char* name; +}; + +/** + * Initialisiert interne Datenstrukturen für LostIO + */ +void lio_init(void); + +#endif diff --git a/src/kernel2/include/tasks.h b/src/kernel2/include/tasks.h index 04d6b41..5256e0f 100644 --- a/src/kernel2/include/tasks.h +++ b/src/kernel2/include/tasks.h @@ -107,6 +107,10 @@ typedef struct pm_process { /// Speicherverbrauch des Prozesses uintmax_t memory_used; + + /// Baum aller geoeffneten LostIO-Streams + tree_t* lio_streams; + } pm_process_t; typedef struct { diff --git a/src/kernel2/src/init.c b/src/kernel2/src/init.c index c92a10f..9ad5d0b 100644 --- a/src/kernel2/src/init.c +++ b/src/kernel2/src/init.c @@ -52,6 +52,7 @@ #include "lock.h" #include "gdt.h" #include "timer.h" +#include "lostio/core.h" struct multiboot_info multiboot_info; @@ -270,6 +271,9 @@ void init(int multiboot_magic, struct multiboot_info *boot_info, bool bsp) // Timer initialisieren timer_init(); + // LostIO initialisieren + lio_init(); + // Init-Modul laden debug_print(DEBUG_FLAG_INIT, "Lade Module"); load_init_module(&multiboot_info); diff --git a/src/kernel2/src/lostio/include/lostio_int.h b/src/kernel2/src/lostio/include/lostio_int.h new file mode 100644 index 0000000..45630bc --- /dev/null +++ b/src/kernel2/src/lostio/include/lostio_int.h @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2008 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LOSTIO_INT_H +#define LOSTIO_INT_H + +#include +#include + +#include "lostio/core.h" +#include "tasks.h" + +struct lio_service; + +/** + * Beschreibt eine von LostIO verwaltete Ressource (d.h. in der Regel eine + * Datei). Alle Informationen, die nicht für einen bestimmten Client + * spezifisch sind, werden hier gespeichert. + */ +struct lio_resource { + + /** Verzeichnisbaum, zu dem die Ressource gehört */ + struct lio_tree* tree; + + /** + * Verzeichniseinträge (struct lio_node), falls die Ressource ein + * Verzeichnis ist + */ + list_t* children; + + /** Größe der Ressource in Bytes */ + uint64_t size; + + /** + * Die Blockgröße ist die kleinste Einheit, in der Anfragen an den + * Service gemacht werden. Sie wird auch intern für den Cache verwendet. + * Nur Zweierpotenzen; block_size * LIO_CLUSTER_SIZE sollte durch PAGE_SIZE + * teilbar sein. + */ + uint32_t blocksize; + + /* FIXME Sollte backendspezifisch sein */ + tree_t* dirty; + bool dirty_lock; + + /** Hat unterschiedliche Ressourcen fuer Lesen und Schreiben */ + bool ispipe; + + bool readable; + bool writable; + bool seekable; + bool moredata; + bool browsable; + bool changeable; + bool resolvable; + bool retargetable; + + /** Benutzt uebersetzungstabellen */ + bool translated; + + /** Id der Ressource fuer Userspace-Programme */ + lio_usp_resource_t usp_id; + + /** Sortierung nach usp_id im Baum */ + struct tree_item usp_item; + + /** Private Daten des Services */ + void* opaque; +}; + +struct lio_tree { + struct lio_node* root; + struct lio_service* service; + struct lio_stream* source; + + lio_usp_tree_t usp_id; + struct tree_item usp_item; +}; + + +/** + * Initialisiert die Verwaltung der Userspace-Deskriptoren für Kernelobjekte + */ +int lio_init_userspace(void); + +void lio_usp_add_resource(struct lio_resource* res); +struct lio_resource* lio_usp_get_resource(lio_usp_resource_t id); +void lio_usp_remove_resource(struct lio_resource* res); + +struct lio_usp_stream* lio_usp_add_stream(pm_process_t* proc, + struct lio_stream* stream); +struct lio_usp_stream* lio_usp_get_stream(pm_process_t* proc, + lio_usp_stream_t id); +void lio_usp_remove_stream(pm_process_t* proc, struct lio_usp_stream* stream); +void lio_usp_add_tree(struct lio_tree* tree); +void lio_usp_remove_tree(struct lio_tree* tree); +struct lio_tree* lio_usp_get_tree(lio_usp_tree_t id); +lio_usp_resource_t lio_usp_get_id(struct lio_resource* res); + +#endif diff --git a/src/kernel2/src/lostio/lostio.c b/src/kernel2/src/lostio/lostio.c new file mode 100644 index 0000000..3843f4e --- /dev/null +++ b/src/kernel2/src/lostio/lostio.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2010 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include "lostio/core.h" +#include "lostio_int.h" + +void lio_init(void) +{ + lio_init_userspace(); + + return; +} diff --git a/src/kernel2/src/lostio/userspace.c b/src/kernel2/src/lostio/userspace.c new file mode 100644 index 0000000..23a8c16 --- /dev/null +++ b/src/kernel2/src/lostio/userspace.c @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include "lostio/core.h" +#include "lostio_int.h" + +static tree_t* resource_tree; +static tree_t* tree_tree; + +int lio_init_userspace(void) +{ + resource_tree = tree_create(struct lio_resource, usp_item, usp_id); + tree_tree = tree_create(struct lio_tree, usp_item, usp_id); + return 0; +} + +static lio_usp_resource_t new_resourceid(void) +{ + static lio_usp_resource_t prev_id = 0; + return ++prev_id; +} + +static lio_usp_stream_t new_streamid(void) +{ + static lio_usp_stream_t prev_id = 0; + return ++prev_id; +} + +static lio_usp_tree_t new_treeid(void) +{ + static lio_usp_tree_t prev_id = 0; + return ++prev_id; +} + + +void lio_usp_add_resource(struct lio_resource* res) +{ + res->usp_id = new_resourceid(); + tree_insert(resource_tree, res); +} + +struct lio_resource* lio_usp_get_resource(lio_usp_resource_t id) +{ + return tree_search(resource_tree, id); +} + + +void lio_usp_remove_resource(struct lio_resource* res) +{ + tree_remove(resource_tree, res); +} + +struct lio_usp_stream* lio_usp_add_stream(pm_process_t* proc, + struct lio_stream* stream) +{ + struct lio_usp_stream* entry = malloc(sizeof(*entry)); + + entry->stream = stream; + entry->usp_id = new_streamid(); + + tree_insert(proc->lio_streams, entry); + return entry; +} + +struct lio_usp_stream* lio_usp_get_stream(pm_process_t* proc, + lio_usp_stream_t id) +{ + return tree_search(proc->lio_streams, id); +} + +void lio_usp_remove_stream(pm_process_t* proc, struct lio_usp_stream* stream) +{ + tree_remove(proc->lio_streams, stream); + free(stream); +} + +void lio_usp_add_tree(struct lio_tree* tree) +{ + tree->usp_id = new_treeid(); + tree_insert(tree_tree, tree); +} + +void lio_usp_remove_tree(struct lio_tree* tree) +{ + tree_remove(tree_tree, tree); +} + +struct lio_tree* lio_usp_get_tree(lio_usp_tree_t id) +{ + return tree_search(tree_tree, id); +} + +lio_usp_resource_t lio_usp_get_id(struct lio_resource* res) +{ + return res->usp_id; +} diff --git a/src/kernel2/src/tasks/pm.c b/src/kernel2/src/tasks/pm.c index 846323a..8f887b9 100644 --- a/src/kernel2/src/tasks/pm.c +++ b/src/kernel2/src/tasks/pm.c @@ -44,6 +44,7 @@ #include "tasks.h" #include "lock.h" #include "timer.h" +#include "lostio/core.h" struct on_destroy_info { @@ -166,6 +167,10 @@ pm_process_t* pm_create(pm_process_t* parent, const char* cmdline) process->rpc_handler = NULL; process->rpcs = list_create(); + // Dateiliste initialisieren + process->lio_streams = + tree_create(struct lio_usp_stream, usp_item, usp_id); + list_push(process_list, process); process->memory_used = 0; -- 1.6.0.2 From kevin at tyndur.org Sat Dec 3 18:20:50 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 3 Dec 2011 18:20:50 +0100 Subject: [tyndur-devel] [RFC PATCH 2/5] kernel2: Zentrale LIOv2-Clientfunktionen In-Reply-To: <1322932853-21843-1-git-send-email-kevin@tyndur.org> References: <1322932853-21843-1-git-send-email-kevin@tyndur.org> Message-ID: <1322932853-21843-3-git-send-email-kevin@tyndur.org> + kernel2: Alles, was ein Client so mit Ressourcen und Streams anstellen kann, ausgenommen die Ressource erstmal zu bekommen. Signed-off-by: Kevin Wolf --- src/kernel2/include/lostio/client.h | 188 ++++++++++ src/kernel2/src/lostio/client.c | 531 +++++++++++++++++++++++++++ src/kernel2/src/lostio/include/lostio_int.h | 91 +++++ 3 files changed, 810 insertions(+), 0 deletions(-) create mode 100644 src/kernel2/include/lostio/client.h create mode 100644 src/kernel2/src/lostio/client.c diff --git a/src/kernel2/include/lostio/client.h b/src/kernel2/include/lostio/client.h new file mode 100644 index 0000000..d3490f0 --- /dev/null +++ b/src/kernel2/include/lostio/client.h @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2008 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOSTIO_CLIENT_H_ +#define _LOSTIO_CLIENT_H_ + +#include "lostio/core.h" + +struct lio_dir_entry { + struct lio_resource* resource; + char name[LIO_MAX_FNLEN + 1]; + struct lio_stat stat; +}; + +/** + * Loest einen Pfad zu einer Ressource auf + * + * @return Die zum Pfad gehoerende Ressource oder NULL, wenn der Pfad keine + * existierende Ressource beschreibt. + */ +struct lio_resource* lio_get_resource(const char* path, int follow_symlinks); + +/** + * Oeffnet einen Stream zu einer Ressource + * + * @param flags Bitmaske für den Modus, in dem der Stream arbeiten soll (siehe + * enum lio_flags) + * + * @return Stream zur Ressource oder NULL, wenn die Ressource nicht erfolgreich + * geoeffnet werden konnte. + */ +struct lio_stream* lio_open(struct lio_resource* res, int flags); + +/** + * Liest aus einem Stream aus. + * + * @return Anzahl der gelesenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_read(struct lio_stream* s, size_t bytes, void* buf); + +/** + * Liest aus einem Stream aus, ohne die Position des streams zu benutzen oder + * zu veraendern. + * + * @return Anzahl der gelesenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_pread(struct lio_stream* s, uint64_t offset, size_t bytes, + void* buf); + +/** + * Schreibt in einen Stream + * + * @return Anzahl der geschriebenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_write(struct lio_stream* s, size_t bytes, const void* buf); + +/** + * Schreibt in einen Stream, ohne dabei die Position des Streams zu benutzen + * oder zu veraendern. + * + * @return Anzahl der geschriebenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_pwrite(struct lio_stream* s, uint64_t offset, size_t bytes, + const void* buf); + +/** + * Position veraendern. Funktioniert nur, wenn die Ressource seekable ist, und + * es sich um keine Pipe handelt. + * + * @param offset Offset um den die Position angepasst werden soll. Wie sie genau + * angepasst wird, haengt vom Parameter whence ab. + * @param whence Einer der drei Werte aus enum lio_seek_whence. + * - LIO_SEEK_SET: Position auf den angegebenen Wert setzen. + * - LIO_SEEK_CUR: Angegebenen Wert zur aktuellen Position + * dazu addieren. + * - LIO_SEEK_END: Position auf das Dateiende setzen. + * + * @return Neue Position oder < 0 im Fehlerfall. + */ +int64_t lio_seek(struct lio_stream* s, int64_t offset, int whence); + +/** + * Schreibt Aenderungen, die bisher nur im Cache sind, zurueck. Dabei werden + * nur die Cluster beruecksichtigt, die im angegebenen Bereich liegen. + * + * @param s Stream, dessen Aendungen geschrieben werden sollen + * @param offset Start des zurueckzuschreibenden Bereichs (in Bytes) + * @param bytes Laenge des zurueckzuschreibenden Bereichs (in Bytes) oder 0, + * falls die gesamte Datei zurueckgeschrieben werden soll + * + * @return 0 bei Erfolg, ungleich 0 im Fehlerfall + * + * @attention Diese Funktion ist unterbrechbar + */ +int lio_sync_blocks(struct lio_resource* res, uint64_t offset, size_t bytes); + +/** + * Schreibt alle zum Zeitpunkt des Aufrufs der Funktion vorhandenen + * Aenderungen, die bisher nur im Cache sind, zurueck + * + * @return 0 bei Erfolg, ungleich 0 im Fehlerfall + * @attention Diese Funktion ist unterbrechbar + */ +int lio_sync(struct lio_stream* s); + +/** + * Alle veraenderten Blocks im Cache rausschreiben + * + * @param soft Wenn true, wird nicht blockiert, wenn ein Cluster nicht gesynct + * werden kann. Es wird auch kein Fehler zurückgegeben. (Ziel ist es, einfach + * irgendwelche Dirty-Cluster loszuwerden) + * + * @return 0 bei Erfolg, -errno im Fehlerfall + */ +int lio_sync_all(bool soft); + +/** + * Aendert die Dateigroesse + * + * @param size Neue Dateigroesse + * @return 0 bei Erfolg, negativ im Fehlerfall + */ +int lio_truncate(struct lio_stream* s, uint64_t size); + +/** + * Schliesst einen Stream + * + * @return 0 bei Erfolg, ungleich 0 im Fehlerfall + */ +int lio_close(struct lio_stream* s); + +/** + * Inhalt eines Verzeichnisses auslesen + */ +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); + +/** Erstellt ein neues Verzeichnis */ +struct lio_resource* lio_mkdir(struct lio_resource* parent, const char* name); + +/** Erstellt einen neuen Symlink */ +struct lio_resource* lio_mksymlink(struct lio_resource* parent, + const char* name, const char* target); + +/** + * Gibt Informationen zu einer Ressource zurueck + */ +int lio_stat(struct lio_resource* resource, struct lio_stat* sbuf); + +/** Verzeichniseintrag loeschen */ +int lio_unlink(struct lio_resource* parent, const char* name); + +#endif diff --git a/src/kernel2/src/lostio/client.c b/src/kernel2/src/lostio/client.c new file mode 100644 index 0000000..f87c6fa --- /dev/null +++ b/src/kernel2/src/lostio/client.c @@ -0,0 +1,531 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include "kernel.h" +#include "kprintf.h" + +#include "lostio/client.h" +#include "lostio_int.h" + +/** + * Loest einen Pfad zu einer Ressource auf + * + * @return Die zum Pfad gehoerende Ressource oder NULL, wenn der Pfad keine + * existierende Ressource beschreibt. + */ +struct lio_resource* lio_get_resource(const char* path, int follow_symlinks) +{ + /* TODO */ + return NULL; +} + +/** + * Oeffnet einen Stream zu einer Ressource + * + * @param flags Bitmaske für den Modus, in dem der Stream arbeiten soll (siehe + * enum lio_flags) + * + * @return Stream zur Ressource oder NULL, wenn die Ressource nicht erfolgreich + * geoeffnet werden konnte. + */ +struct lio_stream* lio_open(struct lio_resource* res, int flags) +{ + struct lio_stream* s; + + if (res == NULL) { + return NULL; + } + + // Nur lesbare Ressourcen duerfen mit dem LIO_READ-Flag geoeffnet werden, + // und nur Schreibbare mit LIO_WRITE oder LIO_TRUNC. + bool symlink = !!(flags & LIO_SYMLINK); + if (((flags & LIO_READ) && !res->readable && !symlink) || + ((flags & (LIO_WRITE | LIO_TRUNC) && !res->writable && !symlink)) || + ((flags & LIO_READ) && !res->resolvable && symlink) || + ((flags & (LIO_WRITE | LIO_TRUNC) && !res->retargetable && symlink))) + { + return NULL; + } + + // Symlinks duerfen nur als solche geoeffnet werden + if (res->resolvable && !(flags & LIO_SYMLINK)) { + return NULL; + } + + // Stream anlegen und initialisieren + s = calloc(1, sizeof(*s)); + s->res = s->res_read = s->res_write = res; + s->flags = flags; + s->eof = false; + + if (res->tree->service->lio_ops.preopen && + res->tree->service->lio_ops.preopen(s)) + { + goto fail; + } + + + // Datei leeren, wenn LIO_TRUNC gesetzt ist + if (flags & LIO_TRUNC) { + if (lio_truncate(s, 0) < 0) { + goto fail; + } + } + + return s; + +fail: + free(s); + return NULL; +} + +/** + * Liest aus einem Stream aus. + * + * @return Anzahl der gelesenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_read(struct lio_stream* s, size_t bytes, void* buf) +{ + ssize_t result; + + result = lio_pread(s, s->pos_read, bytes, buf); + if (result > 0) { + s->pos_read += result; + } + + return result; +} + +/** + * Liest aus einem Stream aus, ohne die Position des streams zu benutzen oder + * zu veraendern. + * + * @return Anzahl der gelesenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_pread(struct lio_stream* s, uint64_t offset, size_t bytes, + void* buf) +{ + ssize_t ret = 0; + struct lio_resource* res; + + // Stream muss existieren und zum Lesen geoeffnet sein + if (!s || (s->flags & LIO_READ) == 0) { + return -EBADF; + } + + res = s->res_read; + + // Position pruefen + if (offset >= res->size) { + if (res->moredata) { + return -EAGAIN; + } + return 0; + } + + // Abschneiden, wenn ueber das Dateiende hinausgelesen wird + if (offset + bytes > res->size) { + bytes = res->size - offset; + } + + // Daten einlesen + uint64_t offset_aligned = ROUND_TO_BLOCK_DOWN(offset, res->blocksize); + size_t bytes_aligned = ROUND_TO_NEXT_BLOCK( + bytes + (offset - offset_aligned), res->blocksize); + + struct lio_driver* drv = &res->tree->service->lio_ops; + uint8_t* bounce = malloc(bytes_aligned); + uint8_t* p = bounce; + uint64_t curoffset = offset_aligned; + + ret = drv->read(res, curoffset, bytes_aligned, p); + if (ret >= 0) { + ret = bytes; + memcpy(buf, bounce + (offset - offset_aligned), ret); + } + + free(bounce); + + return ret; +} + +/** + * Schreibt in einen Stream + * + * @return Anzahl der geschriebenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_write(struct lio_stream* s, size_t bytes, const void* buf) +{ + ssize_t result; + uint64_t pos; + + pos = ((s->res_read == s->res_write) ? s->pos_read : s->pos_write); + + result = lio_pwrite(s, pos, bytes, buf); + if (result > 0) { + if (s->res_read == s->res_write) { + s->pos_read += result; + } else { + s->pos_write += result; + } + } + + return result; +} + +/** + * Schreibt in einen Stream, ohne dabei die Position des Streams zu benutzen + * oder zu veraendern. + * + * @return Anzahl der geschriebenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_pwrite(struct lio_stream* s, uint64_t offset, size_t bytes, + const void* buf) +{ + ssize_t ret; + struct lio_resource* res; + + // Stream muss existieren und zum Schreiben geoeffnet sein + if (!s || (s->flags & LIO_WRITE) == 0) { + return -EBADF; + } + + res = s->res_write; + if (!res->writable && (!(s->flags & LIO_SYMLINK) || !res->retargetable)) { + return -EBADF; + } + + // Falls noetig Ressource vergroessern + if ((offset + bytes) > res->size) { + ret = lio_truncate(s, offset + bytes); + if (ret < 0) { + return ret; + } + } + + // Daten einlesen + uint64_t offset_aligned = ROUND_TO_BLOCK_DOWN(offset, res->blocksize); + size_t bytes_aligned = ROUND_TO_NEXT_BLOCK( + bytes + (offset - offset_aligned), res->blocksize); + + struct lio_driver* drv = &res->tree->service->lio_ops; + uint8_t* bounce = calloc(1, bytes_aligned); + uint8_t* p = bounce; + uint64_t curoffset = offset_aligned; + int old_flags; + + old_flags = s->flags; + s->flags |= LIO_READ; + ret = lio_pread(s, offset_aligned, bytes_aligned, bounce); + s->flags = old_flags; + + if (ret < 0) { + goto out; + } + memcpy(bounce + (offset - offset_aligned), buf, bytes); + + ret = drv->write(res, curoffset, bytes_aligned, p); + if (ret >= 0) { + ret = bytes; + } + + // Offset zeigt jetzt auf das erste Byte nach dem letzten geschriebenen + if (ret > 0){ + if (res->size < offset) { + res->size = offset; + } + } + +out: + free(bounce); + return ret; +} + +/** + * Position veraendern. Funktioniert nur, wenn die Ressource seekable ist, und + * es sich um keine Pipe handelt. + * + * @param offset Offset um den die Position angepasst werden soll. Wie sie genau + * angepasst wird, haengt vom Parameter whence ab. + * @param whence Einer der drei Werte aus enum lio_seek_whence. + * - LIO_SEEK_SET: Position auf den angegebenen Wert setzen. + * - LIO_SEEK_CUR: Angegebenen Wert zur aktuellen Position + * dazu addieren. + * - LIO_SEEK_END: Position auf das Dateiende setzen. + * + * @return Neue Position oder < 0 im Fehlerfall. + */ +int64_t lio_seek(struct lio_stream* s, int64_t offset, int whence) +{ + if ((s->res_read != s->res_write) || !s->res_read->seekable) { + return -EINVAL; + } + + switch (whence) { + case LIO_SEEK_SET: + if (offset < 0) { + return -EINVAL; + } else { + s->pos_read = offset; + } + break; + + case LIO_SEEK_CUR: + if ((int64_t)(s->pos_read + offset) < 0) { + return -EINVAL; + } else { + s->pos_read += offset; + } + break; + + case LIO_SEEK_END: + if ((int64_t)(s->res_read->size + offset) < 0) { + return -EINVAL; + } else { + s->pos_read = s->res_read->size + offset; + } + break; + default: + return -EINVAL; + } + + return s->pos_read; +} + +/** + * Schreibt Aenderungen, die bisher nur im Cache sind, zurueck. Dabei werden + * nur die Cluster beruecksichtigt, die im angegebenen Bereich liegen. + * + * @param s Stream, dessen Aendungen geschrieben werden sollen + * @param offset Start des zurueckzuschreibenden Bereichs (in Bytes) + * @param bytes Laenge des zurueckzuschreibenden Bereichs (in Bytes) oder 0, + * falls die gesamte Datei zurueckgeschrieben werden soll + * + * @return 0 bei Erfolg, ungleich 0 im Fehlerfall + * + * @attention Diese Funktion ist unterbrechbar + */ +int lio_sync_blocks(struct lio_resource* res, uint64_t offset, size_t bytes) +{ + return 0; +} + +/** + * Schreibt alle zum Zeitpunkt des Aufrufs der Funktion vorhandenen + * Aenderungen, die bisher nur im Cache sind, zurueck + * + * @return 0 bei Erfolg, ungleich 0 im Fehlerfall + * @attention Diese Funktion ist unterbrechbar + */ +int lio_sync(struct lio_stream* s) +{ + struct lio_resource* res = s->res_write; + struct lio_driver* drv = &res->tree->service->lio_ops; + + /* + * TODO Muss z.B. ata nochmal gesynct werden, nachdem ext2 dran war? Ist es + * Aufgabe des Treibers oder von LIO? + */ + if (drv->sync) { + drv->sync(res); + } + + return 0; +} + +/** + * Alle veraenderten Blocks im Cache rausschreiben + * + * @param soft Wenn true, wird nicht blockiert, wenn ein Cluster nicht gesynct + * werden kann. Es wird auch kein Fehler zurückgegeben. (Ziel ist es, einfach + * irgendwelche Dirty-Cluster loszuwerden) + * + * @return 0 bei Erfolg, -errno im Fehlerfall + */ +int lio_sync_all(bool soft) +{ + return 0; +} + +/** + * Aendert die Dateigroesse + * + * @param size Neue Dateigroesse + * @return 0 bei Erfolg, negativ im Fehlerfall + */ +int lio_truncate(struct lio_stream* s, uint64_t size) +{ + struct lio_resource* res = s->res_write; + struct lio_driver* drv = &res->tree->service->lio_ops; + + /* Zunaechst den Treiber informieren */ + if (drv->truncate) { + int ret = drv->truncate(res, size); + if (ret < 0) { + return ret; + } + } + + /* Anschliessend die Ressourcengroesse anpassen (drv->truncate kann das + * u.U. auch schon gemacht haben) */ + res->size = size; + + return 0; +} + +/** + * Schliesst einen Stream + * + * @return 0 bei Erfolg, ungleich 0 im Fehlerfall + */ +int lio_close(struct lio_stream* s) +{ + if (s->res->tree->service->lio_ops.close) { + s->res->tree->service->lio_ops.close(s); + } + + free(s); + return 0; +} + +/** + * Inhalt eines Verzeichnisses auslesen + */ +ssize_t lio_read_dir(struct lio_resource* dir, size_t start, size_t num, + struct lio_dir_entry* buf) +{ + struct lio_node* node; + size_t cnt = 0; + + /* Die Ressource muss auch wirklich ein Verzeichnis sein */ + if (!dir->browsable) { + return -EBADF; + } + + /* Wenn der Aufrufer keine Eintraege will, sind wir fertig */ + if (!num) { + return 0; + } + + /* Zunaechst kommt der Eintrag fuer . */ + if (start == 0) { + strcpy(buf[0].name, "."); + buf[0].resource = dir; + lio_stat(dir, &buf[0].stat); + cnt++; + } + + /* Und dann der ganzer Rest */ + if (!dir->children) { + dir->tree->service->lio_ops.load_children(dir); + } + + for (; (cnt < num) && + (node = list_get_element_at(dir->children, start - 1 + cnt));) + { + buf[cnt].resource = node->res; + strncpy(buf[cnt].name, node->name, LIO_MAX_FNLEN); + buf[cnt].name[LIO_MAX_FNLEN] = 0; + lio_stat(node->res, &buf[cnt].stat); + cnt++; + } + + return cnt; +} + +/** Erstellt eine neue Datei */ +struct lio_resource* lio_mkfile(struct lio_resource* parent, const char* name) +{ + if (!parent->tree->service->lio_ops.make_file || !parent->changeable) { + return NULL; + } + + return parent->tree->service->lio_ops.make_file(parent, name); +} + +/** Erstellt ein neues Verzeichnis */ +struct lio_resource* lio_mkdir(struct lio_resource* parent, const char* name) +{ + if (!parent->tree->service->lio_ops.make_dir || !parent->changeable) { + return NULL; + } + + return parent->tree->service->lio_ops.make_dir(parent, name); +} + +/** Erstellt einen neuen Symlink */ +struct lio_resource* lio_mksymlink(struct lio_resource* parent, + const char* name, const char* target) +{ + if (!parent->tree->service->lio_ops.make_symlink || !parent->changeable) { + return NULL; + } + + return parent->tree->service->lio_ops.make_symlink(parent, name, target); +} + +/** + * Gibt Informationen zu einer Ressource zurueck + */ +int lio_stat(struct lio_resource* resource, struct lio_stat* sbuf) +{ + memset(sbuf, 0, sizeof(*sbuf)); + sbuf->size = resource->size; + + sbuf->flags = (resource->readable ? LIO_FLAG_READABLE : 0) | + (resource->writable ? LIO_FLAG_WRITABLE : 0) | + (resource->browsable ? LIO_FLAG_BROWSABLE : 0) | + (resource->changeable ? LIO_FLAG_CHANGEABLE : 0) | + (resource->resolvable ? LIO_FLAG_RESOLVABLE : 0) | + (resource->retargetable ? LIO_FLAG_RETARGETABLE : 0) | + (resource->seekable ? LIO_FLAG_SEEKABLE : 0) | + (resource->ispipe ? LIO_FLAG_PIPE : 0); + return 0; +} + +/** Verzeichniseintrag loeschen */ +int lio_unlink(struct lio_resource* parent, const char* name) +{ + if (!parent->tree->service->lio_ops.unlink) { + return -EINVAL; + } + + return parent->tree->service->lio_ops.unlink(parent, name); +} + diff --git a/src/kernel2/src/lostio/include/lostio_int.h b/src/kernel2/src/lostio/include/lostio_int.h index 45630bc..c7a511f 100644 --- a/src/kernel2/src/lostio/include/lostio_int.h +++ b/src/kernel2/src/lostio/include/lostio_int.h @@ -42,7 +42,98 @@ #include "lostio/core.h" #include "tasks.h" +#define ROUND_TO_NEXT_BLOCK(bytes, blocksize) \ + ((bytes) + (blocksize) - 1) & ~((blocksize) - 1) +#define ROUND_TO_BLOCK_DOWN(bytes, blocksize) \ + ((bytes)) & ~((blocksize) - 1) + struct lio_service; +struct lio_driver { + /** + * Laedt alle Kindknoten nach res->children + */ + int (*load_children)(struct lio_resource* res); + + /** + * Wird aufgerufen wenn eine Ressource geoeffnet wird. + * + * @return 0 bei Erfolg, negativ bei Fehlern. Bei einem Fehler wird das + * Oeffnen abgebrochen. + */ + int (*preopen)(struct lio_stream* stream); + + /** Stream wird geschlossen */ + void (*close)(struct lio_stream* stream); + + /** Erstellt eine neue Datei */ + struct lio_resource* (*make_file)(struct lio_resource* parent, + const char* name); + + /** Erstellt ein neues Verzeichnis */ + struct lio_resource* (*make_dir)(struct lio_resource* parent, + const char* name); + + /** Erstellt einen neuen Symlink */ + struct lio_resource* (*make_symlink)(struct lio_resource* parent, + const char* name, const char* target); + + /** Verzeichniseintrag loeschen */ + int (*unlink)(struct lio_resource* parent, const char* name); + + /** + * Laedt Daten vom Service in den Cache. + * offset und bytes muessen auf die Blockgroesse ausgerichtet sein. + * + * @return 0 bei Erfolg (Puffer ist komplett gelesen), negativ im + * Fehlerfall. + * + * TODO iovec statt bytes/buf + */ + int (*read)(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf); + + /** + * Schreibt Daten aus dem Cache in den Service zurueck + * offset und bytes muessen auf die Blockgroesse ausgerichtet sein. + * + * @return 0 bei Erfolg (Puffer ist komplett geschrieben), negativ im + * Fehlerfall. + * + * TODO iovec statt bytes/buf + */ + int (*write)(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf); + + /** Schreibt eventuelle im Treiber gecachte Daten zurueck */ + int (*sync)(struct lio_resource* res); + + /** + * Setzt die Dateigroesse. + * + * Diese Funktion wird auch aufgerufen, bevor eine Datei durch einen + * Schreibzugriff vergroessert wird. Ein Service kann write()-Aufrufe + * hinter dem Dateiende verwerfen. + */ + int (*truncate)(struct lio_resource* res, uint64_t size); + +}; + + +/** + * Beschreibt einen LostIO-Service. + */ +struct lio_service { + /** Eindeutiger Name des Service */ + char* name; + + /** Funktionspointer, die den eigentlichen Treiber implementieren */ + struct lio_driver lio_ops; + + /** Private Daten des Services */ + void* opaque; +}; + + /** * Beschreibt eine von LostIO verwaltete Ressource (d.h. in der Regel eine -- 1.6.0.2 From kevin at tyndur.org Sat Dec 3 18:20:51 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 3 Dec 2011 18:20:51 +0100 Subject: [tyndur-devel] =?utf-8?q?=5BRFC_PATCH_3/5=5D_kernel2=3A_Ressource?= =?utf-8?q?n_und_Verzeichnisb=C3=A4ume?= In-Reply-To: <1322932853-21843-1-git-send-email-kevin@tyndur.org> References: <1322932853-21843-1-git-send-email-kevin@tyndur.org> Message-ID: <1322932853-21843-4-git-send-email-kevin@tyndur.org> + kernel2: Funktionen zur Verwaltung von Services, Verzeichnisbäumen und Ressourcen Signed-off-by: Kevin Wolf --- src/kernel2/src/lostio/client.c | 105 ++++++++- src/kernel2/src/lostio/include/lostio_int.h | 74 ++++++ src/kernel2/src/lostio/lostio.c | 1 + src/kernel2/src/lostio/tree.c | 365 +++++++++++++++++++++++++++ 4 files changed, 543 insertions(+), 2 deletions(-) create mode 100644 src/kernel2/src/lostio/tree.c diff --git a/src/kernel2/src/lostio/client.c b/src/kernel2/src/lostio/client.c index f87c6fa..43baadf 100644 --- a/src/kernel2/src/lostio/client.c +++ b/src/kernel2/src/lostio/client.c @@ -44,6 +44,35 @@ #include "lostio_int.h" /** + * Versucht den uebergebenen Symlink aufzuloesen. Wenn die Resource, auf die er + * Zeigt, existiert wird ein Zeiger darauf zurueckgegeben, NULL sonst. + * + * @return Zeiger auf das Ziel, oder NULL falls der Link nicht aufgeloest werden + * konnte. + */ +static struct lio_resource* resolve_symlink(struct lio_resource* link) +{ + char buf[link->size + 1]; + struct lio_stream* stream; + ssize_t len; + + if (!(stream = lio_open(link, LIO_READ | LIO_SYMLINK))) { + return NULL; + } + + len = lio_read(stream, link->size, buf); + lio_close(stream); + + if (len < 0) { + return NULL; + } + buf[len] = 0; + + // TODO: Relative Symlinks + return lio_get_resource(buf, 1); +} + +/** * Loest einen Pfad zu einer Ressource auf * * @return Die zum Pfad gehoerende Ressource oder NULL, wenn der Pfad keine @@ -51,8 +80,80 @@ */ struct lio_resource* lio_get_resource(const char* path, int follow_symlinks) { - /* TODO */ - return NULL; + struct lio_tree* tree; + struct lio_resource* res; + struct lio_node* node; + const char* rel_path; + char* tokenize_path; + char* name; + int i; + + // Passenden Baum raussuchen + tree = lio_get_tree(path, &rel_path); + if (tree == NULL) { + return NULL; + } + + node = tree->root; + + // Von der Wurzel aus durchhangeln + char* saveptr; + tokenize_path = strdup(rel_path); + name = strtok_r(tokenize_path, "/", &saveptr); + while (name != NULL) { + res = node->res; + + // Falls wir es mit einem Symlink zu tun haben, versuchen wir doch mal + // dem zu folgen. + if (res->resolvable) { + res = resolve_symlink(res); + + // War wohl nix + if (!res) { + goto out; + } + } + + tree = res->tree; + + // Wir suchen noch ein Kind, aber diese Ressource hat keine + if (!res->browsable) { + res = NULL; + goto out; + } + + // Falls die Liste der Kinder nicht geladen ist, nachholen + if (res->children == NULL) { + if (tree->service->lio_ops.load_children(res)) { + res = NULL; + goto out; + } + } + + // Passendes Kind raussuchen + for (i = 0; (node = list_get_element_at(res->children, i)); i++) { + if (strcmp(node->name, name) == 0) { + goto found; + } + } + res = NULL; + goto out; + +found: + // Passender Kindknoten wurde gefunden, weiter im Pfad + name = strtok_r(NULL, "/", &saveptr); + } + + res = node->res; + + // Auch das koennte noch mal ein Symlink sein, den wir aufloesen muessen + if (res && follow_symlinks && res->resolvable) { + res = resolve_symlink(res); + } + +out: + free(tokenize_path); + return res; } /** diff --git a/src/kernel2/src/lostio/include/lostio_int.h b/src/kernel2/src/lostio/include/lostio_int.h index c7a511f..67343b1 100644 --- a/src/kernel2/src/lostio/include/lostio_int.h +++ b/src/kernel2/src/lostio/include/lostio_int.h @@ -50,6 +50,12 @@ struct lio_service; struct lio_driver { /** + * Root-Ressource eines Dateisystems laden, das root-Feld in tree ist also + * noch NULL. + */ + struct lio_resource* (*load_root)(struct lio_tree* tree); + + /** * Laedt alle Kindknoten nach res->children */ int (*load_children)(struct lio_resource* res); @@ -202,10 +208,78 @@ struct lio_tree { /** + * Initialisiert die statischen Variablen von tree.c + */ +int lio_init_tree(void); + +/** * Initialisiert die Verwaltung der Userspace-Deskriptoren für Kernelobjekte */ int lio_init_userspace(void); +/** + * Neue Ressource initialisieren. + * Vom Aufrufer initialisiert werden muessen (werden alle auf 0 initialisiert): + * - blocksize + * - tree + * - Flags + * + * @return Zeiger auf die neue Ressource + */ +struct lio_resource* lio_create_resource(void); + +/** + * Interne Daten einer Ressource initialisieren. Dabei werden nur die internen + * Felder veraendert, der Rest muss vom Aufrufer gesetzt werden. Diese Funktion + * kann verwendet werden, wenn der Speicher fuer eine Resource bereits + * verfuegbar ist (beispielsweise bei statischem Speicher). + * + * @param res Zu initialisierende Ressource + */ +void lio_init_resource(struct lio_resource* res); + +/** + * Ressource zerstören und Speicher freigeben. Der Aufrufer ist dafür + * zuständig, allenfalls Caches zu syncen. + * + * @param res Zu zerstoerende Ressource + */ +void lio_destroy_resource(struct lio_resource* res); + +/** + * Loest einen gegebenen Pfad in einen Verzeichnisbaum und einen + * servicerelativen Pfad auf. + * + * @param path Aufzulosender Pfad + * @param rel_path Wenn rel_path != NULL ist, wird darin ein Pointer auf den + * servicerelativen Teil des Pfads zurueckgegeben + * + * @return Den zum Pfad gehoerenden Verzeichnisbaum oder NULL im Fehlerfall + */ +struct lio_tree* lio_get_tree(const char* path, const char** rel_path); + +/** + * Registriert einen neuen LIO-Service + */ +void lio_add_service(struct lio_service* service); + +/** Kindknoten einer Ressource suchen */ +struct lio_node* lio_resource_get_child(struct lio_resource* parent, + const char* name); + +/** Einer Resource einen Kindknoten anfuegen */ +void lio_resource_add_child(struct lio_resource* parent, + struct lio_node* child); + +/** Kindknoten einer Ressource entfernen */ +void lio_resource_remove_child(struct lio_resource* parent, + struct lio_node* child); + +/** Neuen Knoten anlegen und bei Elternressource als Kind eintragen */ +struct lio_node* lio_create_node(struct lio_resource* parent, + struct lio_resource* res, const char* name); + + void lio_usp_add_resource(struct lio_resource* res); struct lio_resource* lio_usp_get_resource(lio_usp_resource_t id); void lio_usp_remove_resource(struct lio_resource* res); diff --git a/src/kernel2/src/lostio/lostio.c b/src/kernel2/src/lostio/lostio.c index 3843f4e..9a08d58 100644 --- a/src/kernel2/src/lostio/lostio.c +++ b/src/kernel2/src/lostio/lostio.c @@ -40,6 +40,7 @@ void lio_init(void) { + lio_init_tree(); lio_init_userspace(); return; diff --git a/src/kernel2/src/lostio/tree.c b/src/kernel2/src/lostio/tree.c new file mode 100644 index 0000000..4078d52 --- /dev/null +++ b/src/kernel2/src/lostio/tree.c @@ -0,0 +1,365 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include "kernel.h" +#include "kprintf.h" + +#include "lostio/core.h" +#include "lostio/client.h" +#include "lostio_int.h" + +static list_t* lio_trees; +static list_t* lio_services; + +/** + * Initialisiert die statischen Variablen dieser Datei + */ +int lio_init_tree(void) +{ + lio_trees = list_create(); + lio_services = list_create(); + + return 0; +} + +/** + * Erzeugt einen neuen Verzeichnisbaum. Das root-Feld im der Baum-Struktur muss + * vom Aufrufer eingefuellt werden. + * + * @param serv LIO-Service, der den Baum verwaltet + * @param source LIO-Stream der Datenquelle + * + * @return Den neu angelegten Baum oder NULL im Fehlerfall + */ +static struct lio_tree* lio_add_tree(struct lio_service* serv, + struct lio_stream* source) +{ + struct lio_tree* tree; + + // TODO Der Service sollte auch wirklich fuer den Pfad zustaendig sein + + // Neuen Baum anlegen und in die Liste pushen + tree = calloc(1, sizeof(*tree)); + tree->service = serv; + tree->source = source; + + lio_usp_add_tree(tree); + + return tree; +} + +/** + * Zerlegt einen Pfad. Die zwei uebergebenen Zeiger zeigen anschliessend auf + * den Namen des zustaendigen Services bzw. den Anfang des servicerelativen + * Pfads im Originalpfad. + * + * Im Fehlerfall (der Pfad enthaelt kein ":/") wird rel_path auf NULL gesetzt. + */ +static void split_path(const char* path, const char** service, + const char** rel_path) +{ + const char* service_name; + const char* tmp_rel_path; + + service_name = strrchr(path, '|'); + if (service_name == NULL) { + service_name = path; + } else { + service_name++; + } + + tmp_rel_path = strstr(service_name, ":/"); + if (tmp_rel_path != NULL) { + tmp_rel_path += 2; + } + + *service = service_name; + *rel_path = tmp_rel_path; +} + +/** + * Sucht den richtigen Service zur Verarbeitung eines Pfads und erzeugt einen + * neuen Verzeichnisbaum fuer diesen. + * + * @param path Pfad der zu oeffnenden Datei + * @param rel_path Wenn rel_path != NULL ist, wird darin ein Pointer auf den + * servicerelativen Teil des Pfads zurueckgegeben. + * + * @return Den neu angelegten Verzeichnisbaum oder NULL im Fehlerfall + */ +static struct lio_tree* mount(const char* path, const char** rel_path) +{ + struct lio_stream* source_stream; + struct lio_resource* source_res; + struct lio_service* service; + struct lio_resource* root_res; + struct lio_node* root_node; + struct lio_tree* tree; + const char* service_name; + const char* tmp_rel_path; + int i; + + // Pfad aufsplitten + split_path(path, &service_name, &tmp_rel_path); + + // Passenden Service suchen + for (i = 0; (service = list_get_element_at(lio_services, i)); i++) { + + size_t len = strlen(service->name); + + if (len != tmp_rel_path - 2 - service_name) { + continue; + } + + if (!strncmp(service->name, service_name, len)) { + goto found; + } + } + return NULL; + +found: + + // Quelle oeffnen + source_stream = NULL; + if (path == service_name) { + source_stream = NULL; + } else { + char* source; + source = malloc(service_name - path); + strncpy(source, path, service_name - path - 1); + source[service_name - path - 1] = '\0'; + + if (!(source_res = lio_get_resource(source, 1))) { + return NULL; + } + + // TODO: Was machen wir hier mit den Flags fuer fopen genau? + source_stream = lio_open(source_res, LIO_READ | LIO_WRITE); + free(source); + + if (source_stream == NULL) { + return NULL; + } + } + + tree = lio_add_tree(service, source_stream); + + // Wurzelressource laden + root_res = service->lio_ops.load_root(tree); + if (root_res == NULL) { + if (source_stream) { + lio_close(source_stream); + } + goto out_err; + } + + // Wurzelknoten fuer neuen Baum anlegen + root_node = calloc(1, sizeof(*root_node)); + root_node->res = root_res; + root_node->name = malloc(tmp_rel_path - path + 1); + strncpy(root_node->name, path, tmp_rel_path - path); + root_node->name[tmp_rel_path - path] = '\0'; + + tree->root = root_node; + root_node->res->tree = tree; + + // Neuen Baum registrieren + list_push(lio_trees, tree); + if (rel_path) { + *rel_path = tmp_rel_path; + } + + return tree; + +out_err: + lio_usp_remove_tree(tree); + free(tree); + return NULL; +} + +/** + * Loest einen gegebenen Pfad in einen Verzeichnisbaum und einen + * servicerelativen Pfad auf. + * + * @param path Aufzulosender Pfad + * @param rel_path Wenn rel_path != NULL ist, wird darin ein Pointer auf den + * servicerelativen Teil des Pfads zurueckgegeben + * + * @return Den zum Pfad gehoerenden Verzeichnisbaum oder NULL im Fehlerfall + */ +struct lio_tree* lio_get_tree(const char* path, const char** rel_path) +{ + int i; + struct lio_tree* tree; + const char* service_name; + const char* tmp_rel_path; + + // Pfad fuer den Baum heraussucen + split_path(path, &service_name, &tmp_rel_path); + if (rel_path) { + *rel_path = tmp_rel_path; + } + + // Suchen, ob es schon einen Baum fuer den Pfad gibt + for (i = 0; (tree = list_get_element_at(lio_trees, i)); i++) { + if (!tree->root) { + panic("BUG: lio_tree ohne Wurzel"); + } + + if (strlen(tree->root->name) != (tmp_rel_path - path)) { + continue; + } + + if (!strncmp(tree->root->name, path, tmp_rel_path - path)) { + return tree; + } + } + + // Neuen Baum anlegen + tree = mount(path, rel_path); + + return tree; +} + +/** + * Registriert einen neuen LIO-Service + */ +void lio_add_service(struct lio_service* service) +{ + list_push(lio_services, service); +} + +/** + * Neue Ressource initialisieren. + * Vom Aufrufer initialisiert werden muessen (werden alle auf 0 initialisiert): + * - blocksize + * - tree + * - Flags + * + * @return Zeiger auf die neue Ressource + */ +struct lio_resource* lio_create_resource(void) +{ + struct lio_resource* res = calloc(sizeof(*res), 1); + + lio_init_resource(res); + + return res; +} + +/** + * Interne Daten einer Ressource initialisieren. Dabei werden nur die internen + * Felder veraendert, der Rest muss vom Aufrufer gesetzt werden. Diese Funktion + * kann verwendet werden, wenn der Speicher fuer eine Resource bereits + * verfuegbar ist (beispielsweise bei statischem Speicher). + * + * @param res Zu initialisierende Ressource + */ +void lio_init_resource(struct lio_resource* res) +{ + lio_usp_add_resource(res); +} + +/** + * Ressource zerstoeren und Speicher freigeben. Der Aufrufer ist dafuer + * allenfalls Caches zu syncen. + * + * @param res Zu zerstoerende Ressource + */ +void lio_destroy_resource(struct lio_resource* res) +{ + lio_usp_remove_resource(res); + free(res); +} + +/** Kindknoten einer Ressource suchen */ +struct lio_node* lio_resource_get_child(struct lio_resource* parent, + const char* name) +{ + struct lio_node* n; + size_t i; + + for (i = 0; (n = list_get_element_at(parent->children, i)); i++) { + if (!strcmp(name, n->name)) { + return n; + } + } + + return NULL; +} + +/** Einer Resource einen Kindknoten anfuegen */ +void lio_resource_add_child(struct lio_resource* parent, + struct lio_node* child) +{ + if (!parent->children) { + parent->children = list_create(); + } + + list_push(parent->children, child); +} + +/** Kindknoten einer Ressource entfernen */ +void lio_resource_remove_child(struct lio_resource* parent, + struct lio_node* child) +{ + struct lio_node* n; + size_t i; + + // FIXME: Hier brauchen wir irgendwann noch gescheite Locks + for (i = 0; (n = list_get_element_at(parent->children, i)); i++) { + if (n == child) { + list_remove(parent->children, i); + break; + } + } +} + +/** Neuen Knoten anlegen und bei Elternressource als Kind eintragen */ +struct lio_node* lio_create_node(struct lio_resource* parent, + struct lio_resource* res, const char* name) +{ + struct lio_node* n = calloc(sizeof(*n), 1); + + n->res = res; + n->name = strdup(name); + lio_resource_add_child(parent, n); + + return n; +} + -- 1.6.0.2 From kevin at tyndur.org Sat Dec 3 18:20:52 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 3 Dec 2011 18:20:52 +0100 Subject: [tyndur-devel] [RFC PATCH 4/5] kernel2: LIOv2-Service tmp In-Reply-To: <1322932853-21843-1-git-send-email-kevin@tyndur.org> References: <1322932853-21843-1-git-send-email-kevin@tyndur.org> Message-ID: <1322932853-21843-5-git-send-email-kevin@tyndur.org> + kernel2: tmp:/ stellt eine dateisystembasierte RAM-Disk zur Verfügung Signed-off-by: Kevin Wolf --- src/kernel2/src/arch/i386/Makefile.all | 2 +- src/kernel2/src/lostio/lostio.c | 4 + src/kernel2/src/lostio/modules/tmp.c | 223 ++++++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+), 1 deletions(-) create mode 100644 src/kernel2/src/lostio/modules/tmp.c diff --git a/src/kernel2/src/arch/i386/Makefile.all b/src/kernel2/src/arch/i386/Makefile.all index 0a63791..57bcb56 100644 --- a/src/kernel2/src/arch/i386/Makefile.all +++ b/src/kernel2/src/arch/i386/Makefile.all @@ -9,5 +9,5 @@ $LOST_TOOLS_OBJCOPY -B i386:i386 -I binary -O elf32-i386 rm_trampoline.o rm_tram rm rm_trampoline.o echo "LD $1/kernel/tyndur2" -$LOST_TOOLS_LD -otyndur2.krn -Tkernel.ld header.o --start-group !(header).o */*.o $KERNEL/*.o $KERNEL/*/!(rm_trampoline).o $2 --end-group +$LOST_TOOLS_LD -otyndur2.krn -Tkernel.ld header.o --start-group !(header).o */*.o $KERNEL/*.o $KERNEL/*/!(rm_trampoline).o $KERNEL/lostio/*/*.o $2 --end-group mv tyndur2.krn $1/kernel/tyndur2 diff --git a/src/kernel2/src/lostio/lostio.c b/src/kernel2/src/lostio/lostio.c index 9a08d58..779b7c3 100644 --- a/src/kernel2/src/lostio/lostio.c +++ b/src/kernel2/src/lostio/lostio.c @@ -38,10 +38,14 @@ #include "lostio/core.h" #include "lostio_int.h" +extern void lio_init_tmp(void); + void lio_init(void) { lio_init_tree(); lio_init_userspace(); + lio_init_tmp(); + return; } diff --git a/src/kernel2/src/lostio/modules/tmp.c b/src/kernel2/src/lostio/modules/tmp.c new file mode 100644 index 0000000..412e47b --- /dev/null +++ b/src/kernel2/src/lostio/modules/tmp.c @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include "kprintf.h" + +#include "lostio/core.h" +#include "lostio/client.h" +#include "lostio_int.h" + +#define BLOCKSIZE 1024 + +static struct lio_resource root_res = { + .size = 0, + .blocksize = BLOCKSIZE, + .changeable = 1, + .browsable = 1, + .children = NULL, + .opaque = NULL, +}; + +struct tmp_state { + void* buf; + size_t size; +}; + +static struct lio_resource* load_root(struct lio_tree* tree) +{ + if (tree->source) { + return NULL; + } + + lio_init_resource(&root_res); + return &root_res; +} + +static int load_children(struct lio_resource* res) +{ + return 0; +} + +static int tmp_read(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf) +{ + struct tmp_state* s = res->opaque; + + if (bytes % BLOCKSIZE) { + bytes += BLOCKSIZE - (bytes % BLOCKSIZE); + } + + if (s->buf && (offset < res->size)) { + if (bytes > (s->size - offset)) { + size_t total = bytes; + bytes = s->size - offset; + memset((char*) buf + bytes, 0, total - bytes); + } + memcpy(buf, s->buf + offset, bytes); + } else { + memset(buf, 0, bytes); + } + + return 0; +} + +static int tmp_write(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf) +{ + struct tmp_state* s = res->opaque; + + if (res->size <= offset) { + /* Hinter das Dateiende wird nicht geschrieben */ + return -EIO; + } else if (s->size < offset + bytes) { + /* Der Puffer muss vergroessert werden */ + void* p = realloc(s->buf, offset + bytes); + if (p == NULL) { + return -ENOMEM; + } + s->buf = p; + s->size = offset + bytes; + } + + memcpy(s->buf + offset, buf, bytes); + + return 0; +} + +static struct lio_resource* make_file(struct lio_resource* parent, + const char* name) +{ + struct lio_resource* res; + struct tmp_state* s; + + res = lio_create_resource(); + lio_create_node(parent, res, name); + + res->blocksize = BLOCKSIZE; + res->readable = 1; + res->writable = 1; + res->seekable = 1; + res->tree = parent->tree; + + s = calloc(1, sizeof(*s)); + res->opaque = s; + + return res; +} + +static struct lio_resource* make_dir(struct lio_resource* parent, + const char* name) +{ + struct lio_resource* res; + + res = lio_create_resource(); + lio_create_node(parent, res, name); + + res->blocksize = BLOCKSIZE; + res->browsable = 1; + res->changeable = 1; + res->tree = parent->tree; + + return res; +} + +static struct lio_resource* make_symlink(struct lio_resource* parent, + const char* name, const char* target) +{ + struct lio_resource* res; + struct tmp_state* s; + + res = lio_create_resource(); + lio_create_node(parent, res, name); + + res->blocksize = BLOCKSIZE; + res->resolvable = 1; + res->retargetable = 1; + res->tree = parent->tree; + + s = calloc(1, sizeof(*s)); + s->buf = strdup(target); + s->size = strlen(s->buf); + + res->opaque = s; + res->size = s->size; + + return res; +} + +static int unlink(struct lio_resource* parent, const char* name) +{ + struct lio_node* child; + struct lio_resource* res; + + if (!(child = lio_resource_get_child(parent, name))) { + return -ENOENT; + } + res = child->res; + + // Ressource hat noch Kinder + if (res->browsable && list_size(res->children)) { + return -EEXIST; + } + + lio_sync_blocks(res, 0, 0); + lio_resource_remove_child(parent, child); + lio_destroy_resource(res); + return 0; +} + + +static struct lio_service service = { + .name = "tmp", + .lio_ops = { + .load_root = load_root, + .load_children = load_children, + .read = tmp_read, + .write = tmp_write, + .make_file = make_file, + .make_dir = make_dir, + .make_symlink = make_symlink, + .unlink = unlink, + }, +}; + +void lio_init_tmp(void) +{ + lio_add_service(&service); +} -- 1.6.0.2 From kevin at tyndur.org Sat Dec 3 18:20:53 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 3 Dec 2011 18:20:53 +0100 Subject: [tyndur-devel] [RFC PATCH 5/5] kernel2: LIOv2-Clientsyscalls implementiert In-Reply-To: <1322932853-21843-1-git-send-email-kevin@tyndur.org> References: <1322932853-21843-1-git-send-email-kevin@tyndur.org> Message-ID: <1322932853-21843-6-git-send-email-kevin@tyndur.org> + 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 --- 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 +#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 From kevin at tyndur.org Sat Dec 10 14:18:12 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 10 Dec 2011 14:18:12 +0100 Subject: [tyndur-devel] [PATCH 1/2] shell: bincat: Kein fseek auf NULL aufrufen In-Reply-To: <1323523093-9772-1-git-send-email-kevin@tyndur.org> References: <1323523093-9772-1-git-send-email-kevin@tyndur.org> Message-ID: <1323523093-9772-2-git-send-email-kevin@tyndur.org> ! shell: Wenn bincat die Datei nicht öffnen kann, muss es sofort einen Fehler zurückgeben und nicht erst noch den NULL-Pointer an fseek weitergeben, damit es garantiert rot gibt. Signed-off-by: Kevin Wolf --- src/modules/c/shell/cmds/bincat.c | 51 +++++++++++++++++++------------------ 1 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/modules/c/shell/cmds/bincat.c b/src/modules/c/shell/cmds/bincat.c index d21d4d9..41066a2 100644 --- a/src/modules/c/shell/cmds/bincat.c +++ b/src/modules/c/shell/cmds/bincat.c @@ -135,43 +135,44 @@ void bincat_display_usage(void); } FILE* file = fopen(path, "r"); + if (file == NULL) { + printf(TMS(bincat_opening_error, + "Konnte '%s' nicht zum lesen öffnen!\n"), path); + return EXIT_FAILURE; + } + + char buffer[BLOCK_SIZE]; + size_t size; fseek(file, start, SEEK_SET); m = start - 8; - if (file == NULL) { - printf(TMS(bincat_opening_error, - "Konnte '%s' nicht zum lesen öffnen!\n"), path); - return -1; - } else { - char buffer[BLOCK_SIZE]; - size_t size; - while (feof(file) != EOF && (total_read <= length || length == 0)) { + while (feof(file) != EOF && (total_read <= length || length == 0)) { - size = fread(buffer, 1, BLOCK_SIZE, file); + size = fread(buffer, 1, BLOCK_SIZE, file); - total_read += size; + total_read += size; - if (length && (total_read > length)) { - size -= total_read - length; - } + if (length && (total_read > length)) { + size -= total_read - length; + } - for (n=0; n < size; n++) { - if ((n % 8) == 0) { - if (n == 8) { - printf("0x%08x", m); - } - m += 8; - printf("\n"); - printf("0x%08x: ", m); + for (n=0; n < size; n++) { + if ((n % 8) == 0) { + if (n == 8) { + printf("0x%08x", m); } - - printf("0x%02x ", ((uint32_t) buffer[n]) & 0xFF); + m += 8; + printf("\n"); + printf("0x%08x: ", m); } - } - fclose(file); + printf("0x%02x ", ((uint32_t) buffer[n]) & 0xFF); + } } + + fclose(file); + printf("\n"); return EXIT_SUCCESS; } -- 1.6.0.2 From kevin at tyndur.org Sat Dec 10 14:18:11 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 10 Dec 2011 14:18:11 +0100 Subject: [PATCH 0/2] Shell-Änderungen aus dem LIOv2-Branch Message-ID: <1323523093-9772-1-git-send-email-kevin@tyndur.org> Kevin Wolf (2): shell: bincat: Kein fseek auf NULL aufrufen shell: Neuer Befehl sync src/modules/c/shell/cmds/bincat.c | 51 +++++++++++++++--------------- src/modules/c/shell/cmds/sync.c | 61 ++++++++++++++++++++++++++++++++++++ src/modules/c/shell/commmands.c | 1 + src/modules/c/shell/lang/lang_en.c | 1 + src/modules/c/shell/shell.c | 1 + src/modules/c/shell/shell.h | 1 + 6 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 src/modules/c/shell/cmds/sync.c From kevin at tyndur.org Sat Dec 10 14:18:13 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 10 Dec 2011 14:18:13 +0100 Subject: [tyndur-devel] [PATCH 2/2] shell: Neuer Befehl sync In-Reply-To: <1323523093-9772-1-git-send-email-kevin@tyndur.org> References: <1323523093-9772-1-git-send-email-kevin@tyndur.org> Message-ID: <1323523093-9772-3-git-send-email-kevin@tyndur.org> + shell: Neuer Befehl sync, der lio_sync_all() aufruft. Geht im Moment natürlich noch schief, weil der Kernel das noch nicht kann. Signed-off-by: Kevin Wolf --- src/modules/c/shell/cmds/sync.c | 61 ++++++++++++++++++++++++++++++++++++ src/modules/c/shell/commmands.c | 1 + src/modules/c/shell/lang/lang_en.c | 1 + src/modules/c/shell/shell.c | 1 + src/modules/c/shell/shell.h | 1 + 5 files changed, 65 insertions(+), 0 deletions(-) create mode 100644 src/modules/c/shell/cmds/sync.c diff --git a/src/modules/c/shell/cmds/sync.c b/src/modules/c/shell/cmds/sync.c new file mode 100644 index 0000000..70ade7a --- /dev/null +++ b/src/modules/c/shell/cmds/sync.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2010 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +static void sync_display_usage(void); + +#ifdef CONFIG_SHELL_BUILTIN_ONLY + int shell_command_sync(int argc, char* argv[], const char* args) +#else + int main(int argc, char* argv[]) +#endif +{ + if (argc != 1) { + sync_display_usage(); + return -1; + } + + lio_sync_all(); + return EXIT_SUCCESS; +} + +static void sync_display_usage() +{ + puts("\nAufruf: sync"); +} + diff --git a/src/modules/c/shell/commmands.c b/src/modules/c/shell/commmands.c index 816aae2..419a453 100644 --- a/src/modules/c/shell/commmands.c +++ b/src/modules/c/shell/commmands.c @@ -190,6 +190,7 @@ int shell_command_help(int argc, char* argv[], const char* args) " cat Zeigt den Inhalt der Datei an\n" " bincat Zeigt den Inhalt der Datei als einzelne Bytes an\n" " pipe Ein-/Ausgabe auf einer Datei (z.B. TCP-Verbindung)\n" + " sync Alle veraenderten Block im Cache rausschreiben\n" "\n" " date Zeigt das Datum und die Uhrzeit an\n" " free Zeigt den Speicherverbrauch des Systems an\n" diff --git a/src/modules/c/shell/lang/lang_en.c b/src/modules/c/shell/lang/lang_en.c index a73a518..6a7c050 100644 --- a/src/modules/c/shell/lang/lang_en.c +++ b/src/modules/c/shell/lang/lang_en.c @@ -83,6 +83,7 @@ static const struct tms_strings dict[] = { " cat Show contents of a file\n" " bincat Show binary contents of a file (byte-wise)\n" " pipe In-/Output to a file (e.g. TCP connection)\n" + " sync Write all changes from the cache to disk\n" "\n" " date Show current date and time\n" " free Show total system memory usage\n" diff --git a/src/modules/c/shell/shell.c b/src/modules/c/shell/shell.c index 72492f9..d111124 100644 --- a/src/modules/c/shell/shell.c +++ b/src/modules/c/shell/shell.c @@ -103,6 +103,7 @@ shell_command_t shell_commands[] = { {"sleep", &shell_command_sleep}, {"bench", &shell_command_bench}, {"read", &shell_command_read}, + {"sync", &shell_command_sync}, #endif {NULL, NULL} }; diff --git a/src/modules/c/shell/shell.h b/src/modules/c/shell/shell.h index e69323c..40f91c9 100644 --- a/src/modules/c/shell/shell.h +++ b/src/modules/c/shell/shell.h @@ -84,6 +84,7 @@ int shell_command_clear(int argc, char* argv[], const char* args); int shell_command_sleep(int argc, char* argv[], const char* args); int shell_command_bench(int argc, char* argv[], const char* args); int shell_command_read(int argc, char* argv[], const char* args); + int shell_command_sync(int argc, char* argv[], const char* args); #endif #endif -- 1.6.0.2 From kevin at tyndur.org Sat Dec 10 21:37:56 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 10 Dec 2011 21:37:56 +0100 Subject: [tyndur-devel] [PATCH v2 0/6] kernel2: LIOv2-Grundlagen Message-ID: <1323549482-1766-1-git-send-email-kevin@tyndur.org> Nach dieser Patchserie ist tmp:/ als LIOv2-Service funktionsfähig. Alles interessante und potentiell problematisch wie der Cache, Userspace-Services oder Pipes ist noch ausgespart. Kevin Wolf (6): kernel2: LIOv2-Grundgerüst kernel2: Zentrale LIOv2-Clientfunktionen kernel2: Ressourcen und Verzeichnisbäume kernel2: LIOv2-Service tmp kernel2: LIOv2-Clientsyscalls implementiert kernel2: Beim Prozessende offene Dateien schliessen src/include/syscall_structs.h | 3 + src/kernel2/include/lostio/client.h | 188 ++++++++ src/kernel2/include/lostio/core.h | 82 ++++ src/kernel2/include/lostio/userspace.h | 84 ++++ src/kernel2/include/tasks.h | 7 + src/kernel2/src/arch/i386/Makefile.all | 2 +- src/kernel2/src/init.c | 4 + src/kernel2/src/lostio/client.c | 632 +++++++++++++++++++++++++++ src/kernel2/src/lostio/include/lostio_int.h | 295 +++++++++++++ src/kernel2/src/lostio/lostio.c | 51 +++ src/kernel2/src/lostio/modules/tmp.c | 223 ++++++++++ src/kernel2/src/lostio/tree.c | 365 +++++++++++++++ src/kernel2/src/lostio/userspace.c | 154 +++++++ src/kernel2/src/syscalls/lostio.c | 228 +++++++++- src/kernel2/src/syscalls/pm.c | 7 + src/kernel2/src/tasks/pm.c | 39 ++- 16 files changed, 2343 insertions(+), 21 deletions(-) create mode 100644 src/kernel2/include/lostio/client.h create mode 100644 src/kernel2/include/lostio/core.h create mode 100644 src/kernel2/include/lostio/userspace.h create mode 100644 src/kernel2/src/lostio/client.c create mode 100644 src/kernel2/src/lostio/include/lostio_int.h create mode 100644 src/kernel2/src/lostio/lostio.c create mode 100644 src/kernel2/src/lostio/modules/tmp.c create mode 100644 src/kernel2/src/lostio/tree.c create mode 100644 src/kernel2/src/lostio/userspace.c From kevin at tyndur.org Sat Dec 10 21:37:57 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 10 Dec 2011 21:37:57 +0100 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH_v2_1/6=5D_kernel2=3A_LIOv2-Grun?= =?utf-8?q?dger=C3=BCst?= In-Reply-To: <1323549482-1766-1-git-send-email-kevin@tyndur.org> References: <1323549482-1766-1-git-send-email-kevin@tyndur.org> Message-ID: <1323549482-1766-2-git-send-email-kevin@tyndur.org> + kernel2: LIOv2-Datenstrukturen zur Verwaltung von Verzeichnisbäumen + kernel2: Funktionen zur Verwaltung der Userspace-Deskriptoren für LIOv2-Kernelobjekte Signed-off-by: Kevin Wolf --- src/include/syscall_structs.h | 3 + src/kernel2/include/lostio/core.h | 82 ++++++++++++++ src/kernel2/include/lostio/userspace.h | 84 +++++++++++++++ src/kernel2/include/tasks.h | 4 + src/kernel2/src/init.c | 4 + src/kernel2/src/lostio/include/lostio_int.h | 131 +++++++++++++++++++++++ src/kernel2/src/lostio/lostio.c | 46 ++++++++ src/kernel2/src/lostio/userspace.c | 154 +++++++++++++++++++++++++++ src/kernel2/src/tasks/pm.c | 6 + 9 files changed, 514 insertions(+), 0 deletions(-) create mode 100644 src/kernel2/include/lostio/core.h create mode 100644 src/kernel2/include/lostio/userspace.h create mode 100644 src/kernel2/src/lostio/include/lostio_int.h create mode 100644 src/kernel2/src/lostio/lostio.c create mode 100644 src/kernel2/src/lostio/userspace.c diff --git a/src/include/syscall_structs.h b/src/include/syscall_structs.h index 6ec63a0..ab2ec95 100644 --- a/src/include/syscall_structs.h +++ b/src/include/syscall_structs.h @@ -82,6 +82,9 @@ typedef int64_t lio_usp_stream_t; /** ID einer LostIO-Ressource */ typedef int64_t lio_usp_resource_t; +/** ID eines LostIO-Verzeichnisbaums */ +typedef int64_t lio_usp_tree_t; + /** * Beschreibt als Bitmaske den Modus, in dem ein Stream arbeiten soll. */ diff --git a/src/kernel2/include/lostio/core.h b/src/kernel2/include/lostio/core.h new file mode 100644 index 0000000..b1183b4 --- /dev/null +++ b/src/kernel2/include/lostio/core.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2008 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOSTIO_CORE_H_ +#define _LOSTIO_CORE_H_ + +#include +#include +#include +#include + +struct lio_resource; +struct lio_tree; + +struct lio_stream { + struct lio_resource* res; + + struct lio_resource* res_read; + uint64_t pos_read; + struct lio_resource* res_write; + uint64_t pos_write; + + int flags; + bool eof; +}; + +struct lio_usp_stream { + struct lio_stream* stream; + + /** Id des Streams fuer Userspace-Programme */ + lio_usp_stream_t usp_id; + + /** Sortierung nach usp_id im Baum */ + struct tree_item usp_item; +}; + +struct lio_node { + struct lio_resource* res; + + // Fuer den Wurzelknoten eines Baums ist der Name der Pfad der Quelle und + // hoert mit einem / auf (z.B. ata:/ata00p0|ext2:/) + char* name; +}; + +/** + * Initialisiert interne Datenstrukturen für LostIO + */ +void lio_init(void); + +#endif diff --git a/src/kernel2/include/lostio/userspace.h b/src/kernel2/include/lostio/userspace.h new file mode 100644 index 0000000..a8a5cdc --- /dev/null +++ b/src/kernel2/include/lostio/userspace.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2008 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOSTIO_USERSPACE_H +#define _LOSTIO_USERSPACE_H + +#include "lostio/core.h" + + + +/***** Streams ******/ + +/** Weist einem Stream eine Userspace-ID zu */ +struct lio_usp_stream* lio_usp_add_stream(pm_process_t* proc, + struct lio_stream* stream); + +/** + * Gibt den zur Userspace-ID gehörenden Stream zurück, oder NULL wenn es + * keinen passenden Stream gibt. + */ +struct lio_usp_stream* lio_usp_get_stream(pm_process_t* proc, + lio_usp_stream_t id); + +/** Gibt die Userspace-ID des Streams wieder frei */ +void lio_usp_remove_stream(pm_process_t* proc, struct lio_usp_stream* stream); + + + +/***** Ressourcen ******/ + +/** + * Gibt die zur Userspace-ID gehörende Ressource zurück, oder NULL wenn es + * keine passende Ressource gibt. + */ +struct lio_resource* lio_usp_get_resource(lio_usp_resource_t id); + +/** + * Gitb die Userspace-ID zu einer gegebenen Ressource zurück. + */ +lio_usp_resource_t lio_usp_get_id(struct lio_resource* res); + + + +/***** Verzeichnisbäume ******/ + +/** + * Gibt den zur Userspace-ID gehörenden Verzeichnisbaum zurück, oder NULL + * wenn es keinen passenden Verzeichnisbaum gibt. + */ +struct lio_tree* lio_usp_get_tree(lio_usp_tree_t id); + +#endif diff --git a/src/kernel2/include/tasks.h b/src/kernel2/include/tasks.h index 04d6b41..5256e0f 100644 --- a/src/kernel2/include/tasks.h +++ b/src/kernel2/include/tasks.h @@ -107,6 +107,10 @@ typedef struct pm_process { /// Speicherverbrauch des Prozesses uintmax_t memory_used; + + /// Baum aller geoeffneten LostIO-Streams + tree_t* lio_streams; + } pm_process_t; typedef struct { diff --git a/src/kernel2/src/init.c b/src/kernel2/src/init.c index c92a10f..9ad5d0b 100644 --- a/src/kernel2/src/init.c +++ b/src/kernel2/src/init.c @@ -52,6 +52,7 @@ #include "lock.h" #include "gdt.h" #include "timer.h" +#include "lostio/core.h" struct multiboot_info multiboot_info; @@ -270,6 +271,9 @@ void init(int multiboot_magic, struct multiboot_info *boot_info, bool bsp) // Timer initialisieren timer_init(); + // LostIO initialisieren + lio_init(); + // Init-Modul laden debug_print(DEBUG_FLAG_INIT, "Lade Module"); load_init_module(&multiboot_info); diff --git a/src/kernel2/src/lostio/include/lostio_int.h b/src/kernel2/src/lostio/include/lostio_int.h new file mode 100644 index 0000000..63d3630 --- /dev/null +++ b/src/kernel2/src/lostio/include/lostio_int.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2008 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LOSTIO_INT_H +#define LOSTIO_INT_H + +#include +#include + +#include "lostio/core.h" +#include "tasks.h" + +struct lio_service; + +/** + * Beschreibt eine von LostIO verwaltete Ressource (d.h. in der Regel eine + * Datei). Alle Informationen, die nicht für einen bestimmten Client + * spezifisch sind, werden hier gespeichert. + */ +struct lio_resource { + + /** Verzeichnisbaum, zu dem die Ressource gehört */ + struct lio_tree* tree; + + /** + * Verzeichniseinträge (struct lio_node), falls die Ressource ein + * Verzeichnis ist + */ + list_t* children; + + /** Größe der Ressource in Bytes */ + uint64_t size; + + /** + * Die Blockgröße ist die kleinste Einheit, in der Anfragen an den + * Service gemacht werden. Sie wird auch intern für den Cache verwendet. + * Nur Zweierpotenzen; block_size * LIO_CLUSTER_SIZE sollte durch PAGE_SIZE + * teilbar sein. + */ + uint32_t blocksize; + + /* FIXME Sollte backendspezifisch sein */ + tree_t* dirty; + bool dirty_lock; + + /** Hat unterschiedliche Ressourcen fuer Lesen und Schreiben */ + bool ispipe; + + bool readable; + bool writable; + bool seekable; + bool moredata; + bool browsable; + bool changeable; + bool resolvable; + bool retargetable; + + /** Benutzt uebersetzungstabellen */ + bool translated; + + /** Id der Ressource fuer Userspace-Programme */ + lio_usp_resource_t usp_id; + + /** Sortierung nach usp_id im Baum */ + struct tree_item usp_item; + + /** Private Daten des Services */ + void* opaque; +}; + +struct lio_tree { + struct lio_node* root; + struct lio_service* service; + struct lio_stream* source; + + lio_usp_tree_t usp_id; + struct tree_item usp_item; +}; + + +/** + * Initialisiert die Verwaltung der Userspace-Deskriptoren für Kernelobjekte + */ +int lio_init_userspace(void); + + +/** Weist einer Ressource eine Userspace-ID zu */ +void lio_usp_add_resource(struct lio_resource* res); + +/** Gibt die Userspace-ID der Ressource wieder frei */ +void lio_usp_remove_resource(struct lio_resource* res); + +/** Weist einem Verzeichnisbaum eine Userspace-ID zu */ +void lio_usp_add_tree(struct lio_tree* tree); + +/** Gibt die Userspace-ID des Verzeichnisbaums wieder frei */ +void lio_usp_remove_tree(struct lio_tree* tree); + +#endif diff --git a/src/kernel2/src/lostio/lostio.c b/src/kernel2/src/lostio/lostio.c new file mode 100644 index 0000000..3843f4e --- /dev/null +++ b/src/kernel2/src/lostio/lostio.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2010 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include "lostio/core.h" +#include "lostio_int.h" + +void lio_init(void) +{ + lio_init_userspace(); + + return; +} diff --git a/src/kernel2/src/lostio/userspace.c b/src/kernel2/src/lostio/userspace.c new file mode 100644 index 0000000..d6376de --- /dev/null +++ b/src/kernel2/src/lostio/userspace.c @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include "lostio/core.h" +#include "lostio_int.h" + +static tree_t* resource_tree; +static tree_t* tree_tree; + +/** + * Initialisiert die Verwaltung der Userspace-Deskriptoren für Kernelobjekte + */ +int lio_init_userspace(void) +{ + resource_tree = tree_create(struct lio_resource, usp_item, usp_id); + tree_tree = tree_create(struct lio_tree, usp_item, usp_id); + return 0; +} + +static lio_usp_resource_t new_resourceid(void) +{ + static lio_usp_resource_t prev_id = 0; + return ++prev_id; +} + +static lio_usp_stream_t new_streamid(void) +{ + static lio_usp_stream_t prev_id = 0; + return ++prev_id; +} + +static lio_usp_tree_t new_treeid(void) +{ + static lio_usp_tree_t prev_id = 0; + return ++prev_id; +} + + +/** Weist einer Ressource eine Userspace-ID zu */ +void lio_usp_add_resource(struct lio_resource* res) +{ + res->usp_id = new_resourceid(); + tree_insert(resource_tree, res); +} + +/** + * Gibt die zur Userspace-ID gehörende Ressource zurück, oder NULL wenn es + * keine passende Ressource gibt. + */ +struct lio_resource* lio_usp_get_resource(lio_usp_resource_t id) +{ + return tree_search(resource_tree, id); +} + + +/** Gibt die Userspace-ID der Ressource wieder frei */ +void lio_usp_remove_resource(struct lio_resource* res) +{ + tree_remove(resource_tree, res); +} + +/** Weist einem Stream eine Userspace-ID zu */ +struct lio_usp_stream* lio_usp_add_stream(pm_process_t* proc, + struct lio_stream* stream) +{ + struct lio_usp_stream* entry = malloc(sizeof(*entry)); + + entry->stream = stream; + entry->usp_id = new_streamid(); + + tree_insert(proc->lio_streams, entry); + return entry; +} + +/** + * Gibt den zur Userspace-ID gehörenden Stream zurück, oder NULL wenn es + * keinen passenden Stream gibt. + */ +struct lio_usp_stream* lio_usp_get_stream(pm_process_t* proc, + lio_usp_stream_t id) +{ + return tree_search(proc->lio_streams, id); +} + +/** Gibt die Userspace-ID des Streams wieder frei */ +void lio_usp_remove_stream(pm_process_t* proc, struct lio_usp_stream* stream) +{ + tree_remove(proc->lio_streams, stream); + free(stream); +} + +/** Weist einem Verzeichnisbaum eine Userspace-ID zu */ +void lio_usp_add_tree(struct lio_tree* tree) +{ + tree->usp_id = new_treeid(); + tree_insert(tree_tree, tree); +} + +/** Gibt die Userspace-ID des Verzeichnisbaums wieder frei */ +void lio_usp_remove_tree(struct lio_tree* tree) +{ + tree_remove(tree_tree, tree); +} + +/** + * Gibt den zur Userspace-ID gehörenden Verzeichnisbaum zurück, oder NULL + * wenn es keinen passenden Verzeichnisbaum gibt. + */ +struct lio_tree* lio_usp_get_tree(lio_usp_tree_t id) +{ + return tree_search(tree_tree, id); +} + +/** + * Gitb die Userspace-ID zu einer gegebenen Ressource zurück. + */ +lio_usp_resource_t lio_usp_get_id(struct lio_resource* res) +{ + return res->usp_id; +} diff --git a/src/kernel2/src/tasks/pm.c b/src/kernel2/src/tasks/pm.c index 846323a..047c4d5 100644 --- a/src/kernel2/src/tasks/pm.c +++ b/src/kernel2/src/tasks/pm.c @@ -44,6 +44,8 @@ #include "tasks.h" #include "lock.h" #include "timer.h" +#include "lostio/core.h" +#include "lostio/userspace.h" struct on_destroy_info { @@ -166,6 +168,10 @@ pm_process_t* pm_create(pm_process_t* parent, const char* cmdline) process->rpc_handler = NULL; process->rpcs = list_create(); + // Dateiliste initialisieren + process->lio_streams = + tree_create(struct lio_usp_stream, usp_item, usp_id); + list_push(process_list, process); process->memory_used = 0; -- 1.6.0.2 From kevin at tyndur.org Sat Dec 10 21:37:58 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 10 Dec 2011 21:37:58 +0100 Subject: [tyndur-devel] [PATCH v2 2/6] kernel2: Zentrale LIOv2-Clientfunktionen In-Reply-To: <1323549482-1766-1-git-send-email-kevin@tyndur.org> References: <1323549482-1766-1-git-send-email-kevin@tyndur.org> Message-ID: <1323549482-1766-3-git-send-email-kevin@tyndur.org> + kernel2: Alles, was ein Client so mit Ressourcen und Streams anstellen kann, ausgenommen die Ressource erstmal zu bekommen. Signed-off-by: Kevin Wolf --- src/kernel2/include/lostio/client.h | 188 ++++++++++ src/kernel2/src/lostio/client.c | 531 +++++++++++++++++++++++++++ src/kernel2/src/lostio/include/lostio_int.h | 91 +++++ 3 files changed, 810 insertions(+), 0 deletions(-) create mode 100644 src/kernel2/include/lostio/client.h create mode 100644 src/kernel2/src/lostio/client.c diff --git a/src/kernel2/include/lostio/client.h b/src/kernel2/include/lostio/client.h new file mode 100644 index 0000000..d3490f0 --- /dev/null +++ b/src/kernel2/include/lostio/client.h @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2008 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOSTIO_CLIENT_H_ +#define _LOSTIO_CLIENT_H_ + +#include "lostio/core.h" + +struct lio_dir_entry { + struct lio_resource* resource; + char name[LIO_MAX_FNLEN + 1]; + struct lio_stat stat; +}; + +/** + * Loest einen Pfad zu einer Ressource auf + * + * @return Die zum Pfad gehoerende Ressource oder NULL, wenn der Pfad keine + * existierende Ressource beschreibt. + */ +struct lio_resource* lio_get_resource(const char* path, int follow_symlinks); + +/** + * Oeffnet einen Stream zu einer Ressource + * + * @param flags Bitmaske für den Modus, in dem der Stream arbeiten soll (siehe + * enum lio_flags) + * + * @return Stream zur Ressource oder NULL, wenn die Ressource nicht erfolgreich + * geoeffnet werden konnte. + */ +struct lio_stream* lio_open(struct lio_resource* res, int flags); + +/** + * Liest aus einem Stream aus. + * + * @return Anzahl der gelesenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_read(struct lio_stream* s, size_t bytes, void* buf); + +/** + * Liest aus einem Stream aus, ohne die Position des streams zu benutzen oder + * zu veraendern. + * + * @return Anzahl der gelesenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_pread(struct lio_stream* s, uint64_t offset, size_t bytes, + void* buf); + +/** + * Schreibt in einen Stream + * + * @return Anzahl der geschriebenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_write(struct lio_stream* s, size_t bytes, const void* buf); + +/** + * Schreibt in einen Stream, ohne dabei die Position des Streams zu benutzen + * oder zu veraendern. + * + * @return Anzahl der geschriebenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_pwrite(struct lio_stream* s, uint64_t offset, size_t bytes, + const void* buf); + +/** + * Position veraendern. Funktioniert nur, wenn die Ressource seekable ist, und + * es sich um keine Pipe handelt. + * + * @param offset Offset um den die Position angepasst werden soll. Wie sie genau + * angepasst wird, haengt vom Parameter whence ab. + * @param whence Einer der drei Werte aus enum lio_seek_whence. + * - LIO_SEEK_SET: Position auf den angegebenen Wert setzen. + * - LIO_SEEK_CUR: Angegebenen Wert zur aktuellen Position + * dazu addieren. + * - LIO_SEEK_END: Position auf das Dateiende setzen. + * + * @return Neue Position oder < 0 im Fehlerfall. + */ +int64_t lio_seek(struct lio_stream* s, int64_t offset, int whence); + +/** + * Schreibt Aenderungen, die bisher nur im Cache sind, zurueck. Dabei werden + * nur die Cluster beruecksichtigt, die im angegebenen Bereich liegen. + * + * @param s Stream, dessen Aendungen geschrieben werden sollen + * @param offset Start des zurueckzuschreibenden Bereichs (in Bytes) + * @param bytes Laenge des zurueckzuschreibenden Bereichs (in Bytes) oder 0, + * falls die gesamte Datei zurueckgeschrieben werden soll + * + * @return 0 bei Erfolg, ungleich 0 im Fehlerfall + * + * @attention Diese Funktion ist unterbrechbar + */ +int lio_sync_blocks(struct lio_resource* res, uint64_t offset, size_t bytes); + +/** + * Schreibt alle zum Zeitpunkt des Aufrufs der Funktion vorhandenen + * Aenderungen, die bisher nur im Cache sind, zurueck + * + * @return 0 bei Erfolg, ungleich 0 im Fehlerfall + * @attention Diese Funktion ist unterbrechbar + */ +int lio_sync(struct lio_stream* s); + +/** + * Alle veraenderten Blocks im Cache rausschreiben + * + * @param soft Wenn true, wird nicht blockiert, wenn ein Cluster nicht gesynct + * werden kann. Es wird auch kein Fehler zurückgegeben. (Ziel ist es, einfach + * irgendwelche Dirty-Cluster loszuwerden) + * + * @return 0 bei Erfolg, -errno im Fehlerfall + */ +int lio_sync_all(bool soft); + +/** + * Aendert die Dateigroesse + * + * @param size Neue Dateigroesse + * @return 0 bei Erfolg, negativ im Fehlerfall + */ +int lio_truncate(struct lio_stream* s, uint64_t size); + +/** + * Schliesst einen Stream + * + * @return 0 bei Erfolg, ungleich 0 im Fehlerfall + */ +int lio_close(struct lio_stream* s); + +/** + * Inhalt eines Verzeichnisses auslesen + */ +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); + +/** Erstellt ein neues Verzeichnis */ +struct lio_resource* lio_mkdir(struct lio_resource* parent, const char* name); + +/** Erstellt einen neuen Symlink */ +struct lio_resource* lio_mksymlink(struct lio_resource* parent, + const char* name, const char* target); + +/** + * Gibt Informationen zu einer Ressource zurueck + */ +int lio_stat(struct lio_resource* resource, struct lio_stat* sbuf); + +/** Verzeichniseintrag loeschen */ +int lio_unlink(struct lio_resource* parent, const char* name); + +#endif diff --git a/src/kernel2/src/lostio/client.c b/src/kernel2/src/lostio/client.c new file mode 100644 index 0000000..f87c6fa --- /dev/null +++ b/src/kernel2/src/lostio/client.c @@ -0,0 +1,531 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include "kernel.h" +#include "kprintf.h" + +#include "lostio/client.h" +#include "lostio_int.h" + +/** + * Loest einen Pfad zu einer Ressource auf + * + * @return Die zum Pfad gehoerende Ressource oder NULL, wenn der Pfad keine + * existierende Ressource beschreibt. + */ +struct lio_resource* lio_get_resource(const char* path, int follow_symlinks) +{ + /* TODO */ + return NULL; +} + +/** + * Oeffnet einen Stream zu einer Ressource + * + * @param flags Bitmaske für den Modus, in dem der Stream arbeiten soll (siehe + * enum lio_flags) + * + * @return Stream zur Ressource oder NULL, wenn die Ressource nicht erfolgreich + * geoeffnet werden konnte. + */ +struct lio_stream* lio_open(struct lio_resource* res, int flags) +{ + struct lio_stream* s; + + if (res == NULL) { + return NULL; + } + + // Nur lesbare Ressourcen duerfen mit dem LIO_READ-Flag geoeffnet werden, + // und nur Schreibbare mit LIO_WRITE oder LIO_TRUNC. + bool symlink = !!(flags & LIO_SYMLINK); + if (((flags & LIO_READ) && !res->readable && !symlink) || + ((flags & (LIO_WRITE | LIO_TRUNC) && !res->writable && !symlink)) || + ((flags & LIO_READ) && !res->resolvable && symlink) || + ((flags & (LIO_WRITE | LIO_TRUNC) && !res->retargetable && symlink))) + { + return NULL; + } + + // Symlinks duerfen nur als solche geoeffnet werden + if (res->resolvable && !(flags & LIO_SYMLINK)) { + return NULL; + } + + // Stream anlegen und initialisieren + s = calloc(1, sizeof(*s)); + s->res = s->res_read = s->res_write = res; + s->flags = flags; + s->eof = false; + + if (res->tree->service->lio_ops.preopen && + res->tree->service->lio_ops.preopen(s)) + { + goto fail; + } + + + // Datei leeren, wenn LIO_TRUNC gesetzt ist + if (flags & LIO_TRUNC) { + if (lio_truncate(s, 0) < 0) { + goto fail; + } + } + + return s; + +fail: + free(s); + return NULL; +} + +/** + * Liest aus einem Stream aus. + * + * @return Anzahl der gelesenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_read(struct lio_stream* s, size_t bytes, void* buf) +{ + ssize_t result; + + result = lio_pread(s, s->pos_read, bytes, buf); + if (result > 0) { + s->pos_read += result; + } + + return result; +} + +/** + * Liest aus einem Stream aus, ohne die Position des streams zu benutzen oder + * zu veraendern. + * + * @return Anzahl der gelesenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_pread(struct lio_stream* s, uint64_t offset, size_t bytes, + void* buf) +{ + ssize_t ret = 0; + struct lio_resource* res; + + // Stream muss existieren und zum Lesen geoeffnet sein + if (!s || (s->flags & LIO_READ) == 0) { + return -EBADF; + } + + res = s->res_read; + + // Position pruefen + if (offset >= res->size) { + if (res->moredata) { + return -EAGAIN; + } + return 0; + } + + // Abschneiden, wenn ueber das Dateiende hinausgelesen wird + if (offset + bytes > res->size) { + bytes = res->size - offset; + } + + // Daten einlesen + uint64_t offset_aligned = ROUND_TO_BLOCK_DOWN(offset, res->blocksize); + size_t bytes_aligned = ROUND_TO_NEXT_BLOCK( + bytes + (offset - offset_aligned), res->blocksize); + + struct lio_driver* drv = &res->tree->service->lio_ops; + uint8_t* bounce = malloc(bytes_aligned); + uint8_t* p = bounce; + uint64_t curoffset = offset_aligned; + + ret = drv->read(res, curoffset, bytes_aligned, p); + if (ret >= 0) { + ret = bytes; + memcpy(buf, bounce + (offset - offset_aligned), ret); + } + + free(bounce); + + return ret; +} + +/** + * Schreibt in einen Stream + * + * @return Anzahl der geschriebenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_write(struct lio_stream* s, size_t bytes, const void* buf) +{ + ssize_t result; + uint64_t pos; + + pos = ((s->res_read == s->res_write) ? s->pos_read : s->pos_write); + + result = lio_pwrite(s, pos, bytes, buf); + if (result > 0) { + if (s->res_read == s->res_write) { + s->pos_read += result; + } else { + s->pos_write += result; + } + } + + return result; +} + +/** + * Schreibt in einen Stream, ohne dabei die Position des Streams zu benutzen + * oder zu veraendern. + * + * @return Anzahl der geschriebenen Bytes oder negativ im Fehlerfall + */ +ssize_t lio_pwrite(struct lio_stream* s, uint64_t offset, size_t bytes, + const void* buf) +{ + ssize_t ret; + struct lio_resource* res; + + // Stream muss existieren und zum Schreiben geoeffnet sein + if (!s || (s->flags & LIO_WRITE) == 0) { + return -EBADF; + } + + res = s->res_write; + if (!res->writable && (!(s->flags & LIO_SYMLINK) || !res->retargetable)) { + return -EBADF; + } + + // Falls noetig Ressource vergroessern + if ((offset + bytes) > res->size) { + ret = lio_truncate(s, offset + bytes); + if (ret < 0) { + return ret; + } + } + + // Daten einlesen + uint64_t offset_aligned = ROUND_TO_BLOCK_DOWN(offset, res->blocksize); + size_t bytes_aligned = ROUND_TO_NEXT_BLOCK( + bytes + (offset - offset_aligned), res->blocksize); + + struct lio_driver* drv = &res->tree->service->lio_ops; + uint8_t* bounce = calloc(1, bytes_aligned); + uint8_t* p = bounce; + uint64_t curoffset = offset_aligned; + int old_flags; + + old_flags = s->flags; + s->flags |= LIO_READ; + ret = lio_pread(s, offset_aligned, bytes_aligned, bounce); + s->flags = old_flags; + + if (ret < 0) { + goto out; + } + memcpy(bounce + (offset - offset_aligned), buf, bytes); + + ret = drv->write(res, curoffset, bytes_aligned, p); + if (ret >= 0) { + ret = bytes; + } + + // Offset zeigt jetzt auf das erste Byte nach dem letzten geschriebenen + if (ret > 0){ + if (res->size < offset) { + res->size = offset; + } + } + +out: + free(bounce); + return ret; +} + +/** + * Position veraendern. Funktioniert nur, wenn die Ressource seekable ist, und + * es sich um keine Pipe handelt. + * + * @param offset Offset um den die Position angepasst werden soll. Wie sie genau + * angepasst wird, haengt vom Parameter whence ab. + * @param whence Einer der drei Werte aus enum lio_seek_whence. + * - LIO_SEEK_SET: Position auf den angegebenen Wert setzen. + * - LIO_SEEK_CUR: Angegebenen Wert zur aktuellen Position + * dazu addieren. + * - LIO_SEEK_END: Position auf das Dateiende setzen. + * + * @return Neue Position oder < 0 im Fehlerfall. + */ +int64_t lio_seek(struct lio_stream* s, int64_t offset, int whence) +{ + if ((s->res_read != s->res_write) || !s->res_read->seekable) { + return -EINVAL; + } + + switch (whence) { + case LIO_SEEK_SET: + if (offset < 0) { + return -EINVAL; + } else { + s->pos_read = offset; + } + break; + + case LIO_SEEK_CUR: + if ((int64_t)(s->pos_read + offset) < 0) { + return -EINVAL; + } else { + s->pos_read += offset; + } + break; + + case LIO_SEEK_END: + if ((int64_t)(s->res_read->size + offset) < 0) { + return -EINVAL; + } else { + s->pos_read = s->res_read->size + offset; + } + break; + default: + return -EINVAL; + } + + return s->pos_read; +} + +/** + * Schreibt Aenderungen, die bisher nur im Cache sind, zurueck. Dabei werden + * nur die Cluster beruecksichtigt, die im angegebenen Bereich liegen. + * + * @param s Stream, dessen Aendungen geschrieben werden sollen + * @param offset Start des zurueckzuschreibenden Bereichs (in Bytes) + * @param bytes Laenge des zurueckzuschreibenden Bereichs (in Bytes) oder 0, + * falls die gesamte Datei zurueckgeschrieben werden soll + * + * @return 0 bei Erfolg, ungleich 0 im Fehlerfall + * + * @attention Diese Funktion ist unterbrechbar + */ +int lio_sync_blocks(struct lio_resource* res, uint64_t offset, size_t bytes) +{ + return 0; +} + +/** + * Schreibt alle zum Zeitpunkt des Aufrufs der Funktion vorhandenen + * Aenderungen, die bisher nur im Cache sind, zurueck + * + * @return 0 bei Erfolg, ungleich 0 im Fehlerfall + * @attention Diese Funktion ist unterbrechbar + */ +int lio_sync(struct lio_stream* s) +{ + struct lio_resource* res = s->res_write; + struct lio_driver* drv = &res->tree->service->lio_ops; + + /* + * TODO Muss z.B. ata nochmal gesynct werden, nachdem ext2 dran war? Ist es + * Aufgabe des Treibers oder von LIO? + */ + if (drv->sync) { + drv->sync(res); + } + + return 0; +} + +/** + * Alle veraenderten Blocks im Cache rausschreiben + * + * @param soft Wenn true, wird nicht blockiert, wenn ein Cluster nicht gesynct + * werden kann. Es wird auch kein Fehler zurückgegeben. (Ziel ist es, einfach + * irgendwelche Dirty-Cluster loszuwerden) + * + * @return 0 bei Erfolg, -errno im Fehlerfall + */ +int lio_sync_all(bool soft) +{ + return 0; +} + +/** + * Aendert die Dateigroesse + * + * @param size Neue Dateigroesse + * @return 0 bei Erfolg, negativ im Fehlerfall + */ +int lio_truncate(struct lio_stream* s, uint64_t size) +{ + struct lio_resource* res = s->res_write; + struct lio_driver* drv = &res->tree->service->lio_ops; + + /* Zunaechst den Treiber informieren */ + if (drv->truncate) { + int ret = drv->truncate(res, size); + if (ret < 0) { + return ret; + } + } + + /* Anschliessend die Ressourcengroesse anpassen (drv->truncate kann das + * u.U. auch schon gemacht haben) */ + res->size = size; + + return 0; +} + +/** + * Schliesst einen Stream + * + * @return 0 bei Erfolg, ungleich 0 im Fehlerfall + */ +int lio_close(struct lio_stream* s) +{ + if (s->res->tree->service->lio_ops.close) { + s->res->tree->service->lio_ops.close(s); + } + + free(s); + return 0; +} + +/** + * Inhalt eines Verzeichnisses auslesen + */ +ssize_t lio_read_dir(struct lio_resource* dir, size_t start, size_t num, + struct lio_dir_entry* buf) +{ + struct lio_node* node; + size_t cnt = 0; + + /* Die Ressource muss auch wirklich ein Verzeichnis sein */ + if (!dir->browsable) { + return -EBADF; + } + + /* Wenn der Aufrufer keine Eintraege will, sind wir fertig */ + if (!num) { + return 0; + } + + /* Zunaechst kommt der Eintrag fuer . */ + if (start == 0) { + strcpy(buf[0].name, "."); + buf[0].resource = dir; + lio_stat(dir, &buf[0].stat); + cnt++; + } + + /* Und dann der ganzer Rest */ + if (!dir->children) { + dir->tree->service->lio_ops.load_children(dir); + } + + for (; (cnt < num) && + (node = list_get_element_at(dir->children, start - 1 + cnt));) + { + buf[cnt].resource = node->res; + strncpy(buf[cnt].name, node->name, LIO_MAX_FNLEN); + buf[cnt].name[LIO_MAX_FNLEN] = 0; + lio_stat(node->res, &buf[cnt].stat); + cnt++; + } + + return cnt; +} + +/** Erstellt eine neue Datei */ +struct lio_resource* lio_mkfile(struct lio_resource* parent, const char* name) +{ + if (!parent->tree->service->lio_ops.make_file || !parent->changeable) { + return NULL; + } + + return parent->tree->service->lio_ops.make_file(parent, name); +} + +/** Erstellt ein neues Verzeichnis */ +struct lio_resource* lio_mkdir(struct lio_resource* parent, const char* name) +{ + if (!parent->tree->service->lio_ops.make_dir || !parent->changeable) { + return NULL; + } + + return parent->tree->service->lio_ops.make_dir(parent, name); +} + +/** Erstellt einen neuen Symlink */ +struct lio_resource* lio_mksymlink(struct lio_resource* parent, + const char* name, const char* target) +{ + if (!parent->tree->service->lio_ops.make_symlink || !parent->changeable) { + return NULL; + } + + return parent->tree->service->lio_ops.make_symlink(parent, name, target); +} + +/** + * Gibt Informationen zu einer Ressource zurueck + */ +int lio_stat(struct lio_resource* resource, struct lio_stat* sbuf) +{ + memset(sbuf, 0, sizeof(*sbuf)); + sbuf->size = resource->size; + + sbuf->flags = (resource->readable ? LIO_FLAG_READABLE : 0) | + (resource->writable ? LIO_FLAG_WRITABLE : 0) | + (resource->browsable ? LIO_FLAG_BROWSABLE : 0) | + (resource->changeable ? LIO_FLAG_CHANGEABLE : 0) | + (resource->resolvable ? LIO_FLAG_RESOLVABLE : 0) | + (resource->retargetable ? LIO_FLAG_RETARGETABLE : 0) | + (resource->seekable ? LIO_FLAG_SEEKABLE : 0) | + (resource->ispipe ? LIO_FLAG_PIPE : 0); + return 0; +} + +/** Verzeichniseintrag loeschen */ +int lio_unlink(struct lio_resource* parent, const char* name) +{ + if (!parent->tree->service->lio_ops.unlink) { + return -EINVAL; + } + + return parent->tree->service->lio_ops.unlink(parent, name); +} + diff --git a/src/kernel2/src/lostio/include/lostio_int.h b/src/kernel2/src/lostio/include/lostio_int.h index 63d3630..db3a98e 100644 --- a/src/kernel2/src/lostio/include/lostio_int.h +++ b/src/kernel2/src/lostio/include/lostio_int.h @@ -42,7 +42,98 @@ #include "lostio/core.h" #include "tasks.h" +#define ROUND_TO_NEXT_BLOCK(bytes, blocksize) \ + ((bytes) + (blocksize) - 1) & ~((blocksize) - 1) +#define ROUND_TO_BLOCK_DOWN(bytes, blocksize) \ + ((bytes)) & ~((blocksize) - 1) + struct lio_service; +struct lio_driver { + /** + * Laedt alle Kindknoten nach res->children + */ + int (*load_children)(struct lio_resource* res); + + /** + * Wird aufgerufen wenn eine Ressource geoeffnet wird. + * + * @return 0 bei Erfolg, negativ bei Fehlern. Bei einem Fehler wird das + * Oeffnen abgebrochen. + */ + int (*preopen)(struct lio_stream* stream); + + /** Stream wird geschlossen */ + void (*close)(struct lio_stream* stream); + + /** Erstellt eine neue Datei */ + struct lio_resource* (*make_file)(struct lio_resource* parent, + const char* name); + + /** Erstellt ein neues Verzeichnis */ + struct lio_resource* (*make_dir)(struct lio_resource* parent, + const char* name); + + /** Erstellt einen neuen Symlink */ + struct lio_resource* (*make_symlink)(struct lio_resource* parent, + const char* name, const char* target); + + /** Verzeichniseintrag loeschen */ + int (*unlink)(struct lio_resource* parent, const char* name); + + /** + * Laedt Daten vom Service in den Cache. + * offset und bytes muessen auf die Blockgroesse ausgerichtet sein. + * + * @return 0 bei Erfolg (Puffer ist komplett gelesen), negativ im + * Fehlerfall. + * + * TODO iovec statt bytes/buf + */ + int (*read)(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf); + + /** + * Schreibt Daten aus dem Cache in den Service zurueck + * offset und bytes muessen auf die Blockgroesse ausgerichtet sein. + * + * @return 0 bei Erfolg (Puffer ist komplett geschrieben), negativ im + * Fehlerfall. + * + * TODO iovec statt bytes/buf + */ + int (*write)(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf); + + /** Schreibt eventuelle im Treiber gecachte Daten zurueck */ + int (*sync)(struct lio_resource* res); + + /** + * Setzt die Dateigroesse. + * + * Diese Funktion wird auch aufgerufen, bevor eine Datei durch einen + * Schreibzugriff vergroessert wird. Ein Service kann write()-Aufrufe + * hinter dem Dateiende verwerfen. + */ + int (*truncate)(struct lio_resource* res, uint64_t size); + +}; + + +/** + * Beschreibt einen LostIO-Service. + */ +struct lio_service { + /** Eindeutiger Name des Service */ + char* name; + + /** Funktionspointer, die den eigentlichen Treiber implementieren */ + struct lio_driver lio_ops; + + /** Private Daten des Services */ + void* opaque; +}; + + /** * Beschreibt eine von LostIO verwaltete Ressource (d.h. in der Regel eine -- 1.6.0.2 From kevin at tyndur.org Sat Dec 10 21:37:59 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 10 Dec 2011 21:37:59 +0100 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH_v2_3/6=5D_kernel2=3A_Ressourcen?= =?utf-8?q?_und_Verzeichnisb=C3=A4ume?= In-Reply-To: <1323549482-1766-1-git-send-email-kevin@tyndur.org> References: <1323549482-1766-1-git-send-email-kevin@tyndur.org> Message-ID: <1323549482-1766-4-git-send-email-kevin@tyndur.org> + kernel2: Funktionen zur Verwaltung von Services, Verzeichnisbäumen und Ressourcen Signed-off-by: Kevin Wolf --- src/kernel2/src/lostio/client.c | 105 ++++++++- src/kernel2/src/lostio/include/lostio_int.h | 73 ++++++ src/kernel2/src/lostio/lostio.c | 1 + src/kernel2/src/lostio/tree.c | 365 +++++++++++++++++++++++++++ 4 files changed, 542 insertions(+), 2 deletions(-) create mode 100644 src/kernel2/src/lostio/tree.c diff --git a/src/kernel2/src/lostio/client.c b/src/kernel2/src/lostio/client.c index f87c6fa..43baadf 100644 --- a/src/kernel2/src/lostio/client.c +++ b/src/kernel2/src/lostio/client.c @@ -44,6 +44,35 @@ #include "lostio_int.h" /** + * Versucht den uebergebenen Symlink aufzuloesen. Wenn die Resource, auf die er + * Zeigt, existiert wird ein Zeiger darauf zurueckgegeben, NULL sonst. + * + * @return Zeiger auf das Ziel, oder NULL falls der Link nicht aufgeloest werden + * konnte. + */ +static struct lio_resource* resolve_symlink(struct lio_resource* link) +{ + char buf[link->size + 1]; + struct lio_stream* stream; + ssize_t len; + + if (!(stream = lio_open(link, LIO_READ | LIO_SYMLINK))) { + return NULL; + } + + len = lio_read(stream, link->size, buf); + lio_close(stream); + + if (len < 0) { + return NULL; + } + buf[len] = 0; + + // TODO: Relative Symlinks + return lio_get_resource(buf, 1); +} + +/** * Loest einen Pfad zu einer Ressource auf * * @return Die zum Pfad gehoerende Ressource oder NULL, wenn der Pfad keine @@ -51,8 +80,80 @@ */ struct lio_resource* lio_get_resource(const char* path, int follow_symlinks) { - /* TODO */ - return NULL; + struct lio_tree* tree; + struct lio_resource* res; + struct lio_node* node; + const char* rel_path; + char* tokenize_path; + char* name; + int i; + + // Passenden Baum raussuchen + tree = lio_get_tree(path, &rel_path); + if (tree == NULL) { + return NULL; + } + + node = tree->root; + + // Von der Wurzel aus durchhangeln + char* saveptr; + tokenize_path = strdup(rel_path); + name = strtok_r(tokenize_path, "/", &saveptr); + while (name != NULL) { + res = node->res; + + // Falls wir es mit einem Symlink zu tun haben, versuchen wir doch mal + // dem zu folgen. + if (res->resolvable) { + res = resolve_symlink(res); + + // War wohl nix + if (!res) { + goto out; + } + } + + tree = res->tree; + + // Wir suchen noch ein Kind, aber diese Ressource hat keine + if (!res->browsable) { + res = NULL; + goto out; + } + + // Falls die Liste der Kinder nicht geladen ist, nachholen + if (res->children == NULL) { + if (tree->service->lio_ops.load_children(res)) { + res = NULL; + goto out; + } + } + + // Passendes Kind raussuchen + for (i = 0; (node = list_get_element_at(res->children, i)); i++) { + if (strcmp(node->name, name) == 0) { + goto found; + } + } + res = NULL; + goto out; + +found: + // Passender Kindknoten wurde gefunden, weiter im Pfad + name = strtok_r(NULL, "/", &saveptr); + } + + res = node->res; + + // Auch das koennte noch mal ein Symlink sein, den wir aufloesen muessen + if (res && follow_symlinks && res->resolvable) { + res = resolve_symlink(res); + } + +out: + free(tokenize_path); + return res; } /** diff --git a/src/kernel2/src/lostio/include/lostio_int.h b/src/kernel2/src/lostio/include/lostio_int.h index db3a98e..86221f1 100644 --- a/src/kernel2/src/lostio/include/lostio_int.h +++ b/src/kernel2/src/lostio/include/lostio_int.h @@ -50,6 +50,12 @@ struct lio_service; struct lio_driver { /** + * Root-Ressource eines Dateisystems laden, das root-Feld in tree ist also + * noch NULL. + */ + struct lio_resource* (*load_root)(struct lio_tree* tree); + + /** * Laedt alle Kindknoten nach res->children */ int (*load_children)(struct lio_resource* res); @@ -202,10 +208,77 @@ struct lio_tree { /** + * Initialisiert die statischen Variablen von tree.c + */ +int lio_init_tree(void); + +/** * Initialisiert die Verwaltung der Userspace-Deskriptoren für Kernelobjekte */ int lio_init_userspace(void); +/** + * Neue Ressource initialisieren. + * Vom Aufrufer initialisiert werden muessen (werden alle auf 0 initialisiert): + * - blocksize + * - tree + * - Flags + * + * @return Zeiger auf die neue Ressource + */ +struct lio_resource* lio_create_resource(void); + +/** + * Interne Daten einer Ressource initialisieren. Dabei werden nur die internen + * Felder veraendert, der Rest muss vom Aufrufer gesetzt werden. Diese Funktion + * kann verwendet werden, wenn der Speicher fuer eine Resource bereits + * verfuegbar ist (beispielsweise bei statischem Speicher). + * + * @param res Zu initialisierende Ressource + */ +void lio_init_resource(struct lio_resource* res); + +/** + * Ressource zerstören und Speicher freigeben. Der Aufrufer ist dafür + * zuständig, allenfalls Caches zu syncen. + * + * @param res Zu zerstoerende Ressource + */ +void lio_destroy_resource(struct lio_resource* res); + +/** + * Loest einen gegebenen Pfad in einen Verzeichnisbaum und einen + * servicerelativen Pfad auf. + * + * @param path Aufzulosender Pfad + * @param rel_path Wenn rel_path != NULL ist, wird darin ein Pointer auf den + * servicerelativen Teil des Pfads zurueckgegeben + * + * @return Den zum Pfad gehoerenden Verzeichnisbaum oder NULL im Fehlerfall + */ +struct lio_tree* lio_get_tree(const char* path, const char** rel_path); + +/** + * Registriert einen neuen LIO-Service + */ +void lio_add_service(struct lio_service* service); + +/** Kindknoten einer Ressource suchen */ +struct lio_node* lio_resource_get_child(struct lio_resource* parent, + const char* name); + +/** Einer Resource einen Kindknoten anfuegen */ +void lio_resource_add_child(struct lio_resource* parent, + struct lio_node* child); + +/** Kindknoten einer Ressource entfernen */ +void lio_resource_remove_child(struct lio_resource* parent, + struct lio_node* child); + +/** Neuen Knoten anlegen und bei Elternressource als Kind eintragen */ +struct lio_node* lio_create_node(struct lio_resource* parent, + struct lio_resource* res, const char* name); + /** Weist einer Ressource eine Userspace-ID zu */ void lio_usp_add_resource(struct lio_resource* res); diff --git a/src/kernel2/src/lostio/lostio.c b/src/kernel2/src/lostio/lostio.c index 3843f4e..9a08d58 100644 --- a/src/kernel2/src/lostio/lostio.c +++ b/src/kernel2/src/lostio/lostio.c @@ -40,6 +40,7 @@ void lio_init(void) { + lio_init_tree(); lio_init_userspace(); return; diff --git a/src/kernel2/src/lostio/tree.c b/src/kernel2/src/lostio/tree.c new file mode 100644 index 0000000..4078d52 --- /dev/null +++ b/src/kernel2/src/lostio/tree.c @@ -0,0 +1,365 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include "kernel.h" +#include "kprintf.h" + +#include "lostio/core.h" +#include "lostio/client.h" +#include "lostio_int.h" + +static list_t* lio_trees; +static list_t* lio_services; + +/** + * Initialisiert die statischen Variablen dieser Datei + */ +int lio_init_tree(void) +{ + lio_trees = list_create(); + lio_services = list_create(); + + return 0; +} + +/** + * Erzeugt einen neuen Verzeichnisbaum. Das root-Feld im der Baum-Struktur muss + * vom Aufrufer eingefuellt werden. + * + * @param serv LIO-Service, der den Baum verwaltet + * @param source LIO-Stream der Datenquelle + * + * @return Den neu angelegten Baum oder NULL im Fehlerfall + */ +static struct lio_tree* lio_add_tree(struct lio_service* serv, + struct lio_stream* source) +{ + struct lio_tree* tree; + + // TODO Der Service sollte auch wirklich fuer den Pfad zustaendig sein + + // Neuen Baum anlegen und in die Liste pushen + tree = calloc(1, sizeof(*tree)); + tree->service = serv; + tree->source = source; + + lio_usp_add_tree(tree); + + return tree; +} + +/** + * Zerlegt einen Pfad. Die zwei uebergebenen Zeiger zeigen anschliessend auf + * den Namen des zustaendigen Services bzw. den Anfang des servicerelativen + * Pfads im Originalpfad. + * + * Im Fehlerfall (der Pfad enthaelt kein ":/") wird rel_path auf NULL gesetzt. + */ +static void split_path(const char* path, const char** service, + const char** rel_path) +{ + const char* service_name; + const char* tmp_rel_path; + + service_name = strrchr(path, '|'); + if (service_name == NULL) { + service_name = path; + } else { + service_name++; + } + + tmp_rel_path = strstr(service_name, ":/"); + if (tmp_rel_path != NULL) { + tmp_rel_path += 2; + } + + *service = service_name; + *rel_path = tmp_rel_path; +} + +/** + * Sucht den richtigen Service zur Verarbeitung eines Pfads und erzeugt einen + * neuen Verzeichnisbaum fuer diesen. + * + * @param path Pfad der zu oeffnenden Datei + * @param rel_path Wenn rel_path != NULL ist, wird darin ein Pointer auf den + * servicerelativen Teil des Pfads zurueckgegeben. + * + * @return Den neu angelegten Verzeichnisbaum oder NULL im Fehlerfall + */ +static struct lio_tree* mount(const char* path, const char** rel_path) +{ + struct lio_stream* source_stream; + struct lio_resource* source_res; + struct lio_service* service; + struct lio_resource* root_res; + struct lio_node* root_node; + struct lio_tree* tree; + const char* service_name; + const char* tmp_rel_path; + int i; + + // Pfad aufsplitten + split_path(path, &service_name, &tmp_rel_path); + + // Passenden Service suchen + for (i = 0; (service = list_get_element_at(lio_services, i)); i++) { + + size_t len = strlen(service->name); + + if (len != tmp_rel_path - 2 - service_name) { + continue; + } + + if (!strncmp(service->name, service_name, len)) { + goto found; + } + } + return NULL; + +found: + + // Quelle oeffnen + source_stream = NULL; + if (path == service_name) { + source_stream = NULL; + } else { + char* source; + source = malloc(service_name - path); + strncpy(source, path, service_name - path - 1); + source[service_name - path - 1] = '\0'; + + if (!(source_res = lio_get_resource(source, 1))) { + return NULL; + } + + // TODO: Was machen wir hier mit den Flags fuer fopen genau? + source_stream = lio_open(source_res, LIO_READ | LIO_WRITE); + free(source); + + if (source_stream == NULL) { + return NULL; + } + } + + tree = lio_add_tree(service, source_stream); + + // Wurzelressource laden + root_res = service->lio_ops.load_root(tree); + if (root_res == NULL) { + if (source_stream) { + lio_close(source_stream); + } + goto out_err; + } + + // Wurzelknoten fuer neuen Baum anlegen + root_node = calloc(1, sizeof(*root_node)); + root_node->res = root_res; + root_node->name = malloc(tmp_rel_path - path + 1); + strncpy(root_node->name, path, tmp_rel_path - path); + root_node->name[tmp_rel_path - path] = '\0'; + + tree->root = root_node; + root_node->res->tree = tree; + + // Neuen Baum registrieren + list_push(lio_trees, tree); + if (rel_path) { + *rel_path = tmp_rel_path; + } + + return tree; + +out_err: + lio_usp_remove_tree(tree); + free(tree); + return NULL; +} + +/** + * Loest einen gegebenen Pfad in einen Verzeichnisbaum und einen + * servicerelativen Pfad auf. + * + * @param path Aufzulosender Pfad + * @param rel_path Wenn rel_path != NULL ist, wird darin ein Pointer auf den + * servicerelativen Teil des Pfads zurueckgegeben + * + * @return Den zum Pfad gehoerenden Verzeichnisbaum oder NULL im Fehlerfall + */ +struct lio_tree* lio_get_tree(const char* path, const char** rel_path) +{ + int i; + struct lio_tree* tree; + const char* service_name; + const char* tmp_rel_path; + + // Pfad fuer den Baum heraussucen + split_path(path, &service_name, &tmp_rel_path); + if (rel_path) { + *rel_path = tmp_rel_path; + } + + // Suchen, ob es schon einen Baum fuer den Pfad gibt + for (i = 0; (tree = list_get_element_at(lio_trees, i)); i++) { + if (!tree->root) { + panic("BUG: lio_tree ohne Wurzel"); + } + + if (strlen(tree->root->name) != (tmp_rel_path - path)) { + continue; + } + + if (!strncmp(tree->root->name, path, tmp_rel_path - path)) { + return tree; + } + } + + // Neuen Baum anlegen + tree = mount(path, rel_path); + + return tree; +} + +/** + * Registriert einen neuen LIO-Service + */ +void lio_add_service(struct lio_service* service) +{ + list_push(lio_services, service); +} + +/** + * Neue Ressource initialisieren. + * Vom Aufrufer initialisiert werden muessen (werden alle auf 0 initialisiert): + * - blocksize + * - tree + * - Flags + * + * @return Zeiger auf die neue Ressource + */ +struct lio_resource* lio_create_resource(void) +{ + struct lio_resource* res = calloc(sizeof(*res), 1); + + lio_init_resource(res); + + return res; +} + +/** + * Interne Daten einer Ressource initialisieren. Dabei werden nur die internen + * Felder veraendert, der Rest muss vom Aufrufer gesetzt werden. Diese Funktion + * kann verwendet werden, wenn der Speicher fuer eine Resource bereits + * verfuegbar ist (beispielsweise bei statischem Speicher). + * + * @param res Zu initialisierende Ressource + */ +void lio_init_resource(struct lio_resource* res) +{ + lio_usp_add_resource(res); +} + +/** + * Ressource zerstoeren und Speicher freigeben. Der Aufrufer ist dafuer + * allenfalls Caches zu syncen. + * + * @param res Zu zerstoerende Ressource + */ +void lio_destroy_resource(struct lio_resource* res) +{ + lio_usp_remove_resource(res); + free(res); +} + +/** Kindknoten einer Ressource suchen */ +struct lio_node* lio_resource_get_child(struct lio_resource* parent, + const char* name) +{ + struct lio_node* n; + size_t i; + + for (i = 0; (n = list_get_element_at(parent->children, i)); i++) { + if (!strcmp(name, n->name)) { + return n; + } + } + + return NULL; +} + +/** Einer Resource einen Kindknoten anfuegen */ +void lio_resource_add_child(struct lio_resource* parent, + struct lio_node* child) +{ + if (!parent->children) { + parent->children = list_create(); + } + + list_push(parent->children, child); +} + +/** Kindknoten einer Ressource entfernen */ +void lio_resource_remove_child(struct lio_resource* parent, + struct lio_node* child) +{ + struct lio_node* n; + size_t i; + + // FIXME: Hier brauchen wir irgendwann noch gescheite Locks + for (i = 0; (n = list_get_element_at(parent->children, i)); i++) { + if (n == child) { + list_remove(parent->children, i); + break; + } + } +} + +/** Neuen Knoten anlegen und bei Elternressource als Kind eintragen */ +struct lio_node* lio_create_node(struct lio_resource* parent, + struct lio_resource* res, const char* name) +{ + struct lio_node* n = calloc(sizeof(*n), 1); + + n->res = res; + n->name = strdup(name); + lio_resource_add_child(parent, n); + + return n; +} + -- 1.6.0.2 From kevin at tyndur.org Sat Dec 10 21:38:00 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 10 Dec 2011 21:38:00 +0100 Subject: [tyndur-devel] [PATCH v2 4/6] kernel2: LIOv2-Service tmp In-Reply-To: <1323549482-1766-1-git-send-email-kevin@tyndur.org> References: <1323549482-1766-1-git-send-email-kevin@tyndur.org> Message-ID: <1323549482-1766-5-git-send-email-kevin@tyndur.org> + kernel2: tmp:/ stellt eine dateisystembasierte RAM-Disk zur Verfügung Signed-off-by: Kevin Wolf --- src/kernel2/src/arch/i386/Makefile.all | 2 +- src/kernel2/src/lostio/lostio.c | 4 + src/kernel2/src/lostio/modules/tmp.c | 223 ++++++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+), 1 deletions(-) create mode 100644 src/kernel2/src/lostio/modules/tmp.c diff --git a/src/kernel2/src/arch/i386/Makefile.all b/src/kernel2/src/arch/i386/Makefile.all index 0a63791..57bcb56 100644 --- a/src/kernel2/src/arch/i386/Makefile.all +++ b/src/kernel2/src/arch/i386/Makefile.all @@ -9,5 +9,5 @@ $LOST_TOOLS_OBJCOPY -B i386:i386 -I binary -O elf32-i386 rm_trampoline.o rm_tram rm rm_trampoline.o echo "LD $1/kernel/tyndur2" -$LOST_TOOLS_LD -otyndur2.krn -Tkernel.ld header.o --start-group !(header).o */*.o $KERNEL/*.o $KERNEL/*/!(rm_trampoline).o $2 --end-group +$LOST_TOOLS_LD -otyndur2.krn -Tkernel.ld header.o --start-group !(header).o */*.o $KERNEL/*.o $KERNEL/*/!(rm_trampoline).o $KERNEL/lostio/*/*.o $2 --end-group mv tyndur2.krn $1/kernel/tyndur2 diff --git a/src/kernel2/src/lostio/lostio.c b/src/kernel2/src/lostio/lostio.c index 9a08d58..779b7c3 100644 --- a/src/kernel2/src/lostio/lostio.c +++ b/src/kernel2/src/lostio/lostio.c @@ -38,10 +38,14 @@ #include "lostio/core.h" #include "lostio_int.h" +extern void lio_init_tmp(void); + void lio_init(void) { lio_init_tree(); lio_init_userspace(); + lio_init_tmp(); + return; } diff --git a/src/kernel2/src/lostio/modules/tmp.c b/src/kernel2/src/lostio/modules/tmp.c new file mode 100644 index 0000000..412e47b --- /dev/null +++ b/src/kernel2/src/lostio/modules/tmp.c @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include "kprintf.h" + +#include "lostio/core.h" +#include "lostio/client.h" +#include "lostio_int.h" + +#define BLOCKSIZE 1024 + +static struct lio_resource root_res = { + .size = 0, + .blocksize = BLOCKSIZE, + .changeable = 1, + .browsable = 1, + .children = NULL, + .opaque = NULL, +}; + +struct tmp_state { + void* buf; + size_t size; +}; + +static struct lio_resource* load_root(struct lio_tree* tree) +{ + if (tree->source) { + return NULL; + } + + lio_init_resource(&root_res); + return &root_res; +} + +static int load_children(struct lio_resource* res) +{ + return 0; +} + +static int tmp_read(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf) +{ + struct tmp_state* s = res->opaque; + + if (bytes % BLOCKSIZE) { + bytes += BLOCKSIZE - (bytes % BLOCKSIZE); + } + + if (s->buf && (offset < res->size)) { + if (bytes > (s->size - offset)) { + size_t total = bytes; + bytes = s->size - offset; + memset((char*) buf + bytes, 0, total - bytes); + } + memcpy(buf, s->buf + offset, bytes); + } else { + memset(buf, 0, bytes); + } + + return 0; +} + +static int tmp_write(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf) +{ + struct tmp_state* s = res->opaque; + + if (res->size <= offset) { + /* Hinter das Dateiende wird nicht geschrieben */ + return -EIO; + } else if (s->size < offset + bytes) { + /* Der Puffer muss vergroessert werden */ + void* p = realloc(s->buf, offset + bytes); + if (p == NULL) { + return -ENOMEM; + } + s->buf = p; + s->size = offset + bytes; + } + + memcpy(s->buf + offset, buf, bytes); + + return 0; +} + +static struct lio_resource* make_file(struct lio_resource* parent, + const char* name) +{ + struct lio_resource* res; + struct tmp_state* s; + + res = lio_create_resource(); + lio_create_node(parent, res, name); + + res->blocksize = BLOCKSIZE; + res->readable = 1; + res->writable = 1; + res->seekable = 1; + res->tree = parent->tree; + + s = calloc(1, sizeof(*s)); + res->opaque = s; + + return res; +} + +static struct lio_resource* make_dir(struct lio_resource* parent, + const char* name) +{ + struct lio_resource* res; + + res = lio_create_resource(); + lio_create_node(parent, res, name); + + res->blocksize = BLOCKSIZE; + res->browsable = 1; + res->changeable = 1; + res->tree = parent->tree; + + return res; +} + +static struct lio_resource* make_symlink(struct lio_resource* parent, + const char* name, const char* target) +{ + struct lio_resource* res; + struct tmp_state* s; + + res = lio_create_resource(); + lio_create_node(parent, res, name); + + res->blocksize = BLOCKSIZE; + res->resolvable = 1; + res->retargetable = 1; + res->tree = parent->tree; + + s = calloc(1, sizeof(*s)); + s->buf = strdup(target); + s->size = strlen(s->buf); + + res->opaque = s; + res->size = s->size; + + return res; +} + +static int unlink(struct lio_resource* parent, const char* name) +{ + struct lio_node* child; + struct lio_resource* res; + + if (!(child = lio_resource_get_child(parent, name))) { + return -ENOENT; + } + res = child->res; + + // Ressource hat noch Kinder + if (res->browsable && list_size(res->children)) { + return -EEXIST; + } + + lio_sync_blocks(res, 0, 0); + lio_resource_remove_child(parent, child); + lio_destroy_resource(res); + return 0; +} + + +static struct lio_service service = { + .name = "tmp", + .lio_ops = { + .load_root = load_root, + .load_children = load_children, + .read = tmp_read, + .write = tmp_write, + .make_file = make_file, + .make_dir = make_dir, + .make_symlink = make_symlink, + .unlink = unlink, + }, +}; + +void lio_init_tmp(void) +{ + lio_add_service(&service); +} -- 1.6.0.2 From kevin at tyndur.org Sat Dec 10 21:38:01 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 10 Dec 2011 21:38:01 +0100 Subject: [tyndur-devel] [PATCH v2 5/6] kernel2: LIOv2-Clientsyscalls implementiert In-Reply-To: <1323549482-1766-1-git-send-email-kevin@tyndur.org> References: <1323549482-1766-1-git-send-email-kevin@tyndur.org> Message-ID: <1323549482-1766-6-git-send-email-kevin@tyndur.org> + 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 --- 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..aa27ace 100644 --- a/src/kernel2/src/syscalls/lostio.c +++ b/src/kernel2/src/syscalls/lostio.c @@ -41,72 +41,219 @@ #include "syscall.h" #include +#include "lostio/client.h" +#include "lostio/userspace.h" + /// 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 From kevin at tyndur.org Sat Dec 10 21:38:02 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 10 Dec 2011 21:38:02 +0100 Subject: [tyndur-devel] [PATCH v2 6/6] kernel2: Beim Prozessende offene Dateien schliessen In-Reply-To: <1323549482-1766-1-git-send-email-kevin@tyndur.org> References: <1323549482-1766-1-git-send-email-kevin@tyndur.org> Message-ID: <1323549482-1766-7-git-send-email-kevin@tyndur.org> + kernel2: Wenn ein Prozess beendet wird, dann werden auch alle offenen Dateien geschlossen Signed-off-by: Kevin Wolf --- src/kernel2/include/tasks.h | 3 +++ src/kernel2/src/syscalls/pm.c | 7 +++++++ src/kernel2/src/tasks/pm.c | 33 +++++++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/kernel2/include/tasks.h b/src/kernel2/include/tasks.h index 5256e0f..1b719d7 100644 --- a/src/kernel2/include/tasks.h +++ b/src/kernel2/include/tasks.h @@ -155,6 +155,9 @@ void pm_init(void); /// Prozess erstellen pm_process_t* pm_create(pm_process_t* parent, const char* cmdline); +/// Datenstrukturen eines Prozesses freigeben (vor dem Taskwechsel) +void pm_prepare_destroy(pm_process_t* process); + /// Prozess zerstoeren void pm_destroy(pm_process_t* process); diff --git a/src/kernel2/src/syscalls/pm.c b/src/kernel2/src/syscalls/pm.c index 806e827..eb63254 100644 --- a/src/kernel2/src/syscalls/pm.c +++ b/src/kernel2/src/syscalls/pm.c @@ -82,9 +82,16 @@ void syscall_pm_exit_process(void) { pm_process_t* old_task = current_process; + // Ein paar erste Datenstrukturen freigeben + pm_prepare_destroy(old_task); + // Task abgeben pm_scheduler_push(current_thread); + // Den Prozess blockieren + while (pm_block(old_task) == false); + + // Genau jetzt muss der Prozess geloescht werden: Der Thread ist nicht mehr // aktiv, und er darf auch nicht wieder aktiviert werden. pm_destroy(old_task); diff --git a/src/kernel2/src/tasks/pm.c b/src/kernel2/src/tasks/pm.c index 047c4d5..e3085c5 100644 --- a/src/kernel2/src/tasks/pm.c +++ b/src/kernel2/src/tasks/pm.c @@ -45,6 +45,7 @@ #include "lock.h" #include "timer.h" #include "lostio/core.h" +#include "lostio/client.h" #include "lostio/userspace.h" @@ -180,6 +181,33 @@ pm_process_t* pm_create(pm_process_t* parent, const char* cmdline) } /** + * Datenstrukturen eines Prozesses freigeben (falls von diesem Prozess selbst + * aufgerufen, darf der Task noch nicht gewechselt worden sein, damit + * unterbrechbare LIOv2-Funktionen benutzt werden koennen) + * + * @param process Pointer auf die Prozssstruktur. + */ +void pm_prepare_destroy(pm_process_t* process) +{ + // Alle Dateien schliessen und freigeben + struct lio_usp_stream* fd = NULL; + struct lio_usp_stream* next = NULL; + struct lio_stream* s; + + fd = tree_next(process->lio_streams, NULL); + while (fd != NULL) { + next = tree_next(process->lio_streams, fd); + + s = fd->stream; + lio_usp_remove_stream(process, fd); + lio_close(s); + + fd = next; + } + tree_destroy(process->lio_streams); +} + +/** * Prozess zerstoeren * * @param process Pointer auf die Prozssstruktur. @@ -194,9 +222,6 @@ void pm_destroy(pm_process_t* process) mmc_activate(&init_process.context); } - // Den Prozess blockieren - while (pm_block(process) == false); - // Eventhandler ausfuehren while ((info = list_pop(process->on_destroy))) { info->handler(process, info->prv); @@ -238,7 +263,7 @@ void pm_destroy(pm_process_t* process) while ((thread = list_get_element_at(process->threads, i++))) { pm_thread_destroy(thread); } - + // Kommandozeile freigeben free(process->cmdline); -- 1.6.0.2 From max at tyndur.org Sun Dec 11 22:11:07 2011 From: max at tyndur.org (Max Reitz) Date: Sun, 11 Dec 2011 22:11:07 +0100 Subject: [tyndur-devel] [PATCH 1/2] shell: bincat: Kein fseek auf NULL aufrufen In-Reply-To: <1323523093-9772-2-git-send-email-kevin@tyndur.org> References: <1323523093-9772-1-git-send-email-kevin@tyndur.org> <1323523093-9772-2-git-send-email-kevin@tyndur.org> Message-ID: <4EE51C6B.3050502@tyndur.org> On 10.12.2011 14:18, Kevin Wolf wrote: > ! shell: Wenn bincat die Datei nicht öffnen kann, muss es sofort einen > Fehler zurückgeben und nicht erst noch den NULL-Pointer an fseek > weitergeben, damit es garantiert rot gibt. > > Signed-off-by: Kevin Wolf [...] > > + if (file == NULL) { > + printf(TMS(bincat_opening_error, > + "Konnte '%s' nicht zum lesen öffnen!\n"), path); Na, eigentlich sollte das "zum Lesen" sein. ;-) Sieht aber recht sinnstiftend aus. Acked-by: Max Reitz From max at tyndur.org Sun Dec 11 22:14:24 2011 From: max at tyndur.org (Max Reitz) Date: Sun, 11 Dec 2011 22:14:24 +0100 Subject: [tyndur-devel] [PATCH 2/2] shell: Neuer Befehl sync In-Reply-To: <1323523093-9772-3-git-send-email-kevin@tyndur.org> References: <1323523093-9772-1-git-send-email-kevin@tyndur.org> <1323523093-9772-3-git-send-email-kevin@tyndur.org> Message-ID: <4EE51D30.8000806@tyndur.org> On 10.12.2011 14:18, Kevin Wolf wrote: > + shell: Neuer Befehl sync, der lio_sync_all() aufruft. Geht im Moment > natürlich noch schief, weil der Kernel das noch nicht kann. > > Signed-off-by: Kevin Wolf [...] > > + " sync Alle veraenderten Block im Cache rausschreiben\n" Nicht eher "Bloecke"? ;-) Ansonsten weiß ich zwar nicht, ob der Syscall wirklich so aufgerufen wird, aber der Rest sieht korrekt aus. Acked-by: Max Reitz From max at tyndur.org Sun Dec 11 22:19:42 2011 From: max at tyndur.org (Max Reitz) Date: Sun, 11 Dec 2011 22:19:42 +0100 Subject: [tyndur-devel] [PATCH 2/2] shell: Neuer Befehl sync In-Reply-To: <4EE51D30.8000806@tyndur.org> References: <1323523093-9772-1-git-send-email-kevin@tyndur.org> <1323523093-9772-3-git-send-email-kevin@tyndur.org> <4EE51D30.8000806@tyndur.org> Message-ID: <4EE51E6E.5080009@tyndur.org> Oh, ich nehme mein Ack (vorerst) zurück, ich habe gerade in der anderen Patchserie gesehen, dass lio_sync_all anscheinend noch einen bool-Parameter benötigt - ist das in syscall.h ein anderes lio_sync_all als das in lostio/client.h? Max From kevin at tyndur.org Sun Dec 11 22:59:00 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 11 Dec 2011 22:59:00 +0100 Subject: [tyndur-devel] [PATCH 1/2] shell: bincat: Kein fseek auf NULL aufrufen In-Reply-To: <4EE51C6B.3050502@tyndur.org> References: <1323523093-9772-1-git-send-email-kevin@tyndur.org> <1323523093-9772-2-git-send-email-kevin@tyndur.org> <4EE51C6B.3050502@tyndur.org> Message-ID: <20111211215859.GA10129@silvanus> On Sun, Dec 11, 2011 at 10:11:07PM +0100, Max Reitz wrote: > On 10.12.2011 14:18, Kevin Wolf wrote: > >! shell: Wenn bincat die Datei nicht öffnen kann, muss es sofort einen > > Fehler zurückgeben und nicht erst noch den NULL-Pointer an fseek > > weitergeben, damit es garantiert rot gibt. > > > >Signed-off-by: Kevin Wolf > [...] > > > >+ if (file == NULL) { > >+ printf(TMS(bincat_opening_error, > >+ "Konnte '%s' nicht zum lesen öffnen!\n"), path); > Na, eigentlich sollte das "zum Lesen" sein. ;-) Ist zwar nur verschobener Code, aber ich fix das dann gleich noch vor dem git push. From kevin at tyndur.org Sun Dec 11 23:07:21 2011 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 11 Dec 2011 23:07:21 +0100 Subject: [tyndur-devel] [PATCH 2/2] shell: Neuer Befehl sync In-Reply-To: <4EE51E6E.5080009@tyndur.org> References: <1323523093-9772-1-git-send-email-kevin@tyndur.org> <1323523093-9772-3-git-send-email-kevin@tyndur.org> <4EE51D30.8000806@tyndur.org> <4EE51E6E.5080009@tyndur.org> Message-ID: <20111211220721.GB10129@silvanus> On Sun, Dec 11, 2011 at 10:19:42PM +0100, Max Reitz wrote: > Oh, ich nehme mein Ack (vorerst) zurück, ich habe gerade in der > anderen Patchserie gesehen, dass lio_sync_all anscheinend noch einen > bool-Parameter benötigt - ist das in syscall.h ein anderes > lio_sync_all als das in lostio/client.h? Hm, gute Frage. Unterschiedliche Funktionen sind es auf jeden Fall, einmal libc und einmal im Kernel, aber ob sie unterschiedlich funktionieren, muss ich erstmal nachschauen... Die libc-Funktion sieht so aus: int lio_sync_all(void) { int result; asm( "pushl $0;" "int $0x30;" "add $0x4, %%esp;" : "=a" (result) : "0" (SYSCALL_LIO_SYNC_ALL)); return result; } Der Syscall ist definiert als: int syscall_lio_sync_all(int soft); Und er ruft folgendes auf: int lio_sync_all(bool soft) Ich glaube, das passt also soweit (außer dass es vielleicht schön wäre, wenn es auch für die andere Variante eine libc-Funktion braucht - aber wirklich benutzt wird soft = true im Moment nur im LIOv2-Branch und nur vom Kerneltask, der den Cache zurückschreibt). Aber ich glaube es wäre nicht verkehrt, sich für int oder bool zu entscheiden und es nicht zu mischen... Kevin From max at tyndur.org Mon Dec 26 01:34:32 2011 From: max at tyndur.org (Max Reitz) Date: Mon, 26 Dec 2011 01:34:32 +0100 Subject: [tyndur-devel] [PATCH] libc: inet_addr Message-ID: <1324859672-23570-1-git-send-email-max@tyndur.org> + Ein weiterer Wrapper neben inet_aton um ip_to_string. Signed-off-by: Max Reitz --- src/modules/include/arpa/inet.h | 7 +++++++ src/modules/include/netinet/in.h | 6 ++++++ src/modules/lib/posix/net.c | 10 ++++++++++ 3 files changed, 23 insertions(+), 0 deletions(-) diff --git a/src/modules/include/arpa/inet.h b/src/modules/include/arpa/inet.h index 4689df6..7d1741a 100644 --- a/src/modules/include/arpa/inet.h +++ b/src/modules/include/arpa/inet.h @@ -50,6 +50,13 @@ unsigned short int ntohs(unsigned short int netshort); int inet_aton(const char* ip_string, struct in_addr* ip); /** + * Tut im Grunde das Gleiche wie inet_aton. + * + * @return INADDR_NONE (0) im Fehlerfall; Adresswert bei Erfolg + */ +in_addr_t inet_addr(const char* ip_string); + +/** * Wandelt eine 32-Bit-Adresse in einen String um. Der String ist in einem * statischen Puffer und wird beim naechsten Aufruf ueberschrieben. */ diff --git a/src/modules/include/netinet/in.h b/src/modules/include/netinet/in.h index 8e95fce..8c8cbf9 100644 --- a/src/modules/include/netinet/in.h +++ b/src/modules/include/netinet/in.h @@ -35,6 +35,12 @@ /// Laenge einer IP-Adresse als String #define INET_ADDRSTRLEN 16 +/// Ungueltige IP-Adresse +#define INADDR_NONE 0x00000000 + +/// Adresse, die fuer alle lokalen IP-Adressen steht +#define INADDR_ANY 0x00000000 + typedef uint32_t in_addr_t; struct in_addr { in_addr_t s_addr; diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c index f470a63..b25b177 100644 --- a/src/modules/lib/posix/net.c +++ b/src/modules/lib/posix/net.c @@ -105,6 +105,16 @@ int inet_aton(const char* ip_string, struct in_addr* ip) } /** + * Tut im Grunde das Gleiche wie inet_aton. + * + * @return INADDR_NONE (0) im Fehlerfall; Adresswert bei Erfolg + */ +in_addr_t inet_addr(const char* ip_string) +{ + return string_to_ip((char*) ip_string); +} + +/** * Wandelt eine 32-Bit-Adresse in einen String um. Der String ist in einem * statischen Puffer und wird beim naechsten Aufruf ueberschrieben. */ -- 1.7.8.1 From max at tyndur.org Mon Dec 26 02:07:57 2011 From: max at tyndur.org (Max Reitz) Date: Mon, 26 Dec 2011 02:07:57 +0100 Subject: [tyndur-devel] [PATCH] lbuilds: sdldoom 1.10 Message-ID: <1324861677-3732-1-git-send-email-max@tyndur.org> + Das altbekannte heitere Familienspiel für Jung und Alt, jetzt endlich auch für týndur. Netzwerk funktioniert hoffentlich automatisch, sobald UDP implementiert wurde. Signed-off-by: Max Reitz --- lbuilds/sdldoom/1.10/files/bool.patch | 19 +++++++++++ lbuilds/sdldoom/1.10/files/network.patch | 42 ++++++++++++++++++++++++ lbuilds/sdldoom/1.10/files/series | 4 ++ lbuilds/sdldoom/1.10/files/sprintf.patch | 13 +++++++ lbuilds/sdldoom/1.10/files/strupr.patch | 17 ++++++++++ lbuilds/sdldoom/1.10/sdldoom-1.10.lbuild | 51 ++++++++++++++++++++++++++++++ 6 files changed, 146 insertions(+), 0 deletions(-) create mode 100644 lbuilds/sdldoom/1.10/files/bool.patch create mode 100644 lbuilds/sdldoom/1.10/files/network.patch create mode 100644 lbuilds/sdldoom/1.10/files/series create mode 100644 lbuilds/sdldoom/1.10/files/sprintf.patch create mode 100644 lbuilds/sdldoom/1.10/files/strupr.patch create mode 100644 lbuilds/sdldoom/1.10/sdldoom-1.10.lbuild diff --git a/lbuilds/sdldoom/1.10/files/bool.patch b/lbuilds/sdldoom/1.10/files/bool.patch new file mode 100644 index 0000000..d54038b --- /dev/null +++ b/lbuilds/sdldoom/1.10/files/bool.patch @@ -0,0 +1,19 @@ +Index: sdldoom-1.10/doomtype.h +=================================================================== +--- sdldoom-1.10.orig/doomtype.h 1999-12-21 06:16:09.000000000 +0100 ++++ sdldoom-1.10/doomtype.h 2011-12-26 01:20:58.000000000 +0100 +@@ -31,13 +31,12 @@ + #ifdef __cplusplus + typedef bool boolean; + #else +-#ifdef __BEOS__ /* boolean is a builtin type for MWCC */ ++#include + #define boolean D_BOOL + #undef false + #define false D_false + #undef true + #define true D_true +-#endif + typedef enum {false, true} boolean; + #endif + typedef unsigned char byte; diff --git a/lbuilds/sdldoom/1.10/files/network.patch b/lbuilds/sdldoom/1.10/files/network.patch new file mode 100644 index 0000000..e1c7e34 --- /dev/null +++ b/lbuilds/sdldoom/1.10/files/network.patch @@ -0,0 +1,42 @@ +Index: sdldoom-1.10/i_net.c +=================================================================== +--- sdldoom-1.10.orig/i_net.c 1999-12-21 06:16:16.000000000 +0100 ++++ sdldoom-1.10/i_net.c 2011-12-26 00:36:33.000000000 +0100 +@@ -51,7 +51,11 @@ + #define Win32_Winsock + #include + #else +-#error You should hack this file for your BSD sockets layer ++#include ++#include ++#include ++#include ++#include + #endif + #endif + #endif +@@ -107,6 +111,10 @@ + // NETWORKING + // + ++#ifndef IPPORT_USERRESERVED ++#define IPPORT_USERRESERVED 1024 ++#endif ++ + int DOOMPORT = (IPPORT_USERRESERVED +0x1d ); + + int sendsocket; +@@ -261,10 +269,13 @@ + struct hostent* hostentry; // host information entry + int v; + ++ /* + // get local address + v = gethostname (hostname, sizeof(hostname)); + if (v == -1) + I_Error ("GetLocalAddress : gethostname: errno %d",errno); ++ */ ++ strcpy(hostname, "localhost"); + + hostentry = gethostbyname (hostname); + if (!hostentry) diff --git a/lbuilds/sdldoom/1.10/files/series b/lbuilds/sdldoom/1.10/files/series new file mode 100644 index 0000000..d61f479 --- /dev/null +++ b/lbuilds/sdldoom/1.10/files/series @@ -0,0 +1,4 @@ +network.patch +strupr.patch +sprintf.patch +bool.patch diff --git a/lbuilds/sdldoom/1.10/files/sprintf.patch b/lbuilds/sdldoom/1.10/files/sprintf.patch new file mode 100644 index 0000000..86377fb --- /dev/null +++ b/lbuilds/sdldoom/1.10/files/sprintf.patch @@ -0,0 +1,13 @@ +Index: sdldoom-1.10/hu_stuff.c +=================================================================== +--- sdldoom-1.10.orig/hu_stuff.c 2011-12-26 00:01:09.000000000 +0100 ++++ sdldoom-1.10/hu_stuff.c 2011-12-26 00:01:27.000000000 +0100 +@@ -405,7 +405,7 @@ + j = HU_FONTSTART; + for (i=0;i> series + (which quilt > /dev/null 2>&1) || (patch -p1 < $i) || die "Fehler beim Anwenden von $i" + done + (which quilt > /dev/null 2>&1) && quilt push -a || die "Fehler beim Anwenden der Patches" +} + +src_configure() { + cd ${MY_S} + + CC=`tc-cc` CFLAGS="-nostdinc -I `tc-incdir` -I `tc-incdir`/SDL -L`tc-libdir`" ./configure --host=`tc-host` --prefix="${R}" || die "Fehler beim Configure" +} + +src_compile() { + cd ${MY_S} + + lmake || die "Fehler beim Bauen" +} + +src_install() { + cd ${MY_S} + + lmake DESTDIR="${D}" install || die "Fehler beim Installieren" + + gunzip "${DISTDIR}/doom1.wad.gz" + rm -f "${DISTDIR}/doom1.wad.gz" + mkdir -p "${D}/${R}/share/doom" + mv "${DISTDIR}/doom1.wad" "${D}/${R}/share/doom" +} -- 1.7.8.1 From max at tyndur.org Mon Dec 26 15:48:56 2011 From: max at tyndur.org (Max Reitz) Date: Mon, 26 Dec 2011 15:48:56 +0100 Subject: [tyndur-devel] [PATCH] lbuilds: sdldoom 1.10 Message-ID: <1324910936-9582-1-git-send-email-max@tyndur.org> ! Wenn das lustige Familienspiel keine familienfreundlichen Welten laden kann, ist es schwierig, sich mit all den Menschen, denen man darin begegnet, anzufreunden. Signed-off-by: Max Reitz --- lbuilds/sdldoom/1.10/files/sprintf.patch | 26 ++++++++++++++++++++++++-- lbuilds/sdldoom/1.10/sdldoom-1.10.lbuild | 1 - 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lbuilds/sdldoom/1.10/files/sprintf.patch b/lbuilds/sdldoom/1.10/files/sprintf.patch index 86377fb..683418f 100644 --- a/lbuilds/sdldoom/1.10/files/sprintf.patch +++ b/lbuilds/sdldoom/1.10/files/sprintf.patch @@ -1,7 +1,7 @@ Index: sdldoom-1.10/hu_stuff.c =================================================================== ---- sdldoom-1.10.orig/hu_stuff.c 2011-12-26 00:01:09.000000000 +0100 -+++ sdldoom-1.10/hu_stuff.c 2011-12-26 00:01:27.000000000 +0100 +--- sdldoom-1.10.orig/hu_stuff.c 1999-12-21 06:16:16.000000000 +0100 ++++ sdldoom-1.10/hu_stuff.c 2011-12-26 15:24:15.000000000 +0100 @@ -405,7 +405,7 @@ j = HU_FONTSTART; for (i=0;iepsd != 1 || j != 8) + { + // animations +- sprintf(name, "WIA%d%.2d%.2d", wbs->epsd, j, i); ++ sprintf(name, "WIA%d%02d%02d", wbs->epsd, j, i); + a->p[i] = W_CacheLumpName(name, PU_STATIC); + } + else diff --git a/lbuilds/sdldoom/1.10/sdldoom-1.10.lbuild b/lbuilds/sdldoom/1.10/sdldoom-1.10.lbuild index 131e6cf..90906ac 100644 --- a/lbuilds/sdldoom/1.10/sdldoom-1.10.lbuild +++ b/lbuilds/sdldoom/1.10/sdldoom-1.10.lbuild @@ -14,7 +14,6 @@ MY_S="${S}/${P}" src_unpack() { lunpack ${P}.tar.gz - mv doom1.wad ${MY_S} cd ${MY_S} -- 1.7.8.1