kernel/ext2: Add support for symbolic links
This commit is contained in:
parent
34e1ef36b1
commit
41f578aa18
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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 };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user