• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef LIBRARIES_NACL_IO_DIR_NODE_H_
6 #define LIBRARIES_NACL_IO_DIR_NODE_H_
7 
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 #include "nacl_io/getdents_helper.h"
13 #include "nacl_io/node.h"
14 
15 namespace nacl_io {
16 
17 class DevFs;
18 class Html5Fs;
19 class HttpFs;
20 class MemFs;
21 class DirNode;
22 
23 typedef sdk_util::ScopedRef<DirNode> ScopedDirNode;
24 
25 class DirNode : public Node {
26  protected:
27   explicit DirNode(Filesystem* fs);
28   virtual ~DirNode();
29 
30  public:
31   typedef std::map<std::string, ScopedNode> NodeMap_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,
39                      void* buf,
40                      size_t count,
41                      int* out_bytes);
42   virtual Error Write(const HandleAttr& attr,
43                       const void* buf,
44                       size_t count,
45                       int* out_bytes);
46 
47   // Adds a finds or adds a directory entry as an INO, updating the refcount
48   virtual Error AddChild(const std::string& name, const ScopedNode& node);
49   virtual Error RemoveChild(const std::string& name);
50   virtual Error FindChild(const std::string& name, ScopedNode* out_node);
51   virtual int ChildCount();
52 
53  protected:
54   void BuildCache_Locked();
55   void ClearCache_Locked();
56 
57  private:
58   GetDentsHelper cache_;
59   NodeMap_t map_;
60   bool cache_built_;
61 
62   friend class DevFs;
63   friend class Html5Fs;
64   friend class HttpFs;
65   friend class MemFs;
66 };
67 
68 }  // namespace nacl_io
69 
70 #endif  // LIBRARIES_NACL_IO_DIR_NODE_H_
71