Mike Frysinger | 38ae98d | 2012-04-11 12:03:44 -0400 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "cros-disks/platform.h" |
| 6 | |
Ben Chan | 35cd7ae | 2019-05-02 22:42:37 -0700 | [diff] [blame] | 7 | #include <errno.h> |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 8 | #include <sys/mount.h> |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 9 | #include <sys/stat.h> |
| 10 | #include <unistd.h> |
| 11 | |
Ben Chan | 5e3ca67 | 2014-08-25 15:53:58 -0700 | [diff] [blame] | 12 | #include <memory> |
| 13 | #include <vector> |
| 14 | |
Qijiang Fan | 713061e | 2021-03-08 15:45:12 +0900 | [diff] [blame] | 15 | #include <base/check.h> |
Ben Chan | cd8fda4 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 16 | #include <base/files/file_util.h> |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 17 | #include <base/logging.h> |
Heng-Ruey Hsu | 5759506 | 2016-05-24 16:48:58 +0800 | [diff] [blame] | 18 | #include <base/memory/free_deleter.h> |
Mike Frysinger | 38ae98d | 2012-04-11 12:03:44 -0400 | [diff] [blame] | 19 | #include <base/stl_util.h> |
Ben Chan | 97e20d4 | 2014-02-05 18:38:07 -0800 | [diff] [blame] | 20 | #include <base/strings/string_util.h> |
| 21 | #include <base/strings/stringprintf.h> |
Ben Chan | 950db3d | 2018-10-31 13:55:02 -0700 | [diff] [blame] | 22 | #include <brillo/userdb_utils.h> |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 23 | |
François Degros | 8b4e31e | 2019-07-29 11:39:19 +1000 | [diff] [blame] | 24 | #include "cros-disks/quote.h" |
| 25 | |
Ben Chan | 460439f | 2011-09-13 09:16:28 -0700 | [diff] [blame] | 26 | namespace cros_disks { |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 27 | |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 28 | Platform::Platform() |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 29 | : mount_group_id_(0), mount_user_id_(0), mount_user_("root") {} |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 30 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 31 | bool Platform::GetRealPath(const std::string& path, |
| 32 | std::string* real_path) const { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 33 | CHECK(real_path) << "Invalid real_path argument"; |
| 34 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 35 | std::unique_ptr<char, base::FreeDeleter> result( |
| 36 | realpath(path.c_str(), nullptr)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 37 | if (!result) { |
Austin Tankiang | a57f577 | 2021-05-18 18:41:56 +1000 | [diff] [blame] | 38 | PLOG(ERROR) << "Cannot get real path of " << redact(path); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 39 | return false; |
| 40 | } |
| 41 | |
| 42 | *real_path = result.get(); |
| 43 | return true; |
| 44 | } |
| 45 | |
Sergei Datsenko | 0f014d2 | 2018-04-04 16:37:22 +1000 | [diff] [blame] | 46 | bool Platform::PathExists(const std::string& path) const { |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 47 | return base::PathExists(base::FilePath(path)); |
Sergei Datsenko | 0f014d2 | 2018-04-04 16:37:22 +1000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | bool Platform::DirectoryExists(const std::string& path) const { |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 51 | return base::DirectoryExists(base::FilePath(path)); |
Sergei Datsenko | 0f014d2 | 2018-04-04 16:37:22 +1000 | [diff] [blame] | 52 | } |
| 53 | |
Sergei Datsenko | e2d1d0b | 2020-11-18 12:48:13 +1100 | [diff] [blame] | 54 | bool Platform::Lstat(const std::string& path, base::stat_wrapper_t* out) const { |
| 55 | return base::File::Lstat(path.c_str(), out) == 0; |
| 56 | } |
| 57 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 58 | bool Platform::CreateDirectory(const std::string& path) const { |
| 59 | if (!base::CreateDirectory(base::FilePath(path))) { |
François Degros | 8b4e31e | 2019-07-29 11:39:19 +1000 | [diff] [blame] | 60 | LOG(ERROR) << "Cannot create directory " << quote(path); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 61 | return false; |
| 62 | } |
François Degros | 8b4e31e | 2019-07-29 11:39:19 +1000 | [diff] [blame] | 63 | LOG(INFO) << "Created directory " << quote(path); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 64 | return true; |
| 65 | } |
| 66 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 67 | bool Platform::CreateOrReuseEmptyDirectory(const std::string& path) const { |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 68 | CHECK(!path.empty()) << "Invalid path argument"; |
| 69 | |
| 70 | // Reuse the target path if it already exists and is empty. |
| 71 | // rmdir handles the cases when the target path exists but |
| 72 | // is not empty, is already mounted or is used by some process. |
| 73 | rmdir(path.c_str()); |
| 74 | if (mkdir(path.c_str(), S_IRWXU) != 0) { |
François Degros | c309d93 | 2021-02-04 15:12:30 +1100 | [diff] [blame] | 75 | PLOG(ERROR) << "Cannot create directory " << redact(path); |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 76 | return false; |
| 77 | } |
| 78 | return true; |
| 79 | } |
| 80 | |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 81 | bool Platform::CreateOrReuseEmptyDirectoryWithFallback( |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 82 | std::string* path, |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 83 | unsigned max_suffix_to_retry, |
Sergei Datsenko | 7e7c764 | 2021-01-08 19:15:34 +1100 | [diff] [blame] | 84 | const std::unordered_set<std::string>& reserved_paths) const { |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 85 | CHECK(path && !path->empty()) << "Invalid path argument"; |
| 86 | |
Qijiang Fan | 5243904 | 2020-06-17 15:34:38 +0900 | [diff] [blame] | 87 | if (!base::Contains(reserved_paths, *path) && |
Eric Caruso | e8f5ba1 | 2018-01-10 14:32:03 -0800 | [diff] [blame] | 88 | CreateOrReuseEmptyDirectory(*path)) |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 89 | return true; |
| 90 | |
| 91 | for (unsigned suffix = 1; suffix <= max_suffix_to_retry; ++suffix) { |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 92 | std::string fallback_path = GetDirectoryFallbackName(*path, suffix); |
Qijiang Fan | 5243904 | 2020-06-17 15:34:38 +0900 | [diff] [blame] | 93 | if (!base::Contains(reserved_paths, fallback_path) && |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 94 | CreateOrReuseEmptyDirectory(fallback_path)) { |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 95 | *path = fallback_path; |
| 96 | return true; |
| 97 | } |
| 98 | } |
| 99 | return false; |
| 100 | } |
| 101 | |
Sergei Datsenko | bcd8e46 | 2018-04-20 15:44:56 +1000 | [diff] [blame] | 102 | bool Platform::CreateTemporaryDirInDir(const std::string& dir, |
| 103 | const std::string& prefix, |
| 104 | std::string* path) const { |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 105 | base::FilePath dest; |
| 106 | bool result = |
| 107 | base::CreateTemporaryDirInDir(base::FilePath(dir), prefix, &dest); |
Sergei Datsenko | bcd8e46 | 2018-04-20 15:44:56 +1000 | [diff] [blame] | 108 | if (result && path) |
| 109 | *path = dest.value(); |
| 110 | return result; |
| 111 | } |
| 112 | |
Sergei Datsenko | ad2cb6a | 2018-05-15 17:34:26 +1000 | [diff] [blame] | 113 | int Platform::WriteFile(const std::string& file, |
| 114 | const char* data, |
| 115 | int size) const { |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 116 | return base::WriteFile(base::FilePath(file), data, size); |
Sergei Datsenko | ad2cb6a | 2018-05-15 17:34:26 +1000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | int Platform::ReadFile(const std::string& file, char* data, int size) const { |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 120 | return base::ReadFile(base::FilePath(file), data, size); |
Sergei Datsenko | bcd8e46 | 2018-04-20 15:44:56 +1000 | [diff] [blame] | 121 | } |
| 122 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 123 | std::string Platform::GetDirectoryFallbackName(const std::string& path, |
| 124 | unsigned suffix) const { |
Alex Vakulenko | e50371c | 2016-01-20 16:06:19 -0800 | [diff] [blame] | 125 | if (!path.empty() && base::IsAsciiDigit(path[path.size() - 1])) |
Ben Chan | ec4eaab | 2012-02-05 23:26:58 -0800 | [diff] [blame] | 126 | return base::StringPrintf("%s (%u)", path.c_str(), suffix); |
| 127 | |
| 128 | return base::StringPrintf("%s %u", path.c_str(), suffix); |
| 129 | } |
| 130 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 131 | bool Platform::GetGroupId(const std::string& group_name, |
| 132 | gid_t* group_id) const { |
Ben Chan | 950db3d | 2018-10-31 13:55:02 -0700 | [diff] [blame] | 133 | return brillo::userdb::GetGroupInfo(group_name, group_id); |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 136 | bool Platform::GetUserAndGroupId(const std::string& user_name, |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 137 | uid_t* user_id, |
| 138 | gid_t* group_id) const { |
Ben Chan | 950db3d | 2018-10-31 13:55:02 -0700 | [diff] [blame] | 139 | return brillo::userdb::GetUserInfo(user_name, user_id, group_id); |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 142 | bool Platform::GetOwnership(const std::string& path, |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 143 | uid_t* user_id, |
| 144 | gid_t* group_id) const { |
Ben Chan | b1ac5a8 | 2011-08-02 17:53:55 -0700 | [diff] [blame] | 145 | struct stat path_status; |
| 146 | if (stat(path.c_str(), &path_status) != 0) { |
François Degros | 8b4e31e | 2019-07-29 11:39:19 +1000 | [diff] [blame] | 147 | PLOG(ERROR) << "Cannot get ownership info for " << quote(path); |
Ben Chan | b1ac5a8 | 2011-08-02 17:53:55 -0700 | [diff] [blame] | 148 | return false; |
| 149 | } |
| 150 | |
| 151 | if (user_id) |
| 152 | *user_id = path_status.st_uid; |
| 153 | |
| 154 | if (group_id) |
| 155 | *group_id = path_status.st_gid; |
| 156 | |
| 157 | return true; |
| 158 | } |
| 159 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 160 | bool Platform::GetPermissions(const std::string& path, mode_t* mode) const { |
Ben Chan | b1ac5a8 | 2011-08-02 17:53:55 -0700 | [diff] [blame] | 161 | CHECK(mode) << "Invalid mode argument"; |
| 162 | |
| 163 | struct stat path_status; |
| 164 | if (stat(path.c_str(), &path_status) != 0) { |
François Degros | 8b4e31e | 2019-07-29 11:39:19 +1000 | [diff] [blame] | 165 | PLOG(ERROR) << "Cannot get the permissions of " << quote(path); |
Ben Chan | b1ac5a8 | 2011-08-02 17:53:55 -0700 | [diff] [blame] | 166 | return false; |
| 167 | } |
| 168 | *mode = path_status.st_mode; |
| 169 | return true; |
| 170 | } |
| 171 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 172 | bool Platform::SetMountUser(const std::string& user_name) { |
Ben Chan | 98f8ae0 | 2011-10-04 16:34:34 -0700 | [diff] [blame] | 173 | if (GetUserAndGroupId(user_name, &mount_user_id_, &mount_group_id_)) { |
| 174 | mount_user_ = user_name; |
| 175 | return true; |
| 176 | } |
| 177 | return false; |
Ben Chan | 93dec93 | 2011-08-03 12:57:49 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 180 | bool Platform::RemoveEmptyDirectory(const std::string& path) const { |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 181 | if (rmdir(path.c_str()) != 0) { |
François Degros | 8b4e31e | 2019-07-29 11:39:19 +1000 | [diff] [blame] | 182 | PLOG(ERROR) << "Cannot remove directory " << quote(path); |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 183 | return false; |
| 184 | } |
| 185 | return true; |
| 186 | } |
| 187 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 188 | bool Platform::SetOwnership(const std::string& path, |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 189 | uid_t user_id, |
| 190 | gid_t group_id) const { |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 191 | if (chown(path.c_str(), user_id, group_id)) { |
François Degros | 8b4e31e | 2019-07-29 11:39:19 +1000 | [diff] [blame] | 192 | PLOG(ERROR) << "Cannot set ownership of " << quote(path) << " to uid " |
| 193 | << user_id << " and gid " << group_id; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 194 | return false; |
| 195 | } |
| 196 | return true; |
| 197 | } |
| 198 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 199 | bool Platform::SetPermissions(const std::string& path, mode_t mode) const { |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 200 | if (chmod(path.c_str(), mode)) { |
François Degros | 8b4e31e | 2019-07-29 11:39:19 +1000 | [diff] [blame] | 201 | PLOG(ERROR) << "Cannot set permissions of " << quote(path) << " to " |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 202 | << base::StringPrintf("%04o", mode); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 203 | return false; |
| 204 | } |
| 205 | return true; |
| 206 | } |
| 207 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 208 | MountErrorType Platform::Unmount(const std::string& path, int flags) const { |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 209 | error_t error = 0; |
Anand K Mistry | 68418e6 | 2018-08-22 11:37:04 +1000 | [diff] [blame] | 210 | if (umount2(path.c_str(), flags) != 0) { |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 211 | error = errno; |
François Degros | 8b4e31e | 2019-07-29 11:39:19 +1000 | [diff] [blame] | 212 | PLOG(ERROR) << "Cannot unmount " << quote(path) << " with flags " << flags; |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 213 | } else { |
François Degros | 8b4e31e | 2019-07-29 11:39:19 +1000 | [diff] [blame] | 214 | LOG(INFO) << "Unmounted " << quote(path) << " with flags " << flags; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 215 | } |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 216 | switch (error) { |
| 217 | case 0: |
François Degros | 3a79690 | 2019-07-12 14:49:58 +1000 | [diff] [blame] | 218 | return MOUNT_ERROR_NONE; |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 219 | case ENOENT: |
François Degros | 3a79690 | 2019-07-12 14:49:58 +1000 | [diff] [blame] | 220 | return MOUNT_ERROR_PATH_NOT_MOUNTED; |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 221 | case EPERM: |
François Degros | 3a79690 | 2019-07-12 14:49:58 +1000 | [diff] [blame] | 222 | return MOUNT_ERROR_INSUFFICIENT_PERMISSIONS; |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 223 | case EBUSY: |
François Degros | 3a79690 | 2019-07-12 14:49:58 +1000 | [diff] [blame] | 224 | return MOUNT_ERROR_PATH_ALREADY_MOUNTED; |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 225 | default: |
François Degros | 3a79690 | 2019-07-12 14:49:58 +1000 | [diff] [blame] | 226 | return MOUNT_ERROR_UNKNOWN; |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 227 | } |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 230 | MountErrorType Platform::Mount(const std::string& source_path, |
| 231 | const std::string& target_path, |
| 232 | const std::string& filesystem_type, |
François Degros | 5abcca2 | 2020-09-10 16:51:13 +1000 | [diff] [blame] | 233 | const uint64_t flags, |
| 234 | const std::string& options) const { |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 235 | // Pass the nosymfollow option as both a flag and a string option for |
| 236 | // compatibility across kernels. The mount syscall ignores unknown flags, |
| 237 | // so kernels that don't have MS_NOSYMFOLLOW will pick up nosymfollow from |
| 238 | // the data parameter through the chromiumos LSM. Kernels that do have |
| 239 | // MS_NOSYMFOLLOW will pick up the same behavior directly from the flag; |
| 240 | // our LSM ignores the string option in that case. |
| 241 | // |
| 242 | // TODO(b/152074038): Remove the string option once all devices have been |
| 243 | // upreved to a kernel that supports MS_NOSYMFOLLOW (currently 5.4+). |
| 244 | std::string mount_options = options; |
| 245 | if ((flags & MS_NOSYMFOLLOW) == MS_NOSYMFOLLOW) { |
Sergei Datsenko | 84c2d0d | 2020-10-12 11:02:35 +1100 | [diff] [blame] | 246 | if (!mount_options.empty()) { |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 247 | mount_options += ","; |
| 248 | } |
Sergei Datsenko | 84c2d0d | 2020-10-12 11:02:35 +1100 | [diff] [blame] | 249 | mount_options += "nosymfollow"; |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 250 | } |
| 251 | |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 252 | error_t error = 0; |
Sam McNally | c56ae31 | 2018-05-22 13:14:27 +1000 | [diff] [blame] | 253 | if (mount(source_path.c_str(), target_path.c_str(), filesystem_type.c_str(), |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 254 | flags, mount_options.c_str()) != 0) { |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 255 | error = errno; |
François Degros | 5abcca2 | 2020-09-10 16:51:13 +1000 | [diff] [blame] | 256 | PLOG(ERROR) << "Cannot create mount point " << quote(target_path) << " for " |
| 257 | << quote(source_path) << " as filesystem " |
| 258 | << quote(filesystem_type) << " with flags 0x" << std::hex |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 259 | << flags << " and options " << quote(mount_options); |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 260 | } else { |
François Degros | 5abcca2 | 2020-09-10 16:51:13 +1000 | [diff] [blame] | 261 | LOG(INFO) << "Created mount point " << quote(target_path) << " for " |
| 262 | << quote(source_path) << " as filesystem " |
| 263 | << quote(filesystem_type) << " with flags 0x" << std::hex << flags |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 264 | << " and options " << quote(mount_options); |
Sam McNally | c56ae31 | 2018-05-22 13:14:27 +1000 | [diff] [blame] | 265 | } |
François Degros | 5abcca2 | 2020-09-10 16:51:13 +1000 | [diff] [blame] | 266 | |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 267 | switch (error) { |
| 268 | case 0: |
François Degros | 3a79690 | 2019-07-12 14:49:58 +1000 | [diff] [blame] | 269 | return MOUNT_ERROR_NONE; |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 270 | case ENODEV: |
François Degros | 3a79690 | 2019-07-12 14:49:58 +1000 | [diff] [blame] | 271 | return MOUNT_ERROR_UNSUPPORTED_FILESYSTEM; |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 272 | case ENOENT: |
| 273 | case ENOTBLK: |
| 274 | case ENOTDIR: |
François Degros | 3a79690 | 2019-07-12 14:49:58 +1000 | [diff] [blame] | 275 | return MOUNT_ERROR_INVALID_PATH; |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 276 | case EPERM: |
François Degros | 3a79690 | 2019-07-12 14:49:58 +1000 | [diff] [blame] | 277 | return MOUNT_ERROR_INSUFFICIENT_PERMISSIONS; |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 278 | default: |
François Degros | 3a79690 | 2019-07-12 14:49:58 +1000 | [diff] [blame] | 279 | return MOUNT_ERROR_UNKNOWN; |
Sergei Datsenko | b362e4a | 2019-04-03 17:23:24 +1100 | [diff] [blame] | 280 | } |
Sam McNally | c56ae31 | 2018-05-22 13:14:27 +1000 | [diff] [blame] | 281 | } |
| 282 | |
Ben Chan | 29be915 | 2011-07-25 14:39:48 -0700 | [diff] [blame] | 283 | } // namespace cros_disks |