1 /* Copyright (c) 2017. 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 "src/surf/FileImpl.hpp"
8 #include "src/surf/HostImpl.hpp"
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_file, surf, "Logging specific to the SURF file module");
14 int FileImpl::seek(sg_offset_t offset, int origin)
18 current_position_ = offset;
21 current_position_ += offset;
24 current_position_ = size_ + offset;
31 int FileImpl::unlink(sg_host_t host)
33 simgrid::surf::StorageImpl* st = host->pimpl_->findStorageOnMountList(mount_point_.c_str());
34 /* Check if the file is on this storage */
35 if (st->content_->find(path_) == st->content_->end()) {
36 XBT_WARN("File %s is not on disk %s. Impossible to unlink", cname(), st->cname());
39 XBT_DEBUG("UNLINK %s on disk '%s'", cname(), st->cname());
40 st->usedSize_ -= size_;
42 // Remove the file from storage
43 st->content_->erase(path_);
49 void FileImpl::move(sg_host_t host, const char* fullpath)
51 /* Check if the new full path is on the same mount point */
52 if (not strncmp(mount_point_.c_str(), fullpath, mount_point_.size())) {
53 std::map<std::string, sg_size_t>* content = host->pimpl_->findStorageOnMountList(mount_point_.c_str())->content_;
54 if (content->find(path_) != content->end()) { // src file exists
55 sg_size_t new_size = content->at(path_);
56 content->erase(path_);
57 std::string path = std::string(fullpath).substr(mount_point_.size(), strlen(fullpath));
58 content->insert({path.c_str(), new_size});
59 XBT_DEBUG("Move file from %s to %s, size '%llu'", path_.c_str(), fullpath, new_size);
61 XBT_WARN("File %s doesn't exist", path_.c_str());
64 XBT_WARN("New full path %s is not on the same mount point: %s.", fullpath, mount_point_.c_str());