mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:57:45 +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
|
@ -6,5 +6,5 @@ CharacterDevice::~CharacterDevice()
|
|||
|
||||
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"
|
||||
#endif
|
||||
|
||||
RetainPtr<FileDescriptor> FileDescriptor::create(RetainPtr<VirtualFileSystem::Node>&& vnode)
|
||||
RetainPtr<FileDescriptor> FileDescriptor::create(RetainPtr<Vnode>&& 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));
|
||||
}
|
||||
|
||||
FileDescriptor::FileDescriptor(RetainPtr<VirtualFileSystem::Node>&& vnode)
|
||||
FileDescriptor::FileDescriptor(RetainPtr<Vnode>&& vnode)
|
||||
: m_vnode(move(vnode))
|
||||
{
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ String FileDescriptor::absolute_path()
|
|||
return buf;
|
||||
}
|
||||
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)
|
||||
|
|
|
@ -13,7 +13,7 @@ class TTY;
|
|||
|
||||
class FileDescriptor : public Retainable<FileDescriptor> {
|
||||
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_reader(FIFO&);
|
||||
~FileDescriptor();
|
||||
|
@ -46,7 +46,7 @@ public:
|
|||
|
||||
InodeMetadata metadata() const { return m_vnode->metadata(); }
|
||||
|
||||
VirtualFileSystem::Node* vnode() { return m_vnode.ptr(); }
|
||||
Vnode* vnode() { return m_vnode.ptr(); }
|
||||
|
||||
#ifdef SERENITY
|
||||
bool isBlocking() const { return m_isBlocking; }
|
||||
|
@ -62,11 +62,11 @@ public:
|
|||
ByteBuffer& generatorCache() { return m_generatorCache; }
|
||||
|
||||
private:
|
||||
friend class VirtualFileSystem;
|
||||
explicit FileDescriptor(RetainPtr<VirtualFileSystem::Node>&&);
|
||||
friend class VFS;
|
||||
explicit FileDescriptor(RetainPtr<Vnode>&&);
|
||||
FileDescriptor(FIFO&, FIFO::Direction);
|
||||
|
||||
RetainPtr<VirtualFileSystem::Node> m_vnode;
|
||||
RetainPtr<Vnode> m_vnode;
|
||||
RetainPtr<CoreInode> m_inode;
|
||||
|
||||
Unix::off_t m_currentOffset { 0 };
|
||||
|
|
|
@ -65,7 +65,7 @@ private:
|
|||
};
|
||||
|
||||
class CoreInode : public Retainable<CoreInode> {
|
||||
friend class VirtualFileSystem;
|
||||
friend class VFS;
|
||||
public:
|
||||
virtual ~CoreInode();
|
||||
|
||||
|
|
|
@ -10,45 +10,45 @@
|
|||
|
||||
//#define VFS_DEBUG
|
||||
|
||||
static VirtualFileSystem* s_the;
|
||||
static VFS* s_the;
|
||||
|
||||
#ifndef SERENITY
|
||||
typedef int InterruptDisabler;
|
||||
#endif
|
||||
|
||||
VirtualFileSystem& VirtualFileSystem::the()
|
||||
VFS& VFS::the()
|
||||
{
|
||||
ASSERT(s_the);
|
||||
return *s_the;
|
||||
}
|
||||
|
||||
void VirtualFileSystem::initializeGlobals()
|
||||
void VFS::initializeGlobals()
|
||||
{
|
||||
s_the = nullptr;
|
||||
FileSystem::initializeGlobals();
|
||||
}
|
||||
|
||||
VirtualFileSystem::VirtualFileSystem()
|
||||
VFS::VFS()
|
||||
{
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf("VFS: Constructing VFS\n");
|
||||
#endif
|
||||
s_the = this;
|
||||
m_maxNodeCount = 16;
|
||||
m_nodes = reinterpret_cast<Node*>(kmalloc(sizeof(Node) * maxNodeCount()));
|
||||
memset(m_nodes, 0, sizeof(Node) * maxNodeCount());
|
||||
m_nodes = reinterpret_cast<Vnode*>(kmalloc(sizeof(Vnode) * maxNodeCount()));
|
||||
memset(m_nodes, 0, sizeof(Vnode) * maxNodeCount());
|
||||
|
||||
for (unsigned i = 0; i < m_maxNodeCount; ++i)
|
||||
m_nodeFreeList.append(&m_nodes[i]);
|
||||
}
|
||||
|
||||
VirtualFileSystem::~VirtualFileSystem()
|
||||
VFS::~VFS()
|
||||
{
|
||||
kprintf("VFS: ~VirtualFileSystem with %u nodes allocated\n", allocatedNodeCount());
|
||||
// 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();
|
||||
if (!metadata.isValid())
|
||||
|
@ -91,7 +91,7 @@ auto VirtualFileSystem::makeNode(InodeIdentifier inode) -> RetainPtr<Node>
|
|||
return vnode;
|
||||
}
|
||||
|
||||
auto VirtualFileSystem::makeNode(CharacterDevice& device) -> RetainPtr<Node>
|
||||
auto VFS::makeNode(CharacterDevice& device) -> RetainPtr<Vnode>
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
auto vnode = allocateNode();
|
||||
|
@ -107,7 +107,7 @@ auto VirtualFileSystem::makeNode(CharacterDevice& device) -> RetainPtr<Node>
|
|||
return vnode;
|
||||
}
|
||||
|
||||
auto VirtualFileSystem::getOrCreateNode(InodeIdentifier inode) -> RetainPtr<Node>
|
||||
auto VFS::getOrCreateNode(InodeIdentifier inode) -> RetainPtr<Vnode>
|
||||
{
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
|
@ -118,7 +118,7 @@ auto VirtualFileSystem::getOrCreateNode(InodeIdentifier inode) -> RetainPtr<Node
|
|||
return makeNode(inode);
|
||||
}
|
||||
|
||||
auto VirtualFileSystem::getOrCreateNode(CharacterDevice& device) -> RetainPtr<Node>
|
||||
auto VFS::getOrCreateNode(CharacterDevice& device) -> RetainPtr<Vnode>
|
||||
{
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
|
@ -129,7 +129,7 @@ auto VirtualFileSystem::getOrCreateNode(CharacterDevice& device) -> RetainPtr<No
|
|||
return makeNode(device);
|
||||
}
|
||||
|
||||
bool VirtualFileSystem::mount(RetainPtr<FileSystem>&& fileSystem, const String& path)
|
||||
bool VFS::mount(RetainPtr<FileSystem>&& fileSystem, const String& path)
|
||||
{
|
||||
ASSERT(fileSystem);
|
||||
int error;
|
||||
|
@ -146,7 +146,7 @@ bool VirtualFileSystem::mount(RetainPtr<FileSystem>&& fileSystem, const String&
|
|||
return true;
|
||||
}
|
||||
|
||||
bool VirtualFileSystem::mountRoot(RetainPtr<FileSystem>&& fileSystem)
|
||||
bool VFS::mountRoot(RetainPtr<FileSystem>&& fileSystem)
|
||||
{
|
||||
if (m_rootNode) {
|
||||
kprintf("VFS: mountRoot can't mount another root\n");
|
||||
|
@ -175,7 +175,7 @@ bool VirtualFileSystem::mountRoot(RetainPtr<FileSystem>&& fileSystem)
|
|||
return true;
|
||||
}
|
||||
|
||||
auto VirtualFileSystem::allocateNode() -> RetainPtr<Node>
|
||||
auto VFS::allocateNode() -> RetainPtr<Vnode>
|
||||
{
|
||||
if (m_nodeFreeList.isEmpty()) {
|
||||
kprintf("VFS: allocateNode has no nodes left\n");
|
||||
|
@ -189,7 +189,7 @@ auto VirtualFileSystem::allocateNode() -> RetainPtr<Node>
|
|||
return adopt(*node);
|
||||
}
|
||||
|
||||
void VirtualFileSystem::freeNode(Node* node)
|
||||
void VFS::freeNode(Vnode* node)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
ASSERT(node);
|
||||
|
@ -209,7 +209,7 @@ void VirtualFileSystem::freeNode(Node* node)
|
|||
}
|
||||
|
||||
#ifndef SERENITY
|
||||
bool VirtualFileSystem::isDirectory(const String& path, InodeIdentifier base)
|
||||
bool VFS::isDirectory(const String& path, InodeIdentifier base)
|
||||
{
|
||||
int error;
|
||||
auto inode = resolvePath(path, error, base);
|
||||
|
@ -220,7 +220,7 @@ bool VirtualFileSystem::isDirectory(const String& path, InodeIdentifier base)
|
|||
}
|
||||
#endif
|
||||
|
||||
auto VirtualFileSystem::findMountForHost(InodeIdentifier inode) -> Mount*
|
||||
auto VFS::findMountForHost(InodeIdentifier inode) -> Mount*
|
||||
{
|
||||
for (auto& mount : m_mounts) {
|
||||
if (mount->host() == inode)
|
||||
|
@ -229,7 +229,7 @@ auto VirtualFileSystem::findMountForHost(InodeIdentifier inode) -> Mount*
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
auto VirtualFileSystem::findMountForGuest(InodeIdentifier inode) -> Mount*
|
||||
auto VFS::findMountForGuest(InodeIdentifier inode) -> Mount*
|
||||
{
|
||||
for (auto& mount : m_mounts) {
|
||||
if (mount->guest() == inode)
|
||||
|
@ -238,12 +238,12 @@ auto VirtualFileSystem::findMountForGuest(InodeIdentifier inode) -> Mount*
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool VirtualFileSystem::isRoot(InodeIdentifier inode) const
|
||||
bool VFS::is_vfs_root(InodeIdentifier inode) const
|
||||
{
|
||||
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())
|
||||
return;
|
||||
|
@ -255,7 +255,7 @@ void VirtualFileSystem::enumerateDirectoryInode(InodeIdentifier directoryInode,
|
|||
else
|
||||
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);
|
||||
ASSERT(mount);
|
||||
resolvedInode = mount->host();
|
||||
|
@ -266,7 +266,7 @@ void VirtualFileSystem::enumerateDirectoryInode(InodeIdentifier directoryInode,
|
|||
}
|
||||
|
||||
#ifndef SERENITY
|
||||
void VirtualFileSystem::listDirectory(const String& path, InodeIdentifier base)
|
||||
void VFS::listDirectory(const String& path, InodeIdentifier base)
|
||||
{
|
||||
int error;
|
||||
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;
|
||||
auto directory = resolvePath(path, error, base);
|
||||
|
@ -392,7 +392,7 @@ void VirtualFileSystem::listDirectoryRecursively(const String& path, InodeIdenti
|
|||
}
|
||||
#endif
|
||||
|
||||
bool VirtualFileSystem::touch(const String& path)
|
||||
bool VFS::touch(const String& path)
|
||||
{
|
||||
int error;
|
||||
auto inode = resolvePath(path, error);
|
||||
|
@ -401,7 +401,7 @@ bool VirtualFileSystem::touch(const String& path)
|
|||
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.
|
||||
(void) options;
|
||||
|
@ -411,7 +411,7 @@ RetainPtr<FileDescriptor> VirtualFileSystem::open(CharacterDevice& device, int o
|
|||
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);
|
||||
if (!inode.isValid())
|
||||
|
@ -422,7 +422,7 @@ RetainPtr<FileDescriptor> VirtualFileSystem::open(const String& path, int& error
|
|||
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!
|
||||
(void) path;
|
||||
|
@ -431,7 +431,7 @@ RetainPtr<FileDescriptor> VirtualFileSystem::create(const String& path, InodeIde
|
|||
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!
|
||||
(void) path;
|
||||
|
@ -440,7 +440,7 @@ RetainPtr<FileDescriptor> VirtualFileSystem::mkdir(const String& path, InodeIden
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
InodeIdentifier VirtualFileSystem::resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error)
|
||||
InodeIdentifier VFS::resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error)
|
||||
{
|
||||
auto symlinkContents = symlinkInode.readEntireFile();
|
||||
if (!symlinkContents)
|
||||
|
@ -452,14 +452,14 @@ InodeIdentifier VirtualFileSystem::resolveSymbolicLink(InodeIdentifier base, Ino
|
|||
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())
|
||||
return nullptr;
|
||||
return inode_id.fileSystem()->get_inode(inode_id);
|
||||
}
|
||||
|
||||
String VirtualFileSystem::absolute_path(CoreInode& core_inode)
|
||||
String VFS::absolute_path(CoreInode& core_inode)
|
||||
{
|
||||
int error;
|
||||
Vector<InodeIdentifier> lineage;
|
||||
|
@ -494,7 +494,7 @@ String VirtualFileSystem::absolute_path(CoreInode& core_inode)
|
|||
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())
|
||||
return { };
|
||||
|
@ -545,7 +545,7 @@ InodeIdentifier VirtualFileSystem::resolvePath(const String& path, int& error, I
|
|||
#endif
|
||||
inode = mount->guest();
|
||||
}
|
||||
if (wasRootInodeAtHeadOfLoop && inode.isRootInode() && !isRoot(inode) && part == "..") {
|
||||
if (wasRootInodeAtHeadOfLoop && inode.isRootInode() && !is_vfs_root(inode) && part == "..") {
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf(" -- is guest\n");
|
||||
#endif
|
||||
|
@ -574,13 +574,13 @@ InodeIdentifier VirtualFileSystem::resolvePath(const String& path, int& error, I
|
|||
return inode;
|
||||
}
|
||||
|
||||
void VirtualFileSystem::Node::retain()
|
||||
void Vnode::retain()
|
||||
{
|
||||
InterruptDisabler disabler; // FIXME: Make a Retainable with atomic retain count instead.
|
||||
++retainCount;
|
||||
}
|
||||
|
||||
void VirtualFileSystem::Node::release()
|
||||
void Vnode::release()
|
||||
{
|
||||
InterruptDisabler disabler; // FIXME: Make a Retainable with atomic retain count instead.
|
||||
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)
|
||||
return m_core_inode->metadata();
|
||||
|
@ -598,19 +598,19 @@ const InodeMetadata& VirtualFileSystem::Node::metadata() const
|
|||
return m_cachedMetadata;
|
||||
}
|
||||
|
||||
VirtualFileSystem::Mount::Mount(InodeIdentifier host, RetainPtr<FileSystem>&& guestFileSystem)
|
||||
VFS::Mount::Mount(InodeIdentifier host, RetainPtr<FileSystem>&& guestFileSystem)
|
||||
: m_host(host)
|
||||
, m_guest(guestFileSystem->rootInode())
|
||||
, m_fileSystem(move(guestFileSystem))
|
||||
{
|
||||
}
|
||||
|
||||
void VirtualFileSystem::registerCharacterDevice(CharacterDevice& device)
|
||||
void VFS::registerCharacterDevice(CharacterDevice& 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) {
|
||||
callback(*mount);
|
||||
|
|
|
@ -33,7 +33,46 @@ inline constexpr dword encodedDevice(unsigned major, unsigned minor)
|
|||
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
|
||||
friend ByteBuffer procfs$vnodes();
|
||||
public:
|
||||
|
@ -54,56 +93,22 @@ public:
|
|||
RetainPtr<FileSystem> m_fileSystem;
|
||||
};
|
||||
|
||||
struct Node {
|
||||
InodeIdentifier inode;
|
||||
const InodeMetadata& metadata() const;
|
||||
static VFS& the() PURE;
|
||||
|
||||
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(); }
|
||||
|
||||
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();
|
||||
VFS();
|
||||
~VFS();
|
||||
|
||||
#ifndef SERENITY
|
||||
bool isDirectory(const String& path, InodeIdentifier base = InodeIdentifier());
|
||||
void listDirectory(const String& path, InodeIdentifier base);
|
||||
void listDirectoryRecursively(const String& path, InodeIdentifier base);
|
||||
#endif
|
||||
|
||||
unsigned maxNodeCount() const { return m_maxNodeCount; }
|
||||
unsigned allocatedNodeCount() const { return m_maxNodeCount - m_nodeFreeList.size(); }
|
||||
|
||||
Node* root() { return m_rootNode.ptr(); }
|
||||
const Node* root() const { return m_rootNode.ptr(); }
|
||||
Vnode* root() { return m_rootNode.ptr(); }
|
||||
const Vnode* root() const { return m_rootNode.ptr(); }
|
||||
|
||||
bool mountRoot(RetainPtr<FileSystem>&&);
|
||||
bool mount(RetainPtr<FileSystem>&&, const String& path);
|
||||
|
@ -113,8 +118,6 @@ public:
|
|||
RetainPtr<FileDescriptor> create(const String& path, InodeIdentifier base = InodeIdentifier());
|
||||
RetainPtr<FileDescriptor> mkdir(const String& path, InodeIdentifier base = InodeIdentifier());
|
||||
|
||||
bool isRoot(InodeIdentifier) const;
|
||||
|
||||
bool touch(const String&path);
|
||||
|
||||
void registerCharacterDevice(CharacterDevice&);
|
||||
|
@ -126,36 +129,39 @@ public:
|
|||
|
||||
private:
|
||||
friend class FileDescriptor;
|
||||
friend class Vnode;
|
||||
|
||||
RetainPtr<CoreInode> get_inode(InodeIdentifier);
|
||||
|
||||
bool is_vfs_root(InodeIdentifier) const;
|
||||
|
||||
void enumerateDirectoryInode(InodeIdentifier, Function<bool(const FileSystem::DirectoryEntry&)>);
|
||||
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 resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error);
|
||||
|
||||
RetainPtr<Node> allocateNode();
|
||||
void freeNode(Node*);
|
||||
RetainPtr<Vnode> allocateNode();
|
||||
void freeNode(Vnode*);
|
||||
|
||||
RetainPtr<Node> makeNode(InodeIdentifier);
|
||||
RetainPtr<Node> makeNode(CharacterDevice&);
|
||||
RetainPtr<Node> getOrCreateNode(InodeIdentifier);
|
||||
RetainPtr<Node> getOrCreateNode(CharacterDevice&);
|
||||
RetainPtr<Vnode> makeNode(InodeIdentifier);
|
||||
RetainPtr<Vnode> makeNode(CharacterDevice&);
|
||||
RetainPtr<Vnode> getOrCreateNode(InodeIdentifier);
|
||||
RetainPtr<Vnode> getOrCreateNode(CharacterDevice&);
|
||||
|
||||
Mount* findMountForHost(InodeIdentifier);
|
||||
Mount* findMountForGuest(InodeIdentifier);
|
||||
|
||||
HashMap<InodeIdentifier, Node*> m_inode2vnode;
|
||||
HashMap<dword, Node*> m_device2vnode;
|
||||
HashMap<InodeIdentifier, Vnode*> m_inode2vnode;
|
||||
HashMap<dword, Vnode*> m_device2vnode;
|
||||
|
||||
Vector<OwnPtr<Mount>> m_mounts;
|
||||
|
||||
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;
|
||||
};
|
||||
|
|
|
@ -22,9 +22,9 @@ int main(int c, char** v)
|
|||
if (c >= 2)
|
||||
filename = v[1];
|
||||
|
||||
VirtualFileSystem::initializeGlobals();
|
||||
VFS::initializeGlobals();
|
||||
|
||||
VirtualFileSystem vfs;
|
||||
VFS vfs;
|
||||
|
||||
auto zero = make<ZeroDevice>();
|
||||
vfs.registerCharacterDevice(*zero);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue