Exemple #1
0
        public static bool CheckPathAccessModes(FileAccessPermissions permissions, AccessModes request)
        {
            if (request.HasFlag(AccessModes.R_OK))
            {
                if (!(permissions.HasFlag(FileAccessPermissions.UserRead) || permissions.HasFlag(FileAccessPermissions.GroupRead) || permissions.HasFlag(FileAccessPermissions.OtherRead)))
                {
                    return(false);
                }
            }

            if (request.HasFlag(AccessModes.W_OK))
            {
                if (!(permissions.HasFlag(FileAccessPermissions.UserWrite) || permissions.HasFlag(FileAccessPermissions.GroupWrite) || permissions.HasFlag(FileAccessPermissions.OtherWrite)))
                {
                    return(false);
                }
            }

            // ReSharper disable once InvertIf
            if (request.HasFlag(AccessModes.X_OK))
            {
                if (!(permissions.HasFlag(FileAccessPermissions.UserExecute) || permissions.HasFlag(FileAccessPermissions.GroupExecute) || permissions.HasFlag(FileAccessPermissions.OtherExecute)))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #2
0
        protected override Errno OnAccessPath(string path, AccessModes mode)
        {
            string[] pieces = _vfs.SplitPath(path);

            if (pieces.Length == 0)
            {
                return(mode.HasFlag(AccessModes.W_OK) ? Errno.EROFS : 0);
            }

            long romSetId = _vfs.GetRomSetId(pieces[0]);

            if (romSetId <= 0)
            {
                return(Errno.ENOENT);
            }

            RomSet romSet = _vfs.GetRomSet(romSetId);

            if (romSet == null)
            {
                return(Errno.ENOENT);
            }

            if (pieces.Length == 1)
            {
                return(mode.HasFlag(AccessModes.W_OK) ? Errno.EROFS : 0);
            }

            CachedMachine machine = _vfs.GetMachine(romSetId, pieces[1]);

            if (machine == null)
            {
                return(Errno.ENOENT);
            }

            if (pieces.Length == 2)
            {
                return(mode.HasFlag(AccessModes.W_OK) ? Errno.EROFS : 0);
            }

            CachedFile file = _vfs.GetFile(machine.Id, pieces[2]);

            if (file != null)
            {
                if (pieces.Length > 3)
                {
                    return(Errno.ENOSYS);
                }

                return(mode.HasFlag(AccessModes.W_OK) ? Errno.EROFS : 0);
            }

            CachedDisk disk = _vfs.GetDisk(machine.Id, pieces[2]);

            if (disk != null)
            {
                if (pieces.Length > 3)
                {
                    return(Errno.ENOSYS);
                }

                return(mode.HasFlag(AccessModes.W_OK) ? Errno.EROFS : 0);
            }

            CachedMedia media = _vfs.GetMedia(machine.Id, pieces[2]);

            if (media == null)
            {
                return(Errno.ENOENT);
            }

            if (pieces.Length > 3)
            {
                return(Errno.ENOSYS);
            }

            return(mode.HasFlag(AccessModes.W_OK) ? Errno.EROFS : 0);
        }