| 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 <dirent.h> | 5 #include "nacl_mounts/kernel_object.h" |
| 6 |
| 6 #include <errno.h> | 7 #include <errno.h> |
| 7 #include <fcntl.h> | 8 #include <fcntl.h> |
| 8 #include <pthread.h> | 9 #include <pthread.h> |
| 9 #include <stdint.h> | |
| 10 #include <sys/stat.h> | |
| 11 | 10 |
| 12 #include <algorithm> | 11 #include <algorithm> |
| 13 #include <map> | 12 #include <map> |
| 14 #include <string> | 13 #include <string> |
| 15 #include <vector> | 14 #include <vector> |
| 16 | 15 |
| 17 #include "nacl_mounts/kernel_handle.h" | 16 #include "nacl_mounts/kernel_handle.h" |
| 18 #include "nacl_mounts/kernel_object.h" | |
| 19 #include "nacl_mounts/mount.h" | 17 #include "nacl_mounts/mount.h" |
| 20 #include "nacl_mounts/mount_node.h" | 18 #include "nacl_mounts/mount_node.h" |
| 21 #include "utils/auto_lock.h" | 19 #include "utils/auto_lock.h" |
| 22 | 20 |
| 23 KernelObject::KernelObject() { | 21 KernelObject::KernelObject() { |
| 24 pthread_mutex_init(&lock_, NULL); | 22 pthread_mutex_init(&lock_, NULL); |
| 25 } | 23 } |
| 26 | 24 |
| 27 KernelObject::~KernelObject() { | 25 KernelObject::~KernelObject() { |
| 28 pthread_mutex_destroy(&lock_); | 26 pthread_mutex_destroy(&lock_); |
| 29 } | 27 } |
| 30 | 28 |
| 31 // Uses longest prefix to find the mount for the give path, then | 29 // Uses longest prefix to find the mount for the give path, then |
| 32 // acquires the mount and returns it with a relative path. | 30 // acquires the mount and returns it with a relative path. |
| 33 Mount* KernelObject::AcquireMountAndPath(const std::string& relpath, | 31 Mount* KernelObject::AcquireMountAndPath(const std::string& relpath, |
| 34 Path* out_path) { | 32 Path* out_path) { |
| 35 AutoLock lock(&lock_); | 33 AutoLock lock(&lock_); |
| 36 Mount* mount = NULL; | 34 Mount* mount = NULL; |
| 37 MountNode* node = NULL; | |
| 38 | 35 |
| 39 Path abs_path = GetAbsPathLocked(relpath); | 36 Path abs_path = GetAbsPathLocked(relpath); |
| 40 | 37 |
| 41 // Find longest prefix | 38 // Find longest prefix |
| 42 size_t max = abs_path.Size(); | 39 size_t max = abs_path.Size(); |
| 43 for (size_t len = 0; len < abs_path.Size(); len++) { | 40 for (size_t len = 0; len < abs_path.Size(); len++) { |
| 44 MountMap_t::iterator it = mounts_.find(abs_path.Range(0, max - len)); | 41 MountMap_t::iterator it = mounts_.find(abs_path.Range(0, max - len)); |
| 45 if (it != mounts_.end()) { | 42 if (it != mounts_.end()) { |
| 46 out_path->Set("/"); | 43 out_path->Set("/"); |
| 47 out_path->Append(abs_path.Range(max - len, max)); | 44 out_path->Append(abs_path.Range(max - len, max)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 Path abs_path(cwd_); | 140 Path abs_path(cwd_); |
| 144 if (path[0] == '/') { | 141 if (path[0] == '/') { |
| 145 abs_path = path; | 142 abs_path = path; |
| 146 } else { | 143 } else { |
| 147 abs_path = cwd_; | 144 abs_path = cwd_; |
| 148 abs_path.Append(path); | 145 abs_path.Append(path); |
| 149 } | 146 } |
| 150 | 147 |
| 151 return abs_path; | 148 return abs_path; |
| 152 } | 149 } |
| 153 | |
| OLD | NEW |