mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:17:45 +00:00
Kernel: Move TmpFS towards OOM safety
This commit is contained in:
parent
8f9872581b
commit
23c021912e
2 changed files with 15 additions and 12 deletions
|
@ -11,9 +11,9 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
NonnullRefPtr<TmpFS> TmpFS::create()
|
RefPtr<TmpFS> TmpFS::create()
|
||||||
{
|
{
|
||||||
return adopt_ref(*new TmpFS);
|
return adopt_ref_if_nonnull(new TmpFS);
|
||||||
}
|
}
|
||||||
|
|
||||||
TmpFS::TmpFS()
|
TmpFS::TmpFS()
|
||||||
|
@ -27,7 +27,7 @@ TmpFS::~TmpFS()
|
||||||
bool TmpFS::initialize()
|
bool TmpFS::initialize()
|
||||||
{
|
{
|
||||||
m_root_inode = TmpFSInode::create_root(*this);
|
m_root_inode = TmpFSInode::create_root(*this);
|
||||||
return true;
|
return !m_root_inode.is_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<Inode> TmpFS::root_inode() const
|
NonnullRefPtr<Inode> TmpFS::root_inode() const
|
||||||
|
@ -84,14 +84,15 @@ TmpFSInode::~TmpFSInode()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent)
|
RefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent)
|
||||||
{
|
{
|
||||||
auto inode = adopt_ref(*new TmpFSInode(fs, metadata, parent));
|
auto inode = adopt_ref_if_nonnull(new TmpFSInode(fs, metadata, parent));
|
||||||
fs.register_inode(inode);
|
if (inode)
|
||||||
|
fs.register_inode(*inode);
|
||||||
return inode;
|
return inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<TmpFSInode> TmpFSInode::create_root(TmpFS& fs)
|
RefPtr<TmpFSInode> TmpFSInode::create_root(TmpFS& fs)
|
||||||
{
|
{
|
||||||
InodeMetadata metadata;
|
InodeMetadata metadata;
|
||||||
auto now = kgettimeofday().to_truncated_seconds();
|
auto now = kgettimeofday().to_truncated_seconds();
|
||||||
|
@ -270,10 +271,12 @@ KResultOr<NonnullRefPtr<Inode>> TmpFSInode::create_child(const String& name, mod
|
||||||
metadata.mtime = now;
|
metadata.mtime = now;
|
||||||
|
|
||||||
auto child = TmpFSInode::create(fs(), metadata, identifier());
|
auto child = TmpFSInode::create(fs(), metadata, identifier());
|
||||||
auto result = add_child(child, name, mode);
|
if (!child)
|
||||||
|
return ENOMEM;
|
||||||
|
auto result = add_child(*child, name, mode);
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result;
|
return result;
|
||||||
return child;
|
return child.release_nonnull();
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult TmpFSInode::add_child(Inode& child, const StringView& name, mode_t)
|
KResult TmpFSInode::add_child(Inode& child, const StringView& name, mode_t)
|
||||||
|
|
|
@ -21,7 +21,7 @@ class TmpFS final : public FS {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~TmpFS() override;
|
virtual ~TmpFS() override;
|
||||||
static NonnullRefPtr<TmpFS> create();
|
static RefPtr<TmpFS> create();
|
||||||
virtual bool initialize() override;
|
virtual bool initialize() override;
|
||||||
|
|
||||||
virtual const char* class_name() const override { return "TmpFS"; }
|
virtual const char* class_name() const override { return "TmpFS"; }
|
||||||
|
@ -74,8 +74,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TmpFSInode(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent);
|
TmpFSInode(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent);
|
||||||
static NonnullRefPtr<TmpFSInode> create(TmpFS&, InodeMetadata metadata, InodeIdentifier parent);
|
static RefPtr<TmpFSInode> create(TmpFS&, InodeMetadata metadata, InodeIdentifier parent);
|
||||||
static NonnullRefPtr<TmpFSInode> create_root(TmpFS&);
|
static RefPtr<TmpFSInode> create_root(TmpFS&);
|
||||||
|
|
||||||
void notify_watchers();
|
void notify_watchers();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue