Commit Graph

246 Commits

Author SHA1 Message Date
Zach Hilman c3becdbca7 filesystem: Clear registered union paths on factory creation 2018-11-18 23:31:30 -05:00
bunnei 5b8f70ea2e
Merge pull request #1632 from DarkLordZach/keys-manager-optimizations
game_list: Optimize game list refresh
2018-11-16 07:02:37 -08:00
Lioncash b725d1fdf7 file_sys/errors: Extract FS-related error codes to file_sys/errors.h
Keeps filesystem-related error codes in one spot.
2018-11-16 00:13:50 -05:00
Zach Hilman 4838bc8ddc fsp_srv: Add support for using open source archive if not found in NAND 2018-11-15 22:35:16 -05:00
bunnei 97605e36f7
Merge pull request #1618 from DarkLordZach/dump-nso
patch_manager: Add support for dumping uncompressed NSOs
2018-11-15 14:46:10 -08:00
Zach Hilman 8f183a47dd filesystem: Cache RegisteredCacheUnion instead of constructing on demand
Prevents unnecessary re-reads of the metadata and unnecessary temporary objects.
2018-11-01 20:24:32 -04:00
Zach Hilman bdaa76c0db ns: Implement command 400: GetApplicationControlData
Returns the raw NACP bytes and the raw icon bytes into a title-provided buffer. Pulls from Registration Cache for control data, returning all zeros should it not exist.
2018-10-29 16:20:16 -04:00
Zach Hilman 9078bb9854 bis_factory: Add getter for mod dump root for a title ID
Equates to yuzu_dir/dump/<title id>/
2018-10-29 16:08:03 -04:00
Zach Hilman 5ee19add1b fsp_srv: Implement ISaveDataInfoReader
An object to read SaveDataInfo objects, which describe a unique save on the system. This implementation iterates through all the directories in the save data space and uses the paths to reconstruct the metadata.
2018-10-29 13:54:39 -04:00
Zach Hilman 2e8177f0c9 fsp_srv: Implement command 61: OpenSaveDataInfoReaderBySaveDataSpaceId
Needed by Checkpoint. Returns an object that can iterate through all savedata on the system.
2018-10-29 13:54:39 -04:00
Zach Hilman df264d2ccb savedata_factory: Expose accessors for SaveDataSpace 2018-10-29 13:54:38 -04:00
DeeJayBro 3b1e4c0995 service/filesystem: Add DirectoryDelete & DirectoryDeleteRecursively 2018-10-27 11:56:39 +02:00
Zach Hilman 780c21ab2d fsp_srv: Apply patches to Data storage in OpenDataStorageByDataId 2018-10-17 09:04:20 -04:00
Lioncash 39ae73b356 file_sys/registered_cache: Use unique_ptr and regular pointers instead of shared_ptrs where applicable
The data retrieved in these cases are ultimately chiefly owned by either
the RegisteredCache instance itself, or the filesystem factories. Both
these should live throughout the use of their contained data. If they
don't, it should be considered an interface/design issue, and using
shared_ptr instances here would mask that, as the data would always be
prolonged after the main owner's lifetime ended.

This makes the lifetime of the data explicit and makes it harder to
accidentally create cyclic references. It also makes the interface
slightly more flexible than the previous API, as a shared_ptr can be
created from a unique_ptr, but not the other way around, so this allows
for that use-case if it ever becomes necessary in some form.
2018-10-16 09:38:52 -04:00
Lioncash 0149162dba filesystem: Make CreateFactories() and InstallInterface() take a VfsFilesystem instance by reference
Neither of these functions alter the ownership of the provided pointer,
so we can simply make the parameters a reference rather than a direct
shared pointer alias. This way we also disallow passing incorrect memory values like
nullptr.
2018-10-13 11:36:35 -04:00
Zach Hilman 38c2ac95af romfs_factory: Extract packed update setter to new function 2018-10-05 08:53:51 -04:00
Lioncash cba78dc70a services/fsp_srv: Amend service function table
Adds new functions that have been given names to the table. Information
is based off what is provided on Switchbrew.
2018-10-02 21:34:33 -04:00
Zach Hilman 940a711caf filesystem: Add LayeredFS VFS directory getter 2018-09-21 19:53:33 -04:00
David Marcec cbc7ad8f6d Fixed GetAccountId stub, Added error code for OpenDirectory and added ActivateNpadWithRevision
With these, `Nintendo Entertainment System - Nintendo Switch Online` loads
2018-09-19 23:25:00 +10:00
Lioncash 6ac955a0b4 hle/service: Default constructors and destructors in the cpp file where applicable
When a destructor isn't defaulted into a cpp file, it can cause the use
of forward declarations to seemingly fail to compile for non-obvious
reasons. It also allows inlining of the construction/destruction logic
all over the place where a constructor or destructor is invoked, which
can lead to code bloat. This isn't so much a worry here, given the
services won't be created and destroyed frequently.

The cause of the above mentioned non-obvious errors can be demonstrated
as follows:

------- Demonstrative example, if you know how the described error happens, skip forwards -------

Assume we have the following in the header, which we'll call "thing.h":

\#include <memory>

// Forward declaration. For example purposes, assume the definition
// of Object is in some header named "object.h"
class Object;

class Thing {
public:
    // assume no constructors or destructors are specified here,
    // or the constructors/destructors are defined as:
    //
    // Thing() = default;
    // ~Thing() = default;
    //

    // ... Some interface member functions would be defined here

private:
    std::shared_ptr<Object> obj;
};

If this header is included in a cpp file, (which we'll call "main.cpp"),
this will result in a compilation error, because even though no
destructor is specified, the destructor will still need to be generated by
the compiler because std::shared_ptr's destructor is *not* trivial (in
other words, it does something other than nothing), as std::shared_ptr's
destructor needs to do two things:

1. Decrement the shared reference count of the object being pointed to,
   and if the reference count decrements to zero,

2. Free the Object instance's memory (aka deallocate the memory it's
   pointing to).

And so the compiler generates the code for the destructor doing this inside main.cpp.

Now, keep in mind, the Object forward declaration is not a complete type. All it
does is tell the compiler "a type named Object exists" and allows us to
use the name in certain situations to avoid a header dependency. So the
compiler needs to generate destruction code for Object, but the compiler
doesn't know *how* to destruct it. A forward declaration doesn't tell
the compiler anything about Object's constructor or destructor. So, the
compiler will issue an error in this case because it's undefined
behavior to try and deallocate (or construct) an incomplete type and
std::shared_ptr and std::unique_ptr make sure this isn't the case
internally.

Now, if we had defaulted the destructor in "thing.cpp", where we also
include "object.h", this would never be an issue, as the destructor
would only have its code generated in one place, and it would be in a
place where the full class definition of Object would be visible to the
compiler.

---------------------- End example ----------------------------

Given these service classes are more than certainly going to change in
the future, this defaults the constructors and destructors into the
relevant cpp files to make the construction and destruction of all of
the services consistent and unlikely to run into cases where forward
declarations are indirectly causing compilation errors. It also has the
plus of avoiding the need to rebuild several services if destruction
logic changes, since it would only be necessary to recompile the single
cpp file.
2018-09-10 23:55:31 -04:00
Zach Hilman c913136eb2 bktr: Fix bucket overlap error 2018-09-04 17:01:54 -04:00
Zach Hilman 9951f6d054 registration: Add RegisteredCacheUnion
Aggregates multiple caches into one interface
2018-09-04 16:21:40 -04:00
bunnei 325f3e0693
Merge pull request #1213 from DarkLordZach/octopath-fs
filesystem/maxwell_3d: Various changes to boot Project Octopath Traveller
2018-09-02 10:49:18 -04:00
Lioncash fda8f1da20 filesystem: Move dir retrieval after path checking in DeleteFile()
We don't need to do the lookup if the path is considered empty
currently.
2018-09-02 09:20:17 -04:00
Zach Hilman 19d0951ae6 filesystem: Implement OpenReadOnlySaveDataFilesystem 2018-08-31 23:19:49 -04:00
Zach Hilman 7939ea18e8 filesystem: Add OpenFileSystemWithPatch 2018-08-31 23:19:23 -04:00
Lioncash 4a587b81b2 core/core: Replace includes with forward declarations where applicable
The follow-up to e2457418da, which
replaces most of the includes in the core header with forward declarations.

This makes it so that if any of the headers the core header was
previously including change, then no one will need to rebuild the bulk
of the core, due to core.h being quite a prevalent inclusion.

This should make turnaround for changes much faster for developers.
2018-08-31 16:30:14 -04:00
Sebastian Valle f170159fde
Merge pull request #1166 from lioncash/typo
filesystem: Fix typo in log message
2018-08-25 07:19:46 -05:00
Lioncash f6f5c2e4d8 filesystem: Fix typo in log message 2018-08-23 22:12:31 -04:00
Zach Hilman ef3768f323 filesystem: Add CreateFactories methods to fs
Allows frontend to create registration caches for use before a game has booted.
2018-08-23 11:52:44 -04:00
Zach Hilman 410062031b filesystem: Add logging to registration getters 2018-08-23 11:52:44 -04:00
Lioncash 29ac15d1b8 vfs: Replace mode.h include with forward declarations where applicable
Avoids the need to rebuild these source files if the mode header
changes.
2018-08-21 15:06:42 -04:00
Lioncash 477eee3993 service/filesystem: Use forward declarations where applicable
Avoids the need to rebuild multiple source files if the filesystem code
headers change.

This also gets rid of a few instances of indirect inclusions being
relied upon
2018-08-20 23:28:46 -04:00
Zach Hilman 27da7bc9da filesystem: Add support for loading of system archives 2018-08-18 21:28:23 -04:00
Zach Hilman c0257cf52f filesystem: Add Open and Register functions for BISFactory 2018-08-11 22:50:48 -04:00
bunnei 69cd213fac
Merge pull request #990 from lioncash/entry
fsp_srv: Emplace entries first when building index instead of emplacing last
2018-08-09 19:29:36 -04:00
Zach Hilman 4b471f0554 core: Port core to VfsFilesystem for file access 2018-08-08 21:18:45 -04:00
Zach Hilman b36dee364e filesystem: Remove unnecessary if conditions 2018-08-08 21:18:45 -04:00
Lioncash 7353cfc781 fsp_srv: Use std::string_view's copy() function instead of strncpy()
Given elements inserted into a vector are zeroed out, we can just copy
MAX_LEN - 1 elements and the data will already be properly null
terminated.
2018-08-08 18:51:52 -04:00
Lioncash 4afb05d0cc fsp_srv: Emplace entries first when building index instead of emplacing last
The current way were doing it would require copying a 768 character
buffer (part of the Entry struct) to the new element in the vector.
Given it's a plain array, std::move won't eliminate that.

Instead, we can emplace an instance directly into the destination buffer
and then fill it out, avoiding the need to perform any unnecessary
copies.

Given this is done in a loop, we can request the destination to allocate
all of the necessary memory ahead of time, avoiding the need to
potentially keep reallocating over and over on every few insertions into
the vector.
2018-08-08 18:51:41 -04:00
Lioncash df51207ed2 service: Remove redundant #pragma once directives
These don't do anything within .cpp files (we don't include cpp files,
so...)
2018-08-04 17:39:08 -04:00
Lioncash 208a457909 service/filesystem: Add fsp:ldr and fsp:pr services
Adds the basic skeleton for the remaining fsp services based off
information provided by Switch Brew.
2018-08-01 17:01:29 -04:00
Zach Hilman 59cb258409 VFS Regression and Accuracy Fixes (#776)
* Regression and Mode Fixes

* Review Fixes

* string_view correction

* Add operator& for FileSys::Mode

* Return std::string from SanitizePath

* Farming Simulator Fix

* Use != With mode operator&
2018-07-23 19:40:35 -07:00
Lioncash 398444e676 file_util, vfs: Use std::string_view where applicable
Avoids unnecessary construction of std::string instances where
applicable.
2018-07-22 03:22:21 -04:00
Lioncash d66b43dadf file_util: Use an enum class for GetUserPath()
Instead of using an unsigned int as a parameter and expecting a user to
always pass in the correct values, we can just convert the enum into an
enum class and use that type as the parameter type instead, which makes
the interface more type safe.

We also get rid of the bookkeeping "NUM_" element in the enum by just
using an unordered map. This function is generally low-frequency in
terms of calls (and I'd hope so, considering otherwise would mean we're
slamming the disk with IO all the time) so I'd consider this acceptable
in this case.
2018-07-21 16:21:19 -04:00
Sebastian Valle 78dd1cd441
Merge pull request #720 from Subv/getentrytype_root
Filesystem: Return EntryType::Directory for the root directory.
2018-07-19 15:23:32 -05:00
bunnei 38b35e752b
Merge pull request #712 from lioncash/fsp
fsp_srv: Misc individual changes
2018-07-19 12:31:33 -07:00
Subv e5c916a27c Filesystem: Return EntryType::Directory for the root directory.
It is unknown if this is correct behavior, but it makes sense and fixes a regression with Stardew Valley.
2018-07-19 13:11:09 -05:00
Lioncash 6c1ba02e0c fsp_srv: Remove unnecessary vector construction in IFile's Write() function
We can avoid constructing a std::vector here by simply passing a pointer
to the original data and the size of the copy we wish to perform to the
backend's Write() function instead, avoiding copying the data where it's
otherwise not needed.
2018-07-19 11:01:07 -04:00
Lioncash 3e9b79e088 fsp_srv: Remove unnecessary std::vector construction in IDirectory's Read() function
We were using a second std::vector as a buffer to convert another
std::vector's data into a byte sequence, however we can just use
pointers to the original data and use them directly with WriteBuffer,
which avoids copying the data at all into a separate std::vector.

We simply cast the pointers to u8* (which is allowed by the standard,
given std::uint8_t is an alias for unsigned char on platforms that we
support).
2018-07-19 10:46:54 -04:00
Lioncash 5da4c78c6a filesystem: std::move VirtualDir instance in VfsDirectoryServiceWrapper's constructor
Avoids unnecessary atomic reference count incrementing and decrementing
2018-07-19 10:34:11 -04:00
Lioncash abbf038191 filesystem: Use std::string's empty() function instead of comparing against a literal
This is simply a basic value check as opposed to potentially doing
string based operations (unlikely, but still, avoiding it is free).
2018-07-19 10:32:23 -04:00
Lioncash 2cc0ef83cf filesystem: Remove pragma disabling global optimizations
This was just an artifact missed during PR review.
2018-07-19 10:30:53 -04:00
Lioncash f317080f40 fsp_srv: Make IStorage constructor explicit
Prevents implicit conversions.
2018-07-19 10:04:16 -04:00
Lioncash 910ad2e110 fsp_srv: Add missing includes
Gets rid of relying on indirect inclusions.
2018-07-19 10:03:17 -04:00
Lioncash 6be342118a fsp_srv: Resolve sign-mismatch warnings in assertion comparisons 2018-07-19 09:58:32 -04:00
Lioncash d6e9b96e2f fsp_srv: Respect write length in Write()
Previously we were just copying the data whole-sale, even if the length
was less than the total data size. This effectively makes the
actual_data vector useless, which is likely not intended.

Instead, amend this to only copy the given length amount of data.

At the same time, we can avoid zeroing out the data before using it by
passing iterators to the constructor instead of a size.
2018-07-19 09:57:48 -04:00
Zach Hilman 29aff8d5ab Virtual Filesystem 2: Electric Boogaloo (#676)
* Virtual Filesystem

* Fix delete bug and documentate

* Review fixes + other stuff

* Fix puyo regression
2018-07-18 18:07:11 -07:00
Zach Hilman 69bfe075b5 General Filesystem and Save Data Fixes (#670) 2018-07-17 12:42:15 -07:00
bunnei 7230ceb584
Merge pull request #559 from Subv/mount_savedata
Services/FS: Return the correct error code when trying to mount a nonexistent savedata.
2018-07-11 20:21:52 -07:00
bunnei 913896cbd9 Revert "Virtual Filesystem (#597)"
This reverts commit 77c684c114.
2018-07-07 20:24:51 -07:00
Zach Hilman 77c684c114 Virtual Filesystem (#597)
* Add VfsFile and VfsDirectory classes

* Finish abstract Vfs classes

* Implement RealVfsFile (computer fs backend)

* Finish RealVfsFile and RealVfsDirectory

* Finished OffsetVfsFile

* More changes

* Fix import paths

* Major refactor

* Remove double const

* Use experimental/filesystem or filesystem depending on compiler

* Port partition_filesystem

* More changes

* More Overhaul

* FSP_SRV fixes

* Fixes and testing

* Try to get filesystem to compile

* Filesystem on linux

* Remove std::filesystem and document/test

* Compile fixes

* Missing include

* Bug fixes

* Fixes

* Rename v_file and v_dir

* clang-format fix

* Rename NGLOG_* to LOG_*

* Most review changes

* Fix TODO

* Guess 'main' to be Directory by filename
2018-07-06 10:51:32 -04:00
James Rowe 0d46f0df12 Update clang format 2018-07-02 21:45:47 -04:00
James Rowe 638956aa81 Rename logging macro back to LOG_* 2018-07-02 21:45:47 -04:00
Subv 5f57a70a7d Services/FS: Return the correct error code when trying to mount a nonexistent savedata. 2018-06-18 19:26:01 -05:00
mailwl a2efb1dd48 Common/string_util: add StringFromBuffer function
convert input buffer (std::vector<u8>) to string, stripping zero chars
2018-06-07 09:59:47 +03:00
Lioncash 7c9644646f
general: Make formatting of logged hex values more straightforward
This makes the formatting expectations more obvious (e.g. any zero padding specified
is padding that's entirely dedicated to the value being printed, not any pretty-printing
that also gets tacked on).
2018-05-02 09:49:36 -04:00
Lioncash b5b613ea29
filesystem: Move logging macros over to new fmt-compatible ones 2018-04-24 12:00:52 -04:00
mailwl a0179e5ca5 Service/FS: implement IFileSystem::RenameFile 2018-04-24 10:56:05 +03:00
Lioncash ccca5e7c28 service: Use nested namespace specifiers where applicable
Tidies up namespace declarations
2018-04-19 22:20:28 -04:00
bunnei bddad50dd4 fsp_srv: Implement DeleteFile.
- Used by Binding of Isaac.
2018-04-15 13:15:18 -04:00
bunnei 9cab6809f2 fsp_srv: Implement IFile::Flush. 2018-04-14 19:46:09 -04:00
Hexagon12 cc89b7bfcb Various fixes and clang 2018-04-11 14:48:56 +03:00
Hexagon12 ae5e2d07c6
Updated fsp-srv with more service names. 2018-04-10 19:30:27 +03:00
James Rowe f16eb90b8f Fix spelling of Initialize 2018-04-07 07:23:21 -06:00
bunnei f4ba523992 hle_ipc, fsp_srv: Cleanup logging. 2018-03-31 23:30:00 -04:00
bunnei 88582b84a5 fsp_srv: Implement GetSize and SetSize. 2018-03-31 16:06:45 -04:00
bunnei a397a9e9a4
Merge pull request #255 from Subv/sd_card
FS: Implemented access to the SD card
2018-03-23 20:48:26 -04:00
Subv eff3f60b73 FS: Implemented IFileSystem::CreateDirectory. 2018-03-21 09:55:59 -05:00
Subv 0485ee499f FS: Implemented IFileSystem's OpenDirectory function.
Note that the filter parameter is not yet implemented.
2018-03-19 23:02:30 -05:00
Subv 21bac2d7d7 FS: Added the IDirectory IPC interface and implemented its two functions. 2018-03-19 23:01:47 -05:00
Subv 808704c78c FS: Implement MountSdCard. 2018-03-19 21:21:49 -05:00
Subv c4ca802b9d FS: Added an SDMC archive factory and registered it to the SDMC archive on startup. 2018-03-19 21:17:15 -05:00
N00byKing d16e08454d
oops 2018-03-19 17:43:04 +01:00
N00byKing ef875d6a35 Clean Warnings (?) 2018-03-19 17:07:08 +01:00
Subv e4b7a1d160 FS: Stubbed CreateSaveData. It currently does nothing. 2018-03-04 14:31:57 -05:00
Subv 0eefe6e4d1 FS: Make EnsureSaveData create the savedata folder when called for the first time. 2018-03-04 14:30:07 -05:00
Subv cc6e4ae6cf FS: Implement MountSaveData and some of the IFile interface. 2018-03-01 19:03:53 -05:00
Subv d140c8ecf7 Filesystem: Added a SaveData Factory and associated Disk_FileSystem. 2018-03-01 19:03:52 -05:00
bunnei 516a95721c service: Remove remaining uses of BufferDescriptor*. 2018-02-13 23:54:13 -05:00
bunnei 8e7da73214 fsp_srv: Stub MountSdCard. 2018-02-09 23:33:50 -05:00
mailwl 335096e19a Service: stub some functions in am, audio, time, vi services 2018-02-07 15:11:17 +03:00
bunnei 1b1d399e5f hle: Rename RequestBuilder to ResponseBuilder. 2018-01-24 22:24:10 -05:00
bunnei f9dae99006 service: Fix all incorrect IPC response headers. 2018-01-24 22:21:33 -05:00
bunnei 8e50d6002b fsp_srv: Various improvements to IStorage:Read implementation. 2018-01-21 15:51:43 -05:00
David Marcec d64b7d7dfd filesystem: Implement basic IStorage functionality. 2018-01-21 15:39:28 -05:00