Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add MSG_file_tell function and prepare MSG_file_seek
[simgrid.git] / src / surf / storage.cpp
index 5ecef32..a7e6b7c 100644 (file)
@@ -33,6 +33,7 @@ static XBT_INLINE void routing_storage_type_free(void *r)
   free(stype->model);
   free(stype->type_id);
   free(stype->content);
+  free(stype->content_type);
   xbt_dict_free(&(stype->properties));
   xbt_dict_free(&(stype->properties));
   free(stype);
@@ -332,8 +333,8 @@ void StorageModel::updateActionsState(double /*now*/, double delta)
       /* Hack to avoid rounding differences between x86 and x86_64
        * (note that the next sizes are of type sg_size_t). */
       long incr = delta * rate + MAXMIN_PRECISION;
-      action->p_storage->m_usedSize += incr; // disk usage
-      action->p_file->size += incr; // file size
+      action->p_storage->m_usedSize += (incr - action->p_file->size); // disk usage
+      action->p_file->size = incr; // file size
 
       sg_size_t *psize = xbt_new(sg_size_t,1);
       *psize = action->p_file->size;
@@ -419,9 +420,9 @@ Storage::Storage(StorageModelPtr model, const char* name, xbt_dict_t properties)
 
 StorageLmm::StorageLmm(StorageModelPtr model, const char* name, xbt_dict_t properties,
             lmm_system_t maxminSystem, double bread, double bwrite, double bconnection,
-            const char* type_id, char *content_name, char *content_type, size_t size)
+            const char* type_id, char *content_name, char *content_type, sg_size_t size)
  :  Resource(model, name, properties), ResourceLmm(), Storage(model, name, properties) {
-  XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%lu'", bconnection, bread, bwrite, ((unsigned long)size));
+  XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%llu'", bconnection, bread, bwrite, size);
 
   p_stateCurrent = SURF_RESOURCE_ON;
   m_usedSize = 0;
@@ -511,6 +512,7 @@ StorageActionPtr StorageLmm::open(const char* mount, const char* path)
   file->name = xbt_strdup(path);
   file->size = size;
   file->mount = xbt_strdup(mount);
+  file->current_position = 0;
 
   StorageActionLmmPtr action = new StorageActionLmm(p_model, 0, p_stateCurrent != SURF_RESOURCE_ON, this, OPEN);
   action->p_file = file;
@@ -541,8 +543,13 @@ StorageActionPtr StorageLmm::close(surf_file_t fd)
 
 StorageActionPtr StorageLmm::read(surf_file_t fd, sg_size_t size)
 {
-  if(size > fd->size)
+  if(size > fd->size){
     size = fd->size;
+    fd->current_position = fd->size;
+  }
+  else
+       fd->current_position += size;
+
   StorageActionLmmPtr action = new StorageActionLmm(p_model, size, p_stateCurrent != SURF_RESOURCE_ON, this, READ);
   return action;
 }
@@ -554,7 +561,7 @@ StorageActionPtr StorageLmm::write(surf_file_t fd, sg_size_t size)
 
   StorageActionLmmPtr action = new StorageActionLmm(p_model, size, p_stateCurrent != SURF_RESOURCE_ON, this, WRITE);
   action->p_file = fd;
-
+  fd->current_position += size;
   // If the storage is full
   if(m_usedSize==m_size) {
     action->setState(SURF_ACTION_FAILED);