mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
Some checks are pending
mkdocs / deploy (push) Waiting to run
Run in an elevated credential mode (root) and let the kernel manage entitlements. Will result in slightly different behavior but should not be noticed by most.
56 lines
1.1 KiB
C++
56 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include "fs_open.hpp"
|
|
#include "ugid.hpp"
|
|
|
|
// Linux can set ugid because it allows for credentials per
|
|
// thread. FreeBSD however does not and must create as root then
|
|
// chown. Another option for both platforms would be to create a temp
|
|
// file, chown, then rename to target. Unfortunately, depending on if
|
|
// the target filesystem is POSIX compliant or uses POSIX / extended
|
|
// ACLs it is not possible to know what is best.
|
|
|
|
|
|
#if defined __linux__
|
|
namespace fs
|
|
{
|
|
static
|
|
inline
|
|
int
|
|
open_as(const ugid_t ugid_,
|
|
const fs::path &path_,
|
|
const int flags_,
|
|
const mode_t mode_)
|
|
{
|
|
const ugid::SetGuard _(ugid_);
|
|
|
|
return fs::open(path_,flags_,mode_);
|
|
}
|
|
}
|
|
#elif defined __FreeBSD__
|
|
#include "fs_fchown.hpp"
|
|
|
|
namespace fs
|
|
{
|
|
static
|
|
inline
|
|
int
|
|
open_as(const ugid_t ugid_,
|
|
const fs::path &path_,
|
|
const int flags_,
|
|
const mode_t mode_)
|
|
{
|
|
int rv;
|
|
|
|
rv = fs::open(path_,flags_,mode_);
|
|
if(rv < 0)
|
|
return rv;
|
|
|
|
fs::fchown(rv,ugid_.uid,ugid_.gid);
|
|
|
|
return rv;
|
|
}
|
|
}
|
|
#else
|
|
#error "Not Supported!"
|
|
#endif
|