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