Add a basic read-only implementation for the Ext2 filesystem #29

Merged
apio merged 14 commits from ext2 into main 2023-07-01 15:38:00 +00:00
2 changed files with 31 additions and 1 deletions
Showing only changes of commit 41f578aa18 - Show all commits

View File

@ -1,5 +1,5 @@
#include "fs/ext2/Inode.h"
#include <luna/String.h>
#include <luna/Buffer.h>
namespace Ext2
{
@ -162,4 +162,29 @@ namespace Ext2
return m_entries[index];
}
Result<StringView> Inode::readlink()
{
check(m_type == VFS::InodeType::Symlink);
if (!m_link.is_empty()) return m_link.view();
const usize length = size();
if (length < 60)
{
// The symlink location is stored inline within the inode's data blocks.
m_link = TRY(String::from_string_view(
StringView::from_fixed_size_cstring((char*)&m_raw_inode.direct_pointers[0], length)));
return m_link.view();
}
Buffer buf = TRY(Buffer::create_sized(length));
TRY(read(buf.data(), 0, length));
m_link = TRY(String::from_string_view(StringView::from_fixed_size_cstring((char*)buf.data(), length)));
return m_link.view();
}
}

View File

@ -1,5 +1,6 @@
#pragma once
#include "fs/ext2/FileSystem.h"
#include <luna/String.h>
#define EXT2_FIFO 0x1000
#define EXT2_CHR 0x2000
@ -125,6 +126,8 @@ namespace Ext2
return false;
}
Result<StringView> readlink() override;
Result<void> lazy_initialize_dir() const;
// FIXME: Implement readlink() and device numbers.
@ -138,6 +141,8 @@ namespace Ext2
FileSystem* m_fs;
ino_t m_inum;
String m_link;
mutable Vector<VFS::DirectoryEntry> m_entries;
mutable bool m_dir_already_lazily_initialized { false };