2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2018-10-10 11:53:07 +02:00
|
|
|
#include <AK/HashMap.h>
|
2020-08-24 19:35:19 -06:00
|
|
|
#include <AK/Singleton.h>
|
2020-03-23 13:45:10 +01:00
|
|
|
#include <AK/StringView.h>
|
2019-05-16 03:02:37 +02:00
|
|
|
#include <Kernel/FileSystem/FileSystem.h>
|
|
|
|
#include <Kernel/FileSystem/Inode.h>
|
2022-10-05 19:27:36 +02:00
|
|
|
#include <Kernel/InterruptDisabler.h>
|
2021-08-06 10:45:34 +02:00
|
|
|
#include <Kernel/Memory/MemoryManager.h>
|
2019-04-06 20:29:48 +02:00
|
|
|
#include <Kernel/Net/LocalSocket.h>
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
static u32 s_lastFileSystemID;
|
2021-11-18 15:11:31 +01:00
|
|
|
static Singleton<HashMap<FileSystemID, FileSystem*>> s_file_system_map;
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2021-11-18 15:11:31 +01:00
|
|
|
static HashMap<FileSystemID, FileSystem*>& all_file_systems()
|
2018-10-10 11:53:07 +02:00
|
|
|
{
|
2021-07-11 00:20:38 +02:00
|
|
|
return *s_file_system_map;
|
2018-12-20 00:39:29 +01:00
|
|
|
}
|
|
|
|
|
2021-07-11 00:20:38 +02:00
|
|
|
FileSystem::FileSystem()
|
2019-05-02 03:28:20 +02:00
|
|
|
: m_fsid(++s_lastFileSystemID)
|
2018-10-10 11:53:07 +02:00
|
|
|
{
|
2021-07-11 00:20:38 +02:00
|
|
|
s_file_system_map->set(m_fsid, this);
|
2018-10-10 11:53:07 +02:00
|
|
|
}
|
|
|
|
|
2021-07-11 00:20:38 +02:00
|
|
|
FileSystem::~FileSystem()
|
2018-10-10 11:53:07 +02:00
|
|
|
{
|
2021-07-11 00:20:38 +02:00
|
|
|
s_file_system_map->remove(m_fsid);
|
2018-10-10 11:53:07 +02:00
|
|
|
}
|
|
|
|
|
2021-11-18 15:11:31 +01:00
|
|
|
FileSystem* FileSystem::from_fsid(FileSystemID id)
|
2018-10-10 11:53:07 +02:00
|
|
|
{
|
2021-07-11 00:20:38 +02:00
|
|
|
auto it = all_file_systems().find(id);
|
|
|
|
if (it != all_file_systems().end())
|
2018-10-10 11:53:07 +02:00
|
|
|
return (*it).value;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-11-11 00:55:02 +01:00
|
|
|
FileSystem::DirectoryEntryView::DirectoryEntryView(StringView n, InodeIdentifier i, u8 ft)
|
2020-08-18 12:41:27 +02:00
|
|
|
: name(n)
|
|
|
|
, inode(i)
|
|
|
|
, file_type(ft)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-07-11 00:20:38 +02:00
|
|
|
void FileSystem::sync()
|
2018-12-20 00:39:29 +01:00
|
|
|
{
|
2021-09-11 23:28:59 -04:00
|
|
|
Inode::sync_all();
|
2019-04-25 22:05:53 +02:00
|
|
|
|
2022-08-19 20:53:40 +02:00
|
|
|
NonnullLockRefPtrVector<FileSystem, 32> file_systems;
|
2019-04-25 22:05:53 +02:00
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
2021-07-11 00:20:38 +02:00
|
|
|
for (auto& it : all_file_systems())
|
|
|
|
file_systems.append(*it.value);
|
2019-04-25 22:05:53 +02:00
|
|
|
}
|
|
|
|
|
2021-07-11 00:20:38 +02:00
|
|
|
for (auto& fs : file_systems)
|
2019-06-27 13:44:26 +02:00
|
|
|
fs.flush_writes();
|
2018-12-20 00:39:29 +01:00
|
|
|
}
|
2019-06-16 11:49:39 +02:00
|
|
|
|
2021-07-11 00:20:38 +02:00
|
|
|
void FileSystem::lock_all()
|
2019-06-16 11:49:39 +02:00
|
|
|
{
|
2021-07-11 00:20:38 +02:00
|
|
|
for (auto& it : all_file_systems()) {
|
2019-06-16 11:49:39 +02:00
|
|
|
it.value->m_lock.lock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
}
|