From 35f87ce0a7aeddaaad118daed3022e01453b838d Mon Sep 17 00:00:00 2001 From: Paul Kronenwetter Date: Sun, 21 May 2017 15:00:40 -0400 Subject: [PATCH] Patch for issue #14 that "fixes" read access from phone. Creation and writes will very likely fail and this probably breaks compatibility with Marshmallow and below. --- adbfs.cpp | 17 +++++++++-------- utils.h | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/adbfs.cpp b/adbfs.cpp index 11bcbf5..5556df6 100644 --- a/adbfs.cpp +++ b/adbfs.cpp @@ -150,7 +150,7 @@ queue adb_shell(const string& command) actual_command.assign(command); //adb_shell_escape_command(actual_command); actual_command.insert(0, "adb shell \""); - actual_command.append("\""); + actual_command.append("\" 2>/dev/null"); return exec_command(actual_command); } @@ -428,13 +428,13 @@ static int adb_getattr(const char *path, struct stat *stbuf) stbuf->st_nlink = 1; /* number of hard links */ - foruid = getpwnam(output_chunk[1].c_str()); + foruid = getpwnam(output_chunk[2].c_str()); if (foruid) stbuf->st_uid = foruid->pw_uid; /* user ID of owner */ else stbuf->st_uid = 98; /* 98 has been chosen (poorly) so that it doesn't map to anything */ - forgid = getgrnam(output_chunk[2].c_str()); + forgid = getgrnam(output_chunk[3].c_str()); if (forgid) stbuf->st_gid = forgid->gr_gid; /* group ID of owner */ else @@ -449,7 +449,7 @@ static int adb_getattr(const char *path, struct stat *stbuf) switch (stbuf->st_mode & S_IFMT) { case S_IFBLK: case S_IFCHR: - stbuf->st_rdev = atoi(output_chunk[3].c_str()) * 256 + atoi(output_chunk[4].c_str()); + stbuf->st_rdev = atoi(output_chunk[4].c_str()) * 256 + atoi(output_chunk[4].c_str()); stbuf->st_size = 0; iDate = 5; break; @@ -457,8 +457,8 @@ static int adb_getattr(const char *path, struct stat *stbuf) break; case S_IFREG: - stbuf->st_size = atoi(output_chunk[3].c_str()); /* total size, in bytes */ - iDate = 4; + stbuf->st_size = atoi(output_chunk[4].c_str()); /* total size, in bytes */ + iDate = 5; break; default: @@ -467,7 +467,7 @@ static int adb_getattr(const char *path, struct stat *stbuf) case S_IFLNK: case S_IFDIR: stbuf->st_size = 0; - iDate = 3; + iDate = 5; break; } @@ -551,7 +551,8 @@ static int adb_readdir(const char *path, void *buf, fuse_fill_dir_t filler, // we can get e.g. "permission denied" during listing, need to check every line separately if (!is_valid_ls_output(output.front())) { // error format: "lstat '//efs' failed: Permission denied" - if (!output.front().compare(output.front().length() - sizeof(PERMISSION_ERR_MSG) + 1, + if (output.front().length() > sizeof(PERMISSION_ERR_MSG) + 1 && + !output.front().compare(output.front().length() - sizeof(PERMISSION_ERR_MSG) + 1, sizeof(PERMISSION_ERR_MSG) - 1, PERMISSION_ERR_MSG)) { size_t nameStart = output.front().rfind("/") + 1; const string& fname_l = output.front().substr(nameStart, output.front().find("' ") - nameStart); diff --git a/utils.h b/utils.h index 7e64a71..cf509c8 100644 --- a/utils.h +++ b/utils.h @@ -164,7 +164,7 @@ queue exec_command(const string& command) while ( fgets( buff, sizeof buff, fp ) != NULL && !feof(fp) ) { tmp_string.assign(buff); - tmp_string.erase(tmp_string.size()-2); + tmp_string.erase(tmp_string.size()-1); output.push(tmp_string); }