blob: 798e58d4c987db37919e13e0c67ed539d107d4ec [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#include "Ntfs.h"
19#include "Utils.h"
20
21#include <android-base/logging.h>
22#include <android-base/stringprintf.h>
23
24#include <string>
25#include <vector>
26
27#include <sys/mount.h>
28
29using android::base::StringPrintf;
30
31namespace android {
32namespace volmgr {
33namespace ntfs {
34
35static const char* kFsckPath = "/sbin/fsck.ntfs";
36static const char* kMountPath = "/sbin/mount.ntfs";
37
38bool IsSupported() {
39 return access(kFsckPath, X_OK) == 0 && access(kMountPath, X_OK) == 0 &&
40 IsFilesystemSupported("ntfs");
41}
42
43status_t Check(const std::string& source) {
44 std::vector<std::string> cmd;
45 cmd.push_back(kFsckPath);
46 cmd.push_back("-n");
47 cmd.push_back(source);
48
49 // Ntfs devices are currently always untrusted
50 return ForkExecvp(cmd, sFsckUntrustedContext);
51}
52
53status_t Mount(const std::string& source, const std::string& target, bool ro, bool remount,
54 bool executable, int ownerUid, int ownerGid, int permMask) {
55 char mountData[255];
56
57 const char* c_source = source.c_str();
58 const char* c_target = target.c_str();
59
60 sprintf(mountData,
61 "utf8,uid=%d,gid=%d,fmask=%o,dmask=%o,"
62 "shortname=mixed,nodev,nosuid,dirsync",
63 ownerUid, ownerGid, permMask, permMask);
64
65 if (!executable) strlcat(mountData, ",noexec", sizeof(mountData));
66 if (ro) strlcat(mountData, ",ro", sizeof(mountData));
67 if (remount) strlcat(mountData, ",remount", sizeof(mountData));
68
69 std::vector<std::string> cmd;
70 cmd.push_back(kMountPath);
71 cmd.push_back("-o");
72 cmd.push_back(mountData);
73 cmd.push_back(c_source);
74 cmd.push_back(c_target);
75
76 return ForkExecvp(cmd);
77}
78
79} // namespace ntfs
80} // namespace volmgr
81} // namespace android