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
3 // found in the LICENSE file.
5 #ifndef LIBRARIES_NACL_IO_MOUNT_H_
6 #define LIBRARIES_NACL_IO_MOUNT_H_
11 #include "nacl_io/error.h"
12 #include "nacl_io/inode_pool.h"
13 #include "nacl_io/mount_node.h"
14 #include "nacl_io/path.h"
16 #include "sdk_util/macros.h"
17 #include "sdk_util/ref_object.h"
18 #include "sdk_util/scoped_ref.h"
24 class PepperInterface;
26 typedef sdk_util::ScopedRef<Mount> ScopedMount;
27 typedef std::map<std::string, std::string> StringMap_t;
29 // NOTE: The KernelProxy is the only class that should be setting errno. All
30 // other classes should return Error (as defined by nacl_io/error.h).
31 class Mount : public sdk_util::RefObject {
33 // The protected functions are only used internally and will not
34 // acquire or release the mount's lock.
38 // Init must be called by the factory before the mount is used.
39 // This function must assign a root node, or replace FindNode.
40 // |ppapi| can be NULL. If so, this mount cannot make any pepper calls.
41 virtual Error Init(int dev, StringMap_t& args, PepperInterface* ppapi);
42 virtual void Destroy();
45 PepperInterface* ppapi() { return ppapi_; }
47 // All paths in functions below are expected to containing a leading "/".
49 // Test whether a file or directory at a given path can be accessed.
50 // Returns 0 on success, or an appropriate errno value on failure.
51 virtual Error Access(const Path& path, int a_mode) = 0;
53 // Open a node at |path| with the specified open flags. The resulting
54 // MountNode is created with a ref count of 1.
55 // Assumes that |out_node| is non-NULL.
56 virtual Error Open(const Path& path,
58 ScopedMountNode* out_node) = 0;
60 // OpenResource is only used to read files from the NaCl NMF file. No mount
61 // except MountPassthrough should implement it.
62 // Assumes that |out_node| is non-NULL.
63 virtual Error OpenResource(const Path& path, ScopedMountNode* out_node);
65 // Unlink, Mkdir, Rmdir will affect the both the RefCount
66 // and the nlink number in the stat object.
67 virtual Error Unlink(const Path& path) = 0;
68 virtual Error Mkdir(const Path& path, int permissions) = 0;
69 virtual Error Rmdir(const Path& path) = 0;
70 virtual Error Remove(const Path& path) = 0;
72 // Assumes that |node| is non-NULL.
73 void OnNodeCreated(MountNode* node);
75 // Assumes that |node| is non-NULL.
76 void OnNodeDestroyed(MountNode* node);
79 // Device number for the mount.
81 PepperInterface* ppapi_; // Weak reference.
82 INodePool inode_pool_;
85 // May only be called by the KernelProxy when the Kernel's
86 // lock is held, so we make it private.
87 friend class KernelObject;
88 friend class KernelProxy;
89 DISALLOW_COPY_AND_ASSIGN(Mount);
92 } // namespace nacl_io
94 #endif // LIBRARIES_NACL_IO_MOUNT_H_