Skip to content

Commit

Permalink
enable nopath and nullpath_ok
Browse files Browse the repository at this point in the history
  • Loading branch information
trapexit committed Apr 12, 2017
1 parent 3c8afc1 commit 162b99e
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 55 deletions.
10 changes: 10 additions & 0 deletions src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ namespace mergerfs
const std::string controlfile;

public:
static
const
Config &
get(void)
{
const fuse_context *fc = fuse_get_context();

return get(fc);
}

static
const Config &
get(const fuse_context *fc)
Expand Down
2 changes: 1 addition & 1 deletion src/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ _create_core(const string &existingpath,
if(rv == -1)
return -errno;

fh = reinterpret_cast<uint64_t>(new FileInfo(rv));
fh = reinterpret_cast<uint64_t>(new FileInfo(rv,fusepath));

return 0;
}
Expand Down
34 changes: 34 additions & 0 deletions src/dirinfo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright (c) 2017, Antonio SJ Musumeci <trapexit@spawn.link>
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.
*/

#ifndef __DIRINFO_HPP__
#define __DIRINFO_HPP__

#include <string>

class DirInfo
{
public:
DirInfo(const char *fusepath_)
: fusepath(fusepath_)
{
}

public:
std::string fusepath;
};

#endif
2 changes: 1 addition & 1 deletion src/fgetattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace mergerfs
{
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);

return _fgetattr(fi->fd,*st);
return ::_fgetattr(fi->fd,*st);
}
}
}
9 changes: 7 additions & 2 deletions src/fileinfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@
#ifndef __FILEINFO_HPP__
#define __FILEINFO_HPP__

#include <string>

class FileInfo
{
public:
FileInfo(int _fd) :
fd(_fd)
FileInfo(const int fd_,
const char *fusepath_)
: fd(fd_),
fusepath(fusepath_)
{
}

public:
int fd;
std::string fusepath;
};

#endif
2 changes: 1 addition & 1 deletion src/flush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace mergerfs
{
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);

return _flush(fi->fd);
return ::_flush(fi->fd);
}
}
}
4 changes: 4 additions & 0 deletions src/fs_base_fsync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#ifndef __FS_BASE_FSYNC_HPP__
#define __FS_BASE_FSYNC_HPP__

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <unistd.h>

#include "errno.hpp"
Expand Down
6 changes: 3 additions & 3 deletions src/fs_base_ioctl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace fs
static
inline
int
ioctl(const int fd,
const int request,
void *data)
ioctl(const int fd,
const unsigned long request,
void *data)
{
return ::ioctl(fd,request,data);
}
Expand Down
7 changes: 1 addition & 6 deletions src/fsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <fuse.h>

#include <string>
Expand Down Expand Up @@ -52,8 +48,7 @@ namespace mergerfs
{
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);

return _fsync(fi->fd,
isdatasync);
return ::_fsync(fi->fd,isdatasync);
}
}
}
53 changes: 53 additions & 0 deletions src/fsyncdir.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright (c) 2017, Antonio SJ Musumeci <trapexit@spawn.link>
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.h>

#include <string>
#include <vector>

#include "errno.hpp"
#include "dirinfo.hpp"
#include "fs_base_fsync.hpp"

static
int
_fsyncdir(const DirInfo *di,
const int isdatasync)
{
int rv;

rv = -1;
errno = ENOSYS;

return ((rv == -1) ? -errno : 0);
}

namespace mergerfs
{
namespace fuse
{
int
fsyncdir(const char *fusepath,
int isdatasync,
fuse_file_info *ffi)
{
DirInfo *di = reinterpret_cast<DirInfo*>(ffi->fh);

return ::_fsyncdir(di,isdatasync);
}
}
}
33 changes: 33 additions & 0 deletions src/fsyncdir.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright (c) 2017, Antonio SJ Musumeci <trapexit@spawn.link>
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.
*/

#ifndef __FSYNCDIR_HPP__
#define __FSYNCDIR_HPP__

#include <fuse.h>

namespace mergerfs
{
namespace fuse
{
int
fsyncdir(const char *fusepath,
int isdatasync,
fuse_file_info *ffi);
}
}

#endif
3 changes: 1 addition & 2 deletions src/ftruncate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ namespace mergerfs
{
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);

return _ftruncate(fi->fd,
size);
return ::_ftruncate(fi->fd,size);
}
}
}
38 changes: 23 additions & 15 deletions src/ioctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <fcntl.h>

#include "config.hpp"
#include "dirinfo.hpp"
#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_base_close.hpp"
Expand All @@ -37,9 +38,9 @@ using namespace mergerfs;

static
int
_ioctl(const int fd,
const int cmd,
void *data)
_ioctl(const int fd,
const unsigned long cmd,
void *data)
{
int rv;

Expand All @@ -48,6 +49,17 @@ _ioctl(const int fd,
return ((rv == -1) ? -errno : rv);
}

static
int
_ioctl_file(fuse_file_info *ffi,
const unsigned long cmd,
void *data)
{
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);

return _ioctl(fi->fd,cmd,data);
}

#ifdef FUSE_IOCTL_DIR

#ifndef O_NOATIME
Expand All @@ -60,7 +72,7 @@ _ioctl_dir_base(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const uint64_t minfreespace,
const char *fusepath,
const int cmd,
const unsigned long cmd,
void *data)
{
int fd;
Expand Down Expand Up @@ -88,10 +100,11 @@ _ioctl_dir_base(Policy::Func::Search searchFunc,

static
int
_ioctl_dir(const char *fusepath,
const int cmd,
void *data)
_ioctl_dir(fuse_file_info *ffi,
const unsigned long cmd,
void *data)
{
DirInfo *di = reinterpret_cast<DirInfo*>(ffi->fh);
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
const ugid::Set ugid(fc->uid,fc->gid);
Expand All @@ -100,7 +113,7 @@ _ioctl_dir(const char *fusepath,
return _ioctl_dir_base(config.getattr,
config.srcmounts,
config.minfreespace,
fusepath,
di->fusepath.c_str(),
cmd,
data);
}
Expand All @@ -120,15 +133,10 @@ namespace mergerfs
{
#ifdef FUSE_IOCTL_DIR
if(flags & FUSE_IOCTL_DIR)
return _ioctl_dir(fusepath,
cmd,
data);
return ::_ioctl_dir(ffi,cmd,data);
#endif
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);

return _ioctl(fi->fd,
cmd,
data);
return ::_ioctl_file(ffi,cmd,data);
}
}
}
7 changes: 4 additions & 3 deletions src/mergerfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "flock.hpp"
#include "flush.hpp"
#include "fsync.hpp"
#include "fsyncdir.hpp"
#include "ftruncate.hpp"
#include "getattr.hpp"
#include "getxattr.hpp"
Expand Down Expand Up @@ -71,9 +72,9 @@ namespace local
get_fuse_operations(struct fuse_operations &ops,
const bool direct_io)
{
ops.flag_nullpath_ok = false;
ops.flag_nullpath_ok = true;
#if FLAG_NOPATH
ops.flag_nopath = false;
ops.flag_nopath = true;
#endif
#if FLAG_UTIME
ops.flag_utime_omit_ok = true;
Expand All @@ -94,7 +95,7 @@ namespace local
#endif
ops.flush = mergerfs::fuse::flush;
ops.fsync = mergerfs::fuse::fsync;
ops.fsyncdir = NULL;
ops.fsyncdir = mergerfs::fuse::fsyncdir;
ops.ftruncate = mergerfs::fuse::ftruncate;
ops.getattr = mergerfs::fuse::getattr;
ops.getdir = NULL; /* deprecated; use readdir */
Expand Down
2 changes: 1 addition & 1 deletion src/open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ _open_core(const string *basepath,
if(fd == -1)
return -errno;

fh = reinterpret_cast<uint64_t>(new FileInfo(fd));
fh = reinterpret_cast<uint64_t>(new FileInfo(fd,fusepath));

return 0;
}
Expand Down
4 changes: 3 additions & 1 deletion src/opendir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <fuse.h>

#include "dirinfo.hpp"

namespace mergerfs
{
namespace fuse
Expand All @@ -24,7 +26,7 @@ namespace mergerfs
opendir(const char *fusepath,
fuse_file_info *ffi)
{
ffi->fh = 0;
ffi->fh = reinterpret_cast<uint64_t>(new DirInfo(fusepath));

return 0;
}
Expand Down
Loading

0 comments on commit 162b99e

Please sign in to comment.