Miosix
2.0alpha1
|
#include <devfs.h>
Public Types | |
enum | DeviceType { STREAM, BLOCK, TTY } |
Public Member Functions | |
Device (DeviceType d) | |
int | open (intrusive_ref_ptr< FileBase > &file, intrusive_ref_ptr< FilesystemBase > fs, int flags, int mode) |
int | fstat (struct stat *pstat) const |
virtual int | isatty () const |
virtual ssize_t | readBlock (void *buffer, size_t size, off_t where) |
virtual ssize_t | writeBlock (const void *buffer, size_t size, off_t where) |
virtual void | IRQwrite (const char *str) |
virtual int | ioctl (int cmd, void *arg) |
virtual | ~Device () |
Public Member Functions inherited from miosix::IntrusiveRefCountedSharedFromThis< Device > | |
IntrusiveRefCountedSharedFromThis () | |
intrusive_ref_ptr< Device > | shared_from_this () |
intrusive_ref_ptr< const Device > | shared_from_this () const |
virtual | ~IntrusiveRefCountedSharedFromThis () |
Protected Attributes | |
unsigned int | st_ino |
inode of device file | |
short | st_dev |
device (unique id of the filesystem) of device file | |
const bool | seekable |
If true, device is seekable. | |
const bool | block |
If true, it is a block device. | |
const bool | tty |
If true, it is a tty. | |
Additional Inherited Members | |
Protected Member Functions inherited from miosix::IntrusiveRefCounted | |
IntrusiveRefCounted () | |
IntrusiveRefCounted (const IntrusiveRefCounted &) | |
IntrusiveRefCounted & | operator= (const IntrusiveRefCounted &) |
Instances of this class are devices inside DevFs. When open is called, a DevFsFile is returned, which has its own seek point so that multiple files can be opened on the same device retaining an unique seek point. A DevFsFile then calls readBlock() and writeBlock() on this class. These functions have a third argument which is the seek point, making them stateless.
Individual devices must subclass Device and reimplement readBlock(), writeBlock() and ioctl() as needed. A mutex may be required as multiple concurrent readBlock(), writeBlock() and ioctl() can occur.
Classes of this type are reference counted, must be allocated on the heap and managed through intrusive_ref_ptr<FileBase>
This class is defined also if WITH_DEVFS is not defined as it is used by the Console interface, but in this case the interface is reduced to a minimum
|
inline |
Constructor
d | device type |
|
virtual |
Destructor
int miosix::Device::fstat | ( | struct stat * | pstat | ) | const |
Obtain information for the file type managed by this Device
pstat | file information is stored here |
|
virtual |
Performs device-specific operations
cmd | specifies the operation to perform |
arg | optional argument that some operation require |
|
virtual |
Write a string. An extension to the Device interface that adds a new member function, which is used by the kernel on console devices to write debug information before the kernel is started or in case of serious errors, right before rebooting. Can ONLY be called when the kernel is not yet started, paused or within an interrupt. This default implementation ignores writes.
str | the string to write. The string must be NUL terminated. |
|
virtual |
Check whether the file refers to a terminal.
int miosix::Device::open | ( | intrusive_ref_ptr< FileBase > & | file, |
intrusive_ref_ptr< FilesystemBase > | fs, | ||
int | flags, | ||
int | mode | ||
) |
Return an instance of the file type managed by this Device
file | the file object will be stored here, if the call succeeds |
fs | pointer to the DevFs |
flags | file flags (open for reading, writing, ...) |
mode | file permissions |
|
virtual |
Read a block of data
buffer | buffer where read data will be stored |
size | buffer size |
where | where to read from |
|
virtual |
Write a block of data
buffer | buffer where take data to write |
size | buffer size |
where | where to write to |