1 /* Copyright (c) 2006-2015. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_S4U_FILE_HPP
7 #define SIMGRID_S4U_FILE_HPP
9 #include "simgrid/plugins/file_system.h"
10 #include <xbt/Extendable.hpp>
13 #include <simgrid/simix.h>
19 /** @brief A simulated file
21 * Used to simulate the time it takes to access to a file, but does not really store any information.
23 * They are located on @ref simgrid::s4u::Storage that are accessed from a given @ref simgrid::s4u::Host through
25 * For now, you cannot change the mountpoints programatically, and must declare them from your platform file.
30 File(std::string fullpath, void* userdata);
31 File(std::string fullpath, sg_host_t host, void* userdata);
34 /** Retrieves the path to the file */
35 const char* getPath() { return fullpath_.c_str(); }
37 /** Simulates a local read action. Returns the size of data actually read */
38 sg_size_t read(sg_size_t size);
40 /** Simulates a write action. Returns the size of data actually written. */
41 sg_size_t write(sg_size_t size);
43 /** Allows to store user data on that host */
44 void setUserdata(void* data) { userdata_ = data; }
45 /** Retrieves the previously stored data */
46 void* getUserdata() { return userdata_; }
49 void seek(sg_offset_t pos); /** Sets the file head to the given position. */
50 void seek(sg_offset_t pos, int origin); /** Sets the file head to the given position from a given origin. */
51 sg_size_t tell(); /** Retrieves the current file position */
53 /** Rename a file. WARNING: It is forbidden to move the file to another mount point */
54 void move(std::string fullpath);
55 int remoteCopy(sg_host_t host, const char* fullpath);
56 int remoteMove(sg_host_t host, const char* fullpath);
58 int unlink(); /** Remove a file from the contents of a disk */
62 Storage* localStorage;
63 std::string mount_point_;
68 std::string fullpath_;
69 sg_size_t current_position_ = SEEK_SET;
70 void* userdata_ = nullptr;
73 XBT_PUBLIC_CLASS FileSystemStorageExt {
75 static simgrid::xbt::Extension<Storage, FileSystemStorageExt> EXTENSION_ID;
76 explicit FileSystemStorageExt(Storage* ptr);
77 ~FileSystemStorageExt();
78 std::map<std::string, sg_size_t>* parseContent(std::string filename);
79 std::map<std::string, sg_size_t>* getContent() { return content_; }
80 sg_size_t getSize() { return size_; }
81 sg_size_t getUsedSize() { return usedSize_; }
82 void decrUsedSize(sg_size_t size) { usedSize_ -= size; }
83 void incrUsedSize(sg_size_t size) { usedSize_ += size; }
85 std::map<std::string, sg_size_t>* content_;
86 sg_size_t usedSize_ = 0;
90 XBT_PUBLIC_CLASS FileDescriptorHostExt
93 static simgrid::xbt::Extension<Host, FileDescriptorHostExt> EXTENSION_ID;
94 FileDescriptorHostExt() = default;
95 ~FileDescriptorHostExt() { delete file_descriptor_table; }
96 std::vector<int>* file_descriptor_table = nullptr; // Created lazily on need
99 } // namespace simgrid::s4u
101 #endif /* SIMGRID_S4U_HOST_HPP */