From: Pierre Veyre Date: Fri, 8 Nov 2013 08:56:05 +0000 (+0100) Subject: Add MSG_file_rename function X-Git-Tag: v3_11_beta~346 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/985adefb9840db3a67c9d92856e861baa8a7b032?ds=sidebyside Add MSG_file_rename function --- diff --git a/include/msg/msg.h b/include/msg/msg.h index 144d42baa2..5976cc324a 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -94,7 +94,7 @@ XBT_PUBLIC(int) MSG_file_unlink(msg_file_t fd); XBT_PUBLIC(xbt_dict_t) MSG_file_ls(const char *mount, const char *path); XBT_PUBLIC(msg_error_t) MSG_file_move (msg_file_t fd, msg_host_t dest, char* mount, char* fullname); XBT_PUBLIC(msg_error_t) MSG_file_seek (msg_file_t fd, sg_storage_size_t offset, int whence); -XBT_PUBLIC(msg_error_t) MSG_file_rename (msg_file_t fd, char* new_name); +XBT_PUBLIC(msg_error_t) MSG_file_rename (msg_file_t fd, const char* new_name); XBT_PUBLIC(void) __MSG_file_get_info(msg_file_t fd); /************************** Storage handling ***********************************/ XBT_PUBLIC(msg_host_t) MSG_get_storage_by_name(const char *name); diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index ecdd1d62ed..b595bf6ee7 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -489,7 +489,7 @@ XBT_PUBLIC(int) simcall_file_unlink(smx_file_t fd); XBT_PUBLIC(xbt_dict_t) simcall_file_ls(const char* mount, const char* path); XBT_PUBLIC(sg_storage_size_t) simcall_file_get_size(smx_file_t fd); XBT_PUBLIC(xbt_dynar_t) simcall_file_get_info(smx_file_t fd); - +XBT_PUBLIC(void) simcall_file_rename(smx_file_t fd, const char* new_name); /***************************** Storage **********************************/ XBT_PUBLIC(sg_storage_size_t) simcall_storage_get_free_size (const char* name); XBT_PUBLIC(sg_storage_size_t) simcall_storage_get_used_size (const char* name); diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 0f0694a186..cce0dd9cbc 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -287,7 +287,7 @@ typedef struct surf_workstation_model_extension_public { surf_action_t(*ls) (void *workstation, const char* mount, const char *path); sg_storage_size_t (*get_size) (void *workstation, surf_file_t fd); xbt_dynar_t (*get_info) (void *workstation, surf_file_t fd); - + void (*rename) (void *workstation, surf_file_t fd, const char *new_name); int (*link_shared) (const void *link); xbt_dict_t(*get_properties) (const void *resource); void (*add_traces) (void); diff --git a/src/msg/msg_io.c b/src/msg/msg_io.c index cb2018a497..1aa60efaba 100644 --- a/src/msg/msg_io.c +++ b/src/msg/msg_io.c @@ -216,9 +216,9 @@ msg_error_t MSG_file_seek (msg_file_t fd, sg_storage_size_t offset, int whence) /* * Rename the file in the contents of its associated storage. */ -msg_error_t MSG_file_rename (msg_file_t fd, char* new_name) +msg_error_t MSG_file_rename (msg_file_t fd, const char* new_name) { - THROW_UNIMPLEMENTED; + simcall_file_rename(fd->simdata->smx_file, new_name); return MSG_OK; } diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index 07a354ca90..aa0d016316 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -300,6 +300,19 @@ xbt_dynar_t SIMIX_file_get_info(smx_process_t process, smx_file_t fd) fd->surf_file); } +void SIMIX_pre_file_rename(smx_simcall_t simcall, smx_file_t fd, const char* new_name) +{ + return SIMIX_file_rename(simcall->issuer, fd, new_name); +} + +void SIMIX_file_rename(smx_process_t process, smx_file_t fd, const char* new_name) +{ + smx_host_t host = process->smx_host; + return surf_workstation_model->extension.workstation.rename(host, + fd->surf_file, new_name); +} + + sg_storage_size_t SIMIX_pre_storage_get_free_size(smx_simcall_t simcall, const char* name) { return SIMIX_storage_get_free_size(simcall->issuer, name); diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index a3fea00b10..2e01b20fb9 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -34,6 +34,7 @@ void SIMIX_pre_file_ls(smx_simcall_t simcall, const char* mount, const char* path); sg_storage_size_t SIMIX_pre_file_get_size(smx_simcall_t simcall, smx_file_t fd); xbt_dynar_t SIMIX_pre_file_get_info(smx_simcall_t simcall, smx_file_t fd); +void SIMIX_pre_file_rename(smx_simcall_t simcall, smx_file_t fd, const char* new_name); void* SIMIX_file_get_data(smx_file_t fd); void SIMIX_file_set_data(smx_file_t fd, void *data); @@ -47,6 +48,7 @@ smx_action_t SIMIX_file_ls(smx_process_t process, const char *mount, const char *path); sg_storage_size_t SIMIX_file_get_size(smx_process_t process, smx_file_t fd); xbt_dynar_t SIMIX_file_get_info(smx_process_t process, smx_file_t fd); +void SIMIX_file_rename(smx_process_t process, smx_file_t fd, const char* new_name); sg_storage_size_t SIMIX_pre_storage_get_free_size(smx_simcall_t simcall,const char* name); sg_storage_size_t SIMIX_storage_get_free_size(smx_process_t process,const char* name); diff --git a/src/simix/smx_smurf_private.h b/src/simix/smx_smurf_private.h index 1e191f71e4..f3b01fdf57 100644 --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@ -357,6 +357,7 @@ ACTION(SIMCALL_FILE_UNLINK, file_unlink, WITH_ANSWER, TINT(result), TSPEC(fd, sm ACTION(SIMCALL_FILE_LS, file_ls, WITHOUT_ANSWER, TSPEC(result, xbt_dict_t), TSTRING(mount), TSTRING(path)) sep \ ACTION(SIMCALL_FILE_GET_SIZE, file_get_size, WITH_ANSWER, TSIZE(result), TSPEC(fd, smx_file_t)) sep \ ACTION(SIMCALL_FILE_GET_INFO, file_get_info, WITH_ANSWER, TSPEC(result, xbt_dynar_t), TSPEC(fd, smx_file_t)) sep \ +ACTION(SIMCALL_FILE_RENAME, file_rename, WITH_ANSWER, TVOID(result), TSPEC(fd, smx_file_t), TSTRING(new_name)) sep \ ACTION(SIMCALL_STORAGE_GET_FREE_SIZE, storage_get_free_size, WITH_ANSWER, TSIZE(result), TSTRING(name)) sep \ ACTION(SIMCALL_STORAGE_GET_USED_SIZE, storage_get_used_size, WITH_ANSWER, TSIZE(result), TSTRING(name)) sep \ ACTION(SIMCALL_STORAGE_GET_PROPERTIES, storage_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(storage, smx_storage_t)) sep \ diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index a4453a8cbd..a8d7f4cc12 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -1273,6 +1273,15 @@ xbt_dynar_t simcall_file_get_info(smx_file_t fd) return simcall_BODY_file_get_info(fd); } +/** + * \ingroup simix_file_management + * + */ +void simcall_file_rename(smx_file_t fd, const char* new_name) +{ + return simcall_BODY_file_rename(fd, new_name); +} + /** * \ingroup simix_storage_management * \brief Returns the free space size on a given storage element. diff --git a/src/surf/workstation.c b/src/surf/workstation.c index f50cf05b3d..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 */ @@ -473,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); @@ -551,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;