Skip to content

Commit

Permalink
Merge branch 'dirioctl'
Browse files Browse the repository at this point in the history
  • Loading branch information
trapexit committed Sep 26, 2014
2 parents cfe7609 + 075d62d commit 6c31efc
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
THE SOFTWARE.
*/

#include <fuse.h>

#include <string>
#include <vector>

Expand Down Expand Up @@ -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&
Expand Down
3 changes: 3 additions & 0 deletions src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef __CONFIG_HPP__
#define __CONFIG_HPP__

#include <fuse.h>

#include <sys/stat.h>

#include <string>
Expand Down Expand Up @@ -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);
}
Expand Down
35 changes: 35 additions & 0 deletions src/destroy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <[email protected]>
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 changes: 32 additions & 0 deletions src/destroy.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <[email protected]>
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 changes: 41 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <[email protected]>
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 changes: 32 additions & 0 deletions src/init.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <[email protected]>
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 changes: 66 additions & 0 deletions src/ioctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions src/mergerfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,28 @@
#include "chmod.hpp"
#include "chown.hpp"
#include "create.hpp"
#include "destroy.hpp"
#include "fallocate.hpp"
#include "fgetattr.hpp"
#include "flush.hpp"
#include "fsync.hpp"
#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"
Expand All @@ -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;
Expand All @@ -93,22 +97,22 @@ 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;
ops.lock = NULL;
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;
Expand Down
40 changes: 40 additions & 0 deletions src/opendir.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <[email protected]>
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;
}
}
}
Loading

0 comments on commit 6c31efc

Please sign in to comment.