| 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 #ifndef LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ | 5 #ifndef LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ |
| 6 #define LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ | 6 #define LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ |
| 7 | 7 |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 class KernelObject { | 30 class KernelObject { |
| 31 public: | 31 public: |
| 32 struct Descriptor_t { | 32 struct Descriptor_t { |
| 33 Descriptor_t() : flags(0) {} | 33 Descriptor_t() : flags(0) {} |
| 34 explicit Descriptor_t(const ScopedKernelHandle& h) : handle(h), flags(0) {} | 34 explicit Descriptor_t(const ScopedKernelHandle& h) : handle(h), flags(0) {} |
| 35 | 35 |
| 36 ScopedKernelHandle handle; | 36 ScopedKernelHandle handle; |
| 37 int flags; | 37 int flags; |
| 38 }; | 38 }; |
| 39 typedef std::vector<Descriptor_t> HandleMap_t; | 39 typedef std::vector<Descriptor_t> HandleMap_t; |
| 40 typedef std::map<int, std::string> FdPathMap_t; |
| 40 typedef std::map<std::string, ScopedFilesystem> FsMap_t; | 41 typedef std::map<std::string, ScopedFilesystem> FsMap_t; |
| 41 | 42 |
| 42 KernelObject(); | 43 KernelObject(); |
| 43 virtual ~KernelObject(); | 44 virtual ~KernelObject(); |
| 44 | 45 |
| 45 // Attach the given Filesystem object at the specified path. | 46 // Attach the given Filesystem object at the specified path. |
| 46 Error AttachFsAtPath(const ScopedFilesystem& fs, const std::string& path); | 47 Error AttachFsAtPath(const ScopedFilesystem& fs, const std::string& path); |
| 47 | 48 |
| 48 // Unmap the Filesystem object from the specified path and release it. | 49 // Unmap the Filesystem object from the specified path and release it. |
| 49 Error DetachFsAtPath(const std::string& path); | 50 Error DetachFsAtPath(const std::string& path); |
| 50 | 51 |
| 51 // Find the filesystem for the given path, and acquires it and return a | 52 // Find the filesystem for the given path, and acquires it and return a |
| 52 // path relative to the filesystem. | 53 // path relative to the filesystem. |
| 53 // Assumes |out_fs| and |rel_path| are non-NULL. | 54 // Assumes |out_fs| and |rel_path| are non-NULL. |
| 54 Error AcquireFsAndRelPath(const std::string& path, | 55 Error AcquireFsAndRelPath(const std::string& path, |
| 55 ScopedFilesystem* out_fs, | 56 ScopedFilesystem* out_fs, |
| 56 Path* rel_path); | 57 Path* rel_path); |
| 57 | 58 |
| 58 // Find the filesystem and node for the given path, acquiring/creating it as | 59 // Find the filesystem and node for the given path, acquiring/creating it as |
| 59 // specified by the |oflags|. | 60 // specified by the |oflags|. |
| 60 // Assumes |out_fs| and |out_node| are non-NULL. | 61 // Assumes |out_fs| and |out_node| are non-NULL. |
| 61 Error AcquireFsAndNode(const std::string& path, | 62 Error AcquireFsAndNode(const std::string& path, |
| 62 int oflags, | 63 int oflags, |
| 63 ScopedFilesystem* out_fs, | 64 ScopedFilesystem* out_fs, |
| 64 ScopedNode* out_node); | 65 ScopedNode* out_node); |
| 65 | 66 |
| 66 // Get FD-specific flags (currently only FD_CLOEXEC is supported). | 67 // Get FD-specific flags (currently only FD_CLOEXEC is supported). |
| 67 Error GetFDFlags(int fd, int* out_flags); | 68 Error GetFDFlags(int fd, int* out_flags); |
| 69 // Get path at which FD was opened, if available. |
| 70 std::string GetFDPath(int fd); |
| 68 // Set FD-specific flags (currently only FD_CLOEXEC is supported). | 71 // Set FD-specific flags (currently only FD_CLOEXEC is supported). |
| 69 Error SetFDFlags(int fd, int flags); | 72 Error SetFDFlags(int fd, int flags); |
| 70 | 73 |
| 71 // Convert from FD to KernelHandle, and acquire the handle. | 74 // Convert from FD to KernelHandle, and acquire the handle. |
| 72 // Assumes |out_handle| is non-NULL. | 75 // Assumes |out_handle| is non-NULL. |
| 73 Error AcquireHandle(int fd, ScopedKernelHandle* out_handle); | 76 Error AcquireHandle(int fd, ScopedKernelHandle* out_handle); |
| 74 | 77 |
| 75 // Allocate a new fd and assign the handle to it, while | 78 // Allocate a new fd and assign the handle to it, while |
| 76 // ref counting the handle and associated filesystem. | 79 // ref counting the handle and associated filesystem. |
| 77 // Assumes |handle| is non-NULL; | 80 // Assumes |handle| is non-NULL; |
| 78 int AllocateFD(const ScopedKernelHandle& handle); | 81 int AllocateFD(const ScopedKernelHandle& handle, std::string path); |
| 79 | 82 |
| 80 // Assumes |handle| is non-NULL; | 83 // Assumes |handle| is non-NULL; |
| 81 void FreeAndReassignFD(int fd, const ScopedKernelHandle& handle); | 84 void FreeAndReassignFD(int fd, const ScopedKernelHandle& handle); |
| 82 void FreeFD(int fd); | 85 void FreeFD(int fd); |
| 83 | 86 |
| 84 // Returns or sets CWD | 87 // Returns or sets CWD |
| 85 std::string GetCWD(); | 88 std::string GetCWD(); |
| 86 Error SetCWD(const std::string& path); | 89 Error SetCWD(const std::string& path); |
| 87 | 90 |
| 88 // Returns parts of the absolute path for the given relative path | 91 // Returns parts of the absolute path for the given relative path |
| 89 Path GetAbsParts(const std::string& path); | 92 Path GetAbsParts(const std::string& path); |
| 90 | 93 |
| 91 private: | 94 private: |
| 92 std::string cwd_; | 95 std::string cwd_; |
| 93 std::vector<int> free_fds_; | 96 std::vector<int> free_fds_; |
| 94 HandleMap_t handle_map_; | 97 HandleMap_t handle_map_; |
| 98 FdPathMap_t fd_paths_; |
| 95 FsMap_t filesystems_; | 99 FsMap_t filesystems_; |
| 96 | 100 |
| 97 // Lock to protect free_fds_ and handle_map_. | 101 // Lock to protect free_fds_ and handle_map_. |
| 98 sdk_util::SimpleLock handle_lock_; | 102 sdk_util::SimpleLock handle_lock_; |
| 99 | 103 |
| 100 // Lock to protect filesystems_. | 104 // Lock to protect filesystems_. |
| 101 sdk_util::SimpleLock fs_lock_; | 105 sdk_util::SimpleLock fs_lock_; |
| 102 | 106 |
| 103 // Lock to protect cwd_. | 107 // Lock to protect cwd_. |
| 104 sdk_util::SimpleLock cwd_lock_; | 108 sdk_util::SimpleLock cwd_lock_; |
| 105 | 109 |
| 106 DISALLOW_COPY_AND_ASSIGN(KernelObject); | 110 DISALLOW_COPY_AND_ASSIGN(KernelObject); |
| 107 }; | 111 }; |
| 108 | 112 |
| 109 } // namespace nacl_io | 113 } // namespace nacl_io |
| 110 | 114 |
| 111 #endif // LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ | 115 #endif // LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ |
| OLD | NEW |