Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 17 | #include "PublicVolume.h" |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 18 | |
| 19 | #include "AppFuseUtil.h" |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 20 | #include "Utils.h" |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 21 | #include "VolumeManager.h" |
Jeff Sharkey | 37ba125 | 2018-01-19 10:55:18 +0900 | [diff] [blame] | 22 | #include "fs/Exfat.h" |
| 23 | #include "fs/Vfat.h" |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 24 | |
Elliott Hughes | 7e128fb | 2015-12-04 15:50:53 -0800 | [diff] [blame] | 25 | #include <android-base/logging.h> |
Sudheer Shanka | 40ab674 | 2018-09-18 13:07:45 -0700 | [diff] [blame] | 26 | #include <android-base/properties.h> |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 27 | #include <android-base/stringprintf.h> |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 28 | #include <cutils/fs.h> |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 29 | #include <private/android_filesystem_config.h> |
Jeff Sharkey | 7bdf4d5 | 2017-09-18 14:47:10 -0600 | [diff] [blame] | 30 | #include <utils/Timers.h> |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 31 | |
| 32 | #include <fcntl.h> |
| 33 | #include <stdlib.h> |
| 34 | #include <sys/mount.h> |
| 35 | #include <sys/stat.h> |
Elliott Hughes | 0e08e84 | 2017-05-18 09:08:24 -0700 | [diff] [blame] | 36 | #include <sys/sysmacros.h> |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 37 | #include <sys/types.h> |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 38 | #include <sys/wait.h> |
| 39 | |
Sudheer Shanka | 40ab674 | 2018-09-18 13:07:45 -0700 | [diff] [blame] | 40 | using android::base::GetBoolProperty; |
Dan Albert | ae9e890 | 2015-03-16 10:35:17 -0700 | [diff] [blame] | 41 | using android::base::StringPrintf; |
| 42 | |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 43 | namespace android { |
| 44 | namespace vold { |
| 45 | |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 46 | static const char* kFusePath = "/system/bin/sdcard"; |
| 47 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 48 | static const char* kAsecPath = "/mnt/secure/asec"; |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 49 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 50 | PublicVolume::PublicVolume(dev_t device) : VolumeBase(Type::kPublic), mDevice(device), mFusePid(0) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 51 | setId(StringPrintf("public:%u,%u", major(device), minor(device))); |
| 52 | mDevPath = StringPrintf("/dev/block/vold/%s", getId().c_str()); |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 55 | PublicVolume::~PublicVolume() {} |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 56 | |
| 57 | status_t PublicVolume::readMetadata() { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 58 | status_t res = ReadMetadataUntrusted(mDevPath, &mFsType, &mFsUuid, &mFsLabel); |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 59 | |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 60 | auto listener = getListener(); |
| 61 | if (listener) listener->onVolumeMetadataChanged(getId(), mFsType, mFsUuid, mFsLabel); |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 62 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 63 | return res; |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | status_t PublicVolume::initAsecStage() { |
| 67 | std::string legacyPath(mRawPath + "/android_secure"); |
| 68 | std::string securePath(mRawPath + "/.android_secure"); |
| 69 | |
| 70 | // Recover legacy secure path |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 71 | if (!access(legacyPath.c_str(), R_OK | X_OK) && access(securePath.c_str(), R_OK | X_OK)) { |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 72 | if (rename(legacyPath.c_str(), securePath.c_str())) { |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 73 | PLOG(WARNING) << getId() << " failed to rename legacy ASEC dir"; |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 77 | if (TEMP_FAILURE_RETRY(mkdir(securePath.c_str(), 0700))) { |
| 78 | if (errno != EEXIST) { |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 79 | PLOG(WARNING) << getId() << " creating ASEC stage failed"; |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 80 | return -errno; |
| 81 | } |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 82 | } |
| 83 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 84 | BindMount(securePath, kAsecPath); |
| 85 | |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 86 | return OK; |
| 87 | } |
| 88 | |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 89 | status_t PublicVolume::doCreate() { |
| 90 | return CreateDeviceNode(mDevPath, mDevice); |
| 91 | } |
| 92 | |
| 93 | status_t PublicVolume::doDestroy() { |
| 94 | return DestroyDeviceNode(mDevPath); |
| 95 | } |
| 96 | |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 97 | status_t PublicVolume::doMount() { |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 98 | readMetadata(); |
| 99 | |
Jeff Sharkey | 37ba125 | 2018-01-19 10:55:18 +0900 | [diff] [blame] | 100 | if (mFsType == "vfat" && vfat::IsSupported()) { |
| 101 | if (vfat::Check(mDevPath)) { |
| 102 | LOG(ERROR) << getId() << " failed filesystem check"; |
| 103 | return -EIO; |
| 104 | } |
| 105 | } else if (mFsType == "exfat" && exfat::IsSupported()) { |
| 106 | if (exfat::Check(mDevPath)) { |
| 107 | LOG(ERROR) << getId() << " failed filesystem check"; |
| 108 | return -EIO; |
| 109 | } |
| 110 | } else { |
Makoto Onuki | c82c9ce | 2015-06-24 13:30:45 -0700 | [diff] [blame] | 111 | LOG(ERROR) << getId() << " unsupported filesystem " << mFsType; |
| 112 | return -EIO; |
| 113 | } |
| 114 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 115 | // Use UUID as stable name, if available |
| 116 | std::string stableName = getId(); |
| 117 | if (!mFsUuid.empty()) { |
Jeff Sharkey | f0121c5 | 2015-04-06 14:08:45 -0700 | [diff] [blame] | 118 | stableName = mFsUuid; |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | mRawPath = StringPrintf("/mnt/media_rw/%s", stableName.c_str()); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 122 | |
Jeff Sharkey | 1bd078f | 2015-08-06 11:40:00 -0700 | [diff] [blame] | 123 | mFuseDefault = StringPrintf("/mnt/runtime/default/%s", stableName.c_str()); |
| 124 | mFuseRead = StringPrintf("/mnt/runtime/read/%s", stableName.c_str()); |
| 125 | mFuseWrite = StringPrintf("/mnt/runtime/write/%s", stableName.c_str()); |
Sudheer Shanka | dd4bb17 | 2019-01-16 23:35:49 -0800 | [diff] [blame] | 126 | mFuseFull = StringPrintf("/mnt/runtime/full/%s", stableName.c_str()); |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 127 | |
| 128 | setInternalPath(mRawPath); |
Jeff Sharkey | 8474ee3 | 2015-07-30 16:54:23 -0700 | [diff] [blame] | 129 | if (getMountFlags() & MountFlags::kVisible) { |
| 130 | setPath(StringPrintf("/storage/%s", stableName.c_str())); |
| 131 | } else { |
| 132 | setPath(mRawPath); |
| 133 | } |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 134 | |
Qin Chao | e0074f1 | 2015-12-15 15:20:41 +0800 | [diff] [blame] | 135 | if (fs_prepare_dir(mRawPath.c_str(), 0700, AID_ROOT, AID_ROOT)) { |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 136 | PLOG(ERROR) << getId() << " failed to create mount points"; |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 137 | return -errno; |
| 138 | } |
| 139 | |
Jeff Sharkey | 37ba125 | 2018-01-19 10:55:18 +0900 | [diff] [blame] | 140 | if (mFsType == "vfat") { |
| 141 | if (vfat::Mount(mDevPath, mRawPath, false, false, false, AID_MEDIA_RW, AID_MEDIA_RW, 0007, |
| 142 | true)) { |
| 143 | PLOG(ERROR) << getId() << " failed to mount " << mDevPath; |
| 144 | return -EIO; |
| 145 | } |
| 146 | } else if (mFsType == "exfat") { |
| 147 | if (exfat::Mount(mDevPath, mRawPath, AID_MEDIA_RW, AID_MEDIA_RW, 0007)) { |
| 148 | PLOG(ERROR) << getId() << " failed to mount " << mDevPath; |
| 149 | return -EIO; |
| 150 | } |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Jeff Sharkey | f1b996d | 2015-04-17 17:35:20 -0700 | [diff] [blame] | 153 | if (getMountFlags() & MountFlags::kPrimary) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 154 | initAsecStage(); |
| 155 | } |
| 156 | |
Jeff Sharkey | c7b5b57 | 2015-06-30 15:54:17 -0700 | [diff] [blame] | 157 | if (!(getMountFlags() & MountFlags::kVisible)) { |
| 158 | // Not visible to apps, so no need to spin up FUSE |
| 159 | return OK; |
| 160 | } |
| 161 | |
Qin Chao | e0074f1 | 2015-12-15 15:20:41 +0800 | [diff] [blame] | 162 | if (fs_prepare_dir(mFuseDefault.c_str(), 0700, AID_ROOT, AID_ROOT) || |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 163 | fs_prepare_dir(mFuseRead.c_str(), 0700, AID_ROOT, AID_ROOT) || |
Sudheer Shanka | dd4bb17 | 2019-01-16 23:35:49 -0800 | [diff] [blame] | 164 | fs_prepare_dir(mFuseWrite.c_str(), 0700, AID_ROOT, AID_ROOT) || |
| 165 | fs_prepare_dir(mFuseFull.c_str(), 0700, AID_ROOT, AID_ROOT)) { |
Qin Chao | e0074f1 | 2015-12-15 15:20:41 +0800 | [diff] [blame] | 166 | PLOG(ERROR) << getId() << " failed to create FUSE mount points"; |
| 167 | return -errno; |
| 168 | } |
| 169 | |
Sudheer Shanka | dd4bb17 | 2019-01-16 23:35:49 -0800 | [diff] [blame] | 170 | dev_t before = GetDevice(mFuseFull); |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 171 | |
shafik | 5cf32b5 | 2019-09-25 13:56:01 +0100 | [diff] [blame] | 172 | bool isFuse = base::GetBoolProperty(kPropFuseSnapshot, false); |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 173 | if (isFuse) { |
| 174 | LOG(INFO) << "Mounting public fuse volume"; |
Nandana Dutt | a914cc7 | 2019-08-29 15:22:42 +0100 | [diff] [blame] | 175 | android::base::unique_fd fd; |
Zim | 981222f | 2019-09-09 10:24:44 +0100 | [diff] [blame] | 176 | int user_id = getMountUserId(); |
Zim | a438b24 | 2019-09-25 14:37:38 +0100 | [diff] [blame] | 177 | int result = MountUserFuse(user_id, getInternalPath(), stableName, &fd); |
Zim | 981222f | 2019-09-09 10:24:44 +0100 | [diff] [blame] | 178 | |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 179 | if (result != 0) { |
| 180 | LOG(ERROR) << "Failed to mount public fuse volume"; |
| 181 | return -result; |
| 182 | } |
Zim | 5048b4b | 2019-11-19 09:16:03 +0000 | [diff] [blame] | 183 | |
| 184 | auto callback = getMountCallback(); |
| 185 | if (callback) { |
| 186 | bool is_ready = false; |
| 187 | callback->onVolumeChecking(std::move(fd), getPath(), getInternalPath(), &is_ready); |
| 188 | if (!is_ready) { |
| 189 | return -EIO; |
| 190 | } |
| 191 | } |
| 192 | |
Zim | a438b24 | 2019-09-25 14:37:38 +0100 | [diff] [blame] | 193 | return OK; |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 194 | } |
| 195 | |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 196 | if (!(mFusePid = fork())) { |
Jeff Sharkey | c7b5b57 | 2015-06-30 15:54:17 -0700 | [diff] [blame] | 197 | if (getMountFlags() & MountFlags::kPrimary) { |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 198 | // clang-format off |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 199 | if (execl(kFusePath, kFusePath, |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 200 | "-u", "1023", // AID_MEDIA_RW |
| 201 | "-g", "1023", // AID_MEDIA_RW |
Jeff Sharkey | 20642ae | 2015-07-28 10:57:29 -0700 | [diff] [blame] | 202 | "-U", std::to_string(getMountUserId()).c_str(), |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 203 | "-w", |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 204 | mRawPath.c_str(), |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 205 | stableName.c_str(), |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 206 | NULL)) { |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 207 | // clang-format on |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 208 | PLOG(ERROR) << "Failed to exec"; |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 209 | } |
| 210 | } else { |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 211 | // clang-format off |
Sudheer Shanka | 5504901 | 2019-01-09 12:15:15 -0800 | [diff] [blame] | 212 | if (execl(kFusePath, kFusePath, |
| 213 | "-u", "1023", // AID_MEDIA_RW |
| 214 | "-g", "1023", // AID_MEDIA_RW |
| 215 | "-U", std::to_string(getMountUserId()).c_str(), |
| 216 | mRawPath.c_str(), |
| 217 | stableName.c_str(), |
| 218 | NULL)) { |
| 219 | // clang-format on |
| 220 | PLOG(ERROR) << "Failed to exec"; |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | |
Jeff Sharkey | c7b5b57 | 2015-06-30 15:54:17 -0700 | [diff] [blame] | 224 | LOG(ERROR) << "FUSE exiting"; |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 225 | _exit(1); |
| 226 | } |
| 227 | |
| 228 | if (mFusePid == -1) { |
Jeff Sharkey | 9c48498 | 2015-03-31 10:35:33 -0700 | [diff] [blame] | 229 | PLOG(ERROR) << getId() << " failed to fork"; |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 230 | return -errno; |
| 231 | } |
| 232 | |
Jeff Sharkey | 7bdf4d5 | 2017-09-18 14:47:10 -0600 | [diff] [blame] | 233 | nsecs_t start = systemTime(SYSTEM_TIME_BOOTTIME); |
Sudheer Shanka | dd4bb17 | 2019-01-16 23:35:49 -0800 | [diff] [blame] | 234 | while (before == GetDevice(mFuseFull)) { |
Sudheer Shanka | 4b6ca4e | 2018-09-21 10:54:54 -0700 | [diff] [blame] | 235 | LOG(DEBUG) << "Waiting for FUSE to spin up..."; |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 236 | usleep(50000); // 50ms |
Jeff Sharkey | 7bdf4d5 | 2017-09-18 14:47:10 -0600 | [diff] [blame] | 237 | |
| 238 | nsecs_t now = systemTime(SYSTEM_TIME_BOOTTIME); |
| 239 | if (nanoseconds_to_milliseconds(now - start) > 5000) { |
| 240 | LOG(WARNING) << "Timed out while waiting for FUSE to spin up"; |
| 241 | return -ETIMEDOUT; |
| 242 | } |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 243 | } |
Daniel Rosenberg | 1d79d10 | 2017-07-11 17:59:55 -0700 | [diff] [blame] | 244 | /* sdcardfs will have exited already. FUSE will still be running */ |
Daniel Rosenberg | 8b9a5b3 | 2018-03-12 15:47:23 -0700 | [diff] [blame] | 245 | TEMP_FAILURE_RETRY(waitpid(mFusePid, nullptr, 0)); |
| 246 | mFusePid = 0; |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 247 | |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 248 | return OK; |
| 249 | } |
| 250 | |
| 251 | status_t PublicVolume::doUnmount() { |
John Cormie | 25cc7e3 | 2016-04-18 14:23:29 -0700 | [diff] [blame] | 252 | // Unmount the storage before we kill the FUSE process. If we kill |
| 253 | // the FUSE process first, most file system operations will return |
| 254 | // ENOTCONN until the unmount completes. This is an exotic and unusual |
| 255 | // error code and might cause broken behaviour in applications. |
Jeff Sharkey | 8aff854 | 2016-03-30 20:37:28 -0600 | [diff] [blame] | 256 | KillProcessesUsingPath(getPath()); |
| 257 | |
shafik | 5cf32b5 | 2019-09-25 13:56:01 +0100 | [diff] [blame] | 258 | bool isFuse = base::GetBoolProperty(kPropFuseSnapshot, false); |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 259 | if (isFuse) { |
| 260 | // Use UUID as stable name, if available |
| 261 | std::string stableName = getId(); |
| 262 | if (!mFsUuid.empty()) { |
| 263 | stableName = mFsUuid; |
| 264 | } |
| 265 | |
Zim | a438b24 | 2019-09-25 14:37:38 +0100 | [diff] [blame] | 266 | std::string fuse_path( |
| 267 | StringPrintf("/mnt/user/%d/%s", getMountUserId(), stableName.c_str())); |
| 268 | std::string pass_through_path( |
| 269 | StringPrintf("/mnt/pass_through/%d/%s", getMountUserId(), stableName.c_str())); |
| 270 | if (UnmountUserFuse(pass_through_path, fuse_path) != OK) { |
| 271 | PLOG(INFO) << "UnmountUserFuse failed on public fuse volume"; |
| 272 | return -errno; |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 273 | } |
Zim | a438b24 | 2019-09-25 14:37:38 +0100 | [diff] [blame] | 274 | ForceUnmount(kAsecPath); |
| 275 | ForceUnmount(mRawPath); |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 276 | |
Zim | a438b24 | 2019-09-25 14:37:38 +0100 | [diff] [blame] | 277 | rmdir(fuse_path.c_str()); |
| 278 | rmdir(pass_through_path.c_str()); |
| 279 | rmdir(mRawPath.c_str()); |
| 280 | mRawPath.clear(); |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 281 | return OK; |
| 282 | } |
| 283 | |
Jeff Sharkey | 48d81d3 | 2015-04-12 21:50:32 -0700 | [diff] [blame] | 284 | ForceUnmount(kAsecPath); |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 285 | |
| 286 | ForceUnmount(mFuseDefault); |
| 287 | ForceUnmount(mFuseRead); |
| 288 | ForceUnmount(mFuseWrite); |
Sudheer Shanka | dd4bb17 | 2019-01-16 23:35:49 -0800 | [diff] [blame] | 289 | ForceUnmount(mFuseFull); |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 290 | ForceUnmount(mRawPath); |
| 291 | |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 292 | rmdir(mFuseDefault.c_str()); |
| 293 | rmdir(mFuseRead.c_str()); |
| 294 | rmdir(mFuseWrite.c_str()); |
Sudheer Shanka | dd4bb17 | 2019-01-16 23:35:49 -0800 | [diff] [blame] | 295 | rmdir(mFuseFull.c_str()); |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 296 | rmdir(mRawPath.c_str()); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 297 | |
Jeff Sharkey | 66270a2 | 2015-06-24 11:49:24 -0700 | [diff] [blame] | 298 | mFuseDefault.clear(); |
| 299 | mFuseRead.clear(); |
| 300 | mFuseWrite.clear(); |
Sudheer Shanka | dd4bb17 | 2019-01-16 23:35:49 -0800 | [diff] [blame] | 301 | mFuseFull.clear(); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 302 | mRawPath.clear(); |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 303 | |
| 304 | return OK; |
| 305 | } |
| 306 | |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 307 | status_t PublicVolume::doFormat(const std::string& fsType) { |
Oleksiy Avramchenko | 4cff06d | 2018-05-23 18:59:48 +0200 | [diff] [blame] | 308 | bool useVfat = vfat::IsSupported(); |
| 309 | bool useExfat = exfat::IsSupported(); |
| 310 | status_t res = OK; |
| 311 | |
| 312 | // Resolve the target filesystem type |
| 313 | if (fsType == "auto" && useVfat && useExfat) { |
| 314 | uint64_t size = 0; |
| 315 | |
| 316 | res = GetBlockDevSize(mDevPath, &size); |
| 317 | if (res != OK) { |
| 318 | LOG(ERROR) << "Couldn't get device size " << mDevPath; |
| 319 | return res; |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 320 | } |
Oleksiy Avramchenko | 4cff06d | 2018-05-23 18:59:48 +0200 | [diff] [blame] | 321 | |
| 322 | // If both vfat & exfat are supported use exfat for SDXC (>~32GiB) cards |
| 323 | if (size > 32896LL * 1024 * 1024) { |
| 324 | useVfat = false; |
| 325 | } else { |
| 326 | useExfat = false; |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 327 | } |
Oleksiy Avramchenko | 4cff06d | 2018-05-23 18:59:48 +0200 | [diff] [blame] | 328 | } else if (fsType == "vfat") { |
| 329 | useExfat = false; |
| 330 | } else if (fsType == "exfat") { |
| 331 | useVfat = false; |
| 332 | } |
| 333 | |
| 334 | if (!useVfat && !useExfat) { |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 335 | LOG(ERROR) << "Unsupported filesystem " << fsType; |
| 336 | return -EINVAL; |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 337 | } |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 338 | |
Oleksiy Avramchenko | 4cff06d | 2018-05-23 18:59:48 +0200 | [diff] [blame] | 339 | if (WipeBlockDevice(mDevPath) != OK) { |
| 340 | LOG(WARNING) << getId() << " failed to wipe"; |
| 341 | } |
| 342 | |
| 343 | if (useVfat) { |
| 344 | res = vfat::Format(mDevPath, 0); |
| 345 | } else if (useExfat) { |
| 346 | res = exfat::Format(mDevPath); |
| 347 | } |
| 348 | |
| 349 | if (res != OK) { |
| 350 | LOG(ERROR) << getId() << " failed to format"; |
| 351 | res = -errno; |
| 352 | } |
| 353 | |
| 354 | return res; |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Jeff Sharkey | deb2405 | 2015-03-02 21:01:40 -0800 | [diff] [blame] | 357 | } // namespace vold |
| 358 | } // namespace android |