Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 1 | // Copyright (C) 2016 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #define LOG_TAG "sdcard" |
| 16 | |
| 17 | #include <dirent.h> |
| 18 | #include <errno.h> |
| 19 | #include <fcntl.h> |
| 20 | #include <linux/fuse.h> |
| 21 | #include <pthread.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | #include <sys/inotify.h> |
| 25 | #include <sys/mount.h> |
| 26 | #include <sys/resource.h> |
| 27 | #include <sys/stat.h> |
| 28 | #include <sys/types.h> |
| 29 | #include <unistd.h> |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 30 | #include <vector> |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 31 | |
Daniel Rosenberg | 9526819 | 2016-08-26 16:54:46 -0700 | [diff] [blame] | 32 | #include <android-base/file.h> |
Jorge Lucangeli Obes | c9e1710 | 2016-07-12 17:05:32 -0400 | [diff] [blame] | 33 | #include <android-base/logging.h> |
Jorge Lucangeli Obes | bae15b4 | 2016-07-18 13:46:42 -0400 | [diff] [blame] | 34 | #include <android-base/macros.h> |
Daniel Rosenberg | 9526819 | 2016-08-26 16:54:46 -0700 | [diff] [blame] | 35 | #include <android-base/stringprintf.h> |
| 36 | #include <android-base/strings.h> |
Jorge Lucangeli Obes | c9e1710 | 2016-07-12 17:05:32 -0400 | [diff] [blame] | 37 | |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 38 | #include <cutils/fs.h> |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 39 | #include <cutils/multiuser.h> |
Daniel Rosenberg | 9526819 | 2016-08-26 16:54:46 -0700 | [diff] [blame] | 40 | #include <cutils/properties.h> |
| 41 | |
Jorge Lucangeli Obes | c96f53e | 2016-07-14 14:50:14 -0400 | [diff] [blame] | 42 | #include <libminijail.h> |
| 43 | #include <scoped_minijail.h> |
| 44 | |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 45 | #include <private/android_filesystem_config.h> |
| 46 | |
Daniel Rosenberg | c336f86 | 2018-01-17 18:11:20 -0800 | [diff] [blame] | 47 | #define PROP_SDCARDFS_DEVICE "ro.sys.sdcardfs" |
| 48 | #define PROP_SDCARDFS_USER "persist.sys.sdcardfs" |
| 49 | |
| 50 | static bool supports_esdfs(void) { |
| 51 | std::string filesystems; |
| 52 | if (!android::base::ReadFileToString("/proc/filesystems", &filesystems)) { |
| 53 | PLOG(ERROR) << "Could not read /proc/filesystems"; |
| 54 | return false; |
| 55 | } |
| 56 | for (const auto& fs : android::base::Split(filesystems, "\n")) { |
| 57 | if (fs.find("esdfs") != std::string::npos) return true; |
| 58 | } |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | static bool should_use_sdcardfs(void) { |
| 63 | char property[PROPERTY_VALUE_MAX]; |
| 64 | |
| 65 | // Allow user to have a strong opinion about state |
| 66 | property_get(PROP_SDCARDFS_USER, property, ""); |
| 67 | if (!strcmp(property, "force_on")) { |
| 68 | LOG(WARNING) << "User explicitly enabled sdcardfs"; |
| 69 | return true; |
| 70 | } else if (!strcmp(property, "force_off")) { |
| 71 | LOG(WARNING) << "User explicitly disabled sdcardfs"; |
| 72 | return !supports_esdfs(); |
| 73 | } |
| 74 | |
| 75 | // Fall back to device opinion about state |
| 76 | if (property_get_bool(PROP_SDCARDFS_DEVICE, true)) { |
| 77 | LOG(WARNING) << "Device explicitly enabled sdcardfs"; |
| 78 | return true; |
| 79 | } else { |
| 80 | LOG(WARNING) << "Device explicitly disabled sdcardfs"; |
| 81 | return !supports_esdfs(); |
| 82 | } |
| 83 | } |
| 84 | |
Jeff Sharkey | 68e1093 | 2018-01-08 11:22:38 -0700 | [diff] [blame] | 85 | // NOTE: This is a vestigial program that simply exists to mount the in-kernel |
| 86 | // sdcardfs filesystem. The older FUSE-based design that used to live here has |
| 87 | // been completely removed to avoid confusion. |
Daniel Rosenberg | 9526819 | 2016-08-26 16:54:46 -0700 | [diff] [blame] | 88 | |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 89 | /* Supplementary groups to execute with. */ |
| 90 | static const gid_t kGroups[1] = { AID_PACKAGE_INFO }; |
| 91 | |
Jorge Lucangeli Obes | c96f53e | 2016-07-14 14:50:14 -0400 | [diff] [blame] | 92 | static void drop_privs(uid_t uid, gid_t gid) { |
| 93 | ScopedMinijail j(minijail_new()); |
Jorge Lucangeli Obes | bae15b4 | 2016-07-18 13:46:42 -0400 | [diff] [blame] | 94 | minijail_set_supplementary_gids(j.get(), arraysize(kGroups), kGroups); |
Jorge Lucangeli Obes | c96f53e | 2016-07-14 14:50:14 -0400 | [diff] [blame] | 95 | minijail_change_gid(j.get(), gid); |
| 96 | minijail_change_uid(j.get(), uid); |
| 97 | /* minijail_enter() will abort if priv-dropping fails. */ |
| 98 | minijail_enter(j.get()); |
| 99 | } |
| 100 | |
Rom Lemarchand | 9813914 | 2017-09-15 18:47:50 +0000 | [diff] [blame] | 101 | static bool sdcardfs_setup(const std::string& source_path, const std::string& dest_path, |
| 102 | uid_t fsuid, gid_t fsgid, bool multi_user, userid_t userid, gid_t gid, |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 103 | mode_t mask, bool derive_gid, bool default_normal, bool unshared_obb, |
| 104 | bool use_esdfs) { |
| 105 | // Add new options at the end of the vector. |
| 106 | std::vector<std::string> new_opts_list; |
| 107 | if (multi_user) new_opts_list.push_back("multiuser,"); |
| 108 | if (derive_gid) new_opts_list.push_back("derive_gid,"); |
| 109 | if (default_normal) new_opts_list.push_back("default_normal,"); |
| 110 | if (unshared_obb) new_opts_list.push_back("unshared_obb,"); |
Jeff Sharkey | e2e3610 | 2018-01-08 11:43:46 -0700 | [diff] [blame] | 111 | // Try several attempts, each time with one less option, to gracefully |
| 112 | // handle older kernels that aren't updated yet. |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 113 | for (int i = 0; i <= new_opts_list.size(); ++i) { |
Jeff Sharkey | e2e3610 | 2018-01-08 11:43:46 -0700 | [diff] [blame] | 114 | std::string new_opts; |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 115 | for (int j = 0; j < new_opts_list.size() - i; ++j) { |
| 116 | new_opts += new_opts_list[j]; |
| 117 | } |
Daniel Rosenberg | 9526819 | 2016-08-26 16:54:46 -0700 | [diff] [blame] | 118 | |
Jeff Sharkey | e2e3610 | 2018-01-08 11:43:46 -0700 | [diff] [blame] | 119 | auto opts = android::base::StringPrintf("fsuid=%d,fsgid=%d,%smask=%d,userid=%d,gid=%d", |
| 120 | fsuid, fsgid, new_opts.c_str(), mask, userid, gid); |
Daniel Rosenberg | c336f86 | 2018-01-17 18:11:20 -0800 | [diff] [blame] | 121 | if (mount(source_path.c_str(), dest_path.c_str(), use_esdfs ? "esdfs" : "sdcardfs", |
Jeff Sharkey | e2e3610 | 2018-01-08 11:43:46 -0700 | [diff] [blame] | 122 | MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()) == -1) { |
| 123 | PLOG(WARNING) << "Failed to mount sdcardfs with options " << opts; |
Rom Lemarchand | 9813914 | 2017-09-15 18:47:50 +0000 | [diff] [blame] | 124 | } else { |
Jeff Sharkey | e2e3610 | 2018-01-08 11:43:46 -0700 | [diff] [blame] | 125 | return true; |
Rom Lemarchand | 9813914 | 2017-09-15 18:47:50 +0000 | [diff] [blame] | 126 | } |
Daniel Rosenberg | 9526819 | 2016-08-26 16:54:46 -0700 | [diff] [blame] | 127 | } |
Jeff Sharkey | e2e3610 | 2018-01-08 11:43:46 -0700 | [diff] [blame] | 128 | |
| 129 | return false; |
Daniel Rosenberg | 9526819 | 2016-08-26 16:54:46 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Daniel Rosenberg | fc59232 | 2016-10-27 17:43:37 -0700 | [diff] [blame] | 132 | static bool sdcardfs_setup_bind_remount(const std::string& source_path, const std::string& dest_path, |
| 133 | gid_t gid, mode_t mask) { |
| 134 | std::string opts = android::base::StringPrintf("mask=%d,gid=%d", mask, gid); |
| 135 | |
| 136 | if (mount(source_path.c_str(), dest_path.c_str(), nullptr, |
| 137 | MS_BIND, nullptr) != 0) { |
| 138 | PLOG(ERROR) << "failed to bind mount sdcardfs filesystem"; |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | if (mount(source_path.c_str(), dest_path.c_str(), "none", |
| 143 | MS_REMOUNT | MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()) != 0) { |
| 144 | PLOG(ERROR) << "failed to mount sdcardfs filesystem"; |
| 145 | if (umount2(dest_path.c_str(), MNT_DETACH)) |
| 146 | PLOG(WARNING) << "Failed to unmount bind"; |
| 147 | return false; |
| 148 | } |
| 149 | |
| 150 | return true; |
| 151 | } |
| 152 | |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 153 | static bool sdcardfs_setup_secondary(const std::string& default_path, |
| 154 | const std::string& source_path, const std::string& dest_path, |
| 155 | uid_t fsuid, gid_t fsgid, bool multi_user, userid_t userid, |
| 156 | gid_t gid, mode_t mask, bool derive_gid, bool default_normal, |
| 157 | bool unshared_obb, bool use_esdfs) { |
Daniel Rosenberg | c336f86 | 2018-01-17 18:11:20 -0800 | [diff] [blame] | 158 | if (use_esdfs) { |
| 159 | return sdcardfs_setup(source_path, dest_path, fsuid, fsgid, multi_user, userid, gid, mask, |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 160 | derive_gid, default_normal, unshared_obb, use_esdfs); |
Daniel Rosenberg | c336f86 | 2018-01-17 18:11:20 -0800 | [diff] [blame] | 161 | } else { |
| 162 | return sdcardfs_setup_bind_remount(default_path, dest_path, gid, mask); |
| 163 | } |
| 164 | } |
| 165 | |
Daniel Rosenberg | 9526819 | 2016-08-26 16:54:46 -0700 | [diff] [blame] | 166 | static void run_sdcardfs(const std::string& source_path, const std::string& label, uid_t uid, |
Rom Lemarchand | 9813914 | 2017-09-15 18:47:50 +0000 | [diff] [blame] | 167 | gid_t gid, userid_t userid, bool multi_user, bool full_write, |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 168 | bool derive_gid, bool default_normal, bool unshared_obb, bool use_esdfs) { |
Daniel Rosenberg | 9526819 | 2016-08-26 16:54:46 -0700 | [diff] [blame] | 169 | std::string dest_path_default = "/mnt/runtime/default/" + label; |
| 170 | std::string dest_path_read = "/mnt/runtime/read/" + label; |
| 171 | std::string dest_path_write = "/mnt/runtime/write/" + label; |
Sudheer Shanka | 81c687d | 2019-01-16 23:25:28 -0800 | [diff] [blame] | 172 | std::string dest_path_full = "/mnt/runtime/full/" + label; |
Daniel Rosenberg | 9526819 | 2016-08-26 16:54:46 -0700 | [diff] [blame] | 173 | |
| 174 | umask(0); |
| 175 | if (multi_user) { |
| 176 | // Multi-user storage is fully isolated per user, so "other" |
| 177 | // permissions are completely masked off. |
| 178 | if (!sdcardfs_setup(source_path, dest_path_default, uid, gid, multi_user, userid, |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 179 | AID_SDCARD_RW, 0006, derive_gid, default_normal, unshared_obb, |
| 180 | use_esdfs) || |
Daniel Rosenberg | c336f86 | 2018-01-17 18:11:20 -0800 | [diff] [blame] | 181 | !sdcardfs_setup_secondary(dest_path_default, source_path, dest_path_read, uid, gid, |
| 182 | multi_user, userid, AID_EVERYBODY, 0027, derive_gid, |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 183 | default_normal, unshared_obb, use_esdfs) || |
Daniel Rosenberg | c336f86 | 2018-01-17 18:11:20 -0800 | [diff] [blame] | 184 | !sdcardfs_setup_secondary(dest_path_default, source_path, dest_path_write, uid, gid, |
| 185 | multi_user, userid, AID_EVERYBODY, full_write ? 0007 : 0027, |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 186 | derive_gid, default_normal, unshared_obb, use_esdfs) || |
Sudheer Shanka | 81c687d | 2019-01-16 23:25:28 -0800 | [diff] [blame] | 187 | !sdcardfs_setup_secondary(dest_path_default, source_path, dest_path_full, uid, gid, |
| 188 | multi_user, userid, AID_EVERYBODY, 0007, derive_gid, |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 189 | default_normal, unshared_obb, use_esdfs)) { |
Daniel Rosenberg | 9526819 | 2016-08-26 16:54:46 -0700 | [diff] [blame] | 190 | LOG(FATAL) << "failed to sdcardfs_setup"; |
| 191 | } |
| 192 | } else { |
| 193 | // Physical storage is readable by all users on device, but |
| 194 | // the Android directories are masked off to a single user |
| 195 | // deep inside attr_from_stat(). |
| 196 | if (!sdcardfs_setup(source_path, dest_path_default, uid, gid, multi_user, userid, |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 197 | AID_SDCARD_RW, 0006, derive_gid, default_normal, unshared_obb, |
| 198 | use_esdfs) || |
Daniel Rosenberg | c336f86 | 2018-01-17 18:11:20 -0800 | [diff] [blame] | 199 | !sdcardfs_setup_secondary(dest_path_default, source_path, dest_path_read, uid, gid, |
| 200 | multi_user, userid, AID_EVERYBODY, full_write ? 0027 : 0022, |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 201 | derive_gid, default_normal, unshared_obb, use_esdfs) || |
Daniel Rosenberg | c336f86 | 2018-01-17 18:11:20 -0800 | [diff] [blame] | 202 | !sdcardfs_setup_secondary(dest_path_default, source_path, dest_path_write, uid, gid, |
| 203 | multi_user, userid, AID_EVERYBODY, full_write ? 0007 : 0022, |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 204 | derive_gid, default_normal, unshared_obb, use_esdfs) || |
Sudheer Shanka | 81c687d | 2019-01-16 23:25:28 -0800 | [diff] [blame] | 205 | !sdcardfs_setup_secondary(dest_path_default, source_path, dest_path_full, uid, gid, |
| 206 | multi_user, userid, AID_EVERYBODY, 0007, derive_gid, |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 207 | default_normal, unshared_obb, use_esdfs)) { |
Daniel Rosenberg | 9526819 | 2016-08-26 16:54:46 -0700 | [diff] [blame] | 208 | LOG(FATAL) << "failed to sdcardfs_setup"; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // Will abort if priv-dropping fails. |
| 213 | drop_privs(uid, gid); |
| 214 | |
| 215 | if (multi_user) { |
| 216 | std::string obb_path = source_path + "/obb"; |
| 217 | fs_prepare_dir(obb_path.c_str(), 0775, uid, gid); |
| 218 | } |
| 219 | |
| 220 | exit(0); |
| 221 | } |
| 222 | |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 223 | static int usage() { |
Jorge Lucangeli Obes | c9e1710 | 2016-07-12 17:05:32 -0400 | [diff] [blame] | 224 | LOG(ERROR) << "usage: sdcard [OPTIONS] <source_path> <label>" |
| 225 | << " -u: specify UID to run as" |
| 226 | << " -g: specify GID to run as" |
| 227 | << " -U: specify user ID that owns device" |
| 228 | << " -m: source_path is multi-user" |
Rom Lemarchand | 9813914 | 2017-09-15 18:47:50 +0000 | [diff] [blame] | 229 | << " -w: runtime write mount has full write access" |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 230 | << " -P: preserve owners on the lower file system" |
| 231 | << " -o: obb dir doesn't need to be shared between users"; |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 232 | return 1; |
| 233 | } |
| 234 | |
| 235 | int main(int argc, char **argv) { |
| 236 | const char *source_path = NULL; |
| 237 | const char *label = NULL; |
| 238 | uid_t uid = 0; |
| 239 | gid_t gid = 0; |
| 240 | userid_t userid = 0; |
| 241 | bool multi_user = false; |
| 242 | bool full_write = false; |
Rom Lemarchand | 9813914 | 2017-09-15 18:47:50 +0000 | [diff] [blame] | 243 | bool derive_gid = false; |
Jeff Sharkey | e2e3610 | 2018-01-08 11:43:46 -0700 | [diff] [blame] | 244 | bool default_normal = false; |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 245 | bool unshared_obb = false; |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 246 | int i; |
| 247 | struct rlimit rlim; |
| 248 | int fs_version; |
| 249 | |
Jeff Sharkey | e2e3610 | 2018-01-08 11:43:46 -0700 | [diff] [blame] | 250 | setenv("ANDROID_LOG_TAGS", "*:v", 1); |
| 251 | android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM)); |
| 252 | |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 253 | int opt; |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 254 | while ((opt = getopt(argc, argv, "u:g:U:mwGio")) != -1) { |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 255 | switch (opt) { |
| 256 | case 'u': |
| 257 | uid = strtoul(optarg, NULL, 10); |
| 258 | break; |
| 259 | case 'g': |
| 260 | gid = strtoul(optarg, NULL, 10); |
| 261 | break; |
| 262 | case 'U': |
| 263 | userid = strtoul(optarg, NULL, 10); |
| 264 | break; |
| 265 | case 'm': |
| 266 | multi_user = true; |
| 267 | break; |
| 268 | case 'w': |
| 269 | full_write = true; |
| 270 | break; |
Rom Lemarchand | 9813914 | 2017-09-15 18:47:50 +0000 | [diff] [blame] | 271 | case 'G': |
| 272 | derive_gid = true; |
| 273 | break; |
Jeff Sharkey | e2e3610 | 2018-01-08 11:43:46 -0700 | [diff] [blame] | 274 | case 'i': |
| 275 | default_normal = true; |
| 276 | break; |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 277 | case 'o': |
| 278 | unshared_obb = true; |
| 279 | break; |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 280 | case '?': |
| 281 | default: |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 282 | LOG(ERROR) << "Unknown option: '" << opt << "'"; |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 283 | return usage(); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | for (i = optind; i < argc; i++) { |
| 288 | char* arg = argv[i]; |
| 289 | if (!source_path) { |
| 290 | source_path = arg; |
| 291 | } else if (!label) { |
| 292 | label = arg; |
| 293 | } else { |
Jorge Lucangeli Obes | c9e1710 | 2016-07-12 17:05:32 -0400 | [diff] [blame] | 294 | LOG(ERROR) << "too many arguments"; |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 295 | return usage(); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | if (!source_path) { |
Jorge Lucangeli Obes | c9e1710 | 2016-07-12 17:05:32 -0400 | [diff] [blame] | 300 | LOG(ERROR) << "no source path specified"; |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 301 | return usage(); |
| 302 | } |
| 303 | if (!label) { |
Jorge Lucangeli Obes | c9e1710 | 2016-07-12 17:05:32 -0400 | [diff] [blame] | 304 | LOG(ERROR) << "no label specified"; |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 305 | return usage(); |
| 306 | } |
| 307 | if (!uid || !gid) { |
Jorge Lucangeli Obes | c9e1710 | 2016-07-12 17:05:32 -0400 | [diff] [blame] | 308 | LOG(ERROR) << "uid and gid must be nonzero"; |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 309 | return usage(); |
| 310 | } |
| 311 | |
| 312 | rlim.rlim_cur = 8192; |
| 313 | rlim.rlim_max = 8192; |
Christopher Ferris | d6b0d37 | 2016-10-06 12:51:20 -0700 | [diff] [blame] | 314 | if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) { |
Jorge Lucangeli Obes | c9e1710 | 2016-07-12 17:05:32 -0400 | [diff] [blame] | 315 | PLOG(ERROR) << "setting RLIMIT_NOFILE failed"; |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 316 | } |
| 317 | |
Paul Crowley | 26aabfd | 2019-08-16 12:39:17 -0700 | [diff] [blame] | 318 | while ((fs_read_atomic_int("/data/misc/installd/layout_version", &fs_version) == -1) || |
| 319 | (fs_version < 3)) { |
Jorge Lucangeli Obes | c9e1710 | 2016-07-12 17:05:32 -0400 | [diff] [blame] | 320 | LOG(ERROR) << "installd fs upgrade not yet complete; waiting..."; |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 321 | sleep(1); |
| 322 | } |
| 323 | |
Jeff Sharkey | 68e1093 | 2018-01-08 11:22:38 -0700 | [diff] [blame] | 324 | run_sdcardfs(source_path, label, uid, gid, userid, multi_user, full_write, derive_gid, |
Sudheer Shanka | cabc526 | 2019-03-05 14:38:45 -0800 | [diff] [blame] | 325 | default_normal, unshared_obb, !should_use_sdcardfs()); |
Jorge Lucangeli Obes | c255f25 | 2016-07-12 15:13:05 -0400 | [diff] [blame] | 326 | return 1; |
| 327 | } |