FreeNOS
Public Member Functions | Private Attributes
IOBuffer Class Reference

Abstract Input/Output buffer. More...

#include <IOBuffer.h>

Public Member Functions

 IOBuffer ()
 Default empty constructor. More...
 
 IOBuffer (const FileSystemMessage *msg)
 Constructor. More...
 
virtual ~IOBuffer ()
 Destructor. More...
 
Size getCount () const
 Get byte count. More...
 
void addCount (const Size bytes)
 Increment byte counter. More...
 
void setMessage (const FileSystemMessage *msg)
 Set filesystem message. More...
 
const FileSystemMessagegetMessage () const
 Get filesystem message. More...
 
u8getBuffer ()
 Get raw buffer. More...
 
FileSystem::Result read (void *buffer, const Size size, const Size offset=ZERO)
 Read bytes from the I/O buffer. More...
 
FileSystem::Result write (const void *buffer, const Size size, const Size offset=ZERO)
 Write bytes to the I/O buffer. More...
 
FileSystem::Result bufferedRead ()
 Buffered read bytes from the I/O buffer. More...
 
FileSystem::Result bufferedWrite (const void *buffer, const Size size)
 Buffered write bytes to the I/O buffer. More...
 
FileSystem::Result flushWrite ()
 Flush write buffers. More...
 
u8 operator[] (Size index) const
 Byte index operator. More...
 

Private Attributes

const FileSystemMessagem_message
 Current request being processed. More...
 
bool m_directMapped
 True if using directly memory-mapped memory (unbuffered) More...
 
Memory::Range m_directMapRange
 Contains the memory address range of the direct memory mapping. More...
 
u8m_buffer
 Buffer for storing temporary data. More...
 
Size m_size
 Buffer size. More...
 
Size m_count
 Bytes written to the buffer. More...
 

Detailed Description

Abstract Input/Output buffer.

Definition at line 37 of file IOBuffer.h.

Constructor & Destructor Documentation

◆ IOBuffer() [1/2]

IOBuffer::IOBuffer ( )

Default empty constructor.

Definition at line 24 of file IOBuffer.cpp.

◆ IOBuffer() [2/2]

IOBuffer::IOBuffer ( const FileSystemMessage msg)

Constructor.

Parameters
msgDescribes the request being processed.

Definition at line 33 of file IOBuffer.cpp.

References setMessage().

◆ ~IOBuffer()

IOBuffer::~IOBuffer ( )
virtual

Destructor.

Definition at line 43 of file IOBuffer.cpp.

References ERROR, m_buffer, m_directMapped, m_directMapRange, SELF, API::Success, UnMap, and VMCtl().

Member Function Documentation

◆ addCount()

void IOBuffer::addCount ( const Size  bytes)

Increment byte counter.

Parameters
bytesNumber of bytes to increment

Definition at line 114 of file IOBuffer.cpp.

References assert, m_count, and m_size.

Referenced by LinnFile::read().

◆ bufferedRead()

FileSystem::Result IOBuffer::bufferedRead ( )

Buffered read bytes from the I/O buffer.

Returns
Result code

Definition at line 130 of file IOBuffer.cpp.

References m_buffer, m_count, m_directMapped, m_message, read(), FileSystemMessage::size, and FileSystem::Success.

Referenced by FileSystemServer::inodeHandler().

◆ bufferedWrite()

FileSystem::Result IOBuffer::bufferedWrite ( const void *  buffer,
const Size  size 
)

Buffered write bytes to the I/O buffer.

Parameters
bufferContains the bytes to write.
sizeNumber of bytes to write.
Returns
Result code

Definition at line 146 of file IOBuffer.cpp.

References MemoryBlock::copy(), m_buffer, m_count, m_size, and FileSystem::Success.

Referenced by i8250::read(), PL011::read(), NS16550::read(), ATAController::read(), and DeviceLog::write().

◆ flushWrite()

FileSystem::Result IOBuffer::flushWrite ( )

Flush write buffers.

Returns
Result code

Definition at line 204 of file IOBuffer.cpp.

References m_buffer, m_count, m_directMapped, FileSystem::Success, and write().

Referenced by FileSystemServer::inodeHandler().

◆ getBuffer()

u8 * IOBuffer::getBuffer ( )

Get raw buffer.

Returns
Buffer pointer.

Definition at line 125 of file IOBuffer.cpp.

References m_buffer.

Referenced by LinnFile::read(), and VGA::write().

◆ getCount()

Size IOBuffer::getCount ( ) const

Get byte count.

Returns
Byte count of the internal buffer.

Definition at line 109 of file IOBuffer.cpp.

References m_count.

Referenced by FileSystemServer::inodeHandler(), PL011::read(), and NS16550::read().

◆ getMessage()

const FileSystemMessage * IOBuffer::getMessage ( ) const

Get filesystem message.

Returns
FileSystemMessage pointer.

Definition at line 120 of file IOBuffer.cpp.

References m_message.

Referenced by UDPFactory::read(), ICMPFactory::read(), and UDPSocket::write().

◆ operator[]()

u8 IOBuffer::operator[] ( Size  index) const

Byte index operator.

Parameters
indexIndex value
Returns
Byte value at the given index or 0 if index is invalid.

Definition at line 217 of file IOBuffer.cpp.

References m_buffer, and m_size.

◆ read()

FileSystem::Result IOBuffer::read ( void *  buffer,
const Size  size,
const Size  offset = ZERO 
)

Read bytes from the I/O buffer.

Parameters
bufferCopy bytes from the I/O buffer to this memory address.
sizeNumber of bytes to copy.
offsetThe offset inside the I/O buffer to start reading.
Returns
Result code

Definition at line 156 of file IOBuffer.cpp.

References FileSystemMessage::buffer, MemoryBlock::copy(), ERROR, ChannelMessage::from, FileSystem::IOError, m_buffer, m_count, m_directMapped, m_message, API::Read, FileSystem::Success, API::Success, and VMCopy().

Referenced by bufferedRead(), UDP::sendPacket(), FileSystemServer::waitFileHandler(), LogLevelFile::write(), IPV4Address::write(), ARPSocket::write(), PseudoFile::write(), UDPSocket::write(), and ICMPSocket::write().

◆ setMessage()

void IOBuffer::setMessage ( const FileSystemMessage msg)

Set filesystem message.

Parameters
msgFileSystemMessage pointer
Todo:
Only allow direct-mapping if the remote buffer size is a multiple of PAGESIZE. If the size isnt a full page, the rest of the page might contain other data.

Definition at line 63 of file IOBuffer.cpp.

References Memory::Range::access, FileSystemMessage::action, assert, FileSystemMessage::buffer, ERROR, ChannelMessage::from, isKernel, LookupVirtual, m_buffer, m_count, m_directMapped, m_directMapRange, m_message, m_size, MapContiguous, NULL, PAGEMASK, Memory::Readable, FileSystem::ReadFile, SELF, FileSystemMessage::size, Memory::Range::size, API::Success, Memory::User, Memory::Range::virt, VMCtl(), Memory::Writable, FileSystem::WriteFile, and ZERO.

Referenced by FileSystemRequest::FileSystemRequest(), IOBuffer(), and UDPSocket::write().

◆ write()

FileSystem::Result IOBuffer::write ( const void *  buffer,
const Size  size,
const Size  offset = ZERO 
)

Field Documentation

◆ m_buffer

u8* IOBuffer::m_buffer
private

Buffer for storing temporary data.

Definition at line 177 of file IOBuffer.h.

Referenced by bufferedRead(), bufferedWrite(), flushWrite(), getBuffer(), operator[](), read(), setMessage(), write(), and ~IOBuffer().

◆ m_count

Size IOBuffer::m_count
private

Bytes written to the buffer.

Definition at line 183 of file IOBuffer.h.

Referenced by addCount(), bufferedRead(), bufferedWrite(), flushWrite(), getCount(), read(), setMessage(), and write().

◆ m_directMapped

bool IOBuffer::m_directMapped
private

True if using directly memory-mapped memory (unbuffered)

Definition at line 171 of file IOBuffer.h.

Referenced by bufferedRead(), flushWrite(), read(), setMessage(), write(), and ~IOBuffer().

◆ m_directMapRange

Memory::Range IOBuffer::m_directMapRange
private

Contains the memory address range of the direct memory mapping.

Definition at line 174 of file IOBuffer.h.

Referenced by setMessage(), and ~IOBuffer().

◆ m_message

const FileSystemMessage* IOBuffer::m_message
private

Current request being processed.

Read() and write() will use fields from the current request to fill in arguments for VMCopy().

See also
VMCopy
IOBuffer::read
IOBuffer::write

Definition at line 168 of file IOBuffer.h.

Referenced by bufferedRead(), getMessage(), read(), setMessage(), and write().

◆ m_size

Size IOBuffer::m_size
private

Buffer size.

Definition at line 180 of file IOBuffer.h.

Referenced by addCount(), bufferedWrite(), operator[](), and setMessage().


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