mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:47:35 +00:00
Ext2FS: Don't allocate blocks until we're committed to a new inode
Otherwise we would leak the blocks in case we returned earlier than expected. :^)
This commit is contained in:
parent
bd7c38e7b6
commit
e364846622
1 changed files with 3 additions and 7 deletions
|
@ -1204,13 +1204,6 @@ RefPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& name
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto blocks = allocate_blocks(group_index_from_inode(inode_id), needed_blocks);
|
|
||||||
if (blocks.size() != needed_blocks) {
|
|
||||||
kprintf("Ext2FS: create_inode: allocate_blocks failed\n");
|
|
||||||
error = -ENOSPC;
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
||||||
auto result = parent_inode->add_child({ fsid(), inode_id }, name, mode);
|
auto result = parent_inode->add_child({ fsid(), inode_id }, name, mode);
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
|
@ -1218,6 +1211,9 @@ RefPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& name
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto blocks = allocate_blocks(group_index_from_inode(inode_id), needed_blocks);
|
||||||
|
ASSERT(blocks.size() == needed_blocks);
|
||||||
|
|
||||||
// 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.
|
||||||
bool success = set_inode_allocation_state(inode_id, true);
|
bool success = set_inode_allocation_state(inode_id, true);
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue