12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- use crate::raw_fn;
- use crate::afs;
- use crate::afs::AfsInstance;
- use crate::error::{CreateBepOvfsError, MountError, AfsFreeError, AfsMkdirError};
- pub struct AfsBepOvFsInstance{
- parent: afs::AfsInstance,
- }
- impl AfsBepOvFsInstance {
- pub fn new(fs_layer_handles: &[&AfsInstance], writable: bool) -> Result<Self, CreateBepOvfsError>{
- let mut afs_handle_vec = Vec::<i32>::new();
- for i in fs_layer_handles {
- afs_handle_vec.push(i.get_handle_value());
- }
- let afs_handle_slice = afs_handle_vec.as_slice();
- let r = unsafe {
- raw_fn::afs_create_bep_ovfs(
- afs_handle_slice.as_ptr(),
- afs_handle_slice.len(),
- if writable { 1 } else { 0 },
- )
- };
- match r {
- v if v > 0 => Ok(Self {
- parent: afs::AfsInstance::new_from_handle(v),
- }),
- -1 => Err(CreateBepOvfsError::EmptyFsLayerArray),
- -2 => Err(CreateBepOvfsError::MemeoryReadOutOfBounds),
- -3 => Err(CreateBepOvfsError::InvalidArrayElementLength),
- -4 => Err(CreateBepOvfsError::InvalidHandle),
- -5 => Err(CreateBepOvfsError::CreateAfsInstanceFailed),
- _ => Err(CreateBepOvfsError::UnknownError(r))
- }
- }
- pub fn new_from_handle(handle: i32) -> Self {
- Self{
- parent: afs::AfsInstance::new_from_handle(handle),
- }
- }
- pub fn mount(&self, mnt_path: &str) -> Result<(), MountError>{
- self.parent.mount(mnt_path)
- }
- pub fn free(&self) -> Result<(), AfsFreeError>{
- self.parent.free()
- }
- pub fn get_handle_value(&self) -> i32{
- self.parent.get_handle_value()
- }
- pub fn mkdir(&self, path: &str, mode: i32) -> Result<(), AfsMkdirError>{
- self.parent.mkdir(path, mode)
- }
- }
|