Kernel: Implement TmpFS directory listing

This commit is contained in:
Bananymous 2023-11-06 20:42:40 +02:00
parent c3ed700324
commit ff6b127c3a
1 changed files with 44 additions and 2 deletions

View File

@ -276,9 +276,51 @@ namespace Kernel
return BAN::RefPtr<Inode>(inode);
}
BAN::ErrorOr<void> TmpDirectoryInode::list_next_inodes_impl(off_t, DirectoryEntryList*, size_t)
BAN::ErrorOr<void> TmpDirectoryInode::list_next_inodes_impl(off_t data_block_index, DirectoryEntryList* list, size_t list_len)
{
return BAN::Error::from_errno(ENOTSUP);
if (list_len < (size_t)blksize())
{
dprintln("buffer is too small");
return BAN::Error::from_errno(ENOBUFS);
}
auto block_index = this->block_index(data_block_index);
list->entry_count = 0;
// if we reach a non-allocated block, it marks the end
if (!block_index.has_value())
return {};
auto* dirp = list->array;
const size_t byte_count = BAN::Math::min<size_t>(size() - data_block_index * blksize(), blksize());
m_fs.with_block_buffer(block_index.value(), [&](BAN::ByteSpan bytespan) {
bytespan = bytespan.slice(0, byte_count);
while (bytespan.size() > 0)
{
const auto& entry = bytespan.as<TmpDirectoryEntry>();
if (entry.type != DT_UNKNOWN)
{
// TODO: dirents should be aligned
dirp->dirent.d_ino = entry.ino;
dirp->dirent.d_type = entry.type;
strncpy(dirp->dirent.d_name, entry.name, entry.name_len);
dirp->dirent.d_name[entry.name_len] = '\0';
dirp->rec_len = sizeof(DirectoryEntry) + entry.name_len + 1;
dirp = dirp->next();
list->entry_count++;
}
bytespan = bytespan.slice(entry.rec_len);
}
});
return {};
}
BAN::ErrorOr<void> TmpDirectoryInode::create_file_impl(BAN::StringView name, mode_t mode, uid_t uid, gid_t gid)