mirror of
https://github.com/trapexit/mergerfs.git
synced 2025-01-21 00:58:47 +08:00
further abstraction of system calls
This commit is contained in:
parent
1ad05d7783
commit
d0b6cd1f38
|
@ -47,7 +47,7 @@ _access(Policy::Func::Search searchFunc,
|
|||
|
||||
fs::path::make(basepaths[0],fusepath,fullpath);
|
||||
|
||||
rv = fs::access(fullpath,mask,AT_EACCESS);
|
||||
rv = fs::eaccess(fullpath,mask);
|
||||
|
||||
return ((rv == -1) ? -errno : 0);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "errno.hpp"
|
||||
#include "fs_attr.hpp"
|
||||
#include "fs_base_realpath.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_base_statvfs.hpp"
|
||||
#include "fs_path.hpp"
|
||||
|
@ -154,7 +155,7 @@ namespace fs
|
|||
{
|
||||
fs::path::make(&srcmounts[i],fusepath,fullpath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
rv = fs::lstat(fullpath,st);
|
||||
if(FSTAT_FAILED(rv))
|
||||
continue;
|
||||
|
||||
|
@ -201,7 +202,7 @@ namespace fs
|
|||
|
||||
for(size_t i = 0; i < strs.size(); i++)
|
||||
{
|
||||
rv = ::realpath(strs[i].c_str(),NULL);
|
||||
rv = fs::realpath(strs[i]);
|
||||
if(rv == NULL)
|
||||
continue;
|
||||
|
||||
|
|
|
@ -27,20 +27,29 @@ namespace fs
|
|||
inline
|
||||
int
|
||||
access(const int dirfd,
|
||||
const std::string &pathname,
|
||||
const std::string &path,
|
||||
const int mode,
|
||||
const int flags)
|
||||
{
|
||||
return ::faccessat(dirfd,pathname.c_str(),mode,flags);
|
||||
return ::faccessat(dirfd,path.c_str(),mode,flags);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
access(const std::string &pathname,
|
||||
access(const std::string &path,
|
||||
const int mode,
|
||||
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
Normal file
33
src/fs_base_lseek.hpp
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -20,6 +20,16 @@
|
|||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
ssize_t
|
||||
read(const int fd,
|
||||
void *buf,
|
||||
const size_t count)
|
||||
{
|
||||
return ::read(fd,buf,count);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
ssize_t
|
||||
|
|
42
src/fs_base_realpath.hpp
Normal file
42
src/fs_base_realpath.hpp
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -20,6 +20,16 @@
|
|||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
ssize_t
|
||||
write(const int fd,
|
||||
const void *buf,
|
||||
const size_t count)
|
||||
{
|
||||
return ::write(fd,buf,count);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
ssize_t
|
||||
|
|
|
@ -16,20 +16,21 @@
|
|||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_attr.hpp"
|
||||
#include "fs_base_chown.hpp"
|
||||
#include "fs_base_chmod.hpp"
|
||||
#include "fs_base_chown.hpp"
|
||||
#include "fs_base_close.hpp"
|
||||
#include "fs_base_lseek.hpp"
|
||||
#include "fs_base_mkdir.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_fallocate.hpp"
|
||||
#include "fs_sendfile.hpp"
|
||||
|
@ -52,7 +53,7 @@ namespace fs
|
|||
nleft = count;
|
||||
while(nleft > 0)
|
||||
{
|
||||
nwritten = ::write(fd,buf,nleft);
|
||||
nwritten = fs::write(fd,buf,nleft);
|
||||
if(nwritten == -1)
|
||||
{
|
||||
if(errno == EINTR)
|
||||
|
@ -83,12 +84,12 @@ namespace fs
|
|||
bufsize = (blocksize * 16);
|
||||
buf.resize(bufsize);
|
||||
|
||||
::lseek(fdin,0,SEEK_SET);
|
||||
fs::lseek(fdin,0,SEEK_SET);
|
||||
|
||||
totalwritten = 0;
|
||||
while(totalwritten < count)
|
||||
{
|
||||
nr = ::read(fdin,&buf[0],bufsize);
|
||||
nr = fs::read(fdin,&buf[0],bufsize);
|
||||
if(nr == -1)
|
||||
{
|
||||
if(errno == EINTR)
|
||||
|
@ -151,7 +152,7 @@ namespace fs
|
|||
int rv;
|
||||
struct stat stin;
|
||||
|
||||
rv = ::fstat(fdin,&stin);
|
||||
rv = fs::fstat(fdin,stin);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user