public static Result EnsureApplicationCacheStorage(this FileSystemClient fs, out long requiredSize, 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, index, dataSize, journalSize, allowExisting)); }
public static Result EnsureApplicationCacheStorage(this FileSystemClient fs, out long requiredSize, out CacheStorageTargetMedia target, Ncm.ApplicationId applicationId, ref ApplicationControlProperty nacp) { if (nacp.CacheStorageSize <= 0) { requiredSize = default; target = default; return(Result.Success); } return(EnsureApplicationCacheStorageImpl(fs, out requiredSize, out target, applicationId, nacp.SaveDataOwnerId.Value, 0, nacp.CacheStorageSize, nacp.CacheStorageJournalSize, true)); }
private static Result GetCacheStorageTargetMediaImpl(this FileSystemClient fs, out CacheStorageTargetMedia target, Ncm.ApplicationId applicationId) { target = CacheStorageTargetMedia.None; var filter = new SaveDataFilter(); filter.SetProgramId(applicationId); filter.SetSaveDataType(SaveDataType.Cache); if (fs.IsSdCardAccessible()) { Result rc = fs.FindSaveDataWithFilter(out _, SaveDataSpaceId.SdCache, ref filter); if (rc.IsFailure() && !ResultFs.TargetNotFound.Includes(rc)) { return(rc); } if (rc.IsSuccess()) { target = CacheStorageTargetMedia.SdCard; } } // Not on the SD card. Check it it's in NAND if (target == CacheStorageTargetMedia.None) { Result rc = fs.FindSaveDataWithFilter(out _, SaveDataSpaceId.User, ref filter); if (rc.IsFailure() && !ResultFs.TargetNotFound.Includes(rc)) { return(rc); } if (rc.IsSuccess()) { target = CacheStorageTargetMedia.Nand; } } return(Result.Success); }
public static Result CreateApplicationCacheStorage(this FileSystemClient fs, out long requiredSize, out CacheStorageTargetMedia target, Ncm.ApplicationId applicationId, ref ApplicationControlProperty nacp, ushort index, long dataSize, long journalSize) { UnsafeHelpers.SkipParamInit(out requiredSize, out target); if (index > nacp.CacheStorageMaxIndex) { return(ResultFs.CacheStorageIndexTooLarge.Log()); } if (dataSize + journalSize > nacp.CacheStorageMaxSizeAndMaxJournalSize) { return(ResultFs.CacheStorageSizeTooLarge.Log()); } Result rc = fs.EnsureApplicationCacheStorage(out requiredSize, out target, applicationId, nacp.SaveDataOwnerId.Value, index, dataSize, journalSize, false); fs.Impl.AbortIfNeeded(rc); return(rc); }
public static Result GetCacheStorageTargetMedia(this FileSystemClient fs, out CacheStorageTargetMedia target, Ncm.ApplicationId applicationId) { return(GetCacheStorageTargetMediaImpl(fs, out target, applicationId)); }
private static Result EnsureApplicationCacheStorageImpl(this FileSystemClient fs, out long requiredSize, out CacheStorageTargetMedia target, Ncm.ApplicationId applicationId, ulong saveDataOwnerId, short index, long dataSize, long journalSize, bool allowExisting) { requiredSize = default; target = CacheStorageTargetMedia.SdCard; Result rc = fs.GetCacheStorageTargetMediaImpl(out CacheStorageTargetMedia targetMedia, applicationId); if (rc.IsFailure()) { return(rc); } long requiredSizeLocal = 0; if (targetMedia == CacheStorageTargetMedia.Nand) { rc = TryCreateCacheStorage(fs, out requiredSizeLocal, SaveDataSpaceId.User, applicationId, saveDataOwnerId, index, dataSize, journalSize, allowExisting); if (rc.IsFailure()) { return(rc); } } else if (targetMedia == CacheStorageTargetMedia.SdCard) { rc = TryCreateCacheStorage(fs, out requiredSizeLocal, SaveDataSpaceId.SdCache, applicationId, saveDataOwnerId, index, dataSize, journalSize, allowExisting); if (rc.IsFailure()) { return(rc); } } // Savedata doesn't exist. Try to create a new one. else { // Try to create the savedata on the SD card first if (fs.IsSdCardAccessible()) { target = CacheStorageTargetMedia.SdCard; Result CreateFuncSdCard() => fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, saveDataOwnerId, index, dataSize, journalSize, SaveDataFlags.None); rc = CreateSaveData(fs, CreateFuncSdCard, ref requiredSizeLocal, 0x4000, dataSize, journalSize); if (rc.IsFailure()) { return(rc); } if (requiredSizeLocal == 0) { requiredSize = 0; return(Result.Success); } } // If the save can't be created on the SD card, try creating it on the User BIS partition requiredSizeLocal = 0; target = CacheStorageTargetMedia.Nand; Result CreateFuncNand() => fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, saveDataOwnerId, index, dataSize, journalSize, SaveDataFlags.None); rc = CreateSaveData(fs, CreateFuncNand, ref requiredSizeLocal, 0x4000, dataSize, journalSize); if (rc.IsFailure()) { return(rc); } if (requiredSizeLocal != 0) { target = CacheStorageTargetMedia.None; requiredSize = requiredSizeLocal; return(ResultFs.InsufficientFreeSpace.Log()); } } requiredSize = 0; return(Result.Success); }