Browse Source

Merge pull request #330 from trapexit/cleanup

further abstraction of system calls
pull/333/head
Antonio SJ Musumeci 8 years ago
committed by GitHub
parent
commit
c7c5b07389
  1. 2
      src/access.cpp
  2. 5
      src/fs.cpp
  3. 17
      src/fs_base_access.hpp
  4. 33
      src/fs_base_lseek.hpp
  5. 10
      src/fs_base_read.hpp
  6. 42
      src/fs_base_realpath.hpp
  7. 10
      src/fs_base_write.hpp
  8. 17
      src/fs_clonefile.cpp

2
src/access.cpp

@ -47,7 +47,7 @@ _access(Policy::Func::Search searchFunc,
fs::path::make(basepaths[0],fusepath,fullpath); fs::path::make(basepaths[0],fusepath,fullpath);
rv = fs::access(fullpath,mask,AT_EACCESS);
rv = fs::eaccess(fullpath,mask);
return ((rv == -1) ? -errno : 0); return ((rv == -1) ? -errno : 0);
} }

5
src/fs.cpp

@ -25,6 +25,7 @@
#include "errno.hpp" #include "errno.hpp"
#include "fs_attr.hpp" #include "fs_attr.hpp"
#include "fs_base_realpath.hpp"
#include "fs_base_stat.hpp" #include "fs_base_stat.hpp"
#include "fs_base_statvfs.hpp" #include "fs_base_statvfs.hpp"
#include "fs_path.hpp" #include "fs_path.hpp"
@ -154,7 +155,7 @@ namespace fs
{ {
fs::path::make(&srcmounts[i],fusepath,fullpath); fs::path::make(&srcmounts[i],fusepath,fullpath);
rv = ::lstat(fullpath.c_str(),&st);
rv = fs::lstat(fullpath,st);
if(FSTAT_FAILED(rv)) if(FSTAT_FAILED(rv))
continue; continue;
@ -201,7 +202,7 @@ namespace fs
for(size_t i = 0; i < strs.size(); i++) for(size_t i = 0; i < strs.size(); i++)
{ {
rv = ::realpath(strs[i].c_str(),NULL);
rv = fs::realpath(strs[i]);
if(rv == NULL) if(rv == NULL)
continue; continue;

17
src/fs_base_access.hpp

@ -27,20 +27,29 @@ namespace fs
inline inline
int int
access(const int dirfd, access(const int dirfd,
const std::string &pathname,
const std::string &path,
const int mode, const int mode,
const int flags) const int flags)
{ {
return ::faccessat(dirfd,pathname.c_str(),mode,flags);
return ::faccessat(dirfd,path.c_str(),mode,flags);
} }
static static
inline inline
int int
access(const std::string &pathname,
access(const std::string &path,
const int mode, const int mode,
const int flags) const int flags)
{ {
return fs::access(AT_FDCWD,pathname,mode,flags);
return fs::access(AT_FDCWD,path,mode,flags);
}
static
inline
int
eaccess(const std::string &path,
const int mode)
{
return fs::access(path,mode,AT_EACCESS);
} }
} }

33
src/fs_base_lseek.hpp

@ -0,0 +1,33 @@
/*
ISC License
Copyright (c) 2016, 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 <sys/types.h>
#include <unistd.h>
namespace fs
{
static
inline
off_t
lseek(const int fd,
const off_t offset,
const int whence)
{
return ::lseek(fd,offset,whence);
}
}

10
src/fs_base_read.hpp

@ -20,6 +20,16 @@
namespace fs namespace fs
{ {
static
inline
ssize_t
read(const int fd,
void *buf,
const size_t count)
{
return ::read(fd,buf,count);
}
static static
inline inline
ssize_t ssize_t

42
src/fs_base_realpath.hpp

@ -0,0 +1,42 @@
/*
ISC License
Copyright (c) 2016, 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 <string>
#include <limits.h>
#include <stdlib.h>
namespace fs
{
static
inline
char *
realpath(const std::string &path,
char *resolved_path)
{
return ::realpath(path.c_str(),resolved_path);
}
static
inline
char *
realpath(const std::string &path)
{
return fs::realpath(path,NULL);
}
}

10
src/fs_base_write.hpp

@ -20,6 +20,16 @@
namespace fs namespace fs
{ {
static
inline
ssize_t
write(const int fd,
const void *buf,
const size_t count)
{
return ::write(fd,buf,count);
}
static static
inline inline
ssize_t ssize_t

17
src/fs_clonefile.cpp

@ -16,20 +16,21 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include "errno.hpp" #include "errno.hpp"
#include "fs_attr.hpp" #include "fs_attr.hpp"
#include "fs_base_chown.hpp"
#include "fs_base_chmod.hpp" #include "fs_base_chmod.hpp"
#include "fs_base_chown.hpp"
#include "fs_base_close.hpp" #include "fs_base_close.hpp"
#include "fs_base_lseek.hpp"
#include "fs_base_mkdir.hpp" #include "fs_base_mkdir.hpp"
#include "fs_base_open.hpp" #include "fs_base_open.hpp"
#include "fs_base_read.hpp"
#include "fs_base_stat.hpp"
#include "fs_base_write.hpp"
#include "fs_fadvise.hpp" #include "fs_fadvise.hpp"
#include "fs_fallocate.hpp" #include "fs_fallocate.hpp"
#include "fs_sendfile.hpp" #include "fs_sendfile.hpp"
@ -52,7 +53,7 @@ namespace fs
nleft = count; nleft = count;
while(nleft > 0) while(nleft > 0)
{ {
nwritten = ::write(fd,buf,nleft);
nwritten = fs::write(fd,buf,nleft);
if(nwritten == -1) if(nwritten == -1)
{ {
if(errno == EINTR) if(errno == EINTR)
@ -83,12 +84,12 @@ namespace fs
bufsize = (blocksize * 16); bufsize = (blocksize * 16);
buf.resize(bufsize); buf.resize(bufsize);
::lseek(fdin,0,SEEK_SET);
fs::lseek(fdin,0,SEEK_SET);
totalwritten = 0; totalwritten = 0;
while(totalwritten < count) while(totalwritten < count)
{ {
nr = ::read(fdin,&buf[0],bufsize);
nr = fs::read(fdin,&buf[0],bufsize);
if(nr == -1) if(nr == -1)
{ {
if(errno == EINTR) if(errno == EINTR)
@ -151,7 +152,7 @@ namespace fs
int rv; int rv;
struct stat stin; struct stat stin;
rv = ::fstat(fdin,&stin);
rv = fs::fstat(fdin,stin);
if(rv == -1) if(rv == -1)
return -1; return -1;

Loading…
Cancel
Save