FreeNOS
Public Member Functions | Private Attributes
FileStorage Class Reference

Use a file as Storage provider. More...

#include <FileStorage.h>

Inheritance diagram for FileStorage:
Storage

Public Member Functions

 FileStorage (const char *path, Size offset=ZERO)
 Constructor function. More...
 
virtual FileSystem::Result initialize ()
 Initialize the Storage device. More...
 
virtual FileSystem::Result read (const u64 offset, void *buffer, const Size size) const
 Read a contiguous set of data. More...
 
virtual FileSystem::Result write (const u64 offset, void *buffer, const Size size)
 Write a contiguous set of data. More...
 
virtual u64 capacity () const
 Retrieve maximum storage capacity. More...
 
- Public Member Functions inherited from Storage
 Storage ()
 Constructor function. More...
 
virtual ~Storage ()
 Destructor function. More...
 

Private Attributes

const char * m_path
 Path to the file. More...
 
Size m_fd
 File descriptor of the file. More...
 
FileSystemClient m_file
 Client for file system I/O. More...
 
FileSystem::FileStat m_stat
 Status of the file for Storage I/O. More...
 
Size m_offset
 Offset used as a base for I/O. More...
 

Detailed Description

Use a file as Storage provider.

See also
Storage

Definition at line 38 of file FileStorage.h.

Constructor & Destructor Documentation

◆ FileStorage()

FileStorage::FileStorage ( const char *  path,
Size  offset = ZERO 
)

Constructor function.

Parameters
pathFull path to the file to use.
offsetOffset in the file as a base for I/O.

Definition at line 21 of file FileStorage.cpp.

Member Function Documentation

◆ capacity()

u64 FileStorage::capacity ( ) const
virtual

Retrieve maximum storage capacity.

Returns
Storage capacity.

Implements Storage.

Definition at line 71 of file FileStorage.cpp.

References m_stat, and FileSystem::FileStat::size.

◆ initialize()

FileSystem::Result FileStorage::initialize ( )
virtual

Initialize the Storage device.

Returns
Result code

Implements Storage.

Definition at line 28 of file FileStorage.cpp.

References m_fd, m_file, m_path, m_stat, FileSystemClient::openFile(), FileSystemClient::statFile(), and FileSystem::Success.

◆ read()

FileSystem::Result FileStorage::read ( const u64  offset,
void *  buffer,
const Size  size 
) const
virtual

Read a contiguous set of data.

Parameters
offsetOffset to start reading from.
bufferOutput buffer.
sizeNumber of bytes to copied.
Returns
Result code

Implements Storage.

Definition at line 39 of file FileStorage.cpp.

References FileDescriptor::getEntry(), StrictSingleton< FileDescriptor >::instance(), FileSystem::IOError, m_fd, m_file, m_offset, FileDescriptor::Entry::open, FileDescriptor::Entry::position, and FileSystemClient::readFile().

◆ write()

FileSystem::Result FileStorage::write ( const u64  offset,
void *  buffer,
const Size  size 
)
virtual

Write a contiguous set of data.

Parameters
offsetOffset to start writing to.
bufferInput buffer.
sizeNumber of bytes to written.
Returns
Result code

Reimplemented from Storage.

Definition at line 55 of file FileStorage.cpp.

References FileDescriptor::getEntry(), StrictSingleton< FileDescriptor >::instance(), FileSystem::IOError, m_fd, m_file, m_offset, FileDescriptor::Entry::open, FileDescriptor::Entry::position, and FileSystemClient::writeFile().

Field Documentation

◆ m_fd

Size FileStorage::m_fd
private

File descriptor of the file.

Definition at line 92 of file FileStorage.h.

Referenced by initialize(), read(), and write().

◆ m_file

FileSystemClient FileStorage::m_file
private

Client for file system I/O.

Definition at line 95 of file FileStorage.h.

Referenced by initialize(), read(), and write().

◆ m_offset

Size FileStorage::m_offset
private

Offset used as a base for I/O.

Definition at line 101 of file FileStorage.h.

Referenced by read(), and write().

◆ m_path

const char* FileStorage::m_path
private

Path to the file.

Definition at line 89 of file FileStorage.h.

Referenced by initialize().

◆ m_stat

FileSystem::FileStat FileStorage::m_stat
private

Status of the file for Storage I/O.

Definition at line 98 of file FileStorage.h.

Referenced by capacity(), and initialize().


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