ReXGlue SDK
Loading...
Searching...
No Matches
rex::kernel::FileObject Struct Reference
Inheritance diagram for rex::kernel::FileObject:
[legend]

Public Member Functions

 FileObject (std::unique_ptr< filesystem::IFile > file_in, bool synchronous)
 ~FileObject ()
X_STATUS ReadScatter (TitleRuntime &runtime, u32 segments_address, u32 length, u64 byte_offset, u32 *out_bytes_read, u32 apc_context)
X_STATUS Read (TitleRuntime &runtime, u32 buffer_address, u32 buffer_length, u64 byte_offset, u32 *out_bytes_read, u32 apc_context, bool notify_completion=true)
X_STATUS Read (u32 buffer_address, u32 buffer_length, u64 byte_offset, u32 *out_bytes_read, u32 apc_context, bool notify_completion=true) override
X_STATUS Write (TitleRuntime &runtime, u32 buffer_address, u32 buffer_length, u64 byte_offset, u32 *out_bytes_written, u32 apc_context)
X_STATUS Write (u32 buffer_address, u32 buffer_length, u64 byte_offset, u32 *out_bytes_written, u32 apc_context) override
X_STATUS QueryDirectory (TitleRuntime &runtime, X_FILE_DIRECTORY_INFORMATION *out_info, size_t length, std::string_view file_name, bool restart)
X_STATUS SetLength (u64 length)
X_STATUS SetAllocation (u64 size)
X_STATUS Rename (filesystem::IFileSystem &file_system, std::string_view path, bool replace_existing, FileObject *root)
u64 Seek (i64 distance, SeekOrigin origin) override
X_STATUS SetLengthToPosition () override
void SetPosition (u64 value)
u64 GetPosition ()
void SetFindPattern (std::string_view pattern) override
std::optional< filesystem::FileStat > FindNext () override
u64 GetSize () override
std::string GetAbsolutePath () override
void RegisterIOCompletionPort (TitleRuntime &runtime, u32 key, X_HANDLE port)

Public Attributes

std::unique_ptr< filesystem::IFile > file
std::unique_ptr< rex::platform::Event > async_event
std::mutex file_lock
std::mutex completion_port_lock
std::vector< std::pair< u32, X_HANDLE > > completion_ports
IObjectTable * port_table = nullptr
PropagateConst< std::unique_ptr< filesystem::IDirectory > > find
bool is_synchronous = false
TitleRuntime * owner = nullptr

Constructor & Destructor Documentation

◆ FileObject()

rex::kernel::FileObject::FileObject ( std::unique_ptr< filesystem::IFile > file_in,
bool synchronous )
Parameters
synchronousTrue when the file was opened for synchronous IO.

◆ ~FileObject()

rex::kernel::FileObject::~FileObject ( )

Closes the IO completion port handles the file owns.

Member Function Documentation

◆ FindNext()

std::optional< filesystem::FileStat > rex::kernel::FileObject::FindNext ( )
overridevirtual
Returns
The entry, empty when the listing is exhausted or absent.

Implements rex::kernel::IOpenedFile.

◆ GetAbsolutePath()

std::string rex::kernel::FileObject::GetAbsolutePath ( )
overridevirtual

◆ GetSize()

u64 rex::kernel::FileObject::GetSize ( )
overridevirtual

◆ QueryDirectory()

X_STATUS rex::kernel::FileObject::QueryDirectory ( TitleRuntime & runtime,
X_FILE_DIRECTORY_INFORMATION * out_info,
size_t length,
std::string_view file_name,
bool restart )

Writes the next directory entry that matches a pattern.

Parameters
out_infoReceives the entry.
file_nameThe pattern, empty to continue the current listing.
Returns
X_STATUS_SUCCESS; X_STATUS_NO_SUCH_FILE when this call started the listing and nothing matches; X_STATUS_NO_MORE_FILES when a started listing has no entry left; X_STATUS_BUFFER_OVERFLOW when the name does not fit.

◆ Read() [1/2]

X_STATUS rex::kernel::FileObject::Read ( TitleRuntime & runtime,
u32 buffer_address,
u32 buffer_length,
u64 byte_offset,
u32 * out_bytes_read,
u32 apc_context,
bool notify_completion = true )

Reads into guest memory and notifies the IO completion ports of the file.

Parameters
byte_offsetThe file offset, or the maximum value to read at the current position.
out_bytes_readReceives the bytes read, may be null.
apc_contextThe context reported to the completion ports.
notify_completionFalse to skip the completion ports and the async event.

◆ Read() [2/2]

X_STATUS rex::kernel::FileObject::Read ( u32 buffer_address,
u32 buffer_length,
u64 byte_offset,
u32 * out_bytes_read,
u32 apc_context,
bool notify_completion = true )
inlineoverridevirtual

Reads into guest memory and notifies the IO completion ports of the file.

Parameters
byte_offsetThe file offset, or the maximum value to read at the current position.
out_bytes_readReceives the bytes read, may be null.
apc_contextThe context reported to the completion ports.
notify_completionFalse to skip the completion ports and the async event.

Implements rex::kernel::IOpenedFile.

◆ ReadScatter()

X_STATUS rex::kernel::FileObject::ReadScatter ( TitleRuntime & runtime,
u32 segments_address,
u32 length,
u64 byte_offset,
u32 * out_bytes_read,
u32 apc_context )

Reads into the page sized segments of a guest segment array.

Parameters
segments_addressThe guest address of the segment array.
byte_offsetThe file offset, or the maximum value to read at the current position.
out_bytes_readReceives the bytes read, may be null.
apc_contextThe context reported to the completion ports.
Returns
The status of the first failed read, otherwise X_STATUS_SUCCESS.

◆ RegisterIOCompletionPort()

void rex::kernel::FileObject::RegisterIOCompletionPort ( TitleRuntime & runtime,
u32 key,
X_HANDLE port )

Associates an IO completion port with the file. The file owns a duplicate of the port handle.

Parameters
keyThe completion key reported with each notification.
portThe handle of the IO completion port.

◆ Rename()

X_STATUS rex::kernel::FileObject::Rename ( filesystem::IFileSystem & file_system,
std::string_view path,
bool replace_existing,
FileObject * root )

Moves the file inside its mount.

Parameters
file_systemThe file system that serves the file.
replace_existingTrue to replace a closed file at the new path.
rootThe directory the new path is relative to, or null.
Returns
X_STATUS_SUCCESS, or the mapped filesystem error.

◆ Seek()

u64 rex::kernel::FileObject::Seek ( i64 distance,
SeekOrigin origin )
overridevirtual

Moves the position of the file.

Parameters
distanceThe signed byte distance.
originThe origin the distance is measured from.

Implements rex::kernel::IOpenedFile.

◆ SetAllocation()

X_STATUS rex::kernel::FileObject::SetAllocation ( u64 size)

Sets the allocation size of the file, which truncates only a file that is longer.

Returns
X_STATUS_SUCCESS, or the mapped filesystem error.

◆ SetFindPattern()

void rex::kernel::FileObject::SetFindPattern ( std::string_view pattern)
overridevirtual

Starts a directory listing.

Parameters
patternThe pattern to match, empty for every entry.

Implements rex::kernel::IOpenedFile.

◆ SetLength()

X_STATUS rex::kernel::FileObject::SetLength ( u64 length)
Returns
X_STATUS_SUCCESS, or the mapped filesystem error.

◆ SetLengthToPosition()

X_STATUS rex::kernel::FileObject::SetLengthToPosition ( )
overridevirtual

Sets the length of the file to the current position.

Returns
X_STATUS_SUCCESS, or the mapped filesystem error.

Implements rex::kernel::IOpenedFile.

◆ Write() [1/2]

X_STATUS rex::kernel::FileObject::Write ( TitleRuntime & runtime,
u32 buffer_address,
u32 buffer_length,
u64 byte_offset,
u32 * out_bytes_written,
u32 apc_context )

Writes from guest memory and notifies the IO completion ports of the file.

Parameters
byte_offsetThe file offset, or the maximum value to write at the current position.
out_bytes_writtenReceives the bytes written, may be null.
apc_contextThe context reported to the completion ports.

◆ Write() [2/2]

X_STATUS rex::kernel::FileObject::Write ( u32 buffer_address,
u32 buffer_length,
u64 byte_offset,
u32 * out_bytes_written,
u32 apc_context )
inlineoverridevirtual

Writes from guest memory and notifies the IO completion ports of the file.

Parameters
byte_offsetThe file offset, or the maximum value to write at the current position.
out_bytes_writtenReceives the bytes written, may be null.
apc_contextThe context reported to the completion ports.

Implements rex::kernel::IOpenedFile.

Member Data Documentation

◆ async_event

std::unique_ptr<rex::platform::Event> rex::kernel::FileObject::async_event

Auto reset event set when an asynchronous read or write completes, waited on by the handle.

◆ completion_port_lock

std::mutex rex::kernel::FileObject::completion_port_lock

Guards completion_ports and port_table.

◆ completion_ports

std::vector<std::pair<u32, X_HANDLE> > rex::kernel::FileObject::completion_ports

Completion key and port handle of each IO completion port the file posts to.

◆ file_lock

std::mutex rex::kernel::FileObject::file_lock
mutable

Guards position_, find and the reads and writes of file.

◆ find

PropagateConst<std::unique_ptr<filesystem::IDirectory> > rex::kernel::FileObject::find

Directory listing a find call is walking, null before the first find.

◆ owner

TitleRuntime* rex::kernel::FileObject::owner = nullptr

The runtime the interface Read and Write run in, set when the table creates the file.

◆ port_table

IObjectTable* rex::kernel::FileObject::port_table = nullptr

Table that owns the handles in completion_ports, set when the first port registers.


The documentation for this struct was generated from the following file: