Browse Source

Merge branch 'dirioctl'

pull/37/merge 1.5.0
Antonio SJ Musumeci 10 years ago
parent
commit
6c31efc964
  1. 10
      src/config.cpp
  2. 3
      src/config.hpp
  3. 35
      src/destroy.cpp
  4. 32
      src/destroy.hpp
  5. 41
      src/init.cpp
  6. 32
      src/init.hpp
  7. 66
      src/ioctl.cpp
  8. 12
      src/mergerfs.cpp
  9. 40
      src/opendir.cpp
  10. 33
      src/opendir.hpp
  11. 38
      src/releasedir.cpp
  12. 33
      src/releasedir.hpp

10
src/config.cpp

@ -22,8 +22,6 @@
THE SOFTWARE. THE SOFTWARE.
*/ */
#include <fuse.h>
#include <string> #include <string>
#include <vector> #include <vector>
@ -57,10 +55,16 @@ namespace mergerfs
search = &Policy::ff; search = &Policy::ff;
} }
const Config&
get(const struct fuse_context *fc)
{
return *((Config*)fc->private_data);
}
const Config& const Config&
get(void) get(void)
{ {
return (*((Config*)fuse_get_context()->private_data));
return get(fuse_get_context());
} }
Config& Config&

3
src/config.hpp

@ -25,6 +25,8 @@
#ifndef __CONFIG_HPP__ #ifndef __CONFIG_HPP__
#define __CONFIG_HPP__ #define __CONFIG_HPP__
#include <fuse.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <string> #include <string>
@ -56,6 +58,7 @@ namespace mergerfs
const std::string controlfile; const std::string controlfile;
}; };
const Config &get(const struct fuse_context *fc);
const Config &get(void); const Config &get(void);
Config &get_writable(void); Config &get_writable(void);
} }

35
src/destroy.cpp

@ -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

@ -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

@ -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

@ -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);
}
}

66
src/ioctl.cpp

@ -25,12 +25,20 @@
#include <fuse.h> #include <fuse.h>
#include <string> #include <string>
#include <vector>
#include <errno.h> #include <errno.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <linux/fs.h> #include <linux/fs.h>
#include "config.hpp"
#include "fileinfo.hpp" #include "fileinfo.hpp"
#include "ugid.hpp"
#include "rwlock.hpp"
using std::string;
using std::vector;
using namespace mergerfs;
static static
int int
@ -72,6 +80,57 @@ _ioctl(const int fd,
return ((rv == -1) ? -errno : rv); 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 mergerfs
{ {
namespace ioctl namespace ioctl
@ -86,6 +145,13 @@ namespace mergerfs
{ {
const FileInfo *fileinfo = (FileInfo*)ffi->fh; const FileInfo *fileinfo = (FileInfo*)ffi->fh;
if(flags & FUSE_IOCTL_DIR)
return _ioctl_dir(fusepath,
cmd,
arg,
flags,
data);
return _ioctl(fileinfo->fd, return _ioctl(fileinfo->fd,
cmd, cmd,
arg, arg,

12
src/mergerfs.cpp

@ -38,6 +38,7 @@
#include "chmod.hpp" #include "chmod.hpp"
#include "chown.hpp" #include "chown.hpp"
#include "create.hpp" #include "create.hpp"
#include "destroy.hpp"
#include "fallocate.hpp" #include "fallocate.hpp"
#include "fgetattr.hpp" #include "fgetattr.hpp"
#include "flush.hpp" #include "flush.hpp"
@ -45,17 +46,20 @@
#include "ftruncate.hpp" #include "ftruncate.hpp"
#include "getattr.hpp" #include "getattr.hpp"
#include "getxattr.hpp" #include "getxattr.hpp"
#include "init.hpp"
#include "ioctl.hpp" #include "ioctl.hpp"
#include "link.hpp" #include "link.hpp"
#include "listxattr.hpp" #include "listxattr.hpp"
#include "mkdir.hpp" #include "mkdir.hpp"
#include "mknod.hpp" #include "mknod.hpp"
#include "open.hpp" #include "open.hpp"
#include "opendir.hpp"
#include "read.hpp" #include "read.hpp"
#include "read_buf.hpp" #include "read_buf.hpp"
#include "readdir.hpp" #include "readdir.hpp"
#include "readlink.hpp" #include "readlink.hpp"
#include "release.hpp" #include "release.hpp"
#include "releasedir.hpp"
#include "removexattr.hpp" #include "removexattr.hpp"
#include "rename.hpp" #include "rename.hpp"
#include "rmdir.hpp" #include "rmdir.hpp"
@ -82,7 +86,7 @@ get_fuse_operations()
ops.chmod = mergerfs::chmod::chmod; ops.chmod = mergerfs::chmod::chmod;
ops.chown = mergerfs::chown::chown; ops.chown = mergerfs::chown::chown;
ops.create = mergerfs::create::create; ops.create = mergerfs::create::create;
ops.destroy = NULL;
ops.destroy = mergerfs::destroy::destroy;
ops.fallocate = mergerfs::fallocate::fallocate; ops.fallocate = mergerfs::fallocate::fallocate;
ops.fgetattr = mergerfs::fgetattr::fgetattr; ops.fgetattr = mergerfs::fgetattr::fgetattr;
ops.flock = NULL; ops.flock = NULL;
@ -93,7 +97,7 @@ get_fuse_operations()
ops.getattr = mergerfs::getattr::getattr; ops.getattr = mergerfs::getattr::getattr;
ops.getdir = NULL; /* deprecated; use readdir */ ops.getdir = NULL; /* deprecated; use readdir */
ops.getxattr = mergerfs::getxattr::getxattr; ops.getxattr = mergerfs::getxattr::getxattr;
ops.init = NULL;
ops.init = mergerfs::init::init;
ops.ioctl = mergerfs::ioctl::ioctl; ops.ioctl = mergerfs::ioctl::ioctl;
ops.link = mergerfs::link::link; ops.link = mergerfs::link::link;
ops.listxattr = mergerfs::listxattr::listxattr; ops.listxattr = mergerfs::listxattr::listxattr;
@ -101,14 +105,14 @@ get_fuse_operations()
ops.mkdir = mergerfs::mkdir::mkdir; ops.mkdir = mergerfs::mkdir::mkdir;
ops.mknod = mergerfs::mknod::mknod; ops.mknod = mergerfs::mknod::mknod;
ops.open = mergerfs::open::open; ops.open = mergerfs::open::open;
ops.opendir = NULL;
ops.opendir = mergerfs::opendir::opendir;
ops.poll = NULL; ops.poll = NULL;
ops.read = mergerfs::read::read; ops.read = mergerfs::read::read;
ops.read_buf = mergerfs::read_buf::read_buf; ops.read_buf = mergerfs::read_buf::read_buf;
ops.readdir = mergerfs::readdir::readdir; ops.readdir = mergerfs::readdir::readdir;
ops.readlink = mergerfs::readlink::readlink; ops.readlink = mergerfs::readlink::readlink;
ops.release = mergerfs::release::release; ops.release = mergerfs::release::release;
ops.releasedir = NULL;
ops.releasedir = mergerfs::releasedir::releasedir;
ops.removexattr = mergerfs::removexattr::removexattr; ops.removexattr = mergerfs::removexattr::removexattr;
ops.rename = mergerfs::rename::rename; ops.rename = mergerfs::rename::rename;
ops.rmdir = mergerfs::rmdir::rmdir; ops.rmdir = mergerfs::rmdir::rmdir;

40
src/opendir.cpp

@ -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

@ -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

@ -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

@ -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…
Cancel
Save