2014-05-12 12:41:46 -04:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
|
|
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fuse.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "config.hpp"
|
2015-09-15 18:49:18 -04:00
|
|
|
#include "fs_path.hpp"
|
2014-08-03 15:50:28 -04:00
|
|
|
#include "rwlock.hpp"
|
2015-09-15 18:49:18 -04:00
|
|
|
#include "ugid.hpp"
|
2014-05-12 12:41:46 -04:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
2015-06-22 23:35:46 -04:00
|
|
|
using mergerfs::Policy;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
|
|
|
static
|
|
|
|
int
|
2015-06-25 17:55:16 -04:00
|
|
|
_symlink(Policy::Func::Create createFunc,
|
|
|
|
const vector<string> &srcmounts,
|
|
|
|
const size_t minfreespace,
|
|
|
|
const string &oldpath,
|
|
|
|
const string &newpath)
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
|
|
|
int rv;
|
2015-02-24 18:47:31 -05:00
|
|
|
int error;
|
|
|
|
string newpathdir;
|
2015-07-01 07:47:40 -04:00
|
|
|
vector<string> newpathdirs;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2015-07-01 07:47:40 -04:00
|
|
|
newpathdir = fs::path::dirname(newpath);
|
2015-06-16 22:12:55 -04:00
|
|
|
rv = createFunc(srcmounts,newpathdir,minfreespace,newpathdirs);
|
2015-02-02 21:10:36 -05:00
|
|
|
if(rv == -1)
|
|
|
|
return -errno;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2015-02-24 18:47:31 -05:00
|
|
|
error = 0;
|
2015-06-30 23:35:28 -04:00
|
|
|
for(size_t i = 0, ei = newpathdirs.size(); i != ei; i++)
|
2015-02-24 18:47:31 -05:00
|
|
|
{
|
2015-07-01 07:47:40 -04:00
|
|
|
fs::path::append(newpathdirs[i],newpath);
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2015-07-01 07:47:40 -04:00
|
|
|
rv = symlink(oldpath.c_str(),newpathdirs[i].c_str());
|
2015-02-24 18:47:31 -05:00
|
|
|
if(rv == -1)
|
|
|
|
error = errno;
|
|
|
|
}
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2015-02-24 18:47:31 -05:00
|
|
|
return -error;
|
2014-05-12 12:41:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace mergerfs
|
|
|
|
{
|
2015-07-15 10:04:57 -04:00
|
|
|
namespace fuse
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
|
|
|
int
|
|
|
|
symlink(const char *oldpath,
|
|
|
|
const char *newpath)
|
|
|
|
{
|
2015-09-08 15:56:02 -04:00
|
|
|
const fuse_context *fc = fuse_get_context();
|
|
|
|
const Config &config = Config::get(fc);
|
|
|
|
const ugid::Set ugid(fc->uid,fc->gid);
|
|
|
|
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2015-06-25 17:55:16 -04:00
|
|
|
return _symlink(config.symlink,
|
2015-02-24 18:47:31 -05:00
|
|
|
config.srcmounts,
|
2015-06-16 22:12:55 -04:00
|
|
|
config.minfreespace,
|
2014-05-12 12:41:46 -04:00
|
|
|
oldpath,
|
|
|
|
newpath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|