Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add MSG_host_get_storage_list() function
[simgrid.git] / src / msg / msg_io.c
1 /* Copyright (c) 2004 - 2013. The SimGrid Team.
2  * All rights reserved.                                                       */
3
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.   */
6
7 #include "msg_private.h"
8 #include "xbt/log.h"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_io, msg,
11                                 "Logging specific to MSG (io)");
12
13 /** @addtogroup msg_file_management
14  *     \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Files" --> \endhtmlonly
15  * (#msg_file_t) and the functions for managing it.
16  *
17  *  \see #msg_file_t
18  */
19
20 /********************************* File **************************************/
21
22 /** \ingroup msg_file_management
23  * \brief Display information related to a file descriptor
24  *
25  * \param fd is a the file descriptor
26  */
27
28 void MSG_file_dump (msg_file_t fd){
29    THROW_UNIMPLEMENTED;
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);
36 }
37
38 /** \ingroup msg_file_management
39  * \brief Read a file
40  *
41  * \param size of the file to read
42  * \param fd is a the file descriptor
43  * \return the number of bytes successfully read
44  */
45 size_t MSG_file_read(size_t size, msg_file_t fd)
46 {
47   return simcall_file_read(size, fd->simdata->smx_file);
48 }
49
50 /** \ingroup msg_file_management
51  * \brief Write into a file
52  *
53  * \param size of the file to write
54  * \param fd is a the file descriptor
55  * \return the number of bytes successfully write
56  */
57 size_t MSG_file_write(size_t size, msg_file_t fd)
58 {
59   return simcall_file_write(size, fd->simdata->smx_file);
60 }
61
62 /** \ingroup msg_file_management
63  * \brief Opens the file whose name is the string pointed to by path
64  *
65  * \param mount is the mount point where find the file is located
66  * \param path is the file location on the storage
67  *
68  * \return An #msg_file_t associated to the file
69  */
70 msg_file_t MSG_file_open(const char* mount, const char* fullname)
71 {
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);
76   return file;
77 }
78
79 /** \ingroup msg_file_management
80  * \brief Close the file
81  *
82  * \param fd is the file to close
83  * \return 0 on success or 1 on error
84  */
85 int MSG_file_close(msg_file_t fd)
86 {
87   int res = simcall_file_close(fd->simdata->smx_file);
88   free(fd->fullname);
89   xbt_free(fd->simdata);
90   xbt_free(fd);
91   return res;
92 }
93
94 /** \ingroup msg_file_management
95  * \brief Unlink the file pointed by fd
96  *
97  * \param fd is the file descriptor (#msg_file_t)
98  * \return 0 on success or 1 on error
99  */
100 int MSG_file_unlink(msg_file_t fd)
101 {
102   return simcall_file_unlink(fd->simdata->smx_file);
103 }
104
105 /** \ingroup msg_file_management
106  * \brief Return the size of a file
107  *
108  * \param fd is the file descriptor (#msg_file_t)
109  * \return the size of the file (as a size_t)
110  */
111
112 size_t MSG_file_get_size(msg_file_t fd){
113   return simcall_file_get_size(fd->simdata->smx_file);
114 }
115
116 /** \ingroup msg_file_management
117  * \brief Search for file
118  *
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
123  */
124 xbt_dict_t MSG_file_ls(const char *mount, const char *path)
125 {
126   xbt_assert(path,"You must set path");
127   int size = strlen(path);
128   if(size && path[size-1] != '/')
129   {
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);
133     xbt_free(new_path);
134     return dict;
135   }
136
137   return simcall_file_ls(mount, path);
138 }
139
140 /** \ingroup msg_storage_management
141  * \brief Return the free space size of a storage element
142  * \param sd is the storage descriptor (#msg_storage_t)
143  * \return the free space size of the storage element (as a size_t)
144  */
145 size_t MSG_storage_get_free_size(msg_storage_t sd){
146   return simcall_storage_get_free_size(sd->simdata->smx_storage);
147 }