Update FS enum and structure names

The new names should be all or mostly all official
This commit is contained in:
Alex Barney 2019-12-06 22:33:24 -06:00
parent 89d70757a3
commit ba2a923296
19 changed files with 170 additions and 256 deletions

View File

@ -1,7 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using LibHac.Account;
using LibHac.Fs.Shim;
using LibHac.FsSystem.Save;
using LibHac.Ncm;
using LibHac.Ns;
@ -20,7 +19,7 @@ namespace LibHac.Fs
{
var filter = new SaveDataFilter();
filter.SetTitleId(applicationId);
filter.SetSaveDataType(SaveDataType.SaveData);
filter.SetSaveDataType(SaveDataType.Account);
filter.SetUserId(new UserId(uid.Id.High, uid.Id.Low));
Result rc = fs.FindSaveDataWithFilter(out SaveDataInfo saveDataInfo, SaveDataSpaceId.User, ref filter);
@ -74,7 +73,7 @@ namespace LibHac.Fs
{
var filter = new SaveDataFilter();
filter.SetTitleId(applicationId);
filter.SetSaveDataType(SaveDataType.DeviceSaveData);
filter.SetSaveDataType(SaveDataType.Device);
Result rc = fs.FindSaveDataWithFilter(out SaveDataInfo saveDataInfo, SaveDataSpaceId.User, ref filter);
@ -142,7 +141,7 @@ namespace LibHac.Fs
{
var filter = new SaveDataFilter();
filter.SetTitleId(applicationId);
filter.SetSaveDataType(SaveDataType.TemporaryStorage);
filter.SetSaveDataType(SaveDataType.Temporary);
Result rc = fs.FindSaveDataWithFilter(out _, SaveDataSpaceId.User, ref filter);
@ -213,7 +212,7 @@ namespace LibHac.Fs
var filter = new SaveDataFilter();
filter.SetTitleId(applicationId);
filter.SetSaveDataType(SaveDataType.BcatDeliveryCacheStorage);
filter.SetSaveDataType(SaveDataType.Bcat);
Result rc = fs.FindSaveDataWithFilter(out SaveDataInfo saveDataInfo, SaveDataSpaceId.User, ref filter);

View File

@ -20,7 +20,7 @@ namespace LibHac.Fs
System = 31,
SystemProperEncryption = 32,
SystemProperPartition = 33,
Invalid = 35
SignedSystemPartitionOnSafeMode = 34
}
public enum ContentStorageId
@ -40,9 +40,9 @@ namespace LibHac.Fs
public enum GameCardPartitionRaw
{
Normal = 0,
Secure = 1,
Writable = 2
NormalReadOnly = 0,
SecureReadOnly = 1,
RootWriteOnly = 2
}
public enum SaveDataSpaceId : byte
@ -50,16 +50,16 @@ namespace LibHac.Fs
System = 0,
User = 1,
SdSystem = 2,
TemporaryStorage = 3,
Temporary = 3,
SdCache = 4,
ProperSystem = 100,
Safe = 101,
SafeMode = 101,
BisAuto = 127
}
public enum CustomStorageId
{
User = 0,
System = 0,
SdCard = 1
}
@ -69,27 +69,27 @@ namespace LibHac.Fs
Control = 1,
Manual = 2,
Logo = 3,
Data = 4,
Data = 4
}
public enum FileSystemProxyType
{
Code = 0,
Data = 1,
Rom = 1,
Logo = 2,
ContentControl = 3,
ContentManual = 4,
ContentMeta = 5,
ContentData = 6,
ApplicationPackage = 7,
Control = 3,
Manual = 4,
Meta = 5,
Data = 6,
Package = 7,
RegisteredUpdate = 8
}
public enum SaveMetaType : byte
public enum SaveDataMetaType : byte
{
None = 0,
Thumbnail = 1,
ExtensionInfo = 2
ExtensionContext = 2
}
public enum SaveDataState : byte
@ -98,7 +98,7 @@ namespace LibHac.Fs
Creating = 1,
State2 = 2,
MarkedForDeletion = 3,
Extending = 4,
Extending = 4
}
public enum ImageDirectoryId
@ -146,4 +146,31 @@ namespace LibHac.Fs
InvalidateCache = 2,
QueryRange = 3
}
public enum SaveDataType : byte
{
System = 0,
Account = 1,
Bcat = 2,
Device = 3,
Temporary = 4,
Cache = 5,
SystemBcat = 6
}
public enum SaveDataRank : byte
{
Primary = 0,
Secondary = 1
}
[Flags]
public enum SaveDataFlags
{
None = 0,
KeepAfterResettingSystemSaveData = 1 << 0,
KeepAfterRefurbishment = 1 << 1,
KeepAfterResettingSystemSaveDataWithoutUserSaveData = 1 << 2,
NeedsSecureDelete = 1 << 3
}
}

View File

@ -4,20 +4,16 @@ namespace LibHac.Fs
{
public static class GameCard
{
public static long GetGameCardSizeBytes(GameCardSize size)
public static long GetGameCardSizeBytes(GameCardSizeInternal size) => size switch
{
switch (size)
{
case GameCardSize.Size1Gb: return 0x3B800000;
case GameCardSize.Size2Gb: return 0x77000000;
case GameCardSize.Size4Gb: return 0xEE000000;
case GameCardSize.Size8Gb: return 0x1DC000000;
case GameCardSize.Size16Gb: return 0x3B8000000;
case GameCardSize.Size32Gb: return 0x770000000;
default:
throw new ArgumentOutOfRangeException(nameof(size), size, null);
}
}
GameCardSizeInternal.Size1Gb => 0x3B800000,
GameCardSizeInternal.Size2Gb => 0x77000000,
GameCardSizeInternal.Size4Gb => 0xEE000000,
GameCardSizeInternal.Size8Gb => 0x1DC000000,
GameCardSizeInternal.Size16Gb => 0x3B8000000,
GameCardSizeInternal.Size32Gb => 0x770000000,
_ => 0
};
public static long CardPageToOffset(int page)
{
@ -25,7 +21,7 @@ namespace LibHac.Fs
}
}
public enum GameCardSize
public enum GameCardSizeInternal : byte
{
Size1Gb = 0xFA,
Size2Gb = 0xF8,
@ -38,8 +34,11 @@ namespace LibHac.Fs
[Flags]
public enum GameCardAttribute : byte
{
AutoBoot = 1 << 0,
HistoryErase = 1 << 1,
RepairTool = 1 << 2
None = 0,
AutoBootFlag = 1 << 0,
HistoryEraseFlag = 1 << 1,
RepairToolFlag = 1 << 2,
DifferentRegionCupToTerraDeviceFlag = 1 << 3,
DifferentRegionCupToGlobalDeviceFlag = 1 << 4
}
}

View File

@ -1,95 +0,0 @@
using System;
using System.Buffers.Binary;
using LibHac.FsSystem.Save;
using LibHac.Kvdb;
namespace LibHac.Fs
{
public class SaveDataAttributeKvdb : IComparable<SaveDataAttributeKvdb>, IComparable, IEquatable<SaveDataAttributeKvdb>, IExportable
{
public ulong TitleId { get; private set; }
public UserId UserId { get; private set; }
public ulong SaveId { get; private set; }
public SaveDataType Type { get; private set; }
public byte Rank { get; private set; }
public short Index { get; private set; }
public int ExportSize => 0x40;
private bool _isFrozen;
public void ToBytes(Span<byte> output)
{
if (output.Length < ExportSize) throw new InvalidOperationException("Output buffer is too small.");
BinaryPrimitives.WriteUInt64LittleEndian(output, TitleId);
UserId.ToBytes(output.Slice(8));
BinaryPrimitives.WriteUInt64LittleEndian(output.Slice(0x18), SaveId);
output[0x20] = (byte)Type;
output[0x21] = Rank;
BinaryPrimitives.WriteInt16LittleEndian(output.Slice(0x22), Index);
}
public void FromBytes(ReadOnlySpan<byte> input)
{
if (_isFrozen) throw new InvalidOperationException("Unable to modify frozen object.");
if (input.Length < ExportSize) throw new InvalidOperationException("Input data is too short.");
TitleId = BinaryPrimitives.ReadUInt64LittleEndian(input);
UserId = new UserId(input.Slice(8));
SaveId = BinaryPrimitives.ReadUInt64LittleEndian(input.Slice(0x18));
Type = (SaveDataType)input[0x20];
Rank = input[0x21];
Index = BinaryPrimitives.ReadInt16LittleEndian(input.Slice(0x22));
}
public void Freeze() => _isFrozen = true;
public bool Equals(SaveDataAttributeKvdb other)
{
return other != null && TitleId == other.TitleId && UserId.Equals(other.UserId) && SaveId == other.SaveId &&
Type == other.Type && Rank == other.Rank && Index == other.Index;
}
public override bool Equals(object obj)
{
return obj is SaveDataAttributeKvdb other && Equals(other);
}
public override int GetHashCode()
{
unchecked
{
// ReSharper disable NonReadonlyMemberInGetHashCode
int hashCode = TitleId.GetHashCode();
hashCode = (hashCode * 397) ^ UserId.GetHashCode();
hashCode = (hashCode * 397) ^ SaveId.GetHashCode();
hashCode = (hashCode * 397) ^ (int)Type;
hashCode = (hashCode * 397) ^ Rank.GetHashCode();
hashCode = (hashCode * 397) ^ Index.GetHashCode();
return hashCode;
// ReSharper restore NonReadonlyMemberInGetHashCode
}
}
public int CompareTo(SaveDataAttributeKvdb other)
{
int titleIdComparison = TitleId.CompareTo(other.TitleId);
if (titleIdComparison != 0) return titleIdComparison;
int typeComparison = Type.CompareTo(other.Type);
if (typeComparison != 0) return typeComparison;
int userIdComparison = UserId.CompareTo(other.UserId);
if (userIdComparison != 0) return userIdComparison;
int saveIdComparison = SaveId.CompareTo(other.SaveId);
if (saveIdComparison != 0) return saveIdComparison;
int rankComparison = Rank.CompareTo(other.Rank);
if (rankComparison != 0) return rankComparison;
return Index.CompareTo(other.Index);
}
public int CompareTo(object obj)
{
if (obj is null) return 1;
return obj is SaveDataAttributeKvdb other ? CompareTo(other) : throw new ArgumentException($"Object must be of type {nameof(SaveDataAttributeKvdb)}");
}
}
}

View File

@ -1,7 +1,6 @@
using System;
using System.Runtime.InteropServices;
using LibHac.Common;
using LibHac.FsSystem.Save;
using LibHac.Ncm;
namespace LibHac.Fs
@ -13,7 +12,7 @@ namespace LibHac.Fs
[FieldOffset(0x08)] public UserId UserId;
[FieldOffset(0x18)] public ulong SaveDataId;
[FieldOffset(0x20)] public SaveDataType Type;
[FieldOffset(0x21)] public byte Rank;
[FieldOffset(0x21)] public SaveDataRank Rank;
[FieldOffset(0x22)] public short Index;
public override bool Equals(object obj)
@ -69,7 +68,7 @@ namespace LibHac.Fs
[FieldOffset(0x02)] public bool FilterByUserId;
[FieldOffset(0x03)] public bool FilterBySaveDataId;
[FieldOffset(0x04)] public bool FilterByIndex;
[FieldOffset(0x05)] public byte Rank;
[FieldOffset(0x05)] public SaveDataRank Rank;
[FieldOffset(0x08)] public TitleId TitleId;
[FieldOffset(0x10)] public UserId UserId;
@ -129,17 +128,17 @@ namespace LibHac.Fs
public struct SaveMetaCreateInfo
{
[FieldOffset(0)] public int Size;
[FieldOffset(4)] public SaveMetaType Type;
[FieldOffset(4)] public SaveDataMetaType Type;
}
[StructLayout(LayoutKind.Explicit, Size = 0x40)]
public struct SaveDataCreateInfo
public struct SaveDataCreationInfo
{
[FieldOffset(0x00)] public long Size;
[FieldOffset(0x08)] public long JournalSize;
[FieldOffset(0x10)] public ulong BlockSize;
[FieldOffset(0x18)] public TitleId OwnerId;
[FieldOffset(0x20)] public uint Flags;
[FieldOffset(0x20)] public SaveDataFlags Flags;
[FieldOffset(0x24)] public SaveDataSpaceId SpaceId;
[FieldOffset(0x25)] public bool Field25;
}
@ -155,7 +154,7 @@ namespace LibHac.Fs
[FieldOffset(0x28)] public TitleId TitleId;
[FieldOffset(0x30)] public long Size;
[FieldOffset(0x38)] public short Index;
[FieldOffset(0x3A)] public byte Rank;
[FieldOffset(0x3A)] public SaveDataRank Rank;
[FieldOffset(0x3B)] public SaveDataState State;
}
}

View File

@ -42,7 +42,7 @@ namespace LibHac.Fs.Shim
IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();
rc = fsProxy.OpenFileSystemWithId(out IFileSystem fileSystem, ref fsPath, default, FileSystemProxyType.ApplicationPackage);
rc = fsProxy.OpenFileSystemWithId(out IFileSystem fileSystem, ref fsPath, default, FileSystemProxyType.Package);
if (rc.IsFailure()) return rc;
return fs.Register(mountName, fileSystem);

View File

@ -55,10 +55,10 @@ namespace LibHac.Fs.Shim
private static FileSystemProxyType ConvertToFileSystemProxyType(ContentType type) => type switch
{
ContentType.Meta => FileSystemProxyType.ContentMeta,
ContentType.Control => FileSystemProxyType.ContentControl,
ContentType.Manual => FileSystemProxyType.ContentManual,
ContentType.Data => FileSystemProxyType.ContentData,
ContentType.Meta => FileSystemProxyType.Meta,
ContentType.Control => FileSystemProxyType.Control,
ContentType.Manual => FileSystemProxyType.Manual,
ContentType.Data => FileSystemProxyType.Data,
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
};
}

View File

@ -23,7 +23,7 @@ namespace LibHac.Fs.Shim
{
switch (storageId)
{
case CustomStorageId.User:
case CustomStorageId.System:
case CustomStorageId.SdCard:
return "CustomStorage0";
default:

View File

@ -1,7 +1,6 @@
using System;
using LibHac.Common;
using LibHac.FsService;
using LibHac.FsSystem.Save;
using LibHac.Ncm;
namespace LibHac.Fs.Shim
@ -15,14 +14,14 @@ namespace LibHac.Fs.Shim
if (fs.IsEnabledAccessLog(AccessLogTarget.Application))
{
TimeSpan startTime = fs.Time.GetCurrent();
rc = MountSaveDataImpl(fs, mountName, SaveDataSpaceId.User, titleId, userId, SaveDataType.SaveData, false, 0);
rc = MountSaveDataImpl(fs, mountName, SaveDataSpaceId.User, titleId, userId, SaveDataType.Account, false, 0);
TimeSpan endTime = fs.Time.GetCurrent();
fs.OutputAccessLog(rc, startTime, endTime, $", name: \"{mountName.ToString()}\", applicationid: 0x{titleId}, userid: 0x{userId}");
}
else
{
rc = MountSaveDataImpl(fs, mountName, SaveDataSpaceId.User, titleId, userId, SaveDataType.SaveData, false, 0);
rc = MountSaveDataImpl(fs, mountName, SaveDataSpaceId.User, titleId, userId, SaveDataType.Account, false, 0);
}
if (rc.IsSuccess() && fs.IsEnabledAccessLog(AccessLogTarget.Application))
@ -40,14 +39,14 @@ namespace LibHac.Fs.Shim
if (fs.IsEnabledAccessLog(AccessLogTarget.Application))
{
TimeSpan startTime = fs.Time.GetCurrent();
rc = MountSaveDataImpl(fs, mountName, SaveDataSpaceId.User, titleId, userId, SaveDataType.SaveData, true, 0);
rc = MountSaveDataImpl(fs, mountName, SaveDataSpaceId.User, titleId, userId, SaveDataType.Account, true, 0);
TimeSpan endTime = fs.Time.GetCurrent();
fs.OutputAccessLog(rc, startTime, endTime, $", name: \"{mountName.ToString()}\", applicationid: 0x{titleId}, userid: 0x{userId}");
}
else
{
rc = MountSaveDataImpl(fs, mountName, SaveDataSpaceId.User, titleId, userId, SaveDataType.SaveData, false, 0);
rc = MountSaveDataImpl(fs, mountName, SaveDataSpaceId.User, titleId, userId, SaveDataType.Account, false, 0);
}
if (rc.IsSuccess() && fs.IsEnabledAccessLog(AccessLogTarget.Application))

View File

@ -2,7 +2,6 @@
using System.Runtime.InteropServices;
using LibHac.Common;
using LibHac.FsService;
using LibHac.FsSystem.Save;
using LibHac.Ncm;
namespace LibHac.Fs.Shim
@ -10,7 +9,7 @@ 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, uint flags)
long size, long journalSize, SaveDataFlags flags)
{
return fs.RunOperationWithAccessLog(AccessLogTarget.System,
() =>
@ -21,10 +20,10 @@ namespace LibHac.Fs.Shim
{
TitleId = applicationId,
UserId = userId,
Type = SaveDataType.SaveData
Type = SaveDataType.Account
};
var createInfo = new SaveDataCreateInfo
var createInfo = new SaveDataCreationInfo
{
Size = size,
JournalSize = journalSize,
@ -36,7 +35,7 @@ namespace LibHac.Fs.Shim
var metaInfo = new SaveMetaCreateInfo
{
Type = SaveMetaType.Thumbnail,
Type = SaveDataMetaType.Thumbnail,
Size = 0x40060
};
@ -46,7 +45,7 @@ namespace LibHac.Fs.Shim
}
public static Result CreateSaveData(this FileSystemClient fs, TitleId applicationId, UserId userId, TitleId ownerId,
long size, long journalSize, HashSalt hashSalt, uint flags)
long size, long journalSize, HashSalt hashSalt, SaveDataFlags flags)
{
return fs.RunOperationWithAccessLog(AccessLogTarget.System,
() =>
@ -57,10 +56,10 @@ namespace LibHac.Fs.Shim
{
TitleId = applicationId,
UserId = userId,
Type = SaveDataType.SaveData
Type = SaveDataType.Account
};
var createInfo = new SaveDataCreateInfo
var createInfo = new SaveDataCreationInfo
{
Size = size,
JournalSize = journalSize,
@ -72,7 +71,7 @@ namespace LibHac.Fs.Shim
var metaInfo = new SaveMetaCreateInfo
{
Type = SaveMetaType.Thumbnail,
Type = SaveDataMetaType.Thumbnail,
Size = 0x40060
};
@ -91,10 +90,10 @@ namespace LibHac.Fs.Shim
var attribute = new SaveDataAttribute
{
TitleId = applicationId,
Type = SaveDataType.BcatDeliveryCacheStorage
Type = SaveDataType.Bcat
};
var createInfo = new SaveDataCreateInfo
var createInfo = new SaveDataCreationInfo
{
Size = size,
JournalSize = 0x200000,
@ -112,7 +111,7 @@ namespace LibHac.Fs.Shim
}
public static Result CreateDeviceSaveData(this FileSystemClient fs, TitleId applicationId, TitleId ownerId,
long size, long journalSize, uint flags)
long size, long journalSize, SaveDataFlags flags)
{
return fs.RunOperationWithAccessLog(AccessLogTarget.System,
() =>
@ -122,10 +121,10 @@ namespace LibHac.Fs.Shim
var attribute = new SaveDataAttribute
{
TitleId = applicationId,
Type = SaveDataType.DeviceSaveData
Type = SaveDataType.Device
};
var createInfo = new SaveDataCreateInfo
var createInfo = new SaveDataCreationInfo
{
Size = size,
JournalSize = journalSize,
@ -142,7 +141,7 @@ namespace LibHac.Fs.Shim
() => $", 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{flags:x8}");
}
public static Result CreateTemporaryStorage(this FileSystemClient fs, TitleId applicationId, TitleId ownerId, long size, uint flags)
public static Result CreateTemporaryStorage(this FileSystemClient fs, TitleId applicationId, TitleId ownerId, long size, SaveDataFlags flags)
{
return fs.RunOperationWithAccessLog(AccessLogTarget.System,
() =>
@ -152,16 +151,16 @@ namespace LibHac.Fs.Shim
var attribute = new SaveDataAttribute
{
TitleId = applicationId,
Type = SaveDataType.TemporaryStorage
Type = SaveDataType.Temporary
};
var createInfo = new SaveDataCreateInfo
var createInfo = new SaveDataCreationInfo
{
Size = size,
BlockSize = 0x4000,
OwnerId = ownerId,
Flags = flags,
SpaceId = SaveDataSpaceId.TemporaryStorage
SpaceId = SaveDataSpaceId.Temporary
};
var metaInfo = new SaveMetaCreateInfo();
@ -172,7 +171,7 @@ namespace LibHac.Fs.Shim
}
public static Result CreateSystemSaveData(this FileSystemClient fs, SaveDataSpaceId spaceId,
ulong saveDataId, UserId userId, TitleId ownerId, long size, long journalSize, uint flags)
ulong saveDataId, UserId userId, TitleId ownerId, long size, long journalSize, SaveDataFlags flags)
{
return fs.RunOperationWithAccessLog(AccessLogTarget.System,
() =>
@ -185,7 +184,7 @@ namespace LibHac.Fs.Shim
SaveDataId = saveDataId
};
var createInfo = new SaveDataCreateInfo
var createInfo = new SaveDataCreationInfo
{
Size = size,
JournalSize = journalSize,
@ -201,31 +200,31 @@ namespace LibHac.Fs.Shim
}
public static Result CreateSystemSaveData(this FileSystemClient fs, ulong saveDataId, UserId userId,
TitleId ownerId, long size, long journalSize, uint flags)
TitleId ownerId, long size, long journalSize, SaveDataFlags flags)
{
return CreateSystemSaveData(fs, SaveDataSpaceId.System, saveDataId, userId, ownerId, size, journalSize, flags);
}
public static Result CreateSystemSaveData(this FileSystemClient fs, ulong saveDataId, UserId userId, long size,
long journalSize, uint flags)
long journalSize, SaveDataFlags flags)
{
return CreateSystemSaveData(fs, SaveDataSpaceId.System, saveDataId, userId, TitleId.Zero, size, journalSize, flags);
}
public static Result CreateSystemSaveData(this FileSystemClient fs, ulong saveDataId, TitleId ownerId, long size,
long journalSize, uint flags)
long journalSize, SaveDataFlags flags)
{
return CreateSystemSaveData(fs, SaveDataSpaceId.System, saveDataId, UserId.Zero, ownerId, size, journalSize, flags);
}
public static Result CreateSystemSaveData(this FileSystemClient fs, ulong saveDataId, long size,
long journalSize, uint flags)
long journalSize, SaveDataFlags flags)
{
return CreateSystemSaveData(fs, SaveDataSpaceId.System, saveDataId, UserId.Zero, TitleId.Zero, size, journalSize, flags);
}
public static Result CreateSystemSaveData(this FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId,
TitleId ownerId, long size, long journalSize, uint flags)
TitleId ownerId, long size, long journalSize, SaveDataFlags flags)
{
return CreateSystemSaveData(fs, spaceId, saveDataId, UserId.Zero, ownerId, size, journalSize, flags);
}

View File

@ -3,7 +3,6 @@ using System.Runtime.CompilerServices;
using LibHac.Common;
using LibHac.Fs;
using LibHac.FsSystem;
using LibHac.FsSystem.Save;
using LibHac.Kvdb;
using LibHac.Ncm;
using LibHac.Spl;
@ -125,7 +124,7 @@ namespace LibHac.FsService
}
else
{
if (spaceId != SaveDataSpaceId.ProperSystem && spaceId != SaveDataSpaceId.Safe)
if (spaceId != SaveDataSpaceId.ProperSystem && spaceId != SaveDataSpaceId.SafeMode)
{
rc = reader.Indexer.GetBySaveDataId(out SaveDataIndexerValue value, saveDataId);
if (rc.IsFailure()) return rc;
@ -136,7 +135,7 @@ namespace LibHac.FsService
rc = reader.Indexer.GetKey(out SaveDataAttribute key, saveDataId);
if (rc.IsFailure()) return rc;
if (key.Type == SaveDataType.SystemSaveData || key.Type == SaveDataType.BcatSystemStorage)
if (key.Type == SaveDataType.System || key.Type == SaveDataType.SystemBcat)
{
// Check if permissions allow deleting system save data
}
@ -256,7 +255,7 @@ namespace LibHac.FsService
throw new NotImplementedException();
}
private Result CreateSaveDataFileSystemImpl(ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo,
private Result CreateSaveDataFileSystemImpl(ref SaveDataAttribute attribute, ref SaveDataCreationInfo creationInfo,
ref SaveMetaCreateInfo metaCreateInfo, ref OptionalHashSalt hashSalt, bool something)
{
ulong saveDataId = 0;
@ -270,7 +269,7 @@ namespace LibHac.FsService
if (attribute.SaveDataId == FileSystemServer.SaveIndexerId)
{
saveDataId = FileSystemServer.SaveIndexerId;
rc = FsProxyCore.DoesSaveDataExist(out bool saveExists, createInfo.SpaceId, saveDataId);
rc = FsProxyCore.DoesSaveDataExist(out bool saveExists, creationInfo.SpaceId, saveDataId);
if (rc.IsSuccess() && saveExists)
{
@ -281,7 +280,7 @@ namespace LibHac.FsService
}
else
{
rc = FsServer.SaveDataIndexerManager.GetSaveDataIndexer(out reader, createInfo.SpaceId);
rc = FsServer.SaveDataIndexerManager.GetSaveDataIndexer(out reader, creationInfo.SpaceId);
if (rc.IsFailure()) return rc;
SaveDataAttribute indexerKey = attribute;
@ -294,8 +293,8 @@ namespace LibHac.FsService
}
else
{
if (attribute.Type != SaveDataType.SystemSaveData &&
attribute.Type != SaveDataType.BcatSystemStorage)
if (attribute.Type != SaveDataType.System &&
attribute.Type != SaveDataType.SystemBcat)
{
if (reader.Indexer.IsFull())
{
@ -316,7 +315,7 @@ namespace LibHac.FsService
rc = reader.Indexer.SetState(saveDataId, SaveDataState.Creating);
if (rc.IsFailure()) return rc;
SaveDataSpaceId indexerSpaceId = GetSpaceIdForIndexer(createInfo.SpaceId);
SaveDataSpaceId indexerSpaceId = GetSpaceIdForIndexer(creationInfo.SpaceId);
rc = reader.Indexer.SetSpaceId(saveDataId, indexerSpaceId);
if (rc.IsFailure()) return rc;
@ -331,30 +330,30 @@ namespace LibHac.FsService
if (rc.IsFailure()) return rc;
}
rc = FsProxyCore.CreateSaveDataFileSystem(saveDataId, ref attribute, ref createInfo, SaveDataRootPath,
rc = FsProxyCore.CreateSaveDataFileSystem(saveDataId, ref attribute, ref creationInfo, SaveDataRootPath,
hashSalt, false);
if (rc.IsFailure())
{
if (rc != ResultFs.PathAlreadyExists) return rc;
rc = DeleteSaveDataFileSystemImpl2(createInfo.SpaceId, saveDataId);
rc = DeleteSaveDataFileSystemImpl2(creationInfo.SpaceId, saveDataId);
if (rc.IsFailure()) return rc;
rc = FsProxyCore.CreateSaveDataFileSystem(saveDataId, ref attribute, ref createInfo, SaveDataRootPath,
rc = FsProxyCore.CreateSaveDataFileSystem(saveDataId, ref attribute, ref creationInfo, SaveDataRootPath,
hashSalt, false);
if (rc.IsFailure()) return rc;
}
if (metaCreateInfo.Type != SaveMetaType.None)
if (metaCreateInfo.Type != SaveDataMetaType.None)
{
rc = FsProxyCore.CreateSaveDataMetaFile(saveDataId, createInfo.SpaceId, metaCreateInfo.Type,
rc = FsProxyCore.CreateSaveDataMetaFile(saveDataId, creationInfo.SpaceId, metaCreateInfo.Type,
metaCreateInfo.Size);
if (rc.IsFailure()) return rc;
if (metaCreateInfo.Type == SaveMetaType.Thumbnail)
if (metaCreateInfo.Type == SaveDataMetaType.Thumbnail)
{
rc = FsProxyCore.OpenSaveDataMetaFile(out IFile metaFile, saveDataId, createInfo.SpaceId,
rc = FsProxyCore.OpenSaveDataMetaFile(out IFile metaFile, saveDataId, creationInfo.SpaceId,
metaCreateInfo.Type);
using (metaFile)
@ -391,13 +390,13 @@ namespace LibHac.FsService
// Revert changes if an error happened in the middle of creation
if (isDeleteNeeded)
{
DeleteSaveDataFileSystemImpl2(createInfo.SpaceId, saveDataId);
DeleteSaveDataFileSystemImpl2(creationInfo.SpaceId, saveDataId);
if (reader.IsInitialized && saveDataId != FileSystemServer.SaveIndexerId)
{
rc = reader.Indexer.GetBySaveDataId(out SaveDataIndexerValue value, saveDataId);
if (rc.IsSuccess() && value.SpaceId == createInfo.SpaceId)
if (rc.IsSuccess() && value.SpaceId == creationInfo.SpaceId)
{
reader.Indexer.Delete(saveDataId);
reader.Indexer.Commit();
@ -409,15 +408,15 @@ namespace LibHac.FsService
}
}
public Result CreateSaveDataFileSystem(ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo,
public Result CreateSaveDataFileSystem(ref SaveDataAttribute attribute, ref SaveDataCreationInfo creationInfo,
ref SaveMetaCreateInfo metaCreateInfo)
{
OptionalHashSalt hashSalt = default;
return CreateUserSaveDataFileSystem(ref attribute, ref createInfo, ref metaCreateInfo, ref hashSalt);
return CreateUserSaveDataFileSystem(ref attribute, ref creationInfo, ref metaCreateInfo, ref hashSalt);
}
public Result CreateSaveDataFileSystemWithHashSalt(ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo,
public Result CreateSaveDataFileSystemWithHashSalt(ref SaveDataAttribute attribute, ref SaveDataCreationInfo creationInfo,
ref SaveMetaCreateInfo metaCreateInfo, ref HashSalt hashSalt)
{
var hashSaltCopy = new OptionalHashSalt
@ -426,23 +425,23 @@ namespace LibHac.FsService
HashSalt = hashSalt
};
return CreateUserSaveDataFileSystem(ref attribute, ref createInfo, ref metaCreateInfo, ref hashSaltCopy);
return CreateUserSaveDataFileSystem(ref attribute, ref creationInfo, ref metaCreateInfo, ref hashSaltCopy);
}
private Result CreateUserSaveDataFileSystem(ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo,
private Result CreateUserSaveDataFileSystem(ref SaveDataAttribute attribute, ref SaveDataCreationInfo creationInfo,
ref SaveMetaCreateInfo metaCreateInfo, ref OptionalHashSalt hashSalt)
{
return CreateSaveDataFileSystemImpl(ref attribute, ref createInfo, ref metaCreateInfo, ref hashSalt, false);
return CreateSaveDataFileSystemImpl(ref attribute, ref creationInfo, ref metaCreateInfo, ref hashSalt, false);
}
public Result CreateSaveDataFileSystemBySystemSaveDataId(ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo)
public Result CreateSaveDataFileSystemBySystemSaveDataId(ref SaveDataAttribute attribute, ref SaveDataCreationInfo creationInfo)
{
if (!IsSystemSaveDataId(attribute.SaveDataId))
return ResultFs.InvalidArgument.Log();
SaveDataCreateInfo newCreateInfo = createInfo;
SaveDataCreationInfo newCreationInfo = creationInfo;
if (createInfo.OwnerId == TitleId.Zero)
if (creationInfo.OwnerId == TitleId.Zero)
{
// todo: Assign the current program's ID
// throw new NotImplementedException();
@ -450,15 +449,15 @@ namespace LibHac.FsService
// Missing permission checks
if (attribute.Type == SaveDataType.BcatSystemStorage)
if (attribute.Type == SaveDataType.SystemBcat)
{
newCreateInfo.OwnerId = SystemTitleIds.Bcat;
newCreationInfo.OwnerId = SystemTitleIds.Bcat;
}
SaveMetaCreateInfo metaCreateInfo = default;
OptionalHashSalt optionalHashSalt = default;
return CreateSaveDataFileSystemImpl(ref attribute, ref newCreateInfo, ref metaCreateInfo,
return CreateSaveDataFileSystemImpl(ref attribute, ref newCreationInfo, ref metaCreateInfo,
ref optionalHashSalt, false);
}
@ -551,7 +550,7 @@ namespace LibHac.FsService
SaveDataSpaceId actualSpaceId;
if (attributeCopy.Type == SaveDataType.CacheStorage)
if (attributeCopy.Type == SaveDataType.Cache)
{
// Check whether the save is on the SD card or the BIS
throw new NotImplementedException();
@ -849,7 +848,7 @@ namespace LibHac.FsService
}
public Result OpenSaveDataMetaFile(out IFile file, SaveDataSpaceId spaceId, ref SaveDataAttribute attribute,
SaveMetaType type)
SaveDataMetaType type)
{
throw new NotImplementedException();
}
@ -1080,7 +1079,7 @@ namespace LibHac.FsService
private static SaveDataSpaceId GetSpaceIdForIndexer(SaveDataSpaceId spaceId)
{
return spaceId == SaveDataSpaceId.ProperSystem || spaceId == SaveDataSpaceId.Safe
return spaceId == SaveDataSpaceId.ProperSystem || spaceId == SaveDataSpaceId.SafeMode
? SaveDataSpaceId.System
: spaceId;
}

View File

@ -3,7 +3,6 @@ using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Shim;
using LibHac.FsSystem;
using LibHac.FsSystem.Save;
using LibHac.FsService.Creators;
using LibHac.Spl;
using RightsId = LibHac.Fs.RightsId;
@ -44,11 +43,11 @@ namespace LibHac.FsService
{
switch (partitionId)
{
case GameCardPartitionRaw.Normal:
case GameCardPartitionRaw.NormalReadOnly:
return FsCreators.GameCardStorageCreator.CreateNormal(handle, out storage);
case GameCardPartitionRaw.Secure:
case GameCardPartitionRaw.SecureReadOnly:
return FsCreators.GameCardStorageCreator.CreateSecure(handle, out storage);
case GameCardPartitionRaw.Writable:
case GameCardPartitionRaw.RootWriteOnly:
return FsCreators.GameCardStorageCreator.CreateWritable(handle, out storage);
default:
throw new ArgumentOutOfRangeException(nameof(partitionId), partitionId, null);
@ -132,13 +131,13 @@ namespace LibHac.FsService
fileSystem = encryptedFs;
return Result.Success;
}
case CustomStorageId.User:
case CustomStorageId.System:
{
Result rc = FsCreators.BuiltInStorageFileSystemCreator.Create(out IFileSystem userFs, string.Empty,
BisPartitionId.User);
if (rc.IsFailure()) return rc;
string customStorageDir = CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.User);
string customStorageDir = CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.System);
string subDirName = $"/{customStorageDir}";
rc = Util.CreateSubFileSystem(out IFileSystem subFs, userFs, subDirName, true);
@ -264,7 +263,7 @@ namespace LibHac.FsService
return Util.CreateSubFileSystem(out fileSystem, hostFs, saveDataRootPath, true);
}
string dirName = spaceId == SaveDataSpaceId.TemporaryStorage ? "/temp" : "/save";
string dirName = spaceId == SaveDataSpaceId.Temporary ? "/temp" : "/save";
return OpenSaveDataDirectoryImpl(out fileSystem, spaceId, dirName, true);
}
@ -283,7 +282,7 @@ namespace LibHac.FsService
return Util.CreateSubFileSystem(out fileSystem, sysFs, saveDirName, createIfMissing);
case SaveDataSpaceId.User:
case SaveDataSpaceId.TemporaryStorage:
case SaveDataSpaceId.Temporary:
rc = OpenBisFileSystem(out IFileSystem userFs, string.Empty, BisPartitionId.User);
if (rc.IsFailure()) return rc;
@ -308,7 +307,7 @@ namespace LibHac.FsService
return Util.CreateSubFileSystem(out fileSystem, sysProperFs, saveDirName, createIfMissing);
case SaveDataSpaceId.Safe:
case SaveDataSpaceId.SafeMode:
rc = OpenBisFileSystem(out IFileSystem safeFs, string.Empty, BisPartitionId.SafeMode);
if (rc.IsFailure()) return rc;
@ -319,7 +318,7 @@ namespace LibHac.FsService
}
}
public Result OpenSaveDataMetaFile(out IFile file, ulong saveDataId, SaveDataSpaceId spaceId, SaveMetaType type)
public Result OpenSaveDataMetaFile(out IFile file, ulong saveDataId, SaveDataSpaceId spaceId, SaveDataMetaType type)
{
file = default;
@ -351,7 +350,7 @@ namespace LibHac.FsService
}
}
public Result CreateSaveDataMetaFile(ulong saveDataId, SaveDataSpaceId spaceId, SaveMetaType type, long size)
public Result CreateSaveDataMetaFile(ulong saveDataId, SaveDataSpaceId spaceId, SaveDataMetaType type, long size)
{
string metaDirPath = $"/saveMeta/{saveDataId:x16}";
@ -367,11 +366,11 @@ namespace LibHac.FsService
}
public Result CreateSaveDataFileSystem(ulong saveDataId, ref SaveDataAttribute attribute,
ref SaveDataCreateInfo createInfo, U8Span rootPath, OptionalHashSalt hashSalt, bool something)
ref SaveDataCreationInfo creationInfo, U8Span rootPath, OptionalHashSalt hashSalt, bool something)
{
// Use directory save data for now
Result rc = OpenSaveDataDirectory(out IFileSystem fileSystem, createInfo.SpaceId, string.Empty, false);
Result rc = OpenSaveDataDirectory(out IFileSystem fileSystem, creationInfo.SpaceId, string.Empty, false);
if (rc.IsFailure()) return rc;
return fileSystem.EnsureDirectoryExists(GetSaveDataIdPath(saveDataId));

View File

@ -21,8 +21,8 @@ namespace LibHac.FsService
Result OpenSdCardFileSystem(out IFileSystem fileSystem);
Result FormatSdCardFileSystem();
Result DeleteSaveDataFileSystem(ulong saveDataId);
Result CreateSaveDataFileSystem(ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo, ref SaveMetaCreateInfo metaCreateInfo);
Result CreateSaveDataFileSystemBySystemSaveDataId(ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo);
Result CreateSaveDataFileSystem(ref SaveDataAttribute attribute, ref SaveDataCreationInfo creationInfo, ref SaveMetaCreateInfo metaCreateInfo);
Result CreateSaveDataFileSystemBySystemSaveDataId(ref SaveDataAttribute attribute, ref SaveDataCreationInfo creationInfo);
Result RegisterSaveDataFileSystemAtomicDeletion(ReadOnlySpan<ulong> saveDataIds);
Result DeleteSaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId);
Result FormatSdCardDryRun();
@ -33,7 +33,7 @@ namespace LibHac.FsService
Result ExtendSaveDataFileSystem(SaveDataSpaceId spaceId, ulong saveDataId, long dataSize, long journalSize);
Result DeleteCacheStorage(short index);
Result GetCacheStorageSize(out long dataSize, out long journalSize, short index);
Result CreateSaveDataFileSystemWithHashSalt(ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo, ref SaveMetaCreateInfo metaCreateInfo, ref HashSalt hashSalt);
Result CreateSaveDataFileSystemWithHashSalt(ref SaveDataAttribute attribute, ref SaveDataCreationInfo creationInfo, ref SaveMetaCreateInfo metaCreateInfo, ref HashSalt hashSalt);
Result OpenSaveDataFileSystem(out IFileSystem fileSystem, SaveDataSpaceId spaceId, ref SaveDataAttribute attribute);
Result OpenSaveDataFileSystemBySystemSaveDataId(out IFileSystem fileSystem, SaveDataSpaceId spaceId, ref SaveDataAttribute attribute);
Result OpenReadOnlySaveDataFileSystem(out IFileSystem fileSystem, SaveDataSpaceId spaceId, ref SaveDataAttribute attribute);
@ -50,7 +50,7 @@ namespace LibHac.FsService
Result OpenSaveDataInfoReaderWithFilter(out ISaveDataInfoReader infoReader, SaveDataSpaceId spaceId, ref SaveDataFilter filter);
Result ReadSaveDataFileSystemExtraDataBySaveDataAttribute(Span<byte> extraDataBuffer, SaveDataSpaceId spaceId, ref SaveDataAttribute attribute);
Result WriteSaveDataFileSystemExtraDataBySaveDataAttribute(ref SaveDataAttribute attribute, SaveDataSpaceId spaceId, ReadOnlySpan<byte> extraDataBuffer, ReadOnlySpan<byte> maskBuffer);
Result OpenSaveDataMetaFile(out IFile file, SaveDataSpaceId spaceId, ref SaveDataAttribute attribute, SaveMetaType type);
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 OpenImageDirectoryFileSystem(out IFileSystem fileSystem, ImageDirectoryId dirId);

View File

@ -50,7 +50,7 @@ namespace LibHac.FsService
reader = new SaveDataIndexerReader(_sdCardIndexer.Indexer, _sdCardIndexer.Locker);
return Result.Success;
case SaveDataSpaceId.TemporaryStorage:
case SaveDataSpaceId.Temporary:
throw new NotImplementedException();
case SaveDataSpaceId.ProperSystem:
@ -64,12 +64,12 @@ namespace LibHac.FsService
reader = new SaveDataIndexerReader(_safeIndexer.Indexer, _safeIndexer.Locker);
return Result.Success;
case SaveDataSpaceId.Safe:
case SaveDataSpaceId.SafeMode:
Monitor.Enter(_properSystemIndexer.Locker);
if (!_properSystemIndexer.IsInitialized)
{
_properSystemIndexer.Indexer = new SaveDataIndexer(FsClient, "saveDataIxrDbSf", SaveDataSpaceId.Safe, SaveDataId);
_properSystemIndexer.Indexer = new SaveDataIndexer(FsClient, "saveDataIxrDbSf", SaveDataSpaceId.SafeMode, SaveDataId);
}
reader = new SaveDataIndexerReader(_properSystemIndexer.Indexer, _properSystemIndexer.Locker);

View File

@ -2,7 +2,6 @@
using System.Runtime.InteropServices;
using LibHac.Common;
using LibHac.Fs;
using LibHac.FsSystem.Save;
using LibHac.Ncm;
namespace LibHac.FsService
@ -85,7 +84,7 @@ namespace LibHac.FsService
FilterBySaveDataSpaceId = true;
SpaceId = spaceId;
Rank = filter.Rank;
Rank = (int)filter.Rank;
if (filter.FilterByTitleId)
{
@ -150,7 +149,8 @@ namespace LibHac.FsService
return false;
}
if ((Rank & 1) == 0 && info.Rank != 0)
// When filtering by secondary rank include primary ranks as well
if ((Rank & 1) == 1 || info.Rank == SaveDataRank.Primary)
{
return false;
}

View File

@ -45,9 +45,9 @@ namespace LibHac.FsService
{
return spaceId == SaveDataSpaceId.System ||
spaceId == SaveDataSpaceId.User ||
spaceId == SaveDataSpaceId.TemporaryStorage ||
spaceId == SaveDataSpaceId.Temporary ||
spaceId == SaveDataSpaceId.ProperSystem ||
spaceId == SaveDataSpaceId.Safe;
spaceId == SaveDataSpaceId.SafeMode;
}
}
}

View File

@ -284,15 +284,4 @@ namespace LibHac.FsSystem.Save
return new Guid(b);
}
}
public enum SaveDataType : byte
{
SystemSaveData = 0,
SaveData = 1,
BcatDeliveryCacheStorage = 2,
DeviceSaveData = 3,
TemporaryStorage = 4,
CacheStorage = 5,
BcatSystemStorage = 6
}
}

View File

@ -38,7 +38,7 @@ namespace LibHac
public int BackupAreaStartPage { get; set; }
public byte KekIndex { get; set; }
public byte TitleKeyDecIndex { get; set; }
public GameCardSize GameCardSize { get; set; }
public GameCardSizeInternal GameCardSize { get; set; }
public byte CardHeaderVersion { get; set; }
public GameCardAttribute Flags { get; set; }
public ulong PackageId { get; set; }
@ -91,7 +91,7 @@ namespace LibHac
byte keyIndex = reader.ReadByte();
KekIndex = (byte)(keyIndex >> 4);
TitleKeyDecIndex = (byte)(keyIndex & 7);
GameCardSize = (GameCardSize)reader.ReadByte();
GameCardSize = (GameCardSizeInternal)reader.ReadByte();
CardHeaderVersion = reader.ReadByte();
Flags = (GameCardAttribute)reader.ReadByte();
PackageId = reader.ReadUInt64();
@ -133,7 +133,7 @@ namespace LibHac
Sha256.GenerateSha256Hash(sigData, ImageHash);
reader.BaseStream.Position = RootPartitionOffset;
byte[] headerBytes = reader.ReadBytes((int) RootPartitionHeaderSize);
byte[] headerBytes = reader.ReadBytes((int)RootPartitionHeaderSize);
Span<byte> actualHeaderHash = stackalloc byte[Sha256.DigestSize];
Sha256.GenerateSha256Hash(headerBytes, actualHeaderHash);

View File

@ -192,16 +192,16 @@ namespace hactoolnet
}
}
private static string GetCartridgeType(GameCardSize size)
private static string GetCartridgeType(GameCardSizeInternal size)
{
switch (size)
{
case GameCardSize.Size1Gb: return "1GB";
case GameCardSize.Size2Gb: return "2GB";
case GameCardSize.Size4Gb: return "4GB";
case GameCardSize.Size8Gb: return "8GB";
case GameCardSize.Size16Gb: return "16GB";
case GameCardSize.Size32Gb: return "32GB";
case GameCardSizeInternal.Size1Gb: return "1GB";
case GameCardSizeInternal.Size2Gb: return "2GB";
case GameCardSizeInternal.Size4Gb: return "4GB";
case GameCardSizeInternal.Size8Gb: return "8GB";
case GameCardSizeInternal.Size16Gb: return "16GB";
case GameCardSizeInternal.Size32Gb: return "32GB";
default: return string.Empty;
}
}