use alloc::string::String;
use ax_fs_ng::fops::{Directory, File};
use crate::ApiResult;
pub use ax_fs_ng::fops::DirEntry as AxDirEntry;
pub use ax_fs_ng::fops::FileAttr as AxFileAttr;
pub use ax_fs_ng::fops::FileAttrExt as AxFileAttrExt;
pub use ax_fs_ng::fops::FilePerm as AxFilePerm;
pub use ax_fs_ng::fops::FilePermExt as AxFilePermExt;
pub use ax_fs_ng::fops::FileType as AxFileType;
pub use ax_fs_ng::fops::FileTypeExt as AxFileTypeExt;
pub use ax_fs_ng::fops::OpenOptions as AxOpenOptions;
pub use ax_io::SeekFrom as AxSeekFrom;
pub struct AxFileHandle(File);
pub struct AxDirHandle(Directory);
pub fn ax_open_file(path: &str, opts: &AxOpenOptions) -> ApiResult<AxFileHandle> {
Ok(AxFileHandle(File::open(path, opts)?))
}
pub fn ax_open_dir(path: &str, opts: &AxOpenOptions) -> ApiResult<AxDirHandle> {
Ok(AxDirHandle(Directory::open_dir(path, opts)?))
}
pub fn ax_read_file(file: &mut AxFileHandle, buf: &mut [u8]) -> ApiResult<usize> {
Ok(file.0.read(buf)?)
}
pub fn ax_read_file_at(file: &AxFileHandle, offset: u64, buf: &mut [u8]) -> ApiResult<usize> {
Ok(file.0.read_at(offset, buf)?)
}
pub fn ax_write_file(file: &mut AxFileHandle, buf: &[u8]) -> ApiResult<usize> {
Ok(file.0.write(buf)?)
}
pub fn ax_write_file_at(file: &AxFileHandle, offset: u64, buf: &[u8]) -> ApiResult<usize> {
Ok(file.0.write_at(offset, buf)?)
}
pub fn ax_truncate_file(file: &AxFileHandle, size: u64) -> ApiResult {
file.0.truncate(size)?;
Ok(())
}
pub fn ax_flush_file(file: &AxFileHandle) -> ApiResult {
file.0.flush()?;
Ok(())
}
pub fn ax_seek_file(file: &mut AxFileHandle, pos: AxSeekFrom) -> ApiResult<u64> {
Ok(file.0.seek(pos)?)
}
pub fn ax_file_attr(file: &AxFileHandle) -> ApiResult<AxFileAttr> {
Ok(file.0.get_attr()?)
}
pub fn ax_read_dir(dir: &mut AxDirHandle, dirents: &mut [AxDirEntry]) -> ApiResult<usize> {
Ok(dir.0.read_dir(dirents)?)
}
pub fn ax_create_dir(path: &str) -> ApiResult {
ax_fs_ng::api::create_dir(path)?;
Ok(())
}
pub fn ax_remove_dir(path: &str) -> ApiResult {
ax_fs_ng::api::remove_dir(path)?;
Ok(())
}
pub fn ax_remove_file(path: &str) -> ApiResult {
ax_fs_ng::api::remove_file(path)?;
Ok(())
}
pub fn ax_rename(old: &str, new: &str) -> ApiResult {
ax_fs_ng::api::rename(old, new)?;
Ok(())
}
pub fn ax_current_dir() -> ApiResult<String> {
Ok(ax_fs_ng::api::current_dir()?)
}
pub fn ax_set_current_dir(path: &str) -> ApiResult {
ax_fs_ng::api::set_current_dir(path)?;
Ok(())
}