- XBT_DEBUG("WRITE %s on disk '%s'", fd->cname(), st->cname());
- return st->write(fd, size);
+ XBT_DEBUG("WRITE %s on disk '%s'. size '%llu/%llu'", fd->cname(), st->cname(), size, fd->size());
+
+ StorageAction* action = st->write(size);
+ action->file_ = fd;
+ /* Substract the part of the file that might disappear from the used sized on the storage element */
+ st->usedSize_ -= (fd->size() - fd->tell());
+ // If the storage is full before even starting to write
+ if (st->usedSize_ >= st->size_) {
+ action->setState(Action::State::failed);
+ }
+ return action;