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

Base class for all File systems. More...

#include <Devtab.hxx>

Inheritance diagram for FileSystem:
FileIO SPIFFS SpiSPIFFS Stm32SPIFFS TiSPIFFS< ERASE_PAGE_SIZE >

Public Member Functions

 FileSystem ()
 Constructor.
 
virtual ~FileSystem ()
 Destructor.
 
virtual void mount (const char *mount_point)=0
 Mount the file system.
 
virtual void format ()=0
 Format the file system, all data will be lost.
 

Static Public Member Functions

static int open (struct _reent *reent, const char *path, int flags, int mode)
 Open a file or device.
 
static int close (struct _reent *reent, int fd)
 Close a file or device.
 
static int unlink (struct _reent *reent, const char *path)
 Remove a file.
 
static int stat (struct _reent *reent, const char *path, struct stat *stat)
 Get the status information of a file or device.
 
static int fsync (int fd)
 Synchronize (flush) a file to disk.
 
static int closedir (DIR *dirp)
 Close a directory.
 
static DIRopendir (const char *name)
 Open a directory.
 
static struct direntreaddir (DIR *dirp)
 Read the next entry in a directory.
 
- Static Public Member Functions inherited from FileIO
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

virtual int unlink (const char *path)=0
 Remove a file.
 
virtual int fstat (File *file, struct stat *stat) override
 Get the status information of a file or device.
 
virtual int stat (const char *path, struct stat *stat)=0
 Get the status information of a file or device.
 
virtual int fsync (File *file)=0
 Synchronize (flush) a file to disk.
 
virtual int closedir (File *file)=0
 Close a directory.
 
virtual Fileopendir (File *file, const char *name)=0
 Open a directory.
 
virtual struct direntreaddir (File *file)=0
 Read the next entry in a directory.
 
- Protected Member Functions inherited from FileIO
 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 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.
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (FileSystem)
 

Static Private Member Functions

static FileSystemfs_lookup (const char *path)
 Locate the file system for a given path.
 

Private Attributes

FileSystemnext
 next device in linked list
 
FileSystemprev
 previous device in linked list
 

Static Private Attributes

static FileSystemfirst = NULL
 first device in linked list
 

Additional Inherited Members

- Static Protected Member Functions inherited from FileIO
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 inherited from FileIO
const char * name
 device name
 
- Static Protected Attributes inherited from FileIO
static const unsigned int numOpenFiles = 20
 
static File files []
 File descriptor pool.
 
static OSMutex mutex
 mutual exclusion for fileio
 

Detailed Description

Base class for all File systems.

Definition at line 279 of file Devtab.hxx.

Constructor & Destructor Documentation

◆ FileSystem()

FileSystem::FileSystem ( )

Constructor.

Definition at line 43 of file FileSystem.cxx.

◆ ~FileSystem()

FileSystem::~FileSystem ( )
virtual

Destructor.

Definition at line 59 of file FileSystem.cxx.

Member Function Documentation

◆ close()

int FileSystem::close ( struct _reent *  reent,
int  fd 
)
static

Close a file or device.

Parameters
reentthread save reentrant structure
fdfile descriptor to close
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 159 of file FileSystem.cxx.

◆ closedir() [1/2]

int FileSystem::closedir ( DIR dirp)
static

Close a directory.

Parameters

dirp directory pointer to close

Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 269 of file FileSystem.cxx.

◆ closedir() [2/2]

virtual int FileSystem::closedir ( File file)
protectedpure virtual

Close a directory.

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

Implemented in SPIFFS.

◆ format()

virtual void FileSystem::format ( )
pure virtual

Format the file system, all data will be lost.

The file system must not be mounted at the time of calling this.

Implemented in SPIFFS.

◆ fs_lookup()

FileSystem * FileSystem::fs_lookup ( const char *  path)
staticprivate

Locate the file system for a given path.

Parameters
pathfull path to file/directory
Returns
reference to file system on success, else nullptr

Definition at line 81 of file FileSystem.cxx.

◆ fstat()

int FileSystem::fstat ( File file,
struct stat stat 
)
overrideprotectedvirtual

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.

Implements FileIO.

Reimplemented in SPIFFS.

Definition at line 236 of file FileSystem.cxx.

◆ fsync() [1/2]

virtual int FileSystem::fsync ( File file)
protectedpure virtual

Synchronize (flush) a file to disk.

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

Implemented in SPIFFS.

◆ fsync() [2/2]

int FileSystem::fsync ( int  fd)
static

Synchronize (flush) a file to disk.

Parameters
fdfile descriptor to sync
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 246 of file FileSystem.cxx.

◆ mount()

virtual void FileSystem::mount ( const char *  mount_point)
pure virtual

Mount the file system.

Parameters
mount_pointpath in the root file system for the mount point Must not contain any trailing '/' characters, e.g. "/usr", not "/usr/". Unlike in linux, each mount must be entirely unique point in the system. For example, mounting of both "/usr" and "/usr/bin" is is not supported. However, "/usr" and "/usr1" is supported. This saves on file open logic.

Implemented in SPIFFS.

◆ open()

int FileSystem::open ( struct _reent *  reent,
const char *  path,
int  flags,
int  mode 
)
static

Open a file or device.

Parameters
reentthread save reentrant structure
pathfile or device name
flagsopen flags
modeopen mode, ignored in this implementation
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 119 of file FileSystem.cxx.

◆ opendir() [1/2]

DIR * FileSystem::opendir ( const char *  name)
static

Open a directory.

Parameters
namedirectory path
Returns
pointer to the open directory on success, NULL on error

Definition at line 291 of file FileSystem.cxx.

◆ opendir() [2/2]

virtual File * FileSystem::opendir ( File file,
const char *  name 
)
protectedpure virtual

Open a directory.

Parameters
filefile reference for this device
namedirectory path
Returns
pointer to the open directory on success, NULL on error

Implemented in SPIFFS.

◆ readdir() [1/2]

struct dirent * FileSystem::readdir ( DIR dirp)
static

Read the next entry in a directory.

Parameters
dirpdirectory pointer to read.
Returns
pointer to a struct dirent representing the next directectory entry

Definition at line 325 of file FileSystem.cxx.

◆ readdir() [2/2]

virtual struct dirent * FileSystem::readdir ( File file)
protectedpure virtual

Read the next entry in a directory.

Parameters
filefile reference for this device
Returns
pointer to a struct dirent representing the next directectory entry

Implemented in SPIFFS.

◆ stat() [1/2]

virtual int FileSystem::stat ( const char *  path,
struct stat *  stat 
)
protectedpure virtual

Get the status information of a file or device.

Parameters
pathfile or device name
statstructure to fill status info into
Returns
0 upon success, -1 upon failure with errno containing the cause

Implemented in SPIFFS.

◆ stat() [2/2]

int FileSystem::stat ( struct _reent *  reent,
const char *  path,
struct stat *  stat 
)
static

Get the status information of a file or device.

Parameters
reentthread safe reentrant structure
pathfile or device name
statstructure to fill status info into
Returns
0 upon success, -1 upon failure with errno containing the cause
Parameters
reentthread save reentrant structure
pathfile or device name
statstructure to fill status info into
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 212 of file FileSystem.cxx.

◆ unlink() [1/2]

virtual int FileSystem::unlink ( const char *  path)
protectedpure virtual

Remove a file.

Parameters
pathfile name
Returns
0 upon successor or negative error number upon error.

Implemented in SPIFFS.

◆ unlink() [2/2]

int FileSystem::unlink ( struct _reent *  reent,
const char *  path 
)
static

Remove a file.

Parameters
reentthread safe reentrant structure
pathfile name
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 187 of file FileSystem.cxx.

Member Data Documentation

◆ first

FileSystem * FileSystem::first = NULL
staticprivate

first device in linked list

Definition at line 417 of file Devtab.hxx.

◆ next

FileSystem* FileSystem::next
private

next device in linked list

Definition at line 420 of file Devtab.hxx.

◆ prev

FileSystem* FileSystem::prev
private

previous device in linked list

Definition at line 423 of file Devtab.hxx.


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