From 0d25cc9ad1625da528585d5a51ab2279dc185088 Mon Sep 17 00:00:00 2001 From: dipcore Date: Wed, 5 Oct 2016 22:54:41 -0400 Subject: [PATCH 1/2] chmod and chown support --- adbfs.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/adbfs.cpp b/adbfs.cpp index 11bcbf5..59515d7 100644 --- a/adbfs.cpp +++ b/adbfs.cpp @@ -80,6 +80,7 @@ #include #include #include +#include void handler(int sig) { void *array[10]; @@ -942,6 +943,42 @@ 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 command = "chmod "; + command.append(mode_c); + command.append(" "); + command.append(path); + + 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 command = "chown "; + command.append(uid_c); + command.append("."); + command.append(gid_c); + command.append(" "); + command.append(path); + + adb_shell(command); + invalidateCache(string(path)); + + return 0; +} + + /** Main struct for FUSE interface. */ @@ -974,6 +1011,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); } From a61fe2432a8eb80147dc0707d0e5c27ae67dcbb6 Mon Sep 17 00:00:00 2001 From: dipcore Date: Thu, 6 Oct 2016 14:38:43 -0400 Subject: [PATCH 2/2] using shell_escape_path in chmod and chown fn-s --- adbfs.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/adbfs.cpp b/adbfs.cpp index 59515d7..cafd69b 100644 --- a/adbfs.cpp +++ b/adbfs.cpp @@ -948,10 +948,14 @@ 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); + command.append(path_string); adb_shell(command); invalidateCache(string(path)); @@ -965,16 +969,19 @@ static int adb_chown(const char* path, uid_t uid, gid_t gid) 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); + command.append(path_string); adb_shell(command); invalidateCache(string(path)); - return 0; }