fix: 10 separate fs functions, SF_FILE constant, pub(crate) FsBlock
This commit is contained in:
1 parent
819ffb3e5a
commit
de15d645b4
4 files changed
+61
-18
No files matched your search
@@ -1,16 +1,58 @@
|
|||||||
use core::ffi::CStr;
|
use core::ffi::CStr;
|
||||||
use crate::sys::{fs_read, FsInfo};
|
use crate::sys::{fs_execute, FsBlock};
|
||||||
|
|
||||||
pub fn read_file(path: &CStr, buf: &mut [u8]) -> Result<(), u32> {
|
fn execute(op: u32, offset: u32, offset_hi: u32, count: u32, buf: *mut u8, path: &CStr) -> Result<(), u32> {
|
||||||
let info = FsInfo {
|
let info = FsBlock {
|
||||||
operation: 0,
|
operation: op,
|
||||||
offset: 0,
|
offset,
|
||||||
offset_hi: 0,
|
offset_hi,
|
||||||
byte_count: buf.len() as u32,
|
byte_count: count,
|
||||||
buffer: buf.as_mut_ptr(),
|
buffer: buf,
|
||||||
reserved: 0,
|
_pad: 0,
|
||||||
path: path.as_ptr() as *const u8,
|
path: path.as_ptr() as *const u8,
|
||||||
};
|
};
|
||||||
let result = unsafe { fs_read(&info) };
|
match unsafe { fs_execute(&info) } {
|
||||||
if result == 0 { Ok(()) } else { Err(result) }
|
0 => Ok(()),
|
||||||
|
e => Err(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_file(path: &CStr, buf: &mut [u8]) -> Result<(), u32> {
|
||||||
|
execute(0, 0, 0, buf.len() as u32, buf.as_mut_ptr(), path)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_folder(path: &CStr, buf: &mut [u8]) -> Result<(), u32> {
|
||||||
|
execute(1, 0, 0, buf.len() as u32, buf.as_mut_ptr(), path)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_file(path: &CStr, buf: &[u8]) -> Result<(), u32> {
|
||||||
|
execute(2, 0, 0, buf.len() as u32, buf.as_ptr() as *mut u8, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_file(path: &CStr, buf: &[u8]) -> Result<(), u32> {
|
||||||
|
execute(3, 0, 0, buf.len() as u32, buf.as_ptr() as *mut u8, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_size(path: &CStr, size: u64) -> Result<(), u32> {
|
||||||
|
execute(4, size as u32, (size >> 32) as u32, 0, core::ptr::null_mut(), path)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_attributes(path: &CStr, buf: &mut [u8]) -> Result<(), u32> {
|
||||||
|
execute(5, 0, 0, buf.len() as u32, buf.as_mut_ptr(), path)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_attributes(path: &CStr, buf: &[u8]) -> Result<(), u32> {
|
||||||
|
execute(6, 0, 0, buf.len() as u32, buf.as_ptr() as *mut u8, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(path: &CStr) -> Result<(), u32> {
|
||||||
|
execute(7, 0, 0, 0, core::ptr::null_mut(), path)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete(path: &CStr) -> Result<(), u32> {
|
||||||
|
execute(8, 0, 0, 0, core::ptr::null_mut(), path)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_folder(path: &CStr) -> Result<(), u32> {
|
||||||
|
execute(9, 0, 0, 0, core::ptr::null_mut(), path)
|
||||||
}
|
}
|
||||||
@@ -20,3 +20,4 @@ SF_SYS_MISC = 68
|
|||||||
SSF_MEM_ALLOC = 12
|
SSF_MEM_ALLOC = 12
|
||||||
SSF_MEM_FREE = 13
|
SSF_MEM_FREE = 13
|
||||||
SSF_LOAD_DLL = 19
|
SSF_LOAD_DLL = 19
|
||||||
|
SF_FILE = 70
|
||||||
+4
-4
@@ -69,17 +69,17 @@ extern "C" {
|
|||||||
pub fn load_dll(name: *const u8) -> *const u32;
|
pub fn load_dll(name: *const u8) -> *const u32;
|
||||||
|
|
||||||
// 70
|
// 70
|
||||||
#[link_name = "_fs_read"]
|
#[link_name = "_fs_execute"]
|
||||||
pub fn fs_read(info: *const FsInfo) -> u32;
|
pub fn fs_execute(info: *const FsBlock) -> u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct FsInfo {
|
pub(crate) struct FsBlock {
|
||||||
pub operation: u32,
|
pub operation: u32,
|
||||||
pub offset: u32,
|
pub offset: u32,
|
||||||
pub offset_hi: u32,
|
pub offset_hi: u32,
|
||||||
pub byte_count: u32,
|
pub byte_count: u32,
|
||||||
pub buffer: *mut u8,
|
pub buffer: *mut u8,
|
||||||
pub reserved: u8,
|
pub _pad: u8,
|
||||||
pub path: *const u8,
|
pub path: *const u8,
|
||||||
}
|
}
|
||||||
+3
-3
@@ -20,7 +20,7 @@ section '.text'
|
|||||||
public _get_lang
|
public _get_lang
|
||||||
public _load_dll
|
public _load_dll
|
||||||
public _set_event_mask
|
public _set_event_mask
|
||||||
public _fs_read
|
public _fs_execute
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
mov eax, SF_TERMINATE_PROCESS
|
mov eax, SF_TERMINATE_PROCESS
|
||||||
@@ -144,9 +144,9 @@ _set_event_mask:
|
|||||||
int 0x40
|
int 0x40
|
||||||
ret
|
ret
|
||||||
|
|
||||||
_fs_read:
|
_fs_execute:
|
||||||
push ebx
|
push ebx
|
||||||
mov eax, 70
|
mov eax, SF_FILE
|
||||||
mov ebx, [esp + 4 * 2]
|
mov ebx, [esp + 4 * 2]
|
||||||
int 0x40
|
int 0x40
|
||||||
pop ebx
|
pop ebx
|
||||||
|
|||||||
Reference in new issue
Block a user