2018-10-10 06:53:07 -03:00
|
|
|
#include <AK/Assertions.h>
|
|
|
|
|
#include <AK/HashMap.h>
|
2019-01-28 19:55:55 -02:00
|
|
|
#include <AK/StringBuilder.h>
|
2019-05-15 22:02:37 -03:00
|
|
|
#include <Kernel/FileSystem/FileSystem.h>
|
|
|
|
|
#include <Kernel/FileSystem/Inode.h>
|
2019-04-06 15:29:48 -03:00
|
|
|
#include <Kernel/Net/LocalSocket.h>
|
2019-06-07 06:43:58 -03:00
|
|
|
#include <Kernel/VM/MemoryManager.h>
|
|
|
|
|
#include <LibC/errno_numbers.h>
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2018-10-19 06:20:49 -03:00
|
|
|
static dword s_lastFileSystemID;
|
2018-12-19 21:39:29 -02:00
|
|
|
static HashMap<dword, FS*>* s_fs_map;
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2018-12-19 21:39:29 -02:00
|
|
|
static HashMap<dword, FS*>& all_fses()
|
2018-10-10 06:53:07 -03:00
|
|
|
{
|
2018-12-19 21:39:29 -02:00
|
|
|
if (!s_fs_map)
|
|
|
|
|
s_fs_map = new HashMap<dword, FS*>();
|
|
|
|
|
return *s_fs_map;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 14:13:10 -02:00
|
|
|
FS::FS()
|
2019-05-01 22:28:20 -03:00
|
|
|
: m_fsid(++s_lastFileSystemID)
|
2018-10-10 06:53:07 -03:00
|
|
|
{
|
2018-12-19 21:39:29 -02:00
|
|
|
all_fses().set(m_fsid, this);
|
2018-10-10 06:53:07 -03:00
|
|
|
}
|
|
|
|
|
|
2018-11-15 14:13:10 -02:00
|
|
|
FS::~FS()
|
2018-10-10 06:53:07 -03:00
|
|
|
{
|
2018-12-19 21:39:29 -02:00
|
|
|
all_fses().remove(m_fsid);
|
2018-10-10 06:53:07 -03:00
|
|
|
}
|
|
|
|
|
|
2018-12-02 21:20:00 -02:00
|
|
|
FS* FS::from_fsid(dword id)
|
2018-10-10 06:53:07 -03:00
|
|
|
{
|
2018-12-19 21:39:29 -02:00
|
|
|
auto it = all_fses().find(id);
|
|
|
|
|
if (it != all_fses().end())
|
2018-10-10 06:53:07 -03:00
|
|
|
return (*it).value;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 14:13:10 -02:00
|
|
|
FS::DirectoryEntry::DirectoryEntry(const char* n, InodeIdentifier i, byte ft)
|
2018-11-18 11:57:41 -02:00
|
|
|
: name_length(strlen(n))
|
2018-11-12 21:17:30 -02:00
|
|
|
, inode(i)
|
2019-01-31 14:31:23 -02:00
|
|
|
, file_type(ft)
|
2018-11-12 21:17:30 -02:00
|
|
|
{
|
|
|
|
|
memcpy(name, n, name_length);
|
|
|
|
|
name[name_length] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 08:00:53 -03:00
|
|
|
FS::DirectoryEntry::DirectoryEntry(const char* n, int nl, InodeIdentifier i, byte ft)
|
2018-11-12 21:17:30 -02:00
|
|
|
: name_length(nl)
|
|
|
|
|
, inode(i)
|
2019-01-31 14:31:23 -02:00
|
|
|
, file_type(ft)
|
2018-11-12 21:17:30 -02:00
|
|
|
{
|
|
|
|
|
memcpy(name, n, nl);
|
|
|
|
|
name[nl] = '\0';
|
|
|
|
|
}
|
2018-11-13 10:02:39 -02:00
|
|
|
|
2018-12-19 21:39:29 -02:00
|
|
|
void FS::sync()
|
|
|
|
|
{
|
2019-05-15 22:02:37 -03:00
|
|
|
Inode::sync();
|
2019-04-25 17:05:53 -03:00
|
|
|
|
2019-06-21 13:37:47 -03:00
|
|
|
Vector<NonnullRefPtr<FS>, 32> fses;
|
2019-04-25 17:05:53 -03:00
|
|
|
{
|
|
|
|
|
InterruptDisabler disabler;
|
|
|
|
|
for (auto& it : all_fses())
|
|
|
|
|
fses.append(*it.value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto fs : fses)
|
|
|
|
|
fs->flush_writes();
|
2018-12-19 21:39:29 -02:00
|
|
|
}
|
2019-06-16 06:49:39 -03:00
|
|
|
|
|
|
|
|
void FS::lock_all()
|
|
|
|
|
{
|
|
|
|
|
for (auto& it : all_fses()) {
|
|
|
|
|
it.value->m_lock.lock();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|