[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Lost] [Patch] ramdisk
Am Donnerstag, 28. August 2008 23:25:22 schrieb stultus / dunklermeuchler:
> + ramdisk_fs_destroy. Das Dateisystem kann jetzt auch restlos abgebaut
> werden, bzw sollte es zumindenst.
> Index: src/modules/cdi/ramdisk/dir.c
> ===================================================================
> --- src/modules/cdi/ramdisk/dir.c (revision 0)
> +++ src/modules/cdi/ramdisk/dir.c (revision 0)
> @@ -0,0 +1,63 @@
> +/*
> + * Copyright (c) 2008 The LOST Project. All rights reserved.
> + *
> + * This code is derived from software contributed to the LOST Project
> + * by Alexander Siol.
> + *
> + * 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 LOST Project
> + * and its contributors.
> + * 4. Neither the name of the LOST 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 <string.h>
> +
> +#include "ramdisk_cdi.h"
> +
> +
> +cdi_list_t ramdisk_fs_dir_list(struct cdi_fs_stream* stream)
> +{
> + return stream->res->children;
> +}
> +
> +int ramdisk_fs_dir_create_child(struct cdi_fs_stream* stream, const char*
> name, + struct cdi_fs_res* parent)
> +{
> + struct ramdisk_fs_res* res = malloc(sizeof(*res));
> + struct ramdisk_fs_res* parent_res = (struct ramdisk_fs_res*) parent;
> +
> + memset(res, 0, sizeof(*res));
> +
> + res->res.loaded = 1;
> +
> + res->res.name = strdup(name);
> + res->res.res = &ramdisk_fs_res;
> +
> + cdi_list_push(parent_res->res.children, res);
> + res->res.parent = parent;
> +
> + stream->res = (struct cdi_fs_res*) res;
> + return 1;
> +}
> Index: src/modules/cdi/ramdisk/ramdisk_cdi.h
> ===================================================================
> --- src/modules/cdi/ramdisk/ramdisk_cdi.h (revision 0)
> +++ src/modules/cdi/ramdisk/ramdisk_cdi.h (revision 0)
> @@ -0,0 +1,103 @@
> +/*
> + * Copyright (c) 2008 The LOST Project. All rights reserved.
> + *
> + * This code is derived from software contributed to the LOST Project
> + * by Alexander Siol.
> + *
> + * 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 LOST Project
> + * and its contributors.
> + * 4. Neither the name of the LOST 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 _RAMDISK_CDI_H_
> +#define _RAMDISK_CDI_H_
> +
> +#include <stdint.h>
> +#include <stdlib.h>
> +
> +#include "cdi/fs.h"
> +
> +
> +/**
> + * Dateisystemressource fuer ramdisk
> + */
> +struct ramdisk_fs_res {
> + struct cdi_fs_res res;
Nenn das besser cdi. Zeilen wie res->res.res sind nicht gerade intuitiv
verständlich.
> +
> + // Buffer fuer die Daten, und dessen Groesse
> + void* buffer;
> + size_t size;
> +
> + // Zugriffszeiten (Meta-Informationen)
> + int64_t access_time;
> + int64_t modification_time;
> +};
> +
> +
> +// CDI-IF
> +int ramdisk_fs_init(struct cdi_fs_filesystem* fs);
> +int ramdisk_fs_destroy(struct cdi_fs_filesystem* fs);
> +
> +// CDI Res
> +int ramdisk_fs_res_load(struct cdi_fs_stream* stream);
> +int ramdisk_fs_res_unload(struct cdi_fs_stream* stream);
> +//int ramdisk_fs_res_remove(struct cdi_fs_stream* stream);
> +//int ramdisk_fs_res_rename(struct cdi_fs_stream* stream, const char*
> name); +//int ramdisk_fs_res_move(struct cdi_fs_stream* stream, struct
> cdi_fs_res* dest); +int ramdisk_fs_res_assign_class(struct
> cdi_fs_stream* stream, + cdi_fs_res_class_t class);
> +//int ramdisk_fs_res_remove_class(struct cdi_fs_stream* stream,
> +// cdi_fs_res_class_t class);
Entweder rein oder raus. Auskommentierter Code ist lokal zwar toll, aber
nichts für das SVN.
> +int64_t ramdisk_fs_res_meta_read(struct cdi_fs_stream* stream,
> cdi_fs_meta_t meta); +int ramdisk_fs_res_meta_write(struct
> cdi_fs_stream* stream, cdi_fs_meta_t meta, + int64_t value);
> +
> +// CDI File
> +size_t ramdisk_fs_file_read(struct cdi_fs_stream* stream, uint64_t start,
> + size_t size, void* data);
> +size_t ramdisk_fs_file_write(struct cdi_fs_stream* stream, uint64_t
> start, + size_t size, const void* data);
> +int ramdisk_fs_file_truncate(struct cdi_fs_stream* stream, uint64_t
> size); +
> +// CDI Dir
> +cdi_list_t ramdisk_fs_dir_list(struct cdi_fs_stream* stream);
> +int ramdisk_fs_dir_create_child(struct cdi_fs_stream* stream,
> + const char* name, struct cdi_fs_res* parent);
> +
> +// CDI Link
> +//const char* ramdisk_fs_link_read(struct cdi_fs_stream* stream);
> +//int ramdisk_fs_link_write(struct cdi_fs_stream* stream, const
> char* path); +
> +
> +// ramdisk-Ressourcen(-Typen)
> +extern struct cdi_fs_res_res ramdisk_fs_res;
> +extern struct cdi_fs_res_file ramdisk_fs_file;
> +extern struct cdi_fs_res_dir ramdisk_fs_dir;
> +extern struct cdi_fs_res_link ramdisk_fs_link;
> +
> +#endif
> +
> Index: src/modules/cdi/ramdisk/file.c
> ===================================================================
> --- src/modules/cdi/ramdisk/file.c (revision 0)
> +++ src/modules/cdi/ramdisk/file.c (revision 0)
> @@ -0,0 +1,95 @@
> +/*
> + * Copyright (c) 2008 The LOST Project. All rights reserved.
> + *
> + * This code is derived from software contributed to the LOST Project
> + * by Alexander Siol.
> + *
> + * 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 LOST Project
> + * and its contributors.
> + * 4. Neither the name of the LOST 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 "ramdisk_cdi.h"
> +
> +size_t ramdisk_fs_file_read(struct cdi_fs_stream* stream, uint64_t start,
> + size_t size, void* data)
> +{
> + struct ramdisk_fs_res* res = (struct ramdisk_fs_res*) stream->res;
> +
> + // maximal bis Ende lesen.
> + if ((res->size - start) < size) {
> + size = res->size - start;
> + }
> +
> + memcpy(data, res->buffer + start, size);
> + return size;
> +}
> +
> +size_t ramdisk_fs_file_write(struct cdi_fs_stream* stream, uint64_t start,
> + size_t size, const void* data)
> +{
> + struct ramdisk_fs_res* res = (struct ramdisk_fs_res*) stream->res;
> +
> + // Es soll mehr geschrieben werden als Platz ist. Buffer
> vergroessern!. + if ((res->size - start) < size) {
> + void* new_buffer;
> + size_t new_size;
> + new_size = start + size;
> + if (!(new_buffer = realloc(res->buffer,new_size))) {
> + stream->error = CDI_FS_ERROR_INTERNAL;
> + return 0;
> + }
> + memset(res->buffer + res->size, 0, new_size - res->size);
Das ist unnötig, wird ja vom memcpy gleich wieder überschrieben.
> + res->buffer = new_buffer;
> + res->size = new_size;
> + }
> +
> + memcpy(res->buffer + start, data, size);
> + return size;
> +}
> +
> +int ramdisk_fs_file_truncate(struct cdi_fs_stream* stream, uint64_t size)
> +{
> + struct ramdisk_fs_res* res = (struct ramdisk_fs_res*) stream->res;
> +
> + // Nichts zu tun
> + if (size == res->size) {
> + return 1;
> + }
> +
> + void* new_buffer;
> + if (!(new_buffer = realloc(res->buffer,size))) {
> + stream->error = CDI_FS_ERROR_INTERNAL;
> + }
return 0?
> + if (res->size < size) {
> + memset(new_buffer + res->size,0,size - res->size);
> + }
> +
> + res->buffer = new_buffer;
> + res->size = size;
> + return 1;
> +}
> Index: src/modules/cdi/ramdisk/init.c
> ===================================================================
> --- src/modules/cdi/ramdisk/init.c (revision 0)
> +++ src/modules/cdi/ramdisk/init.c (revision 0)
> @@ -0,0 +1,77 @@
> +/*
> + * Copyright (c) 2008 The LOST Project. All rights reserved.
> + *
> + * This code is derived from software contributed to the LOST Project
> + * by Alexander Siol.
> + *
> + * 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 LOST Project
> + * and its contributors.
> + * 4. Neither the name of the LOST 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 "ramdisk_cdi.h"
> +#include <stdio.h>
> +
> +static int dir_clear(struct cdi_fs_res* real_res)
> +{
> + struct ramdisk_fs_res* res = (struct ramdisk_fs_res*) real_res;
> + struct ramdisk_fs_res* child;
> +
> + while ((child = cdi_list_pop(res->res.children))) {
> + if (child->res.dir) {
> + dir_clear((struct cdi_fs_res*)child);
> + }
> + free(child->res.name);
> + free(child->buffer);
> + free(child);
> + }
> +
> + cdi_list_destroy(res->res.children);
> + res->res.children = NULL;
> + return 1;
> +}
> +
> +int ramdisk_fs_init(struct cdi_fs_filesystem* cdi_fs)
> +{
> + struct ramdisk_fs_res* root_res;
> +
> + root_res = malloc(sizeof(*root_res));
> + memset(root_res, 0, sizeof(*root_res));
> + root_res->res.name = strdup("/");
Warum kann man nicht einfach "/" ohne strdup nehmen? Wird der String später
verändert?
> + root_res->res.res = &ramdisk_fs_res;
> + root_res->res.dir = &ramdisk_fs_dir;
> + root_res->res.loaded = 1;
> +
> + cdi_fs->root_res = (struct cdi_fs_res*) root_res;
> + return 1;
> +}
> +
> +int ramdisk_fs_destroy(struct cdi_fs_filesystem* fs)
> +{
> + dir_clear(fs->root_res);
free?
> + return 0;
> +}
> Index: src/modules/cdi/ramdisk/Makefile.all
> ===================================================================
> --- src/modules/cdi/ramdisk/Makefile.all (revision 0)
> +++ src/modules/cdi/ramdisk/Makefile.all (revision 0)
> @@ -0,0 +1,6 @@
> +shopt -s extglob
> +source $LOST_BUILDMK_ROOT/config.sh
> +
> +echo "LD $1/modules/ramdisk"
> +$LOST_TOOLS_LD -oramdisk.mod -Ttext=0x40000000 *.o --start-group $2
> --end-group +$LOST_TOOLS_STRIP -s ramdisk.mod -o $1/modules/ramdisk
> Index: src/modules/cdi/ramdisk/main.c
> ===================================================================
> --- src/modules/cdi/ramdisk/main.c (revision 0)
> +++ src/modules/cdi/ramdisk/main.c (revision 0)
> @@ -0,0 +1,98 @@
> +/*
> + * Copyright (c) 2008 The LOST Project. All rights reserved.
> + *
> + * This code is derived from software contributed to the LOST Project
> + * by Alexander Siol.
> + *
> + * 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 LOST Project
> + * and its contributors.
> + * 4. Neither the name of the LOST 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 <stdint.h>
> +#include <stdlib.h>
> +#include <stdio.h>
> +
> +#include "cdi/fs.h"
> +#include "cdi/misc.h"
> +
> +#include "ramdisk_cdi.h"
> +
> +struct ramdisk_driver {
> + struct cdi_fs_driver fs;
> +};
> +
> +static struct ramdisk_driver ramdisk_driver;
> +static const char* driver_name = "ramdisk";
> +
> +static int ramdisk_driver_init(struct ramdisk_driver* driver);
> +static void ramdisk_driver_destroy(struct cdi_driver* driver);
> +
> +#ifdef CDI_STANDALONE
> +int main()
> +#else
> +int init_ramdisk
> +#endif
> +{
> + cdi_init();
> +
> + if (ramdisk_driver_init(&ramdisk_driver) != 0) {
> + return -1;
> + }
> + cdi_fs_driver_register((struct cdi_fs_driver*) &ramdisk_driver);
> +
> +#ifdef CDI_STANDALONE
> + cdi_run_drivers();
> +#endif
> +
> + return 0;
> +}
> +
> +/**
> + * Initialisiert die Datenstrukturen fuer den ramdisk-Treiber
> + */
> +static int ramdisk_driver_init(struct ramdisk_driver* driver)
> +{
> + // Konstruktor der Vaterklasse
> + cdi_fs_driver_init((struct cdi_fs_driver*) driver);
> +
> + // Namen setzen
> + driver->fs.drv.name = driver_name;
> + driver->fs.fs_init = ramdisk_fs_init;
> + driver->fs.fs_destroy = ramdisk_fs_destroy;
> +
> + driver->fs.drv.destroy = ramdisk_driver_destroy;
> + return 0;
> +}
> +
> +/**
> + * Deinitialisiert die Datenstrukturen fuer den ramdisk-Treiber
> + */
> +static void ramdisk_driver_destroy(struct cdi_driver* driver)
> +{
> + cdi_fs_driver_destroy((struct cdi_fs_driver*) driver);
> +}
> Index: src/modules/cdi/ramdisk/res.c
> ===================================================================
> --- src/modules/cdi/ramdisk/res.c (revision 0)
> +++ src/modules/cdi/ramdisk/res.c (revision 0)
> @@ -0,0 +1,156 @@
> +/*
> + * Copyright (c) 2008 The LOST Project. All rights reserved.
> + *
> + * This code is derived from software contributed to the LOST Project
> + * by Alexander Siol.
> + *
> + * 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 LOST Project
> + * and its contributors.
> + * 4. Neither the name of the LOST 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 "ramdisk_cdi.h"
> +
> +int ramdisk_fs_res_load(struct cdi_fs_stream* stream)
> +{
> + struct ramdisk_fs_res* res = (struct ramdisk_fs_res*) stream->res;
> +
> + if (res->res.loaded) {
> + return 0;
> + }
> +
> + res->res.loaded = 1;
> + return 1;
> +}
> +
> +int ramdisk_fs_res_unload(struct cdi_fs_stream* stream)
> +{
> + struct ramdisk_fs_res* res = (struct ramdisk_fs_res*) stream->res;
> +
> + if (!res->res.loaded) {
> + return 0;
> + }
> +
> + res->res.loaded = 0;
> + return 1;
> +}
> +
> +int64_t ramdisk_fs_res_meta_read(struct cdi_fs_stream* stream,
> cdi_fs_meta_t meta) +{
> + struct ramdisk_fs_res* res = (struct ramdisk_fs_res*) stream->res;
> +
> + switch (meta) {
> + case CDI_FS_META_SIZE:
> + return res->size;
> +
> + case CDI_FS_META_USEDBLOCKS:
> + return 1;
> +
> + case CDI_FS_META_BLOCKSZ:
> + return res->size;
> +
> + case CDI_FS_META_BESTBLOCKSZ:
> + return res->size;
> +
> + case CDI_FS_META_CREATETIME:
> + return res->modification_time;
> +
> + case CDI_FS_META_ACCESSTIME:
> + return res->access_time;
> +
> + case CDI_FS_META_CHANGETIME:
> + return res->modification_time;
> + }
> +
> + return 0;
> +}
Vielleicht vor dem return 0; noch einen Fehler setzen?
> +
> +int ramdisk_fs_res_meta_write(struct cdi_fs_stream* stream, cdi_fs_meta_t
> meta, + int64_t value)
> +{
> + struct ramdisk_fs_res* res = (struct ramdisk_fs_res*) stream->res;
> +
> + switch (meta) {
> + case CDI_FS_META_ACCESSTIME:
> + res->access_time = value;
> + return 1;
> +
> + case CDI_FS_META_CHANGETIME:
> + res->modification_time = value;
> + return 1;
> +
> + // RO:
> + case CDI_FS_META_SIZE:
> + case CDI_FS_META_USEDBLOCKS:
> + case CDI_FS_META_BESTBLOCKSZ:
> + case CDI_FS_META_BLOCKSZ:
> + case CDI_FS_META_CREATETIME:
> + return 0;
> + }
> +
> + return 0;
> +}
Hier jeweils auch.
> +
> +int ramdisk_fs_res_assign_class(struct cdi_fs_stream* stream,
> + cdi_fs_res_class_t class)
> +{
> + struct ramdisk_fs_res* res = (struct ramdisk_fs_res*) stream->res;
> +
> + // In ramdisk koennen die Ressource nur zu maximal einer Klasse
> gleichzeitig + // gehoeren
> + if (res->res.file || res->res.dir || res->res.link ||
> res->res.special) + {
> + stream->error = CDI_FS_ERROR_ONS;
> + return 0;
> + }
> +
> + switch (class) {
> + case CDI_FS_CLASS_FILE:
> + res->res.file = &ramdisk_fs_file;
> + break;
> +
> + case CDI_FS_CLASS_DIR:
> + res->res.dir = &ramdisk_fs_dir;
> + break;
> +
> + case CDI_FS_CLASS_LINK:
> + stream->error = CDI_FS_ERROR_NOT_IMPLEMENTED;
> + goto error_out;
> + break;
> +
> + case CDI_FS_CLASS_SPECIAL:
> + stream->error = CDI_FS_ERROR_NOT_IMPLEMENTED;
> + goto error_out;
> + break;
> +
> + };
> +
> + return 1;
> +
> +error_out:
> + return 0;
> +}
Ja, goto ist schon toll, um im Fehlerfall wieder Sachen freizugeben. Aber
direkt ein return 0; tut es hier eigentlich auch...
> Index: src/modules/cdi/ramdisk/resources.c
> ===================================================================
> --- src/modules/cdi/ramdisk/resources.c (revision 0)
> +++ src/modules/cdi/ramdisk/resources.c (revision 0)
> @@ -0,0 +1,67 @@
> +/*
> + * Copyright (c) 2008 The LOST Project. All rights reserved.
> + *
> + * This code is derived from software contributed to the LOST Project
> + * by Alexander Siol.
> + *
> + * 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 LOST Project
> + * and its contributors.
> + * 4. Neither the name of the LOST 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 "ramdisk_cdi.h"
> +
> +struct cdi_fs_res_res ramdisk_fs_res = {
> + .load = ramdisk_fs_res_load,
> + .unload = ramdisk_fs_res_unload,
> +
> + .meta_read = ramdisk_fs_res_meta_read,
> + .meta_write = ramdisk_fs_res_meta_write,
> +
> + .assign_class = ramdisk_fs_res_assign_class
> +};
> +
> +struct cdi_fs_res_file ramdisk_fs_file = {
> + // Prinzipiell haben wir nur ausfuehrbare Dateien, der Rest wird mit
> den + // Berechtigungen geregelt
> + .executable = 1,
> +
> + .read = ramdisk_fs_file_read,
> + .write = ramdisk_fs_file_write,
> + .truncate = ramdisk_fs_file_truncate
> +};
> +
> +struct cdi_fs_res_dir ramdisk_fs_dir = {
> + .list = ramdisk_fs_dir_list,
> + .create_child = ramdisk_fs_dir_create_child
> +};
> +
> +struct cdi_fs_res_link ramdisk_fs_link = {
> + .read_link = NULL,//ramdisk_fs_link_read,
> + .write_link = NULL,//ramdisk_fs_link_write
Auskommentierter Code
> +};
> +
Wenn man die structs in die passenden Dateien verschiebt, hätte man eine Datei
weniger, könnte im Editor direkt vom struct aus die Funktionen suchen und
nebenbei noch einen Haufen Funktionen static machen, oder?