1 /*++
2 
3 Copyright (c) 1989-2000 Microsoft Corporation
4 
5 Module Name:
6 
7     FatData.c
8 
9 Abstract:
10 
11     This module declares the global data used by the Fat file system.
12 
13 
14 --*/
15 
16 #ifndef _FATDATA_
17 #define _FATDATA_
18 
19 //
20 //  The global fsd data record, and a global zero large integer
21 //
22 
23 extern FAT_DATA FatData;
24 
25 extern IO_STATUS_BLOCK FatGarbageIosb;
26 
27 extern NPAGED_LOOKASIDE_LIST FatIrpContextLookasideList;
28 extern NPAGED_LOOKASIDE_LIST FatNonPagedFcbLookasideList;
29 extern NPAGED_LOOKASIDE_LIST FatEResourceLookasideList;
30 
31 extern SLIST_HEADER FatCloseContextSList;
32 extern FAST_MUTEX FatCloseQueueMutex;
33 
34 extern PDEVICE_OBJECT FatDiskFileSystemDeviceObject;
35 extern PDEVICE_OBJECT FatCdromFileSystemDeviceObject;
36 
37 extern LARGE_INTEGER FatLargeZero;
38 extern LARGE_INTEGER FatMaxLarge;
39 extern LARGE_INTEGER Fat30Milliseconds;
40 extern LARGE_INTEGER Fat100Milliseconds;
41 extern LARGE_INTEGER FatOneSecond;
42 extern LARGE_INTEGER FatOneDay;
43 extern LARGE_INTEGER FatJanOne1980;
44 extern LARGE_INTEGER FatDecThirtyOne1979;
45 
46 extern FAT_TIME_STAMP FatTimeJanOne1980;
47 
48 extern LARGE_INTEGER FatMagic10000;
49 #define FAT_SHIFT10000 13
50 
51 extern LARGE_INTEGER FatMagic86400000;
52 #define FAT_SHIFT86400000 26
53 
54 #define FatConvert100nsToMilliseconds(LARGE_INTEGER) (                      \
55     RtlExtendedMagicDivide( (LARGE_INTEGER), FatMagic10000, FAT_SHIFT10000 )\
56     )
57 
58 #define FatConvertMillisecondsToDays(LARGE_INTEGER) (                       \
59     RtlExtendedMagicDivide( (LARGE_INTEGER), FatMagic86400000, FAT_SHIFT86400000 ) \
60     )
61 
62 #define FatConvertDaysToMilliseconds(DAYS) (                                \
63     Int32x32To64( (DAYS), 86400000 )                                        \
64     )
65 
66 //
67 //  Reserve MDL for paging file io forward progress.
68 //
69 
70 #define FAT_RESERVE_MDL_SIZE    16
71 
72 #ifndef __REACTOS__
73 __volatile extern PMDL FatReserveMdl;
74 #else
75 extern __volatile PMDL FatReserveMdl;
76 #endif
77 extern KEVENT FatReserveEvent;
78 
79 //
80 //  The global structure used to contain our fast I/O callbacks
81 //
82 
83 extern FAST_IO_DISPATCH FatFastIoDispatch;
84 
85 //
86 //  Global to store disk IO accounting Enabled/Disabled state
87 //
88 
89 extern LOGICAL FatDiskAccountingEnabled;
90 
91 //
92 // Read ahead amount used for normal data files
93 //
94 
95 #define READ_AHEAD_GRANULARITY           (0x10000)
96 
97 //
98 //  Define maximum number of parallel Reads or Writes that will be generated
99 //  per one request.
100 //
101 
102 #define FAT_MAX_IO_RUNS_ON_STACK        ((ULONG) 5)
103 
104 //
105 //  Define the maximum number of delayed closes.
106 //
107 
108 #define FAT_MAX_DELAYED_CLOSES          ((ULONG)16)
109 
110 extern ULONG FatMaxDelayedCloseCount;
111 
112 //
113 //  The maximum chunk size we use when defragmenting files.
114 //
115 
116 #define FAT_DEFAULT_DEFRAG_CHUNK_IN_BYTES       (0x10000)
117 
118 //
119 // Define constant for time rounding.
120 //
121 
122 #define TenMSec (10*1000*10)
123 #define TwoSeconds (2*1000*1000*10)
124 #define AlmostTenMSec (TenMSec - 1)
125 #define AlmostTwoSeconds (TwoSeconds - 1)
126 
127 // too big #define HighPartPerDay (24*60*60*1000*1000*10 >> 32)
128 
129 #define HighPartPerDay (52734375 >> 18)
130 
131 //
132 //  The global Fat debug level variable, its values are:
133 //
134 //      0x00000000      Always gets printed (used when about to bug check)
135 //
136 //      0x00000001      Error conditions
137 //      0x00000002      Debug hooks
138 //      0x00000004      Catch exceptions before completing Irp
139 //      0x00000008
140 //
141 //      0x00000010
142 //      0x00000020
143 //      0x00000040
144 //      0x00000080
145 //
146 //      0x00000100
147 //      0x00000200
148 //      0x00000400
149 //      0x00000800
150 //
151 //      0x00001000
152 //      0x00002000
153 //      0x00004000
154 //      0x00008000
155 //
156 //      0x00010000
157 //      0x00020000
158 //      0x00040000
159 //      0x00080000
160 //
161 //      0x00100000
162 //      0x00200000
163 //      0x00400000
164 //      0x00800000
165 //
166 //      0x01000000
167 //      0x02000000
168 //      0x04000000
169 //      0x08000000
170 //
171 //      0x10000000
172 //      0x20000000
173 //      0x40000000
174 //      0x80000000
175 //
176 
177 
178 #ifdef FASTFATDBG
179 
180 #define DEBUG_TRACE_ERROR                (0x00000001)
181 #define DEBUG_TRACE_DEBUG_HOOKS          (0x00000002)
182 #define DEBUG_TRACE_CATCH_EXCEPTIONS     (0x00000004)
183 #define DEBUG_TRACE_UNWIND               (0x00000008)
184 #define DEBUG_TRACE_CLEANUP              (0x00000010)
185 #define DEBUG_TRACE_CLOSE                (0x00000020)
186 #define DEBUG_TRACE_CREATE               (0x00000040)
187 #define DEBUG_TRACE_DIRCTRL              (0x00000080)
188 #define DEBUG_TRACE_EA                   (0x00000100)
189 #define DEBUG_TRACE_FILEINFO             (0x00000200)
190 #define DEBUG_TRACE_FSCTRL               (0x00000400)
191 #define DEBUG_TRACE_LOCKCTRL             (0x00000800)
192 #define DEBUG_TRACE_READ                 (0x00001000)
193 #define DEBUG_TRACE_VOLINFO              (0x00002000)
194 #define DEBUG_TRACE_WRITE                (0x00004000)
195 #define DEBUG_TRACE_FLUSH                (0x00008000)
196 #define DEBUG_TRACE_DEVCTRL              (0x00010000)
197 #define DEBUG_TRACE_SHUTDOWN             (0x00020000)
198 #define DEBUG_TRACE_FATDATA              (0x00040000)
199 #define DEBUG_TRACE_PNP                  (0x00080000)
200 #define DEBUG_TRACE_ACCHKSUP             (0x00100000)
201 #define DEBUG_TRACE_ALLOCSUP             (0x00200000)
202 #define DEBUG_TRACE_DIRSUP               (0x00400000)
203 #define DEBUG_TRACE_FILOBSUP             (0x00800000)
204 #define DEBUG_TRACE_NAMESUP              (0x01000000)
205 #define DEBUG_TRACE_VERFYSUP             (0x02000000)
206 #define DEBUG_TRACE_CACHESUP             (0x04000000)
207 #define DEBUG_TRACE_SPLAYSUP             (0x08000000)
208 #define DEBUG_TRACE_DEVIOSUP             (0x10000000)
209 #define DEBUG_TRACE_STRUCSUP             (0x20000000)
210 #define DEBUG_TRACE_FSP_DISPATCHER       (0x40000000)
211 #define DEBUG_TRACE_FSP_DUMP             (0x80000000)
212 
213 extern LONG FatDebugTraceLevel;
214 extern LONG FatDebugTraceIndent;
215 
216 #define DebugTrace(INDENT,LEVEL,X,Y) {                      \
217     LONG _i;                                                \
218     if (((LEVEL) == 0) || (FatDebugTraceLevel & (LEVEL))) { \
219         _i = (ULONG)PsGetCurrentThread();                   \
220         DbgPrint("%08lx:",_i);                              \
221         if ((INDENT) < 0) {                                 \
222             FatDebugTraceIndent += (INDENT);                \
223         }                                                   \
224         if (FatDebugTraceIndent < 0) {                      \
225             FatDebugTraceIndent = 0;                        \
226         }                                                   \
227         for (_i = 0; _i < FatDebugTraceIndent; _i += 1) {   \
228             DbgPrint(" ");                                  \
229         }                                                   \
230         DbgPrint(X,Y);                                      \
231         if ((INDENT) > 0) {                                 \
232             FatDebugTraceIndent += (INDENT);                \
233         }                                                   \
234     }                                                       \
235 }
236 
237 #if !defined(__REACTOS__) || defined(_MSC_VER)
238 #define DebugDump(STR,LEVEL,PTR) {                          \
239     __pragma(warning(push))                                 \
240     __pragma(warning(disable:4210))                         \
241     ULONG _i;                                               \
242     VOID FatDump(IN PVOID Ptr);                             \
243     if (((LEVEL) == 0) || (FatDebugTraceLevel & (LEVEL))) { \
244         _i = (ULONG)PsGetCurrentThread();                   \
245         DbgPrint("%08lx:",_i);                              \
246         DbgPrint(STR);                                      \
247         if (PTR != NULL) {FatDump(PTR);}                    \
248         NT_ASSERT(FALSE);                                   \
249     }                                                       \
250     __pragma(warning(pop))                                  \
251 }
252 #else
253 #define DebugDump(STR,LEVEL,PTR) {                          \
254     ULONG _i;                                               \
255     VOID FatDump(IN PVOID Ptr);                             \
256     if (((LEVEL) == 0) || (FatDebugTraceLevel & (LEVEL))) { \
257         _i = (ULONG)PsGetCurrentThread();                   \
258         DbgPrint("%08lx:",_i);                              \
259         DbgPrint(STR);                                      \
260         if (PTR != NULL) {FatDump(PTR);}                    \
261         NT_ASSERT(FALSE);                                   \
262     }                                                       \
263 }
264 #endif
265 
266 #define DebugUnwind(X) {                                                      \
267     if (_SEH2_AbnormalTermination()) {                                        \
268         DebugTrace(0, DEBUG_TRACE_UNWIND, #X ", Abnormal termination.\n", 0); \
269     }                                                                         \
270 }
271 
272 //
273 //  The following variables are used to keep track of the total amount
274 //  of requests processed by the file system, and the number of requests
275 //  that end up being processed by the Fsp thread.  The first variable
276 //  is incremented whenever an Irp context is created (which is always
277 //  at the start of an Fsd entry point) and the second is incremented
278 //  by read request.
279 //
280 
281 extern ULONG FatFsdEntryCount;
282 extern ULONG FatFspEntryCount;
283 extern ULONG FatIoCallDriverCount;
284 extern ULONG FatTotalTicks[];
285 
286 #define DebugDoit(X)                     {X;}
287 
288 extern LONG FatPerformanceTimerLevel;
289 
290 #define TimerStart(LEVEL) {                     \
291     LARGE_INTEGER TStart, TEnd;                 \
292     LARGE_INTEGER TElapsed;                     \
293     TStart = KeQueryPerformanceCounter( NULL ); \
294 
295 #define TimerStop(LEVEL,s)                                    \
296     TEnd = KeQueryPerformanceCounter( NULL );                 \
297     TElapsed.QuadPart = TEnd.QuadPart - TStart.QuadPart;      \
298     FatTotalTicks[FatLogOf(LEVEL)] += TElapsed.LowPart;       \
299     if (FlagOn( FatPerformanceTimerLevel, (LEVEL))) {         \
300         DbgPrint("Time of %s %ld\n", (s), TElapsed.LowPart ); \
301     }                                                         \
302 }
303 
304 //
305 //  I need this because C can't support conditional compilation within
306 //  a macro.
307 //
308 
309 extern PVOID FatNull;
310 
311 #else
312 
313 #define DebugTrace(INDENT,LEVEL,X,Y)     {NOTHING;}
314 #define DebugDump(STR,LEVEL,PTR)         {NOTHING;}
315 #define DebugUnwind(X)                   {NOTHING;}
316 #define DebugDoit(X)                     {NOTHING;}
317 
318 #define TimerStart(LEVEL)
319 #define TimerStop(LEVEL,s)
320 
321 #define FatNull NULL
322 
323 #endif // FASTFATDBG
324 
325 //
326 //  The following macro is for all people who compile with the DBG switch
327 //  set, not just fastfat dbg users
328 //
329 
330 #if DBG
331 
332 #define DbgDoit(X)                       {X;}
333 
334 #else
335 
336 #define DbgDoit(X)                       {NOTHING;}
337 
338 #endif // DBG
339 
340 #if DBG
341 
342 extern NTSTATUS FatBreakOnInterestingIoCompletion;
343 extern NTSTATUS FatBreakOnInterestingExceptionStatus;
344 extern NTSTATUS FatBreakOnInterestingIrpCompletion;
345 
346 extern BOOLEAN FatTestRaisedStatus;
347 
348 #endif
349 
350 #endif // _FATDATA_
351 
352 
353