Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
FileIO Class Referenceabstract

Base class for both Device and FileSystem objects. More...

#include <Devtab.hxx>

Inheritance diagram for FileIO:
Device FileSystem Node Null SPIFFS DccDecoder< Module > DeviceFile EEPROM I2C NonBlockNode Pic32mxCan Pipe RailcomDriverBase< HW > RailcomDriverBase< HW > RamDiskBase SPI Serial Socket TinyUsbCdc TivaDCC< HW > TivaFlash TivaNRZ< HW > TivaTestPacketSource< HW > SpiSPIFFS Stm32SPIFFS TiSPIFFS< ERASE_PAGE_SIZE >

Static Public Member Functions

static ssize_t read (struct _reent *reent, int fd, void *buf, size_t count)
 Read from a file or device.
 
static ssize_t write (struct _reent *reent, int fd, const void *buf, size_t count)
 Write to a file or device.
 
static _off_t lseek (struct _reent *reent, int fd, _off_t offset, int whence)
 Change the offset index of a file or device.
 
static int fstat (struct _reent *reent, int fd, struct stat *stat)
 Get the status information of a file or device.
 
static int ioctl (int fd, unsigned long int key, unsigned long data)
 Request and ioctl transaction.
 
static int fcntl (int fd, int cmd, unsigned long data)
 Manipulate a file descriptor.
 
static bool is_device (int fd)
 Test if the file descriptor belongs to a device.
 

Protected Member Functions

 FileIO (const char *name)
 Constructor.
 
virtual ~FileIO ()
 Destructor.
 
virtual int open (File *file, const char *path, int flags, int mode)=0
 Open a file or device.
 
virtual int close (File *file)=0
 Close a file or device.
 
virtual ssize_t read (File *file, void *buf, size_t count)=0
 Read from a file or device.
 
virtual ssize_t write (File *file, const void *buf, size_t count)=0
 Write to a file or device.
 
virtual off_t lseek (File *f, off_t offset, int whence)
 Seek method.
 
virtual int fstat (File *file, struct stat *stat)=0
 Get the status information of a file or device.
 
virtual int ioctl (File *file, unsigned long int key, unsigned long data)
 Request an ioctl transaction.
 
virtual int fcntl (File *file, int cmd, unsigned long data)
 Manipulate a file descriptor.
 
virtual bool select (File *file, int mode)
 Device select method.
 

Static Protected Member Functions

static int fd_alloc (void)
 Allocate a free file descriptor.
 
static void fd_free (int fd)
 Free up a file descriptor.
 
static Filefile_lookup (int fd)
 Looks up a reference to a File corresponding to a given file descriptor.
 
static int fd_lookup (File *file)
 Looks up a file descriptor corresponding to a given File reference.
 

Protected Attributes

const char * name
 device name
 

Static Protected Attributes

static const unsigned int numOpenFiles = 20
 
static File files []
 File descriptor pool.
 
static OSMutex mutex
 mutual exclusion for fileio
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (FileIO)
 

Friends

class Device
 Allow access from Device class.
 
class FileSystem
 Allow access from FileSystem class.
 

Detailed Description

Base class for both Device and FileSystem objects.

Definition at line 72 of file Devtab.hxx.

Constructor & Destructor Documentation

◆ FileIO()

FileIO::FileIO ( const char *  name)
inlineprotected

Constructor.

Parameters
namename of mount point in the root file system. Pointer must be valid throughout the entire lifetime.

Definition at line 144 of file Devtab.hxx.

◆ ~FileIO()

virtual FileIO::~FileIO ( )
inlineprotectedvirtual

Destructor.

Definition at line 150 of file Devtab.hxx.

Member Function Documentation

◆ close()

virtual int FileIO::close ( File file)
protectedpure virtual

Close a file or device.

Parameters
filefile reference for this device
Returns
0 upon success, -1 upon failure with errno containing the cause

Implemented in Node, Null, Pipe, CC32xxSocket, CC32xxSocket, FreeRTOSTCPSocket, and SPIFFS.

◆ fcntl() [1/2]

int FileIO::fcntl ( File file,
int  cmd,
unsigned long  data 
)
protectedvirtual

Manipulate a file descriptor.

Parameters
filefile reference for this device
cmdoperation to perform
dataparameter to the cmd operation
Returns
dependent on the operation (POSIX compliant where applicable) or negative error number upon error.

Reimplemented in Pipe, CC32xxSocket, CC32xxSocket, and FreeRTOSTCPSocket.

Definition at line 310 of file Fileio.cxx.

◆ fcntl() [2/2]

int FileIO::fcntl ( int  fd,
int  cmd,
unsigned long  data 
)
static

Manipulate a file descriptor.

Parameters
fdfile descriptor
cmdoperation to perform
dataparameter to the cmd operation
Returns
dependent on the operation (POSIX compliant where applicable) or -1 on error with errno set appropriately

Definition at line 233 of file Fileio.cxx.

◆ fd_alloc()

int FileIO::fd_alloc ( void  )
staticprotected

Allocate a free file descriptor.

This call must be made with the static Device::mutex locked.

Returns
file number on success, else -1 on failure
file number on success, else -1 on failure

Definition at line 47 of file Fileio.cxx.

◆ fd_free()

void FileIO::fd_free ( int  fd)
staticprotected

Free up a file descriptor.

Parameters
fdnumber to free up

Definition at line 71 of file Fileio.cxx.

◆ fd_lookup()

int FileIO::fd_lookup ( File file)
staticprotected

Looks up a file descriptor corresponding to a given File reference.

Parameters
fileis a reference to a File structure.
Returns
file descriptor (assert on error).

Definition at line 101 of file Fileio.cxx.

◆ file_lookup()

File * FileIO::file_lookup ( int  fd)
staticprotected

Looks up a reference to a File corresponding to a given file descriptor.

Parameters
fdis a file descriptor as supplied to the read-write-close-ioctl commands.
Returns
NULL and sets errno if fd is invalid, otherwise the File reference.

Definition at line 82 of file Fileio.cxx.

◆ fstat() [1/2]

virtual int FileIO::fstat ( File file,
struct stat *  stat 
)
protectedpure virtual

Get the status information of a file or device.

Parameters
filefile reference for this device
statstructure to fill status info into
Returns
0 upon successor or negative error number upon error.

Implemented in FileSystem, Node, FlashFile< FLASH >, Null, SPIFFS, CC32xxDeviceFile, and TivaEEPROMFile.

◆ fstat() [2/2]

int FileIO::fstat ( struct _reent *  reent,
int  fd,
struct stat *  stat 
)
static

Get the status information of a file or device.

Parameters
reentthread safe reentrant structure
fdfile descriptor to get status of
statstructure to fill status info into
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 186 of file Fileio.cxx.

◆ ioctl() [1/2]

int FileIO::ioctl ( File file,
unsigned long int  key,
unsigned long  data 
)
protectedvirtual

Request an ioctl transaction.

Parameters
filefile reference for this device
keyioctl key
datakey data
Returns
0 upon success or negative error number upon error.

Reimplemented in NonBlockNode, I2C, TCAN4550Can, MCP2515Can, RailcomDriverBase< HW >, RailcomDriverBase< HW >, Serial, Socket, SPI, TCAN4550Can, Stm32Can, Stm32Uart, CC32xxUart, TivaDCC< HW >, TivaUart, TivaCan, and TivaNRZ< HW >.

Definition at line 299 of file Fileio.cxx.

◆ ioctl() [2/2]

int FileIO::ioctl ( int  fd,
unsigned long int  key,
unsigned long  data 
)
static

Request and ioctl transaction.

Parameters
fdfile descriptor
keyioctl key
datakey data
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 209 of file Fileio.cxx.

◆ is_device()

static bool FileIO::is_device ( int  fd)
inlinestatic

Test if the file descriptor belongs to a device.

Parameters
fdfile descriptor
Returns
true if fd belongs to a device, false if belongs to a file system

Definition at line 134 of file Devtab.hxx.

◆ lseek() [1/2]

off_t FileIO::lseek ( File f,
off_t  offset,
int  whence 
)
protectedvirtual

Seek method.

Parameters
ffile reference for this device
offsetoffset in bytes from whence directive
whenceSEEK_SET if to set the file offset to an abosolute position, SEEK_CUR if to set the file offset from current position
Returns
current offest or negative error number upon error.
Parameters
ffile reference for this device
offsetoffset in bytes from whence directive
whenceSEEK_SET if to set the file offset to an abosolute position, SEEK_CUR if to set the file offset from current position
Returns
current offset, or -1 with errno set upon error.

Reimplemented in Pipe, Socket, SPIFFS, and EEPROM.

Definition at line 279 of file Fileio.cxx.

◆ lseek() [2/2]

_off_t FileIO::lseek ( struct _reent *  reent,
int  fd,
_off_t  offset,
int  whence 
)
static

Change the offset index of a file or device.

Parameters
reentthread save reentrant structure
fdfile descriptor to seek
offsetoffset within file
whencetype of seek to complete
Returns
resulting offset from beginning of file, -1 upon failure with errno containing the cause

Definition at line 163 of file Fileio.cxx.

◆ open()

virtual int FileIO::open ( File file,
const char *  path,
int  flags,
int  mode 
)
protectedpure virtual

Open a file or device.

Parameters
filefile reference for this device
pathfile or device name
flagsopen flags
modeopen mode, ignored in this implementation
Returns
0 upon success, -1 upon failure with errno containing the cause

Implemented in Node, Null, RamDiskBase, DeviceFile, EEPROM, FlashFile< FLASH >, SPIFFS, and CC32xxDeviceFile.

◆ read() [1/2]

virtual ssize_t FileIO::read ( File file,
void *  buf,
size_t  count 
)
protectedpure virtual

Read from a file or device.

Parameters
filefile reference for this device
buflocation to place read data
countnumber of bytes to read
Returns
number of bytes read upon success, -1 upon failure with errno containing the cause

Implemented in Null, TivaFlash, Pic32mxCan, BenchmarkCan, Can, DccDecoder< Module >, DeviceFile, EEPROM, I2C, TCAN4550Can, Pipe, RailcomDriverBase< HW >, RailcomDriverBase< HW >, RamDiskBase, Serial, Socket, SPI, TCAN4550Can, MbedAsyncUSBSerial, Pic32mxCdc, SPIFFS, Stm32RailcomSender, TivaDCC< HW >, TivaNRZ< HW >, TinyUsbCdc, and TivaTestPacketSource< HW >.

◆ read() [2/2]

ssize_t FileIO::read ( struct _reent *  reent,
int  fd,
void *  buf,
size_t  count 
)
static

Read from a file or device.

Parameters
reentthread save reentrant structure
fdfile descriptor to read
buflocation to place read data
countnumber of bytes to read
Returns
number of bytes read upon success, -1 upon failure with errno containing the cause
Parameters
reentthread safe reentrant structure
fdfile descriptor to read
buflocation to place read data
countnumber of bytes to read
Returns
number of bytes read upon success, -1 upon failure with errno containing the cause

Definition at line 115 of file Fileio.cxx.

◆ select()

virtual bool FileIO::select ( File file,
int  mode 
)
inlineprotectedvirtual

Device select method.

Default impementation returns true.

Parameters
filereference to the file
modeFREAD for read active, FWRITE for write active, 0 for exceptions
Returns
true if active, false if inactive

Reimplemented in Can, DccDecoder< Module >, TCAN4550Can, Pipe, Serial, Socket, TCAN4550Can, CC32xxSocket, CC32xxSocket, FreeRTOSTCPSocket, Pic32mxCan, Pic32mxCdc, TivaCdc, TivaTestPacketSource< HW >, and TinyUsbCdc.

Definition at line 226 of file Devtab.hxx.

◆ write() [1/2]

virtual ssize_t FileIO::write ( File file,
const void *  buf,
size_t  count 
)
protectedpure virtual

Write to a file or device.

Parameters
filefile reference for this device
buflocation to find write data
countnumber of bytes to write
Returns
number of bytes written upon success, -1 upon failure with errno containing the cause

Implemented in TivaTestPacketSource< HW >, Null, RailcomDriverBase< HW >, RailcomDriverBase< HW >, TivaFlash, Pic32mxCan, BenchmarkCan, Can, DccDecoder< Module >, DeviceFile, EEPROM, I2C, TCAN4550Can, Pipe, RamDiskBase, Serial, Socket, SPI, TCAN4550Can, MbedAsyncUSBSerial, Pic32mxCdc, SPIFFS, Stm32RailcomSender, TivaDCC< HW >, TivaCdc, TivaNRZ< HW >, and TinyUsbCdc.

◆ write() [2/2]

ssize_t FileIO::write ( struct _reent *  reent,
int  fd,
const void *  buf,
size_t  count 
)
static

Write to a file or device.

Parameters
reentthread save reentrant structure
fdfile descriptor to write
buflocation to find write data
countnumber of bytes to write
Returns
number of bytes written upon success, -1 upon failure with errno containing the cause

Definition at line 139 of file Fileio.cxx.

Friends And Related Symbol Documentation

◆ Device

friend class Device
friend

Allow access from Device class.

Definition at line 269 of file Devtab.hxx.

◆ FileSystem

friend class FileSystem
friend

Allow access from FileSystem class.

Definition at line 272 of file Devtab.hxx.

Member Data Documentation

◆ files

File FileIO::files
staticprotected

File descriptor pool.

Definition at line 261 of file Devtab.hxx.

◆ mutex

OSMutex FileIO::mutex
staticprotected

mutual exclusion for fileio

Definition at line 264 of file Devtab.hxx.

◆ name

const char* FileIO::name
protected

device name

Definition at line 266 of file Devtab.hxx.

◆ numOpenFiles

const unsigned int FileIO::numOpenFiles = 20
staticprotected
Returns
the maximum number of open file descriptors possible (the size of the files[] array.

Definition at line 258 of file Devtab.hxx.


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