2019-01-25 07:03:46 -05:00
|
|
|
/*
|
|
|
|
|
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 "config.hpp"
|
|
|
|
|
#include "errno.hpp"
|
|
|
|
|
#include "fs_clonepath.hpp"
|
2020-08-17 16:29:22 -04:00
|
|
|
#include "fs_link.hpp"
|
2020-06-21 14:45:14 -04:00
|
|
|
#include "fs_lstat.hpp"
|
2019-01-25 07:03:46 -05:00
|
|
|
#include "fs_path.hpp"
|
2020-06-21 14:45:14 -04:00
|
|
|
#include "fuse_getattr.hpp"
|
|
|
|
|
#include "fuse_symlink.hpp"
|
2021-03-28 12:34:30 -04:00
|
|
|
#include "state.hpp"
|
2019-01-25 07:03:46 -05:00
|
|
|
#include "ugid.hpp"
|
|
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
#include "fuse.h"
|
2019-01-25 07:03:46 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace l
|
|
|
|
|
{
|
2020-06-21 14:45:14 -04:00
|
|
|
static
|
|
|
|
|
int
|
|
|
|
|
link_exdev_rel_symlink(const char *oldpath_,
|
|
|
|
|
const char *newpath_,
|
|
|
|
|
struct stat *st_,
|
|
|
|
|
fuse_timeouts_t *timeouts_)
|
|
|
|
|
{
|
|
|
|
|
int rv;
|
|
|
|
|
gfs::path target(oldpath_);
|
|
|
|
|
gfs::path linkpath(newpath_);
|
|
|
|
|
|
|
|
|
|
target = target.lexically_relative(linkpath.parent_path());
|
|
|
|
|
|
2021-03-28 12:34:30 -04:00
|
|
|
rv = FUSE::SYMLINK::symlink(target.c_str(),linkpath.c_str());
|
2020-06-21 14:45:14 -04:00
|
|
|
if(rv == 0)
|
2021-03-28 12:34:30 -04:00
|
|
|
rv = FUSE::GETATTR::getattr(oldpath_,st_,timeouts_);
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2022-03-19 15:15:34 -04:00
|
|
|
// Disable caching since we created a symlink but should be a regular.
|
|
|
|
|
timeouts_->attr = 0;
|
|
|
|
|
timeouts_->entry = 0;
|
2020-06-21 14:45:14 -04:00
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int
|
2021-03-28 12:34:30 -04:00
|
|
|
link_exdev_abs_base_symlink(const char *oldpath_,
|
|
|
|
|
const char *newpath_,
|
|
|
|
|
struct stat *st_,
|
|
|
|
|
fuse_timeouts_t *timeouts_)
|
2020-06-21 14:45:14 -04:00
|
|
|
{
|
|
|
|
|
int rv;
|
|
|
|
|
StrVec basepaths;
|
2021-03-28 12:34:30 -04:00
|
|
|
gfs::path target;
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2021-03-28 12:34:30 -04:00
|
|
|
target = "FIXME";
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2021-03-28 12:34:30 -04:00
|
|
|
rv = FUSE::SYMLINK::symlink(target.c_str(),newpath_);
|
2020-06-21 14:45:14 -04:00
|
|
|
if(rv == 0)
|
2021-03-28 12:34:30 -04:00
|
|
|
rv = FUSE::GETATTR::getattr(oldpath_,st_,timeouts_);
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2022-03-19 15:15:34 -04:00
|
|
|
// Disable caching since we created a symlink but should be a regular.
|
|
|
|
|
timeouts_->attr = 0;
|
|
|
|
|
timeouts_->entry = 0;
|
2020-06-21 14:45:14 -04:00
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int
|
2021-03-28 12:34:30 -04:00
|
|
|
link_exdev_abs_pool_symlink(const gfs::path &mount_,
|
|
|
|
|
const char *oldpath_,
|
|
|
|
|
const char *newpath_,
|
|
|
|
|
struct stat *st_,
|
|
|
|
|
fuse_timeouts_t *timeouts_)
|
2020-06-21 14:45:14 -04:00
|
|
|
{
|
|
|
|
|
int rv;
|
2021-03-28 12:34:30 -04:00
|
|
|
gfs::path target;
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2021-03-28 12:34:30 -04:00
|
|
|
target = mount_ / &oldpath_[1];
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2021-03-28 12:34:30 -04:00
|
|
|
rv = FUSE::SYMLINK::symlink(target.c_str(),newpath_);
|
2020-06-21 14:45:14 -04:00
|
|
|
if(rv == 0)
|
2021-03-28 12:34:30 -04:00
|
|
|
rv = FUSE::GETATTR::getattr(oldpath_,st_,timeouts_);
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2022-03-19 15:15:34 -04:00
|
|
|
// Disable caching since we created a symlink but should be a regular.
|
|
|
|
|
timeouts_->attr = 0;
|
|
|
|
|
timeouts_->entry = 0;
|
2020-06-21 14:45:14 -04:00
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int
|
2021-03-28 12:34:30 -04:00
|
|
|
link_exdev(State &s_,
|
2020-06-21 14:45:14 -04:00
|
|
|
const char *oldpath_,
|
|
|
|
|
const char *newpath_,
|
|
|
|
|
struct stat *st_,
|
|
|
|
|
fuse_timeouts_t *timeouts_)
|
|
|
|
|
{
|
2021-03-28 12:34:30 -04:00
|
|
|
switch(s_->link_exdev)
|
2020-06-21 14:45:14 -04:00
|
|
|
{
|
2021-03-28 12:34:30 -04:00
|
|
|
case LinkEXDEV::INVALID:
|
|
|
|
|
case LinkEXDEV::PASSTHROUGH:
|
2020-06-21 14:45:14 -04:00
|
|
|
return -EXDEV;
|
2021-03-28 12:34:30 -04:00
|
|
|
case LinkEXDEV::REL_SYMLINK:
|
2020-06-21 14:45:14 -04:00
|
|
|
return l::link_exdev_rel_symlink(oldpath_,
|
|
|
|
|
newpath_,
|
|
|
|
|
st_,
|
|
|
|
|
timeouts_);
|
2021-03-28 12:34:30 -04:00
|
|
|
case LinkEXDEV::ABS_BASE_SYMLINK:
|
|
|
|
|
return l::link_exdev_abs_base_symlink(oldpath_,
|
2020-06-21 14:45:14 -04:00
|
|
|
newpath_,
|
|
|
|
|
st_,
|
|
|
|
|
timeouts_);
|
2021-03-28 12:34:30 -04:00
|
|
|
case LinkEXDEV::ABS_POOL_SYMLINK:
|
|
|
|
|
return l::link_exdev_abs_pool_symlink(s_->mountpoint,
|
2020-06-21 14:45:14 -04:00
|
|
|
oldpath_,
|
|
|
|
|
newpath_,
|
|
|
|
|
st_,
|
|
|
|
|
timeouts_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -EXDEV;
|
2019-01-25 07:03:46 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-28 12:34:30 -04:00
|
|
|
namespace FUSE::LINK
|
2019-01-25 07:03:46 -05:00
|
|
|
{
|
|
|
|
|
int
|
2020-06-21 14:45:14 -04:00
|
|
|
link(const char *oldpath_,
|
|
|
|
|
const char *newpath_,
|
|
|
|
|
struct stat *st_,
|
|
|
|
|
fuse_timeouts_t *timeouts_)
|
2019-01-25 07:03:46 -05:00
|
|
|
{
|
2020-06-21 14:45:14 -04:00
|
|
|
int rv;
|
2021-03-28 12:34:30 -04:00
|
|
|
State s;
|
2022-05-15 13:11:02 -04:00
|
|
|
gfs::path oldpath;
|
|
|
|
|
gfs::path newpath;
|
2020-12-19 15:06:08 -05:00
|
|
|
const fuse_context *fc = fuse_get_context();
|
2019-09-24 10:27:46 -04:00
|
|
|
const ugid::Set ugid(fc->uid,fc->gid);
|
|
|
|
|
|
2022-05-15 13:11:02 -04:00
|
|
|
oldpath = &oldpath_[1];
|
|
|
|
|
newpath = &newpath_[1];
|
|
|
|
|
rv = s->link(oldpath,newpath);
|
2020-06-21 14:45:14 -04:00
|
|
|
if(rv == -EXDEV)
|
2021-03-28 12:34:30 -04:00
|
|
|
return l::link_exdev(s,oldpath_,newpath_,st_,timeouts_);
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2022-05-15 13:11:02 -04:00
|
|
|
return s->getattr(newpath,st_,timeouts_);
|
2019-01-25 07:03:46 -05:00
|
|
|
}
|
|
|
|
|
}
|