Ejemplo n.º 1
0
        protected Result ValidateWriteParams(long offset, int size, OpenMode openMode, out bool isResizeNeeded)
        {
            isResizeNeeded = false;

            if (!openMode.HasFlag(OpenMode.Write))
            {
                return(ResultFs.InvalidOpenModeForWrite.Log());
            }

            Result rc = GetSize(out long fileSize);

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

            if (offset + size > fileSize)
            {
                isResizeNeeded = true;

                if (!openMode.HasFlag(OpenMode.AllowAppend))
                {
                    return(ResultFs.FileExtensionWithoutOpenModeAllowAppend.Log());
                }
            }

            return(Result.Success);
        }
Ejemplo n.º 2
0
        protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
        {
            file = default;

            FsPath fullPath;

            unsafe { _ = &fullPath; } // workaround for CS0165

            Result rc = ResolveFullPath(fullPath.Str, path);

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

            lock (Locker)
            {
                rc = BaseFs.OpenFile(out IFile baseFile, fullPath, mode);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                file = new DirectorySaveDataFile(this, baseFile, mode);

                if (mode.HasFlag(OpenMode.Write))
                {
                    OpenWritableFileCount++;
                }

                return(Result.Success);
            }
        }
        protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
        {
            UnsafeHelpers.SkipParamInit(out file);

            Unsafe.SkipInit(out FsPath fullPath);

            Result rc = ResolveFullPath(fullPath.Str, path);

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

            lock (Locker)
            {
                rc = BaseFs.OpenFile(out IFile baseFile, fullPath, mode);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                file = new DirectorySaveDataFile(this, baseFile, mode);

                if (mode.HasFlag(OpenMode.Write))
                {
                    OpenWritableFileCount++;
                }

                return(Result.Success);
            }
        }
Ejemplo n.º 4
0
        protected Result ValidateReadParams(out long bytesToRead, long offset, int size, OpenMode openMode)
        {
            bytesToRead = default;

            if (!openMode.HasFlag(OpenMode.Read))
            {
                return(ResultFs.InvalidOpenModeForRead.Log());
            }

            Result rc = GetSize(out long fileSize);

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

            if (offset > fileSize)
            {
                return(ResultFs.ValueOutOfRange.Log());
            }

            bytesToRead = Math.Min(fileSize - offset, size);

            return(Result.Success);
        }
        protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
        {
            file = default;

            if (!IsInitialized)
            {
                return(ResultFs.PreconditionViolation.Log());
            }

            if (!mode.HasFlag(OpenMode.Read) && !mode.HasFlag(OpenMode.Write))
            {
                return(ResultFs.InvalidArgument.Log());
            }

            int entryIndex = MetaData.FindEntry(path.Slice(1));

            if (entryIndex < 0)
            {
                return(ResultFs.PathNotFound.Log());
            }

            ref T entry = ref MetaData.GetEntry(entryIndex);
Ejemplo n.º 6
0
        public Result OpenFile(out FileAccessor file, U8Span path, OpenMode mode)
        {
            UnsafeHelpers.SkipParamInit(out file);

            Result rc = CheckPath(new U8Span(_mountName.Name), path);

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

            IFile iFile = null;

            try
            {
                rc = _fileSystem.OpenFile(out iFile, path, mode);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                var fileAccessor = new FileAccessor(FsClient, ref iFile, this, mode);

                using (ScopedLock.Lock(ref _openListLock))
                {
                    _openFiles.AddLast(fileAccessor);
                }

                if (_isPathCacheAttached)
                {
                    if (mode.HasFlag(OpenMode.AllowAppend))
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }

                file = Shared.Move(ref fileAccessor);
                return(Result.Success);
            }
            finally
            {
                iFile?.Dispose();
            }
        }
Ejemplo n.º 7
0
        public IFile OpenFile(string path, OpenMode mode)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                IFile baseFile = BaseFs.OpenFile(fullPath, mode);
                var   file     = new DirectorySaveDataFile(this, baseFile);

                if (mode.HasFlag(OpenMode.Write))
                {
                    OpenWritableFileCount++;
                }

                return(file);
            }
        }
Ejemplo n.º 8
0
        protected override Result OpenFileImpl(out IFile file, string path, OpenMode mode)
        {
            file = default;
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                Result rc = BaseFs.OpenFile(out IFile baseFile, fullPath, mode);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                file = new DirectorySaveDataFile(this, baseFile, mode);

                if (mode.HasFlag(OpenMode.Write))
                {
                    OpenWritableFileCount++;
                }

                return(Result.Success);
            }
        }
Ejemplo n.º 9
0
 private static FileShare GetFileShare(OpenMode mode)
 {
     return(mode.HasFlag(OpenMode.Write) ? FileShare.Read : FileShare.ReadWrite);
 }