mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:37:35 +00:00
Rename FileHandle to FileDescriptor.
This commit is contained in:
parent
e088121b3a
commit
83172e6a4b
18 changed files with 160 additions and 154 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue