San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 1 | /* |
| 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 Cui | d1104f7 | 2015-01-02 13:28:28 -0800 | [diff] [blame] | 17 | #include <dirent.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 18 | #include <errno.h> |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 19 | #include <fcntl.h> |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 20 | #include <fts.h> |
Yabin Cui | d1104f7 | 2015-01-02 13:28:28 -0800 | [diff] [blame] | 21 | #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 Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 27 | #include <sys/stat.h> |
| 28 | #include <sys/types.h> |
Elliott Hughes | 0e08e84 | 2017-05-18 09:08:24 -0700 | [diff] [blame^] | 29 | #include <sys/sysmacros.h> |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 30 | #include <sys/wait.h> |
Yabin Cui | d1104f7 | 2015-01-02 13:28:28 -0800 | [diff] [blame] | 31 | #include <unistd.h> |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 32 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 33 | #include <linux/kdev_t.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 34 | |
| 35 | #define LOG_TAG "Vold" |
| 36 | |
Kenny Root | 7b18a7b | 2010-03-15 13:13:41 -0700 | [diff] [blame] | 37 | #include <openssl/md5.h> |
| 38 | |
Elliott Hughes | 7e128fb | 2015-12-04 15:50:53 -0800 | [diff] [blame] | 39 | #include <android-base/logging.h> |
| 40 | #include <android-base/stringprintf.h> |
Jeff Sharkey | 71ebe15 | 2013-09-17 17:24:38 -0700 | [diff] [blame] | 41 | #include <cutils/fs.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 42 | #include <cutils/log.h> |
| 43 | |
Robert Craig | b9e3ba5 | 2014-02-04 10:53:00 -0500 | [diff] [blame] | 44 | #include <selinux/android.h> |
| 45 | |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 46 | #include <sysutils/NetlinkEvent.h> |
| 47 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 48 | #include <private/android_filesystem_config.h> |
| 49 | |
Jeff Sharkey | 5a6bfca | 2015-05-14 20:33:55 -0700 | [diff] [blame] | 50 | #include "Benchmark.h" |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 51 | #include "EmulatedVolume.h" |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 52 | #include "VolumeManager.h" |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 53 | #include "NetlinkManager.h" |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 54 | #include "ResponseCode.h" |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 55 | #include "Loop.h" |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 56 | #include "fs/Ext4.h" |
| 57 | #include "fs/Vfat.h" |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 58 | #include "Utils.h" |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 59 | #include "Devmapper.h" |
San Mehat | 586536c | 2010-02-16 17:12:00 -0800 | [diff] [blame] | 60 | #include "Process.h" |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 61 | #include "Asec.h" |
Hiroaki Miyazawa | 14eab55 | 2015-02-04 13:29:15 +0900 | [diff] [blame] | 62 | #include "VoldUtil.h" |
Ken Sumrall | 29d8da8 | 2011-05-18 17:20:07 -0700 | [diff] [blame] | 63 | #include "cryptfs.h" |
San Mehat | 2396993 | 2010-01-09 07:08:06 -0800 | [diff] [blame] | 64 | |
Mike Lockwood | 97f2fc1 | 2011-06-07 10:51:38 -0700 | [diff] [blame] | 65 | #define MASS_STORAGE_FILE_PATH "/sys/class/android_usb/android0/f_mass_storage/lun/file" |
| 66 | |
Chih-Hung Hsieh | cc5d580 | 2016-05-11 15:05:05 -0700 | [diff] [blame] | 67 | #define ROUND_UP_POWER_OF_2(number, po2) (((!!((number) & ((1U << (po2)) - 1))) << (po2))\ |
| 68 | + ((number) & (~((1U << (po2)) - 1)))) |
Daniel Rosenberg | 6a74dca | 2014-05-23 13:47:00 -0700 | [diff] [blame] | 69 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 70 | using android::base::StringPrintf; |
| 71 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 72 | /* |
| 73 | * Path to external storage where *only* root can access ASEC image files |
| 74 | */ |
| 75 | const char *VolumeManager::SEC_ASECDIR_EXT = "/mnt/secure/asec"; |
| 76 | |
| 77 | /* |
| 78 | * Path to internal storage where *only* root can access ASEC image files |
| 79 | */ |
| 80 | const char *VolumeManager::SEC_ASECDIR_INT = "/data/app-asec"; |
| 81 | |
| 82 | /* |
| 83 | * Path to where secure containers are mounted |
| 84 | */ |
| 85 | const char *VolumeManager::ASECDIR = "/mnt/asec"; |
| 86 | |
| 87 | /* |
| 88 | * Path to where OBBs are mounted |
| 89 | */ |
| 90 | const char *VolumeManager::LOOPDIR = "/mnt/obb"; |
| 91 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 92 | static const char* kUserMountPath = "/mnt/user"; |
| 93 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 94 | static const unsigned int kMajorBlockMmc = 179; |
Yu Ning | 942d4e8 | 2016-01-08 17:36:47 +0800 | [diff] [blame] | 95 | static const unsigned int kMajorBlockExperimentalMin = 240; |
| 96 | static const unsigned int kMajorBlockExperimentalMax = 254; |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 97 | |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 98 | /* writes superblock at end of file or device given by name */ |
| 99 | static int writeSuperBlock(const char* name, struct asec_superblock *sb, unsigned int numImgSectors) { |
Jeff Sharkey | ce6a913 | 2015-04-08 21:07:21 -0700 | [diff] [blame] | 100 | int sbfd = open(name, O_RDWR | O_CLOEXEC); |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 101 | if (sbfd < 0) { |
| 102 | SLOGE("Failed to open %s for superblock write (%s)", name, strerror(errno)); |
| 103 | return -1; |
| 104 | } |
| 105 | |
| 106 | if (lseek(sbfd, (numImgSectors * 512), SEEK_SET) < 0) { |
| 107 | SLOGE("Failed to lseek for superblock (%s)", strerror(errno)); |
| 108 | close(sbfd); |
| 109 | return -1; |
| 110 | } |
| 111 | |
| 112 | if (write(sbfd, sb, sizeof(struct asec_superblock)) != sizeof(struct asec_superblock)) { |
| 113 | SLOGE("Failed to write superblock (%s)", strerror(errno)); |
| 114 | close(sbfd); |
| 115 | return -1; |
| 116 | } |
| 117 | close(sbfd); |
| 118 | return 0; |
| 119 | } |
| 120 | |
Mateusz Nowak | a4f48d0 | 2015-08-03 18:06:39 +0200 | [diff] [blame] | 121 | static unsigned long adjustSectorNumExt4(unsigned long numSectors) { |
Daniel Rosenberg | e9196fe | 2014-06-10 17:16:03 -0700 | [diff] [blame] | 122 | // Ext4 started to reserve 2% or 4096 clusters, whichever is smaller for |
| 123 | // preventing costly operations or unexpected ENOSPC error. |
| 124 | // Ext4::format() uses default block size without clustering. |
Mateusz Nowak | a4f48d0 | 2015-08-03 18:06:39 +0200 | [diff] [blame] | 125 | unsigned long clusterSectors = 4096 / 512; |
| 126 | unsigned long reservedSectors = (numSectors * 2)/100 + (numSectors % 50 > 0); |
Daniel Rosenberg | e9196fe | 2014-06-10 17:16:03 -0700 | [diff] [blame] | 127 | numSectors += reservedSectors > (4096 * clusterSectors) ? (4096 * clusterSectors) : reservedSectors; |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 128 | return ROUND_UP_POWER_OF_2(numSectors, 3); |
| 129 | } |
| 130 | |
Mateusz Nowak | a4f48d0 | 2015-08-03 18:06:39 +0200 | [diff] [blame] | 131 | static unsigned long adjustSectorNumFAT(unsigned long numSectors) { |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 132 | /* |
| 133 | * Add some headroom |
| 134 | */ |
Mateusz Nowak | a4f48d0 | 2015-08-03 18:06:39 +0200 | [diff] [blame] | 135 | unsigned long fatSize = (((numSectors * 4) / 512) + 1) * 2; |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 136 | numSectors += fatSize + 2; |
| 137 | /* |
| 138 | * FAT is aligned to 32 kb with 512b sectors. |
| 139 | */ |
| 140 | return ROUND_UP_POWER_OF_2(numSectors, 6); |
| 141 | } |
| 142 | |
| 143 | static int setupLoopDevice(char* buffer, size_t len, const char* asecFileName, const char* idHash, bool debug) { |
| 144 | if (Loop::lookupActive(idHash, buffer, len)) { |
| 145 | if (Loop::create(idHash, asecFileName, buffer, len)) { |
| 146 | SLOGE("ASEC loop device creation failed for %s (%s)", asecFileName, strerror(errno)); |
| 147 | return -1; |
| 148 | } |
| 149 | if (debug) { |
| 150 | SLOGD("New loop device created at %s", buffer); |
| 151 | } |
| 152 | } else { |
| 153 | if (debug) { |
| 154 | SLOGD("Found active loopback for %s at %s", asecFileName, buffer); |
| 155 | } |
| 156 | } |
| 157 | return 0; |
| 158 | } |
| 159 | |
Mateusz Nowak | a4f48d0 | 2015-08-03 18:06:39 +0200 | [diff] [blame] | 160 | static int setupDevMapperDevice(char* buffer, size_t len, const char* loopDevice, const char* asecFileName, const char* key, const char* idHash , unsigned long numImgSectors, bool* createdDMDevice, bool debug) { |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 161 | if (strcmp(key, "none")) { |
| 162 | if (Devmapper::lookupActive(idHash, buffer, len)) { |
| 163 | if (Devmapper::create(idHash, loopDevice, key, numImgSectors, |
| 164 | buffer, len)) { |
| 165 | SLOGE("ASEC device mapping failed for %s (%s)", asecFileName, strerror(errno)); |
| 166 | return -1; |
| 167 | } |
| 168 | if (debug) { |
| 169 | SLOGD("New devmapper instance created at %s", buffer); |
| 170 | } |
| 171 | } else { |
| 172 | if (debug) { |
| 173 | SLOGD("Found active devmapper for %s at %s", asecFileName, buffer); |
| 174 | } |
| 175 | } |
| 176 | *createdDMDevice = true; |
| 177 | } else { |
| 178 | strcpy(buffer, loopDevice); |
| 179 | *createdDMDevice = false; |
| 180 | } |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | static void waitForDevMapper(const char *dmDevice) { |
| 185 | /* |
| 186 | * Wait for the device mapper node to be created. Sometimes it takes a |
| 187 | * while. Wait for up to 1 second. We could also inspect incoming uevents, |
| 188 | * but that would take more effort. |
| 189 | */ |
| 190 | int tries = 25; |
| 191 | while (tries--) { |
| 192 | if (!access(dmDevice, F_OK) || errno != ENOENT) { |
| 193 | break; |
| 194 | } |
| 195 | usleep(40 * 1000); |
| 196 | } |
| 197 | } |
| 198 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 199 | VolumeManager *VolumeManager::sInstance = NULL; |
| 200 | |
| 201 | VolumeManager *VolumeManager::Instance() { |
| 202 | if (!sInstance) |
| 203 | sInstance = new VolumeManager(); |
| 204 | return sInstance; |
| 205 | } |
| 206 | |
| 207 | VolumeManager::VolumeManager() { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 208 | mDebug = false; |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 209 | mActiveContainers = new AsecIdCollection(); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 210 | mBroadcaster = NULL; |
Mike Lockwood | a28056b | 2010-10-28 15:21:24 -0400 | [diff] [blame] | 211 | mUmsSharingCount = 0; |
| 212 | mSavedDirtyRatio = -1; |
| 213 | // set dirty ratio to 0 when UMS is active |
| 214 | mUmsDirtyRatio = 0; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | VolumeManager::~VolumeManager() { |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 218 | delete mActiveContainers; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Kenny Root | 7b18a7b | 2010-03-15 13:13:41 -0700 | [diff] [blame] | 221 | char *VolumeManager::asecHash(const char *id, char *buffer, size_t len) { |
Kenny Root | acc9e7d | 2010-06-18 19:06:50 -0700 | [diff] [blame] | 222 | static const char* digits = "0123456789abcdef"; |
| 223 | |
Kenny Root | 7b18a7b | 2010-03-15 13:13:41 -0700 | [diff] [blame] | 224 | unsigned char sig[MD5_DIGEST_LENGTH]; |
| 225 | |
Kenny Root | acc9e7d | 2010-06-18 19:06:50 -0700 | [diff] [blame] | 226 | if (buffer == NULL) { |
| 227 | SLOGE("Destination buffer is NULL"); |
| 228 | errno = ESPIPE; |
| 229 | return NULL; |
| 230 | } else if (id == NULL) { |
| 231 | SLOGE("Source buffer is NULL"); |
| 232 | errno = ESPIPE; |
| 233 | return NULL; |
| 234 | } else if (len < MD5_ASCII_LENGTH_PLUS_NULL) { |
Colin Cross | 59846b6 | 2014-02-06 20:34:29 -0800 | [diff] [blame] | 235 | SLOGE("Target hash buffer size < %d bytes (%zu)", |
Kenny Root | acc9e7d | 2010-06-18 19:06:50 -0700 | [diff] [blame] | 236 | MD5_ASCII_LENGTH_PLUS_NULL, len); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 237 | errno = ESPIPE; |
| 238 | return NULL; |
| 239 | } |
Kenny Root | 7b18a7b | 2010-03-15 13:13:41 -0700 | [diff] [blame] | 240 | |
| 241 | MD5(reinterpret_cast<const unsigned char*>(id), strlen(id), sig); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 242 | |
Kenny Root | acc9e7d | 2010-06-18 19:06:50 -0700 | [diff] [blame] | 243 | char *p = buffer; |
Kenny Root | 7b18a7b | 2010-03-15 13:13:41 -0700 | [diff] [blame] | 244 | for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { |
Kenny Root | acc9e7d | 2010-06-18 19:06:50 -0700 | [diff] [blame] | 245 | *p++ = digits[sig[i] >> 4]; |
| 246 | *p++ = digits[sig[i] & 0x0F]; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 247 | } |
Kenny Root | acc9e7d | 2010-06-18 19:06:50 -0700 | [diff] [blame] | 248 | *p = '\0'; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 249 | |
| 250 | return buffer; |
| 251 | } |
| 252 | |
Jeff Sharkey | f1b996d | 2015-04-17 17:35:20 -0700 | [diff] [blame] | 253 | int VolumeManager::setDebug(bool enable) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 254 | mDebug = enable; |
Jeff Sharkey | f1b996d | 2015-04-17 17:35:20 -0700 | [diff] [blame] | 255 | return 0; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 256 | } |
| 257 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 258 | int VolumeManager::start() { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 259 | // Always start from a clean slate by unmounting everything in |
| 260 | // directories that we own, in case we crashed. |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 261 | unmountAll(); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 262 | |
| 263 | // Assume that we always have an emulated volume on internal |
| 264 | // storage; the framework will decide if it should be mounted. |
Jeff Sharkey | c8e04c5 | 2015-04-21 12:14:17 -0700 | [diff] [blame] | 265 | CHECK(mInternalEmulated == nullptr); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 266 | mInternalEmulated = std::shared_ptr<android::vold::VolumeBase>( |
Jeff Sharkey | 3161fb3 | 2015-04-12 16:03:33 -0700 | [diff] [blame] | 267 | new android::vold::EmulatedVolume("/data/media")); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 268 | mInternalEmulated->create(); |
| 269 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | int VolumeManager::stop() { |
Jeff Sharkey | c8e04c5 | 2015-04-21 12:14:17 -0700 | [diff] [blame] | 274 | CHECK(mInternalEmulated != nullptr); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 275 | mInternalEmulated->destroy(); |
| 276 | mInternalEmulated = nullptr; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 277 | return 0; |
| 278 | } |
| 279 | |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 280 | void VolumeManager::handleBlockEvent(NetlinkEvent *evt) { |
Jeff Sharkey | c8e04c5 | 2015-04-21 12:14:17 -0700 | [diff] [blame] | 281 | std::lock_guard<std::mutex> lock(mLock); |
| 282 | |
Jeff Sharkey | f1b996d | 2015-04-17 17:35:20 -0700 | [diff] [blame] | 283 | if (mDebug) { |
| 284 | LOG(VERBOSE) << "----------------"; |
| 285 | LOG(VERBOSE) << "handleBlockEvent with action " << (int) evt->getAction(); |
| 286 | evt->dump(); |
| 287 | } |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 288 | |
Mateusz Nowak | 6440379 | 2015-08-03 16:39:19 +0200 | [diff] [blame] | 289 | std::string eventPath(evt->findParam("DEVPATH")?evt->findParam("DEVPATH"):""); |
| 290 | std::string devType(evt->findParam("DEVTYPE")?evt->findParam("DEVTYPE"):""); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 291 | |
| 292 | if (devType != "disk") return; |
| 293 | |
| 294 | int major = atoi(evt->findParam("MAJOR")); |
| 295 | int minor = atoi(evt->findParam("MINOR")); |
| 296 | dev_t device = makedev(major, minor); |
| 297 | |
| 298 | switch (evt->getAction()) { |
| 299 | case NetlinkEvent::Action::kAdd: { |
Chih-Hung Hsieh | 11a2ce8 | 2016-07-27 14:11:02 -0700 | [diff] [blame] | 300 | for (const auto& source : mDiskSources) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 301 | if (source->matches(eventPath)) { |
Yu Ning | 942d4e8 | 2016-01-08 17:36:47 +0800 | [diff] [blame] | 302 | // For now, assume that MMC and virtio-blk (the latter is |
| 303 | // emulator-specific; see Disk.cpp for details) devices are SD, |
| 304 | // and that everything else is USB |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 305 | int flags = source->getFlags(); |
Yu Ning | 942d4e8 | 2016-01-08 17:36:47 +0800 | [diff] [blame] | 306 | if (major == kMajorBlockMmc |
| 307 | || (android::vold::IsRunningInEmulator() |
| 308 | && major >= (int) kMajorBlockExperimentalMin |
| 309 | && major <= (int) kMajorBlockExperimentalMax)) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 310 | flags |= android::vold::Disk::Flags::kSd; |
| 311 | } else { |
| 312 | flags |= android::vold::Disk::Flags::kUsb; |
| 313 | } |
| 314 | |
| 315 | auto disk = new android::vold::Disk(eventPath, device, |
| 316 | source->getNickname(), flags); |
| 317 | disk->create(); |
| 318 | mDisks.push_back(std::shared_ptr<android::vold::Disk>(disk)); |
| 319 | break; |
| 320 | } |
| 321 | } |
| 322 | break; |
| 323 | } |
| 324 | case NetlinkEvent::Action::kChange: { |
Jeff Sharkey | 7d9d011 | 2015-04-14 23:14:23 -0700 | [diff] [blame] | 325 | LOG(DEBUG) << "Disk at " << major << ":" << minor << " changed"; |
Chih-Hung Hsieh | 11a2ce8 | 2016-07-27 14:11:02 -0700 | [diff] [blame] | 326 | for (const auto& disk : mDisks) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 327 | if (disk->getDevice() == device) { |
| 328 | disk->readMetadata(); |
| 329 | disk->readPartitions(); |
| 330 | } |
| 331 | } |
| 332 | break; |
| 333 | } |
| 334 | case NetlinkEvent::Action::kRemove: { |
| 335 | auto i = mDisks.begin(); |
| 336 | while (i != mDisks.end()) { |
| 337 | if ((*i)->getDevice() == device) { |
| 338 | (*i)->destroy(); |
| 339 | i = mDisks.erase(i); |
| 340 | } else { |
| 341 | ++i; |
| 342 | } |
| 343 | } |
| 344 | break; |
| 345 | } |
| 346 | default: { |
| 347 | LOG(WARNING) << "Unexpected block event action " << (int) evt->getAction(); |
| 348 | break; |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | void VolumeManager::addDiskSource(const std::shared_ptr<DiskSource>& diskSource) { |
Wei Wang | 6b455c2 | 2017-01-20 11:52:33 -0800 | [diff] [blame] | 354 | std::lock_guard<std::mutex> lock(mLock); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 355 | mDiskSources.push_back(diskSource); |
| 356 | } |
| 357 | |
| 358 | std::shared_ptr<android::vold::Disk> VolumeManager::findDisk(const std::string& id) { |
| 359 | for (auto disk : mDisks) { |
| 360 | if (disk->getId() == id) { |
| 361 | return disk; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 362 | } |
| 363 | } |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 364 | return nullptr; |
| 365 | } |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 366 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 367 | std::shared_ptr<android::vold::VolumeBase> VolumeManager::findVolume(const std::string& id) { |
| 368 | if (mInternalEmulated->getId() == id) { |
| 369 | return mInternalEmulated; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 370 | } |
Chih-Hung Hsieh | 11a2ce8 | 2016-07-27 14:11:02 -0700 | [diff] [blame] | 371 | for (const auto& disk : mDisks) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 372 | auto vol = disk->findVolume(id); |
| 373 | if (vol != nullptr) { |
| 374 | return vol; |
| 375 | } |
| 376 | } |
| 377 | return nullptr; |
| 378 | } |
| 379 | |
Jeff Sharkey | c86ab6f | 2015-06-26 14:02:09 -0700 | [diff] [blame] | 380 | void VolumeManager::listVolumes(android::vold::VolumeBase::Type type, |
| 381 | std::list<std::string>& list) { |
| 382 | list.clear(); |
Chih-Hung Hsieh | 11a2ce8 | 2016-07-27 14:11:02 -0700 | [diff] [blame] | 383 | for (const auto& disk : mDisks) { |
Jeff Sharkey | c86ab6f | 2015-06-26 14:02:09 -0700 | [diff] [blame] | 384 | disk->listVolumes(type, list); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | nsecs_t VolumeManager::benchmarkPrivate(const std::string& id) { |
Jeff Sharkey | 5a6bfca | 2015-05-14 20:33:55 -0700 | [diff] [blame] | 389 | std::string path; |
Jeff Sharkey | c86ab6f | 2015-06-26 14:02:09 -0700 | [diff] [blame] | 390 | if (id == "private" || id == "null") { |
Jeff Sharkey | 5a6bfca | 2015-05-14 20:33:55 -0700 | [diff] [blame] | 391 | path = "/data"; |
Jeff Sharkey | c86ab6f | 2015-06-26 14:02:09 -0700 | [diff] [blame] | 392 | } else { |
| 393 | auto vol = findVolume(id); |
| 394 | if (vol != nullptr && vol->getState() == android::vold::VolumeBase::State::kMounted) { |
| 395 | path = vol->getPath(); |
| 396 | } |
Jeff Sharkey | 5a6bfca | 2015-05-14 20:33:55 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | if (path.empty()) { |
| 400 | LOG(WARNING) << "Failed to find volume for " << id; |
| 401 | return -1; |
| 402 | } |
| 403 | |
Jeff Sharkey | c86ab6f | 2015-06-26 14:02:09 -0700 | [diff] [blame] | 404 | return android::vold::BenchmarkPrivate(path); |
Jeff Sharkey | 5a6bfca | 2015-05-14 20:33:55 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Jeff Sharkey | bc40cc8 | 2015-06-18 14:25:08 -0700 | [diff] [blame] | 407 | int VolumeManager::forgetPartition(const std::string& partGuid) { |
| 408 | std::string normalizedGuid; |
| 409 | if (android::vold::NormalizeHex(partGuid, normalizedGuid)) { |
| 410 | LOG(WARNING) << "Invalid GUID " << partGuid; |
| 411 | return -1; |
| 412 | } |
| 413 | |
| 414 | std::string keyPath = android::vold::BuildKeyPath(normalizedGuid); |
| 415 | if (unlink(keyPath.c_str()) != 0) { |
| 416 | LOG(ERROR) << "Failed to unlink " << keyPath; |
| 417 | return -1; |
| 418 | } |
| 419 | |
| 420 | return 0; |
| 421 | } |
| 422 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 423 | int VolumeManager::linkPrimary(userid_t userId) { |
| 424 | std::string source(mPrimary->getPath()); |
| 425 | if (mPrimary->getType() == android::vold::VolumeBase::Type::kEmulated) { |
| 426 | source = StringPrintf("%s/%d", source.c_str(), userId); |
Jeff Sharkey | 32679a8 | 2015-07-21 14:22:01 -0700 | [diff] [blame] | 427 | fs_prepare_dir(source.c_str(), 0755, AID_ROOT, AID_ROOT); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | std::string target(StringPrintf("/mnt/user/%d/primary", userId)); |
| 431 | if (TEMP_FAILURE_RETRY(unlink(target.c_str()))) { |
| 432 | if (errno != ENOENT) { |
| 433 | SLOGW("Failed to unlink %s: %s", target.c_str(), strerror(errno)); |
| 434 | } |
| 435 | } |
Jeff Sharkey | 1bfb375 | 2015-04-29 15:22:23 -0700 | [diff] [blame] | 436 | LOG(DEBUG) << "Linking " << source << " to " << target; |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 437 | if (TEMP_FAILURE_RETRY(symlink(source.c_str(), target.c_str()))) { |
| 438 | SLOGW("Failed to link %s to %s: %s", source.c_str(), target.c_str(), |
| 439 | strerror(errno)); |
| 440 | return -errno; |
| 441 | } |
| 442 | return 0; |
| 443 | } |
| 444 | |
Jeff Sharkey | bd3038d | 2015-06-10 09:42:01 -0700 | [diff] [blame] | 445 | int VolumeManager::onUserAdded(userid_t userId, int userSerialNumber) { |
| 446 | mAddedUsers[userId] = userSerialNumber; |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | int VolumeManager::onUserRemoved(userid_t userId) { |
| 451 | mAddedUsers.erase(userId); |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | int VolumeManager::onUserStarted(userid_t userId) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 456 | // Note that sometimes the system will spin up processes from Zygote |
| 457 | // before actually starting the user, so we're okay if Zygote |
| 458 | // already created this directory. |
| 459 | std::string path(StringPrintf("%s/%d", kUserMountPath, userId)); |
| 460 | fs_prepare_dir(path.c_str(), 0755, AID_ROOT, AID_ROOT); |
| 461 | |
Jeff Sharkey | bd3038d | 2015-06-10 09:42:01 -0700 | [diff] [blame] | 462 | mStartedUsers.insert(userId); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 463 | if (mPrimary) { |
| 464 | linkPrimary(userId); |
| 465 | } |
| 466 | return 0; |
| 467 | } |
| 468 | |
Jeff Sharkey | bd3038d | 2015-06-10 09:42:01 -0700 | [diff] [blame] | 469 | int VolumeManager::onUserStopped(userid_t userId) { |
| 470 | mStartedUsers.erase(userId); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | int VolumeManager::setPrimary(const std::shared_ptr<android::vold::VolumeBase>& vol) { |
| 475 | mPrimary = vol; |
Jeff Sharkey | bd3038d | 2015-06-10 09:42:01 -0700 | [diff] [blame] | 476 | for (userid_t userId : mStartedUsers) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 477 | linkPrimary(userId); |
| 478 | } |
| 479 | return 0; |
| 480 | } |
| 481 | |
Jeff Sharkey | c7b5b57 | 2015-06-30 15:54:17 -0700 | [diff] [blame] | 482 | static int unmount_tree(const char* path) { |
| 483 | size_t path_len = strlen(path); |
| 484 | |
| 485 | FILE* fp = setmntent("/proc/mounts", "r"); |
| 486 | if (fp == NULL) { |
| 487 | ALOGE("Error opening /proc/mounts: %s", strerror(errno)); |
| 488 | return -errno; |
| 489 | } |
| 490 | |
| 491 | // Some volumes can be stacked on each other, so force unmount in |
| 492 | // reverse order to give us the best chance of success. |
| 493 | std::list<std::string> toUnmount; |
| 494 | mntent* mentry; |
| 495 | while ((mentry = getmntent(fp)) != NULL) { |
| 496 | if (strncmp(mentry->mnt_dir, path, path_len) == 0) { |
| 497 | toUnmount.push_front(std::string(mentry->mnt_dir)); |
| 498 | } |
| 499 | } |
| 500 | endmntent(fp); |
| 501 | |
Chih-Hung Hsieh | 11a2ce8 | 2016-07-27 14:11:02 -0700 | [diff] [blame] | 502 | for (const auto& path : toUnmount) { |
Jeff Sharkey | c7b5b57 | 2015-06-30 15:54:17 -0700 | [diff] [blame] | 503 | if (umount2(path.c_str(), MNT_DETACH)) { |
| 504 | ALOGW("Failed to unmount %s: %s", path.c_str(), strerror(errno)); |
| 505 | } |
| 506 | } |
| 507 | return 0; |
| 508 | } |
| 509 | |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 510 | int VolumeManager::remountUid(uid_t uid, const std::string& mode) { |
| 511 | LOG(DEBUG) << "Remounting " << uid << " as mode " << mode; |
| 512 | |
| 513 | DIR* dir; |
| 514 | struct dirent* de; |
| 515 | char rootName[PATH_MAX]; |
| 516 | char pidName[PATH_MAX]; |
| 517 | int pidFd; |
| 518 | int nsFd; |
| 519 | struct stat sb; |
| 520 | pid_t child; |
| 521 | |
| 522 | if (!(dir = opendir("/proc"))) { |
| 523 | PLOG(ERROR) << "Failed to opendir"; |
| 524 | return -1; |
| 525 | } |
| 526 | |
| 527 | // Figure out root namespace to compare against below |
Daichi Hirono | 10d3488 | 2016-01-29 14:33:51 +0900 | [diff] [blame] | 528 | if (android::vold::SaneReadLinkAt(dirfd(dir), "1/ns/mnt", rootName, PATH_MAX) == -1) { |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 529 | PLOG(ERROR) << "Failed to readlink"; |
| 530 | closedir(dir); |
| 531 | return -1; |
| 532 | } |
| 533 | |
| 534 | // Poke through all running PIDs look for apps running as UID |
| 535 | while ((de = readdir(dir))) { |
| 536 | pidFd = -1; |
| 537 | nsFd = -1; |
| 538 | |
| 539 | pidFd = openat(dirfd(dir), de->d_name, O_RDONLY | O_DIRECTORY | O_CLOEXEC); |
| 540 | if (pidFd < 0) { |
| 541 | goto next; |
| 542 | } |
| 543 | if (fstat(pidFd, &sb) != 0) { |
| 544 | PLOG(WARNING) << "Failed to stat " << de->d_name; |
| 545 | goto next; |
| 546 | } |
| 547 | if (sb.st_uid != uid) { |
| 548 | goto next; |
| 549 | } |
| 550 | |
| 551 | // Matches so far, but refuse to touch if in root namespace |
| 552 | LOG(DEBUG) << "Found matching PID " << de->d_name; |
Daichi Hirono | 10d3488 | 2016-01-29 14:33:51 +0900 | [diff] [blame] | 553 | if (android::vold::SaneReadLinkAt(pidFd, "ns/mnt", pidName, PATH_MAX) == -1) { |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 554 | PLOG(WARNING) << "Failed to read namespace for " << de->d_name; |
| 555 | goto next; |
| 556 | } |
| 557 | if (!strcmp(rootName, pidName)) { |
| 558 | LOG(WARNING) << "Skipping due to root namespace"; |
| 559 | goto next; |
| 560 | } |
| 561 | |
| 562 | // We purposefully leave the namespace open across the fork |
| 563 | nsFd = openat(pidFd, "ns/mnt", O_RDONLY); |
| 564 | if (nsFd < 0) { |
Jeff Sharkey | c7b5b57 | 2015-06-30 15:54:17 -0700 | [diff] [blame] | 565 | PLOG(WARNING) << "Failed to open namespace for " << de->d_name; |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 566 | goto next; |
| 567 | } |
| 568 | |
| 569 | if (!(child = fork())) { |
| 570 | if (setns(nsFd, CLONE_NEWNS) != 0) { |
Jeff Sharkey | c7b5b57 | 2015-06-30 15:54:17 -0700 | [diff] [blame] | 571 | PLOG(ERROR) << "Failed to setns for " << de->d_name; |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 572 | _exit(1); |
| 573 | } |
| 574 | |
Jeff Sharkey | c7b5b57 | 2015-06-30 15:54:17 -0700 | [diff] [blame] | 575 | unmount_tree("/storage"); |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 576 | |
| 577 | std::string storageSource; |
| 578 | if (mode == "default") { |
Jeff Sharkey | 1bd078f | 2015-08-06 11:40:00 -0700 | [diff] [blame] | 579 | storageSource = "/mnt/runtime/default"; |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 580 | } else if (mode == "read") { |
Jeff Sharkey | 1bd078f | 2015-08-06 11:40:00 -0700 | [diff] [blame] | 581 | storageSource = "/mnt/runtime/read"; |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 582 | } else if (mode == "write") { |
Jeff Sharkey | 1bd078f | 2015-08-06 11:40:00 -0700 | [diff] [blame] | 583 | storageSource = "/mnt/runtime/write"; |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 584 | } else { |
| 585 | // Sane default of no storage visible |
| 586 | _exit(0); |
| 587 | } |
| 588 | if (TEMP_FAILURE_RETRY(mount(storageSource.c_str(), "/storage", |
| 589 | NULL, MS_BIND | MS_REC | MS_SLAVE, NULL)) == -1) { |
Jeff Sharkey | c7b5b57 | 2015-06-30 15:54:17 -0700 | [diff] [blame] | 590 | PLOG(ERROR) << "Failed to mount " << storageSource << " for " |
| 591 | << de->d_name; |
| 592 | _exit(1); |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 593 | } |
Jeff Sharkey | c7b5b57 | 2015-06-30 15:54:17 -0700 | [diff] [blame] | 594 | |
| 595 | // Mount user-specific symlink helper into place |
| 596 | userid_t user_id = multiuser_get_user_id(uid); |
| 597 | std::string userSource(StringPrintf("/mnt/user/%d", user_id)); |
| 598 | if (TEMP_FAILURE_RETRY(mount(userSource.c_str(), "/storage/self", |
| 599 | NULL, MS_BIND, NULL)) == -1) { |
| 600 | PLOG(ERROR) << "Failed to mount " << userSource << " for " |
| 601 | << de->d_name; |
| 602 | _exit(1); |
| 603 | } |
| 604 | |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 605 | _exit(0); |
| 606 | } |
| 607 | |
| 608 | if (child == -1) { |
| 609 | PLOG(ERROR) << "Failed to fork"; |
| 610 | goto next; |
| 611 | } else { |
| 612 | TEMP_FAILURE_RETRY(waitpid(child, nullptr, 0)); |
| 613 | } |
| 614 | |
| 615 | next: |
| 616 | close(nsFd); |
| 617 | close(pidFd); |
| 618 | } |
| 619 | closedir(dir); |
| 620 | return 0; |
| 621 | } |
| 622 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 623 | int VolumeManager::reset() { |
| 624 | // Tear down all existing disks/volumes and start from a blank slate so |
| 625 | // newly connected framework hears all events. |
| 626 | mInternalEmulated->destroy(); |
| 627 | mInternalEmulated->create(); |
Chih-Hung Hsieh | 11a2ce8 | 2016-07-27 14:11:02 -0700 | [diff] [blame] | 628 | for (const auto& disk : mDisks) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 629 | disk->destroy(); |
| 630 | disk->create(); |
| 631 | } |
Jeff Sharkey | bd3038d | 2015-06-10 09:42:01 -0700 | [diff] [blame] | 632 | mAddedUsers.clear(); |
| 633 | mStartedUsers.clear(); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 634 | return 0; |
| 635 | } |
| 636 | |
Keun-young Park | a5bbb5e | 2017-03-13 18:02:50 -0700 | [diff] [blame] | 637 | // Can be called twice (sequentially) during shutdown. should be safe for that. |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 638 | int VolumeManager::shutdown() { |
Keun-young Park | a5bbb5e | 2017-03-13 18:02:50 -0700 | [diff] [blame] | 639 | if (mInternalEmulated == nullptr) { |
| 640 | return 0; // already shutdown |
| 641 | } |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 642 | mInternalEmulated->destroy(); |
Keun-young Park | a5bbb5e | 2017-03-13 18:02:50 -0700 | [diff] [blame] | 643 | mInternalEmulated = nullptr; |
Chih-Hung Hsieh | 11a2ce8 | 2016-07-27 14:11:02 -0700 | [diff] [blame] | 644 | for (const auto& disk : mDisks) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 645 | disk->destroy(); |
| 646 | } |
| 647 | mDisks.clear(); |
| 648 | return 0; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 651 | int VolumeManager::unmountAll() { |
Jeff Sharkey | c8e04c5 | 2015-04-21 12:14:17 -0700 | [diff] [blame] | 652 | std::lock_guard<std::mutex> lock(mLock); |
| 653 | |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 654 | // First, try gracefully unmounting all known devices |
| 655 | if (mInternalEmulated != nullptr) { |
| 656 | mInternalEmulated->unmount(); |
| 657 | } |
Chih-Hung Hsieh | 11a2ce8 | 2016-07-27 14:11:02 -0700 | [diff] [blame] | 658 | for (const auto& disk : mDisks) { |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 659 | disk->unmountAll(); |
| 660 | } |
| 661 | |
| 662 | // Worst case we might have some stale mounts lurking around, so |
| 663 | // force unmount those just to be safe. |
| 664 | FILE* fp = setmntent("/proc/mounts", "r"); |
| 665 | if (fp == NULL) { |
| 666 | SLOGE("Error opening /proc/mounts: %s", strerror(errno)); |
| 667 | return -errno; |
| 668 | } |
| 669 | |
| 670 | // Some volumes can be stacked on each other, so force unmount in |
| 671 | // reverse order to give us the best chance of success. |
| 672 | std::list<std::string> toUnmount; |
| 673 | mntent* mentry; |
| 674 | while ((mentry = getmntent(fp)) != NULL) { |
| 675 | if (strncmp(mentry->mnt_dir, "/mnt/", 5) == 0 |
| 676 | || strncmp(mentry->mnt_dir, "/storage/", 9) == 0) { |
| 677 | toUnmount.push_front(std::string(mentry->mnt_dir)); |
| 678 | } |
| 679 | } |
| 680 | endmntent(fp); |
| 681 | |
Chih-Hung Hsieh | 11a2ce8 | 2016-07-27 14:11:02 -0700 | [diff] [blame] | 682 | for (const auto& path : toUnmount) { |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 683 | SLOGW("Tearing down stale mount %s", path.c_str()); |
| 684 | android::vold::ForceUnmount(path); |
| 685 | } |
| 686 | |
| 687 | return 0; |
| 688 | } |
| 689 | |
Kenny Root | 508c0e1 | 2010-07-12 09:59:49 -0700 | [diff] [blame] | 690 | int VolumeManager::getObbMountPath(const char *sourceFile, char *mountPath, int mountPathLen) { |
| 691 | char idHash[33]; |
| 692 | if (!asecHash(sourceFile, idHash, sizeof(idHash))) { |
| 693 | SLOGE("Hash of '%s' failed (%s)", sourceFile, strerror(errno)); |
| 694 | return -1; |
| 695 | } |
| 696 | |
| 697 | memset(mountPath, 0, mountPathLen); |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 698 | int written = snprintf(mountPath, mountPathLen, "%s/%s", VolumeManager::LOOPDIR, idHash); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 699 | if ((written < 0) || (written >= mountPathLen)) { |
| 700 | errno = EINVAL; |
| 701 | return -1; |
| 702 | } |
Kenny Root | 508c0e1 | 2010-07-12 09:59:49 -0700 | [diff] [blame] | 703 | |
| 704 | if (access(mountPath, F_OK)) { |
| 705 | errno = ENOENT; |
| 706 | return -1; |
| 707 | } |
| 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 712 | int VolumeManager::getAsecMountPath(const char *id, char *buffer, int maxlen) { |
San Mehat | 88ac2c0 | 2010-03-23 11:15:58 -0700 | [diff] [blame] | 713 | char asecFileName[255]; |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 714 | |
Nick Kralevich | 0de7c61 | 2014-01-27 14:58:06 -0800 | [diff] [blame] | 715 | if (!isLegalAsecId(id)) { |
| 716 | SLOGE("getAsecMountPath: Invalid asec id \"%s\"", id); |
| 717 | errno = EINVAL; |
| 718 | return -1; |
| 719 | } |
| 720 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 721 | if (findAsec(id, asecFileName, sizeof(asecFileName))) { |
| 722 | SLOGE("Couldn't find ASEC %s", id); |
| 723 | return -1; |
| 724 | } |
San Mehat | 88ac2c0 | 2010-03-23 11:15:58 -0700 | [diff] [blame] | 725 | |
| 726 | memset(buffer, 0, maxlen); |
| 727 | if (access(asecFileName, F_OK)) { |
| 728 | errno = ENOENT; |
| 729 | return -1; |
| 730 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 731 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 732 | int written = snprintf(buffer, maxlen, "%s/%s", VolumeManager::ASECDIR, id); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 733 | if ((written < 0) || (written >= maxlen)) { |
| 734 | SLOGE("getAsecMountPath failed for %s: couldn't construct path in buffer", id); |
| 735 | errno = EINVAL; |
| 736 | return -1; |
| 737 | } |
| 738 | |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 739 | return 0; |
| 740 | } |
| 741 | |
Dianne Hackborn | 736910c | 2011-06-27 13:37:07 -0700 | [diff] [blame] | 742 | int VolumeManager::getAsecFilesystemPath(const char *id, char *buffer, int maxlen) { |
| 743 | char asecFileName[255]; |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 744 | |
Nick Kralevich | 0de7c61 | 2014-01-27 14:58:06 -0800 | [diff] [blame] | 745 | if (!isLegalAsecId(id)) { |
| 746 | SLOGE("getAsecFilesystemPath: Invalid asec id \"%s\"", id); |
| 747 | errno = EINVAL; |
| 748 | return -1; |
| 749 | } |
| 750 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 751 | if (findAsec(id, asecFileName, sizeof(asecFileName))) { |
| 752 | SLOGE("Couldn't find ASEC %s", id); |
| 753 | return -1; |
| 754 | } |
Dianne Hackborn | 736910c | 2011-06-27 13:37:07 -0700 | [diff] [blame] | 755 | |
| 756 | memset(buffer, 0, maxlen); |
| 757 | if (access(asecFileName, F_OK)) { |
| 758 | errno = ENOENT; |
| 759 | return -1; |
| 760 | } |
| 761 | |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 762 | int written = snprintf(buffer, maxlen, "%s", asecFileName); |
| 763 | if ((written < 0) || (written >= maxlen)) { |
| 764 | errno = EINVAL; |
| 765 | return -1; |
| 766 | } |
| 767 | |
Dianne Hackborn | 736910c | 2011-06-27 13:37:07 -0700 | [diff] [blame] | 768 | return 0; |
| 769 | } |
| 770 | |
Mateusz Nowak | a4f48d0 | 2015-08-03 18:06:39 +0200 | [diff] [blame] | 771 | int VolumeManager::createAsec(const char *id, unsigned long numSectors, const char *fstype, |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 772 | const char *key, const int ownerUid, bool isExternal) { |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 773 | struct asec_superblock sb; |
| 774 | memset(&sb, 0, sizeof(sb)); |
| 775 | |
Nick Kralevich | 0de7c61 | 2014-01-27 14:58:06 -0800 | [diff] [blame] | 776 | if (!isLegalAsecId(id)) { |
| 777 | SLOGE("createAsec: Invalid asec id \"%s\"", id); |
| 778 | errno = EINVAL; |
| 779 | return -1; |
| 780 | } |
| 781 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 782 | const bool wantFilesystem = strcmp(fstype, "none"); |
| 783 | bool usingExt4 = false; |
| 784 | if (wantFilesystem) { |
| 785 | usingExt4 = !strcmp(fstype, "ext4"); |
| 786 | if (usingExt4) { |
| 787 | sb.c_opts |= ASEC_SB_C_OPTS_EXT4; |
| 788 | } else if (strcmp(fstype, "fat")) { |
| 789 | SLOGE("Invalid filesystem type %s", fstype); |
| 790 | errno = EINVAL; |
| 791 | return -1; |
| 792 | } |
| 793 | } |
| 794 | |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 795 | sb.magic = ASEC_SB_MAGIC; |
| 796 | sb.ver = ASEC_SB_VER; |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 797 | |
San Mehat | d31e380 | 2010-02-18 08:37:45 -0800 | [diff] [blame] | 798 | if (numSectors < ((1024*1024)/512)) { |
Mateusz Nowak | a4f48d0 | 2015-08-03 18:06:39 +0200 | [diff] [blame] | 799 | SLOGE("Invalid container size specified (%lu sectors)", numSectors); |
San Mehat | d31e380 | 2010-02-18 08:37:45 -0800 | [diff] [blame] | 800 | errno = EINVAL; |
| 801 | return -1; |
| 802 | } |
| 803 | |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 804 | char asecFileName[255]; |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 805 | |
| 806 | if (!findAsec(id, asecFileName, sizeof(asecFileName))) { |
| 807 | SLOGE("ASEC file '%s' currently exists - destroy it first! (%s)", |
| 808 | asecFileName, strerror(errno)); |
| 809 | errno = EADDRINUSE; |
| 810 | return -1; |
| 811 | } |
| 812 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 813 | const char *asecDir = isExternal ? VolumeManager::SEC_ASECDIR_EXT : VolumeManager::SEC_ASECDIR_INT; |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 814 | |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 815 | int written = snprintf(asecFileName, sizeof(asecFileName), "%s/%s.asec", asecDir, id); |
| 816 | if ((written < 0) || (size_t(written) >= sizeof(asecFileName))) { |
| 817 | errno = EINVAL; |
| 818 | return -1; |
| 819 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 820 | |
| 821 | if (!access(asecFileName, F_OK)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 822 | SLOGE("ASEC file '%s' currently exists - destroy it first! (%s)", |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 823 | asecFileName, strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 824 | errno = EADDRINUSE; |
| 825 | return -1; |
| 826 | } |
| 827 | |
Mateusz Nowak | a4f48d0 | 2015-08-03 18:06:39 +0200 | [diff] [blame] | 828 | unsigned long numImgSectors; |
Daniel Rosenberg | 6a74dca | 2014-05-23 13:47:00 -0700 | [diff] [blame] | 829 | if (usingExt4) |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 830 | numImgSectors = adjustSectorNumExt4(numSectors); |
Daniel Rosenberg | 6a74dca | 2014-05-23 13:47:00 -0700 | [diff] [blame] | 831 | else |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 832 | numImgSectors = adjustSectorNumFAT(numSectors); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 833 | |
| 834 | // Add +1 for our superblock which is at the end |
| 835 | if (Loop::createImageFile(asecFileName, numImgSectors + 1)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 836 | SLOGE("ASEC image file creation failed (%s)", strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 837 | return -1; |
| 838 | } |
| 839 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 840 | char idHash[33]; |
| 841 | if (!asecHash(id, idHash, sizeof(idHash))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 842 | SLOGE("Hash of '%s' failed (%s)", id, strerror(errno)); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 843 | unlink(asecFileName); |
| 844 | return -1; |
| 845 | } |
| 846 | |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 847 | char loopDevice[255]; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 848 | if (Loop::create(idHash, asecFileName, loopDevice, sizeof(loopDevice))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 849 | SLOGE("ASEC loop device creation failed (%s)", strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 850 | unlink(asecFileName); |
| 851 | return -1; |
| 852 | } |
| 853 | |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 854 | char dmDevice[255]; |
| 855 | bool cleanupDm = false; |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 856 | |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 857 | if (strcmp(key, "none")) { |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 858 | // XXX: This is all we support for now |
| 859 | sb.c_cipher = ASEC_SB_C_CIPHER_TWOFISH; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 860 | if (Devmapper::create(idHash, loopDevice, key, numImgSectors, dmDevice, |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 861 | sizeof(dmDevice))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 862 | SLOGE("ASEC device mapping failed (%s)", strerror(errno)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 863 | Loop::destroyByDevice(loopDevice); |
| 864 | unlink(asecFileName); |
| 865 | return -1; |
| 866 | } |
| 867 | cleanupDm = true; |
| 868 | } else { |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 869 | sb.c_cipher = ASEC_SB_C_CIPHER_NONE; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 870 | strcpy(dmDevice, loopDevice); |
| 871 | } |
| 872 | |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 873 | /* |
| 874 | * Drop down the superblock at the end of the file |
| 875 | */ |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 876 | if (writeSuperBlock(loopDevice, &sb, numImgSectors)) { |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 877 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 878 | Devmapper::destroy(idHash); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 879 | } |
| 880 | Loop::destroyByDevice(loopDevice); |
| 881 | unlink(asecFileName); |
| 882 | return -1; |
| 883 | } |
| 884 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 885 | if (wantFilesystem) { |
| 886 | int formatStatus; |
rpcraig | a54e13a | 2012-09-21 14:17:08 -0400 | [diff] [blame] | 887 | char mountPoint[255]; |
| 888 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 889 | int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 890 | if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) { |
| 891 | SLOGE("ASEC fs format failed: couldn't construct mountPoint"); |
| 892 | if (cleanupDm) { |
| 893 | Devmapper::destroy(idHash); |
| 894 | } |
| 895 | Loop::destroyByDevice(loopDevice); |
| 896 | unlink(asecFileName); |
| 897 | return -1; |
| 898 | } |
rpcraig | a54e13a | 2012-09-21 14:17:08 -0400 | [diff] [blame] | 899 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 900 | if (usingExt4) { |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 901 | formatStatus = android::vold::ext4::Format(dmDevice, numImgSectors, mountPoint); |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 902 | } else { |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 903 | formatStatus = android::vold::vfat::Format(dmDevice, numImgSectors); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 904 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 905 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 906 | if (formatStatus < 0) { |
| 907 | SLOGE("ASEC fs format failed (%s)", strerror(errno)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 908 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 909 | Devmapper::destroy(idHash); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 910 | } |
San Mehat | eb13a90 | 2010-01-07 12:12:50 -0800 | [diff] [blame] | 911 | Loop::destroyByDevice(loopDevice); |
| 912 | unlink(asecFileName); |
| 913 | return -1; |
| 914 | } |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 915 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 916 | if (mkdir(mountPoint, 0000)) { |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 917 | if (errno != EEXIST) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 918 | SLOGE("Mountpoint creation failed (%s)", strerror(errno)); |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 919 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 920 | Devmapper::destroy(idHash); |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 921 | } |
| 922 | Loop::destroyByDevice(loopDevice); |
| 923 | unlink(asecFileName); |
| 924 | return -1; |
| 925 | } |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 926 | } |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 927 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 928 | int mountStatus; |
| 929 | if (usingExt4) { |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 930 | mountStatus = android::vold::ext4::Mount(dmDevice, mountPoint, |
| 931 | false, false, false); |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 932 | } else { |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 933 | mountStatus = android::vold::vfat::Mount(dmDevice, mountPoint, |
| 934 | false, false, false, ownerUid, 0, 0000, false); |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | if (mountStatus) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 938 | SLOGE("ASEC FAT mount failed (%s)", strerror(errno)); |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 939 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 940 | Devmapper::destroy(idHash); |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 941 | } |
| 942 | Loop::destroyByDevice(loopDevice); |
| 943 | unlink(asecFileName); |
| 944 | return -1; |
| 945 | } |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 946 | |
| 947 | if (usingExt4) { |
Jeff Sharkey | ce6a913 | 2015-04-08 21:07:21 -0700 | [diff] [blame] | 948 | int dirfd = open(mountPoint, O_DIRECTORY | O_CLOEXEC); |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 949 | if (dirfd >= 0) { |
| 950 | if (fchown(dirfd, ownerUid, AID_SYSTEM) |
| 951 | || fchmod(dirfd, S_IRUSR | S_IWUSR | S_IXUSR | S_ISGID | S_IRGRP | S_IXGRP)) { |
| 952 | SLOGI("Cannot chown/chmod new ASEC mount point %s", mountPoint); |
| 953 | } |
| 954 | close(dirfd); |
| 955 | } |
| 956 | } |
San Mehat | a1091cb | 2010-02-28 20:17:20 -0800 | [diff] [blame] | 957 | } else { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 958 | SLOGI("Created raw secure container %s (no filesystem)", id); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 959 | } |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 960 | |
Kenny Root | cbacf78 | 2010-09-24 15:11:48 -0700 | [diff] [blame] | 961 | mActiveContainers->push_back(new ContainerData(strdup(id), ASEC)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 962 | return 0; |
| 963 | } |
| 964 | |
Mateusz Nowak | a4f48d0 | 2015-08-03 18:06:39 +0200 | [diff] [blame] | 965 | int VolumeManager::resizeAsec(const char *id, unsigned long numSectors, const char *key) { |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 966 | char asecFileName[255]; |
| 967 | char mountPoint[255]; |
| 968 | bool cleanupDm = false; |
| 969 | |
| 970 | if (!isLegalAsecId(id)) { |
| 971 | SLOGE("resizeAsec: Invalid asec id \"%s\"", id); |
| 972 | errno = EINVAL; |
| 973 | return -1; |
| 974 | } |
| 975 | |
| 976 | if (findAsec(id, asecFileName, sizeof(asecFileName))) { |
| 977 | SLOGE("Couldn't find ASEC %s", id); |
| 978 | return -1; |
| 979 | } |
| 980 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 981 | int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id); |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 982 | if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) { |
| 983 | SLOGE("ASEC resize failed for %s: couldn't construct mountpoint", id); |
| 984 | return -1; |
| 985 | } |
| 986 | |
| 987 | if (isMountpointMounted(mountPoint)) { |
| 988 | SLOGE("ASEC %s mounted. Unmount before resizing", id); |
| 989 | errno = EBUSY; |
| 990 | return -1; |
| 991 | } |
| 992 | |
| 993 | struct asec_superblock sb; |
| 994 | int fd; |
Mateusz Nowak | a4f48d0 | 2015-08-03 18:06:39 +0200 | [diff] [blame] | 995 | unsigned long oldNumSec = 0; |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 996 | |
Jeff Sharkey | ce6a913 | 2015-04-08 21:07:21 -0700 | [diff] [blame] | 997 | if ((fd = open(asecFileName, O_RDONLY | O_CLOEXEC)) < 0) { |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 998 | SLOGE("Failed to open ASEC file (%s)", strerror(errno)); |
| 999 | return -1; |
| 1000 | } |
| 1001 | |
| 1002 | struct stat info; |
| 1003 | if (fstat(fd, &info) < 0) { |
| 1004 | SLOGE("Failed to get file size (%s)", strerror(errno)); |
| 1005 | close(fd); |
| 1006 | return -1; |
| 1007 | } |
| 1008 | |
| 1009 | oldNumSec = info.st_size / 512; |
| 1010 | |
Mateusz Nowak | a4f48d0 | 2015-08-03 18:06:39 +0200 | [diff] [blame] | 1011 | unsigned long numImgSectors; |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 1012 | if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) |
| 1013 | numImgSectors = adjustSectorNumExt4(numSectors); |
| 1014 | else |
| 1015 | numImgSectors = adjustSectorNumFAT(numSectors); |
| 1016 | /* |
| 1017 | * add one block for the superblock |
| 1018 | */ |
Mateusz Nowak | a4f48d0 | 2015-08-03 18:06:39 +0200 | [diff] [blame] | 1019 | SLOGD("Resizing from %lu sectors to %lu sectors", oldNumSec, numImgSectors + 1); |
Jeff Sharkey | 43ed123 | 2014-08-22 12:29:05 -0700 | [diff] [blame] | 1020 | if (oldNumSec == numImgSectors + 1) { |
| 1021 | SLOGW("Size unchanged; ignoring resize request"); |
| 1022 | return 0; |
| 1023 | } else if (oldNumSec > numImgSectors + 1) { |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 1024 | SLOGE("Only growing is currently supported."); |
| 1025 | close(fd); |
| 1026 | return -1; |
| 1027 | } |
| 1028 | |
| 1029 | /* |
| 1030 | * Try to read superblock. |
| 1031 | */ |
| 1032 | memset(&sb, 0, sizeof(struct asec_superblock)); |
| 1033 | if (lseek(fd, ((oldNumSec - 1) * 512), SEEK_SET) < 0) { |
| 1034 | SLOGE("lseek failed (%s)", strerror(errno)); |
| 1035 | close(fd); |
| 1036 | return -1; |
| 1037 | } |
| 1038 | if (read(fd, &sb, sizeof(struct asec_superblock)) != sizeof(struct asec_superblock)) { |
| 1039 | SLOGE("superblock read failed (%s)", strerror(errno)); |
| 1040 | close(fd); |
| 1041 | return -1; |
| 1042 | } |
| 1043 | close(fd); |
| 1044 | |
| 1045 | if (mDebug) { |
| 1046 | SLOGD("Container sb magic/ver (%.8x/%.2x)", sb.magic, sb.ver); |
| 1047 | } |
| 1048 | if (sb.magic != ASEC_SB_MAGIC || sb.ver != ASEC_SB_VER) { |
| 1049 | SLOGE("Bad container magic/version (%.8x/%.2x)", sb.magic, sb.ver); |
| 1050 | errno = EMEDIUMTYPE; |
| 1051 | return -1; |
| 1052 | } |
| 1053 | |
| 1054 | if (!(sb.c_opts & ASEC_SB_C_OPTS_EXT4)) { |
| 1055 | SLOGE("Only ext4 partitions are supported for resize"); |
| 1056 | errno = EINVAL; |
| 1057 | return -1; |
| 1058 | } |
| 1059 | |
| 1060 | if (Loop::resizeImageFile(asecFileName, numImgSectors + 1)) { |
| 1061 | SLOGE("Resize of ASEC image file failed. Could not resize %s", id); |
| 1062 | return -1; |
| 1063 | } |
| 1064 | |
| 1065 | /* |
| 1066 | * Drop down a copy of the superblock at the end of the file |
| 1067 | */ |
| 1068 | if (writeSuperBlock(asecFileName, &sb, numImgSectors)) |
| 1069 | goto fail; |
| 1070 | |
| 1071 | char idHash[33]; |
| 1072 | if (!asecHash(id, idHash, sizeof(idHash))) { |
| 1073 | SLOGE("Hash of '%s' failed (%s)", id, strerror(errno)); |
| 1074 | goto fail; |
| 1075 | } |
| 1076 | |
| 1077 | char loopDevice[255]; |
| 1078 | if (setupLoopDevice(loopDevice, sizeof(loopDevice), asecFileName, idHash, mDebug)) |
| 1079 | goto fail; |
| 1080 | |
| 1081 | char dmDevice[255]; |
| 1082 | |
| 1083 | if (setupDevMapperDevice(dmDevice, sizeof(dmDevice), loopDevice, asecFileName, key, idHash, numImgSectors, &cleanupDm, mDebug)) { |
| 1084 | Loop::destroyByDevice(loopDevice); |
| 1085 | goto fail; |
| 1086 | } |
| 1087 | |
| 1088 | /* |
| 1089 | * Wait for the device mapper node to be created. |
| 1090 | */ |
| 1091 | waitForDevMapper(dmDevice); |
| 1092 | |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 1093 | if (android::vold::ext4::Resize(dmDevice, numImgSectors)) { |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 1094 | SLOGE("Unable to resize %s (%s)", id, strerror(errno)); |
| 1095 | if (cleanupDm) { |
| 1096 | Devmapper::destroy(idHash); |
| 1097 | } |
| 1098 | Loop::destroyByDevice(loopDevice); |
| 1099 | goto fail; |
| 1100 | } |
| 1101 | |
| 1102 | return 0; |
| 1103 | fail: |
| 1104 | Loop::resizeImageFile(asecFileName, oldNumSec); |
| 1105 | return -1; |
| 1106 | } |
| 1107 | |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1108 | int VolumeManager::finalizeAsec(const char *id) { |
| 1109 | char asecFileName[255]; |
| 1110 | char loopDevice[255]; |
| 1111 | char mountPoint[255]; |
| 1112 | |
Nick Kralevich | 0de7c61 | 2014-01-27 14:58:06 -0800 | [diff] [blame] | 1113 | if (!isLegalAsecId(id)) { |
| 1114 | SLOGE("finalizeAsec: Invalid asec id \"%s\"", id); |
| 1115 | errno = EINVAL; |
| 1116 | return -1; |
| 1117 | } |
| 1118 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1119 | if (findAsec(id, asecFileName, sizeof(asecFileName))) { |
| 1120 | SLOGE("Couldn't find ASEC %s", id); |
| 1121 | return -1; |
| 1122 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1123 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1124 | char idHash[33]; |
| 1125 | if (!asecHash(id, idHash, sizeof(idHash))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1126 | SLOGE("Hash of '%s' failed (%s)", id, strerror(errno)); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1127 | return -1; |
| 1128 | } |
| 1129 | |
| 1130 | if (Loop::lookupActive(idHash, loopDevice, sizeof(loopDevice))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1131 | SLOGE("Unable to finalize %s (%s)", id, strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1132 | return -1; |
| 1133 | } |
| 1134 | |
Hiroaki Miyazawa | 14eab55 | 2015-02-04 13:29:15 +0900 | [diff] [blame] | 1135 | unsigned long nr_sec = 0; |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1136 | struct asec_superblock sb; |
| 1137 | |
| 1138 | if (Loop::lookupInfo(loopDevice, &sb, &nr_sec)) { |
| 1139 | return -1; |
| 1140 | } |
| 1141 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 1142 | int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 1143 | if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) { |
| 1144 | SLOGE("ASEC finalize failed: couldn't construct mountPoint"); |
| 1145 | return -1; |
| 1146 | } |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1147 | |
| 1148 | int result = 0; |
| 1149 | if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) { |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 1150 | result = android::vold::ext4::Mount(loopDevice, mountPoint, |
| 1151 | true, true, true); |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1152 | } else { |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 1153 | result = android::vold::vfat::Mount(loopDevice, mountPoint, |
| 1154 | true, true, true, 0, 0, 0227, false); |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | if (result) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1158 | SLOGE("ASEC finalize mount failed (%s)", strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1159 | return -1; |
| 1160 | } |
| 1161 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1162 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1163 | SLOGD("ASEC %s finalized", id); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1164 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1165 | return 0; |
| 1166 | } |
| 1167 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1168 | int VolumeManager::fixupAsecPermissions(const char *id, gid_t gid, const char* filename) { |
| 1169 | char asecFileName[255]; |
| 1170 | char loopDevice[255]; |
| 1171 | char mountPoint[255]; |
| 1172 | |
| 1173 | if (gid < AID_APP) { |
| 1174 | SLOGE("Group ID is not in application range"); |
| 1175 | return -1; |
| 1176 | } |
| 1177 | |
Nick Kralevich | 0de7c61 | 2014-01-27 14:58:06 -0800 | [diff] [blame] | 1178 | if (!isLegalAsecId(id)) { |
| 1179 | SLOGE("fixupAsecPermissions: Invalid asec id \"%s\"", id); |
| 1180 | errno = EINVAL; |
| 1181 | return -1; |
| 1182 | } |
| 1183 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1184 | if (findAsec(id, asecFileName, sizeof(asecFileName))) { |
| 1185 | SLOGE("Couldn't find ASEC %s", id); |
| 1186 | return -1; |
| 1187 | } |
| 1188 | |
| 1189 | char idHash[33]; |
| 1190 | if (!asecHash(id, idHash, sizeof(idHash))) { |
| 1191 | SLOGE("Hash of '%s' failed (%s)", id, strerror(errno)); |
| 1192 | return -1; |
| 1193 | } |
| 1194 | |
| 1195 | if (Loop::lookupActive(idHash, loopDevice, sizeof(loopDevice))) { |
| 1196 | SLOGE("Unable fix permissions during lookup on %s (%s)", id, strerror(errno)); |
| 1197 | return -1; |
| 1198 | } |
| 1199 | |
Hiroaki Miyazawa | 14eab55 | 2015-02-04 13:29:15 +0900 | [diff] [blame] | 1200 | unsigned long nr_sec = 0; |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1201 | struct asec_superblock sb; |
| 1202 | |
| 1203 | if (Loop::lookupInfo(loopDevice, &sb, &nr_sec)) { |
| 1204 | return -1; |
| 1205 | } |
| 1206 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 1207 | int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 1208 | if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) { |
| 1209 | SLOGE("Unable remount to fix permissions for %s: couldn't construct mountpoint", id); |
| 1210 | return -1; |
| 1211 | } |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1212 | |
| 1213 | int result = 0; |
| 1214 | if ((sb.c_opts & ASEC_SB_C_OPTS_EXT4) == 0) { |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 1218 | int ret = android::vold::ext4::Mount(loopDevice, mountPoint, |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1219 | false /* read-only */, |
| 1220 | true /* remount */, |
| 1221 | false /* executable */); |
| 1222 | if (ret) { |
| 1223 | SLOGE("Unable remount to fix permissions for %s (%s)", id, strerror(errno)); |
| 1224 | return -1; |
| 1225 | } |
| 1226 | |
| 1227 | char *paths[] = { mountPoint, NULL }; |
| 1228 | |
| 1229 | FTS *fts = fts_open(paths, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL); |
| 1230 | if (fts) { |
| 1231 | // Traverse the entire hierarchy and chown to system UID. |
| 1232 | for (FTSENT *ftsent = fts_read(fts); ftsent != NULL; ftsent = fts_read(fts)) { |
| 1233 | // We don't care about the lost+found directory. |
| 1234 | if (!strcmp(ftsent->fts_name, "lost+found")) { |
| 1235 | continue; |
| 1236 | } |
| 1237 | |
| 1238 | /* |
| 1239 | * There can only be one file marked as private right now. |
| 1240 | * This should be more robust, but it satisfies the requirements |
| 1241 | * we have for right now. |
| 1242 | */ |
| 1243 | const bool privateFile = !strcmp(ftsent->fts_name, filename); |
| 1244 | |
Jeff Sharkey | ce6a913 | 2015-04-08 21:07:21 -0700 | [diff] [blame] | 1245 | int fd = open(ftsent->fts_accpath, O_NOFOLLOW | O_CLOEXEC); |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1246 | if (fd < 0) { |
| 1247 | SLOGE("Couldn't open file %s: %s", ftsent->fts_accpath, strerror(errno)); |
| 1248 | result = -1; |
| 1249 | continue; |
| 1250 | } |
| 1251 | |
| 1252 | result |= fchown(fd, AID_SYSTEM, privateFile? gid : AID_SYSTEM); |
| 1253 | |
| 1254 | if (ftsent->fts_info & FTS_D) { |
Kenny Root | 1a673c8 | 2012-05-10 16:45:29 -0700 | [diff] [blame] | 1255 | result |= fchmod(fd, 0755); |
Kenny Root | 348c8ab | 2012-05-10 15:39:53 -0700 | [diff] [blame] | 1256 | } else if (ftsent->fts_info & FTS_F) { |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1257 | result |= fchmod(fd, privateFile ? 0640 : 0644); |
| 1258 | } |
Robert Craig | b9e3ba5 | 2014-02-04 10:53:00 -0500 | [diff] [blame] | 1259 | |
Stephen Smalley | 5093e61 | 2014-02-12 09:43:08 -0500 | [diff] [blame] | 1260 | if (selinux_android_restorecon(ftsent->fts_path, 0) < 0) { |
Robert Craig | b9e3ba5 | 2014-02-04 10:53:00 -0500 | [diff] [blame] | 1261 | SLOGE("restorecon failed for %s: %s\n", ftsent->fts_path, strerror(errno)); |
| 1262 | result |= -1; |
| 1263 | } |
| 1264 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1265 | close(fd); |
| 1266 | } |
| 1267 | fts_close(fts); |
| 1268 | |
| 1269 | // Finally make the directory readable by everyone. |
Jeff Sharkey | ce6a913 | 2015-04-08 21:07:21 -0700 | [diff] [blame] | 1270 | int dirfd = open(mountPoint, O_DIRECTORY | O_CLOEXEC); |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1271 | if (dirfd < 0 || fchmod(dirfd, 0755)) { |
| 1272 | SLOGE("Couldn't change owner of existing directory %s: %s", mountPoint, strerror(errno)); |
| 1273 | result |= -1; |
| 1274 | } |
| 1275 | close(dirfd); |
| 1276 | } else { |
| 1277 | result |= -1; |
| 1278 | } |
| 1279 | |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 1280 | result |= android::vold::ext4::Mount(loopDevice, mountPoint, |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1281 | true /* read-only */, |
| 1282 | true /* remount */, |
| 1283 | true /* execute */); |
| 1284 | |
| 1285 | if (result) { |
| 1286 | SLOGE("ASEC fix permissions failed (%s)", strerror(errno)); |
| 1287 | return -1; |
| 1288 | } |
| 1289 | |
| 1290 | if (mDebug) { |
| 1291 | SLOGD("ASEC %s permissions fixed", id); |
| 1292 | } |
| 1293 | return 0; |
| 1294 | } |
| 1295 | |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 1296 | int VolumeManager::renameAsec(const char *id1, const char *id2) { |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1297 | char asecFilename1[255]; |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 1298 | char *asecFilename2; |
| 1299 | char mountPoint[255]; |
| 1300 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1301 | const char *dir; |
| 1302 | |
Nick Kralevich | 0de7c61 | 2014-01-27 14:58:06 -0800 | [diff] [blame] | 1303 | if (!isLegalAsecId(id1)) { |
| 1304 | SLOGE("renameAsec: Invalid asec id1 \"%s\"", id1); |
| 1305 | errno = EINVAL; |
| 1306 | return -1; |
| 1307 | } |
| 1308 | |
| 1309 | if (!isLegalAsecId(id2)) { |
| 1310 | SLOGE("renameAsec: Invalid asec id2 \"%s\"", id2); |
| 1311 | errno = EINVAL; |
| 1312 | return -1; |
| 1313 | } |
| 1314 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1315 | if (findAsec(id1, asecFilename1, sizeof(asecFilename1), &dir)) { |
| 1316 | SLOGE("Couldn't find ASEC %s", id1); |
| 1317 | return -1; |
| 1318 | } |
| 1319 | |
| 1320 | asprintf(&asecFilename2, "%s/%s.asec", dir, id2); |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 1321 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 1322 | int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id1); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 1323 | if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) { |
| 1324 | SLOGE("Rename failed: couldn't construct mountpoint"); |
| 1325 | goto out_err; |
| 1326 | } |
| 1327 | |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 1328 | if (isMountpointMounted(mountPoint)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1329 | SLOGW("Rename attempt when src mounted"); |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 1330 | errno = EBUSY; |
| 1331 | goto out_err; |
| 1332 | } |
| 1333 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 1334 | written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id2); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 1335 | if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) { |
| 1336 | SLOGE("Rename failed: couldn't construct mountpoint2"); |
| 1337 | goto out_err; |
| 1338 | } |
| 1339 | |
San Mehat | 96956ed | 2010-02-24 08:42:51 -0800 | [diff] [blame] | 1340 | if (isMountpointMounted(mountPoint)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1341 | SLOGW("Rename attempt when dst mounted"); |
San Mehat | 96956ed | 2010-02-24 08:42:51 -0800 | [diff] [blame] | 1342 | errno = EBUSY; |
| 1343 | goto out_err; |
| 1344 | } |
| 1345 | |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 1346 | if (!access(asecFilename2, F_OK)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1347 | SLOGE("Rename attempt when dst exists"); |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 1348 | errno = EADDRINUSE; |
| 1349 | goto out_err; |
| 1350 | } |
| 1351 | |
| 1352 | if (rename(asecFilename1, asecFilename2)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1353 | SLOGE("Rename of '%s' to '%s' failed (%s)", asecFilename1, asecFilename2, strerror(errno)); |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 1354 | goto out_err; |
| 1355 | } |
| 1356 | |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 1357 | free(asecFilename2); |
| 1358 | return 0; |
| 1359 | |
| 1360 | out_err: |
San Mehat | 048b080 | 2010-01-23 08:17:06 -0800 | [diff] [blame] | 1361 | free(asecFilename2); |
| 1362 | return -1; |
| 1363 | } |
| 1364 | |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1365 | #define UNMOUNT_RETRIES 5 |
| 1366 | #define UNMOUNT_SLEEP_BETWEEN_RETRY_MS (1000 * 1000) |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 1367 | int VolumeManager::unmountAsec(const char *id, bool force) { |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1368 | char asecFileName[255]; |
| 1369 | char mountPoint[255]; |
| 1370 | |
Nick Kralevich | 0de7c61 | 2014-01-27 14:58:06 -0800 | [diff] [blame] | 1371 | if (!isLegalAsecId(id)) { |
| 1372 | SLOGE("unmountAsec: Invalid asec id \"%s\"", id); |
| 1373 | errno = EINVAL; |
| 1374 | return -1; |
| 1375 | } |
| 1376 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1377 | if (findAsec(id, asecFileName, sizeof(asecFileName))) { |
| 1378 | SLOGE("Couldn't find ASEC %s", id); |
| 1379 | return -1; |
| 1380 | } |
| 1381 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 1382 | int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 1383 | if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) { |
| 1384 | SLOGE("ASEC unmount failed for %s: couldn't construct mountpoint", id); |
| 1385 | return -1; |
| 1386 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1387 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1388 | char idHash[33]; |
| 1389 | if (!asecHash(id, idHash, sizeof(idHash))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1390 | SLOGE("Hash of '%s' failed (%s)", id, strerror(errno)); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1391 | return -1; |
| 1392 | } |
| 1393 | |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1394 | return unmountLoopImage(id, idHash, asecFileName, mountPoint, force); |
| 1395 | } |
| 1396 | |
Kenny Root | 508c0e1 | 2010-07-12 09:59:49 -0700 | [diff] [blame] | 1397 | int VolumeManager::unmountObb(const char *fileName, bool force) { |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1398 | char mountPoint[255]; |
| 1399 | |
| 1400 | char idHash[33]; |
| 1401 | if (!asecHash(fileName, idHash, sizeof(idHash))) { |
| 1402 | SLOGE("Hash of '%s' failed (%s)", fileName, strerror(errno)); |
| 1403 | return -1; |
| 1404 | } |
| 1405 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 1406 | int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::LOOPDIR, idHash); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 1407 | if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) { |
| 1408 | SLOGE("OBB unmount failed for %s: couldn't construct mountpoint", fileName); |
| 1409 | return -1; |
| 1410 | } |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1411 | |
| 1412 | return unmountLoopImage(fileName, idHash, fileName, mountPoint, force); |
| 1413 | } |
| 1414 | |
| 1415 | int VolumeManager::unmountLoopImage(const char *id, const char *idHash, |
| 1416 | const char *fileName, const char *mountPoint, bool force) { |
San Mehat | 0586d54 | 2010-01-12 15:38:59 -0800 | [diff] [blame] | 1417 | if (!isMountpointMounted(mountPoint)) { |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1418 | SLOGE("Unmount request for %s when not mounted", id); |
Kenny Root | 918e5f9 | 2010-09-30 18:00:52 -0700 | [diff] [blame] | 1419 | errno = ENOENT; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1420 | return -1; |
| 1421 | } |
San Mehat | 2396993 | 2010-01-09 07:08:06 -0800 | [diff] [blame] | 1422 | |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1423 | int i, rc; |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1424 | for (i = 1; i <= UNMOUNT_RETRIES; i++) { |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1425 | rc = umount(mountPoint); |
| 1426 | if (!rc) { |
| 1427 | break; |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1428 | } |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1429 | if (rc && (errno == EINVAL || errno == ENOENT)) { |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1430 | SLOGI("Container %s unmounted OK", id); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1431 | rc = 0; |
| 1432 | break; |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1433 | } |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1434 | SLOGW("%s unmount attempt %d failed (%s)", |
San Mehat | 8c940ef | 2010-02-13 14:19:53 -0800 | [diff] [blame] | 1435 | id, i, strerror(errno)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1436 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 1437 | int signal = 0; // default is to just complain |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 1438 | |
| 1439 | if (force) { |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1440 | if (i > (UNMOUNT_RETRIES - 2)) |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 1441 | signal = SIGKILL; |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1442 | else if (i > (UNMOUNT_RETRIES - 3)) |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 1443 | signal = SIGTERM; |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 1444 | } |
San Mehat | 8c940ef | 2010-02-13 14:19:53 -0800 | [diff] [blame] | 1445 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 1446 | Process::killProcessesWithOpenFiles(mountPoint, signal); |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1447 | usleep(UNMOUNT_SLEEP_BETWEEN_RETRY_MS); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | if (rc) { |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 1451 | errno = EBUSY; |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1452 | SLOGE("Failed to unmount container %s (%s)", id, strerror(errno)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1453 | return -1; |
| 1454 | } |
| 1455 | |
San Mehat | 12f4b89 | 2010-02-24 11:43:22 -0800 | [diff] [blame] | 1456 | int retries = 10; |
| 1457 | |
| 1458 | while(retries--) { |
| 1459 | if (!rmdir(mountPoint)) { |
| 1460 | break; |
| 1461 | } |
| 1462 | |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1463 | SLOGW("Failed to rmdir %s (%s)", mountPoint, strerror(errno)); |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1464 | usleep(UNMOUNT_SLEEP_BETWEEN_RETRY_MS); |
San Mehat | 12f4b89 | 2010-02-24 11:43:22 -0800 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | if (!retries) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1468 | SLOGE("Timed out trying to rmdir %s (%s)", mountPoint, strerror(errno)); |
San Mehat | f5c6198 | 2010-02-03 11:04:46 -0800 | [diff] [blame] | 1469 | } |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 1470 | |
Paul Lawrence | 60dec16 | 2014-09-02 10:52:15 -0700 | [diff] [blame] | 1471 | for (i=1; i <= UNMOUNT_RETRIES; i++) { |
| 1472 | if (Devmapper::destroy(idHash) && errno != ENXIO) { |
| 1473 | SLOGE("Failed to destroy devmapper instance (%s)", strerror(errno)); |
| 1474 | usleep(UNMOUNT_SLEEP_BETWEEN_RETRY_MS); |
| 1475 | continue; |
| 1476 | } else { |
| 1477 | break; |
| 1478 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | char loopDevice[255]; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1482 | if (!Loop::lookupActive(idHash, loopDevice, sizeof(loopDevice))) { |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1483 | Loop::destroyByDevice(loopDevice); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1484 | } else { |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1485 | SLOGW("Failed to find loop device for {%s} (%s)", fileName, strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1486 | } |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 1487 | |
| 1488 | AsecIdCollection::iterator it; |
| 1489 | for (it = mActiveContainers->begin(); it != mActiveContainers->end(); ++it) { |
Kenny Root | cbacf78 | 2010-09-24 15:11:48 -0700 | [diff] [blame] | 1490 | ContainerData* cd = *it; |
| 1491 | if (!strcmp(cd->id, id)) { |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 1492 | free(*it); |
| 1493 | mActiveContainers->erase(it); |
| 1494 | break; |
| 1495 | } |
| 1496 | } |
| 1497 | if (it == mActiveContainers->end()) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1498 | SLOGW("mActiveContainers is inconsistent!"); |
San Mehat | 8870516 | 2010-01-15 09:26:28 -0800 | [diff] [blame] | 1499 | } |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1500 | return 0; |
| 1501 | } |
| 1502 | |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 1503 | int VolumeManager::destroyAsec(const char *id, bool force) { |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1504 | char asecFileName[255]; |
| 1505 | char mountPoint[255]; |
| 1506 | |
Nick Kralevich | 0de7c61 | 2014-01-27 14:58:06 -0800 | [diff] [blame] | 1507 | if (!isLegalAsecId(id)) { |
| 1508 | SLOGE("destroyAsec: Invalid asec id \"%s\"", id); |
| 1509 | errno = EINVAL; |
| 1510 | return -1; |
| 1511 | } |
| 1512 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1513 | if (findAsec(id, asecFileName, sizeof(asecFileName))) { |
| 1514 | SLOGE("Couldn't find ASEC %s", id); |
| 1515 | return -1; |
| 1516 | } |
| 1517 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 1518 | int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 1519 | if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) { |
| 1520 | SLOGE("ASEC destroy failed for %s: couldn't construct mountpoint", id); |
| 1521 | return -1; |
| 1522 | } |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1523 | |
San Mehat | 0586d54 | 2010-01-12 15:38:59 -0800 | [diff] [blame] | 1524 | if (isMountpointMounted(mountPoint)) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1525 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1526 | SLOGD("Unmounting container before destroy"); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1527 | } |
San Mehat | 4ba8948 | 2010-02-18 09:00:18 -0800 | [diff] [blame] | 1528 | if (unmountAsec(id, force)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1529 | SLOGE("Failed to unmount asec %s for destroy (%s)", id, strerror(errno)); |
San Mehat | 0586d54 | 2010-01-12 15:38:59 -0800 | [diff] [blame] | 1530 | return -1; |
| 1531 | } |
| 1532 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1533 | |
San Mehat | 0586d54 | 2010-01-12 15:38:59 -0800 | [diff] [blame] | 1534 | if (unlink(asecFileName)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1535 | SLOGE("Failed to unlink asec '%s' (%s)", asecFileName, strerror(errno)); |
San Mehat | 0586d54 | 2010-01-12 15:38:59 -0800 | [diff] [blame] | 1536 | return -1; |
| 1537 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1538 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1539 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1540 | SLOGD("ASEC %s destroyed", id); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1541 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1542 | return 0; |
| 1543 | } |
| 1544 | |
Nick Kralevich | 0de7c61 | 2014-01-27 14:58:06 -0800 | [diff] [blame] | 1545 | /* |
| 1546 | * Legal ASEC ids consist of alphanumeric characters, '-', |
| 1547 | * '_', or '.'. ".." is not allowed. The first or last character |
| 1548 | * of the ASEC id cannot be '.' (dot). |
| 1549 | */ |
| 1550 | bool VolumeManager::isLegalAsecId(const char *id) const { |
| 1551 | size_t i; |
| 1552 | size_t len = strlen(id); |
| 1553 | |
| 1554 | if (len == 0) { |
| 1555 | return false; |
| 1556 | } |
| 1557 | if ((id[0] == '.') || (id[len - 1] == '.')) { |
| 1558 | return false; |
| 1559 | } |
| 1560 | |
| 1561 | for (i = 0; i < len; i++) { |
| 1562 | if (id[i] == '.') { |
| 1563 | // i=0 is guaranteed never to have a dot. See above. |
| 1564 | if (id[i-1] == '.') return false; |
| 1565 | continue; |
| 1566 | } |
| 1567 | if (id[i] == '_' || id[i] == '-') continue; |
| 1568 | if (id[i] >= 'a' && id[i] <= 'z') continue; |
| 1569 | if (id[i] >= 'A' && id[i] <= 'Z') continue; |
| 1570 | if (id[i] >= '0' && id[i] <= '9') continue; |
| 1571 | return false; |
| 1572 | } |
| 1573 | |
| 1574 | return true; |
| 1575 | } |
| 1576 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1577 | bool VolumeManager::isAsecInDirectory(const char *dir, const char *asecName) const { |
Jeff Sharkey | ce6a913 | 2015-04-08 21:07:21 -0700 | [diff] [blame] | 1578 | int dirfd = open(dir, O_DIRECTORY | O_CLOEXEC); |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1579 | if (dirfd < 0) { |
| 1580 | SLOGE("Couldn't open internal ASEC dir (%s)", strerror(errno)); |
Nick Kralevich | 25e581a | 2015-02-06 08:55:08 -0800 | [diff] [blame] | 1581 | return false; |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
Nick Kralevich | 25e581a | 2015-02-06 08:55:08 -0800 | [diff] [blame] | 1584 | struct stat sb; |
| 1585 | bool ret = (fstatat(dirfd, asecName, &sb, AT_SYMLINK_NOFOLLOW) == 0) |
| 1586 | && S_ISREG(sb.st_mode); |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1587 | |
| 1588 | close(dirfd); |
| 1589 | |
| 1590 | return ret; |
| 1591 | } |
| 1592 | |
| 1593 | int VolumeManager::findAsec(const char *id, char *asecPath, size_t asecPathLen, |
| 1594 | const char **directory) const { |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1595 | char *asecName; |
| 1596 | |
Nick Kralevich | 0de7c61 | 2014-01-27 14:58:06 -0800 | [diff] [blame] | 1597 | if (!isLegalAsecId(id)) { |
| 1598 | SLOGE("findAsec: Invalid asec id \"%s\"", id); |
| 1599 | errno = EINVAL; |
| 1600 | return -1; |
| 1601 | } |
| 1602 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1603 | if (asprintf(&asecName, "%s.asec", id) < 0) { |
| 1604 | SLOGE("Couldn't allocate string to write ASEC name"); |
| 1605 | return -1; |
| 1606 | } |
| 1607 | |
| 1608 | const char *dir; |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 1609 | if (isAsecInDirectory(VolumeManager::SEC_ASECDIR_INT, asecName)) { |
| 1610 | dir = VolumeManager::SEC_ASECDIR_INT; |
| 1611 | } else if (isAsecInDirectory(VolumeManager::SEC_ASECDIR_EXT, asecName)) { |
| 1612 | dir = VolumeManager::SEC_ASECDIR_EXT; |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1613 | } else { |
| 1614 | free(asecName); |
| 1615 | return -1; |
| 1616 | } |
| 1617 | |
| 1618 | if (directory != NULL) { |
| 1619 | *directory = dir; |
| 1620 | } |
| 1621 | |
| 1622 | if (asecPath != NULL) { |
| 1623 | int written = snprintf(asecPath, asecPathLen, "%s/%s", dir, asecName); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 1624 | if ((written < 0) || (size_t(written) >= asecPathLen)) { |
| 1625 | SLOGE("findAsec failed for %s: couldn't construct ASEC path", id); |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1626 | free(asecName); |
| 1627 | return -1; |
| 1628 | } |
| 1629 | } |
| 1630 | |
| 1631 | free(asecName); |
| 1632 | return 0; |
| 1633 | } |
| 1634 | |
Jeff Sharkey | 43ed123 | 2014-08-22 12:29:05 -0700 | [diff] [blame] | 1635 | int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid, bool readOnly) { |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1636 | char asecFileName[255]; |
| 1637 | char mountPoint[255]; |
| 1638 | |
Nick Kralevich | 0de7c61 | 2014-01-27 14:58:06 -0800 | [diff] [blame] | 1639 | if (!isLegalAsecId(id)) { |
| 1640 | SLOGE("mountAsec: Invalid asec id \"%s\"", id); |
| 1641 | errno = EINVAL; |
| 1642 | return -1; |
| 1643 | } |
| 1644 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1645 | if (findAsec(id, asecFileName, sizeof(asecFileName))) { |
| 1646 | SLOGE("Couldn't find ASEC %s", id); |
| 1647 | return -1; |
| 1648 | } |
| 1649 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 1650 | int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 1651 | if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) { |
Colin Cross | 59846b6 | 2014-02-06 20:34:29 -0800 | [diff] [blame] | 1652 | SLOGE("ASEC mount failed for %s: couldn't construct mountpoint", id); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 1653 | return -1; |
| 1654 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1655 | |
| 1656 | if (isMountpointMounted(mountPoint)) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1657 | SLOGE("ASEC %s already mounted", id); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1658 | errno = EBUSY; |
| 1659 | return -1; |
| 1660 | } |
| 1661 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1662 | char idHash[33]; |
| 1663 | if (!asecHash(id, idHash, sizeof(idHash))) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1664 | SLOGE("Hash of '%s' failed (%s)", id, strerror(errno)); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1665 | return -1; |
| 1666 | } |
Kenny Root | 7b18a7b | 2010-03-15 13:13:41 -0700 | [diff] [blame] | 1667 | |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1668 | char loopDevice[255]; |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 1669 | if (setupLoopDevice(loopDevice, sizeof(loopDevice), asecFileName, idHash, mDebug)) |
| 1670 | return -1; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1671 | |
| 1672 | char dmDevice[255]; |
| 1673 | bool cleanupDm = false; |
Tim Murray | 8439dc9 | 2014-12-15 11:56:11 -0800 | [diff] [blame] | 1674 | |
Hiroaki Miyazawa | 14eab55 | 2015-02-04 13:29:15 +0900 | [diff] [blame] | 1675 | unsigned long nr_sec = 0; |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 1676 | struct asec_superblock sb; |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 1677 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1678 | if (Loop::lookupInfo(loopDevice, &sb, &nr_sec)) { |
| 1679 | return -1; |
| 1680 | } |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 1681 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1682 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1683 | SLOGD("Container sb magic/ver (%.8x/%.2x)", sb.magic, sb.ver); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1684 | } |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 1685 | if (sb.magic != ASEC_SB_MAGIC || sb.ver != ASEC_SB_VER) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1686 | SLOGE("Bad container magic/version (%.8x/%.2x)", sb.magic, sb.ver); |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 1687 | Loop::destroyByDevice(loopDevice); |
| 1688 | errno = EMEDIUMTYPE; |
| 1689 | return -1; |
| 1690 | } |
| 1691 | nr_sec--; // We don't want the devmapping to extend onto our superblock |
| 1692 | |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 1693 | if (setupDevMapperDevice(dmDevice, sizeof(dmDevice), loopDevice, asecFileName, key, idHash , nr_sec, &cleanupDm, mDebug)) { |
| 1694 | Loop::destroyByDevice(loopDevice); |
| 1695 | return -1; |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1696 | } |
| 1697 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1698 | if (mkdir(mountPoint, 0000)) { |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1699 | if (errno != EEXIST) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1700 | SLOGE("Mountpoint creation failed (%s)", strerror(errno)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1701 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1702 | Devmapper::destroy(idHash); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1703 | } |
| 1704 | Loop::destroyByDevice(loopDevice); |
| 1705 | return -1; |
| 1706 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1707 | } |
| 1708 | |
Kenny Root | cdc2a1c | 2012-05-03 13:49:46 -0700 | [diff] [blame] | 1709 | /* |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 1710 | * Wait for the device mapper node to be created. |
Kenny Root | cdc2a1c | 2012-05-03 13:49:46 -0700 | [diff] [blame] | 1711 | */ |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 1712 | waitForDevMapper(dmDevice); |
Kenny Root | cdc2a1c | 2012-05-03 13:49:46 -0700 | [diff] [blame] | 1713 | |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1714 | int result; |
| 1715 | if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) { |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 1716 | result = android::vold::ext4::Mount(dmDevice, mountPoint, |
| 1717 | readOnly, false, readOnly); |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1718 | } else { |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 1719 | result = android::vold::vfat::Mount(dmDevice, mountPoint, |
| 1720 | readOnly, false, readOnly, ownerUid, 0, 0222, false); |
Kenny Root | 344ca10 | 2012-04-03 17:23:01 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | if (result) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1724 | SLOGE("ASEC mount failed (%s)", strerror(errno)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1725 | if (cleanupDm) { |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1726 | Devmapper::destroy(idHash); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1727 | } |
| 1728 | Loop::destroyByDevice(loopDevice); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1729 | return -1; |
| 1730 | } |
| 1731 | |
Kenny Root | cbacf78 | 2010-09-24 15:11:48 -0700 | [diff] [blame] | 1732 | mActiveContainers->push_back(new ContainerData(strdup(id), ASEC)); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1733 | if (mDebug) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1734 | SLOGD("ASEC %s mounted", id); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 1735 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1736 | return 0; |
| 1737 | } |
| 1738 | |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1739 | /** |
| 1740 | * Mounts an image file <code>img</code>. |
| 1741 | */ |
Jeff Sharkey | 6947904 | 2012-09-25 16:14:57 -0700 | [diff] [blame] | 1742 | int VolumeManager::mountObb(const char *img, const char *key, int ownerGid) { |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1743 | char mountPoint[255]; |
| 1744 | |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1745 | char idHash[33]; |
| 1746 | if (!asecHash(img, idHash, sizeof(idHash))) { |
| 1747 | SLOGE("Hash of '%s' failed (%s)", img, strerror(errno)); |
| 1748 | return -1; |
| 1749 | } |
| 1750 | |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 1751 | int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::LOOPDIR, idHash); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 1752 | if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) { |
Colin Cross | 59846b6 | 2014-02-06 20:34:29 -0800 | [diff] [blame] | 1753 | SLOGE("OBB mount failed for %s: couldn't construct mountpoint", img); |
rpcraig | d1c226f | 2012-10-09 06:58:16 -0400 | [diff] [blame] | 1754 | return -1; |
| 1755 | } |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1756 | |
| 1757 | if (isMountpointMounted(mountPoint)) { |
| 1758 | SLOGE("Image %s already mounted", img); |
| 1759 | errno = EBUSY; |
| 1760 | return -1; |
| 1761 | } |
| 1762 | |
| 1763 | char loopDevice[255]; |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 1764 | if (setupLoopDevice(loopDevice, sizeof(loopDevice), img, idHash, mDebug)) |
| 1765 | return -1; |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1766 | |
| 1767 | char dmDevice[255]; |
| 1768 | bool cleanupDm = false; |
| 1769 | int fd; |
Hiroaki Miyazawa | 14eab55 | 2015-02-04 13:29:15 +0900 | [diff] [blame] | 1770 | unsigned long nr_sec = 0; |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1771 | |
Jeff Sharkey | ce6a913 | 2015-04-08 21:07:21 -0700 | [diff] [blame] | 1772 | if ((fd = open(loopDevice, O_RDWR | O_CLOEXEC)) < 0) { |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1773 | SLOGE("Failed to open loopdevice (%s)", strerror(errno)); |
| 1774 | Loop::destroyByDevice(loopDevice); |
| 1775 | return -1; |
| 1776 | } |
| 1777 | |
Hiroaki Miyazawa | 14eab55 | 2015-02-04 13:29:15 +0900 | [diff] [blame] | 1778 | get_blkdev_size(fd, &nr_sec); |
| 1779 | if (nr_sec == 0) { |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1780 | SLOGE("Failed to get loop size (%s)", strerror(errno)); |
| 1781 | Loop::destroyByDevice(loopDevice); |
| 1782 | close(fd); |
| 1783 | return -1; |
| 1784 | } |
| 1785 | |
| 1786 | close(fd); |
| 1787 | |
Hiroaki Miyazawa | 14eab55 | 2015-02-04 13:29:15 +0900 | [diff] [blame] | 1788 | if (setupDevMapperDevice(dmDevice, sizeof(loopDevice), loopDevice, img,key, idHash, nr_sec, &cleanupDm, mDebug)) { |
Daniel Rosenberg | fcd34a0 | 2014-05-22 11:23:56 -0700 | [diff] [blame] | 1789 | Loop::destroyByDevice(loopDevice); |
| 1790 | return -1; |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | if (mkdir(mountPoint, 0755)) { |
| 1794 | if (errno != EEXIST) { |
| 1795 | SLOGE("Mountpoint creation failed (%s)", strerror(errno)); |
| 1796 | if (cleanupDm) { |
| 1797 | Devmapper::destroy(idHash); |
| 1798 | } |
| 1799 | Loop::destroyByDevice(loopDevice); |
| 1800 | return -1; |
| 1801 | } |
| 1802 | } |
| 1803 | |
yoshiyuki hama | 476a627 | 2015-01-28 16:37:23 +0900 | [diff] [blame] | 1804 | /* |
| 1805 | * Wait for the device mapper node to be created. |
| 1806 | */ |
| 1807 | waitForDevMapper(dmDevice); |
| 1808 | |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 1809 | if (android::vold::vfat::Mount(dmDevice, mountPoint, |
| 1810 | true, false, true, 0, ownerGid, 0227, false)) { |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1811 | SLOGE("Image mount failed (%s)", strerror(errno)); |
| 1812 | if (cleanupDm) { |
| 1813 | Devmapper::destroy(idHash); |
| 1814 | } |
| 1815 | Loop::destroyByDevice(loopDevice); |
| 1816 | return -1; |
| 1817 | } |
| 1818 | |
Kenny Root | cbacf78 | 2010-09-24 15:11:48 -0700 | [diff] [blame] | 1819 | mActiveContainers->push_back(new ContainerData(strdup(img), OBB)); |
Kenny Root | fb7c4d5 | 2010-06-30 18:48:41 -0700 | [diff] [blame] | 1820 | if (mDebug) { |
| 1821 | SLOGD("Image %s mounted", img); |
| 1822 | } |
| 1823 | return 0; |
| 1824 | } |
| 1825 | |
Kenny Root | 508c0e1 | 2010-07-12 09:59:49 -0700 | [diff] [blame] | 1826 | int VolumeManager::listMountedObbs(SocketClient* cli) { |
Yabin Cui | d1104f7 | 2015-01-02 13:28:28 -0800 | [diff] [blame] | 1827 | FILE *fp = setmntent("/proc/mounts", "r"); |
| 1828 | if (fp == NULL) { |
Kenny Root | 508c0e1 | 2010-07-12 09:59:49 -0700 | [diff] [blame] | 1829 | SLOGE("Error opening /proc/mounts (%s)", strerror(errno)); |
| 1830 | return -1; |
| 1831 | } |
| 1832 | |
| 1833 | // Create a string to compare against that has a trailing slash |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 1834 | int loopDirLen = strlen(VolumeManager::LOOPDIR); |
Kenny Root | 508c0e1 | 2010-07-12 09:59:49 -0700 | [diff] [blame] | 1835 | char loopDir[loopDirLen + 2]; |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 1836 | strcpy(loopDir, VolumeManager::LOOPDIR); |
Kenny Root | 508c0e1 | 2010-07-12 09:59:49 -0700 | [diff] [blame] | 1837 | loopDir[loopDirLen++] = '/'; |
| 1838 | loopDir[loopDirLen] = '\0'; |
| 1839 | |
Yabin Cui | d1104f7 | 2015-01-02 13:28:28 -0800 | [diff] [blame] | 1840 | mntent* mentry; |
| 1841 | while ((mentry = getmntent(fp)) != NULL) { |
| 1842 | if (!strncmp(mentry->mnt_dir, loopDir, loopDirLen)) { |
Jeff Sharkey | ce6a913 | 2015-04-08 21:07:21 -0700 | [diff] [blame] | 1843 | int fd = open(mentry->mnt_fsname, O_RDONLY | O_CLOEXEC); |
Kenny Root | 508c0e1 | 2010-07-12 09:59:49 -0700 | [diff] [blame] | 1844 | if (fd >= 0) { |
| 1845 | struct loop_info64 li; |
| 1846 | if (ioctl(fd, LOOP_GET_STATUS64, &li) >= 0) { |
| 1847 | cli->sendMsg(ResponseCode::AsecListResult, |
| 1848 | (const char*) li.lo_file_name, false); |
| 1849 | } |
| 1850 | close(fd); |
| 1851 | } |
| 1852 | } |
| 1853 | } |
Yabin Cui | d1104f7 | 2015-01-02 13:28:28 -0800 | [diff] [blame] | 1854 | endmntent(fp); |
Kenny Root | 508c0e1 | 2010-07-12 09:59:49 -0700 | [diff] [blame] | 1855 | return 0; |
| 1856 | } |
| 1857 | |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 1858 | extern "C" int vold_unmountAll(void) { |
Ken Sumrall | 425524d | 2012-06-14 20:55:28 -0700 | [diff] [blame] | 1859 | VolumeManager *vm = VolumeManager::Instance(); |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 1860 | return vm->unmountAll(); |
Ken Sumrall | 425524d | 2012-06-14 20:55:28 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1863 | bool VolumeManager::isMountpointMounted(const char *mp) |
| 1864 | { |
Yabin Cui | d1104f7 | 2015-01-02 13:28:28 -0800 | [diff] [blame] | 1865 | FILE *fp = setmntent("/proc/mounts", "r"); |
| 1866 | if (fp == NULL) { |
San Mehat | 97ac40e | 2010-03-24 10:24:19 -0700 | [diff] [blame] | 1867 | SLOGE("Error opening /proc/mounts (%s)", strerror(errno)); |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1868 | return false; |
| 1869 | } |
| 1870 | |
Yabin Cui | d1104f7 | 2015-01-02 13:28:28 -0800 | [diff] [blame] | 1871 | bool found_mp = false; |
| 1872 | mntent* mentry; |
| 1873 | while ((mentry = getmntent(fp)) != NULL) { |
| 1874 | if (strcmp(mentry->mnt_dir, mp) == 0) { |
| 1875 | found_mp = true; |
| 1876 | break; |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1877 | } |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1878 | } |
Yabin Cui | d1104f7 | 2015-01-02 13:28:28 -0800 | [diff] [blame] | 1879 | endmntent(fp); |
| 1880 | return found_mp; |
San Mehat | a19b250 | 2010-01-06 10:33:53 -0800 | [diff] [blame] | 1881 | } |
| 1882 | |
Jeff Sharkey | 71ebe15 | 2013-09-17 17:24:38 -0700 | [diff] [blame] | 1883 | int VolumeManager::mkdirs(char* path) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 1884 | // Only offer to create directories for paths managed by vold |
| 1885 | if (strncmp(path, "/storage/", 9) == 0) { |
| 1886 | // fs_mkdirs() does symlink checking and relative path enforcement |
| 1887 | return fs_mkdirs(path, 0700); |
Jeff Sharkey | 71ebe15 | 2013-09-17 17:24:38 -0700 | [diff] [blame] | 1888 | } else { |
Cylen Yao | 27cfee3 | 2014-05-02 19:23:42 +0800 | [diff] [blame] | 1889 | SLOGE("Failed to find mounted volume for %s", path); |
Jeff Sharkey | 71ebe15 | 2013-09-17 17:24:38 -0700 | [diff] [blame] | 1890 | return -EINVAL; |
| 1891 | } |
Jeff Sharkey | 71ebe15 | 2013-09-17 17:24:38 -0700 | [diff] [blame] | 1892 | } |