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; | |
Sam Clegg
2014/01/07 23:56:39
Actually, why not just add at std::string to Descr
| |
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); |
77 Error AcquireHandleAndPath(int fd, ScopedKernelHandle *out_handle, | |
78 std::string& path); | |
74 | 79 |
75 // Allocate a new fd and assign the handle to it, while | 80 // Allocate a new fd and assign the handle to it, while |
76 // ref counting the handle and associated filesystem. | 81 // ref counting the handle and associated filesystem. |
77 // Assumes |handle| is non-NULL; | 82 // Assumes |handle| is non-NULL; |
78 int AllocateFD(const ScopedKernelHandle& handle); | 83 int AllocateFD(const ScopedKernelHandle& handle, |
84 std::string path = std::string()); | |
79 | 85 |
80 // Assumes |handle| is non-NULL; | 86 // Assumes |handle| is non-NULL; |
81 void FreeAndReassignFD(int fd, const ScopedKernelHandle& handle); | 87 void FreeAndReassignFD(int fd, const ScopedKernelHandle& handle, |
88 const std::string &path); | |
82 void FreeFD(int fd); | 89 void FreeFD(int fd); |
83 | 90 |
84 // Returns or sets CWD | 91 // Returns or sets CWD |
85 std::string GetCWD(); | 92 std::string GetCWD(); |
86 Error SetCWD(const std::string& path); | 93 Error SetCWD(const std::string& path); |
87 | 94 |
88 // Returns parts of the absolute path for the given relative path | 95 // Returns parts of the absolute path for the given relative path |
89 Path GetAbsParts(const std::string& path); | 96 Path GetAbsParts(const std::string& path); |
90 | 97 |
91 private: | 98 private: |
92 std::string cwd_; | 99 std::string cwd_; |
93 std::vector<int> free_fds_; | 100 std::vector<int> free_fds_; |
94 HandleMap_t handle_map_; | 101 HandleMap_t handle_map_; |
102 FdPathMap_t fd_paths_; | |
95 FsMap_t filesystems_; | 103 FsMap_t filesystems_; |
96 | 104 |
97 // Lock to protect free_fds_ and handle_map_. | 105 // Lock to protect free_fds_ and handle_map_. |
98 sdk_util::SimpleLock handle_lock_; | 106 sdk_util::SimpleLock handle_lock_; |
99 | 107 |
100 // Lock to protect filesystems_. | 108 // Lock to protect filesystems_. |
101 sdk_util::SimpleLock fs_lock_; | 109 sdk_util::SimpleLock fs_lock_; |
102 | 110 |
103 // Lock to protect cwd_. | 111 // Lock to protect cwd_. |
104 sdk_util::SimpleLock cwd_lock_; | 112 sdk_util::SimpleLock cwd_lock_; |
105 | 113 |
106 DISALLOW_COPY_AND_ASSIGN(KernelObject); | 114 DISALLOW_COPY_AND_ASSIGN(KernelObject); |
107 }; | 115 }; |
108 | 116 |
109 } // namespace nacl_io | 117 } // namespace nacl_io |
110 | 118 |
111 #endif // LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ | 119 #endif // LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ |
OLD | NEW |