FileSystem.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/HashMap.h>
  7. #include <AK/Singleton.h>
  8. #include <AK/StringView.h>
  9. #include <Kernel/FileSystem/FileSystem.h>
  10. #include <Kernel/FileSystem/Inode.h>
  11. #include <Kernel/FileSystem/VirtualFileSystem.h>
  12. #include <Kernel/Interrupts/InterruptDisabler.h>
  13. #include <Kernel/Memory/MemoryManager.h>
  14. #include <Kernel/Net/LocalSocket.h>
  15. namespace Kernel {
  16. static u32 s_lastFileSystemID;
  17. FileSystem::FileSystem()
  18. : m_fsid(++s_lastFileSystemID)
  19. {
  20. }
  21. FileSystem::~FileSystem()
  22. {
  23. }
  24. ErrorOr<void> FileSystem::prepare_to_unmount(Inode& mount_guest_inode)
  25. {
  26. return m_attach_count.with([&](auto& attach_count) -> ErrorOr<void> {
  27. dbgln_if(VFS_DEBUG, "VFS: File system {} (id {}) is attached {} time(s)", class_name(), m_fsid.value(), attach_count);
  28. if (attach_count == 1)
  29. return prepare_to_clear_last_mount(mount_guest_inode);
  30. return {};
  31. });
  32. }
  33. FileSystem::DirectoryEntryView::DirectoryEntryView(StringView n, InodeIdentifier i, u8 ft)
  34. : name(n)
  35. , inode(i)
  36. , file_type(ft)
  37. {
  38. }
  39. void FileSystem::sync()
  40. {
  41. Inode::sync_all();
  42. VirtualFileSystem::the().sync_filesystems();
  43. }
  44. void FileSystem::lock_all()
  45. {
  46. VirtualFileSystem::the().lock_all_filesystems();
  47. }
  48. }