[UDFS] Import a UDF File System Driver created by Alexander Telyatnikov (Alter) and...
[reactos.git] / reactos / drivers / filesystems / udfs / ntifs_ex.h
1 ////////////////////////////////////////////////////////////////////
2 // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
3 // All rights reserved
4 ////////////////////////////////////////////////////////////////////
5
6 #ifndef __NTIFS_EX_H__
7 #define __NTIFS_EX_H__
8
9 #ifndef WIN64
10
11 // _MM_PAGE_PRIORITY_ provides a method for the system to handle requests
12 // intelligently in low resource conditions.
13 //
14 // LowPagePriority should be used when it is acceptable to the driver for the
15 // mapping request to fail if the system is low on resources. An example of
16 // this could be for a non-critical network connection where the driver can
17 // handle the failure case when system resources are close to being depleted.
18 //
19 // NormalPagePriority should be used when it is acceptable to the driver for the
20 // mapping request to fail if the system is very low on resources. An example
21 // of this could be for a non-critical local filesystem request.
22 //
23 // HighPagePriority should be used when it is unacceptable to the driver for the
24 // mapping request to fail unless the system is completely out of resources.
25 // An example of this would be the paging file path in a driver.
26 //
27
28 #if 0
29 typedef enum _MM_PAGE_PRIORITY {
30 LowPagePriority,
31 NormalPagePriority = 16,
32 HighPagePriority = 32
33 } MM_PAGE_PRIORITY;
34 #endif
35
36 #endif //WIN64
37
38 //
39 // Note: This function is not available in WDM 1.0
40 //
41 #if 0
42 NTKERNELAPI
43 PVOID
44 MmMapLockedPagesSpecifyCache (
45 IN PMDL MemoryDescriptorList,
46 IN KPROCESSOR_MODE AccessMode,
47 IN MEMORY_CACHING_TYPE CacheType,
48 IN PVOID BaseAddress,
49 IN ULONG BugCheckOnFailure,
50 IN MM_PAGE_PRIORITY Priority
51 );
52 #endif
53
54 // PVOID
55 // MmGetSystemAddressForMdlSafe (
56 // IN PMDL MDL,
57 // IN MM_PAGE_PRIORITY PRIORITY
58 // )
59 //
60 // Routine Description:
61 //
62 // This routine returns the mapped address of an MDL. If the
63 // Mdl is not already mapped or a system address, it is mapped.
64 //
65 // Arguments:
66 //
67 // MemoryDescriptorList - Pointer to the MDL to map.
68 //
69 // Priority - Supplies an indication as to how important it is that this
70 // request succeed under low available PTE conditions.
71 //
72 // Return Value:
73 //
74 // Returns the base address where the pages are mapped. The base address
75 // has the same offset as the virtual address in the MDL.
76 //
77 // Unlike MmGetSystemAddressForMdl, Safe guarantees that it will always
78 // return NULL on failure instead of bugchecking the system.
79 //
80 // This macro is not usable by WDM 1.0 drivers as 1.0 did not include
81 // MmMapLockedPagesSpecifyCache. The solution for WDM 1.0 drivers is to
82 // provide synchronization and set/reset the MDL_MAPPING_CAN_FAIL bit.
83 //
84 //--
85
86 #if 0
87 #define MmGetSystemAddressForMdlSafe(MDL, PRIORITY) \
88 (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
89 MDL_SOURCE_IS_NONPAGED_POOL)) ? \
90 ((MDL)->MappedSystemVa) : \
91 (MmMapLockedPagesSpecifyCache((MDL), \
92 KernelMode, \
93 MmCached, \
94 NULL, \
95 FALSE, \
96 (PRIORITY))))
97 #endif
98
99
100 __inline PVOID MmGetSystemAddressForMdlSafer(IN PMDL Mdl)
101 {
102 PVOID Addr;
103
104 if (Mdl->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | MDL_SOURCE_IS_NONPAGED_POOL)) {
105 Addr = Mdl->MappedSystemVa;
106 } else {
107 CSHORT PrevFlag = Mdl->MdlFlags & MDL_MAPPING_CAN_FAIL;
108
109 Mdl->MdlFlags |= MDL_MAPPING_CAN_FAIL;
110 Addr = MmMapLockedPages(Mdl, KernelMode);
111 Mdl->MdlFlags = (Mdl->MdlFlags & ~MDL_MAPPING_CAN_FAIL) | PrevFlag;
112 }
113
114 return(Addr);
115 }
116
117 #define FULL_SECURITY_INFORMATION (OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION)
118
119 #ifndef WIN64
120 #if 0
121 NTSYSAPI
122 ULONG
123 NTAPI
124 RtlLengthRequiredSid (
125 IN UCHAR SubAuthorityCount
126 );
127 #endif
128
129 #endif //WIN64
130
131 NTSYSAPI
132 NTSTATUS
133 NTAPI
134 RtlSetGroupSecurityDescriptor (
135 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
136 IN PSID Group,
137 IN BOOLEAN GroupDefaulted
138 );
139
140 NTSYSAPI
141 NTSTATUS
142 NTAPI
143 RtlSetSaclSecurityDescriptor (
144 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
145 IN BOOLEAN SaclPresent,
146 IN PACL Sacl,
147 IN BOOLEAN SaclDefaulted
148 );
149
150 NTSYSAPI
151 PUCHAR
152 NTAPI
153 RtlSubAuthorityCountSid (
154 IN PSID Sid
155 );
156
157 #if 0
158 NTKERNELAPI
159 HANDLE
160 PsReferencePrimaryToken (
161 IN PEPROCESS Process
162 );
163 #endif
164
165 NTSYSAPI
166 NTSTATUS
167 NTAPI
168 RtlAbsoluteToSelfRelativeSD (
169 IN PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
170 IN OUT PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
171 IN PULONG BufferLength
172 );
173
174 NTSYSAPI
175 NTSTATUS
176 NTAPI
177 RtlAllocateAndInitializeSid (
178 IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
179 IN UCHAR SubAuthorityCount,
180 IN ULONG SubAuthority0,
181 IN ULONG SubAuthority1,
182 IN ULONG SubAuthority2,
183 IN ULONG SubAuthority3,
184 IN ULONG SubAuthority4,
185 IN ULONG SubAuthority5,
186 IN ULONG SubAuthority6,
187 IN ULONG SubAuthority7,
188 OUT PSID *Sid
189 );
190
191 NTSYSAPI
192 NTSTATUS
193 NTAPI
194 RtlConvertSidToUnicodeString (
195 OUT PUNICODE_STRING DestinationString,
196 IN PVOID Sid,
197 IN BOOLEAN AllocateDestinationString
198 );
199
200 NTSYSAPI
201 NTSTATUS
202 NTAPI
203 RtlGetGroupSecurityDescriptor (
204 IN PSECURITY_DESCRIPTOR SecurityDescriptor,
205 OUT PSID *Group,
206 OUT PBOOLEAN GroupDefaulted
207 );
208
209 NTSYSAPI
210 NTSTATUS
211 NTAPI
212 RtlGetOwnerSecurityDescriptor (
213 IN PSECURITY_DESCRIPTOR SecurityDescriptor,
214 OUT PSID *Owner,
215 OUT PBOOLEAN OwnerDefaulted
216 );
217
218 NTSYSAPI
219 NTSTATUS
220 NTAPI
221 RtlInitializeSid (
222 IN OUT PSID Sid,
223 IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority,
224 IN UCHAR SubAuthorityCount
225 );
226
227 #ifndef WIN64
228
229 #if 0
230
231 typedef struct _TOKEN_OWNER { // to
232 PSID Owner;
233 } TOKEN_OWNER;
234
235 typedef struct _TOKEN_PRIMARY_GROUP { // tpg
236 PSID PrimaryGroup;
237 } TOKEN_PRIMARY_GROUP;
238
239 #endif
240
241 #endif //WIN64
242
243 // The following macro is used to detemine if the file object is opened
244 // for read only access (i.e., it is not also opened for write access or
245 // delete access).
246 //
247 // BOOLEAN
248 // IsFileObjectReadOnly (
249 // IN PFILE_OBJECT FileObject
250 // );
251
252 #define IsFileObjectReadOnly(FO) (!((FO)->WriteAccess | (FO)->DeleteAccess))
253
254 //
255 #ifndef FSCTL_GET_COMPRESSION
256
257 #define FSCTL_GET_COMPRESSION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
258 #define FSCTL_SET_COMPRESSION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 16, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
259
260 #define FSCTL_GET_NTFS_VOLUME_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 25, METHOD_BUFFERED, FILE_ANY_ACCESS)
261 #define FSCTL_GET_NTFS_FILE_RECORD CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 26, METHOD_BUFFERED, FILE_ANY_ACCESS)
262
263 #define FSCTL_GET_HFS_INFORMATION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 31, METHOD_BUFFERED, FILE_ANY_ACCESS)
264
265 #endif //FSCTL_GET_COMPRESSION
266
267
268 #if (_WIN32_WINNT >= 0x0500)
269 #if 0
270 #define FSCTL_READ_PROPERTY_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 33, METHOD_NEITHER, FILE_ANY_ACCESS)
271 #define FSCTL_WRITE_PROPERTY_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 34, METHOD_NEITHER, FILE_ANY_ACCESS)
272 #define FSCTL_FIND_FILES_BY_SID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 35, METHOD_NEITHER, FILE_ANY_ACCESS)
273
274 #define FSCTL_DUMP_PROPERTY_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 37, METHOD_NEITHER, FILE_ANY_ACCESS)
275 #define FSCTL_SET_OBJECT_ID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 38, METHOD_BUFFERED, FILE_WRITE_DATA)
276 #define FSCTL_GET_OBJECT_ID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 39, METHOD_BUFFERED, FILE_ANY_ACCESS)
277 #define FSCTL_DELETE_OBJECT_ID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 40, METHOD_BUFFERED, FILE_WRITE_DATA)
278 #define FSCTL_SET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 41, METHOD_BUFFERED, FILE_WRITE_DATA)
279 #define FSCTL_GET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 42, METHOD_BUFFERED, FILE_ANY_ACCESS)
280 #define FSCTL_DELETE_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 43, METHOD_BUFFERED, FILE_WRITE_DATA)
281 #define FSCTL_ENUM_USN_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 44, METHOD_NEITHER, FILE_READ_DATA)
282 #define FSCTL_SECURITY_ID_CHECK CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 45, METHOD_NEITHER, FILE_READ_DATA)
283 #define FSCTL_READ_USN_JOURNAL CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 46, METHOD_NEITHER, FILE_READ_DATA)
284 #define FSCTL_SET_OBJECT_ID_EXTENDED CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 47, METHOD_BUFFERED, FILE_WRITE_DATA)
285 #define FSCTL_CREATE_OR_GET_OBJECT_ID CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 48, METHOD_BUFFERED, FILE_ANY_ACCESS)
286 #define FSCTL_SET_SPARSE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 49, METHOD_BUFFERED, FILE_WRITE_DATA)
287 #define FSCTL_SET_ZERO_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 50, METHOD_BUFFERED, FILE_WRITE_DATA)
288 #define FSCTL_QUERY_ALLOCATED_RANGES CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 51, METHOD_NEITHER, FILE_READ_DATA)
289 #define FSCTL_ENABLE_UPGRADE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 52, METHOD_BUFFERED, FILE_WRITE_DATA)
290 #define FSCTL_SET_ENCRYPTION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 53, METHOD_BUFFERED, FILE_ANY_ACCESS)
291 #define FSCTL_ENCRYPTION_FSCTL_IO CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 54, METHOD_NEITHER, FILE_ANY_ACCESS)
292 #define FSCTL_WRITE_RAW_ENCRYPTED CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 55, METHOD_NEITHER, FILE_ANY_ACCESS)
293 #define FSCTL_READ_RAW_ENCRYPTED CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 56, METHOD_NEITHER, FILE_ANY_ACCESS)
294 #define FSCTL_CREATE_USN_JOURNAL CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 57, METHOD_NEITHER, FILE_READ_DATA)
295 #define FSCTL_READ_FILE_USN_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 58, METHOD_NEITHER, FILE_READ_DATA)
296 #define FSCTL_WRITE_USN_CLOSE_RECORD CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 59, METHOD_NEITHER, FILE_READ_DATA)
297 #define FSCTL_EXTEND_VOLUME CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 60, METHOD_BUFFERED, FILE_ANY_ACCESS)
298 #define FSCTL_QUERY_USN_JOURNAL CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 61, METHOD_BUFFERED, FILE_ANY_ACCESS)
299 #define FSCTL_DELETE_USN_JOURNAL CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 62, METHOD_BUFFERED, FILE_ANY_ACCESS)
300 #define FSCTL_MARK_HANDLE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 63, METHOD_BUFFERED, FILE_ANY_ACCESS)
301 #define FSCTL_SIS_COPYFILE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 64, METHOD_BUFFERED, FILE_ANY_ACCESS)
302 #define FSCTL_SIS_LINK_FILES CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 65, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
303 #define FSCTL_HSM_MSG CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 66, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
304
305 #define FSCTL_HSM_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 68, METHOD_NEITHER, FILE_READ_DATA | FILE_WRITE_DATA)
306 #define FSCTL_RECALL_FILE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 69, METHOD_NEITHER, FILE_ANY_ACCESS)
307
308 #define FSCTL_READ_FROM_PLEX CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 71, METHOD_OUT_DIRECT, FILE_READ_DATA)
309 #define FSCTL_FILE_PREFETCH CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 72, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
310 #endif
311 #endif // (_WIN32_WINNT >= 0x0500)
312
313 // file system flags
314 #ifndef FILE_VOLUME_QUOTAS
315
316 #define FILE_VOLUME_QUOTAS 0x00000020
317 #define FILE_SUPPORTS_SPARSE_FILES 0x00000040
318 #define FILE_SUPPORTS_REPARSE_POINTS 0x00000080
319 #define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100
320 #define FS_LFN_APIS 0x00004000
321 #define FILE_SUPPORTS_OBJECT_IDS 0x00010000
322 #define FILE_SUPPORTS_ENCRYPTION 0x00020000
323 #define FILE_NAMED_STREAMS 0x00040000
324 #define FILE_READ_ONLY_VOLUME 0x00080000
325
326 #endif //FILE_VOLUME_QUOTAS
327
328 // Output flags for the FSCTL_IS_VOLUME_DIRTY
329 #define VOLUME_IS_DIRTY (0x00000001)
330 #define VOLUME_UPGRADE_SCHEDULED (0x00000002)
331
332 NTSYSAPI
333 NTSTATUS
334 NTAPI
335 ZwFsControlFile(
336 IN HANDLE DeviceHandle,
337 IN HANDLE Event OPTIONAL,
338 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
339 IN PVOID ApcContext OPTIONAL,
340 OUT PIO_STATUS_BLOCK IoStatusBlock,
341 IN ULONG IoControlCode,
342 IN PVOID InputBuffer,
343 IN ULONG InputBufferSize,
344 OUT PVOID OutputBuffer,
345 IN ULONG OutputBufferSize
346 );
347
348 NTSYSAPI
349 NTSTATUS
350 NTAPI
351 ZwDeviceIoControlFile(
352 IN HANDLE DeviceHandle,
353 IN HANDLE Event OPTIONAL,
354 IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL,
355 IN PVOID UserApcContext OPTIONAL,
356 OUT PIO_STATUS_BLOCK IoStatusBlock,
357 IN ULONG IoControlCode,
358 IN PVOID InputBuffer,
359 IN ULONG InputBufferSize,
360 OUT PVOID OutputBuffer,
361 IN ULONG OutputBufferSize
362 );
363
364
365 NTSYSAPI
366 NTSTATUS
367 NTAPI
368 ZwQueryVolumeInformationFile(
369 IN HANDLE FileHandle,
370 OUT PIO_STATUS_BLOCK IoStatusBlock,
371 OUT PVOID FsInformation,
372 IN ULONG Length,
373 IN FS_INFORMATION_CLASS FsInformationClass
374 );
375
376
377 #ifndef FILE_ATTRIBUTE_SPARSE_FILE
378
379 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
380 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
381 #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
382 #define FILE_ATTRIBUTE_OFFLINE 0x00001000
383 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
384 #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
385
386 #endif //FILE_ATTRIBUTE_SPARSE_FILE
387
388 #define FileFsFullSizeInformation (FS_INFORMATION_CLASS(7))
389 #define FileFsObjectIdInformation (FS_INFORMATION_CLASS(8))
390 #define FileFsDriverPathInformation (FS_INFORMATION_CLASS(9))
391
392 #ifndef WIN64
393
394 #if 0
395 typedef struct _FILE_FS_FULL_SIZE_INFORMATION {
396 LARGE_INTEGER TotalAllocationUnits;
397 LARGE_INTEGER CallerAvailableAllocationUnits;
398 LARGE_INTEGER ActualAvailableAllocationUnits;
399 ULONG SectorsPerAllocationUnit;
400 ULONG BytesPerSector;
401 } FILE_FS_FULL_SIZE_INFORMATION, *PFILE_FS_FULL_SIZE_INFORMATION;
402 #endif
403
404 #endif //WIN64
405
406 #ifndef IRP_MN_SURPRISE_REMOVAL
407 #define IRP_MN_SURPRISE_REMOVAL 0x17
408 #endif //IRP_MN_SURPRISE_REMOVAL
409
410 #ifndef IoCopyCurrentIrpStackLocationToNext
411
412 #define IoCopyCurrentIrpStackLocationToNext( Irp ) { \
413 PIO_STACK_LOCATION irpSp; \
414 PIO_STACK_LOCATION nextIrpSp; \
415 irpSp = IoGetCurrentIrpStackLocation( (Irp) ); \
416 nextIrpSp = IoGetNextIrpStackLocation( (Irp) ); \
417 RtlCopyMemory( nextIrpSp, irpSp, FIELD_OFFSET(IO_STACK_LOCATION, CompletionRoutine)); \
418 nextIrpSp->Control = 0; }
419
420 #define IoSkipCurrentIrpStackLocation( Irp ) \
421 (Irp)->CurrentLocation++; \
422 (Irp)->Tail.Overlay.CurrentStackLocation++;
423
424 #endif //IoCopyCurrentIrpStackLocationToNext
425
426 #ifndef VPB_REMOVE_PENDING
427 #define VPB_REMOVE_PENDING 0x00000008
428 #endif //VPB_REMOVE_PENDING
429
430
431 //
432 // Volume lock/unlock notification routines, implemented in PnP.c
433 //
434 // These routines provide PnP volume lock notification support
435 // for all filesystems.
436 //
437
438 #define FSRTL_VOLUME_DISMOUNT 1
439 #define FSRTL_VOLUME_DISMOUNT_FAILED 2
440 #define FSRTL_VOLUME_LOCK 3
441 #define FSRTL_VOLUME_LOCK_FAILED 4
442 #define FSRTL_VOLUME_UNLOCK 5
443 #define FSRTL_VOLUME_MOUNT 6
444
445 /*NTKERNELAPI
446 NTSTATUS
447 FsRtlNotifyVolumeEvent (
448 IN PFILE_OBJECT FileObject,
449 IN ULONG EventCode
450 );*/
451
452 typedef NTSTATUS (*ptrFsRtlNotifyVolumeEvent) (
453 IN PFILE_OBJECT FileObject,
454 IN ULONG EventCode
455 );
456
457 #include "..\Include\ntddk_ex.h"
458
459 #endif //__NTIFS_EX_H__