summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-04-28 14:53:50 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-04-28 14:53:50 +0200
commit7ec1f6ab3c4ea71d51757ce689a6b4a991b121a0 (patch)
tree20d83703e3c68467419ace179cc4a34004a0b09f /Kernel
parent75734aa00377bd1f29dd4e1fd805fe0928e5d6a5 (diff)
downloadserenity-7ec1f6ab3c4ea71d51757ce689a6b4a991b121a0.zip
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.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/File.cpp31
-rw-r--r--Kernel/File.h36
2 files changed, 67 insertions, 0 deletions
diff --git a/Kernel/File.cpp b/Kernel/File.cpp
new file mode 100644
index 0000000000..8f09ad25e8
--- /dev/null
+++ b/Kernel/File.cpp
@@ -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);
+}
+
diff --git a/Kernel/File.h b/Kernel/File.h
new file mode 100644
index 0000000000..51235cf5e0
--- /dev/null
+++ b/Kernel/File.h
@@ -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();
+};