1*c2c66affSColin Finck ////////////////////////////////////////////////////////////////////
2*c2c66affSColin Finck // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
3*c2c66affSColin Finck // All rights reserved
4*c2c66affSColin Finck // This file was released under the GPLv2 on June 2015.
5*c2c66affSColin Finck ////////////////////////////////////////////////////////////////////
6*c2c66affSColin Finck /*************************************************************************
7*c2c66affSColin Finck *
8*c2c66affSColin Finck * File: env_spec_w32.h
9*c2c66affSColin Finck *
10*c2c66affSColin Finck * Module: User-mode applications (User mode execution only)
11*c2c66affSColin Finck *
12*c2c66affSColin Finck * Description:
13*c2c66affSColin Finck *
14*c2c66affSColin Finck *
15*c2c66affSColin Finck * Author: Alter
16*c2c66affSColin Finck *
17*c2c66affSColin Finck *************************************************************************/
18*c2c66affSColin Finck 
19*c2c66affSColin Finck #ifndef __ENV_SPEC_W32__H_
20*c2c66affSColin Finck #define __ENV_SPEC_W32__H_
21*c2c66affSColin Finck 
22*c2c66affSColin Finck #ifdef NT_NATIVE_MODE
23*c2c66affSColin Finck //#include "ntddk.h" // include this for its native functions and defn's
24*c2c66affSColin Finck #include "nt_native.h"
25*c2c66affSColin Finck #else //NT_NATIVE_MODE
26*c2c66affSColin Finck #include <windows.h>
27*c2c66affSColin Finck #endif //NT_NATIVE_MODE
28*c2c66affSColin Finck #include "platform.h"
29*c2c66affSColin Finck //#ifndef WITHOUT_FORMATTER
30*c2c66affSColin Finck #include "udferr_usr.h"
31*c2c66affSColin Finck //#endif WITHOUT_FORMATTER
32*c2c66affSColin Finck 
33*c2c66affSColin Finck #ifndef NT_NATIVE_MODE
34*c2c66affSColin Finck #ifdef ASSERT
35*c2c66affSColin Finck   #undef ASSERT
36*c2c66affSColin Finck   #define ASSERT(a)    if(!(a)) {__asm int 3;}
37*c2c66affSColin Finck #endif
38*c2c66affSColin Finck #endif //NT_NATIVE_MODE
39*c2c66affSColin Finck 
40*c2c66affSColin Finck #ifndef MAXIMUM_FILENAME_LENGTH
41*c2c66affSColin Finck #define MAXIMUM_FILENAME_LENGTH MAX_PATH
42*c2c66affSColin Finck #endif //MAXIMUM_FILENAME_LENGTH
43*c2c66affSColin Finck 
44*c2c66affSColin Finck #ifndef PAGE_SHIFT
45*c2c66affSColin Finck #define PAGE_SHIFT 12
46*c2c66affSColin Finck #endif //PAGE_SHIFT
47*c2c66affSColin Finck 
48*c2c66affSColin Finck #ifndef PAGE_SIZE
49*c2c66affSColin Finck #define PAGE_SIZE (ULONG)0x1000
50*c2c66affSColin Finck #endif //PAGE_SIZE
51*c2c66affSColin Finck 
52*c2c66affSColin Finck #ifndef PHYSICAL_ADDRESS
53*c2c66affSColin Finck #define PHYSICAL_ADDRESS  LARGE_INTEGER
54*c2c66affSColin Finck #endif //PHYSICAL_ADDRESS
55*c2c66affSColin Finck 
56*c2c66affSColin Finck #define OS_SUCCESS(a)     NT_SUCCESS(a)
57*c2c66affSColin Finck #define OSSTATUS          NTSTATUS
58*c2c66affSColin Finck 
59*c2c66affSColin Finck #if defined UDF_DBG || defined DEBUG
60*c2c66affSColin Finck #define DBG
61*c2c66affSColin Finck #ifndef CDRW_W32
62*c2c66affSColin Finck #define UDF_DBG
63*c2c66affSColin Finck #endif //CDRW_W32
64*c2c66affSColin Finck #endif
65*c2c66affSColin Finck 
66*c2c66affSColin Finck #define ERESEOURCE        ULONG
67*c2c66affSColin Finck #define PERESEOURCE       PULONG
68*c2c66affSColin Finck 
69*c2c66affSColin Finck #define KEVENT            ULONG
70*c2c66affSColin Finck #define PKEVENT           PULONG
71*c2c66affSColin Finck 
72*c2c66affSColin Finck typedef ULONG KSPIN_LOCK;  // winnt ntndis
73*c2c66affSColin Finck typedef KSPIN_LOCK *PKSPIN_LOCK;
74*c2c66affSColin Finck 
75*c2c66affSColin Finck #ifndef NT_NATIVE_MODE
76*c2c66affSColin Finck // Status ot
77*c2c66affSColin Finck #define NTSTATUS LONG
78*c2c66affSColin Finck 
79*c2c66affSColin Finck #define NT_SUCCESS(x) ( (NTSTATUS)(x)>=0 )
80*c2c66affSColin Finck 
81*c2c66affSColin Finck #define PsGetCurrentThread()  GetCurrentThreadId()
82*c2c66affSColin Finck 
83*c2c66affSColin Finck #define PsGetVersion(a,b,c,d) { \
84*c2c66affSColin Finck     OSVERSIONINFO OsVer;        \
85*c2c66affSColin Finck     OsVer.dwOSVersionInfoSize = sizeof(OsVer); \
86*c2c66affSColin Finck     GetVersionEx(&OsVer); \
87*c2c66affSColin Finck     if(a) (*(a)) = OsVer.dwMajorVersion; \
88*c2c66affSColin Finck     if(b) (*(b)) = OsVer.dwMinorVersion; \
89*c2c66affSColin Finck     if(c) (*(c)) = OsVer.dwBuildNumber;  \
90*c2c66affSColin Finck     if(d) (d)->Buffer = L"";  \
91*c2c66affSColin Finck     if(d) (d)->Length = 0;  \
92*c2c66affSColin Finck     if(d) (d)->MaximumLength = 0;  \
93*c2c66affSColin Finck }
94*c2c66affSColin Finck 
95*c2c66affSColin Finck extern "C"
96*c2c66affSColin Finck VOID
97*c2c66affSColin Finck PrintDbgConsole(
98*c2c66affSColin Finck     PCHAR DebugMessage,
99*c2c66affSColin Finck     ...
100*c2c66affSColin Finck     );
101*c2c66affSColin Finck 
102*c2c66affSColin Finck #else //NT_NATIVE_MODE
103*c2c66affSColin Finck #define HINSTANCE HANDLE
104*c2c66affSColin Finck #endif //NT_NATIVE_MODE
105*c2c66affSColin Finck 
106*c2c66affSColin Finck typedef
107*c2c66affSColin Finck int (*PSKIN_INIT) (
108*c2c66affSColin Finck     HINSTANCE hInstance,      // handle to current instance
109*c2c66affSColin Finck     HINSTANCE hPrevInstance,  // handle to previous instance
110*c2c66affSColin Finck     int nCmdShow              // show state
111*c2c66affSColin Finck     );
112*c2c66affSColin Finck 
113*c2c66affSColin Finck typedef
114*c2c66affSColin Finck int (*PSKIN_PRINTF) (
115*c2c66affSColin Finck     const char* Message,
116*c2c66affSColin Finck     ...
117*c2c66affSColin Finck     );
118*c2c66affSColin Finck 
119*c2c66affSColin Finck typedef
120*c2c66affSColin Finck PWCHAR (__stdcall *PSKIN_GETCMDLINE) (
121*c2c66affSColin Finck     VOID
122*c2c66affSColin Finck     );
123*c2c66affSColin Finck 
124*c2c66affSColin Finck typedef
125*c2c66affSColin Finck ULONG (__stdcall *PSKIN_MSG) (
126*c2c66affSColin Finck     ULONG MsgId,
127*c2c66affSColin Finck     ULONG MsgSubId,
128*c2c66affSColin Finck     PVOID DataIn,
129*c2c66affSColin Finck     ULONG DataInLen,
130*c2c66affSColin Finck     PVOID DataOut,
131*c2c66affSColin Finck     ULONG DataInOut
132*c2c66affSColin Finck     );
133*c2c66affSColin Finck 
134*c2c66affSColin Finck typedef struct _SKIN_API {
135*c2c66affSColin Finck     PSKIN_INIT        Init;
136*c2c66affSColin Finck     PSKIN_PRINTF      Printf;
137*c2c66affSColin Finck     PSKIN_GETCMDLINE  GetCommandLine;
138*c2c66affSColin Finck     PSKIN_MSG         Msg;
139*c2c66affSColin Finck } SKIN_API, *PSKIN_API;
140*c2c66affSColin Finck 
141*c2c66affSColin Finck #ifdef USE_SKIN_MODEL
142*c2c66affSColin Finck 
143*c2c66affSColin Finck extern "C" PSKIN_API SkinAPI;
144*c2c66affSColin Finck extern PSKIN_API SkinLoad(
145*c2c66affSColin Finck     PWCHAR path,
146*c2c66affSColin Finck     HINSTANCE hInstance,      // handle to current instance
147*c2c66affSColin Finck     HINSTANCE hPrevInstance,  // handle to previous instance
148*c2c66affSColin Finck     int nCmdShow              // show state
149*c2c66affSColin Finck     );
150*c2c66affSColin Finck 
151*c2c66affSColin Finck #define SkinPrintf                       SkinAPI->Printf
152*c2c66affSColin Finck #define SkinGetCmdLine                   SkinAPI->GetCommandLine
153*c2c66affSColin Finck #define SkinNotify(op, state, ctx, sz)   SkinAPI->Msg(op, state, ctx, sz, NULL, 0)
154*c2c66affSColin Finck #define SkinAsk(op, state, ctx, def)     SkinAPI->Msg(op, state, ctx, sizeof(ctx), NULL, 0)
155*c2c66affSColin Finck 
156*c2c66affSColin Finck #else
157*c2c66affSColin Finck 
158*c2c66affSColin Finck #define SkinLoad(path)    {;}
159*c2c66affSColin Finck 
160*c2c66affSColin Finck #if defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
161*c2c66affSColin Finck   #define SkinPrintf(x)                    {;}
162*c2c66affSColin Finck /*VOID
163*c2c66affSColin Finck inline
164*c2c66affSColin Finck SkinPrintf(
165*c2c66affSColin Finck     PCHAR Message,
166*c2c66affSColin Finck     ...
167*c2c66affSColin Finck     )
168*c2c66affSColin Finck {
169*c2c66affSColin Finck     //do nothing
170*c2c66affSColin Finck     return;
171*c2c66affSColin Finck }*/
172*c2c66affSColin Finck #else // defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
173*c2c66affSColin Finck   #define SkinPrintf                       printf
174*c2c66affSColin Finck #endif
175*c2c66affSColin Finck 
176*c2c66affSColin Finck #define SkinGetCmdLine                   GetCommandLineW
177*c2c66affSColin Finck #define SkinNotify(op, state, ctx)       {;}
178*c2c66affSColin Finck #define SkinAsk(op, state, ctx, def)     (def)
179*c2c66affSColin Finck 
180*c2c66affSColin Finck #endif // defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
181*c2c66affSColin Finck 
182*c2c66affSColin Finck #if defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
183*c2c66affSColin Finck 
184*c2c66affSColin Finck   #if defined(PRINT_TO_DBG_LOG) || defined(PRINT_ALWAYS)
185*c2c66affSColin Finck     #define UserPrint(x) PrintDbgConsole x
186*c2c66affSColin Finck   #else
187*c2c66affSColin Finck     #define UserPrint(x) {;}
188*c2c66affSColin Finck   #endif // PRINT_TO_DBG_LOG
189*c2c66affSColin Finck 
190*c2c66affSColin Finck #else // defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
191*c2c66affSColin Finck 
192*c2c66affSColin Finck   #if defined(PRINT_TO_DBG_LOG) || defined(PRINT_ALWAYS)
193*c2c66affSColin Finck 
194*c2c66affSColin Finck     #define UserPrint(x) \
195*c2c66affSColin Finck     {                    \
196*c2c66affSColin Finck      SkinPrintf x ;          \
197*c2c66affSColin Finck      PrintDbgConsole x ; \
198*c2c66affSColin Finck     }
199*c2c66affSColin Finck 
200*c2c66affSColin Finck   #else // PRINT_TO_DBG_LOG
201*c2c66affSColin Finck 
202*c2c66affSColin Finck     #define UserPrint(x) \
203*c2c66affSColin Finck     {                    \
204*c2c66affSColin Finck      SkinPrintf x ;          \
205*c2c66affSColin Finck     }
206*c2c66affSColin Finck 
207*c2c66affSColin Finck   #endif // PRINT_TO_DBG_LOG
208*c2c66affSColin Finck 
209*c2c66affSColin Finck #endif // defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
210*c2c66affSColin Finck 
211*c2c66affSColin Finck #if defined(DBG) || defined(PRINT_ALWAYS)
212*c2c66affSColin Finck 
213*c2c66affSColin Finck   #define DbgPrint SkinPrintf
214*c2c66affSColin Finck 
215*c2c66affSColin Finck   #ifdef KdPrint
216*c2c66affSColin Finck     #undef KdPrint
217*c2c66affSColin Finck   #endif
218*c2c66affSColin Finck 
219*c2c66affSColin Finck   #if defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
220*c2c66affSColin Finck     #ifdef PRINT_TO_DBG_LOG
221*c2c66affSColin Finck       #define KdPrint(x) PrintDbgConsole x;
222*c2c66affSColin Finck     #else
223*c2c66affSColin Finck       #define KdPrint(x) {;}
224*c2c66affSColin Finck     #endif
225*c2c66affSColin Finck   #else
226*c2c66affSColin Finck 
227*c2c66affSColin Finck     #if defined(PRINT_TO_DBG_LOG) || defined(PRINT_ALWAYS)
228*c2c66affSColin Finck       #define KdPrint(x) \
229*c2c66affSColin Finck       {                    \
230*c2c66affSColin Finck        SkinPrintf x ;          \
231*c2c66affSColin Finck        PrintDbgConsole x ; \
232*c2c66affSColin Finck       }
233*c2c66affSColin Finck     #else
234*c2c66affSColin Finck       #define KdPrint(x) \
235*c2c66affSColin Finck       {                    \
236*c2c66affSColin Finck        SkinPrintf x ;          \
237*c2c66affSColin Finck       }
238*c2c66affSColin Finck     #endif
239*c2c66affSColin Finck   #endif
240*c2c66affSColin Finck 
241*c2c66affSColin Finck   #ifdef USE_MM_PRINT
242*c2c66affSColin Finck     #define MmPrint(_x_) DbgPrint _x_
243*c2c66affSColin Finck   #else
244*c2c66affSColin Finck     #define MmPrint(_x_) {NOTHING;}
245*c2c66affSColin Finck   #endif //USE_MM_PRINT
246*c2c66affSColin Finck 
247*c2c66affSColin Finck   #ifdef USE_TIME_PRINT
248*c2c66affSColin Finck     extern ULONG UdfTimeStamp;
249*c2c66affSColin Finck     #define TmPrint(_x_) {UdfTimeStamp++;KdPrint(("TM:%d: ",UdfTimeStamp));KdPrint(_x_);}
250*c2c66affSColin Finck   #else
251*c2c66affSColin Finck     #define TmPrint KdPrint
252*c2c66affSColin Finck   #endif //USE_MM_PRINT
253*c2c66affSColin Finck 
254*c2c66affSColin Finck   #ifdef USE_PERF_PRINT
255*c2c66affSColin Finck     #define PerfPrint(_x_) DbgPrint _x_
256*c2c66affSColin Finck   #else
257*c2c66affSColin Finck     #define PerfPrint(_x_) {NOTHING;}
258*c2c66affSColin Finck   #endif //USE_MM_PRINT
259*c2c66affSColin Finck 
260*c2c66affSColin Finck #if defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
261*c2c66affSColin Finck   #ifdef USE_AD_PRINT
262*c2c66affSColin Finck     #undef USE_AD_PRINT
263*c2c66affSColin Finck   #endif
264*c2c66affSColin Finck   #ifdef USE_TH_PRINT
265*c2c66affSColin Finck     #undef USE_TH_PRINT
266*c2c66affSColin Finck   #endif
267*c2c66affSColin Finck #endif
268*c2c66affSColin Finck 
269*c2c66affSColin Finck   #ifdef USE_AD_PRINT
270*c2c66affSColin Finck     #define AdPrint(_x_) {DbgPrint("Thrd:%x:",PsGetCurrentThread());DbgPrint _x_;}
271*c2c66affSColin Finck   #else
272*c2c66affSColin Finck     #define AdPrint(_x_) {NOTHING;}
273*c2c66affSColin Finck   #endif
274*c2c66affSColin Finck 
275*c2c66affSColin Finck   #ifdef USE_TH_PRINT
276*c2c66affSColin Finck     #define ThPrint(_x_) {DbgPrint("Thrd:%x:",PsGetCurrentThread());DbgPrint _x_;}
277*c2c66affSColin Finck   #else
278*c2c66affSColin Finck     #define ThPrint(_x_) {NOTHING;}
279*c2c66affSColin Finck   #endif
280*c2c66affSColin Finck 
281*c2c66affSColin Finck   #ifdef USE_DUMP_EXT
282*c2c66affSColin Finck     #define ExtPrint(_x_) DbgPrint _x_
283*c2c66affSColin Finck   #else
284*c2c66affSColin Finck     #define ExtPrint(_x_) {NOTHING;}
285*c2c66affSColin Finck   #endif //USE_MM_PRINT
286*c2c66affSColin Finck 
287*c2c66affSColin Finck #else
288*c2c66affSColin Finck   #define KdPrint(x)     {NOTHING;}
289*c2c66affSColin Finck   #define MmPrint(_x_)   {NOTHING;}
290*c2c66affSColin Finck   #define TmPrint(_x_)   {NOTHING;}
291*c2c66affSColin Finck   #define PerfPrint(_x_) {NOTHING;}
292*c2c66affSColin Finck   #define AdPrint(_x_)   {NOTHING;}
293*c2c66affSColin Finck   #define ThPrint(_x_)   {NOTHING;}
294*c2c66affSColin Finck   #define ExtPrint(_x_)  {NOTHING;}
295*c2c66affSColin Finck #endif
296*c2c66affSColin Finck 
297*c2c66affSColin Finck #define DbgTouch(a)
298*c2c66affSColin Finck 
299*c2c66affSColin Finck #ifndef NT_NATIVE_MODE
300*c2c66affSColin Finck #include "assert.h"
301*c2c66affSColin Finck 
302*c2c66affSColin Finck #define ASSERT(_x_)   assert(_x_)
303*c2c66affSColin Finck #define UDFTouch(a)
304*c2c66affSColin Finck 
305*c2c66affSColin Finck #endif //NT_NATIVE_MODE
306*c2c66affSColin Finck 
307*c2c66affSColin Finck #define NonPagedPool            0
308*c2c66affSColin Finck #define PagedPool               1
309*c2c66affSColin Finck //#define NonPagedPoolMustSucceed 2
310*c2c66affSColin Finck #define NonPagedPoolCacheAligned 4
311*c2c66affSColin Finck 
312*c2c66affSColin Finck #define KdDump(a,b)                         \
313*c2c66affSColin Finck if((a)!=NULL) {                             \
314*c2c66affSColin Finck     ULONG i;                                \
315*c2c66affSColin Finck     for(i=0; i<(b); i++) {                  \
316*c2c66affSColin Finck         ULONG c;                            \
317*c2c66affSColin Finck         c = (ULONG)(*(((PUCHAR)(a))+i));    \
318*c2c66affSColin Finck         KdPrint(("%2.2x ",c));              \
319*c2c66affSColin Finck         if ((i & 0x0f) == 0x0f) KdPrint(("\n"));   \
320*c2c66affSColin Finck     }                                       \
321*c2c66affSColin Finck     KdPrint(("\n"));                        \
322*c2c66affSColin Finck }
323*c2c66affSColin Finck 
324*c2c66affSColin Finck //mem ot
325*c2c66affSColin Finck //#define ExAllocatePool(hernya,size) MyAllocatePool(size)
326*c2c66affSColin Finck //#define ExFreePool(size) MyFreePool((PCHAR)(size))
327*c2c66affSColin Finck //#define SystemAllocatePool(hernya,size) GlobalAlloc(GMEM_DISCARDABLE, size);
328*c2c66affSColin Finck //#define SystemFreePool(addr) GlobalFree((PVOID)(addr))
329*c2c66affSColin Finck #define DbgMoveMemory     RtlMoveMemory
330*c2c66affSColin Finck #define DbgCompareMemory  RtlCompareMemory
331*c2c66affSColin Finck #define DbgCopyMemory     RtlCopyMemory
332*c2c66affSColin Finck #define DbgAllocatePool   ExAllocatePool
333*c2c66affSColin Finck #define DbgAllocatePoolWithTag(a,b,c)   ExAllocatePool(a,b)
334*c2c66affSColin Finck #define DbgFreePool       ExFreePool
335*c2c66affSColin Finck 
336*c2c66affSColin Finck #ifdef NT_NATIVE_MODE
337*c2c66affSColin Finck /*
338*c2c66affSColin Finck #define GlobalAlloc(foo, size)  MyGlobalAlloc( size );
339*c2c66affSColin Finck #define GlobalFree(ptr)         MyGlobalFree( ptr );
340*c2c66affSColin Finck 
341*c2c66affSColin Finck extern "C"
342*c2c66affSColin Finck PVOID MyGlobalAlloc(ULONG Size);
343*c2c66affSColin Finck 
344*c2c66affSColin Finck extern "C"
345*c2c66affSColin Finck VOID  MyGlobalFree(PVOID Addr);
346*c2c66affSColin Finck */
347*c2c66affSColin Finck #endif
348*c2c66affSColin Finck 
349*c2c66affSColin Finck #if !defined(KERNEL_MODE_MM_BEHAVIOR) && !defined(USE_THREAD_HEAPS)
350*c2c66affSColin Finck #define ExAllocatePoolWithTag(hernya,size,tag) GlobalAlloc(GMEM_DISCARDABLE, (size))
351*c2c66affSColin Finck #define ExAllocatePool(hernya,size) GlobalAlloc(GMEM_DISCARDABLE, (size))
352*c2c66affSColin Finck #define ExFreePool(addr) GlobalFree((PVOID)(addr))
353*c2c66affSColin Finck #endif
354*c2c66affSColin Finck 
355*c2c66affSColin Finck #if defined(KERNEL_MODE_MM_BEHAVIOR) || defined(USE_THREAD_HEAPS)
356*c2c66affSColin Finck #define ExAllocatePoolWithTag(MemoryType,size,tag) ExAllocatePool((MemoryType), (size))
357*c2c66affSColin Finck 
358*c2c66affSColin Finck extern "C"
359*c2c66affSColin Finck PVOID ExAllocatePool(ULONG MemoryType, ULONG Size);
360*c2c66affSColin Finck 
361*c2c66affSColin Finck extern "C"
362*c2c66affSColin Finck VOID  ExFreePool(PVOID Addr);
363*c2c66affSColin Finck #endif //KERNEL_MODE_MM_BEHAVIOR || USE_THREAD_HEAPS
364*c2c66affSColin Finck 
365*c2c66affSColin Finck #ifndef NT_NATIVE_MODE
366*c2c66affSColin Finck 
367*c2c66affSColin Finck //string ot
368*c2c66affSColin Finck typedef struct _UNICODE_STRING {
369*c2c66affSColin Finck     USHORT Length;
370*c2c66affSColin Finck     USHORT MaximumLength;
371*c2c66affSColin Finck     PWSTR  Buffer;
372*c2c66affSColin Finck } UNICODE_STRING;
373*c2c66affSColin Finck typedef UNICODE_STRING *PUNICODE_STRING;
374*c2c66affSColin Finck 
375*c2c66affSColin Finck typedef struct _ANSI_STRING {
376*c2c66affSColin Finck     USHORT Length;
377*c2c66affSColin Finck     USHORT MaximumLength;
378*c2c66affSColin Finck     PSTR   Buffer;
379*c2c66affSColin Finck } ANSI_STRING;
380*c2c66affSColin Finck typedef ANSI_STRING *PANSI_STRING;
381*c2c66affSColin Finck 
382*c2c66affSColin Finck #endif //NT_NATIVE_MODE
383*c2c66affSColin Finck 
384*c2c66affSColin Finck #define PtrOffset(BASE,OFFSET) ((ULONG)((ULONG)(OFFSET) - (ULONG)(BASE)))
385*c2c66affSColin Finck 
386*c2c66affSColin Finck // Device object ot
387*c2c66affSColin Finck 
388*c2c66affSColin Finck #ifndef DO_UNLOAD_PENDING
389*c2c66affSColin Finck // Define Device Object (DO) flags
390*c2c66affSColin Finck //
391*c2c66affSColin Finck 
392*c2c66affSColin Finck #define DO_UNLOAD_PENDING               0x00000001
393*c2c66affSColin Finck #define DO_VERIFY_VOLUME                0x00000002
394*c2c66affSColin Finck #define DO_BUFFERED_IO                  0x00000004
395*c2c66affSColin Finck #define DO_EXCLUSIVE                    0x00000008
396*c2c66affSColin Finck #define DO_DIRECT_IO                    0x00000010
397*c2c66affSColin Finck #define DO_MAP_IO_BUFFER                0x00000020
398*c2c66affSColin Finck #define DO_DEVICE_HAS_NAME              0x00000040
399*c2c66affSColin Finck #define DO_DEVICE_INITIALIZING          0x00000080
400*c2c66affSColin Finck #define DO_SYSTEM_BOOT_PARTITION        0x00000100
401*c2c66affSColin Finck #define DO_LONG_TERM_REQUESTS           0x00000200
402*c2c66affSColin Finck #define DO_NEVER_LAST_DEVICE            0x00000400
403*c2c66affSColin Finck #define DO_SHUTDOWN_REGISTERED          0x00000800
404*c2c66affSColin Finck 
405*c2c66affSColin Finck #endif //DO_UNLOAD_PENDING
406*c2c66affSColin Finck 
407*c2c66affSColin Finck #ifdef NT_NATIVE_MODE
408*c2c66affSColin Finck #define _DEVICE_OBJECT _MY_DEVICE_OBJECT
409*c2c66affSColin Finck #define DEVICE_OBJECT  MY_DEVICE_OBJECT
410*c2c66affSColin Finck #define PDEVICE_OBJECT PMY_DEVICE_OBJECT
411*c2c66affSColin Finck #endif //NT_NATIVE_MODE
412*c2c66affSColin Finck 
413*c2c66affSColin Finck typedef struct _DEVICE_OBJECT {
414*c2c66affSColin Finck 
415*c2c66affSColin Finck #ifndef LIBUDF
416*c2c66affSColin Finck 
417*c2c66affSColin Finck     HANDLE h;
418*c2c66affSColin Finck     PVOID  DeviceExtension;
419*c2c66affSColin Finck     ULONG  Flags;
420*c2c66affSColin Finck     ULONG  AlignmentRequirement;
421*c2c66affSColin Finck     UCHAR  StackSize;
422*c2c66affSColin Finck 
423*c2c66affSColin Finck #endif // LIBUDF
424*c2c66affSColin Finck 
425*c2c66affSColin Finck 
426*c2c66affSColin Finck #ifdef LIBUDFFMT
427*c2c66affSColin Finck 
428*c2c66affSColin Finck     struct _UDF_FMT_PARAMETERS* cbio;
429*c2c66affSColin Finck     PVOID  lpContext;
430*c2c66affSColin Finck 
431*c2c66affSColin Finck #else
432*c2c66affSColin Finck #ifdef LIBUDF
433*c2c66affSColin Finck     PVOID  lpContext;
434*c2c66affSColin Finck #endif // LIBUDF
435*c2c66affSColin Finck #endif // LIBUDFFMT
436*c2c66affSColin Finck 
437*c2c66affSColin Finck } DEVICE_OBJECT, *PDEVICE_OBJECT;
438*c2c66affSColin Finck 
439*c2c66affSColin Finck #ifndef CDRW_W32
440*c2c66affSColin Finck /*
441*c2c66affSColin Finck typedef ULONG DEVICE_OBJECT;
442*c2c66affSColin Finck typedef ULONG PDEVICE_OBJECT;
443*c2c66affSColin Finck */
444*c2c66affSColin Finck #define INVALID_PACKET 0x01
445*c2c66affSColin Finck 
446*c2c66affSColin Finck typedef struct _PACKET {
447*c2c66affSColin Finck     // Node Identifier
448*c2c66affSColin Finck //  UDFIdentifier               NodeIdentifier;
449*c2c66affSColin Finck     // Pointer to the buffer (in non-paged pool)
450*c2c66affSColin Finck     PCHAR           buffer;
451*c2c66affSColin Finck     // Offset, from which this data was read
452*c2c66affSColin Finck     LARGE_INTEGER   offset;
453*c2c66affSColin Finck     // Flags
454*c2c66affSColin Finck     UCHAR           flags;
455*c2c66affSColin Finck } PACKET, *PPACKET;
456*c2c66affSColin Finck 
457*c2c66affSColin Finck #define UDFInitPacket(x) STATUS_SUCCESS
458*c2c66affSColin Finck #endif //CDRW_W32
459*c2c66affSColin Finck 
460*c2c66affSColin Finck #define try_return(S)   { S; goto try_exit; }
461*c2c66affSColin Finck #define NOTHING
462*c2c66affSColin Finck 
463*c2c66affSColin Finck #define FlagOn(x,f) ((x) & (f))
464*c2c66affSColin Finck 
465*c2c66affSColin Finck #define RtlCompareMemory(s1,s2,l)  MyRtlCompareMemory(s1,s2,l)
466*c2c66affSColin Finck // Structure ot
467*c2c66affSColin Finck extern "C"
468*c2c66affSColin Finck ULONG
469*c2c66affSColin Finck MyRtlCompareMemory(
470*c2c66affSColin Finck     PVOID s1,
471*c2c66affSColin Finck     PVOID s2,
472*c2c66affSColin Finck     ULONG len
473*c2c66affSColin Finck     );
474*c2c66affSColin Finck //#define RtlCompareMemory(d1,d2,l)   (ULONG)(memcmp (d1,d2,l))
475*c2c66affSColin Finck 
476*c2c66affSColin Finck #define KeSetEvent(pEvt, foo, foo2)          {NOTHING;}
477*c2c66affSColin Finck #define KeInitializeEvent(pEvt, foo, foo2)   {NOTHING;}
478*c2c66affSColin Finck #define KeWaitForSingleObject(pEvt, foo, a, b, c)     {NOTHING;}
479*c2c66affSColin Finck #define DbgWaitForSingleObject(o, to)   KeWaitForSingleObject(o, Executive, KernelMode, FALSE, to);
480*c2c66affSColin Finck //#define DbgWaitForSingleObject   KeWaitForSingleObject
481*c2c66affSColin Finck #ifdef NT_NATIVE_MODE
482*c2c66affSColin Finck #define KeDelayExecutionThread(mode, foo, t)  { NtDelayExecution(false, t); }
483*c2c66affSColin Finck #else //NT_NATIVE_MODE
484*c2c66affSColin Finck #define KeDelayExecutionThread(mode, foo, t) { Sleep( abs((LONG)(((t)->QuadPart)/10000)) ); }
485*c2c66affSColin Finck #endif //NT_NATIVE_MODE
486*c2c66affSColin Finck 
487*c2c66affSColin Finck /*#define RtlCompareUnicodeString(s1,s2,cs) \
488*c2c66affSColin Finck  (((s1)->Length == (s2)->Length) && \
489*c2c66affSColin Finck   (RtlCompareMemory(s1,s2,(s1)->Length)))
490*c2c66affSColin Finck */
491*c2c66affSColin Finck #ifndef CDRW_W32
492*c2c66affSColin Finck #ifdef _X86_
493*c2c66affSColin Finck 
494*c2c66affSColin Finck // This is an illegal use of INT3
495*c2c66affSColin Finck #define UDFBreakPoint() __asm int 3
496*c2c66affSColin Finck #else // _X86_
497*c2c66affSColin Finck 
498*c2c66affSColin Finck #define UDFBreakPoint() DbgBreakPoint()
499*c2c66affSColin Finck #endif // _X86_
500*c2c66affSColin Finck 
501*c2c66affSColin Finck #ifdef BRUTE
502*c2c66affSColin Finck #define BrutePoint() UDFBreakPoint()
503*c2c66affSColin Finck #else
504*c2c66affSColin Finck #define BrutePoint() {}
505*c2c66affSColin Finck #endif // BRUTE
506*c2c66affSColin Finck 
507*c2c66affSColin Finck #ifdef VALIDATE_STRUCTURES
508*c2c66affSColin Finck #define ValidateFileInfo(fi)            \
509*c2c66affSColin Finck {    /* validate FileInfo */            \
510*c2c66affSColin Finck     if((fi)->IntegrityTag) {            \
511*c2c66affSColin Finck         KdPrint(("UDF: ERROR! Using deallocated structure !!!\n"));\
512*c2c66affSColin Finck         /*BrutePoint();*/                   \
513*c2c66affSColin Finck     }                                   \
514*c2c66affSColin Finck }
515*c2c66affSColin Finck #else
516*c2c66affSColin Finck #define ValidateFileInfo(fi)  {}
517*c2c66affSColin Finck #endif
518*c2c66affSColin Finck 
519*c2c66affSColin Finck #else //CDRW_W32
520*c2c66affSColin Finck 
521*c2c66affSColin Finck #ifdef BRUTE
522*c2c66affSColin Finck #ifdef _X86_
523*c2c66affSColin Finck 
524*c2c66affSColin Finck // This is an illegal use of INT3
525*c2c66affSColin Finck #define BrutePoint() __asm int 3
526*c2c66affSColin Finck #else // _X86_
527*c2c66affSColin Finck 
528*c2c66affSColin Finck #define BrutePoint() DbgBreakPoint()
529*c2c66affSColin Finck #endif // _X86_
530*c2c66affSColin Finck #else
531*c2c66affSColin Finck #define BrutePoint() {}
532*c2c66affSColin Finck #endif // BRUTE
533*c2c66affSColin Finck 
534*c2c66affSColin Finck #endif //CDRW_W32
535*c2c66affSColin Finck 
536*c2c66affSColin Finck #ifndef NT_NATIVE_MODE
537*c2c66affSColin Finck 
538*c2c66affSColin Finck extern "C"
539*c2c66affSColin Finck ULONG
540*c2c66affSColin Finck RtlCompareUnicodeString(
541*c2c66affSColin Finck     PUNICODE_STRING s1,
542*c2c66affSColin Finck     PUNICODE_STRING s2,
543*c2c66affSColin Finck     BOOLEAN UpCase);
544*c2c66affSColin Finck 
545*c2c66affSColin Finck extern "C"
546*c2c66affSColin Finck NTSTATUS
547*c2c66affSColin Finck RtlUpcaseUnicodeString(
548*c2c66affSColin Finck     PUNICODE_STRING dst,
549*c2c66affSColin Finck     PUNICODE_STRING src,
550*c2c66affSColin Finck     BOOLEAN Alloc
551*c2c66affSColin Finck     );
552*c2c66affSColin Finck 
553*c2c66affSColin Finck extern "C"
554*c2c66affSColin Finck NTSTATUS
555*c2c66affSColin Finck RtlAppendUnicodeToString(
556*c2c66affSColin Finck     IN PUNICODE_STRING Str1,
557*c2c66affSColin Finck     IN PWSTR Str2
558*c2c66affSColin Finck     );
559*c2c66affSColin Finck 
560*c2c66affSColin Finck #endif //NT_NATIVE_MODE
561*c2c66affSColin Finck 
562*c2c66affSColin Finck extern "C"
563*c2c66affSColin Finck NTSTATUS
564*c2c66affSColin Finck MyInitUnicodeString(
565*c2c66affSColin Finck     IN PUNICODE_STRING Str1,
566*c2c66affSColin Finck     IN PCWSTR Str2
567*c2c66affSColin Finck     );
568*c2c66affSColin Finck 
569*c2c66affSColin Finck #ifndef NT_NATIVE_MODE
570*c2c66affSColin Finck #define KeQuerySystemTime(t)     GetSystemTimeAsFileTime((LPFILETIME)(t));
571*c2c66affSColin Finck 
572*c2c66affSColin Finck typedef struct _FILE_BOTH_DIR_INFORMATION {
573*c2c66affSColin Finck     ULONG           NextEntryOffset;
574*c2c66affSColin Finck     ULONG           FileIndex;
575*c2c66affSColin Finck     LARGE_INTEGER   CreationTime;
576*c2c66affSColin Finck     LARGE_INTEGER   LastAccessTime;
577*c2c66affSColin Finck     LARGE_INTEGER   LastWriteTime;
578*c2c66affSColin Finck     LARGE_INTEGER   ChangeTime;
579*c2c66affSColin Finck     LARGE_INTEGER   EndOfFile;
580*c2c66affSColin Finck     LARGE_INTEGER   AllocationSize;
581*c2c66affSColin Finck     ULONG           FileAttributes;
582*c2c66affSColin Finck     ULONG           FileNameLength;
583*c2c66affSColin Finck     ULONG           EaSize;
584*c2c66affSColin Finck     CCHAR           ShortNameLength;
585*c2c66affSColin Finck     WCHAR           ShortName[12];
586*c2c66affSColin Finck     WCHAR           FileName[1];
587*c2c66affSColin Finck } FILE_BOTH_DIR_INFORMATION, *PFILE_BOTH_DIR_INFORMATION;
588*c2c66affSColin Finck 
589*c2c66affSColin Finck #endif //NT_NATIVE_MODE
590*c2c66affSColin Finck 
591*c2c66affSColin Finck typedef UCHAR KIRQL;
592*c2c66affSColin Finck typedef KIRQL *PKIRQL;
593*c2c66affSColin Finck 
594*c2c66affSColin Finck typedef ULONG ERESOURCE;
595*c2c66affSColin Finck typedef ERESOURCE *PERESOURCE;
596*c2c66affSColin Finck 
597*c2c66affSColin Finck #define KeRaiseIrql(irql, oldIrql)                    \
598*c2c66affSColin Finck {                                                     \
599*c2c66affSColin Finck     *oldIrql = 0;                                     \
600*c2c66affSColin Finck }
601*c2c66affSColin Finck 
602*c2c66affSColin Finck #define KeLowerIrql(oldIrql)  {;}
603*c2c66affSColin Finck 
604*c2c66affSColin Finck #define KeInitializeSpinLock(sl)                    \
605*c2c66affSColin Finck {                                                     \
606*c2c66affSColin Finck   *(sl) = 0;                                          \
607*c2c66affSColin Finck }
608*c2c66affSColin Finck 
609*c2c66affSColin Finck #define KeAcquireSpinLock(sl,irql)                    \
610*c2c66affSColin Finck {                                                     \
611*c2c66affSColin Finck     ULONG isLocked = TRUE;                            \
612*c2c66affSColin Finck     while(isLocked) AcquireXLock(*(sl), isLocked, TRUE);\
613*c2c66affSColin Finck }
614*c2c66affSColin Finck 
615*c2c66affSColin Finck #define ExAcquireResourceExclusiveLite(res, wait)     \
616*c2c66affSColin Finck {                                                     \
617*c2c66affSColin Finck     ULONG isLocked = TRUE;                            \
618*c2c66affSColin Finck     while(isLocked) AcquireXLock(*(res), isLocked, TRUE);\
619*c2c66affSColin Finck }
620*c2c66affSColin Finck 
621*c2c66affSColin Finck #define ExAcquireResourceSharedLite(res, wait)        \
622*c2c66affSColin Finck {                                                     \
623*c2c66affSColin Finck     ULONG isLocked = TRUE;                            \
624*c2c66affSColin Finck     while(isLocked) AcquireXLock(*(res), isLocked, TRUE);\
625*c2c66affSColin Finck }
626*c2c66affSColin Finck 
627*c2c66affSColin Finck #define KeReleaseSpinLock(sl,irql)                    \
628*c2c66affSColin Finck {                                                     \
629*c2c66affSColin Finck     ULONG isLocked;                                   \
630*c2c66affSColin Finck     AcquireXLock(*(sl), isLocked, FALSE);             \
631*c2c66affSColin Finck }
632*c2c66affSColin Finck 
633*c2c66affSColin Finck #define ExGetCurrentResourceThread()  0
634*c2c66affSColin Finck 
635*c2c66affSColin Finck #define ExReleaseResourceForThreadLite(res, thrdID)   \
636*c2c66affSColin Finck {                                                     \
637*c2c66affSColin Finck     ULONG isLocked;                                   \
638*c2c66affSColin Finck     AcquireXLock(*(res), isLocked, FALSE);            \
639*c2c66affSColin Finck }
640*c2c66affSColin Finck 
ExInitializeResourceLite(PULONG res)641*c2c66affSColin Finck NTSTATUS inline ExInitializeResourceLite(PULONG res)
642*c2c66affSColin Finck {
643*c2c66affSColin Finck    *(res) = 0;
644*c2c66affSColin Finck    return STATUS_SUCCESS;
645*c2c66affSColin Finck }
646*c2c66affSColin Finck 
647*c2c66affSColin Finck #define ExDeleteResourceLite(res)                     \
648*c2c66affSColin Finck {                                                     \
649*c2c66affSColin Finck    *(res) = 0;                                        \
650*c2c66affSColin Finck }
651*c2c66affSColin Finck 
652*c2c66affSColin Finck #define ExConvertExclusiveToSharedLite(res) {/* do nothing */}
653*c2c66affSColin Finck 
654*c2c66affSColin Finck #ifndef CDRW_W32
655*c2c66affSColin Finck 
656*c2c66affSColin Finck #define UDFAcquireResourceExclusive(Resource,CanWait)  \
657*c2c66affSColin Finck     ExAcquireResourceExclusiveLite((Resource),(CanWait))
658*c2c66affSColin Finck #define UDFAcquireResourceShared(Resource,CanWait) \
659*c2c66affSColin Finck     ExAcquireResourceSharedLite((Resource),(CanWait))
660*c2c66affSColin Finck // a convenient macro (must be invoked in the context of the thread that acquired the resource)
661*c2c66affSColin Finck #define UDFReleaseResource(Resource)    \
662*c2c66affSColin Finck     ExReleaseResourceForThreadLite((Resource), ExGetCurrentResourceThread())
663*c2c66affSColin Finck #define UDFDeleteResource(Resource)    \
664*c2c66affSColin Finck     ExDeleteResourceLite((Resource))
665*c2c66affSColin Finck #define UDFConvertExclusiveToSharedLite(Resource) \
666*c2c66affSColin Finck     ExConvertExclusiveToSharedLite((Resource))
667*c2c66affSColin Finck #define UDFInitializeResourceLite(Resource) \
668*c2c66affSColin Finck     ExInitializeResourceLite((Resource))
669*c2c66affSColin Finck #define UDFAcquireSharedStarveExclusive(Resource,CanWait) \
670*c2c66affSColin Finck     ExAcquireSharedStarveExclusive((Resource),(CanWait))
671*c2c66affSColin Finck #define UDFAcquireSharedWaitForExclusive(Resource,CanWait) \
672*c2c66affSColin Finck     ExAcquireSharedWaitForExclusive((Resource),(CanWait))
673*c2c66affSColin Finck //#define UDFDebugAcquireResourceExclusiveLite(a,b,c,d) ExAcquireResourceExclusiveLite(a,b)
674*c2c66affSColin Finck 
675*c2c66affSColin Finck #define UDFInterlockedIncrement(addr) \
676*c2c66affSColin Finck     ((*addr)++)
677*c2c66affSColin Finck #define UDFInterlockedDecrement(addr) \
678*c2c66affSColin Finck     ((*addr)--)
679*c2c66affSColin Finck int
680*c2c66affSColin Finck __inline
UDFInterlockedExchangeAdd(PLONG addr,LONG i)681*c2c66affSColin Finck UDFInterlockedExchangeAdd(PLONG addr, LONG i) {
682*c2c66affSColin Finck     LONG Old = (*addr);
683*c2c66affSColin Finck     (*addr) += i;
684*c2c66affSColin Finck     return Old;
685*c2c66affSColin Finck }
686*c2c66affSColin Finck 
687*c2c66affSColin Finck #endif //CDRW_W32
688*c2c66affSColin Finck 
689*c2c66affSColin Finck //
690*c2c66affSColin Finck // Interrupt Request Level definitions
691*c2c66affSColin Finck //
692*c2c66affSColin Finck 
693*c2c66affSColin Finck #define PASSIVE_LEVEL 0             // Passive release level
694*c2c66affSColin Finck #define LOW_LEVEL 0                 // Lowest interrupt level
695*c2c66affSColin Finck #define APC_LEVEL 1                 // APC interrupt level
696*c2c66affSColin Finck #define DISPATCH_LEVEL 2            // Dispatcher level
697*c2c66affSColin Finck 
698*c2c66affSColin Finck #define PROFILE_LEVEL 27            // timer used for profiling.
699*c2c66affSColin Finck #define CLOCK1_LEVEL 28             // Interval clock 1 level - Not used on x86
700*c2c66affSColin Finck #define CLOCK2_LEVEL 28             // Interval clock 2 level
701*c2c66affSColin Finck #define IPI_LEVEL 29                // Interprocessor interrupt level
702*c2c66affSColin Finck #define POWER_LEVEL 30              // Power failure level
703*c2c66affSColin Finck #define HIGH_LEVEL 31               // Highest interrupt level
704*c2c66affSColin Finck #define SYNCH_LEVEL (IPI_LEVEL-1)   // synchronization level
705*c2c66affSColin Finck 
706*c2c66affSColin Finck #define KeGetCurrentIrql()      PASSIVE_LEVEL
707*c2c66affSColin Finck 
708*c2c66affSColin Finck #ifndef NT_NATIVE_MODE
709*c2c66affSColin Finck 
710*c2c66affSColin Finck typedef struct _TIME_FIELDS {
711*c2c66affSColin Finck     USHORT Year;        // range [1601...]
712*c2c66affSColin Finck     USHORT Month;       // range [1..12]
713*c2c66affSColin Finck     USHORT Day;         // range [1..31]
714*c2c66affSColin Finck     USHORT Hour;        // range [0..23]
715*c2c66affSColin Finck     USHORT Minute;      // range [0..59]
716*c2c66affSColin Finck     USHORT Second;      // range [0..59]
717*c2c66affSColin Finck     USHORT Milliseconds;// range [0..999]
718*c2c66affSColin Finck     USHORT Weekday;     // range [0..6] == [Sunday..Saturday]
719*c2c66affSColin Finck } TIME_FIELDS;
720*c2c66affSColin Finck typedef TIME_FIELDS *PTIME_FIELDS;
721*c2c66affSColin Finck 
722*c2c66affSColin Finck //#define RtlTimeFieldsToTime(a,b)     TRUE
723*c2c66affSColin Finck BOOLEAN
724*c2c66affSColin Finck RtlTimeFieldsToTime(
725*c2c66affSColin Finck     IN PTIME_FIELDS TimeFields,
726*c2c66affSColin Finck     IN PLARGE_INTEGER Time
727*c2c66affSColin Finck     );
728*c2c66affSColin Finck 
729*c2c66affSColin Finck #define ExSystemTimeToLocalTime(SysTime, LocTime)     FileTimeToLocalFileTime((PFILETIME)(SysTime), (PFILETIME)(LocTime))
730*c2c66affSColin Finck 
731*c2c66affSColin Finck //#define RtlTimeToTimeFields(a,b) {}
732*c2c66affSColin Finck BOOLEAN
733*c2c66affSColin Finck RtlTimeToTimeFields(
734*c2c66affSColin Finck     IN PLARGE_INTEGER Time,
735*c2c66affSColin Finck     IN PTIME_FIELDS TimeFields
736*c2c66affSColin Finck     );
737*c2c66affSColin Finck 
738*c2c66affSColin Finck #define ExLocalTimeToSystemTime(LocTime, SysTime)     LocalFileTimeToFileTime((PFILETIME)(LocTime), (PFILETIME)(SysTime))
739*c2c66affSColin Finck 
740*c2c66affSColin Finck #endif //NT_NATIVE_MODE
741*c2c66affSColin Finck 
742*c2c66affSColin Finck #ifndef CDRW_W32
743*c2c66affSColin Finck 
744*c2c66affSColin Finck typedef struct _FSRTL_COMMON_FCB_HEADER {
745*c2c66affSColin Finck     SHORT           NodeTypeCode;
746*c2c66affSColin Finck     SHORT           NodeByteSize;
747*c2c66affSColin Finck     UCHAR           Flags;
748*c2c66affSColin Finck     UCHAR           IsFastIoPossible;
749*c2c66affSColin Finck #if (_WIN32_WINNT >= 0x0400)
750*c2c66affSColin Finck     UCHAR           Flags2;
751*c2c66affSColin Finck     UCHAR           Reserved;
752*c2c66affSColin Finck #endif // (_WIN32_WINNT >= 0x0400)
753*c2c66affSColin Finck     PERESOURCE      Resource;
754*c2c66affSColin Finck     PERESOURCE      PagingIoResource;
755*c2c66affSColin Finck     LARGE_INTEGER   AllocationSize;
756*c2c66affSColin Finck     LARGE_INTEGER   FileSize;
757*c2c66affSColin Finck     LARGE_INTEGER   ValidDataLength;
758*c2c66affSColin Finck } FSRTL_COMMON_FCB_HEADER, *PFSRTL_COMMON_FCB_HEADER;
759*c2c66affSColin Finck 
760*c2c66affSColin Finck typedef struct _SECTION_OBJECT_POINTERS {
761*c2c66affSColin Finck     PVOID DataSectionObject;
762*c2c66affSColin Finck     PVOID SharedCacheMap;
763*c2c66affSColin Finck     PVOID ImageSectionObject;
764*c2c66affSColin Finck } SECTION_OBJECT_POINTERS;
765*c2c66affSColin Finck typedef SECTION_OBJECT_POINTERS *PSECTION_OBJECT_POINTERS;
766*c2c66affSColin Finck 
767*c2c66affSColin Finck 
768*c2c66affSColin Finck extern NTSTATUS UDFPhReadSynchronous(
769*c2c66affSColin Finck                    PDEVICE_OBJECT      DeviceObject,
770*c2c66affSColin Finck                    PVOID           Buffer,
771*c2c66affSColin Finck                    ULONG           Length,
772*c2c66affSColin Finck                    LONGLONG        Offset,
773*c2c66affSColin Finck                    PULONG          ReadBytes,
774*c2c66affSColin Finck                    ULONG           Flags);
775*c2c66affSColin Finck 
776*c2c66affSColin Finck extern NTSTATUS UDFPhWriteSynchronous(
777*c2c66affSColin Finck                    PDEVICE_OBJECT  DeviceObject,   // the physical device object
778*c2c66affSColin Finck                    PVOID           Buffer,
779*c2c66affSColin Finck                    ULONG           Length,
780*c2c66affSColin Finck                    LONGLONG        Offset,
781*c2c66affSColin Finck                    PULONG          WrittenBytes,
782*c2c66affSColin Finck                    ULONG           Flags);
783*c2c66affSColin Finck 
784*c2c66affSColin Finck #if 0
785*c2c66affSColin Finck extern NTSTATUS
786*c2c66affSColin Finck UDFPhWriteVerifySynchronous(
787*c2c66affSColin Finck     PDEVICE_OBJECT  DeviceObject,   // the physical device object
788*c2c66affSColin Finck     PVOID           Buffer,
789*c2c66affSColin Finck     ULONG           Length,
790*c2c66affSColin Finck     LONGLONG        Offset,
791*c2c66affSColin Finck     PULONG          WrittenBytes,
792*c2c66affSColin Finck     ULONG           Flags
793*c2c66affSColin Finck     );
794*c2c66affSColin Finck #endif
795*c2c66affSColin Finck 
796*c2c66affSColin Finck #define UDFPhWriteVerifySynchronous   UDFPhWriteSynchronous
797*c2c66affSColin Finck 
798*c2c66affSColin Finck extern NTSTATUS UDFPhSendIOCTL(
799*c2c66affSColin Finck     IN ULONG IoControlCode,
800*c2c66affSColin Finck     IN PDEVICE_OBJECT DeviceObject,
801*c2c66affSColin Finck     IN PVOID InputBuffer ,
802*c2c66affSColin Finck     IN ULONG InputBufferLength,
803*c2c66affSColin Finck     OUT PVOID OutputBuffer ,
804*c2c66affSColin Finck     IN ULONG OutputBufferLength,
805*c2c66affSColin Finck     IN BOOLEAN OverrideVerify,
806*c2c66affSColin Finck     OUT PVOID Iosb OPTIONAL);
807*c2c66affSColin Finck 
808*c2c66affSColin Finck #endif //CDRW_W32
809*c2c66affSColin Finck 
810*c2c66affSColin Finck VOID set_image_size(HANDLE h,
811*c2c66affSColin Finck //                    ULONG LBA);
812*c2c66affSColin Finck                     int64  len);
813*c2c66affSColin Finck 
814*c2c66affSColin Finck #ifdef UDF_FORMAT_MEDIA
815*c2c66affSColin Finck struct _UDFVolumeControlBlock;
816*c2c66affSColin Finck #endif
817*c2c66affSColin Finck 
818*c2c66affSColin Finck #ifndef UDF_FORMAT_MEDIA
819*c2c66affSColin Finck ULONG write(
820*c2c66affSColin Finck             HANDLE h,
821*c2c66affSColin Finck             PCHAR buff,
822*c2c66affSColin Finck             ULONG len);
823*c2c66affSColin Finck #endif
824*c2c66affSColin Finck 
825*c2c66affSColin Finck extern "C"
826*c2c66affSColin Finck HANDLE
827*c2c66affSColin Finck my_open(
828*c2c66affSColin Finck #ifndef CDRW_W32
829*c2c66affSColin Finck     struct _UDFVolumeControlBlock* Vcb,
830*c2c66affSColin Finck #endif //CDRW_W32
831*c2c66affSColin Finck     PWCHAR fn);
832*c2c66affSColin Finck 
833*c2c66affSColin Finck #ifdef UDF_FORMAT_MEDIA
834*c2c66affSColin Finck struct _UDFFmtState;
835*c2c66affSColin Finck #endif //UDF_FORMAT_MEDIA
836*c2c66affSColin Finck 
837*c2c66affSColin Finck extern
838*c2c66affSColin Finck void
839*c2c66affSColin Finck my_exit(
840*c2c66affSColin Finck #ifdef UDF_FORMAT_MEDIA
841*c2c66affSColin Finck     struct _UDFFmtState* fms,
842*c2c66affSColin Finck #endif //UDF_FORMAT_MEDIA
843*c2c66affSColin Finck     int rc
844*c2c66affSColin Finck     );
845*c2c66affSColin Finck 
846*c2c66affSColin Finck #ifndef CDRW_W32
847*c2c66affSColin Finck uint64 udf_lseek64(HANDLE fd, uint64 offset, int whence);
848*c2c66affSColin Finck #endif //CDRW_W32
849*c2c66affSColin Finck 
850*c2c66affSColin Finck #ifdef LIBUDFFMT
851*c2c66affSColin Finck BOOLEAN
852*c2c66affSColin Finck udf_get_sizes(
853*c2c66affSColin Finck     IN PDEVICE_OBJECT DeviceObject,
854*c2c66affSColin Finck     IN ULONG* blocks
855*c2c66affSColin Finck     );
856*c2c66affSColin Finck #endif //LIBUDFFMT
857*c2c66affSColin Finck 
858*c2c66affSColin Finck int64
859*c2c66affSColin Finck get_file_size(
860*c2c66affSColin Finck     HANDLE h
861*c2c66affSColin Finck     );
862*c2c66affSColin Finck 
863*c2c66affSColin Finck int64
864*c2c66affSColin Finck set_file_pointer(
865*c2c66affSColin Finck     HANDLE h,
866*c2c66affSColin Finck     int64 sz
867*c2c66affSColin Finck     );
868*c2c66affSColin Finck 
869*c2c66affSColin Finck #ifndef NT_NATIVE_MODE
870*c2c66affSColin Finck typedef struct _IO_STATUS_BLOCK {
871*c2c66affSColin Finck     ULONG Status;
872*c2c66affSColin Finck     ULONG Information;
873*c2c66affSColin Finck } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
874*c2c66affSColin Finck #endif //NT_NATIVE_MODE
875*c2c66affSColin Finck 
876*c2c66affSColin Finck 
877*c2c66affSColin Finck #ifndef UDF_FORMAT_MEDIA
878*c2c66affSColin Finck extern ULONG   LockMode;
879*c2c66affSColin Finck extern BOOLEAN open_as_device;
880*c2c66affSColin Finck extern BOOLEAN opt_invalidate_volume;
881*c2c66affSColin Finck #endif //UDF_FORMAT_MEDIA
882*c2c66affSColin Finck 
883*c2c66affSColin Finck extern "C"
884*c2c66affSColin Finck ULONG
885*c2c66affSColin Finck MyLockVolume(
886*c2c66affSColin Finck     HANDLE h,
887*c2c66affSColin Finck     ULONG* pLockMode // OUT
888*c2c66affSColin Finck     );
889*c2c66affSColin Finck 
890*c2c66affSColin Finck extern "C"
891*c2c66affSColin Finck ULONG
892*c2c66affSColin Finck MyUnlockVolume(
893*c2c66affSColin Finck     HANDLE h,
894*c2c66affSColin Finck     ULONG* pLockMode // IN
895*c2c66affSColin Finck     );
896*c2c66affSColin Finck 
897*c2c66affSColin Finck #ifndef CDRW_W32
898*c2c66affSColin Finck ULONG
899*c2c66affSColin Finck UDFGetDevType(PDEVICE_OBJECT DeviceObject);
900*c2c66affSColin Finck #endif //CDRW_W32
901*c2c66affSColin Finck 
902*c2c66affSColin Finck #ifndef INVALID_HANDLE_VALUE
903*c2c66affSColin Finck #define INVALID_HANDLE_VALUE    ((HANDLE)(-1))
904*c2c66affSColin Finck #endif
905*c2c66affSColin Finck 
906*c2c66affSColin Finck #ifndef ANSI_DOS_STAR
907*c2c66affSColin Finck 
908*c2c66affSColin Finck #define ANSI_DOS_STAR   ('<')
909*c2c66affSColin Finck #define ANSI_DOS_QM     ('>')
910*c2c66affSColin Finck #define ANSI_DOS_DOT    ('"')
911*c2c66affSColin Finck 
912*c2c66affSColin Finck #define DOS_STAR        (L'<')
913*c2c66affSColin Finck #define DOS_QM          (L'>')
914*c2c66affSColin Finck #define DOS_DOT         (L'"')
915*c2c66affSColin Finck 
916*c2c66affSColin Finck #endif //ANSI_DOS_STAR
917*c2c66affSColin Finck 
918*c2c66affSColin Finck extern "C"
919*c2c66affSColin Finck BOOLEAN
920*c2c66affSColin Finck ProbeMemory(
921*c2c66affSColin Finck     PVOID   MemPtr,
922*c2c66affSColin Finck     ULONG   Length,
923*c2c66affSColin Finck     BOOLEAN ForWrite
924*c2c66affSColin Finck     );
925*c2c66affSColin Finck 
926*c2c66affSColin Finck #ifdef NT_NATIVE_MODE
927*c2c66affSColin Finck #include "env_spec_nt.h"
928*c2c66affSColin Finck #endif //NT_NATIVE_MODE
929*c2c66affSColin Finck 
930*c2c66affSColin Finck #ifndef InitializeListHead
931*c2c66affSColin Finck 
932*c2c66affSColin Finck //
933*c2c66affSColin Finck //  Doubly-linked list manipulation routines.  Implemented as macros
934*c2c66affSColin Finck //  but logically these are procedures.
935*c2c66affSColin Finck //
936*c2c66affSColin Finck 
937*c2c66affSColin Finck //
938*c2c66affSColin Finck //  VOID
939*c2c66affSColin Finck //  InitializeListHead(
940*c2c66affSColin Finck //      PLIST_ENTRY ListHead
941*c2c66affSColin Finck //      );
942*c2c66affSColin Finck //
943*c2c66affSColin Finck 
944*c2c66affSColin Finck #define InitializeListHead(ListHead) (\
945*c2c66affSColin Finck     (ListHead)->Flink = (ListHead)->Blink = (ListHead))
946*c2c66affSColin Finck 
947*c2c66affSColin Finck //
948*c2c66affSColin Finck //  BOOLEAN
949*c2c66affSColin Finck //  IsListEmpty(
950*c2c66affSColin Finck //      PLIST_ENTRY ListHead
951*c2c66affSColin Finck //      );
952*c2c66affSColin Finck //
953*c2c66affSColin Finck 
954*c2c66affSColin Finck #define IsListEmpty(ListHead) \
955*c2c66affSColin Finck     ((ListHead)->Flink == (ListHead))
956*c2c66affSColin Finck 
957*c2c66affSColin Finck //
958*c2c66affSColin Finck //  PLIST_ENTRY
959*c2c66affSColin Finck //  RemoveHeadList(
960*c2c66affSColin Finck //      PLIST_ENTRY ListHead
961*c2c66affSColin Finck //      );
962*c2c66affSColin Finck //
963*c2c66affSColin Finck 
964*c2c66affSColin Finck #define RemoveHeadList(ListHead) \
965*c2c66affSColin Finck     (ListHead)->Flink;\
966*c2c66affSColin Finck     {RemoveEntryList((ListHead)->Flink)}
967*c2c66affSColin Finck 
968*c2c66affSColin Finck //
969*c2c66affSColin Finck //  PLIST_ENTRY
970*c2c66affSColin Finck //  RemoveTailList(
971*c2c66affSColin Finck //      PLIST_ENTRY ListHead
972*c2c66affSColin Finck //      );
973*c2c66affSColin Finck //
974*c2c66affSColin Finck 
975*c2c66affSColin Finck #define RemoveTailList(ListHead) \
976*c2c66affSColin Finck     (ListHead)->Blink;\
977*c2c66affSColin Finck     {RemoveEntryList((ListHead)->Blink)}
978*c2c66affSColin Finck 
979*c2c66affSColin Finck //
980*c2c66affSColin Finck //  VOID
981*c2c66affSColin Finck //  RemoveEntryList(
982*c2c66affSColin Finck //      PLIST_ENTRY Entry
983*c2c66affSColin Finck //      );
984*c2c66affSColin Finck //
985*c2c66affSColin Finck 
986*c2c66affSColin Finck #define RemoveEntryList(Entry) {\
987*c2c66affSColin Finck     PLIST_ENTRY _EX_Blink;\
988*c2c66affSColin Finck     PLIST_ENTRY _EX_Flink;\
989*c2c66affSColin Finck     _EX_Flink = (Entry)->Flink;\
990*c2c66affSColin Finck     _EX_Blink = (Entry)->Blink;\
991*c2c66affSColin Finck     _EX_Blink->Flink = _EX_Flink;\
992*c2c66affSColin Finck     _EX_Flink->Blink = _EX_Blink;\
993*c2c66affSColin Finck     }
994*c2c66affSColin Finck 
995*c2c66affSColin Finck //
996*c2c66affSColin Finck //  VOID
997*c2c66affSColin Finck //  InsertTailList(
998*c2c66affSColin Finck //      PLIST_ENTRY ListHead,
999*c2c66affSColin Finck //      PLIST_ENTRY Entry
1000*c2c66affSColin Finck //      );
1001*c2c66affSColin Finck //
1002*c2c66affSColin Finck 
1003*c2c66affSColin Finck #define InsertTailList(ListHead,Entry) {\
1004*c2c66affSColin Finck     PLIST_ENTRY _EX_Blink;\
1005*c2c66affSColin Finck     PLIST_ENTRY _EX_ListHead;\
1006*c2c66affSColin Finck     _EX_ListHead = (ListHead);\
1007*c2c66affSColin Finck     _EX_Blink = _EX_ListHead->Blink;\
1008*c2c66affSColin Finck     (Entry)->Flink = _EX_ListHead;\
1009*c2c66affSColin Finck     (Entry)->Blink = _EX_Blink;\
1010*c2c66affSColin Finck     _EX_Blink->Flink = (Entry);\
1011*c2c66affSColin Finck     _EX_ListHead->Blink = (Entry);\
1012*c2c66affSColin Finck     }
1013*c2c66affSColin Finck 
1014*c2c66affSColin Finck //
1015*c2c66affSColin Finck //  VOID
1016*c2c66affSColin Finck //  InsertHeadList(
1017*c2c66affSColin Finck //      PLIST_ENTRY ListHead,
1018*c2c66affSColin Finck //      PLIST_ENTRY Entry
1019*c2c66affSColin Finck //      );
1020*c2c66affSColin Finck //
1021*c2c66affSColin Finck 
1022*c2c66affSColin Finck #define InsertHeadList(ListHead,Entry) {\
1023*c2c66affSColin Finck     PLIST_ENTRY _EX_Flink;\
1024*c2c66affSColin Finck     PLIST_ENTRY _EX_ListHead;\
1025*c2c66affSColin Finck     _EX_ListHead = (ListHead);\
1026*c2c66affSColin Finck     _EX_Flink = _EX_ListHead->Flink;\
1027*c2c66affSColin Finck     (Entry)->Flink = _EX_Flink;\
1028*c2c66affSColin Finck     (Entry)->Blink = _EX_ListHead;\
1029*c2c66affSColin Finck     _EX_Flink->Blink = (Entry);\
1030*c2c66affSColin Finck     _EX_ListHead->Flink = (Entry);\
1031*c2c66affSColin Finck     }
1032*c2c66affSColin Finck 
1033*c2c66affSColin Finck #endif //InitializeListHead
1034*c2c66affSColin Finck 
1035*c2c66affSColin Finck #endif  // __ENV_SPEC_W32__H_
1036