Kernel: Add File, a base class for anything that a FileDescriptor can wrap.

FileDescriptor is getting out of control, and the layering isn't quite right
so let's make a File class that everything can inherit from. Then we can
stop worrying about all kinds of specifics in FileDescriptor.
This commit is contained in:
Andreas Kling 2019-04-28 14:53:50 +02:00
parent 75734aa003
commit 7ec1f6ab3c
2 changed files with 67 additions and 0 deletions

31
Kernel/File.cpp Normal file
View file

@ -0,0 +1,31 @@
#include <Kernel/File.h>
#include <Kernel/FileSystem/FileDescriptor.h>
File::File()
{
}
File::~File()
{
}
KResultOr<Retained<FileDescriptor>> File::open(int options)
{
UNUSED_PARAM(options);
return FileDescriptor::create(this);
}
void File::close()
{
}
int File::ioctl(Process&, unsigned, unsigned)
{
return -ENOTTY;
}
KResultOr<Region*> File::mmap(Process&, LinearAddress, size_t, size_t)
{
return KResult(-ENODEV);
}

36
Kernel/File.h Normal file
View file

@ -0,0 +1,36 @@
#include <AK/Retainable.h>
#include <AK/Types.h>
#include <Kernel/FileSystem/FileDescriptor.h>
class Process;
class File : public Retainable<File> {
public:
virtual ~File();
virtual KResultOr<Retained<FileDescriptor>> open(int options);
virtual void close();
virtual bool can_read(Process&) const = 0;
virtual bool can_write(Process&) const = 0;
virtual ssize_t read(Process&, byte*, ssize_t) = 0;
virtual ssize_t write(Process&, const byte*, ssize_t) = 0;
virtual int ioctl(Process&, unsigned request, unsigned arg);
virtual KResultOr<Region*> mmap(Process&, LinearAddress preferred_laddr, size_t offset, size_t size);
virtual String absolute_path() const = 0;
virtual const char* class_name() const = 0;
virtual bool is_seekable() const { return false; }
virtual bool is_device() const { return false; }
virtual bool is_tty() const { return false; }
virtual bool is_master_pty() const { return false; }
virtual bool is_block_device() const { return false; }
virtual bool is_character_device() const { return false; }
protected:
File();
};