1use alloc::string::String;
2use axerrno::AxResult;
3use axfs::fops::{Directory, File};
4
5pub use axfs::fops::DirEntry as AxDirEntry;
6pub use axfs::fops::FileAttr as AxFileAttr;
7pub use axfs::fops::FilePerm as AxFilePerm;
8pub use axfs::fops::FileType as AxFileType;
9pub use axfs::fops::OpenOptions as AxOpenOptions;
10pub use axio::SeekFrom as AxSeekFrom;
11
12#[cfg(feature = "myfs")]
13pub use axfs::fops::{Disk as AxDisk, MyFileSystemIf};
14
15pub struct AxFileHandle(File);
17
18pub struct AxDirHandle(Directory);
20
21pub fn ax_open_file(path: &str, opts: &AxOpenOptions) -> AxResult<AxFileHandle> {
22 Ok(AxFileHandle(File::open(path, opts)?))
23}
24
25pub fn ax_open_dir(path: &str, opts: &AxOpenOptions) -> AxResult<AxDirHandle> {
26 Ok(AxDirHandle(Directory::open_dir(path, opts)?))
27}
28
29pub fn ax_read_file(file: &mut AxFileHandle, buf: &mut [u8]) -> AxResult<usize> {
30 file.0.read(buf)
31}
32
33pub fn ax_read_file_at(file: &AxFileHandle, offset: u64, buf: &mut [u8]) -> AxResult<usize> {
34 file.0.read_at(offset, buf)
35}
36
37pub fn ax_write_file(file: &mut AxFileHandle, buf: &[u8]) -> AxResult<usize> {
38 file.0.write(buf)
39}
40
41pub fn ax_write_file_at(file: &AxFileHandle, offset: u64, buf: &[u8]) -> AxResult<usize> {
42 file.0.write_at(offset, buf)
43}
44
45pub fn ax_truncate_file(file: &AxFileHandle, size: u64) -> AxResult {
46 file.0.truncate(size)
47}
48
49pub fn ax_flush_file(file: &AxFileHandle) -> AxResult {
50 file.0.flush()
51}
52
53pub fn ax_seek_file(file: &mut AxFileHandle, pos: AxSeekFrom) -> AxResult<u64> {
54 file.0.seek(pos)
55}
56
57pub fn ax_file_attr(file: &AxFileHandle) -> AxResult<AxFileAttr> {
58 file.0.get_attr()
59}
60
61pub fn ax_read_dir(dir: &mut AxDirHandle, dirents: &mut [AxDirEntry]) -> AxResult<usize> {
62 dir.0.read_dir(dirents)
63}
64
65pub fn ax_create_dir(path: &str) -> AxResult {
66 axfs::api::create_dir(path)
67}
68
69pub fn ax_remove_dir(path: &str) -> AxResult {
70 axfs::api::remove_dir(path)
71}
72
73pub fn ax_remove_file(path: &str) -> AxResult {
74 axfs::api::remove_file(path)
75}
76
77pub fn ax_rename(old: &str, new: &str) -> AxResult {
78 axfs::api::rename(old, new)
79}
80
81pub fn ax_current_dir() -> AxResult<String> {
82 axfs::api::current_dir()
83}
84
85pub fn ax_set_current_dir(path: &str) -> AxResult {
86 axfs::api::set_current_dir(path)
87}