Conversation
| #include <megaton/__priv/nn/fs.h> | ||
|
|
||
|
|
||
| #define BOTWTOOLKIT_TCP_SEND2 // todo: replace with BOTWTOOLKIT_TCP_SEND (double check this) |
There was a problem hiding this comment.
Using tcp to send debug information (for now). Probably need to have a discussion about debug logging and how we want to handle that for the library. Should we write to a debug file, now that we can? Should we log to tcp? Is there a particular format we want to use for debug info?
| result = nn::fs::CreateFile(name, 0); | ||
| if(result.IsFailure()) { | ||
| botw::tcp::sendf("Library sys_open: nn::fs::CreateFile failed! Exit code=%d\n", result.GetInnerValueForDebug()); | ||
| return -1; |
There was a problem hiding this comment.
Need to look like how to manifest these errors in rust
for example there should be some other sys call to get last error ?
There was a problem hiding this comment.
I didn't see any syscall like that, could be wrong. I agree we definitely should find out how to pass these errors to Rust. I'll make an issue for it.
| } | ||
| } | ||
| botw::tcp::sendf("Unable to allocate FD - FDList is full!\n"); | ||
| return 0; |
There was a problem hiding this comment.
returning stdin in case of error seems like a bad idea
| } | ||
|
|
||
| FileDescriptor insertIntoFDList(FD fd) { | ||
| for(FileDescriptor i = 3; i < NUM_FDS; i++) { |
There was a problem hiding this comment.
Not thread safe!
Also this is not very efficient, but it might be fine for now as we are prototyping. if we have time at the end this would need fixing
|
|
||
| int32_t stat_dir(nn::fs::DirectoryHandle handle, const char* name, FileAttr* stat) { | ||
| nn::Result result; | ||
| // TODO: What values should these have? |
There was a problem hiding this comment.
look at the unix documentation for these values, there are some optional fields and it should tell you how to fill those
|
|
||
| extern "C" isize sys_read(FileDescriptor fd, u8* buf, usize len) { | ||
| botw::tcp::sendf("Library: sys_read called! fd=%d len=%d\n", fd, len); | ||
| FD outerFD = FDList[fd]; |
There was a problem hiding this comment.
needs bounds check / null check on untrusted parameters
(a good reason why writing this in Rust would be easier :p)
added access, truncate, chmod, umask
…move nnheaders from Licensor.toml
| return 0; | ||
| } | ||
| case FileDescriptorType::DIR: { | ||
| nn::fs::DirectoryHandle dh = nn::fs::DirectoryHandle { outer_fd.get_internal_fd() }; |
There was a problem hiding this comment.
nn::fs::DirectoryHandle dh { outer_fd.get_internal_fd() };
| result = nn::fs::DeleteFile(name); | ||
| if(result.IsFailure()){ | ||
| botw::tcp::sendf("Library: sys_unlink: nn::fs::DeleteFile failed with %d!\n", result.GetInnerValueForDebug()); | ||
| return -1; |
Implements the following syscalls: sys_open, sys_close, sys_read, sys_write, and sys_stat for files and directories.
Creates a basic architecture to implement the syscalls.
Essentially, to accommodate the Unix "everything is a file" approach, we store a global array of structs containing information about different kinds of file descriptors- files, directories, tcp streams, and stdio for now. Because they may store different data, I created a union to represent each of their internal mappings and state. For example, for the File FD, I store its internal fd given to us by the switch, as well as a seek offset, since the switch doesn't handle that for us.