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);
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);
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);
/*
* 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;
}
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);
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);
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);
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 \
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.
#include "storage_private.h"
#include "surf/surf_resource.h"
#include "simgrid/sg_config.h"
+#include <inttypes.h>
typedef struct workstation_CLM03 {
s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */
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);
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;