diff --git a/src/LibHac/Fs/FsEnums.cs b/src/LibHac/Fs/FsEnums.cs index 236998d1..ea0ca1ad 100644 --- a/src/LibHac/Fs/FsEnums.cs +++ b/src/LibHac/Fs/FsEnums.cs @@ -143,10 +143,14 @@ namespace LibHac.Fs public enum OperationId { - Clear = 0, - ClearSignature = 1, + FillZero = 0, + DestroySignature = 1, InvalidateCache = 2, - QueryRange = 3 + QueryRange = 3, + QueryUnpreparedRange = 4, + QueryLazyLoadCompletionRate = 5, + SetLazyLoadPriority = 6, + ReadyLazyLoadFile = 10001 } public enum SaveDataType : byte diff --git a/src/LibHac/Fs/Fsa/IFileSystem.cs b/src/LibHac/Fs/Fsa/IFileSystem.cs index 8ab4a061..ad6fd1f0 100644 --- a/src/LibHac/Fs/Fsa/IFileSystem.cs +++ b/src/LibHac/Fs/Fsa/IFileSystem.cs @@ -17,23 +17,16 @@ namespace LibHac.Fs.Fsa /// The initial size of the created file. /// Flags to control how the file is created. /// Should usually be - /// The of the requested operation. - /// - /// The following codes may be returned under certain conditions: - /// - /// The parent directory of the specified path does not exist: - /// Specified path already exists as either a file or directory: - /// Insufficient free space to create the file: - /// - public Result CreateFile(U8Span path, long size, CreateFileOptions option) + /// : The operation was successful.
+ /// : The parent directory of the specified path does not exist.
+ /// : Specified path already exists as either a file or directory.
+ /// : Insufficient free space to create the file.
+ public Result CreateFile(in Path path, long size, CreateFileOptions option) { - if (path.IsNull()) - return ResultFs.NullptrArgument.Log(); - if (size < 0) return ResultFs.OutOfRange.Log(); - return DoCreateFile(path, size, option); + return DoCreateFile(in path, size, option); } /// @@ -42,141 +35,88 @@ namespace LibHac.Fs.Fsa /// The full path of the file to create. /// The initial size of the created file. /// Should usually be - /// The of the requested operation. - /// - /// The following codes may be returned under certain conditions: - /// - /// The parent directory of the specified path does not exist: - /// Specified path already exists as either a file or directory: - /// Insufficient free space to create the file: - /// - public Result CreateFile(U8Span path, long size) + /// : The operation was successful.
+ /// : The parent directory of the specified path does not exist.
+ /// : Specified path already exists as either a file or directory.
+ /// : Insufficient free space to create the file.
+ public Result CreateFile(in Path path, long size) { - if (path.IsNull()) - return ResultFs.NullptrArgument.Log(); - - if (size < 0) - return ResultFs.OutOfRange.Log(); - - return DoCreateFile(path, size, CreateFileOptions.None); + return CreateFile(in path, size, CreateFileOptions.None); } /// /// Deletes the specified file. /// /// The full path of the file to delete. - /// The of the requested operation. - /// - /// The following codes may be returned under certain conditions: - /// - /// The specified path does not exist or is a directory: - /// - public Result DeleteFile(U8Span path) + /// : The operation was successful.
+ /// : The specified path does not exist or is a directory.
+ public Result DeleteFile(in Path path) { - if (path.IsNull()) - return ResultFs.NullptrArgument.Log(); - - return DoDeleteFile(path); + return DoDeleteFile(in path); } /// /// Creates all directories and subdirectories in the specified path unless they already exist. /// /// The full path of the directory to create. - /// The of the requested operation. - /// - /// The following codes may be returned under certain conditions: - /// - /// The parent directory of the specified path does not exist: - /// Specified path already exists as either a file or directory: - /// Insufficient free space to create the directory: - /// - public Result CreateDirectory(U8Span path) + /// : The operation was successful.
+ /// : The parent directory of the specified path does not exist.
+ /// : Specified path already exists as either a file or directory.
+ /// : Insufficient free space to create the directory.
+ public Result CreateDirectory(in Path path) { - if (path.IsNull()) - return ResultFs.NullptrArgument.Log(); - - return DoCreateDirectory(path); + return DoCreateDirectory(in path); } /// /// Deletes the specified directory. /// /// The full path of the directory to delete. - /// The of the requested operation. - /// - /// The following codes may be returned under certain conditions: - /// - /// The specified path does not exist or is a file: - /// The specified directory is not empty: - /// - public Result DeleteDirectory(U8Span path) + /// : The operation was successful.
+ /// : The specified path does not exist or is a file.
+ /// : The specified directory is not empty.
+ public Result DeleteDirectory(in Path path) { - if (path.IsNull()) - return ResultFs.NullptrArgument.Log(); - - return DoDeleteDirectory(path); + return DoDeleteDirectory(in path); } /// /// Deletes the specified directory and any subdirectories and files in the directory. /// /// The full path of the directory to delete. - /// The of the requested operation. - /// - /// The following codes may be returned under certain conditions: - /// - /// The specified path does not exist or is a file: - /// - public Result DeleteDirectoryRecursively(U8Span path) + /// : The operation was successful.
+ /// : The specified path does not exist or is a file.
+ public Result DeleteDirectoryRecursively(in Path path) { - if (path.IsNull()) - return ResultFs.NullptrArgument.Log(); - - return DoDeleteDirectoryRecursively(path); + return DoDeleteDirectoryRecursively(in path); } /// /// Deletes any subdirectories and files in the specified directory. /// /// The full path of the directory to clean. - /// The of the requested operation. - /// - /// The following codes may be returned under certain conditions: - /// - /// The specified path does not exist or is a file: - /// - public Result CleanDirectoryRecursively(U8Span path) + /// : The operation was successful.
+ /// : The specified path does not exist or is a file.
+ public Result CleanDirectoryRecursively(in Path path) { - if (path.IsNull()) - return ResultFs.NullptrArgument.Log(); - - return DoCleanDirectoryRecursively(path); + return DoCleanDirectoryRecursively(in path); } /// /// Renames or moves a file to a new location. /// - /// The full path of the file to rename. + /// The current full path of the file to rename. /// The new full path of the file. - /// The of the requested operation. + /// : The operation was successful.
+ /// : does not exist or is a directory.
+ /// : 's parent directory does not exist.
+ /// : already exists as either a file or directory.
/// /// If and are the same, this function does nothing and returns successfully. - /// The following codes may be returned under certain conditions: - /// - /// does not exist or is a directory: - /// 's parent directory does not exist: - /// already exists as either a file or directory: /// - public Result RenameFile(U8Span currentPath, U8Span newPath) + public Result RenameFile(in Path currentPath, in Path newPath) { - if (currentPath.IsNull()) - return ResultFs.NullptrArgument.Log(); - - if (newPath.IsNull()) - return ResultFs.NullptrArgument.Log(); - - return DoRenameFile(currentPath, newPath); + return DoRenameFile(in currentPath, in newPath); } /// @@ -184,33 +124,38 @@ namespace LibHac.Fs.Fsa /// /// The full path of the directory to rename. /// The new full path of the directory. - /// The of the requested operation. + /// : The operation was successful.
+ /// : does not exist or is a file.
+ /// : 's parent directory does not exist.
+ /// : already exists as either a file or directory.
+ /// : Either or is a subpath of the other.
/// /// If and are the same, this function does nothing and returns . - /// The following codes may be returned under certain conditions: - /// - /// does not exist or is a file: - /// 's parent directory does not exist: - /// already exists as either a file or directory: - /// Either or is a subpath of the other: /// - public Result RenameDirectory(U8Span currentPath, U8Span newPath) + public Result RenameDirectory(in Path currentPath, in Path newPath) { - if (currentPath.IsNull()) - return ResultFs.NullptrArgument.Log(); - - if (newPath.IsNull()) - return ResultFs.NullptrArgument.Log(); - - return DoRenameDirectory(currentPath, newPath); + return DoRenameDirectory(in currentPath, in newPath); } /// /// Determines whether the specified path is a file or directory, or does not exist. /// - /// If the operation returns successfully, the of the file. + /// If the operation returns successfully, contains the of the file. /// The full path to check. - /// The of the requested operation. + /// : The operation was successful.
+ /// : The specified path does not exist.
+ public Result GetEntryType(out DirectoryEntryType entryType, in Path path) + { + return DoGetEntryType(out entryType, in path); + } + + /// + /// Determines whether the specified path is a file or directory, or does not exist. + /// + /// If the operation returns successfully, contains the of the file. + /// The full path to check. + /// : The operation was successful.
+ /// : The specified path does not exist.
public Result GetEntryType(out DirectoryEntryType entryType, U8Span path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -218,7 +163,11 @@ namespace LibHac.Fs.Fsa if (path.IsNull()) return ResultFs.NullptrArgument.Log(); - return DoGetEntryType(out entryType, path); + var pathNormalized = new Path(); + Result rs = pathNormalized.InitializeWithNormalization(path); + if (rs.IsFailure()) return rs; + + return DoGetEntryType(out entryType, in pathNormalized); } /// @@ -227,14 +176,9 @@ namespace LibHac.Fs.Fsa /// If the operation returns successfully, the amount of free space available on the drive, in bytes. /// The path of the drive to query. Unused in almost all cases. /// The of the requested operation. - public Result GetFreeSpaceSize(out long freeSpace, U8Span path) + public Result GetFreeSpaceSize(out long freeSpace, in Path path) { - UnsafeHelpers.SkipParamInit(out freeSpace); - - if (path.IsNull()) - return ResultFs.NullptrArgument.Log(); - - return DoGetFreeSpaceSize(out freeSpace, path); + return DoGetFreeSpaceSize(out freeSpace, in path); } /// @@ -243,14 +187,9 @@ namespace LibHac.Fs.Fsa /// If the operation returns successfully, the total size of the drive, in bytes. /// The path of the drive to query. Unused in almost all cases. /// The of the requested operation. - public Result GetTotalSpaceSize(out long totalSpace, U8Span path) + public Result GetTotalSpaceSize(out long totalSpace, in Path path) { - UnsafeHelpers.SkipParamInit(out totalSpace); - - if (path.IsNull()) - return ResultFs.NullptrArgument.Log(); - - return DoGetTotalSpaceSize(out totalSpace, path); + return DoGetTotalSpaceSize(out totalSpace, in path); } /// @@ -260,33 +199,44 @@ namespace LibHac.Fs.Fsa /// An instance for the specified path. /// The full path of the file to open. /// Specifies the access permissions of the created . - /// The of the requested operation. - /// - /// The following codes may be returned under certain conditions: - /// - /// The specified path does not exist or is a directory: - /// + /// : The operation was successful.
+ /// : The specified path does not exist or is a directory.
+ /// : When opening as , + /// the file is already opened as .
public Result OpenFile(out IFile file, U8Span path, OpenMode mode) { + UnsafeHelpers.SkipParamInit(out file); + if (path.IsNull()) - { - UnsafeHelpers.SkipParamInit(out file); return ResultFs.NullptrArgument.Log(); - } - if ((mode & OpenMode.ReadWrite) == 0) + var pathNormalized = new Path(); + Result rs = pathNormalized.InitializeWithNormalization(path); + if (rs.IsFailure()) return rs; + + return DoOpenFile(out file, in pathNormalized, mode); + } + + /// + /// Opens an instance for the specified path. + /// + /// If the operation returns successfully, + /// An instance for the specified path. + /// The full path of the file to open. + /// Specifies the access permissions of the created . + /// : The operation was successful.
+ /// : The specified path does not exist or is a directory.
+ /// : When opening as , + /// the file is already opened as .
+ public Result OpenFile(out IFile file, in Path path, OpenMode mode) + { + if ((mode & OpenMode.ReadWrite) == 0 || (mode & ~OpenMode.All) != 0) { UnsafeHelpers.SkipParamInit(out file); return ResultFs.InvalidOpenMode.Log(); } - if ((mode & ~OpenMode.All) != 0) - { - UnsafeHelpers.SkipParamInit(out file); - return ResultFs.InvalidOpenMode.Log(); - } - - return DoOpenFile(out file, path, mode); + return DoOpenFile(out file, in path, mode); } /// @@ -296,33 +246,18 @@ namespace LibHac.Fs.Fsa /// An instance for the specified directory. /// The directory's full path. /// Specifies which sub-entries should be enumerated. - /// The of the requested operation. - /// - /// The following codes may be returned under certain conditions: - /// - /// The specified path does not exist or is a file: - /// - public Result OpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + /// : The operation was successful.
+ /// : The specified path does not exist or is a file.
+ public Result OpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { - if (path.IsNull()) - { - UnsafeHelpers.SkipParamInit(out directory); - return ResultFs.NullptrArgument.Log(); - } - - if ((mode & OpenDirectoryMode.All) == 0) + if ((mode & OpenDirectoryMode.All) == 0 || + (mode & ~(OpenDirectoryMode.All | OpenDirectoryMode.NoFileSize)) != 0) { UnsafeHelpers.SkipParamInit(out directory); return ResultFs.InvalidOpenMode.Log(); } - if ((mode & ~(OpenDirectoryMode.All | OpenDirectoryMode.NoFileSize)) != 0) - { - UnsafeHelpers.SkipParamInit(out directory); - return ResultFs.InvalidOpenMode.Log(); - } - - return DoOpenDirectory(out directory, path, mode); + return DoOpenDirectory(out directory, in path, mode); } /// @@ -344,21 +279,11 @@ namespace LibHac.Fs.Fsa /// If the operation returns successfully, the timestamps for the specified file or directory. /// These value are expressed as Unix timestamps. /// The path of the file or directory. - /// The of the requested operation. - /// - /// The following codes may be returned under certain conditions: - /// - /// The specified path does not exist: - /// - public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) + /// : The operation was successful.
+ /// : The specified path does not exist.
+ public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) { - if (path.IsNull()) - { - UnsafeHelpers.SkipParamInit(out timeStamp); - return ResultFs.NullptrArgument.Log(); - } - - return DoGetFileTimeStampRaw(out timeStamp, path); + return DoGetFileTimeStampRaw(out timeStamp, in path); } /// @@ -373,60 +298,51 @@ namespace LibHac.Fs.Fsa /// The type of query to perform. /// The full path of the file to query. /// The of the requested operation. - public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, U8Span path) + public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, in Path path) { - if (path.IsNull()) - return ResultFs.NullptrArgument.Log(); - return DoQueryEntry(outBuffer, inBuffer, queryId, path); } - protected abstract Result DoCreateFile(U8Span path, long size, CreateFileOptions option); - protected abstract Result DoDeleteFile(U8Span path); - protected abstract Result DoCreateDirectory(U8Span path); - protected abstract Result DoDeleteDirectory(U8Span path); - protected abstract Result DoDeleteDirectoryRecursively(U8Span path); - protected abstract Result DoCleanDirectoryRecursively(U8Span path); - protected abstract Result DoRenameFile(U8Span currentPath, U8Span newPath); - protected abstract Result DoRenameDirectory(U8Span currentPath, U8Span newPath); - protected abstract Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path); + protected abstract Result DoCreateFile(in Path path, long size, CreateFileOptions option); + protected abstract Result DoDeleteFile(in Path path); + protected abstract Result DoCreateDirectory(in Path path); + protected abstract Result DoDeleteDirectory(in Path path); + protected abstract Result DoDeleteDirectoryRecursively(in Path path); + protected abstract Result DoCleanDirectoryRecursively(in Path path); + protected abstract Result DoRenameFile(in Path currentPath, in Path newPath); + protected abstract Result DoRenameDirectory(in Path currentPath, in Path newPath); + protected abstract Result DoGetEntryType(out DirectoryEntryType entryType, in Path path); - protected virtual Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected virtual Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { UnsafeHelpers.SkipParamInit(out freeSpace); return ResultFs.NotImplemented.Log(); } - protected virtual Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected virtual Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { UnsafeHelpers.SkipParamInit(out totalSpace); return ResultFs.NotImplemented.Log(); } - protected abstract Result DoOpenFile(out IFile file, U8Span path, OpenMode mode); - protected abstract Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode); + protected abstract Result DoOpenFile(out IFile file, in Path path, OpenMode mode); + protected abstract Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode); protected abstract Result DoCommit(); protected virtual Result DoCommitProvisionally(long counter) => ResultFs.NotImplemented.Log(); protected virtual Result DoRollback() => ResultFs.NotImplemented.Log(); protected virtual Result DoFlush() => ResultFs.NotImplemented.Log(); - protected virtual Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) + protected virtual Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) { UnsafeHelpers.SkipParamInit(out timeStamp); return ResultFs.NotImplemented.Log(); } protected virtual Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - U8Span path) => ResultFs.NotImplemented.Log(); + in Path path) => ResultFs.NotImplemented.Log(); - protected virtual void Dispose(bool disposing) { } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } + public virtual void Dispose() { } } /// @@ -460,6 +376,9 @@ namespace LibHac.Fs.Fsa /// Turns a folder in a into a concatenation file by /// setting the directory's archive flag. /// - MakeConcatFile = 0 + SetConcatenationFileAttribute = 0, + UpdateMac = 1, + IsSignedSystemPartitionOnSdCardValid = 2, + QueryUnpreparedFileInformation = 3 } } diff --git a/src/LibHac/Fs/Fsa/UserFileSystemPrivate.cs b/src/LibHac/Fs/Fsa/UserFileSystemPrivate.cs index f32afd5a..af078567 100644 --- a/src/LibHac/Fs/Fsa/UserFileSystemPrivate.cs +++ b/src/LibHac/Fs/Fsa/UserFileSystemPrivate.cs @@ -73,7 +73,7 @@ namespace LibHac.Fs.Fsa fs.Impl.AbortIfNeeded(rc); if (rc.IsFailure()) return rc; - rc = fileSystem.QueryEntry(Span.Empty, ReadOnlySpan.Empty, QueryId.MakeConcatFile, subPath); + rc = fileSystem.QueryEntry(Span.Empty, ReadOnlySpan.Empty, QueryId.SetConcatenationFileAttribute, subPath); fs.Impl.AbortIfNeeded(rc); return rc; } diff --git a/src/LibHac/Fs/Impl/FileSystemServiceObjectAdapter.cs b/src/LibHac/Fs/Impl/FileSystemServiceObjectAdapter.cs index f41819b5..aeac867f 100644 --- a/src/LibHac/Fs/Impl/FileSystemServiceObjectAdapter.cs +++ b/src/LibHac/Fs/Impl/FileSystemServiceObjectAdapter.cs @@ -23,7 +23,7 @@ namespace LibHac.Fs.Impl BaseFs = baseFileSystem.AddReference(); } - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { Result rc = GetPathForServiceObject(out PathSf sfPath, path); if (rc.IsFailure()) return rc; @@ -31,7 +31,7 @@ namespace LibHac.Fs.Impl return BaseFs.Target.CreateFile(in sfPath, size, (int)option); } - protected override Result DoDeleteFile(U8Span path) + protected override Result DoDeleteFile(in Path path) { Result rc = GetPathForServiceObject(out PathSf sfPath, path); if (rc.IsFailure()) return rc; @@ -39,7 +39,7 @@ namespace LibHac.Fs.Impl return BaseFs.Target.DeleteFile(in sfPath); } - protected override Result DoCreateDirectory(U8Span path) + protected override Result DoCreateDirectory(in Path path) { Result rc = GetPathForServiceObject(out PathSf sfPath, path); if (rc.IsFailure()) return rc; @@ -47,7 +47,7 @@ namespace LibHac.Fs.Impl return BaseFs.Target.DeleteFile(in sfPath); } - protected override Result DoDeleteDirectory(U8Span path) + protected override Result DoDeleteDirectory(in Path path) { Result rc = GetPathForServiceObject(out PathSf sfPath, path); if (rc.IsFailure()) return rc; @@ -55,7 +55,7 @@ namespace LibHac.Fs.Impl return BaseFs.Target.DeleteDirectory(in sfPath); } - protected override Result DoDeleteDirectoryRecursively(U8Span path) + protected override Result DoDeleteDirectoryRecursively(in Path path) { Result rc = GetPathForServiceObject(out PathSf sfPath, path); if (rc.IsFailure()) return rc; @@ -63,7 +63,7 @@ namespace LibHac.Fs.Impl return BaseFs.Target.DeleteDirectoryRecursively(in sfPath); } - protected override Result DoCleanDirectoryRecursively(U8Span path) + protected override Result DoCleanDirectoryRecursively(in Path path) { Result rc = GetPathForServiceObject(out PathSf sfPath, path); if (rc.IsFailure()) return rc; @@ -71,7 +71,7 @@ namespace LibHac.Fs.Impl return BaseFs.Target.CleanDirectoryRecursively(in sfPath); } - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) + protected override Result DoRenameFile(in Path currentPath, in Path newPath) { Result rc = GetPathForServiceObject(out PathSf oldSfPath, currentPath); if (rc.IsFailure()) return rc; @@ -82,7 +82,7 @@ namespace LibHac.Fs.Impl return BaseFs.Target.RenameFile(in oldSfPath, in newSfPath); } - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { Result rc = GetPathForServiceObject(out PathSf oldSfPath, currentPath); if (rc.IsFailure()) return rc; @@ -93,7 +93,7 @@ namespace LibHac.Fs.Impl return BaseFs.Target.RenameDirectory(in oldSfPath, in newSfPath); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -105,7 +105,7 @@ namespace LibHac.Fs.Impl return BaseFs.Target.GetEntryType(out sfEntryType, in sfPath); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { UnsafeHelpers.SkipParamInit(out freeSpace); @@ -115,7 +115,7 @@ namespace LibHac.Fs.Impl return BaseFs.Target.GetFreeSpaceSize(out freeSpace, in sfPath); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { UnsafeHelpers.SkipParamInit(out totalSpace); @@ -125,7 +125,7 @@ namespace LibHac.Fs.Impl return BaseFs.Target.GetTotalSpaceSize(out totalSpace, in sfPath); } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out file); @@ -147,7 +147,7 @@ namespace LibHac.Fs.Impl } } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { UnsafeHelpers.SkipParamInit(out directory); @@ -174,7 +174,7 @@ namespace LibHac.Fs.Impl return BaseFs.Target.Commit(); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) { UnsafeHelpers.SkipParamInit(out timeStamp); @@ -185,7 +185,7 @@ namespace LibHac.Fs.Impl } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - U8Span path) + in Path path) { Result rc = GetPathForServiceObject(out PathSf sfPath, path); if (rc.IsFailure()) return rc; @@ -198,14 +198,10 @@ namespace LibHac.Fs.Impl return BaseFs.AddReference(); } - protected override void Dispose(bool disposing) + public override void Dispose() { - if (disposing) - { - BaseFs?.Dispose(); - } - - base.Dispose(disposing); + BaseFs?.Dispose(); + base.Dispose(); } private Result GetPathForServiceObject(out PathSf sfPath, U8Span path) diff --git a/src/LibHac/Fs/InMemoryFileSystem.cs b/src/LibHac/Fs/InMemoryFileSystem.cs index fa128148..7b7ae3e0 100644 --- a/src/LibHac/Fs/InMemoryFileSystem.cs +++ b/src/LibHac/Fs/InMemoryFileSystem.cs @@ -21,7 +21,7 @@ namespace LibHac.Fs FsTable = new FileTable(); } - protected override Result DoCreateDirectory(U8Span path) + protected override Result DoCreateDirectory(in Path path) { Unsafe.SkipInit(out FsPath normalizedPath); Result rc = PathNormalizer.Normalize(normalizedPath.Str, out _, path, false, false); @@ -46,7 +46,7 @@ namespace LibHac.Fs return Result.Success; } - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { Unsafe.SkipInit(out FsPath normalizedPath); Result rc = PathNormalizer.Normalize(normalizedPath.Str, out _, path, false, false); @@ -61,7 +61,7 @@ namespace LibHac.Fs return file.File.SetSize(size); } - protected override Result DoDeleteDirectory(U8Span path) + protected override Result DoDeleteDirectory(in Path path) { Unsafe.SkipInit(out FsPath normalizedPath); Result rc = PathNormalizer.Normalize(normalizedPath.Str, out _, path, false, false); @@ -70,7 +70,7 @@ namespace LibHac.Fs return FsTable.DeleteDirectory(normalizedPath, false); } - protected override Result DoDeleteDirectoryRecursively(U8Span path) + protected override Result DoDeleteDirectoryRecursively(in Path path) { Unsafe.SkipInit(out FsPath normalizedPath); Result rc = PathNormalizer.Normalize(normalizedPath.Str, out _, path, false, false); @@ -79,7 +79,7 @@ namespace LibHac.Fs return FsTable.DeleteDirectory(normalizedPath, true); } - protected override Result DoCleanDirectoryRecursively(U8Span path) + protected override Result DoCleanDirectoryRecursively(in Path path) { Unsafe.SkipInit(out FsPath normalizedPath); Result rc = PathNormalizer.Normalize(normalizedPath.Str, out _, path, false, false); @@ -88,7 +88,7 @@ namespace LibHac.Fs return FsTable.CleanDirectory(normalizedPath); } - protected override Result DoDeleteFile(U8Span path) + protected override Result DoDeleteFile(in Path path) { Unsafe.SkipInit(out FsPath normalizedPath); Result rc = PathNormalizer.Normalize(normalizedPath.Str, out _, path, false, false); @@ -97,7 +97,7 @@ namespace LibHac.Fs return FsTable.DeleteFile(normalizedPath); } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { UnsafeHelpers.SkipParamInit(out directory); @@ -112,7 +112,7 @@ namespace LibHac.Fs return Result.Success; } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out file); @@ -128,7 +128,7 @@ namespace LibHac.Fs return Result.Success; } - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { Unsafe.SkipInit(out FsPath normalizedCurrentPath); Unsafe.SkipInit(out FsPath normalizedNewPath); @@ -142,7 +142,7 @@ namespace LibHac.Fs return FsTable.RenameDirectory(normalizedCurrentPath, normalizedNewPath); } - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) + protected override Result DoRenameFile(in Path currentPath, in Path newPath) { Unsafe.SkipInit(out FsPath normalizedCurrentPath); Unsafe.SkipInit(out FsPath normalizedNewPath); @@ -156,7 +156,7 @@ namespace LibHac.Fs return FsTable.RenameFile(normalizedCurrentPath, normalizedNewPath); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { UnsafeHelpers.SkipParamInit(out entryType); diff --git a/src/LibHac/FsSrv/Impl/AsynchronousAccessFileSystem.cs b/src/LibHac/FsSrv/Impl/AsynchronousAccessFileSystem.cs index 98283ad9..4ce75b8e 100644 --- a/src/LibHac/FsSrv/Impl/AsynchronousAccessFileSystem.cs +++ b/src/LibHac/FsSrv/Impl/AsynchronousAccessFileSystem.cs @@ -1,5 +1,4 @@ -using LibHac.Common; -using LibHac.Fs; +using LibHac.Fs; using LibHac.Fs.Fsa; using LibHac.FsSystem; @@ -18,7 +17,7 @@ namespace LibHac.FsSrv.Impl } // ReSharper disable once RedundantOverriddenMember - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { // Todo: Implement return base.DoOpenFile(out file, path, mode); diff --git a/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs b/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs index 68cbefc6..bfcee098 100644 --- a/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs +++ b/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs @@ -39,18 +39,14 @@ namespace LibHac.FsSrv.Impl } } - protected override void Dispose(bool disposing) + public override void Dispose() { - if (disposing) - { - AccessFailureManager?.Dispose(); - } - - base.Dispose(disposing); + AccessFailureManager?.Dispose(); + base.Dispose(); } // ReSharper disable once RedundantOverriddenMember - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { // Todo: Implement return base.DoOpenFile(out file, path, mode); diff --git a/src/LibHac/FsSrv/Impl/IResultConvertFileSystem.cs b/src/LibHac/FsSrv/Impl/IResultConvertFileSystem.cs index 3baf69fa..93b44a44 100644 --- a/src/LibHac/FsSrv/Impl/IResultConvertFileSystem.cs +++ b/src/LibHac/FsSrv/Impl/IResultConvertFileSystem.cs @@ -104,65 +104,61 @@ namespace LibHac.FsSrv.Impl BaseFileSystem = Shared.Move(ref baseFileSystem); } - protected override void Dispose(bool disposing) + public override void Dispose() { - if (disposing) - { - BaseFileSystem?.Dispose(); - BaseFileSystem = null; - } - - base.Dispose(disposing); + BaseFileSystem?.Dispose(); + BaseFileSystem = null; + base.Dispose(); } - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { return ConvertResult(BaseFileSystem.Target.CreateFile(path, size, option)); } - protected override Result DoDeleteFile(U8Span path) + protected override Result DoDeleteFile(in Path path) { return ConvertResult(BaseFileSystem.Target.DeleteFile(path)); } - protected override Result DoCreateDirectory(U8Span path) + protected override Result DoCreateDirectory(in Path path) { return ConvertResult(BaseFileSystem.Target.CreateDirectory(path)); } - protected override Result DoDeleteDirectory(U8Span path) + protected override Result DoDeleteDirectory(in Path path) { return ConvertResult(BaseFileSystem.Target.DeleteDirectory(path)); } - protected override Result DoDeleteDirectoryRecursively(U8Span path) + protected override Result DoDeleteDirectoryRecursively(in Path path) { return ConvertResult(BaseFileSystem.Target.DeleteDirectoryRecursively(path)); } - protected override Result DoCleanDirectoryRecursively(U8Span path) + protected override Result DoCleanDirectoryRecursively(in Path path) { return ConvertResult(BaseFileSystem.Target.CleanDirectoryRecursively(path)); } - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) + protected override Result DoRenameFile(in Path currentPath, in Path newPath) { return ConvertResult(BaseFileSystem.Target.RenameFile(currentPath, newPath)); } - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { return ConvertResult(BaseFileSystem.Target.RenameDirectory(currentPath, newPath)); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { return ConvertResult(BaseFileSystem.Target.GetEntryType(out entryType, path)); } - protected abstract override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode); + protected abstract override Result DoOpenFile(out IFile file, in Path path, OpenMode mode); - protected abstract override Result DoOpenDirectory(out IDirectory directory, U8Span path, + protected abstract override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode); protected override Result DoCommit() @@ -185,23 +181,23 @@ namespace LibHac.FsSrv.Impl return ConvertResult(BaseFileSystem.Target.Flush()); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) { return ConvertResult(BaseFileSystem.Target.GetFileTimeStampRaw(out timeStamp, path)); } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - U8Span path) + in Path path) { return ConvertResult(BaseFileSystem.Target.QueryEntry(outBuffer, inBuffer, queryId, path)); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { return ConvertResult(BaseFileSystem.Target.GetFreeSpaceSize(out freeSpace, path)); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { return ConvertResult(BaseFileSystem.Target.GetTotalSpaceSize(out totalSpace, path)); } diff --git a/src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs b/src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs index 080c84b9..bfd4c76a 100644 --- a/src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs +++ b/src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs @@ -47,28 +47,24 @@ namespace LibHac.FsSrv.Impl } // ReSharper disable once RedundantOverriddenMember - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { // Todo: Implement return base.DoOpenFile(out file, path, mode); } // ReSharper disable once RedundantOverriddenMember - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { // Todo: Implement return base.DoOpenDirectory(out directory, path, mode); } - protected override void Dispose(bool disposing) + public override void Dispose() { - if (disposing) - { - _entryCountSemaphore?.Dispose(); - _mountCountSemaphore?.Dispose(); - } - - base.Dispose(disposing); + _entryCountSemaphore?.Dispose(); + _mountCountSemaphore?.Dispose(); + base.Dispose(); } } } diff --git a/src/LibHac/FsSrv/Impl/SaveDataResultConvertFileSystem.cs b/src/LibHac/FsSrv/Impl/SaveDataResultConvertFileSystem.cs index 0b2741f9..6ff3f2ca 100644 --- a/src/LibHac/FsSrv/Impl/SaveDataResultConvertFileSystem.cs +++ b/src/LibHac/FsSrv/Impl/SaveDataResultConvertFileSystem.cs @@ -176,7 +176,7 @@ namespace LibHac.FsSrv.Impl return new ReferenceCountedDisposable(resultConvertFileSystem); } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out file); @@ -187,7 +187,7 @@ namespace LibHac.FsSrv.Impl return Result.Success; } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { UnsafeHelpers.SkipParamInit(out directory); diff --git a/src/LibHac/FsSystem/AesXtsFileSystem.cs b/src/LibHac/FsSystem/AesXtsFileSystem.cs index 3344fa87..513a9c67 100644 --- a/src/LibHac/FsSystem/AesXtsFileSystem.cs +++ b/src/LibHac/FsSystem/AesXtsFileSystem.cs @@ -33,22 +33,18 @@ namespace LibHac.FsSystem BlockSize = blockSize; } - protected override void Dispose(bool disposing) + public override void Dispose() { - if (disposing) - { - SharedBaseFileSystem?.Dispose(); - } - - base.Dispose(disposing); + SharedBaseFileSystem?.Dispose(); + base.Dispose(); } - protected override Result DoCreateDirectory(U8Span path) + protected override Result DoCreateDirectory(in Path path) { return BaseFileSystem.CreateDirectory(path); } - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { return CreateFile(path, size, option, new byte[0x20]); } @@ -82,27 +78,27 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoDeleteDirectory(U8Span path) + protected override Result DoDeleteDirectory(in Path path) { return BaseFileSystem.DeleteDirectory(path); } - protected override Result DoDeleteDirectoryRecursively(U8Span path) + protected override Result DoDeleteDirectoryRecursively(in Path path) { return BaseFileSystem.DeleteDirectoryRecursively(path); } - protected override Result DoCleanDirectoryRecursively(U8Span path) + protected override Result DoCleanDirectoryRecursively(in Path path) { return BaseFileSystem.CleanDirectoryRecursively(path); } - protected override Result DoDeleteFile(U8Span path) + protected override Result DoDeleteFile(in Path path) { return BaseFileSystem.DeleteFile(path); } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { UnsafeHelpers.SkipParamInit(out directory); @@ -113,7 +109,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out file); @@ -126,7 +122,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { // todo: Return proper result codes @@ -186,7 +182,7 @@ namespace LibHac.FsSystem } } - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) + protected override Result DoRenameFile(in Path currentPath, in Path newPath) { // todo: Return proper result codes @@ -210,22 +206,22 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { return BaseFileSystem.GetEntryType(out entryType, path); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) { return BaseFileSystem.GetFileTimeStampRaw(out timeStamp, path); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { return BaseFileSystem.GetFreeSpaceSize(out freeSpace, path); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { return BaseFileSystem.GetTotalSpaceSize(out totalSpace, path); } @@ -246,7 +242,7 @@ namespace LibHac.FsSystem } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - U8Span path) + in Path path) { return BaseFileSystem.QueryEntry(outBuffer, inBuffer, queryId, path); } diff --git a/src/LibHac/FsSystem/ApplicationTemporaryFileSystem.cs b/src/LibHac/FsSystem/ApplicationTemporaryFileSystem.cs index 0412b9be..bd489b2c 100644 --- a/src/LibHac/FsSystem/ApplicationTemporaryFileSystem.cs +++ b/src/LibHac/FsSystem/ApplicationTemporaryFileSystem.cs @@ -1,5 +1,4 @@ using System; -using LibHac.Common; using LibHac.Fs; using LibHac.Fs.Fsa; @@ -7,57 +6,57 @@ namespace LibHac.FsSystem { public class ApplicationTemporaryFileSystem : IFileSystem, ISaveDataExtraDataAccessor { - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { throw new NotImplementedException(); } - protected override Result DoDeleteFile(U8Span path) + protected override Result DoDeleteFile(in Path path) { throw new NotImplementedException(); } - protected override Result DoCreateDirectory(U8Span path) + protected override Result DoCreateDirectory(in Path path) { throw new NotImplementedException(); } - protected override Result DoDeleteDirectory(U8Span path) + protected override Result DoDeleteDirectory(in Path path) { throw new NotImplementedException(); } - protected override Result DoDeleteDirectoryRecursively(U8Span path) + protected override Result DoDeleteDirectoryRecursively(in Path path) { throw new NotImplementedException(); } - protected override Result DoCleanDirectoryRecursively(U8Span path) + protected override Result DoCleanDirectoryRecursively(in Path path) { throw new NotImplementedException(); } - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) + protected override Result DoRenameFile(in Path currentPath, in Path newPath) { throw new NotImplementedException(); } - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { throw new NotImplementedException(); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { throw new NotImplementedException(); } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { throw new NotImplementedException(); } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { throw new NotImplementedException(); } diff --git a/src/LibHac/FsSystem/ConcatenationFileSystem.cs b/src/LibHac/FsSystem/ConcatenationFileSystem.cs index ccb8ea6f..5c5ddc34 100644 --- a/src/LibHac/FsSystem/ConcatenationFileSystem.cs +++ b/src/LibHac/FsSystem/ConcatenationFileSystem.cs @@ -99,7 +99,7 @@ namespace LibHac.FsSystem return BaseFileSystem.SetFileAttributes(path, NxFileAttributes.Archive); } - protected override Result DoCreateDirectory(U8Span path) + protected override Result DoCreateDirectory(in Path path) { var parent = new U8Span(PathTools.GetParentDirectory(path)); @@ -112,7 +112,7 @@ namespace LibHac.FsSystem return BaseFileSystem.CreateDirectory(path); } - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { CreateFileOptions newOptions = option & ~CreateFileOptions.CreateConcatenationFile; @@ -158,7 +158,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoDeleteDirectory(U8Span path) + protected override Result DoDeleteDirectory(in Path path) { if (IsConcatenationFile(path)) { @@ -168,21 +168,21 @@ namespace LibHac.FsSystem return BaseFileSystem.DeleteDirectory(path); } - protected override Result DoDeleteDirectoryRecursively(U8Span path) + protected override Result DoDeleteDirectoryRecursively(in Path path) { if (IsConcatenationFile(path)) return ResultFs.PathNotFound.Log(); return BaseFileSystem.DeleteDirectoryRecursively(path); } - protected override Result DoCleanDirectoryRecursively(U8Span path) + protected override Result DoCleanDirectoryRecursively(in Path path) { if (IsConcatenationFile(path)) return ResultFs.PathNotFound.Log(); return BaseFileSystem.CleanDirectoryRecursively(path); } - protected override Result DoDeleteFile(U8Span path) + protected override Result DoDeleteFile(in Path path) { if (!IsConcatenationFile(path)) { @@ -206,7 +206,7 @@ namespace LibHac.FsSystem return BaseFileSystem.DeleteDirectory(path); } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { UnsafeHelpers.SkipParamInit(out directory); @@ -222,7 +222,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out file); @@ -253,7 +253,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { if (IsConcatenationFile(currentPath)) { @@ -263,7 +263,7 @@ namespace LibHac.FsSystem return BaseFileSystem.RenameDirectory(currentPath, newPath); } - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) + protected override Result DoRenameFile(in Path currentPath, in Path newPath) { if (IsConcatenationFile(currentPath)) { @@ -275,7 +275,7 @@ namespace LibHac.FsSystem } } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { if (IsConcatenationFile(path)) { @@ -286,17 +286,17 @@ namespace LibHac.FsSystem return BaseFileSystem.GetEntryType(out entryType, path); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { return BaseFileSystem.GetFreeSpaceSize(out freeSpace, path); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { return BaseFileSystem.GetTotalSpaceSize(out totalSpace, path); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) { return BaseFileSystem.GetFileTimeStampRaw(out timeStamp, path); } @@ -317,9 +317,9 @@ namespace LibHac.FsSystem } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - U8Span path) + in Path path) { - if (queryId != QueryId.MakeConcatFile) return ResultFs.UnsupportedQueryEntryForConcatenationFileSystem.Log(); + if (queryId != QueryId.SetConcatenationFileAttribute) return ResultFs.UnsupportedQueryEntryForConcatenationFileSystem.Log(); return SetConcatenationFileAttribute(path); } diff --git a/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs b/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs index 8809c332..708b4a60 100644 --- a/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs +++ b/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs @@ -186,14 +186,14 @@ namespace LibHac.FsSystem _fsClient = fsClient; } - protected override void Dispose(bool disposing) + public override void Dispose() { _lockFile?.Dispose(); _lockFile = null; _cacheObserver?.Unregister(_spaceId, _saveDataId); _baseFs?.Dispose(); - base.Dispose(disposing); + base.Dispose(); } public Result Initialize(bool isJournalingSupported, bool isMultiCommitSupported, bool isJournalingEnabled) @@ -299,7 +299,7 @@ namespace LibHac.FsSystem return PathNormalizer.Normalize(outPath.Slice(2), out _, relativePath, false, false); } - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { Unsafe.SkipInit(out FsPath fullPath); @@ -311,7 +311,7 @@ namespace LibHac.FsSystem return _baseFs.CreateFile(fullPath, size, option); } - protected override Result DoDeleteFile(U8Span path) + protected override Result DoDeleteFile(in Path path) { Unsafe.SkipInit(out FsPath fullPath); @@ -323,7 +323,7 @@ namespace LibHac.FsSystem return _baseFs.DeleteFile(fullPath); } - protected override Result DoCreateDirectory(U8Span path) + protected override Result DoCreateDirectory(in Path path) { Unsafe.SkipInit(out FsPath fullPath); @@ -335,7 +335,7 @@ namespace LibHac.FsSystem return _baseFs.CreateDirectory(fullPath); } - protected override Result DoDeleteDirectory(U8Span path) + protected override Result DoDeleteDirectory(in Path path) { Unsafe.SkipInit(out FsPath fullPath); @@ -347,7 +347,7 @@ namespace LibHac.FsSystem return _baseFs.DeleteDirectory(fullPath); } - protected override Result DoDeleteDirectoryRecursively(U8Span path) + protected override Result DoDeleteDirectoryRecursively(in Path path) { Unsafe.SkipInit(out FsPath fullPath); @@ -359,7 +359,7 @@ namespace LibHac.FsSystem return _baseFs.DeleteDirectoryRecursively(fullPath); } - protected override Result DoCleanDirectoryRecursively(U8Span path) + protected override Result DoCleanDirectoryRecursively(in Path path) { Unsafe.SkipInit(out FsPath fullPath); @@ -371,7 +371,7 @@ namespace LibHac.FsSystem return _baseFs.CleanDirectoryRecursively(fullPath); } - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) + protected override Result DoRenameFile(in Path currentPath, in Path newPath) { Unsafe.SkipInit(out FsPath fullCurrentPath); Unsafe.SkipInit(out FsPath fullNewPath); @@ -387,7 +387,7 @@ namespace LibHac.FsSystem return _baseFs.RenameFile(fullCurrentPath, fullNewPath); } - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { Unsafe.SkipInit(out FsPath fullCurrentPath); Unsafe.SkipInit(out FsPath fullNewPath); @@ -403,7 +403,7 @@ namespace LibHac.FsSystem return _baseFs.RenameDirectory(fullCurrentPath, fullNewPath); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { Unsafe.SkipInit(out FsPath fullPath); @@ -419,7 +419,7 @@ namespace LibHac.FsSystem return _baseFs.GetEntryType(out entryType, fullPath); } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out file); @@ -443,7 +443,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { UnsafeHelpers.SkipParamInit(out directory); @@ -549,7 +549,7 @@ namespace LibHac.FsSystem return Initialize(_isJournalingSupported, _isMultiCommitSupported, _isJournalingEnabled); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { UnsafeHelpers.SkipParamInit(out freeSpace); @@ -563,7 +563,7 @@ namespace LibHac.FsSystem return _baseFs.GetFreeSpaceSize(out freeSpace, fullPath); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { UnsafeHelpers.SkipParamInit(out totalSpace); diff --git a/src/LibHac/FsSystem/FileSystemExtensions.cs b/src/LibHac/FsSystem/FileSystemExtensions.cs index e184af4d..26db95f2 100644 --- a/src/LibHac/FsSystem/FileSystemExtensions.cs +++ b/src/LibHac/FsSystem/FileSystemExtensions.cs @@ -202,7 +202,7 @@ namespace LibHac.FsSystem public static void SetConcatenationFileAttribute(this IFileSystem fs, string path) { - fs.QueryEntry(Span.Empty, Span.Empty, QueryId.MakeConcatFile, path.ToU8Span()); + fs.QueryEntry(Span.Empty, Span.Empty, QueryId.SetConcatenationFileAttribute, path.ToU8Span()); } public static void CleanDirectoryRecursivelyGeneric(IFileSystem fileSystem, string path) diff --git a/src/LibHac/FsSystem/ForwardingFileSystem.cs b/src/LibHac/FsSystem/ForwardingFileSystem.cs index 0bcfbfa8..2857923d 100644 --- a/src/LibHac/FsSystem/ForwardingFileSystem.cs +++ b/src/LibHac/FsSystem/ForwardingFileSystem.cs @@ -19,50 +19,46 @@ namespace LibHac.FsSystem BaseFileSystem = Shared.Move(ref baseFileSystem); } - protected override void Dispose(bool disposing) + public override void Dispose() { - if (disposing) - { - BaseFileSystem?.Dispose(); - } - - base.Dispose(disposing); + BaseFileSystem?.Dispose(); + base.Dispose(); } - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) => + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) => BaseFileSystem.Target.CreateFile(path, size, option); - protected override Result DoDeleteFile(U8Span path) => BaseFileSystem.Target.DeleteFile(path); + protected override Result DoDeleteFile(in Path path) => BaseFileSystem.Target.DeleteFile(path); - protected override Result DoCreateDirectory(U8Span path) => BaseFileSystem.Target.CreateDirectory(path); + protected override Result DoCreateDirectory(in Path path) => BaseFileSystem.Target.CreateDirectory(path); - protected override Result DoDeleteDirectory(U8Span path) => BaseFileSystem.Target.DeleteDirectory(path); + protected override Result DoDeleteDirectory(in Path path) => BaseFileSystem.Target.DeleteDirectory(path); - protected override Result DoDeleteDirectoryRecursively(U8Span path) => + protected override Result DoDeleteDirectoryRecursively(in Path path) => BaseFileSystem.Target.DeleteDirectoryRecursively(path); - protected override Result DoCleanDirectoryRecursively(U8Span path) => + protected override Result DoCleanDirectoryRecursively(in Path path) => BaseFileSystem.Target.CleanDirectoryRecursively(path); - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) => + protected override Result DoRenameFile(in Path currentPath, in Path newPath) => BaseFileSystem.Target.RenameFile(currentPath, newPath); - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) => + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) => BaseFileSystem.Target.RenameDirectory(currentPath, newPath); - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) => + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) => BaseFileSystem.Target.GetEntryType(out entryType, path); - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) => + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) => BaseFileSystem.Target.GetFreeSpaceSize(out freeSpace, path); - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) => + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) => BaseFileSystem.Target.GetTotalSpaceSize(out totalSpace, path); - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) => + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) => BaseFileSystem.Target.OpenFile(out file, path, mode); - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) => + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) => BaseFileSystem.Target.OpenDirectory(out directory, path, mode); protected override Result DoCommit() => BaseFileSystem.Target.Commit(); @@ -74,10 +70,10 @@ namespace LibHac.FsSystem protected override Result DoFlush() => BaseFileSystem.Target.Flush(); - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) => + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) => BaseFileSystem.Target.GetFileTimeStampRaw(out timeStamp, path); protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - U8Span path) => BaseFileSystem.Target.QueryEntry(outBuffer, inBuffer, queryId, path); + in Path path) => BaseFileSystem.Target.QueryEntry(outBuffer, inBuffer, queryId, path); } } diff --git a/src/LibHac/FsSystem/LayeredFileSystem.cs b/src/LibHac/FsSystem/LayeredFileSystem.cs index af5cf0b2..6a24c8b1 100644 --- a/src/LibHac/FsSystem/LayeredFileSystem.cs +++ b/src/LibHac/FsSystem/LayeredFileSystem.cs @@ -37,7 +37,7 @@ namespace LibHac.FsSystem Sources.AddRange(sourceFileSystems); } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { UnsafeHelpers.SkipParamInit(out directory); @@ -108,7 +108,7 @@ namespace LibHac.FsSystem return ResultFs.PathNotFound.Log(); } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out file); @@ -137,7 +137,7 @@ namespace LibHac.FsSystem return ResultFs.PathNotFound.Log(); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -155,7 +155,7 @@ namespace LibHac.FsSystem return ResultFs.PathNotFound.Log(); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) { UnsafeHelpers.SkipParamInit(out timeStamp); @@ -173,7 +173,7 @@ namespace LibHac.FsSystem } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - U8Span path) + in Path path) { foreach (IFileSystem fs in Sources) { @@ -193,14 +193,14 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoCreateDirectory(U8Span path) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoDeleteDirectory(U8Span path) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoDeleteDirectoryRecursively(U8Span path) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoCleanDirectoryRecursively(U8Span path) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoDeleteFile(U8Span path) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoCreateDirectory(in Path path) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoDeleteDirectory(in Path path) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoDeleteDirectoryRecursively(in Path path) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoCleanDirectoryRecursively(in Path path) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoDeleteFile(in Path path) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoRenameFile(in Path currentPath, in Path newPath) => ResultFs.UnsupportedOperation.Log(); private class MergedDirectory : IDirectory { diff --git a/src/LibHac/FsSystem/LocalFileSystem.cs b/src/LibHac/FsSystem/LocalFileSystem.cs index 7593a31f..db98cbcb 100644 --- a/src/LibHac/FsSystem/LocalFileSystem.cs +++ b/src/LibHac/FsSystem/LocalFileSystem.cs @@ -11,6 +11,7 @@ using LibHac.Fs.Fsa; using LibHac.FsSystem.Impl; using LibHac.Util; using static LibHac.Fs.StringTraits; +using Path = LibHac.Fs.Path; namespace LibHac.FsSystem { @@ -226,7 +227,7 @@ namespace LibHac.FsSystem return GetSizeInternal(out fileSize, info); } - protected override Result DoCreateDirectory(U8Span path) + protected override Result DoCreateDirectory(in Path path) { return DoCreateDirectory(path, NxFileAttributes.None); } @@ -252,7 +253,7 @@ namespace LibHac.FsSystem return CreateDirInternal(dir, archiveAttribute); } - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { Result rc = ResolveFullPath(out string fullPath, path, false); if (rc.IsFailure()) return rc; @@ -280,7 +281,7 @@ namespace LibHac.FsSystem } } - protected override Result DoDeleteDirectory(U8Span path) + protected override Result DoDeleteDirectory(in Path path) { Result rc = ResolveFullPath(out string fullPath, path, true); if (rc.IsFailure()) return rc; @@ -292,7 +293,7 @@ namespace LibHac.FsSystem () => DeleteDirectoryInternal(dir, false), _fsClient); } - protected override Result DoDeleteDirectoryRecursively(U8Span path) + protected override Result DoDeleteDirectoryRecursively(in Path path) { Result rc = ResolveFullPath(out string fullPath, path, true); if (rc.IsFailure()) return rc; @@ -304,7 +305,7 @@ namespace LibHac.FsSystem () => DeleteDirectoryInternal(dir, true), _fsClient); } - protected override Result DoCleanDirectoryRecursively(U8Span path) + protected override Result DoCleanDirectoryRecursively(in Path path) { Result rc = ResolveFullPath(out string fullPath, path, true); if (rc.IsFailure()) return rc; @@ -340,7 +341,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoDeleteFile(U8Span path) + protected override Result DoDeleteFile(in Path path) { Result rc = ResolveFullPath(out string fullPath, path, true); if (rc.IsFailure()) return rc; @@ -352,7 +353,7 @@ namespace LibHac.FsSystem () => DeleteFileInternal(file), _fsClient); } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { UnsafeHelpers.SkipParamInit(out directory); Result rc = ResolveFullPath(out string fullPath, path, true); @@ -375,7 +376,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out file); @@ -400,7 +401,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { Result rc = CheckSubPath(currentPath, newPath); if (rc.IsFailure()) return rc; @@ -424,7 +425,7 @@ namespace LibHac.FsSystem () => RenameDirInternal(currentDirInfo, newDirInfo), _fsClient); } - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) + protected override Result DoRenameFile(in Path currentPath, in Path newPath) { Result rc = ResolveFullPath(out string fullCurrentPath, currentPath, true); if (rc.IsFailure()) return rc; @@ -445,7 +446,7 @@ namespace LibHac.FsSystem () => RenameFileInternal(currentFileInfo, newFileInfo), _fsClient); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -473,7 +474,7 @@ namespace LibHac.FsSystem return ResultFs.PathNotFound.Log(); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) { UnsafeHelpers.SkipParamInit(out timeStamp); @@ -503,7 +504,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { UnsafeHelpers.SkipParamInit(out freeSpace); @@ -514,7 +515,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { UnsafeHelpers.SkipParamInit(out totalSpace); @@ -531,7 +532,7 @@ namespace LibHac.FsSystem } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - U8Span path) + in Path path) { return ResultFs.UnsupportedOperation.Log(); } diff --git a/src/LibHac/FsSystem/PartitionFileSystem.cs b/src/LibHac/FsSystem/PartitionFileSystem.cs index 280c8117..1e415999 100644 --- a/src/LibHac/FsSystem/PartitionFileSystem.cs +++ b/src/LibHac/FsSystem/PartitionFileSystem.cs @@ -7,6 +7,7 @@ using LibHac.Common; using LibHac.Crypto; using LibHac.Fs; using LibHac.Fs.Fsa; +using Path = LibHac.Fs.Path; namespace LibHac.FsSystem { @@ -33,13 +34,13 @@ namespace LibHac.FsSystem BaseStorage = storage; } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { directory = new PartitionDirectory(this, path.ToString(), mode); return Result.Success; } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { path = PathTools.Normalize(path.ToString()).TrimStart('/').ToU8Span(); @@ -57,7 +58,7 @@ namespace LibHac.FsSystem return new PartitionFile(BaseStorage, HeaderSize + entry.Offset, entry.Size, mode); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -76,14 +77,14 @@ namespace LibHac.FsSystem return ResultFs.PathNotFound.Log(); } - protected override Result DoCreateDirectory(U8Span path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoDeleteDirectory(U8Span path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoDeleteDirectoryRecursively(U8Span path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoCleanDirectoryRecursively(U8Span path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoDeleteFile(U8Span path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoCreateDirectory(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoDeleteDirectory(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoDeleteDirectoryRecursively(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoCleanDirectoryRecursively(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoDeleteFile(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoRenameFile(in Path currentPath, in Path newPath) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); protected override Result DoCommit() { diff --git a/src/LibHac/FsSystem/PartitionFileSystemCore.cs b/src/LibHac/FsSystem/PartitionFileSystemCore.cs index 0a0f0b9d..51a96205 100644 --- a/src/LibHac/FsSystem/PartitionFileSystemCore.cs +++ b/src/LibHac/FsSystem/PartitionFileSystemCore.cs @@ -43,17 +43,13 @@ namespace LibHac.FsSystem return Result.Success; } - protected override void Dispose(bool disposing) + public override void Dispose() { - if (disposing) - { - BaseStorageShared?.Dispose(); - } - - base.Dispose(disposing); + BaseStorageShared?.Dispose(); + base.Dispose(); } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { UnsafeHelpers.SkipParamInit(out directory); @@ -70,7 +66,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out file); @@ -90,7 +86,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -122,14 +118,14 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoCreateDirectory(U8Span path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoDeleteDirectory(U8Span path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoDeleteDirectoryRecursively(U8Span path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoCleanDirectoryRecursively(U8Span path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoDeleteFile(U8Span path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoCreateDirectory(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoDeleteDirectory(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoDeleteDirectoryRecursively(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoCleanDirectoryRecursively(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoDeleteFile(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoRenameFile(in Path currentPath, in Path newPath) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); protected override Result DoCommitProvisionally(long counter) => ResultFs.UnsupportedCommitProvisionallyForPartitionFileSystem.Log(); private class PartitionFile : IFile diff --git a/src/LibHac/FsSystem/ReadOnlyFileSystem.cs b/src/LibHac/FsSystem/ReadOnlyFileSystem.cs index f2a0936b..475c9152 100644 --- a/src/LibHac/FsSystem/ReadOnlyFileSystem.cs +++ b/src/LibHac/FsSystem/ReadOnlyFileSystem.cs @@ -28,12 +28,12 @@ namespace LibHac.FsSystem return new ReferenceCountedDisposable(fs); } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { return BaseFs.OpenDirectory(out directory, path, mode); } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out file); @@ -44,17 +44,17 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { return BaseFs.GetEntryType(out entryType, path); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { return BaseFs.GetFreeSpaceSize(out freeSpace, path); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { return BaseFs.GetTotalSpaceSize(out totalSpace, path); @@ -62,7 +62,7 @@ namespace LibHac.FsSystem // return ResultFs.UnsupportedOperationReadOnlyFileSystemGetSpace.Log(); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) { return BaseFs.GetFileTimeStampRaw(out timeStamp, path); @@ -75,30 +75,26 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DoCreateDirectory(U8Span path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); + protected override Result DoCreateDirectory(in Path path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoDeleteDirectory(U8Span path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); + protected override Result DoDeleteDirectory(in Path path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoDeleteDirectoryRecursively(U8Span path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); + protected override Result DoDeleteDirectoryRecursively(in Path path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoCleanDirectoryRecursively(U8Span path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); + protected override Result DoCleanDirectoryRecursively(in Path path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoDeleteFile(U8Span path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); + protected override Result DoDeleteFile(in Path path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); + protected override Result DoRenameFile(in Path currentPath, in Path newPath) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override void Dispose(bool disposing) + public override void Dispose() { - if (disposing) - { - BaseFsShared?.Dispose(); - } - - base.Dispose(disposing); + BaseFsShared?.Dispose(); + base.Dispose(); } } } diff --git a/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs b/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs index 03e34d3d..f0f091d2 100644 --- a/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs +++ b/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs @@ -25,7 +25,7 @@ namespace LibHac.FsSystem.RomFs FileTable = new HierarchicalRomFileTable(dirHashTable, dirEntryTable, fileHashTable, fileEntryTable); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -49,7 +49,7 @@ namespace LibHac.FsSystem.RomFs return Result.Success; } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { UnsafeHelpers.SkipParamInit(out directory); @@ -62,7 +62,7 @@ namespace LibHac.FsSystem.RomFs return Result.Success; } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out file); @@ -86,23 +86,23 @@ namespace LibHac.FsSystem.RomFs return BaseStorage; } - protected override Result DoCreateDirectory(U8Span path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoDeleteDirectory(U8Span path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoDeleteDirectoryRecursively(U8Span path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoCleanDirectoryRecursively(U8Span path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoDeleteFile(U8Span path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoCreateDirectory(in Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoDeleteDirectory(in Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoDeleteDirectoryRecursively(in Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoCleanDirectoryRecursively(in Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoDeleteFile(in Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoRenameFile(in Path currentPath, in Path newPath) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); protected override Result DoCommitProvisionally(long counter) => ResultFs.UnsupportedCommitProvisionallyForRomFsFileSystem.Log(); - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { freeSpace = 0; return Result.Success; } - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { UnsafeHelpers.SkipParamInit(out totalSpace); return ResultFs.UnsupportedGetTotalSpaceSizeForRomFsFileSystem.Log(); diff --git a/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs b/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs index c447d4f0..cb5bbe3a 100644 --- a/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs +++ b/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs @@ -1,10 +1,10 @@ using System.Collections.Generic; using System.IO; -using LibHac.Common; using LibHac.Common.Keys; using LibHac.Crypto; using LibHac.Fs; using LibHac.Fs.Fsa; +using Path = LibHac.Fs.Path; namespace LibHac.FsSystem.Save { @@ -146,91 +146,91 @@ namespace LibHac.FsSystem.Save IntegrityStorageType.Save, integrityCheckLevel, LeaveOpen); } - protected override Result DoCreateDirectory(U8Span path) + protected override Result DoCreateDirectory(in Path path) { Result result = SaveDataFileSystemCore.CreateDirectory(path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { Result result = SaveDataFileSystemCore.CreateFile(path, size, option); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoDeleteDirectory(U8Span path) + protected override Result DoDeleteDirectory(in Path path) { Result result = SaveDataFileSystemCore.DeleteDirectory(path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoDeleteDirectoryRecursively(U8Span path) + protected override Result DoDeleteDirectoryRecursively(in Path path) { Result result = SaveDataFileSystemCore.DeleteDirectoryRecursively(path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoCleanDirectoryRecursively(U8Span path) + protected override Result DoCleanDirectoryRecursively(in Path path) { Result result = SaveDataFileSystemCore.CleanDirectoryRecursively(path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoDeleteFile(U8Span path) + protected override Result DoDeleteFile(in Path path) { Result result = SaveDataFileSystemCore.DeleteFile(path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { Result result = SaveDataFileSystemCore.OpenDirectory(out directory, path, mode); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { Result result = SaveDataFileSystemCore.OpenFile(out file, path, mode); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { Result result = SaveDataFileSystemCore.RenameDirectory(currentPath, newPath); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) + protected override Result DoRenameFile(in Path currentPath, in Path newPath) { Result result = SaveDataFileSystemCore.RenameFile(currentPath, newPath); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { Result result = SaveDataFileSystemCore.GetEntryType(out entryType, path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { Result result = SaveDataFileSystemCore.GetFreeSpaceSize(out freeSpace, path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { Result result = SaveDataFileSystemCore.GetTotalSpaceSize(out totalSpace, path); @@ -309,15 +309,14 @@ namespace LibHac.FsSystem.Save return journalValidity; } - protected override void Dispose(bool disposing) + public override void Dispose() { - if (disposing) + if (!LeaveOpen) { - if (!LeaveOpen) - { - BaseStorage?.Dispose(); - } + BaseStorage?.Dispose(); } + + base.Dispose(); } } } diff --git a/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs b/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs index 3060fad7..a20f7b06 100644 --- a/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs +++ b/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs @@ -4,6 +4,7 @@ using LibHac.Common; using LibHac.Fs; using LibHac.Fs.Fsa; using LibHac.Util; +using Path = LibHac.Fs.Path; namespace LibHac.FsSystem.Save { @@ -31,7 +32,7 @@ namespace LibHac.FsSystem.Save FileTable = new HierarchicalSaveFileTable(dirTableStorage, fileTableStorage); } - protected override Result DoCreateDirectory(U8Span path) + protected override Result DoCreateDirectory(in Path path) { Unsafe.SkipInit(out FsPath normalizedPath); @@ -43,7 +44,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { Unsafe.SkipInit(out FsPath normalizedPath); @@ -73,7 +74,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result DoDeleteDirectory(U8Span path) + protected override Result DoDeleteDirectory(in Path path) { Unsafe.SkipInit(out FsPath normalizedPath); @@ -85,7 +86,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result DoDeleteDirectoryRecursively(U8Span path) + protected override Result DoDeleteDirectoryRecursively(in Path path) { Unsafe.SkipInit(out FsPath normalizedPath); @@ -101,7 +102,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result DoCleanDirectoryRecursively(U8Span path) + protected override Result DoCleanDirectoryRecursively(in Path path) { Unsafe.SkipInit(out FsPath normalizedPath); @@ -113,7 +114,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result DoDeleteFile(U8Span path) + protected override Result DoDeleteFile(in Path path) { Unsafe.SkipInit(out FsPath normalizedPath); @@ -135,7 +136,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { UnsafeHelpers.SkipParamInit(out directory); @@ -154,7 +155,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out file); @@ -175,7 +176,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { Unsafe.SkipInit(out FsPath normalizedCurrentPath); Unsafe.SkipInit(out FsPath normalizedNewPath); @@ -189,7 +190,7 @@ namespace LibHac.FsSystem.Save return FileTable.RenameDirectory(normalizedCurrentPath, normalizedNewPath); } - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) + protected override Result DoRenameFile(in Path currentPath, in Path newPath) { Unsafe.SkipInit(out FsPath normalizedCurrentPath); Unsafe.SkipInit(out FsPath normalizedNewPath); @@ -205,7 +206,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -229,7 +230,7 @@ namespace LibHac.FsSystem.Save return ResultFs.PathNotFound.Log(); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { int freeBlockCount = AllocationTable.GetFreeListLength(); freeSpace = Header.BlockSize * freeBlockCount; @@ -237,7 +238,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { totalSpace = Header.BlockSize * Header.BlockCount; diff --git a/src/LibHac/FsSystem/SaveDataFileSystemCacheRegisterBase.cs b/src/LibHac/FsSystem/SaveDataFileSystemCacheRegisterBase.cs index ed34363b..013de88b 100644 --- a/src/LibHac/FsSystem/SaveDataFileSystemCacheRegisterBase.cs +++ b/src/LibHac/FsSystem/SaveDataFileSystemCacheRegisterBase.cs @@ -68,12 +68,9 @@ namespace LibHac.FsSystem } } - protected override void Dispose(bool disposing) + public override void Dispose() { - if (_baseFileSystem is null) - return; - - if (disposing) + if (_baseFileSystem is not null) { if (typeof(T) == typeof(SaveDataFileSystem)) { @@ -95,60 +92,60 @@ namespace LibHac.FsSystem _baseFileSystem = null; } - base.Dispose(disposing); + base.Dispose(); } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { return _baseFileSystem.Target.OpenFile(out file, path, mode); } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { return _baseFileSystem.Target.OpenDirectory(out directory, path, mode); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { return _baseFileSystem.Target.GetEntryType(out entryType, path); } - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { return _baseFileSystem.Target.CreateFile(path, size, option); } - protected override Result DoDeleteFile(U8Span path) + protected override Result DoDeleteFile(in Path path) { return _baseFileSystem.Target.DeleteFile(path); } - protected override Result DoCreateDirectory(U8Span path) + protected override Result DoCreateDirectory(in Path path) { return _baseFileSystem.Target.CreateDirectory(path); } - protected override Result DoDeleteDirectory(U8Span path) + protected override Result DoDeleteDirectory(in Path path) { return _baseFileSystem.Target.DeleteDirectory(path); } - protected override Result DoDeleteDirectoryRecursively(U8Span path) + protected override Result DoDeleteDirectoryRecursively(in Path path) { return _baseFileSystem.Target.DeleteDirectoryRecursively(path); } - protected override Result DoCleanDirectoryRecursively(U8Span path) + protected override Result DoCleanDirectoryRecursively(in Path path) { return _baseFileSystem.Target.CleanDirectoryRecursively(path); } - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) + protected override Result DoRenameFile(in Path currentPath, in Path newPath) { return _baseFileSystem.Target.RenameFile(currentPath, newPath); } - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { return _baseFileSystem.Target.RenameDirectory(currentPath, newPath); } @@ -168,12 +165,12 @@ namespace LibHac.FsSystem return _baseFileSystem.Target.Rollback(); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { return _baseFileSystem.Target.GetFreeSpaceSize(out freeSpace, path); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { return _baseFileSystem.Target.GetTotalSpaceSize(out totalSpace, path); } diff --git a/src/LibHac/FsSystem/StorageLayoutTypeSetFileSystem.cs b/src/LibHac/FsSystem/StorageLayoutTypeSetFileSystem.cs index 3946ef64..28d50bc3 100644 --- a/src/LibHac/FsSystem/StorageLayoutTypeSetFileSystem.cs +++ b/src/LibHac/FsSystem/StorageLayoutTypeSetFileSystem.cs @@ -38,90 +38,86 @@ namespace LibHac.FsSystem new StorageLayoutTypeSetFileSystem(ref baseFileSystem, storageFlag)); } - protected override void Dispose(bool disposing) + public override void Dispose() { - if (disposing) - { - using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); - BaseFileSystem?.Dispose(); - } - - base.Dispose(disposing); + using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); + BaseFileSystem?.Dispose(); + base.Dispose(); } - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.CreateFile(path, size, option); } - protected override Result DoDeleteFile(U8Span path) + protected override Result DoDeleteFile(in Path path) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.DeleteFile(path); } - protected override Result DoCreateDirectory(U8Span path) + protected override Result DoCreateDirectory(in Path path) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.CreateDirectory(path); } - protected override Result DoDeleteDirectory(U8Span path) + protected override Result DoDeleteDirectory(in Path path) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.DeleteDirectory(path); } - protected override Result DoDeleteDirectoryRecursively(U8Span path) + protected override Result DoDeleteDirectoryRecursively(in Path path) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.DeleteDirectoryRecursively(path); } - protected override Result DoCleanDirectoryRecursively(U8Span path) + protected override Result DoCleanDirectoryRecursively(in Path path) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.CleanDirectoryRecursively(path); } - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) + protected override Result DoRenameFile(in Path currentPath, in Path newPath) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.RenameFile(currentPath, newPath); } - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.RenameDirectory(currentPath, newPath); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.GetEntryType(out entryType, path); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.GetFreeSpaceSize(out freeSpace, path); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.GetTotalSpaceSize(out totalSpace, path); } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.OpenFile(out file, path, mode); } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.OpenDirectory(out directory, path, mode); @@ -151,13 +147,14 @@ namespace LibHac.FsSystem return BaseFileSystem.Target.Flush(); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.GetFileTimeStampRaw(out timeStamp, path); } - protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, U8Span path) + protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, + in Path path) { using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageFlag); return BaseFileSystem.Target.QueryEntry(outBuffer, inBuffer, queryId, path); diff --git a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs index 57322116..0f84a538 100644 --- a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs +++ b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs @@ -44,14 +44,10 @@ namespace LibHac.FsSystem PreserveUnc = preserveUnc; } - protected override void Dispose(bool disposing) + public override void Dispose() { - if (disposing) - { - BaseFileSystemShared?.Dispose(); - } - - base.Dispose(disposing); + BaseFileSystemShared?.Dispose(); + base.Dispose(); } public Result Initialize(U8Span rootPath) @@ -93,7 +89,7 @@ namespace LibHac.FsSystem return PathNormalizer.Normalize(outPath.Slice(RootPath.Length - 2), out _, relativePath, PreserveUnc, false); } - protected override Result DoCreateDirectory(U8Span path) + protected override Result DoCreateDirectory(in Path path) { Span fullPath = stackalloc byte[PathTools.MaxPathLength + 1]; Result rc = ResolveFullPath(fullPath, path); @@ -102,7 +98,7 @@ namespace LibHac.FsSystem return BaseFileSystem.CreateDirectory(new U8Span(fullPath)); } - protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions option) + protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { Span fullPath = stackalloc byte[PathTools.MaxPathLength + 1]; Result rc = ResolveFullPath(fullPath, path); @@ -111,7 +107,7 @@ namespace LibHac.FsSystem return BaseFileSystem.CreateFile(new U8Span(fullPath), size, option); } - protected override Result DoDeleteDirectory(U8Span path) + protected override Result DoDeleteDirectory(in Path path) { Span fullPath = stackalloc byte[PathTools.MaxPathLength + 1]; Result rc = ResolveFullPath(fullPath, path); @@ -120,7 +116,7 @@ namespace LibHac.FsSystem return BaseFileSystem.DeleteDirectory(new U8Span(fullPath)); } - protected override Result DoDeleteDirectoryRecursively(U8Span path) + protected override Result DoDeleteDirectoryRecursively(in Path path) { Span fullPath = stackalloc byte[PathTools.MaxPathLength + 1]; Result rc = ResolveFullPath(fullPath, path); @@ -129,7 +125,7 @@ namespace LibHac.FsSystem return BaseFileSystem.DeleteDirectoryRecursively(new U8Span(fullPath)); } - protected override Result DoCleanDirectoryRecursively(U8Span path) + protected override Result DoCleanDirectoryRecursively(in Path path) { Span fullPath = stackalloc byte[PathTools.MaxPathLength + 1]; Result rc = ResolveFullPath(fullPath, path); @@ -138,7 +134,7 @@ namespace LibHac.FsSystem return BaseFileSystem.CleanDirectoryRecursively(new U8Span(fullPath)); } - protected override Result DoDeleteFile(U8Span path) + protected override Result DoDeleteFile(in Path path) { Span fullPath = stackalloc byte[PathTools.MaxPathLength + 1]; Result rc = ResolveFullPath(fullPath, path); @@ -147,7 +143,7 @@ namespace LibHac.FsSystem return BaseFileSystem.DeleteFile(new U8Span(fullPath)); } - protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(out IDirectory directory, in Path path, OpenDirectoryMode mode) { UnsafeHelpers.SkipParamInit(out directory); @@ -158,7 +154,7 @@ namespace LibHac.FsSystem return BaseFileSystem.OpenDirectory(out directory, new U8Span(fullPath), mode); } - protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) + protected override Result DoOpenFile(out IFile file, in Path path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out file); @@ -169,7 +165,7 @@ namespace LibHac.FsSystem return BaseFileSystem.OpenFile(out file, new U8Span(fullPath), mode); } - protected override Result DoRenameDirectory(U8Span currentPath, U8Span newPath) + protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { Span fullOldPath = stackalloc byte[PathTools.MaxPathLength + 1]; Span fullNewPath = stackalloc byte[PathTools.MaxPathLength + 1]; @@ -183,7 +179,7 @@ namespace LibHac.FsSystem return BaseFileSystem.RenameDirectory(new U8Span(fullOldPath), new U8Span(fullNewPath)); } - protected override Result DoRenameFile(U8Span currentPath, U8Span newPath) + protected override Result DoRenameFile(in Path currentPath, in Path newPath) { Span fullOldPath = stackalloc byte[PathTools.MaxPathLength + 1]; Span fullNewPath = stackalloc byte[PathTools.MaxPathLength + 1]; @@ -197,7 +193,7 @@ namespace LibHac.FsSystem return BaseFileSystem.RenameFile(new U8Span(fullOldPath), new U8Span(fullNewPath)); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -224,7 +220,7 @@ namespace LibHac.FsSystem return BaseFileSystem.Rollback(); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) { UnsafeHelpers.SkipParamInit(out freeSpace); @@ -235,7 +231,7 @@ namespace LibHac.FsSystem return BaseFileSystem.GetFreeSpaceSize(out freeSpace, new U8Span(fullPath)); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) { UnsafeHelpers.SkipParamInit(out totalSpace); @@ -246,7 +242,7 @@ namespace LibHac.FsSystem return BaseFileSystem.GetTotalSpaceSize(out totalSpace, new U8Span(fullPath)); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) { UnsafeHelpers.SkipParamInit(out timeStamp); @@ -258,7 +254,7 @@ namespace LibHac.FsSystem } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - U8Span path) + in Path path) { Span fullPath = stackalloc byte[PathTools.MaxPathLength + 1]; Result rc = ResolveFullPath(fullPath, path);