blob: 6caa5c00d4d0b413ab4b378a564960e091e7cedc [file] [log] [blame]
San Mehatf1b736b2009-10-10 17:22:08 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Yabin Cuid1104f72015-01-02 13:28:28 -080017#include <dirent.h>
San Mehatf1b736b2009-10-10 17:22:08 -070018#include <errno.h>
San Mehata2677e42009-12-13 10:40:18 -080019#include <fcntl.h>
Kenny Root344ca102012-04-03 17:23:01 -070020#include <fts.h>
Yabin Cuid1104f72015-01-02 13:28:28 -080021#include <mntent.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <sys/ioctl.h>
26#include <sys/mount.h>
San Mehata19b2502010-01-06 10:33:53 -080027#include <sys/stat.h>
28#include <sys/types.h>
Jeff Sharkey66270a22015-06-24 11:49:24 -070029#include <sys/wait.h>
Yabin Cuid1104f72015-01-02 13:28:28 -080030#include <unistd.h>
San Mehata19b2502010-01-06 10:33:53 -080031
San Mehata2677e42009-12-13 10:40:18 -080032#include <linux/kdev_t.h>
San Mehatf1b736b2009-10-10 17:22:08 -070033
34#define LOG_TAG "Vold"
35
Kenny Root7b18a7b2010-03-15 13:13:41 -070036#include <openssl/md5.h>
37
Jeff Sharkey36801cc2015-03-13 16:09:20 -070038#include <base/logging.h>
39#include <base/stringprintf.h>
Jeff Sharkey71ebe152013-09-17 17:24:38 -070040#include <cutils/fs.h>
San Mehatf1b736b2009-10-10 17:22:08 -070041#include <cutils/log.h>
42
Robert Craigb9e3ba52014-02-04 10:53:00 -050043#include <selinux/android.h>
44
San Mehatfd7f5872009-10-12 11:32:47 -070045#include <sysutils/NetlinkEvent.h>
46
Kenny Root344ca102012-04-03 17:23:01 -070047#include <private/android_filesystem_config.h>
48
Jeff Sharkey5a6bfca2015-05-14 20:33:55 -070049#include "Benchmark.h"
Jeff Sharkey36801cc2015-03-13 16:09:20 -070050#include "EmulatedVolume.h"
San Mehatf1b736b2009-10-10 17:22:08 -070051#include "VolumeManager.h"
Jeff Sharkey36801cc2015-03-13 16:09:20 -070052#include "NetlinkManager.h"
San Mehata2677e42009-12-13 10:40:18 -080053#include "ResponseCode.h"
San Mehata19b2502010-01-06 10:33:53 -080054#include "Loop.h"
Jeff Sharkeyd0640f62015-05-21 22:35:42 -070055#include "fs/Ext4.h"
56#include "fs/Vfat.h"
Jeff Sharkey36801cc2015-03-13 16:09:20 -070057#include "Utils.h"
San Mehatb78a32c2010-01-10 13:02:12 -080058#include "Devmapper.h"
San Mehat586536c2010-02-16 17:12:00 -080059#include "Process.h"
San Mehatfcf24fe2010-03-03 12:37:32 -080060#include "Asec.h"
Hiroaki Miyazawa14eab552015-02-04 13:29:15 +090061#include "VoldUtil.h"
Ken Sumrall29d8da82011-05-18 17:20:07 -070062#include "cryptfs.h"
Jeff Sharkeybc40cc82015-06-18 14:25:08 -070063#include "fstrim.h"
San Mehat23969932010-01-09 07:08:06 -080064
Mike Lockwood97f2fc12011-06-07 10:51:38 -070065#define MASS_STORAGE_FILE_PATH "/sys/class/android_usb/android0/f_mass_storage/lun/file"
66
Daniel Rosenberg6a74dca2014-05-23 13:47:00 -070067#define ROUND_UP_POWER_OF_2(number, po2) (((!!(number & ((1U << po2) - 1))) << po2)\
68 + (number & (~((1U << po2) - 1))))
69
Jeff Sharkey36801cc2015-03-13 16:09:20 -070070using android::base::StringPrintf;
71
Jeff Sharkey9f18fe72015-04-01 23:32:18 -070072/*
73 * Path to external storage where *only* root can access ASEC image files
74 */
75const char *VolumeManager::SEC_ASECDIR_EXT = "/mnt/secure/asec";
76
77/*
78 * Path to internal storage where *only* root can access ASEC image files
79 */
80const char *VolumeManager::SEC_ASECDIR_INT = "/data/app-asec";
81
82/*
83 * Path to where secure containers are mounted
84 */
85const char *VolumeManager::ASECDIR = "/mnt/asec";
86
87/*
88 * Path to where OBBs are mounted
89 */
90const char *VolumeManager::LOOPDIR = "/mnt/obb";
91
Jeff Sharkey36801cc2015-03-13 16:09:20 -070092static const char* kUserMountPath = "/mnt/user";
93
Jeff Sharkey36801cc2015-03-13 16:09:20 -070094static const unsigned int kMajorBlockMmc = 179;
95
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -070096/* writes superblock at end of file or device given by name */
97static int writeSuperBlock(const char* name, struct asec_superblock *sb, unsigned int numImgSectors) {
Jeff Sharkeyce6a9132015-04-08 21:07:21 -070098 int sbfd = open(name, O_RDWR | O_CLOEXEC);
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -070099 if (sbfd < 0) {
100 SLOGE("Failed to open %s for superblock write (%s)", name, strerror(errno));
101 return -1;
102 }
103
104 if (lseek(sbfd, (numImgSectors * 512), SEEK_SET) < 0) {
105 SLOGE("Failed to lseek for superblock (%s)", strerror(errno));
106 close(sbfd);
107 return -1;
108 }
109
110 if (write(sbfd, sb, sizeof(struct asec_superblock)) != sizeof(struct asec_superblock)) {
111 SLOGE("Failed to write superblock (%s)", strerror(errno));
112 close(sbfd);
113 return -1;
114 }
115 close(sbfd);
116 return 0;
117}
118
119static int adjustSectorNumExt4(unsigned numSectors) {
Daniel Rosenberge9196fe2014-06-10 17:16:03 -0700120 // Ext4 started to reserve 2% or 4096 clusters, whichever is smaller for
121 // preventing costly operations or unexpected ENOSPC error.
122 // Ext4::format() uses default block size without clustering.
123 unsigned clusterSectors = 4096 / 512;
124 unsigned reservedSectors = (numSectors * 2)/100 + (numSectors % 50 > 0);
125 numSectors += reservedSectors > (4096 * clusterSectors) ? (4096 * clusterSectors) : reservedSectors;
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -0700126 return ROUND_UP_POWER_OF_2(numSectors, 3);
127}
128
129static int adjustSectorNumFAT(unsigned numSectors) {
130 /*
131 * Add some headroom
132 */
133 unsigned fatSize = (((numSectors * 4) / 512) + 1) * 2;
134 numSectors += fatSize + 2;
135 /*
136 * FAT is aligned to 32 kb with 512b sectors.
137 */
138 return ROUND_UP_POWER_OF_2(numSectors, 6);
139}
140
141static int setupLoopDevice(char* buffer, size_t len, const char* asecFileName, const char* idHash, bool debug) {
142 if (Loop::lookupActive(idHash, buffer, len)) {
143 if (Loop::create(idHash, asecFileName, buffer, len)) {
144 SLOGE("ASEC loop device creation failed for %s (%s)", asecFileName, strerror(errno));
145 return -1;
146 }
147 if (debug) {
148 SLOGD("New loop device created at %s", buffer);
149 }
150 } else {
151 if (debug) {
152 SLOGD("Found active loopback for %s at %s", asecFileName, buffer);
153 }
154 }
155 return 0;
156}
157
158static int setupDevMapperDevice(char* buffer, size_t len, const char* loopDevice, const char* asecFileName, const char* key, const char* idHash , int numImgSectors, bool* createdDMDevice, bool debug) {
159 if (strcmp(key, "none")) {
160 if (Devmapper::lookupActive(idHash, buffer, len)) {
161 if (Devmapper::create(idHash, loopDevice, key, numImgSectors,
162 buffer, len)) {
163 SLOGE("ASEC device mapping failed for %s (%s)", asecFileName, strerror(errno));
164 return -1;
165 }
166 if (debug) {
167 SLOGD("New devmapper instance created at %s", buffer);
168 }
169 } else {
170 if (debug) {
171 SLOGD("Found active devmapper for %s at %s", asecFileName, buffer);
172 }
173 }
174 *createdDMDevice = true;
175 } else {
176 strcpy(buffer, loopDevice);
177 *createdDMDevice = false;
178 }
179 return 0;
180}
181
182static void waitForDevMapper(const char *dmDevice) {
183 /*
184 * Wait for the device mapper node to be created. Sometimes it takes a
185 * while. Wait for up to 1 second. We could also inspect incoming uevents,
186 * but that would take more effort.
187 */
188 int tries = 25;
189 while (tries--) {
190 if (!access(dmDevice, F_OK) || errno != ENOENT) {
191 break;
192 }
193 usleep(40 * 1000);
194 }
195}
196
San Mehatf1b736b2009-10-10 17:22:08 -0700197VolumeManager *VolumeManager::sInstance = NULL;
198
199VolumeManager *VolumeManager::Instance() {
200 if (!sInstance)
201 sInstance = new VolumeManager();
202 return sInstance;
203}
204
205VolumeManager::VolumeManager() {
San Mehatd9a4e352010-03-12 13:32:47 -0800206 mDebug = false;
San Mehat88705162010-01-15 09:26:28 -0800207 mActiveContainers = new AsecIdCollection();
San Mehatf1b736b2009-10-10 17:22:08 -0700208 mBroadcaster = NULL;
Mike Lockwooda28056b2010-10-28 15:21:24 -0400209 mUmsSharingCount = 0;
210 mSavedDirtyRatio = -1;
211 // set dirty ratio to 0 when UMS is active
212 mUmsDirtyRatio = 0;
San Mehatf1b736b2009-10-10 17:22:08 -0700213}
214
215VolumeManager::~VolumeManager() {
San Mehat88705162010-01-15 09:26:28 -0800216 delete mActiveContainers;
San Mehatf1b736b2009-10-10 17:22:08 -0700217}
218
Kenny Root7b18a7b2010-03-15 13:13:41 -0700219char *VolumeManager::asecHash(const char *id, char *buffer, size_t len) {
Kenny Rootacc9e7d2010-06-18 19:06:50 -0700220 static const char* digits = "0123456789abcdef";
221
Kenny Root7b18a7b2010-03-15 13:13:41 -0700222 unsigned char sig[MD5_DIGEST_LENGTH];
223
Kenny Rootacc9e7d2010-06-18 19:06:50 -0700224 if (buffer == NULL) {
225 SLOGE("Destination buffer is NULL");
226 errno = ESPIPE;
227 return NULL;
228 } else if (id == NULL) {
229 SLOGE("Source buffer is NULL");
230 errno = ESPIPE;
231 return NULL;
232 } else if (len < MD5_ASCII_LENGTH_PLUS_NULL) {
Colin Cross59846b62014-02-06 20:34:29 -0800233 SLOGE("Target hash buffer size < %d bytes (%zu)",
Kenny Rootacc9e7d2010-06-18 19:06:50 -0700234 MD5_ASCII_LENGTH_PLUS_NULL, len);
San Mehatd9a4e352010-03-12 13:32:47 -0800235 errno = ESPIPE;
236 return NULL;
237 }
Kenny Root7b18a7b2010-03-15 13:13:41 -0700238
239 MD5(reinterpret_cast<const unsigned char*>(id), strlen(id), sig);
San Mehatd9a4e352010-03-12 13:32:47 -0800240
Kenny Rootacc9e7d2010-06-18 19:06:50 -0700241 char *p = buffer;
Kenny Root7b18a7b2010-03-15 13:13:41 -0700242 for (int i = 0; i < MD5_DIGEST_LENGTH; i++) {
Kenny Rootacc9e7d2010-06-18 19:06:50 -0700243 *p++ = digits[sig[i] >> 4];
244 *p++ = digits[sig[i] & 0x0F];
San Mehatd9a4e352010-03-12 13:32:47 -0800245 }
Kenny Rootacc9e7d2010-06-18 19:06:50 -0700246 *p = '\0';
San Mehatd9a4e352010-03-12 13:32:47 -0800247
248 return buffer;
249}
250
Jeff Sharkeyf1b996d2015-04-17 17:35:20 -0700251int VolumeManager::setDebug(bool enable) {
San Mehatd9a4e352010-03-12 13:32:47 -0800252 mDebug = enable;
Jeff Sharkeyf1b996d2015-04-17 17:35:20 -0700253 return 0;
San Mehatd9a4e352010-03-12 13:32:47 -0800254}
255
San Mehatf1b736b2009-10-10 17:22:08 -0700256int VolumeManager::start() {
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700257 // Always start from a clean slate by unmounting everything in
258 // directories that we own, in case we crashed.
Jeff Sharkey9c484982015-03-31 10:35:33 -0700259 unmountAll();
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700260
261 // Assume that we always have an emulated volume on internal
262 // storage; the framework will decide if it should be mounted.
Jeff Sharkeyc8e04c52015-04-21 12:14:17 -0700263 CHECK(mInternalEmulated == nullptr);
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700264 mInternalEmulated = std::shared_ptr<android::vold::VolumeBase>(
Jeff Sharkey3161fb32015-04-12 16:03:33 -0700265 new android::vold::EmulatedVolume("/data/media"));
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700266 mInternalEmulated->create();
267
San Mehatf1b736b2009-10-10 17:22:08 -0700268 return 0;
269}
270
271int VolumeManager::stop() {
Jeff Sharkeyc8e04c52015-04-21 12:14:17 -0700272 CHECK(mInternalEmulated != nullptr);
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700273 mInternalEmulated->destroy();
274 mInternalEmulated = nullptr;
San Mehatf1b736b2009-10-10 17:22:08 -0700275 return 0;
276}
277
San Mehatfd7f5872009-10-12 11:32:47 -0700278void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
Jeff Sharkeyc8e04c52015-04-21 12:14:17 -0700279 std::lock_guard<std::mutex> lock(mLock);
280
Jeff Sharkeyf1b996d2015-04-17 17:35:20 -0700281 if (mDebug) {
282 LOG(VERBOSE) << "----------------";
283 LOG(VERBOSE) << "handleBlockEvent with action " << (int) evt->getAction();
284 evt->dump();
285 }
San Mehatf1b736b2009-10-10 17:22:08 -0700286
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700287 std::string eventPath(evt->findParam("DEVPATH"));
288 std::string devType(evt->findParam("DEVTYPE"));
289
290 if (devType != "disk") return;
291
292 int major = atoi(evt->findParam("MAJOR"));
293 int minor = atoi(evt->findParam("MINOR"));
294 dev_t device = makedev(major, minor);
295
296 switch (evt->getAction()) {
297 case NetlinkEvent::Action::kAdd: {
298 for (auto source : mDiskSources) {
299 if (source->matches(eventPath)) {
300 // For now, assume that MMC devices are SD, and that
301 // everything else is USB
302 int flags = source->getFlags();
303 if (major == kMajorBlockMmc) {
304 flags |= android::vold::Disk::Flags::kSd;
305 } else {
306 flags |= android::vold::Disk::Flags::kUsb;
307 }
308
309 auto disk = new android::vold::Disk(eventPath, device,
310 source->getNickname(), flags);
311 disk->create();
312 mDisks.push_back(std::shared_ptr<android::vold::Disk>(disk));
313 break;
314 }
315 }
316 break;
317 }
318 case NetlinkEvent::Action::kChange: {
Jeff Sharkey7d9d0112015-04-14 23:14:23 -0700319 LOG(DEBUG) << "Disk at " << major << ":" << minor << " changed";
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700320 for (auto disk : mDisks) {
321 if (disk->getDevice() == device) {
322 disk->readMetadata();
323 disk->readPartitions();
324 }
325 }
326 break;
327 }
328 case NetlinkEvent::Action::kRemove: {
329 auto i = mDisks.begin();
330 while (i != mDisks.end()) {
331 if ((*i)->getDevice() == device) {
332 (*i)->destroy();
333 i = mDisks.erase(i);
334 } else {
335 ++i;
336 }
337 }
338 break;
339 }
340 default: {
341 LOG(WARNING) << "Unexpected block event action " << (int) evt->getAction();
342 break;
343 }
344 }
345}
346
347void VolumeManager::addDiskSource(const std::shared_ptr<DiskSource>& diskSource) {
348 mDiskSources.push_back(diskSource);
349}
350
351std::shared_ptr<android::vold::Disk> VolumeManager::findDisk(const std::string& id) {
352 for (auto disk : mDisks) {
353 if (disk->getId() == id) {
354 return disk;
San Mehatf1b736b2009-10-10 17:22:08 -0700355 }
356 }
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700357 return nullptr;
358}
San Mehatf1b736b2009-10-10 17:22:08 -0700359
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700360std::shared_ptr<android::vold::VolumeBase> VolumeManager::findVolume(const std::string& id) {
361 if (mInternalEmulated->getId() == id) {
362 return mInternalEmulated;
San Mehatf1b736b2009-10-10 17:22:08 -0700363 }
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700364 for (auto disk : mDisks) {
365 auto vol = disk->findVolume(id);
366 if (vol != nullptr) {
367 return vol;
368 }
369 }
370 return nullptr;
371}
372
Jeff Sharkey5a6bfca2015-05-14 20:33:55 -0700373nsecs_t VolumeManager::benchmarkVolume(const std::string& id) {
374 std::string path;
375 std::string sysPath;
376 auto vol = findVolume(id);
377 if (vol != nullptr) {
378 if (vol->getState() == android::vold::VolumeBase::State::kMounted) {
379 path = vol->getPath();
380 auto disk = findDisk(vol->getDiskId());
381 if (disk != nullptr) {
382 sysPath = disk->getSysPath();
383 }
384 }
385 } else {
386 path = "/data";
387 }
388
389 if (path.empty()) {
390 LOG(WARNING) << "Failed to find volume for " << id;
391 return -1;
392 }
393
394 path += "/misc";
395 if (android::vold::PrepareDir(path, 01771, AID_SYSTEM, AID_MISC)) {
396 return -1;
397 }
398 path += "/vold";
399 if (android::vold::PrepareDir(path, 0700, AID_ROOT, AID_ROOT)) {
400 return -1;
401 }
402 path += "/bench";
403 if (android::vold::PrepareDir(path, 0700, AID_ROOT, AID_ROOT)) {
404 return -1;
405 }
406
407 return android::vold::Benchmark(path, sysPath);
408}
409
Jeff Sharkeybc40cc82015-06-18 14:25:08 -0700410int VolumeManager::forgetPartition(const std::string& partGuid) {
411 std::string normalizedGuid;
412 if (android::vold::NormalizeHex(partGuid, normalizedGuid)) {
413 LOG(WARNING) << "Invalid GUID " << partGuid;
414 return -1;
415 }
416
417 std::string keyPath = android::vold::BuildKeyPath(normalizedGuid);
418 if (unlink(keyPath.c_str()) != 0) {
419 LOG(ERROR) << "Failed to unlink " << keyPath;
420 return -1;
421 }
422
423 return 0;
424}
425
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700426int VolumeManager::linkPrimary(userid_t userId) {
427 std::string source(mPrimary->getPath());
428 if (mPrimary->getType() == android::vold::VolumeBase::Type::kEmulated) {
429 source = StringPrintf("%s/%d", source.c_str(), userId);
430 }
431
432 std::string target(StringPrintf("/mnt/user/%d/primary", userId));
433 if (TEMP_FAILURE_RETRY(unlink(target.c_str()))) {
434 if (errno != ENOENT) {
435 SLOGW("Failed to unlink %s: %s", target.c_str(), strerror(errno));
436 }
437 }
Jeff Sharkey1bfb3752015-04-29 15:22:23 -0700438 LOG(DEBUG) << "Linking " << source << " to " << target;
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700439 if (TEMP_FAILURE_RETRY(symlink(source.c_str(), target.c_str()))) {
440 SLOGW("Failed to link %s to %s: %s", source.c_str(), target.c_str(),
441 strerror(errno));
442 return -errno;
443 }
444 return 0;
445}
446
Jeff Sharkeybd3038d2015-06-10 09:42:01 -0700447int VolumeManager::onUserAdded(userid_t userId, int userSerialNumber) {
448 mAddedUsers[userId] = userSerialNumber;
449 return 0;
450}
451
452int VolumeManager::onUserRemoved(userid_t userId) {
453 mAddedUsers.erase(userId);
454 return 0;
455}
456
457int VolumeManager::onUserStarted(userid_t userId) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700458 // Note that sometimes the system will spin up processes from Zygote
459 // before actually starting the user, so we're okay if Zygote
460 // already created this directory.
461 std::string path(StringPrintf("%s/%d", kUserMountPath, userId));
462 fs_prepare_dir(path.c_str(), 0755, AID_ROOT, AID_ROOT);
463
Jeff Sharkeybd3038d2015-06-10 09:42:01 -0700464 mStartedUsers.insert(userId);
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700465 if (mPrimary) {
466 linkPrimary(userId);
467 }
468 return 0;
469}
470
Jeff Sharkeybd3038d2015-06-10 09:42:01 -0700471int VolumeManager::onUserStopped(userid_t userId) {
472 mStartedUsers.erase(userId);
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700473 return 0;
474}
475
476int VolumeManager::setPrimary(const std::shared_ptr<android::vold::VolumeBase>& vol) {
477 mPrimary = vol;
Jeff Sharkeybd3038d2015-06-10 09:42:01 -0700478 for (userid_t userId : mStartedUsers) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700479 linkPrimary(userId);
480 }
481 return 0;
482}
483
Jeff Sharkey66270a22015-06-24 11:49:24 -0700484int VolumeManager::remountUid(uid_t uid, const std::string& mode) {
485 LOG(DEBUG) << "Remounting " << uid << " as mode " << mode;
486
487 DIR* dir;
488 struct dirent* de;
489 char rootName[PATH_MAX];
490 char pidName[PATH_MAX];
491 int pidFd;
492 int nsFd;
493 struct stat sb;
494 pid_t child;
495
496 if (!(dir = opendir("/proc"))) {
497 PLOG(ERROR) << "Failed to opendir";
498 return -1;
499 }
500
501 // Figure out root namespace to compare against below
502 if (readlinkat(dirfd(dir), "1/ns/mnt", rootName, PATH_MAX) == -1) {
503 PLOG(ERROR) << "Failed to readlink";
504 closedir(dir);
505 return -1;
506 }
507
508 // Poke through all running PIDs look for apps running as UID
509 while ((de = readdir(dir))) {
510 pidFd = -1;
511 nsFd = -1;
512
513 pidFd = openat(dirfd(dir), de->d_name, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
514 if (pidFd < 0) {
515 goto next;
516 }
517 if (fstat(pidFd, &sb) != 0) {
518 PLOG(WARNING) << "Failed to stat " << de->d_name;
519 goto next;
520 }
521 if (sb.st_uid != uid) {
522 goto next;
523 }
524
525 // Matches so far, but refuse to touch if in root namespace
526 LOG(DEBUG) << "Found matching PID " << de->d_name;
527 if (readlinkat(pidFd, "ns/mnt", pidName, PATH_MAX) == -1) {
528 PLOG(WARNING) << "Failed to read namespace for " << de->d_name;
529 goto next;
530 }
531 if (!strcmp(rootName, pidName)) {
532 LOG(WARNING) << "Skipping due to root namespace";
533 goto next;
534 }
535
536 // We purposefully leave the namespace open across the fork
537 nsFd = openat(pidFd, "ns/mnt", O_RDONLY);
538 if (nsFd < 0) {
539 PLOG(WARNING) << "Failed to open namespace";
540 goto next;
541 }
542
543 if (!(child = fork())) {
544 if (setns(nsFd, CLONE_NEWNS) != 0) {
545 PLOG(ERROR) << "Failed to setns";
546 _exit(1);
547 }
548
549 // Unmount current view and replace with requested view
550 umount2("/storage", MNT_FORCE);
551
552 std::string storageSource;
553 if (mode == "default") {
554 storageSource = "/mnt/runtime_default";
555 } else if (mode == "read") {
556 storageSource = "/mnt/runtime_read";
557 } else if (mode == "write") {
558 storageSource = "/mnt/runtime_write";
559 } else {
560 // Sane default of no storage visible
561 _exit(0);
562 }
563 if (TEMP_FAILURE_RETRY(mount(storageSource.c_str(), "/storage",
564 NULL, MS_BIND | MS_REC | MS_SLAVE, NULL)) == -1) {
565 PLOG(WARNING) << "Failed to mount " << storageSource;
566 return false;
567 }
568 _exit(0);
569 }
570
571 if (child == -1) {
572 PLOG(ERROR) << "Failed to fork";
573 goto next;
574 } else {
575 TEMP_FAILURE_RETRY(waitpid(child, nullptr, 0));
576 }
577
578next:
579 close(nsFd);
580 close(pidFd);
581 }
582 closedir(dir);
583 return 0;
584}
585
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700586int VolumeManager::reset() {
587 // Tear down all existing disks/volumes and start from a blank slate so
588 // newly connected framework hears all events.
589 mInternalEmulated->destroy();
590 mInternalEmulated->create();
591 for (auto disk : mDisks) {
592 disk->destroy();
593 disk->create();
594 }
Jeff Sharkeybd3038d2015-06-10 09:42:01 -0700595 mAddedUsers.clear();
596 mStartedUsers.clear();
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700597 return 0;
598}
599
600int VolumeManager::shutdown() {
Jeff Sharkey9c484982015-03-31 10:35:33 -0700601 mInternalEmulated->destroy();
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700602 for (auto disk : mDisks) {
603 disk->destroy();
604 }
605 mDisks.clear();
606 return 0;
San Mehatf1b736b2009-10-10 17:22:08 -0700607}
608
Jeff Sharkey9c484982015-03-31 10:35:33 -0700609int VolumeManager::unmountAll() {
Jeff Sharkeyc8e04c52015-04-21 12:14:17 -0700610 std::lock_guard<std::mutex> lock(mLock);
611
Jeff Sharkey9c484982015-03-31 10:35:33 -0700612 // First, try gracefully unmounting all known devices
613 if (mInternalEmulated != nullptr) {
614 mInternalEmulated->unmount();
615 }
616 for (auto disk : mDisks) {
617 disk->unmountAll();
618 }
619
620 // Worst case we might have some stale mounts lurking around, so
621 // force unmount those just to be safe.
622 FILE* fp = setmntent("/proc/mounts", "r");
623 if (fp == NULL) {
624 SLOGE("Error opening /proc/mounts: %s", strerror(errno));
625 return -errno;
626 }
627
628 // Some volumes can be stacked on each other, so force unmount in
629 // reverse order to give us the best chance of success.
630 std::list<std::string> toUnmount;
631 mntent* mentry;
632 while ((mentry = getmntent(fp)) != NULL) {
633 if (strncmp(mentry->mnt_dir, "/mnt/", 5) == 0
634 || strncmp(mentry->mnt_dir, "/storage/", 9) == 0) {
635 toUnmount.push_front(std::string(mentry->mnt_dir));
636 }
637 }
638 endmntent(fp);
639
640 for (auto path : toUnmount) {
641 SLOGW("Tearing down stale mount %s", path.c_str());
642 android::vold::ForceUnmount(path);
643 }
644
645 return 0;
646}
647
Kenny Root508c0e12010-07-12 09:59:49 -0700648int VolumeManager::getObbMountPath(const char *sourceFile, char *mountPath, int mountPathLen) {
649 char idHash[33];
650 if (!asecHash(sourceFile, idHash, sizeof(idHash))) {
651 SLOGE("Hash of '%s' failed (%s)", sourceFile, strerror(errno));
652 return -1;
653 }
654
655 memset(mountPath, 0, mountPathLen);
Jeff Sharkey9f18fe72015-04-01 23:32:18 -0700656 int written = snprintf(mountPath, mountPathLen, "%s/%s", VolumeManager::LOOPDIR, idHash);
rpcraigd1c226f2012-10-09 06:58:16 -0400657 if ((written < 0) || (written >= mountPathLen)) {
658 errno = EINVAL;
659 return -1;
660 }
Kenny Root508c0e12010-07-12 09:59:49 -0700661
662 if (access(mountPath, F_OK)) {
663 errno = ENOENT;
664 return -1;
665 }
666
667 return 0;
668}
669
San Mehata19b2502010-01-06 10:33:53 -0800670int VolumeManager::getAsecMountPath(const char *id, char *buffer, int maxlen) {
San Mehat88ac2c02010-03-23 11:15:58 -0700671 char asecFileName[255];
Kenny Root344ca102012-04-03 17:23:01 -0700672
Nick Kralevich0de7c612014-01-27 14:58:06 -0800673 if (!isLegalAsecId(id)) {
674 SLOGE("getAsecMountPath: Invalid asec id \"%s\"", id);
675 errno = EINVAL;
676 return -1;
677 }
678
Kenny Root344ca102012-04-03 17:23:01 -0700679 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
680 SLOGE("Couldn't find ASEC %s", id);
681 return -1;
682 }
San Mehat88ac2c02010-03-23 11:15:58 -0700683
684 memset(buffer, 0, maxlen);
685 if (access(asecFileName, F_OK)) {
686 errno = ENOENT;
687 return -1;
688 }
San Mehata19b2502010-01-06 10:33:53 -0800689
Jeff Sharkey9f18fe72015-04-01 23:32:18 -0700690 int written = snprintf(buffer, maxlen, "%s/%s", VolumeManager::ASECDIR, id);
rpcraigd1c226f2012-10-09 06:58:16 -0400691 if ((written < 0) || (written >= maxlen)) {
692 SLOGE("getAsecMountPath failed for %s: couldn't construct path in buffer", id);
693 errno = EINVAL;
694 return -1;
695 }
696
San Mehata19b2502010-01-06 10:33:53 -0800697 return 0;
698}
699
Dianne Hackborn736910c2011-06-27 13:37:07 -0700700int VolumeManager::getAsecFilesystemPath(const char *id, char *buffer, int maxlen) {
701 char asecFileName[255];
Kenny Root344ca102012-04-03 17:23:01 -0700702
Nick Kralevich0de7c612014-01-27 14:58:06 -0800703 if (!isLegalAsecId(id)) {
704 SLOGE("getAsecFilesystemPath: Invalid asec id \"%s\"", id);
705 errno = EINVAL;
706 return -1;
707 }
708
Kenny Root344ca102012-04-03 17:23:01 -0700709 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
710 SLOGE("Couldn't find ASEC %s", id);
711 return -1;
712 }
Dianne Hackborn736910c2011-06-27 13:37:07 -0700713
714 memset(buffer, 0, maxlen);
715 if (access(asecFileName, F_OK)) {
716 errno = ENOENT;
717 return -1;
718 }
719
rpcraigd1c226f2012-10-09 06:58:16 -0400720 int written = snprintf(buffer, maxlen, "%s", asecFileName);
721 if ((written < 0) || (written >= maxlen)) {
722 errno = EINVAL;
723 return -1;
724 }
725
Dianne Hackborn736910c2011-06-27 13:37:07 -0700726 return 0;
727}
728
Kenny Root344ca102012-04-03 17:23:01 -0700729int VolumeManager::createAsec(const char *id, unsigned int numSectors, const char *fstype,
730 const char *key, const int ownerUid, bool isExternal) {
San Mehatfcf24fe2010-03-03 12:37:32 -0800731 struct asec_superblock sb;
732 memset(&sb, 0, sizeof(sb));
733
Nick Kralevich0de7c612014-01-27 14:58:06 -0800734 if (!isLegalAsecId(id)) {
735 SLOGE("createAsec: Invalid asec id \"%s\"", id);
736 errno = EINVAL;
737 return -1;
738 }
739
Kenny Root344ca102012-04-03 17:23:01 -0700740 const bool wantFilesystem = strcmp(fstype, "none");
741 bool usingExt4 = false;
742 if (wantFilesystem) {
743 usingExt4 = !strcmp(fstype, "ext4");
744 if (usingExt4) {
745 sb.c_opts |= ASEC_SB_C_OPTS_EXT4;
746 } else if (strcmp(fstype, "fat")) {
747 SLOGE("Invalid filesystem type %s", fstype);
748 errno = EINVAL;
749 return -1;
750 }
751 }
752
San Mehatfcf24fe2010-03-03 12:37:32 -0800753 sb.magic = ASEC_SB_MAGIC;
754 sb.ver = ASEC_SB_VER;
San Mehata19b2502010-01-06 10:33:53 -0800755
San Mehatd31e3802010-02-18 08:37:45 -0800756 if (numSectors < ((1024*1024)/512)) {
San Mehat97ac40e2010-03-24 10:24:19 -0700757 SLOGE("Invalid container size specified (%d sectors)", numSectors);
San Mehatd31e3802010-02-18 08:37:45 -0800758 errno = EINVAL;
759 return -1;
760 }
761
San Mehata19b2502010-01-06 10:33:53 -0800762 char asecFileName[255];
Kenny Root344ca102012-04-03 17:23:01 -0700763
764 if (!findAsec(id, asecFileName, sizeof(asecFileName))) {
765 SLOGE("ASEC file '%s' currently exists - destroy it first! (%s)",
766 asecFileName, strerror(errno));
767 errno = EADDRINUSE;
768 return -1;
769 }
770
Jeff Sharkey9f18fe72015-04-01 23:32:18 -0700771 const char *asecDir = isExternal ? VolumeManager::SEC_ASECDIR_EXT : VolumeManager::SEC_ASECDIR_INT;
Kenny Root344ca102012-04-03 17:23:01 -0700772
rpcraigd1c226f2012-10-09 06:58:16 -0400773 int written = snprintf(asecFileName, sizeof(asecFileName), "%s/%s.asec", asecDir, id);
774 if ((written < 0) || (size_t(written) >= sizeof(asecFileName))) {
775 errno = EINVAL;
776 return -1;
777 }
San Mehata19b2502010-01-06 10:33:53 -0800778
779 if (!access(asecFileName, F_OK)) {
San Mehat97ac40e2010-03-24 10:24:19 -0700780 SLOGE("ASEC file '%s' currently exists - destroy it first! (%s)",
Kenny Root344ca102012-04-03 17:23:01 -0700781 asecFileName, strerror(errno));
San Mehata19b2502010-01-06 10:33:53 -0800782 errno = EADDRINUSE;
783 return -1;
784 }
785
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -0700786 unsigned numImgSectors;
Daniel Rosenberg6a74dca2014-05-23 13:47:00 -0700787 if (usingExt4)
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -0700788 numImgSectors = adjustSectorNumExt4(numSectors);
Daniel Rosenberg6a74dca2014-05-23 13:47:00 -0700789 else
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -0700790 numImgSectors = adjustSectorNumFAT(numSectors);
San Mehatfcf24fe2010-03-03 12:37:32 -0800791
792 // Add +1 for our superblock which is at the end
793 if (Loop::createImageFile(asecFileName, numImgSectors + 1)) {
San Mehat97ac40e2010-03-24 10:24:19 -0700794 SLOGE("ASEC image file creation failed (%s)", strerror(errno));
San Mehata19b2502010-01-06 10:33:53 -0800795 return -1;
796 }
797
San Mehatd9a4e352010-03-12 13:32:47 -0800798 char idHash[33];
799 if (!asecHash(id, idHash, sizeof(idHash))) {
San Mehat97ac40e2010-03-24 10:24:19 -0700800 SLOGE("Hash of '%s' failed (%s)", id, strerror(errno));
San Mehatd9a4e352010-03-12 13:32:47 -0800801 unlink(asecFileName);
802 return -1;
803 }
804
San Mehata19b2502010-01-06 10:33:53 -0800805 char loopDevice[255];
San Mehatd9a4e352010-03-12 13:32:47 -0800806 if (Loop::create(idHash, asecFileName, loopDevice, sizeof(loopDevice))) {
San Mehat97ac40e2010-03-24 10:24:19 -0700807 SLOGE("ASEC loop device creation failed (%s)", strerror(errno));
San Mehata19b2502010-01-06 10:33:53 -0800808 unlink(asecFileName);
809 return -1;
810 }
811
San Mehatb78a32c2010-01-10 13:02:12 -0800812 char dmDevice[255];
813 bool cleanupDm = false;
San Mehata19b2502010-01-06 10:33:53 -0800814
San Mehatb78a32c2010-01-10 13:02:12 -0800815 if (strcmp(key, "none")) {
San Mehatfcf24fe2010-03-03 12:37:32 -0800816 // XXX: This is all we support for now
817 sb.c_cipher = ASEC_SB_C_CIPHER_TWOFISH;
San Mehatd9a4e352010-03-12 13:32:47 -0800818 if (Devmapper::create(idHash, loopDevice, key, numImgSectors, dmDevice,
San Mehatb78a32c2010-01-10 13:02:12 -0800819 sizeof(dmDevice))) {
San Mehat97ac40e2010-03-24 10:24:19 -0700820 SLOGE("ASEC device mapping failed (%s)", strerror(errno));
San Mehatb78a32c2010-01-10 13:02:12 -0800821 Loop::destroyByDevice(loopDevice);
822 unlink(asecFileName);
823 return -1;
824 }
825 cleanupDm = true;
826 } else {
San Mehatfcf24fe2010-03-03 12:37:32 -0800827 sb.c_cipher = ASEC_SB_C_CIPHER_NONE;
San Mehatb78a32c2010-01-10 13:02:12 -0800828 strcpy(dmDevice, loopDevice);
829 }
830
San Mehatfcf24fe2010-03-03 12:37:32 -0800831 /*
832 * Drop down the superblock at the end of the file
833 */
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -0700834 if (writeSuperBlock(loopDevice, &sb, numImgSectors)) {
San Mehatfcf24fe2010-03-03 12:37:32 -0800835 if (cleanupDm) {
San Mehatd9a4e352010-03-12 13:32:47 -0800836 Devmapper::destroy(idHash);
San Mehatfcf24fe2010-03-03 12:37:32 -0800837 }
838 Loop::destroyByDevice(loopDevice);
839 unlink(asecFileName);
840 return -1;
841 }
842
Kenny Root344ca102012-04-03 17:23:01 -0700843 if (wantFilesystem) {
844 int formatStatus;
rpcraiga54e13a2012-09-21 14:17:08 -0400845 char mountPoint[255];
846
Jeff Sharkey9f18fe72015-04-01 23:32:18 -0700847 int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
rpcraigd1c226f2012-10-09 06:58:16 -0400848 if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
849 SLOGE("ASEC fs format failed: couldn't construct mountPoint");
850 if (cleanupDm) {
851 Devmapper::destroy(idHash);
852 }
853 Loop::destroyByDevice(loopDevice);
854 unlink(asecFileName);
855 return -1;
856 }
rpcraiga54e13a2012-09-21 14:17:08 -0400857
Kenny Root344ca102012-04-03 17:23:01 -0700858 if (usingExt4) {
Jeff Sharkeyd0640f62015-05-21 22:35:42 -0700859 formatStatus = android::vold::ext4::Format(dmDevice, numImgSectors, mountPoint);
Kenny Root344ca102012-04-03 17:23:01 -0700860 } else {
Jeff Sharkeyd0640f62015-05-21 22:35:42 -0700861 formatStatus = android::vold::vfat::Format(dmDevice, numImgSectors);
San Mehatb78a32c2010-01-10 13:02:12 -0800862 }
San Mehata19b2502010-01-06 10:33:53 -0800863
Kenny Root344ca102012-04-03 17:23:01 -0700864 if (formatStatus < 0) {
865 SLOGE("ASEC fs format failed (%s)", strerror(errno));
San Mehatb78a32c2010-01-10 13:02:12 -0800866 if (cleanupDm) {
San Mehatd9a4e352010-03-12 13:32:47 -0800867 Devmapper::destroy(idHash);
San Mehatb78a32c2010-01-10 13:02:12 -0800868 }
San Mehateb13a902010-01-07 12:12:50 -0800869 Loop::destroyByDevice(loopDevice);
870 unlink(asecFileName);
871 return -1;
872 }
Kenny Root344ca102012-04-03 17:23:01 -0700873
Kenny Root344ca102012-04-03 17:23:01 -0700874 if (mkdir(mountPoint, 0000)) {
San Mehata1091cb2010-02-28 20:17:20 -0800875 if (errno != EEXIST) {
San Mehat97ac40e2010-03-24 10:24:19 -0700876 SLOGE("Mountpoint creation failed (%s)", strerror(errno));
San Mehata1091cb2010-02-28 20:17:20 -0800877 if (cleanupDm) {
San Mehatd9a4e352010-03-12 13:32:47 -0800878 Devmapper::destroy(idHash);
San Mehata1091cb2010-02-28 20:17:20 -0800879 }
880 Loop::destroyByDevice(loopDevice);
881 unlink(asecFileName);
882 return -1;
883 }
San Mehatb78a32c2010-01-10 13:02:12 -0800884 }
San Mehata1091cb2010-02-28 20:17:20 -0800885
Kenny Root344ca102012-04-03 17:23:01 -0700886 int mountStatus;
887 if (usingExt4) {
Jeff Sharkeyd0640f62015-05-21 22:35:42 -0700888 mountStatus = android::vold::ext4::Mount(dmDevice, mountPoint,
889 false, false, false);
Kenny Root344ca102012-04-03 17:23:01 -0700890 } else {
Jeff Sharkeyd0640f62015-05-21 22:35:42 -0700891 mountStatus = android::vold::vfat::Mount(dmDevice, mountPoint,
892 false, false, false, ownerUid, 0, 0000, false);
Kenny Root344ca102012-04-03 17:23:01 -0700893 }
894
895 if (mountStatus) {
San Mehat97ac40e2010-03-24 10:24:19 -0700896 SLOGE("ASEC FAT mount failed (%s)", strerror(errno));
San Mehata1091cb2010-02-28 20:17:20 -0800897 if (cleanupDm) {
San Mehatd9a4e352010-03-12 13:32:47 -0800898 Devmapper::destroy(idHash);
San Mehata1091cb2010-02-28 20:17:20 -0800899 }
900 Loop::destroyByDevice(loopDevice);
901 unlink(asecFileName);
902 return -1;
903 }
Kenny Root344ca102012-04-03 17:23:01 -0700904
905 if (usingExt4) {
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700906 int dirfd = open(mountPoint, O_DIRECTORY | O_CLOEXEC);
Kenny Root344ca102012-04-03 17:23:01 -0700907 if (dirfd >= 0) {
908 if (fchown(dirfd, ownerUid, AID_SYSTEM)
909 || fchmod(dirfd, S_IRUSR | S_IWUSR | S_IXUSR | S_ISGID | S_IRGRP | S_IXGRP)) {
910 SLOGI("Cannot chown/chmod new ASEC mount point %s", mountPoint);
911 }
912 close(dirfd);
913 }
914 }
San Mehata1091cb2010-02-28 20:17:20 -0800915 } else {
San Mehat97ac40e2010-03-24 10:24:19 -0700916 SLOGI("Created raw secure container %s (no filesystem)", id);
San Mehata19b2502010-01-06 10:33:53 -0800917 }
San Mehat88705162010-01-15 09:26:28 -0800918
Kenny Rootcbacf782010-09-24 15:11:48 -0700919 mActiveContainers->push_back(new ContainerData(strdup(id), ASEC));
San Mehata19b2502010-01-06 10:33:53 -0800920 return 0;
921}
922
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -0700923int VolumeManager::resizeAsec(const char *id, unsigned numSectors, const char *key) {
924 char asecFileName[255];
925 char mountPoint[255];
926 bool cleanupDm = false;
927
928 if (!isLegalAsecId(id)) {
929 SLOGE("resizeAsec: Invalid asec id \"%s\"", id);
930 errno = EINVAL;
931 return -1;
932 }
933
934 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
935 SLOGE("Couldn't find ASEC %s", id);
936 return -1;
937 }
938
Jeff Sharkey9f18fe72015-04-01 23:32:18 -0700939 int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -0700940 if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
941 SLOGE("ASEC resize failed for %s: couldn't construct mountpoint", id);
942 return -1;
943 }
944
945 if (isMountpointMounted(mountPoint)) {
946 SLOGE("ASEC %s mounted. Unmount before resizing", id);
947 errno = EBUSY;
948 return -1;
949 }
950
951 struct asec_superblock sb;
952 int fd;
953 unsigned int oldNumSec = 0;
954
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700955 if ((fd = open(asecFileName, O_RDONLY | O_CLOEXEC)) < 0) {
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -0700956 SLOGE("Failed to open ASEC file (%s)", strerror(errno));
957 return -1;
958 }
959
960 struct stat info;
961 if (fstat(fd, &info) < 0) {
962 SLOGE("Failed to get file size (%s)", strerror(errno));
963 close(fd);
964 return -1;
965 }
966
967 oldNumSec = info.st_size / 512;
968
969 unsigned numImgSectors;
970 if (sb.c_opts & ASEC_SB_C_OPTS_EXT4)
971 numImgSectors = adjustSectorNumExt4(numSectors);
972 else
973 numImgSectors = adjustSectorNumFAT(numSectors);
974 /*
975 * add one block for the superblock
976 */
977 SLOGD("Resizing from %d sectors to %d sectors", oldNumSec, numImgSectors + 1);
Jeff Sharkey43ed1232014-08-22 12:29:05 -0700978 if (oldNumSec == numImgSectors + 1) {
979 SLOGW("Size unchanged; ignoring resize request");
980 return 0;
981 } else if (oldNumSec > numImgSectors + 1) {
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -0700982 SLOGE("Only growing is currently supported.");
983 close(fd);
984 return -1;
985 }
986
987 /*
988 * Try to read superblock.
989 */
990 memset(&sb, 0, sizeof(struct asec_superblock));
991 if (lseek(fd, ((oldNumSec - 1) * 512), SEEK_SET) < 0) {
992 SLOGE("lseek failed (%s)", strerror(errno));
993 close(fd);
994 return -1;
995 }
996 if (read(fd, &sb, sizeof(struct asec_superblock)) != sizeof(struct asec_superblock)) {
997 SLOGE("superblock read failed (%s)", strerror(errno));
998 close(fd);
999 return -1;
1000 }
1001 close(fd);
1002
1003 if (mDebug) {
1004 SLOGD("Container sb magic/ver (%.8x/%.2x)", sb.magic, sb.ver);
1005 }
1006 if (sb.magic != ASEC_SB_MAGIC || sb.ver != ASEC_SB_VER) {
1007 SLOGE("Bad container magic/version (%.8x/%.2x)", sb.magic, sb.ver);
1008 errno = EMEDIUMTYPE;
1009 return -1;
1010 }
1011
1012 if (!(sb.c_opts & ASEC_SB_C_OPTS_EXT4)) {
1013 SLOGE("Only ext4 partitions are supported for resize");
1014 errno = EINVAL;
1015 return -1;
1016 }
1017
1018 if (Loop::resizeImageFile(asecFileName, numImgSectors + 1)) {
1019 SLOGE("Resize of ASEC image file failed. Could not resize %s", id);
1020 return -1;
1021 }
1022
1023 /*
1024 * Drop down a copy of the superblock at the end of the file
1025 */
1026 if (writeSuperBlock(asecFileName, &sb, numImgSectors))
1027 goto fail;
1028
1029 char idHash[33];
1030 if (!asecHash(id, idHash, sizeof(idHash))) {
1031 SLOGE("Hash of '%s' failed (%s)", id, strerror(errno));
1032 goto fail;
1033 }
1034
1035 char loopDevice[255];
1036 if (setupLoopDevice(loopDevice, sizeof(loopDevice), asecFileName, idHash, mDebug))
1037 goto fail;
1038
1039 char dmDevice[255];
1040
1041 if (setupDevMapperDevice(dmDevice, sizeof(dmDevice), loopDevice, asecFileName, key, idHash, numImgSectors, &cleanupDm, mDebug)) {
1042 Loop::destroyByDevice(loopDevice);
1043 goto fail;
1044 }
1045
1046 /*
1047 * Wait for the device mapper node to be created.
1048 */
1049 waitForDevMapper(dmDevice);
1050
Jeff Sharkeyd0640f62015-05-21 22:35:42 -07001051 if (android::vold::ext4::Resize(dmDevice, numImgSectors)) {
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -07001052 SLOGE("Unable to resize %s (%s)", id, strerror(errno));
1053 if (cleanupDm) {
1054 Devmapper::destroy(idHash);
1055 }
1056 Loop::destroyByDevice(loopDevice);
1057 goto fail;
1058 }
1059
1060 return 0;
1061fail:
1062 Loop::resizeImageFile(asecFileName, oldNumSec);
1063 return -1;
1064}
1065
San Mehata19b2502010-01-06 10:33:53 -08001066int VolumeManager::finalizeAsec(const char *id) {
1067 char asecFileName[255];
1068 char loopDevice[255];
1069 char mountPoint[255];
1070
Nick Kralevich0de7c612014-01-27 14:58:06 -08001071 if (!isLegalAsecId(id)) {
1072 SLOGE("finalizeAsec: Invalid asec id \"%s\"", id);
1073 errno = EINVAL;
1074 return -1;
1075 }
1076
Kenny Root344ca102012-04-03 17:23:01 -07001077 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
1078 SLOGE("Couldn't find ASEC %s", id);
1079 return -1;
1080 }
San Mehata19b2502010-01-06 10:33:53 -08001081
San Mehatd9a4e352010-03-12 13:32:47 -08001082 char idHash[33];
1083 if (!asecHash(id, idHash, sizeof(idHash))) {
San Mehat97ac40e2010-03-24 10:24:19 -07001084 SLOGE("Hash of '%s' failed (%s)", id, strerror(errno));
San Mehatd9a4e352010-03-12 13:32:47 -08001085 return -1;
1086 }
1087
1088 if (Loop::lookupActive(idHash, loopDevice, sizeof(loopDevice))) {
San Mehat97ac40e2010-03-24 10:24:19 -07001089 SLOGE("Unable to finalize %s (%s)", id, strerror(errno));
San Mehata19b2502010-01-06 10:33:53 -08001090 return -1;
1091 }
1092
Hiroaki Miyazawa14eab552015-02-04 13:29:15 +09001093 unsigned long nr_sec = 0;
Kenny Root344ca102012-04-03 17:23:01 -07001094 struct asec_superblock sb;
1095
1096 if (Loop::lookupInfo(loopDevice, &sb, &nr_sec)) {
1097 return -1;
1098 }
1099
Jeff Sharkey9f18fe72015-04-01 23:32:18 -07001100 int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
rpcraigd1c226f2012-10-09 06:58:16 -04001101 if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
1102 SLOGE("ASEC finalize failed: couldn't construct mountPoint");
1103 return -1;
1104 }
Kenny Root344ca102012-04-03 17:23:01 -07001105
1106 int result = 0;
1107 if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) {
Jeff Sharkeyd0640f62015-05-21 22:35:42 -07001108 result = android::vold::ext4::Mount(loopDevice, mountPoint,
1109 true, true, true);
Kenny Root344ca102012-04-03 17:23:01 -07001110 } else {
Jeff Sharkeyd0640f62015-05-21 22:35:42 -07001111 result = android::vold::vfat::Mount(loopDevice, mountPoint,
1112 true, true, true, 0, 0, 0227, false);
Kenny Root344ca102012-04-03 17:23:01 -07001113 }
1114
1115 if (result) {
San Mehat97ac40e2010-03-24 10:24:19 -07001116 SLOGE("ASEC finalize mount failed (%s)", strerror(errno));
San Mehata19b2502010-01-06 10:33:53 -08001117 return -1;
1118 }
1119
San Mehatd9a4e352010-03-12 13:32:47 -08001120 if (mDebug) {
San Mehat97ac40e2010-03-24 10:24:19 -07001121 SLOGD("ASEC %s finalized", id);
San Mehatd9a4e352010-03-12 13:32:47 -08001122 }
San Mehata19b2502010-01-06 10:33:53 -08001123 return 0;
1124}
1125
Kenny Root344ca102012-04-03 17:23:01 -07001126int VolumeManager::fixupAsecPermissions(const char *id, gid_t gid, const char* filename) {
1127 char asecFileName[255];
1128 char loopDevice[255];
1129 char mountPoint[255];
1130
1131 if (gid < AID_APP) {
1132 SLOGE("Group ID is not in application range");
1133 return -1;
1134 }
1135
Nick Kralevich0de7c612014-01-27 14:58:06 -08001136 if (!isLegalAsecId(id)) {
1137 SLOGE("fixupAsecPermissions: Invalid asec id \"%s\"", id);
1138 errno = EINVAL;
1139 return -1;
1140 }
1141
Kenny Root344ca102012-04-03 17:23:01 -07001142 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
1143 SLOGE("Couldn't find ASEC %s", id);
1144 return -1;
1145 }
1146
1147 char idHash[33];
1148 if (!asecHash(id, idHash, sizeof(idHash))) {
1149 SLOGE("Hash of '%s' failed (%s)", id, strerror(errno));
1150 return -1;
1151 }
1152
1153 if (Loop::lookupActive(idHash, loopDevice, sizeof(loopDevice))) {
1154 SLOGE("Unable fix permissions during lookup on %s (%s)", id, strerror(errno));
1155 return -1;
1156 }
1157
Hiroaki Miyazawa14eab552015-02-04 13:29:15 +09001158 unsigned long nr_sec = 0;
Kenny Root344ca102012-04-03 17:23:01 -07001159 struct asec_superblock sb;
1160
1161 if (Loop::lookupInfo(loopDevice, &sb, &nr_sec)) {
1162 return -1;
1163 }
1164
Jeff Sharkey9f18fe72015-04-01 23:32:18 -07001165 int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
rpcraigd1c226f2012-10-09 06:58:16 -04001166 if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
1167 SLOGE("Unable remount to fix permissions for %s: couldn't construct mountpoint", id);
1168 return -1;
1169 }
Kenny Root344ca102012-04-03 17:23:01 -07001170
1171 int result = 0;
1172 if ((sb.c_opts & ASEC_SB_C_OPTS_EXT4) == 0) {
1173 return 0;
1174 }
1175
Jeff Sharkeyd0640f62015-05-21 22:35:42 -07001176 int ret = android::vold::ext4::Mount(loopDevice, mountPoint,
Kenny Root344ca102012-04-03 17:23:01 -07001177 false /* read-only */,
1178 true /* remount */,
1179 false /* executable */);
1180 if (ret) {
1181 SLOGE("Unable remount to fix permissions for %s (%s)", id, strerror(errno));
1182 return -1;
1183 }
1184
1185 char *paths[] = { mountPoint, NULL };
1186
1187 FTS *fts = fts_open(paths, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL);
1188 if (fts) {
1189 // Traverse the entire hierarchy and chown to system UID.
1190 for (FTSENT *ftsent = fts_read(fts); ftsent != NULL; ftsent = fts_read(fts)) {
1191 // We don't care about the lost+found directory.
1192 if (!strcmp(ftsent->fts_name, "lost+found")) {
1193 continue;
1194 }
1195
1196 /*
1197 * There can only be one file marked as private right now.
1198 * This should be more robust, but it satisfies the requirements
1199 * we have for right now.
1200 */
1201 const bool privateFile = !strcmp(ftsent->fts_name, filename);
1202
Jeff Sharkeyce6a9132015-04-08 21:07:21 -07001203 int fd = open(ftsent->fts_accpath, O_NOFOLLOW | O_CLOEXEC);
Kenny Root344ca102012-04-03 17:23:01 -07001204 if (fd < 0) {
1205 SLOGE("Couldn't open file %s: %s", ftsent->fts_accpath, strerror(errno));
1206 result = -1;
1207 continue;
1208 }
1209
1210 result |= fchown(fd, AID_SYSTEM, privateFile? gid : AID_SYSTEM);
1211
1212 if (ftsent->fts_info & FTS_D) {
Kenny Root1a673c82012-05-10 16:45:29 -07001213 result |= fchmod(fd, 0755);
Kenny Root348c8ab2012-05-10 15:39:53 -07001214 } else if (ftsent->fts_info & FTS_F) {
Kenny Root344ca102012-04-03 17:23:01 -07001215 result |= fchmod(fd, privateFile ? 0640 : 0644);
1216 }
Robert Craigb9e3ba52014-02-04 10:53:00 -05001217
Stephen Smalley5093e612014-02-12 09:43:08 -05001218 if (selinux_android_restorecon(ftsent->fts_path, 0) < 0) {
Robert Craigb9e3ba52014-02-04 10:53:00 -05001219 SLOGE("restorecon failed for %s: %s\n", ftsent->fts_path, strerror(errno));
1220 result |= -1;
1221 }
1222
Kenny Root344ca102012-04-03 17:23:01 -07001223 close(fd);
1224 }
1225 fts_close(fts);
1226
1227 // Finally make the directory readable by everyone.
Jeff Sharkeyce6a9132015-04-08 21:07:21 -07001228 int dirfd = open(mountPoint, O_DIRECTORY | O_CLOEXEC);
Kenny Root344ca102012-04-03 17:23:01 -07001229 if (dirfd < 0 || fchmod(dirfd, 0755)) {
1230 SLOGE("Couldn't change owner of existing directory %s: %s", mountPoint, strerror(errno));
1231 result |= -1;
1232 }
1233 close(dirfd);
1234 } else {
1235 result |= -1;
1236 }
1237
Jeff Sharkeyd0640f62015-05-21 22:35:42 -07001238 result |= android::vold::ext4::Mount(loopDevice, mountPoint,
Kenny Root344ca102012-04-03 17:23:01 -07001239 true /* read-only */,
1240 true /* remount */,
1241 true /* execute */);
1242
1243 if (result) {
1244 SLOGE("ASEC fix permissions failed (%s)", strerror(errno));
1245 return -1;
1246 }
1247
1248 if (mDebug) {
1249 SLOGD("ASEC %s permissions fixed", id);
1250 }
1251 return 0;
1252}
1253
San Mehat048b0802010-01-23 08:17:06 -08001254int VolumeManager::renameAsec(const char *id1, const char *id2) {
Kenny Root344ca102012-04-03 17:23:01 -07001255 char asecFilename1[255];
San Mehat048b0802010-01-23 08:17:06 -08001256 char *asecFilename2;
1257 char mountPoint[255];
1258
Kenny Root344ca102012-04-03 17:23:01 -07001259 const char *dir;
1260
Nick Kralevich0de7c612014-01-27 14:58:06 -08001261 if (!isLegalAsecId(id1)) {
1262 SLOGE("renameAsec: Invalid asec id1 \"%s\"", id1);
1263 errno = EINVAL;
1264 return -1;
1265 }
1266
1267 if (!isLegalAsecId(id2)) {
1268 SLOGE("renameAsec: Invalid asec id2 \"%s\"", id2);
1269 errno = EINVAL;
1270 return -1;
1271 }
1272
Kenny Root344ca102012-04-03 17:23:01 -07001273 if (findAsec(id1, asecFilename1, sizeof(asecFilename1), &dir)) {
1274 SLOGE("Couldn't find ASEC %s", id1);
1275 return -1;
1276 }
1277
1278 asprintf(&asecFilename2, "%s/%s.asec", dir, id2);
San Mehat048b0802010-01-23 08:17:06 -08001279
Jeff Sharkey9f18fe72015-04-01 23:32:18 -07001280 int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id1);
rpcraigd1c226f2012-10-09 06:58:16 -04001281 if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
1282 SLOGE("Rename failed: couldn't construct mountpoint");
1283 goto out_err;
1284 }
1285
San Mehat048b0802010-01-23 08:17:06 -08001286 if (isMountpointMounted(mountPoint)) {
San Mehat97ac40e2010-03-24 10:24:19 -07001287 SLOGW("Rename attempt when src mounted");
San Mehat048b0802010-01-23 08:17:06 -08001288 errno = EBUSY;
1289 goto out_err;
1290 }
1291
Jeff Sharkey9f18fe72015-04-01 23:32:18 -07001292 written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id2);
rpcraigd1c226f2012-10-09 06:58:16 -04001293 if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
1294 SLOGE("Rename failed: couldn't construct mountpoint2");
1295 goto out_err;
1296 }
1297
San Mehat96956ed2010-02-24 08:42:51 -08001298 if (isMountpointMounted(mountPoint)) {
San Mehat97ac40e2010-03-24 10:24:19 -07001299 SLOGW("Rename attempt when dst mounted");
San Mehat96956ed2010-02-24 08:42:51 -08001300 errno = EBUSY;
1301 goto out_err;
1302 }
1303
San Mehat048b0802010-01-23 08:17:06 -08001304 if (!access(asecFilename2, F_OK)) {
San Mehat97ac40e2010-03-24 10:24:19 -07001305 SLOGE("Rename attempt when dst exists");
San Mehat048b0802010-01-23 08:17:06 -08001306 errno = EADDRINUSE;
1307 goto out_err;
1308 }
1309
1310 if (rename(asecFilename1, asecFilename2)) {
San Mehat97ac40e2010-03-24 10:24:19 -07001311 SLOGE("Rename of '%s' to '%s' failed (%s)", asecFilename1, asecFilename2, strerror(errno));
San Mehat048b0802010-01-23 08:17:06 -08001312 goto out_err;
1313 }
1314
San Mehat048b0802010-01-23 08:17:06 -08001315 free(asecFilename2);
1316 return 0;
1317
1318out_err:
San Mehat048b0802010-01-23 08:17:06 -08001319 free(asecFilename2);
1320 return -1;
1321}
1322
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001323#define UNMOUNT_RETRIES 5
1324#define UNMOUNT_SLEEP_BETWEEN_RETRY_MS (1000 * 1000)
San Mehat4ba89482010-02-18 09:00:18 -08001325int VolumeManager::unmountAsec(const char *id, bool force) {
San Mehata19b2502010-01-06 10:33:53 -08001326 char asecFileName[255];
1327 char mountPoint[255];
1328
Nick Kralevich0de7c612014-01-27 14:58:06 -08001329 if (!isLegalAsecId(id)) {
1330 SLOGE("unmountAsec: Invalid asec id \"%s\"", id);
1331 errno = EINVAL;
1332 return -1;
1333 }
1334
Kenny Root344ca102012-04-03 17:23:01 -07001335 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
1336 SLOGE("Couldn't find ASEC %s", id);
1337 return -1;
1338 }
1339
Jeff Sharkey9f18fe72015-04-01 23:32:18 -07001340 int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
rpcraigd1c226f2012-10-09 06:58:16 -04001341 if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
1342 SLOGE("ASEC unmount failed for %s: couldn't construct mountpoint", id);
1343 return -1;
1344 }
San Mehata19b2502010-01-06 10:33:53 -08001345
San Mehatd9a4e352010-03-12 13:32:47 -08001346 char idHash[33];
1347 if (!asecHash(id, idHash, sizeof(idHash))) {
San Mehat97ac40e2010-03-24 10:24:19 -07001348 SLOGE("Hash of '%s' failed (%s)", id, strerror(errno));
San Mehatd9a4e352010-03-12 13:32:47 -08001349 return -1;
1350 }
1351
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001352 return unmountLoopImage(id, idHash, asecFileName, mountPoint, force);
1353}
1354
Kenny Root508c0e12010-07-12 09:59:49 -07001355int VolumeManager::unmountObb(const char *fileName, bool force) {
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001356 char mountPoint[255];
1357
1358 char idHash[33];
1359 if (!asecHash(fileName, idHash, sizeof(idHash))) {
1360 SLOGE("Hash of '%s' failed (%s)", fileName, strerror(errno));
1361 return -1;
1362 }
1363
Jeff Sharkey9f18fe72015-04-01 23:32:18 -07001364 int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::LOOPDIR, idHash);
rpcraigd1c226f2012-10-09 06:58:16 -04001365 if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
1366 SLOGE("OBB unmount failed for %s: couldn't construct mountpoint", fileName);
1367 return -1;
1368 }
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001369
1370 return unmountLoopImage(fileName, idHash, fileName, mountPoint, force);
1371}
1372
1373int VolumeManager::unmountLoopImage(const char *id, const char *idHash,
1374 const char *fileName, const char *mountPoint, bool force) {
San Mehat0586d542010-01-12 15:38:59 -08001375 if (!isMountpointMounted(mountPoint)) {
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001376 SLOGE("Unmount request for %s when not mounted", id);
Kenny Root918e5f92010-09-30 18:00:52 -07001377 errno = ENOENT;
San Mehatb78a32c2010-01-10 13:02:12 -08001378 return -1;
1379 }
San Mehat23969932010-01-09 07:08:06 -08001380
San Mehatb78a32c2010-01-10 13:02:12 -08001381 int i, rc;
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001382 for (i = 1; i <= UNMOUNT_RETRIES; i++) {
San Mehatb78a32c2010-01-10 13:02:12 -08001383 rc = umount(mountPoint);
1384 if (!rc) {
1385 break;
San Mehata19b2502010-01-06 10:33:53 -08001386 }
San Mehatb78a32c2010-01-10 13:02:12 -08001387 if (rc && (errno == EINVAL || errno == ENOENT)) {
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001388 SLOGI("Container %s unmounted OK", id);
San Mehatb78a32c2010-01-10 13:02:12 -08001389 rc = 0;
1390 break;
San Mehata19b2502010-01-06 10:33:53 -08001391 }
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001392 SLOGW("%s unmount attempt %d failed (%s)",
San Mehat8c940ef2010-02-13 14:19:53 -08001393 id, i, strerror(errno));
San Mehatb78a32c2010-01-10 13:02:12 -08001394
Jeff Sharkey36801cc2015-03-13 16:09:20 -07001395 int signal = 0; // default is to just complain
San Mehat4ba89482010-02-18 09:00:18 -08001396
1397 if (force) {
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001398 if (i > (UNMOUNT_RETRIES - 2))
Jeff Sharkey36801cc2015-03-13 16:09:20 -07001399 signal = SIGKILL;
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001400 else if (i > (UNMOUNT_RETRIES - 3))
Jeff Sharkey36801cc2015-03-13 16:09:20 -07001401 signal = SIGTERM;
San Mehat4ba89482010-02-18 09:00:18 -08001402 }
San Mehat8c940ef2010-02-13 14:19:53 -08001403
Jeff Sharkey36801cc2015-03-13 16:09:20 -07001404 Process::killProcessesWithOpenFiles(mountPoint, signal);
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001405 usleep(UNMOUNT_SLEEP_BETWEEN_RETRY_MS);
San Mehatb78a32c2010-01-10 13:02:12 -08001406 }
1407
1408 if (rc) {
San Mehat4ba89482010-02-18 09:00:18 -08001409 errno = EBUSY;
San Mehat97ac40e2010-03-24 10:24:19 -07001410 SLOGE("Failed to unmount container %s (%s)", id, strerror(errno));
San Mehatb78a32c2010-01-10 13:02:12 -08001411 return -1;
1412 }
1413
San Mehat12f4b892010-02-24 11:43:22 -08001414 int retries = 10;
1415
1416 while(retries--) {
1417 if (!rmdir(mountPoint)) {
1418 break;
1419 }
1420
San Mehat97ac40e2010-03-24 10:24:19 -07001421 SLOGW("Failed to rmdir %s (%s)", mountPoint, strerror(errno));
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001422 usleep(UNMOUNT_SLEEP_BETWEEN_RETRY_MS);
San Mehat12f4b892010-02-24 11:43:22 -08001423 }
1424
1425 if (!retries) {
San Mehat97ac40e2010-03-24 10:24:19 -07001426 SLOGE("Timed out trying to rmdir %s (%s)", mountPoint, strerror(errno));
San Mehatf5c61982010-02-03 11:04:46 -08001427 }
San Mehat88705162010-01-15 09:26:28 -08001428
Paul Lawrence60dec162014-09-02 10:52:15 -07001429 for (i=1; i <= UNMOUNT_RETRIES; i++) {
1430 if (Devmapper::destroy(idHash) && errno != ENXIO) {
1431 SLOGE("Failed to destroy devmapper instance (%s)", strerror(errno));
1432 usleep(UNMOUNT_SLEEP_BETWEEN_RETRY_MS);
1433 continue;
1434 } else {
1435 break;
1436 }
San Mehata19b2502010-01-06 10:33:53 -08001437 }
1438
1439 char loopDevice[255];
San Mehatd9a4e352010-03-12 13:32:47 -08001440 if (!Loop::lookupActive(idHash, loopDevice, sizeof(loopDevice))) {
San Mehata19b2502010-01-06 10:33:53 -08001441 Loop::destroyByDevice(loopDevice);
San Mehatd9a4e352010-03-12 13:32:47 -08001442 } else {
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001443 SLOGW("Failed to find loop device for {%s} (%s)", fileName, strerror(errno));
San Mehata19b2502010-01-06 10:33:53 -08001444 }
San Mehat88705162010-01-15 09:26:28 -08001445
1446 AsecIdCollection::iterator it;
1447 for (it = mActiveContainers->begin(); it != mActiveContainers->end(); ++it) {
Kenny Rootcbacf782010-09-24 15:11:48 -07001448 ContainerData* cd = *it;
1449 if (!strcmp(cd->id, id)) {
San Mehat88705162010-01-15 09:26:28 -08001450 free(*it);
1451 mActiveContainers->erase(it);
1452 break;
1453 }
1454 }
1455 if (it == mActiveContainers->end()) {
San Mehat97ac40e2010-03-24 10:24:19 -07001456 SLOGW("mActiveContainers is inconsistent!");
San Mehat88705162010-01-15 09:26:28 -08001457 }
San Mehatb78a32c2010-01-10 13:02:12 -08001458 return 0;
1459}
1460
San Mehat4ba89482010-02-18 09:00:18 -08001461int VolumeManager::destroyAsec(const char *id, bool force) {
San Mehatb78a32c2010-01-10 13:02:12 -08001462 char asecFileName[255];
1463 char mountPoint[255];
1464
Nick Kralevich0de7c612014-01-27 14:58:06 -08001465 if (!isLegalAsecId(id)) {
1466 SLOGE("destroyAsec: Invalid asec id \"%s\"", id);
1467 errno = EINVAL;
1468 return -1;
1469 }
1470
Kenny Root344ca102012-04-03 17:23:01 -07001471 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
1472 SLOGE("Couldn't find ASEC %s", id);
1473 return -1;
1474 }
1475
Jeff Sharkey9f18fe72015-04-01 23:32:18 -07001476 int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
rpcraigd1c226f2012-10-09 06:58:16 -04001477 if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
1478 SLOGE("ASEC destroy failed for %s: couldn't construct mountpoint", id);
1479 return -1;
1480 }
San Mehatb78a32c2010-01-10 13:02:12 -08001481
San Mehat0586d542010-01-12 15:38:59 -08001482 if (isMountpointMounted(mountPoint)) {
San Mehatd9a4e352010-03-12 13:32:47 -08001483 if (mDebug) {
San Mehat97ac40e2010-03-24 10:24:19 -07001484 SLOGD("Unmounting container before destroy");
San Mehatd9a4e352010-03-12 13:32:47 -08001485 }
San Mehat4ba89482010-02-18 09:00:18 -08001486 if (unmountAsec(id, force)) {
San Mehat97ac40e2010-03-24 10:24:19 -07001487 SLOGE("Failed to unmount asec %s for destroy (%s)", id, strerror(errno));
San Mehat0586d542010-01-12 15:38:59 -08001488 return -1;
1489 }
1490 }
San Mehata19b2502010-01-06 10:33:53 -08001491
San Mehat0586d542010-01-12 15:38:59 -08001492 if (unlink(asecFileName)) {
San Mehat97ac40e2010-03-24 10:24:19 -07001493 SLOGE("Failed to unlink asec '%s' (%s)", asecFileName, strerror(errno));
San Mehat0586d542010-01-12 15:38:59 -08001494 return -1;
1495 }
San Mehata19b2502010-01-06 10:33:53 -08001496
San Mehatd9a4e352010-03-12 13:32:47 -08001497 if (mDebug) {
San Mehat97ac40e2010-03-24 10:24:19 -07001498 SLOGD("ASEC %s destroyed", id);
San Mehatd9a4e352010-03-12 13:32:47 -08001499 }
San Mehata19b2502010-01-06 10:33:53 -08001500 return 0;
1501}
1502
Nick Kralevich0de7c612014-01-27 14:58:06 -08001503/*
1504 * Legal ASEC ids consist of alphanumeric characters, '-',
1505 * '_', or '.'. ".." is not allowed. The first or last character
1506 * of the ASEC id cannot be '.' (dot).
1507 */
1508bool VolumeManager::isLegalAsecId(const char *id) const {
1509 size_t i;
1510 size_t len = strlen(id);
1511
1512 if (len == 0) {
1513 return false;
1514 }
1515 if ((id[0] == '.') || (id[len - 1] == '.')) {
1516 return false;
1517 }
1518
1519 for (i = 0; i < len; i++) {
1520 if (id[i] == '.') {
1521 // i=0 is guaranteed never to have a dot. See above.
1522 if (id[i-1] == '.') return false;
1523 continue;
1524 }
1525 if (id[i] == '_' || id[i] == '-') continue;
1526 if (id[i] >= 'a' && id[i] <= 'z') continue;
1527 if (id[i] >= 'A' && id[i] <= 'Z') continue;
1528 if (id[i] >= '0' && id[i] <= '9') continue;
1529 return false;
1530 }
1531
1532 return true;
1533}
1534
Kenny Root344ca102012-04-03 17:23:01 -07001535bool VolumeManager::isAsecInDirectory(const char *dir, const char *asecName) const {
Jeff Sharkeyce6a9132015-04-08 21:07:21 -07001536 int dirfd = open(dir, O_DIRECTORY | O_CLOEXEC);
Kenny Root344ca102012-04-03 17:23:01 -07001537 if (dirfd < 0) {
1538 SLOGE("Couldn't open internal ASEC dir (%s)", strerror(errno));
Nick Kralevich25e581a2015-02-06 08:55:08 -08001539 return false;
Kenny Root344ca102012-04-03 17:23:01 -07001540 }
1541
Nick Kralevich25e581a2015-02-06 08:55:08 -08001542 struct stat sb;
1543 bool ret = (fstatat(dirfd, asecName, &sb, AT_SYMLINK_NOFOLLOW) == 0)
1544 && S_ISREG(sb.st_mode);
Kenny Root344ca102012-04-03 17:23:01 -07001545
1546 close(dirfd);
1547
1548 return ret;
1549}
1550
1551int VolumeManager::findAsec(const char *id, char *asecPath, size_t asecPathLen,
1552 const char **directory) const {
Kenny Root344ca102012-04-03 17:23:01 -07001553 char *asecName;
1554
Nick Kralevich0de7c612014-01-27 14:58:06 -08001555 if (!isLegalAsecId(id)) {
1556 SLOGE("findAsec: Invalid asec id \"%s\"", id);
1557 errno = EINVAL;
1558 return -1;
1559 }
1560
Kenny Root344ca102012-04-03 17:23:01 -07001561 if (asprintf(&asecName, "%s.asec", id) < 0) {
1562 SLOGE("Couldn't allocate string to write ASEC name");
1563 return -1;
1564 }
1565
1566 const char *dir;
Jeff Sharkey9f18fe72015-04-01 23:32:18 -07001567 if (isAsecInDirectory(VolumeManager::SEC_ASECDIR_INT, asecName)) {
1568 dir = VolumeManager::SEC_ASECDIR_INT;
1569 } else if (isAsecInDirectory(VolumeManager::SEC_ASECDIR_EXT, asecName)) {
1570 dir = VolumeManager::SEC_ASECDIR_EXT;
Kenny Root344ca102012-04-03 17:23:01 -07001571 } else {
1572 free(asecName);
1573 return -1;
1574 }
1575
1576 if (directory != NULL) {
1577 *directory = dir;
1578 }
1579
1580 if (asecPath != NULL) {
1581 int written = snprintf(asecPath, asecPathLen, "%s/%s", dir, asecName);
rpcraigd1c226f2012-10-09 06:58:16 -04001582 if ((written < 0) || (size_t(written) >= asecPathLen)) {
1583 SLOGE("findAsec failed for %s: couldn't construct ASEC path", id);
Kenny Root344ca102012-04-03 17:23:01 -07001584 free(asecName);
1585 return -1;
1586 }
1587 }
1588
1589 free(asecName);
1590 return 0;
1591}
1592
Jeff Sharkey43ed1232014-08-22 12:29:05 -07001593int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid, bool readOnly) {
San Mehata19b2502010-01-06 10:33:53 -08001594 char asecFileName[255];
1595 char mountPoint[255];
1596
Nick Kralevich0de7c612014-01-27 14:58:06 -08001597 if (!isLegalAsecId(id)) {
1598 SLOGE("mountAsec: Invalid asec id \"%s\"", id);
1599 errno = EINVAL;
1600 return -1;
1601 }
1602
Kenny Root344ca102012-04-03 17:23:01 -07001603 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
1604 SLOGE("Couldn't find ASEC %s", id);
1605 return -1;
1606 }
1607
Jeff Sharkey9f18fe72015-04-01 23:32:18 -07001608 int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
rpcraigd1c226f2012-10-09 06:58:16 -04001609 if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
Colin Cross59846b62014-02-06 20:34:29 -08001610 SLOGE("ASEC mount failed for %s: couldn't construct mountpoint", id);
rpcraigd1c226f2012-10-09 06:58:16 -04001611 return -1;
1612 }
San Mehata19b2502010-01-06 10:33:53 -08001613
1614 if (isMountpointMounted(mountPoint)) {
San Mehat97ac40e2010-03-24 10:24:19 -07001615 SLOGE("ASEC %s already mounted", id);
San Mehata19b2502010-01-06 10:33:53 -08001616 errno = EBUSY;
1617 return -1;
1618 }
1619
San Mehatd9a4e352010-03-12 13:32:47 -08001620 char idHash[33];
1621 if (!asecHash(id, idHash, sizeof(idHash))) {
San Mehat97ac40e2010-03-24 10:24:19 -07001622 SLOGE("Hash of '%s' failed (%s)", id, strerror(errno));
San Mehatd9a4e352010-03-12 13:32:47 -08001623 return -1;
1624 }
Kenny Root7b18a7b2010-03-15 13:13:41 -07001625
San Mehata19b2502010-01-06 10:33:53 -08001626 char loopDevice[255];
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -07001627 if (setupLoopDevice(loopDevice, sizeof(loopDevice), asecFileName, idHash, mDebug))
1628 return -1;
San Mehatb78a32c2010-01-10 13:02:12 -08001629
1630 char dmDevice[255];
1631 bool cleanupDm = false;
Tim Murray8439dc92014-12-15 11:56:11 -08001632
Hiroaki Miyazawa14eab552015-02-04 13:29:15 +09001633 unsigned long nr_sec = 0;
San Mehatfcf24fe2010-03-03 12:37:32 -08001634 struct asec_superblock sb;
San Mehatfcf24fe2010-03-03 12:37:32 -08001635
Kenny Root344ca102012-04-03 17:23:01 -07001636 if (Loop::lookupInfo(loopDevice, &sb, &nr_sec)) {
1637 return -1;
1638 }
San Mehatfcf24fe2010-03-03 12:37:32 -08001639
San Mehatd9a4e352010-03-12 13:32:47 -08001640 if (mDebug) {
San Mehat97ac40e2010-03-24 10:24:19 -07001641 SLOGD("Container sb magic/ver (%.8x/%.2x)", sb.magic, sb.ver);
San Mehatd9a4e352010-03-12 13:32:47 -08001642 }
San Mehatfcf24fe2010-03-03 12:37:32 -08001643 if (sb.magic != ASEC_SB_MAGIC || sb.ver != ASEC_SB_VER) {
San Mehat97ac40e2010-03-24 10:24:19 -07001644 SLOGE("Bad container magic/version (%.8x/%.2x)", sb.magic, sb.ver);
San Mehatfcf24fe2010-03-03 12:37:32 -08001645 Loop::destroyByDevice(loopDevice);
1646 errno = EMEDIUMTYPE;
1647 return -1;
1648 }
1649 nr_sec--; // We don't want the devmapping to extend onto our superblock
1650
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -07001651 if (setupDevMapperDevice(dmDevice, sizeof(dmDevice), loopDevice, asecFileName, key, idHash , nr_sec, &cleanupDm, mDebug)) {
1652 Loop::destroyByDevice(loopDevice);
1653 return -1;
San Mehata19b2502010-01-06 10:33:53 -08001654 }
1655
Kenny Root344ca102012-04-03 17:23:01 -07001656 if (mkdir(mountPoint, 0000)) {
San Mehatb78a32c2010-01-10 13:02:12 -08001657 if (errno != EEXIST) {
San Mehat97ac40e2010-03-24 10:24:19 -07001658 SLOGE("Mountpoint creation failed (%s)", strerror(errno));
San Mehatb78a32c2010-01-10 13:02:12 -08001659 if (cleanupDm) {
San Mehatd9a4e352010-03-12 13:32:47 -08001660 Devmapper::destroy(idHash);
San Mehatb78a32c2010-01-10 13:02:12 -08001661 }
1662 Loop::destroyByDevice(loopDevice);
1663 return -1;
1664 }
San Mehata19b2502010-01-06 10:33:53 -08001665 }
1666
Kenny Rootcdc2a1c2012-05-03 13:49:46 -07001667 /*
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -07001668 * Wait for the device mapper node to be created.
Kenny Rootcdc2a1c2012-05-03 13:49:46 -07001669 */
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -07001670 waitForDevMapper(dmDevice);
Kenny Rootcdc2a1c2012-05-03 13:49:46 -07001671
Kenny Root344ca102012-04-03 17:23:01 -07001672 int result;
1673 if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) {
Jeff Sharkeyd0640f62015-05-21 22:35:42 -07001674 result = android::vold::ext4::Mount(dmDevice, mountPoint,
1675 readOnly, false, readOnly);
Kenny Root344ca102012-04-03 17:23:01 -07001676 } else {
Jeff Sharkeyd0640f62015-05-21 22:35:42 -07001677 result = android::vold::vfat::Mount(dmDevice, mountPoint,
1678 readOnly, false, readOnly, ownerUid, 0, 0222, false);
Kenny Root344ca102012-04-03 17:23:01 -07001679 }
1680
1681 if (result) {
San Mehat97ac40e2010-03-24 10:24:19 -07001682 SLOGE("ASEC mount failed (%s)", strerror(errno));
San Mehatb78a32c2010-01-10 13:02:12 -08001683 if (cleanupDm) {
San Mehatd9a4e352010-03-12 13:32:47 -08001684 Devmapper::destroy(idHash);
San Mehatb78a32c2010-01-10 13:02:12 -08001685 }
1686 Loop::destroyByDevice(loopDevice);
San Mehata19b2502010-01-06 10:33:53 -08001687 return -1;
1688 }
1689
Kenny Rootcbacf782010-09-24 15:11:48 -07001690 mActiveContainers->push_back(new ContainerData(strdup(id), ASEC));
San Mehatd9a4e352010-03-12 13:32:47 -08001691 if (mDebug) {
San Mehat97ac40e2010-03-24 10:24:19 -07001692 SLOGD("ASEC %s mounted", id);
San Mehatd9a4e352010-03-12 13:32:47 -08001693 }
San Mehata19b2502010-01-06 10:33:53 -08001694 return 0;
1695}
1696
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001697/**
1698 * Mounts an image file <code>img</code>.
1699 */
Jeff Sharkey69479042012-09-25 16:14:57 -07001700int VolumeManager::mountObb(const char *img, const char *key, int ownerGid) {
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001701 char mountPoint[255];
1702
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001703 char idHash[33];
1704 if (!asecHash(img, idHash, sizeof(idHash))) {
1705 SLOGE("Hash of '%s' failed (%s)", img, strerror(errno));
1706 return -1;
1707 }
1708
Jeff Sharkey9f18fe72015-04-01 23:32:18 -07001709 int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::LOOPDIR, idHash);
rpcraigd1c226f2012-10-09 06:58:16 -04001710 if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
Colin Cross59846b62014-02-06 20:34:29 -08001711 SLOGE("OBB mount failed for %s: couldn't construct mountpoint", img);
rpcraigd1c226f2012-10-09 06:58:16 -04001712 return -1;
1713 }
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001714
1715 if (isMountpointMounted(mountPoint)) {
1716 SLOGE("Image %s already mounted", img);
1717 errno = EBUSY;
1718 return -1;
1719 }
1720
1721 char loopDevice[255];
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -07001722 if (setupLoopDevice(loopDevice, sizeof(loopDevice), img, idHash, mDebug))
1723 return -1;
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001724
1725 char dmDevice[255];
1726 bool cleanupDm = false;
1727 int fd;
Hiroaki Miyazawa14eab552015-02-04 13:29:15 +09001728 unsigned long nr_sec = 0;
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001729
Jeff Sharkeyce6a9132015-04-08 21:07:21 -07001730 if ((fd = open(loopDevice, O_RDWR | O_CLOEXEC)) < 0) {
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001731 SLOGE("Failed to open loopdevice (%s)", strerror(errno));
1732 Loop::destroyByDevice(loopDevice);
1733 return -1;
1734 }
1735
Hiroaki Miyazawa14eab552015-02-04 13:29:15 +09001736 get_blkdev_size(fd, &nr_sec);
1737 if (nr_sec == 0) {
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001738 SLOGE("Failed to get loop size (%s)", strerror(errno));
1739 Loop::destroyByDevice(loopDevice);
1740 close(fd);
1741 return -1;
1742 }
1743
1744 close(fd);
1745
Hiroaki Miyazawa14eab552015-02-04 13:29:15 +09001746 if (setupDevMapperDevice(dmDevice, sizeof(loopDevice), loopDevice, img,key, idHash, nr_sec, &cleanupDm, mDebug)) {
Daniel Rosenbergfcd34a02014-05-22 11:23:56 -07001747 Loop::destroyByDevice(loopDevice);
1748 return -1;
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001749 }
1750
1751 if (mkdir(mountPoint, 0755)) {
1752 if (errno != EEXIST) {
1753 SLOGE("Mountpoint creation failed (%s)", strerror(errno));
1754 if (cleanupDm) {
1755 Devmapper::destroy(idHash);
1756 }
1757 Loop::destroyByDevice(loopDevice);
1758 return -1;
1759 }
1760 }
1761
yoshiyuki hama476a6272015-01-28 16:37:23 +09001762 /*
1763 * Wait for the device mapper node to be created.
1764 */
1765 waitForDevMapper(dmDevice);
1766
Jeff Sharkeyd0640f62015-05-21 22:35:42 -07001767 if (android::vold::vfat::Mount(dmDevice, mountPoint,
1768 true, false, true, 0, ownerGid, 0227, false)) {
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001769 SLOGE("Image mount failed (%s)", strerror(errno));
1770 if (cleanupDm) {
1771 Devmapper::destroy(idHash);
1772 }
1773 Loop::destroyByDevice(loopDevice);
1774 return -1;
1775 }
1776
Kenny Rootcbacf782010-09-24 15:11:48 -07001777 mActiveContainers->push_back(new ContainerData(strdup(img), OBB));
Kenny Rootfb7c4d52010-06-30 18:48:41 -07001778 if (mDebug) {
1779 SLOGD("Image %s mounted", img);
1780 }
1781 return 0;
1782}
1783
Kenny Root508c0e12010-07-12 09:59:49 -07001784int VolumeManager::listMountedObbs(SocketClient* cli) {
Yabin Cuid1104f72015-01-02 13:28:28 -08001785 FILE *fp = setmntent("/proc/mounts", "r");
1786 if (fp == NULL) {
Kenny Root508c0e12010-07-12 09:59:49 -07001787 SLOGE("Error opening /proc/mounts (%s)", strerror(errno));
1788 return -1;
1789 }
1790
1791 // Create a string to compare against that has a trailing slash
Jeff Sharkey9f18fe72015-04-01 23:32:18 -07001792 int loopDirLen = strlen(VolumeManager::LOOPDIR);
Kenny Root508c0e12010-07-12 09:59:49 -07001793 char loopDir[loopDirLen + 2];
Jeff Sharkey9f18fe72015-04-01 23:32:18 -07001794 strcpy(loopDir, VolumeManager::LOOPDIR);
Kenny Root508c0e12010-07-12 09:59:49 -07001795 loopDir[loopDirLen++] = '/';
1796 loopDir[loopDirLen] = '\0';
1797
Yabin Cuid1104f72015-01-02 13:28:28 -08001798 mntent* mentry;
1799 while ((mentry = getmntent(fp)) != NULL) {
1800 if (!strncmp(mentry->mnt_dir, loopDir, loopDirLen)) {
Jeff Sharkeyce6a9132015-04-08 21:07:21 -07001801 int fd = open(mentry->mnt_fsname, O_RDONLY | O_CLOEXEC);
Kenny Root508c0e12010-07-12 09:59:49 -07001802 if (fd >= 0) {
1803 struct loop_info64 li;
1804 if (ioctl(fd, LOOP_GET_STATUS64, &li) >= 0) {
1805 cli->sendMsg(ResponseCode::AsecListResult,
1806 (const char*) li.lo_file_name, false);
1807 }
1808 close(fd);
1809 }
1810 }
1811 }
Yabin Cuid1104f72015-01-02 13:28:28 -08001812 endmntent(fp);
Kenny Root508c0e12010-07-12 09:59:49 -07001813 return 0;
1814}
1815
Jeff Sharkey9c484982015-03-31 10:35:33 -07001816extern "C" int vold_unmountAll(void) {
Ken Sumrall425524d2012-06-14 20:55:28 -07001817 VolumeManager *vm = VolumeManager::Instance();
Jeff Sharkey9c484982015-03-31 10:35:33 -07001818 return vm->unmountAll();
Ken Sumrall425524d2012-06-14 20:55:28 -07001819}
1820
San Mehata19b2502010-01-06 10:33:53 -08001821bool VolumeManager::isMountpointMounted(const char *mp)
1822{
Yabin Cuid1104f72015-01-02 13:28:28 -08001823 FILE *fp = setmntent("/proc/mounts", "r");
1824 if (fp == NULL) {
San Mehat97ac40e2010-03-24 10:24:19 -07001825 SLOGE("Error opening /proc/mounts (%s)", strerror(errno));
San Mehata19b2502010-01-06 10:33:53 -08001826 return false;
1827 }
1828
Yabin Cuid1104f72015-01-02 13:28:28 -08001829 bool found_mp = false;
1830 mntent* mentry;
1831 while ((mentry = getmntent(fp)) != NULL) {
1832 if (strcmp(mentry->mnt_dir, mp) == 0) {
1833 found_mp = true;
1834 break;
San Mehata19b2502010-01-06 10:33:53 -08001835 }
San Mehata19b2502010-01-06 10:33:53 -08001836 }
Yabin Cuid1104f72015-01-02 13:28:28 -08001837 endmntent(fp);
1838 return found_mp;
San Mehata19b2502010-01-06 10:33:53 -08001839}
1840
Jeff Sharkey71ebe152013-09-17 17:24:38 -07001841int VolumeManager::mkdirs(char* path) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -07001842 // Only offer to create directories for paths managed by vold
1843 if (strncmp(path, "/storage/", 9) == 0) {
1844 // fs_mkdirs() does symlink checking and relative path enforcement
1845 return fs_mkdirs(path, 0700);
Jeff Sharkey71ebe152013-09-17 17:24:38 -07001846 } else {
Cylen Yao27cfee32014-05-02 19:23:42 +08001847 SLOGE("Failed to find mounted volume for %s", path);
Jeff Sharkey71ebe152013-09-17 17:24:38 -07001848 return -EINVAL;
1849 }
Jeff Sharkey71ebe152013-09-17 17:24:38 -07001850}