1*f40fafd4SAndroid Build Coastguard Worker /*
2*f40fafd4SAndroid Build Coastguard Worker * Copyright (C) 2017 The Android Open Source Project
3*f40fafd4SAndroid Build Coastguard Worker *
4*f40fafd4SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*f40fafd4SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*f40fafd4SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*f40fafd4SAndroid Build Coastguard Worker *
8*f40fafd4SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*f40fafd4SAndroid Build Coastguard Worker *
10*f40fafd4SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*f40fafd4SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*f40fafd4SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*f40fafd4SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*f40fafd4SAndroid Build Coastguard Worker * limitations under the License.
15*f40fafd4SAndroid Build Coastguard Worker */
16*f40fafd4SAndroid Build Coastguard Worker
17*f40fafd4SAndroid Build Coastguard Worker #define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER
18*f40fafd4SAndroid Build Coastguard Worker
19*f40fafd4SAndroid Build Coastguard Worker #include "VoldNativeService.h"
20*f40fafd4SAndroid Build Coastguard Worker
21*f40fafd4SAndroid Build Coastguard Worker #include <android-base/logging.h>
22*f40fafd4SAndroid Build Coastguard Worker #include <android-base/strings.h>
23*f40fafd4SAndroid Build Coastguard Worker #include <fs_mgr.h>
24*f40fafd4SAndroid Build Coastguard Worker #include <fscrypt/fscrypt.h>
25*f40fafd4SAndroid Build Coastguard Worker #include <private/android_filesystem_config.h>
26*f40fafd4SAndroid Build Coastguard Worker #include <utils/Trace.h>
27*f40fafd4SAndroid Build Coastguard Worker
28*f40fafd4SAndroid Build Coastguard Worker #include <stdio.h>
29*f40fafd4SAndroid Build Coastguard Worker #include <fstream>
30*f40fafd4SAndroid Build Coastguard Worker #include <thread>
31*f40fafd4SAndroid Build Coastguard Worker
32*f40fafd4SAndroid Build Coastguard Worker #include "Benchmark.h"
33*f40fafd4SAndroid Build Coastguard Worker #include "Checkpoint.h"
34*f40fafd4SAndroid Build Coastguard Worker #include "FsCrypt.h"
35*f40fafd4SAndroid Build Coastguard Worker #include "IdleMaint.h"
36*f40fafd4SAndroid Build Coastguard Worker #include "KeyStorage.h"
37*f40fafd4SAndroid Build Coastguard Worker #include "Keystore.h"
38*f40fafd4SAndroid Build Coastguard Worker #include "MetadataCrypt.h"
39*f40fafd4SAndroid Build Coastguard Worker #include "MoveStorage.h"
40*f40fafd4SAndroid Build Coastguard Worker #include "VoldNativeServiceValidation.h"
41*f40fafd4SAndroid Build Coastguard Worker #include "VoldUtil.h"
42*f40fafd4SAndroid Build Coastguard Worker #include "VolumeManager.h"
43*f40fafd4SAndroid Build Coastguard Worker #include "cryptfs.h"
44*f40fafd4SAndroid Build Coastguard Worker #include "incfs.h"
45*f40fafd4SAndroid Build Coastguard Worker
46*f40fafd4SAndroid Build Coastguard Worker using namespace std::literals;
47*f40fafd4SAndroid Build Coastguard Worker
48*f40fafd4SAndroid Build Coastguard Worker namespace android {
49*f40fafd4SAndroid Build Coastguard Worker namespace vold {
50*f40fafd4SAndroid Build Coastguard Worker
51*f40fafd4SAndroid Build Coastguard Worker namespace {
52*f40fafd4SAndroid Build Coastguard Worker
53*f40fafd4SAndroid Build Coastguard Worker constexpr const char* kDump = "android.permission.DUMP";
54*f40fafd4SAndroid Build Coastguard Worker constexpr auto kIncFsReadNoTimeoutMs = 100;
55*f40fafd4SAndroid Build Coastguard Worker
error(const std::string & msg)56*f40fafd4SAndroid Build Coastguard Worker static binder::Status error(const std::string& msg) {
57*f40fafd4SAndroid Build Coastguard Worker PLOG(ERROR) << msg;
58*f40fafd4SAndroid Build Coastguard Worker return binder::Status::fromServiceSpecificError(errno, String8(msg.c_str()));
59*f40fafd4SAndroid Build Coastguard Worker }
60*f40fafd4SAndroid Build Coastguard Worker
translate(int status)61*f40fafd4SAndroid Build Coastguard Worker static binder::Status translate(int status) {
62*f40fafd4SAndroid Build Coastguard Worker if (status == 0) {
63*f40fafd4SAndroid Build Coastguard Worker return binder::Status::ok();
64*f40fafd4SAndroid Build Coastguard Worker } else {
65*f40fafd4SAndroid Build Coastguard Worker return binder::Status::fromServiceSpecificError(status);
66*f40fafd4SAndroid Build Coastguard Worker }
67*f40fafd4SAndroid Build Coastguard Worker }
68*f40fafd4SAndroid Build Coastguard Worker
translateBool(bool status)69*f40fafd4SAndroid Build Coastguard Worker static binder::Status translateBool(bool status) {
70*f40fafd4SAndroid Build Coastguard Worker if (status) {
71*f40fafd4SAndroid Build Coastguard Worker return binder::Status::ok();
72*f40fafd4SAndroid Build Coastguard Worker } else {
73*f40fafd4SAndroid Build Coastguard Worker return binder::Status::fromServiceSpecificError(status);
74*f40fafd4SAndroid Build Coastguard Worker }
75*f40fafd4SAndroid Build Coastguard Worker }
76*f40fafd4SAndroid Build Coastguard Worker
77*f40fafd4SAndroid Build Coastguard Worker #define ENFORCE_SYSTEM_OR_ROOT \
78*f40fafd4SAndroid Build Coastguard Worker { \
79*f40fafd4SAndroid Build Coastguard Worker binder::Status status = CheckUidOrRoot(AID_SYSTEM); \
80*f40fafd4SAndroid Build Coastguard Worker if (!status.isOk()) { \
81*f40fafd4SAndroid Build Coastguard Worker return status; \
82*f40fafd4SAndroid Build Coastguard Worker } \
83*f40fafd4SAndroid Build Coastguard Worker }
84*f40fafd4SAndroid Build Coastguard Worker
85*f40fafd4SAndroid Build Coastguard Worker #define CHECK_ARGUMENT_ID(id) \
86*f40fafd4SAndroid Build Coastguard Worker { \
87*f40fafd4SAndroid Build Coastguard Worker binder::Status status = CheckArgumentId((id)); \
88*f40fafd4SAndroid Build Coastguard Worker if (!status.isOk()) { \
89*f40fafd4SAndroid Build Coastguard Worker return status; \
90*f40fafd4SAndroid Build Coastguard Worker } \
91*f40fafd4SAndroid Build Coastguard Worker }
92*f40fafd4SAndroid Build Coastguard Worker
93*f40fafd4SAndroid Build Coastguard Worker #define CHECK_ARGUMENT_PATH(path) \
94*f40fafd4SAndroid Build Coastguard Worker { \
95*f40fafd4SAndroid Build Coastguard Worker binder::Status status = CheckArgumentPath((path)); \
96*f40fafd4SAndroid Build Coastguard Worker if (!status.isOk()) { \
97*f40fafd4SAndroid Build Coastguard Worker return status; \
98*f40fafd4SAndroid Build Coastguard Worker } \
99*f40fafd4SAndroid Build Coastguard Worker }
100*f40fafd4SAndroid Build Coastguard Worker
101*f40fafd4SAndroid Build Coastguard Worker #define CHECK_ARGUMENT_HEX(hex) \
102*f40fafd4SAndroid Build Coastguard Worker { \
103*f40fafd4SAndroid Build Coastguard Worker binder::Status status = CheckArgumentHex((hex)); \
104*f40fafd4SAndroid Build Coastguard Worker if (!status.isOk()) { \
105*f40fafd4SAndroid Build Coastguard Worker return status; \
106*f40fafd4SAndroid Build Coastguard Worker } \
107*f40fafd4SAndroid Build Coastguard Worker }
108*f40fafd4SAndroid Build Coastguard Worker
109*f40fafd4SAndroid Build Coastguard Worker #define ACQUIRE_LOCK \
110*f40fafd4SAndroid Build Coastguard Worker std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \
111*f40fafd4SAndroid Build Coastguard Worker ATRACE_CALL();
112*f40fafd4SAndroid Build Coastguard Worker
113*f40fafd4SAndroid Build Coastguard Worker #define ACQUIRE_CRYPT_LOCK \
114*f40fafd4SAndroid Build Coastguard Worker std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \
115*f40fafd4SAndroid Build Coastguard Worker ATRACE_CALL();
116*f40fafd4SAndroid Build Coastguard Worker
117*f40fafd4SAndroid Build Coastguard Worker } // namespace
118*f40fafd4SAndroid Build Coastguard Worker
start()119*f40fafd4SAndroid Build Coastguard Worker status_t VoldNativeService::start() {
120*f40fafd4SAndroid Build Coastguard Worker IPCThreadState::self()->disableBackgroundScheduling(true);
121*f40fafd4SAndroid Build Coastguard Worker status_t ret = BinderService<VoldNativeService>::publish();
122*f40fafd4SAndroid Build Coastguard Worker if (ret != android::OK) {
123*f40fafd4SAndroid Build Coastguard Worker return ret;
124*f40fafd4SAndroid Build Coastguard Worker }
125*f40fafd4SAndroid Build Coastguard Worker sp<ProcessState> ps(ProcessState::self());
126*f40fafd4SAndroid Build Coastguard Worker ps->startThreadPool();
127*f40fafd4SAndroid Build Coastguard Worker ps->giveThreadPoolName();
128*f40fafd4SAndroid Build Coastguard Worker return android::OK;
129*f40fafd4SAndroid Build Coastguard Worker }
130*f40fafd4SAndroid Build Coastguard Worker
dump(int fd,const Vector<String16> &)131*f40fafd4SAndroid Build Coastguard Worker status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) {
132*f40fafd4SAndroid Build Coastguard Worker const binder::Status dump_permission = CheckPermission(kDump);
133*f40fafd4SAndroid Build Coastguard Worker if (!dump_permission.isOk()) {
134*f40fafd4SAndroid Build Coastguard Worker dprintf(fd, "%s\n", dump_permission.toString8().c_str());
135*f40fafd4SAndroid Build Coastguard Worker return PERMISSION_DENIED;
136*f40fafd4SAndroid Build Coastguard Worker }
137*f40fafd4SAndroid Build Coastguard Worker
138*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
139*f40fafd4SAndroid Build Coastguard Worker dprintf(fd, "vold is happy!\n");
140*f40fafd4SAndroid Build Coastguard Worker return NO_ERROR;
141*f40fafd4SAndroid Build Coastguard Worker }
142*f40fafd4SAndroid Build Coastguard Worker
setListener(const android::sp<android::os::IVoldListener> & listener)143*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::setListener(
144*f40fafd4SAndroid Build Coastguard Worker const android::sp<android::os::IVoldListener>& listener) {
145*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
146*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
147*f40fafd4SAndroid Build Coastguard Worker
148*f40fafd4SAndroid Build Coastguard Worker VolumeManager::Instance()->setListener(listener);
149*f40fafd4SAndroid Build Coastguard Worker return Ok();
150*f40fafd4SAndroid Build Coastguard Worker }
151*f40fafd4SAndroid Build Coastguard Worker
monitor()152*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::monitor() {
153*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
154*f40fafd4SAndroid Build Coastguard Worker
155*f40fafd4SAndroid Build Coastguard Worker // Simply acquire/release each lock for watchdog
156*f40fafd4SAndroid Build Coastguard Worker { ACQUIRE_LOCK; }
157*f40fafd4SAndroid Build Coastguard Worker { ACQUIRE_CRYPT_LOCK; }
158*f40fafd4SAndroid Build Coastguard Worker
159*f40fafd4SAndroid Build Coastguard Worker return Ok();
160*f40fafd4SAndroid Build Coastguard Worker }
161*f40fafd4SAndroid Build Coastguard Worker
reset()162*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::reset() {
163*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
164*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
165*f40fafd4SAndroid Build Coastguard Worker
166*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->reset());
167*f40fafd4SAndroid Build Coastguard Worker }
168*f40fafd4SAndroid Build Coastguard Worker
shutdown()169*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::shutdown() {
170*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
171*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
172*f40fafd4SAndroid Build Coastguard Worker
173*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->shutdown());
174*f40fafd4SAndroid Build Coastguard Worker }
175*f40fafd4SAndroid Build Coastguard Worker
abortFuse()176*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::abortFuse() {
177*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
178*f40fafd4SAndroid Build Coastguard Worker // if acquire lock, maybe lead to a deadlock if lock is held by a
179*f40fafd4SAndroid Build Coastguard Worker // thread that is blocked on a FUSE operation.
180*f40fafd4SAndroid Build Coastguard Worker // abort fuse doesn't need to access any state, so do not acquire lock
181*f40fafd4SAndroid Build Coastguard Worker
182*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->abortFuse());
183*f40fafd4SAndroid Build Coastguard Worker }
184*f40fafd4SAndroid Build Coastguard Worker
onUserAdded(int32_t userId,int32_t userSerial,int32_t sharesStorageWithUserId)185*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial,
186*f40fafd4SAndroid Build Coastguard Worker int32_t sharesStorageWithUserId) {
187*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
188*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
189*f40fafd4SAndroid Build Coastguard Worker
190*f40fafd4SAndroid Build Coastguard Worker return translate(
191*f40fafd4SAndroid Build Coastguard Worker VolumeManager::Instance()->onUserAdded(userId, userSerial, sharesStorageWithUserId));
192*f40fafd4SAndroid Build Coastguard Worker }
193*f40fafd4SAndroid Build Coastguard Worker
onUserRemoved(int32_t userId)194*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::onUserRemoved(int32_t userId) {
195*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
196*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
197*f40fafd4SAndroid Build Coastguard Worker
198*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->onUserRemoved(userId));
199*f40fafd4SAndroid Build Coastguard Worker }
200*f40fafd4SAndroid Build Coastguard Worker
onUserStarted(int32_t userId)201*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::onUserStarted(int32_t userId) {
202*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
203*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
204*f40fafd4SAndroid Build Coastguard Worker
205*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->onUserStarted(userId));
206*f40fafd4SAndroid Build Coastguard Worker }
207*f40fafd4SAndroid Build Coastguard Worker
onUserStopped(int32_t userId)208*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::onUserStopped(int32_t userId) {
209*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
210*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
211*f40fafd4SAndroid Build Coastguard Worker
212*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->onUserStopped(userId));
213*f40fafd4SAndroid Build Coastguard Worker }
214*f40fafd4SAndroid Build Coastguard Worker
addAppIds(const std::vector<std::string> & packageNames,const std::vector<int32_t> & appIds)215*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames,
216*f40fafd4SAndroid Build Coastguard Worker const std::vector<int32_t>& appIds) {
217*f40fafd4SAndroid Build Coastguard Worker return Ok();
218*f40fafd4SAndroid Build Coastguard Worker }
219*f40fafd4SAndroid Build Coastguard Worker
addSandboxIds(const std::vector<int32_t> & appIds,const std::vector<std::string> & sandboxIds)220*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds,
221*f40fafd4SAndroid Build Coastguard Worker const std::vector<std::string>& sandboxIds) {
222*f40fafd4SAndroid Build Coastguard Worker return Ok();
223*f40fafd4SAndroid Build Coastguard Worker }
224*f40fafd4SAndroid Build Coastguard Worker
onSecureKeyguardStateChanged(bool isShowing)225*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) {
226*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
227*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
228*f40fafd4SAndroid Build Coastguard Worker
229*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing));
230*f40fafd4SAndroid Build Coastguard Worker }
231*f40fafd4SAndroid Build Coastguard Worker
partition(const std::string & diskId,int32_t partitionType,int32_t ratio)232*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType,
233*f40fafd4SAndroid Build Coastguard Worker int32_t ratio) {
234*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
235*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_ID(diskId);
236*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
237*f40fafd4SAndroid Build Coastguard Worker
238*f40fafd4SAndroid Build Coastguard Worker auto disk = VolumeManager::Instance()->findDisk(diskId);
239*f40fafd4SAndroid Build Coastguard Worker if (disk == nullptr) {
240*f40fafd4SAndroid Build Coastguard Worker return error("Failed to find disk " + diskId);
241*f40fafd4SAndroid Build Coastguard Worker }
242*f40fafd4SAndroid Build Coastguard Worker switch (partitionType) {
243*f40fafd4SAndroid Build Coastguard Worker case PARTITION_TYPE_PUBLIC:
244*f40fafd4SAndroid Build Coastguard Worker return translate(disk->partitionPublic());
245*f40fafd4SAndroid Build Coastguard Worker case PARTITION_TYPE_PRIVATE:
246*f40fafd4SAndroid Build Coastguard Worker return translate(disk->partitionPrivate());
247*f40fafd4SAndroid Build Coastguard Worker case PARTITION_TYPE_MIXED:
248*f40fafd4SAndroid Build Coastguard Worker return translate(disk->partitionMixed(ratio));
249*f40fafd4SAndroid Build Coastguard Worker default:
250*f40fafd4SAndroid Build Coastguard Worker return error("Unknown type " + std::to_string(partitionType));
251*f40fafd4SAndroid Build Coastguard Worker }
252*f40fafd4SAndroid Build Coastguard Worker }
253*f40fafd4SAndroid Build Coastguard Worker
forgetPartition(const std::string & partGuid,const std::string & fsUuid)254*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::forgetPartition(const std::string& partGuid,
255*f40fafd4SAndroid Build Coastguard Worker const std::string& fsUuid) {
256*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
257*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_HEX(partGuid);
258*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_HEX(fsUuid);
259*f40fafd4SAndroid Build Coastguard Worker bool success = true;
260*f40fafd4SAndroid Build Coastguard Worker
261*f40fafd4SAndroid Build Coastguard Worker {
262*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
263*f40fafd4SAndroid Build Coastguard Worker success &= VolumeManager::Instance()->forgetPartition(partGuid, fsUuid);
264*f40fafd4SAndroid Build Coastguard Worker }
265*f40fafd4SAndroid Build Coastguard Worker
266*f40fafd4SAndroid Build Coastguard Worker {
267*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_CRYPT_LOCK;
268*f40fafd4SAndroid Build Coastguard Worker success &= fscrypt_destroy_volume_keys(fsUuid);
269*f40fafd4SAndroid Build Coastguard Worker }
270*f40fafd4SAndroid Build Coastguard Worker
271*f40fafd4SAndroid Build Coastguard Worker return translateBool(success);
272*f40fafd4SAndroid Build Coastguard Worker }
273*f40fafd4SAndroid Build Coastguard Worker
mount(const std::string & volId,int32_t mountFlags,int32_t mountUserId,const android::sp<android::os::IVoldMountCallback> & callback)274*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::mount(
275*f40fafd4SAndroid Build Coastguard Worker const std::string& volId, int32_t mountFlags, int32_t mountUserId,
276*f40fafd4SAndroid Build Coastguard Worker const android::sp<android::os::IVoldMountCallback>& callback) {
277*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
278*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_ID(volId);
279*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
280*f40fafd4SAndroid Build Coastguard Worker
281*f40fafd4SAndroid Build Coastguard Worker auto vol = VolumeManager::Instance()->findVolume(volId);
282*f40fafd4SAndroid Build Coastguard Worker if (vol == nullptr) {
283*f40fafd4SAndroid Build Coastguard Worker return error("Failed to find volume " + volId);
284*f40fafd4SAndroid Build Coastguard Worker }
285*f40fafd4SAndroid Build Coastguard Worker
286*f40fafd4SAndroid Build Coastguard Worker vol->setMountFlags(mountFlags);
287*f40fafd4SAndroid Build Coastguard Worker vol->setMountUserId(mountUserId);
288*f40fafd4SAndroid Build Coastguard Worker
289*f40fafd4SAndroid Build Coastguard Worker vol->setMountCallback(callback);
290*f40fafd4SAndroid Build Coastguard Worker int res = vol->mount();
291*f40fafd4SAndroid Build Coastguard Worker vol->setMountCallback(nullptr);
292*f40fafd4SAndroid Build Coastguard Worker
293*f40fafd4SAndroid Build Coastguard Worker if (res != OK) {
294*f40fafd4SAndroid Build Coastguard Worker return translate(res);
295*f40fafd4SAndroid Build Coastguard Worker }
296*f40fafd4SAndroid Build Coastguard Worker
297*f40fafd4SAndroid Build Coastguard Worker return translate(OK);
298*f40fafd4SAndroid Build Coastguard Worker }
299*f40fafd4SAndroid Build Coastguard Worker
unmount(const std::string & volId)300*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::unmount(const std::string& volId) {
301*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
302*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_ID(volId);
303*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
304*f40fafd4SAndroid Build Coastguard Worker
305*f40fafd4SAndroid Build Coastguard Worker auto vol = VolumeManager::Instance()->findVolume(volId);
306*f40fafd4SAndroid Build Coastguard Worker if (vol == nullptr) {
307*f40fafd4SAndroid Build Coastguard Worker return error("Failed to find volume " + volId);
308*f40fafd4SAndroid Build Coastguard Worker }
309*f40fafd4SAndroid Build Coastguard Worker return translate(vol->unmount());
310*f40fafd4SAndroid Build Coastguard Worker }
311*f40fafd4SAndroid Build Coastguard Worker
format(const std::string & volId,const std::string & fsType)312*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) {
313*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
314*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_ID(volId);
315*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
316*f40fafd4SAndroid Build Coastguard Worker
317*f40fafd4SAndroid Build Coastguard Worker auto vol = VolumeManager::Instance()->findVolume(volId);
318*f40fafd4SAndroid Build Coastguard Worker if (vol == nullptr) {
319*f40fafd4SAndroid Build Coastguard Worker return error("Failed to find volume " + volId);
320*f40fafd4SAndroid Build Coastguard Worker }
321*f40fafd4SAndroid Build Coastguard Worker return translate(vol->format(fsType));
322*f40fafd4SAndroid Build Coastguard Worker }
323*f40fafd4SAndroid Build Coastguard Worker
pathForVolId(const std::string & volId,std::string * path)324*f40fafd4SAndroid Build Coastguard Worker static binder::Status pathForVolId(const std::string& volId, std::string* path) {
325*f40fafd4SAndroid Build Coastguard Worker if (volId == "private" || volId == "null") {
326*f40fafd4SAndroid Build Coastguard Worker *path = "/data";
327*f40fafd4SAndroid Build Coastguard Worker } else {
328*f40fafd4SAndroid Build Coastguard Worker auto vol = VolumeManager::Instance()->findVolume(volId);
329*f40fafd4SAndroid Build Coastguard Worker if (vol == nullptr) {
330*f40fafd4SAndroid Build Coastguard Worker return error("Failed to find volume " + volId);
331*f40fafd4SAndroid Build Coastguard Worker }
332*f40fafd4SAndroid Build Coastguard Worker if (vol->getType() != VolumeBase::Type::kPrivate) {
333*f40fafd4SAndroid Build Coastguard Worker return error("Volume " + volId + " not private");
334*f40fafd4SAndroid Build Coastguard Worker }
335*f40fafd4SAndroid Build Coastguard Worker if (vol->getState() != VolumeBase::State::kMounted) {
336*f40fafd4SAndroid Build Coastguard Worker return error("Volume " + volId + " not mounted");
337*f40fafd4SAndroid Build Coastguard Worker }
338*f40fafd4SAndroid Build Coastguard Worker *path = vol->getPath();
339*f40fafd4SAndroid Build Coastguard Worker if (path->empty()) {
340*f40fafd4SAndroid Build Coastguard Worker return error("Volume " + volId + " missing path");
341*f40fafd4SAndroid Build Coastguard Worker }
342*f40fafd4SAndroid Build Coastguard Worker }
343*f40fafd4SAndroid Build Coastguard Worker return Ok();
344*f40fafd4SAndroid Build Coastguard Worker }
345*f40fafd4SAndroid Build Coastguard Worker
benchmark(const std::string & volId,const android::sp<android::os::IVoldTaskListener> & listener)346*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::benchmark(
347*f40fafd4SAndroid Build Coastguard Worker const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) {
348*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
349*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_ID(volId);
350*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
351*f40fafd4SAndroid Build Coastguard Worker
352*f40fafd4SAndroid Build Coastguard Worker std::string path;
353*f40fafd4SAndroid Build Coastguard Worker auto status = pathForVolId(volId, &path);
354*f40fafd4SAndroid Build Coastguard Worker if (!status.isOk()) return status;
355*f40fafd4SAndroid Build Coastguard Worker
356*f40fafd4SAndroid Build Coastguard Worker std::thread([=]() { android::vold::Benchmark(path, listener); }).detach();
357*f40fafd4SAndroid Build Coastguard Worker return Ok();
358*f40fafd4SAndroid Build Coastguard Worker }
359*f40fafd4SAndroid Build Coastguard Worker
moveStorage(const std::string & fromVolId,const std::string & toVolId,const android::sp<android::os::IVoldTaskListener> & listener)360*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::moveStorage(
361*f40fafd4SAndroid Build Coastguard Worker const std::string& fromVolId, const std::string& toVolId,
362*f40fafd4SAndroid Build Coastguard Worker const android::sp<android::os::IVoldTaskListener>& listener) {
363*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
364*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_ID(fromVolId);
365*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_ID(toVolId);
366*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
367*f40fafd4SAndroid Build Coastguard Worker
368*f40fafd4SAndroid Build Coastguard Worker auto fromVol = VolumeManager::Instance()->findVolume(fromVolId);
369*f40fafd4SAndroid Build Coastguard Worker auto toVol = VolumeManager::Instance()->findVolume(toVolId);
370*f40fafd4SAndroid Build Coastguard Worker if (fromVol == nullptr) {
371*f40fafd4SAndroid Build Coastguard Worker return error("Failed to find volume " + fromVolId);
372*f40fafd4SAndroid Build Coastguard Worker } else if (toVol == nullptr) {
373*f40fafd4SAndroid Build Coastguard Worker return error("Failed to find volume " + toVolId);
374*f40fafd4SAndroid Build Coastguard Worker }
375*f40fafd4SAndroid Build Coastguard Worker
376*f40fafd4SAndroid Build Coastguard Worker std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach();
377*f40fafd4SAndroid Build Coastguard Worker return Ok();
378*f40fafd4SAndroid Build Coastguard Worker }
379*f40fafd4SAndroid Build Coastguard Worker
remountUid(int32_t uid,int32_t remountMode)380*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) {
381*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
382*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
383*f40fafd4SAndroid Build Coastguard Worker
384*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->remountUid(uid, remountMode));
385*f40fafd4SAndroid Build Coastguard Worker }
386*f40fafd4SAndroid Build Coastguard Worker
remountAppStorageDirs(int uid,int pid,const std::vector<std::string> & packageNames)387*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::remountAppStorageDirs(int uid, int pid,
388*f40fafd4SAndroid Build Coastguard Worker const std::vector<std::string>& packageNames) {
389*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
390*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
391*f40fafd4SAndroid Build Coastguard Worker
392*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->handleAppStorageDirs(uid, pid,
393*f40fafd4SAndroid Build Coastguard Worker false /* doUnmount */, packageNames));
394*f40fafd4SAndroid Build Coastguard Worker }
395*f40fafd4SAndroid Build Coastguard Worker
unmountAppStorageDirs(int uid,int pid,const std::vector<std::string> & packageNames)396*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::unmountAppStorageDirs(int uid, int pid,
397*f40fafd4SAndroid Build Coastguard Worker const std::vector<std::string>& packageNames) {
398*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
399*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
400*f40fafd4SAndroid Build Coastguard Worker
401*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->handleAppStorageDirs(uid, pid,
402*f40fafd4SAndroid Build Coastguard Worker true /* doUnmount */, packageNames));
403*f40fafd4SAndroid Build Coastguard Worker }
404*f40fafd4SAndroid Build Coastguard Worker
setupAppDir(const std::string & path,int32_t appUid)405*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::setupAppDir(const std::string& path, int32_t appUid) {
406*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
407*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_PATH(path);
408*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
409*f40fafd4SAndroid Build Coastguard Worker
410*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->setupAppDir(path, appUid));
411*f40fafd4SAndroid Build Coastguard Worker }
412*f40fafd4SAndroid Build Coastguard Worker
ensureAppDirsCreated(const std::vector<std::string> & paths,int32_t appUid)413*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::ensureAppDirsCreated(const std::vector<std::string>& paths,
414*f40fafd4SAndroid Build Coastguard Worker int32_t appUid) {
415*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
416*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
417*f40fafd4SAndroid Build Coastguard Worker
418*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->ensureAppDirsCreated(paths, appUid));
419*f40fafd4SAndroid Build Coastguard Worker }
420*f40fafd4SAndroid Build Coastguard Worker
fixupAppDir(const std::string & path,int32_t appUid)421*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::fixupAppDir(const std::string& path, int32_t appUid) {
422*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
423*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_PATH(path);
424*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
425*f40fafd4SAndroid Build Coastguard Worker
426*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->fixupAppDir(path, appUid));
427*f40fafd4SAndroid Build Coastguard Worker }
428*f40fafd4SAndroid Build Coastguard Worker
createObb(const std::string & sourcePath,int32_t ownerGid,std::string * _aidl_return)429*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::createObb(const std::string& sourcePath, int32_t ownerGid,
430*f40fafd4SAndroid Build Coastguard Worker std::string* _aidl_return) {
431*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
432*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_PATH(sourcePath);
433*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
434*f40fafd4SAndroid Build Coastguard Worker
435*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->createObb(sourcePath, ownerGid, _aidl_return));
436*f40fafd4SAndroid Build Coastguard Worker }
437*f40fafd4SAndroid Build Coastguard Worker
destroyObb(const std::string & volId)438*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::destroyObb(const std::string& volId) {
439*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
440*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_ID(volId);
441*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
442*f40fafd4SAndroid Build Coastguard Worker
443*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->destroyObb(volId));
444*f40fafd4SAndroid Build Coastguard Worker }
445*f40fafd4SAndroid Build Coastguard Worker
createStubVolume(const std::string & sourcePath,const std::string & mountPath,const std::string & fsType,const std::string & fsUuid,const std::string & fsLabel,int32_t flags,std::string * _aidl_return)446*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::createStubVolume(const std::string& sourcePath,
447*f40fafd4SAndroid Build Coastguard Worker const std::string& mountPath,
448*f40fafd4SAndroid Build Coastguard Worker const std::string& fsType,
449*f40fafd4SAndroid Build Coastguard Worker const std::string& fsUuid,
450*f40fafd4SAndroid Build Coastguard Worker const std::string& fsLabel, int32_t flags,
451*f40fafd4SAndroid Build Coastguard Worker std::string* _aidl_return) {
452*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
453*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_PATH(sourcePath);
454*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_PATH(mountPath);
455*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_HEX(fsUuid);
456*f40fafd4SAndroid Build Coastguard Worker // Label limitation seems to be different between fs (including allowed characters), so checking
457*f40fafd4SAndroid Build Coastguard Worker // is quite meaningless.
458*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
459*f40fafd4SAndroid Build Coastguard Worker
460*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->createStubVolume(
461*f40fafd4SAndroid Build Coastguard Worker sourcePath, mountPath, fsType, fsUuid, fsLabel, flags, _aidl_return));
462*f40fafd4SAndroid Build Coastguard Worker }
463*f40fafd4SAndroid Build Coastguard Worker
destroyStubVolume(const std::string & volId)464*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::destroyStubVolume(const std::string& volId) {
465*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
466*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_ID(volId);
467*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
468*f40fafd4SAndroid Build Coastguard Worker
469*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->destroyStubVolume(volId));
470*f40fafd4SAndroid Build Coastguard Worker }
471*f40fafd4SAndroid Build Coastguard Worker
fstrim(int32_t fstrimFlags,const android::sp<android::os::IVoldTaskListener> & listener)472*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::fstrim(
473*f40fafd4SAndroid Build Coastguard Worker int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) {
474*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
475*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
476*f40fafd4SAndroid Build Coastguard Worker
477*f40fafd4SAndroid Build Coastguard Worker std::thread([=]() { android::vold::Trim(listener); }).detach();
478*f40fafd4SAndroid Build Coastguard Worker return Ok();
479*f40fafd4SAndroid Build Coastguard Worker }
480*f40fafd4SAndroid Build Coastguard Worker
runIdleMaint(bool needGC,const android::sp<android::os::IVoldTaskListener> & listener)481*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::runIdleMaint(
482*f40fafd4SAndroid Build Coastguard Worker bool needGC, const android::sp<android::os::IVoldTaskListener>& listener) {
483*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
484*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
485*f40fafd4SAndroid Build Coastguard Worker
486*f40fafd4SAndroid Build Coastguard Worker std::thread([=]() { android::vold::RunIdleMaint(needGC, listener); }).detach();
487*f40fafd4SAndroid Build Coastguard Worker return Ok();
488*f40fafd4SAndroid Build Coastguard Worker }
489*f40fafd4SAndroid Build Coastguard Worker
abortIdleMaint(const android::sp<android::os::IVoldTaskListener> & listener)490*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::abortIdleMaint(
491*f40fafd4SAndroid Build Coastguard Worker const android::sp<android::os::IVoldTaskListener>& listener) {
492*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
493*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
494*f40fafd4SAndroid Build Coastguard Worker
495*f40fafd4SAndroid Build Coastguard Worker std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach();
496*f40fafd4SAndroid Build Coastguard Worker return Ok();
497*f40fafd4SAndroid Build Coastguard Worker }
498*f40fafd4SAndroid Build Coastguard Worker
getStorageLifeTime(int32_t * _aidl_return)499*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::getStorageLifeTime(int32_t* _aidl_return) {
500*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
501*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
502*f40fafd4SAndroid Build Coastguard Worker
503*f40fafd4SAndroid Build Coastguard Worker *_aidl_return = GetStorageLifeTime();
504*f40fafd4SAndroid Build Coastguard Worker return Ok();
505*f40fafd4SAndroid Build Coastguard Worker }
506*f40fafd4SAndroid Build Coastguard Worker
getStorageRemainingLifetime(int32_t * _aidl_return)507*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::getStorageRemainingLifetime(int32_t* _aidl_return) {
508*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
509*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
510*f40fafd4SAndroid Build Coastguard Worker
511*f40fafd4SAndroid Build Coastguard Worker *_aidl_return = GetStorageRemainingLifetime();
512*f40fafd4SAndroid Build Coastguard Worker return Ok();
513*f40fafd4SAndroid Build Coastguard Worker }
514*f40fafd4SAndroid Build Coastguard Worker
setGCUrgentPace(int32_t neededSegments,int32_t minSegmentThreshold,float dirtyReclaimRate,float reclaimWeight,int32_t gcPeriod,int32_t minGCSleepTime,int32_t targetDirtyRatio)515*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::setGCUrgentPace(int32_t neededSegments,
516*f40fafd4SAndroid Build Coastguard Worker int32_t minSegmentThreshold,
517*f40fafd4SAndroid Build Coastguard Worker float dirtyReclaimRate, float reclaimWeight,
518*f40fafd4SAndroid Build Coastguard Worker int32_t gcPeriod, int32_t minGCSleepTime,
519*f40fafd4SAndroid Build Coastguard Worker int32_t targetDirtyRatio) {
520*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
521*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
522*f40fafd4SAndroid Build Coastguard Worker
523*f40fafd4SAndroid Build Coastguard Worker SetGCUrgentPace(neededSegments, minSegmentThreshold, dirtyReclaimRate, reclaimWeight, gcPeriod,
524*f40fafd4SAndroid Build Coastguard Worker minGCSleepTime, targetDirtyRatio);
525*f40fafd4SAndroid Build Coastguard Worker return Ok();
526*f40fafd4SAndroid Build Coastguard Worker }
527*f40fafd4SAndroid Build Coastguard Worker
refreshLatestWrite()528*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::refreshLatestWrite() {
529*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
530*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
531*f40fafd4SAndroid Build Coastguard Worker
532*f40fafd4SAndroid Build Coastguard Worker RefreshLatestWrite();
533*f40fafd4SAndroid Build Coastguard Worker return Ok();
534*f40fafd4SAndroid Build Coastguard Worker }
535*f40fafd4SAndroid Build Coastguard Worker
getWriteAmount(int32_t * _aidl_return)536*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::getWriteAmount(int32_t* _aidl_return) {
537*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
538*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
539*f40fafd4SAndroid Build Coastguard Worker
540*f40fafd4SAndroid Build Coastguard Worker *_aidl_return = GetWriteAmount();
541*f40fafd4SAndroid Build Coastguard Worker return Ok();
542*f40fafd4SAndroid Build Coastguard Worker }
543*f40fafd4SAndroid Build Coastguard Worker
mountAppFuse(int32_t uid,int32_t mountId,android::base::unique_fd * _aidl_return)544*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t mountId,
545*f40fafd4SAndroid Build Coastguard Worker android::base::unique_fd* _aidl_return) {
546*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
547*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
548*f40fafd4SAndroid Build Coastguard Worker
549*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->mountAppFuse(uid, mountId, _aidl_return));
550*f40fafd4SAndroid Build Coastguard Worker }
551*f40fafd4SAndroid Build Coastguard Worker
unmountAppFuse(int32_t uid,int32_t mountId)552*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t mountId) {
553*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
554*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
555*f40fafd4SAndroid Build Coastguard Worker
556*f40fafd4SAndroid Build Coastguard Worker return translate(VolumeManager::Instance()->unmountAppFuse(uid, mountId));
557*f40fafd4SAndroid Build Coastguard Worker }
558*f40fafd4SAndroid Build Coastguard Worker
openAppFuseFile(int32_t uid,int32_t mountId,int32_t fileId,int32_t flags,android::base::unique_fd * _aidl_return)559*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::openAppFuseFile(int32_t uid, int32_t mountId, int32_t fileId,
560*f40fafd4SAndroid Build Coastguard Worker int32_t flags,
561*f40fafd4SAndroid Build Coastguard Worker android::base::unique_fd* _aidl_return) {
562*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
563*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
564*f40fafd4SAndroid Build Coastguard Worker
565*f40fafd4SAndroid Build Coastguard Worker int fd = VolumeManager::Instance()->openAppFuseFile(uid, mountId, fileId, flags);
566*f40fafd4SAndroid Build Coastguard Worker if (fd == -1) {
567*f40fafd4SAndroid Build Coastguard Worker return error("Failed to open AppFuse file for uid: " + std::to_string(uid) +
568*f40fafd4SAndroid Build Coastguard Worker " mountId: " + std::to_string(mountId) + " fileId: " + std::to_string(fileId) +
569*f40fafd4SAndroid Build Coastguard Worker " flags: " + std::to_string(flags));
570*f40fafd4SAndroid Build Coastguard Worker }
571*f40fafd4SAndroid Build Coastguard Worker
572*f40fafd4SAndroid Build Coastguard Worker *_aidl_return = android::base::unique_fd(fd);
573*f40fafd4SAndroid Build Coastguard Worker return Ok();
574*f40fafd4SAndroid Build Coastguard Worker }
575*f40fafd4SAndroid Build Coastguard Worker
fbeEnable()576*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::fbeEnable() {
577*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
578*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_CRYPT_LOCK;
579*f40fafd4SAndroid Build Coastguard Worker
580*f40fafd4SAndroid Build Coastguard Worker return translateBool(fscrypt_initialize_systemwide_keys());
581*f40fafd4SAndroid Build Coastguard Worker }
582*f40fafd4SAndroid Build Coastguard Worker
initUser0()583*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::initUser0() {
584*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
585*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_CRYPT_LOCK;
586*f40fafd4SAndroid Build Coastguard Worker
587*f40fafd4SAndroid Build Coastguard Worker return translateBool(fscrypt_init_user0());
588*f40fafd4SAndroid Build Coastguard Worker }
589*f40fafd4SAndroid Build Coastguard Worker
mountFstab(const std::string & blkDevice,const std::string & mountPoint,bool isZoned,const std::vector<std::string> & userDevices)590*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::mountFstab(const std::string& blkDevice,
591*f40fafd4SAndroid Build Coastguard Worker const std::string& mountPoint, bool isZoned,
592*f40fafd4SAndroid Build Coastguard Worker const std::vector<std::string>& userDevices) {
593*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
594*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
595*f40fafd4SAndroid Build Coastguard Worker
596*f40fafd4SAndroid Build Coastguard Worker return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false, false,
597*f40fafd4SAndroid Build Coastguard Worker "null", isZoned, userDevices, {}, 0));
598*f40fafd4SAndroid Build Coastguard Worker }
599*f40fafd4SAndroid Build Coastguard Worker
encryptFstab(const std::string & blkDevice,const std::string & mountPoint,bool shouldFormat,const std::string & fsType,bool isZoned,const std::vector<std::string> & userDevices,const std::vector<bool> & deviceAliased,int64_t length)600*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice,
601*f40fafd4SAndroid Build Coastguard Worker const std::string& mountPoint, bool shouldFormat,
602*f40fafd4SAndroid Build Coastguard Worker const std::string& fsType, bool isZoned,
603*f40fafd4SAndroid Build Coastguard Worker const std::vector<std::string>& userDevices,
604*f40fafd4SAndroid Build Coastguard Worker const std::vector<bool>& deviceAliased,
605*f40fafd4SAndroid Build Coastguard Worker int64_t length) {
606*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
607*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
608*f40fafd4SAndroid Build Coastguard Worker
609*f40fafd4SAndroid Build Coastguard Worker return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true, shouldFormat,
610*f40fafd4SAndroid Build Coastguard Worker fsType, isZoned, userDevices,
611*f40fafd4SAndroid Build Coastguard Worker deviceAliased, length));
612*f40fafd4SAndroid Build Coastguard Worker }
613*f40fafd4SAndroid Build Coastguard Worker
setStorageBindingSeed(const std::vector<uint8_t> & seed)614*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::setStorageBindingSeed(const std::vector<uint8_t>& seed) {
615*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
616*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_CRYPT_LOCK;
617*f40fafd4SAndroid Build Coastguard Worker
618*f40fafd4SAndroid Build Coastguard Worker return translateBool(setKeyStorageBindingSeed(seed));
619*f40fafd4SAndroid Build Coastguard Worker }
620*f40fafd4SAndroid Build Coastguard Worker
createUserStorageKeys(int32_t userId,bool ephemeral)621*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::createUserStorageKeys(int32_t userId, bool ephemeral) {
622*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
623*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_CRYPT_LOCK;
624*f40fafd4SAndroid Build Coastguard Worker
625*f40fafd4SAndroid Build Coastguard Worker return translateBool(fscrypt_create_user_keys(userId, ephemeral));
626*f40fafd4SAndroid Build Coastguard Worker }
627*f40fafd4SAndroid Build Coastguard Worker
destroyUserStorageKeys(int32_t userId)628*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::destroyUserStorageKeys(int32_t userId) {
629*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
630*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_CRYPT_LOCK;
631*f40fafd4SAndroid Build Coastguard Worker
632*f40fafd4SAndroid Build Coastguard Worker return translateBool(fscrypt_destroy_user_keys(userId));
633*f40fafd4SAndroid Build Coastguard Worker }
634*f40fafd4SAndroid Build Coastguard Worker
setCeStorageProtection(int32_t userId,const std::vector<uint8_t> & secret)635*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::setCeStorageProtection(int32_t userId,
636*f40fafd4SAndroid Build Coastguard Worker const std::vector<uint8_t>& secret) {
637*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
638*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_CRYPT_LOCK;
639*f40fafd4SAndroid Build Coastguard Worker
640*f40fafd4SAndroid Build Coastguard Worker return translateBool(fscrypt_set_ce_key_protection(userId, secret));
641*f40fafd4SAndroid Build Coastguard Worker }
642*f40fafd4SAndroid Build Coastguard Worker
getUnlockedUsers(std::vector<int> * _aidl_return)643*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::getUnlockedUsers(std::vector<int>* _aidl_return) {
644*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
645*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_CRYPT_LOCK;
646*f40fafd4SAndroid Build Coastguard Worker
647*f40fafd4SAndroid Build Coastguard Worker *_aidl_return = fscrypt_get_unlocked_users();
648*f40fafd4SAndroid Build Coastguard Worker return Ok();
649*f40fafd4SAndroid Build Coastguard Worker }
650*f40fafd4SAndroid Build Coastguard Worker
unlockCeStorage(int32_t userId,const std::vector<uint8_t> & secret)651*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::unlockCeStorage(int32_t userId,
652*f40fafd4SAndroid Build Coastguard Worker const std::vector<uint8_t>& secret) {
653*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
654*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_CRYPT_LOCK;
655*f40fafd4SAndroid Build Coastguard Worker
656*f40fafd4SAndroid Build Coastguard Worker return translateBool(fscrypt_unlock_ce_storage(userId, secret));
657*f40fafd4SAndroid Build Coastguard Worker }
658*f40fafd4SAndroid Build Coastguard Worker
lockCeStorage(int32_t userId)659*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::lockCeStorage(int32_t userId) {
660*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
661*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_CRYPT_LOCK;
662*f40fafd4SAndroid Build Coastguard Worker
663*f40fafd4SAndroid Build Coastguard Worker return translateBool(fscrypt_lock_ce_storage(userId));
664*f40fafd4SAndroid Build Coastguard Worker }
665*f40fafd4SAndroid Build Coastguard Worker
prepareUserStorage(const std::optional<std::string> & uuid,int32_t userId,int32_t flags)666*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::prepareUserStorage(const std::optional<std::string>& uuid,
667*f40fafd4SAndroid Build Coastguard Worker int32_t userId, int32_t flags) {
668*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
669*f40fafd4SAndroid Build Coastguard Worker std::string empty_string = "";
670*f40fafd4SAndroid Build Coastguard Worker auto uuid_ = uuid ? *uuid : empty_string;
671*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_HEX(uuid_);
672*f40fafd4SAndroid Build Coastguard Worker
673*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_CRYPT_LOCK;
674*f40fafd4SAndroid Build Coastguard Worker return translateBool(fscrypt_prepare_user_storage(uuid_, userId, flags));
675*f40fafd4SAndroid Build Coastguard Worker }
676*f40fafd4SAndroid Build Coastguard Worker
destroyUserStorage(const std::optional<std::string> & uuid,int32_t userId,int32_t flags)677*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::destroyUserStorage(const std::optional<std::string>& uuid,
678*f40fafd4SAndroid Build Coastguard Worker int32_t userId, int32_t flags) {
679*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
680*f40fafd4SAndroid Build Coastguard Worker std::string empty_string = "";
681*f40fafd4SAndroid Build Coastguard Worker auto uuid_ = uuid ? *uuid : empty_string;
682*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_HEX(uuid_);
683*f40fafd4SAndroid Build Coastguard Worker
684*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_CRYPT_LOCK;
685*f40fafd4SAndroid Build Coastguard Worker return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags));
686*f40fafd4SAndroid Build Coastguard Worker }
687*f40fafd4SAndroid Build Coastguard Worker
prepareSandboxForApp(const std::string & packageName,int32_t appId,const std::string & sandboxId,int32_t userId)688*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName,
689*f40fafd4SAndroid Build Coastguard Worker int32_t appId, const std::string& sandboxId,
690*f40fafd4SAndroid Build Coastguard Worker int32_t userId) {
691*f40fafd4SAndroid Build Coastguard Worker return Ok();
692*f40fafd4SAndroid Build Coastguard Worker }
693*f40fafd4SAndroid Build Coastguard Worker
destroySandboxForApp(const std::string & packageName,const std::string & sandboxId,int32_t userId)694*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName,
695*f40fafd4SAndroid Build Coastguard Worker const std::string& sandboxId,
696*f40fafd4SAndroid Build Coastguard Worker int32_t userId) {
697*f40fafd4SAndroid Build Coastguard Worker return Ok();
698*f40fafd4SAndroid Build Coastguard Worker }
699*f40fafd4SAndroid Build Coastguard Worker
startCheckpoint(int32_t retry)700*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::startCheckpoint(int32_t retry) {
701*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
702*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
703*f40fafd4SAndroid Build Coastguard Worker
704*f40fafd4SAndroid Build Coastguard Worker return cp_startCheckpoint(retry);
705*f40fafd4SAndroid Build Coastguard Worker }
706*f40fafd4SAndroid Build Coastguard Worker
needsRollback(bool * _aidl_return)707*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::needsRollback(bool* _aidl_return) {
708*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
709*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
710*f40fafd4SAndroid Build Coastguard Worker
711*f40fafd4SAndroid Build Coastguard Worker *_aidl_return = cp_needsRollback();
712*f40fafd4SAndroid Build Coastguard Worker return Ok();
713*f40fafd4SAndroid Build Coastguard Worker }
714*f40fafd4SAndroid Build Coastguard Worker
needsCheckpoint(bool * _aidl_return)715*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) {
716*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
717*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
718*f40fafd4SAndroid Build Coastguard Worker
719*f40fafd4SAndroid Build Coastguard Worker *_aidl_return = cp_needsCheckpoint();
720*f40fafd4SAndroid Build Coastguard Worker return Ok();
721*f40fafd4SAndroid Build Coastguard Worker }
722*f40fafd4SAndroid Build Coastguard Worker
isCheckpointing(bool * _aidl_return)723*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::isCheckpointing(bool* _aidl_return) {
724*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
725*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
726*f40fafd4SAndroid Build Coastguard Worker
727*f40fafd4SAndroid Build Coastguard Worker *_aidl_return = cp_isCheckpointing();
728*f40fafd4SAndroid Build Coastguard Worker return Ok();
729*f40fafd4SAndroid Build Coastguard Worker }
730*f40fafd4SAndroid Build Coastguard Worker
commitChanges()731*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::commitChanges() {
732*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
733*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
734*f40fafd4SAndroid Build Coastguard Worker
735*f40fafd4SAndroid Build Coastguard Worker return cp_commitChanges();
736*f40fafd4SAndroid Build Coastguard Worker }
737*f40fafd4SAndroid Build Coastguard Worker
prepareCheckpoint()738*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::prepareCheckpoint() {
739*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
740*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
741*f40fafd4SAndroid Build Coastguard Worker
742*f40fafd4SAndroid Build Coastguard Worker return cp_prepareCheckpoint();
743*f40fafd4SAndroid Build Coastguard Worker }
744*f40fafd4SAndroid Build Coastguard Worker
restoreCheckpoint(const std::string & mountPoint)745*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) {
746*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
747*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_PATH(mountPoint);
748*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
749*f40fafd4SAndroid Build Coastguard Worker
750*f40fafd4SAndroid Build Coastguard Worker return cp_restoreCheckpoint(mountPoint);
751*f40fafd4SAndroid Build Coastguard Worker }
752*f40fafd4SAndroid Build Coastguard Worker
restoreCheckpointPart(const std::string & mountPoint,int count)753*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::restoreCheckpointPart(const std::string& mountPoint, int count) {
754*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
755*f40fafd4SAndroid Build Coastguard Worker CHECK_ARGUMENT_PATH(mountPoint);
756*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
757*f40fafd4SAndroid Build Coastguard Worker
758*f40fafd4SAndroid Build Coastguard Worker return cp_restoreCheckpoint(mountPoint, count);
759*f40fafd4SAndroid Build Coastguard Worker }
760*f40fafd4SAndroid Build Coastguard Worker
markBootAttempt()761*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::markBootAttempt() {
762*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
763*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
764*f40fafd4SAndroid Build Coastguard Worker
765*f40fafd4SAndroid Build Coastguard Worker return cp_markBootAttempt();
766*f40fafd4SAndroid Build Coastguard Worker }
767*f40fafd4SAndroid Build Coastguard Worker
abortChanges(const std::string & message,bool retry)768*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::abortChanges(const std::string& message, bool retry) {
769*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
770*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
771*f40fafd4SAndroid Build Coastguard Worker
772*f40fafd4SAndroid Build Coastguard Worker cp_abortChanges(message, retry);
773*f40fafd4SAndroid Build Coastguard Worker return Ok();
774*f40fafd4SAndroid Build Coastguard Worker }
775*f40fafd4SAndroid Build Coastguard Worker
supportsCheckpoint(bool * _aidl_return)776*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) {
777*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
778*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
779*f40fafd4SAndroid Build Coastguard Worker
780*f40fafd4SAndroid Build Coastguard Worker return cp_supportsCheckpoint(*_aidl_return);
781*f40fafd4SAndroid Build Coastguard Worker }
782*f40fafd4SAndroid Build Coastguard Worker
supportsBlockCheckpoint(bool * _aidl_return)783*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::supportsBlockCheckpoint(bool* _aidl_return) {
784*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
785*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
786*f40fafd4SAndroid Build Coastguard Worker
787*f40fafd4SAndroid Build Coastguard Worker return cp_supportsBlockCheckpoint(*_aidl_return);
788*f40fafd4SAndroid Build Coastguard Worker }
789*f40fafd4SAndroid Build Coastguard Worker
supportsFileCheckpoint(bool * _aidl_return)790*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::supportsFileCheckpoint(bool* _aidl_return) {
791*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
792*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
793*f40fafd4SAndroid Build Coastguard Worker
794*f40fafd4SAndroid Build Coastguard Worker return cp_supportsFileCheckpoint(*_aidl_return);
795*f40fafd4SAndroid Build Coastguard Worker }
796*f40fafd4SAndroid Build Coastguard Worker
resetCheckpoint()797*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::resetCheckpoint() {
798*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
799*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
800*f40fafd4SAndroid Build Coastguard Worker
801*f40fafd4SAndroid Build Coastguard Worker cp_resetCheckpoint();
802*f40fafd4SAndroid Build Coastguard Worker return Ok();
803*f40fafd4SAndroid Build Coastguard Worker }
804*f40fafd4SAndroid Build Coastguard Worker
initializeIncFs()805*f40fafd4SAndroid Build Coastguard Worker static void initializeIncFs() {
806*f40fafd4SAndroid Build Coastguard Worker // Obtaining IncFS features triggers initialization of IncFS.
807*f40fafd4SAndroid Build Coastguard Worker incfs::features();
808*f40fafd4SAndroid Build Coastguard Worker }
809*f40fafd4SAndroid Build Coastguard Worker
earlyBootEnded()810*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::earlyBootEnded() {
811*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
812*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
813*f40fafd4SAndroid Build Coastguard Worker
814*f40fafd4SAndroid Build Coastguard Worker initializeIncFs();
815*f40fafd4SAndroid Build Coastguard Worker Keystore::earlyBootEnded();
816*f40fafd4SAndroid Build Coastguard Worker return Ok();
817*f40fafd4SAndroid Build Coastguard Worker }
818*f40fafd4SAndroid Build Coastguard Worker
incFsEnabled(bool * _aidl_return)819*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::incFsEnabled(bool* _aidl_return) {
820*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
821*f40fafd4SAndroid Build Coastguard Worker
822*f40fafd4SAndroid Build Coastguard Worker *_aidl_return = incfs::enabled();
823*f40fafd4SAndroid Build Coastguard Worker return Ok();
824*f40fafd4SAndroid Build Coastguard Worker }
825*f40fafd4SAndroid Build Coastguard Worker
mountIncFs(const std::string & backingPath,const std::string & targetDir,int32_t flags,const std::string & sysfsName,::android::os::incremental::IncrementalFileSystemControlParcel * _aidl_return)826*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::mountIncFs(
827*f40fafd4SAndroid Build Coastguard Worker const std::string& backingPath, const std::string& targetDir, int32_t flags,
828*f40fafd4SAndroid Build Coastguard Worker const std::string& sysfsName,
829*f40fafd4SAndroid Build Coastguard Worker ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) {
830*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
831*f40fafd4SAndroid Build Coastguard Worker if (auto status = CheckIncrementalPath(IncrementalPathKind::MountTarget, targetDir);
832*f40fafd4SAndroid Build Coastguard Worker !status.isOk()) {
833*f40fafd4SAndroid Build Coastguard Worker return status;
834*f40fafd4SAndroid Build Coastguard Worker }
835*f40fafd4SAndroid Build Coastguard Worker if (auto status = CheckIncrementalPath(IncrementalPathKind::MountSource, backingPath);
836*f40fafd4SAndroid Build Coastguard Worker !status.isOk()) {
837*f40fafd4SAndroid Build Coastguard Worker return status;
838*f40fafd4SAndroid Build Coastguard Worker }
839*f40fafd4SAndroid Build Coastguard Worker
840*f40fafd4SAndroid Build Coastguard Worker auto [backingFd, backingSymlink] = OpenDirInProcfs(backingPath);
841*f40fafd4SAndroid Build Coastguard Worker if (!backingFd.ok()) {
842*f40fafd4SAndroid Build Coastguard Worker return translate(-errno);
843*f40fafd4SAndroid Build Coastguard Worker }
844*f40fafd4SAndroid Build Coastguard Worker auto [targetFd, targetSymlink] = OpenDirInProcfs(targetDir);
845*f40fafd4SAndroid Build Coastguard Worker if (!targetFd.ok()) {
846*f40fafd4SAndroid Build Coastguard Worker return translate(-errno);
847*f40fafd4SAndroid Build Coastguard Worker }
848*f40fafd4SAndroid Build Coastguard Worker
849*f40fafd4SAndroid Build Coastguard Worker auto control = incfs::mount(backingSymlink, targetSymlink,
850*f40fafd4SAndroid Build Coastguard Worker {.flags = IncFsMountFlags(flags),
851*f40fafd4SAndroid Build Coastguard Worker // Mount with read timeouts.
852*f40fafd4SAndroid Build Coastguard Worker .defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS,
853*f40fafd4SAndroid Build Coastguard Worker // Mount with read logs disabled.
854*f40fafd4SAndroid Build Coastguard Worker .readLogBufferPages = 0,
855*f40fafd4SAndroid Build Coastguard Worker .sysfsName = sysfsName.c_str()});
856*f40fafd4SAndroid Build Coastguard Worker if (!control) {
857*f40fafd4SAndroid Build Coastguard Worker return translate(-errno);
858*f40fafd4SAndroid Build Coastguard Worker }
859*f40fafd4SAndroid Build Coastguard Worker auto fds = control.releaseFds();
860*f40fafd4SAndroid Build Coastguard Worker using android::base::unique_fd;
861*f40fafd4SAndroid Build Coastguard Worker _aidl_return->cmd.reset(unique_fd(fds[CMD].release()));
862*f40fafd4SAndroid Build Coastguard Worker _aidl_return->pendingReads.reset(unique_fd(fds[PENDING_READS].release()));
863*f40fafd4SAndroid Build Coastguard Worker _aidl_return->log.reset(unique_fd(fds[LOGS].release()));
864*f40fafd4SAndroid Build Coastguard Worker if (fds[BLOCKS_WRITTEN].ok()) {
865*f40fafd4SAndroid Build Coastguard Worker _aidl_return->blocksWritten.emplace(unique_fd(fds[BLOCKS_WRITTEN].release()));
866*f40fafd4SAndroid Build Coastguard Worker }
867*f40fafd4SAndroid Build Coastguard Worker return Ok();
868*f40fafd4SAndroid Build Coastguard Worker }
869*f40fafd4SAndroid Build Coastguard Worker
unmountIncFs(const std::string & dir)870*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::unmountIncFs(const std::string& dir) {
871*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
872*f40fafd4SAndroid Build Coastguard Worker if (auto status = CheckIncrementalPath(IncrementalPathKind::Any, dir); !status.isOk()) {
873*f40fafd4SAndroid Build Coastguard Worker return status;
874*f40fafd4SAndroid Build Coastguard Worker }
875*f40fafd4SAndroid Build Coastguard Worker
876*f40fafd4SAndroid Build Coastguard Worker auto [fd, symLink] = OpenDirInProcfs(dir);
877*f40fafd4SAndroid Build Coastguard Worker if (!fd.ok()) {
878*f40fafd4SAndroid Build Coastguard Worker return translate(-errno);
879*f40fafd4SAndroid Build Coastguard Worker }
880*f40fafd4SAndroid Build Coastguard Worker return translate(incfs::unmount(symLink));
881*f40fafd4SAndroid Build Coastguard Worker }
882*f40fafd4SAndroid Build Coastguard Worker
setIncFsMountOptions(const::android::os::incremental::IncrementalFileSystemControlParcel & control,bool enableReadLogs,bool enableReadTimeouts,const std::string & sysfsName)883*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::setIncFsMountOptions(
884*f40fafd4SAndroid Build Coastguard Worker const ::android::os::incremental::IncrementalFileSystemControlParcel& control,
885*f40fafd4SAndroid Build Coastguard Worker bool enableReadLogs, bool enableReadTimeouts, const std::string& sysfsName) {
886*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
887*f40fafd4SAndroid Build Coastguard Worker
888*f40fafd4SAndroid Build Coastguard Worker auto incfsControl =
889*f40fafd4SAndroid Build Coastguard Worker incfs::createControl(control.cmd.get(), control.pendingReads.get(), control.log.get(),
890*f40fafd4SAndroid Build Coastguard Worker control.blocksWritten ? control.blocksWritten->get() : -1);
891*f40fafd4SAndroid Build Coastguard Worker auto cleanupFunc = [](auto incfsControl) {
892*f40fafd4SAndroid Build Coastguard Worker for (auto& fd : incfsControl->releaseFds()) {
893*f40fafd4SAndroid Build Coastguard Worker (void)fd.release();
894*f40fafd4SAndroid Build Coastguard Worker }
895*f40fafd4SAndroid Build Coastguard Worker };
896*f40fafd4SAndroid Build Coastguard Worker auto cleanup =
897*f40fafd4SAndroid Build Coastguard Worker std::unique_ptr<incfs::Control, decltype(cleanupFunc)>(&incfsControl, cleanupFunc);
898*f40fafd4SAndroid Build Coastguard Worker
899*f40fafd4SAndroid Build Coastguard Worker constexpr auto minReadLogBufferPages = INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES;
900*f40fafd4SAndroid Build Coastguard Worker constexpr auto maxReadLogBufferPages = 8 * INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES;
901*f40fafd4SAndroid Build Coastguard Worker auto options = incfs::MountOptions{
902*f40fafd4SAndroid Build Coastguard Worker .defaultReadTimeoutMs =
903*f40fafd4SAndroid Build Coastguard Worker enableReadTimeouts ? INCFS_DEFAULT_READ_TIMEOUT_MS : kIncFsReadNoTimeoutMs,
904*f40fafd4SAndroid Build Coastguard Worker .readLogBufferPages = enableReadLogs ? maxReadLogBufferPages : 0,
905*f40fafd4SAndroid Build Coastguard Worker .sysfsName = sysfsName.c_str()};
906*f40fafd4SAndroid Build Coastguard Worker
907*f40fafd4SAndroid Build Coastguard Worker for (;;) {
908*f40fafd4SAndroid Build Coastguard Worker const auto error = incfs::setOptions(incfsControl, options);
909*f40fafd4SAndroid Build Coastguard Worker if (!error) {
910*f40fafd4SAndroid Build Coastguard Worker return Ok();
911*f40fafd4SAndroid Build Coastguard Worker }
912*f40fafd4SAndroid Build Coastguard Worker if (!enableReadLogs || error != -ENOMEM) {
913*f40fafd4SAndroid Build Coastguard Worker return binder::Status::fromServiceSpecificError(error);
914*f40fafd4SAndroid Build Coastguard Worker }
915*f40fafd4SAndroid Build Coastguard Worker // In case of memory allocation error retry with a smaller buffer.
916*f40fafd4SAndroid Build Coastguard Worker options.readLogBufferPages /= 2;
917*f40fafd4SAndroid Build Coastguard Worker if (options.readLogBufferPages < minReadLogBufferPages) {
918*f40fafd4SAndroid Build Coastguard Worker return binder::Status::fromServiceSpecificError(error);
919*f40fafd4SAndroid Build Coastguard Worker }
920*f40fafd4SAndroid Build Coastguard Worker }
921*f40fafd4SAndroid Build Coastguard Worker // unreachable, but makes the compiler happy
922*f40fafd4SAndroid Build Coastguard Worker return Ok();
923*f40fafd4SAndroid Build Coastguard Worker }
924*f40fafd4SAndroid Build Coastguard Worker
bindMount(const std::string & sourceDir,const std::string & targetDir)925*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::bindMount(const std::string& sourceDir,
926*f40fafd4SAndroid Build Coastguard Worker const std::string& targetDir) {
927*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
928*f40fafd4SAndroid Build Coastguard Worker if (auto status = CheckIncrementalPath(IncrementalPathKind::Any, sourceDir); !status.isOk()) {
929*f40fafd4SAndroid Build Coastguard Worker return status;
930*f40fafd4SAndroid Build Coastguard Worker }
931*f40fafd4SAndroid Build Coastguard Worker if (auto status = CheckIncrementalPath(IncrementalPathKind::Bind, targetDir); !status.isOk()) {
932*f40fafd4SAndroid Build Coastguard Worker return status;
933*f40fafd4SAndroid Build Coastguard Worker }
934*f40fafd4SAndroid Build Coastguard Worker
935*f40fafd4SAndroid Build Coastguard Worker auto [sourceFd, sourceSymlink] = OpenDirInProcfs(sourceDir);
936*f40fafd4SAndroid Build Coastguard Worker if (!sourceFd.ok()) {
937*f40fafd4SAndroid Build Coastguard Worker return translate(-errno);
938*f40fafd4SAndroid Build Coastguard Worker }
939*f40fafd4SAndroid Build Coastguard Worker auto [targetFd, targetSymlink] = OpenDirInProcfs(targetDir);
940*f40fafd4SAndroid Build Coastguard Worker if (!targetFd.ok()) {
941*f40fafd4SAndroid Build Coastguard Worker return translate(-errno);
942*f40fafd4SAndroid Build Coastguard Worker }
943*f40fafd4SAndroid Build Coastguard Worker return translate(incfs::bindMount(sourceSymlink, targetSymlink));
944*f40fafd4SAndroid Build Coastguard Worker }
945*f40fafd4SAndroid Build Coastguard Worker
destroyDsuMetadataKey(const std::string & dsuSlot)946*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::destroyDsuMetadataKey(const std::string& dsuSlot) {
947*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
948*f40fafd4SAndroid Build Coastguard Worker ACQUIRE_LOCK;
949*f40fafd4SAndroid Build Coastguard Worker
950*f40fafd4SAndroid Build Coastguard Worker return translateBool(destroy_dsu_metadata_key(dsuSlot));
951*f40fafd4SAndroid Build Coastguard Worker }
952*f40fafd4SAndroid Build Coastguard Worker
getStorageSize(int64_t * storageSize)953*f40fafd4SAndroid Build Coastguard Worker binder::Status VoldNativeService::getStorageSize(int64_t* storageSize) {
954*f40fafd4SAndroid Build Coastguard Worker ENFORCE_SYSTEM_OR_ROOT;
955*f40fafd4SAndroid Build Coastguard Worker return translate(GetStorageSize(storageSize));
956*f40fafd4SAndroid Build Coastguard Worker }
957*f40fafd4SAndroid Build Coastguard Worker
958*f40fafd4SAndroid Build Coastguard Worker } // namespace vold
959*f40fafd4SAndroid Build Coastguard Worker } // namespace android
960