Rename TitleId to ProgramId and add other NCM ID types

This commit is contained in:
Alex Barney 2020-07-09 21:22:04 -07:00
parent 3819cfdca7
commit 717e54fe4e
24 changed files with 622 additions and 221 deletions

View File

@ -3,7 +3,6 @@ using System.Diagnostics;
using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Shim;
using LibHac.Ncm;
using static LibHac.Fs.StringTraits;
namespace LibHac.Bcat.Detail.Service.Core
@ -56,7 +55,7 @@ namespace LibHac.Bcat.Detail.Service.Core
if (!DisableStorage)
{
rc = Server.GetFsClient()
.MountBcatSaveData(new U8Span(mountName.Name), new TitleId(applicationId));
.MountBcatSaveData(new U8Span(mountName.Name), new Ncm.ApplicationId(applicationId));
if (rc.IsFailure())
{

View File

@ -1,16 +0,0 @@
using LibHac.Ncm;
namespace LibHac.Common
{
public static class SystemTitleIds
{
public static TitleId Fs => new TitleId(0x0100000000000000);
public static TitleId Loader => new TitleId(0x0100000000000001);
public static TitleId Ncm => new TitleId(0x0100000000000002);
public static TitleId ProcessManager => new TitleId(0x0100000000000003);
public static TitleId Sm => new TitleId(0x0100000000000004);
public static TitleId Boot => new TitleId(0x0100000000000005);
public static TitleId Bcat => new TitleId(0x010000000000000C);
}
}

View File

@ -9,14 +9,14 @@ namespace LibHac.Fs
{
public static class ApplicationSaveDataManagement
{
public static Result EnsureApplicationSaveData(FileSystemClient fs, out long requiredSize, TitleId applicationId,
public static Result EnsureApplicationSaveData(FileSystemClient fs, out long requiredSize, Ncm.ApplicationId applicationId,
ref ApplicationControlProperty nacp, ref Uid uid)
{
requiredSize = default;
long requiredSizeSum = 0;
// Create local variable for use in closures
TitleId saveDataOwnerId = nacp.SaveDataOwnerId;
ProgramId saveDataOwnerId = nacp.SaveDataOwnerId;
// Ensure the user account save exists
if (uid != Uid.Zero && nacp.UserAccountSaveDataSize > 0)
@ -29,7 +29,7 @@ namespace LibHac.Fs
Result CreateAccountSaveFunc()
{
UserId userId = ConvertAccountUidToFsUserId(uidLocal);
return fs.CreateSaveData(applicationId, userId, saveDataOwnerId, accountSaveDataSize,
return fs.CreateSaveData(applicationId, userId, saveDataOwnerId.Value, accountSaveDataSize,
accountSaveJournalSize, SaveDataFlags.None);
}
@ -51,7 +51,7 @@ namespace LibHac.Fs
long deviceSaveDataSize = nacp.DeviceSaveDataSize;
long deviceSaveJournalSize = nacp.DeviceSaveDataJournalSize;
Result CreateDeviceSaveFunc() => fs.CreateDeviceSaveData(applicationId, saveDataOwnerId,
Result CreateDeviceSaveFunc() => fs.CreateDeviceSaveData(applicationId, saveDataOwnerId.Value,
deviceSaveDataSize, deviceSaveJournalSize, 0);
var filter = new SaveDataFilter();
@ -106,7 +106,7 @@ namespace LibHac.Fs
}
else
{
Result createRc = fs.CreateTemporaryStorage(applicationId, nacp.SaveDataOwnerId,
Result createRc = fs.CreateTemporaryStorage(applicationId, nacp.SaveDataOwnerId.Value,
nacp.TemporaryStorageSize, 0);
if (createRc.IsFailure())
@ -202,7 +202,7 @@ namespace LibHac.Fs
}
private static Result EnsureApplicationBcatDeliveryCacheStorageImpl(FileSystemClient fs, out long requiredSize,
TitleId applicationId, ref ApplicationControlProperty nacp)
Ncm.ApplicationId applicationId, ref ApplicationControlProperty nacp)
{
const long bcatDeliveryCacheJournalSize = 0x200000;
@ -232,7 +232,7 @@ namespace LibHac.Fs
}
private static Result EnsureApplicationCacheStorageImpl(this FileSystemClient fs, out long requiredSize,
out CacheStorageTargetMedia target, TitleId applicationId, TitleId saveDataOwnerId, short index,
out CacheStorageTargetMedia target, Ncm.ApplicationId applicationId, ulong saveDataOwnerId, short index,
long dataSize, long journalSize, bool allowExisting)
{
requiredSize = default;
@ -299,7 +299,7 @@ namespace LibHac.Fs
}
public static Result EnsureApplicationCacheStorage(this FileSystemClient fs, out long requiredSize,
out CacheStorageTargetMedia target, TitleId applicationId, TitleId saveDataOwnerId, short index,
out CacheStorageTargetMedia target, Ncm.ApplicationId applicationId, ulong saveDataOwnerId, short index,
long dataSize, long journalSize, bool allowExisting)
{
return EnsureApplicationCacheStorageImpl(fs, out requiredSize, out target, applicationId, saveDataOwnerId,
@ -307,14 +307,14 @@ namespace LibHac.Fs
}
public static Result EnsureApplicationCacheStorage(this FileSystemClient fs, out long requiredSize,
TitleId applicationId, ref ApplicationControlProperty nacp)
Ncm.ApplicationId applicationId, ref ApplicationControlProperty nacp)
{
return EnsureApplicationCacheStorageImpl(fs, out requiredSize, out _, applicationId, nacp.SaveDataOwnerId,
return EnsureApplicationCacheStorageImpl(fs, out requiredSize, out _, applicationId, nacp.SaveDataOwnerId.Value,
0, nacp.CacheStorageSize, nacp.CacheStorageJournalSize, true);
}
public static Result EnsureApplicationCacheStorage(this FileSystemClient fs, out long requiredSize,
out CacheStorageTargetMedia target, TitleId applicationId, ref ApplicationControlProperty nacp)
out CacheStorageTargetMedia target, Ncm.ApplicationId applicationId, ref ApplicationControlProperty nacp)
{
if (nacp.CacheStorageSize <= 0)
{
@ -324,18 +324,18 @@ namespace LibHac.Fs
}
return EnsureApplicationCacheStorageImpl(fs, out requiredSize, out target, applicationId,
nacp.SaveDataOwnerId, 0, nacp.CacheStorageSize, nacp.CacheStorageJournalSize, true);
nacp.SaveDataOwnerId.Value, 0, nacp.CacheStorageSize, nacp.CacheStorageJournalSize, true);
}
public static Result EnsureApplicationBcatDeliveryCacheStorage(this FileSystemClient fs, out long requiredSize,
TitleId applicationId, ref ApplicationControlProperty nacp)
Ncm.ApplicationId applicationId, ref ApplicationControlProperty nacp)
{
return EnsureApplicationBcatDeliveryCacheStorageImpl(fs, out requiredSize, applicationId, ref nacp);
}
public static Result TryCreateCacheStorage(this FileSystemClient fs, out long requiredSize,
SaveDataSpaceId spaceId, TitleId applicationId, TitleId saveDataOwnerId, short index, long dataSize,
long journalSize, bool allowExisting)
SaveDataSpaceId spaceId, Ncm.ApplicationId applicationId, ulong saveDataOwnerId, short index,
long dataSize, long journalSize, bool allowExisting)
{
requiredSize = default;
long requiredSizeLocal = 0;
@ -383,12 +383,14 @@ namespace LibHac.Fs
return rc;
}
public static Result GetCacheStorageTargetMedia(this FileSystemClient fs, out CacheStorageTargetMedia target, TitleId applicationId)
public static Result GetCacheStorageTargetMedia(this FileSystemClient fs, out CacheStorageTargetMedia target,
Ncm.ApplicationId applicationId)
{
return GetCacheStorageTargetMediaImpl(fs, out target, applicationId);
}
private static Result GetCacheStorageTargetMediaImpl(this FileSystemClient fs, out CacheStorageTargetMedia target, TitleId applicationId)
private static Result GetCacheStorageTargetMediaImpl(this FileSystemClient fs,
out CacheStorageTargetMedia target, Ncm.ApplicationId applicationId)
{
target = CacheStorageTargetMedia.None;

View File

@ -8,8 +8,7 @@ namespace LibHac.Fs
[StructLayout(LayoutKind.Explicit, Size = 0x40)]
public struct SaveDataAttribute : IEquatable<SaveDataAttribute>, IComparable<SaveDataAttribute>
{
// todo: rename to ProgramId
[FieldOffset(0x00)] public TitleId TitleId;
[FieldOffset(0x00)] public ProgramId ProgramId;
[FieldOffset(0x08)] public UserId UserId;
[FieldOffset(0x18)] public ulong SaveDataId;
[FieldOffset(0x20)] public SaveDataType Type;
@ -23,7 +22,7 @@ namespace LibHac.Fs
public bool Equals(SaveDataAttribute other)
{
return TitleId == other.TitleId &&
return ProgramId == other.ProgramId &&
Type == other.Type &&
UserId.Equals(other.UserId) &&
SaveDataId == other.SaveDataId &&
@ -34,13 +33,13 @@ namespace LibHac.Fs
public override int GetHashCode()
{
// ReSharper disable NonReadonlyMemberInGetHashCode
return HashCode.Combine(TitleId, Type, UserId, SaveDataId, Rank, Index);
return HashCode.Combine(ProgramId, Type, UserId, SaveDataId, Rank, Index);
// ReSharper restore NonReadonlyMemberInGetHashCode
}
public int CompareTo(SaveDataAttribute other)
{
int titleIdComparison = TitleId.CompareTo(other.TitleId);
int titleIdComparison = ProgramId.CompareTo(other.ProgramId);
if (titleIdComparison != 0) return titleIdComparison;
int typeComparison = Type.CompareTo(other.Type);
if (typeComparison != 0) return typeComparison;
@ -64,13 +63,13 @@ namespace LibHac.Fs
[FieldOffset(0x04)] public bool FilterByIndex;
[FieldOffset(0x05)] public SaveDataRank Rank;
[FieldOffset(0x08)] public TitleId ProgramId;
[FieldOffset(0x08)] public ProgramId ProgramId;
[FieldOffset(0x10)] public UserId UserId;
[FieldOffset(0x20)] public ulong SaveDataId;
[FieldOffset(0x28)] public SaveDataType SaveDataType;
[FieldOffset(0x2A)] public short Index;
public void SetProgramId(TitleId value)
public void SetProgramId(ProgramId value)
{
FilterByProgramId = true;
ProgramId = value;
@ -131,7 +130,7 @@ namespace LibHac.Fs
[FieldOffset(0x00)] public long Size;
[FieldOffset(0x08)] public long JournalSize;
[FieldOffset(0x10)] public ulong BlockSize;
[FieldOffset(0x18)] public TitleId OwnerId;
[FieldOffset(0x18)] public ulong OwnerId;
[FieldOffset(0x20)] public SaveDataFlags Flags;
[FieldOffset(0x24)] public SaveDataSpaceId SpaceId;
[FieldOffset(0x25)] public bool Field25;
@ -145,7 +144,7 @@ namespace LibHac.Fs
[FieldOffset(0x09)] public SaveDataType Type;
[FieldOffset(0x10)] public UserId UserId;
[FieldOffset(0x20)] public ulong SaveDataIdFromKey;
[FieldOffset(0x28)] public TitleId TitleId;
[FieldOffset(0x28)] public ProgramId ProgramId;
[FieldOffset(0x30)] public long Size;
[FieldOffset(0x38)] public short Index;
[FieldOffset(0x3A)] public SaveDataRank Rank;

View File

@ -2,13 +2,12 @@
using LibHac.Common;
using LibHac.Fs.Fsa;
using LibHac.FsService;
using LibHac.Ncm;
namespace LibHac.Fs.Shim
{
public static class BcatSaveData
{
public static Result MountBcatSaveData(this FileSystemClient fs, U8Span mountName, TitleId applicationId)
public static Result MountBcatSaveData(this FileSystemClient fs, U8Span mountName, Ncm.ApplicationId applicationId)
{
Result rc;
@ -37,7 +36,7 @@ namespace LibHac.Fs.Shim
return Result.Success;
}
private static Result MountBcatSaveDataImpl(FileSystemClient fs, U8Span mountName, TitleId applicationId)
private static Result MountBcatSaveDataImpl(FileSystemClient fs, U8Span mountName, Ncm.ApplicationId applicationId)
{
Result rc = MountHelpers.CheckMountName(mountName);
if (rc.IsFailure()) return rc;
@ -45,7 +44,7 @@ namespace LibHac.Fs.Shim
IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();
SaveDataAttribute attribute = default;
attribute.TitleId = applicationId;
attribute.ProgramId = applicationId;
attribute.Type = SaveDataType.Bcat;
rc = fsProxy.OpenSaveDataFileSystem(out IFileSystem fileSystem, SaveDataSpaceId.User, ref attribute);

View File

@ -9,15 +9,16 @@ namespace LibHac.Fs.Shim
{
public static class Content
{
// todo: add logging
public static Result MountContent(this FileSystemClient fs, U8Span mountName, U8Span path, ContentType type)
{
if (type == ContentType.Meta)
return ResultFs.InvalidArgument.Log();
return MountContent(fs, mountName, path, TitleId.Zero, type);
return MountContent(fs, mountName, path, ProgramId.InvalidId, type);
}
public static Result MountContent(this FileSystemClient fs, U8Span mountName, TitleId programId, ContentType type)
public static Result MountContent(this FileSystemClient fs, U8Span mountName, ProgramId programId, ContentType type)
{
Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName);
if (rc.IsFailure()) return rc;
@ -32,23 +33,33 @@ namespace LibHac.Fs.Shim
return fs.Register(mountName, fileSystem);
}
public static Result MountContent(this FileSystemClient fs, U8Span mountName, U8Span path, TitleId titleId, ContentType type)
public static Result MountContent(this FileSystemClient fs, U8Span mountName, U8Span path, ProgramId programId, ContentType type)
{
Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName);
if (rc.IsFailure()) return rc;
FileSystemProxyType fspType = ConvertToFileSystemProxyType(type);
return MountContentImpl(fs, mountName, path, titleId, fspType);
return MountContentImpl(fs, mountName, path, programId.Value, fspType);
}
private static Result MountContentImpl(FileSystemClient fs, U8Span mountName, U8Span path, TitleId titleId, FileSystemProxyType type)
public static Result MountContent(this FileSystemClient fs, U8Span mountName, U8Span path, DataId dataId, ContentType type)
{
Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName);
if (rc.IsFailure()) return rc;
FileSystemProxyType fspType = ConvertToFileSystemProxyType(type);
return MountContentImpl(fs, mountName, path, dataId.Value, fspType);
}
private static Result MountContentImpl(FileSystemClient fs, U8Span mountName, U8Span path, ulong id, FileSystemProxyType type)
{
FsPath.FromSpan(out FsPath fsPath, path);
IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();
Result rc = fsProxy.OpenFileSystemWithId(out IFileSystem fileSystem, ref fsPath, titleId, type);
Result rc = fsProxy.OpenFileSystemWithId(out IFileSystem fileSystem, ref fsPath, id, type);
if (rc.IsFailure()) return rc;
return fs.Register(mountName, fileSystem);

View File

@ -9,7 +9,7 @@ namespace LibHac.Fs.Shim
{
public static class RightsId
{
public static Result GetRightsId(this FileSystemClient fs, out FsRightsId rightsId, TitleId programId,
public static Result GetRightsId(this FileSystemClient fs, out FsRightsId rightsId, ProgramId programId,
StorageId storageId)
{
IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();

View File

@ -8,7 +8,7 @@ namespace LibHac.Fs.Shim
{
public static class SaveData
{
public static Result MountSaveData(this FileSystemClient fs, U8Span mountName, TitleId applicationId, UserId userId)
public static Result MountSaveData(this FileSystemClient fs, U8Span mountName, Ncm.ApplicationId applicationId, UserId userId)
{
Result rc;
@ -33,7 +33,7 @@ namespace LibHac.Fs.Shim
return rc;
}
public static Result MountSaveDataReadOnly(this FileSystemClient fs, U8Span mountName, TitleId applicationId, UserId userId)
public static Result MountSaveDataReadOnly(this FileSystemClient fs, U8Span mountName, Ncm.ApplicationId applicationId, UserId userId)
{
Result rc;
@ -133,7 +133,7 @@ namespace LibHac.Fs.Shim
return rc;
}
public static Result MountCacheStorage(this FileSystemClient fs, U8Span mountName, TitleId applicationId)
public static Result MountCacheStorage(this FileSystemClient fs, U8Span mountName, Ncm.ApplicationId applicationId)
{
Result rc;
@ -158,7 +158,7 @@ namespace LibHac.Fs.Shim
return rc;
}
public static Result MountCacheStorage(this FileSystemClient fs, U8Span mountName, TitleId applicationId, int index)
public static Result MountCacheStorage(this FileSystemClient fs, U8Span mountName, Ncm.ApplicationId applicationId, int index)
{
Result rc;
@ -184,7 +184,7 @@ namespace LibHac.Fs.Shim
}
private static Result MountSaveDataImpl(this FileSystemClient fs, U8Span mountName, SaveDataSpaceId spaceId,
TitleId titleId, UserId userId, SaveDataType type, bool openReadOnly, short index)
ProgramId programId, UserId userId, SaveDataType type, bool openReadOnly, short index)
{
Result rc = MountHelpers.CheckMountName(mountName);
if (rc.IsFailure()) return rc;
@ -192,7 +192,7 @@ namespace LibHac.Fs.Shim
IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();
SaveDataAttribute attribute = default;
attribute.TitleId = titleId;
attribute.ProgramId = programId;
attribute.UserId = userId;
attribute.Type = type;
attribute.Index = index;

View File

@ -8,8 +8,8 @@ namespace LibHac.Fs.Shim
{
public static class SaveDataManagement
{
public static Result CreateSaveData(this FileSystemClient fs, TitleId applicationId, UserId userId, TitleId ownerId,
long size, long journalSize, SaveDataFlags flags)
public static Result CreateSaveData(this FileSystemClient fs, Ncm.ApplicationId applicationId, UserId userId,
ulong ownerId, long size, long journalSize, SaveDataFlags flags)
{
return fs.RunOperationWithAccessLog(AccessLogTarget.System,
() =>
@ -18,7 +18,7 @@ namespace LibHac.Fs.Shim
var attribute = new SaveDataAttribute
{
TitleId = applicationId,
ProgramId = applicationId,
UserId = userId,
Type = SaveDataType.Account
};
@ -41,11 +41,12 @@ namespace LibHac.Fs.Shim
return fsProxy.CreateSaveDataFileSystem(ref attribute, ref createInfo, ref metaInfo);
},
() => $", applicationid: 0x{applicationId.Value:X}, userid: 0x{userId}, save_data_owner_id: 0x{ownerId.Value:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:X8}");
() =>
$", applicationid: 0x{applicationId.Value:X}, userid: 0x{userId}, save_data_owner_id: 0x{ownerId:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:X8}");
}
public static Result CreateSaveData(this FileSystemClient fs, TitleId applicationId, UserId userId, TitleId ownerId,
long size, long journalSize, HashSalt hashSalt, SaveDataFlags flags)
public static Result CreateSaveData(this FileSystemClient fs, Ncm.ApplicationId applicationId, UserId userId,
ulong ownerId, long size, long journalSize, HashSalt hashSalt, SaveDataFlags flags)
{
return fs.RunOperationWithAccessLog(AccessLogTarget.System,
() =>
@ -54,7 +55,7 @@ namespace LibHac.Fs.Shim
var attribute = new SaveDataAttribute
{
TitleId = applicationId,
ProgramId = applicationId,
UserId = userId,
Type = SaveDataType.Account
};
@ -75,12 +76,14 @@ namespace LibHac.Fs.Shim
Size = 0x40060
};
return fsProxy.CreateSaveDataFileSystemWithHashSalt(ref attribute, ref createInfo, ref metaInfo, ref hashSalt);
return fsProxy.CreateSaveDataFileSystemWithHashSalt(ref attribute, ref createInfo, ref metaInfo,
ref hashSalt);
},
() => $", applicationid: 0x{applicationId.Value:X}, userid: 0x{userId}, save_data_owner_id: 0x{ownerId.Value:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:X8}");
() =>
$", applicationid: 0x{applicationId.Value:X}, userid: 0x{userId}, save_data_owner_id: 0x{ownerId:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:X8}");
}
public static Result CreateBcatSaveData(this FileSystemClient fs, TitleId applicationId, long size)
public static Result CreateBcatSaveData(this FileSystemClient fs, Ncm.ApplicationId applicationId, long size)
{
return fs.RunOperationWithAccessLog(AccessLogTarget.System,
() =>
@ -89,7 +92,7 @@ namespace LibHac.Fs.Shim
var attribute = new SaveDataAttribute
{
TitleId = applicationId,
ProgramId = applicationId,
Type = SaveDataType.Bcat
};
@ -98,7 +101,7 @@ namespace LibHac.Fs.Shim
Size = size,
JournalSize = 0x200000,
BlockSize = 0x4000,
OwnerId = SystemTitleIds.Bcat,
OwnerId = SystemProgramId.Bcat.Value,
Flags = 0,
SpaceId = SaveDataSpaceId.User
};
@ -110,7 +113,7 @@ namespace LibHac.Fs.Shim
() => $", applicationid: 0x{applicationId.Value:X}, save_data_size: {size}");
}
public static Result CreateDeviceSaveData(this FileSystemClient fs, TitleId applicationId, TitleId ownerId,
public static Result CreateDeviceSaveData(this FileSystemClient fs, Ncm.ApplicationId applicationId, ulong ownerId,
long size, long journalSize, SaveDataFlags flags)
{
return fs.RunOperationWithAccessLog(AccessLogTarget.System,
@ -120,7 +123,7 @@ namespace LibHac.Fs.Shim
var attribute = new SaveDataAttribute
{
TitleId = applicationId,
ProgramId = applicationId,
Type = SaveDataType.Device
};
@ -138,10 +141,10 @@ namespace LibHac.Fs.Shim
return fsProxy.CreateSaveDataFileSystem(ref attribute, ref createInfo, ref metaInfo);
},
() => $", applicationid: 0x{applicationId.Value:X}, save_data_owner_id: 0x{ownerId.Value:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:X8}");
() => $", applicationid: 0x{applicationId.Value:X}, save_data_owner_id: 0x{ownerId:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:X8}");
}
public static Result CreateTemporaryStorage(this FileSystemClient fs, TitleId applicationId, TitleId ownerId, long size, SaveDataFlags flags)
public static Result CreateTemporaryStorage(this FileSystemClient fs, Ncm.ApplicationId applicationId, ulong ownerId, long size, SaveDataFlags flags)
{
return fs.RunOperationWithAccessLog(AccessLogTarget.System,
() =>
@ -150,7 +153,7 @@ namespace LibHac.Fs.Shim
var attribute = new SaveDataAttribute
{
TitleId = applicationId,
ProgramId = applicationId,
Type = SaveDataType.Temporary
};
@ -167,11 +170,11 @@ namespace LibHac.Fs.Shim
return fsProxy.CreateSaveDataFileSystem(ref attribute, ref createInfo, ref metaInfo);
},
() => $", applicationid: 0x{applicationId.Value:X}, save_data_owner_id: 0x{ownerId.Value:X}, save_data_size: {size}, save_data_flags: 0x{(int)flags:X8}");
() => $", applicationid: 0x{applicationId.Value:X}, save_data_owner_id: 0x{ownerId:X}, save_data_size: {size}, save_data_flags: 0x{(int)flags:X8}");
}
public static Result CreateCacheStorage(this FileSystemClient fs, TitleId applicationId,
SaveDataSpaceId spaceId, TitleId ownerId, short index, long size, long journalSize, SaveDataFlags flags)
public static Result CreateCacheStorage(this FileSystemClient fs, Ncm.ApplicationId applicationId,
SaveDataSpaceId spaceId, ulong ownerId, short index, long size, long journalSize, SaveDataFlags flags)
{
return fs.RunOperationWithAccessLog(AccessLogTarget.System,
() =>
@ -180,7 +183,7 @@ namespace LibHac.Fs.Shim
var attribute = new SaveDataAttribute
{
TitleId = applicationId,
ProgramId = applicationId,
Type = SaveDataType.Cache,
Index = index
};
@ -199,23 +202,23 @@ namespace LibHac.Fs.Shim
return fsProxy.CreateSaveDataFileSystem(ref attribute, ref creationInfo, ref metaInfo);
},
() => $", applicationid: 0x{applicationId.Value:X}, savedataspaceid: {spaceId}, save_data_owner_id: 0x{ownerId.Value:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:X8}");
() => $", applicationid: 0x{applicationId.Value:X}, savedataspaceid: {spaceId}, save_data_owner_id: 0x{ownerId:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:X8}");
}
public static Result CreateCacheStorage(this FileSystemClient fs, TitleId applicationId,
SaveDataSpaceId spaceId, TitleId ownerId, long size, long journalSize, SaveDataFlags flags)
public static Result CreateCacheStorage(this FileSystemClient fs, Ncm.ApplicationId applicationId,
SaveDataSpaceId spaceId, ulong ownerId, long size, long journalSize, SaveDataFlags flags)
{
return CreateCacheStorage(fs, applicationId, spaceId, ownerId, 0, size, journalSize, flags);
}
public static Result CreateCacheStorage(this FileSystemClient fs, TitleId applicationId, TitleId ownerId,
long size, long journalSize, SaveDataFlags flags)
public static Result CreateCacheStorage(this FileSystemClient fs, Ncm.ApplicationId applicationId,
ulong ownerId, long size, long journalSize, SaveDataFlags flags)
{
return CreateCacheStorage(fs, applicationId, SaveDataSpaceId.User, ownerId, 0, size, journalSize, flags);
}
public static Result CreateSystemSaveData(this FileSystemClient fs, SaveDataSpaceId spaceId,
ulong saveDataId, UserId userId, TitleId ownerId, long size, long journalSize, SaveDataFlags flags)
ulong saveDataId, UserId userId, ulong ownerId, long size, long journalSize, SaveDataFlags flags)
{
return fs.RunOperationWithAccessLog(AccessLogTarget.System,
() =>
@ -240,11 +243,11 @@ namespace LibHac.Fs.Shim
return fsProxy.CreateSaveDataFileSystemBySystemSaveDataId(ref attribute, ref createInfo);
},
() => $", savedataspaceid: {spaceId}, savedataid: 0x{saveDataId:X}, userid: 0x{userId.Id.High:X16}{userId.Id.Low:X16}, save_data_owner_id: 0x{ownerId.Value:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:x8}");
() => $", savedataspaceid: {spaceId}, savedataid: 0x{saveDataId:X}, userid: 0x{userId.Id.High:X16}{userId.Id.Low:X16}, save_data_owner_id: 0x{ownerId:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:x8}");
}
public static Result CreateSystemSaveData(this FileSystemClient fs, ulong saveDataId, UserId userId,
TitleId ownerId, long size, long journalSize, SaveDataFlags flags)
ulong ownerId, long size, long journalSize, SaveDataFlags flags)
{
return CreateSystemSaveData(fs, SaveDataSpaceId.System, saveDataId, userId, ownerId, size, journalSize, flags);
}
@ -252,10 +255,10 @@ namespace LibHac.Fs.Shim
public static Result CreateSystemSaveData(this FileSystemClient fs, ulong saveDataId, UserId userId, long size,
long journalSize, SaveDataFlags flags)
{
return CreateSystemSaveData(fs, SaveDataSpaceId.System, saveDataId, userId, TitleId.Zero, size, journalSize, flags);
return CreateSystemSaveData(fs, SaveDataSpaceId.System, saveDataId, userId, 0, size, journalSize, flags);
}
public static Result CreateSystemSaveData(this FileSystemClient fs, ulong saveDataId, TitleId ownerId, long size,
public static Result CreateSystemSaveData(this FileSystemClient fs, ulong saveDataId, ulong ownerId, long size,
long journalSize, SaveDataFlags flags)
{
return CreateSystemSaveData(fs, SaveDataSpaceId.System, saveDataId, UserId.Zero, ownerId, size, journalSize, flags);
@ -264,11 +267,11 @@ namespace LibHac.Fs.Shim
public static Result CreateSystemSaveData(this FileSystemClient fs, ulong saveDataId, long size,
long journalSize, SaveDataFlags flags)
{
return CreateSystemSaveData(fs, SaveDataSpaceId.System, saveDataId, UserId.Zero, TitleId.Zero, size, journalSize, flags);
return CreateSystemSaveData(fs, SaveDataSpaceId.System, saveDataId, UserId.Zero, 0, size, journalSize, flags);
}
public static Result CreateSystemSaveData(this FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId,
TitleId ownerId, long size, long journalSize, SaveDataFlags flags)
ulong ownerId, long size, long journalSize, SaveDataFlags flags)
{
return CreateSystemSaveData(fs, spaceId, saveDataId, UserId.Zero, ownerId, size, journalSize, flags);
}

View File

@ -34,7 +34,7 @@ namespace LibHac.FsService
AutoCreateSaveData = true;
}
public Result OpenFileSystemWithId(out IFileSystem fileSystem, ref FsPath path, TitleId titleId, FileSystemProxyType type)
public Result OpenFileSystemWithId(out IFileSystem fileSystem, ref FsPath path, ulong id, FileSystemProxyType type)
{
fileSystem = default;
@ -46,7 +46,7 @@ namespace LibHac.FsService
if (normalizer.Result.IsFailure()) return normalizer.Result;
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return FsProxyCore.OpenFileSystem(out fileSystem, normalizer.Path, type, canMountSystemDataPrivate, titleId);
return FsProxyCore.OpenFileSystem(out fileSystem, normalizer.Path, type, canMountSystemDataPrivate, id);
}
private PathNormalizer.Option GetPathNormalizerOptions(U8Span path)
@ -60,7 +60,7 @@ namespace LibHac.FsService
return PathNormalizer.Option.HasMountName | PathNormalizer.Option.PreserveTailSeparator | hostOption;
}
public Result OpenFileSystemWithPatch(out IFileSystem fileSystem, TitleId titleId, FileSystemProxyType type)
public Result OpenFileSystemWithPatch(out IFileSystem fileSystem, ProgramId programId, FileSystemProxyType type)
{
throw new NotImplementedException();
}
@ -82,7 +82,7 @@ namespace LibHac.FsService
throw new NotImplementedException();
}
public Result OpenDataFileSystemByProgramId(out IFileSystem fileSystem, TitleId titleId)
public Result OpenDataFileSystemByProgramId(out IFileSystem fileSystem, ProgramId programId)
{
throw new NotImplementedException();
}
@ -92,12 +92,12 @@ namespace LibHac.FsService
throw new NotImplementedException();
}
public Result OpenDataStorageByProgramId(out IStorage storage, TitleId programId)
public Result OpenDataStorageByProgramId(out IStorage storage, ProgramId programId)
{
throw new NotImplementedException();
}
public Result OpenDataStorageByDataId(out IStorage storage, TitleId dataId, StorageId storageId)
public Result OpenDataStorageByDataId(out IStorage storage, DataId dataId, StorageId storageId)
{
throw new NotImplementedException();
}
@ -459,7 +459,7 @@ namespace LibHac.FsService
SaveDataCreationInfo newCreationInfo = creationInfo;
if (creationInfo.OwnerId == TitleId.Zero)
if (creationInfo.OwnerId == 0)
{
// todo: Assign the current program's ID
// throw new NotImplementedException();
@ -469,7 +469,7 @@ namespace LibHac.FsService
if (attribute.Type == SaveDataType.SystemBcat)
{
newCreationInfo.OwnerId = SystemTitleIds.Bcat;
newCreationInfo.OwnerId = SystemProgramId.Bcat.Value;
}
SaveMetaCreateInfo metaCreateInfo = default;
@ -563,7 +563,7 @@ namespace LibHac.FsService
SaveDataAttribute attributeCopy;
if (attribute.TitleId == TitleId.Zero)
if (attribute.ProgramId == ProgramId.InvalidId)
{
throw new NotImplementedException();
}
@ -577,7 +577,7 @@ namespace LibHac.FsService
if (attributeCopy.Type == SaveDataType.Cache)
{
// Check whether the save is on the SD card or the BIS
Result rc = GetSpaceIdForCacheStorage(out actualSpaceId, attributeCopy.TitleId);
Result rc = GetSpaceIdForCacheStorage(out actualSpaceId, attributeCopy.ProgramId);
if (rc.IsFailure()) return rc;
}
else
@ -885,7 +885,7 @@ namespace LibHac.FsService
throw new NotImplementedException();
}
private Result GetSpaceIdForCacheStorage(out SaveDataSpaceId spaceId, TitleId programId)
private Result GetSpaceIdForCacheStorage(out SaveDataSpaceId spaceId, ProgramId programId)
{
spaceId = default;
@ -937,7 +937,7 @@ namespace LibHac.FsService
throw new NotImplementedException();
}
public Result ListAccessibleSaveDataOwnerId(out int readCount, Span<TitleId> idBuffer, TitleId programId, int startIndex,
public Result ListAccessibleSaveDataOwnerId(out int readCount, Span<Ncm.ApplicationId> idBuffer, ProgramId programId, int startIndex,
int bufferIdCount)
{
throw new NotImplementedException();
@ -1010,7 +1010,7 @@ namespace LibHac.FsService
throw new NotImplementedException();
}
public Result GetRightsId(out RightsId rightsId, TitleId programId, StorageId storageId)
public Result GetRightsId(out RightsId rightsId, ProgramId programId, StorageId storageId)
{
throw new NotImplementedException();
}
@ -1188,7 +1188,7 @@ namespace LibHac.FsService
fileSystem = default;
SaveDataAttribute attribute = default;
attribute.TitleId = new TitleId(MultiCommitManager.ProgramId);
attribute.ProgramId = new ProgramId(MultiCommitManager.ProgramId);
attribute.SaveDataId = MultiCommitManager.SaveDataId;
Result rc = OpenSaveDataFileSystemImpl(out IFileSystem saveFs, out _, SaveDataSpaceId.System, ref attribute,

View File

@ -8,7 +8,6 @@ using LibHac.Fs.Shim;
using LibHac.FsSystem;
using LibHac.FsService.Creators;
using LibHac.FsSystem.NcaUtils;
using LibHac.Ncm;
using LibHac.Spl;
using RightsId = LibHac.Fs.RightsId;
@ -36,15 +35,15 @@ namespace LibHac.FsService
}
public Result OpenFileSystem(out IFileSystem fileSystem, U8Span path, FileSystemProxyType type,
bool canMountSystemDataPrivate, TitleId titleId)
bool canMountSystemDataPrivate, ulong programId)
{
fileSystem = default;
// Get a reference to the path that will be advanced as each part of the path is parsed
U8Span path2 = path.Slice(0, StringUtils.GetLength(path));
U8Span currentPath = path.Slice(0, StringUtils.GetLength(path));
// Open the root filesystem based on the path's mount name
Result rc = OpenFileSystemFromMountName(ref path2, out IFileSystem baseFileSystem, out bool shouldContinue,
Result rc = OpenFileSystemFromMountName(ref currentPath, out IFileSystem baseFileSystem, out bool shouldContinue,
out MountNameInfo mountNameInfo);
if (rc.IsFailure()) return rc;
@ -64,7 +63,7 @@ namespace LibHac.FsService
return rc;
}
rc = IsContentPathDir(ref path2, out bool isDirectory);
rc = IsContentPathDir(ref currentPath, out bool isDirectory);
if (rc.IsFailure()) return rc;
if (isDirectory)
@ -74,22 +73,22 @@ namespace LibHac.FsService
if (type == FileSystemProxyType.Manual)
{
rc = TryOpenCaseSensitiveContentDirectory(out IFileSystem manualFileSystem, baseFileSystem, path2);
rc = TryOpenCaseSensitiveContentDirectory(out IFileSystem manualFileSystem, baseFileSystem, currentPath);
if (rc.IsFailure()) return rc;
fileSystem = new ReadOnlyFileSystem(manualFileSystem);
return Result.Success;
}
return TryOpenContentDirectory(path2, out fileSystem, baseFileSystem, type, true);
return TryOpenContentDirectory(currentPath, out fileSystem, baseFileSystem, type, true);
}
rc = TryOpenNsp(ref path2, out IFileSystem nspFileSystem, baseFileSystem);
rc = TryOpenNsp(ref currentPath, out IFileSystem nspFileSystem, baseFileSystem);
if (rc.IsSuccess())
{
// Must be the end of the path to open Application Package FS type
if (path2.Length == 0 || path2[0] == 0)
if (currentPath.Length == 0 || currentPath[0] == 0)
{
if (type == FileSystemProxyType.Package)
{
@ -108,9 +107,9 @@ namespace LibHac.FsService
return ResultFs.InvalidNcaMountPoint.Log();
}
TitleId openTitleId = mountNameInfo.IsHostFs ? new TitleId(ulong.MaxValue) : titleId;
ulong openProgramId = mountNameInfo.IsHostFs ? ulong.MaxValue : programId;
rc = TryOpenNca(ref path2, out Nca nca, baseFileSystem, openTitleId);
rc = TryOpenNca(ref currentPath, out Nca nca, baseFileSystem, openProgramId);
if (rc.IsFailure()) return rc;
rc = OpenNcaStorage(out IStorage ncaSectionStorage, nca, out NcaFormatType fsType, type,
@ -403,8 +402,6 @@ namespace LibHac.FsService
case FileSystemProxyType.Control:
case FileSystemProxyType.Manual:
case FileSystemProxyType.Meta:
// Nintendo doesn't include the Data case in the switch. Maybe an oversight?
case FileSystemProxyType.Data:
case FileSystemProxyType.RegisteredUpdate:
dirName = new[] { (byte)'/', (byte)'d', (byte)'a', (byte)'t', (byte)'a', (byte)'/' };
break;
@ -487,7 +484,7 @@ namespace LibHac.FsService
return rc;
}
private Result TryOpenNca(ref U8Span path, out Nca nca, IFileSystem baseFileSystem, TitleId programId)
private Result TryOpenNca(ref U8Span path, out Nca nca, IFileSystem baseFileSystem, ulong ncaId)
{
nca = default;
@ -498,11 +495,11 @@ namespace LibHac.FsService
rc = FsCreators.StorageOnNcaCreator.OpenNca(out Nca ncaTemp, ncaFileStorage);
if (rc.IsFailure()) return rc;
if (programId.Value == ulong.MaxValue)
if (ncaId == ulong.MaxValue)
{
ulong ncaProgramId = ncaTemp.Header.TitleId;
if (ncaProgramId != ulong.MaxValue && programId.Value != ncaProgramId)
if (ncaProgramId != ulong.MaxValue && ncaId != ncaProgramId)
{
return ResultFs.InvalidNcaProgramId.Log();
}

View File

@ -12,9 +12,9 @@ namespace LibHac.FsService
{
Result SetCurrentProcess(long processId);
Result OpenDataFileSystemByCurrentProcess(out IFileSystem fileSystem);
Result OpenFileSystemWithPatch(out IFileSystem fileSystem, TitleId titleId, FileSystemProxyType type);
Result OpenFileSystemWithId(out IFileSystem fileSystem, ref FsPath path, TitleId titleId, FileSystemProxyType type);
Result OpenDataFileSystemByProgramId(out IFileSystem fileSystem, TitleId titleId);
Result OpenFileSystemWithPatch(out IFileSystem fileSystem, ProgramId programId, FileSystemProxyType type);
Result OpenFileSystemWithId(out IFileSystem fileSystem, ref FsPath path, ulong id, FileSystemProxyType type);
Result OpenDataFileSystemByProgramId(out IFileSystem fileSystem, ProgramId programId);
Result OpenBisFileSystem(out IFileSystem fileSystem, ref FsPath rootPath, BisPartitionId partitionId);
Result OpenBisStorage(out IStorage storage, BisPartitionId partitionId);
Result InvalidateBisCache();
@ -54,14 +54,14 @@ namespace LibHac.FsService
Result WriteSaveDataFileSystemExtraDataBySaveDataAttribute(ref SaveDataAttribute attribute, SaveDataSpaceId spaceId, ReadOnlySpan<byte> extraDataBuffer, ReadOnlySpan<byte> maskBuffer);
Result OpenSaveDataMetaFile(out IFile file, SaveDataSpaceId spaceId, ref SaveDataAttribute attribute, SaveDataMetaType type);
Result ListAccessibleSaveDataOwnerId(out int readCount, Span<TitleId> idBuffer, TitleId programId, int startIndex, int bufferIdCount);
Result ListAccessibleSaveDataOwnerId(out int readCount, Span<Ncm.ApplicationId> idBuffer, ProgramId programId, int startIndex, int bufferIdCount);
Result OpenImageDirectoryFileSystem(out IFileSystem fileSystem, ImageDirectoryId dirId);
Result OpenContentStorageFileSystem(out IFileSystem fileSystem, ContentStorageId storageId);
Result OpenCloudBackupWorkStorageFileSystem(out IFileSystem fileSystem, CloudBackupWorkStorageId storageId);
Result OpenCustomStorageFileSystem(out IFileSystem fileSystem, CustomStorageId storageId);
Result OpenDataStorageByCurrentProcess(out IStorage storage);
Result OpenDataStorageByProgramId(out IStorage storage, TitleId programId);
Result OpenDataStorageByDataId(out IStorage storage, TitleId dataId, StorageId storageId);
Result OpenDataStorageByProgramId(out IStorage storage, ProgramId programId);
Result OpenDataStorageByDataId(out IStorage storage, DataId dataId, StorageId storageId);
Result OpenPatchDataStorageByCurrentProcess(out IStorage storage);
Result OpenDataFileSystemWithProgramIndex(out IFileSystem fileSystem, byte programIndex);
Result OpenDataStorageWithProgramIndex(out IStorage storage, byte programIndex);
@ -72,7 +72,7 @@ namespace LibHac.FsService
Result CorruptSaveDataFileSystem(ulong saveDataId);
Result CreatePaddingFile(long size);
Result DeleteAllPaddingFiles();
Result GetRightsId(out RightsId rightsId, TitleId programId, StorageId storageId);
Result GetRightsId(out RightsId rightsId, ProgramId programId, StorageId storageId);
Result RegisterExternalKey(ref RightsId rightsId, ref AccessKey externalKey);
Result UnregisterAllExternalKey();
Result GetRightsIdByPath(out RightsId rightsId, ref FsPath path);

View File

@ -8,7 +8,6 @@ using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Shim;
using LibHac.Kvdb;
using LibHac.Ncm;
namespace LibHac.FsService
{
@ -47,7 +46,7 @@ namespace LibHac.FsService
Type = key.Type,
UserId = key.UserId,
SaveDataIdFromKey = key.SaveDataId,
TitleId = key.TitleId,
ProgramId = key.ProgramId,
Size = value.Size,
Index = key.Index,
Rank = key.Rank,
@ -589,7 +588,7 @@ namespace LibHac.FsService
{
if (ResultFs.TargetNotFound.Includes(rc))
{
rc = FsClient.CreateSystemSaveData(spaceId, saveDataId, TitleId.Zero, 0xC0000, 0xC0000, 0);
rc = FsClient.CreateSystemSaveData(spaceId, saveDataId, 0, 0xC0000, 0xC0000, 0);
if (rc.IsFailure()) return rc;
rc = FsClient.MountSystemSaveData(MountName, spaceId, saveDataId);
@ -605,7 +604,7 @@ namespace LibHac.FsService
rc = FsClient.DeleteSaveData(spaceId, saveDataId);
if (rc.IsFailure()) return rc;
rc = FsClient.CreateSystemSaveData(spaceId, saveDataId, TitleId.Zero, 0xC0000, 0xC0000, 0);
rc = FsClient.CreateSystemSaveData(spaceId, saveDataId, 0, 0xC0000, 0xC0000, 0);
if (rc.IsFailure()) return rc;
rc = FsClient.MountSystemSaveData(MountName, spaceId, saveDataId);

View File

@ -61,7 +61,7 @@ namespace LibHac.FsService
[FieldOffset(0x01)] public SaveDataSpaceId SpaceId;
[FieldOffset(0x08)] public bool FilterByProgramId;
[FieldOffset(0x10)] public TitleId ProgramId;
[FieldOffset(0x10)] public ProgramId ProgramId;
[FieldOffset(0x18)] public bool FilterBySaveDataType;
[FieldOffset(0x19)] public SaveDataType SaveDataType;
@ -123,7 +123,7 @@ namespace LibHac.FsService
SpaceId = spaceId;
}
public void SetProgramId(TitleId value)
public void SetProgramId(ProgramId value)
{
FilterByProgramId = true;
ProgramId = value;
@ -160,7 +160,7 @@ namespace LibHac.FsService
return false;
}
if (FilterByProgramId && info.TitleId != ProgramId)
if (FilterByProgramId && info.ProgramId != ProgramId)
{
return false;
}

View File

@ -0,0 +1,48 @@
namespace LibHac.Ncm
{
public readonly struct ApplicationId
{
public readonly ulong Value;
public ApplicationId(ulong value)
{
Value = value;
}
public static ApplicationId InvalidId => default;
public static ApplicationId Start => new ApplicationId(0x0100000000010000);
public static ApplicationId End => new ApplicationId(0x01FFFFFFFFFFFFFF);
public static implicit operator ProgramId(ApplicationId id) => new ProgramId(id.Value);
public static bool IsApplicationId(ProgramId programId)
{
return Start <= programId && programId <= End;
}
}
public readonly struct PatchId
{
public readonly ulong Value;
public PatchId(ulong value)
{
Value = value;
}
public static implicit operator ProgramId(PatchId id) => new ProgramId(id.Value);
}
public readonly struct DeltaId
{
public readonly ulong Value;
public DeltaId(ulong value)
{
Value = value;
}
public static implicit operator ProgramId(DeltaId id) => new ProgramId(id.Value);
}
}

32
src/LibHac/Ncm/DataId.cs Normal file
View File

@ -0,0 +1,32 @@
using System;
using System.Diagnostics;
namespace LibHac.Ncm
{
[DebuggerDisplay("{" + nameof(Value) + "}")]
public readonly struct DataId : IEquatable<DataId>, IComparable<DataId>
{
public readonly ulong Value;
public DataId(ulong value)
{
Value = value;
}
public static DataId InvalidId => default;
public override string ToString() => $"{Value:X16}";
public override bool Equals(object obj) => obj is DataId id && Equals(id);
public bool Equals(DataId other) => Value == other.Value;
public int CompareTo(DataId other) => Value.CompareTo(other.Value);
public override int GetHashCode() => Value.GetHashCode();
public static bool operator ==(DataId left, DataId right) => left.Equals(right);
public static bool operator !=(DataId left, DataId right) => !(left == right);
public static bool operator <(DataId left, DataId right) => left.CompareTo(right) < 0;
public static bool operator >(DataId left, DataId right) => left.CompareTo(right) > 0;
public static bool operator <=(DataId left, DataId right) => left.CompareTo(right) <= 0;
public static bool operator >=(DataId left, DataId right) => left.CompareTo(right) >= 0;
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Diagnostics;
namespace LibHac.Ncm
{
[DebuggerDisplay("{" + nameof(Value) + "}")]
public readonly struct ProgramId : IEquatable<ProgramId>, IComparable<ProgramId>
{
public readonly ulong Value;
public ProgramId(ulong value)
{
Value = value;
}
public static ProgramId InvalidId => default;
public override string ToString() => $"{Value:X16}";
public override bool Equals(object obj) => obj is ProgramId id && Equals(id);
public bool Equals(ProgramId other) => Value == other.Value;
public int CompareTo(ProgramId other) => Value.CompareTo(other.Value);
public override int GetHashCode() => Value.GetHashCode();
public static bool operator ==(ProgramId left, ProgramId right) => left.Equals(right);
public static bool operator !=(ProgramId left, ProgramId right) => !(left == right);
public static bool operator <(ProgramId left, ProgramId right) => left.CompareTo(right) < 0;
public static bool operator >(ProgramId left, ProgramId right) => left.CompareTo(right) > 0;
public static bool operator <=(ProgramId left, ProgramId right) => left.CompareTo(right) <= 0;
public static bool operator >=(ProgramId left, ProgramId right) => left.CompareTo(right) >= 0;
}
}

View File

@ -0,0 +1,335 @@
namespace LibHac.Ncm
{
public readonly struct SystemProgramId
{
public readonly ulong Value;
public SystemProgramId(ulong value)
{
Value = value;
}
public static implicit operator ProgramId(SystemProgramId id) => new ProgramId(id.Value);
public static bool IsSystemProgramId(ProgramId programId)
{
return Start <= programId && programId <= End;
}
public static bool IsSystemProgramId(SystemProgramId id) => true;
public static SystemProgramId Start => new SystemProgramId(0x0100000000000000);
public static SystemProgramId Fs => new SystemProgramId(0x0100000000000000);
public static SystemProgramId Loader => new SystemProgramId(0x0100000000000001);
public static SystemProgramId Ncm => new SystemProgramId(0x0100000000000002);
public static SystemProgramId Pm => new SystemProgramId(0x0100000000000003);
public static SystemProgramId Sm => new SystemProgramId(0x0100000000000004);
public static SystemProgramId Boot => new SystemProgramId(0x0100000000000005);
public static SystemProgramId Usb => new SystemProgramId(0x0100000000000006);
public static SystemProgramId Tma => new SystemProgramId(0x0100000000000007);
public static SystemProgramId Boot2 => new SystemProgramId(0x0100000000000008);
public static SystemProgramId Settings => new SystemProgramId(0x0100000000000009);
public static SystemProgramId Bus => new SystemProgramId(0x010000000000000A);
public static SystemProgramId Bluetooth => new SystemProgramId(0x010000000000000B);
public static SystemProgramId Bcat => new SystemProgramId(0x010000000000000C);
public static SystemProgramId Dmnt => new SystemProgramId(0x010000000000000D);
public static SystemProgramId Friends => new SystemProgramId(0x010000000000000E);
public static SystemProgramId Nifm => new SystemProgramId(0x010000000000000F);
public static SystemProgramId Ptm => new SystemProgramId(0x0100000000000010);
public static SystemProgramId Shell => new SystemProgramId(0x0100000000000011);
public static SystemProgramId BsdSockets => new SystemProgramId(0x0100000000000012);
public static SystemProgramId Hid => new SystemProgramId(0x0100000000000013);
public static SystemProgramId Audio => new SystemProgramId(0x0100000000000014);
public static SystemProgramId LogManager => new SystemProgramId(0x0100000000000015);
public static SystemProgramId Wlan => new SystemProgramId(0x0100000000000016);
public static SystemProgramId Cs => new SystemProgramId(0x0100000000000017);
public static SystemProgramId Ldn => new SystemProgramId(0x0100000000000018);
public static SystemProgramId NvServices => new SystemProgramId(0x0100000000000019);
public static SystemProgramId Pcv => new SystemProgramId(0x010000000000001A);
public static SystemProgramId Ppc => new SystemProgramId(0x010000000000001B);
public static SystemProgramId NvnFlinger => new SystemProgramId(0x010000000000001C);
public static SystemProgramId Pcie => new SystemProgramId(0x010000000000001D);
public static SystemProgramId Account => new SystemProgramId(0x010000000000001E);
public static SystemProgramId Ns => new SystemProgramId(0x010000000000001F);
public static SystemProgramId Nfc => new SystemProgramId(0x0100000000000020);
public static SystemProgramId Psc => new SystemProgramId(0x0100000000000021);
public static SystemProgramId CapSrv => new SystemProgramId(0x0100000000000022);
public static SystemProgramId Am => new SystemProgramId(0x0100000000000023);
public static SystemProgramId Ssl => new SystemProgramId(0x0100000000000024);
public static SystemProgramId Nim => new SystemProgramId(0x0100000000000025);
public static SystemProgramId Cec => new SystemProgramId(0x0100000000000026);
public static SystemProgramId Tspm => new SystemProgramId(0x0100000000000027);
public static SystemProgramId Spl => new SystemProgramId(0x0100000000000028);
public static SystemProgramId Lbl => new SystemProgramId(0x0100000000000029);
public static SystemProgramId Btm => new SystemProgramId(0x010000000000002A);
public static SystemProgramId Erpt => new SystemProgramId(0x010000000000002B);
public static SystemProgramId Time => new SystemProgramId(0x010000000000002C);
public static SystemProgramId Vi => new SystemProgramId(0x010000000000002D);
public static SystemProgramId Pctl => new SystemProgramId(0x010000000000002E);
public static SystemProgramId Npns => new SystemProgramId(0x010000000000002F);
public static SystemProgramId Eupld => new SystemProgramId(0x0100000000000030);
public static SystemProgramId Arp => new SystemProgramId(0x0100000000000031);
public static SystemProgramId Glue => new SystemProgramId(0x0100000000000031);
public static SystemProgramId Eclct => new SystemProgramId(0x0100000000000032);
public static SystemProgramId Es => new SystemProgramId(0x0100000000000033);
public static SystemProgramId Fatal => new SystemProgramId(0x0100000000000034);
public static SystemProgramId Grc => new SystemProgramId(0x0100000000000035);
public static SystemProgramId Creport => new SystemProgramId(0x0100000000000036);
public static SystemProgramId Ro => new SystemProgramId(0x0100000000000037);
public static SystemProgramId Profiler => new SystemProgramId(0x0100000000000038);
public static SystemProgramId Sdb => new SystemProgramId(0x0100000000000039);
public static SystemProgramId Migration => new SystemProgramId(0x010000000000003A);
public static SystemProgramId Jit => new SystemProgramId(0x010000000000003B);
public static SystemProgramId JpegDec => new SystemProgramId(0x010000000000003C);
public static SystemProgramId SafeMode => new SystemProgramId(0x010000000000003D);
public static SystemProgramId Olsc => new SystemProgramId(0x010000000000003E);
public static SystemProgramId Dt => new SystemProgramId(0x010000000000003F);
public static SystemProgramId Nd => new SystemProgramId(0x0100000000000040);
public static SystemProgramId Ngct => new SystemProgramId(0x0100000000000041);
public static SystemProgramId Pgl => new SystemProgramId(0x0100000000000042);
public static SystemProgramId End => new SystemProgramId(0x01000000000007FF);
}
public readonly struct SystemDataId
{
public readonly ulong Value;
public SystemDataId(ulong value)
{
Value = value;
}
public static implicit operator DataId(SystemDataId id) => new DataId(id.Value);
public static bool IsSystemDataId(DataId dataId)
{
return Start <= dataId && dataId <= End;
}
public static bool IsSystemDataId(SystemDataId id) => true;
public static SystemDataId Start => new SystemDataId(0x0100000000000800);
public static SystemDataId CertStore => new SystemDataId(0x0100000000000800);
public static SystemDataId ErrorMessage => new SystemDataId(0x0100000000000801);
public static SystemDataId MiiModel => new SystemDataId(0x0100000000000802);
public static SystemDataId BrowserDll => new SystemDataId(0x0100000000000803);
public static SystemDataId Help => new SystemDataId(0x0100000000000804);
public static SystemDataId SharedFont => new SystemDataId(0x0100000000000805);
public static SystemDataId NgWord => new SystemDataId(0x0100000000000806);
public static SystemDataId SsidList => new SystemDataId(0x0100000000000807);
public static SystemDataId Dictionary => new SystemDataId(0x0100000000000808);
public static SystemDataId SystemVersion => new SystemDataId(0x0100000000000809);
public static SystemDataId AvatarImage => new SystemDataId(0x010000000000080A);
public static SystemDataId LocalNews => new SystemDataId(0x010000000000080B);
public static SystemDataId Eula => new SystemDataId(0x010000000000080C);
public static SystemDataId UrlBlackList => new SystemDataId(0x010000000000080D);
public static SystemDataId TimeZoneBinar => new SystemDataId(0x010000000000080E);
public static SystemDataId CertStoreCruiser => new SystemDataId(0x010000000000080F);
public static SystemDataId FontNintendoExtension => new SystemDataId(0x0100000000000810);
public static SystemDataId FontStandard => new SystemDataId(0x0100000000000811);
public static SystemDataId FontKorean => new SystemDataId(0x0100000000000812);
public static SystemDataId FontChineseTraditional => new SystemDataId(0x0100000000000813);
public static SystemDataId FontChineseSimple => new SystemDataId(0x0100000000000814);
public static SystemDataId FontBfcpx => new SystemDataId(0x0100000000000815);
public static SystemDataId SystemUpdate => new SystemDataId(0x0100000000000816);
public static SystemDataId FirmwareDebugSettings => new SystemDataId(0x0100000000000818);
public static SystemDataId BootImagePackage => new SystemDataId(0x0100000000000819);
public static SystemDataId BootImagePackageSafe => new SystemDataId(0x010000000000081A);
public static SystemDataId BootImagePackageExFat => new SystemDataId(0x010000000000081B);
public static SystemDataId BootImagePackageExFatSafe => new SystemDataId(0x010000000000081C);
public static SystemDataId FatalMessage => new SystemDataId(0x010000000000081D);
public static SystemDataId ControllerIcon => new SystemDataId(0x010000000000081E);
public static SystemDataId PlatformConfigIcosa => new SystemDataId(0x010000000000081F);
public static SystemDataId PlatformConfigCopper => new SystemDataId(0x0100000000000820);
public static SystemDataId PlatformConfigHoag => new SystemDataId(0x0100000000000821);
public static SystemDataId ControllerFirmware => new SystemDataId(0x0100000000000822);
public static SystemDataId NgWord2 => new SystemDataId(0x0100000000000823);
public static SystemDataId PlatformConfigIcosaMariko => new SystemDataId(0x0100000000000824);
public static SystemDataId ApplicationBlackList => new SystemDataId(0x0100000000000825);
public static SystemDataId RebootlessSystemUpdateVersion => new SystemDataId(0x0100000000000826);
public static SystemDataId ContentActionTable => new SystemDataId(0x0100000000000827);
public static SystemDataId End => new SystemDataId(0x0100000000000FFF);
}
public readonly struct SystemUpdateId
{
public readonly ulong Value;
public SystemUpdateId(ulong value)
{
Value = value;
}
public static implicit operator DataId(SystemUpdateId id) => new DataId(id.Value);
}
public readonly struct SystemAppletId
{
public readonly ulong Value;
public SystemAppletId(ulong value)
{
Value = value;
}
public static implicit operator ProgramId(SystemAppletId id) => new ProgramId(id.Value);
public static bool IsSystemAppletId(ProgramId programId)
{
return Start <= programId && programId <= End;
}
public static bool IsSystemAppletId(SystemAppletId id) => true;
public static SystemAppletId Start => new SystemAppletId(0x0100000000001000);
public static SystemAppletId Qlaunch => new SystemAppletId(0x0100000000001000);
public static SystemAppletId Auth => new SystemAppletId(0x0100000000001001);
public static SystemAppletId Cabinet => new SystemAppletId(0x0100000000001002);
public static SystemAppletId Controller => new SystemAppletId(0x0100000000001003);
public static SystemAppletId DataErase => new SystemAppletId(0x0100000000001004);
public static SystemAppletId Error => new SystemAppletId(0x0100000000001005);
public static SystemAppletId NetConnect => new SystemAppletId(0x0100000000001006);
public static SystemAppletId PlayerSelect => new SystemAppletId(0x0100000000001007);
public static SystemAppletId Swkbd => new SystemAppletId(0x0100000000001008);
public static SystemAppletId MiiEdit => new SystemAppletId(0x0100000000001009);
public static SystemAppletId Web => new SystemAppletId(0x010000000000100A);
public static SystemAppletId Shop => new SystemAppletId(0x010000000000100B);
public static SystemAppletId OverlayDisp => new SystemAppletId(0x010000000000100C);
public static SystemAppletId PhotoViewer => new SystemAppletId(0x010000000000100D);
public static SystemAppletId Set => new SystemAppletId(0x010000000000100E);
public static SystemAppletId OfflineWeb => new SystemAppletId(0x010000000000100F);
public static SystemAppletId LoginShare => new SystemAppletId(0x0100000000001010);
public static SystemAppletId WifiWebAuth => new SystemAppletId(0x0100000000001011);
public static SystemAppletId Starter => new SystemAppletId(0x0100000000001012);
public static SystemAppletId MyPage => new SystemAppletId(0x0100000000001013);
public static SystemAppletId PlayReport => new SystemAppletId(0x0100000000001014);
public static SystemAppletId MaintenanceMenu => new SystemAppletId(0x0100000000001015);
public static SystemAppletId Gift => new SystemAppletId(0x010000000000101A);
public static SystemAppletId DummyShop => new SystemAppletId(0x010000000000101B);
public static SystemAppletId UserMigration => new SystemAppletId(0x010000000000101C);
public static SystemAppletId Encounter => new SystemAppletId(0x010000000000101D);
public static SystemAppletId Story => new SystemAppletId(0x0100000000001020);
public static SystemAppletId End => new SystemAppletId(0x0100000000001FFF);
}
public readonly struct SystemDebugAppletId
{
public readonly ulong Value;
public SystemDebugAppletId(ulong value)
{
Value = value;
}
public static implicit operator ProgramId(SystemDebugAppletId id) => new ProgramId(id.Value);
public static bool IsSystemDebugAppletId(ProgramId programId)
{
return Start <= programId && programId <= End;
}
public static bool IsSystemDebugAppletId(SystemDebugAppletId id) => true;
public static SystemDebugAppletId Start => new SystemDebugAppletId(0x0100000000002000);
public static SystemDebugAppletId SnapShotDumper => new SystemDebugAppletId(0x0100000000002071);
public static SystemDebugAppletId End => new SystemDebugAppletId(0x0100000000002FFF);
}
public readonly struct LibraryAppletId
{
public readonly ulong Value;
public LibraryAppletId(ulong value)
{
Value = value;
}
public static implicit operator SystemAppletId(LibraryAppletId id) => new SystemAppletId(id.Value);
public static implicit operator ProgramId(LibraryAppletId id) => new ProgramId(id.Value);
public static bool IsLibraryAppletId(ProgramId programId)
{
return programId == Auth ||
programId == Controller ||
programId == Error ||
programId == PlayerSelect ||
programId == Swkbd ||
programId == Web ||
programId == Shop ||
programId == PhotoViewer ||
programId == OfflineWeb ||
programId == LoginShare ||
programId == WifiWebAuth ||
programId == MyPage;
}
public static bool IsLibraryAppletId(LibraryAppletId id) => true;
public static LibraryAppletId Auth => new LibraryAppletId(SystemAppletId.Auth.Value);
public static LibraryAppletId Controller => new LibraryAppletId(SystemAppletId.Controller.Value);
public static LibraryAppletId Error => new LibraryAppletId(SystemAppletId.Error.Value);
public static LibraryAppletId PlayerSelect => new LibraryAppletId(SystemAppletId.PlayerSelect.Value);
public static LibraryAppletId Swkbd => new LibraryAppletId(SystemAppletId.Swkbd.Value);
public static LibraryAppletId Web => new LibraryAppletId(SystemAppletId.Web.Value);
public static LibraryAppletId Shop => new LibraryAppletId(SystemAppletId.Shop.Value);
public static LibraryAppletId PhotoViewer => new LibraryAppletId(SystemAppletId.PhotoViewer.Value);
public static LibraryAppletId OfflineWeb => new LibraryAppletId(SystemAppletId.OfflineWeb.Value);
public static LibraryAppletId LoginShare => new LibraryAppletId(SystemAppletId.LoginShare.Value);
public static LibraryAppletId WifiWebAuth => new LibraryAppletId(SystemAppletId.WifiWebAuth.Value);
public static LibraryAppletId MyPage => new LibraryAppletId(SystemAppletId.MyPage.Value);
}
public readonly struct WebAppletId
{
public readonly ulong Value;
public WebAppletId(ulong value)
{
Value = value;
}
public static implicit operator LibraryAppletId(WebAppletId id) => new LibraryAppletId(id.Value);
public static implicit operator SystemAppletId(WebAppletId id) => new SystemAppletId(id.Value);
public static implicit operator ProgramId(WebAppletId id) => new ProgramId(id.Value);
public static bool IsWebAppletId(ProgramId programId)
{
return programId == Web ||
programId == Shop ||
programId == OfflineWeb ||
programId == LoginShare ||
programId == WifiWebAuth;
}
public static bool IsWebAppletId(WebAppletId id) => true;
public static WebAppletId Web => new WebAppletId(LibraryAppletId.Web.Value);
public static WebAppletId Shop => new WebAppletId(LibraryAppletId.Shop.Value);
public static WebAppletId OfflineWeb => new WebAppletId(LibraryAppletId.OfflineWeb.Value);
public static WebAppletId LoginShare => new WebAppletId(LibraryAppletId.LoginShare.Value);
public static WebAppletId WifiWebAuth => new WebAppletId(LibraryAppletId.WifiWebAuth.Value);
}
public readonly struct SystemApplicationId
{
public readonly ulong Value;
public SystemApplicationId(ulong value)
{
Value = value;
}
public static implicit operator ProgramId(SystemApplicationId id) => new ProgramId(id.Value);
}
}

View File

@ -1,35 +0,0 @@
using System;
using System.Diagnostics;
namespace LibHac.Ncm
{
[DebuggerDisplay("{" + nameof(Value) + "}")]
public struct TitleId : IEquatable<TitleId>, IComparable<TitleId>, IComparable
{
public static TitleId Zero => default;
public readonly ulong Value;
public TitleId(ulong value)
{
Value = value;
}
public static explicit operator ulong(TitleId titleId) => titleId.Value;
public override string ToString() => $"{Value:X16}";
public int CompareTo(object obj)
{
if (ReferenceEquals(null, obj)) return 1;
return obj is TitleId other ? CompareTo(other) : throw new ArgumentException($"Object must be of type {nameof(TitleId)}");
}
public int CompareTo(TitleId other) => Value.CompareTo(other.Value);
public bool Equals(TitleId other) => Value == other.Value;
public override bool Equals(object obj) => obj is TitleId other && Equals(other);
public override int GetHashCode() => Value.GetHashCode();
public static bool operator ==(TitleId left, TitleId right) => left.Equals(right);
public static bool operator !=(TitleId left, TitleId right) => !left.Equals(right);
}
}

View File

@ -38,7 +38,7 @@ namespace LibHac.Ns
[FieldOffset(0x3040)] private sbyte _ratingAge;
[FieldOffset(0x3060)] private byte _displayVersion;
[FieldOffset(0x3070)] public ulong AddOnContentBaseId;
[FieldOffset(0x3078)] public TitleId SaveDataOwnerId;
[FieldOffset(0x3078)] public ProgramId SaveDataOwnerId;
[FieldOffset(0x3080)] public long UserAccountSaveDataSize;
[FieldOffset(0x3088)] public long UserAccountSaveDataJournalSize;
[FieldOffset(0x3090)] public long DeviceSaveDataSize;

View File

@ -1,7 +1,6 @@
using LibHac.Account;
using LibHac.Fs;
using LibHac.Fs.Shim;
using LibHac.Ncm;
using LibHac.Ns;
using Xunit;
@ -16,7 +15,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
{
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
var applicationId = new TitleId(11);
var applicationId = new Ncm.ApplicationId(11);
var userId = new Uid(2, 3);
var nacp = new ApplicationControlProperty
@ -33,7 +32,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
Assert.Success(iterator.ReadSaveDataInfo(out long entriesRead, info));
Assert.Equal(1, entriesRead);
Assert.Equal(applicationId, info[0].TitleId);
Assert.Equal(applicationId, info[0].ProgramId);
Assert.Equal(ConvertAccountUidToFsUserId(userId), info[0].UserId);
Assert.Equal(SaveDataType.Account, info[0].Type);
}
@ -43,7 +42,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
{
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
var applicationId = new TitleId(11);
var applicationId = new Ncm.ApplicationId(11);
var userId = new Uid(2, 3);
var nacp = new ApplicationControlProperty
@ -60,7 +59,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
Assert.Success(iterator.ReadSaveDataInfo(out long entriesRead, info));
Assert.Equal(1, entriesRead);
Assert.Equal(applicationId, info[0].TitleId);
Assert.Equal(applicationId, info[0].ProgramId);
Assert.Equal(UserId.Zero, info[0].UserId);
Assert.Equal(SaveDataType.Device, info[0].Type);
}
@ -70,7 +69,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
{
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
var applicationId = new TitleId(11);
var applicationId = new Ncm.ApplicationId(11);
var userId = new Uid(2, 3);
var nacp = new ApplicationControlProperty
@ -86,7 +85,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
Assert.Success(iterator.ReadSaveDataInfo(out long entriesRead, info));
Assert.Equal(1, entriesRead);
Assert.Equal(applicationId, info[0].TitleId);
Assert.Equal(applicationId, info[0].ProgramId);
Assert.Equal(UserId.Zero, info[0].UserId);
Assert.Equal(SaveDataType.Bcat, info[0].Type);
}
@ -96,7 +95,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
{
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
var applicationId = new TitleId(11);
var applicationId = new Ncm.ApplicationId(11);
var userId = new Uid(2, 3);
var nacp = new ApplicationControlProperty
@ -112,7 +111,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
Assert.Success(iterator.ReadSaveDataInfo(out long entriesRead, info));
Assert.Equal(1, entriesRead);
Assert.Equal(applicationId, info[0].TitleId);
Assert.Equal(applicationId, info[0].ProgramId);
Assert.Equal(UserId.Zero, info[0].UserId);
Assert.Equal(SaveDataType.Temporary, info[0].Type);
}
@ -122,7 +121,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
{
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
var applicationId = new TitleId(11);
var applicationId = new Ncm.ApplicationId(11);
var nacp = new ApplicationControlProperty
{
@ -141,7 +140,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
Assert.Success(iterator.ReadSaveDataInfo(out long entriesRead, info));
Assert.Equal(1, entriesRead);
Assert.Equal(applicationId, info[0].TitleId);
Assert.Equal(applicationId, info[0].ProgramId);
Assert.Equal(SaveDataType.Cache, info[0].Type);
}
@ -150,7 +149,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
{
FileSystemClient fs = FileSystemServerFactory.CreateClient(false);
var applicationId = new TitleId(11);
var applicationId = new Ncm.ApplicationId(11);
var nacp = new ApplicationControlProperty
{
@ -169,7 +168,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
Assert.Success(iterator.ReadSaveDataInfo(out long entriesRead, info));
Assert.Equal(1, entriesRead);
Assert.Equal(applicationId, info[0].TitleId);
Assert.Equal(applicationId, info[0].ProgramId);
Assert.Equal(SaveDataType.Cache, info[0].Type);
}
@ -180,7 +179,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
{
FileSystemClient fs = FileSystemServerFactory.CreateClient(isSdCardInserted);
var applicationId = new TitleId(11);
var applicationId = new Ncm.ApplicationId(11);
var nacp = new ApplicationControlProperty
{
@ -199,7 +198,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests
{
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.GetCacheStorageTargetMedia(out CacheStorageTargetMedia target, new TitleId(11)));
Assert.Success(fs.GetCacheStorageTargetMedia(out CacheStorageTargetMedia target, new Ncm.ApplicationId(11)));
Assert.Equal(CacheStorageTargetMedia.None, target);
}
}

View File

@ -1,7 +1,6 @@
using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Shim;
using LibHac.Ncm;
using Xunit;
namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
@ -11,7 +10,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
[Fact]
public void MountBcatSaveData_SaveDoesNotExist_ReturnsTargetNotFound()
{
var applicationId = new TitleId(1);
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Result(ResultFs.TargetNotFound, fs.MountBcatSaveData("bcat_test".ToU8Span(), applicationId));
@ -20,7 +19,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
[Fact]
public void MountBcatSaveData_SaveExists_ReturnsSuccess()
{
var applicationId = new TitleId(1);
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateBcatSaveData(applicationId, 0x400000));
@ -30,7 +29,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
[Fact]
public void MountBcatSaveData_WrittenDataPersists()
{
var applicationId = new TitleId(1);
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateBcatSaveData(applicationId, 0x400000));

View File

@ -1,7 +1,6 @@
using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Shim;
using LibHac.Ncm;
using Xunit;
namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
@ -11,10 +10,10 @@ namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
[Fact]
public void MountCacheStorage_CanMountCreatedCacheStorage()
{
var applicationId = new TitleId(1);
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId, 0, 0, SaveDataFlags.None);
fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, SaveDataFlags.None);
Assert.Success(fs.MountCacheStorage("cache".ToU8Span(), applicationId));
}
@ -22,10 +21,10 @@ namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
[Fact]
public void MountCacheStorage_WrittenDataPersists()
{
var applicationId = new TitleId(1);
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId, 0, 0, SaveDataFlags.None);
fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None);
fs.MountCacheStorage("cache".ToU8Span(), applicationId);
fs.CreateFile("cache:/file".ToU8Span(), 0);
@ -40,10 +39,10 @@ namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
[Fact]
public void MountCacheStorage_SdCardIsPreferredOverBis()
{
var applicationId = new TitleId(1);
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId, 0, 0, SaveDataFlags.None);
fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None);
fs.MountCacheStorage("cache".ToU8Span(), applicationId);
fs.CreateFile("cache:/sd".ToU8Span(), 0);
fs.Commit("cache".ToU8Span());
@ -52,7 +51,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
// Turn off the SD card so the User save is mounted
fs.SetSdCardAccessibility(false);
fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId, 0, 0, SaveDataFlags.None);
fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, SaveDataFlags.None);
fs.MountCacheStorage("cache".ToU8Span(), applicationId);
fs.CreateFile("cache:/bis".ToU8Span(), 0);
fs.Commit("cache".ToU8Span());

View File

@ -1,7 +1,6 @@
using System.Linq;
using LibHac.Fs;
using LibHac.Fs.Shim;
using LibHac.Ncm;
using Xunit;
namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
@ -11,10 +10,10 @@ namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
[Fact]
public void CreateCacheStorage_InUserSaveSpace_StorageIsCreated()
{
var applicationId = new TitleId(1);
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId, 0, 0, SaveDataFlags.None));
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, SaveDataFlags.None));
fs.OpenSaveDataIterator(out SaveDataIterator iterator, SaveDataSpaceId.User);
@ -22,16 +21,16 @@ namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
iterator.ReadSaveDataInfo(out long entriesRead, info);
Assert.Equal(1, entriesRead);
Assert.Equal(applicationId, info[0].TitleId);
Assert.Equal(applicationId, info[0].ProgramId);
}
[Fact]
public void CreateCacheStorage_InSdCacheSaveSpace_StorageIsCreated()
{
var applicationId = new TitleId(1);
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId, 0, 0, SaveDataFlags.None));
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None));
fs.OpenSaveDataIterator(out SaveDataIterator iterator, SaveDataSpaceId.SdCache);
@ -39,36 +38,36 @@ namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
iterator.ReadSaveDataInfo(out long entriesRead, info);
Assert.Equal(1, entriesRead);
Assert.Equal(applicationId, info[0].TitleId);
Assert.Equal(applicationId, info[0].ProgramId);
}
[Fact]
public void CreateCacheStorage_InSdCacheSaveSpaceWhenNoSdCard_ReturnsSdCardNotFound()
{
var applicationId = new TitleId(1);
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(false);
Assert.Result(ResultFs.SdCardNotFound, fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId, 0, 0, SaveDataFlags.None));
Assert.Result(ResultFs.SdCardNotFound, fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None));
}
[Fact]
public void CreateCacheStorage_AlreadyExists_ReturnsPathAlreadyExists()
{
var applicationId = new TitleId(1);
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId, 0, 0, SaveDataFlags.None));
Assert.Result(ResultFs.PathAlreadyExists, fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId, 0, 0, SaveDataFlags.None));
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, SaveDataFlags.None));
Assert.Result(ResultFs.PathAlreadyExists, fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, SaveDataFlags.None));
}
[Fact]
public void CreateCacheStorage_WithIndex_CreatesMultiple()
{
var applicationId = new TitleId(1);
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId, 0, 0, 0, SaveDataFlags.None));
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId, 1, 0, 0, SaveDataFlags.None));
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, 0, SaveDataFlags.None));
Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 1, 0, 0, SaveDataFlags.None));
fs.OpenSaveDataIterator(out SaveDataIterator iterator, SaveDataSpaceId.User);
@ -76,8 +75,8 @@ namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
iterator.ReadSaveDataInfo(out long entriesRead, info);
Assert.Equal(2, entriesRead);
Assert.Equal(applicationId, info[0].TitleId);
Assert.Equal(applicationId, info[1].TitleId);
Assert.Equal(applicationId, info[0].ProgramId);
Assert.Equal(applicationId, info[1].ProgramId);
var expectedIndexes = new short[] { 0, 1 };
short[] actualIndexes = info.Take(2).Select(x => x.Index).OrderBy(x => x).ToArray();
@ -88,7 +87,7 @@ namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
[Fact]
public void CreateBcatSaveData_DoesNotExist_SaveIsCreated()
{
var applicationId = new TitleId(1);
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateBcatSaveData(applicationId, 0x400000));
@ -99,14 +98,14 @@ namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests
iterator.ReadSaveDataInfo(out long entriesRead, info);
Assert.Equal(1, entriesRead);
Assert.Equal(applicationId, info[0].TitleId);
Assert.Equal(applicationId, info[0].ProgramId);
Assert.Equal(SaveDataType.Bcat, info[0].Type);
}
[Fact]
public void CreateBcatSaveData_AlreadyExists_ReturnsPathAlreadyExists()
{
var applicationId = new TitleId(1);
var applicationId = new Ncm.ApplicationId(1);
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
Assert.Success(fs.CreateBcatSaveData(applicationId, 0x400000));