cat-dev 0.0.13

A library for interacting with the CAT-DEV hardware units distributed by Nintendo (i.e. a type of Wii-U DevKits).
Documentation
//! Handle a client requesting us to move the location of an open file.

use crate::{
	fsemul::pcfs::sata::{
		proto::{SataRequest, SataResponse, SataResultCode, SataSetFilePositionPacketBody},
		server::PcfsServerState,
	},
	net::{
		additions::StreamID,
		server::requestable::{Body, State},
	},
};
use tracing::debug;

/// A filesystem error occured.
const FS_ERROR: u32 = 0xFFF0_FFE0;

/// Handle setting the position within an already open file.
pub async fn handle_set_file_position(
	stream: StreamID,
	State(state): State<PcfsServerState>,
	// Validate that the body is actually a change owner packet.
	Body(request): Body<SataRequest<SataSetFilePositionPacketBody>>,
) -> SataResponse<SataResultCode> {
	let packet = request.body();

	if let Err(cause) = packet
		.move_to_pointer()
		.do_move(
			state.host_filesystem(),
			packet.file_descriptor(),
			Some(stream.to_raw()),
		)
		.await
	{
		debug!(
			?cause,
			packet.fd = packet.file_descriptor(),
			packet.typ = "PcfsSrvSetFilePosition",
			"Failed to move file to a specific pointer!",
		);

		SataResponse::new(
			state.pid(),
			request.header().clone(),
			SataResultCode::error(FS_ERROR),
		)
	} else {
		SataResponse::new(
			state.pid(),
			request.header().clone(),
			SataResultCode::success(),
		)
	}
}