-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserdata_alias_remove.cpp
More file actions
66 lines (56 loc) · 2.09 KB
/
Copy pathuserdata_alias_remove.cpp
File metadata and controls
66 lines (56 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* This removes a userdata aliasing file, which maps storage space for
* a specific purpose to a special-purpose partition, allowing for its
* later release.
*/
#include <errno.h>
#include <error.h>
#include <stdio.h>
#include <android-base/file.h>
#include <android-base/properties.h>
#include <fstab/fstab.h>
static constexpr const char* ALIAS_REMOVE_PROP_NAME = "userdata.alias.remove";
int main(void) {
android::fs_mgr::Fstab fstab;
if (!android::fs_mgr::ReadDefaultFstab(&fstab)) {
error(1, 0, "no valid fstab");
}
android::fs_mgr::FstabEntry* dataEntry =
android::fs_mgr::GetEntryForMountPoint(&fstab, "/data");
if (!dataEntry) {
error(1, 0, "/data is not mounted yet");
}
/* Only F2FS supports device aliasing file */
if (dataEntry->fs_type != "f2fs") {
return 0;
}
std::string target = android::base::GetProperty(ALIAS_REMOVE_PROP_NAME, "");
for (size_t i = 0; i < dataEntry->user_devices.size(); ++i) {
if (dataEntry->device_aliased[i]) {
std::string deviceName = android::base::Basename(dataEntry->user_devices[i]);
if (target == deviceName) {
std::string filename = "/data/" + target;
if (unlink(filename.c_str())) {
error(1, errno, "Failed to remove file: %s", filename.c_str());
}
return 0;
}
}
}
error(1, 0, "%s is not a device aliasing file", target.c_str());
}