1 /* Copyright (c) 2004 - 2013. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "msg_private.h"
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_io, msg,
11 "Logging specific to MSG (io)");
13 /** @addtogroup msg_file_management
14 * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Files" --> \endhtmlonly
15 * (#msg_file_t) and the functions for managing it.
20 /********************************* File **************************************/
21 void __MSG_file_get_info(msg_file_t fd){
22 xbt_dynar_t info = simcall_file_get_info(fd->simdata->smx_file);
23 fd->info->content_type = xbt_dynar_pop_as(info, char *);
24 fd->info->storage_type = xbt_dynar_pop_as(info, char *);
25 fd->info->storageId = xbt_dynar_pop_as(info, char *);
26 fd->info->mount_point = xbt_dynar_pop_as(info, char *);
27 fd->info->size = xbt_dynar_pop_as(info, size_t);
29 xbt_dynar_free_container(&info);
31 /** \ingroup msg_file_management
32 * \brief Display information related to a file descriptor
34 * \param fd is a the file descriptor
37 void MSG_file_dump (msg_file_t fd){
38 // THROW_UNIMPLEMENTED;
39 /* Update the cached information first */
40 __MSG_file_get_info(fd);
41 XBT_INFO("File Descriptor information:\n\t\tFull name: '%s'"
42 "\n\t\tSize: %zu\n\t\tMount point: '%s'\n\t\tStorage Id: '%s'"
43 "\n\t\tStorage Type: '%s'\n\t\tContent Type: '%s'",
44 fd->fullname, fd->info->size, fd->info->mount_point, fd->info->storageId,
45 fd->info->storage_type, fd->info->content_type);
48 /** \ingroup msg_file_management
51 * \param size of the file to read
52 * \param fd is a the file descriptor
53 * \return the number of bytes successfully read
55 size_t MSG_file_read(size_t size, msg_file_t fd)
57 return simcall_file_read(size, fd->simdata->smx_file);
60 /** \ingroup msg_file_management
61 * \brief Write into a file
63 * \param size of the file to write
64 * \param fd is a the file descriptor
65 * \return the number of bytes successfully write
67 size_t MSG_file_write(size_t size, msg_file_t fd)
69 return simcall_file_write(size, fd->simdata->smx_file);
72 /** \ingroup msg_file_management
73 * \brief Opens the file whose name is the string pointed to by path
75 * \param mount is the mount point where find the file is located
76 * \param path is the file location on the storage
78 * \return An #msg_file_t associated to the file
80 msg_file_t MSG_file_open(const char* mount, const char* fullname)
82 msg_file_t file = xbt_new(s_msg_file_t,1);
83 file->fullname = xbt_strdup(fullname);
84 file->simdata = xbt_new0(s_simdata_file_t,1);
85 file->info = xbt_new0(s_file_info_t,1);
86 file->simdata->smx_file = simcall_file_open(mount, fullname);
90 /** \ingroup msg_file_management
91 * \brief Close the file
93 * \param fd is the file to close
94 * \return 0 on success or 1 on error
96 int MSG_file_close(msg_file_t fd)
98 int res = simcall_file_close(fd->simdata->smx_file);
100 xbt_free(fd->simdata);
106 /** \ingroup msg_file_management
107 * \brief Unlink the file pointed by fd
109 * \param fd is the file descriptor (#msg_file_t)
110 * \return 0 on success or 1 on error
112 int MSG_file_unlink(msg_file_t fd)
114 return simcall_file_unlink(fd->simdata->smx_file);
117 /** \ingroup msg_file_management
118 * \brief Return the size of a file
120 * \param fd is the file descriptor (#msg_file_t)
121 * \return the size of the file (as a size_t)
124 size_t MSG_file_get_size(msg_file_t fd){
125 return simcall_file_get_size(fd->simdata->smx_file);
128 /** \ingroup msg_file_management
129 * \brief Search for file
131 * \param mount is the mount point where find the file is located
132 * \param path the file regex to find
133 * \return a xbt_dict_t of file where key is the name of file and the
134 * value the msg_stat_t corresponding to the key
136 xbt_dict_t MSG_file_ls(const char *mount, const char *path)
138 xbt_assert(path,"You must set path");
139 int size = strlen(path);
140 if(size && path[size-1] != '/')
142 char *new_path = bprintf("%s/",path);
143 XBT_DEBUG("Change '%s' for '%s'",path,new_path);
144 xbt_dict_t dict = simcall_file_ls(mount, new_path);
149 return simcall_file_ls(mount, path);
152 /** \ingroup msg_storage_management
153 * \brief Return the free space size of a storage element
154 * \param the storage name (#char*)
155 * \return the free space size of the storage element (as a size_t)
157 size_t MSG_storage_get_free_size(const char* name){
158 return simcall_storage_get_free_size(name);
161 /** \ingroup msg_storage_management
162 * \brief Return the used space size of a storage element
163 * \param the storage name (#char*)
164 * \return the used space size of the storage element (as a size_t)
166 size_t MSG_storage_get_used_size(const char* name){
167 return simcall_storage_get_used_size(name);