abi_definitions/file_system/
path.rs1use core::{
2 ffi::c_char,
3 ptr::{self, copy_nonoverlapping},
4};
5use task::block_on;
6
7use crate::{XilaFileSystemStatistics, XilaTaskIdentifier, abi_unsafe_function, parse_c_str};
8
9abi_unsafe_function! {
10 fn xila_file_system_get_statistics_from_path(
16 path: *const c_char,
17 statistics: *mut XilaFileSystemStatistics,
18 ) -> XilaFileSystemResult {
19 let path = parse_c_str(path)?;
20
21 log::information!("Getting statistics for path {path:?}");
22
23 let result = block_on(virtual_file_system::get_instance().get_statistics(&path))?;
24
25 log::information!("Got statistics for path {path:?}: {result:?}");
26
27 ptr::write(statistics, XilaFileSystemStatistics::from_statistics(result));
28 Ok(())
29 }
30}
31
32abi_unsafe_function! {
33 fn xila_file_system_resolve_path(
39 path: *const i8,
40 resolved_path: *mut u8,
41 resolved_path_size: usize,
42 ) -> XilaFileSystemResult {
43 let path = parse_c_str(path as *const c_char)?;
45
46 copy_nonoverlapping(
50 path.as_ptr(),
51 resolved_path,
52 usize::min(resolved_path_size, path.len()),
53 );
54
55 Ok(())
56 }
57}
58
59abi_unsafe_function! {
60 fn xila_file_system_rename(
66 old_path: *const c_char,
67 new_path: *const c_char,
68 ) -> XilaFileSystemResult {
69 let old_path = parse_c_str(old_path)?;
70 let new_path = parse_c_str(new_path)?;
71
72 block_on(virtual_file_system::get_instance().rename(&old_path, &new_path))?;
75 Ok(())
76 }
77}
78
79abi_unsafe_function! {
80 fn xila_file_system_remove(
86 task: XilaTaskIdentifier,
87 path: *const c_char,
88 ) -> XilaFileSystemResult {
89 let path = parse_c_str(path)?;
90
91 block_on(virtual_file_system::get_instance().remove(task.into(), path))
92 }
93}