From 07ed1dc1962bfbb35171b6ac7cc9bc5b0354bdad Mon Sep 17 00:00:00 2001 From: AzureMarker Date: Sat, 22 Jan 2022 18:40:19 -0800 Subject: [PATCH] Add basic RomFS support Seems to crash the 3DS if there is no actual RomFS data in the 3dsx file, so there's room for improvement. --- ctru-rs/src/lib.rs | 1 + ctru-rs/src/romfs.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 ctru-rs/src/romfs.rs diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index c2c8243..eef067d 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -34,6 +34,7 @@ pub mod console; pub mod error; pub mod gfx; pub mod sdmc; +pub mod romfs; pub mod services; pub mod srv; pub mod thread; diff --git a/ctru-rs/src/romfs.rs b/ctru-rs/src/romfs.rs new file mode 100644 index 0000000..09cfaa1 --- /dev/null +++ b/ctru-rs/src/romfs.rs @@ -0,0 +1,24 @@ +use std::ffi::CStr; + +#[non_exhaustive] +pub struct RomFS; + +impl RomFS { + pub fn new() -> crate::Result { + let mount_name = CStr::from_bytes_with_nul(b"romfs\0").unwrap(); + let result = unsafe { ctru_sys::romfsMountSelf(mount_name.as_ptr()) }; + + if result < 0 { + Err(result.into()) + } else { + Ok(Self) + } + } +} + +impl Drop for RomFS { + fn drop(&mut self) { + let mount_name = CStr::from_bytes_with_nul(b"romfs\0").unwrap(); + unsafe { ctru_sys::romfsUnmount(mount_name.as_ptr()) }; + } +} \ No newline at end of file