X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/fb5a144e806900edc6d26992740acf2c117538fa..985adefb9840db3a67c9d92856e861baa8a7b032:/src/surf/workstation.c diff --git a/src/surf/workstation.c b/src/surf/workstation.c index c4c000bb15..c986d51f21 100644 --- a/src/surf/workstation.c +++ b/src/surf/workstation.c @@ -11,6 +11,7 @@ #include "storage_private.h" #include "surf/surf_resource.h" #include "simgrid/sg_config.h" +#include typedef struct workstation_CLM03 { s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */ @@ -369,15 +370,14 @@ static xbt_dict_t ws_get_storage_list(void *workstation) { s_mount_t mnt; unsigned int i; - xbt_dict_t storage_list = xbt_dict_new(); + xbt_dict_t storage_list = xbt_dict_new_homogeneous(NULL); char *storage_name = NULL; workstation_CLM03_t ws = (workstation_CLM03_t) surf_workstation_resource_priv(workstation); xbt_dynar_t storages = ws->storage; - xbt_dynar_foreach(storages,i,mnt) - { - storage_name = ((storage_t)mnt.storage)->generic_resource.name; + xbt_dynar_foreach(storages,i,mnt){ + storage_name = ((storage_t)mnt.storage)->generic_resource.name; xbt_dict_set(storage_list,mnt.name,storage_name,NULL); } return storage_list; @@ -400,22 +400,20 @@ static surf_action_t ws_action_close(void *workstation, surf_file_t fd) return model->extension.storage.close(st, fd); } -static surf_action_t ws_action_read(void *workstation, sg_storage_size_t size, - surf_file_t fd) +static surf_action_t ws_action_read(void *workstation, surf_file_t fd, sg_storage_size_t size) { storage_t st = find_storage_on_mount_list(workstation, fd->mount); XBT_DEBUG("READ on disk '%s'",st->generic_resource.name); surf_model_t model = st->generic_resource.model; - return model->extension.storage.read(st, size, fd); + return model->extension.storage.read(st, fd, size); } -static surf_action_t ws_action_write(void *workstation, sg_storage_size_t size, - surf_file_t fd) +static surf_action_t ws_action_write(void *workstation, surf_file_t fd, sg_storage_size_t size) { storage_t st = find_storage_on_mount_list(workstation, fd->mount); XBT_DEBUG("WRITE on disk '%s'",st->generic_resource.name); surf_model_t model = st->generic_resource.model; - return model->extension.storage.write(st, size, fd); + return model->extension.storage.write(st, fd, size); } static int ws_file_unlink(void *workstation, surf_file_t fd) @@ -464,8 +462,10 @@ static sg_storage_size_t ws_file_get_size(void *workstation, surf_file_t fd) static xbt_dynar_t ws_file_get_info(void *workstation, surf_file_t fd) { storage_t st = find_storage_on_mount_list(workstation, fd->mount); + sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1); + *psize = fd->size; xbt_dynar_t info = xbt_dynar_new(sizeof(void*), NULL); - xbt_dynar_push_as(info, void *, (void*)fd->size); + xbt_dynar_push_as(info, sg_storage_size_t *, psize); xbt_dynar_push_as(info, void *, fd->mount); xbt_dynar_push_as(info, void *, st->generic_resource.name); xbt_dynar_push_as(info, void *, st->type_id); @@ -474,6 +474,34 @@ static xbt_dynar_t ws_file_get_info(void *workstation, surf_file_t fd) return info; } +static void ws_file_rename(void *workstation, surf_file_t fd, const char* new_name) +{ + storage_t storage = find_storage_on_mount_list(workstation, fd->mount); + + const char* old_full_name = fd->name; + xbt_dynar_t dyn = NULL; + const char* separator; + const char* ctype = storage->content_type; + + // TODO: PV: use an enum and a switch case to manage content type properly + if(!strcmp(ctype, "txt_unix")) + separator = strdup("/"); + else + separator = strdup("\\"); + + // Split file with separator and replace file name + dyn = xbt_str_split(old_full_name, separator); + xbt_dynar_pop_ptr(dyn); + xbt_dynar_push(dyn, &new_name); + char *new_full_name = xbt_str_join(dyn, separator); + + sg_storage_size_t *psize; + psize = (sg_storage_size_t*) xbt_dict_get_or_null(storage->content,old_full_name); + xbt_dict_remove(storage->content, old_full_name); + xbt_dict_set(storage->content,new_full_name,psize,NULL); + XBT_DEBUG("Change file name from %s to %s, size '%" PRIu64 "'",fd->name, new_full_name, *psize); +} + static sg_storage_size_t ws_storage_get_free_size(void *workstation,const char* name) { storage_t st = find_storage_on_mount_list(workstation, name); @@ -552,6 +580,7 @@ static void surf_workstation_model_init_internal(void) surf_workstation_model->extension.workstation.ls = ws_action_ls; surf_workstation_model->extension.workstation.get_size = ws_file_get_size; surf_workstation_model->extension.workstation.get_info = ws_file_get_info; + surf_workstation_model->extension.workstation.rename = ws_file_rename; surf_workstation_model->extension.workstation.get_free_size = ws_storage_get_free_size; surf_workstation_model->extension.workstation.get_used_size = ws_storage_get_used_size; surf_workstation_model->extension.workstation.get_storage_list = ws_get_storage_list;