Ejemplo n.º 1
0
            static Result Mount(FileSystemClientImpl fs, U8Span mountName, BisPartitionId partitionId)
            {
                Result rc = fs.CheckMountNameAcceptingReservedMountName(mountName);

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

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

                // Nintendo doesn't use the provided rootPath
                FspPath.CreateEmpty(out FspPath sfPath);

                ReferenceCountedDisposable <IFileSystemSf> fileSystem = null;

                try
                {
                    rc = fsProxy.Target.OpenBisFileSystem(out fileSystem, in sfPath, partitionId);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    var nameGenerator     = new BisCommonMountNameGenerator(partitionId);
                    var fileSystemAdapter = new FileSystemServiceObjectAdapter(fileSystem);

                    return(fs.Fs.Register(mountName, fileSystemAdapter, nameGenerator));
                }
                finally
                {
                    fileSystem?.Dispose();
                }
            }
Ejemplo n.º 2
0
        public static bool IsValidMountName(this FileSystemClientImpl fs, U8Span name)
        {
            if (name.IsEmpty())
            {
                return(false);
            }

            // Check for a single-letter mount name
            if ((name.Length <= 1 || name[1] == 0) &&
                ('a' <= name[0] && name[0] <= 'z' || 'A' <= name[0] && name[0] <= 'Z'))
            {
                return(false);
            }

            // Check for mount or directory separators
            int length = 0;

            for (int i = 0; i < name.Length && name[i] != 0; i++)
            {
                if (PathTool.IsDriveSeparator(name[i]) || PathTool.IsSeparator(name[i]))
                {
                    return(false);
                }

                if (++length > PathTools.MountNameLengthMax)
                {
                    return(false);
                }
            }

            // Todo: VerifyUtf8String
            return(true);
        }
Ejemplo n.º 3
0
        internal static Result FindFileSystem(this FileSystemClientImpl fs, out FileSystemAccessor fileSystem,
                                              out U8Span subPath, U8Span path)
        {
            UnsafeHelpers.SkipParamInit(out fileSystem);
            subPath = default;

            if (path.IsNull())
            {
                return(ResultFs.NullptrArgument.Log());
            }

            int hostMountNameLen = StringUtils.GetLength(CommonPaths.HostRootFileSystemMountName);

            if (StringUtils.Compare(path, CommonPaths.HostRootFileSystemMountName, hostMountNameLen) == 0)
            {
                return(ResultFs.NotMounted.Log());
            }

            Result rc = GetMountNameAndSubPath(out MountName mountName, out subPath, path);

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

            return(fs.Find(out fileSystem, new U8Span(mountName.Name)));
        }
Ejemplo n.º 4
0
        public static Result CheckMountNameAcceptingReservedMountName(this FileSystemClientImpl fs, U8Span name)
        {
            if (name.IsNull())
            {
                return(ResultFs.NullptrArgument.Log());
            }

            if (!fs.IsValidMountName(name))
            {
                return(ResultFs.InvalidMountName.Log());
            }

            return(Result.Success);
        }
Ejemplo n.º 5
0
        private static Result MountSaveDataImpl(this FileSystemClientImpl fs, U8Span mountName, SaveDataSpaceId spaceId,
                                                ProgramId programId, UserId userId, SaveDataType type, bool openReadOnly, ushort index)
        {
            Result rc = fs.CheckMountName(mountName);

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

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

            rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, programId, type, userId, 0, index);
            if (rc.IsFailure())
            {
                return(rc);
            }

            ReferenceCountedDisposable <IFileSystemSf> fileSystem = null;

            try
            {
                if (openReadOnly)
                {
                    rc = fsProxy.Target.OpenReadOnlySaveDataFileSystem(out fileSystem, spaceId, in attribute);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }
                }
                else
                {
                    rc = fsProxy.Target.OpenSaveDataFileSystem(out fileSystem, spaceId, in attribute);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }
                }

                var fileSystemAdapter = new FileSystemServiceObjectAdapter(fileSystem);

                return(fs.Fs.Register(mountName, fileSystemAdapter, fileSystemAdapter, null, false, true));
            }
            finally
            {
                fileSystem?.Dispose();
            }
        }
Ejemplo n.º 6
0
        public static Result Unmount(this FileSystemClientImpl fs, U8Span mountName)
        {
            Result rc = fs.Find(out FileSystemAccessor fileSystem, mountName);

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

            if (fileSystem.IsFileDataCacheAttachable())
            {
                // Todo: Data cache purge
            }

            fs.Unregister(mountName);
            return(Result.Success);
        }
Ejemplo n.º 7
0
        public static Result IsMounted(this FileSystemClientImpl fs, out bool isMounted, U8Span mountName)
        {
            UnsafeHelpers.SkipParamInit(out isMounted);

            Result rc = fs.Find(out _, mountName);

            if (rc.IsFailure())
            {
                if (!ResultFs.NotMounted.Includes(rc))
                {
                    return(rc);
                }

                isMounted = false;
            }
            else
            {
                isMounted = true;
            }

            return(Result.Success);
        }
Ejemplo n.º 8
0
        private static Result MountBis(this FileSystemClientImpl fs, U8Span mountName, BisPartitionId partitionId,
                                       U8Span rootPath)
        {
            Result rc;

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

                Span <byte> logBuffer = stackalloc byte[0x300];
                var         idString  = new IdString();
                var         sb        = new U8StringBuilder(logBuffer, true);

                sb.Append(LogName).Append(mountName).Append(LogQuote)
                .Append(LogBisPartitionId).Append(idString.ToString(partitionId))
                .Append(LogPath).Append(rootPath).Append(LogQuote);

                fs.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer));
            }
            else
            {
                rc = Mount(fs, mountName, partitionId);
            }

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

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

            return(Result.Success);
Ejemplo n.º 9
0
 public static bool IsUsedReservedMountName(this FileSystemClientImpl fs, U8Span name)
 {
     return(name.Length > 0 && name[0] == CommonPaths.ReservedMountNamePrefixCharacter);
 }
Ejemplo n.º 10
0
 public static ReferenceCountedDisposable <IFileSystemProxy> GetFileSystemProxyServiceObject(
     this FileSystemClientImpl fs)
 {
     ref FileSystemProxyServiceObjectGlobals g = ref fs.Globals.FileSystemProxyServiceObject;
Ejemplo n.º 11
0
 public static void Unregister(this FileSystemClientImpl fs, U8Span name)
 {
     fs.Globals.UserMountTable.MountTable.Unmount(name);
 }
Ejemplo n.º 12
0
 public static Result Find(this FileSystemClientImpl fs, out FileSystemAccessor fileSystem, U8Span name)
 {
     return(fs.Globals.UserMountTable.MountTable.Find(out fileSystem, name));
 }
Ejemplo n.º 13
0
 public static Result Register(this FileSystemClientImpl fs, FileSystemAccessor fileSystem)
 {
     return(fs.Globals.UserMountTable.MountTable.Mount(fileSystem));
 }
Ejemplo n.º 14
0
 internal static Result ReadSaveDataFileSystemExtraData(this FileSystemClientImpl fs,
                                                        out SaveDataExtraData extraData, SaveDataSpaceId spaceId, in SaveDataAttribute attribute)
Ejemplo n.º 15
0
 internal static Result ReadSaveDataFileSystemExtraData(this FileSystemClientImpl fs,
                                                        out SaveDataExtraData extraData, SaveDataSpaceId spaceId, ulong saveDataId)
 {
     throw new NotImplementedException();
 }