Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for setting UID/GID through mount options #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions apfsfuse/ApfsFuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <getopt.h>

#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

Expand All @@ -54,6 +55,8 @@ static struct fuse_lowlevel_ops ops;
static Device *g_disk = nullptr;
static ApfsContainer *g_container = nullptr;
static ApfsVolume *g_volume = nullptr;
static uid_t g_uid = 0;
static gid_t g_gid = 0;

struct Directory
{
Expand Down Expand Up @@ -108,16 +111,12 @@ static bool apfs_stat_internal(fuse_ino_t ino, struct stat &st)

// st.st_uid = rec.owner;
// st.st_gid = rec.group;
st.st_uid = geteuid();
st.st_gid = getegid();
st.st_uid = g_uid;
st.st_uid = g_gid;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can't be right. Did you mean to set st.st_gid?


if (rec.optional_present_flags & ApfsDir::Inode::INO_HAS_RDEV)
st.st_rdev = rec.rdev;

// st_uid
// st_gid
// st_rdev?

if (S_ISREG(st.st_mode))
{
if (rec.bsd_flags & 0x20) // Compressed
Expand Down Expand Up @@ -618,6 +617,24 @@ bool add_option(std::string &optstr, const char *name, const char *value)
return true;
}

static int apfs_parse_fuse_opt(void* data, const char* arg, int key, struct fuse_args* outargs)
{
if (key == FUSE_OPT_KEY_OPT)
{
if (strncmp(arg, "uid=", 4) == 0 || strncmp(arg, "user_id=", 8) == 0)
{
g_uid = (uid_t)strtol(strchr(arg, '=') + sizeof(char), NULL, 10);
return 0;
}
if (strncmp(arg, "gid=", 4) == 0 || strncmp(arg, "group_id=", 9) == 0)
{
g_gid = (gid_t)strtol(strchr(arg, '=') + sizeof(char), NULL, 10);
return 0;
}
}
return 1;
}

int main(int argc, char *argv[])
{
struct fuse_args args = FUSE_ARGS_INIT(0, nullptr);
Expand All @@ -639,6 +656,8 @@ int main(int argc, char *argv[])
// static const char *dev_path = "/mnt/data/Projekte/VS17/Apfs/Data/apfs_clone_test.img";

memset(&ops, 0, sizeof(ops));
g_uid = geteuid();
g_gid = getegid();

// ops.bmap = apfs_bmap;
// ops.destroy = apfs_destroy;
Expand Down Expand Up @@ -761,7 +780,11 @@ int main(int argc, char *argv[])
fuse_opt_add_arg(&args, "-o");
fuse_opt_add_arg(&args, mount_options.c_str());

if ((ch = fuse_mount(mountpoint, &args)) != NULL)
if (fuse_opt_parse(&args, NULL, NULL, apfs_parse_fuse_opt) != 0)
{
std::cerr << "Unable to parse options!" << std::endl;
}
else if ((ch = fuse_mount(mountpoint, &args)) != NULL)
{
struct fuse_session *se;

Expand Down