blob: d0b1143caefd26c76fa09a16903dbfeb0f28dc48 [file] [log] [blame]
Dan Pasanend2509612015-10-27 22:52:37 -05001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "Exfat.h"
18#include "Utils.h"
19
20#include <android-base/logging.h>
21#include <android-base/stringprintf.h>
22
23#include <vector>
24#include <string>
25
26#include <sys/mount.h>
27
28using android::base::StringPrintf;
29
30namespace android {
31namespace vold {
32namespace exfat {
33
34static const char* kMkfsPath = "/system/bin/mkfs.exfat";
35static const char* kFsckPath = "/system/bin/fsck.exfat";
Ketut Putu Kumajayafb6bf982015-12-02 16:17:23 +070036#ifdef CONFIG_KERNEL_HAVE_EXFAT
37static const char* kMountPath = "/system/bin/mount";
38#else
Dan Pasanend2509612015-10-27 22:52:37 -050039static const char* kMountPath = "/system/bin/mount.exfat";
Ketut Putu Kumajayafb6bf982015-12-02 16:17:23 +070040#endif
Dan Pasanend2509612015-10-27 22:52:37 -050041
42bool IsSupported() {
43 return access(kMkfsPath, X_OK) == 0
44 && access(kFsckPath, X_OK) == 0
45 && access(kMountPath, X_OK) == 0
46 && IsFilesystemSupported("exfat");
47}
48
49status_t Check(const std::string& source) {
50 std::vector<std::string> cmd;
51 cmd.push_back(kFsckPath);
52 cmd.push_back(source);
53
Michael Bestas7e0bc982015-12-06 23:53:55 +020054 // Exfat devices are currently always untrusted
55 return ForkExecvp(cmd, sFsckUntrustedContext);
Dan Pasanend2509612015-10-27 22:52:37 -050056}
57
58status_t Mount(const std::string& source, const std::string& target, bool ro,
59 bool remount, bool executable, int ownerUid, int ownerGid, int permMask) {
60 char mountData[255];
61
62 const char* c_source = source.c_str();
63 const char* c_target = target.c_str();
64
65 sprintf(mountData,
Ketut Putu Kumajayafb6bf982015-12-02 16:17:23 +070066#ifdef CONFIG_KERNEL_HAVE_EXFAT
67 "noatime,nodev,nosuid,uid=%d,gid=%d,fmask=%o,dmask=%o,%s,%s",
68#else
Dan Pasanend2509612015-10-27 22:52:37 -050069 "noatime,nodev,nosuid,dirsync,uid=%d,gid=%d,fmask=%o,dmask=%o,%s,%s",
Ketut Putu Kumajayafb6bf982015-12-02 16:17:23 +070070#endif
Dan Pasanend2509612015-10-27 22:52:37 -050071 ownerUid, ownerGid, permMask, permMask,
72 (executable ? "exec" : "noexec"),
73 (ro ? "ro" : "rw"));
74
75 std::vector<std::string> cmd;
76 cmd.push_back(kMountPath);
Ketut Putu Kumajayafb6bf982015-12-02 16:17:23 +070077#ifdef CONFIG_KERNEL_HAVE_EXFAT
78 cmd.push_back("-t");
79 cmd.push_back("exfat");
80#endif
Dan Pasanend2509612015-10-27 22:52:37 -050081 cmd.push_back("-o");
82 cmd.push_back(mountData);
83 cmd.push_back(c_source);
84 cmd.push_back(c_target);
85
86 return ForkExecvp(cmd);
87}
88
89status_t Format(const std::string& source) {
90 std::vector<std::string> cmd;
91 cmd.push_back(kMkfsPath);
92 cmd.push_back(source);
93
94 return ForkExecvp(cmd);
95}
96
97} // namespace exfat
98} // namespace vold
99} // namespace android