Skip to content

Commit

Permalink
wrap most posix filesystem functions
Browse files Browse the repository at this point in the history
  • Loading branch information
trapexit committed Oct 19, 2016
1 parent 18d684c commit 1dc7bff
Show file tree
Hide file tree
Showing 69 changed files with 1,262 additions and 227 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
ISC License

Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>

Permission to use, copy, modify, and/or distribute this software for any
Expand Down
6 changes: 2 additions & 4 deletions src/access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
#include <string>
#include <vector>

#include <fcntl.h>
#include <unistd.h>

#include "config.hpp"
#include "errno.hpp"
#include "fs_base_access.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
#include "ugid.hpp"
Expand Down Expand Up @@ -49,7 +47,7 @@ _access(Policy::Func::Search searchFunc,

fs::path::make(basepaths[0],fusepath,fullpath);

rv = ::faccessat(AT_FDCWD,fullpath.c_str(),mask,AT_EACCESS);
rv = fs::access(fullpath,mask,AT_EACCESS);

return ((rv == -1) ? -errno : 0);
}
Expand Down
3 changes: 2 additions & 1 deletion src/chmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "config.hpp"
#include "errno.hpp"
#include "fs_base_chmod.hpp"
#include "fs_path.hpp"
#include "rv.hpp"
#include "rwlock.hpp"
Expand All @@ -42,7 +43,7 @@ _chmod_loop_core(const string *basepath,

fs::path::make(basepath,fusepath,fullpath);

rv = ::chmod(fullpath.c_str(),mode);
rv = fs::chmod(fullpath,mode);

return calc_error(rv,error,errno);
}
Expand Down
3 changes: 2 additions & 1 deletion src/chown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "config.hpp"
#include "errno.hpp"
#include "fs_base_chown.hpp"
#include "fs_path.hpp"
#include "rv.hpp"
#include "rwlock.hpp"
Expand All @@ -44,7 +45,7 @@ _chown_loop_core(const string *basepath,

fs::path::make(basepath,fusepath,fullpath);

rv = ::lchown(fullpath.c_str(),uid,gid);
rv = fs::lchown(fullpath,uid,gid);

return calc_error(rv,error,errno);
}
Expand Down
7 changes: 2 additions & 5 deletions src/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@

#include <fuse.h>

#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

#include <string>
#include <vector>

#include "config.hpp"
#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_base_open.hpp"
#include "fs_clonepath.hpp"
#include "fs_path.hpp"
#include "rwlock.hpp"
Expand Down Expand Up @@ -57,7 +54,7 @@ _create_core(const string &existingpath,

fs::path::make(&createpath,fusepath,fullpath);

fd = ::open(fullpath.c_str(),flags,mode);
fd = fs::open(fullpath,flags,mode);
if(fd == -1)
return -errno;

Expand Down
1 change: 0 additions & 1 deletion src/fallocate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ namespace mergerfs
{
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);


return _fallocate(fi->fd,
mode,
offset,
Expand Down
7 changes: 2 additions & 5 deletions src/fgetattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

#include <fuse.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_base_stat.hpp"

static
int
Expand All @@ -30,7 +27,7 @@ _fgetattr(const int fd,
{
int rv;

rv = ::fstat(fd,&st);
rv = fs::fstat(fd,st);

return ((rv == -1) ? -errno : 0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/fgetattr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

namespace mergerfs
Expand Down
8 changes: 4 additions & 4 deletions src/flush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@

#include <fuse.h>

#include <unistd.h>

#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_base_close.hpp"
#include "fs_base_dup.hpp"

static
int
_flush(const int fd)
{
int rv;

rv = ::dup(fd);
rv = fs::dup(fd);
if(rv == -1)
errno = EIO;
else
rv = ::close(rv);
rv = fs::close(rv);

return ((rv == -1) ? -errno : 0);
}
Expand Down
44 changes: 15 additions & 29 deletions src/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@
#include <string>
#include <vector>

#include <fcntl.h>
#include <fcntl.h>
#include <glob.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/types.h>
#include <unistd.h>

#include "errno.hpp"
#include "fs_attr.hpp"
#include "fs_base_stat.hpp"
#include "fs_base_statvfs.hpp"
#include "fs_path.hpp"
#include "fs_xattr.hpp"
#include "statvfs_util.hpp"
Expand All @@ -47,7 +44,7 @@ namespace fs
{
int rv;

rv = ::lstat(path.c_str(),&st);
rv = fs::lstat(path,st);

return LSTAT_SUCCEEDED(rv);
}
Expand All @@ -60,74 +57,63 @@ namespace fs
return exists(path,st);
}

bool
statvfs(const string &path,
struct statvfs &st)
{
int rv;

rv = ::statvfs(path.c_str(),&st);

return STATVFS_SUCCEEDED(rv);
}

bool
info(const string &path,
bool &readonly,
uint64_t &spaceavail,
uint64_t &spaceused)
{
bool rv;
int rv;
struct statvfs st;

rv = fs::statvfs(path,st);
if(rv)
if(STATVFS_SUCCEEDED(rv))
{
readonly = StatVFS::readonly(st);
spaceavail = StatVFS::spaceavail(st);
spaceused = StatVFS::spaceused(st);
}

return rv;
return STATVFS_SUCCEEDED(rv);
}

bool
readonly(const string &path)
{
bool rv;
int rv;
struct statvfs st;

rv = fs::statvfs(path,st);

return (rv && StatVFS::readonly(st));
return (STATVFS_SUCCEEDED(rv) && StatVFS::readonly(st));
}

bool
spaceavail(const string &path,
uint64_t &spaceavail)
{
bool rv;
int rv;
struct statvfs st;

rv = fs::statvfs(path,st);
if(rv)
if(STATVFS_SUCCEEDED(rv))
spaceavail = StatVFS::spaceavail(st);

return rv;
return STATVFS_SUCCEEDED(rv);
}

bool
spaceused(const string &path,
uint64_t &spaceused)
{
bool rv;
int rv;
struct statvfs st;

rv = fs::statvfs(path,st);
if(rv)
if(STATVFS_SUCCEEDED(rv))
spaceused = StatVFS::spaceused(st);

return rv;
return STATVFS_SUCCEEDED(rv);
}

void
Expand Down Expand Up @@ -159,7 +145,7 @@ namespace fs
string fullpath;
struct stat st;

rv = ::fstat(fd,&st);
rv = fs::fstat(fd,st);
if(FSTAT_FAILED(rv))
return -1;

Expand Down
3 changes: 0 additions & 3 deletions src/fs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ namespace fs
struct stat &st);
bool exists(const string &path);

bool statvfs(const string &path,
struct statvfs &st);

bool info(const string &path,
bool &readonly,
uint64_t &spaceavail,
Expand Down
23 changes: 11 additions & 12 deletions src/fs_attr_linux.icpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

#include <fcntl.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <string>

#include "errno.hpp"
#include "fs_base_close.hpp"
#include "fs_base_open.hpp"
#include "fs_base_ioctl.hpp"

using std::string;

Expand All @@ -36,7 +35,7 @@ namespace fs
get_fs_ioc_flags(const int fd,
int &flags)
{
return ::ioctl(fd,FS_IOC_GETFLAGS,&flags);
return fs::ioctl(fd,FS_IOC_GETFLAGS,(void*)&flags);
}

static
Expand All @@ -48,28 +47,28 @@ namespace fs
int rv;
const int openflags = O_RDONLY|O_NONBLOCK;

fd = ::open(file.c_str(),openflags);
fd = fs::open(file,openflags);
if(fd == -1)
return -1;

rv = get_fs_ioc_flags(fd,flags);
if(rv == -1)
{
int error = errno;
::close(fd);
fs::close(fd);
errno = error;
return -1;
}

return ::close(fd);
return fs::close(fd);
}

static
int
set_fs_ioc_flags(const int fd,
const int flags)
{
return ::ioctl(fd,FS_IOC_SETFLAGS,&flags);
return fs::ioctl(fd,FS_IOC_SETFLAGS,(void*)&flags);
}

static
Expand All @@ -81,20 +80,20 @@ namespace fs
int rv;
const int openflags = O_RDONLY|O_NONBLOCK;

fd = ::open(file.c_str(),openflags);
fd = fs::open(file,openflags);
if(fd == -1)
return -1;

rv = set_fs_ioc_flags(fd,flags);
if(rv == -1)
{
int error = errno;
::close(fd);
fs::close(fd);
errno = error;
return -1;
}

return ::close(fd);
return fs::close(fd);
}

int
Expand Down
Loading

0 comments on commit 1dc7bff

Please sign in to comment.