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_MOUNT_H_ | 5 #ifndef LIBRARIES_NACL_IO_MOUNT_H_ |
6 #define LIBRARIES_NACL_IO_MOUNT_H_ | 6 #define LIBRARIES_NACL_IO_MOUNT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "nacl_io/error.h" | |
11 #include "nacl_io/inode_pool.h" | 12 #include "nacl_io/inode_pool.h" |
12 #include "nacl_io/mount_node.h" | 13 #include "nacl_io/mount_node.h" |
13 #include "nacl_io/path.h" | 14 #include "nacl_io/path.h" |
14 #include "utils/macros.h" | 15 #include "utils/macros.h" |
15 #include "utils/ref_object.h" | 16 #include "utils/ref_object.h" |
16 | 17 |
17 class MountNode; | 18 class MountNode; |
18 class PepperInterface; | 19 class PepperInterface; |
19 | 20 |
20 typedef std::map<std::string, std::string> StringMap_t; | 21 typedef std::map<std::string, std::string> StringMap_t; |
21 | 22 |
22 | |
23 class Mount : public RefObject { | 23 class Mount : public RefObject { |
24 protected: | 24 protected: |
25 // The protected functions are only used internally and will not | 25 // The protected functions are only used internally and will not |
26 // acquire or release the mount's lock. | 26 // acquire or release the mount's lock. |
27 Mount(); | 27 Mount(); |
28 virtual ~Mount(); | 28 virtual ~Mount(); |
29 | 29 |
30 // Init must be called by the factory before the mount is used. | 30 // Init must be called by the factory before the mount is used. |
31 // This function must assign a root node, or replace FindNode. | 31 // This function must assign a root node, or replace FindNode. |
32 // |ppapi| can be NULL. If so, this mount cannot make any pepper calls. | 32 // |ppapi| can be NULL. If so, this mount cannot make any pepper calls. |
33 virtual bool Init(int dev, StringMap_t& args, PepperInterface* ppapi); | 33 virtual Error Init(int dev, StringMap_t& args, PepperInterface* ppapi); |
34 virtual void Destroy(); | 34 virtual void Destroy(); |
35 | 35 |
36 public: | 36 public: |
37 template <class M> | 37 template <class M> |
38 static Mount* Create(int dev, StringMap_t& args, PepperInterface* ppapi); | 38 static Error Create(int dev, |
39 StringMap_t& args, | |
40 PepperInterface* ppapi, | |
41 Mount** out_mount); | |
39 | 42 |
40 PepperInterface* ppapi() { return ppapi_; } | 43 PepperInterface* ppapi() { return ppapi_; } |
41 | 44 |
42 // All paths are expected to containing a leading "/" | 45 // All paths are expected to containing a leading "/" |
43 void AcquireNode(MountNode* node); | 46 void AcquireNode(MountNode* node); |
44 void ReleaseNode(MountNode* node); | 47 void ReleaseNode(MountNode* node); |
45 | 48 |
46 // Open a node at |path| with the specified open flags. The resulting | 49 // Open a node at |path| with the specified open flags. The resulting |
47 // MountNode is created with a ref count of 1. | 50 // MountNode is created with a ref count of 1. |
48 virtual MountNode *Open(const Path& path, int o_flags) = 0; | 51 virtual Error Open(const Path& path, int o_flags, MountNode** out_node) = 0; |
49 | 52 |
50 // OpenResource is only used to read files from the NaCl NMF file. No mount | 53 // OpenResource is only used to read files from the NaCl NMF file. No mount |
51 // except MountPassthrough should implement it. | 54 // except MountPassthrough should implement it. |
52 virtual MountNode *OpenResource(const Path& path) { return NULL; } | 55 virtual Error OpenResource(const Path& path, MountNode** out_node); |
53 | 56 |
54 // Unlink, Mkdir, Rmdir will affect the both the RefCount | 57 // Unlink, Mkdir, Rmdir will affect the both the RefCount |
55 // and the nlink number in the stat object. | 58 // and the nlink number in the stat object. |
56 virtual int Unlink(const Path& path) = 0; | 59 virtual Error Unlink(const Path& path) = 0; |
57 virtual int Mkdir(const Path& path, int permissions) = 0; | 60 virtual Error Mkdir(const Path& path, int permissions) = 0; |
58 virtual int Rmdir(const Path& path) = 0; | 61 virtual Error Rmdir(const Path& path) = 0; |
59 virtual int Remove(const Path& path) = 0; | 62 virtual Error Remove(const Path& path) = 0; |
60 | 63 |
61 // Convert from R,W,R/W open flags to STAT permission flags | 64 // Convert from R,W,R/W open flags to STAT permission flags |
62 static int OpenModeToPermission(int mode); | 65 static int OpenModeToPermission(int mode); |
63 | 66 |
64 void OnNodeCreated(MountNode* node) ; | 67 void OnNodeCreated(MountNode* node); |
65 void OnNodeDestroyed(MountNode* node); | 68 void OnNodeDestroyed(MountNode* node); |
66 | 69 |
67 protected: | 70 protected: |
68 // Device number for the mount. | 71 // Device number for the mount. |
69 int dev_; | 72 int dev_; |
70 PepperInterface* ppapi_; // Weak reference. | 73 PepperInterface* ppapi_; // Weak reference. |
71 INodePool inode_pool_; | 74 INodePool inode_pool_; |
72 | 75 |
73 private: | 76 private: |
74 // May only be called by the KernelProxy when the Kernel's | 77 // May only be called by the KernelProxy when the Kernel's |
75 // lock is held, so we make it private. | 78 // lock is held, so we make it private. |
76 friend class KernelObject; | 79 friend class KernelObject; |
77 friend class KernelProxy; | 80 friend class KernelProxy; |
78 void Acquire() { RefObject::Acquire(); } | 81 void Acquire() { RefObject::Acquire(); } |
79 bool Release() { return RefObject::Release(); } | 82 bool Release() { return RefObject::Release(); } |
80 | 83 |
81 DISALLOW_COPY_AND_ASSIGN(Mount); | 84 DISALLOW_COPY_AND_ASSIGN(Mount); |
82 }; | 85 }; |
83 | 86 |
87 /*static*/ | |
88 template <class M> | |
89 Error Mount::Create(int dev, | |
90 StringMap_t& args, | |
91 PepperInterface* ppapi, | |
92 Mount** out_mount) { | |
93 Mount* mnt = new M(); | |
94 Error error = mnt->Init(dev, args, ppapi); | |
noelallen1
2013/06/07 21:48:43
if (NULL == *out_mount)?
binji
2013/06/07 23:23:11
Added comment to Create declaration above.
| |
95 if (error) { | |
96 delete mnt; | |
97 *out_mount = NULL; | |
98 return error; | |
99 } | |
84 | 100 |
85 template <class M> | 101 *out_mount = mnt; |
86 /*static*/ | 102 return 0; |
87 Mount* Mount::Create(int dev, StringMap_t& args, PepperInterface* ppapi) { | |
88 Mount* mnt = new M(); | |
89 if (mnt->Init(dev, args, ppapi) == false) { | |
90 delete mnt; | |
91 return NULL; | |
92 } | |
93 return mnt; | |
94 } | 103 } |
95 | 104 |
96 #endif // LIBRARIES_NACL_IO_MOUNT_H_ | 105 #endif // LIBRARIES_NACL_IO_MOUNT_H_ |
OLD | NEW |