kernel/ext2: Add support for symbolic links
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
apio 2023-06-22 20:10:09 +02:00
parent cf897ebb78
commit 00d625a697
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 31 additions and 1 deletions

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 };