bep_ovfs.rs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. use crate::raw_fn;
  2. use crate::afs;
  3. use crate::afs::AfsInstance;
  4. use crate::error::{CreateBepOvfsError, MountError, AfsFreeError, AfsMkdirError};
  5. pub struct AfsBepOvFsInstance{
  6. parent: afs::AfsInstance,
  7. }
  8. impl AfsBepOvFsInstance {
  9. pub fn new(fs_layer_handles: &[&AfsInstance], writable: bool) -> Result<Self, CreateBepOvfsError>{
  10. let mut afs_handle_vec = Vec::<i32>::new();
  11. for i in fs_layer_handles {
  12. afs_handle_vec.push(i.get_handle_value());
  13. }
  14. let afs_handle_slice = afs_handle_vec.as_slice();
  15. let r = unsafe {
  16. raw_fn::afs_create_bep_ovfs(
  17. afs_handle_slice.as_ptr(),
  18. afs_handle_slice.len(),
  19. if writable { 1 } else { 0 },
  20. )
  21. };
  22. match r {
  23. v if v > 0 => Ok(Self {
  24. parent: afs::AfsInstance::new_from_handle(v),
  25. }),
  26. -1 => Err(CreateBepOvfsError::EmptyFsLayerArray),
  27. -2 => Err(CreateBepOvfsError::MemeoryReadOutOfBounds),
  28. -3 => Err(CreateBepOvfsError::InvalidArrayElementLength),
  29. -4 => Err(CreateBepOvfsError::InvalidHandle),
  30. -5 => Err(CreateBepOvfsError::CreateAfsInstanceFailed),
  31. _ => Err(CreateBepOvfsError::UnknownError(r))
  32. }
  33. }
  34. pub fn new_from_handle(handle: i32) -> Self {
  35. Self{
  36. parent: afs::AfsInstance::new_from_handle(handle),
  37. }
  38. }
  39. pub fn mount(&self, mnt_path: &str) -> Result<(), MountError>{
  40. self.parent.mount(mnt_path)
  41. }
  42. pub fn free(&self) -> Result<(), AfsFreeError>{
  43. self.parent.free()
  44. }
  45. pub fn get_handle_value(&self) -> i32{
  46. self.parent.get_handle_value()
  47. }
  48. pub fn mkdir(&self, path: &str, mode: i32) -> Result<(), AfsMkdirError>{
  49. self.parent.mkdir(path, mode)
  50. }
  51. }