Am Sonntag, 24. August 2008 20.03:56 schrieb stultus / dunklermeuchler: > Index: src/modules/cdi/ramdisk/dir.c > =================================================================== >... > +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; > + res->buffer = NULL; > + res->size = 0; Hm ist ja eigentlich garnicht nötig wenn du oben eh res auf 0 setzt... > + > + 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/file.c > =================================================================== > +#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; > + } res->buffer = new_buffer; > + memset(res->buffer + res->size, 0, new_size - res->size); > + res->buffer = new_buffer; Dafür hier nicht. > + 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; > + } > + if (res->size < size) { > + memset(new_buffer + res->size,0,size - res->size); > + } Oder auch so, von mir aus... ;-) > + > + res->buffer = new_buffer; > + res->size = size; > + return 1; > +} > Index: src/modules/cdi/ramdisk/init.c > =================================================================== > .... > +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("/"); > + root_res->res.res = &ramdisk_fs_res; > + root_res->res.dir = &ramdisk_fs_dir; > + root_res->res.loaded = 1; > + root_res->buffer = 0; > + root_res->size = 0; Eigentlich auch unnötig. > + > + cdi_fs->root_res = (struct cdi_fs_res*) root_res; > + return 1; > +} > + > +int ramdisk_fs_destroy(struct cdi_fs_filesystem* fs) > +{ > + return 0; > +}
Attachment:
signature.asc
Description: This is a digitally signed message part.