mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:37:35 +00:00
More work towards getting bash to build.
Implemented some syscalls: dup(), dup2(), getdtablesize(). FileHandle is now a retainable, since that's needed for dup()'ed fd's. I didn't really test any of this beyond a basic smoke check.
This commit is contained in:
parent
82f84bab11
commit
9f2b9c82bf
17 changed files with 114 additions and 23 deletions
|
@ -4,7 +4,7 @@ CharacterDevice::~CharacterDevice()
|
|||
{
|
||||
}
|
||||
|
||||
OwnPtr<FileHandle> CharacterDevice::open(int options)
|
||||
RetainPtr<FileHandle> CharacterDevice::open(int options)
|
||||
{
|
||||
return VirtualFileSystem::the().open(*this, options);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ class CharacterDevice {
|
|||
public:
|
||||
virtual ~CharacterDevice();
|
||||
|
||||
virtual OwnPtr<FileHandle> open(int options);
|
||||
RetainPtr<FileHandle> open(int options);
|
||||
|
||||
virtual bool hasDataAvailableForRead() const = 0;
|
||||
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
#include "TTY.h"
|
||||
#include <AK/BufferStream.h>
|
||||
|
||||
RetainPtr<FileHandle> FileHandle::create(RetainPtr<VirtualFileSystem::Node>&& vnode)
|
||||
{
|
||||
return adopt(*new FileHandle(move(vnode)));
|
||||
}
|
||||
|
||||
FileHandle::FileHandle(RetainPtr<VirtualFileSystem::Node>&& vnode)
|
||||
: m_vnode(move(vnode))
|
||||
{
|
||||
|
@ -15,9 +20,9 @@ FileHandle::~FileHandle()
|
|||
{
|
||||
}
|
||||
|
||||
OwnPtr<FileHandle> FileHandle::clone()
|
||||
RetainPtr<FileHandle> FileHandle::clone()
|
||||
{
|
||||
auto handle = make<FileHandle>(m_vnode.copyRef());
|
||||
auto handle = FileHandle::create(m_vnode.copyRef());
|
||||
if (!handle)
|
||||
return nullptr;
|
||||
handle->m_currentOffset = m_currentOffset;
|
||||
|
|
|
@ -3,15 +3,16 @@
|
|||
#include "VirtualFileSystem.h"
|
||||
#include "InodeMetadata.h"
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Retainable.h>
|
||||
|
||||
class TTY;
|
||||
|
||||
class FileHandle {
|
||||
class FileHandle : public Retainable<FileHandle> {
|
||||
public:
|
||||
explicit FileHandle(RetainPtr<VirtualFileSystem::Node>&&);
|
||||
static RetainPtr<FileHandle> create(RetainPtr<VirtualFileSystem::Node>&&);
|
||||
~FileHandle();
|
||||
|
||||
OwnPtr<FileHandle> clone();
|
||||
RetainPtr<FileHandle> clone();
|
||||
|
||||
int close();
|
||||
|
||||
|
@ -39,9 +40,6 @@ public:
|
|||
VirtualFileSystem::Node* vnode() { return m_vnode.ptr(); }
|
||||
|
||||
#ifdef SERENITY
|
||||
int fd() const { return m_fd; }
|
||||
void setFD(int fd) { m_fd = fd; }
|
||||
|
||||
bool isBlocking() const { return m_isBlocking; }
|
||||
void setBlocking(bool b) { m_isBlocking = b; }
|
||||
#endif
|
||||
|
@ -50,6 +48,7 @@ public:
|
|||
|
||||
private:
|
||||
friend class VirtualFileSystem;
|
||||
explicit FileHandle(RetainPtr<VirtualFileSystem::Node>&&);
|
||||
|
||||
RetainPtr<VirtualFileSystem::Node> m_vnode;
|
||||
|
||||
|
|
|
@ -398,15 +398,15 @@ bool VirtualFileSystem::touch(const String& path)
|
|||
return inode.fileSystem()->setModificationTime(inode, ktime(nullptr));
|
||||
}
|
||||
|
||||
OwnPtr<FileHandle> VirtualFileSystem::open(CharacterDevice& device, int options)
|
||||
RetainPtr<FileHandle> VirtualFileSystem::open(CharacterDevice& device, int options)
|
||||
{
|
||||
auto vnode = getOrCreateNode(device);
|
||||
if (!vnode)
|
||||
return nullptr;
|
||||
return make<FileHandle>(move(vnode));
|
||||
return FileHandle::create(move(vnode));
|
||||
}
|
||||
|
||||
OwnPtr<FileHandle> VirtualFileSystem::open(const String& path, int& error, int options, InodeIdentifier base)
|
||||
RetainPtr<FileHandle> 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 @@ OwnPtr<FileHandle> VirtualFileSystem::open(const String& path, int& error, int o
|
|||
auto vnode = getOrCreateNode(inode);
|
||||
if (!vnode)
|
||||
return nullptr;
|
||||
return make<FileHandle>(move(vnode));
|
||||
return FileHandle::create(move(vnode));
|
||||
}
|
||||
|
||||
OwnPtr<FileHandle> VirtualFileSystem::create(const String& path, InodeIdentifier base)
|
||||
RetainPtr<FileHandle> VirtualFileSystem::create(const String& path, InodeIdentifier base)
|
||||
{
|
||||
// FIXME: Do the real thing, not just this fake thing!
|
||||
(void) path;
|
||||
|
@ -425,7 +425,7 @@ OwnPtr<FileHandle> VirtualFileSystem::create(const String& path, InodeIdentifier
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
OwnPtr<FileHandle> VirtualFileSystem::mkdir(const String& path, InodeIdentifier base)
|
||||
RetainPtr<FileHandle> VirtualFileSystem::mkdir(const String& path, InodeIdentifier base)
|
||||
{
|
||||
// FIXME: Do the real thing, not just this fake thing!
|
||||
(void) path;
|
||||
|
|
|
@ -93,10 +93,10 @@ public:
|
|||
bool mountRoot(RetainPtr<FileSystem>&&);
|
||||
bool mount(RetainPtr<FileSystem>&&, const String& path);
|
||||
|
||||
OwnPtr<FileHandle> open(CharacterDevice&, int options);
|
||||
OwnPtr<FileHandle> open(const String& path, int& error, int options = 0, InodeIdentifier base = InodeIdentifier());
|
||||
OwnPtr<FileHandle> create(const String& path, InodeIdentifier base = InodeIdentifier());
|
||||
OwnPtr<FileHandle> mkdir(const String& path, InodeIdentifier base = InodeIdentifier());
|
||||
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());
|
||||
|
||||
bool isRoot(InodeIdentifier) const;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue