blob: 45661ec47045b2a0db9f580030bdfa01acd2778d [file] [log] [blame]
Tom Marshalle3d144e2019-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* kMountPath = "/sbin/mount.ntfs";
36
37status_t Mount(const std::string& source, const std::string& target, bool ro, bool remount,
38 bool executable, int ownerUid, int ownerGid, int permMask) {
39 char mountData[255];
40
41 const char* c_source = source.c_str();
42 const char* c_target = target.c_str();
43
44 sprintf(mountData,
45 "utf8,uid=%d,gid=%d,fmask=%o,dmask=%o,"
46 "shortname=mixed,nodev,nosuid,dirsync",
47 ownerUid, ownerGid, permMask, permMask);
48
49 if (!executable) strlcat(mountData, ",noexec", sizeof(mountData));
50 if (ro) strlcat(mountData, ",ro", sizeof(mountData));
51 if (remount) strlcat(mountData, ",remount", sizeof(mountData));
52
53 std::vector<std::string> cmd;
54 cmd.push_back(kMountPath);
55 cmd.push_back("-o");
56 cmd.push_back(mountData);
57 cmd.push_back(c_source);
58 cmd.push_back(c_target);
59
60 return ForkExecvp(cmd);
61}
62
63} // namespace ntfs
64} // namespace volmgr
65} // namespace android