vfs: check userland buffers before reading them.
[haiku.git] / src / kits / tracker / VirtualDirectoryManager.h
blob5af8f6a29b72c75c8d11bbf98efe1520a20c3d07
1 /*
2 * Copyright 2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ingo Weinhold, ingo_weinhold@gmx.de
7 */
8 #ifndef _VIRTUAL_DIRECTORY_MANAGER_H
9 #define _VIRTUAL_DIRECTORY_MANAGER_H
12 #include <dirent.h>
14 #include <map>
16 #include <Locker.h>
17 #include <Node.h>
20 class BStringList;
23 namespace BPrivate {
25 class Model;
28 class VirtualDirectoryManager {
29 public:
30 static VirtualDirectoryManager* Instance();
32 bool Lock() { return fLock.Lock(); }
33 void Unlock() { fLock.Unlock(); }
35 status_t ResolveDirectoryPaths(
36 const node_ref& definitionFileNodeRef,
37 const entry_ref& definitionFileEntryRef,
38 BStringList& _directoryPaths,
39 node_ref* _definitionFileNodeRef = NULL,
40 entry_ref* _definitionFileEntryRef = NULL);
42 bool GetDefinitionFileChangeTime(
43 const node_ref& definitionFileRef,
44 bigtime_t& _time) const;
46 bool GetRootDefinitionFile(
47 const node_ref& definitionFileRef,
48 node_ref& _rootDefinitionFileRef);
49 bool GetSubDirectoryDefinitionFile(
50 const node_ref& baseDefinitionRef,
51 const char* subDirName,
52 entry_ref& _entryRef, node_ref& _nodeRef);
53 bool GetParentDirectoryDefinitionFile(
54 const node_ref& subDirDefinitionRef,
55 entry_ref& _entryRef, node_ref& _nodeRef);
57 status_t TranslateDirectoryEntry(
58 const node_ref& definitionFileRef,
59 dirent* buffer);
60 status_t TranslateDirectoryEntry(
61 const node_ref& definitionFileRef,
62 entry_ref& entryRef, node_ref& _nodeRef);
64 bool DefinitionFileChanged(
65 const node_ref& definitionFileRef);
66 // returns whether the directory still
67 // exists
68 status_t DirectoryRemoved(
69 const node_ref& definitionFileRef);
71 static bool GetEntry(const BStringList& directoryPaths,
72 const char* name, entry_ref* _ref,
73 struct stat* _st);
75 private:
76 class Info;
77 class RootInfo;
79 typedef std::map<node_ref, Info*> NodeRefInfoMap;
81 private:
82 VirtualDirectoryManager();
84 Info* _InfoForNodeRef(const node_ref& nodeRef) const;
86 bool _AddInfo(Info* info);
87 void _RemoveInfo(Info* info);
89 void _UpdateTree(RootInfo* root);
90 void _UpdateTree(Info* info);
92 void _RemoveDirectory(Info* info);
94 status_t _ResolveUnknownDefinitionFile(
95 const node_ref& definitionFileNodeRef,
96 const entry_ref& definitionFileEntryRef,
97 Info*& _info);
98 status_t _CreateRootInfo(
99 const node_ref& definitionFileNodeRef,
100 const entry_ref& definitionFileEntryRef,
101 Info*& _info);
102 status_t _ReadSubDirectoryDefinitionFileInfo(
103 const entry_ref& entryRef,
104 entry_ref& _rootDefinitionFileEntryRef,
105 BString& _subDirPath);
107 private:
108 BLocker fLock;
109 NodeRefInfoMap fInfos;
112 } // namespace BPrivate
115 #endif // _VIRTUAL_DIRECTORY_MANAGER_H