Verified Commit 4314bebe authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

preload: Generalize OpenFileMap::add

Allow to add already instantiated OpenFile to the OpenFileMap.

This will come in hands when we will have sub-classes of the OpenFile.
In that case this new add function will accept all object that are
derived from the OpenFile class. See directories functionalities.
parent 4645fd16
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ public:

    bool exist(int fd);

    int add(std::string path, int flags);
    int add(std::shared_ptr<OpenFile>);
    
    bool remove(int fd);

+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ int adafs_open(const std::string& path, mode_t mode, int flags) {
    }

    // TODO the open flags should not be in the map just set the pos accordingly
    return CTX->file_map()->add(path, flags);
    return CTX->file_map()->add(std::make_shared<OpenFile>(path, flags));
}

int adafs_mk_node(const std::string& path, const mode_t mode) {
+1 −2
Original line number Diff line number Diff line
@@ -95,9 +95,8 @@ int OpenFileMap::safe_generate_fd_idx_() {
    return fd;
}

int OpenFileMap::add(string path, const int flags) {
int OpenFileMap::add(std::shared_ptr<OpenFile> open_file) {
    auto fd = safe_generate_fd_idx_();
    auto open_file = make_shared<OpenFile>(path, flags);
    lock_guard<recursive_mutex> lock(files_mutex_);
    files_.insert(make_pair(fd, open_file));
    return fd;