Miosix  2.01
miosix::Device Class Reference

#include <devfs.h>

Inheritance diagram for miosix::Device:
Collaboration diagram for miosix::Device:

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< Deviceshared_from_this ()
 
intrusive_ref_ptr< const Deviceshared_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 &)
 
IntrusiveRefCountedoperator= (const IntrusiveRefCounted &)
 

Detailed Description

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

Member Enumeration Documentation

Possible device types

Enumerator
STREAM 

Not seekable device, like /dev/random.

BLOCK 

Seekable block device.

TTY 

Like STREAM, but additionally is a TTY.

Constructor & Destructor Documentation

miosix::Device::Device ( DeviceType  d)
inline

Constructor

Parameters
ddevice type
miosix::Device::~Device ( )
virtual

Destructor

Member Function Documentation

int miosix::Device::fstat ( struct stat *  pstat) const

Obtain information for the file type managed by this Device

Parameters
pstatfile information is stored here
Returns
0 on success, or a negative number on failure
int miosix::Device::ioctl ( int  cmd,
void *  arg 
)
virtual

Performs device-specific operations

Parameters
cmdspecifies the operation to perform
argoptional argument that some operation require
Returns
the exact return value depends on CMD, -1 is returned on error
void miosix::Device::IRQwrite ( const char *  str)
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.

Parameters
strthe string to write. The string must be NUL terminated.
int miosix::Device::isatty ( ) const
virtual

Check whether the file refers to a terminal.

Returns
1 if it is a terminal, 0 if it is not, or a negative number in case of errors
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

Parameters
filethe file object will be stored here, if the call succeeds
fspointer to the DevFs
flagsfile flags (open for reading, writing, ...)
modefile permissions
Returns
0 on success, or a negative number on failure
ssize_t miosix::Device::readBlock ( void *  buffer,
size_t  size,
off_t  where 
)
virtual

Read a block of data

Parameters
bufferbuffer where read data will be stored
sizebuffer size
wherewhere to read from
Returns
number of bytes read or a negative number on failure
ssize_t miosix::Device::writeBlock ( const void *  buffer,
size_t  size,
off_t  where 
)
virtual

Write a block of data

Parameters
bufferbuffer where take data to write
sizebuffer size
wherewhere to write to
Returns
number of bytes written or a negative number on failure

The documentation for this class was generated from the following files: