Mojo C++ bindings: better log message for serialization warnings.
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / filesystem.h
blobb05810bd5e15b8d68878e5c76a1831ca880f2072
1 // Copyright 2013 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_FILESYSTEM_H_
6 #define LIBRARIES_NACL_IO_FILESYSTEM_H_
8 #include <map>
9 #include <string>
11 #include "nacl_io/error.h"
12 #include "nacl_io/inode_pool.h"
13 #include "nacl_io/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"
20 struct fuse_operations;
22 namespace nacl_io {
24 class Filesystem;
25 class Node;
26 class PepperInterface;
28 typedef sdk_util::ScopedRef<Filesystem> ScopedFilesystem;
29 typedef std::map<std::string, std::string> StringMap_t;
31 // This structure is passed to all filesystems via the Filesystem::Init virtual
32 // function. With it, we can add or remove initialization values without
33 // changing the function signature.
34 struct FsInitArgs {
35 FsInitArgs() : dev(0), ppapi(NULL), fuse_ops(NULL) {}
36 explicit FsInitArgs(int dev) : dev(dev), ppapi(NULL), fuse_ops(NULL) {}
38 // Device number of the new filesystem.
39 int dev;
40 StringMap_t string_map;
41 PepperInterface* ppapi;
42 fuse_operations* fuse_ops;
45 // NOTE: The KernelProxy is the only class that should be setting errno. All
46 // other classes should return Error (as defined by nacl_io/error.h).
47 class Filesystem : public sdk_util::RefObject {
48 protected:
49 // The protected functions are only used internally and will not
50 // acquire or release the filesystem's lock.
51 Filesystem();
52 virtual ~Filesystem();
54 // Init must be called by the factory before the filesystem is used.
55 // |ppapi| can be NULL. If so, this filesystem cannot make any pepper calls.
56 virtual Error Init(const FsInitArgs& args);
57 virtual void Destroy();
59 public:
60 PepperInterface* ppapi() { return ppapi_; }
61 int dev() { return dev_; }
63 // All paths in functions below are expected to containing a leading "/".
65 // Test whether a file or directory at a given path can be accessed.
66 // Returns 0 on success, or an appropriate errno value on failure.
67 virtual Error Access(const Path& path, int a_mode) = 0;
69 // Open a node at |path| with the specified open flags. The resulting
70 // Node is created with a ref count of 1.
71 // Assumes that |out_node| is non-NULL.
72 virtual Error Open(const Path& path,
73 int open_flags,
74 ScopedNode* out_node) = 0;
76 // OpenResource is only used to read files from the NaCl NMF file. No
77 // filesystem except PassthroughFs should implement it.
78 // Assumes that |out_node| is non-NULL.
79 virtual Error OpenResource(const Path& path, ScopedNode* out_node);
81 // Unlink, Mkdir, Rmdir will affect the both the RefCount
82 // and the nlink number in the stat object.
83 virtual Error Unlink(const Path& path) = 0;
84 virtual Error Mkdir(const Path& path, int permissions) = 0;
85 virtual Error Rmdir(const Path& path) = 0;
86 virtual Error Remove(const Path& path) = 0;
87 virtual Error Rename(const Path& path, const Path& newpath) = 0;
88 virtual Error Filesystem_VIoctl(int request, va_list args);
90 // Helper function that forwards to Filesystem_VIoctl.
91 Error Filesystem_Ioctl(int request, ...);
93 // Assumes that |node| is non-NULL.
94 void OnNodeCreated(Node* node);
96 // Assumes that |node| is non-NULL.
97 void OnNodeDestroyed(Node* node);
99 protected:
100 // Device number for the filesystem.
101 int dev_;
102 PepperInterface* ppapi_; // Weak reference.
103 INodePool inode_pool_;
105 private:
106 // May only be called by the KernelProxy when the Kernel's
107 // lock is held, so we make it private.
108 friend class KernelObject;
109 friend class KernelProxy;
110 DISALLOW_COPY_AND_ASSIGN(Filesystem);
113 } // namespace nacl_io
115 #endif // LIBRARIES_NACL_IO_FILESYSTEM_H_