Commit 78519216 authored by sevenuz's avatar sevenuz Committed by Julius Athenstaedt
Browse files

mkdir causes segvault

parent b1419535
Loading
Loading
Loading
Loading
+37 −2
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ alloc_inode(const std::string& path) {
    std::lock_guard<std::mutex> lk(ino_mutex);
    fuse_ino_t ino = next_ino++;
    ino_map[ino] = {path, {}, 1};
    path_map[path] = ino;
    return ino;
}

@@ -146,7 +147,6 @@ lookup_handler(fuse_req_t req, fuse_ino_t parent, const char* name) {
        ino_map[ino].lookup_count++;
    } else {
        ino = alloc_inode(child);
        path_map[child] = ino;
    }

    struct stat st;
@@ -498,6 +498,41 @@ flush_handler(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info* fi) {
    fuse_reply_err(req, 0);
}

static void
mkdir_handler(fuse_req_t req, fuse_ino_t parent, const char* name,
              mode_t mode) {
    auto* ud = udata(req);
    auto* parent_inode = get_inode(parent);
    if(!parent_inode) {
        fuse_reply_err(req, ENOENT);
        return;
    }
    std::string path = parent_inode->path + name;
    int rc = gkfs::syscall::gkfs_create(path, mode | S_IFDIR);
    if(rc == -1) {
        fuse_reply_err(req, 1);
        return;
    }
    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, 1);
        return;
    }
    fuse_ino_t ino = alloc_inode(path);
    fuse_log(FUSE_LOG_DEBUG, "create new inode ino %i\n", ino);
    ino_map[ino].st = st;
    fuse_entry_param e = {};
    e.ino = ino;
    e.attr = st;
    e.attr_timeout = ud->timeout;
    e.entry_timeout = ud->timeout;
    fuse_reply_entry(req, &e);
    fuse_log(FUSE_LOG_DEBUG, "flush success \n");
    fuse_reply_err(req, 0);
}

static void
init_gekkofs() {
    // TODO how to handle mount point
@@ -553,7 +588,7 @@ init_ll_ops(fuse_lowlevel_ops* ops) {

    // directory
    ops->lookup = lookup_handler;
    // ops->mkdir
    ops->mkdir = mkdir_handler;
    // ops->rmdir
    ops->readdir = readdir_handler;
    ops->opendir = opendir_handler;
+3 −0
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ def test_read(gkfs_daemon, fuse_client):
    file = gkfs_daemon.mountdir / "file"
    file2 = gkfs_daemon.mountdir / "file2"

    dir = gkfs_daemon.mountdir / "dir"

    sh.bash("-c", "echo baum > " + str(file))
    assert sh.ls(fuse_client.mountdir) == "file\n"
    assert sh.cat(file) == "baum\n"
@@ -52,3 +54,4 @@ def test_read(gkfs_daemon, fuse_client):
    assert sh.wc("-c", str(file2)) == "0 " + str(file2) + "\n"
    sh.truncate("-s", "20", str(file2))
    assert sh.wc("-c", str(file2)) == "20 " + str(file2) + "\n"
    sh.mkdir(str(dir))