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

chmod and chown support #16

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
46 changes: 46 additions & 0 deletions adbfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
#include <string.h>

void handler(int sig) {
void *array[10];
Expand Down Expand Up @@ -942,6 +943,49 @@ static int adb_readlink(const char *path, char *buf, size_t size)
return 0;
}

static int adb_chmod(const char* path, mode_t mode)
{
char mode_c[4];
sprintf(mode_c, "%3o", mode&0777);

string path_string;
path_string.assign(path);
shell_escape_path(path_string);

string command = "chmod ";
command.append(mode_c);
command.append(" ");
command.append(path_string);

adb_shell(command);
invalidateCache(string(path));
return 0;
}
static int adb_chown(const char* path, uid_t uid, gid_t gid)
{
char uid_c[10];
char gid_c[10];

sprintf(uid_c, "%i", uid);
sprintf(gid_c, "%i", gid);

string path_string;
path_string.assign(path);
shell_escape_path(path_string);

string command = "chown ";
command.append(uid_c);
command.append(".");
command.append(gid_c);
command.append(" ");
command.append(path_string);

adb_shell(command);
invalidateCache(string(path));
return 0;
}


/**
Main struct for FUSE interface.
*/
Expand Down Expand Up @@ -974,6 +1018,8 @@ int main(int argc, char *argv[])
adbfs_oper.rmdir = adb_rmdir;
adbfs_oper.unlink = adb_unlink;
adbfs_oper.readlink = adb_readlink;
adbfs_oper.chmod = adb_chmod;
adbfs_oper.chown = adb_chown;
adb_shell("ls");
return fuse_main(argc, argv, &adbfs_oper, NULL);
}