Miosix  2.0alpha1
miosix::FileBase Class Referenceabstract

#include <file.h>

Inheritance diagram for miosix::FileBase:
Collaboration diagram for miosix::FileBase:

Public Member Functions

 FileBase (intrusive_ref_ptr< FilesystemBase > parent)
 
virtual ssize_t write (const void *data, size_t len)=0
 
virtual ssize_t read (void *data, size_t len)=0
 
virtual off_t lseek (off_t pos, int whence)=0
 
virtual int fstat (struct stat *pstat) const =0
 
virtual int isatty () const
 
virtual int fcntl (int cmd, int opt)
 
virtual int ioctl (int cmd, void *arg)
 
virtual int getdents (void *dp, int len)
 
const intrusive_ref_ptr
< FilesystemBase
getParent () const
 
virtual ~FileBase ()
 

Additional Inherited Members

- Protected Member Functions inherited from miosix::IntrusiveRefCounted
 IntrusiveRefCounted ()
 
 IntrusiveRefCounted (const IntrusiveRefCounted &)
 
IntrusiveRefCountedoperator= (const IntrusiveRefCounted &)
 

Detailed Description

The unix file abstraction. Also some device drivers are seen as files. Classes of this type are reference counted, must be allocated on the heap and managed through intrusive_ref_ptr<FileBase>

Constructor & Destructor Documentation

miosix::FileBase::FileBase ( intrusive_ref_ptr< FilesystemBase parent)

Constructor

Parameters
parentthe filesystem to which this file belongs
miosix::FileBase::~FileBase ( )
virtual

File destructor

Member Function Documentation

int miosix::FileBase::fcntl ( int  cmd,
int  opt 
)
virtual

Perform various operations on a file descriptor

Parameters
cmdspecifies the operation to perform
optoptional argument that some operation require
Returns
the exact return value depends on CMD, -1 is returned on error
virtual int miosix::FileBase::fstat ( struct stat *  pstat) const
pure virtual

Return file information.

Parameters
pstatpointer to stat struct
Returns
0 on success, or a negative number on failure

Implemented in miosix::Fat32File, miosix::DirectoryBase, miosix::DevFsFile, and miosix::TerminalDevice.

int miosix::FileBase::getdents ( void *  dp,
int  len 
)
virtual

Also directories can be opened as files. In this case, this system call allows to retrieve directory entries.

Parameters
dppointer to a memory buffer where one or more struct dirent will be placed. dp must be four words aligned.
lenmemory buffer size.
Returns
the number of bytes read on success, or a negative number on failure.

Reimplemented in miosix::Fat32Directory, and miosix::MountpointFsDirectory.

const intrusive_ref_ptr<FilesystemBase> miosix::FileBase::getParent ( ) const
inline
Returns
a pointer to the parent filesystem
int miosix::FileBase::ioctl ( int  cmd,
void *  arg 
)
virtual

Perform various operations on a file descriptor

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

Reimplemented in miosix::Fat32File, miosix::DevFsFile, and miosix::TerminalDevice.

int miosix::FileBase::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

Reimplemented in miosix::DevFsFile, and miosix::TerminalDevice.

virtual off_t miosix::FileBase::lseek ( off_t  pos,
int  whence 
)
pure virtual

Move file pointer, if the file supports random-access.

Parameters
posoffset to sum to the beginning of the file, current position or end of file, depending on whence
whenceSEEK_SET, SEEK_CUR or SEEK_END
Returns
the offset from the beginning of the file if the operation completed, or a negative number in case of errors

Implemented in miosix::Fat32File, miosix::DirectoryBase, miosix::DevFsFile, and miosix::TerminalDevice.

virtual ssize_t miosix::FileBase::read ( void *  data,
size_t  len 
)
pure virtual

Read data from the file, if the file supports reading.

Parameters
databuffer to store read data
lenthe number of bytes to read
Returns
the number of read characters, or a negative number in case of errors

Implemented in miosix::Fat32File, miosix::DirectoryBase, miosix::DevFsFile, and miosix::TerminalDevice.

virtual ssize_t miosix::FileBase::write ( const void *  data,
size_t  len 
)
pure virtual

Write data to the file, if the file supports writing.

Parameters
datathe data to write
lenthe number of bytes to write
Returns
the number of written characters, or a negative number in case of errors

Implemented in miosix::Fat32File, miosix::DirectoryBase, miosix::DevFsFile, and miosix::TerminalDevice.


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