mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:57:42 +00:00
Rename:
VirtualFileSystem -> VFS VirtualFileSystem::Node -> Vnode
This commit is contained in:
parent
c735c56e4c
commit
457a5df7d5
13 changed files with 143 additions and 137 deletions
|
@ -615,7 +615,7 @@ Region::Region(LinearAddress a, size_t s, String&& n, bool r, bool w, bool cow)
|
||||||
MM.register_region(*this);
|
MM.register_region(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Region::Region(LinearAddress a, size_t s, RetainPtr<VirtualFileSystem::Node>&& vnode, String&& n, bool r, bool w)
|
Region::Region(LinearAddress a, size_t s, RetainPtr<Vnode>&& vnode, String&& n, bool r, bool w)
|
||||||
: linearAddress(a)
|
: linearAddress(a)
|
||||||
, size(s)
|
, size(s)
|
||||||
, m_vmo(VMObject::create_file_backed(move(vnode), s))
|
, m_vmo(VMObject::create_file_backed(move(vnode), s))
|
||||||
|
@ -655,7 +655,7 @@ void PhysicalPage::return_to_freelist()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<VirtualFileSystem::Node>&& vnode, size_t size)
|
RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<Vnode>&& vnode, size_t size)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
if (vnode->vmo())
|
if (vnode->vmo())
|
||||||
|
@ -696,7 +696,7 @@ VMObject::VMObject(size_t size)
|
||||||
m_physical_pages.resize(page_count());
|
m_physical_pages.resize(page_count());
|
||||||
}
|
}
|
||||||
|
|
||||||
VMObject::VMObject(RetainPtr<VirtualFileSystem::Node>&& vnode, size_t size)
|
VMObject::VMObject(RetainPtr<Vnode>&& vnode, size_t size)
|
||||||
: m_size(size)
|
: m_size(size)
|
||||||
, m_vnode(move(vnode))
|
, m_vnode(move(vnode))
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,15 +62,15 @@ public:
|
||||||
|
|
||||||
class VMObject : public Retainable<VMObject> {
|
class VMObject : public Retainable<VMObject> {
|
||||||
public:
|
public:
|
||||||
static RetainPtr<VMObject> create_file_backed(RetainPtr<VirtualFileSystem::Node>&&, size_t);
|
static RetainPtr<VMObject> create_file_backed(RetainPtr<Vnode>&&, size_t);
|
||||||
static RetainPtr<VMObject> create_anonymous(size_t);
|
static RetainPtr<VMObject> create_anonymous(size_t);
|
||||||
RetainPtr<VMObject> clone();
|
RetainPtr<VMObject> clone();
|
||||||
|
|
||||||
~VMObject();
|
~VMObject();
|
||||||
bool is_anonymous() const { return m_anonymous; }
|
bool is_anonymous() const { return m_anonymous; }
|
||||||
|
|
||||||
VirtualFileSystem::Node* vnode() { return m_vnode.ptr(); }
|
Vnode* vnode() { return m_vnode.ptr(); }
|
||||||
const VirtualFileSystem::Node* vnode() const { return m_vnode.ptr(); }
|
const Vnode* vnode() const { return m_vnode.ptr(); }
|
||||||
size_t vnode_offset() const { return m_vnode_offset; }
|
size_t vnode_offset() const { return m_vnode_offset; }
|
||||||
|
|
||||||
String name() const { return m_name; }
|
String name() const { return m_name; }
|
||||||
|
@ -81,14 +81,14 @@ public:
|
||||||
Vector<RetainPtr<PhysicalPage>>& physical_pages() { return m_physical_pages; }
|
Vector<RetainPtr<PhysicalPage>>& physical_pages() { return m_physical_pages; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VMObject(RetainPtr<VirtualFileSystem::Node>&&, size_t);
|
VMObject(RetainPtr<Vnode>&&, size_t);
|
||||||
explicit VMObject(VMObject&);
|
explicit VMObject(VMObject&);
|
||||||
explicit VMObject(size_t);
|
explicit VMObject(size_t);
|
||||||
String m_name;
|
String m_name;
|
||||||
bool m_anonymous { false };
|
bool m_anonymous { false };
|
||||||
Unix::off_t m_vnode_offset { 0 };
|
Unix::off_t m_vnode_offset { 0 };
|
||||||
size_t m_size { 0 };
|
size_t m_size { 0 };
|
||||||
RetainPtr<VirtualFileSystem::Node> m_vnode;
|
RetainPtr<Vnode> m_vnode;
|
||||||
Vector<RetainPtr<PhysicalPage>> m_physical_pages;
|
Vector<RetainPtr<PhysicalPage>> m_physical_pages;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ class Region : public Retainable<Region> {
|
||||||
public:
|
public:
|
||||||
Region(LinearAddress, size_t, String&&, bool r, bool w, bool cow = false);
|
Region(LinearAddress, size_t, String&&, bool r, bool w, bool cow = false);
|
||||||
Region(LinearAddress, size_t, RetainPtr<VMObject>&&, size_t offset_in_vmo, String&&, bool r, bool w, bool cow = false);
|
Region(LinearAddress, size_t, RetainPtr<VMObject>&&, size_t offset_in_vmo, String&&, bool r, bool w, bool cow = false);
|
||||||
Region(LinearAddress, size_t, RetainPtr<VirtualFileSystem::Node>&&, String&&, bool r, bool w);
|
Region(LinearAddress, size_t, RetainPtr<Vnode>&&, String&&, bool r, bool w);
|
||||||
~Region();
|
~Region();
|
||||||
|
|
||||||
const VMObject& vmo() const { return *m_vmo; }
|
const VMObject& vmo() const { return *m_vmo; }
|
||||||
|
|
|
@ -136,7 +136,7 @@ ByteBuffer procfs$pid_exe(Process& process)
|
||||||
ProcessInspectionHandle handle(process);
|
ProcessInspectionHandle handle(process);
|
||||||
auto inode = process.executable_inode();
|
auto inode = process.executable_inode();
|
||||||
ASSERT(inode);
|
ASSERT(inode);
|
||||||
return VirtualFileSystem::the().absolute_path(*inode).toByteBuffer();
|
return VFS::the().absolute_path(*inode).toByteBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer procfs$pid_cwd(Process& process)
|
ByteBuffer procfs$pid_cwd(Process& process)
|
||||||
|
@ -144,7 +144,7 @@ ByteBuffer procfs$pid_cwd(Process& process)
|
||||||
ProcessInspectionHandle handle(process);
|
ProcessInspectionHandle handle(process);
|
||||||
auto inode = process.cwd_inode();
|
auto inode = process.cwd_inode();
|
||||||
ASSERT(inode);
|
ASSERT(inode);
|
||||||
return VirtualFileSystem::the().absolute_path(*inode).toByteBuffer();
|
return VFS::the().absolute_path(*inode).toByteBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcFileSystem::addProcess(Process& process)
|
void ProcFileSystem::addProcess(Process& process)
|
||||||
|
@ -214,9 +214,9 @@ ByteBuffer procfs$regions()
|
||||||
ByteBuffer procfs$mounts()
|
ByteBuffer procfs$mounts()
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
auto buffer = ByteBuffer::createUninitialized(VirtualFileSystem::the().mountCount() * 80);
|
auto buffer = ByteBuffer::createUninitialized(VFS::the().mountCount() * 80);
|
||||||
char* ptr = (char*)buffer.pointer();
|
char* ptr = (char*)buffer.pointer();
|
||||||
VirtualFileSystem::the().forEachMount([&ptr] (auto& mount) {
|
VFS::the().forEachMount([&ptr] (auto& mount) {
|
||||||
auto& fs = mount.fileSystem();
|
auto& fs = mount.fileSystem();
|
||||||
ptr += ksprintf(ptr, "%s @ ", fs.className());
|
ptr += ksprintf(ptr, "%s @ ", fs.className());
|
||||||
if (!mount.host().isValid())
|
if (!mount.host().isValid())
|
||||||
|
@ -330,7 +330,7 @@ ByteBuffer procfs$summary()
|
||||||
|
|
||||||
ByteBuffer procfs$vnodes()
|
ByteBuffer procfs$vnodes()
|
||||||
{
|
{
|
||||||
auto& vfs = VirtualFileSystem::the();
|
auto& vfs = VFS::the();
|
||||||
auto buffer = ByteBuffer::createUninitialized(vfs.m_maxNodeCount * 256);
|
auto buffer = ByteBuffer::createUninitialized(vfs.m_maxNodeCount * 256);
|
||||||
char* ptr = (char*)buffer.pointer();
|
char* ptr = (char*)buffer.pointer();
|
||||||
for (size_t i = 0; i < vfs.m_maxNodeCount; ++i) {
|
for (size_t i = 0; i < vfs.m_maxNodeCount; ++i) {
|
||||||
|
|
|
@ -102,7 +102,7 @@ Region* Process::allocate_region(LinearAddress laddr, size_t size, String&& name
|
||||||
return m_regions.last().ptr();
|
return m_regions.last().ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
Region* Process::allocate_file_backed_region(LinearAddress laddr, size_t size, RetainPtr<VirtualFileSystem::Node>&& vnode, String&& name, bool is_readable, bool is_writable)
|
Region* Process::allocate_file_backed_region(LinearAddress laddr, size_t size, RetainPtr<Vnode>&& vnode, String&& name, bool is_readable, bool is_writable)
|
||||||
{
|
{
|
||||||
ASSERT(!vnode->isCharacterDevice());
|
ASSERT(!vnode->isCharacterDevice());
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<Stri
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
int error;
|
int error;
|
||||||
auto descriptor = VirtualFileSystem::the().open(path, error, 0, m_cwd ? m_cwd->inode : InodeIdentifier());
|
auto descriptor = VFS::the().open(path, error, 0, m_cwd ? m_cwd->inode : InodeIdentifier());
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
ASSERT(error != 0);
|
ASSERT(error != 0);
|
||||||
return error;
|
return error;
|
||||||
|
@ -483,14 +483,14 @@ Process* Process::create_user_process(const String& path, uid_t uid, gid_t gid,
|
||||||
if (arguments.isEmpty()) {
|
if (arguments.isEmpty()) {
|
||||||
arguments.append(parts.last());
|
arguments.append(parts.last());
|
||||||
}
|
}
|
||||||
RetainPtr<VirtualFileSystem::Node> cwd;
|
RetainPtr<Vnode> cwd;
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
if (auto* parent = Process::from_pid(parent_pid))
|
if (auto* parent = Process::from_pid(parent_pid))
|
||||||
cwd = parent->m_cwd.copyRef();
|
cwd = parent->m_cwd.copyRef();
|
||||||
}
|
}
|
||||||
if (!cwd)
|
if (!cwd)
|
||||||
cwd = VirtualFileSystem::the().root();
|
cwd = VFS::the().root();
|
||||||
|
|
||||||
auto* process = new Process(parts.takeLast(), uid, gid, parent_pid, Ring3, move(cwd), nullptr, tty);
|
auto* process = new Process(parts.takeLast(), uid, gid, parent_pid, Ring3, move(cwd), nullptr, tty);
|
||||||
|
|
||||||
|
@ -570,7 +570,7 @@ Process* Process::create_kernel_process(void (*e)(), String&& name)
|
||||||
return process;
|
return process;
|
||||||
}
|
}
|
||||||
|
|
||||||
Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring, RetainPtr<VirtualFileSystem::Node>&& cwd, RetainPtr<VirtualFileSystem::Node>&& executable, TTY* tty, Process* fork_parent)
|
Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring, RetainPtr<Vnode>&& cwd, RetainPtr<Vnode>&& executable, TTY* tty, Process* fork_parent)
|
||||||
: m_name(move(name))
|
: m_name(move(name))
|
||||||
, m_pid(next_pid++) // FIXME: RACE: This variable looks racy!
|
, m_pid(next_pid++) // FIXME: RACE: This variable looks racy!
|
||||||
, m_uid(uid)
|
, m_uid(uid)
|
||||||
|
@ -1124,7 +1124,7 @@ int Process::sys$lstat(const char* path, Unix::stat* statbuf)
|
||||||
{
|
{
|
||||||
VALIDATE_USER_WRITE(statbuf, sizeof(Unix::stat));
|
VALIDATE_USER_WRITE(statbuf, sizeof(Unix::stat));
|
||||||
int error;
|
int error;
|
||||||
auto descriptor = VirtualFileSystem::the().open(move(path), error, O_NOFOLLOW_NOERROR, cwd_inode()->identifier());
|
auto descriptor = VFS::the().open(move(path), error, O_NOFOLLOW_NOERROR, cwd_inode()->identifier());
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return error;
|
return error;
|
||||||
descriptor->stat(statbuf);
|
descriptor->stat(statbuf);
|
||||||
|
@ -1135,7 +1135,7 @@ int Process::sys$stat(const char* path, Unix::stat* statbuf)
|
||||||
{
|
{
|
||||||
VALIDATE_USER_WRITE(statbuf, sizeof(Unix::stat));
|
VALIDATE_USER_WRITE(statbuf, sizeof(Unix::stat));
|
||||||
int error;
|
int error;
|
||||||
auto descriptor = VirtualFileSystem::the().open(move(path), error, 0, cwd_inode()->identifier());
|
auto descriptor = VFS::the().open(move(path), error, 0, cwd_inode()->identifier());
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return error;
|
return error;
|
||||||
descriptor->stat(statbuf);
|
descriptor->stat(statbuf);
|
||||||
|
@ -1148,7 +1148,7 @@ int Process::sys$readlink(const char* path, char* buffer, size_t size)
|
||||||
VALIDATE_USER_WRITE(buffer, size);
|
VALIDATE_USER_WRITE(buffer, size);
|
||||||
|
|
||||||
int error;
|
int error;
|
||||||
auto descriptor = VirtualFileSystem::the().open(path, error, O_RDONLY | O_NOFOLLOW_NOERROR, cwd_inode()->identifier());
|
auto descriptor = VFS::the().open(path, error, O_RDONLY | O_NOFOLLOW_NOERROR, cwd_inode()->identifier());
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
|
@ -1169,7 +1169,7 @@ int Process::sys$chdir(const char* path)
|
||||||
{
|
{
|
||||||
VALIDATE_USER_READ(path, strlen(path));
|
VALIDATE_USER_READ(path, strlen(path));
|
||||||
int error;
|
int error;
|
||||||
auto descriptor = VirtualFileSystem::the().open(path, error, 0, cwd_inode()->identifier());
|
auto descriptor = VFS::the().open(path, error, 0, cwd_inode()->identifier());
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return error;
|
return error;
|
||||||
if (!descriptor->isDirectory())
|
if (!descriptor->isDirectory())
|
||||||
|
@ -1182,7 +1182,7 @@ int Process::sys$getcwd(char* buffer, size_t size)
|
||||||
{
|
{
|
||||||
VALIDATE_USER_WRITE(buffer, size);
|
VALIDATE_USER_WRITE(buffer, size);
|
||||||
ASSERT(cwd_inode());
|
ASSERT(cwd_inode());
|
||||||
auto path = VirtualFileSystem::the().absolute_path(*cwd_inode());
|
auto path = VFS::the().absolute_path(*cwd_inode());
|
||||||
if (path.isNull())
|
if (path.isNull())
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (size < path.length() + 1)
|
if (size < path.length() + 1)
|
||||||
|
@ -1210,7 +1210,7 @@ int Process::sys$open(const char* path, int options)
|
||||||
if (number_of_open_file_descriptors() >= m_max_open_file_descriptors)
|
if (number_of_open_file_descriptors() >= m_max_open_file_descriptors)
|
||||||
return -EMFILE;
|
return -EMFILE;
|
||||||
int error;
|
int error;
|
||||||
auto descriptor = VirtualFileSystem::the().open(path, error, options, cwd_inode()->identifier());
|
auto descriptor = VFS::the().open(path, error, options, cwd_inode()->identifier());
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return error;
|
return error;
|
||||||
if (options & O_DIRECTORY && !descriptor->isDirectory())
|
if (options & O_DIRECTORY && !descriptor->isDirectory())
|
||||||
|
|
|
@ -222,7 +222,7 @@ private:
|
||||||
friend class Scheduler;
|
friend class Scheduler;
|
||||||
friend class Region;
|
friend class Region;
|
||||||
|
|
||||||
Process(String&& name, uid_t, gid_t, pid_t ppid, RingLevel, RetainPtr<VirtualFileSystem::Node>&& cwd = nullptr, RetainPtr<VirtualFileSystem::Node>&& executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr);
|
Process(String&& name, uid_t, gid_t, pid_t ppid, RingLevel, RetainPtr<Vnode>&& cwd = nullptr, RetainPtr<Vnode>&& executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr);
|
||||||
|
|
||||||
int do_exec(const String& path, Vector<String>&& arguments, Vector<String>&& environment);
|
int do_exec(const String& path, Vector<String>&& arguments, Vector<String>&& environment);
|
||||||
void push_value_on_stack(dword);
|
void push_value_on_stack(dword);
|
||||||
|
@ -276,13 +276,13 @@ private:
|
||||||
byte m_termination_status { 0 };
|
byte m_termination_status { 0 };
|
||||||
byte m_termination_signal { 0 };
|
byte m_termination_signal { 0 };
|
||||||
|
|
||||||
RetainPtr<VirtualFileSystem::Node> m_cwd;
|
RetainPtr<Vnode> m_cwd;
|
||||||
RetainPtr<VirtualFileSystem::Node> m_executable;
|
RetainPtr<Vnode> m_executable;
|
||||||
|
|
||||||
TTY* m_tty { nullptr };
|
TTY* m_tty { nullptr };
|
||||||
|
|
||||||
Region* allocate_region(LinearAddress, size_t, String&& name, bool is_readable = true, bool is_writable = true);
|
Region* allocate_region(LinearAddress, size_t, String&& name, bool is_readable = true, bool is_writable = true);
|
||||||
Region* allocate_file_backed_region(LinearAddress, size_t, RetainPtr<VirtualFileSystem::Node>&& vnode, String&& name, bool is_readable, bool is_writable);
|
Region* allocate_file_backed_region(LinearAddress, size_t, RetainPtr<Vnode>&& vnode, String&& name, bool is_readable, bool is_writable);
|
||||||
Region* allocate_region_with_vmo(LinearAddress, size_t, RetainPtr<VMObject>&&, size_t offset_in_vmo, String&& name, bool is_readable, bool is_writable);
|
Region* allocate_region_with_vmo(LinearAddress, size_t, RetainPtr<VMObject>&&, size_t offset_in_vmo, String&& name, bool is_readable, bool is_writable);
|
||||||
bool deallocate_region(Region& region);
|
bool deallocate_region(Region& region);
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@ static void init_stage2()
|
||||||
{
|
{
|
||||||
Syscall::initialize();
|
Syscall::initialize();
|
||||||
|
|
||||||
auto vfs = make<VirtualFileSystem>();
|
auto vfs = make<VFS>();
|
||||||
|
|
||||||
auto dev_zero = make<ZeroDevice>();
|
auto dev_zero = make<ZeroDevice>();
|
||||||
vfs->registerCharacterDevice(*dev_zero);
|
vfs->registerCharacterDevice(*dev_zero);
|
||||||
|
@ -267,7 +267,7 @@ void init()
|
||||||
|
|
||||||
MemoryManager::initialize();
|
MemoryManager::initialize();
|
||||||
|
|
||||||
VirtualFileSystem::initializeGlobals();
|
VFS::initializeGlobals();
|
||||||
StringImpl::initializeGlobals();
|
StringImpl::initializeGlobals();
|
||||||
|
|
||||||
PIT::initialize();
|
PIT::initialize();
|
||||||
|
|
|
@ -6,5 +6,5 @@ CharacterDevice::~CharacterDevice()
|
||||||
|
|
||||||
RetainPtr<FileDescriptor> CharacterDevice::open(int options)
|
RetainPtr<FileDescriptor> CharacterDevice::open(int options)
|
||||||
{
|
{
|
||||||
return VirtualFileSystem::the().open(*this, options);
|
return VFS::the().open(*this, options);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "TTY.h"
|
#include "TTY.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RetainPtr<FileDescriptor> FileDescriptor::create(RetainPtr<VirtualFileSystem::Node>&& vnode)
|
RetainPtr<FileDescriptor> FileDescriptor::create(RetainPtr<Vnode>&& vnode)
|
||||||
{
|
{
|
||||||
return adopt(*new FileDescriptor(move(vnode)));
|
return adopt(*new FileDescriptor(move(vnode)));
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ RetainPtr<FileDescriptor> FileDescriptor::create_pipe_reader(FIFO& fifo)
|
||||||
return adopt(*new FileDescriptor(fifo, FIFO::Reader));
|
return adopt(*new FileDescriptor(fifo, FIFO::Reader));
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDescriptor::FileDescriptor(RetainPtr<VirtualFileSystem::Node>&& vnode)
|
FileDescriptor::FileDescriptor(RetainPtr<Vnode>&& vnode)
|
||||||
: m_vnode(move(vnode))
|
: m_vnode(move(vnode))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,7 @@ String FileDescriptor::absolute_path()
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
ASSERT(m_vnode->core_inode());
|
ASSERT(m_vnode->core_inode());
|
||||||
return VirtualFileSystem::the().absolute_path(*m_vnode->core_inode());
|
return VFS::the().absolute_path(*m_vnode->core_inode());
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDescriptor::FileDescriptor(FIFO& fifo, FIFO::Direction direction)
|
FileDescriptor::FileDescriptor(FIFO& fifo, FIFO::Direction direction)
|
||||||
|
|
|
@ -13,7 +13,7 @@ class TTY;
|
||||||
|
|
||||||
class FileDescriptor : public Retainable<FileDescriptor> {
|
class FileDescriptor : public Retainable<FileDescriptor> {
|
||||||
public:
|
public:
|
||||||
static RetainPtr<FileDescriptor> create(RetainPtr<VirtualFileSystem::Node>&&);
|
static RetainPtr<FileDescriptor> create(RetainPtr<Vnode>&&);
|
||||||
static RetainPtr<FileDescriptor> create_pipe_writer(FIFO&);
|
static RetainPtr<FileDescriptor> create_pipe_writer(FIFO&);
|
||||||
static RetainPtr<FileDescriptor> create_pipe_reader(FIFO&);
|
static RetainPtr<FileDescriptor> create_pipe_reader(FIFO&);
|
||||||
~FileDescriptor();
|
~FileDescriptor();
|
||||||
|
@ -46,7 +46,7 @@ public:
|
||||||
|
|
||||||
InodeMetadata metadata() const { return m_vnode->metadata(); }
|
InodeMetadata metadata() const { return m_vnode->metadata(); }
|
||||||
|
|
||||||
VirtualFileSystem::Node* vnode() { return m_vnode.ptr(); }
|
Vnode* vnode() { return m_vnode.ptr(); }
|
||||||
|
|
||||||
#ifdef SERENITY
|
#ifdef SERENITY
|
||||||
bool isBlocking() const { return m_isBlocking; }
|
bool isBlocking() const { return m_isBlocking; }
|
||||||
|
@ -62,11 +62,11 @@ public:
|
||||||
ByteBuffer& generatorCache() { return m_generatorCache; }
|
ByteBuffer& generatorCache() { return m_generatorCache; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class VirtualFileSystem;
|
friend class VFS;
|
||||||
explicit FileDescriptor(RetainPtr<VirtualFileSystem::Node>&&);
|
explicit FileDescriptor(RetainPtr<Vnode>&&);
|
||||||
FileDescriptor(FIFO&, FIFO::Direction);
|
FileDescriptor(FIFO&, FIFO::Direction);
|
||||||
|
|
||||||
RetainPtr<VirtualFileSystem::Node> m_vnode;
|
RetainPtr<Vnode> m_vnode;
|
||||||
RetainPtr<CoreInode> m_inode;
|
RetainPtr<CoreInode> m_inode;
|
||||||
|
|
||||||
Unix::off_t m_currentOffset { 0 };
|
Unix::off_t m_currentOffset { 0 };
|
||||||
|
|
|
@ -65,7 +65,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
class CoreInode : public Retainable<CoreInode> {
|
class CoreInode : public Retainable<CoreInode> {
|
||||||
friend class VirtualFileSystem;
|
friend class VFS;
|
||||||
public:
|
public:
|
||||||
virtual ~CoreInode();
|
virtual ~CoreInode();
|
||||||
|
|
||||||
|
|
|
@ -10,45 +10,45 @@
|
||||||
|
|
||||||
//#define VFS_DEBUG
|
//#define VFS_DEBUG
|
||||||
|
|
||||||
static VirtualFileSystem* s_the;
|
static VFS* s_the;
|
||||||
|
|
||||||
#ifndef SERENITY
|
#ifndef SERENITY
|
||||||
typedef int InterruptDisabler;
|
typedef int InterruptDisabler;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VirtualFileSystem& VirtualFileSystem::the()
|
VFS& VFS::the()
|
||||||
{
|
{
|
||||||
ASSERT(s_the);
|
ASSERT(s_the);
|
||||||
return *s_the;
|
return *s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualFileSystem::initializeGlobals()
|
void VFS::initializeGlobals()
|
||||||
{
|
{
|
||||||
s_the = nullptr;
|
s_the = nullptr;
|
||||||
FileSystem::initializeGlobals();
|
FileSystem::initializeGlobals();
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFileSystem::VirtualFileSystem()
|
VFS::VFS()
|
||||||
{
|
{
|
||||||
#ifdef VFS_DEBUG
|
#ifdef VFS_DEBUG
|
||||||
kprintf("VFS: Constructing VFS\n");
|
kprintf("VFS: Constructing VFS\n");
|
||||||
#endif
|
#endif
|
||||||
s_the = this;
|
s_the = this;
|
||||||
m_maxNodeCount = 16;
|
m_maxNodeCount = 16;
|
||||||
m_nodes = reinterpret_cast<Node*>(kmalloc(sizeof(Node) * maxNodeCount()));
|
m_nodes = reinterpret_cast<Vnode*>(kmalloc(sizeof(Vnode) * maxNodeCount()));
|
||||||
memset(m_nodes, 0, sizeof(Node) * maxNodeCount());
|
memset(m_nodes, 0, sizeof(Vnode) * maxNodeCount());
|
||||||
|
|
||||||
for (unsigned i = 0; i < m_maxNodeCount; ++i)
|
for (unsigned i = 0; i < m_maxNodeCount; ++i)
|
||||||
m_nodeFreeList.append(&m_nodes[i]);
|
m_nodeFreeList.append(&m_nodes[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFileSystem::~VirtualFileSystem()
|
VFS::~VFS()
|
||||||
{
|
{
|
||||||
kprintf("VFS: ~VirtualFileSystem with %u nodes allocated\n", allocatedNodeCount());
|
kprintf("VFS: ~VirtualFileSystem with %u nodes allocated\n", allocatedNodeCount());
|
||||||
// FIXME: m_nodes is never freed. Does it matter though?
|
// FIXME: m_nodes is never freed. Does it matter though?
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VirtualFileSystem::makeNode(InodeIdentifier inode) -> RetainPtr<Node>
|
auto VFS::makeNode(InodeIdentifier inode) -> RetainPtr<Vnode>
|
||||||
{
|
{
|
||||||
auto metadata = inode.metadata();
|
auto metadata = inode.metadata();
|
||||||
if (!metadata.isValid())
|
if (!metadata.isValid())
|
||||||
|
@ -91,7 +91,7 @@ auto VirtualFileSystem::makeNode(InodeIdentifier inode) -> RetainPtr<Node>
|
||||||
return vnode;
|
return vnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VirtualFileSystem::makeNode(CharacterDevice& device) -> RetainPtr<Node>
|
auto VFS::makeNode(CharacterDevice& device) -> RetainPtr<Vnode>
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
auto vnode = allocateNode();
|
auto vnode = allocateNode();
|
||||||
|
@ -107,7 +107,7 @@ auto VirtualFileSystem::makeNode(CharacterDevice& device) -> RetainPtr<Node>
|
||||||
return vnode;
|
return vnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VirtualFileSystem::getOrCreateNode(InodeIdentifier inode) -> RetainPtr<Node>
|
auto VFS::getOrCreateNode(InodeIdentifier inode) -> RetainPtr<Vnode>
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
|
@ -118,7 +118,7 @@ auto VirtualFileSystem::getOrCreateNode(InodeIdentifier inode) -> RetainPtr<Node
|
||||||
return makeNode(inode);
|
return makeNode(inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VirtualFileSystem::getOrCreateNode(CharacterDevice& device) -> RetainPtr<Node>
|
auto VFS::getOrCreateNode(CharacterDevice& device) -> RetainPtr<Vnode>
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
|
@ -129,7 +129,7 @@ auto VirtualFileSystem::getOrCreateNode(CharacterDevice& device) -> RetainPtr<No
|
||||||
return makeNode(device);
|
return makeNode(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VirtualFileSystem::mount(RetainPtr<FileSystem>&& fileSystem, const String& path)
|
bool VFS::mount(RetainPtr<FileSystem>&& fileSystem, const String& path)
|
||||||
{
|
{
|
||||||
ASSERT(fileSystem);
|
ASSERT(fileSystem);
|
||||||
int error;
|
int error;
|
||||||
|
@ -146,7 +146,7 @@ bool VirtualFileSystem::mount(RetainPtr<FileSystem>&& fileSystem, const String&
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VirtualFileSystem::mountRoot(RetainPtr<FileSystem>&& fileSystem)
|
bool VFS::mountRoot(RetainPtr<FileSystem>&& fileSystem)
|
||||||
{
|
{
|
||||||
if (m_rootNode) {
|
if (m_rootNode) {
|
||||||
kprintf("VFS: mountRoot can't mount another root\n");
|
kprintf("VFS: mountRoot can't mount another root\n");
|
||||||
|
@ -175,7 +175,7 @@ bool VirtualFileSystem::mountRoot(RetainPtr<FileSystem>&& fileSystem)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VirtualFileSystem::allocateNode() -> RetainPtr<Node>
|
auto VFS::allocateNode() -> RetainPtr<Vnode>
|
||||||
{
|
{
|
||||||
if (m_nodeFreeList.isEmpty()) {
|
if (m_nodeFreeList.isEmpty()) {
|
||||||
kprintf("VFS: allocateNode has no nodes left\n");
|
kprintf("VFS: allocateNode has no nodes left\n");
|
||||||
|
@ -189,7 +189,7 @@ auto VirtualFileSystem::allocateNode() -> RetainPtr<Node>
|
||||||
return adopt(*node);
|
return adopt(*node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualFileSystem::freeNode(Node* node)
|
void VFS::freeNode(Vnode* node)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
ASSERT(node);
|
ASSERT(node);
|
||||||
|
@ -209,7 +209,7 @@ void VirtualFileSystem::freeNode(Node* node)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SERENITY
|
#ifndef SERENITY
|
||||||
bool VirtualFileSystem::isDirectory(const String& path, InodeIdentifier base)
|
bool VFS::isDirectory(const String& path, InodeIdentifier base)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
auto inode = resolvePath(path, error, base);
|
auto inode = resolvePath(path, error, base);
|
||||||
|
@ -220,7 +220,7 @@ bool VirtualFileSystem::isDirectory(const String& path, InodeIdentifier base)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto VirtualFileSystem::findMountForHost(InodeIdentifier inode) -> Mount*
|
auto VFS::findMountForHost(InodeIdentifier inode) -> Mount*
|
||||||
{
|
{
|
||||||
for (auto& mount : m_mounts) {
|
for (auto& mount : m_mounts) {
|
||||||
if (mount->host() == inode)
|
if (mount->host() == inode)
|
||||||
|
@ -229,7 +229,7 @@ auto VirtualFileSystem::findMountForHost(InodeIdentifier inode) -> Mount*
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VirtualFileSystem::findMountForGuest(InodeIdentifier inode) -> Mount*
|
auto VFS::findMountForGuest(InodeIdentifier inode) -> Mount*
|
||||||
{
|
{
|
||||||
for (auto& mount : m_mounts) {
|
for (auto& mount : m_mounts) {
|
||||||
if (mount->guest() == inode)
|
if (mount->guest() == inode)
|
||||||
|
@ -238,12 +238,12 @@ auto VirtualFileSystem::findMountForGuest(InodeIdentifier inode) -> Mount*
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VirtualFileSystem::isRoot(InodeIdentifier inode) const
|
bool VFS::is_vfs_root(InodeIdentifier inode) const
|
||||||
{
|
{
|
||||||
return inode == m_rootNode->inode;
|
return inode == m_rootNode->inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualFileSystem::enumerateDirectoryInode(InodeIdentifier directoryInode, Function<bool(const FileSystem::DirectoryEntry&)> callback)
|
void VFS::enumerateDirectoryInode(InodeIdentifier directoryInode, Function<bool(const FileSystem::DirectoryEntry&)> callback)
|
||||||
{
|
{
|
||||||
if (!directoryInode.isValid())
|
if (!directoryInode.isValid())
|
||||||
return;
|
return;
|
||||||
|
@ -255,7 +255,7 @@ void VirtualFileSystem::enumerateDirectoryInode(InodeIdentifier directoryInode,
|
||||||
else
|
else
|
||||||
resolvedInode = entry.inode;
|
resolvedInode = entry.inode;
|
||||||
|
|
||||||
if (directoryInode.isRootInode() && !isRoot(directoryInode) && !strcmp(entry.name, "..")) {
|
if (directoryInode.isRootInode() && !is_vfs_root(directoryInode) && !strcmp(entry.name, "..")) {
|
||||||
auto mount = findMountForGuest(entry.inode);
|
auto mount = findMountForGuest(entry.inode);
|
||||||
ASSERT(mount);
|
ASSERT(mount);
|
||||||
resolvedInode = mount->host();
|
resolvedInode = mount->host();
|
||||||
|
@ -266,7 +266,7 @@ void VirtualFileSystem::enumerateDirectoryInode(InodeIdentifier directoryInode,
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SERENITY
|
#ifndef SERENITY
|
||||||
void VirtualFileSystem::listDirectory(const String& path, InodeIdentifier base)
|
void VFS::listDirectory(const String& path, InodeIdentifier base)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
auto directoryInode = resolvePath(path, error, base);
|
auto directoryInode = resolvePath(path, error, base);
|
||||||
|
@ -367,7 +367,7 @@ void VirtualFileSystem::listDirectory(const String& path, InodeIdentifier base)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualFileSystem::listDirectoryRecursively(const String& path, InodeIdentifier base)
|
void VFS::listDirectoryRecursively(const String& path, InodeIdentifier base)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
auto directory = resolvePath(path, error, base);
|
auto directory = resolvePath(path, error, base);
|
||||||
|
@ -392,7 +392,7 @@ void VirtualFileSystem::listDirectoryRecursively(const String& path, InodeIdenti
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool VirtualFileSystem::touch(const String& path)
|
bool VFS::touch(const String& path)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
auto inode = resolvePath(path, error);
|
auto inode = resolvePath(path, error);
|
||||||
|
@ -401,7 +401,7 @@ bool VirtualFileSystem::touch(const String& path)
|
||||||
return inode.fileSystem()->setModificationTime(inode, ktime(nullptr));
|
return inode.fileSystem()->setModificationTime(inode, ktime(nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
RetainPtr<FileDescriptor> VirtualFileSystem::open(CharacterDevice& device, int options)
|
RetainPtr<FileDescriptor> VFS::open(CharacterDevice& device, int options)
|
||||||
{
|
{
|
||||||
// FIXME: Respect options.
|
// FIXME: Respect options.
|
||||||
(void) options;
|
(void) options;
|
||||||
|
@ -411,7 +411,7 @@ RetainPtr<FileDescriptor> VirtualFileSystem::open(CharacterDevice& device, int o
|
||||||
return FileDescriptor::create(move(vnode));
|
return FileDescriptor::create(move(vnode));
|
||||||
}
|
}
|
||||||
|
|
||||||
RetainPtr<FileDescriptor> VirtualFileSystem::open(const String& path, int& error, int options, InodeIdentifier base)
|
RetainPtr<FileDescriptor> VFS::open(const String& path, int& error, int options, InodeIdentifier base)
|
||||||
{
|
{
|
||||||
auto inode = resolvePath(path, error, base, options);
|
auto inode = resolvePath(path, error, base, options);
|
||||||
if (!inode.isValid())
|
if (!inode.isValid())
|
||||||
|
@ -422,7 +422,7 @@ RetainPtr<FileDescriptor> VirtualFileSystem::open(const String& path, int& error
|
||||||
return FileDescriptor::create(move(vnode));
|
return FileDescriptor::create(move(vnode));
|
||||||
}
|
}
|
||||||
|
|
||||||
RetainPtr<FileDescriptor> VirtualFileSystem::create(const String& path, InodeIdentifier base)
|
RetainPtr<FileDescriptor> VFS::create(const String& path, InodeIdentifier base)
|
||||||
{
|
{
|
||||||
// FIXME: Do the real thing, not just this fake thing!
|
// FIXME: Do the real thing, not just this fake thing!
|
||||||
(void) path;
|
(void) path;
|
||||||
|
@ -431,7 +431,7 @@ RetainPtr<FileDescriptor> VirtualFileSystem::create(const String& path, InodeIde
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
RetainPtr<FileDescriptor> VirtualFileSystem::mkdir(const String& path, InodeIdentifier base)
|
RetainPtr<FileDescriptor> VFS::mkdir(const String& path, InodeIdentifier base)
|
||||||
{
|
{
|
||||||
// FIXME: Do the real thing, not just this fake thing!
|
// FIXME: Do the real thing, not just this fake thing!
|
||||||
(void) path;
|
(void) path;
|
||||||
|
@ -440,7 +440,7 @@ RetainPtr<FileDescriptor> VirtualFileSystem::mkdir(const String& path, InodeIden
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
InodeIdentifier VirtualFileSystem::resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error)
|
InodeIdentifier VFS::resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error)
|
||||||
{
|
{
|
||||||
auto symlinkContents = symlinkInode.readEntireFile();
|
auto symlinkContents = symlinkInode.readEntireFile();
|
||||||
if (!symlinkContents)
|
if (!symlinkContents)
|
||||||
|
@ -452,14 +452,14 @@ InodeIdentifier VirtualFileSystem::resolveSymbolicLink(InodeIdentifier base, Ino
|
||||||
return resolvePath(linkee, error, base);
|
return resolvePath(linkee, error, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
RetainPtr<CoreInode> VirtualFileSystem::get_inode(InodeIdentifier inode_id)
|
RetainPtr<CoreInode> VFS::get_inode(InodeIdentifier inode_id)
|
||||||
{
|
{
|
||||||
if (!inode_id.isValid())
|
if (!inode_id.isValid())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return inode_id.fileSystem()->get_inode(inode_id);
|
return inode_id.fileSystem()->get_inode(inode_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
String VirtualFileSystem::absolute_path(CoreInode& core_inode)
|
String VFS::absolute_path(CoreInode& core_inode)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
Vector<InodeIdentifier> lineage;
|
Vector<InodeIdentifier> lineage;
|
||||||
|
@ -494,7 +494,7 @@ String VirtualFileSystem::absolute_path(CoreInode& core_inode)
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
InodeIdentifier VirtualFileSystem::resolvePath(const String& path, int& error, InodeIdentifier base, int options)
|
InodeIdentifier VFS::resolvePath(const String& path, int& error, InodeIdentifier base, int options)
|
||||||
{
|
{
|
||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
return { };
|
return { };
|
||||||
|
@ -545,7 +545,7 @@ InodeIdentifier VirtualFileSystem::resolvePath(const String& path, int& error, I
|
||||||
#endif
|
#endif
|
||||||
inode = mount->guest();
|
inode = mount->guest();
|
||||||
}
|
}
|
||||||
if (wasRootInodeAtHeadOfLoop && inode.isRootInode() && !isRoot(inode) && part == "..") {
|
if (wasRootInodeAtHeadOfLoop && inode.isRootInode() && !is_vfs_root(inode) && part == "..") {
|
||||||
#ifdef VFS_DEBUG
|
#ifdef VFS_DEBUG
|
||||||
kprintf(" -- is guest\n");
|
kprintf(" -- is guest\n");
|
||||||
#endif
|
#endif
|
||||||
|
@ -574,13 +574,13 @@ InodeIdentifier VirtualFileSystem::resolvePath(const String& path, int& error, I
|
||||||
return inode;
|
return inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualFileSystem::Node::retain()
|
void Vnode::retain()
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler; // FIXME: Make a Retainable with atomic retain count instead.
|
InterruptDisabler disabler; // FIXME: Make a Retainable with atomic retain count instead.
|
||||||
++retainCount;
|
++retainCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualFileSystem::Node::release()
|
void Vnode::release()
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler; // FIXME: Make a Retainable with atomic retain count instead.
|
InterruptDisabler disabler; // FIXME: Make a Retainable with atomic retain count instead.
|
||||||
ASSERT(retainCount);
|
ASSERT(retainCount);
|
||||||
|
@ -589,7 +589,7 @@ void VirtualFileSystem::Node::release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const InodeMetadata& VirtualFileSystem::Node::metadata() const
|
const InodeMetadata& Vnode::metadata() const
|
||||||
{
|
{
|
||||||
if (m_core_inode)
|
if (m_core_inode)
|
||||||
return m_core_inode->metadata();
|
return m_core_inode->metadata();
|
||||||
|
@ -598,19 +598,19 @@ const InodeMetadata& VirtualFileSystem::Node::metadata() const
|
||||||
return m_cachedMetadata;
|
return m_cachedMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualFileSystem::Mount::Mount(InodeIdentifier host, RetainPtr<FileSystem>&& guestFileSystem)
|
VFS::Mount::Mount(InodeIdentifier host, RetainPtr<FileSystem>&& guestFileSystem)
|
||||||
: m_host(host)
|
: m_host(host)
|
||||||
, m_guest(guestFileSystem->rootInode())
|
, m_guest(guestFileSystem->rootInode())
|
||||||
, m_fileSystem(move(guestFileSystem))
|
, m_fileSystem(move(guestFileSystem))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualFileSystem::registerCharacterDevice(CharacterDevice& device)
|
void VFS::registerCharacterDevice(CharacterDevice& device)
|
||||||
{
|
{
|
||||||
m_characterDevices.set(encodedDevice(device.major(), device.minor()), &device);
|
m_characterDevices.set(encodedDevice(device.major(), device.minor()), &device);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualFileSystem::forEachMount(Function<void(const Mount&)> callback) const
|
void VFS::forEachMount(Function<void(const Mount&)> callback) const
|
||||||
{
|
{
|
||||||
for (auto& mount : m_mounts) {
|
for (auto& mount : m_mounts) {
|
||||||
callback(*mount);
|
callback(*mount);
|
||||||
|
|
|
@ -33,7 +33,46 @@ inline constexpr dword encodedDevice(unsigned major, unsigned minor)
|
||||||
return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
|
return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
class VirtualFileSystem {
|
class VFS;
|
||||||
|
|
||||||
|
class Vnode {
|
||||||
|
public:
|
||||||
|
InodeIdentifier inode;
|
||||||
|
const InodeMetadata& metadata() const;
|
||||||
|
|
||||||
|
bool inUse() const { return inode.isValid() || m_characterDevice; }
|
||||||
|
|
||||||
|
bool isCharacterDevice() const { return m_characterDevice; }
|
||||||
|
CharacterDevice* characterDevice() { return m_characterDevice; }
|
||||||
|
const CharacterDevice* characterDevice() const { return m_characterDevice; }
|
||||||
|
|
||||||
|
void retain();
|
||||||
|
void release();
|
||||||
|
|
||||||
|
FileSystem* fileSystem() { return inode.fileSystem(); }
|
||||||
|
const FileSystem* fileSystem() const { return inode.fileSystem(); }
|
||||||
|
|
||||||
|
VFS* vfs() { return m_vfs; }
|
||||||
|
const VFS* vfs() const { return m_vfs; }
|
||||||
|
|
||||||
|
void* vmo() { return m_vmo; }
|
||||||
|
void set_vmo(void* vmo) { m_vmo = vmo; }
|
||||||
|
|
||||||
|
unsigned retain_count() const { return retainCount; }
|
||||||
|
|
||||||
|
CoreInode* core_inode() { return m_core_inode.ptr(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class VFS;
|
||||||
|
VFS* m_vfs { nullptr };
|
||||||
|
unsigned retainCount { 0 };
|
||||||
|
CharacterDevice* m_characterDevice { nullptr };
|
||||||
|
mutable InodeMetadata m_cachedMetadata;
|
||||||
|
void* m_vmo { nullptr };
|
||||||
|
RetainPtr<CoreInode> m_core_inode;
|
||||||
|
};
|
||||||
|
|
||||||
|
class VFS {
|
||||||
AK_MAKE_ETERNAL
|
AK_MAKE_ETERNAL
|
||||||
friend ByteBuffer procfs$vnodes();
|
friend ByteBuffer procfs$vnodes();
|
||||||
public:
|
public:
|
||||||
|
@ -54,56 +93,22 @@ public:
|
||||||
RetainPtr<FileSystem> m_fileSystem;
|
RetainPtr<FileSystem> m_fileSystem;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Node {
|
static VFS& the() PURE;
|
||||||
InodeIdentifier inode;
|
|
||||||
const InodeMetadata& metadata() const;
|
|
||||||
|
|
||||||
bool inUse() const { return inode.isValid() || m_characterDevice; }
|
VFS();
|
||||||
|
~VFS();
|
||||||
bool isCharacterDevice() const { return m_characterDevice; }
|
|
||||||
CharacterDevice* characterDevice() { return m_characterDevice; }
|
|
||||||
const CharacterDevice* characterDevice() const { return m_characterDevice; }
|
|
||||||
|
|
||||||
void retain();
|
|
||||||
void release();
|
|
||||||
|
|
||||||
FileSystem* fileSystem() { return inode.fileSystem(); }
|
|
||||||
const FileSystem* fileSystem() const { return inode.fileSystem(); }
|
|
||||||
|
|
||||||
VirtualFileSystem* vfs() { return m_vfs; }
|
|
||||||
const VirtualFileSystem* vfs() const { return m_vfs; }
|
|
||||||
|
|
||||||
void* vmo() { return m_vmo; }
|
|
||||||
void set_vmo(void* vmo) { m_vmo = vmo; }
|
|
||||||
|
|
||||||
unsigned retain_count() const { return retainCount; }
|
|
||||||
|
|
||||||
CoreInode* core_inode() { return m_core_inode.ptr(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class VirtualFileSystem;
|
|
||||||
VirtualFileSystem* m_vfs { nullptr };
|
|
||||||
unsigned retainCount { 0 };
|
|
||||||
CharacterDevice* m_characterDevice { nullptr };
|
|
||||||
mutable InodeMetadata m_cachedMetadata;
|
|
||||||
void* m_vmo { nullptr };
|
|
||||||
RetainPtr<CoreInode> m_core_inode;
|
|
||||||
};
|
|
||||||
|
|
||||||
static VirtualFileSystem& the() PURE;
|
|
||||||
|
|
||||||
VirtualFileSystem();
|
|
||||||
~VirtualFileSystem();
|
|
||||||
|
|
||||||
|
#ifndef SERENITY
|
||||||
bool isDirectory(const String& path, InodeIdentifier base = InodeIdentifier());
|
bool isDirectory(const String& path, InodeIdentifier base = InodeIdentifier());
|
||||||
void listDirectory(const String& path, InodeIdentifier base);
|
void listDirectory(const String& path, InodeIdentifier base);
|
||||||
void listDirectoryRecursively(const String& path, InodeIdentifier base);
|
void listDirectoryRecursively(const String& path, InodeIdentifier base);
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned maxNodeCount() const { return m_maxNodeCount; }
|
unsigned maxNodeCount() const { return m_maxNodeCount; }
|
||||||
unsigned allocatedNodeCount() const { return m_maxNodeCount - m_nodeFreeList.size(); }
|
unsigned allocatedNodeCount() const { return m_maxNodeCount - m_nodeFreeList.size(); }
|
||||||
|
|
||||||
Node* root() { return m_rootNode.ptr(); }
|
Vnode* root() { return m_rootNode.ptr(); }
|
||||||
const Node* root() const { return m_rootNode.ptr(); }
|
const Vnode* root() const { return m_rootNode.ptr(); }
|
||||||
|
|
||||||
bool mountRoot(RetainPtr<FileSystem>&&);
|
bool mountRoot(RetainPtr<FileSystem>&&);
|
||||||
bool mount(RetainPtr<FileSystem>&&, const String& path);
|
bool mount(RetainPtr<FileSystem>&&, const String& path);
|
||||||
|
@ -113,8 +118,6 @@ public:
|
||||||
RetainPtr<FileDescriptor> create(const String& path, InodeIdentifier base = InodeIdentifier());
|
RetainPtr<FileDescriptor> create(const String& path, InodeIdentifier base = InodeIdentifier());
|
||||||
RetainPtr<FileDescriptor> mkdir(const String& path, InodeIdentifier base = InodeIdentifier());
|
RetainPtr<FileDescriptor> mkdir(const String& path, InodeIdentifier base = InodeIdentifier());
|
||||||
|
|
||||||
bool isRoot(InodeIdentifier) const;
|
|
||||||
|
|
||||||
bool touch(const String&path);
|
bool touch(const String&path);
|
||||||
|
|
||||||
void registerCharacterDevice(CharacterDevice&);
|
void registerCharacterDevice(CharacterDevice&);
|
||||||
|
@ -126,36 +129,39 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class FileDescriptor;
|
friend class FileDescriptor;
|
||||||
|
friend class Vnode;
|
||||||
|
|
||||||
RetainPtr<CoreInode> get_inode(InodeIdentifier);
|
RetainPtr<CoreInode> get_inode(InodeIdentifier);
|
||||||
|
|
||||||
|
bool is_vfs_root(InodeIdentifier) const;
|
||||||
|
|
||||||
void enumerateDirectoryInode(InodeIdentifier, Function<bool(const FileSystem::DirectoryEntry&)>);
|
void enumerateDirectoryInode(InodeIdentifier, Function<bool(const FileSystem::DirectoryEntry&)>);
|
||||||
InodeIdentifier resolve_path(const String& path, int& error, CoreInode& base, int options = 0);
|
InodeIdentifier resolve_path(const String& path, int& error, CoreInode& base, int options = 0);
|
||||||
InodeIdentifier resolvePath(const String& path, int& error, InodeIdentifier base = InodeIdentifier(), int options = 0);
|
InodeIdentifier resolvePath(const String& path, int& error, InodeIdentifier base = InodeIdentifier(), int options = 0);
|
||||||
InodeIdentifier resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error);
|
InodeIdentifier resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error);
|
||||||
|
|
||||||
RetainPtr<Node> allocateNode();
|
RetainPtr<Vnode> allocateNode();
|
||||||
void freeNode(Node*);
|
void freeNode(Vnode*);
|
||||||
|
|
||||||
RetainPtr<Node> makeNode(InodeIdentifier);
|
RetainPtr<Vnode> makeNode(InodeIdentifier);
|
||||||
RetainPtr<Node> makeNode(CharacterDevice&);
|
RetainPtr<Vnode> makeNode(CharacterDevice&);
|
||||||
RetainPtr<Node> getOrCreateNode(InodeIdentifier);
|
RetainPtr<Vnode> getOrCreateNode(InodeIdentifier);
|
||||||
RetainPtr<Node> getOrCreateNode(CharacterDevice&);
|
RetainPtr<Vnode> getOrCreateNode(CharacterDevice&);
|
||||||
|
|
||||||
Mount* findMountForHost(InodeIdentifier);
|
Mount* findMountForHost(InodeIdentifier);
|
||||||
Mount* findMountForGuest(InodeIdentifier);
|
Mount* findMountForGuest(InodeIdentifier);
|
||||||
|
|
||||||
HashMap<InodeIdentifier, Node*> m_inode2vnode;
|
HashMap<InodeIdentifier, Vnode*> m_inode2vnode;
|
||||||
HashMap<dword, Node*> m_device2vnode;
|
HashMap<dword, Vnode*> m_device2vnode;
|
||||||
|
|
||||||
Vector<OwnPtr<Mount>> m_mounts;
|
Vector<OwnPtr<Mount>> m_mounts;
|
||||||
|
|
||||||
unsigned m_maxNodeCount { 0 };
|
unsigned m_maxNodeCount { 0 };
|
||||||
Node* m_nodes { nullptr };
|
Vnode* m_nodes { nullptr };
|
||||||
|
|
||||||
Vector<Node*> m_nodeFreeList;
|
Vector<Vnode*> m_nodeFreeList;
|
||||||
|
|
||||||
RetainPtr<Node> m_rootNode;
|
RetainPtr<Vnode> m_rootNode;
|
||||||
|
|
||||||
HashMap<dword, CharacterDevice*> m_characterDevices;
|
HashMap<dword, CharacterDevice*> m_characterDevices;
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,9 +22,9 @@ int main(int c, char** v)
|
||||||
if (c >= 2)
|
if (c >= 2)
|
||||||
filename = v[1];
|
filename = v[1];
|
||||||
|
|
||||||
VirtualFileSystem::initializeGlobals();
|
VFS::initializeGlobals();
|
||||||
|
|
||||||
VirtualFileSystem vfs;
|
VFS vfs;
|
||||||
|
|
||||||
auto zero = make<ZeroDevice>();
|
auto zero = make<ZeroDevice>();
|
||||||
vfs.registerCharacterDevice(*zero);
|
vfs.registerCharacterDevice(*zero);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue