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