Пример #1
0
        public static unsafe int ReadFile(FileHandle fileHandle, byte[] bufferToReceiveData)
        {
            int  bytesRead;
            bool readSuccess;

            fixed(byte *pointerToBufferForReading = bufferToReceiveData)
            readSuccess = Win32.ReadFile(fileHandle, pointerToBufferForReading, bufferToReceiveData.Length, out bytesRead, IntPtr.Zero) != 0;

            if (!readSuccess)
            {
                throw new FileSystemException(fileHandle.FileFullName, new Win32Exception(Marshal.GetLastWin32Error()).Message);
            }

            return(bytesRead);
        }
Пример #2
0
        public static unsafe long GetFilePointer(FileHandle fileHandle)
        {
            int lowOffsetDword = 0, highOffsetDword = 0;

            lowOffsetDword = Win32.SetFilePointer(fileHandle, lowOffsetDword, &highOffsetDword, (int)SeekOrigin.Current);
            if (lowOffsetDword != (int)Win32.INVALID_HANDLE_VALUE)
            {
                return(Data.JoinToLong(highOffsetDword, lowOffsetDword));
            }

            var errorCode = Marshal.GetLastWin32Error();

            if (errorCode != Win32.NO_ERROR)
            {
                throw new FileSystemException(fileHandle.FileFullName, new Win32Exception(errorCode).Message);
            }

            return(Data.JoinToLong(highOffsetDword, lowOffsetDword));
        }
Пример #3
0
        public static unsafe bool SetFilePointer(FileHandle fileHandle, long offset)
        {
            var lowOffsetDword  = (int)offset;
            var highOffsetDword = (int)(offset >> 32);

            lowOffsetDword = Win32.SetFilePointer(fileHandle, lowOffsetDword, &highOffsetDword, (int)SeekOrigin.Begin);

            if (lowOffsetDword != (int)Win32.INVALID_HANDLE_VALUE)
            {
                return(true);
            }

            var errorCode = Marshal.GetLastWin32Error();

            if (errorCode != Win32.NO_ERROR)
            {
                throw new FileSystemException(fileHandle.FileFullName, new Win32Exception(errorCode).Message);
            }

            return(true);
        }