mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Kernel: Simplify FS::create_directory() a little bit
None of the clients of this function actually used the returned Inode, so it can simply return a KResult instead.
This commit is contained in:
parent
cb97ef5589
commit
8731682d0e
Notes:
sideshowbarker
2024-07-19 09:32:11 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/8731682d0ec
10 changed files with 22 additions and 25 deletions
|
@ -83,10 +83,9 @@ RefPtr<Inode> DevPtsFS::create_inode(InodeIdentifier, const String&, mode_t, off
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Inode> DevPtsFS::create_directory(InodeIdentifier, const String&, mode_t, uid_t, gid_t, int& error)
|
||||
KResult DevPtsFS::create_directory(InodeIdentifier, const String&, mode_t, uid_t, gid_t)
|
||||
{
|
||||
error = -EROFS;
|
||||
return nullptr;
|
||||
return KResult(-EROFS);
|
||||
}
|
||||
|
||||
RefPtr<Inode> DevPtsFS::get_inode(InodeIdentifier inode_id) const
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
|
||||
virtual InodeIdentifier root_inode() const override;
|
||||
virtual RefPtr<Inode> create_inode(InodeIdentifier parent_inode, const String& name, mode_t, off_t size, dev_t, uid_t, gid_t, int& error) override;
|
||||
virtual RefPtr<Inode> create_directory(InodeIdentifier parent_inode, const String& name, mode_t, uid_t, gid_t, int& error) override;
|
||||
virtual KResult create_directory(InodeIdentifier parent_inode, const String& name, mode_t, uid_t, gid_t) override;
|
||||
virtual RefPtr<Inode> get_inode(InodeIdentifier) const override;
|
||||
|
||||
static void register_slave_pty(SlavePTY&);
|
||||
|
|
|
@ -1347,7 +1347,7 @@ bool Ext2FS::set_block_allocation_state(BlockIndex block_index, bool new_state)
|
|||
return true;
|
||||
}
|
||||
|
||||
RefPtr<Inode> Ext2FS::create_directory(InodeIdentifier parent_id, const String& name, mode_t mode, uid_t uid, gid_t gid, int& error)
|
||||
KResult Ext2FS::create_directory(InodeIdentifier parent_id, const String& name, mode_t mode, uid_t uid, gid_t gid)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
ASSERT(parent_id.fsid() == fsid());
|
||||
|
@ -1359,9 +1359,10 @@ RefPtr<Inode> Ext2FS::create_directory(InodeIdentifier parent_id, const String&
|
|||
|
||||
// NOTE: When creating a new directory, make the size 1 block.
|
||||
// There's probably a better strategy here, but this works for now.
|
||||
int error;
|
||||
auto inode = create_inode(parent_id, name, mode, block_size(), 0, uid, gid, error);
|
||||
if (!inode)
|
||||
return nullptr;
|
||||
return KResult(error);
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
dbgprintf("Ext2FS: create_directory: created new directory named '%s' with inode %u\n", name.characters(), inode->identifier().index());
|
||||
|
@ -1375,9 +1376,9 @@ RefPtr<Inode> Ext2FS::create_directory(InodeIdentifier parent_id, const String&
|
|||
ASSERT(success);
|
||||
|
||||
auto parent_inode = get_inode(parent_id);
|
||||
error = parent_inode->increment_link_count();
|
||||
if (error < 0)
|
||||
return nullptr;
|
||||
auto result = parent_inode->increment_link_count();
|
||||
if (result.is_error())
|
||||
return result;
|
||||
|
||||
auto& bgd = const_cast<ext2_group_desc&>(group_descriptor(group_index_from_inode(inode->identifier().index())));
|
||||
++bgd.bg_used_dirs_count;
|
||||
|
@ -1387,8 +1388,7 @@ RefPtr<Inode> Ext2FS::create_directory(InodeIdentifier parent_id, const String&
|
|||
|
||||
m_block_group_descriptors_dirty = true;
|
||||
|
||||
error = 0;
|
||||
return inode;
|
||||
return KSuccess;
|
||||
}
|
||||
|
||||
RefPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& name, mode_t mode, off_t size, dev_t dev, uid_t uid, gid_t gid, int& error)
|
||||
|
|
|
@ -126,7 +126,7 @@ private:
|
|||
virtual const char* class_name() const override;
|
||||
virtual InodeIdentifier root_inode() const override;
|
||||
virtual RefPtr<Inode> create_inode(InodeIdentifier parent_inode, const String& name, mode_t, off_t size, dev_t, uid_t, gid_t, int& error) override;
|
||||
virtual RefPtr<Inode> create_directory(InodeIdentifier parent_inode, const String& name, mode_t, uid_t, gid_t, int& error) override;
|
||||
virtual KResult create_directory(InodeIdentifier parent_inode, const String& name, mode_t, uid_t, gid_t) override;
|
||||
virtual RefPtr<Inode> get_inode(InodeIdentifier) const override;
|
||||
virtual void flush_writes() override;
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ public:
|
|||
};
|
||||
|
||||
virtual RefPtr<Inode> create_inode(InodeIdentifier parent_inode, const String& name, mode_t, off_t size, dev_t, uid_t, gid_t, int& error) = 0;
|
||||
virtual RefPtr<Inode> create_directory(InodeIdentifier parent_inode, const String& name, mode_t, uid_t, gid_t, int& error) = 0;
|
||||
virtual KResult create_directory(InodeIdentifier parent_inode, const String& name, mode_t, uid_t, gid_t) = 0;
|
||||
|
||||
virtual RefPtr<Inode> get_inode(InodeIdentifier) const = 0;
|
||||
|
||||
|
|
|
@ -1041,10 +1041,9 @@ RefPtr<Inode> ProcFS::create_inode(InodeIdentifier, const String&, mode_t, off_t
|
|||
return {};
|
||||
}
|
||||
|
||||
RefPtr<Inode> ProcFS::create_directory(InodeIdentifier, const String&, mode_t, uid_t, gid_t, int& error)
|
||||
KResult ProcFS::create_directory(InodeIdentifier, const String&, mode_t, uid_t, gid_t)
|
||||
{
|
||||
error = -EROFS;
|
||||
return nullptr;
|
||||
return KResult(-EROFS);
|
||||
}
|
||||
|
||||
InodeIdentifier ProcFS::root_inode() const
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
virtual RefPtr<Inode> get_inode(InodeIdentifier) const override;
|
||||
|
||||
virtual RefPtr<Inode> create_inode(InodeIdentifier parent_id, const String& name, mode_t, off_t size, dev_t, uid_t, gid_t, int& error) override;
|
||||
virtual RefPtr<Inode> create_directory(InodeIdentifier parent_id, const String& name, mode_t, uid_t, gid_t, int& error) override;
|
||||
virtual KResult create_directory(InodeIdentifier parent_id, const String& name, mode_t, uid_t, gid_t) override;
|
||||
|
||||
static void add_sys_bool(String&&, Lockable<bool>&, Function<void()>&& notify_callback = nullptr);
|
||||
static void add_sys_string(String&&, Lockable<String>&, Function<void()>&& notify_callback = nullptr);
|
||||
|
|
|
@ -117,12 +117,15 @@ RefPtr<Inode> TmpFS::create_inode(InodeIdentifier parent_id, const String& name,
|
|||
return inode;
|
||||
}
|
||||
|
||||
RefPtr<Inode> TmpFS::create_directory(InodeIdentifier parent_id, const String& name, mode_t mode, uid_t uid, gid_t gid, int& error)
|
||||
KResult TmpFS::create_directory(InodeIdentifier parent_id, const String& name, mode_t mode, uid_t uid, gid_t gid)
|
||||
{
|
||||
// Ensure it's a directory.
|
||||
mode &= ~0170000;
|
||||
mode |= 0040000;
|
||||
return create_inode(parent_id, name, mode, 0, 0, uid, gid, error);
|
||||
int error;
|
||||
if (!create_inode(parent_id, name, mode, 0, 0, uid, gid, error))
|
||||
return KResult(error);
|
||||
return KSuccess;
|
||||
}
|
||||
|
||||
TmpFSInode::TmpFSInode(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent)
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
virtual RefPtr<Inode> get_inode(InodeIdentifier) const override;
|
||||
|
||||
virtual RefPtr<Inode> create_inode(InodeIdentifier parent_id, const String& name, mode_t, off_t size, dev_t, uid_t, gid_t, int& error) override;
|
||||
virtual RefPtr<Inode> create_directory(InodeIdentifier parent_id, const String& name, mode_t, uid_t, gid_t, int& error) override;
|
||||
virtual KResult create_directory(InodeIdentifier parent_id, const String& name, mode_t, uid_t, gid_t) override;
|
||||
|
||||
private:
|
||||
TmpFS();
|
||||
|
|
|
@ -355,11 +355,7 @@ KResult VFS::mkdir(StringView path, mode_t mode, Custody& base)
|
|||
#ifdef VFS_DEBUG
|
||||
dbg() << "VFS::mkdir: '" << p.basename() << "' in " << parent_inode.identifier();
|
||||
#endif
|
||||
int error;
|
||||
auto new_dir = parent_inode.fs().create_directory(parent_inode.identifier(), p.basename(), mode, current->process().uid(), current->process().gid(), error);
|
||||
if (new_dir)
|
||||
return KSuccess;
|
||||
return KResult(error);
|
||||
return parent_inode.fs().create_directory(parent_inode.identifier(), p.basename(), mode, current->process().uid(), current->process().gid());
|
||||
}
|
||||
|
||||
KResult VFS::access(StringView path, int mode, Custody& base)
|
||||
|
|
Loading…
Reference in a new issue