1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 15:07:45 +00:00

AK: Rename RetainPtr => RefPtr and Retained => NonnullRefPtr.

This commit is contained in:
Andreas Kling 2019-06-21 18:37:47 +02:00
parent 77b9fa89dd
commit 90b1354688
188 changed files with 562 additions and 562 deletions

View file

@ -26,9 +26,9 @@ Custody* Custody::get_if_cached(Custody* parent, const String& name)
return nullptr;
}
Retained<Custody> Custody::get_or_create(Custody* parent, const String& name, Inode& inode)
NonnullRefPtr<Custody> Custody::get_or_create(Custody* parent, const String& name, Inode& inode)
{
if (RetainPtr<Custody> cached_custody = get_if_cached(parent, name)) {
if (RefPtr<Custody> cached_custody = get_if_cached(parent, name)) {
if (&cached_custody->inode() != &inode) {
dbgprintf("WTF! cached custody for name '%s' has inode=%s, new inode=%s\n",
name.characters(),

View file

@ -13,8 +13,8 @@ class VFS;
class Custody : public RefCounted<Custody> {
public:
static Custody* get_if_cached(Custody* parent, const String& name);
static Retained<Custody> get_or_create(Custody* parent, const String& name, Inode&);
static Retained<Custody> create(Custody* parent, const String& name, Inode& inode)
static NonnullRefPtr<Custody> get_or_create(Custody* parent, const String& name, Inode&);
static NonnullRefPtr<Custody> create(Custody* parent, const String& name, Inode& inode)
{
return adopt(*new Custody(parent, name, inode));
}
@ -38,9 +38,9 @@ public:
private:
Custody(Custody* parent, const String& name, Inode&);
RetainPtr<Custody> m_parent;
RefPtr<Custody> m_parent;
String m_name;
Retained<Inode> m_inode;
NonnullRefPtr<Inode> m_inode;
bool m_deleted { false };
bool m_mounted_on { false };
};

View file

@ -11,7 +11,7 @@ DevPtsFS& DevPtsFS::the()
return *s_the;
}
Retained<DevPtsFS> DevPtsFS::create()
NonnullRefPtr<DevPtsFS> DevPtsFS::create()
{
return adopt(*new DevPtsFS);
}
@ -36,7 +36,7 @@ const char* DevPtsFS::class_name() const
return "DevPtsFS";
}
Retained<SynthFSInode> DevPtsFS::create_slave_pty_device_file(unsigned index)
NonnullRefPtr<SynthFSInode> DevPtsFS::create_slave_pty_device_file(unsigned index)
{
auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));

View file

@ -11,7 +11,7 @@ public:
[[gnu::pure]] static DevPtsFS& the();
virtual ~DevPtsFS() override;
static Retained<DevPtsFS> create();
static NonnullRefPtr<DevPtsFS> create();
virtual bool initialize() override;
virtual const char* class_name() const override;
@ -22,7 +22,7 @@ public:
private:
DevPtsFS();
Retained<SynthFSInode> create_slave_pty_device_file(unsigned index);
NonnullRefPtr<SynthFSInode> create_slave_pty_device_file(unsigned index);
HashTable<SlavePTY*> m_slave_ptys;
};

View file

@ -45,7 +45,7 @@ Lockable<InlineLRUCache<BlockIdentifier, CachedBlock>>& block_cache()
return *s_cache;
}
DiskBackedFS::DiskBackedFS(Retained<DiskDevice>&& device)
DiskBackedFS::DiskBackedFS(NonnullRefPtr<DiskDevice>&& device)
: m_device(move(device))
{
}

View file

@ -15,7 +15,7 @@ public:
virtual void flush_writes() override;
protected:
explicit DiskBackedFS(Retained<DiskDevice>&&);
explicit DiskBackedFS(NonnullRefPtr<DiskDevice>&&);
void set_block_size(unsigned);
@ -27,7 +27,7 @@ protected:
private:
int m_block_size { 0 };
Retained<DiskDevice> m_device;
NonnullRefPtr<DiskDevice> m_device;
HashMap<unsigned, ByteBuffer> m_write_cache;
};

View file

@ -31,12 +31,12 @@ static byte to_ext2_file_type(mode_t mode)
return EXT2_FT_UNKNOWN;
}
Retained<Ext2FS> Ext2FS::create(Retained<DiskDevice>&& device)
NonnullRefPtr<Ext2FS> Ext2FS::create(NonnullRefPtr<DiskDevice>&& device)
{
return adopt(*new Ext2FS(move(device)));
}
Ext2FS::Ext2FS(Retained<DiskDevice>&& device)
Ext2FS::Ext2FS(NonnullRefPtr<DiskDevice>&& device)
: DiskBackedFS(move(device))
{
}
@ -448,7 +448,7 @@ void Ext2FSInode::flush_metadata()
set_metadata_dirty(false);
}
RetainPtr<Inode> Ext2FS::get_inode(InodeIdentifier inode) const
RefPtr<Inode> Ext2FS::get_inode(InodeIdentifier inode) const
{
LOCKER(m_lock);
ASSERT(inode.fsid() == fsid());
@ -1085,7 +1085,7 @@ bool Ext2FS::set_block_allocation_state(BlockIndex block_index, bool new_state)
return true;
}
RetainPtr<Inode> Ext2FS::create_directory(InodeIdentifier parent_id, const String& name, mode_t mode, int& error)
RefPtr<Inode> Ext2FS::create_directory(InodeIdentifier parent_id, const String& name, mode_t mode, int& error)
{
LOCKER(m_lock);
ASSERT(parent_id.fsid() == fsid());
@ -1125,7 +1125,7 @@ RetainPtr<Inode> Ext2FS::create_directory(InodeIdentifier parent_id, const Strin
return inode;
}
RetainPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& name, mode_t mode, off_t size, dev_t dev, int& error)
RefPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& name, mode_t mode, off_t size, dev_t dev, int& error)
{
LOCKER(m_lock);
ASSERT(parent_id.fsid() == fsid());

View file

@ -60,7 +60,7 @@ class Ext2FS final : public DiskBackedFS {
friend class Ext2FSInode;
public:
static Retained<Ext2FS> create(Retained<DiskDevice>&&);
static NonnullRefPtr<Ext2FS> create(NonnullRefPtr<DiskDevice>&&);
virtual ~Ext2FS() override;
virtual bool initialize() override;
@ -73,7 +73,7 @@ private:
typedef unsigned BlockIndex;
typedef unsigned GroupIndex;
typedef unsigned InodeIndex;
explicit Ext2FS(Retained<DiskDevice>&&);
explicit Ext2FS(NonnullRefPtr<DiskDevice>&&);
const ext2_super_block& super_block() const;
const ext2_group_desc& group_descriptor(unsigned groupIndex) const;
@ -92,9 +92,9 @@ private:
virtual const char* class_name() const override;
virtual InodeIdentifier root_inode() const override;
virtual RetainPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, mode_t, off_t size, dev_t, int& error) override;
virtual RetainPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, mode_t, int& error) override;
virtual RetainPtr<Inode> get_inode(InodeIdentifier) const override;
virtual RefPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, mode_t, off_t size, dev_t, int& error) override;
virtual RefPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, mode_t, int& error) override;
virtual RefPtr<Inode> get_inode(InodeIdentifier) const override;
InodeIndex allocate_inode(GroupIndex preferred_group, off_t expected_size);
Vector<BlockIndex> allocate_blocks(GroupIndex, int count);
@ -126,7 +126,7 @@ private:
mutable ByteBuffer m_cached_super_block;
mutable ByteBuffer m_cached_group_descriptor_table;
mutable HashMap<BlockIndex, RetainPtr<Ext2FSInode>> m_inode_cache;
mutable HashMap<BlockIndex, RefPtr<Ext2FSInode>> m_inode_cache;
};
inline Ext2FS& Ext2FSInode::fs()

View file

@ -16,7 +16,7 @@ Lockable<HashTable<FIFO*>>& all_fifos()
return *s_table;
}
RetainPtr<FIFO> FIFO::from_fifo_id(dword id)
RefPtr<FIFO> FIFO::from_fifo_id(dword id)
{
auto* ptr = reinterpret_cast<FIFO*>(id);
LOCKER(all_fifos().lock());
@ -25,12 +25,12 @@ RetainPtr<FIFO> FIFO::from_fifo_id(dword id)
return ptr;
}
Retained<FIFO> FIFO::create(uid_t uid)
NonnullRefPtr<FIFO> FIFO::create(uid_t uid)
{
return adopt(*new FIFO(uid));
}
Retained<FileDescription> FIFO::open_direction(FIFO::Direction direction)
NonnullRefPtr<FileDescription> FIFO::open_direction(FIFO::Direction direction)
{
auto description = FileDescription::create(this);
attach(direction);

View file

@ -14,14 +14,14 @@ public:
Writer
};
static RetainPtr<FIFO> from_fifo_id(dword);
static RefPtr<FIFO> from_fifo_id(dword);
static Retained<FIFO> create(uid_t);
static NonnullRefPtr<FIFO> create(uid_t);
virtual ~FIFO() override;
uid_t uid() const { return m_uid; }
Retained<FileDescription> open_direction(Direction);
NonnullRefPtr<FileDescription> open_direction(Direction);
void attach(Direction);
void detach(Direction);

View file

@ -15,19 +15,19 @@
#include <Kernel/VM/MemoryManager.h>
#include <LibC/errno_numbers.h>
Retained<FileDescription> FileDescription::create(RetainPtr<Custody>&& custody)
NonnullRefPtr<FileDescription> FileDescription::create(RefPtr<Custody>&& custody)
{
auto description = adopt(*new FileDescription(InodeFile::create(custody->inode())));
description->m_custody = move(custody);
return description;
}
Retained<FileDescription> FileDescription::create(RetainPtr<File>&& file, SocketRole role)
NonnullRefPtr<FileDescription> FileDescription::create(RefPtr<File>&& file, SocketRole role)
{
return adopt(*new FileDescription(move(file), role));
}
FileDescription::FileDescription(RetainPtr<File>&& file, SocketRole role)
FileDescription::FileDescription(RefPtr<File>&& file, SocketRole role)
: m_file(move(file))
{
if (m_file->is_inode())
@ -58,9 +58,9 @@ void FileDescription::set_socket_role(SocketRole role)
socket()->attach(*this);
}
Retained<FileDescription> FileDescription::clone()
NonnullRefPtr<FileDescription> FileDescription::clone()
{
RetainPtr<FileDescription> description;
RefPtr<FileDescription> description;
if (is_fifo()) {
description = fifo()->open_direction(m_fifo_direction);
} else {

View file

@ -21,11 +21,11 @@ class SharedMemory;
class FileDescription : public RefCounted<FileDescription> {
public:
static Retained<FileDescription> create(RetainPtr<Custody>&&);
static Retained<FileDescription> create(RetainPtr<File>&&, SocketRole = SocketRole::None);
static NonnullRefPtr<FileDescription> create(RefPtr<Custody>&&);
static NonnullRefPtr<FileDescription> create(RefPtr<File>&&, SocketRole = SocketRole::None);
~FileDescription();
Retained<FileDescription> clone();
NonnullRefPtr<FileDescription> clone();
int close();
@ -92,7 +92,7 @@ public:
ByteBuffer& generator_cache() { return m_generator_cache; }
void set_original_inode(Badge<VFS>, Retained<Inode>&& inode) { m_inode = move(inode); }
void set_original_inode(Badge<VFS>, NonnullRefPtr<Inode>&& inode) { m_inode = move(inode); }
SocketRole socket_role() const { return m_socket_role; }
void set_socket_role(SocketRole);
@ -105,12 +105,12 @@ public:
private:
friend class VFS;
FileDescription(RetainPtr<File>&&, SocketRole = SocketRole::None);
FileDescription(RefPtr<File>&&, SocketRole = SocketRole::None);
FileDescription(FIFO&, FIFO::Direction);
RetainPtr<Custody> m_custody;
RetainPtr<Inode> m_inode;
RetainPtr<File> m_file;
RefPtr<Custody> m_custody;
RefPtr<Inode> m_inode;
RefPtr<File> m_file;
off_t m_current_offset { 0 };

View file

@ -58,7 +58,7 @@ void FS::sync()
{
Inode::sync();
Vector<Retained<FS>, 32> fses;
Vector<NonnullRefPtr<FS>, 32> fses;
{
InterruptDisabler disabler;
for (auto& it : all_fses())

View file

@ -54,10 +54,10 @@ public:
byte file_type { 0 };
};
virtual RetainPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, mode_t, off_t size, dev_t, int& error) = 0;
virtual RetainPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, mode_t, int& error) = 0;
virtual RefPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, mode_t, off_t size, dev_t, int& error) = 0;
virtual RefPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, mode_t, int& error) = 0;
virtual RetainPtr<Inode> get_inode(InodeIdentifier) const = 0;
virtual RefPtr<Inode> get_inode(InodeIdentifier) const = 0;
virtual void flush_writes() {}

View file

@ -13,7 +13,7 @@ HashTable<Inode*>& all_inodes()
void Inode::sync()
{
Vector<Retained<Inode>, 32> inodes;
Vector<NonnullRefPtr<Inode>, 32> inodes;
{
InterruptDisabler disabler;
for (auto* inode : all_inodes()) {

View file

@ -85,6 +85,6 @@ private:
FS& m_fs;
unsigned m_index { 0 };
WeakPtr<VMObject> m_vmo;
RetainPtr<LocalSocket> m_socket;
RefPtr<LocalSocket> m_socket;
bool m_metadata_dirty { false };
};

View file

@ -4,7 +4,7 @@
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Process.h>
InodeFile::InodeFile(Retained<Inode>&& inode)
InodeFile::InodeFile(NonnullRefPtr<Inode>&& inode)
: m_inode(move(inode))
{
}

View file

@ -6,7 +6,7 @@ class Inode;
class InodeFile final : public File {
public:
static Retained<InodeFile> create(Retained<Inode>&& inode)
static NonnullRefPtr<InodeFile> create(NonnullRefPtr<Inode>&& inode)
{
return adopt(*new InodeFile(move(inode)));
}
@ -33,6 +33,6 @@ public:
virtual bool is_inode() const override { return true; }
private:
explicit InodeFile(Retained<Inode>&&);
Retained<Inode> m_inode;
explicit InodeFile(NonnullRefPtr<Inode>&&);
NonnullRefPtr<Inode> m_inode;
};

View file

@ -174,7 +174,7 @@ ProcFS& ProcFS::the()
return *s_the;
}
Retained<ProcFS> ProcFS::create()
NonnullRefPtr<ProcFS> ProcFS::create()
{
return adopt(*new ProcFS);
}
@ -614,7 +614,7 @@ ByteBuffer procfs$inodes(InodeIdentifier)
extern HashTable<Inode*>& all_inodes();
StringBuilder builder;
for (auto it : all_inodes()) {
RetainPtr<Inode> inode = *it;
RefPtr<Inode> inode = *it;
builder.appendf("Inode{K%x} %02u:%08u (%u)\n", inode.ptr(), inode->fsid(), inode->index(), inode->ref_count());
}
return builder.to_byte_buffer();
@ -747,13 +747,13 @@ const char* ProcFS::class_name() const
return "ProcFS";
}
RetainPtr<Inode> ProcFS::create_inode(InodeIdentifier, const String&, mode_t, off_t, dev_t, int&)
RefPtr<Inode> ProcFS::create_inode(InodeIdentifier, const String&, mode_t, off_t, dev_t, int&)
{
kprintf("FIXME: Implement ProcFS::create_inode()?\n");
return {};
}
RetainPtr<Inode> ProcFS::create_directory(InodeIdentifier, const String&, mode_t, int& error)
RefPtr<Inode> ProcFS::create_directory(InodeIdentifier, const String&, mode_t, int& error)
{
error = -EROFS;
return nullptr;
@ -764,7 +764,7 @@ InodeIdentifier ProcFS::root_inode() const
return { fsid(), FI_Root };
}
RetainPtr<Inode> ProcFS::get_inode(InodeIdentifier inode_id) const
RefPtr<Inode> ProcFS::get_inode(InodeIdentifier inode_id) const
{
#ifdef PROCFS_DEBUG
dbgprintf("ProcFS::get_inode(%u)\n", inode_id.index());

View file

@ -16,16 +16,16 @@ public:
[[gnu::pure]] static ProcFS& the();
virtual ~ProcFS() override;
static Retained<ProcFS> create();
static NonnullRefPtr<ProcFS> create();
virtual bool initialize() override;
virtual const char* class_name() const override;
virtual InodeIdentifier root_inode() const override;
virtual RetainPtr<Inode> get_inode(InodeIdentifier) const override;
virtual RefPtr<Inode> get_inode(InodeIdentifier) const override;
virtual RetainPtr<Inode> create_inode(InodeIdentifier parent_id, const String& name, mode_t, off_t size, dev_t, int& error) override;
virtual RetainPtr<Inode> create_directory(InodeIdentifier parent_id, const String& name, mode_t, int& error) override;
virtual RefPtr<Inode> create_inode(InodeIdentifier parent_id, const String& name, mode_t, off_t size, dev_t, int& error) override;
virtual RefPtr<Inode> create_directory(InodeIdentifier parent_id, const String& name, mode_t, int& error) override;
void add_sys_file(String&&, Function<ByteBuffer(ProcFSInode&)>&& read_callback, Function<ssize_t(ProcFSInode&, const ByteBuffer&)>&& write_callback);
void add_sys_bool(String&&, Lockable<bool>&, Function<void()>&& notify_callback = nullptr);
@ -36,7 +36,7 @@ private:
struct ProcFSDirectoryEntry {
ProcFSDirectoryEntry() {}
ProcFSDirectoryEntry(const char* a_name, unsigned a_proc_file_type, Function<ByteBuffer(InodeIdentifier)>&& a_read_callback = nullptr, Function<ssize_t(InodeIdentifier, const ByteBuffer&)>&& a_write_callback = nullptr, RetainPtr<ProcFSInode>&& a_inode = nullptr)
ProcFSDirectoryEntry(const char* a_name, unsigned a_proc_file_type, Function<ByteBuffer(InodeIdentifier)>&& a_read_callback = nullptr, Function<ssize_t(InodeIdentifier, const ByteBuffer&)>&& a_write_callback = nullptr, RefPtr<ProcFSInode>&& a_inode = nullptr)
: name(a_name)
, proc_file_type(a_proc_file_type)
, read_callback(move(a_read_callback))
@ -49,7 +49,7 @@ private:
unsigned proc_file_type { 0 };
Function<ByteBuffer(InodeIdentifier)> read_callback;
Function<ssize_t(InodeIdentifier, const ByteBuffer&)> write_callback;
RetainPtr<ProcFSInode> inode;
RefPtr<ProcFSInode> inode;
InodeIdentifier identifier(unsigned fsid) const;
};
@ -60,7 +60,7 @@ private:
mutable Lock m_inodes_lock;
mutable HashMap<unsigned, ProcFSInode*> m_inodes;
RetainPtr<ProcFSInode> m_root_inode;
RefPtr<ProcFSInode> m_root_inode;
Lockable<bool> m_kmalloc_stack_helper;
};

View file

@ -5,7 +5,7 @@
//#define SYNTHFS_DEBUG
Retained<SynthFS> SynthFS::create()
NonnullRefPtr<SynthFS> SynthFS::create()
{
return adopt(*new SynthFS);
}
@ -33,7 +33,7 @@ bool SynthFS::initialize()
return true;
}
Retained<SynthFSInode> SynthFS::create_directory(String&& name)
NonnullRefPtr<SynthFSInode> SynthFS::create_directory(String&& name)
{
auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
file->m_name = move(name);
@ -45,7 +45,7 @@ Retained<SynthFSInode> SynthFS::create_directory(String&& name)
return file;
}
Retained<SynthFSInode> SynthFS::create_text_file(String&& name, ByteBuffer&& contents, mode_t mode)
NonnullRefPtr<SynthFSInode> SynthFS::create_text_file(String&& name, ByteBuffer&& contents, mode_t mode)
{
auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
file->m_data = contents;
@ -58,7 +58,7 @@ Retained<SynthFSInode> SynthFS::create_text_file(String&& name, ByteBuffer&& con
return file;
}
Retained<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&& generator, mode_t mode)
NonnullRefPtr<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&& generator, mode_t mode)
{
auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
file->m_generator = move(generator);
@ -71,7 +71,7 @@ Retained<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<By
return file;
}
Retained<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&& read_callback, Function<ssize_t(SynthFSInode&, const ByteBuffer&)>&& write_callback, mode_t mode)
NonnullRefPtr<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&& read_callback, Function<ssize_t(SynthFSInode&, const ByteBuffer&)>&& write_callback, mode_t mode)
{
auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
file->m_generator = move(read_callback);
@ -85,7 +85,7 @@ Retained<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<By
return file;
}
InodeIdentifier SynthFS::add_file(RetainPtr<SynthFSInode>&& file, InodeIndex parent)
InodeIdentifier SynthFS::add_file(RefPtr<SynthFSInode>&& file, InodeIndex parent)
{
LOCKER(m_lock);
ASSERT(file);
@ -138,7 +138,7 @@ InodeIdentifier SynthFS::root_inode() const
return { fsid(), 1 };
}
RetainPtr<Inode> SynthFS::create_inode(InodeIdentifier parentInode, const String& name, mode_t mode, off_t size, dev_t, int& error)
RefPtr<Inode> SynthFS::create_inode(InodeIdentifier parentInode, const String& name, mode_t mode, off_t size, dev_t, int& error)
{
(void)parentInode;
(void)name;
@ -149,7 +149,7 @@ RetainPtr<Inode> SynthFS::create_inode(InodeIdentifier parentInode, const String
return {};
}
RetainPtr<Inode> SynthFS::create_directory(InodeIdentifier, const String&, mode_t, int& error)
RefPtr<Inode> SynthFS::create_directory(InodeIdentifier, const String&, mode_t, int& error)
{
error = -EROFS;
return nullptr;
@ -161,7 +161,7 @@ auto SynthFS::generate_inode_index() -> InodeIndex
return m_next_inode_index++;
}
RetainPtr<Inode> SynthFS::get_inode(InodeIdentifier inode) const
RefPtr<Inode> SynthFS::get_inode(InodeIdentifier inode) const
{
LOCKER(m_lock);
auto it = m_inodes.find(inode.index());

View file

@ -10,14 +10,14 @@ class SynthFSInode;
class SynthFS : public FS {
public:
virtual ~SynthFS() override;
static Retained<SynthFS> create();
static NonnullRefPtr<SynthFS> create();
virtual bool initialize() override;
virtual const char* class_name() const override;
virtual InodeIdentifier root_inode() const override;
virtual RetainPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, mode_t, off_t size, dev_t, int& error) override;
virtual RetainPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, mode_t, int& error) override;
virtual RetainPtr<Inode> get_inode(InodeIdentifier) const override;
virtual RefPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, mode_t, off_t size, dev_t, int& error) override;
virtual RefPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, mode_t, int& error) override;
virtual RefPtr<Inode> get_inode(InodeIdentifier) const override;
protected:
typedef unsigned InodeIndex;
@ -27,17 +27,17 @@ protected:
SynthFS();
Retained<SynthFSInode> create_directory(String&& name);
Retained<SynthFSInode> create_text_file(String&& name, ByteBuffer&&, mode_t = 0010644);
Retained<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&&, mode_t = 0100644);
Retained<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&&, Function<ssize_t(SynthFSInode&, const ByteBuffer&)>&&, mode_t = 0100644);
NonnullRefPtr<SynthFSInode> create_directory(String&& name);
NonnullRefPtr<SynthFSInode> create_text_file(String&& name, ByteBuffer&&, mode_t = 0010644);
NonnullRefPtr<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&&, mode_t = 0100644);
NonnullRefPtr<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&&, Function<ssize_t(SynthFSInode&, const ByteBuffer&)>&&, mode_t = 0100644);
InodeIdentifier add_file(RetainPtr<SynthFSInode>&&, InodeIndex parent = RootInodeIndex);
InodeIdentifier add_file(RefPtr<SynthFSInode>&&, InodeIndex parent = RootInodeIndex);
bool remove_file(InodeIndex);
private:
InodeIndex m_next_inode_index { 2 };
HashMap<InodeIndex, RetainPtr<SynthFSInode>> m_inodes;
HashMap<InodeIndex, RefPtr<SynthFSInode>> m_inodes;
};
struct SynthFSInodeCustomData {

View file

@ -36,7 +36,7 @@ InodeIdentifier VFS::root_inode_id() const
return m_root_inode->identifier();
}
bool VFS::mount(Retained<FS>&& file_system, StringView path)
bool VFS::mount(NonnullRefPtr<FS>&& file_system, StringView path)
{
auto result = resolve_path(path, root_custody());
if (result.is_error()) {
@ -53,7 +53,7 @@ bool VFS::mount(Retained<FS>&& file_system, StringView path)
return true;
}
bool VFS::mount_root(Retained<FS>&& file_system)
bool VFS::mount_root(NonnullRefPtr<FS>&& file_system)
{
if (m_root_inode) {
kprintf("VFS: mount_root can't mount another root\n");
@ -149,9 +149,9 @@ KResult VFS::stat(StringView path, int options, Custody& base, struct stat& stat
return custody_or_error.value()->inode().metadata().stat(statbuf);
}
KResultOr<Retained<FileDescription>> VFS::open(StringView path, int options, mode_t mode, Custody& base)
KResultOr<NonnullRefPtr<FileDescription>> VFS::open(StringView path, int options, mode_t mode, Custody& base)
{
RetainPtr<Custody> parent_custody;
RefPtr<Custody> parent_custody;
auto custody_or_error = resolve_path(path, base, &parent_custody, options);
if (options & O_CREAT) {
if (!parent_custody)
@ -208,7 +208,7 @@ KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
if (!is_regular_file(mode) && !is_block_device(mode) && !is_character_device(mode) && !is_fifo(mode) && !is_socket(mode))
return KResult(-EINVAL);
RetainPtr<Custody> parent_custody;
RefPtr<Custody> parent_custody;
auto existing_file_or_error = resolve_path(path, base, &parent_custody);
if (!existing_file_or_error.is_error())
return KResult(-EEXIST);
@ -230,7 +230,7 @@ KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
return KSuccess;
}
KResultOr<Retained<FileDescription>> VFS::create(StringView path, int options, mode_t mode, Custody& parent_custody)
KResultOr<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int options, mode_t mode, Custody& parent_custody)
{
(void)options;
@ -255,7 +255,7 @@ KResultOr<Retained<FileDescription>> VFS::create(StringView path, int options, m
KResult VFS::mkdir(StringView path, mode_t mode, Custody& base)
{
RetainPtr<Custody> parent_custody;
RefPtr<Custody> parent_custody;
auto result = resolve_path(path, base, &parent_custody);
if (!result.is_error())
return KResult(-EEXIST);
@ -300,7 +300,7 @@ KResult VFS::access(StringView path, int mode, Custody& base)
return KSuccess;
}
KResultOr<Retained<Custody>> VFS::open_directory(StringView path, Custody& base)
KResultOr<NonnullRefPtr<Custody>> VFS::open_directory(StringView path, Custody& base)
{
auto inode_or_error = resolve_path(path, base);
if (inode_or_error.is_error())
@ -339,14 +339,14 @@ KResult VFS::chmod(StringView path, mode_t mode, Custody& base)
KResult VFS::rename(StringView old_path, StringView new_path, Custody& base)
{
RetainPtr<Custody> old_parent_custody;
RefPtr<Custody> old_parent_custody;
auto old_custody_or_error = resolve_path(old_path, base, &old_parent_custody);
if (old_custody_or_error.is_error())
return old_custody_or_error.error();
auto& old_custody = *old_custody_or_error.value();
auto& old_inode = old_custody.inode();
RetainPtr<Custody> new_parent_custody;
RefPtr<Custody> new_parent_custody;
auto new_custody_or_error = resolve_path(new_path, base, &new_parent_custody);
if (new_custody_or_error.is_error()) {
if (new_custody_or_error.error() != -ENOENT)
@ -445,7 +445,7 @@ KResult VFS::link(StringView old_path, StringView new_path, Custody& base)
auto& old_custody = *old_custody_or_error.value();
auto& old_inode = old_custody.inode();
RetainPtr<Custody> parent_custody;
RefPtr<Custody> parent_custody;
auto new_custody_or_error = resolve_path(new_path, base, &parent_custody);
if (!new_custody_or_error.is_error())
return KResult(-EEXIST);
@ -469,7 +469,7 @@ KResult VFS::link(StringView old_path, StringView new_path, Custody& base)
KResult VFS::unlink(StringView path, Custody& base)
{
RetainPtr<Custody> parent_custody;
RefPtr<Custody> parent_custody;
auto custody_or_error = resolve_path(path, base, &parent_custody);
if (custody_or_error.is_error())
return custody_or_error.error();
@ -498,7 +498,7 @@ KResult VFS::unlink(StringView path, Custody& base)
KResult VFS::symlink(StringView target, StringView linkpath, Custody& base)
{
RetainPtr<Custody> parent_custody;
RefPtr<Custody> parent_custody;
auto existing_custody_or_error = resolve_path(linkpath, base, &parent_custody);
if (!existing_custody_or_error.is_error())
return KResult(-EEXIST);
@ -524,7 +524,7 @@ KResult VFS::symlink(StringView target, StringView linkpath, Custody& base)
KResult VFS::rmdir(StringView path, Custody& base)
{
RetainPtr<Custody> parent_custody;
RefPtr<Custody> parent_custody;
auto custody_or_error = resolve_path(path, base, &parent_custody);
if (custody_or_error.is_error())
return KResult(custody_or_error.error());
@ -559,14 +559,14 @@ KResult VFS::rmdir(StringView path, Custody& base)
return parent_inode.remove_child(FileSystemPath(path).basename());
}
RetainPtr<Inode> VFS::get_inode(InodeIdentifier inode_id)
RefPtr<Inode> VFS::get_inode(InodeIdentifier inode_id)
{
if (!inode_id.is_valid())
return nullptr;
return inode_id.fs()->get_inode(inode_id);
}
VFS::Mount::Mount(RetainPtr<Custody>&& host_custody, Retained<FS>&& guest_fs)
VFS::Mount::Mount(RefPtr<Custody>&& host_custody, NonnullRefPtr<FS>&& guest_fs)
: m_guest(guest_fs->root_inode())
, m_guest_fs(move(guest_fs))
, m_host_custody(move(host_custody))
@ -624,7 +624,7 @@ Custody& VFS::root_custody()
return *m_root_custody;
}
KResultOr<Retained<Custody>> VFS::resolve_path(StringView path, Custody& base, RetainPtr<Custody>* parent_custody, int options)
KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path(StringView path, Custody& base, RefPtr<Custody>* parent_custody, int options)
{
if (path.is_empty())
return KResult(-EINVAL);
@ -632,7 +632,7 @@ KResultOr<Retained<Custody>> VFS::resolve_path(StringView path, Custody& base, R
auto parts = path.split_view('/');
InodeIdentifier crumb_id;
Vector<Retained<Custody>, 32> custody_chain;
Vector<NonnullRefPtr<Custody>, 32> custody_chain;
if (path[0] == '/') {
custody_chain.append(root_custody());

View file

@ -35,7 +35,7 @@ class VFS {
public:
class Mount {
public:
Mount(RetainPtr<Custody>&&, Retained<FS>&&);
Mount(RefPtr<Custody>&&, NonnullRefPtr<FS>&&);
InodeIdentifier host() const;
InodeIdentifier guest() const { return m_guest; }
@ -47,8 +47,8 @@ public:
private:
InodeIdentifier m_host;
InodeIdentifier m_guest;
Retained<FS> m_guest_fs;
RetainPtr<Custody> m_host_custody;
NonnullRefPtr<FS> m_guest_fs;
RefPtr<Custody> m_host_custody;
};
[[gnu::pure]] static VFS& the();
@ -56,12 +56,12 @@ public:
VFS();
~VFS();
bool mount_root(Retained<FS>&&);
bool mount(Retained<FS>&&, StringView path);
bool mount_root(NonnullRefPtr<FS>&&);
bool mount(NonnullRefPtr<FS>&&, StringView path);
KResultOr<Retained<FileDescription>> open(RetainPtr<Device>&&, int options);
KResultOr<Retained<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base);
KResultOr<Retained<FileDescription>> create(StringView path, int options, mode_t mode, Custody& parent_custody);
KResultOr<NonnullRefPtr<FileDescription>> open(RefPtr<Device>&&, int options);
KResultOr<NonnullRefPtr<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base);
KResultOr<NonnullRefPtr<FileDescription>> create(StringView path, int options, mode_t mode, Custody& parent_custody);
KResult mkdir(StringView path, mode_t mode, Custody& base);
KResult link(StringView old_path, StringView new_path, Custody& base);
KResult unlink(StringView path, Custody& base);
@ -76,7 +76,7 @@ public:
KResult utime(StringView path, Custody& base, time_t atime, time_t mtime);
KResult rename(StringView oldpath, StringView newpath, Custody& base);
KResult mknod(StringView path, mode_t, dev_t, Custody& base);
KResultOr<Retained<Custody>> open_directory(StringView path, Custody& base);
KResultOr<NonnullRefPtr<Custody>> open_directory(StringView path, Custody& base);
void register_device(Badge<Device>, Device&);
void unregister_device(Badge<Device>, Device&);
@ -91,12 +91,12 @@ public:
Device* get_device(unsigned major, unsigned minor);
Custody& root_custody();
KResultOr<Retained<Custody>> resolve_path(StringView path, Custody& base, RetainPtr<Custody>* parent = nullptr, int options = 0);
KResultOr<NonnullRefPtr<Custody>> resolve_path(StringView path, Custody& base, RefPtr<Custody>* parent = nullptr, int options = 0);
private:
friend class FileDescription;
RetainPtr<Inode> get_inode(InodeIdentifier);
RefPtr<Inode> get_inode(InodeIdentifier);
bool is_vfs_root(InodeIdentifier) const;
@ -105,9 +105,9 @@ private:
Mount* find_mount_for_host(InodeIdentifier);
Mount* find_mount_for_guest(InodeIdentifier);
RetainPtr<Inode> m_root_inode;
RefPtr<Inode> m_root_inode;
Vector<OwnPtr<Mount>> m_mounts;
HashMap<dword, Device*> m_devices;
RetainPtr<Custody> m_root_custody;
RefPtr<Custody> m_root_custody;
};