blob: 747598ac75c5d14a430828e0ff175e2a6576c023 [file] [log] [blame]
Jeff Sharkeydeb24052015-03-02 21:01:40 -08001/*
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 Sharkeydeb24052015-03-02 21:01:40 -080017#include "PublicVolume.h"
Zim3623a212019-07-19 16:46:53 +010018
19#include "AppFuseUtil.h"
Jeff Sharkeydeb24052015-03-02 21:01:40 -080020#include "Utils.h"
Jeff Sharkey36801cc2015-03-13 16:09:20 -070021#include "VolumeManager.h"
Jeff Sharkey37ba1252018-01-19 10:55:18 +090022#include "fs/Exfat.h"
23#include "fs/Vfat.h"
Jeff Sharkeydeb24052015-03-02 21:01:40 -080024
Elliott Hughes7e128fb2015-12-04 15:50:53 -080025#include <android-base/logging.h>
Sudheer Shanka40ab6742018-09-18 13:07:45 -070026#include <android-base/properties.h>
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070027#include <android-base/stringprintf.h>
Jeff Sharkeydeb24052015-03-02 21:01:40 -080028#include <cutils/fs.h>
Jeff Sharkeydeb24052015-03-02 21:01:40 -080029#include <private/android_filesystem_config.h>
Jeff Sharkey7bdf4d52017-09-18 14:47:10 -060030#include <utils/Timers.h>
Jeff Sharkeydeb24052015-03-02 21:01:40 -080031
32#include <fcntl.h>
33#include <stdlib.h>
34#include <sys/mount.h>
35#include <sys/stat.h>
Elliott Hughes0e08e842017-05-18 09:08:24 -070036#include <sys/sysmacros.h>
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070037#include <sys/types.h>
Jeff Sharkeydeb24052015-03-02 21:01:40 -080038#include <sys/wait.h>
39
Sudheer Shanka40ab6742018-09-18 13:07:45 -070040using android::base::GetBoolProperty;
Dan Albertae9e8902015-03-16 10:35:17 -070041using android::base::StringPrintf;
42
Jeff Sharkeydeb24052015-03-02 21:01:40 -080043namespace android {
44namespace vold {
45
Martijn Coenenadcc8452019-12-09 14:18:01 +010046static const char* kSdcardFsPath = "/system/bin/sdcard";
Jeff Sharkeydeb24052015-03-02 21:01:40 -080047
Jeff Sharkey36801cc2015-03-13 16:09:20 -070048static const char* kAsecPath = "/mnt/secure/asec";
Jeff Sharkeydeb24052015-03-02 21:01:40 -080049
Martijn Coenenadcc8452019-12-09 14:18:01 +010050PublicVolume::PublicVolume(dev_t device) : VolumeBase(Type::kPublic), mDevice(device) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -070051 setId(StringPrintf("public:%u,%u", major(device), minor(device)));
52 mDevPath = StringPrintf("/dev/block/vold/%s", getId().c_str());
Martijn Coenenfd7362d2019-12-11 14:57:59 +010053 mFuseMounted = false;
Daniel Rosenbergf36bddd2020-05-11 22:58:42 -070054 mUseSdcardFs = IsSdcardfsUsed();
Jeff Sharkeydeb24052015-03-02 21:01:40 -080055}
56
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070057PublicVolume::~PublicVolume() {}
Jeff Sharkeydeb24052015-03-02 21:01:40 -080058
59status_t PublicVolume::readMetadata() {
Jeff Sharkey3472e522017-10-06 18:02:53 -060060 status_t res = ReadMetadataUntrusted(mDevPath, &mFsType, &mFsUuid, &mFsLabel);
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -060061
Jeff Sharkey814e9d32017-09-13 11:49:44 -060062 auto listener = getListener();
63 if (listener) listener->onVolumeMetadataChanged(getId(), mFsType, mFsUuid, mFsLabel);
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -060064
Jeff Sharkey36801cc2015-03-13 16:09:20 -070065 return res;
Jeff Sharkeydeb24052015-03-02 21:01:40 -080066}
67
68status_t PublicVolume::initAsecStage() {
69 std::string legacyPath(mRawPath + "/android_secure");
70 std::string securePath(mRawPath + "/.android_secure");
71
72 // Recover legacy secure path
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070073 if (!access(legacyPath.c_str(), R_OK | X_OK) && access(securePath.c_str(), R_OK | X_OK)) {
Jeff Sharkeydeb24052015-03-02 21:01:40 -080074 if (rename(legacyPath.c_str(), securePath.c_str())) {
Jeff Sharkey9c484982015-03-31 10:35:33 -070075 PLOG(WARNING) << getId() << " failed to rename legacy ASEC dir";
Jeff Sharkeydeb24052015-03-02 21:01:40 -080076 }
77 }
78
Jeff Sharkey36801cc2015-03-13 16:09:20 -070079 if (TEMP_FAILURE_RETRY(mkdir(securePath.c_str(), 0700))) {
80 if (errno != EEXIST) {
Jeff Sharkey9c484982015-03-31 10:35:33 -070081 PLOG(WARNING) << getId() << " creating ASEC stage failed";
Jeff Sharkey36801cc2015-03-13 16:09:20 -070082 return -errno;
83 }
Jeff Sharkeydeb24052015-03-02 21:01:40 -080084 }
85
Jeff Sharkey36801cc2015-03-13 16:09:20 -070086 BindMount(securePath, kAsecPath);
87
Jeff Sharkeydeb24052015-03-02 21:01:40 -080088 return OK;
89}
90
Omar Eissad9c4b232025-03-13 11:52:43 +000091std::string PublicVolume::getStableName() {
92 // Use UUID as stable name, if available
93 std::string stableName = getId();
94 if (!mFsUuid.empty()) {
95 stableName = mFsUuid;
96 }
97 return stableName;
98}
99
Jeff Sharkey9c484982015-03-31 10:35:33 -0700100status_t PublicVolume::doCreate() {
101 return CreateDeviceNode(mDevPath, mDevice);
102}
103
104status_t PublicVolume::doDestroy() {
105 return DestroyDeviceNode(mDevPath);
106}
107
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800108status_t PublicVolume::doMount() {
Youkichi Hosoi4461c5a2021-11-13 16:27:02 +0900109 bool isVisible = isVisibleForWrite();
Jeff Sharkey9c484982015-03-31 10:35:33 -0700110 readMetadata();
111
Jeff Sharkey37ba1252018-01-19 10:55:18 +0900112 if (mFsType == "vfat" && vfat::IsSupported()) {
113 if (vfat::Check(mDevPath)) {
114 LOG(ERROR) << getId() << " failed filesystem check";
115 return -EIO;
116 }
117 } else if (mFsType == "exfat" && exfat::IsSupported()) {
118 if (exfat::Check(mDevPath)) {
119 LOG(ERROR) << getId() << " failed filesystem check";
120 return -EIO;
121 }
122 } else {
Makoto Onukic82c9ce2015-06-24 13:30:45 -0700123 LOG(ERROR) << getId() << " unsupported filesystem " << mFsType;
124 return -EIO;
125 }
126
Omar Eissad9c4b232025-03-13 11:52:43 +0000127 std::string stableName = getStableName();
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700128
129 mRawPath = StringPrintf("/mnt/media_rw/%s", stableName.c_str());
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700130
Martijn Coenenadcc8452019-12-09 14:18:01 +0100131 mSdcardFsDefault = StringPrintf("/mnt/runtime/default/%s", stableName.c_str());
132 mSdcardFsRead = StringPrintf("/mnt/runtime/read/%s", stableName.c_str());
133 mSdcardFsWrite = StringPrintf("/mnt/runtime/write/%s", stableName.c_str());
134 mSdcardFsFull = StringPrintf("/mnt/runtime/full/%s", stableName.c_str());
Jeff Sharkey66270a22015-06-24 11:49:24 -0700135
136 setInternalPath(mRawPath);
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100137 if (isVisible) {
Jeff Sharkey8474ee32015-07-30 16:54:23 -0700138 setPath(StringPrintf("/storage/%s", stableName.c_str()));
139 } else {
140 setPath(mRawPath);
141 }
Jeff Sharkey66270a22015-06-24 11:49:24 -0700142
Qin Chaoe0074f12015-12-15 15:20:41 +0800143 if (fs_prepare_dir(mRawPath.c_str(), 0700, AID_ROOT, AID_ROOT)) {
Jeff Sharkey66270a22015-06-24 11:49:24 -0700144 PLOG(ERROR) << getId() << " failed to create mount points";
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800145 return -errno;
146 }
147
Jeff Sharkey37ba1252018-01-19 10:55:18 +0900148 if (mFsType == "vfat") {
Zimc9a2be42020-01-24 22:03:02 +0000149 if (vfat::Mount(mDevPath, mRawPath, false, false, false, AID_ROOT,
150 (isVisible ? AID_MEDIA_RW : AID_EXTERNAL_STORAGE), 0007, true)) {
Jeff Sharkey37ba1252018-01-19 10:55:18 +0900151 PLOG(ERROR) << getId() << " failed to mount " << mDevPath;
152 return -EIO;
153 }
154 } else if (mFsType == "exfat") {
Zimc9a2be42020-01-24 22:03:02 +0000155 if (exfat::Mount(mDevPath, mRawPath, AID_ROOT,
156 (isVisible ? AID_MEDIA_RW : AID_EXTERNAL_STORAGE), 0007)) {
Jeff Sharkey37ba1252018-01-19 10:55:18 +0900157 PLOG(ERROR) << getId() << " failed to mount " << mDevPath;
158 return -EIO;
159 }
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800160 }
161
Jeff Sharkeyf1b996d2015-04-17 17:35:20 -0700162 if (getMountFlags() & MountFlags::kPrimary) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700163 initAsecStage();
164 }
165
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100166 if (!isVisible) {
Martijn Coenenadcc8452019-12-09 14:18:01 +0100167 // Not visible to apps, so no need to spin up sdcardfs or FUSE
Jeff Sharkeyc7b5b572015-06-30 15:54:17 -0700168 return OK;
169 }
170
Martijn Coenen86f21a22020-01-06 09:48:14 +0100171 if (mUseSdcardFs) {
172 if (fs_prepare_dir(mSdcardFsDefault.c_str(), 0700, AID_ROOT, AID_ROOT) ||
173 fs_prepare_dir(mSdcardFsRead.c_str(), 0700, AID_ROOT, AID_ROOT) ||
174 fs_prepare_dir(mSdcardFsWrite.c_str(), 0700, AID_ROOT, AID_ROOT) ||
175 fs_prepare_dir(mSdcardFsFull.c_str(), 0700, AID_ROOT, AID_ROOT)) {
176 PLOG(ERROR) << getId() << " failed to create sdcardfs mount points";
177 return -errno;
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800178 }
179
Martijn Coenen86f21a22020-01-06 09:48:14 +0100180 dev_t before = GetDevice(mSdcardFsFull);
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800181
Martijn Coenen86f21a22020-01-06 09:48:14 +0100182 int sdcardFsPid;
183 if (!(sdcardFsPid = fork())) {
184 if (getMountFlags() & MountFlags::kPrimary) {
185 // clang-format off
186 if (execl(kSdcardFsPath, kSdcardFsPath,
187 "-u", "1023", // AID_MEDIA_RW
188 "-g", "1023", // AID_MEDIA_RW
189 "-U", std::to_string(getMountUserId()).c_str(),
190 "-w",
191 mRawPath.c_str(),
192 stableName.c_str(),
193 NULL)) {
194 // clang-format on
195 PLOG(ERROR) << "Failed to exec";
196 }
197 } else {
198 // clang-format off
199 if (execl(kSdcardFsPath, kSdcardFsPath,
200 "-u", "1023", // AID_MEDIA_RW
201 "-g", "1023", // AID_MEDIA_RW
202 "-U", std::to_string(getMountUserId()).c_str(),
203 mRawPath.c_str(),
204 stableName.c_str(),
205 NULL)) {
206 // clang-format on
207 PLOG(ERROR) << "Failed to exec";
208 }
209 }
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800210
Martijn Coenen86f21a22020-01-06 09:48:14 +0100211 LOG(ERROR) << "sdcardfs exiting";
212 _exit(1);
Jeff Sharkey7bdf4d52017-09-18 14:47:10 -0600213 }
Martijn Coenen86f21a22020-01-06 09:48:14 +0100214
215 if (sdcardFsPid == -1) {
216 PLOG(ERROR) << getId() << " failed to fork";
217 return -errno;
218 }
219
220 nsecs_t start = systemTime(SYSTEM_TIME_BOOTTIME);
221 while (before == GetDevice(mSdcardFsFull)) {
222 LOG(DEBUG) << "Waiting for sdcardfs to spin up...";
223 usleep(50000); // 50ms
224
225 nsecs_t now = systemTime(SYSTEM_TIME_BOOTTIME);
226 if (nanoseconds_to_milliseconds(now - start) > 5000) {
227 LOG(WARNING) << "Timed out while waiting for sdcardfs to spin up";
228 return -ETIMEDOUT;
229 }
230 }
231 /* sdcardfs will have exited already. The filesystem will still be running */
232 TEMP_FAILURE_RETRY(waitpid(sdcardFsPid, nullptr, 0));
Jeff Sharkey66270a22015-06-24 11:49:24 -0700233 }
234
Zim415d99d2020-06-29 19:50:47 +0100235 // We need to mount FUSE *after* sdcardfs, since the FUSE daemon may depend
236 // on sdcardfs being up.
237 LOG(INFO) << "Mounting public fuse volume";
238 android::base::unique_fd fd;
239 int user_id = getMountUserId();
240 int result = MountUserFuse(user_id, getInternalPath(), stableName, &fd);
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100241
Zim415d99d2020-06-29 19:50:47 +0100242 if (result != 0) {
243 LOG(ERROR) << "Failed to mount public fuse volume";
244 doUnmount();
245 return -result;
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100246 }
247
Zim415d99d2020-06-29 19:50:47 +0100248 mFuseMounted = true;
249 auto callback = getMountCallback();
250 if (callback) {
251 bool is_ready = false;
252 callback->onVolumeChecking(std::move(fd), getPath(), getInternalPath(), &is_ready);
253 if (!is_ready) {
254 LOG(ERROR) << "Failed to complete public volume mount";
255 doUnmount();
256 return -EIO;
257 }
258 }
259
260 ConfigureReadAheadForFuse(GetFuseMountPathForUser(user_id, stableName), 256u);
261
262 // See comment in model/EmulatedVolume.cpp
263 ConfigureMaxDirtyRatioForFuse(GetFuseMountPathForUser(user_id, stableName), 40u);
264
himanshuz0ad08622023-07-27 21:15:00 +0000265 auto vol_manager = VolumeManager::Instance();
266 // Create bind mounts for all running users
267 for (userid_t started_user : vol_manager->getStartedUsers()) {
268 userid_t mountUserId = getMountUserId();
269 if (started_user == mountUserId) {
270 // No need to bind mount for the user that owns the mount
271 continue;
272 }
273 if (mountUserId != VolumeManager::Instance()->getSharedStorageUser(started_user)) {
274 // No need to bind if the user does not share storage with the mount owner
275 continue;
276 }
Himanshu Gupta4f179692024-05-06 11:40:19 +0100277 // Create mount directory for the user as there is a chance that no other Volume is mounted
278 // for the user (ex: if the user is just started), so /mnt/user/user_id does not exist yet.
279 auto mountDirStatus = PrepareMountDirForUser(started_user);
280 if (mountDirStatus != OK) {
281 LOG(ERROR) << "Failed to create Mount Directory for user " << started_user;
282 }
himanshuz0ad08622023-07-27 21:15:00 +0000283 auto bindMountStatus = bindMountForUser(started_user);
284 if (bindMountStatus != OK) {
285 LOG(ERROR) << "Bind Mounting Public Volume: " << stableName
286 << " for user: " << started_user << "Failed. Error: " << bindMountStatus;
287 }
288 }
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800289 return OK;
290}
291
himanshuz0ad08622023-07-27 21:15:00 +0000292status_t PublicVolume::bindMountForUser(userid_t user_id) {
293 userid_t mountUserId = getMountUserId();
Omar Eissad9c4b232025-03-13 11:52:43 +0000294 std::string stableName = getStableName();
himanshuz0ad08622023-07-27 21:15:00 +0000295
296 LOG(INFO) << "Bind Mounting Public Volume for user: " << user_id
297 << ".Mount owner: " << mountUserId;
298 auto sourcePath = GetFuseMountPathForUser(mountUserId, stableName);
299 auto destPath = GetFuseMountPathForUser(user_id, stableName);
300 PrepareDir(destPath, 0770, AID_ROOT, AID_MEDIA_RW);
301 auto mountRes = BindMount(sourcePath, destPath);
302 LOG(INFO) << "Mount status: " << mountRes;
303
304 return mountRes;
305}
306
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800307status_t PublicVolume::doUnmount() {
John Cormie25cc7e32016-04-18 14:23:29 -0700308 // Unmount the storage before we kill the FUSE process. If we kill
309 // the FUSE process first, most file system operations will return
310 // ENOTCONN until the unmount completes. This is an exotic and unusual
311 // error code and might cause broken behaviour in applications.
Jeff Sharkey8aff8542016-03-30 20:37:28 -0600312 KillProcessesUsingPath(getPath());
313
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100314 if (mFuseMounted) {
Omar Eissad9c4b232025-03-13 11:52:43 +0000315 std::string stableName = getStableName();
Zim3623a212019-07-19 16:46:53 +0100316
himanshuz0ad08622023-07-27 21:15:00 +0000317 // Unmount bind mounts for running users
318 auto vol_manager = VolumeManager::Instance();
319 int user_id = getMountUserId();
320 for (int started_user : vol_manager->getStartedUsers()) {
321 if (started_user == user_id) {
322 // No need to remove bind mount for the user that owns the mount
323 continue;
324 }
325 LOG(INFO) << "Removing Public Volume Bind Mount for: " << started_user;
326 auto mountPath = GetFuseMountPathForUser(started_user, stableName);
327 ForceUnmount(mountPath);
328 rmdir(mountPath.c_str());
329 }
330
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100331 if (UnmountUserFuse(getMountUserId(), getInternalPath(), stableName) != OK) {
332 PLOG(INFO) << "UnmountUserFuse failed on public fuse volume";
333 return -errno;
334 }
335
Martijn Coenen6f5802e2019-11-28 11:53:53 +0100336 mFuseMounted = false;
Zim3623a212019-07-19 16:46:53 +0100337 }
338
Jeff Sharkey48d81d32015-04-12 21:50:32 -0700339 ForceUnmount(kAsecPath);
Jeff Sharkey66270a22015-06-24 11:49:24 -0700340
Martijn Coenen86f21a22020-01-06 09:48:14 +0100341 if (mUseSdcardFs) {
342 ForceUnmount(mSdcardFsDefault);
343 ForceUnmount(mSdcardFsRead);
344 ForceUnmount(mSdcardFsWrite);
345 ForceUnmount(mSdcardFsFull);
346
347 rmdir(mSdcardFsDefault.c_str());
348 rmdir(mSdcardFsRead.c_str());
349 rmdir(mSdcardFsWrite.c_str());
350 rmdir(mSdcardFsFull.c_str());
351
352 mSdcardFsDefault.clear();
353 mSdcardFsRead.clear();
354 mSdcardFsWrite.clear();
355 mSdcardFsFull.clear();
356 }
silver.chen4c45ac62021-07-07 20:27:47 +0800357
358 if (ForceUnmount(mRawPath) != 0){
359 umount2(mRawPath.c_str(),MNT_DETACH);
360 PLOG(INFO) << "use umount lazy if force unmount fail";
361 }
362 if(rmdir(mRawPath.c_str()) != 0) {
363 PLOG(INFO) << "rmdir mRawPath=" << mRawPath << " fail";
364 KillProcessesUsingPath(getPath());
365 }
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700366 mRawPath.clear();
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800367
368 return OK;
369}
370
Jeff Sharkeyd0640f62015-05-21 22:35:42 -0700371status_t PublicVolume::doFormat(const std::string& fsType) {
Alfred Piccioni564f6c62022-09-21 17:32:04 +0200372 bool isVfatSup = vfat::IsSupported();
373 bool isExfatSup = exfat::IsSupported();
Oleksiy Avramchenko4cff06d2018-05-23 18:59:48 +0200374 status_t res = OK;
375
Alfred Piccionifc4934f2023-02-02 09:46:30 +0000376 enum { NONE, VFAT, EXFAT } fsPick = NONE;
Alfred Piccioni564f6c62022-09-21 17:32:04 +0200377
378 // Resolve auto requests
379 if (fsType == "auto" && isVfatSup && isExfatSup) {
Oleksiy Avramchenko4cff06d2018-05-23 18:59:48 +0200380 uint64_t size = 0;
381
382 res = GetBlockDevSize(mDevPath, &size);
383 if (res != OK) {
384 LOG(ERROR) << "Couldn't get device size " << mDevPath;
385 return res;
Jeff Sharkeyd0640f62015-05-21 22:35:42 -0700386 }
Oleksiy Avramchenko4cff06d2018-05-23 18:59:48 +0200387
388 // If both vfat & exfat are supported use exfat for SDXC (>~32GiB) cards
389 if (size > 32896LL * 1024 * 1024) {
Alfred Piccioni564f6c62022-09-21 17:32:04 +0200390 fsPick = EXFAT;
Oleksiy Avramchenko4cff06d2018-05-23 18:59:48 +0200391 } else {
Alfred Piccioni564f6c62022-09-21 17:32:04 +0200392 fsPick = VFAT;
Jeff Sharkeyd0640f62015-05-21 22:35:42 -0700393 }
Alfred Piccioni564f6c62022-09-21 17:32:04 +0200394 } else if (fsType == "auto" && isExfatSup) {
395 fsPick = EXFAT;
396 } else if (fsType == "auto" && isVfatSup) {
397 fsPick = VFAT;
Oleksiy Avramchenko4cff06d2018-05-23 18:59:48 +0200398 }
399
Alfred Piccioni564f6c62022-09-21 17:32:04 +0200400 // Resolve explicit requests
401 if (fsType == "vfat" && isVfatSup) {
402 fsPick = VFAT;
403 } else if (fsType == "exfat" && isExfatSup) {
404 fsPick = EXFAT;
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800405 }
Jeff Sharkeyd0640f62015-05-21 22:35:42 -0700406
Oleksiy Avramchenko4cff06d2018-05-23 18:59:48 +0200407 if (WipeBlockDevice(mDevPath) != OK) {
408 LOG(WARNING) << getId() << " failed to wipe";
409 }
410
Alfred Piccioni564f6c62022-09-21 17:32:04 +0200411 if (fsPick == VFAT) {
Oleksiy Avramchenko4cff06d2018-05-23 18:59:48 +0200412 res = vfat::Format(mDevPath, 0);
Alfred Piccioni564f6c62022-09-21 17:32:04 +0200413 } else if (fsPick == EXFAT) {
Oleksiy Avramchenko4cff06d2018-05-23 18:59:48 +0200414 res = exfat::Format(mDevPath);
Alfred Piccioni564f6c62022-09-21 17:32:04 +0200415 } else {
416 LOG(ERROR) << "Unsupported filesystem " << fsType;
417 return -EINVAL;
Oleksiy Avramchenko4cff06d2018-05-23 18:59:48 +0200418 }
419
420 if (res != OK) {
421 LOG(ERROR) << getId() << " failed to format";
422 res = -errno;
423 }
424
425 return res;
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800426}
427
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800428} // namespace vold
429} // namespace android