mirror of
https://github.com/trapexit/mergerfs.git
synced 2025-03-15 02:35:12 +08:00
add support for ioctl on directories. closes #27
This commit is contained in:
parent
cfe7609bcd
commit
075d62d647
@ -22,8 +22,6 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -57,10 +55,16 @@ namespace mergerfs
|
||||
search = &Policy::ff;
|
||||
}
|
||||
|
||||
const Config&
|
||||
get(const struct fuse_context *fc)
|
||||
{
|
||||
return *((Config*)fc->private_data);
|
||||
}
|
||||
|
||||
const Config&
|
||||
get(void)
|
||||
{
|
||||
return (*((Config*)fuse_get_context()->private_data));
|
||||
return get(fuse_get_context());
|
||||
}
|
||||
|
||||
Config&
|
||||
|
@ -25,6 +25,8 @@
|
||||
#ifndef __CONFIG_HPP__
|
||||
#define __CONFIG_HPP__
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <string>
|
||||
@ -56,6 +58,7 @@ namespace mergerfs
|
||||
const std::string controlfile;
|
||||
};
|
||||
|
||||
const Config &get(const struct fuse_context *fc);
|
||||
const Config &get(void);
|
||||
Config &get_writable(void);
|
||||
}
|
||||
|
35
src/destroy.cpp
Normal file
35
src/destroy.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace destroy
|
||||
{
|
||||
void
|
||||
destroy(void *)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
32
src/destroy.hpp
Normal file
32
src/destroy.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace destroy
|
||||
{
|
||||
void
|
||||
destroy(void *);
|
||||
}
|
||||
}
|
41
src/init.cpp
Normal file
41
src/init.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace init
|
||||
{
|
||||
void *
|
||||
init(struct fuse_conn_info *conn)
|
||||
{
|
||||
conn->want |= FUSE_CAP_IOCTL_DIR;
|
||||
|
||||
return &config::get_writable();
|
||||
}
|
||||
}
|
||||
}
|
32
src/init.hpp
Normal file
32
src/init.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace init
|
||||
{
|
||||
void *
|
||||
init(struct fuse_conn_info *conn);
|
||||
}
|
||||
}
|
@ -25,12 +25,20 @@
|
||||
#include <fuse.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "rwlock.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using namespace mergerfs;
|
||||
|
||||
static
|
||||
int
|
||||
@ -72,6 +80,57 @@ _ioctl(const int fd,
|
||||
return ((rv == -1) ? -errno : rv);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_ioctl_dir_base(const fs::SearchFunc searchFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const string fusepath,
|
||||
const int cmd,
|
||||
void *arg,
|
||||
const unsigned int flags,
|
||||
void *data)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
fs::PathVector paths;
|
||||
|
||||
rv = searchFunc(srcmounts,fusepath,paths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
fd = ::open(paths[0].full.c_str(),flags);
|
||||
if(fd == -1)
|
||||
return -errno;
|
||||
|
||||
rv = _ioctl(fd,cmd,arg,flags,data);
|
||||
|
||||
close(fd);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_ioctl_dir(const string fusepath,
|
||||
const int cmd,
|
||||
void *arg,
|
||||
const unsigned int flags,
|
||||
void *data)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _ioctl_dir_base(*config.search,
|
||||
config.srcmounts,
|
||||
fusepath,
|
||||
cmd,
|
||||
arg,
|
||||
flags,
|
||||
data);
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace ioctl
|
||||
@ -86,6 +145,13 @@ namespace mergerfs
|
||||
{
|
||||
const FileInfo *fileinfo = (FileInfo*)ffi->fh;
|
||||
|
||||
if(flags & FUSE_IOCTL_DIR)
|
||||
return _ioctl_dir(fusepath,
|
||||
cmd,
|
||||
arg,
|
||||
flags,
|
||||
data);
|
||||
|
||||
return _ioctl(fileinfo->fd,
|
||||
cmd,
|
||||
arg,
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "chmod.hpp"
|
||||
#include "chown.hpp"
|
||||
#include "create.hpp"
|
||||
#include "destroy.hpp"
|
||||
#include "fallocate.hpp"
|
||||
#include "fgetattr.hpp"
|
||||
#include "flush.hpp"
|
||||
@ -45,17 +46,20 @@
|
||||
#include "ftruncate.hpp"
|
||||
#include "getattr.hpp"
|
||||
#include "getxattr.hpp"
|
||||
#include "init.hpp"
|
||||
#include "ioctl.hpp"
|
||||
#include "link.hpp"
|
||||
#include "listxattr.hpp"
|
||||
#include "mkdir.hpp"
|
||||
#include "mknod.hpp"
|
||||
#include "open.hpp"
|
||||
#include "opendir.hpp"
|
||||
#include "read.hpp"
|
||||
#include "read_buf.hpp"
|
||||
#include "readdir.hpp"
|
||||
#include "readlink.hpp"
|
||||
#include "release.hpp"
|
||||
#include "releasedir.hpp"
|
||||
#include "removexattr.hpp"
|
||||
#include "rename.hpp"
|
||||
#include "rmdir.hpp"
|
||||
@ -82,7 +86,7 @@ get_fuse_operations()
|
||||
ops.chmod = mergerfs::chmod::chmod;
|
||||
ops.chown = mergerfs::chown::chown;
|
||||
ops.create = mergerfs::create::create;
|
||||
ops.destroy = NULL;
|
||||
ops.destroy = mergerfs::destroy::destroy;
|
||||
ops.fallocate = mergerfs::fallocate::fallocate;
|
||||
ops.fgetattr = mergerfs::fgetattr::fgetattr;
|
||||
ops.flock = NULL;
|
||||
@ -93,7 +97,7 @@ get_fuse_operations()
|
||||
ops.getattr = mergerfs::getattr::getattr;
|
||||
ops.getdir = NULL; /* deprecated; use readdir */
|
||||
ops.getxattr = mergerfs::getxattr::getxattr;
|
||||
ops.init = NULL;
|
||||
ops.init = mergerfs::init::init;
|
||||
ops.ioctl = mergerfs::ioctl::ioctl;
|
||||
ops.link = mergerfs::link::link;
|
||||
ops.listxattr = mergerfs::listxattr::listxattr;
|
||||
@ -101,14 +105,14 @@ get_fuse_operations()
|
||||
ops.mkdir = mergerfs::mkdir::mkdir;
|
||||
ops.mknod = mergerfs::mknod::mknod;
|
||||
ops.open = mergerfs::open::open;
|
||||
ops.opendir = NULL;
|
||||
ops.opendir = mergerfs::opendir::opendir;
|
||||
ops.poll = NULL;
|
||||
ops.read = mergerfs::read::read;
|
||||
ops.read_buf = mergerfs::read_buf::read_buf;
|
||||
ops.readdir = mergerfs::readdir::readdir;
|
||||
ops.readlink = mergerfs::readlink::readlink;
|
||||
ops.release = mergerfs::release::release;
|
||||
ops.releasedir = NULL;
|
||||
ops.releasedir = mergerfs::releasedir::releasedir;
|
||||
ops.removexattr = mergerfs::removexattr::removexattr;
|
||||
ops.rename = mergerfs::rename::rename;
|
||||
ops.rmdir = mergerfs::rmdir::rmdir;
|
||||
|
40
src/opendir.cpp
Normal file
40
src/opendir.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace opendir
|
||||
{
|
||||
int
|
||||
opendir(const char *fusepath,
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
ffi->fh = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
33
src/opendir.hpp
Normal file
33
src/opendir.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace opendir
|
||||
{
|
||||
int opendir(const char *fusepath, struct fuse_file_info *ffi);
|
||||
}
|
||||
}
|
38
src/releasedir.cpp
Normal file
38
src/releasedir.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace releasedir
|
||||
{
|
||||
int
|
||||
releasedir(const char *fusepath,
|
||||
struct fuse_file_info *ffi)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
33
src/releasedir.hpp
Normal file
33
src/releasedir.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fuse.h>
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace releasedir
|
||||
{
|
||||
int releasedir(const char *fusepath, struct fuse_file_info *ffi);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user