mirror of https://github.com/trapexit/mergerfs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
2.5 KiB
135 lines
2.5 KiB
/*
|
|
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 "fs_attr.hpp"
|
|
|
|
#include "errno.hpp"
|
|
#include "fs_close.hpp"
|
|
#include "fs_open.hpp"
|
|
#include "fs_ioctl.hpp"
|
|
|
|
#include <string>
|
|
|
|
#include <fcntl.h>
|
|
#include <linux/fs.h>
|
|
|
|
using std::string;
|
|
|
|
static
|
|
int
|
|
_get_fs_ioc_flags(const int fd,
|
|
int &flags)
|
|
{
|
|
int rv;
|
|
|
|
rv = fs::ioctl(fd,FS_IOC_GETFLAGS,(void*)&flags);
|
|
if(rv == -EINVAL)
|
|
rv = -ENOTSUP;
|
|
|
|
return rv;
|
|
}
|
|
|
|
static
|
|
int
|
|
_get_fs_ioc_flags(const string &file,
|
|
int &flags)
|
|
{
|
|
int fd;
|
|
int rv;
|
|
const int openflags = O_RDONLY|O_NONBLOCK;
|
|
|
|
fd = fs::open(file,openflags);
|
|
if(fd < 0)
|
|
return fd;
|
|
|
|
rv = ::_get_fs_ioc_flags(fd,flags);
|
|
if(rv < 0)
|
|
{
|
|
fs::close(fd);
|
|
return rv;
|
|
}
|
|
|
|
return fs::close(fd);
|
|
}
|
|
|
|
static
|
|
int
|
|
_set_fs_ioc_flags(const int fd,
|
|
const int flags)
|
|
{
|
|
int rv;
|
|
|
|
rv = fs::ioctl(fd,FS_IOC_SETFLAGS,(void*)&flags);
|
|
if(rv == -EINVAL)
|
|
rv = -ENOTSUP;
|
|
|
|
return rv;
|
|
}
|
|
|
|
static
|
|
int
|
|
_set_fs_ioc_flags(const string &file,
|
|
const int flags)
|
|
{
|
|
int fd;
|
|
int rv;
|
|
const int openflags = O_RDONLY|O_NONBLOCK;
|
|
|
|
fd = fs::open(file,openflags);
|
|
if(fd < 0)
|
|
return fd;
|
|
|
|
rv = ::_set_fs_ioc_flags(fd,flags);
|
|
if(rv < 0)
|
|
{
|
|
fs::close(fd);
|
|
return rv;
|
|
}
|
|
|
|
return fs::close(fd);
|
|
}
|
|
|
|
int
|
|
fs::attr::copy(const int fdin,
|
|
const int fdout,
|
|
const u32 flags_)
|
|
{
|
|
int rv;
|
|
int flags;
|
|
|
|
rv = ::_get_fs_ioc_flags(fdin,flags);
|
|
if(rv < 0)
|
|
return rv;
|
|
|
|
if(flags_ & FS_ATTR_CLEAR_IMMUTABLE)
|
|
flags = (flags & ~FS_IMMUTABLE_FL);
|
|
|
|
return ::_set_fs_ioc_flags(fdout,flags);
|
|
}
|
|
|
|
int
|
|
fs::attr::copy(const string &from,
|
|
const string &to)
|
|
{
|
|
int rv;
|
|
int flags;
|
|
|
|
rv = ::_get_fs_ioc_flags(from,flags);
|
|
if(rv < 0)
|
|
return rv;
|
|
|
|
return ::_set_fs_ioc_flags(to,flags);
|
|
}
|