Exemple #1
0
        public unsafe bool Read(long pageNumber, byte *buffer, int count)
        {
            if (_fdReads == -1)
            {
                _fdReads = Syscall.open(_filename, OpenFlags.O_RDONLY);
                if (_fdReads == -1)
                {
                    PosixHelper.ThrowLastError(Marshal.GetLastWin32Error());
                }
            }
            long position = pageNumber * AbstractPager.PageSize;

            while (count > 0)
            {
                var result = Syscall.pread(_fdReads, buffer, (ulong)count, position);
                if (result == 0)                 //eof
                {
                    return(false);
                }
                count    -= (int)result;
                buffer   += result;
                position += result;
            }
            return(true);
        }
        public unsafe bool Read(byte *buffer, long numOfBytes, long offsetInFile)
        {
            if (_fdReads == -1)
            {
                _fdReads = Syscall.open(_filename.FullPath, OpenFlags.O_RDONLY, FilePermissions.S_IRUSR);
                if (_fdReads == -1)
                {
                    var err = Marshal.GetLastWin32Error();
                    Syscall.ThrowLastError(err, "when opening " + _filename);
                }
            }

            while (numOfBytes > 0)
            {
                var result = Syscall.pread(_fdReads, buffer, (ulong)numOfBytes, offsetInFile);
                if (result == 0) //eof
                {
                    return(false);
                }
                numOfBytes   -= result;
                buffer       += result;
                offsetInFile += result;
            }
            return(true);
        }
Exemple #3
0
        public unsafe bool Read(long pageNumber, byte *buffer, int count)
        {
            if (_fdReads == -1)
            {
                _fdReads = Syscall.open(_filename, OpenFlags.O_RDONLY, FilePermissions.S_IRUSR);
                if (_fdReads == -1)
                {
                    var err = Marshal.GetLastWin32Error();
                    PosixHelper.ThrowLastError(err, "when opening " + _filename);
                }
            }
            long position = pageNumber * _options.PageSize;

            while (count > 0)
            {
                var result = Syscall.pread(_fdReads, buffer, (ulong)count, position);
                if (result == 0) //eof
                {
                    return(false);
                }
                count    -= (int)result;
                buffer   += result;
                position += result;
            }
            return(true);
        }