public static Result CreateBcatSaveData(this FileSystemClient fs, TitleId applicationId, long size) { return(fs.RunOperationWithAccessLog(LocalAccessLogMode.System, () => { IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute { TitleId = applicationId, Type = SaveDataType.BcatDeliveryCacheStorage }; var createInfo = new SaveDataCreateInfo { Size = size, JournalSize = 0x200000, BlockSize = 0x4000, OwnerId = SystemTitleIds.Bcat, Flags = 0, SpaceId = SaveDataSpaceId.User }; var metaInfo = new SaveMetaCreateInfo(); return fsProxy.CreateSaveDataFileSystem(ref attribute, ref createInfo, ref metaInfo); }, () => $", applicationid: 0x{applicationId.Value:X}, save_data_size: {size}")); }
public static Result CreateSystemSaveData(this FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId, UserId userId, TitleId ownerId, long size, long journalSize, uint flags) { return(fs.RunOperationWithAccessLog(LocalAccessLogMode.System, () => { IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute { UserId = userId, SaveDataId = saveDataId }; var createInfo = new SaveDataCreateInfo { Size = size, JournalSize = journalSize, BlockSize = 0x4000, OwnerId = ownerId, Flags = flags, SpaceId = spaceId }; 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{flags:X8}")); }
public static Result CreateSaveData(this FileSystemClient fs, TitleId applicationId, UserId userId, TitleId ownerId, long size, long journalSize, HashSalt hashSalt, uint flags) { return(fs.RunOperationWithAccessLog(LocalAccessLogMode.System, () => { IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute { TitleId = applicationId, UserId = userId, Type = SaveDataType.SaveData }; var createInfo = new SaveDataCreateInfo { Size = size, JournalSize = journalSize, BlockSize = 0x4000, OwnerId = ownerId, Flags = flags, SpaceId = SaveDataSpaceId.User }; var metaInfo = new SaveMetaCreateInfo { Type = SaveMetaType.Thumbnail, Size = 0x40060 }; 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{flags:x8}")); }
public Result CreateSaveDataFileSystemBySystemSaveDataId(ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo) { if (!IsSystemSaveDataId(attribute.SaveDataId)) { return(ResultFs.InvalidArgument.Log()); } SaveDataCreateInfo newCreateInfo = createInfo; if (createInfo.OwnerId == TitleId.Zero) { // Assign the current program's ID throw new NotImplementedException(); } // Missing permission checks if (attribute.Type == SaveDataType.BcatSystemStorage) { newCreateInfo.OwnerId = SystemTitleIds.Bcat; } SaveMetaCreateInfo metaCreateInfo = default; OptionalHashSalt optionalHashSalt = default; return(CreateSaveDataFileSystemImpl(ref attribute, ref newCreateInfo, ref metaCreateInfo, ref optionalHashSalt, false)); }
public static Result CreateTemporaryStorage(this FileSystemClient fs, TitleId applicationId, TitleId ownerId, long size, uint flags) { return(fs.RunOperationWithAccessLog(LocalAccessLogMode.System, () => { IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute { TitleId = applicationId, Type = SaveDataType.TemporaryStorage }; var createInfo = new SaveDataCreateInfo { Size = size, BlockSize = 0x4000, OwnerId = ownerId, Flags = flags, SpaceId = SaveDataSpaceId.TemporaryStorage }; var metaInfo = new SaveMetaCreateInfo(); 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{flags:x8}")); }
public Result CreateSaveDataFileSystem(ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo, ref SaveMetaCreateInfo metaCreateInfo) { OptionalHashSalt hashSalt = default; return(CreateUserSaveDataFileSystem(ref attribute, ref createInfo, ref metaCreateInfo, ref hashSalt)); }
public Result CreateSaveDataFileSystem(ulong saveDataId, ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo, U8Span rootPath, OptionalHashSalt hashSalt, bool something) { // Use directory save data for now Result rc = OpenSaveDataDirectory(out IFileSystem fileSystem, createInfo.SpaceId, string.Empty, false); if (rc.IsFailure()) { return(rc); } return(fileSystem.EnsureDirectoryExists(GetSaveDataIdPath(saveDataId))); }
private Result CreateUserSaveDataFileSystem(ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo, ref SaveMetaCreateInfo metaCreateInfo, ref OptionalHashSalt hashSalt) { return(CreateSaveDataFileSystemImpl(ref attribute, ref createInfo, ref metaCreateInfo, ref hashSalt, false)); }
public Result CreateSaveDataFileSystemWithHashSalt(ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo, ref SaveMetaCreateInfo metaCreateInfo, ref HashSalt hashSalt) { var hashSaltCopy = new OptionalHashSalt { IsSet = true, HashSalt = hashSalt }; return(CreateUserSaveDataFileSystem(ref attribute, ref createInfo, ref metaCreateInfo, ref hashSaltCopy)); }
private Result CreateSaveDataFileSystemImpl(ref SaveDataAttribute attribute, ref SaveDataCreateInfo createInfo, ref SaveMetaCreateInfo metaCreateInfo, ref OptionalHashSalt hashSalt, bool something) { ulong saveDataId = 0; bool isDeleteNeeded = false; Result rc; SaveDataIndexerReader reader = default; try { if (attribute.SaveDataId == FileSystemServer.SaveIndexerId) { saveDataId = FileSystemServer.SaveIndexerId; rc = FsProxyCore.DoesSaveDataExist(out bool saveExists, createInfo.SpaceId, saveDataId); if (rc.IsSuccess() && saveExists) { return(ResultFs.PathAlreadyExists.Log()); } isDeleteNeeded = true; } else { rc = FsServer.SaveDataIndexerManager.GetSaveDataIndexer(out reader, createInfo.SpaceId); if (rc.IsFailure()) { return(rc); } SaveDataAttribute indexerKey = attribute; if (attribute.SaveDataId != 0 || attribute.UserId == UserId.Zero) { saveDataId = attribute.SaveDataId; rc = reader.Indexer.AddSystemSaveData(ref indexerKey); } else { if (attribute.Type != SaveDataType.SystemSaveData && attribute.Type != SaveDataType.BcatSystemStorage) { if (reader.Indexer.IsFull()) { return(ResultKvdb.TooLargeKeyOrDbFull.Log()); } } rc = reader.Indexer.Add(out saveDataId, ref indexerKey); } if (rc == ResultFs.SaveDataPathAlreadyExists) { return(ResultFs.PathAlreadyExists.LogConverted(rc)); } isDeleteNeeded = true; rc = reader.Indexer.SetState(saveDataId, SaveDataState.Creating); if (rc.IsFailure()) { return(rc); } SaveDataSpaceId indexerSpaceId = GetSpaceIdForIndexer(createInfo.SpaceId); rc = reader.Indexer.SetSpaceId(saveDataId, indexerSpaceId); if (rc.IsFailure()) { return(rc); } // todo: calculate size long size = 0; rc = reader.Indexer.SetSize(saveDataId, size); if (rc.IsFailure()) { return(rc); } rc = reader.Indexer.Commit(); if (rc.IsFailure()) { return(rc); } } rc = FsProxyCore.CreateSaveDataFileSystem(saveDataId, ref attribute, ref createInfo, SaveDataRootPath, hashSalt, false); if (rc.IsFailure()) { if (rc != ResultFs.PathAlreadyExists) { return(rc); } rc = DeleteSaveDataFileSystemImpl2(createInfo.SpaceId, saveDataId); if (rc.IsFailure()) { return(rc); } rc = FsProxyCore.CreateSaveDataFileSystem(saveDataId, ref attribute, ref createInfo, SaveDataRootPath, hashSalt, false); if (rc.IsFailure()) { return(rc); } } if (metaCreateInfo.Type != SaveMetaType.None) { rc = FsProxyCore.CreateSaveDataMetaFile(saveDataId, createInfo.SpaceId, metaCreateInfo.Type, metaCreateInfo.Size); if (rc.IsFailure()) { return(rc); } if (metaCreateInfo.Type == SaveMetaType.Thumbnail) { rc = FsProxyCore.OpenSaveDataMetaFile(out IFile metaFile, saveDataId, createInfo.SpaceId, metaCreateInfo.Type); using (metaFile) { if (rc.IsFailure()) { return(rc); } ReadOnlySpan <byte> metaFileData = stackalloc byte[0x20]; rc = metaFile.Write(0, metaFileData, WriteOption.Flush); if (rc.IsFailure()) { return(rc); } } } } if (attribute.SaveDataId == FileSystemServer.SaveIndexerId || something) { isDeleteNeeded = false; return(Result.Success); } rc = reader.Indexer.SetState(saveDataId, SaveDataState.Normal); if (rc.IsFailure()) { return(rc); } rc = reader.Indexer.Commit(); if (rc.IsFailure()) { return(rc); } isDeleteNeeded = false; return(Result.Success); } finally { // Revert changes if an error happened in the middle of creation if (isDeleteNeeded) { DeleteSaveDataFileSystemImpl2(createInfo.SpaceId, saveDataId); if (reader.IsInitialized && saveDataId != FileSystemServer.SaveIndexerId) { rc = reader.Indexer.GetBySaveDataId(out SaveDataIndexerValue value, saveDataId); if (rc.IsSuccess() && value.SpaceId == createInfo.SpaceId) { reader.Indexer.Delete(saveDataId); reader.Indexer.Commit(); } } } reader.Dispose(); } }