update for HEAD-2003091401
[reactos.git] / ntoskrnl / io / errlog.c
1 /* $Id$
2  *
3  * COPYRIGHT:       See COPYING in the top level directory
4  * PROJECT:         ReactOS kernel
5  * FILE:            ntoskrnl/io/errlog.c
6  * PURPOSE:         Error logging
7  * PROGRAMMER:      David Welch (welch@cwcom.net)
8  * UPDATE HISTORY:
9  *                  Created 22/05/98
10  */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ddk/ntddk.h>
15
16 #include <internal/port.h>
17
18 //#define NDEBUG
19 #include <internal/debug.h>
20
21 /* TYPES *********************************************************************/
22
23 #ifndef __USE_W32API
24 typedef struct _IO_ERROR_LOG_PACKET
25 {
26    UCHAR MajorFunctionCode;
27    UCHAR RetryCount;
28    USHORT DumpDataSize;
29    USHORT NumberOfStrings;
30    USHORT StringOffset;
31    USHORT EventCategory;
32    NTSTATUS ErrorCode;
33    ULONG UniqueErrorValue;
34    NTSTATUS FinalStatus;
35    ULONG SequenceNumber;
36    ULONG IoControlCode;
37    LARGE_INTEGER DeviceOffset;
38    ULONG DumpData[1];
39 } IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
40 #endif
41
42 typedef struct _ERROR_LOG_ENTRY
43 {
44   ULONG EntrySize;
45 } ERROR_LOG_ENTRY, *PERROR_LOG_ENTRY;
46
47
48 /* GLOBALS *******************************************************************/
49
50 static KSPIN_LOCK IopAllocationLock;
51 static ULONG IopTotalLogSize;
52
53
54 /* FUNCTIONS *****************************************************************/
55
56 NTSTATUS
57 IopInitErrorLog (VOID)
58 {
59   IopTotalLogSize = 0;
60   KeInitializeSpinLock (&IopAllocationLock);
61
62   return STATUS_SUCCESS;
63 }
64
65
66 /*
67  * @implemented
68  */
69 PVOID STDCALL
70 IoAllocateErrorLogEntry (IN PVOID IoObject,
71                          IN UCHAR EntrySize)
72 {
73   PERROR_LOG_ENTRY LogEntry;
74   ULONG LogEntrySize;
75   KIRQL Irql;
76
77   DPRINT1 ("IoAllocateErrorLogEntry() called\n");
78
79   if (IoObject == NULL)
80     return NULL;
81
82   KeAcquireSpinLock (&IopAllocationLock,
83                      &Irql);
84
85   if (IopTotalLogSize > PAGE_SIZE)
86     {
87       KeReleaseSpinLock (&IopAllocationLock,
88                          Irql);
89       return NULL;
90     }
91
92   LogEntrySize = sizeof(ERROR_LOG_ENTRY) + EntrySize;
93   LogEntry = ExAllocatePool (NonPagedPool,
94                              LogEntrySize);
95   if (LogEntry == NULL)
96     {
97       KeReleaseSpinLock (&IopAllocationLock,
98                          Irql);
99       return NULL;
100     }
101
102   IopTotalLogSize += EntrySize;
103
104   LogEntry->EntrySize = LogEntrySize;
105
106   KeReleaseSpinLock (&IopAllocationLock,
107                      Irql);
108
109   return (PVOID)((ULONG_PTR)LogEntry + sizeof(ERROR_LOG_ENTRY));
110 }
111
112
113 /*
114  * @unimplemented
115  */
116 VOID STDCALL
117 IoWriteErrorLogEntry (IN PVOID ElEntry)
118 {
119   PERROR_LOG_ENTRY LogEntry;
120   KIRQL Irql;
121
122   DPRINT1 ("IoWriteErrorLogEntry() called\n");
123
124   LogEntry = (PERROR_LOG_ENTRY)((ULONG_PTR)ElEntry - sizeof(ERROR_LOG_ENTRY));
125
126
127   /* FIXME: Write log entry to the error log port or keep it in a list */
128
129
130   /* Release error log entry */
131   KeAcquireSpinLock (&IopAllocationLock,
132                      &Irql);
133
134   IopTotalLogSize -= LogEntry->EntrySize;
135   ExFreePool (LogEntry);
136
137   KeReleaseSpinLock (&IopAllocationLock,
138                      Irql);
139 }
140
141 /* EOF */