Dan Pasanen | d250961 | 2015-10-27 22:52:37 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 28 | using android::base::StringPrintf; |
| 29 | |
| 30 | namespace android { |
| 31 | namespace vold { |
| 32 | namespace exfat { |
| 33 | |
| 34 | static const char* kMkfsPath = "/system/bin/mkfs.exfat"; |
| 35 | static const char* kFsckPath = "/system/bin/fsck.exfat"; |
Ketut Putu Kumajaya | fb6bf98 | 2015-12-02 16:17:23 +0700 | [diff] [blame] | 36 | #ifdef CONFIG_KERNEL_HAVE_EXFAT |
| 37 | static const char* kMountPath = "/system/bin/mount"; |
| 38 | #else |
Dan Pasanen | d250961 | 2015-10-27 22:52:37 -0500 | [diff] [blame] | 39 | static const char* kMountPath = "/system/bin/mount.exfat"; |
Ketut Putu Kumajaya | fb6bf98 | 2015-12-02 16:17:23 +0700 | [diff] [blame] | 40 | #endif |
Dan Pasanen | d250961 | 2015-10-27 22:52:37 -0500 | [diff] [blame] | 41 | |
| 42 | bool 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 | |
| 49 | status_t Check(const std::string& source) { |
| 50 | std::vector<std::string> cmd; |
| 51 | cmd.push_back(kFsckPath); |
| 52 | cmd.push_back(source); |
| 53 | |
Michael Bestas | 7e0bc98 | 2015-12-06 23:53:55 +0200 | [diff] [blame] | 54 | // Exfat devices are currently always untrusted |
| 55 | return ForkExecvp(cmd, sFsckUntrustedContext); |
Dan Pasanen | d250961 | 2015-10-27 22:52:37 -0500 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | status_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 Kumajaya | fb6bf98 | 2015-12-02 16:17:23 +0700 | [diff] [blame] | 66 | #ifdef CONFIG_KERNEL_HAVE_EXFAT |
| 67 | "noatime,nodev,nosuid,uid=%d,gid=%d,fmask=%o,dmask=%o,%s,%s", |
| 68 | #else |
Dan Pasanen | d250961 | 2015-10-27 22:52:37 -0500 | [diff] [blame] | 69 | "noatime,nodev,nosuid,dirsync,uid=%d,gid=%d,fmask=%o,dmask=%o,%s,%s", |
Ketut Putu Kumajaya | fb6bf98 | 2015-12-02 16:17:23 +0700 | [diff] [blame] | 70 | #endif |
Dan Pasanen | d250961 | 2015-10-27 22:52:37 -0500 | [diff] [blame] | 71 | 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 Kumajaya | fb6bf98 | 2015-12-02 16:17:23 +0700 | [diff] [blame] | 77 | #ifdef CONFIG_KERNEL_HAVE_EXFAT |
| 78 | cmd.push_back("-t"); |
| 79 | cmd.push_back("exfat"); |
| 80 | #endif |
Dan Pasanen | d250961 | 2015-10-27 22:52:37 -0500 | [diff] [blame] | 81 | 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 | |
| 89 | status_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 |