New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IOS: Refactor the filesystem code #6421
Conversation
ac38814
to
d3de225
Compare
The bulk of it looks good in general; the only thing that bothers me a little is the missed opportunity to address the style issues in
|
Sure, might as well fix them. Regarding |
Source/Core/Common/Swap.h
Outdated
template <typename value_type> | ||
struct BigEndianValue | ||
{ | ||
static_assert(std::is_arithmetic<value_type>::value, "value_type must be an arithmetic type"); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
||
namespace IOS::HLE::FS | ||
{ | ||
std::unique_ptr<FileSystem> MakeFileSystem(IOSC& iosc) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
1a8de0c
to
a9056de
Compare
2cdff4c
to
99cb729
Compare
I've added two more commits to futureproof this: one to avoid forgetting to close FDs, the other to make it possible to have two FS instances, each for a different NAND root. This will be useful for copying files between the configured NAND and the session NAND (for movie and netplay). |
|
||
namespace IOS::HLE::FS | ||
{ | ||
std::unique_ptr<FileSystem> MakeFileSystem(bool use_session_path) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
f60137b
to
a166b58
Compare
private: | ||
std::variant<ResultCode, T> m_variant; | ||
}; | ||
} // namespace Common |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This adds a lightweight, easy to use std::variant wrapper intended to be used as a return type for functions that can return either a result or an error code.
Add a new FileSystem class that can be used to perform operations on the emulated Wii filesystem. This will allow separating the IPC code (reading from and writing to memory to handle IOS FS commands) and the actual filesystem code in a much better way. This also paves the way for implementing another filesystem backend in the future -- NAND images for more complete emulation, including filesystem metadata like permissions or file orders, which some games and homebrew actually care about -- without needing to make any more changes to the other parts of the codebase, in addition to making filesystem behaviour tests easier to write.
Extract the existing FS code into a HostBackend implementing the filesystem interface. Compared to the original code, this uses less static state. The open host files map is now a member variable as it should have been. Filesystem handles are now also easier to savestate. Some variable names and log messages were cleaned up. Nothing else has been changed.
Now that we have a proper filesystem interface, it makes more sense to return it instead of the emulated IOS device (which isn't really usable for any purpose other than emulated IPC).
88d14a3
to
c662cef
Compare
It has nothing to do in the filesystem code. (It also smells like a workaround for some kind of timing issue.)
This is the large change in the branch. This lets us use either the host filesystem or (in the future) a NAND image exactly the same way, and make sure the IPC emulation code behaves identically. Less duplicated code. Note that "FileIO" and "FS" were merged, because it actually doesn't make a lot of sense to split them: IOS handles requests for both /dev/fs and files in the same resource manager, and as it turns out, /dev/fs commands can *also* be sent to non /dev/fs file descriptors! If we kept /dev/fs and files split, there would be no way to emulate that correctly. I'm not aware of anything that does that (yet?) but I think it's important to be correct.
Let's use the actual name of the system module. Also, the FS code is not all about files.
Return a FileHandle which will automatically close the FD when the handle goes out of scope. For the rare cases where this behaviour is undesirable, the FD can be released from the handle.
The FS IPC code already logs all commands, so keeping the log messages in the backend is redundant.
Cleaner than having the backend figure out which NAND root to use.
If no one objects to it, I am going to merge this PR in 2 days (one month after the PR was opened). |
Since all FS access will go through the new FS interface (PR dolphin-emu#6421) in order to keep track of metadata properly, there is no need to return absolute paths anymore. In fact, returning host paths is a roadblock to using the FS interface. This starts the migration work by adding a way to get paths that are relative to the Wii NAND instead of always getting absolute paths on the host FS. To prepare for future changes, this commit also makes returned paths canonical by removing the trailing slash when it's unneeded. Eventually, once everything has been migrated to the new interface, we can remove the "from" parameter.
Since all FS access will go through the new FS interface (PR dolphin-emu#6421) in order to keep track of metadata properly, there is no need to return absolute paths anymore. In fact, returning host paths is a roadblock to using the FS interface. This starts the migration work by adding a way to get paths that are relative to the Wii NAND instead of always getting absolute paths on the host FS. To prepare for future changes, this commit also makes returned paths canonical by removing the trailing slash when it's unneeded. Eventually, once everything has been migrated to the new interface, we can remove the "from" parameter.
Since all FS access will go through the new FS interface (PR dolphin-emu#6421) in order to keep track of metadata properly, there is no need to return absolute paths anymore. In fact, returning host paths is a roadblock to using the FS interface. This starts the migration work by adding a way to get paths that are relative to the Wii NAND instead of always getting absolute paths on the host FS. To prepare for future changes, this commit also makes returned paths canonical by removing the trailing slash when it's unneeded. Eventually, once everything has been migrated to the new interface, we can remove the "from" parameter.
Since all FS access will go through the new FS interface (PR dolphin-emu#6421) in order to keep track of metadata properly, there is no need to return absolute paths anymore. In fact, returning host paths is a roadblock to using the FS interface. This starts the migration work by adding a way to get paths that are relative to the Wii NAND instead of always getting absolute paths on the host FS. To prepare for future changes, this commit also makes returned paths canonical by removing the trailing slash when it's unneeded. Eventually, once everything has been migrated to the new interface, we can remove the "from" parameter.
Since all FS access will go through the new FS interface (PR dolphin-emu#6421) in order to keep track of metadata properly, there is no need to return absolute paths anymore. In fact, returning host paths is a roadblock to using the FS interface. This starts the migration work by adding a way to get paths that are relative to the Wii NAND instead of always getting absolute paths on the host FS. To prepare for future changes, this commit also makes returned paths canonical by removing the trailing slash when it's unneeded. Eventually, once everything has been migrated to the new interface, we can remove the "from" parameter.
Since all FS access will go through the new FS interface (PR dolphin-emu#6421) in order to keep track of metadata properly, there is no need to return absolute paths anymore. In fact, returning host paths is a roadblock to using the FS interface. This starts the migration work by adding a way to get paths that are relative to the Wii NAND instead of always getting absolute paths on the host FS. To prepare for future changes, this commit also makes returned paths canonical by removing the trailing slash when it's unneeded. Eventually, once everything has been migrated to the new interface, we can remove the "from" parameter.
Since all FS access will go through the new FS interface (PR dolphin-emu#6421) in order to keep track of metadata properly, there is no need to return absolute paths anymore. In fact, returning host paths is a roadblock to using the FS interface. This starts the migration work by adding a way to get paths that are relative to the Wii NAND instead of always getting absolute paths on the host FS. To prepare for future changes, this commit also makes returned paths canonical by removing the trailing slash when it's unneeded. Eventually, once everything has been migrated to the new interface, we can remove the "from" parameter.
Add a new FileSystem class that can be used to perform operations
on the emulated Wii filesystem.
This will allow separating the IPC code (reading from and writing to
memory to handle IOS FS commands) and the actual filesystem code
in a much better way.
This also paves the way for implementing another filesystem backend
in the future -- NAND images for more complete emulation, including
filesystem metadata like permissions or file orders, which some games
and homebrew actually care about -- without needing to make any more
changes to the other parts of the codebase, in addition to making
filesystem behaviour tests easier to write.