Add filesystem syscall 70 wrapper and fs_demo example #10
No files matched your search
@@ -0,0 +1,25 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use kos::fs::{FileInfo, fs_read};
|
||||
|
||||
static FILENAME: &[u8] = b"/rd/1/readme.txt\0";
|
||||
|
Sweetbread marked this conversation as resolved
|
||||
static mut BUFFER: [u8; 256] = [0u8; 256];
|
||||
|
Sweetbread marked this conversation as resolved
Outdated
Sweetbread
commented
Look at other examples for start command Look at other examples for start command
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
unsafe {
|
||||
|
Sweetbread marked this conversation as resolved
Outdated
Sweetbread
commented
In examples should not be In examples should not be `unsafe`s
|
||||
let info = FileInfo {
|
||||
func: 0,
|
||||
param1: 0,
|
||||
param2: 0,
|
||||
param3: 256,
|
||||
buf: BUFFER.as_mut_ptr(),
|
||||
name: FILENAME.as_ptr(),
|
||||
};
|
||||
|
||||
let (_result, _bytes_read) = fs_read(&info as *const FileInfo);
|
||||
}
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
Sweetbread marked this conversation as resolved
Outdated
Sweetbread
commented
Add the example into Add the example into `Cargo.toml`
|
||||
@@ -0,0 +1,31 @@
|
||||
use core::arch::asm;
|
||||
|
||||
/// KolibriOS Function 70 — filesystem operations
|
||||
/// Passes a pointer to a FileInfo structure via ebx
|
||||
/// int 0x40 with eax=70 is the KolibriOS FS syscall
|
||||
|
||||
#[repr(C, packed)]
|
||||
pub struct FileInfo {
|
||||
pub func: u32, // 0 = read, 1 = read folder, 2 = create/write
|
||||
pub param1: u32, // offset (low)
|
||||
pub param2: u32, // offset (high) or flags
|
||||
pub param3: u32, // bytes to read/write
|
||||
|
Sweetbread marked this conversation as resolved
Outdated
Sweetbread
commented
Em? Why not just name them istead of writing comment? Em? Why not just name them istead of writing comment?
|
||||
pub buf: *mut u8, // pointer to buffer
|
||||
pub name: *const u8, // pointer to filename (ASCIIZ)
|
||||
}
|
||||
|
||||
/// Opens/reads a file on KolibriOS using syscall eax=70
|
||||
/// Returns (eax_result, ebx_bytes_read)
|
||||
|
Sweetbread marked this conversation as resolved
Outdated
Sweetbread
commented
That's too low-level. Those functions should be in That's too low-level. Those functions should be in `src/sys.rs`
|
||||
pub unsafe fn fs_read(info: *const FileInfo) -> (u32, u32) {
|
||||
let eax_out: u32;
|
||||
let ebx_out: u32;
|
||||
unsafe {
|
||||
asm!(
|
||||
"int 0x40",
|
||||
inlateout("eax") 70u32 => eax_out,
|
||||
inlateout("ebx") info as u32 => ebx_out,
|
||||
options(nostack)
|
||||
);
|
||||
}
|
||||
(eax_out, ebx_out)
|
||||
}
|
||||
Reference in new issue
Block a user
Use
c"..."for c-strings