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