mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-20 16:28:54 +00:00
Kernel/FATFS: Implement add_child
This commit is contained in:
parent
5e87b78935
commit
3b39a2f71b
Notes:
sideshowbarker
2024-07-18 03:20:18 +09:00
Author: https://github.com/cqundefine
Commit: 3b39a2f71b
Pull-request: https://github.com/SerenityOS/serenity/pull/23907
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/implicitfield
Reviewed-by: https://github.com/nico
Reviewed-by: https://github.com/timschumi ✅
1 changed files with 33 additions and 2 deletions
|
@ -568,9 +568,40 @@ ErrorOr<NonnullRefPtr<Inode>> FATInode::create_child(StringView name, mode_t mod
|
||||||
return TRY(FATInode::create(fs(), entry, entries[lfn_entries.size()], lfn_entries));
|
return TRY(FATInode::create(fs(), entry, entries[lfn_entries.size()], lfn_entries));
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> FATInode::add_child(Inode&, StringView, mode_t)
|
ErrorOr<void> FATInode::add_child(Inode& inode, StringView name, mode_t mode)
|
||||||
{
|
{
|
||||||
return EROFS;
|
VERIFY(has_flag(m_entry.attributes, FATAttributes::Directory));
|
||||||
|
VERIFY(inode.fsid() == fsid());
|
||||||
|
|
||||||
|
// FIXME: There's a lot of similar code between this function and create_child, we should try to factor out some of the common code.
|
||||||
|
|
||||||
|
dbgln_if(FAT_DEBUG, "FATInode[{}]::add_child(): appending inode {} as \"{}\"", identifier(), inode.identifier(), name);
|
||||||
|
|
||||||
|
auto entry = bit_cast<FATInode*>(&inode)->m_entry;
|
||||||
|
create_83_filename_for(entry, name);
|
||||||
|
|
||||||
|
// TODO: We should set the hidden attribute if the file starts with a dot or read only (the same way Linux does this).
|
||||||
|
if (mode & S_IFDIR)
|
||||||
|
entry.attributes |= FATAttributes::Directory;
|
||||||
|
|
||||||
|
// FIXME: Set the dates
|
||||||
|
|
||||||
|
// FIXME: For some filenames lfn entries are not necessary
|
||||||
|
auto lfn_entries = TRY(create_lfn_entries(name, lfn_entry_checksum(entry)));
|
||||||
|
|
||||||
|
MutexLocker locker(m_inode_lock);
|
||||||
|
|
||||||
|
auto entries = TRY(allocate_entries(lfn_entries.size() + 1));
|
||||||
|
|
||||||
|
// FIXME: If we fail here we should clean up the entries we wrote
|
||||||
|
TRY(fs().write_block(entries[lfn_entries.size()].block, UserOrKernelBuffer::for_kernel_buffer(bit_cast<u8*>(&entry)), sizeof(FATEntry), entries[lfn_entries.size()].entry * sizeof(FATEntry)));
|
||||||
|
|
||||||
|
for (u32 i = 0; i < lfn_entries.size(); i++) {
|
||||||
|
auto location = entries[lfn_entries.size() - i - 1];
|
||||||
|
TRY(fs().write_block(location.block, UserOrKernelBuffer::for_kernel_buffer(bit_cast<u8*>(&lfn_entries[i])), sizeof(FATLongFileNameEntry), location.entry * sizeof(FATLongFileNameEntry)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> FATInode::remove_child(StringView)
|
ErrorOr<void> FATInode::remove_child(StringView)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue