| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "nacl_io/kernel_object.h" | 5 #include "nacl_io/kernel_object.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <pthread.h> | 10 #include <pthread.h> |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 return 0; | 92 return 0; |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 return ENOTDIR; | 96 return ENOTDIR; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Given a path, acquire the associated filesystem and node, creating the | 99 // Given a path, acquire the associated filesystem and node, creating the |
| 100 // node if needed based on the provided flags. | 100 // node if needed based on the provided flags. |
| 101 Error KernelObject::AcquireFsAndNode(const std::string& path, | 101 Error KernelObject::AcquireFsAndNode(const std::string& path, |
| 102 int oflags, | 102 int oflags, mode_t mflags, |
| 103 ScopedFilesystem* out_fs, | 103 ScopedFilesystem* out_fs, |
| 104 ScopedNode* out_node) { | 104 ScopedNode* out_node) { |
| 105 Path rel_parts; | 105 Path rel_parts; |
| 106 out_fs->reset(NULL); | 106 out_fs->reset(NULL); |
| 107 out_node->reset(NULL); | 107 out_node->reset(NULL); |
| 108 Error error = AcquireFsAndRelPath(path, out_fs, &rel_parts); | 108 Error error = AcquireFsAndRelPath(path, out_fs, &rel_parts); |
| 109 if (error) | 109 if (error) |
| 110 return error; | 110 return error; |
| 111 | 111 |
| 112 error = (*out_fs)->Open(rel_parts, oflags, out_node); | 112 error = (*out_fs)->OpenWithMode(rel_parts, oflags, mflags, out_node); |
| 113 if (error) | 113 if (error) |
| 114 return error; | 114 return error; |
| 115 | 115 |
| 116 return 0; | 116 return 0; |
| 117 } | 117 } |
| 118 | 118 |
| 119 Path KernelObject::GetAbsParts(const std::string& path) { | 119 Path KernelObject::GetAbsParts(const std::string& path) { |
| 120 AUTO_LOCK(cwd_lock_); | 120 AUTO_LOCK(cwd_lock_); |
| 121 | 121 |
| 122 Path abs_parts; | 122 Path abs_parts; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 136 | 136 |
| 137 return out; | 137 return out; |
| 138 } | 138 } |
| 139 | 139 |
| 140 Error KernelObject::SetCWD(const std::string& path) { | 140 Error KernelObject::SetCWD(const std::string& path) { |
| 141 std::string abs_path = GetAbsParts(path).Join(); | 141 std::string abs_path = GetAbsParts(path).Join(); |
| 142 | 142 |
| 143 ScopedFilesystem fs; | 143 ScopedFilesystem fs; |
| 144 ScopedNode node; | 144 ScopedNode node; |
| 145 | 145 |
| 146 Error error = AcquireFsAndNode(abs_path, O_RDONLY, &fs, &node); | 146 Error error = AcquireFsAndNode(abs_path, O_RDONLY, 0, &fs, &node); |
| 147 if (error) | 147 if (error) |
| 148 return error; | 148 return error; |
| 149 | 149 |
| 150 if ((node->GetType() & S_IFDIR) == 0) | 150 if ((node->GetType() & S_IFDIR) == 0) |
| 151 return ENOTDIR; | 151 return ENOTDIR; |
| 152 | 152 |
| 153 AUTO_LOCK(cwd_lock_); | 153 AUTO_LOCK(cwd_lock_); |
| 154 cwd_ = abs_path; | 154 cwd_ = abs_path; |
| 155 return 0; | 155 return 0; |
| 156 } | 156 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 AUTO_LOCK(handle_lock_); | 254 AUTO_LOCK(handle_lock_); |
| 255 | 255 |
| 256 handle_map_[fd].handle.reset(NULL); | 256 handle_map_[fd].handle.reset(NULL); |
| 257 free_fds_.push_back(fd); | 257 free_fds_.push_back(fd); |
| 258 | 258 |
| 259 // Force lower numbered FD to be available first. | 259 // Force lower numbered FD to be available first. |
| 260 std::push_heap(free_fds_.begin(), free_fds_.end(), std::greater<int>()); | 260 std::push_heap(free_fds_.begin(), free_fds_.end(), std::greater<int>()); |
| 261 } | 261 } |
| 262 | 262 |
| 263 } // namespace nacl_io | 263 } // namespace nacl_io |
| OLD | NEW |