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