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 **************************************/
22 /** \ingroup msg_file_management
23 * \brief Display information related to a file descriptor
25 * \param fd is a the file descriptor
28 void MSG_file_dump (msg_file_t fd){
30 /* Update the cached information first */
31 // fd->info = __MSG_file_get_info(fd);
32 // XBT_INFO("File Descriptor information:\n\t\tFull name: '%s'"
33 // "\n\t\tSize: %zu\n\t\tMount point: '%s'\n\t\t Storage Id: '%s'"
34 // "\n\t\t Content Type: '%s'", fd->fullname, fd->info->size, NULL,NULL,NULL);
35 // fd->info->mount_point, fd->info->storageId, fd->info->content_type);
38 /** \ingroup msg_file_management
41 * \param size of the file to read
42 * \param fd is a the file descriptor
43 * \return the number of bytes successfully read
45 size_t MSG_file_read(size_t size, msg_file_t fd)
47 return simcall_file_read(size, fd->simdata->smx_file);
50 /** \ingroup msg_file_management
51 * \brief Write into a file
53 * \param size of the file to write
54 * \param fd is a the file descriptor
55 * \return the number of bytes successfully write
57 size_t MSG_file_write(size_t size, msg_file_t fd)
59 return simcall_file_write(size, fd->simdata->smx_file);
62 /** \ingroup msg_file_management
63 * \brief Opens the file whose name is the string pointed to by path
65 * \param mount is the mount point where find the file is located
66 * \param path is the file location on the storage
68 * \return An #msg_file_t associated to the file
70 msg_file_t MSG_file_open(const char* mount, const char* fullname)
72 msg_file_t file = xbt_new(s_msg_file_t,1);
73 file->fullname = xbt_strdup(fullname);
74 file->simdata = xbt_new0(s_simdata_file_t,1);
75 file->simdata->smx_file = simcall_file_open(mount, fullname);
79 /** \ingroup msg_file_management
80 * \brief Close the file
82 * \param fd is the file to close
83 * \return 0 on success or 1 on error
85 int MSG_file_close(msg_file_t fd)
87 int res = simcall_file_close(fd->simdata->smx_file);
89 xbt_free(fd->simdata);
94 /** \ingroup msg_file_management
95 * \brief Unlink the file pointed by fd
97 * \param fd is the file descriptor (#msg_file_t)
98 * \return 0 on success or 1 on error
100 int MSG_file_unlink(msg_file_t fd)
102 return simcall_file_unlink(fd->simdata->smx_file);
105 /** \ingroup msg_file_management
106 * \brief Return the size of a file
108 * \param fd is the file descriptor (#msg_file_t)
109 * \return the size of the file (as a size_t)
112 size_t MSG_file_get_size(msg_file_t fd){
113 return simcall_file_get_size(fd->simdata->smx_file);
116 /** \ingroup msg_file_management
117 * \brief Search for file
119 * \param mount is the mount point where find the file is located
120 * \param path the file regex to find
121 * \return a xbt_dict_t of file where key is the name of file and the
122 * value the msg_stat_t corresponding to the key
124 xbt_dict_t MSG_file_ls(const char *mount, const char *path)
126 xbt_assert(path,"You must set path");
127 int size = strlen(path);
128 if(size && path[size-1] != '/')
130 char *new_path = bprintf("%s/",path);
131 XBT_DEBUG("Change '%s' for '%s'",path,new_path);
132 xbt_dict_t dict = simcall_file_ls(mount, new_path);
137 return simcall_file_ls(mount, path);
140 /** \ingroup msg_storage_management
141 * \brief Return the free space size of a storage element
143 * \param sd is the storage descriptor (#msg_storage_t)
144 * \return the free space size of the storage element (as a size_t)
147 size_t MSG_storage_get_free_size(msg_storage_t sd){
148 return simcall_storage_get_free_size(sd->simdata->smx_storage);