ZystemOS / pluto

An x86 kernel written in Zig
536 stars 19 forks source link

Filesystem syscalls #265

Open SamTebbs33 opened 3 years ago

SamTebbs33 commented 3 years ago

Now that we have user mode implemented, we need some syscalls that will allow programs to interact with the filesystem.

openFile(path: [*]const u8, path_len: usize, create: bool) usize
openDir(path: [*]const u8, path_len: usize, create: bool) usize
openSymlink(path: [*]const u8, path_len: usize, target: [*]const u8, target_len: usize, create: bool) usize
read(handle: usize, buffer: [*]u8, buffer_len: usize) usize
write(handle: usize, buffer: [*]const u8, buffer_len: usize) usize
close(handle: usize)

The open functions return an integer representing a handle to that file. That integer will be used to refer to the file once it is opened. File handles are unique to each process.

Slices must be passed as a pointer and size separately since syscalls use the CPU registers which cannot store complex types. such as slices.

DrDeano commented 3 years ago

Couldn't the syscall function do the conversion from slice to pointer and length

SamTebbs33 commented 3 years ago

Couldn't the syscall function do the conversion from slice to pointer and length

If you're referring to the function that starts the syscall, then sure that can take a slice, but the actual transaction between the process and kernel have to use the two raw values. The things that look like functions in the description aren't actually functions, they're just descriptions of the syscall interface and the arguments each takes.