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/Assertions.h>
|
|
|
|
|
#include <AK/HashMap.h>
|
2020-08-24 19:35:19 -06:00
|
|
|
#include <AK/Singleton.h>
|
2019-01-28 22:55:55 +01:00
|
|
|
#include <AK/StringBuilder.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>
|
2019-04-06 20:29:48 +02:00
|
|
|
#include <Kernel/Net/LocalSocket.h>
|
2019-06-07 11:43:58 +02:00
|
|
|
#include <Kernel/VM/MemoryManager.h>
|
|
|
|
|
#include <LibC/errno_numbers.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;
|
2020-08-24 19:35:19 -06:00
|
|
|
static AK::Singleton<HashMap<u32, FS*>> s_fs_map;
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
static HashMap<u32, FS*>& all_fses()
|
2018-10-10 11:53:07 +02:00
|
|
|
{
|
2018-12-20 00:39:29 +01:00
|
|
|
return *s_fs_map;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 17:13:10 +01:00
|
|
|
FS::FS()
|
2019-05-02 03:28:20 +02:00
|
|
|
: m_fsid(++s_lastFileSystemID)
|
2018-10-10 11:53:07 +02:00
|
|
|
{
|
2018-12-20 00:39:29 +01:00
|
|
|
all_fses().set(m_fsid, this);
|
2018-10-10 11:53:07 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-15 17:13:10 +01:00
|
|
|
FS::~FS()
|
2018-10-10 11:53:07 +02:00
|
|
|
{
|
2018-12-20 00:39:29 +01:00
|
|
|
all_fses().remove(m_fsid);
|
2018-10-10 11:53:07 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
FS* FS::from_fsid(u32 id)
|
2018-10-10 11:53:07 +02:00
|
|
|
{
|
2018-12-20 00:39:29 +01:00
|
|
|
auto it = all_fses().find(id);
|
|
|
|
|
if (it != all_fses().end())
|
2018-10-10 11:53:07 +02:00
|
|
|
return (*it).value;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 12:41:27 +02:00
|
|
|
FS::DirectoryEntryView::DirectoryEntryView(const StringView& n, InodeIdentifier i, u8 ft)
|
|
|
|
|
: name(n)
|
|
|
|
|
, inode(i)
|
|
|
|
|
, file_type(ft)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 00:39:29 +01:00
|
|
|
void FS::sync()
|
|
|
|
|
{
|
2019-05-16 03:02:37 +02:00
|
|
|
Inode::sync();
|
2019-04-25 22:05:53 +02:00
|
|
|
|
2019-06-27 13:44:26 +02:00
|
|
|
NonnullRefPtrVector<FS, 32> fses;
|
2019-04-25 22:05:53 +02:00
|
|
|
{
|
|
|
|
|
InterruptDisabler disabler;
|
|
|
|
|
for (auto& it : all_fses())
|
|
|
|
|
fses.append(*it.value);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 13:44:26 +02:00
|
|
|
for (auto& fs : fses)
|
|
|
|
|
fs.flush_writes();
|
2018-12-20 00:39:29 +01:00
|
|
|
}
|
2019-06-16 11:49:39 +02:00
|
|
|
|
|
|
|
|
void FS::lock_all()
|
|
|
|
|
{
|
|
|
|
|
for (auto& it : all_fses()) {
|
|
|
|
|
it.value->m_lock.lock();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-18 21:46:47 +03:00
|
|
|
void FS::set_block_size(size_t block_size)
|
2019-08-11 10:09:36 +02:00
|
|
|
{
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY(block_size > 0);
|
2019-08-11 10:09:36 +02:00
|
|
|
if (block_size == m_block_size)
|
|
|
|
|
return;
|
|
|
|
|
m_block_size = block_size;
|
|
|
|
|
}
|
2020-02-16 01:27:42 +01:00
|
|
|
|
2021-05-18 21:04:52 +02:00
|
|
|
void FS::set_fragment_size(size_t fragment_size)
|
|
|
|
|
{
|
|
|
|
|
VERIFY(fragment_size > 0);
|
|
|
|
|
if (fragment_size == m_fragment_size)
|
|
|
|
|
return;
|
|
|
|
|
m_fragment_size = fragment_size;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
}
|