diff --git a/kernel/include/fs/devfs.hpp b/kernel/include/fs/devfs.hpp index fdc2fd55..acf62410 100644 --- a/kernel/include/fs/devfs.hpp +++ b/kernel/include/fs/devfs.hpp @@ -21,16 +21,83 @@ enum class device_type { CHAR_DEVICE }; +/*! + * \brief Block device driver interface + */ struct dev_driver { + /*! + * \brief Read a block of data + * \param data The driver data + * \param buffer The buffer into which to read + * \param count The amount of bytes to read + * \param offset The offset at which to start reading + * \param read output reference to indicate the number of bytes read + * \return 0 on success, an error code otherwise + */ virtual size_t read(void* data, char* buffer, size_t count, size_t offset, size_t& read) = 0; + + /*! + * \brief Write a block of data + * \param data The driver data + * \param buffer The buffer from which to read + * \param count The amount of bytes to write + * \param offset The offset at which to start writing + * \param written output reference to indicate the number of bytes written + * \return 0 on success, an error code otherwise + */ virtual size_t write(void* data, const char* buffer, size_t count, size_t offset, size_t& written) = 0; + + /*! + * \brief Clear a portion of a file (write zeroes) + * \param data The driver data + * \param count The amount of bytes to write + * \param offset The offset at which to start writing + * \param written output reference to indicate the number of bytes written + * \return 0 on success, an error code otherwise + */ virtual size_t clear(void* data, size_t count, size_t offset, size_t& written) = 0; + + /*! + * \brief Return the size of the device + * \param data The driver data + * \return The size of the device + */ virtual size_t size(void* data) = 0; }; +/*! + * \brief Character device driver interface + */ struct char_driver { + /*! + * \brief Read a block of data + * \param data The driver data + * \param buffer The buffer into which to read + * \param count The amount of bytes to read + * \param read output reference to indicate the number of bytes read + * \return 0 on success, an error code otherwise + */ virtual size_t read(void* data, char* buffer, size_t count, size_t& read) = 0; + + /*! + * \brief Read a block of data only waiting for a given amount of time + * \param data The driver data + * \param buffer The buffer into which to read + * \param count The amount of bytes to read + * \param read output reference to indicate the number of bytes read + * \param ms The amount of time, in milliseconds, to wait for the read + * \return 0 on success, an error code otherwise + */ virtual size_t read(void* data, char* buffer, size_t count, size_t& read, size_t ms) = 0; + + /*! + * \brief Write a block of data + * \param data The driver data + * \param buffer The buffer from which to read + * \param count The amount of bytes to write + * \param written output reference to indicate the number of bytes written + * \return 0 on success, an error code otherwise + */ virtual size_t write(void* data, const char* buffer, size_t count, size_t& written) = 0; };