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