- add sources.
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / libraries / nacl_io / mount_node_dir.h
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.
4
5 #ifndef LIBRARIES_NACL_IO_MOUNT_NODE_DIR_H_
6 #define LIBRARIES_NACL_IO_MOUNT_NODE_DIR_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "nacl_io/getdents_helper.h"
13 #include "nacl_io/mount_node.h"
14
15 namespace nacl_io {
16
17 class MountDev;
18 class MountHtml5Fs;
19 class MountHttp;
20 class MountMem;
21 class MountNodeDir;
22
23 typedef sdk_util::ScopedRef<MountNodeDir> ScopedMountNodeDir;
24
25 class MountNodeDir : public MountNode {
26  protected:
27   explicit MountNodeDir(Mount* mnt);
28   virtual ~MountNodeDir();
29
30  public:
31   typedef std::map<std::string, ScopedMountNode> MountNodeMap_t;
32
33   virtual Error FTruncate(off_t size);
34   virtual Error GetDents(size_t offs,
35                          struct dirent* pdir,
36                          size_t count,
37                          int* out_bytes);
38   virtual Error Read(const HandleAttr& attr, void *buf,
39                      size_t count, int* out_bytes);
40   virtual Error Write(const HandleAttr& attr, const void *buf,
41                       size_t count, int* out_bytes);
42
43   // Adds a finds or adds a directory entry as an INO, updating the refcount
44   virtual Error AddChild(const std::string& name, const ScopedMountNode& node);
45   virtual Error RemoveChild(const std::string& name);
46   virtual Error FindChild(const std::string& name, ScopedMountNode* out_node);
47   virtual int ChildCount();
48
49
50 protected:
51    void BuildCache_Locked();
52    void ClearCache_Locked();
53
54 private:
55   GetDentsHelper cache_;
56   MountNodeMap_t map_;
57   bool cache_built_;
58
59   friend class MountDev;
60   friend class MountMem;
61   friend class MountHttp;
62   friend class MountHtml5Fs;
63 };
64
65 }  // namespace nacl_io
66
67 #endif  // LIBRARIES_NACL_IO_MOUNT_NODE_DIR_H_