switchbrew / libnx

Library for Switch Homebrew
https://switchbrew.github.io/libnx/
ISC License
1.27k stars 174 forks source link

Add native RomFS file and directory handling #645

Open Bulmanator opened 4 months ago

Bulmanator commented 4 months ago

This exposes some more of the RomFS API to the public facing side allowing file "opening" and directory listing natively without requiring stdio. The main reason for this is to allow reading RomFS files from an arbitary offset without first seeking the file position. As RomFS is read-only this is crucial for contentionless multi-threaded access, but is unfortunately missing from stdio. I kinda just did the directory iteration stuff to round out the API, they both have the added benefit of requiring zero allocation.

The stdio implementation has been updated to use the native APIs as well with a slight caveat when calling romfs_open. It used to return ENOENT if the directory didn't exist but EROFS if the file didn't exist and the O_CREAT flag was set. It now returns EROFS in either case if the O_CREAT flag is set.

I'm happy to write up an example usage for the switchbrew/switch-examples repository.