2018-10-10 11:53:07 +02:00
|
|
|
#include <AK/Assertions.h>
|
|
|
|
#include <AK/HashMap.h>
|
2019-01-28 22:55:55 +01:00
|
|
|
#include <AK/StringBuilder.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
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
static u32 s_lastFileSystemID;
|
|
|
|
static 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
|
|
|
if (!s_fs_map)
|
2019-07-03 21:17:35 +02:00
|
|
|
s_fs_map = new HashMap<u32, FS*>();
|
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;
|
|
|
|
}
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
FS::DirectoryEntry::DirectoryEntry(const char* n, InodeIdentifier i, u8 ft)
|
2018-11-18 14:57:41 +01:00
|
|
|
: name_length(strlen(n))
|
2018-11-13 00:17:30 +01:00
|
|
|
, inode(i)
|
2019-01-31 17:31:23 +01:00
|
|
|
, file_type(ft)
|
2018-11-13 00:17:30 +01:00
|
|
|
{
|
|
|
|
memcpy(name, n, name_length);
|
|
|
|
name[name_length] = '\0';
|
|
|
|
}
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
FS::DirectoryEntry::DirectoryEntry(const char* n, int nl, InodeIdentifier i, u8 ft)
|
2018-11-13 00:17:30 +01:00
|
|
|
: name_length(nl)
|
|
|
|
, inode(i)
|
2019-01-31 17:31:23 +01:00
|
|
|
, file_type(ft)
|
2018-11-13 00:17:30 +01:00
|
|
|
{
|
|
|
|
memcpy(name, n, nl);
|
|
|
|
name[nl] = '\0';
|
|
|
|
}
|
2018-11-13 13:02:39 +01:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|