6e26a67b1ac6c71866fc8e98f0fc7ffa8ce6abe4
[reactos.git] / reactos / drivers / filesystems / udfs / udffs.h
1 ////////////////////////////////////////////////////////////////////
2 // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
3 // All rights reserved
4 // This file was released under the GPLv2 on June 2015.
5 ////////////////////////////////////////////////////////////////////
6 /*************************************************************************
7 *
8 * File: UDF.h
9 *
10 * Module: UDF File System Driver (Kernel mode execution only)
11 *
12 * Description:
13 * The main include file for the UDF file system driver.
14 *
15 *************************************************************************/
16
17 #ifndef _UDF_UDF_H_
18 #define _UDF_UDF_H_
19
20 /**************** OPTIONS *****************/
21
22 //#define UDF_TRACK_UNICODE_STR
23
24 //#define DEMO
25
26 //#define UDF_LIMIT_NAME_LEN
27
28 //#define UDF_LIMIT_DIR_SIZE
29
30 #ifdef UDF_LIMIT_NAME_LEN
31 #define UDF_X_NAME_LEN (20)
32 #define UDF_X_PATH_LEN (25)
33 #else //UDF_LIMIT_NAME_LEN
34 #define UDF_X_NAME_LEN UDF_NAME_LEN
35 #define UDF_X_PATH_LEN UDF_PATH_LEN
36 #endif //UDF_LIMIT_NAME_LEN
37
38 #define IFS_40
39 //#define PRETEND_NTFS
40
41 //#define UDF_ASYNC_IO
42
43 //#define UDF_ENABLE_SECURITY
44
45 #define UDF_HANDLE_EAS
46
47 #define UDF_HDD_SUPPORT
48
49 #define UDF_ALLOW_FRAG_AD
50
51 #ifndef UDF_LIMIT_DIR_SIZE
52 #define UDF_DEFAULT_DIR_PACK_THRESHOLD (128)
53 #else // UDF_LIMIT_DIR_SIZE
54 #define UDF_DEFAULT_DIR_PACK_THRESHOLD (16)
55 #endif // UDF_LIMIT_DIR_SIZE
56
57 #ifdef DEMO
58 #define UDF_DEMO_VOLUME_LABEL L"UDF Demo"
59 #endif //DEMO
60
61 #define UDF_DEFAULT_READAHEAD_GRAN 0x10000
62 #define UDF_DEFAULT_SPARSE_THRESHOLD (256*PACKETSIZE_UDF)
63
64 #define ALLOW_SPARSE
65
66 #define UDF_PACK_DIRS
67
68 #define MOUNT_ERR_THRESHOLD 256
69
70 #define UDF_VALID_FILE_ATTRIBUTES \
71 (FILE_ATTRIBUTE_READONLY | \
72 FILE_ATTRIBUTE_HIDDEN | \
73 FILE_ATTRIBUTE_SYSTEM | \
74 FILE_ATTRIBUTE_DIRECTORY | \
75 FILE_ATTRIBUTE_ARCHIVE | \
76 /*FILE_ATTRIBUTE_DEVICE | */ \
77 FILE_ATTRIBUTE_NORMAL | \
78 FILE_ATTRIBUTE_TEMPORARY | \
79 FILE_ATTRIBUTE_SPARSE_FILE)
80
81 //#define UDF_DISABLE_SYSTEM_CACHE_MANAGER
82
83 //#define UDF_CDRW_EMULATION_ON_ROM
84
85 #define UDF_DELAYED_CLOSE
86
87 #ifdef UDF_DELAYED_CLOSE
88 #define UDF_FE_ALLOCATION_CHARGE
89 #endif //UDF_DELAYED_CLOSE
90
91 #define UDF_ALLOW_RENAME_MOVE
92
93 #define UDF_ALLOW_HARD_LINKS
94
95 #ifdef UDF_ALLOW_HARD_LINKS
96 //#define UDF_ALLOW_LINKS_TO_STREAMS
97 #endif //UDF_ALLOW_HARD_LINKS
98
99 //#define UDF_ALLOW_PRETEND_DELETED
100
101 #define UDF_DEFAULT_BM_FLUSH_TIMEOUT 16 // seconds
102 #define UDF_DEFAULT_TREE_FLUSH_TIMEOUT 5 // seconds
103
104 #define UDF_DEFAULT_FSP_THREAD_PER_CPU (4)
105 #define UDF_FSP_THREAD_PER_CPU (Vcb->ThreadsPerCpu)
106 #define FSP_PER_DEVICE_THRESHOLD (UDFGlobalData.CPU_Count*UDF_FSP_THREAD_PER_CPU)
107
108 /************* END OF OPTIONS **************/
109
110 // some constant definitions
111 #define UDF_PANIC_IDENTIFIER (0x86427531)
112
113 // Common include files - should be in the include dir of the MS supplied IFS Kit
114 #ifndef _CONSOLE
115 extern "C" {
116 #pragma pack(push, 8)
117 #include "ntifs.h"
118 #include "ntifs_ex.h"
119 #pragma pack(pop)
120 }
121 #endif //_CONSOLE
122
123 #include <pseh/pseh2.h>
124
125 #include "Include/check_env.h"
126
127 #define PEXTENDED_IO_STACK_LOCATION PIO_STACK_LOCATION
128
129 #ifndef NDEBUG
130 #define UDF_DBG
131 #endif
132
133 #define VALIDATE_STRUCTURES
134 // the following include files should be in the inc sub-dir associated with this driver
135
136 #define OS_SUCCESS(a) NT_SUCCESS(a)
137 #define OSSTATUS NTSTATUS
138
139 #ifndef _CONSOLE
140 #include "ntdddisk.h"
141 #include <devioctl.h>
142 #include "Include/CrossNt/CrossNt.h"
143 #endif //_CONSOLE
144
145 #include <stddef.h>
146 #include <string.h>
147 #include <stdio.h>
148 //#include "ecma_167.h"
149 //#include "osta_misc.h"
150 #include "wcache.h"
151 #include "CDRW/cdrw_usr.h"
152
153 #include "Include/regtools.h"
154
155 #ifdef _CONSOLE
156 #include "udf_info/udf_rel.h"
157 #include "Include/udf_common.h"
158 #else
159 #include "struct.h"
160 #endif //_CONSOLE
161
162 // global variables - minimize these
163 extern UDFData UDFGlobalData;
164
165 #ifndef _CONSOLE
166 #include "env_spec.h"
167 #include "dldetect.h"
168 #include "udf_dbg.h"
169 #else
170 #include "Include/env_spec_w32.h"
171 #endif //_CONSOLE
172
173 #include "sys_spec.h"
174
175 #include "udf_info/udf_info.h"
176
177 #ifndef _CONSOLE
178 #include "protos.h"
179 #endif //_CONSOLE
180
181 #include "Include/phys_lib.h"
182 #include "errmsg.h"
183 //#include "Include/tools.h"
184 #include "Include/protect.h"
185 #include "udfpubl.h"
186 //#include "ntifs.h"
187 #include "mem.h"
188 #include "Include/key_lib.h"
189
190 extern CCHAR DefLetter[];
191
192 // try-finally simulation
193 #define try_return(S) { S; goto try_exit; }
194 #define try_return1(S) { S; goto try_exit1; }
195 #define try_return2(S) { S; goto try_exit2; }
196
197 // some global (helpful) macros
198 #define UDFSetFlag(Flag, Value) ((Flag) |= (Value))
199 #define UDFClearFlag(Flag, Value) ((Flag) &= ~(Value))
200
201 #define PtrOffset(BASE,OFFSET) ((ULONG)((ULONG)(OFFSET) - (ULONG)(BASE)))
202
203 #define UDFQuadAlign(Value) ((((uint32)(Value)) + 7) & 0xfffffff8)
204
205 // to perform a bug-check (panic), the following macro is used
206 #define UDFPanic(arg1, arg2, arg3) \
207 (KeBugCheckEx(UDF_PANIC_IDENTIFIER, UDF_BUG_CHECK_ID | __LINE__, (uint32)(arg1), (uint32)(arg2), (uint32)(arg3)))
208 // small check for illegal open mode (desired access) if volume is
209 // read only (on standard CD-ROM device or another like this)
210 #define UdfIllegalFcbAccess(Vcb,DesiredAccess) (( \
211 (Vcb->VCBFlags & UDF_VCB_FLAGS_VOLUME_READ_ONLY) && \
212 (FlagOn( (DesiredAccess), \
213 FILE_WRITE_DATA | \
214 FILE_ADD_FILE | \
215 FILE_APPEND_DATA | \
216 FILE_ADD_SUBDIRECTORY | \
217 FILE_WRITE_EA | \
218 FILE_DELETE_CHILD | \
219 FILE_WRITE_ATTRIBUTES | \
220 DELETE | \
221 WRITE_OWNER | \
222 WRITE_DAC )) \
223 ) || ( \
224 !(Vcb->WriteSecurity) && \
225 (FlagOn( (DesiredAccess), \
226 WRITE_OWNER | \
227 0 /*WRITE_DAC*/ )) \
228 ))
229
230
231 //
232 #if !defined(UDF_DBG) && !defined(PRINT_ALWAYS)
233
234 #ifndef _CONSOLE
235 #define UDFAcquireResourceExclusive(Resource,CanWait) \
236 (ExAcquireResourceExclusiveLite((Resource),(CanWait)))
237 #define UDFAcquireResourceShared(Resource,CanWait) \
238 (ExAcquireResourceSharedLite((Resource),(CanWait)))
239 // a convenient macro (must be invoked in the context of the thread that acquired the resource)
240 #define UDFReleaseResource(Resource) \
241 (ExReleaseResourceForThreadLite((Resource), ExGetCurrentResourceThread()))
242 #define UDFDeleteResource(Resource) \
243 (ExDeleteResourceLite((Resource)))
244 #define UDFConvertExclusiveToSharedLite(Resource) \
245 (ExConvertExclusiveToSharedLite((Resource)))
246 #define UDFInitializeResourceLite(Resource) \
247 (ExInitializeResourceLite((Resource)))
248 #define UDFAcquireSharedStarveExclusive(Resource,CanWait) \
249 (ExAcquireSharedStarveExclusive((Resource),(CanWait)))
250 #define UDFAcquireSharedWaitForExclusive(Resource,CanWait) \
251 (ExAcquireSharedWaitForExclusive((Resource),(CanWait)))
252
253 #define UDFInterlockedIncrement(addr) \
254 (InterlockedIncrement((addr)))
255 #define UDFInterlockedDecrement(addr) \
256 (InterlockedDecrement((addr)))
257 #define UDFInterlockedExchangeAdd(addr,i) \
258 (InterlockedExchangeAdd((addr),(i)))
259
260 #endif //_CONSOLE
261
262 #define UDF_CHECK_PAGING_IO_RESOURCE(NTReqFCB)
263 #define UDF_CHECK_EXVCB_RESOURCE(Vcb)
264 #define UDF_CHECK_BITMAP_RESOURCE(Vcb)
265
266
267 #else //UDF_DBG
268
269 #ifndef _CONSOLE
270 #define UDFAcquireResourceExclusive(Resource,CanWait) \
271 (UDFDebugAcquireResourceExclusiveLite((Resource),(CanWait),UDF_BUG_CHECK_ID,__LINE__))
272
273 #define UDFAcquireResourceShared(Resource,CanWait) \
274 (UDFDebugAcquireResourceSharedLite((Resource),(CanWait),UDF_BUG_CHECK_ID,__LINE__))
275 // a convenient macro (must be invoked in the context of the thread that acquired the resource)
276 #define UDFReleaseResource(Resource) \
277 (UDFDebugReleaseResourceForThreadLite((Resource), ExGetCurrentResourceThread(),UDF_BUG_CHECK_ID,__LINE__))
278
279 #define UDFDeleteResource(Resource) \
280 (UDFDebugDeleteResource((Resource), ExGetCurrentResourceThread(),UDF_BUG_CHECK_ID,__LINE__))
281 #define UDFConvertExclusiveToSharedLite(Resource) \
282 (UDFDebugConvertExclusiveToSharedLite((Resource), ExGetCurrentResourceThread(),UDF_BUG_CHECK_ID,__LINE__))
283 #define UDFInitializeResourceLite(Resource) \
284 (UDFDebugInitializeResourceLite((Resource), ExGetCurrentResourceThread(),UDF_BUG_CHECK_ID,__LINE__))
285 #define UDFAcquireSharedStarveExclusive(Resource,CanWait) \
286 (UDFDebugAcquireSharedStarveExclusive((Resource), (CanWait), UDF_BUG_CHECK_ID,__LINE__))
287 #define UDFAcquireSharedWaitForExclusive(Resource,CanWait) \
288 (UDFDebugAcquireSharedWaitForExclusive((Resource), (CanWait), UDF_BUG_CHECK_ID,__LINE__))
289
290 #define UDFInterlockedIncrement(addr) \
291 (UDFDebugInterlockedIncrement((addr), UDF_BUG_CHECK_ID,__LINE__))
292 #define UDFInterlockedDecrement(addr) \
293 (UDFDebugInterlockedDecrement((addr), UDF_BUG_CHECK_ID,__LINE__))
294 #define UDFInterlockedExchangeAdd(addr,i) \
295 (UDFDebugInterlockedExchangeAdd((addr),(i), UDF_BUG_CHECK_ID,__LINE__))
296
297 #endif //_CONSOLE
298
299 #define UDF_CHECK_PAGING_IO_RESOURCE(NTReqFCB) \
300 ASSERT(!ExIsResourceAcquiredExclusiveLite(&(NTReqFCB->PagingIoResource))); \
301 ASSERT(!ExIsResourceAcquiredSharedLite(&(NTReqFCB->PagingIoResource)));
302
303 #define UDF_CHECK_EXVCB_RESOURCE(Vcb) \
304 ASSERT( ExIsResourceAcquiredExclusiveLite(&(Vcb->VCBResource)) );
305
306 #define UDF_CHECK_BITMAP_RESOURCE(Vcb)
307 /* \
308 ASSERT( (ExIsResourceAcquiredExclusiveLite(&(Vcb->VCBResource)) || \
309 ExIsResourceAcquiredSharedLite(&(Vcb->VCBResource))) ); \
310 ASSERT(ExIsResourceAcquiredExclusiveLite(&(Vcb->BitMapResource1))); \
311 */
312 #endif //UDF_DBG
313
314 #define UDFRaiseStatus(IC,S) { \
315 (IC)->SavedExceptionCode = (S); \
316 ExRaiseStatus( (S) ); \
317 }
318
319 #define UDFNormalizeAndRaiseStatus(IC,S) { \
320 (IC)->SavedExceptionCode = FsRtlNormalizeNtstatus((S),STATUS_UNEXPECTED_IO_ERROR); \
321 ExRaiseStatus( (IC)->SavedExceptionCode ); \
322 }
323
324 #define UDFIsRawDevice(RC) ( \
325 ((RC) == STATUS_DEVICE_NOT_READY) || \
326 ((RC) == STATUS_NO_MEDIA_IN_DEVICE) \
327 )
328
329
330 // each file has a unique bug-check identifier associated with it.
331 // Here is a list of constant definitions for these identifiers
332 #define UDF_FILE_INIT (0x00000001)
333 #define UDF_FILE_FILTER (0x00000002)
334 #define UDF_FILE_CREATE (0x00000003)
335 #define UDF_FILE_CLEANUP (0x00000004)
336 #define UDF_FILE_CLOSE (0x00000005)
337 #define UDF_FILE_READ (0x00000006)
338 #define UDF_FILE_WRITE (0x00000007)
339 #define UDF_FILE_INFORMATION (0x00000008)
340 #define UDF_FILE_FLUSH (0x00000009)
341 #define UDF_FILE_VOL_INFORMATION (0x0000000A)
342 #define UDF_FILE_DIR_CONTROL (0x0000000B)
343 #define UDF_FILE_FILE_CONTROL (0x0000000C)
344 #define UDF_FILE_DEVICE_CONTROL (0x0000000D)
345 #define UDF_FILE_SHUTDOWN (0x0000000E)
346 #define UDF_FILE_LOCK_CONTROL (0x0000000F)
347 #define UDF_FILE_SECURITY (0x00000010)
348 #define UDF_FILE_EXT_ATTR (0x00000011)
349 #define UDF_FILE_MISC (0x00000012)
350 #define UDF_FILE_FAST_IO (0x00000013)
351 #define UDF_FILE_FS_CONTROL (0x00000014)
352 #define UDF_FILE_PHYSICAL (0x00000015)
353 #define UDF_FILE_PNP (0x00000016)
354 #define UDF_FILE_VERIFY_FS_CONTROL (0x00000017)
355 #define UDF_FILE_ENV_SPEC (0x00000018)
356 #define UDF_FILE_SYS_SPEC (0x00000019)
357 #define UDF_FILE_PHYS_EJECT (0x0000001A)
358
359 #define UDF_FILE_DLD (0x00000200)
360 #define UDF_FILE_MEM (0x00000201)
361 #define UDF_FILE_MEMH (0x00000202)
362 #define UDF_FILE_WCACHE (0x00000203)
363
364 #define UDF_FILE_UDF_INFO (0x00000100)
365 #define UDF_FILE_UDF_INFO_ALLOC (0x00000101)
366 #define UDF_FILE_UDF_INFO_DIR (0x00000102)
367 #define UDF_FILE_UDF_INFO_MOUNT (0x00000103)
368 #define UDF_FILE_UDF_INFO_EXTENT (0x00000104)
369 #define UDF_FILE_UDF_INFO_REMAP (0x00000105)
370 //#define UDF_FILE_UDF_INFO_ (0x0000010x)
371
372 #define UDF_FILE_PROTECT (0x00000300)
373 //#define UDF_FILE_PROTECT_ (0x0000030x)
374
375 #define SystemAllocatePool(hernya,size) ExAllocatePoolWithTag(hernya, size, 'Snwd')
376 #define SystemFreePool(addr) ExFreePool((PVOID)(addr))
377
378 //Device names
379
380 #include "Include/udf_reg.h"
381
382 #include <ddk/mountmgr.h>
383
384 #endif // _UDF_UDF_H_
385