Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
you can overwrite part of a file without mofiying its size
[simgrid.git] / src / surf / storage_n11.cpp
index 3b914b9..6baacc2 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2014. The SimGrid Team.
+/* Copyright (c) 2013-2015. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -332,8 +332,10 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta)
 
       action->p_storage->m_usedSize += incr; // disk usage
       action->p_file->current_position+= incr; // current_position
-      //  which becomes the new file size
-      action->p_file->size = action->p_file->current_position ;
+      //  which becomes the new file size only if it's greater than the current
+      // file size
+      if (action->p_file->current_position > action->p_file->size)
+        action->p_file->size = action->p_file->current_position ;
 
       sg_size_t *psize = xbt_new(sg_size_t,1);
       *psize = action->p_file->size;
@@ -433,7 +435,11 @@ StorageAction *StorageN11::close(surf_file_t fd)
 StorageAction *StorageN11::read(surf_file_t fd, sg_size_t size)
 {
   if(fd->current_position + size > fd->size){
-    size = fd->size - fd->current_position;
+    if (fd->current_position > fd->size){
+      size = 0;
+    } else {
+      size = fd->size - fd->current_position;
+    }
     fd->current_position = fd->size;
   }
   else
@@ -498,7 +504,7 @@ int StorageN11Action::unref()
 {
   m_refcount--;
   if (!m_refcount) {
-       if (actionHook::is_linked())
+       if (action_hook.is_linked())
          p_stateSet->erase(p_stateSet->iterator_to(*this));
     if (getVariable())
       lmm_variable_free(getModel()->getMaxminSystem(), getVariable());