Commit ae0c8e83 authored by Julius Athenstaedt's avatar Julius Athenstaedt Committed by Ramon Nou
Browse files

fuse: create directly with open, inode cleanup in rmdir and unlink

parent cd7a5abc
Loading
Loading
Loading
Loading
+15 −12
Original line number Diff line number Diff line
@@ -333,7 +333,6 @@ write_handler(fuse_req_t req, fuse_ino_t ino, const char* buf, size_t size,
static void
create_handler(fuse_req_t req, fuse_ino_t parent, const char* name, mode_t mode,
               struct fuse_file_info* fi) {
    fuse_log(FUSE_LOG_DEBUG, "create handler \n");
    auto* ud = udata(req);
    auto* parent_inode = get_inode(parent);
    if(!parent_inode) {
@@ -341,17 +340,11 @@ create_handler(fuse_req_t req, fuse_ino_t parent, const char* name, mode_t mode,
        return;
    }
    std::string path = get_path(parent_inode, name);
    int rc = gkfs::syscall::gkfs_create(path, mode);
    int errno_bu = errno;
    if(rc == -1) {
        fuse_log(FUSE_LOG_DEBUG,
                 "create failed, here here mode %i flags %i errno %i\n", mode,
                 fi->flags, errno);
    }
    int fd = gkfs::syscall::gkfs_open(path, mode, fi->flags);
    fuse_log(FUSE_LOG_DEBUG, "create handler %s\n", path.c_str());
    int fd = gkfs::syscall::gkfs_open(path, mode, fi->flags | O_CREAT);
    if(fd < 0) {
        fuse_log(FUSE_LOG_DEBUG, "create -> open failed errno\n", errno);
        fuse_reply_err(req, rc < 0 ? errno_bu : ENOENT);
        fuse_log(FUSE_LOG_DEBUG, "create -> open failed errno %i\n", errno);
        fuse_reply_err(req, errno);
        return;
    }
    fi->fh = fd;
@@ -359,7 +352,6 @@ create_handler(fuse_req_t req, fuse_ino_t parent, const char* name, mode_t mode,
    struct stat st;
    int sc = gkfs::syscall::gkfs_stat(path, &st);
    if(sc == -1) {
        fuse_log(FUSE_LOG_DEBUG, "thats why its not allowed \n");
        fuse_reply_err(req, ENOENT);
        return;
    }
@@ -399,6 +391,11 @@ unlink_handler(fuse_req_t req, fuse_ino_t parent, const char* name) {
    }

    int rc = gkfs::syscall::gkfs_remove(path);
    auto it_src = path_map.find(path);
    if(it_src != path_map.end()) {
        path_map.erase(it_src);
        ino_map.erase(it_src->second);
    }
    if(rc == -1) {
        fuse_reply_err(req, 1);
        return;
@@ -690,11 +687,17 @@ rmdir_handler(fuse_req_t req, fuse_ino_t parent, const char* name) {
        return;
    }
    std::string path = get_path(parent_inode, name);
    fuse_log(FUSE_LOG_DEBUG, "rmdir  %s\n", path.c_str());
    int rc = gkfs::syscall::gkfs_rmdir(path);
    if(rc == -1) {
        fuse_reply_err(req, errno);
        return;
    }
    auto it_src = path_map.find(path);
    if(it_src != path_map.end()) {
        path_map.erase(it_src);
        ino_map.erase(it_src->second);
    }
    fuse_reply_err(req, 0);
}