Beispiel #1
0
            static Result Mount(FileSystemClient fs, U8Span mountName, GameCardHandle handle,
                                GameCardPartition partitionId)
            {
                Result rc = fs.Impl.CheckMountNameAcceptingReservedMountName(mountName);

                if (rc.IsFailure())
                {
                    return(rc);
                }

                using ReferenceCountedDisposable <IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();

                ReferenceCountedDisposable <IFileSystemSf> fileSystem = null;

                try
                {
                    rc = fsProxy.Target.OpenGameCardFileSystem(out fileSystem, handle, partitionId);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    var fileSystemAdapter  = new FileSystemServiceObjectAdapter(fileSystem);
                    var mountNameGenerator = new GameCardCommonMountNameGenerator(handle, partitionId);
                    return(fs.Register(mountName, fileSystemAdapter, mountNameGenerator));
                }
                finally
                {
                    fileSystem?.Dispose();
                }
            }
Beispiel #2
0
            private static char GetPartitionMountLetter(GameCardPartition partition)
            {
                switch (partition)
                {
                case GameCardPartition.Update: return('U');

                case GameCardPartition.Normal: return('N');

                case GameCardPartition.Secure: return('S');

                default:
                    throw new ArgumentOutOfRangeException(nameof(partition), partition, null);
                }
            }
Beispiel #3
0
        private static ReadOnlySpan <byte> GetGameCardMountNameSuffix(GameCardPartition partition)
        {
            switch (partition)
            {
            case GameCardPartition.Update: return(CommonMountNames.GameCardFileSystemMountNameUpdateSuffix);

            case GameCardPartition.Normal: return(CommonMountNames.GameCardFileSystemMountNameNormalSuffix);

            case GameCardPartition.Secure: return(CommonMountNames.GameCardFileSystemMountNameSecureSuffix);

            default:
                Abort.UnexpectedDefault();
                return(default);
            }
        }
Beispiel #4
0
        public Result OpenGameCardFileSystem(out IFileSystem fileSystem, GameCardHandle handle,
                                             GameCardPartition partitionId)
        {
            Result rc;
            int    tries = 0;

            do
            {
                rc = FsCreators.GameCardFileSystemCreator.Create(out fileSystem, handle, partitionId);

                if (!ResultFs.DataCorrupted.Includes(rc))
                {
                    break;
                }

                tries++;
            } while (tries < 2);

            return(rc);
        }
Beispiel #5
0
        public Result Create(out IFileSystem fileSystem, GameCardHandle handle, GameCardPartition partitionType)
        {
            // Use the old xci code temporarily

            UnsafeHelpers.SkipParamInit(out fileSystem);

            Result rc = GameCard.GetXci(out Xci xci, handle);

            if (rc.IsFailure())
            {
                return(rc);
            }

            if (!xci.HasPartition((XciPartitionType)partitionType))
            {
                return(ResultFs.PartitionNotFound.Log());
            }

            fileSystem = xci.OpenPartition((XciPartitionType)partitionType);
            return(Result.Success);
        }
Beispiel #6
0
        public static Result MountGameCardPartition(this FileSystemClient fs, U8Span mountName, GameCardHandle handle,
                                                    GameCardPartition partitionId)
        {
            Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName);

            if (rc.IsFailure())
            {
                return(rc);
            }

            IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();

            rc = fsProxy.OpenGameCardFileSystem(out IFileSystem cardFs, handle, partitionId);
            if (rc.IsFailure())
            {
                return(rc);
            }

            var mountNameGenerator = new GameCardCommonMountNameGenerator(handle, partitionId);

            return(fs.Register(mountName, cardFs, mountNameGenerator));
        }
Beispiel #7
0
        public static Result MountGameCardPartition(this FileSystemClient fs, U8Span mountName, GameCardHandle handle,
                                                    GameCardPartition partitionId)
        {
            Result      rc;
            Span <byte> logBuffer = stackalloc byte[0x60];

            if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System))
            {
                Tick start = fs.Hos.Os.GetSystemTick();
                rc = Mount(fs, mountName, handle, partitionId);
                Tick end = fs.Hos.Os.GetSystemTick();

                var idString = new IdString();
                var sb       = new U8StringBuilder(logBuffer, true);

                sb.Append(LogName).Append(mountName).Append(LogQuote)
                .Append(LogGameCardHandle).AppendFormat(handle.Value)
                .Append(LogGameCardPartition).Append(idString.ToString(partitionId));

                fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer));
            }
            else
            {
                rc = Mount(fs, mountName, handle, partitionId);
            }
            fs.Impl.AbortIfNeeded(rc);
            if (rc.IsFailure())
            {
                return(rc);
            }

            if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System))
            {
                fs.Impl.EnableFileSystemAccessorAccessLog(mountName);
            }

            return(Result.Success);
Beispiel #8
0
 public GameCardCommonMountNameGenerator(GameCardHandle handle, GameCardPartition partitionId)
 {
     Handle      = handle;
     PartitionId = partitionId;
 }
Beispiel #9
0
 public Result OpenGameCardFileSystem(out IFileSystem fileSystem, GameCardHandle handle,
                                      GameCardPartition partitionId)
 {
     return(FsCreators.GameCardFileSystemCreator.Create(out fileSystem, handle, partitionId));
 }