Remove FS::read_entire_inode() in favor of Inode::read_entire().
This commit is contained in:
parent
04ee693925
commit
7bc41532be
Notes:
sideshowbarker
2024-07-19 16:07:32 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/7bc41532be1
9 changed files with 9 additions and 66 deletions
|
@ -13,7 +13,7 @@ FileSystemPath::FileSystemPath(const String& s)
|
|||
|
||||
bool FileSystemPath::canonicalize(bool resolve_symbolic_links)
|
||||
{
|
||||
// FIXME: Implement "resolveSymbolicLinks"
|
||||
// FIXME: Implement "resolve_symbolic_links"
|
||||
(void) resolve_symbolic_links;
|
||||
auto parts = m_string.split('/');
|
||||
Vector<String> canonical_parts;
|
||||
|
|
|
@ -35,7 +35,6 @@ VFS_OBJS = \
|
|||
../VirtualFileSystem/FileSystem.o \
|
||||
../VirtualFileSystem/DiskBackedFileSystem.o \
|
||||
../VirtualFileSystem/Ext2FileSystem.o \
|
||||
../VirtualFileSystem/InodeIdentifier.o \
|
||||
../VirtualFileSystem/VirtualFileSystem.o \
|
||||
../VirtualFileSystem/FileDescriptor.o \
|
||||
../VirtualFileSystem/SyntheticFileSystem.o
|
||||
|
|
|
@ -195,9 +195,8 @@ ByteBuffer FileDescriptor::read_entire_file()
|
|||
return buffer;
|
||||
}
|
||||
|
||||
if (m_vnode->core_inode())
|
||||
return m_vnode->core_inode()->read_entire(this);
|
||||
return m_vnode->fs()->read_entire_inode(m_vnode->inode, this);
|
||||
ASSERT(inode());
|
||||
return inode()->read_entire(this);
|
||||
}
|
||||
|
||||
bool FileDescriptor::is_directory() const
|
||||
|
|
|
@ -49,8 +49,6 @@ FS* FS::from_fsid(dword id)
|
|||
|
||||
ByteBuffer Inode::read_entire(FileDescriptor* descriptor)
|
||||
{
|
||||
return fs().read_entire_inode(identifier(), descriptor);
|
||||
/*
|
||||
size_t initial_size = metadata().size ? metadata().size : 4096;
|
||||
auto contents = ByteBuffer::create_uninitialized(initial_size);
|
||||
|
||||
|
@ -60,7 +58,6 @@ ByteBuffer Inode::read_entire(FileDescriptor* descriptor)
|
|||
Unix::off_t offset = 0;
|
||||
for (;;) {
|
||||
nread = read_bytes(offset, sizeof(buffer), buffer, descriptor);
|
||||
//kprintf("nread: %u, bufsiz: %u, initial_size: %u\n", nread, sizeof(buffer), initial_size);
|
||||
ASSERT(nread <= (ssize_t)sizeof(buffer));
|
||||
if (nread <= 0)
|
||||
break;
|
||||
|
@ -74,45 +71,6 @@ ByteBuffer Inode::read_entire(FileDescriptor* descriptor)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
contents.trim(offset);
|
||||
return contents;
|
||||
*/
|
||||
}
|
||||
|
||||
ByteBuffer FS::read_entire_inode(InodeIdentifier inode_id, FileDescriptor* handle) const
|
||||
{
|
||||
ASSERT(inode_id.fsid() == id());
|
||||
|
||||
auto inode = get_inode(inode_id);
|
||||
if (!inode) {
|
||||
kprintf("fs: read_entire_inode: lookup for inode %u:%u failed\n", id(), inode_id.index());
|
||||
return nullptr;
|
||||
}
|
||||
auto metadata = inode->metadata();
|
||||
|
||||
size_t initialSize = metadata.size ? metadata.size : 4096;
|
||||
auto contents = ByteBuffer::create_uninitialized(initialSize);
|
||||
|
||||
ssize_t nread;
|
||||
byte buffer[4096];
|
||||
byte* out = contents.pointer();
|
||||
Unix::off_t offset = 0;
|
||||
for (;;) {
|
||||
nread = inode->read_bytes(offset, sizeof(buffer), buffer, handle);
|
||||
//kprintf("nread: %u, bufsiz: %u, initialSize: %u\n", nread, sizeof(buffer), initialSize);
|
||||
ASSERT(nread <= (ssize_t)sizeof(buffer));
|
||||
if (nread <= 0)
|
||||
break;
|
||||
memcpy(out, buffer, nread);
|
||||
out += nread;
|
||||
offset += nread;
|
||||
ASSERT(offset <= (ssize_t)initialSize); // FIXME: Support dynamically growing the buffer.
|
||||
}
|
||||
if (nread < 0) {
|
||||
kprintf("[fs] readInode: ERROR: %d\n", nread);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
contents.trim(offset);
|
||||
return contents;
|
||||
}
|
||||
|
|
|
@ -51,8 +51,6 @@ public:
|
|||
|
||||
virtual RetainPtr<Inode> get_inode(InodeIdentifier) const = 0;
|
||||
|
||||
ByteBuffer read_entire_inode(InodeIdentifier, FileDescriptor* = nullptr) const;
|
||||
|
||||
protected:
|
||||
FS();
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
#include "InodeIdentifier.h"
|
||||
#include "FileSystem.h"
|
||||
|
||||
ByteBuffer InodeIdentifier::read_entire_file() const
|
||||
{
|
||||
if (!fs())
|
||||
return { };
|
||||
return fs()->read_entire_inode(*this, nullptr);
|
||||
}
|
|
@ -35,8 +35,6 @@ public:
|
|||
|
||||
bool is_root_inode() const;
|
||||
|
||||
ByteBuffer read_entire_file() const;
|
||||
|
||||
private:
|
||||
dword m_fsid { 0 };
|
||||
dword m_index { 0 };
|
||||
|
|
|
@ -312,12 +312,12 @@ bool VFS::mkdir(const String& path, mode_t mode, InodeIdentifier base, int& erro
|
|||
return false;
|
||||
}
|
||||
|
||||
InodeIdentifier VFS::resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error)
|
||||
InodeIdentifier VFS::resolve_symbolic_link(InodeIdentifier base, Inode& symlink_inode, int& error)
|
||||
{
|
||||
auto symlinkContents = symlinkInode.read_entire_file();
|
||||
if (!symlinkContents)
|
||||
auto symlink_contents = symlink_inode.read_entire();
|
||||
if (!symlink_contents)
|
||||
return { };
|
||||
auto linkee = String((const char*)symlinkContents.pointer(), symlinkContents.size());
|
||||
auto linkee = String((const char*)symlink_contents.pointer(), symlink_contents.size());
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf("linkee (%s)(%u) from %u:%u\n", linkee.characters(), linkee.length(), base.fsid(), base.index());
|
||||
#endif
|
||||
|
@ -447,7 +447,7 @@ InodeIdentifier VFS::resolve_path(const String& path, InodeIdentifier base, int&
|
|||
if (options & O_NOFOLLOW_NOERROR)
|
||||
return crumb_id;
|
||||
}
|
||||
crumb_id = resolveSymbolicLink(parent, crumb_id, error);
|
||||
crumb_id = resolve_symbolic_link(parent, *crumb_inode, error);
|
||||
if (!crumb_id.is_valid()) {
|
||||
kprintf("Symbolic link resolution failed :(\n");
|
||||
return { };
|
||||
|
|
|
@ -135,7 +135,7 @@ private:
|
|||
|
||||
void traverse_directory_inode(Inode&, Function<bool(const FS::DirectoryEntry&)>);
|
||||
InodeIdentifier resolve_path(const String& path, InodeIdentifier base, int& error, int options = 0, InodeIdentifier* deepest_dir = nullptr);
|
||||
InodeIdentifier resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error);
|
||||
InodeIdentifier resolve_symbolic_link(InodeIdentifier base, Inode& symlink_inode, int& error);
|
||||
|
||||
RetainPtr<Vnode> allocateNode();
|
||||
void freeNode(Vnode*);
|
||||
|
|
Loading…
Add table
Reference in a new issue