1use safa_abi::{
2 errors::ErrorStatus,
3 ffi::str::Str,
4 fs::{DirEntry, OpenOptions},
5};
6
7use super::SyscallNum;
8use super::{define_syscall, err_from_u16};
9use crate::syscalls::types::{OptionalPtrMut, RequiredPtr, RequiredPtrMut, Ri};
10
11define_syscall!(SyscallNum::SysFGetDirEntry => {
12 sysgetdirentry(path: Str, dest_direntry: OptionalPtrMut<DirEntry>)
16});
17
18#[inline]
19pub fn getdirentry(path: &str) -> Result<DirEntry, ErrorStatus> {
20 let mut dest_direntry: DirEntry = unsafe { core::mem::zeroed() };
21 let ptr = RequiredPtrMut::new(&raw mut dest_direntry).into();
22
23 err_from_u16!(sysgetdirentry(Str::from_str(path), ptr), dest_direntry)
24}
25
26define_syscall! {
27 SyscallNum::SysFSOpenAll => {
28 sysopen_all(path: Str, dest_fd: RequiredPtr<Ri>)
32 },
33 SyscallNum::SysFSOpen => {
34 sysopen(path: Str, options: OpenOptions, dest_fd: RequiredPtrMut<Ri>)
38 },
39 SyscallNum::SysFSCreate => {
40 syscreate_file(path: Str)
43 },
44 SyscallNum::SysFSCreateDir => {
45 syscreate_dir(path: Str)
49 },
50 SyscallNum::SysFSRemovePath => {
51 sysremove_path(path: Str)
55 },
56}
57
58#[inline]
59pub fn open_all(path: &str) -> Result<Ri, ErrorStatus> {
63 let mut dest_fd = 0xAAAAAAAAAAAAAAAAusize;
64 let ptr = unsafe { RequiredPtrMut::new_unchecked(&raw mut dest_fd) };
65 err_from_u16!(sysopen_all(Str::from_str(path), ptr), dest_fd)
66}
67
68#[inline]
72pub fn open(path: &str, options: OpenOptions) -> Result<Ri, ErrorStatus> {
73 let mut dest_fd = 0xAAAAAAAAAAAAAAAAusize;
74 let ptr = unsafe { RequiredPtrMut::new_unchecked(&raw mut dest_fd) };
75 err_from_u16!(sysopen(Str::from_str(path), options, ptr), dest_fd)
76}
77
78#[inline]
79pub fn create(path: &str) -> Result<(), ErrorStatus> {
83 err_from_u16!(syscreate_file(Str::from_str(path)))
84}
85
86#[inline]
87pub fn createdir(path: &str) -> Result<(), ErrorStatus> {
91 err_from_u16!(syscreate_dir(Str::from_str(path)))
92}
93
94#[inline]
95pub fn remove_path(path: &str) -> Result<(), ErrorStatus> {
99 err_from_u16!(sysremove_path(Str::from_str(path)))
100}