ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / filesystem.h
blobe6b7ba2aa1e31b958a5662afb8768cacbaab68ba
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 // Open a node at |path| with the specified open and modeflags. The resulting
66 // Node is created with a ref count of 1.
67 // Assumes that |out_node| is non-NULL.
68 virtual Error OpenWithMode(const Path& path,
69 int open_flags,
70 mode_t mode,
71 ScopedNode* out_node) = 0;
73 // Open a node at |path| with the specified open flags. The resulting
74 // Node is created with a ref count of 1.
75 // Assumes that |out_node| is non-NULL.
76 Error Open(const Path& path,
77 int open_flags,
78 ScopedNode* out_node);
80 // OpenResource is only used to read files from the NaCl NMF file. No
81 // filesystem except PassthroughFs should implement it.
82 // Assumes that |out_node| is non-NULL.
83 virtual Error OpenResource(const Path& path, ScopedNode* out_node);
85 // Unlink, Mkdir, Rmdir will affect the both the RefCount
86 // and the nlink number in the stat object.
87 virtual Error Unlink(const Path& path) = 0;
88 virtual Error Mkdir(const Path& path, int permissions) = 0;
89 virtual Error Rmdir(const Path& path) = 0;
90 virtual Error Remove(const Path& path) = 0;
91 virtual Error Rename(const Path& path, const Path& newpath) = 0;
92 virtual Error Filesystem_VIoctl(int request, va_list args);
94 // Helper function that forwards to Filesystem_VIoctl.
95 Error Filesystem_Ioctl(int request, ...);
97 // Assumes that |node| is non-NULL.
98 virtual void OnNodeCreated(Node* node);
100 // Assumes that |node| is non-NULL.
101 virtual void OnNodeDestroyed(Node* node);
103 protected:
104 // Device number for the filesystem.
105 int dev_;
106 PepperInterface* ppapi_; // Weak reference.
107 INodePool inode_pool_;
109 private:
110 // May only be called by the KernelProxy when the Kernel's
111 // lock is held, so we make it private.
112 friend class KernelObject;
113 friend class KernelProxy;
114 DISALLOW_COPY_AND_ASSIGN(Filesystem);
117 } // namespace nacl_io
119 #endif // LIBRARIES_NACL_IO_FILESYSTEM_H_