| 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 22 matching lines...) Expand all Loading... |
| 33 std::string abs_path = GetAbsParts(path).Join(); | 33 std::string abs_path = GetAbsParts(path).Join(); |
| 34 | 34 |
| 35 AUTO_LOCK(fs_lock_); | 35 AUTO_LOCK(fs_lock_); |
| 36 if (filesystems_.find(abs_path) != filesystems_.end()) | 36 if (filesystems_.find(abs_path) != filesystems_.end()) |
| 37 return EBUSY; | 37 return EBUSY; |
| 38 | 38 |
| 39 filesystems_[abs_path] = fs; | 39 filesystems_[abs_path] = fs; |
| 40 return 0; | 40 return 0; |
| 41 } | 41 } |
| 42 | 42 |
| 43 Error KernelObject::DetachFsAtPath(const std::string& path) { | 43 Error KernelObject::DetachFsAtPath(const std::string& path, |
| 44 ScopedFilesystem* out_fs) { |
| 44 std::string abs_path = GetAbsParts(path).Join(); | 45 std::string abs_path = GetAbsParts(path).Join(); |
| 45 | 46 |
| 46 AUTO_LOCK(fs_lock_); | 47 AUTO_LOCK(fs_lock_); |
| 47 FsMap_t::iterator it = filesystems_.find(abs_path); | 48 FsMap_t::iterator it = filesystems_.find(abs_path); |
| 48 if (filesystems_.end() == it) | 49 if (filesystems_.end() == it) |
| 49 return EINVAL; | 50 return EINVAL; |
| 50 | 51 |
| 51 // It is only legal to unmount if there are no open references | 52 // It is only legal to unmount if there are no open references |
| 52 if (it->second->RefCount() != 1) | 53 if (it->second->RefCount() != 1) |
| 53 return EBUSY; | 54 return EBUSY; |
| 54 | 55 |
| 56 *out_fs = it->second; |
| 57 |
| 55 filesystems_.erase(it); | 58 filesystems_.erase(it); |
| 56 return 0; | 59 return 0; |
| 57 } | 60 } |
| 58 | 61 |
| 59 // Uses longest prefix to find the filesystem for the give path, then | 62 // Uses longest prefix to find the filesystem for the give path, then |
| 60 // acquires the filesystem and returns it with a relative path. | 63 // acquires the filesystem and returns it with a relative path. |
| 61 Error KernelObject::AcquireFsAndRelPath(const std::string& path, | 64 Error KernelObject::AcquireFsAndRelPath(const std::string& path, |
| 62 ScopedFilesystem* out_fs, | 65 ScopedFilesystem* out_fs, |
| 63 Path* rel_parts) { | 66 Path* rel_parts) { |
| 64 Path abs_parts = GetAbsParts(path); | 67 Path abs_parts = GetAbsParts(path); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 AUTO_LOCK(handle_lock_); | 243 AUTO_LOCK(handle_lock_); |
| 241 | 244 |
| 242 handle_map_[fd].handle.reset(NULL); | 245 handle_map_[fd].handle.reset(NULL); |
| 243 free_fds_.push_back(fd); | 246 free_fds_.push_back(fd); |
| 244 | 247 |
| 245 // Force lower numbered FD to be available first. | 248 // Force lower numbered FD to be available first. |
| 246 std::push_heap(free_fds_.begin(), free_fds_.end(), std::greater<int>()); | 249 std::push_heap(free_fds_.begin(), free_fds_.end(), std::greater<int>()); |
| 247 } | 250 } |
| 248 | 251 |
| 249 } // namespace nacl_io | 252 } // namespace nacl_io |
| OLD | NEW |