ReactOS  0.4.14-dev-608-gd495a4f
cdprocs.h
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) 1989-2000 Microsoft Corporation
4 
5 Module Name:
6 
7  CdProcs.h
8 
9 Abstract:
10 
11  This module defines all of the globally used procedures in the Cdfs
12  file system.
13 
14 
15 --*/
16 
17 #ifndef _CDPROCS_
18 #define _CDPROCS_
19 
20 #ifdef _MSC_VER
21 #pragma warning( disable: 4127 ) // conditional expression is constant
22 
23 #pragma warning( push )
24 #pragma warning( disable: 4201 ) // nonstandard extension used : nameless struct/union
25 #pragma warning( disable: 4214 ) // nonstandard extension used : bit field types
26 #endif
27 
28 #include <ntifs.h>
29 
30 #include <ntddcdrm.h>
31 #include <ntdddisk.h>
32 #include <ntddscsi.h>
33 #ifdef __REACTOS__
34 #include <pseh/pseh2.h>
35 #endif
36 
37 #ifndef INLINE
38 #define INLINE __inline
39 #endif
40 
41 #include "nodetype.h"
42 #include "cd.h"
43 #include "cdstruc.h"
44 #include "cddata.h"
45 
46 #ifdef CDFS_TELEMETRY_DATA
47 
48 #include <winmeta.h>
49 #include <TraceLoggingProvider.h>
50 #include <telemetry\MicrosoftTelemetry.h>
51 
52 #endif // CDFS_TELEMETRY_DATA
53 
54 #ifdef _MSC_VER
55 #pragma warning( pop )
56 #endif
57 
58 //**** x86 compiler bug ****
59 
60 #if defined(_M_IX86)
61 #undef Int64ShraMod32
62 #define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
63 #endif
64 
65 #ifndef Min
66 #define Min(a, b) ((a) < (b) ? (a) : (b))
67 #endif
68 
69 #ifndef Max
70 #define Max(a, b) ((a) > (b) ? (a) : (b))
71 #endif
72 
73 //
74 // Here are the different pool tags.
75 //
76 
77 #define TAG_CCB 'ccdC' // Ccb
78 #define TAG_CDROM_TOC 'ctdC' // TOC
79 #define TAG_DIRENT_NAME 'nddC' // CdName in dirent
80 #define TAG_ENUM_EXPRESSION 'eedC' // Search expression for enumeration
81 #define TAG_FCB_DATA 'dfdC' // Data Fcb
82 #define TAG_FCB_INDEX 'ifdC' // Index Fcb
83 #define TAG_FCB_NONPAGED 'nfdC' // Nonpaged Fcb
84 #define TAG_FCB_TABLE 'tfdC' // Fcb Table entry
85 #define TAG_FILE_NAME 'nFdC' // Filename buffer
86 #define TAG_GEN_SHORT_NAME 'sgdC' // Generated short name
87 #define TAG_IO_BUFFER 'fbdC' // Temporary IO buffer
88 #define TAG_IO_CONTEXT 'oidC' // Io context for async reads
89 #define TAG_IRP_CONTEXT 'cidC' // Irp Context
90 #define TAG_IRP_CONTEXT_LITE 'lidC' // Irp Context lite
91 #define TAG_MCB_ARRAY 'amdC' // Mcb array
92 #define TAG_PATH_ENTRY_NAME 'nPdC' // CdName in path entry
93 #define TAG_PREFIX_ENTRY 'epdC' // Prefix Entry
94 #define TAG_PREFIX_NAME 'npdC' // Prefix Entry name
95 #define TAG_SPANNING_PATH_TABLE 'psdC' // Buffer for spanning path table
96 #define TAG_UPCASE_NAME 'nudC' // Buffer for upcased name
97 #define TAG_VOL_DESC 'dvdC' // Buffer for volume descriptor
98 #define TAG_VPB 'pvdC' // Vpb allocated in filesystem
99 
100 //
101 // Tag all of our allocations if tagging is turned on
102 //
103 
104 #ifdef POOL_TAGGING
105 
106 #undef FsRtlAllocatePool
107 #undef FsRtlAllocatePoolWithQuota
108 #define FsRtlAllocatePool(a,b) FsRtlAllocatePoolWithTag(a,b,'sfdC')
109 #define FsRtlAllocatePoolWithQuota(a,b) FsRtlAllocatePoolWithQuotaTag(a,b,'sfdC')
110 
111 #endif // POOL_TAGGING
112 
113 
114 //
115 // File access check routine, implemented in AcChkSup.c
116 //
117 
118 //
119 // BOOLEAN
120 // CdIllegalFcbAccess (
121 // _In_ PIRP_CONTEXT IrpContext,
122 // _In_ TYPE_OF_OPEN TypeOfOpen,
123 // _In_ ACCESS_MASK DesiredAccess
124 // );
125 //
126 
127 #define CdIllegalFcbAccess(IC,T,DA) ( \
128  BooleanFlagOn( (DA), \
129  ((T) != UserVolumeOpen ? \
130  (FILE_WRITE_ATTRIBUTES | \
131  FILE_WRITE_DATA | \
132  FILE_WRITE_EA | \
133  FILE_ADD_FILE | \
134  FILE_ADD_SUBDIRECTORY | \
135  FILE_APPEND_DATA) : 0) | \
136  FILE_DELETE_CHILD | \
137  DELETE | \
138  WRITE_DAC ))
139 
140 
141 //
142 // Allocation support routines, implemented in AllocSup.c
143 //
144 // These routines are for querying allocation on individual streams.
145 //
146 
147 _Requires_lock_held_(_Global_critical_region_)
148 VOID
149 CdLookupAllocation (
150  _In_ PIRP_CONTEXT IrpContext,
155  );
156 
157 VOID
159  _In_ PIRP_CONTEXT IrpContext,
160  _Inout_ PFCB Fcb,
161  _In_ ULONG McbEntryOffset,
162  _In_ LONGLONG StartingFileOffset,
164  );
165 
166 VOID
168  _In_ PIRP_CONTEXT IrpContext,
169  _Inout_ PFCB Fcb,
170  _In_ ULONG StartingBlock,
172  );
173 
174 VOID
176  _In_ PIRP_CONTEXT IrpContext,
177  _Inout_ PFCB Fcb,
178  _In_ LONGLONG StartingFileOffset
179  );
180 
181 _At_(Fcb->NodeByteSize, _In_range_(>=, FIELD_OFFSET( FCB, FcbType )))
182 VOID
183 CdInitializeMcb (
184  _In_ PIRP_CONTEXT IrpContext,
185  _Inout_updates_bytes_(Fcb->NodeByteSize) PFCB Fcb
186  );
187 
188 _At_(Fcb->NodeByteSize, _In_range_(>=, FIELD_OFFSET( FCB, FcbType )))
189 _When_(Fcb->NodeTypeCode == CDFS_NTC_FCB_PATH_TABLE, _At_(Fcb->NodeByteSize, _In_range_(==, SIZEOF_FCB_INDEX)))
190 _When_(Fcb->NodeTypeCode == CDFS_NTC_FCB_INDEX, _At_(Fcb->NodeByteSize, _In_range_(==, SIZEOF_FCB_INDEX)))
191 _When_(Fcb->NodeTypeCode == CDFS_NTC_FCB_DATA, _At_(Fcb->NodeByteSize, _In_range_(==, SIZEOF_FCB_DATA)))
192 VOID
193 CdUninitializeMcb (
194  _In_ PIRP_CONTEXT IrpContext,
195  _Inout_updates_bytes_(Fcb->NodeByteSize) PFCB Fcb
196  );
197 
198 
199 //
200 // Buffer control routines for data caching, implemented in CacheSup.c
201 //
202 
203 VOID
205  _In_ PIRP_CONTEXT IrpContext,
206  _In_ PVCB Vcb,
207  _Inout_ PFCB Fcb,
209  );
210 
211 VOID
213  _In_ PIRP_CONTEXT IrpContext,
215  );
216 
217 NTSTATUS
219  _In_ PIRP_CONTEXT IrpContext,
221  );
222 
223 _Requires_lock_held_(_Global_critical_region_)
224 NTSTATUS
225 CdPurgeVolume (
226  _In_ PIRP_CONTEXT IrpContext,
229  );
230 
231 static /* ReactOS Change: GCC "multiple definition" */
232 INLINE /* GCC only accepts __inline as the first modifier */
233 VOID
235  _In_ PIRP_CONTEXT IrpContext,
236  _In_ PFCB Fcb
237  )
238 {
239  //
240  // Unsafe test to see if call / lock neccessary.
241  //
242 
243  if (NULL == Fcb->FileObject) {
244 
245  CdCreateInternalStream( IrpContext,
246  Fcb->Vcb,
247  Fcb,
249  }
250 }
251 
252 
253 //
254 // VOID
255 // CdUnpinData (
256 // _In_ PIRP_CONTEXT IrpContext,
257 // _Inout_ PBCB *Bcb
258 // );
259 //
260 
261 #define CdUnpinData(IC,B) \
262  if (*(B) != NULL) { CcUnpinData( *(B) ); *(B) = NULL; }
263 
264 
265 //
266 // Device I/O routines, implemented in DevIoSup.c
267 //
268 // These routines perform the actual device read and writes. They only affect
269 // the on disk structure and do not alter any other data structures.
270 //
271 
272 _Requires_lock_held_(_Global_critical_region_)
273 VOID
274 CdFreeDirCache (
275  _In_ PIRP_CONTEXT IrpContext
276  );
277 
278 _Requires_lock_held_(_Global_critical_region_)
279 NTSTATUS
280 CdNonCachedRead (
281  _In_ PIRP_CONTEXT IrpContext,
285  );
286 
287 _Requires_lock_held_(_Global_critical_region_)
288 NTSTATUS
289 CdNonCachedXARead (
290  _In_ PIRP_CONTEXT IrpContext,
291  _In_ PFCB Fcb,
294  );
295 
296 _Requires_lock_held_(_Global_critical_region_)
297 NTSTATUS
298 CdVolumeDasdWrite (
299  _In_ PIRP_CONTEXT IrpContext,
300  _In_ PFCB Fcb,
303  );
304 
305 BOOLEAN
307  _In_ PIRP_CONTEXT IrpContext,
310  _In_ BOOLEAN ReturnError,
313  );
314 
315 NTSTATUS
317  _In_ PIRP_CONTEXT IrpContext,
321  );
322 
323 NTSTATUS
324 FASTCALL
326  _In_ PIRP_CONTEXT IrpContext,
332  _In_ BOOLEAN OverrideVerify,
334  );
335 
336 NTSTATUS
338  _In_ PIRP_CONTEXT IrpContext,
346  _In_ BOOLEAN OverrideVerify,
348  );
349 
350 NTSTATUS
352  _In_ PIRP_CONTEXT IrpContext,
353  _Inout_ PIRP Irp,
355  );
356 
357 
358 //
359 // VOID
360 // CdMapUserBuffer (
361 // _In_ PIRP_CONTEXT IrpContext
362 // _Out_ PVOID UserBuffer
363 // );
364 //
365 // Returns pointer to sys address. Will raise on failure.
366 //
367 //
368 // VOID
369 // CdLockUserBuffer (
370 // _Inout_ PIRP_CONTEXT IrpContext,
371 // _In_ ULONG BufferLength
372 // );
373 //
374 
375 #ifndef __REACTOS__
376 #define CdMapUserBuffer(IC, UB) { \
377  *(UB) = (PVOID) ( ((IC)->Irp->MdlAddress == NULL) ? \
378  (IC)->Irp->UserBuffer : \
379  (MmGetSystemAddressForMdlSafe( (IC)->Irp->MdlAddress, NormalPagePriority | MdlMappingNoExecute))); \
380  if (NULL == *(UB)) { \
381  CdRaiseStatus( (IC), STATUS_INSUFFICIENT_RESOURCES); \
382  } \
383  }
384 
385 #else
386 #define CdMapUserBuffer(IC, UB) { \
387  *(UB) = (PVOID) ( ((IC)->Irp->MdlAddress == NULL) ? \
388  (IC)->Irp->UserBuffer : \
389  (MmGetSystemAddressForMdlSafe( (IC)->Irp->MdlAddress, NormalPagePriority))); \
390  if (NULL == *(UB)) { \
391  CdRaiseStatus( (IC), STATUS_INSUFFICIENT_RESOURCES); \
392  } \
393  }
394 
395 #endif
396 
397 
398 #define CdLockUserBuffer(IC,BL,OP) { \
399  if ((IC)->Irp->MdlAddress == NULL) { \
400  (VOID) CdCreateUserMdl( (IC), (BL), TRUE, (OP) ); \
401  } \
402 }
403 
404 
405 //
406 // Dirent support routines, implemented in DirSup.c
407 //
408 
409 VOID
411  _In_ PIRP_CONTEXT IrpContext,
412  _In_ PFCB Fcb,
415  );
416 
417 BOOLEAN
419  _In_ PIRP_CONTEXT IrpContext,
420  _In_ PFCB Fcb,
421  _In_ PDIRENT_ENUM_CONTEXT CurrentDirContext,
422  _Inout_ PDIRENT_ENUM_CONTEXT NextDirContext
423  );
424 
425 _At_(Dirent->CdTime, _Post_notnull_)
426 VOID
427 CdUpdateDirentFromRawDirent (
428  _In_ PIRP_CONTEXT IrpContext,
432  );
433 
434 VOID
436  _In_ PIRP_CONTEXT IrpContext,
439  );
440 
441 _Success_(return != FALSE) BOOLEAN
442 CdFindFile (
443  _In_ PIRP_CONTEXT IrpContext,
449  );
450 
451 BOOLEAN
453  _In_ PIRP_CONTEXT IrpContext,
454  _In_ PFCB Fcb,
458  );
459 
460 _At_(FileContext->ShortName.FileName.MaximumLength, _In_range_(>=, BYTE_COUNT_8_DOT_3))
461 BOOLEAN
462 CdFindFileByShortName (
463  _In_ PIRP_CONTEXT IrpContext,
469  );
470 
471 BOOLEAN
473  _In_ PIRP_CONTEXT IrpContext,
474  _In_ PFCB Fcb,
476  );
477 
478 VOID
480  _In_ PIRP_CONTEXT IrpContext,
481  _In_ PFCB Fcb,
483  );
484 
485 VOID
487  _In_ PIRP_CONTEXT IrpContext,
489  );
490 
491 //
492 // VOID
493 // CdInitializeFileContext (
494 // _In_ PIRP_CONTEXT IrpContext,
495 // _Out_ PFILE_ENUM_CONTEXT FileContext
496 // );
497 //
498 //
499 // VOID
500 // CdInitializeDirent (
501 // _In_ PIRP_CONTEXT IrpContext,
502 // _Out_ PDIRENT Dirent
503 // );
504 //
505 // VOID
506 // CdInitializeDirContext (
507 // _In_ PIRP_CONTEXT IrpContext,
508 // _Out_ PDIRENT_ENUM_CONTEXT DirContext
509 // );
510 //
511 // VOID
512 // CdCleanupDirent (
513 // _In_ PIRP_CONTEXT IrpContext,
514 // _Inout_ PDIRENT Dirent
515 // );
516 //
517 // VOID
518 // CdCleanupDirContext (
519 // _In_ PIRP_CONTEXT IrpContext,
520 // _Inout_ PDIRENT_ENUM_CONTEXT DirContext
521 // );
522 //
523 // VOID
524 // CdLookupInitialFileDirent (
525 // _In_ PIRP_CONTEXT IrpContext,
526 // _In_ PFCB Fcb,
527 // _Out_ PFILE_ENUM_CONTEXT FileContext,
528 // _In_ ULONG DirentOffset
529 // );
530 //
531 
532 #define CdInitializeFileContext(IC,FC) { \
533  RtlZeroMemory( FC, sizeof( FILE_ENUM_CONTEXT )); \
534  (FC)->PriorDirent = &(FC)->Dirents[0]; \
535  (FC)->InitialDirent = &(FC)->Dirents[1]; \
536  (FC)->CurrentDirent = &(FC)->Dirents[2]; \
537  (FC)->ShortName.FileName.MaximumLength = BYTE_COUNT_8_DOT_3; \
538  (FC)->ShortName.FileName.Buffer = (FC)->ShortNameBuffer; \
539 }
540 
541 #define CdInitializeDirent(IC,D) \
542  RtlZeroMemory( D, sizeof( DIRENT ))
543 
544 #define CdInitializeDirContext(IC,DC) \
545  RtlZeroMemory( DC, sizeof( DIRENT_ENUM_CONTEXT ))
546 
547 #define CdCleanupDirent(IC,D) { \
548  if (FlagOn( (D)->Flags, DIRENT_FLAG_ALLOC_BUFFER )) { \
549  CdFreePool( &(D)->CdFileName.FileName.Buffer ); \
550  } \
551 }
552 
553 #define CdCleanupDirContext(IC,DC) \
554  CdUnpinData( (IC), &(DC)->Bcb )
555 
556 #define CdLookupInitialFileDirent(IC,F,FC,DO) \
557  CdLookupDirent( IC, \
558  F, \
559  DO, \
560  &(FC)->InitialDirent->DirContext ); \
561  CdUpdateDirentFromRawDirent( IC, \
562  F, \
563  &(FC)->InitialDirent->DirContext, \
564  &(FC)->InitialDirent->Dirent )
565 
566 
567 //
568 // The following routines are used to manipulate the fscontext fields
569 // of the file object, implemented in FilObSup.c
570 //
571 
572 //
573 // Type of opens. FilObSup.c depends on this order.
574 //
575 
576 typedef enum _TYPE_OF_OPEN {
577 
584 
585 } TYPE_OF_OPEN;
587 
590 VOID
591 CdSetFileObject (
592  _In_ PIRP_CONTEXT IrpContext,
595  PFCB Fcb,
597  );
598 
604 CdDecodeFileObject (
605  _In_ PIRP_CONTEXT IrpContext,
607  PFCB *Fcb,
608  PCCB *Ccb
609  );
610 
614  _Out_ PFCB *Fcb
615  );
616 
617 
618 //
619 // Name support routines, implemented in NameSup.c
620 //
621 
624 VOID
625 CdConvertNameToCdName (
626  _In_ PIRP_CONTEXT IrpContext,
628  );
629 
630 VOID
632  _In_ PIRP_CONTEXT IrpContext,
633  _In_reads_bytes_(ByteCount) PCHAR BigEndian,
635  _Out_writes_bytes_(ByteCount) PCHAR LittleEndian
636  );
637 
638 VOID
639 CdUpcaseName (
640  _In_ PIRP_CONTEXT IrpContext,
642  _Inout_ PCD_NAME UpcaseName
643  );
644 
645 VOID
647  _In_ PIRP_CONTEXT IrpContext,
649  _Out_ PUNICODE_STRING FinalName
650  );
651 
652 BOOLEAN
654  _In_ PIRP_CONTEXT IrpContext,
656  );
657 
658 BOOLEAN
660  _In_ PIRP_CONTEXT IrpContext,
662  );
663 
664 VOID
666  _In_ PIRP_CONTEXT IrpContext,
669  _Out_writes_bytes_to_(BYTE_COUNT_8_DOT_3, *ShortByteCount) PWCHAR ShortFileName,
670  _Out_ PUSHORT ShortByteCount
671  );
672 
673 BOOLEAN
675  _In_ PIRP_CONTEXT IrpContext,
676  _In_ PCD_NAME CurrentName,
677  _In_ PCD_NAME SearchExpression,
678  _In_ ULONG WildcardFlags,
679  _In_ BOOLEAN CheckVersion
680  );
681 
682 ULONG
684  _In_ PIRP_CONTEXT IrpContext,
686  );
687 
690  _In_ PIRP_CONTEXT IrpContext,
691  _In_ PUNICODE_STRING NameA,
692  _In_ PUNICODE_STRING NameB
693  );
694 
695 
696 //
697 // Filesystem control operations. Implemented in Fsctrl.c
698 //
699 
700 _Requires_lock_held_(_Global_critical_region_)
701 _Requires_lock_held_(Vcb->VcbResource)
702 NTSTATUS
703 CdLockVolumeInternal (
704  _In_ PIRP_CONTEXT IrpContext,
705  _Inout_ PVCB Vcb,
707  );
708 
709 NTSTATUS
711  _In_ PIRP_CONTEXT IrpContext,
712  _Inout_ PVCB Vcb,
714  );
715 
716 
717 //
718 // Path table enumeration routines. Implemented in PathSup.c
719 //
720 
721 VOID
723  _In_ PIRP_CONTEXT IrpContext,
724  _In_ ULONG PathEntryOffset,
725  _In_ ULONG Ordinal,
726  _In_ BOOLEAN VerifyBounds,
728  );
729 
730 BOOLEAN
732  _In_ PIRP_CONTEXT IrpContext,
733  _Inout_ PPATH_ENUM_CONTEXT PathContext,
734  _Inout_ PPATH_ENTRY PathEntry
735  );
736 
738 BOOLEAN
739 CdFindPathEntry (
740  _In_ PIRP_CONTEXT IrpContext,
745  );
746 
747 VOID
749  _In_ PIRP_CONTEXT IrpContext,
750  _Inout_ PPATH_ENTRY PathEntry,
752  );
753 
754 //
755 // VOID
756 // CdInitializeCompoundPathEntry (
757 // _In_ PIRP_CONTEXT IrpContext,
758 // _Out_ PCOMPOUND_PATH_ENTRY CompoundPathEntry
759 // );
760 //
761 // VOID
762 // CdCleanupCompoundPathEntry (
763 // _In_ PIRP_CONTEXT IrpContext,
764 // _Out_ PCOMPOUND_PATH_ENTRY CompoundPathEntry
765 // );
766 //
767 
768 #define CdInitializeCompoundPathEntry(IC,CP) \
769  RtlZeroMemory( CP, sizeof( COMPOUND_PATH_ENTRY ))
770 
771 #define CdCleanupCompoundPathEntry(IC,CP) { \
772  CdUnpinData( (IC), &(CP)->PathContext.Bcb ); \
773  if ((CP)->PathContext.AllocatedData) { \
774  CdFreePool( &(CP)->PathContext.Data ); \
775  } \
776  if (FlagOn( (CP)->PathEntry.Flags, PATH_ENTRY_FLAG_ALLOC_BUFFER )) { \
777  CdFreePool( &(CP)->PathEntry.CdDirName.FileName.Buffer ); \
778  } \
779 }
780 
781 
782 //
783 // Largest matching prefix searching routines, implemented in PrefxSup.c
784 //
785 
786 VOID
788  _In_ PIRP_CONTEXT IrpContext,
789  _Inout_ PFCB Fcb,
792  _In_ BOOLEAN ShortNameMatch,
794  );
795 
796 VOID
798  _In_ PIRP_CONTEXT IrpContext,
800  );
801 
802 _Requires_lock_held_(_Global_critical_region_)
803 VOID
804 CdFindPrefix (
805  _In_ PIRP_CONTEXT IrpContext,
809  );
810 
811 
812 //
813 // Synchronization routines. Implemented in Resrcsup.c
814 //
815 // The following routines/macros are used to synchronize the in-memory structures.
816 //
817 // Routine/Macro Synchronizes Subsequent
818 //
819 // CdAcquireCdData Volume Mounts/Dismounts,Vcb Queue CdReleaseCdData
820 // CdAcquireVcbExclusive Vcb for open/close CdReleaseVcb
821 // CdAcquireVcbShared Vcb for open/close CdReleaseVcb
822 // CdAcquireAllFiles Locks out operations to all files CdReleaseAllFiles
823 // CdAcquireFileExclusive Locks out file operations CdReleaseFile
824 // CdAcquireFileShared Files for file operations CdReleaseFile
825 // CdAcquireFcbExclusive Fcb for open/close CdReleaseFcb
826 // CdAcquireFcbShared Fcb for open/close CdReleaseFcb
827 // CdLockCdData Fields in CdData CdUnlockCdData
828 // CdLockVcb Vcb fields, FcbReference, FcbTable CdUnlockVcb
829 // CdLockFcb Fcb fields, prefix table, Mcb CdUnlockFcb
830 //
831 
832 typedef enum _TYPE_OF_ACQUIRE {
833 
837 
839 
840 _Requires_lock_held_(_Global_critical_region_)
845 BOOLEAN
846 CdAcquireResource (
847  _In_ PIRP_CONTEXT IrpContext,
851  );
852 
853 //
854 // BOOLEAN
855 // CdAcquireCdData (
856 // _In_ PIRP_CONTEXT IrpContext
857 // );
858 //
859 // VOID
860 // CdReleaseCdData (
861 // _In_ PIRP_CONTEXT IrpContext
862 // );
863 //
864 // BOOLEAN
865 // CdAcquireVcbExclusive (
866 // _In_ PIRP_CONTEXT IrpContext,
867 // _Inout_ PVCB Vcb,
868 // _In_ BOOLEAN IgnoreWait
869 // );
870 //
871 // BOOLEAN
872 // CdAcquireVcbShared (
873 // _In_ PIRP_CONTEXT IrpContext,
874 // _Inout_ PVCB Vcb,
875 // _In_ BOOLEAN IgnoreWait
876 // );
877 //
878 // VOID
879 // CdReleaseVcb (
880 // _In_ PIRP_CONTEXT IrpContext,
881 // _Inout_ PVCB Vcb
882 // );
883 //
884 // VOID
885 // CdAcquireAllFiles (
886 // _In_ PIRP_CONTEXT,
887 // _In_ PVCB Vcb
888 // );
889 //
890 // VOID
891 // CdReleaseAllFiles (
892 // _In_ PIRP_CONTEXT,
893 // _In_ PVCB Vcb
894 // );
895 //
896 // VOID
897 // CdAcquireFileExclusive (
898 // _In_ PIRP_CONTEXT IrpContext,
899 // _Inout_ PFCB Fcb,
900 // );
901 //
902 // VOID
903 // CdAcquireFileShared (
904 // _In_ PIRP_CONTEXT IrpContext,
905 // _Inout_ PFCB Fcb
906 // );
907 //
908 // VOID
909 // CdReleaseFile (
910 // _In_ PIRP_CONTEXT IrpContext,
911 // _Inout_ PFCB Fcb
912 // );
913 //
914 // BOOLEAN
915 // CdAcquireFcbExclusive (
916 // _In_ PIRP_CONTEXT IrpContext,
917 // _Inout_ PFCB Fcb,
918 // _In_ BOOLEAN IgnoreWait
919 // );
920 //
921 // BOOLEAN
922 // CdAcquireFcbShared (
923 // _In_ PIRP_CONTEXT IrpContext,
924 // _Inout_ PFCB Fcb,
925 // _In_ BOOLEAN IgnoreWait
926 // );
927 //
928 // BOOLEAN
929 // CdReleaseFcb (
930 // _In_ PIRP_CONTEXT IrpContext,
931 // _Inout_ PFCB Fcb
932 // );
933 //
934 // VOID
935 // CdLockCdData (
936 // );
937 //
938 // VOID
939 // CdUnlockCdData (
940 // );
941 //
942 // VOID
943 // CdLockVcb (
944 // _In_ PIRP_CONTEXT IrpContext
945 // );
946 //
947 // VOID
948 // CdUnlockVcb (
949 // _In_ PIRP_CONTEXT IrpContext
950 // );
951 //
952 // VOID
953 // CdLockFcb (
954 // _In_ PIRP_CONTEXT IrpContext,
955 // _Inout_ PFCB Fcb
956 // );
957 //
958 // VOID
959 // CdUnlockFcb (
960 // _In_ PIRP_CONTEXT IrpContext,
961 // _Inout_ PFCB Fcb
962 // );
963 //
964 
965 
966 #define CdAcquireCacheForRead( IC) \
967  ExAcquireResourceSharedLite( &(IC)->Vcb->SectorCacheResource, TRUE)
968 
969 #define CdAcquireCacheForUpdate( IC) \
970  ExAcquireResourceExclusiveLite( &(IC)->Vcb->SectorCacheResource, TRUE)
971 
972 #define CdReleaseCache( IC) \
973  ExReleaseResourceLite( &(IC)->Vcb->SectorCacheResource);
974 
975 #define CdConvertCacheToShared( IC) \
976  ExConvertExclusiveToSharedLite( &(IC)->Vcb->SectorCacheResource);
977 
978 #define CdAcquireCdData(IC) \
979  ExAcquireResourceExclusiveLite( &CdData.DataResource, TRUE )
980 
981 #define CdReleaseCdData(IC) \
982  ExReleaseResourceLite( &CdData.DataResource )
983 
984 #define CdAcquireVcbExclusive(IC,V,I) \
985  CdAcquireResource( (IC), &(V)->VcbResource, (I), AcquireExclusive )
986 
987 #define CdAcquireVcbShared(IC,V,I) \
988  CdAcquireResource( (IC), &(V)->VcbResource, (I), AcquireShared )
989 
990 #define CdReleaseVcb(IC,V) \
991  ExReleaseResourceLite( &(V)->VcbResource )
992 
993 #define CdAcquireAllFiles(IC,V) \
994  CdAcquireResource( (IC), &(V)->FileResource, FALSE, AcquireExclusive )
995 
996 #define CdReleaseAllFiles(IC,V) \
997  ExReleaseResourceLite( &(V)->FileResource )
998 
999 #define CdAcquireFileExclusive(IC,F) \
1000  CdAcquireResource( (IC), (F)->Resource, FALSE, AcquireExclusive )
1001 
1002 #define CdAcquireFileShared(IC,F) \
1003  CdAcquireResource( (IC), (F)->Resource, FALSE, AcquireShared )
1004 
1005 #define CdAcquireFileSharedStarveExclusive(IC,F) \
1006  CdAcquireResource( (IC), (F)->Resource, FALSE, AcquireSharedStarveExclusive )
1007 
1008 #define CdReleaseFile(IC,F) \
1009  ExReleaseResourceLite( (F)->Resource )
1010 
1011 #define CdAcquireFcbExclusive(IC,F,I) \
1012  CdAcquireResource( (IC), &(F)->FcbNonpaged->FcbResource, (I), AcquireExclusive )
1013 
1014 #define CdAcquireFcbShared(IC,F,I) \
1015  CdAcquireResource( (IC), &(F)->FcbNonpaged->FcbResource, (I), AcquireShared )
1016 
1017 #define CdReleaseFcb(IC,F) \
1018  ExReleaseResourceLite( &(F)->FcbNonpaged->FcbResource )
1019 
1020 #define CdLockCdData() \
1021  ExAcquireFastMutex( &CdData.CdDataMutex ); \
1022  CdData.CdDataLockThread = PsGetCurrentThread()
1023 
1024 #define CdUnlockCdData() \
1025  CdData.CdDataLockThread = NULL; \
1026  ExReleaseFastMutex( &CdData.CdDataMutex )
1027 
1028 #define CdLockVcb(IC,V) \
1029  ExAcquireFastMutex( &(V)->VcbMutex ); \
1030  NT_ASSERT( NULL == (V)->VcbLockThread); \
1031  (V)->VcbLockThread = PsGetCurrentThread()
1032 
1033 #define CdUnlockVcb(IC,V) \
1034  NT_ASSERT( NULL != (V)->VcbLockThread); \
1035  (V)->VcbLockThread = NULL; \
1036  ExReleaseFastMutex( &(V)->VcbMutex )
1037 
1038 #if defined(_PREFAST_)
1039 
1040 _Success_(return)
1041 _IRQL_saves_global_(OldIrql, FastMutex)
1042 BOOLEAN DummySaveIrql(_Inout_ PFAST_MUTEX FastMutex);
1043 
1044 _Success_(return)
1045 _IRQL_restores_global_(OldIrql, FastMutex)
1046 BOOLEAN DummyRestoreIrql(_Inout_ PFAST_MUTEX FastMutex);
1047 #endif // _PREFAST_
1048 
1049 #define CdLockFcb(IC,F) { \
1050  PVOID _CurrentThread = PsGetCurrentThread(); \
1051  if (_CurrentThread != (F)->FcbLockThread) { \
1052  ExAcquireFastMutex( &(F)->FcbNonpaged->FcbMutex ); \
1053  NT_ASSERT( (F)->FcbLockCount == 0 ); \
1054  _Analysis_assume_( (F)->FcbLockCount == 0 ); \
1055  (F)->FcbLockThread = _CurrentThread; \
1056  } \
1057  else \
1058  { \
1059  _Analysis_assume_lock_held_( (F)->FcbNonpaged->FcbMutex ); \
1060  _Analysis_assume_(FALSE != DummySaveIrql(&(F)->FcbNonpaged->FcbMutex)); \
1061  } \
1062  (F)->FcbLockCount += 1; \
1063 }
1064 
1065 #define CdUnlockFcb(IC,F) { \
1066  (F)->FcbLockCount -= 1; \
1067  if ((F)->FcbLockCount == 0) { \
1068  (F)->FcbLockThread = NULL; \
1069  ExReleaseFastMutex( &(F)->FcbNonpaged->FcbMutex ); \
1070  } \
1071  else \
1072  { \
1073  _Analysis_assume_lock_not_held_( (F)->FcbNonpaged->FcbMutex ); \
1074  _Analysis_assume_(FALSE != DummyRestoreIrql(&(F)->FcbNonpaged->FcbMutex)); \
1075  } \
1076 }
1077 
1078 //
1079 // The following macro is used to retrieve the oplock structure within
1080 // the Fcb. This structure was moved to the advanced Fcb header
1081 // in Win8.
1082 //
1083 
1084 #if (NTDDI_VERSION >= NTDDI_WIN8)
1085 
1086 #define CdGetFcbOplock(F) &(F)->Header.Oplock
1087 
1088 #else
1089 
1090 #define CdGetFcbOplock(F) &(F)->Oplock
1091 
1092 #endif
1093 
1094 BOOLEAN
1095 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
1096 CdNoopAcquire (
1097  _In_ PVOID Fcb,
1098  _In_ BOOLEAN Wait
1099  );
1100 
1101 VOID
1102 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
1103 CdNoopRelease (
1104  _In_ PVOID Fcb
1105  );
1106 
1107 _Requires_lock_held_(_Global_critical_region_)
1108 _When_(return!=0, _Acquires_shared_lock_(*Fcb->Resource))
1109 BOOLEAN
1110 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
1112  _Inout_ PFCB Fcb,
1113  _In_ BOOLEAN Wait
1114  );
1115 
1116 _Requires_lock_held_(_Global_critical_region_)
1118 VOID
1119 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
1120 CdReleaseFromCache (
1121  _Inout_ PFCB Fcb
1122  );
1123 
1124 _Requires_lock_held_(_Global_critical_region_)
1125 NTSTATUS
1126 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
1127 CdFilterCallbackAcquireForCreateSection (
1129  _Unreferenced_parameter_ PVOID *CompletionContext
1130  );
1131 
1132 _Function_class_(FAST_IO_RELEASE_FILE)
1133 _Requires_lock_held_(_Global_critical_region_)
1134 VOID
1135 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
1136 CdReleaseForCreateSection (
1138  );
1139 
1140 
1141 //
1142 // In-memory structure support routines. Implemented in StrucSup.c
1143 //
1144 
1145 VOID
1147  _In_ PIRP_CONTEXT IrpContext,
1148  _Inout_ PVCB Vcb,
1152  _In_ ULONG TocLength,
1153  _In_ ULONG TocTrackCount,
1154  _In_ ULONG TocDiskFlags,
1155  _In_ ULONG BlockFactor,
1156  _In_ ULONG MediaChangeCount
1157  );
1158 
1159 VOID
1161  _In_ PIRP_CONTEXT IrpContext,
1162  _Inout_ PVCB Vcb,
1164  );
1165 
1166 VOID
1167 CdDeleteVcb (
1168  _In_ PIRP_CONTEXT IrpContext,
1169  _Inout_ PVCB Vcb
1170  );
1171 
1172 PFCB
1173 CdCreateFcb (
1174  _In_ PIRP_CONTEXT IrpContext,
1175  _In_ FILE_ID FileId,
1176  _In_ NODE_TYPE_CODE NodeTypeCode,
1177  _Out_opt_ PBOOLEAN FcbExisted
1178  );
1179 
1180 VOID
1182  _In_ PIRP_CONTEXT IrpContext,
1183  _Inout_ PFCB Fcb,
1185  _In_ PPATH_ENTRY PathEntry
1186  );
1187 
1188 VOID
1190  _In_ PIRP_CONTEXT IrpContext,
1191  _Inout_ PFCB Fcb,
1194  );
1195 
1196 PCCB
1197 CdCreateCcb (
1198  _In_ PIRP_CONTEXT IrpContext,
1199  _In_ PFCB Fcb,
1200  _In_ ULONG Flags
1201  );
1202 
1203 VOID
1204 CdDeleteCcb (
1205  _In_ PIRP_CONTEXT IrpContext,
1207  );
1208 
1210 _When_(RaiseOnError, _At_(IrpContext, _Pre_notnull_))
1211 BOOLEAN
1212 CdCreateFileLock (
1213  _In_opt_ PIRP_CONTEXT IrpContext,
1216  );
1217 
1218 VOID
1220  _In_ PIRP_CONTEXT IrpContext,
1221  _Inout_ PFILE_LOCK FileLock
1222  );
1223 
1226  _In_ PIRP Irp,
1227  _In_ BOOLEAN Wait
1228  );
1229 
1230 VOID
1232  _In_ PIRP_CONTEXT IrpContext,
1233  _In_ BOOLEAN Post
1234  );
1235 
1236 VOID
1238  _Out_ PIRP_CONTEXT IrpContext,
1239  _In_ PIRP_CONTEXT_LITE IrpContextLite
1240  );
1241 
1242 //
1243 // PIRP_CONTEXT_LITE
1244 // CdCreateIrpContextLite (
1245 // _In_ PIRP_CONTEXT IrpContext
1246 // );
1247 //
1248 // VOID
1249 // CdFreeIrpContextLite (
1250 // _Inout_ PIRP_CONTEXT_LITE IrpContextLite
1251 // );
1252 //
1253 
1254 #define CdCreateIrpContextLite(IC) \
1255  ExAllocatePoolWithTag( CdNonPagedPool, sizeof( IRP_CONTEXT_LITE ), TAG_IRP_CONTEXT_LITE )
1256 
1257 #define CdFreeIrpContextLite(ICL) \
1258  CdFreePool( &(ICL) )
1259 
1260 _Requires_lock_held_(_Global_critical_region_)
1261 VOID
1262 CdTeardownStructures (
1263  _In_ PIRP_CONTEXT IrpContext,
1266  );
1267 
1268 //
1269 // VOID
1270 // CdIncrementCleanupCounts (
1271 // _In_ PIRP_CONTEXT IrpContext,
1272 // _Inout_ PFCB Fcb
1273 // );
1274 //
1275 // VOID
1276 // CdDecrementCleanupCounts (
1277 // _In_ PIRP_CONTEXT IrpContext,
1278 // _Inout_ PFCB Fcb
1279 // );
1280 //
1281 // VOID
1282 // CdIncrementReferenceCounts (
1283 // _In_ PIRP_CONTEXT IrpContext,
1284 // _Inout_ PFCB Fcb,
1285 // _In_ ULONG ReferenceCount
1286 // _In_ ULONG UserReferenceCount
1287 // );
1288 //
1289 // VOID
1290 // CdDecrementReferenceCounts (
1291 // _In_ PIRP_CONTEXT IrpContext,
1292 // _Inout_ PFCB Fcb,
1293 // _In_ ULONG ReferenceCount
1294 // _In_ ULONG UserReferenceCount
1295 // );
1296 //
1297 // VOID
1298 // CdIncrementFcbReference (
1299 // _In_ PIRP_CONTEXT IrpContext,
1300 // _Inout_ PFCB Fcb
1301 // );
1302 //
1303 // VOID
1304 // CdDecrementFcbReference (
1305 // _In_ PIRP_CONTEXT IrpContext,
1306 // _Inout_ PFCB Fcb
1307 // );
1308 //
1309 
1310 #define CdIncrementCleanupCounts(IC,F) { \
1311  ASSERT_LOCKED_VCB( (F)->Vcb ); \
1312  (F)->FcbCleanup += 1; \
1313  (F)->Vcb->VcbCleanup += 1; \
1314 }
1315 
1316 #define CdDecrementCleanupCounts(IC,F) { \
1317  ASSERT_LOCKED_VCB( (F)->Vcb ); \
1318  (F)->FcbCleanup -= 1; \
1319  (F)->Vcb->VcbCleanup -= 1; \
1320 }
1321 
1322 #define CdIncrementReferenceCounts(IC,F,C,UC) { \
1323  ASSERT_LOCKED_VCB( (F)->Vcb ); \
1324  (F)->FcbReference += (C); \
1325  (F)->FcbUserReference += (UC); \
1326  (F)->Vcb->VcbReference += (C); \
1327  (F)->Vcb->VcbUserReference += (UC); \
1328 }
1329 
1330 #define CdDecrementReferenceCounts(IC,F,C,UC) { \
1331  ASSERT_LOCKED_VCB( (F)->Vcb ); \
1332  (F)->FcbReference -= (C); \
1333  (F)->FcbUserReference -= (UC); \
1334  (F)->Vcb->VcbReference -= (C); \
1335  (F)->Vcb->VcbUserReference -= (UC); \
1336 }
1337 
1338 //
1339 // PCD_IO_CONTEXT
1340 // CdAllocateIoContext (
1341 // );
1342 //
1343 // VOID
1344 // CdFreeIoContext (
1345 // PCD_IO_CONTEXT IoContext
1346 // );
1347 //
1348 
1349 #define CdAllocateIoContext() \
1350  FsRtlAllocatePoolWithTag( CdNonPagedPool, \
1351  sizeof( CD_IO_CONTEXT ), \
1352  TAG_IO_CONTEXT )
1353 
1354 #define CdFreeIoContext(IO) CdFreePool( (PVOID) &(IO) ) /* ReactOS Change: GCC "passing argument 1 from incompatible pointer type" */
1355 
1356 PFCB
1358  _In_ PIRP_CONTEXT IrpContext,
1359  _In_ PVCB Vcb,
1360  _In_ FILE_ID FileId
1361  );
1362 
1363 PFCB
1364 CdGetNextFcb (
1365  _In_ PIRP_CONTEXT IrpContext,
1366  _In_ PVCB Vcb,
1367  _In_ PVOID *RestartKey
1368  );
1369 
1370 NTSTATUS
1371 CdProcessToc (
1372  _In_ PIRP_CONTEXT IrpContext,
1374  _In_ PCDROM_TOC_LARGE CdromToc,
1376  _Out_ PULONG TrackCount,
1377  _Inout_ PULONG DiskFlags
1378  );
1379 
1380 //
1381 // For debugging purposes we sometimes want to allocate our structures from nonpaged
1382 // pool so that in the kernel debugger we can walk all the structures.
1383 //
1384 
1385 #define CdPagedPool PagedPool
1386 #ifndef __REACTOS__
1387 #define CdNonPagedPool NonPagedPoolNx
1388 #define CdNonPagedPoolCacheAligned NonPagedPoolNxCacheAligned
1389 #else
1390 #define CdNonPagedPool NonPagedPool
1391 #define CdNonPagedPoolCacheAligned NonPagedPoolCacheAligned
1392 #endif
1393 
1394 
1395 //
1396 // Verification support routines. Contained in verfysup.c
1397 //
1398 
1399 static /* ReactOS Change: GCC "multiple definition" */
1400 INLINE
1401 BOOLEAN
1403  _In_ PIRP_CONTEXT IrpContext
1404  )
1405 {
1407 
1408  return ((IrpContext->MajorFunction == IRP_MJ_CREATE) &&
1409  (IrpSp->FileObject->FileName.Length == 0) &&
1410  (IrpSp->FileObject->RelatedFileObject == NULL));
1411 }
1412 
1413 _Requires_lock_held_(_Global_critical_region_)
1414 NTSTATUS
1415 CdPerformVerify (
1416  _Inout_ PIRP_CONTEXT IrpContext,
1419  );
1420 
1421 _Requires_lock_held_(_Global_critical_region_)
1422 BOOLEAN
1423 CdCheckForDismount (
1424  _In_ PIRP_CONTEXT IrpContext,
1427  );
1428 
1429 BOOLEAN
1431  _Inout_ PVCB Vcb
1432  );
1433 
1434 VOID
1435 CdVerifyVcb (
1436  _In_ PIRP_CONTEXT IrpContext,
1437  _Inout_ PVCB Vcb
1438  );
1439 
1440 BOOLEAN
1442  _In_opt_ PIRP_CONTEXT IrpContext,
1443  _In_ PFCB Fcb
1444  );
1445 
1446 _Requires_lock_held_(_Global_critical_region_)
1447 BOOLEAN
1448 CdDismountVcb (
1449  _In_ PIRP_CONTEXT IrpContext,
1450  _Inout_ PVCB Vcb
1451  );
1452 
1453 
1454 //
1455 // Macros to abstract device verify flag changes.
1456 //
1457 
1458 #define CdUpdateMediaChangeCount( V, C) (V)->MediaChangeCount = (C)
1459 #define CdUpdateVcbCondition( V, C) (V)->VcbCondition = (C)
1460 
1461 #define CdMarkRealDevForVerify( DO) SetFlag( (DO)->Flags, DO_VERIFY_VOLUME)
1462 
1463 #define CdMarkRealDevVerifyOk( DO) ClearFlag( (DO)->Flags, DO_VERIFY_VOLUME)
1464 
1465 
1466 #define CdRealDevNeedsVerify( DO) BooleanFlagOn( (DO)->Flags, DO_VERIFY_VOLUME)
1467 
1468 //
1469 // BOOLEAN
1470 // CdIsRawDevice (
1471 // _In_ PIRP_CONTEXT IrpContext,
1472 // _In_ NTSTATUS Status
1473 // );
1474 //
1475 
1476 #define CdIsRawDevice(IC,S) ( \
1477  ((S) == STATUS_DEVICE_NOT_READY) || \
1478  ((S) == STATUS_NO_MEDIA_IN_DEVICE) \
1479 )
1480 
1481 
1482 //
1483 // Work queue routines for posting and retrieving an Irp, implemented in
1484 // workque.c
1485 //
1486 
1487 _Requires_lock_held_(_Global_critical_region_)
1488 NTSTATUS
1489 CdFsdPostRequest (
1490  _Inout_ PIRP_CONTEXT IrpContext,
1491  _Inout_ PIRP Irp
1492  );
1493 
1494 _Requires_lock_held_(_Global_critical_region_)
1495 VOID
1496 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
1497 CdPrePostIrp (
1498  _Inout_ PIRP_CONTEXT IrpContext,
1499  _Inout_ PIRP Irp
1500  );
1501 
1502 _Requires_lock_held_(_Global_critical_region_)
1503 VOID
1504 NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
1505 CdOplockComplete (
1506  _Inout_ PIRP_CONTEXT IrpContext,
1507  _Inout_ PIRP Irp
1508  );
1509 
1510 
1511 //
1512 // Miscellaneous support routines
1513 //
1514 
1515 //
1516 // This macro returns TRUE if a flag in a set of flags is on and FALSE
1517 // otherwise
1518 //
1519 
1520 /* GCC complains about multi-line comments.
1521 //#ifndef BooleanFlagOn
1522 //#define BooleanFlagOn(F,SF) ( \
1523 // (BOOLEAN)(((F) & (SF)) != 0) \
1524 //)
1525 //#endif
1526 
1527 //#ifndef SetFlag
1528 //#define SetFlag(Flags,SingleFlag) { \
1529 // (Flags) |= (SingleFlag); \
1530 //}
1531 //#endif
1532 
1533 //#ifndef ClearFlag
1534 //#define ClearFlag(Flags,SingleFlag) { \
1535 // (Flags) &= ~(SingleFlag); \
1536 //}
1537 //#endif
1538 */
1539 
1540 //
1541 // CAST
1542 // Add2Ptr (
1543 // _In_ PVOID Pointer,
1544 // _In_ ULONG Increment
1545 // _In_ (CAST)
1546 // );
1547 //
1548 // ULONG
1549 // PtrOffset (
1550 // _In_ PVOID BasePtr,
1551 // _In_ PVOID OffsetPtr
1552 // );
1553 //
1554 
1555 #define Add2Ptr(PTR,INC,CAST) ((CAST)((PUCHAR)(PTR) + (INC)))
1556 
1557 #define PtrOffset(BASE,OFFSET) ((ULONG)((ULONG_PTR)(OFFSET) - (ULONG_PTR)(BASE)))
1558 
1559 //
1560 // This macro takes a pointer (or ulong) and returns its rounded up word
1561 // value
1562 //
1563 
1564 #define WordAlign(Ptr) ( \
1565  ((((ULONG)(Ptr)) + 1) & 0xfffffffe) \
1566  )
1567 
1568 //
1569 // This macro takes a pointer (or ulong) and returns its rounded up longword
1570 // value
1571 //
1572 
1573 #define LongAlign(Ptr) ( \
1574  ((((ULONG)(Ptr)) + 3) & 0xfffffffc) \
1575  )
1576 
1577 //
1578 // This macro takes a pointer (or ulong) and returns its rounded up quadword
1579 // value
1580 //
1581 
1582 #define QuadAlign(Ptr) ( \
1583  ((((ULONG)(Ptr)) + 7) & 0xfffffff8) \
1584  )
1585 
1586 //
1587 // The following macros round up and down to sector boundaries.
1588 //
1589 
1590 #define SectorAlign(L) ( \
1591  ((((ULONG)(L)) + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1)) \
1592 )
1593 
1594 #define LlSectorAlign(L) ( \
1595  ((((LONGLONG)(L)) + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1)) \
1596 )
1597 
1598 #define SectorTruncate(L) ( \
1599  ((ULONG)(L)) & ~(SECTOR_SIZE - 1) \
1600 )
1601 
1602 #define LlSectorTruncate(L) ( \
1603  ((LONGLONG)(L)) & ~(SECTOR_SIZE - 1) \
1604 )
1605 
1606 #define BytesFromSectors(L) ( \
1607  ((ULONG) (L)) << SECTOR_SHIFT \
1608 )
1609 
1610 #define SectorsFromBytes(L) ( \
1611  ((ULONG) (L)) >> SECTOR_SHIFT \
1612 )
1613 
1614 static /* ReactOS Change: GCC "multiple definition" */
1615 INLINE
1616 ULONG
1619 ) {
1620 
1621  return (ULONG)(Bytes >> SECTOR_SHIFT);
1622 }
1623 
1624 #define LlBytesFromSectors(L) ( \
1625  Int64ShllMod32( (LONGLONG)(L), SECTOR_SHIFT ) \
1626 )
1627 
1628 #define LlSectorsFromBytes(L) ( \
1629  Int64ShraMod32( (LONGLONG)(L), SECTOR_SHIFT ) \
1630 )
1631 
1632 #define SectorOffset(L) ( \
1633  ((ULONG)(ULONG_PTR) (L)) & SECTOR_MASK \
1634 )
1635 
1636 #define SectorBlockOffset(V,LB) ( \
1637  ((ULONG) (LB)) & ((V)->BlocksPerSector - 1) \
1638 )
1639 
1640 #define BytesFromBlocks(V,B) ( \
1641  (ULONG) (B) << (V)->BlockToByteShift \
1642 )
1643 
1644 #define LlBytesFromBlocks(V,B) ( \
1645  Int64ShllMod32( (LONGLONG) (B), (V)->BlockToByteShift ) \
1646 )
1647 
1648 #define BlockAlign(V,L) ( \
1649  ((ULONG)(L) + (V)->BlockMask) & (V)->BlockInverseMask \
1650 )
1651 
1652 //
1653 // Carefully make sure the mask is sign extended to 64bits
1654 //
1655 
1656 #define LlBlockAlign(V,L) ( \
1657  ((LONGLONG)(L) + (V)->BlockMask) & (LONGLONG)((LONG)(V)->BlockInverseMask) \
1658 )
1659 
1660 #define BlockOffset(V,L) ( \
1661  ((ULONG) (L)) & (V)->BlockMask \
1662 )
1663 
1664 #define RawSectorAlign( B) ((((B)+(RAW_SECTOR_SIZE - 1)) / RAW_SECTOR_SIZE) * RAW_SECTOR_SIZE)
1665 
1666 //
1667 // The following types and macros are used to help unpack the packed and
1668 // misaligned fields found in the Bios parameter block
1669 //
1670 
1671 typedef union _UCHAR1 {
1674 } UCHAR1, *PUCHAR1;
1675 
1676 typedef union _UCHAR2 {
1679 } UCHAR2, *PUCHAR2;
1680 
1681 typedef union _UCHAR4 {
1684 } UCHAR4, *PUCHAR4;
1685 
1686 typedef union _USHORT2 {
1689 } USHORT2, *PUSHORT2;
1690 
1691 //
1692 // This macro copies an unaligned src byte to an aligned dst byte
1693 //
1694 
1695 #define CopyUchar1(Dst,Src) { \
1696  *((UCHAR1 *)(Dst)) = *((UNALIGNED UCHAR1 *)(Src)); \
1697  }
1698 
1699 //
1700 // This macro copies an unaligned src word to an aligned dst word
1701 //
1702 
1703 #define CopyUchar2(Dst,Src) { \
1704  *((UCHAR2 *)(Dst)) = *((UNALIGNED UCHAR2 *)(Src)); \
1705  }
1706 
1707 //
1708 // This macro copies an unaligned src longword to an aligned dsr longword
1709 //
1710 
1711 #define CopyUchar4(Dst,Src) { \
1712  *((UCHAR4 *)(Dst)) = *((UNALIGNED UCHAR4 *)(Src)); \
1713  }
1714 
1715 //
1716 // This macro copies an unaligned src longword to an aligned dsr longword
1717 // accessing the source on a word boundary.
1718 //
1719 
1720 #define CopyUshort2(Dst,Src) { \
1721  *((USHORT2 *)(Dst)) = *((UNALIGNED USHORT2 *)(Src));\
1722  }
1723 
1724 //
1725 // This macro copies an unaligned src longword to a dst longword,
1726 // performing an little/big endian swap.
1727 //
1728 
1729 #define SwapCopyUchar4(Dst,Src) { \
1730  *((UNALIGNED UCHAR1 *)(Dst)) = *((UNALIGNED UCHAR1 *)(Src) + 3); \
1731  *((UNALIGNED UCHAR1 *)(Dst) + 1) = *((UNALIGNED UCHAR1 *)(Src) + 2); \
1732  *((UNALIGNED UCHAR1 *)(Dst) + 2) = *((UNALIGNED UCHAR1 *)(Src) + 1); \
1733  *((UNALIGNED UCHAR1 *)(Dst) + 3) = *((UNALIGNED UCHAR1 *)(Src)); \
1734 }
1735 
1736 VOID
1737 CdLbnToMmSsFf (
1738  _In_ ULONG Blocks,
1739  _Out_writes_(3) PUCHAR Msf
1740  );
1741 
1742 //
1743 // Following routines handle entry in and out of the filesystem. They are
1744 // contained in CdData.c
1745 //
1746 
1763 NTSTATUS
1764 NTAPI
1765 CdFsdDispatch (
1767  _Inout_ PIRP Irp
1768  );
1769 
1770 // DRIVER_DISPATCH CdFsdDispatch;
1771 
1772 LONG
1774  _Inout_ PIRP_CONTEXT IrpContext,
1775  _In_ PEXCEPTION_POINTERS ExceptionPointer
1776  );
1777 
1778 _Requires_lock_held_(_Global_critical_region_)
1779 NTSTATUS
1780 CdProcessException (
1781  _In_opt_ PIRP_CONTEXT IrpContext,
1784  );
1785 
1786 VOID
1788  _Inout_opt_ PIRP_CONTEXT IrpContext,
1791  );
1792 
1793 //
1794 // VOID
1795 // CdRaiseStatus (
1796 // _In_ PRIP_CONTEXT IrpContext,
1797 // _In_ NT_STATUS Status
1798 // );
1799 //
1800 // VOID
1801 // CdNormalizeAndRaiseStatus (
1802 // _In_ PRIP_CONTEXT IrpContext,
1803 // _In_ NT_STATUS Status
1804 // );
1805 //
1806 
1807 #if 0
1808 #define AssertVerifyDevice(C, S) \
1809  NT_ASSERT( (C) == NULL || \
1810  FlagOn( (C)->Flags, IRP_CONTEXT_FLAG_IN_FSP ) || \
1811  !((S) == STATUS_VERIFY_REQUIRED && \
1812  IoGetDeviceToVerify( PsGetCurrentThread() ) == NULL ));
1813 
1814 #define AssertVerifyDeviceIrp(I) \
1815  NT_ASSERT( (I) == NULL || \
1816  !(((I)->IoStatus.Status) == STATUS_VERIFY_REQUIRED && \
1817  ((I)->Tail.Overlay.Thread == NULL || \
1818  IoGetDeviceToVerify( (I)->Tail.Overlay.Thread ) == NULL )));
1819 #else
1820 #define AssertVerifyDevice(C, S)
1821 #define AssertVerifyDeviceIrp(I)
1822 #endif
1823 
1824 
1825 #ifdef CD_SANITY
1826 
1828 VOID
1830  _In_ PIRP_CONTEXT IrpContext,
1832  _In_ BOOLEAN NormalizeStatus,
1833  _In_opt_ ULONG FileId,
1835  );
1836 
1837 #else
1838 
1839 #ifdef __REACTOS__
1840 static // make windows gcc release build compile
1841 #endif
1842 INLINE
1844 VOID
1846  _In_ PIRP_CONTEXT IrpContext,
1848  _In_ BOOLEAN NormalizeStatus,
1849  _In_ ULONG Fileid,
1850  _In_ ULONG Line
1851  )
1852 {
1853  if (NormalizeStatus) {
1854 
1855  IrpContext->ExceptionStatus = FsRtlNormalizeNtstatus( Status, STATUS_UNEXPECTED_IO_ERROR);
1856  }
1857  else {
1858 
1859  IrpContext->ExceptionStatus = Status;
1860  }
1861 
1862  IrpContext->RaisedAtLineFile = (Fileid << 16) | Line;
1863 
1864  ExRaiseStatus( IrpContext->ExceptionStatus );
1865 }
1866 
1867 #endif
1868 
1869 #define CdRaiseStatus( IC, S) CdRaiseStatusEx( (IC), (S), FALSE, BugCheckFileId, __LINE__);
1870 #define CdNormalizeAndRaiseStatus( IC, S) CdRaiseStatusEx( (IC), (S), TRUE, BugCheckFileId, __LINE__);
1871 
1872 //
1873 // Following are the fast entry points.
1874 //
1875 
1876 // _Success_(return != FALSE)
1877 // BOOLEAN
1878 // CdFastQueryBasicInfo (
1879 // _In_ PFILE_OBJECT FileObject,
1880 // _In_ BOOLEAN Wait,
1881 // _Out_ PFILE_BASIC_INFORMATION Buffer,
1882 // _Out_ PIO_STATUS_BLOCK IoStatus,
1883 // _In_ PDEVICE_OBJECT DeviceObject
1884 // );
1885 
1886 FAST_IO_QUERY_BASIC_INFO CdFastQueryBasicInfo;
1887 
1888 // _Success_(return != FALSE)
1889 // BOOLEAN
1890 // CdFastQueryStdInfo (
1891 // _In_ PFILE_OBJECT FileObject,
1892 // _In_ BOOLEAN Wait,
1893 // _Out_ PFILE_STANDARD_INFORMATION Buffer,
1894 // _Out_ PIO_STATUS_BLOCK IoStatus,
1895 // _In_ PDEVICE_OBJECT DeviceObject
1896 // );
1897 
1898 FAST_IO_QUERY_STANDARD_INFO CdFastQueryStdInfo;
1899 
1900 // BOOLEAN
1901 // CdFastLock (
1902 // _In_ PFILE_OBJECT FileObject,
1903 // _In_ PLARGE_INTEGER FileOffset,
1904 // _In_ PLARGE_INTEGER Length,
1905 // _In_ PEPROCESS ProcessId,
1906 // _In_ ULONG Key,
1907 // _In_ BOOLEAN FailImmediately,
1908 // _In_ BOOLEAN ExclusiveLock,
1909 // _Out_ PIO_STATUS_BLOCK IoStatus,
1910 // _In_ PDEVICE_OBJECT DeviceObject
1911 // );
1912 
1913 FAST_IO_LOCK CdFastLock;
1914 
1915 // BOOLEAN
1916 // CdFastUnlockSingle (
1917 // _In_ PFILE_OBJECT FileObject,
1918 // _In_ PLARGE_INTEGER FileOffset,
1919 // _In_ PLARGE_INTEGER Length,
1920 // _In_ PEPROCESS ProcessId,
1921 // _In_ ULONG Key,
1922 // _Out_ PIO_STATUS_BLOCK IoStatus,
1923 // _In_ PDEVICE_OBJECT DeviceObject
1924 // );
1925 
1926 FAST_IO_UNLOCK_SINGLE CdFastUnlockSingle;
1927 
1928 // BOOLEAN
1929 // CdFastUnlockAll (
1930 // _In_ PFILE_OBJECT FileObject,
1931 // _In_ PEPROCESS ProcessId,
1932 // _Out_ PIO_STATUS_BLOCK IoStatus,
1933 // _In_ PDEVICE_OBJECT DeviceObject
1934 // );
1935 
1936 FAST_IO_UNLOCK_ALL CdFastUnlockAll;
1937 
1938 // BOOLEAN
1939 // CdFastUnlockAllByKey (
1940 // _In_ PFILE_OBJECT FileObject,
1941 // _In_ PVOID ProcessId,
1942 // _In_ ULONG Key,
1943 // _Out_ PIO_STATUS_BLOCK IoStatus,
1944 // _In_ PDEVICE_OBJECT DeviceObject
1945 // );
1946 
1947 FAST_IO_UNLOCK_ALL_BY_KEY CdFastUnlockAllByKey;
1948 
1949 // BOOLEAN
1950 // CdFastIoCheckIfPossible (
1951 // _In_ PFILE_OBJECT FileObject,
1952 // _In_ PLARGE_INTEGER FileOffset,
1953 // _In_ ULONG Length,
1954 // _In_ BOOLEAN Wait,
1955 // _In_ ULONG LockKey,
1956 // _In_ BOOLEAN CheckForReadOperation,
1957 // _Out_ PIO_STATUS_BLOCK IoStatus,
1958 // _In_ PDEVICE_OBJECT DeviceObject
1959 // );
1960 
1961 FAST_IO_CHECK_IF_POSSIBLE CdFastIoCheckIfPossible;
1962 
1963 // _Success_(return != FALSE)
1964 // BOOLEAN
1965 // CdFastQueryNetworkInfo (
1966 // _In_ PFILE_OBJECT FileObject,
1967 // _In_ BOOLEAN Wait,
1968 // _Out_ PFILE_NETWORK_OPEN_INFORMATION Buffer,
1969 // _Out_ PIO_STATUS_BLOCK IoStatus,
1970 // _In_ PDEVICE_OBJECT DeviceObject
1971 // );
1972 
1973 FAST_IO_QUERY_NETWORK_OPEN_INFO CdFastQueryNetworkInfo;
1974 
1975 //
1976 // Following are the routines to handle the top level thread logic.
1977 //
1978 
1979 VOID
1981  _Inout_ PIRP_CONTEXT IrpContext,
1982  _In_ PTHREAD_CONTEXT ThreadContext
1983  );
1984 
1985 
1986 //
1987 // VOID
1988 // CdRestoreThreadContext (
1989 // _Inout_ PIRP_CONTEXT IrpContext
1990 // );
1991 //
1992 
1993 #define CdRestoreThreadContext(IC) \
1994  (IC)->ThreadContext->Cdfs = 0; \
1995  IoSetTopLevelIrp( (IC)->ThreadContext->SavedTopLevelIrp ); \
1996  (IC)->ThreadContext = NULL
1997 
1998 ULONG
1999 CdSerial32 (
2002  );
2003 
2004 //
2005 // The following macro is used to determine if an FSD thread can block
2006 // for I/O or wait for a resource. It returns TRUE if the thread can
2007 // block and FALSE otherwise. This attribute can then be used to call
2008 // the FSD & FSP common work routine with the proper wait value.
2009 //
2010 
2011 #define CanFsdWait(I) IoIsOperationSynchronous(I)
2012 
2013 //
2014 // The following macro is used to set the fast i/o possible bits in the
2015 // FsRtl header.
2016 //
2017 // FastIoIsNotPossible - If the Fcb is bad or there are oplocks on the file.
2018 //
2019 // FastIoIsQuestionable - If there are file locks.
2020 //
2021 // FastIoIsPossible - In all other cases.
2022 //
2023 //
2024 
2025 #define CdIsFastIoPossible(F) ((BOOLEAN) \
2026  ((((F)->Vcb->VcbCondition != VcbMounted ) || \
2027  !FsRtlOplockIsFastIoPossible( CdGetFcbOplock(F) )) ? \
2028  \
2029  FastIoIsNotPossible : \
2030  \
2031  ((((F)->FileLock != NULL) && FsRtlAreThereCurrentFileLocks( (F)->FileLock )) ? \
2032  \
2033  FastIoIsQuestionable : \
2034  \
2035  FastIoIsPossible)) \
2036 )
2037 
2038 
2039 //
2040 // The FSP level dispatch/main routine. This is the routine that takes
2041 // IRP's off of the work queue and calls the appropriate FSP level
2042 // work routine.
2043 //
2044 
2045 // VOID
2046 // CdFspDispatch ( // implemented in FspDisp.c
2047 // _Inout_ PIRP_CONTEXT IrpContext
2048 // );
2049 
2050 WORKER_THREAD_ROUTINE CdFspDispatch;
2051 
2052 VOID
2053 CdFspClose ( // implemented in Close.c
2054  _In_opt_ PVCB Vcb
2055  );
2056 
2057 //
2058 // The following routines are the entry points for the different operations
2059 // based on the IrpSp major functions.
2060 //
2061 
2062 _Requires_lock_held_(_Global_critical_region_)
2063 NTSTATUS
2064 CdCommonCreate ( // Implemented in Create.c
2065  _Inout_ PIRP_CONTEXT IrpContext,
2066  _Inout_ PIRP Irp
2067  );
2068 
2069 _Requires_lock_held_(_Global_critical_region_)
2070 NTSTATUS
2071 CdCommonClose ( // Implemented in Close.c
2072  _Inout_ PIRP_CONTEXT IrpContext,
2073  _Inout_ PIRP Irp
2074  );
2075 
2076 _Requires_lock_held_(_Global_critical_region_)
2077 NTSTATUS
2078 CdCommonRead ( // Implemented in Read.c
2079  _Inout_ PIRP_CONTEXT IrpContext,
2080  _Inout_ PIRP Irp
2081  );
2082 
2083 _Requires_lock_held_(_Global_critical_region_)
2084 NTSTATUS
2085 CdCommonWrite ( // Implemented in Write.c
2086  _Inout_ PIRP_CONTEXT IrpContext,
2087  _Inout_ PIRP Irp
2088  );
2089 
2090 _Requires_lock_held_(_Global_critical_region_)
2091 NTSTATUS
2092 CdCommonQueryInfo ( // Implemented in FileInfo.c
2093  _Inout_ PIRP_CONTEXT IrpContext,
2094  _Inout_ PIRP Irp
2095  );
2096 
2097 _Requires_lock_held_(_Global_critical_region_)
2098 NTSTATUS
2099 CdCommonSetInfo ( // Implemented in FileInfo.c
2100  _Inout_ PIRP_CONTEXT IrpContext,
2101  _Inout_ PIRP Irp
2102  );
2103 
2104 _Requires_lock_held_(_Global_critical_region_)
2105 NTSTATUS
2106 CdCommonQueryVolInfo ( // Implemented in VolInfo.c
2107  _Inout_ PIRP_CONTEXT IrpContext,
2108  _Inout_ PIRP Irp
2109  );
2110 
2111 _Requires_lock_held_(_Global_critical_region_)
2112 NTSTATUS
2113 CdCommonDirControl ( // Implemented in DirCtrl.c
2114  _Inout_ PIRP_CONTEXT IrpContext,
2115  _Inout_ PIRP Irp
2116  );
2117 
2118 _Requires_lock_held_(_Global_critical_region_)
2119 NTSTATUS
2120 CdCommonFsControl ( // Implemented in FsCtrl.c
2121  _Inout_ PIRP_CONTEXT IrpContext,
2122  _Inout_ PIRP Irp
2123  );
2124 
2125 NTSTATUS
2126 CdCommonDevControl ( // Implemented in DevCtrl.c
2127  _Inout_ PIRP_CONTEXT IrpContext,
2128  _Inout_ PIRP Irp
2129  );
2130 
2131 NTSTATUS
2132 CdCommonLockControl ( // Implemented in LockCtrl.c
2133  _Inout_ PIRP_CONTEXT IrpContext,
2134  _Inout_ PIRP Irp
2135  );
2136 
2137 _Requires_lock_held_(_Global_critical_region_)
2138 NTSTATUS
2139 CdCommonCleanup ( // Implemented in Cleanup.c
2140  _Inout_ PIRP_CONTEXT IrpContext,
2141  _Inout_ PIRP Irp
2142  );
2143 
2144 _Requires_lock_held_(_Global_critical_region_)
2145 NTSTATUS
2146 CdCommonPnp ( // Implemented in Pnp.c
2147  _Inout_ PIRP_CONTEXT IrpContext,
2148  _Inout_ PIRP Irp
2149  );
2150 
2151 _Requires_lock_held_(_Global_critical_region_)
2152 NTSTATUS
2153 CdCommonShutdown ( // Implemented in Shutdown.c
2154  _Inout_ PIRP_CONTEXT IrpContext,
2155  _Inout_ PIRP Irp
2156  );
2157 
2158 
2159 
2160 //
2161 // The following macros are used to establish the semantics needed
2162 // to do a return from within a try-finally clause. As a rule every
2163 // try clause must end with a label call try_exit. For example,
2164 //
2165 // try {
2166 // :
2167 // :
2168 //
2169 // try_exit: NOTHING;
2170 // } finally {
2171 //
2172 // :
2173 // :
2174 // }
2175 //
2176 // Every return statement executed inside of a try clause should use the
2177 // try_return macro. If the compiler fully supports the try-finally construct
2178 // then the macro should be
2179 //
2180 // #define try_return(S) { return(S); }
2181 //
2182 // If the compiler does not support the try-finally construct then the macro
2183 // should be
2184 //
2185 // #define try_return(S) { S; goto try_exit; }
2186 //
2187 
2188 #ifndef __REACTOS__
2189 #define try_return(S) { S; goto try_exit; }
2190 #define try_leave(S) { S; leave; }
2191 #else
2192 #define try_return(S) { S; goto try_exit; }
2193 #define try_leave(S) { S; _SEH2_LEAVE; }
2194 #endif
2195 
2196 //
2197 // Encapsulate safe pool freeing
2198 //
2199 /* ReactOS Change: GCC "passing argument 1 of CdFreePool from incompatible pointer type" */
2200 #define CdFreePool(x) _CdFreePool((PVOID*)(x))
2201 
2202 static /* ReactOS Change: GCC "multiple definition" */
2203 INLINE
2204 VOID
2207  )
2208 {
2209  if (*Pool != NULL) {
2210 
2211  ExFreePool(*Pool);
2212  *Pool = NULL;
2213  }
2214 }
2215 
2216 #ifdef CDFS_TELEMETRY_DATA
2217 
2218 //
2219 // CDFS Telemetry. Current implementation uses the Telemetry TraceLogging APIs.
2220 //
2221 // The Telemetry TraceLoggingWrite() routines use a lot of stack space. We must
2222 // therefor wrap all our telemetry points with our own routines, and add a guard to
2223 // make sure there's enough stack space to call these routines.
2224 //
2225 // These telemetry routines should not be called on high-performance code paths.
2226 //
2227 
2228 TRACELOGGING_DECLARE_PROVIDER( CdTelemetryProvider );
2229 
2230 VOID
2231 CdInitializeTelemetry (
2232  VOID
2233  );
2234 
2236 VOID
2237 CdTelemetryMount (
2238  __in PGUID VolumeGuid,
2240  __in PVCB Vcb
2241  );
2242 
2243 //
2244 // Every additional argument passed to TraceLoggingWrite() consumes an additional
2245 // 16 to 32 bytes extra stack space. Having 512 bytes reserved space should be
2246 // sufficient for up to 20 arguments or so. This will be less of course if our
2247 // wrapper routines also declare their own local variables.
2248 //
2249 
2250 #define CDFS_TELEMETRY_STACK_THRESHOLD_DEFAULT 512 // for "small" telemetry points
2251 #define CDFS_TELEMETRY_STACK_THRESHOLD_LARGE 2048 // for "large" telemetry points
2252 
2253 INLINE
2254 BOOLEAN
2255 CdTelemetryGuard (
2256  __in ULONG StackSpaceNeeded )
2257 /*++
2258 
2259 Routine Description:
2260 
2261  This routine returns TRUE only when:
2262 
2263  1) There is an ETW listener, AND
2264  2) There is enough free stack space to safely call the Telemetry TraceLogging APIs
2265 
2266  We'll also count how many times there wasn't enough stack space, and include this
2267  value as part of the periodic cdfs Telemetry.
2268 
2269 Arguments:
2270 
2271  StackSpaceNeeded - Stack space needed in bytes
2272 
2273 --*/
2274 {
2275  ASSERT( IoGetRemainingStackSize() >= StackSpaceNeeded );
2276 
2277  if (CdTelemetryProvider->LevelPlus1 <= 5) {
2278 
2279  //
2280  // Bail out early if there are no ETW listeners
2281  //
2282 
2283  return FALSE;
2284  }
2285 
2286  if (IoGetRemainingStackSize() < StackSpaceNeeded) {
2287 
2288  //
2289  // Count how many times it was unsafe to generate telemetry because of
2290  // not enough stack space.
2291  //
2292 
2293  InterlockedIncrement( &CdTelemetryData.MissedTelemetryPoints );
2294 
2295  return FALSE;
2296  }
2297 
2298  return TRUE;
2299 }
2300 
2301 #define CdTelemetryMountSafe( VolumeGuid, Status, Vcb ) \
2302  if (CdTelemetryGuard( CDFS_TELEMETRY_STACK_THRESHOLD_LARGE )) { \
2303  CdTelemetryMount( VolumeGuid, Status, Vcb ); \
2304  }
2305 
2306 #if DBG
2307 #define CDFS_TELEMETRY_PERIODIC_INTERVAL CdTelemetryData.PeriodicInterval
2308 #else
2309 #define CDFS_TELEMETRY_PERIODIC_INTERVAL INTERVAL_ONE_DAY
2310 #endif
2311 
2312 #else // CDFS_TELEMETRY_DATA
2313 
2314 //
2315 // When CDFS_TELEMETRY_DATA is not defined then the CdTelemetry___Safe() routines
2316 // expand to nothing. This minimizes the cdfs.sys binary footprint. This also
2317 // means that the places where these Safe() routines are called do not
2318 // have to have to be surrounded by #ifdef CDFS_TELEMETRY_DATA .. #endif
2319 //
2320 
2321 
2322 #define CdTelemetryMountSafe( ... ) NOTHING
2323 
2324 #endif // CDFS_TELEMETRY_DATA
2325 
2326 #endif // _CDPROCS_
2327 
2328 
static INLINE VOID _CdFreePool(_Inout_ _At_(*Pool, __drv_freesMem(Mem) _Post_null_) PVOID *Pool)
Definition: cdprocs.h:2205
UNICODE_STRING VersionString
Definition: cdstruc.h:256
union _USHORT2 USHORT2
VOID CdDeleteInternalStream(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb)
Definition: cachesup.c:333
signed char * PCHAR
Definition: retypes.h:7
ULONG ForceAlignment
Definition: cdprocs.h:1683
VOID CdCleanupFileContext(_In_ PIRP_CONTEXT IrpContext, _In_ PFILE_ENUM_CONTEXT FileContext)
Definition: dirsup.c:1636
_Inout_ PIRP _In_ NTSTATUS ExceptionCode
Definition: cdprocs.h:1782
#define SIZEOF_FCB_INDEX
Definition: cdstruc.h:1065
#define SIZEOF_FCB_DATA
Definition: cdstruc.h:1062
WORKER_THREAD_ROUTINE CdFspDispatch
Definition: cdprocs.h:2050
_Inout_ PFCB _Out_ PBOOLEAN RemovedStartingFcb
Definition: cdprocs.h:1264
PFCB CdCreateFcb(_In_ PIRP_CONTEXT IrpContext, _In_ FILE_ID FileId, _In_ NODE_TYPE_CODE NodeTypeCode, _Out_opt_ PBOOLEAN FcbExisted)
Definition: strucsup.c:986
return
Definition: dirsup.c:529
_In_ PFCB _In_ LONGLONG _Out_ PLONGLONG DiskOffset
Definition: cdprocs.h:151
#define TRUE
Definition: types.h:120
BOOLEAN CdIsNameInExpression(_In_ PIRP_CONTEXT IrpContext, _In_ PCD_NAME CurrentName, _In_ PCD_NAME SearchExpression, _In_ ULONG WildcardFlags, _In_ BOOLEAN CheckVersion)
Definition: namesup.c:844
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
_Inout_ PFCB * CurrentFcb
Definition: cdprocs.h:806
static INLINE BOOLEAN CdOperationIsDasdOpen(_In_ PIRP_CONTEXT IrpContext)
Definition: cdprocs.h:1402
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
Type
Definition: Type.h:6
_In_ PIRP _In_ PDEVICE_OBJECT Device
Definition: fatprocs.h:2020
_At_(Fcb->NodeByteSize, _In_range_(>=, FIELD_OFFSET(FCB, FcbType))) VOID CdInitializeMcb(_In_ PIRP_CONTEXT IrpContext
#define _Out_writes_bytes_to_(size, count)
Definition: no_sal2.h:374
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:282
unsigned char Uchar
Definition: utypes.h:45
FSRTL_COMPARISON_RESULT CdFullCompareNames(_In_ PIRP_CONTEXT IrpContext, _In_ PUNICODE_STRING NameA, _In_ PUNICODE_STRING NameB)
Definition: namesup.c:1064
PFILE_OBJECT FileObject
Definition: ntfs.h:516
BOOLEAN CdIs8dot3Name(_In_ PIRP_CONTEXT IrpContext, _In_ UNICODE_STRING FileName)
Definition: namesup.c:429
#define IRP_MJ_SHUTDOWN
VOID CdSetThreadContext(_Inout_ PIRP_CONTEXT IrpContext, _In_ PTHREAD_CONTEXT ThreadContext)
Definition: cddata.c:981
FAST_IO_QUERY_BASIC_INFO CdFastQueryBasicInfo
Definition: cdprocs.h:1886
_In_ PIRP Irp
Definition: csq.h:116
Definition: cdstruc.h:908
VOID CdAddAllocationFromDirent(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_ ULONG McbEntryOffset, _In_ LONGLONG StartingFileOffset, _In_ PDIRENT Dirent)
Definition: allocsup.c:335
Definition: cdstruc.h:1073
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG CdSerial32(_In_reads_bytes_(ByteCount) PCHAR Buffer, _In_ ULONG ByteCount)
Definition: cddata.c:1185
#define SECTOR_SHIFT
Definition: cd.h:32
Dirent DirentOffset
Definition: dirsup.c:444
#define _In_reads_bytes_opt_(size)
Definition: no_sal2.h:230
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID _In_ ULONG _In_ BOOLEAN InternalDeviceIoControl
Definition: iofuncs.h:713
VOID CdUpcaseName(_In_ PIRP_CONTEXT IrpContext, _In_ PCD_NAME Name, _Inout_ PCD_NAME UpcaseName)
Definition: namesup.c:194
LONG NTSTATUS
Definition: precomp.h:26
FAST_IO_CHECK_IF_POSSIBLE CdFastIoCheckIfPossible
Definition: cdprocs.h:1961
_Inout_updates_bytes_(Fcb->NodeByteSize) PFCB Fcb)
Definition: allocsup.c:631
USHORT ForceAlignment
Definition: cdprocs.h:1678
BOOLEAN NTAPI CdNoopAcquire(_In_ PVOID Fcb, _In_ BOOLEAN Wait)
Definition: resrcsup.c:218
union _UCHAR2 UCHAR2
FAST_IO_QUERY_STANDARD_INFO CdFastQueryStdInfo
Definition: cdprocs.h:1898
NTSTATUS FASTCALL CdPerformDevIoCtrl(_In_ PIRP_CONTEXT IrpContext, _In_ ULONG IoControlCode, _In_ PDEVICE_OBJECT Device, _Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer, _In_ ULONG OutputBufferLength, _In_ BOOLEAN InternalDeviceIoControl, _In_ BOOLEAN OverrideVerify, _Out_opt_ PIO_STATUS_BLOCK Iosb)
Definition: deviosup.c:1446
ULONG CdShortNameDirentOffset(_In_ PIRP_CONTEXT IrpContext, _In_ PUNICODE_STRING Name)
Definition: namesup.c:955
NTSTATUS CdPerformDevIoCtrlEx(_In_ PIRP_CONTEXT IrpContext, _In_ ULONG IoControlCode, _In_ PDEVICE_OBJECT Device, _In_reads_bytes_opt_(InputBufferLength) PVOID InputBuffer, _In_ ULONG InputBufferLength, _Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer, _In_ ULONG OutputBufferLength, _In_ BOOLEAN InternalDeviceIoControl, _In_ BOOLEAN OverrideVerify, _Out_opt_ PIO_STATUS_BLOCK Iosb)
Definition: deviosup.c:1329
#define _Outptr_
Definition: no_sal2.h:396
_In_ UINT Bytes
Definition: mmcopy.h:9
FAST_IO_QUERY_NETWORK_OPEN_INFO CdFastQueryNetworkInfo
Definition: cdprocs.h:1973
VOID CdUpdateDirentName(_In_ PIRP_CONTEXT IrpContext, _Inout_ PDIRENT Dirent, _In_ ULONG IgnoreCase)
Definition: dirsup.c:534
#define ExRaiseStatus
Definition: ntoskrnl.h:96
union _UCHAR4 * PUCHAR4
VOID CdInsertPrefix(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_ PCD_NAME Name, _In_ BOOLEAN IgnoreCase, _In_ BOOLEAN ShortNameMatch, _Inout_ PFCB ParentFcb)
Definition: prefxsup.c:52
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
_Acquires_shared_lock_(Vcb->Resource)) FINISHED FatAcquireSharedVcb(IN PIRP_CONTEXT IrpContext
Definition: cdstruc.h:504
_In_ PVCB _In_ BOOLEAN DismountUnderway
Definition: cdprocs.h:227
#define _Post_notnull_
Definition: no_sal2.h:460
#define _Ret_valid_
Definition: no_sal2.h:614
VOID CdDeleteFileLock(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFILE_LOCK FileLock)
_Acquires_exclusive_lock_(Vcb->Resource)) FINISHED FatAcquireExclusiveVcb_Real(IN PIRP_CONTEXT IrpContext
uint16_t * PWCHAR
Definition: typedefs.h:54
_In_ PFCB _In_ PCD_NAME _In_ BOOLEAN _Inout_ PFILE_ENUM_CONTEXT _Out_ PCD_NAME * MatchingName
Definition: cdprocs.h:444
#define CDFS_NTC_FCB_PATH_TABLE
Definition: nodetype.h:29
#define FASTCALL
Definition: nt_native.h:50
_When_(TypeOfOpen==UnopenedFileObject, _At_(Fcb, _In_opt_)) _When_(TypeOfOpen !
VOID CdInitializeStackIrpContext(_Out_ PIRP_CONTEXT IrpContext, _In_ PIRP_CONTEXT_LITE IrpContextLite)
Definition: strucsup.c:1839
VOID CdConvertBigToLittleEndian(_In_ PIRP_CONTEXT IrpContext, _In_reads_bytes_(ByteCount) PCHAR BigEndian, _In_ ULONG ByteCount, _Out_writes_bytes_(ByteCount) PCHAR LittleEndian)
Definition: namesup.c:110
union _UCHAR4 UCHAR4
#define DECLSPEC_NORETURN
Definition: ntbasedef.h:176
VOID CdLbnToMmSsFf(_In_ ULONG Blocks, _Out_writes_(3) PUCHAR Msf)
#define INLINE
Definition: cdprocs.h:38
#define CDFS_NTC_FCB_INDEX
Definition: nodetype.h:30
CHAR InputBuffer[80]
Definition: conmgr.c:33
#define _In_opt_
Definition: no_sal2.h:213
VOID CdFspClose(_In_opt_ PVCB Vcb)
_Post_satisfies_(_Old_(CdName->FileName.Length) >=CdName->FileName.Length+CdName->VersionString.Length) VOID CdConvertNameToCdName(_In_ PIRP_CONTEXT IrpContext
PREFIX_ENTRY FileNamePrefix
Definition: cdstruc.h:1030
union _UCHAR1 * PUCHAR1
#define _Out_writes_(size)
Definition: no_sal2.h:367
__GNU_EXTENSION typedef __int64 * PLONGLONG
Definition: ntbasedef.h:389
enum _TYPE_OF_ACQUIRE * PTYPE_OF_ACQUIRE
_In_ PFCB _In_ PCD_NAME _In_ BOOLEAN _In_ ULONG ShortNameDirentOffset
Definition: cdprocs.h:464
VOID CdTruncateAllocation(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_ LONGLONG StartingFileOffset)
Definition: allocsup.c:575
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN TypeOfOpen
Definition: cdprocs.h:593
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
TYPE_OF_OPEN CdFastDecodeFileObject(_In_ PFILE_OBJECT FileObject, _Out_ PFCB *Fcb)
Definition: filobsup.c:206
NAME_LINK ExactCaseName
Definition: cdstruc.h:299
VOID CdInitializeFcbFromPathEntry(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_opt_ PFCB ParentFcb, _In_ PPATH_ENTRY PathEntry)
Definition: strucsup.c:1136
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:848
long LONG
Definition: pedump.c:60
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define CDFS_NTC_FCB_DATA
Definition: nodetype.h:31
#define _Releases_lock_(a)
Definition: btrfs_drv.h:192
_Unreferenced_parameter_ PVOID * CompletionContext
Definition: cdprocs.h:1130
NTSTATUS CdProcessToc(_In_ PIRP_CONTEXT IrpContext, _In_ PDEVICE_OBJECT TargetDeviceObject, _In_ PCDROM_TOC_LARGE CdromToc, _Inout_ PULONG Length, _Out_ PULONG TrackCount, _Inout_ PULONG DiskFlags)
Definition: strucsup.c:2201
#define __drv_aliasesMem
Definition: btrfs_drv.h:189
unsigned char BOOLEAN
#define _Out_writes_bytes_opt_(a)
Definition: btrfs_drv.h:193
VOID CdUpdatePathEntryName(_In_ PIRP_CONTEXT IrpContext, _Inout_ PPATH_ENTRY PathEntry, _In_ BOOLEAN IgnoreCase)
Definition: pathsup.c:781
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN CdReadSectors(_In_ PIRP_CONTEXT IrpContext, _In_ LONGLONG StartingOffset, _In_ ULONG ByteCount, _In_ BOOLEAN ReturnError, _Out_writes_bytes_(ByteCount) PVOID Buffer, _In_ PDEVICE_OBJECT TargetDeviceObject)
Definition: deviosup.c:1080
BOOLEAN CdLookupNextDirent(_In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb, _In_ PDIRENT_ENUM_CONTEXT CurrentDirContext, _Inout_ PDIRENT_ENUM_CONTEXT NextDirContext)
Definition: dirsup.c:208
NTSTATUS CdCompleteMdl(_In_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp)
Definition: cachesup.c:411
#define _Out_writes_bytes_(size)
Definition: no_sal2.h:370
VOID CdCreateInternalStream(_In_ PIRP_CONTEXT IrpContext, _In_ PVCB Vcb, _Inout_ PFCB Fcb, _In_ PUNICODE_STRING Name)
Definition: cachesup.c:38
#define _Out_
Definition: no_sal2.h:323
PFCB CdLookupFcbTable(_In_ PIRP_CONTEXT IrpContext, _In_ PVCB Vcb, _In_ FILE_ID FileId)
Definition: strucsup.c:2107
_In_ PFCB _In_ PCD_NAME _In_ BOOLEAN IgnoreCase
Definition: cdprocs.h:444
Definition: bufpool.h:45
_Inout_ PCD_NAME CdName
Definition: cdprocs.h:628
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
_In_ PFCB _In_ LONGLONG _Out_ PLONGLONG _Out_ PULONG ByteCount
Definition: cdprocs.h:151
_TYPE_OF_ACQUIRE
Definition: cdprocs.h:832
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
_Function_class_(FAST_IO_RELEASE_FILE) _Requires_lock_held_(_Global_critical_region_) VOID NTAPI CdReleaseForCreateSection(_In_ PFILE_OBJECT FileObject)
Definition: resrcsup.c:366
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_In_ PFCB _In_ PCD_NAME _In_ BOOLEAN _Inout_ PFILE_ENUM_CONTEXT FileContext
Definition: cdprocs.h:444
_Success_(return !=FALSE) BOOLEAN CdFindFile(_In_ PIRP_CONTEXT IrpContext
Definition: fsctrl.c:3139
VOID CdLookupLastFileDirent(_In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb, _In_ PFILE_ENUM_CONTEXT FileContext)
Definition: dirsup.c:1426
BOOLEAN CdIsLegalName(_In_ PIRP_CONTEXT IrpContext, _In_ PUNICODE_STRING FileName)
Definition: namesup.c:377
_TYPE_OF_OPEN
Definition: cdprocs.h:576
_IRQL_requires_max_(APC_LEVEL) __drv_dispatchType(DRIVER_DISPATCH) __drv_dispatchType(IRP_MJ_CREATE) __drv_dispatchType(IRP_MJ_CLOSE) __drv_dispatchType(IRP_MJ_READ) __drv_dispatchType(IRP_MJ_WRITE) __drv_dispatchType(IRP_MJ_QUERY_INFORMATION) __drv_dispatchType(IRP_MJ_SET_INFORMATION) __drv_dispatchType(IRP_MJ_QUERY_VOLUME_INFORMATION) __drv_dispatchType(IRP_MJ_DIRECTORY_CONTROL) __drv_dispatchType(IRP_MJ_FILE_SYSTEM_CONTROL) __drv_dispatchType(IRP_MJ_DEVICE_CONTROL) __drv_dispatchType(IRP_MJ_LOCK_CONTROL) __drv_dispatchType(IRP_MJ_CLEANUP) __drv_dispatchType(IRP_MJ_PNP) __drv_dispatchType(IRP_MJ_SHUTDOWN) NTSTATUS NTAPI CdFsdDispatch(_In_ PDEVICE_OBJECT DeviceObject
int64_t LONGLONG
Definition: typedefs.h:66
#define _Out_opt_
Definition: no_sal2.h:339
PCCB CdCreateCcb(_In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb, _In_ ULONG Flags)
Definition: strucsup.c:1405
_Inout_ PFCB StartingFcb
Definition: cdprocs.h:1264
VOID CdGenerate8dot3Name(_In_ PIRP_CONTEXT IrpContext, _In_ PUNICODE_STRING FileName, _In_ ULONG DirentOffset, _Out_writes_bytes_to_(BYTE_COUNT_8_DOT_3, *ShortByteCount) PWCHAR ShortFileName, _Out_ PUSHORT ShortByteCount)
Definition: namesup.c:550
TYPE_OF_OPEN * PTYPE_OF_OPEN
Definition: cdprocs.h:586
return Iosb
Definition: create.c:4426
FAST_IO_UNLOCK_SINGLE CdFastUnlockSingle
Definition: cdprocs.h:1926
union _UCHAR2 * PUCHAR2
LONG CdExceptionFilter(_Inout_ PIRP_CONTEXT IrpContext, _In_ PEXCEPTION_POINTERS ExceptionPointer)
Definition: cddata.c:525
uint64_t ULONGLONG
Definition: typedefs.h:65
ULONG ForceAlignment
Definition: cdprocs.h:1688
#define IRP_MJ_FILE_SYSTEM_CONTROL
enum _TYPE_OF_ACQUIRE TYPE_OF_ACQUIRE
_In_ PFCB _In_ PDIRENT_ENUM_CONTEXT DirContext
Definition: cdprocs.h:429
Definition: bufpool.h:50
BOOLEAN CdLookupNextInitialFileDirent(_In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb, _Inout_ PFILE_ENUM_CONTEXT FileContext)
Definition: dirsup.c:1275
UCHAR ForceAlignment
Definition: cdprocs.h:1673
#define _Inout_
Definition: no_sal2.h:244
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
* PFILE_OBJECT
Definition: iotypes.h:1955
_In_ PFCB ParentFcb
Definition: cdprocs.h:741
VOID CdInitializeVcb(_In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb, _In_ __drv_aliasesMem PDEVICE_OBJECT TargetDeviceObject, _In_ __drv_aliasesMem PVPB Vpb, _In_ __drv_aliasesMem PCDROM_TOC_LARGE CdromToc, _In_ ULONG TocLength, _In_ ULONG TocTrackCount, _In_ ULONG TocDiskFlags, _In_ ULONG BlockFactor, _In_ ULONG MediaChangeCount)
Definition: strucsup.c:241
#define __drv_dispatchType(x)
Definition: driverspecs.h:249
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: ncftp.h:79
_Requires_lock_held_(_Global_critical_region_) VOID CdLookupAllocation(_In_ PIRP_CONTEXT IrpContext
VOID CdDeleteCcb(_In_ PIRP_CONTEXT IrpContext, _In_ __drv_freesMem(Pool) PCCB Ccb)
Definition: strucsup.c:1462
#define _Post_null_
Definition: no_sal2.h:461
unsigned char UCHAR
Definition: xmlstorage.h:181
char * PBOOLEAN
Definition: retypes.h:11
NTSTATUS CdCreateUserMdl(_In_ PIRP_CONTEXT IrpContext, _In_ ULONG BufferLength, _In_ BOOLEAN RaiseOnError, _In_ LOCK_OPERATION Operation)
Definition: deviosup.c:1221
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
BOOLEAN CdLookupNextPathEntry(_In_ PIRP_CONTEXT IrpContext, _Inout_ PPATH_ENUM_CONTEXT PathContext, _Inout_ PPATH_ENTRY PathEntry)
Definition: pathsup.c:207
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
union _UCHAR1 UCHAR1
NTSTATUS CdCommonDevControl(_Inout_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp)
Definition: devctrl.c:46
enum _TYPE_OF_OPEN TYPE_OF_OPEN
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
static INLINE VOID CdVerifyOrCreateDirStreamFile(_In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb)
Definition: cdprocs.h:234
#define _Pre_notnull_
Definition: no_sal2.h:496
BOOLEAN CdFindDirectory(_In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb, _In_ PCD_NAME Name, _In_ BOOLEAN IgnoreCase, _Inout_ PFILE_ENUM_CONTEXT FileContext)
Definition: dirsup.c:997
DRIVER_DISPATCH(nfs41_FsdDispatch)
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
#define _In_reads_bytes_(size)
Definition: no_sal2.h:229
FAST_IO_UNLOCK_ALL CdFastUnlockAll
Definition: cdprocs.h:1936
_Acquires_shared_lock_ Fcb BOOLEAN NTAPI CdAcquireForCache(_Inout_ PFCB Fcb, _In_ BOOLEAN Wait)
Status
Definition: gdiplustypes.h:24
VOID CdDissectName(_In_ PIRP_CONTEXT IrpContext, _Inout_ PUNICODE_STRING RemainingName, _Out_ PUNICODE_STRING FinalName)
Definition: namesup.c:301
static INLINE ULONG SectorsFromLlBytes(ULONGLONG Bytes)
Definition: cdprocs.h:1617
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
VOID CdVerifyVcb(_In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb)
Definition: verfysup.c:411
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
Definition: cdstruc.h:1466
VOID CdAddInitialAllocation(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_ ULONG StartingBlock, _In_ LONGLONG DataLength)
Definition: allocsup.c:484
#define _IRQL_restores_global_(kind, param)
Definition: no_sal2.h:654
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
* PFAST_MUTEX
Definition: extypes.h:17
FAST_IO_UNLOCK_ALL_BY_KEY CdFastUnlockAllByKey
Definition: cdprocs.h:1947
#define InterlockedIncrement
Definition: armddk.h:53
Definition: cdstruc.h:1531
enum _LOCK_OPERATION LOCK_OPERATION
unsigned short Ushort
Definition: utypes.h:44
PFCB CdGetNextFcb(_In_ PIRP_CONTEXT IrpContext, _In_ PVCB Vcb, _In_ PVOID *RestartKey)
Definition: strucsup.c:2155
unsigned short USHORT
Definition: pedump.c:61
#define _IRQL_saves_global_(kind, param)
Definition: no_sal2.h:656
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int * PULONG
Definition: retypes.h:1
BOOLEAN CdVerifyFcbOperation(_In_opt_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb)
Definition: verfysup.c:615
VOID CdCleanupIrpContext(_In_ PIRP_CONTEXT IrpContext, _In_ BOOLEAN Post)
Definition: strucsup.c:1733
#define __drv_freesMem(kind)
Definition: driverspecs.h:254
NTSTATUS CdCommonLockControl(_Inout_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp)
Definition: lockctrl.c:35
#define BYTE_COUNT_8_DOT_3
Definition: cd.h:362
NTSTATUS CdHijackIrpAndFlushDevice(_In_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp, _In_ PDEVICE_OBJECT TargetDeviceObject)
Definition: deviosup.c:4105
#define STATUS_UNEXPECTED_IO_ERROR
Definition: ntstatus.h:455
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
#define IRP_MJ_READ
Definition: rdpdr.c:46
VOID NTAPI CdNoopRelease(_In_ PVOID Fcb)
Definition: resrcsup.c:254
enum _FSRTL_COMPARISON_RESULT FSRTL_COMPARISON_RESULT
#define IRP_MJ_CLEANUP
Definition: iotypes.h:166
_In_ PVCB Vcb
Definition: cdprocs.h:227
VOID CdLookupPathEntry(_In_ PIRP_CONTEXT IrpContext, _In_ ULONG PathEntryOffset, _In_ ULONG Ordinal, _In_ BOOLEAN VerifyBounds, _Inout_ PCOMPOUND_PATH_ENTRY CompoundPathEntry)
VOID CdRemovePrefix(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb)
Definition: prefxsup.c:207
VOID CdDeleteVcb(_In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb)
Definition: strucsup.c:876
_Inout_ PFCB _In_ BOOLEAN RaiseOnError
Definition: cdprocs.h:1214
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
unsigned int ULONG
Definition: retypes.h:1
_In_ PFCB _In_ PDIRENT_ENUM_CONTEXT _Inout_ PDIRENT Dirent
Definition: cdprocs.h:429
VOID CdCompleteRequest(_Inout_opt_ PIRP_CONTEXT IrpContext, _Inout_opt_ PIRP Irp, _In_ NTSTATUS Status)
Definition: cddata.c:914
INLINE DECLSPEC_NORETURN VOID CdRaiseStatusEx(_In_ PIRP_CONTEXT IrpContext, _In_ NTSTATUS Status, _In_ BOOLEAN NormalizeStatus, _In_ ULONG Fileid, _In_ ULONG Line)
Definition: cdprocs.h:1845
_In_ FLT_SET_CONTEXT_OPERATION Operation
Definition: fltkernel.h:1468
_In_ PFCB _In_ PCD_NAME DirName
Definition: cdprocs.h:741
PVCB Vcb
Definition: cdstruc.h:939
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define SECTOR_SIZE
Definition: fs.h:22
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
USHORT NODE_TYPE_CODE
Definition: nodetype.h:22
VOID CdInitializeFcbFromFileContext(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_ PFCB ParentFcb, _In_ PFILE_ENUM_CONTEXT FileContext)
Definition: strucsup.c:1225
NTSTATUS NTAPI FsRtlNormalizeNtstatus(IN NTSTATUS NtStatusToNormalize, IN NTSTATUS NormalizedNtStatus)
Definition: filter.c:90
#define _In_range_(lb, ub)
Definition: no_sal2.h:227
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG DataLength
Definition: hidpi.h:333
_Ret_valid_ PIRP_CONTEXT CdCreateIrpContext(_In_ PIRP Irp, _In_ BOOLEAN Wait)
Definition: strucsup.c:1573
_In_ PFCB Fcb
Definition: cdprocs.h:151
IN OUT PVCB IN PDEVICE_OBJECT TargetDeviceObject
Definition: fatprocs.h:1664
BOOLEAN CdMarkDevForVerifyIfVcbMounted(_Inout_ PVCB Vcb)
Definition: verfysup.c:359
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE _In_ BOOLEAN IgnoreWait
Definition: cdprocs.h:848
#define __in
Definition: dbghelp.h:35
FILE_NAME_NODE ShortName
Definition: fatstruc.h:1114
#define DECLSPEC_NOINLINE
Definition: ntbasedef.h:231
UNICODE_STRING FileName
Definition: cdstruc.h:250
#define APC_LEVEL
Definition: env_spec_w32.h:695
FAST_IO_LOCK CdFastLock
Definition: cdprocs.h:1913
unsigned short * PUSHORT
Definition: retypes.h:2
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1664
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
_Inout_ PIRP _In_ PDEVICE_OBJECT DeviceToVerify
Definition: cdprocs.h:1417
_In_ PFCB _In_ PCD_NAME _In_ BOOLEAN _Inout_ PCOMPOUND_PATH_ENTRY CompoundPathEntry
Definition: cdprocs.h:741
VOID CdUpdateVcbFromVolDescriptor(_In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb, _In_reads_bytes_opt_(SECTOR_SIZE) PCHAR RawIsoVd)
Definition: strucsup.c:436
#define _Inout_opt_
Definition: no_sal2.h:258
VOID CdLookupDirent(_In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb, _In_ ULONG DirentOffset, _Out_ PDIRENT_ENUM_CONTEXT DirContext)
Definition: dirsup.c:125
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
_Inout_ PVCB _In_ BOOLEAN Force
Definition: cdprocs.h:1425
IN BOOLEAN Wait
Definition: fatprocs.h:1529
_Inout_ PFCB _Inout_ PUNICODE_STRING RemainingName
Definition: cdprocs.h:806
NTSTATUS CdUnlockVolumeInternal(_In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb, _In_opt_ PFILE_OBJECT FileObject)
Definition: fsctrl.c:288
union _USHORT2 * PUSHORT2