pub struct HostFilesystem { /* private fields */ }Expand description
A wrapper around interacting with the ‘host’ or PC filesystem for the various times a cat-dev will reach out to the host.
This is little more than a wrapper around a PathBuf, and targeted
methods to make getting files/generating default files/etc. easy. Most of
the actual logic for turning a request from SDIO, ATAPI, etc. all come
from those client/server implementations rather than the logic living here.
Implementations§
Source§impl HostFilesystem
impl HostFilesystem
Sourcepub async fn from_cafe_dir(cafe_dir: Option<PathBuf>) -> Result<Self, FSError>
pub async fn from_cafe_dir(cafe_dir: Option<PathBuf>) -> Result<Self, FSError>
Create a filesystem from a root cafe dir.
If no cafe dir is provided, we will attempt to locate the default installation path for cafe sdk which is:
C:\cafe_sdkon windows./opt/cafe_sdkon any unix/bsd like OS.
NOTE: This will validate that all title id paths are lowercase, as files are always expected to be lowercase when dealing with CAFE. Other files are usually kept in the correct naming format. HOWEVER, users may notice spurious errors with case-insensitivity on linux specifically. If transferring an SDK from a Windows/Mac Case Insensitive to a Mac/Linux case sensitive file system. It is recommended users create their own folder using our recovery tools, rather than rsync’ing a path over from case-insensitive, to case-sensitive.
§Errors
If the Cafe SDK folder is corrupt, or can’t be found. A Cafe SDK folder is considered corrupt if it is missing core files that we need to be able to serve a Cafe-OS distribution. These file requirements may change from version to version of this crate, but should always be compatible with a clean cafe sdk folder.
Sourcepub const fn cafe_sdk_path(&self) -> &PathBuf
pub const fn cafe_sdk_path(&self) -> &PathBuf
The root path to the Cafe SDK.
note: although we do expose this for logging, and other info… we do not recommend manually interacting with the SDK path. There are much better alternatives.
Sourcepub fn disc_emu_path(&self) -> PathBuf
pub fn disc_emu_path(&self) -> PathBuf
The root path to the Cafe SDK.
note: although we do expose this for logging, and other info… we do not recommend manually interacting with the SDK path. There are much better alternatives.
Sourcepub fn force_unique_fds(&mut self) -> Result<(), FSEmulAPIError>
pub fn force_unique_fds(&mut self) -> Result<(), FSEmulAPIError>
Force unique file descriptors for open files.
Certain OS’s can return duplicate fd’s especially when opening, and closing files. This can make deciphering logs harder because the same FD may appear multiple times, when you’re trying to just find the logs related to one file descriptor.
When unique fd’s is turned on, similar to folders we just use a global wrapping counter so that way every file descriptor is guaranteed to be unique.
§Errors
This will error if any file has ever been opened. This is because once a client has already connected, and done some stuff with file stuff it expects one set of behaviors, we cannot change another one.
Sourcepub async fn open_file(
&self,
open_options: OpenOptions,
path: &PathBuf,
stream_owner: Option<u64>,
) -> Result<i32, FSError>
pub async fn open_file( &self, open_options: OpenOptions, path: &PathBuf, stream_owner: Option<u64>, ) -> Result<i32, FSError>
Open a file, and return it’s file descriptor number.
§Errors
If we cannot open our file with the open options provided.
Sourcepub async fn get_file(
&self,
fd: i32,
for_stream: Option<u64>,
) -> Option<CMOccupiedEntry<'_, i32, (File, u64, PathBuf, Option<u64>), RandomState>>
pub async fn get_file( &self, fd: i32, for_stream: Option<u64>, ) -> Option<CMOccupiedEntry<'_, i32, (File, u64, PathBuf, Option<u64>), RandomState>>
Get a file from a file descriptor number.
This file must already be opened (in order to get the file descriptor).
Sourcepub async fn file_length(&self, fd: i32, for_stream: Option<u64>) -> Option<u64>
pub async fn file_length(&self, fd: i32, for_stream: Option<u64>) -> Option<u64>
Get the file length from a file descriptor number.
This file must already be opened (in order to get the file descriptor).
Sourcepub async fn read_file(
&self,
fd: i32,
total_data_to_read: usize,
for_stream: Option<u64>,
) -> Result<Option<Bytes>, FSError>
pub async fn read_file( &self, fd: i32, total_data_to_read: usize, for_stream: Option<u64>, ) -> Result<Option<Bytes>, FSError>
Read from a file descriptor that is actively open.
This will read from a currently open file descriptor, in it’s current location. You might want to set your file location for this FD before if you aren’t already in the same location.
§Errors
If the file descriptor is open, but we could not read from the open file descriptor.
Sourcepub async fn write_file(
&self,
fd: i32,
data_to_write: Bytes,
for_stream: Option<u64>,
) -> Result<(), FSError>
pub async fn write_file( &self, fd: i32, data_to_write: Bytes, for_stream: Option<u64>, ) -> Result<(), FSError>
Write to a file descriptor that is actively open.
This will write from a currently open file descriptor, in it’s current location. You might want to set your file location for this FD before if you aren’t already in the same location.
§Errors
If the file descriptor is open, but we could not write to the open file descriptor.
Sourcepub async fn seek_file(
&self,
fd: i32,
begin: bool,
for_stream: Option<u64>,
) -> Result<(), FSError>
pub async fn seek_file( &self, fd: i32, begin: bool, for_stream: Option<u64>, ) -> Result<(), FSError>
Seek to the beginning or end of a file.
If begin is true then we will seek to the beginning of the file
otherwise we will sync to the end of the file. Precise seeking is not
supported at this time.
§Errors
If we cannot seek to the beginning or end of the file.
Sourcepub async fn close_file(&self, fd: i32, for_stream: Option<u64>)
pub async fn close_file(&self, fd: i32, for_stream: Option<u64>)
Decrement the ref count of handles to a file.
If ref count reaches 0 close the underlying file handle.
§Errors
If we cannot close our file handle when our ref count reaches 0, or if the file isn’t open at all.
Sourcepub fn open_folder(
&self,
path: &PathBuf,
for_stream: Option<u64>,
) -> Result<i32, FSError>
pub fn open_folder( &self, path: &PathBuf, for_stream: Option<u64>, ) -> Result<i32, FSError>
“Open” a folder, or an iterator over a directory.
There’s no real “open file handle”, or reversible directory iterator, so we just create an id from scratch.
§Errors
If the path doesn’t exist, then we can’t open the folder.
Sourcepub async fn mark_folder_read_only(&self, path: PathBuf)
pub async fn mark_folder_read_only(&self, path: PathBuf)
Mark a folder as being ‘read-only’ for this session.
§Errors
If we could not actually insert the folder into the read only map.
Sourcepub async fn ensure_folder_not_read_only(&self, path: &PathBuf)
pub async fn ensure_folder_not_read_only(&self, path: &PathBuf)
Mark a folder as being ‘read-write’ for this session.
Sourcepub async fn folder_is_read_only(&self, path: &PathBuf) -> bool
pub async fn folder_is_read_only(&self, path: &PathBuf) -> bool
Check if a folder is marked as being read only.
Sourcepub async fn next_in_folder(
&self,
fd: i32,
for_stream: Option<u64>,
) -> Result<Option<(PathBuf, usize)>, FSError>
pub async fn next_in_folder( &self, fd: i32, for_stream: Option<u64>, ) -> Result<Option<(PathBuf, usize)>, FSError>
Get the next filename/foldername available in a particular folder, and how many pieces to remove to get just the filename.
This will always return none even if it’s already at the end, unlike a particular iterator.
§Errors
If we get an IO error from the underlying filesystem.
Sourcepub async fn reverse_folder(
&self,
fd: i32,
for_stream: Option<u64>,
) -> Result<(), FSError>
pub async fn reverse_folder( &self, fd: i32, for_stream: Option<u64>, ) -> Result<(), FSError>
Reverse a particular iterator over a folder by one.
Note: This will recreate the directory iterator, and will temporarily
hold two references to [ReadDir] at a time because the underlying
iterator from read directory is not a reversible iterator.
§Errors
If opening another read dir call does not work.
Sourcepub async fn close_folder(&self, fd: i32, for_stream: Option<u64>)
pub async fn close_folder(&self, fd: i32, for_stream: Option<u64>)
Decrement the ref count of handles to a folder.
If ref count reaches 0 close the underlying folder handle.
§Errors
If we cannot close our folder handle when our ref count reaches 0, or if the folder isn’t open at all.
Sourcepub async fn boot1_sytstem_path(&self) -> Result<PathBuf, FSError>
pub async fn boot1_sytstem_path(&self) -> Result<PathBuf, FSError>
Get the path to the current boot1 .bsf file.
This function will create the boot1 system file, if it does not yet exist. As a result it may error, if we can’t create, and place the boot system file.
§Errors
- If the temp directory does not exist, and we can’t create it.
- If the boot system file does not exist, and we can’t write it to disk.
Sourcepub async fn disk_id_path(&self) -> Result<PathBuf, FSError>
pub async fn disk_id_path(&self) -> Result<PathBuf, FSError>
Get the path to the current diskid.bin.
If the current Disk ID does not exist, we will write a blank diskid to this path.
§Errors
- If the temporary directory does not exist, and we can’t create it.
- If the disk ID path does not exist, and we can’t write it to disk.
Sourcepub fn firmware_file_path(&self) -> PathBuf
pub fn firmware_file_path(&self) -> PathBuf
Get the path to the current firmware file to boot on the MION.
This is guaranteed to always exist, as it’s part of our check for a corrupt SDK.
Sourcepub async fn ppc_boot_dlf_path(&self) -> Result<PathBuf, CatBridgeError>
pub async fn ppc_boot_dlf_path(&self) -> Result<PathBuf, CatBridgeError>
Get the path to the disk layout file for the PPC booting process.
This function will create a disk layout file, as well as a Boot System File, and a disk id file if they do not yet exist.
§Errors
- If the temp directory does not exist, and we can’t create it.
- If the boot system file does not exist, and we can’t write it to disk.
- If the diskid file does not exist, and we can’t write it to disk.
- If the firmware image file does not exist.
- If the dlf file does not exist, and we can’t create it.
Sourcepub fn path_allows_writes(&self, path: &Path) -> bool
pub fn path_allows_writes(&self, path: &Path) -> bool
Check if a path is allowed to be writable.
Sourcepub fn resolve_path(
&self,
potentially_prefixed_path: &str,
) -> Result<ResolvedLocation, CatBridgeError>
pub fn resolve_path( &self, potentially_prefixed_path: &str, ) -> Result<ResolvedLocation, CatBridgeError>
Given a UTF-8 string path, get a pathbuf reference.
This understands the current following implementations:
/%MLC_EMU_DIR/%SLC_EMU_DIR/%DISC_EMU_DIR/%SAVE_EMU_DIR/%NETWORK
Most of these are just quick ways of referncing the current set of
directories, within cafe sdk. %NETWORK is the special one which
references a currently mounted network share.
§Errors
If the path requested is not in a mounted path.
Sourcepub fn create_directory(&self, at: &Path) -> Result<(), FSError>
pub fn create_directory(&self, at: &Path) -> Result<(), FSError>
Create a directory within a particular path.
§Errors
If we cannot end up creating this directory due to a filesystem error.
Sourcepub fn copy(&self, from: &Path, to: &Path) -> Result<(), FSError>
pub fn copy(&self, from: &Path, to: &Path) -> Result<(), FSError>
Copy a file, symlink, or directory.
§Errors
If we run into any filesystem error renaming a source, or directory.
Sourcepub fn rename(&self, from: &Path, to: &Path) -> Result<(), FSError>
pub fn rename(&self, from: &Path, to: &Path) -> Result<(), FSError>
Rename a file, symlink, or directory.
This is implemented so we can rename directories, and files without having to worry about the logic. Especially given the fact the built in rename doesn’t support directories.
§Errors
- If we run into any filesystem error renaming a source, or directory.
Sourcepub fn slc_path_for(&self, title_id: TitleID) -> PathBuf
pub fn slc_path_for(&self, title_id: TitleID) -> PathBuf
Get a file from the SLC.
The SLC always serves “sys” files, and are relative to a title id, almost
always a system title id such as (00050010).
note: the file is not guaranteed to exist! It’s just a path!
Sourcepub fn default_cafe_folder() -> Option<PathBuf>
pub fn default_cafe_folder() -> Option<PathBuf>
Get the current OS’s default directory path.
For Windows this is: C:\cafe_sdk.
For Unix/BSD likes this is: /opt/cafe_sdk
Trait Implementations§
Source§impl Clone for HostFilesystem
impl Clone for HostFilesystem
Source§fn clone(&self) -> HostFilesystem
fn clone(&self) -> HostFilesystem
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HostFilesystem
impl Debug for HostFilesystem
Source§impl FromRef<PcfsServerState> for HostFilesystem
Available on crate feature servers only.
impl FromRef<PcfsServerState> for HostFilesystem
servers only.Source§fn from_ref(input: &PcfsServerState) -> Self
fn from_ref(input: &PcfsServerState) -> Self
clients or servers only.Source§impl FromRef<SdioStreamState> for HostFilesystem
Available on crate feature servers only.
impl FromRef<SdioStreamState> for HostFilesystem
servers only.Source§fn from_ref(input: &SdioStreamState) -> Self
fn from_ref(input: &SdioStreamState) -> Self
clients or servers only.Source§impl Structable for HostFilesystem
impl Structable for HostFilesystem
Source§fn definition(&self) -> StructDef<'_>
fn definition(&self) -> StructDef<'_>
Auto Trait Implementations§
impl Freeze for HostFilesystem
impl !RefUnwindSafe for HostFilesystem
impl Send for HostFilesystem
impl Sync for HostFilesystem
impl Unpin for HostFilesystem
impl !UnwindSafe for HostFilesystem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more