Loading ifs/include/preload/open_file_map.hpp +3 −1 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ enum class FileType { class OpenFile { protected: FileType type_; std::string path_; std::array<bool, static_cast<int>(OpenFile_flags::flag_count)> flags_ = {false}; off64_t pos_; Loading @@ -38,7 +39,7 @@ protected: public: // multiple threads may want to update the file position if fd has been duplicated by dup() OpenFile(const std::string& path, int flags); OpenFile(const std::string& path, int flags, FileType type = FileType::regular); ~OpenFile(); Loading @@ -55,6 +56,7 @@ public: void set_flag(OpenFile_flags flag, bool value); FileType type() const; }; Loading ifs/src/preload/open_dir.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -9,12 +9,12 @@ OpenDir::DirEntry::DirEntry(const std::string& name, const FileType type): } OpenDir::OpenDir(const std::string& path): OpenFile(path, 0){ OpenDir::OpenDir(const std::string& path) : OpenFile(path, 0, FileType::directory) { pos_ = 0; is_dirent_valid = false; } void OpenDir::add(const std::string& name, const FileType& type){ entries.push_back(DirEntry(name, type)); } Loading ifs/src/preload/open_file_map.cpp +10 −8 Original line number Diff line number Diff line Loading @@ -7,7 +7,10 @@ using namespace std; OpenFile::OpenFile(const string& path, const int flags) : path_(path) { OpenFile::OpenFile(const string& path, const int flags, FileType type) : type_(type), path_(path) { // set flags to OpenFile if (flags & O_CREAT) flags_[to_underlying(OpenFile_flags::creat)] = true; Loading Loading @@ -62,6 +65,10 @@ void OpenFile::set_flag(OpenFile_flags flag, bool value) { flags_[to_underlying(flag)] = value; } FileType OpenFile::type() const { return type_; } // OpenFileMap starts here shared_ptr<OpenFile> OpenFileMap::get(int fd) { Loading @@ -76,12 +83,10 @@ shared_ptr<OpenFile> OpenFileMap::get(int fd) { shared_ptr<OpenDir> OpenFileMap::get_dir(int dirfd) { auto f = get(dirfd); if(f == nullptr){ if (f == nullptr || f->type() != FileType::directory) { return nullptr; } auto open_dir = static_pointer_cast<OpenDir>(f); // If open_file is not an OpenDir we are returning nullptr return open_dir; return static_pointer_cast<OpenDir>(f); } bool OpenFileMap::exist(const int fd) { Loading Loading @@ -186,6 +191,3 @@ int OpenFileMap::get_fd_idx() { std::lock_guard<std::mutex> inode_lock(fd_idx_mutex); return fd_idx; } Loading
ifs/include/preload/open_file_map.hpp +3 −1 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ enum class FileType { class OpenFile { protected: FileType type_; std::string path_; std::array<bool, static_cast<int>(OpenFile_flags::flag_count)> flags_ = {false}; off64_t pos_; Loading @@ -38,7 +39,7 @@ protected: public: // multiple threads may want to update the file position if fd has been duplicated by dup() OpenFile(const std::string& path, int flags); OpenFile(const std::string& path, int flags, FileType type = FileType::regular); ~OpenFile(); Loading @@ -55,6 +56,7 @@ public: void set_flag(OpenFile_flags flag, bool value); FileType type() const; }; Loading
ifs/src/preload/open_dir.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -9,12 +9,12 @@ OpenDir::DirEntry::DirEntry(const std::string& name, const FileType type): } OpenDir::OpenDir(const std::string& path): OpenFile(path, 0){ OpenDir::OpenDir(const std::string& path) : OpenFile(path, 0, FileType::directory) { pos_ = 0; is_dirent_valid = false; } void OpenDir::add(const std::string& name, const FileType& type){ entries.push_back(DirEntry(name, type)); } Loading
ifs/src/preload/open_file_map.cpp +10 −8 Original line number Diff line number Diff line Loading @@ -7,7 +7,10 @@ using namespace std; OpenFile::OpenFile(const string& path, const int flags) : path_(path) { OpenFile::OpenFile(const string& path, const int flags, FileType type) : type_(type), path_(path) { // set flags to OpenFile if (flags & O_CREAT) flags_[to_underlying(OpenFile_flags::creat)] = true; Loading Loading @@ -62,6 +65,10 @@ void OpenFile::set_flag(OpenFile_flags flag, bool value) { flags_[to_underlying(flag)] = value; } FileType OpenFile::type() const { return type_; } // OpenFileMap starts here shared_ptr<OpenFile> OpenFileMap::get(int fd) { Loading @@ -76,12 +83,10 @@ shared_ptr<OpenFile> OpenFileMap::get(int fd) { shared_ptr<OpenDir> OpenFileMap::get_dir(int dirfd) { auto f = get(dirfd); if(f == nullptr){ if (f == nullptr || f->type() != FileType::directory) { return nullptr; } auto open_dir = static_pointer_cast<OpenDir>(f); // If open_file is not an OpenDir we are returning nullptr return open_dir; return static_pointer_cast<OpenDir>(f); } bool OpenFileMap::exist(const int fd) { Loading Loading @@ -186,6 +191,3 @@ int OpenFileMap::get_fd_idx() { std::lock_guard<std::mutex> inode_lock(fd_idx_mutex); return fd_idx; }