kernel/ext2: Add support for symbolic links
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
This commit is contained in:
parent
cf897ebb78
commit
00d625a697
@ -1,5 +1,5 @@
|
|||||||
#include "fs/ext2/Inode.h"
|
#include "fs/ext2/Inode.h"
|
||||||
#include <luna/String.h>
|
#include <luna/Buffer.h>
|
||||||
|
|
||||||
namespace Ext2
|
namespace Ext2
|
||||||
{
|
{
|
||||||
@ -162,4 +162,29 @@ namespace Ext2
|
|||||||
|
|
||||||
return m_entries[index];
|
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
|
#pragma once
|
||||||
#include "fs/ext2/FileSystem.h"
|
#include "fs/ext2/FileSystem.h"
|
||||||
|
#include <luna/String.h>
|
||||||
|
|
||||||
#define EXT2_FIFO 0x1000
|
#define EXT2_FIFO 0x1000
|
||||||
#define EXT2_CHR 0x2000
|
#define EXT2_CHR 0x2000
|
||||||
@ -125,6 +126,8 @@ namespace Ext2
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result<StringView> readlink() override;
|
||||||
|
|
||||||
Result<void> lazy_initialize_dir() const;
|
Result<void> lazy_initialize_dir() const;
|
||||||
|
|
||||||
// FIXME: Implement readlink() and device numbers.
|
// FIXME: Implement readlink() and device numbers.
|
||||||
@ -138,6 +141,8 @@ namespace Ext2
|
|||||||
FileSystem* m_fs;
|
FileSystem* m_fs;
|
||||||
ino_t m_inum;
|
ino_t m_inum;
|
||||||
|
|
||||||
|
String m_link;
|
||||||
|
|
||||||
mutable Vector<VFS::DirectoryEntry> m_entries;
|
mutable Vector<VFS::DirectoryEntry> m_entries;
|
||||||
mutable bool m_dir_already_lazily_initialized { false };
|
mutable bool m_dir_already_lazily_initialized { false };
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user