HostFilesystem

Struct HostFilesystem 

Source
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

Source

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_sdk on windows.
  • /opt/cafe_sdk on 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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn ensure_folder_not_read_only(&self, path: &PathBuf)

Mark a folder as being ‘read-write’ for this session.

Source

pub async fn folder_is_read_only(&self, path: &PathBuf) -> bool

Check if a folder is marked as being read only.

Source

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.

Source

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.

Source

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.

Source

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.
Source

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.
Source

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.

Source

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.
Source

pub fn path_allows_writes(&self, path: &Path) -> bool

Check if a path is allowed to be writable.

Source

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.

Source

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.

Source

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.

Source

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.
Source

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!

Source

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

Source§

fn clone(&self) -> HostFilesystem

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HostFilesystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromRef<PcfsServerState> for HostFilesystem

Available on crate feature servers only.
Source§

fn from_ref(input: &PcfsServerState) -> Self

Available on crate features clients or servers only.
Converts to this type from a reference to the input type.
Source§

impl FromRef<SdioStreamState> for HostFilesystem

Available on crate feature servers only.
Source§

fn from_ref(input: &SdioStreamState) -> Self

Available on crate features clients or servers only.
Converts to this type from a reference to the input type.
Source§

impl Structable for HostFilesystem

Source§

fn definition(&self) -> StructDef<'_>

Returns the struct’s definition. Read more
Source§

impl Valuable for HostFilesystem

Source§

fn as_value(&self) -> Value<'_>

Converts self into a Value instance. Read more
Source§

fn visit(&self, visitor: &mut dyn Visit)

Calls the relevant method on Visit to extract data from self. Read more
Source§

fn visit_slice(slice: &[Self], visit: &mut dyn Visit)
where Self: Sized,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<InnerTy> FromRef<InnerTy> for InnerTy
where InnerTy: Clone,

Source§

fn from_ref(input: &InnerTy) -> InnerTy

Available on crate features clients or servers only.
Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,