Skip to content

Commit

Permalink
Add callbacks for newer functions
Browse files Browse the repository at this point in the history
* setupmapping
* removemapping
* syncfs
* tmpfile
  • Loading branch information
trapexit committed Aug 13, 2023
1 parent 9849bcd commit 6dcf611
Show file tree
Hide file tree
Showing 14 changed files with 411 additions and 2 deletions.
10 changes: 10 additions & 0 deletions libfuse/include/fuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,16 @@ struct fuse_operations
off_t offset_out,
size_t size,
int flags);

ssize_t (*setupmapping)(uint64_t *fh_,
uint64_t foffset_,
uint64_t len_,
uint64_t flags_,
uint64_t moffset_);

int (*removemapping)();
int (*syncfs)();
int (*tmpfile)(const char *, mode_t, fuse_file_info_t *);
};

/** Extra context that may be needed by some filesystems
Expand Down
9 changes: 9 additions & 0 deletions libfuse/include/fuse_lowlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,15 @@ struct fuse_lowlevel_ops
*/
void (*copy_file_range)(fuse_req_t req,
const struct fuse_in_header *hdr);

void (*setupmapping)(fuse_req_t req,
const struct fuse_in_header *hdr);
void (*removemapping)(fuse_req_t req,
const struct fuse_in_header *hdr);
void (*syncfs)(fuse_req_t req,
const struct fuse_in_header *hdr);
void (*tmpfile)(fuse_req_t req,
const struct fuse_in_header *hdr);
};

/**
Expand Down
102 changes: 101 additions & 1 deletion libfuse/lib/fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ rehash_name(struct fuse *f)
static
int
hash_name(struct fuse *f,
node_t *node,
node_t *node,
uint64_t parentid,
const char *name)
{
Expand Down Expand Up @@ -753,6 +753,7 @@ find_node(struct fuse *f,
if(f->conf.remember)
inc_nlookup(node);

printf("hash_name = %s\n",name);
if(hash_name(f,node,parent,name) == -1)
{
free_node(f,node);
Expand Down Expand Up @@ -2877,6 +2878,101 @@ fuse_lib_copy_file_range(fuse_req_t req_,
fuse_reply_err(req_,rv);
}

static
void
fuse_lib_setupmapping(fuse_req_t req_,
const struct fuse_in_header *hdr_)
{
fuse_reply_err(req_,ENOSYS);
}

static
void
fuse_lib_removemapping(fuse_req_t req_,
const struct fuse_in_header *hdr_)
{
fuse_reply_err(req_,ENOSYS);
}

static
void
fuse_lib_syncfs(fuse_req_t req_,
const struct fuse_in_header *hdr_)
{
fuse_reply_err(req_,ENOSYS);
}

// TODO: This is just a copy of fuse_lib_create. Needs to be rewritten
// so a nameless node can be setup.
// name is always '/'
// nodeid is the base directory
static
void
fuse_lib_tmpfile(fuse_req_t req_,
const struct fuse_in_header *hdr_)
{
int err;
char *path;
struct fuse *f;
const char *name;
fuse_file_info_t ffi = {0};
struct fuse_entry_param e;
struct fuse_create_in *arg;

arg = fuse_hdr_arg(hdr_);
name = PARAM(arg);

ffi.flags = arg->flags;

if(req_->f->conn.proto_minor >= 12)
req_->ctx.umask = arg->umask;
else
name = (char*)arg + sizeof(struct fuse_open_in);

f = req_fuse_prepare(req_);

err = get_path_name(f,hdr_->nodeid,name,&path);
if(!err)
{
err = f->fs->op.tmpfile(path,arg->mode,&ffi);
if(!err)
{
err = lookup_path(f,hdr_->nodeid,name,path,&e,&ffi);
if(err)
{
f->fs->op.release(&ffi);
}
else if(!S_ISREG(e.attr.st_mode))
{
err = -EIO;
f->fs->op.release(&ffi);
forget_node(f,e.ino,1);
}
}
}

if(!err)
{
pthread_mutex_lock(&f->lock);
get_node(f,e.ino)->open_count++;
pthread_mutex_unlock(&f->lock);

if(fuse_reply_create(req_,&e,&ffi) == -ENOENT)
{
/* The open syscall was interrupted,so it
must be cancelled */
fuse_do_release(f,e.ino,&ffi);
forget_node(f,e.ino,1);
}
}
else
{
fuse_reply_err(req_,err);
}

free_path(f,hdr_->nodeid,path);
}

static
lock_t*
locks_conflict(node_t *node,
Expand Down Expand Up @@ -3531,15 +3627,19 @@ static struct fuse_lowlevel_ops fuse_path_ops =
.readlink = fuse_lib_readlink,
.release = fuse_lib_release,
.releasedir = fuse_lib_releasedir,
.removemapping = fuse_lib_removemapping,
.removexattr = fuse_lib_removexattr,
.rename = fuse_lib_rename,
.retrieve_reply = NULL,
.rmdir = fuse_lib_rmdir,
.setattr = fuse_lib_setattr,
.setlk = fuse_lib_setlk,
.setupmapping = fuse_lib_setupmapping,
.setxattr = fuse_lib_setxattr,
.statfs = fuse_lib_statfs,
.symlink = fuse_lib_symlink,
.syncfs = fuse_lib_syncfs,
.tmpfile = fuse_lib_tmpfile,
.unlink = fuse_lib_unlink,
.write = fuse_lib_write,
};
Expand Down
42 changes: 42 additions & 0 deletions libfuse/lib/fuse_lowlevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,42 @@ do_copy_file_range(fuse_req_t req_,
req_->f->op.copy_file_range(req_,hdr_);
}

static
void
do_setupmapping(fuse_req_t req_,
struct fuse_in_header *hdr_)
{
printf("setupmapping\n");
req_->f->op.setupmapping(req_,hdr_);
}

static
void
do_removemapping(fuse_req_t req_,
struct fuse_in_header *hdr_)
{
printf("removemapping\n");
req_->f->op.removemapping(req_,hdr_);
}

static
void
do_syncfs(fuse_req_t req_,
struct fuse_in_header *hdr_)
{
printf("syncfs\n");
req_->f->op.syncfs(req_,hdr_);
}

static
void
do_tmpfile(fuse_req_t req_,
struct fuse_in_header *hdr_)
{
printf("tmpfile\n");
req_->f->op.tmpfile(req_,hdr_);
}

static
int
send_notify_iov(struct fuse_ll *f,
Expand Down Expand Up @@ -1643,6 +1679,10 @@ static struct {
[FUSE_NOTIFY_REPLY] = { do_notify_reply, "NOTIFY_REPLY" },
[FUSE_BATCH_FORGET] = { do_batch_forget, "BATCH_FORGET" },
[FUSE_COPY_FILE_RANGE] = { do_copy_file_range, "COPY_FILE_RANGE" },
[FUSE_SETUPMAPPING] = { do_setupmapping, "SETUPMAPPING" },
[FUSE_REMOVEMAPPING] = { do_removemapping, "REMOVEMAPPING" },
[FUSE_SYNCFS] = { do_syncfs, "SYNCFS" },
[FUSE_TMPFILE] = { do_tmpfile, "TMPFILE" }
};

#define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0]))
Expand Down Expand Up @@ -1815,6 +1855,8 @@ fuse_ll_buf_process_read(struct fuse_session *se_,

in = (struct fuse_in_header*)msgbuf_->mem;

// printf("%d\n",in->opcode);

req = fuse_ll_alloc_req(se_->f);
if(req == NULL)
return fuse_send_enomem(se_->f,se_->ch,in->unique);
Expand Down
28 changes: 28 additions & 0 deletions src/fuse_removemapping.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
ISC License
Copyright (c) 2023, Antonio SJ Musumeci <[email protected]>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include "fuse_removemapping.hpp"

#include <errno.h>


int
FUSE::removemapping()
{
return -ENOSYS;
}
27 changes: 27 additions & 0 deletions src/fuse_removemapping.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
ISC License
Copyright (c) 2023, Antonio SJ Musumeci <[email protected]>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#pragma once

#include "fuse.h"


namespace FUSE
{
int removemapping();
}
35 changes: 35 additions & 0 deletions src/fuse_setupmapping.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
ISC License
Copyright (c) 2023, Antonio SJ Musumeci <[email protected]>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include "fuse_setupmapping.hpp"

#include <sys/types.h>
#include <errno.h>

#include <cstdint>


ssize_t
FUSE::setupmapping(uint64_t *fh_,
uint64_t foffset_,
uint64_t len_,
uint64_t flags_,
uint64_t moffset_)
{
return -ENOSYS;
}
31 changes: 31 additions & 0 deletions src/fuse_setupmapping.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
ISC License
Copyright (c) 2023, Antonio SJ Musumeci <[email protected]>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#pragma once

#include "fuse.h"


namespace FUSE
{
ssize_t setupmapping(uint64_t *fh_,
uint64_t foffset_,
uint64_t len_,
uint64_t flags_,
uint64_t moffset_);
}
28 changes: 28 additions & 0 deletions src/fuse_syncfs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
ISC License
Copyright (c) 2023, Antonio SJ Musumeci <[email protected]>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include "fuse_syncfs.hpp"

#include <errno.h>


int
FUSE::syncfs()
{
return -ENOSYS;
}
Loading

0 comments on commit 6dcf611

Please sign in to comment.