am e93a0517: Set GID required to write, media_rw mount point.
* commit 'e93a0517f4c88310066ac39c6b268ebfcceef44e': Set GID required to write, media_rw mount point.
This commit is contained in:
commit
a5fdea7189
2 changed files with 17 additions and 13 deletions
|
|
@ -64,6 +64,7 @@ loglevel 3
|
||||||
|
|
||||||
# See storage config details at http://source.android.com/tech/storage/
|
# See storage config details at http://source.android.com/tech/storage/
|
||||||
mkdir /mnt/shell 0700 shell shell
|
mkdir /mnt/shell 0700 shell shell
|
||||||
|
mkdir /mnt/media_rw 0700 media_rw media_rw
|
||||||
mkdir /storage 0751 root sdcard_r
|
mkdir /storage 0751 root sdcard_r
|
||||||
|
|
||||||
# Directory for putting things only root should see.
|
# Directory for putting things only root should see.
|
||||||
|
|
|
||||||
|
|
@ -215,6 +215,7 @@ struct fuse {
|
||||||
int fd;
|
int fd;
|
||||||
derive_t derive;
|
derive_t derive;
|
||||||
bool split_perms;
|
bool split_perms;
|
||||||
|
gid_t write_gid;
|
||||||
struct node root;
|
struct node root;
|
||||||
char obbpath[PATH_MAX];
|
char obbpath[PATH_MAX];
|
||||||
|
|
||||||
|
|
@ -681,13 +682,14 @@ static struct node* acquire_or_create_child_locked(
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fuse_init(struct fuse *fuse, int fd, const char *source_path,
|
static void fuse_init(struct fuse *fuse, int fd, const char *source_path,
|
||||||
gid_t fs_gid, derive_t derive, bool split_perms) {
|
gid_t write_gid, derive_t derive, bool split_perms) {
|
||||||
pthread_mutex_init(&fuse->lock, NULL);
|
pthread_mutex_init(&fuse->lock, NULL);
|
||||||
|
|
||||||
fuse->fd = fd;
|
fuse->fd = fd;
|
||||||
fuse->next_generation = 0;
|
fuse->next_generation = 0;
|
||||||
fuse->derive = derive;
|
fuse->derive = derive;
|
||||||
fuse->split_perms = split_perms;
|
fuse->split_perms = split_perms;
|
||||||
|
fuse->write_gid = write_gid;
|
||||||
|
|
||||||
memset(&fuse->root, 0, sizeof(fuse->root));
|
memset(&fuse->root, 0, sizeof(fuse->root));
|
||||||
fuse->root.nid = FUSE_ROOT_ID; /* 1 */
|
fuse->root.nid = FUSE_ROOT_ID; /* 1 */
|
||||||
|
|
@ -712,7 +714,7 @@ static void fuse_init(struct fuse *fuse, int fd, const char *source_path,
|
||||||
* just below that. Shared OBB path is also at top level. */
|
* just below that. Shared OBB path is also at top level. */
|
||||||
fuse->root.perm = PERM_LEGACY_PRE_ROOT;
|
fuse->root.perm = PERM_LEGACY_PRE_ROOT;
|
||||||
fuse->root.mode = 0771;
|
fuse->root.mode = 0771;
|
||||||
fuse->root.gid = fs_gid;
|
fuse->root.gid = AID_SDCARD_R;
|
||||||
fuse->package_to_appid = hashmapCreate(256, str_hash, str_icase_equals);
|
fuse->package_to_appid = hashmapCreate(256, str_hash, str_icase_equals);
|
||||||
fuse->appid_with_rw = hashmapCreate(128, int_hash, int_equals);
|
fuse->appid_with_rw = hashmapCreate(128, int_hash, int_equals);
|
||||||
snprintf(fuse->obbpath, sizeof(fuse->obbpath), "%s/obb", source_path);
|
snprintf(fuse->obbpath, sizeof(fuse->obbpath), "%s/obb", source_path);
|
||||||
|
|
@ -723,7 +725,7 @@ static void fuse_init(struct fuse *fuse, int fd, const char *source_path,
|
||||||
* /Android/user and shared OBB path under /Android/obb. */
|
* /Android/user and shared OBB path under /Android/obb. */
|
||||||
fuse->root.perm = PERM_ROOT;
|
fuse->root.perm = PERM_ROOT;
|
||||||
fuse->root.mode = 0771;
|
fuse->root.mode = 0771;
|
||||||
fuse->root.gid = fs_gid;
|
fuse->root.gid = AID_SDCARD_R;
|
||||||
fuse->package_to_appid = hashmapCreate(256, str_hash, str_icase_equals);
|
fuse->package_to_appid = hashmapCreate(256, str_hash, str_icase_equals);
|
||||||
fuse->appid_with_rw = hashmapCreate(128, int_hash, int_equals);
|
fuse->appid_with_rw = hashmapCreate(128, int_hash, int_equals);
|
||||||
snprintf(fuse->obbpath, sizeof(fuse->obbpath), "%s/Android/obb", source_path);
|
snprintf(fuse->obbpath, sizeof(fuse->obbpath), "%s/Android/obb", source_path);
|
||||||
|
|
@ -1623,7 +1625,7 @@ static int read_package_list(struct fuse *fuse) {
|
||||||
|
|
||||||
char* token = strtok(gids, ",");
|
char* token = strtok(gids, ",");
|
||||||
while (token != NULL) {
|
while (token != NULL) {
|
||||||
if (strtoul(token, NULL, 10) == AID_SDCARD_RW) {
|
if (strtoul(token, NULL, 10) == fuse->write_gid) {
|
||||||
hashmapPut(fuse->appid_with_rw, (void*) appid, (void*) 1);
|
hashmapPut(fuse->appid_with_rw, (void*) appid, (void*) 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1632,7 +1634,7 @@ static int read_package_list(struct fuse *fuse) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE("read_package_list: found %d packages, %d with sdcard_rw\n",
|
TRACE("read_package_list: found %d packages, %d with write_gid\n",
|
||||||
hashmapSize(fuse->package_to_appid),
|
hashmapSize(fuse->package_to_appid),
|
||||||
hashmapSize(fuse->appid_with_rw));
|
hashmapSize(fuse->appid_with_rw));
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
@ -1749,7 +1751,7 @@ static int usage()
|
||||||
ERROR("usage: sdcard [OPTIONS] <source_path> <dest_path>\n"
|
ERROR("usage: sdcard [OPTIONS] <source_path> <dest_path>\n"
|
||||||
" -u: specify UID to run as\n"
|
" -u: specify UID to run as\n"
|
||||||
" -g: specify GID to run as\n"
|
" -g: specify GID to run as\n"
|
||||||
" -G: specify default GID for files (default sdcard_r, requires -d or -l)\n"
|
" -w: specify GID required to write (default sdcard_rw, requires -d or -l)\n"
|
||||||
" -t: specify number of threads to use (default %d)\n"
|
" -t: specify number of threads to use (default %d)\n"
|
||||||
" -d: derive file permissions based on path\n"
|
" -d: derive file permissions based on path\n"
|
||||||
" -l: derive file permissions based on legacy internal layout\n"
|
" -l: derive file permissions based on legacy internal layout\n"
|
||||||
|
|
@ -1759,7 +1761,8 @@ static int usage()
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run(const char* source_path, const char* dest_path, uid_t uid,
|
static int run(const char* source_path, const char* dest_path, uid_t uid,
|
||||||
gid_t gid, gid_t fs_gid, int num_threads, derive_t derive, bool split_perms) {
|
gid_t gid, gid_t write_gid, int num_threads, derive_t derive,
|
||||||
|
bool split_perms) {
|
||||||
int fd;
|
int fd;
|
||||||
char opts[256];
|
char opts[256];
|
||||||
int res;
|
int res;
|
||||||
|
|
@ -1802,7 +1805,7 @@ static int run(const char* source_path, const char* dest_path, uid_t uid,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
fuse_init(&fuse, fd, source_path, fs_gid, derive, split_perms);
|
fuse_init(&fuse, fd, source_path, write_gid, derive, split_perms);
|
||||||
|
|
||||||
umask(0);
|
umask(0);
|
||||||
res = ignite_fuse(&fuse, num_threads);
|
res = ignite_fuse(&fuse, num_threads);
|
||||||
|
|
@ -1822,7 +1825,7 @@ int main(int argc, char **argv)
|
||||||
const char *dest_path = NULL;
|
const char *dest_path = NULL;
|
||||||
uid_t uid = 0;
|
uid_t uid = 0;
|
||||||
gid_t gid = 0;
|
gid_t gid = 0;
|
||||||
gid_t fs_gid = AID_SDCARD_R;
|
gid_t write_gid = AID_SDCARD_RW;
|
||||||
int num_threads = DEFAULT_NUM_THREADS;
|
int num_threads = DEFAULT_NUM_THREADS;
|
||||||
derive_t derive = DERIVE_NONE;
|
derive_t derive = DERIVE_NONE;
|
||||||
bool split_perms = false;
|
bool split_perms = false;
|
||||||
|
|
@ -1830,7 +1833,7 @@ int main(int argc, char **argv)
|
||||||
struct rlimit rlim;
|
struct rlimit rlim;
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "u:g:G:t:dls")) != -1) {
|
while ((opt = getopt(argc, argv, "u:g:w:t:dls")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'u':
|
case 'u':
|
||||||
uid = strtoul(optarg, NULL, 10);
|
uid = strtoul(optarg, NULL, 10);
|
||||||
|
|
@ -1838,8 +1841,8 @@ int main(int argc, char **argv)
|
||||||
case 'g':
|
case 'g':
|
||||||
gid = strtoul(optarg, NULL, 10);
|
gid = strtoul(optarg, NULL, 10);
|
||||||
break;
|
break;
|
||||||
case 'G':
|
case 'w':
|
||||||
fs_gid = strtoul(optarg, NULL, 10);
|
write_gid = strtoul(optarg, NULL, 10);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
num_threads = strtoul(optarg, NULL, 10);
|
num_threads = strtoul(optarg, NULL, 10);
|
||||||
|
|
@ -1902,6 +1905,6 @@ int main(int argc, char **argv)
|
||||||
ERROR("Error setting RLIMIT_NOFILE, errno = %d\n", errno);
|
ERROR("Error setting RLIMIT_NOFILE, errno = %d\n", errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
res = run(source_path, dest_path, uid, gid, fs_gid, num_threads, derive, split_perms);
|
res = run(source_path, dest_path, uid, gid, write_gid, num_threads, derive, split_perms);
|
||||||
return res < 0 ? 1 : 0;
|
return res < 0 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue