The Pedigree Project  0.1
VFS.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef VFS_H
21 #define VFS_H
22 
23 #include "Filesystem.h"
24 #include "pedigree/kernel/compiler.h"
25 #include "pedigree/kernel/processor/types.h"
26 #include "pedigree/kernel/utilities/HashTable.h"
27 #include "pedigree/kernel/utilities/List.h"
28 #include "pedigree/kernel/utilities/LruCache.h"
29 #include "pedigree/kernel/utilities/String.h"
30 #include "pedigree/kernel/utilities/Tree.h"
31 #include "pedigree/kernel/utilities/utility.h"
32 
33 class Disk;
34 class File;
35 class StringView;
36 class HashedStringView;
37 
39 #define VFS_WITH_LRU_CACHES 0
40 
58 {
59  public:
61  typedef void (*MountCallback)();
62 
65 
67  VFS();
69  ~VFS();
70 
72  static VFS &instance();
73 
77  bool mount(Disk *pDisk, String &alias);
78 
82  void addAlias(Filesystem *pFs, const String &alias);
83  void addAlias(const String &oldAlias, const String &newAlias);
84 
86  String getUniqueAlias(const String &alias);
87 
89  bool aliasExists(const String &alias);
90 
92  inline AliasTable &getAliases()
93  {
94  return m_Aliases;
95  }
96 
99  {
100  return m_Mounts;
101  }
102 
106  void removeAlias(const String &alias);
107 
110  void removeAllAliases(Filesystem *pFs, bool canDelete=true);
111 
115  Filesystem *lookupFilesystem(const String &alias);
116  Filesystem *lookupFilesystem(const HashedStringView &alias);
117 
119  File *find(const String &path, File *pStartNode = 0);
120 
122  bool createFile(const String &path, uint32_t mask, File *pStartNode = 0);
123 
125  bool
126  createDirectory(const String &path, uint32_t mask, File *pStartNode = 0);
127 
129  bool createSymlink(
130  const String &path, const String &value, File *pStartNode = 0);
131 
133  bool createLink(const String &path, File *target, File *pStartNode = 0);
134 
137  bool remove(const String &path, File *pStartNode = 0);
138 
141  void addProbeCallback(Filesystem::ProbeCallback callback);
142 
145  void addMountCallback(MountCallback callback);
146 
148  static bool
149  checkAccess(File *pFile, bool bRead, bool bWrite, bool bExecute);
150 
152  static constexpr const char *mountSeparator()
153  {
154  return "ยป";
155  }
156 
157  private:
158  ssize_t findColon(const String &path);
159 
161  static VFS m_Instance;
162 
164  static File *m_EmptyFile;
165 
166  AliasTable m_Aliases;
168 
169  List<Filesystem::ProbeCallback *> m_ProbeCallbacks;
170  List<MountCallback *> m_MountCallbacks;
171 
172  LruCache<String, Filesystem *> m_AliasCache;
173  LruCache<String, File *> m_FindCache;
174 };
175 
176 #endif
HashTable< String, Filesystem *, HashedStringView > AliasTable
Definition: VFS.h:64
Tree< Filesystem *, List< String * > * > & getMounts()
Definition: VFS.h:98
AliasTable & getAliases()
Definition: VFS.h:92
Definition: String.h:49
Definition: Disk.h:32
Filesystem *(* ProbeCallback)(Disk *)
Definition: Filesystem.h:58
Definition: VFS.h:57
static constexpr const char * mountSeparator()
Definition: VFS.h:152
A key/value dictionary.
Definition: Tree.h:33
static VFS m_Instance
Definition: VFS.h:161
Definition: File.h:66
static File * m_EmptyFile
Definition: VFS.h:164