Ejemplo n.º 1
0
        public void Reset()
        {
            lock (this.syncRoot)
            {
                if (this.state == State.Disposed)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed());
                }

                if (this.current != null)
                {
                    this.current.Detach();
                    this.current = null;
                }

                if ((this.readContext != null) &&
                    (!this.readContext.IsInvalid))
                {
                    this.readContext.Close();
                    this.readContext = null;
                }

                this.state = State.BeforeFirst;
            }
        }
        public static bool ReadLogRecordSync(SafeMarshalContext pvMarshal,
                                             [In] ref ulong plsnFirst,
                                             CLFS_CONTEXT_MODE ecxMode,
                                             out byte* ppvReadBuffer,
                                             out int pcbReadBuffer,
                                             out byte peRecordType,
                                             out ulong plsnUndoNext,
                                             out ulong plsnPrevious,
                                             out SafeReadContext ppvReadContext)
        {
            if (!_ReadLogRecord(pvMarshal,
                                ref plsnFirst,
                                ecxMode,
                                out ppvReadBuffer,
                                out pcbReadBuffer,
                                out peRecordType,
                                out plsnUndoNext,
                                out plsnPrevious,
                                out ppvReadContext,
                                null))
            {
                uint errorCode = (uint)Marshal.GetLastWin32Error();
                Utility.CloseInvalidOutSafeHandle(ppvReadContext);
                ppvReadContext = null;
                if (errorCode == Error.ERROR_IO_PENDING)
                {
                    // The CLFS API was called with a NULL overlapped, so the operation should not be asynchronous.
                    // This means that CLFS has a bug, so it is not safe to continue processing.
                    DiagnosticUtility.FailFast("No async in ReadLogRecordSync");
                }
                switch (errorCode)
                {
                    case Error.ERROR_HANDLE_EOF:
                        return false;

                    case Error.ERROR_NOT_FOUND:
                    case Error.ERROR_LOG_START_OF_LOG:
                    case Error.ERROR_LOG_BLOCK_INVALID:
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentInvalid(SR.Argument_InvalidStartSequenceNumber));

                    case Error.ERROR_LOG_BLOCK_INCOMPLETE:
                    case Error.ERROR_INVALID_HANDLE:
                    case Error.ERROR_ACCESS_DENIED:
                    case Error.ERROR_INVALID_PARAMETER:
                    case Error.ERROR_IO_DEVICE:
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ExceptionForKnownCode(errorCode));

                    default:
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ExceptionForUnknownCode(errorCode));
                }
            }

            return true;
        }
        public static bool ReadNextLogRecordSync(SafeReadContext pvReadContext,
                                                 out byte* ppvReadBuffer,
                                                 out int pcbReadBuffer,
                                                 ref byte peRecordType,
                                                 out ulong plsnUndoNext,
                                                 out ulong plsnPrevious,
                                                 out ulong plsnRecord)
        {
            if (!_ReadNextLogRecord(pvReadContext,
                                    out ppvReadBuffer,
                                    out pcbReadBuffer,
                                    ref peRecordType,
                                    IntPtr.Zero,
                                    out plsnUndoNext,
                                    out plsnPrevious,
                                    out plsnRecord,
                                    null))
            {
                uint errorCode = (uint)Marshal.GetLastWin32Error();
                if (errorCode == Error.ERROR_IO_PENDING)
                {
                    // The CLFS API was called with a NULL overlapped, so the operation should not be asynchronous.
                    // This means that CLFS has a bug, so it is not safe to continue processing.
                    DiagnosticUtility.FailFast("No async in ReadNextLogRecordSync");
                }
                switch (errorCode)
                {
                    case Error.ERROR_HANDLE_EOF:
                    case Error.ERROR_LOG_START_OF_LOG:
                        return false;

                    case Error.ERROR_LOG_BLOCK_INCOMPLETE:
                    case Error.ERROR_INVALID_HANDLE:
                    case Error.ERROR_ACCESS_DENIED:
                    case Error.ERROR_INVALID_PARAMETER:
                    case Error.ERROR_IO_DEVICE:
                    case Error.ERROR_LOG_READ_CONTEXT_INVALID:
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ExceptionForKnownCode(errorCode));

                    default:
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ExceptionForUnknownCode(errorCode));
                }
            }

            return true;
        }
        public static bool ReadLogRestartAreaSync(
            SafeMarshalContext pvMarshal,
            out byte* ppvRestartBuffer,
            out int pcbRestartBuffer,
            out ulong plsn,
            out SafeReadContext ppvContext)
        {
            if (!_ReadLogRestartArea(pvMarshal,
                                     out ppvRestartBuffer,
                                     out pcbRestartBuffer,
                                     out plsn,
                                     out ppvContext,
                                     null))
            {
                uint errorCode = (uint)Marshal.GetLastWin32Error();
                Utility.CloseInvalidOutSafeHandle(ppvContext);
                ppvContext = null;
                if (errorCode == Error.ERROR_IO_PENDING)
                {
                    // The CLFS API was called with a NULL overlapped, so the operation should not be asynchronous.
                    // This means that CLFS has a bug, so it is not safe to continue processing.
                    DiagnosticUtility.FailFast("Unexpected IO in progress (ReadLogRA)");
                }
                switch (errorCode)
                {
                    case Error.ERROR_LOG_NO_RESTART:
                        return false;

                    case Error.ERROR_LOG_BLOCK_INCOMPLETE:
                    case Error.ERROR_INVALID_HANDLE:
                    case Error.ERROR_ACCESS_DENIED:
                    case Error.ERROR_INVALID_PARAMETER:
                    case Error.ERROR_IO_DEVICE:
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ExceptionForKnownCode(errorCode));

                    default:
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ExceptionForUnknownCode(errorCode));
                }
            }

            return true;
        }
 extern static bool _ReadNextLogRecord(
     SafeReadContext pvReadContext,
     out byte* ppvReadBuffer,
     out int pcbReadBuffer,
     ref byte peRecordType,
     IntPtr plsnUser, // NOTE: Not used: [In] ref ulong
     out ulong plsnUndoNext,
     out ulong plsnPrevious,
     out ulong plsnRecord,
     NativeOverlapped* pOverlapped);
 extern static bool _ReadLogRecord(
     SafeMarshalContext pvMarshal,
     [In] ref ulong plsnFirst,
     CLFS_CONTEXT_MODE ecxMode,
     out byte* ppvReadBuffer,
     out int pcbReadBuffer,
     out byte peRecordType,
     out ulong plsnUndoNext,
     out ulong plsnPrevious,
     out SafeReadContext ppvReadContext,
     NativeOverlapped* pOverlapped);
 extern static bool _ReadPreviousLogRestartArea(
     SafeReadContext pvReadContext,
     out byte* ppvRestartBuffer,
     out int pcbRestartBuffer,
     out ulong plsnRestart,
     NativeOverlapped* pOverlapped);
 extern static bool _ReadLogRestartArea(
     SafeMarshalContext pvMarshal,
     out byte* ppvRestartBuffer,
     out int pcbRestartBuffer,
     out ulong plsn,
     out SafeReadContext ppvContext,
     NativeOverlapped* overlapped);