mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:57:35 +00:00
Convert some FS methods to return RetainPtr<Inode>.
This commit is contained in:
parent
1e07ead119
commit
673870563d
6 changed files with 25 additions and 25 deletions
|
@ -830,7 +830,7 @@ bool Ext2FS::set_block_allocation_state(GroupIndex group, BlockIndex bi, bool ne
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
InodeIdentifier Ext2FS::create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, int& error)
|
RetainPtr<Inode> Ext2FS::create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, int& error)
|
||||||
{
|
{
|
||||||
ASSERT(parentInode.fsid() == id());
|
ASSERT(parentInode.fsid() == id());
|
||||||
|
|
||||||
|
@ -842,22 +842,22 @@ InodeIdentifier Ext2FS::create_directory(InodeIdentifier parentInode, const Stri
|
||||||
// NOTE: When creating a new directory, make the size 1 block.
|
// NOTE: When creating a new directory, make the size 1 block.
|
||||||
// There's probably a better strategy here, but this works for now.
|
// There's probably a better strategy here, but this works for now.
|
||||||
auto inode = create_inode(parentInode, name, mode, blockSize(), error);
|
auto inode = create_inode(parentInode, name, mode, blockSize(), error);
|
||||||
if (!inode.is_valid())
|
if (!inode)
|
||||||
return { };
|
return { };
|
||||||
|
|
||||||
dbgprintf("Ext2FS: create_directory: created new directory named '%s' with inode %u\n", name.characters(), inode.index());
|
dbgprintf("Ext2FS: create_directory: created new directory named '%s' with inode %u\n", name.characters(), inode->identifier().index());
|
||||||
|
|
||||||
Vector<DirectoryEntry> entries;
|
Vector<DirectoryEntry> entries;
|
||||||
entries.append({ ".", inode, EXT2_FT_DIR });
|
entries.append({ ".", inode->identifier(), EXT2_FT_DIR });
|
||||||
entries.append({ "..", parentInode, EXT2_FT_DIR });
|
entries.append({ "..", parentInode, EXT2_FT_DIR });
|
||||||
|
|
||||||
bool success = write_directory_inode(inode.index(), move(entries));
|
bool success = write_directory_inode(inode->identifier().index(), move(entries));
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
|
|
||||||
success = modify_link_count(parentInode.index(), 1);
|
success = modify_link_count(parentInode.index(), 1);
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
|
|
||||||
auto& bgd = const_cast<ext2_group_desc&>(group_descriptor(group_index_from_inode(inode.index())));
|
auto& bgd = const_cast<ext2_group_desc&>(group_descriptor(group_index_from_inode(inode->identifier().index())));
|
||||||
++bgd.bg_used_dirs_count;
|
++bgd.bg_used_dirs_count;
|
||||||
dbgprintf("Ext2FS: incremented bg_used_dirs_count %u -> %u\n", bgd.bg_used_dirs_count - 1, bgd.bg_used_dirs_count);
|
dbgprintf("Ext2FS: incremented bg_used_dirs_count %u -> %u\n", bgd.bg_used_dirs_count - 1, bgd.bg_used_dirs_count);
|
||||||
|
|
||||||
|
@ -869,21 +869,21 @@ InodeIdentifier Ext2FS::create_directory(InodeIdentifier parentInode, const Stri
|
||||||
return inode;
|
return inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
InodeIdentifier Ext2FS::create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, unsigned size, int& error)
|
RetainPtr<Inode> Ext2FS::create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, unsigned size, int& error)
|
||||||
{
|
{
|
||||||
ASSERT(parentInode.fsid() == id());
|
ASSERT(parentInode.fsid() == id());
|
||||||
|
|
||||||
dbgprintf("Ext2FS: Adding inode '%s' (mode %u) to parent directory %u:\n", name.characters(), mode, parentInode.index());
|
dbgprintf("Ext2FS: Adding inode '%s' (mode %u) to parent directory %u:\n", name.characters(), mode, parentInode.index());
|
||||||
|
|
||||||
// NOTE: This doesn't commit the inode allocation just yet!
|
// NOTE: This doesn't commit the inode allocation just yet!
|
||||||
auto inode = allocate_inode(0, 0);
|
auto inode_id = allocate_inode(0, 0);
|
||||||
if (!inode) {
|
if (!inode_id) {
|
||||||
kprintf("Ext2FS: createInode: allocateInode failed\n");
|
kprintf("Ext2FS: createInode: allocateInode failed\n");
|
||||||
error = -ENOSPC;
|
error = -ENOSPC;
|
||||||
return { };
|
return { };
|
||||||
}
|
}
|
||||||
|
|
||||||
auto blocks = allocate_blocks(group_index_from_inode(inode), ceilDiv(size, blockSize()));
|
auto blocks = allocate_blocks(group_index_from_inode(inode_id), ceilDiv(size, blockSize()));
|
||||||
if (blocks.is_empty()) {
|
if (blocks.is_empty()) {
|
||||||
kprintf("Ext2FS: createInode: allocateBlocks failed\n");
|
kprintf("Ext2FS: createInode: allocateBlocks failed\n");
|
||||||
error = -ENOSPC;
|
error = -ENOSPC;
|
||||||
|
@ -907,16 +907,16 @@ InodeIdentifier Ext2FS::create_inode(InodeIdentifier parentInode, const String&
|
||||||
fileType = EXT2_FT_SYMLINK;
|
fileType = EXT2_FT_SYMLINK;
|
||||||
|
|
||||||
// Try adding it to the directory first, in case the name is already in use.
|
// Try adding it to the directory first, in case the name is already in use.
|
||||||
bool success = add_inode_to_directory(parentInode.index(), inode, name, fileType, error);
|
bool success = add_inode_to_directory(parentInode.index(), inode_id, name, fileType, error);
|
||||||
if (!success)
|
if (!success)
|
||||||
return { };
|
return { };
|
||||||
|
|
||||||
// Looks like we're good, time to update the inode bitmap and group+global inode counters.
|
// Looks like we're good, time to update the inode bitmap and group+global inode counters.
|
||||||
success = set_inode_allocation_state(inode, true);
|
success = set_inode_allocation_state(inode_id, true);
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
|
|
||||||
for (auto bi : blocks) {
|
for (auto bi : blocks) {
|
||||||
success = set_block_allocation_state(group_index_from_inode(inode), bi, true);
|
success = set_block_allocation_state(group_index_from_inode(inode_id), bi, true);
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -949,10 +949,10 @@ InodeIdentifier Ext2FS::create_inode(InodeIdentifier parentInode, const String&
|
||||||
}
|
}
|
||||||
|
|
||||||
e2inode->i_flags = 0;
|
e2inode->i_flags = 0;
|
||||||
success = write_ext2_inode(inode, *e2inode);
|
success = write_ext2_inode(inode_id, *e2inode);
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
|
|
||||||
return { id(), inode };
|
return get_inode({ id(), inode_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
InodeIdentifier Ext2FS::find_parent_of_inode(InodeIdentifier inode_id) const
|
InodeIdentifier Ext2FS::find_parent_of_inode(InodeIdentifier inode_id) const
|
||||||
|
|
|
@ -72,8 +72,8 @@ private:
|
||||||
virtual const char* class_name() const override;
|
virtual const char* class_name() const override;
|
||||||
virtual InodeIdentifier root_inode() const override;
|
virtual InodeIdentifier root_inode() const override;
|
||||||
virtual bool write_inode(InodeIdentifier, const ByteBuffer&) override;
|
virtual bool write_inode(InodeIdentifier, const ByteBuffer&) override;
|
||||||
virtual InodeIdentifier create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size, int& error) override;
|
virtual RetainPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size, int& error) override;
|
||||||
virtual InodeIdentifier create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t, int& error) override;
|
virtual RetainPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t, int& error) override;
|
||||||
virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const override;
|
virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const override;
|
||||||
virtual RetainPtr<Inode> get_inode(InodeIdentifier) const override;
|
virtual RetainPtr<Inode> get_inode(InodeIdentifier) const override;
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,8 @@ public:
|
||||||
byte fileType { 0 };
|
byte fileType { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual InodeIdentifier create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size, int& error) = 0;
|
virtual RetainPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size, int& error) = 0;
|
||||||
virtual InodeIdentifier create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t, int& error) = 0;
|
virtual RetainPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t, int& error) = 0;
|
||||||
|
|
||||||
virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const = 0;
|
virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const = 0;
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ InodeIdentifier SynthFS::root_inode() const
|
||||||
return { id(), 1 };
|
return { id(), 1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
InodeIdentifier SynthFS::create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, unsigned size, int& error)
|
RetainPtr<Inode> SynthFS::create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, unsigned size, int& error)
|
||||||
{
|
{
|
||||||
(void) parentInode;
|
(void) parentInode;
|
||||||
(void) name;
|
(void) name;
|
||||||
|
@ -149,10 +149,10 @@ bool SynthFS::write_inode(InodeIdentifier, const ByteBuffer&)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
InodeIdentifier SynthFS::create_directory(InodeIdentifier, const String&, Unix::mode_t, int& error)
|
RetainPtr<Inode> SynthFS::create_directory(InodeIdentifier, const String&, Unix::mode_t, int& error)
|
||||||
{
|
{
|
||||||
error = -EROFS;
|
error = -EROFS;
|
||||||
return { };
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto SynthFS::generate_inode_index() -> InodeIndex
|
auto SynthFS::generate_inode_index() -> InodeIndex
|
||||||
|
|
|
@ -15,8 +15,8 @@ public:
|
||||||
virtual const char* class_name() const override;
|
virtual const char* class_name() const override;
|
||||||
virtual InodeIdentifier root_inode() const override;
|
virtual InodeIdentifier root_inode() const override;
|
||||||
virtual bool write_inode(InodeIdentifier, const ByteBuffer&) override;
|
virtual bool write_inode(InodeIdentifier, const ByteBuffer&) override;
|
||||||
virtual InodeIdentifier create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size, int& error) override;
|
virtual RetainPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size, int& error) override;
|
||||||
virtual InodeIdentifier create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t, int& error) override;
|
virtual RetainPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t, int& error) override;
|
||||||
virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const override;
|
virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const override;
|
||||||
virtual RetainPtr<Inode> get_inode(InodeIdentifier) const override;
|
virtual RetainPtr<Inode> get_inode(InodeIdentifier) const override;
|
||||||
|
|
||||||
|
|
|
@ -306,7 +306,7 @@ bool VFS::mkdir(const String& path, mode_t mode, InodeIdentifier base, int& erro
|
||||||
}
|
}
|
||||||
dbgprintf("VFS::mkdir: '%s' in %u:%u\n", p.basename().characters(), parent_dir.fsid(), parent_dir.index());
|
dbgprintf("VFS::mkdir: '%s' in %u:%u\n", p.basename().characters(), parent_dir.fsid(), parent_dir.index());
|
||||||
auto new_dir = base.fs()->create_directory(parent_dir, p.basename(), mode, error);
|
auto new_dir = base.fs()->create_directory(parent_dir, p.basename(), mode, error);
|
||||||
if (new_dir.is_valid()) {
|
if (new_dir) {
|
||||||
error = 0;
|
error = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue