blob: 94ca6e70b1d402f6eda0f11a7ed0bc89bd6fca46 [file] [log] [blame]
Tom Marshallbead2612019-01-04 14:37:31 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 * Copyright (C) 2019 The LineageOS Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef ANDROID_VOLMGR_UTILS_H
19#define ANDROID_VOLMGR_UTILS_H
20
21#include <cutils/multiuser.h>
22#include <selinux/selinux.h>
23#include <utils/Errors.h>
24
25#include <chrono>
26#include <string>
27#include <vector>
28
29// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions. It goes in the private:
30// declarations in a class.
31#if !defined(DISALLOW_COPY_AND_ASSIGN)
32#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
33 TypeName(const TypeName&) = delete; \
34 void operator=(const TypeName&) = delete
35#endif
36
37struct DIR;
38
39namespace android {
40namespace volmgr {
41
42/* SELinux contexts used depending on the block device type */
43extern security_context_t sBlkidContext;
44extern security_context_t sBlkidUntrustedContext;
45extern security_context_t sFsckContext;
46extern security_context_t sFsckUntrustedContext;
47
48status_t CreateDeviceNode(const std::string& path, dev_t dev);
49status_t DestroyDeviceNode(const std::string& path);
50
51/* fs_prepare_dir wrapper that creates with SELinux context */
52status_t PrepareDir(const std::string& path, mode_t mode, uid_t uid, gid_t gid);
53
54/* Really unmounts the path, killing active processes along the way */
55status_t ForceUnmount(const std::string& path, bool detach = false);
56
57/* Kills any processes using given path */
58status_t KillProcessesUsingPath(const std::string& path);
59
60/* Creates bind mount from source to target */
61status_t BindMount(const std::string& source, const std::string& target);
62
63/* Reads filesystem metadata from device at path */
64status_t ReadMetadata(const std::string& path, std::string& fsType, std::string& fsUuid,
65 std::string& fsLabel);
66
67/* Reads filesystem metadata from untrusted device at path */
68status_t ReadMetadataUntrusted(const std::string& path, std::string& fsType, std::string& fsUuid,
69 std::string& fsLabel);
70
71/* Returns either WEXITSTATUS() status, or a negative errno */
72status_t ForkExecvp(const std::vector<std::string>& args);
73status_t ForkExecvp(const std::vector<std::string>& args, security_context_t context);
74
75bool IsFilesystemSupported(const std::string& fsType);
76
77/* Wipes contents of block device at given path */
78status_t WipeBlockDevice(const std::string& path);
79
80dev_t GetDevice(const std::string& path);
81
82/* Checks if Android is running in QEMU */
83bool IsRunningInEmulator();
84
85} // namespace volmgr
86} // namespace android
87
88#endif