mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
Rename FileHandle to FileDescriptor.
This commit is contained in:
parent
e088121b3a
commit
83172e6a4b
Notes:
sideshowbarker
2024-07-19 18:32:36 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/83172e6a4b6
18 changed files with 160 additions and 154 deletions
|
@ -34,7 +34,7 @@ VFS_OBJS = \
|
|||
../VirtualFileSystem/Ext2FileSystem.o \
|
||||
../VirtualFileSystem/InodeIdentifier.o \
|
||||
../VirtualFileSystem/VirtualFileSystem.o \
|
||||
../VirtualFileSystem/FileHandle.o \
|
||||
../VirtualFileSystem/FileDescriptor.o \
|
||||
../VirtualFileSystem/SyntheticFileSystem.o
|
||||
|
||||
ELFLOADER_OBJS = \
|
||||
|
|
|
@ -36,10 +36,10 @@ ByteBuffer procfs$pid_fds(Process& process)
|
|||
memset(buffer, 0, stringImpl->length());
|
||||
char* ptr = buffer;
|
||||
for (size_t i = 0; i < process.max_open_file_descriptors(); ++i) {
|
||||
auto* handle = process.file_descriptor(i);
|
||||
if (!handle)
|
||||
auto* descriptor = process.file_descriptor(i);
|
||||
if (!descriptor)
|
||||
continue;
|
||||
ptr += ksprintf(ptr, "% 3u %s\n", i, handle->absolute_path().characters());
|
||||
ptr += ksprintf(ptr, "% 3u %s\n", i, descriptor->absolute_path().characters());
|
||||
}
|
||||
*ptr = '\0';
|
||||
return ByteBuffer::copy((byte*)buffer, ptr - buffer);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "StdLib.h"
|
||||
#include "i386.h"
|
||||
#include "system.h"
|
||||
#include <VirtualFileSystem/FileHandle.h>
|
||||
#include <VirtualFileSystem/FileDescriptor.h>
|
||||
#include <VirtualFileSystem/VirtualFileSystem.h>
|
||||
#include <ELFLoader/ELFLoader.h>
|
||||
#include "MemoryManager.h"
|
||||
|
@ -299,16 +299,16 @@ int Process::exec(const String& path, Vector<String>&& arguments, Vector<String>
|
|||
return -ENOENT;
|
||||
|
||||
int error;
|
||||
auto handle = VirtualFileSystem::the().open(path, error, 0, m_cwd ? m_cwd->inode : InodeIdentifier());
|
||||
if (!handle) {
|
||||
auto descriptor = VirtualFileSystem::the().open(path, error, 0, m_cwd ? m_cwd->inode : InodeIdentifier());
|
||||
if (!descriptor) {
|
||||
ASSERT(error != 0);
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!handle->metadata().mayExecute(m_euid, m_gids))
|
||||
if (!descriptor->metadata().mayExecute(m_euid, m_gids))
|
||||
return -EACCES;
|
||||
|
||||
auto elfData = handle->readEntireFile();
|
||||
auto elfData = descriptor->readEntireFile();
|
||||
if (!elfData)
|
||||
return -EIO; // FIXME: Get a more detailed error from VFS.
|
||||
|
||||
|
@ -379,7 +379,7 @@ int Process::exec(const String& path, Vector<String>&& arguments, Vector<String>
|
|||
|
||||
MM.release_page_directory(*old_page_directory);
|
||||
|
||||
m_executable = handle->vnode();
|
||||
m_executable = descriptor->vnode();
|
||||
m_arguments = move(arguments);
|
||||
m_initialEnvironment = move(environment);
|
||||
|
||||
|
@ -1036,11 +1036,20 @@ Process* Process::fromPID(pid_t pid)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
FileHandle* Process::fileHandleIfExists(int fd)
|
||||
FileDescriptor* Process::file_descriptor(int fd)
|
||||
{
|
||||
if (fd < 0)
|
||||
return nullptr;
|
||||
if ((unsigned)fd < m_file_descriptors.size())
|
||||
if ((size_t)fd < m_file_descriptors.size())
|
||||
return m_file_descriptors[fd].ptr();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const FileDescriptor* Process::file_descriptor(int fd) const
|
||||
{
|
||||
if (fd < 0)
|
||||
return nullptr;
|
||||
if ((size_t)fd < m_file_descriptors.size())
|
||||
return m_file_descriptors[fd].ptr();
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -1048,29 +1057,29 @@ FileHandle* Process::fileHandleIfExists(int fd)
|
|||
ssize_t Process::sys$get_dir_entries(int fd, void* buffer, size_t size)
|
||||
{
|
||||
VALIDATE_USER_WRITE(buffer, size);
|
||||
auto* handle = fileHandleIfExists(fd);
|
||||
if (!handle)
|
||||
auto* descriptor = file_descriptor(fd);
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
return handle->get_dir_entries((byte*)buffer, size);
|
||||
return descriptor->get_dir_entries((byte*)buffer, size);
|
||||
}
|
||||
|
||||
int Process::sys$lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
auto* handle = fileHandleIfExists(fd);
|
||||
if (!handle)
|
||||
auto* descriptor = file_descriptor(fd);
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
return handle->seek(offset, whence);
|
||||
return descriptor->seek(offset, whence);
|
||||
}
|
||||
|
||||
int Process::sys$ttyname_r(int fd, char* buffer, size_t size)
|
||||
{
|
||||
VALIDATE_USER_WRITE(buffer, size);
|
||||
auto* handle = fileHandleIfExists(fd);
|
||||
if (!handle)
|
||||
auto* descriptor = file_descriptor(fd);
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
if (!handle->isTTY())
|
||||
if (!descriptor->isTTY())
|
||||
return -ENOTTY;
|
||||
auto ttyName = handle->tty()->ttyName();
|
||||
auto ttyName = descriptor->tty()->ttyName();
|
||||
if (size < ttyName.length() + 1)
|
||||
return -ERANGE;
|
||||
strcpy(buffer, ttyName.characters());
|
||||
|
@ -1083,13 +1092,13 @@ ssize_t Process::sys$write(int fd, const void* data, size_t size)
|
|||
#ifdef DEBUG_IO
|
||||
kprintf("Process::sys$write: called(%d, %p, %u)\n", fd, data, size);
|
||||
#endif
|
||||
auto* handle = fileHandleIfExists(fd);
|
||||
auto* descriptor = file_descriptor(fd);
|
||||
#ifdef DEBUG_IO
|
||||
kprintf("Process::sys$write: handle=%p\n", handle);
|
||||
kprintf("Process::sys$write: handle=%p\n", descriptor);
|
||||
#endif
|
||||
if (!handle)
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
auto nwritten = handle->write((const byte*)data, size);
|
||||
auto nwritten = descriptor->write((const byte*)data, size);
|
||||
#ifdef DEBUG_IO
|
||||
kprintf("Process::sys$write: nwritten=%u\n", nwritten);
|
||||
#endif
|
||||
|
@ -1102,20 +1111,20 @@ ssize_t Process::sys$read(int fd, void* outbuf, size_t nread)
|
|||
#ifdef DEBUG_IO
|
||||
kprintf("Process::sys$read: called(%d, %p, %u)\n", fd, outbuf, nread);
|
||||
#endif
|
||||
auto* handle = fileHandleIfExists(fd);
|
||||
auto* descriptor = file_descriptor(fd);
|
||||
#ifdef DEBUG_IO
|
||||
kprintf("Process::sys$read: handle=%p\n", handle);
|
||||
kprintf("Process::sys$read: handle=%p\n", descriptor);
|
||||
#endif
|
||||
if (!handle)
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
if (handle->isBlocking()) {
|
||||
if (!handle->hasDataAvailableForRead()) {
|
||||
if (descriptor->isBlocking()) {
|
||||
if (!descriptor->hasDataAvailableForRead()) {
|
||||
m_fdBlockedOnRead = fd;
|
||||
block(BlockedRead);
|
||||
yield();
|
||||
}
|
||||
}
|
||||
nread = handle->read((byte*)outbuf, nread);
|
||||
nread = descriptor->read((byte*)outbuf, nread);
|
||||
#ifdef DEBUG_IO
|
||||
kprintf("Process::sys$read: nread=%u\n", nread);
|
||||
#endif
|
||||
|
@ -1124,10 +1133,10 @@ ssize_t Process::sys$read(int fd, void* outbuf, size_t nread)
|
|||
|
||||
int Process::sys$close(int fd)
|
||||
{
|
||||
auto* handle = fileHandleIfExists(fd);
|
||||
if (!handle)
|
||||
auto* descriptor = file_descriptor(fd);
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
int rc = handle->close();
|
||||
int rc = descriptor->close();
|
||||
m_file_descriptors[fd] = nullptr;
|
||||
return rc;
|
||||
}
|
||||
|
@ -1136,10 +1145,10 @@ int Process::sys$lstat(const char* path, Unix::stat* statbuf)
|
|||
{
|
||||
VALIDATE_USER_WRITE(statbuf, sizeof(Unix::stat));
|
||||
int error;
|
||||
auto handle = VirtualFileSystem::the().open(move(path), error, O_NOFOLLOW_NOERROR, cwdInode());
|
||||
if (!handle)
|
||||
auto descriptor = VirtualFileSystem::the().open(move(path), error, O_NOFOLLOW_NOERROR, cwdInode());
|
||||
if (!descriptor)
|
||||
return error;
|
||||
handle->stat(statbuf);
|
||||
descriptor->stat(statbuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1147,10 +1156,10 @@ int Process::sys$stat(const char* path, Unix::stat* statbuf)
|
|||
{
|
||||
VALIDATE_USER_WRITE(statbuf, sizeof(Unix::stat));
|
||||
int error;
|
||||
auto handle = VirtualFileSystem::the().open(move(path), error, 0, cwdInode());
|
||||
if (!handle)
|
||||
auto descriptor = VirtualFileSystem::the().open(move(path), error, 0, cwdInode());
|
||||
if (!descriptor)
|
||||
return error;
|
||||
handle->stat(statbuf);
|
||||
descriptor->stat(statbuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1160,14 +1169,14 @@ int Process::sys$readlink(const char* path, char* buffer, size_t size)
|
|||
VALIDATE_USER_WRITE(buffer, size);
|
||||
|
||||
int error;
|
||||
auto handle = VirtualFileSystem::the().open(path, error, O_RDONLY | O_NOFOLLOW_NOERROR, cwdInode());
|
||||
if (!handle)
|
||||
auto descriptor = VirtualFileSystem::the().open(path, error, O_RDONLY | O_NOFOLLOW_NOERROR, cwdInode());
|
||||
if (!descriptor)
|
||||
return error;
|
||||
|
||||
if (!handle->metadata().isSymbolicLink())
|
||||
if (!descriptor->metadata().isSymbolicLink())
|
||||
return -EINVAL;
|
||||
|
||||
auto contents = handle->readEntireFile();
|
||||
auto contents = descriptor->readEntireFile();
|
||||
if (!contents)
|
||||
return -EIO; // FIXME: Get a more detailed error from VFS.
|
||||
|
||||
|
@ -1181,12 +1190,12 @@ int Process::sys$chdir(const char* path)
|
|||
{
|
||||
VALIDATE_USER_READ(path, strlen(path));
|
||||
int error;
|
||||
auto handle = VirtualFileSystem::the().open(path, error, 0, cwdInode());
|
||||
if (!handle)
|
||||
auto descriptor = VirtualFileSystem::the().open(path, error, 0, cwdInode());
|
||||
if (!descriptor)
|
||||
return error;
|
||||
if (!handle->isDirectory())
|
||||
if (!descriptor->isDirectory())
|
||||
return -ENOTDIR;
|
||||
m_cwd = handle->vnode();
|
||||
m_cwd = descriptor->vnode();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1205,8 +1214,8 @@ int Process::sys$getcwd(char* buffer, size_t size)
|
|||
size_t Process::number_of_open_file_descriptors() const
|
||||
{
|
||||
size_t count = 0;
|
||||
for (auto& handle : m_file_descriptors) {
|
||||
if (handle)
|
||||
for (auto& descriptor : m_file_descriptors) {
|
||||
if (descriptor)
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
|
@ -1221,10 +1230,10 @@ int Process::sys$open(const char* path, int options)
|
|||
if (number_of_open_file_descriptors() >= m_max_open_file_descriptors)
|
||||
return -EMFILE;
|
||||
int error;
|
||||
auto handle = VirtualFileSystem::the().open(path, error, options, cwdInode());
|
||||
if (!handle)
|
||||
auto descriptor = VirtualFileSystem::the().open(path, error, options, cwdInode());
|
||||
if (!descriptor)
|
||||
return error;
|
||||
if (options & O_DIRECTORY && !handle->isDirectory())
|
||||
if (options & O_DIRECTORY && !descriptor->isDirectory())
|
||||
return -ENOTDIR; // FIXME: This should be handled by VFS::open.
|
||||
|
||||
int fd = 0;
|
||||
|
@ -1232,7 +1241,7 @@ int Process::sys$open(const char* path, int options)
|
|||
if (!m_file_descriptors[fd])
|
||||
break;
|
||||
}
|
||||
m_file_descriptors[fd] = move(handle);
|
||||
m_file_descriptors[fd] = move(descriptor);
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
@ -1249,10 +1258,10 @@ int Process::sys$uname(utsname* buf)
|
|||
|
||||
int Process::sys$isatty(int fd)
|
||||
{
|
||||
auto* handle = fileHandleIfExists(fd);
|
||||
if (!handle)
|
||||
auto* descriptor = file_descriptor(fd);
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
if (!handle->isTTY())
|
||||
if (!descriptor->isTTY())
|
||||
return -ENOTTY;
|
||||
return 1;
|
||||
}
|
||||
|
@ -1486,12 +1495,12 @@ int Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgid)
|
|||
|
||||
pid_t Process::sys$tcgetpgrp(int fd)
|
||||
{
|
||||
auto* handle = fileHandleIfExists(fd);
|
||||
if (!handle)
|
||||
auto* descriptor = file_descriptor(fd);
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
if (!handle->isTTY())
|
||||
if (!descriptor->isTTY())
|
||||
return -ENOTTY;
|
||||
auto& tty = *handle->tty();
|
||||
auto& tty = *descriptor->tty();
|
||||
if (&tty != m_tty)
|
||||
return -ENOTTY;
|
||||
return tty.pgid();
|
||||
|
@ -1503,12 +1512,12 @@ int Process::sys$tcsetpgrp(int fd, pid_t pgid)
|
|||
return -EINVAL;
|
||||
if (get_sid_from_pgid(pgid) != m_sid)
|
||||
return -EINVAL;
|
||||
auto* handle = fileHandleIfExists(fd);
|
||||
if (!handle)
|
||||
auto* descriptor = file_descriptor(fd);
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
if (!handle->isTTY())
|
||||
if (!descriptor->isTTY())
|
||||
return -ENOTTY;
|
||||
auto& tty = *handle->tty();
|
||||
auto& tty = *descriptor->tty();
|
||||
if (&tty != m_tty)
|
||||
return -ENOTTY;
|
||||
tty.set_pgid(pgid);
|
||||
|
@ -1522,8 +1531,8 @@ int Process::sys$getdtablesize()
|
|||
|
||||
int Process::sys$dup(int old_fd)
|
||||
{
|
||||
auto* handle = fileHandleIfExists(old_fd);
|
||||
if (!handle)
|
||||
auto* descriptor = file_descriptor(old_fd);
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
if (number_of_open_file_descriptors() == m_max_open_file_descriptors)
|
||||
return -EMFILE;
|
||||
|
@ -1532,18 +1541,18 @@ int Process::sys$dup(int old_fd)
|
|||
if (!m_file_descriptors[new_fd])
|
||||
break;
|
||||
}
|
||||
m_file_descriptors[new_fd] = handle;
|
||||
m_file_descriptors[new_fd] = descriptor;
|
||||
return new_fd;
|
||||
}
|
||||
|
||||
int Process::sys$dup2(int old_fd, int new_fd)
|
||||
{
|
||||
auto* handle = fileHandleIfExists(old_fd);
|
||||
if (!handle)
|
||||
auto* descriptor = file_descriptor(old_fd);
|
||||
if (!descriptor)
|
||||
return -EBADF;
|
||||
if (number_of_open_file_descriptors() == m_max_open_file_descriptors)
|
||||
return -EMFILE;
|
||||
m_file_descriptors[new_fd] = handle;
|
||||
m_file_descriptors[new_fd] = descriptor;
|
||||
return new_fd;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <VirtualFileSystem/UnixTypes.h>
|
||||
#include "TTY.h"
|
||||
|
||||
class FileHandle;
|
||||
class FileDescriptor;
|
||||
class PageDirectory;
|
||||
class Region;
|
||||
class Zone;
|
||||
|
@ -71,7 +71,8 @@ public:
|
|||
|
||||
const FarPtr& farPtr() const { return m_farPtr; }
|
||||
|
||||
FileHandle* fileHandleIfExists(int fd);
|
||||
FileDescriptor* file_descriptor(int fd);
|
||||
const FileDescriptor* file_descriptor(int fd) const;
|
||||
|
||||
static void doHouseKeeping();
|
||||
|
||||
|
@ -170,8 +171,6 @@ public:
|
|||
|
||||
size_t number_of_open_file_descriptors() const;
|
||||
size_t max_open_file_descriptors() const { return m_max_open_file_descriptors; }
|
||||
FileHandle* file_descriptor(size_t i) { return m_file_descriptors[i].ptr(); }
|
||||
const FileHandle* file_descriptor(size_t i) const { return m_file_descriptors[i].ptr(); }
|
||||
|
||||
void send_signal(int signal, Process* sender);
|
||||
void terminate_due_to_signal(int signal, Process* sender);
|
||||
|
@ -211,7 +210,7 @@ private:
|
|||
State m_state { Invalid };
|
||||
DWORD m_wakeupTime { 0 };
|
||||
TSS32 m_tss;
|
||||
Vector<RetainPtr<FileHandle>> m_file_descriptors;
|
||||
Vector<RetainPtr<FileDescriptor>> m_file_descriptors;
|
||||
RingLevel m_ring { Ring0 };
|
||||
int m_error { 0 };
|
||||
void* m_kernelStack { nullptr };
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <VirtualFileSystem/RandomDevice.h>
|
||||
#include <VirtualFileSystem/Ext2FileSystem.h>
|
||||
#include <VirtualFileSystem/VirtualFileSystem.h>
|
||||
#include <VirtualFileSystem/FileHandle.h>
|
||||
#include <VirtualFileSystem/FileDescriptor.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include "MemoryManager.h"
|
||||
#include <ELFLoader/ELFLoader.h>
|
||||
|
@ -206,11 +206,11 @@ static void init_stage2()
|
|||
#ifdef KSYMS
|
||||
{
|
||||
int error;
|
||||
auto handle = vfs->open("/kernel.map", error);
|
||||
if (!handle) {
|
||||
auto descriptor = vfs->open("/kernel.map", error);
|
||||
if (!descriptor) {
|
||||
kprintf("Failed to open /kernel.map\n");
|
||||
} else {
|
||||
auto buffer = handle->readEntireFile();
|
||||
auto buffer = descriptor->readEntireFile();
|
||||
ASSERT(buffer);
|
||||
loadKsyms(buffer);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ CharacterDevice::~CharacterDevice()
|
|||
{
|
||||
}
|
||||
|
||||
RetainPtr<FileHandle> CharacterDevice::open(int options)
|
||||
RetainPtr<FileDescriptor> CharacterDevice::open(int options)
|
||||
{
|
||||
return VirtualFileSystem::the().open(*this, options);
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
#include <AK/Types.h>
|
||||
#include "Limits.h"
|
||||
#include "FileHandle.h"
|
||||
#include "FileDescriptor.h"
|
||||
|
||||
class CharacterDevice {
|
||||
public:
|
||||
virtual ~CharacterDevice();
|
||||
|
||||
RetainPtr<FileHandle> open(int options);
|
||||
RetainPtr<FileDescriptor> open(int options);
|
||||
|
||||
virtual bool hasDataAvailableForRead() const = 0;
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ Vector<unsigned> Ext2FileSystem::blockListForInode(const ext2_inode& e2inode) co
|
|||
return list;
|
||||
}
|
||||
|
||||
Unix::ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileHandle*) const
|
||||
Unix::ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const
|
||||
{
|
||||
ASSERT(offset >= 0);
|
||||
ASSERT(inode.fileSystemID() == id());
|
||||
|
|
|
@ -46,7 +46,7 @@ private:
|
|||
virtual InodeMetadata inodeMetadata(InodeIdentifier) const override;
|
||||
virtual bool setModificationTime(InodeIdentifier, dword timestamp) override;
|
||||
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) override;
|
||||
virtual Unix::ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileHandle*) const override;
|
||||
virtual Unix::ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const override;
|
||||
virtual InodeIdentifier makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t) override;
|
||||
virtual InodeIdentifier findParentOfInode(InodeIdentifier) const override;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "FileHandle.h"
|
||||
#include "FileDescriptor.h"
|
||||
#include "FileSystem.h"
|
||||
#include "CharacterDevice.h"
|
||||
#include "sys-errno.h"
|
||||
|
@ -6,31 +6,30 @@
|
|||
#include "TTY.h"
|
||||
#include <AK/BufferStream.h>
|
||||
|
||||
RetainPtr<FileHandle> FileHandle::create(RetainPtr<VirtualFileSystem::Node>&& vnode)
|
||||
RetainPtr<FileDescriptor> FileDescriptor::create(RetainPtr<VirtualFileSystem::Node>&& vnode)
|
||||
{
|
||||
return adopt(*new FileHandle(move(vnode)));
|
||||
return adopt(*new FileDescriptor(move(vnode)));
|
||||
}
|
||||
|
||||
FileHandle::FileHandle(RetainPtr<VirtualFileSystem::Node>&& vnode)
|
||||
FileDescriptor::FileDescriptor(RetainPtr<VirtualFileSystem::Node>&& vnode)
|
||||
: m_vnode(move(vnode))
|
||||
{
|
||||
}
|
||||
|
||||
FileHandle::~FileHandle()
|
||||
FileDescriptor::~FileDescriptor()
|
||||
{
|
||||
}
|
||||
|
||||
RetainPtr<FileHandle> FileHandle::clone()
|
||||
RetainPtr<FileDescriptor> FileDescriptor::clone()
|
||||
{
|
||||
auto handle = FileHandle::create(m_vnode.copyRef());
|
||||
if (!handle)
|
||||
auto descriptor = FileDescriptor::create(m_vnode.copyRef());
|
||||
if (!descriptor)
|
||||
return nullptr;
|
||||
handle->m_currentOffset = m_currentOffset;
|
||||
descriptor->m_currentOffset = m_currentOffset;
|
||||
#ifdef SERENITY
|
||||
handle->m_fd = m_fd;
|
||||
handle->m_isBlocking = m_isBlocking;
|
||||
descriptor->m_isBlocking = m_isBlocking;
|
||||
#endif
|
||||
return handle;
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
#ifndef SERENITY
|
||||
|
@ -42,7 +41,7 @@ bool additionWouldOverflow(Unix::off_t a, Unix::off_t b)
|
|||
}
|
||||
#endif
|
||||
|
||||
int FileHandle::stat(Unix::stat* buffer)
|
||||
int FileDescriptor::stat(Unix::stat* buffer)
|
||||
{
|
||||
if (!m_vnode)
|
||||
return -EBADF;
|
||||
|
@ -67,7 +66,7 @@ int FileHandle::stat(Unix::stat* buffer)
|
|||
return 0;
|
||||
}
|
||||
|
||||
Unix::off_t FileHandle::seek(Unix::off_t offset, int whence)
|
||||
Unix::off_t FileDescriptor::seek(Unix::off_t offset, int whence)
|
||||
{
|
||||
if (!m_vnode)
|
||||
return -EBADF;
|
||||
|
@ -108,7 +107,7 @@ Unix::off_t FileHandle::seek(Unix::off_t offset, int whence)
|
|||
return m_currentOffset;
|
||||
}
|
||||
|
||||
Unix::ssize_t FileHandle::read(byte* buffer, Unix::size_t count)
|
||||
Unix::ssize_t FileDescriptor::read(byte* buffer, Unix::size_t count)
|
||||
{
|
||||
if (m_vnode->isCharacterDevice()) {
|
||||
// FIXME: What should happen to m_currentOffset?
|
||||
|
@ -119,7 +118,7 @@ Unix::ssize_t FileHandle::read(byte* buffer, Unix::size_t count)
|
|||
return nread;
|
||||
}
|
||||
|
||||
Unix::ssize_t FileHandle::write(const byte* data, Unix::size_t size)
|
||||
Unix::ssize_t FileDescriptor::write(const byte* data, Unix::size_t size)
|
||||
{
|
||||
if (m_vnode->isCharacterDevice()) {
|
||||
// FIXME: What should happen to m_currentOffset?
|
||||
|
@ -130,14 +129,14 @@ Unix::ssize_t FileHandle::write(const byte* data, Unix::size_t size)
|
|||
return -1;
|
||||
}
|
||||
|
||||
bool FileHandle::hasDataAvailableForRead()
|
||||
bool FileDescriptor::hasDataAvailableForRead()
|
||||
{
|
||||
if (m_vnode->isCharacterDevice())
|
||||
return m_vnode->characterDevice()->hasDataAvailableForRead();
|
||||
return true;
|
||||
}
|
||||
|
||||
ByteBuffer FileHandle::readEntireFile()
|
||||
ByteBuffer FileDescriptor::readEntireFile()
|
||||
{
|
||||
if (m_vnode->isCharacterDevice()) {
|
||||
auto buffer = ByteBuffer::createUninitialized(1024);
|
||||
|
@ -149,12 +148,12 @@ ByteBuffer FileHandle::readEntireFile()
|
|||
return m_vnode->fileSystem()->readEntireInode(m_vnode->inode, this);
|
||||
}
|
||||
|
||||
bool FileHandle::isDirectory() const
|
||||
bool FileDescriptor::isDirectory() const
|
||||
{
|
||||
return m_vnode->metadata().isDirectory();
|
||||
}
|
||||
|
||||
ssize_t FileHandle::get_dir_entries(byte* buffer, Unix::size_t size)
|
||||
ssize_t FileDescriptor::get_dir_entries(byte* buffer, Unix::size_t size)
|
||||
{
|
||||
auto metadata = m_vnode->metadata();
|
||||
if (!metadata.isValid())
|
||||
|
@ -180,33 +179,33 @@ ssize_t FileHandle::get_dir_entries(byte* buffer, Unix::size_t size)
|
|||
return stream.offset();
|
||||
}
|
||||
|
||||
bool FileHandle::isTTY() const
|
||||
bool FileDescriptor::isTTY() const
|
||||
{
|
||||
if (auto* device = m_vnode->characterDevice())
|
||||
return device->isTTY();
|
||||
return false;
|
||||
}
|
||||
|
||||
const TTY* FileHandle::tty() const
|
||||
const TTY* FileDescriptor::tty() const
|
||||
{
|
||||
if (auto* device = m_vnode->characterDevice())
|
||||
return static_cast<const TTY*>(device);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TTY* FileHandle::tty()
|
||||
TTY* FileDescriptor::tty()
|
||||
{
|
||||
if (auto* device = m_vnode->characterDevice())
|
||||
return static_cast<TTY*>(device);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int FileHandle::close()
|
||||
int FileDescriptor::close()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
String FileHandle::absolute_path() const
|
||||
String FileDescriptor::absolute_path() const
|
||||
{
|
||||
if (isTTY())
|
||||
return tty()->ttyName();
|
|
@ -7,12 +7,12 @@
|
|||
|
||||
class TTY;
|
||||
|
||||
class FileHandle : public Retainable<FileHandle> {
|
||||
class FileDescriptor : public Retainable<FileDescriptor> {
|
||||
public:
|
||||
static RetainPtr<FileHandle> create(RetainPtr<VirtualFileSystem::Node>&&);
|
||||
~FileHandle();
|
||||
static RetainPtr<FileDescriptor> create(RetainPtr<VirtualFileSystem::Node>&&);
|
||||
~FileDescriptor();
|
||||
|
||||
RetainPtr<FileHandle> clone();
|
||||
RetainPtr<FileDescriptor> clone();
|
||||
|
||||
int close();
|
||||
|
||||
|
@ -48,7 +48,7 @@ public:
|
|||
|
||||
private:
|
||||
friend class VirtualFileSystem;
|
||||
explicit FileHandle(RetainPtr<VirtualFileSystem::Node>&&);
|
||||
explicit FileDescriptor(RetainPtr<VirtualFileSystem::Node>&&);
|
||||
|
||||
RetainPtr<VirtualFileSystem::Node> m_vnode;
|
||||
|
||||
|
@ -57,7 +57,6 @@ private:
|
|||
ByteBuffer m_generatorCache;
|
||||
|
||||
#ifdef SERENITY
|
||||
int m_fd { -1 };
|
||||
bool m_isBlocking { true };
|
||||
#endif
|
||||
};
|
|
@ -64,7 +64,7 @@ String FileSystem::nameOfChildInDirectory(InodeIdentifier parent, InodeIdentifie
|
|||
return name;
|
||||
}
|
||||
|
||||
ByteBuffer FileSystem::readEntireInode(InodeIdentifier inode, FileHandle* handle) const
|
||||
ByteBuffer FileSystem::readEntireInode(InodeIdentifier inode, FileDescriptor* handle) const
|
||||
{
|
||||
ASSERT(inode.fileSystemID() == id());
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
static const dword mepoch = 476763780;
|
||||
|
||||
class FileHandle;
|
||||
class FileDescriptor;
|
||||
|
||||
class FileSystem : public Retainable<FileSystem> {
|
||||
public:
|
||||
|
@ -32,7 +32,7 @@ public:
|
|||
virtual bool writeInode(InodeIdentifier, const ByteBuffer&) = 0;
|
||||
virtual InodeMetadata inodeMetadata(InodeIdentifier) const = 0;
|
||||
|
||||
virtual Unix::ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileHandle*) const = 0;
|
||||
virtual Unix::ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const = 0;
|
||||
|
||||
struct DirectoryEntry {
|
||||
String name;
|
||||
|
@ -48,7 +48,7 @@ public:
|
|||
virtual InodeIdentifier findParentOfInode(InodeIdentifier) const = 0;
|
||||
|
||||
InodeIdentifier childOfDirectoryInodeWithName(InodeIdentifier, const String& name) const;
|
||||
ByteBuffer readEntireInode(InodeIdentifier, FileHandle* = nullptr) const;
|
||||
ByteBuffer readEntireInode(InodeIdentifier, FileDescriptor* = nullptr) const;
|
||||
String nameOfChildInDirectory(InodeIdentifier parent, InodeIdentifier child) const;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "SyntheticFileSystem.h"
|
||||
#include "FileHandle.h"
|
||||
#include "FileDescriptor.h"
|
||||
#include <AK/StdLib.h>
|
||||
|
||||
#ifndef SERENITY
|
||||
|
@ -192,7 +192,7 @@ bool SyntheticFileSystem::writeInode(InodeIdentifier, const ByteBuffer&)
|
|||
return false;
|
||||
}
|
||||
|
||||
Unix::ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileHandle* handle) const
|
||||
Unix::ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor* handle) const
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
virtual InodeMetadata inodeMetadata(InodeIdentifier) const override;
|
||||
virtual bool setModificationTime(InodeIdentifier, dword timestamp) override;
|
||||
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) override;
|
||||
virtual Unix::ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileHandle*) const override;
|
||||
virtual Unix::ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileDescriptor*) const override;
|
||||
virtual InodeIdentifier makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t) override;
|
||||
virtual InodeIdentifier findParentOfInode(InodeIdentifier) const override;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "VirtualFileSystem.h"
|
||||
#include "FileHandle.h"
|
||||
#include "FileDescriptor.h"
|
||||
#include "FileSystem.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/kmalloc.h>
|
||||
|
@ -398,15 +398,15 @@ bool VirtualFileSystem::touch(const String& path)
|
|||
return inode.fileSystem()->setModificationTime(inode, ktime(nullptr));
|
||||
}
|
||||
|
||||
RetainPtr<FileHandle> VirtualFileSystem::open(CharacterDevice& device, int options)
|
||||
RetainPtr<FileDescriptor> VirtualFileSystem::open(CharacterDevice& device, int options)
|
||||
{
|
||||
auto vnode = getOrCreateNode(device);
|
||||
if (!vnode)
|
||||
return nullptr;
|
||||
return FileHandle::create(move(vnode));
|
||||
return FileDescriptor::create(move(vnode));
|
||||
}
|
||||
|
||||
RetainPtr<FileHandle> VirtualFileSystem::open(const String& path, int& error, int options, InodeIdentifier base)
|
||||
RetainPtr<FileDescriptor> VirtualFileSystem::open(const String& path, int& error, int options, InodeIdentifier base)
|
||||
{
|
||||
auto inode = resolvePath(path, error, base, options);
|
||||
if (!inode.isValid())
|
||||
|
@ -414,10 +414,10 @@ RetainPtr<FileHandle> VirtualFileSystem::open(const String& path, int& error, in
|
|||
auto vnode = getOrCreateNode(inode);
|
||||
if (!vnode)
|
||||
return nullptr;
|
||||
return FileHandle::create(move(vnode));
|
||||
return FileDescriptor::create(move(vnode));
|
||||
}
|
||||
|
||||
RetainPtr<FileHandle> VirtualFileSystem::create(const String& path, InodeIdentifier base)
|
||||
RetainPtr<FileDescriptor> VirtualFileSystem::create(const String& path, InodeIdentifier base)
|
||||
{
|
||||
// FIXME: Do the real thing, not just this fake thing!
|
||||
(void) path;
|
||||
|
@ -425,7 +425,7 @@ RetainPtr<FileHandle> VirtualFileSystem::create(const String& path, InodeIdentif
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
RetainPtr<FileHandle> VirtualFileSystem::mkdir(const String& path, InodeIdentifier base)
|
||||
RetainPtr<FileDescriptor> VirtualFileSystem::mkdir(const String& path, InodeIdentifier base)
|
||||
{
|
||||
// FIXME: Do the real thing, not just this fake thing!
|
||||
(void) path;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#define O_NOFOLLOW_NOERROR 0x4000000
|
||||
|
||||
class CharacterDevice;
|
||||
class FileHandle;
|
||||
class FileDescriptor;
|
||||
|
||||
inline constexpr dword encodedDevice(unsigned major, unsigned minor)
|
||||
{
|
||||
|
@ -93,10 +93,10 @@ public:
|
|||
bool mountRoot(RetainPtr<FileSystem>&&);
|
||||
bool mount(RetainPtr<FileSystem>&&, const String& path);
|
||||
|
||||
RetainPtr<FileHandle> open(CharacterDevice&, int options);
|
||||
RetainPtr<FileHandle> open(const String& path, int& error, int options = 0, InodeIdentifier base = InodeIdentifier());
|
||||
RetainPtr<FileHandle> create(const String& path, InodeIdentifier base = InodeIdentifier());
|
||||
RetainPtr<FileHandle> mkdir(const String& path, InodeIdentifier base = InodeIdentifier());
|
||||
RetainPtr<FileDescriptor> open(CharacterDevice&, int options);
|
||||
RetainPtr<FileDescriptor> open(const String& path, int& error, int options = 0, InodeIdentifier base = InodeIdentifier());
|
||||
RetainPtr<FileDescriptor> create(const String& path, InodeIdentifier base = InodeIdentifier());
|
||||
RetainPtr<FileDescriptor> mkdir(const String& path, InodeIdentifier base = InodeIdentifier());
|
||||
|
||||
bool isRoot(InodeIdentifier) const;
|
||||
|
||||
|
@ -110,7 +110,7 @@ public:
|
|||
String absolutePath(InodeIdentifier);
|
||||
|
||||
private:
|
||||
friend class FileHandle;
|
||||
friend class FileDescriptor;
|
||||
|
||||
void enumerateDirectoryInode(InodeIdentifier, Function<bool(const FileSystem::DirectoryEntry&)>);
|
||||
InodeIdentifier resolvePath(const String& path, int& error, InodeIdentifier base = InodeIdentifier(), int options = 0);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "Ext2FileSystem.h"
|
||||
#include "FileBackedDiskDevice.h"
|
||||
#include "VirtualFileSystem.h"
|
||||
#include "FileHandle.h"
|
||||
#include "FileDescriptor.h"
|
||||
#include "SyntheticFileSystem.h"
|
||||
#include "ZeroDevice.h"
|
||||
#include "NullDevice.h"
|
||||
|
@ -54,12 +54,12 @@ int main(int c, char** v)
|
|||
|
||||
if (!strcmp(v[0], "./vcat")) {
|
||||
int error;
|
||||
auto handle = vfs.open(v[2], error);
|
||||
if (!handle) {
|
||||
auto descriptor = vfs.open(v[2], error);
|
||||
if (!descriptor) {
|
||||
printf("failed to open %s inside fs image\n", v[2]);
|
||||
return 1;
|
||||
}
|
||||
auto contents = handle->readEntireFile();
|
||||
auto contents = descriptor->readEntireFile();
|
||||
|
||||
FILE* fout = fopen(v[3], "w");
|
||||
if (!fout) {
|
||||
|
@ -82,11 +82,11 @@ int main(int c, char** v)
|
|||
vfs.listDirectory("/syn");
|
||||
|
||||
#if 0
|
||||
auto handle = vfs.open("/home/andreas/../../home/./andreas/./file2");
|
||||
printf("handle = %p\n", handle.ptr());
|
||||
ASSERT(handle);
|
||||
auto descriptor = vfs.open("/home/andreas/../../home/./andreas/./file2");
|
||||
printf("descriptor = %p\n", handle.ptr());
|
||||
ASSERT(descriptor);
|
||||
|
||||
auto contents = handle->readEntireFile();
|
||||
auto contents = descriptor->readEntireFile();
|
||||
ASSERT(contents);
|
||||
|
||||
printf("contents: '%s'\n", contents->pointer());
|
||||
|
@ -151,13 +151,13 @@ int main(int c, char** v)
|
|||
char buf[1024];
|
||||
sprintf(buf, "%s/%s", currentDirectory.characters(), parts[1].characters());
|
||||
int error;
|
||||
auto handle = vfs.open(buf, error);
|
||||
if (!handle) {
|
||||
auto descriptor = vfs.open(buf, error);
|
||||
if (!descriptor) {
|
||||
printf("Can't open '%s' :(\n", buf);
|
||||
continue;
|
||||
}
|
||||
Unix::stat st;
|
||||
int rc = handle->stat(&st);
|
||||
int rc = descriptor->stat(&st);
|
||||
if (rc < 0) {
|
||||
printf("stat failed: %d\n", rc);
|
||||
continue;
|
||||
|
@ -182,12 +182,12 @@ int main(int c, char** v)
|
|||
char pathbuf[1024];
|
||||
sprintf(pathbuf, "%s/%s", currentDirectory.characters(), parts[1].characters());
|
||||
int error;
|
||||
auto handle = vfs.open(pathbuf, error);
|
||||
if (!handle) {
|
||||
auto descriptor = vfs.open(pathbuf, error);
|
||||
if (!descriptor) {
|
||||
printf("failed to open %s\n", pathbuf);
|
||||
continue;
|
||||
}
|
||||
auto contents = handle->readEntireFile();
|
||||
auto contents = descriptor->readEntireFile();
|
||||
fwrite(contents.pointer(), sizeof(char), contents.size(), stdout);
|
||||
continue;
|
||||
}
|
||||
|
@ -196,15 +196,15 @@ int main(int c, char** v)
|
|||
char pathbuf[1024];
|
||||
sprintf(pathbuf, "%s/%s", currentDirectory.characters(), parts[1].characters());
|
||||
int error;
|
||||
auto handle = vfs.open(pathbuf, error);
|
||||
if (!handle) {
|
||||
auto descriptor = vfs.open(pathbuf, error);
|
||||
if (!descriptor) {
|
||||
printf("failed to open %s\n", pathbuf);
|
||||
continue;
|
||||
}
|
||||
ssize_t nread;
|
||||
byte buffer[512];
|
||||
for (;;) {
|
||||
nread = handle->read(buffer, sizeof(buffer));
|
||||
nread = descriptor->read(buffer, sizeof(buffer));
|
||||
if (nread <= 0)
|
||||
break;
|
||||
fwrite(buffer, 1, nread, stdout);
|
||||
|
|
Loading…
Reference in a new issue