20 #include "Filesystem.h" 21 #include "Directory.h" 25 #include "pedigree/kernel/Log.h" 26 #include "pedigree/kernel/process/Process.h" 27 #include "pedigree/kernel/process/Thread.h" 28 #include "pedigree/kernel/processor/Processor.h" 29 #include "pedigree/kernel/processor/ProcessorInformation.h" 30 #include "pedigree/kernel/syscallError.h" 31 #include "pedigree/kernel/utilities/LazyEvaluate.h" 32 #include "pedigree/kernel/utilities/StringView.h" 33 #include "pedigree/kernel/utilities/utility.h" 65 assert(pStartNode !=
nullptr);
72 return find(path.
view(), pStartNode);
84 SYSCALL_ERROR(FileExists);
94 SYSCALL_ERROR(DoesNotExist);
109 return pFs->
createFile(pParent, filename, mask);
121 SYSCALL_ERROR(FileExists);
131 SYSCALL_ERROR(DoesNotExist);
158 SYSCALL_ERROR(FileExists);
168 SYSCALL_ERROR(DoesNotExist);
197 SYSCALL_ERROR(FileExists);
207 SYSCALL_ERROR(DoesNotExist);
218 if (
this != target->getFilesystem())
220 SYSCALL_ERROR(CrossDeviceLink);
243 SYSCALL_ERROR(DoesNotExist);
253 FATAL(
"Filesystem::remove: Massive algorithmic error.");
266 FATAL(
"Filesystem::remove: Massive algorithmic error (2)");
282 SYSCALL_ERROR(NotEmpty);
287 for (
auto it : removalDir->
getCache())
289 String name = (*it)->getName();
290 if (name !=
"." && name !=
"..")
292 SYSCALL_ERROR(NotEmpty);
298 if (!removalDir->
empty())
301 SYSCALL_ERROR(IoError);
308 bool bRemoved = pFs->
remove(pParent, pFile);
311 pDParent->
remove(filename);
324 else if (path[0] ==
'/')
333 while ((i < path.length()) && path[i] !=
'/')
335 i = path.nextCharacter(i);
337 while (i < path.length())
339 size_t n = path.nextCharacter(i);
340 if (n >= path.length())
344 else if (path[n] ==
'/')
357 path.
substring(path.nextCharacter(i), path.length());
363 if (currentComponent.length() == 0)
378 SYSCALL_ERROR(NotADirectory);
382 bool dot = currentComponent ==
".";
383 bool dotdot = currentComponent ==
"..";
386 if (dot || (dotdot && pNode->m_pParent == 0) ||
393 return findNode(pNode->m_pParent, restOfPath);
399 SYSCALL_ERROR(NotADirectory);
409 "VFS: found reparse point at '" << pDir->
getFullPath()
410 <<
"', following it (new target: " 429 pFile = pDir->
lookup(currentComponent);
448 if (path.length() > 1 && path[path.length() - 1] ==
'/')
450 path = path.
substring(0, path.length() - 1);
455 ssize_t lastSlash = -1;
456 for (ssize_t i = path.length() - 1; i >= 0; i = path.prevCharacter(i))
466 File *parentNode =
nullptr;
469 filename = path.toString();
470 parentNode = pStartNode;
475 filename = path.
substring(path.nextCharacter(lastSlash), path.length())
478 parentNode =
findNode(pStartNode, path);
490 parentNode = reparseNode;
StringView substring(size_t start, size_t end, bool hashed=HASH_STRINGVIEWS_BY_DEFAULT) const
File * getRootFile() const
int followLink(char *pBuffer, size_t bufLen)
bool createLink(const StringView &path, File *target, File *pStartNode=0)
static Directory * fromFile(File *pF)
bool createFile(const StringView &path, uint32_t mask, File *pStartNode=0)
static ProcessorInformation & information()
File * findNode(File *pNode, StringView path)
bool remove(const StringView &path, File *pStartNode=0)
virtual File * find(const StringView &path)
File * findParent(StringView path, File *pStartNode, String &filename)
virtual String getFullPath(bool bWithLabel=true)
bool createDirectory(const StringView &path, uint32_t mask, File *pStartNode=0)
static Symlink * fromFile(File *pF)
virtual const DirectoryEntryCache & getCache()
void remove(const HashedStringView &s)
virtual bool isDirectory()
File * lookup(const HashedStringView &s) const
Directory * getReparsePoint() const
Get the reparse point attached to this directory. Reparse points allow locations on the filesystem to...
virtual void cacheDirectoryContents()
bool createSymlink(const StringView &path, const String &value, File *pStartNode=0)
static bool checkAccess(File *pFile, bool bRead, bool bWrite, bool bExecute)
virtual bool isCachePopulated() const
virtual File * getRoot() const =0