2019-02-16 02:47:20 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-04-24 03:37:57 +03:00
|
|
|
// Device is the base class of everything that lives in the /dev directory.
|
|
|
|
//
|
|
|
|
// All Devices will automatically register with the VFS.
|
|
|
|
// To expose a Device to the filesystem, simply pass two unique numbers to the constructor,
|
|
|
|
// and then mknod a file in /dev with those numbers.
|
|
|
|
//
|
|
|
|
// There are two main subclasses:
|
|
|
|
// - BlockDevice (random access)
|
|
|
|
// - CharacterDevice (sequential)
|
2019-07-09 15:46:23 +03:00
|
|
|
#include <Kernel/FileSystem/File.h>
|
2019-04-29 05:55:54 +03:00
|
|
|
#include <Kernel/UnixTypes.h>
|
2019-02-16 02:47:20 +03:00
|
|
|
|
2019-04-28 16:02:55 +03:00
|
|
|
class Device : public File {
|
2019-02-16 02:47:20 +03:00
|
|
|
public:
|
2019-04-28 16:02:55 +03:00
|
|
|
virtual ~Device() override;
|
2019-02-16 02:47:20 +03:00
|
|
|
|
|
|
|
unsigned major() const { return m_major; }
|
|
|
|
unsigned minor() const { return m_minor; }
|
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
virtual String absolute_path(const FileDescription&) const override;
|
2019-02-16 02:47:20 +03:00
|
|
|
|
|
|
|
uid_t uid() const { return m_uid; }
|
|
|
|
uid_t gid() const { return m_gid; }
|
|
|
|
|
2019-04-28 16:02:55 +03:00
|
|
|
virtual bool is_device() const override { return true; }
|
2019-02-16 11:57:42 +03:00
|
|
|
|
2019-02-16 02:47:20 +03:00
|
|
|
protected:
|
2019-02-17 12:38:07 +03:00
|
|
|
Device(unsigned major, unsigned minor);
|
2019-02-16 02:47:20 +03:00
|
|
|
void set_uid(uid_t uid) { m_uid = uid; }
|
|
|
|
void set_gid(gid_t gid) { m_gid = gid; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned m_major { 0 };
|
|
|
|
unsigned m_minor { 0 };
|
|
|
|
uid_t m_uid { 0 };
|
|
|
|
gid_t m_gid { 0 };
|
|
|
|
};
|