FileSystem.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/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()
  25. {
  26. return m_attach_count.with([&](auto& attach_count) -> ErrorOr<void> {
  27. if (attach_count == 1)
  28. return prepare_to_clear_last_mount();
  29. return {};
  30. });
  31. }
  32. FileSystem::DirectoryEntryView::DirectoryEntryView(StringView n, InodeIdentifier i, u8 ft)
  33. : name(n)
  34. , inode(i)
  35. , file_type(ft)
  36. {
  37. }
  38. void FileSystem::sync()
  39. {
  40. Inode::sync_all();
  41. VirtualFileSystem::the().sync_filesystems();
  42. }
  43. void FileSystem::lock_all()
  44. {
  45. VirtualFileSystem::the().lock_all_filesystems();
  46. }
  47. }