3 Copyright (c) 1989-2000 Microsoft Corporation
11 This module defines the data structures that make up the major internal
12 part of the Cdfs file system.
16 The global data structures with the CdDataRecord. It contains a pointer
17 to a File System Device object and a queue of Vcb's. There is a Vcb for
18 every currently or previously mounted volumes. We may be in the process
19 of tearing down the Vcb's which have been dismounted. The Vcb's are
20 allocated as an extension to a volume device object.
29 | +--------+ +--------+
32 | +--------+ +--------+
33 +> |Vcb | <-> |Vcb | <-> ...
38 Each Vcb contains a table of all the Fcbs for the volume indexed by
39 their FileId. Each Vcb contains a pointer to the root directory of
40 the volume. Each directory Fcb contains a queue of child Fcb's for
41 its children. There can also be detached subtrees due to open operations
42 by Id where the Fcb's are not connected to the root.
44 The following diagram shows the root structure.
47 | Vcb |---->| Fcb |-----------------------------------------------+
48 | | | Table |--------------------------------------------+ | |
49 | |--+ | |-----------------------------------------+ | | |
50 +--------+ | +--------+ | | |
52 | | | +--------------------+ | | |
53 | V +---------+ | | | |
54 | +--------+ | | | | |
55 | |RootFcb | V V | | |
56 +->| | +--------+ +--------+ | | |
57 | |-->|Child | |Child | | | |
58 +--------+ | Fcb |<-->| Fcb |<--> ... | | |
60 +--------+ +--------+ | | |
62 (Freestanding sub-tree) | | |
64 |OpenById|<-----------------------------------------+ | |
65 | Dir | +--------+ | |
66 | |--->|OpenById|<------------------------------+ |
67 +--------+ | Child | +--------+ |
68 | Dir |--->|OpenById|<-------------------+
73 Attached to each Directory Fcb is a prefix table containing the names
74 of children of this directory for which there is an Fcb. Not all Fcb's
75 will necessarily have an entry in this table.
79 | Fcb |----->| Table |--------------------+
81 +--------+ +--------+ | |
85 | +--------+ +--------+ +--------+ +--------+
86 | | Fcb | | Fcb | | Fcb | | Fcb |
87 +---------->| |<-->| |<-->| |<-->| |
89 +--------+ +--------+ +--------+ +--------+
92 Each file object open on a CDROM volume contains two context pointers. The
93 first will point back to the Fcb for the file object. The second, if present,
94 points to a Ccb (ContextControlBlock) which contains the per-handle information.
95 This includes the state of any directory enumeration.
97 +--------+ +--------+ +--------+
98 | Fcb |<------| File | | Ccb |
101 +--------+ +--------+ +--------+
103 | | +--------+ +--------+
105 | +---------| Object|--->| |
107 | +--------+ +--------+
111 +--------------| File |
118 1. A resource in the CdData synchronizes access to the Vcb queue. This
119 is used during mount/verify/dismount operations.
121 2. A resource in the Vcb is used to synchronize access to Vcb for
122 open/close operations. Typically acquired shared, it
123 is acquired exclusively to lock out these operations.
125 3. A second resource in the Vcb is used to synchronize all file operations.
126 Typically acquired shared, it is acquired exclusively to lock
127 out all file operations. Acquiring both Vcb resources will lock
130 4. A resource in the nonpaged Fcb will synchronize open/close operations
133 5. A fast mutex in the Vcb will protect access to the Fcb table and
134 the open counts in the Vcb. It is also used to modify the reference
135 counts in all Fcbs. This mutex cannot be acquired
136 exclusely and is an end resource.
138 6. A fast mutex in the Fcb will synchronize access to all Fcb fields
139 which aren't synchronized in some other way. A thread may acquire
140 mutexes for multiple Fcb's as long as it works it way toward the
141 root of the tree. This mutex can also be acquired recursively.
143 7. Normal locking order is CdData/Vcb/Fcb starting at any point in this
144 chain. The Vcb is required prior to acquiring resources for multiple
145 files. Shared ownership of the Vcb is sufficient in this case.
147 8. Normal locking order when acquiring multiple Fcb's is from some
148 starting Fcb and walking towards the root of tree. Create typically
149 walks down the tree. In this case we will attempt to acquire the
150 next node optimistically and if that fails we will reference
151 the current node in the tree, release it and acquire the next node.
152 At that point it will be safe to reacquire the parent node.
154 9. Locking order for the Fcb (via the fast mutex) will be from leaf of
155 tree back towards the root. No other resource may be acquired
156 after locking the Vcb (other than in-page reads).
158 10. Cleanup operations only lock the Vcb and Fcb long enough to change the
159 critical counts and share access fields. No reason to synchronize
160 otherwise. None of the structures can go away from beneath us
169 typedef PVOID PBCB
; //**** Bcb's are now part of the cache module
171 #define BYTE_COUNT_EMBEDDED_NAME (32)
174 #define __volatile volatile
175 #define _Unreferenced_parameter_
176 #define __field_range(a,b)
177 #define __analysis_assert(x)
181 // The CD_MCB is used to store the mapping of logical file offset to
182 // logical disk offset. NOTE - This package only deals with the
183 // logical 2048 sectors. Translating to 'raw' sectors happens in
184 // software. We will embed a single MCB_ENTRY in the Fcb since this
185 // will be the typical case.
188 typedef struct _CD_MCB
{
191 // Size and current count of the Mcb entries.
194 ULONG MaximumEntryCount
;
195 ULONG CurrentEntryCount
;
198 // Pointer to the start of the Mcb entries.
201 struct _CD_MCB_ENTRY
*McbArray
;
204 typedef CD_MCB
*PCD_MCB
;
206 typedef struct _CD_MCB_ENTRY
{
209 // Starting offset and number of bytes described by this entry.
210 // The Byte count is rounded to a logical block boundary if this is
218 // Starting offset in the file of mapping described by this dirent.
224 // Data length and block length. Data length is the length of each
225 // data block. Total length is the length of each data block and
229 LONGLONG DataBlockByteCount
;
230 LONGLONG TotalBlockByteCount
;
233 typedef CD_MCB_ENTRY
*PCD_MCB_ENTRY
;
237 // Cd name structure. The following structure is used to represent the
238 // full Cdrom name. This name can be stored in either Unicode or ANSI
242 typedef struct _CD_NAME
{
245 // String containing name without the version number.
246 // The maximum length field for filename indicates the
247 // size of the buffer allocated for the two parts of the name.
250 UNICODE_STRING FileName
;
253 // String containging the version number.
256 UNICODE_STRING VersionString
;
259 typedef CD_NAME
*PCD_NAME
;
262 // Following is the splay link structure for the prefix lookup.
263 // The names can be in either Unicode string or Ansi string format.
266 typedef struct _NAME_LINK
{
268 RTL_SPLAY_LINKS Links
;
269 UNICODE_STRING FileName
;
272 typedef NAME_LINK
*PNAME_LINK
;
276 // Prefix entry. There is one of these for each name in the prefix table.
277 // An Fcb will have one of these embedded for the long name and an optional
278 // pointer to the short name entry.
281 typedef struct _PREFIX_ENTRY
{
284 // Pointer to the Fcb for this entry.
290 // Flags field. Used to indicate if the name is in the prefix table.
296 // Exact case name match.
299 NAME_LINK ExactCaseName
;
302 // Case-insensitive name link.
305 NAME_LINK IgnoreCaseName
;
307 WCHAR FileNameBuffer
[ BYTE_COUNT_EMBEDDED_NAME
];
310 typedef PREFIX_ENTRY
*PPREFIX_ENTRY
;
312 #define PREFIX_FLAG_EXACT_CASE_IN_TREE (0x00000001)
313 #define PREFIX_FLAG_IGNORE_CASE_IN_TREE (0x00000002)
317 // The CD_DATA record is the top record in the CDROM file system in-memory
318 // data structure. This structure must be allocated from non-paged pool.
321 typedef struct _CD_DATA
{
324 // The type and size of this record (must be CDFS_NTC_DATA_HEADER)
327 _Field_range_(==, CDFS_NTC_DATA_HEADER
) NODE_TYPE_CODE NodeTypeCode
;
328 NODE_BYTE_SIZE NodeByteSize
;
331 // A pointer to the Driver object we were initialized with
334 PDRIVER_OBJECT DriverObject
;
343 // The following fields are used to allocate IRP context structures
344 // using a lookaside list, and other fixed sized structures from a
345 // small cache. We use the CdData mutex to protext these structures.
348 ULONG IrpContextDepth
;
349 ULONG IrpContextMaxDepth
;
350 SINGLE_LIST_ENTRY IrpContextList
;
353 // Filesystem device object for CDFS.
356 PDEVICE_OBJECT FileSystemDeviceObject
;
359 PDEVICE_OBJECT HddFileSystemDeviceObject
;
363 // Following are used to manage the async and delayed close queue.
365 // FspCloseActive - Indicates whether there is a thread processing the
367 // ReduceDelayedClose - Indicates that we have hit the upper threshold
368 // for the delayed close queue and need to reduce it to lower threshold.
370 // AsyncCloseQueue - Queue of IrpContext waiting for async close operation.
371 // AsyncCloseCount - Number of entries on the async close queue.
373 // DelayedCloseQueue - Queue of IrpContextLite waiting for delayed close
375 // MaxDelayedCloseCount - Trigger delay close work at this threshold.
376 // MinDelayedCloseCount - Turn off delay close work at this threshold.
377 // DelayedCloseCount - Number of entries on the delayted close queue.
379 // CloseItem - Workqueue item used to start FspClose thread.
382 LIST_ENTRY AsyncCloseQueue
;
383 ULONG AsyncCloseCount
;
384 BOOLEAN FspCloseActive
;
385 BOOLEAN ReduceDelayedClose
;
389 // The following fields describe the deferred close file objects.
392 LIST_ENTRY DelayedCloseQueue
;
393 ULONG DelayedCloseCount
;
394 ULONG MaxDelayedCloseCount
;
395 ULONG MinDelayedCloseCount
;
398 // Fast mutex used to lock the fields of this structure.
401 PVOID CdDataLockThread
;
402 FAST_MUTEX CdDataMutex
;
405 // A resource variable to control access to the global CDFS data record
408 ERESOURCE DataResource
;
411 // Cache manager call back structure, which must be passed on each call
412 // to CcInitializeCacheMap.
415 CACHE_MANAGER_CALLBACKS CacheManagerCallbacks
;
416 CACHE_MANAGER_CALLBACKS CacheManagerVolumeCallbacks
;
419 // This is the ExWorkerItem that does both kinds of deferred closes.
422 PIO_WORKITEM CloseItem
;
425 typedef CD_DATA
*PCD_DATA
;
428 #define CD_FLAGS_SHUTDOWN (0x0001)
432 // Since DVD drives allow > 100 "sessions", we need to use a larger TOC
433 // than the legacy CD definition. The maximum is theoretically 0xaa-16 (max
434 // number of open tracks in a session), but it's quite possible that some
435 // drive does not enforce this, so we'll go with 169 (track 0xaa is always the
439 #define MAXIMUM_NUMBER_TRACKS_LARGE 0xAA
441 typedef struct _CDROM_TOC_LARGE
{
447 UCHAR Length
[2]; // add two bytes for this field
455 TRACK_DATA TrackData
[ MAXIMUM_NUMBER_TRACKS_LARGE
];
457 } CDROM_TOC_LARGE
, *PCDROM_TOC_LARGE
;
459 typedef struct _CD_SECTOR_CACHE_CHUNK
{
464 } CD_SECTOR_CACHE_CHUNK
, *PCD_SECTOR_CACHE_CHUNK
;
466 #define CD_SEC_CACHE_CHUNKS 4
467 #define CD_SEC_CHUNK_BLOCKS 0x18
470 // The Vcb (Volume control block) record corresponds to every
471 // volume mounted by the file system. They are ordered in a queue off
472 // of CdData.VcbQueue.
474 // The Vcb will be in several conditions during its lifespan.
476 // NotMounted - Disk is not currently mounted (i.e. removed
477 // from system) but cleanup and close operations are
480 // MountInProgress - State of the Vcb from the time it is
481 // created until it is successfully mounted or the mount
484 // Mounted - Volume is currently in the mounted state.
486 // Invalid - User has invalidated the volume. Only legal operations
487 // are cleanup and close.
489 // DismountInProgress - We have begun the process of tearing down the
490 // Vcb. It can be deleted when all the references to it
494 typedef enum _VCB_CONDITION
{
500 VcbDismountInProgress
504 typedef struct _VCB
{
507 // The type and size of this record (must be CDFS_NTC_VCB)
510 _Field_range_(==, CDFS_NTC_VCB
) NODE_TYPE_CODE NodeTypeCode
;
511 NODE_BYTE_SIZE NodeByteSize
;
514 // Vpb for this volume.
520 // Device object for the driver below us.
523 PDEVICE_OBJECT TargetDeviceObject
;
526 // File object used to lock the volume.
529 PFILE_OBJECT VolumeLockFileObject
;
532 // Link into queue of Vcb's in the CdData structure. We will create a union with
533 // a LONGLONG to force the Vcb to be quad-aligned.
543 // State flags and condition for the Vcb.
547 VCB_CONDITION VcbCondition
;
550 // Various counts for this Vcb.
552 // VcbCleanup - Open handles left on this system.
553 // VcbReference - Number of reasons this Vcb is still present.
554 // VcbUserReference - Number of user file objects still present.
558 __volatile LONG VcbReference
; /* ReactOS Change: GCC 'pointer targets in passing argument 1 of 'InterlockedXxx' differ in signedness */
559 __volatile LONG VcbUserReference
; /* ReactOS Change: GCC 'pointer targets in passing argument 1 of 'InterlockedXxx' differ in signedness */
562 // Fcb for the Volume Dasd file, root directory and the Path Table.
565 struct _FCB
*VolumeDasdFcb
;
566 struct _FCB
*RootIndexFcb
;
567 struct _FCB
*PathTableFcb
;
570 // Location of current session and offset of volume descriptors.
574 ULONG VdSectorOffset
;
575 ULONG PrimaryVdSectorOffset
;
578 // Following is a sector from the last non-cached read of an XA file.
579 // Also the cooked offset on the disk.
583 LONGLONG XADiskOffset
;
586 // Vcb resource. This is used to synchronize open/cleanup/close operations.
589 ERESOURCE VcbResource
;
592 // File resource. This is used to synchronize all file operations except
593 // open/cleanup/close.
596 ERESOURCE FileResource
;
599 // Vcb fast mutex. This is used to synchronize the fields in the Vcb
600 // when modified when the Vcb is not held exclusively. Included here
601 // are the count fields and Fcb table.
603 // We also use this to synchronize changes to the Fcb reference field.
610 // The following is used to synchronize the dir notify package.
613 PNOTIFY_SYNC NotifySync
;
616 // The following is the head of a list of notify Irps.
619 LIST_ENTRY DirNotifyList
;
622 // Logical block size for this volume as well constant values
623 // associated with the block size.
627 ULONG BlockToSectorShift
;
628 ULONG BlockToByteShift
;
629 ULONG BlocksPerSector
;
631 ULONG BlockInverseMask
;
634 // Fcb table. Synchronized with the Vcb fast mutex.
637 RTL_GENERIC_TABLE FcbTable
;
640 // Volume TOC. Cache this information for quick lookup.
643 PCDROM_TOC_LARGE CdromToc
;
649 // Block factor to determine last session information.
655 // Media change count from device driver for bulletproof detection
659 ULONG MediaChangeCount
;
662 // For raw reads, CDFS must obey the port maximum transfer restrictions.
665 ULONG MaximumTransferRawSectors
;
666 ULONG MaximumPhysicalPages
;
669 // Preallocated VPB for swapout, so we are not forced to consider
670 // must succeed pool.
676 // Directory block cache. Read large numbers of blocks on directory
677 // reads, hoping to benefit from the fact that most mastered/pressed
678 // discs clump metadata in one place thus allowing us to crudely
679 // pre-cache and reduce seeks back to directory data during app install,
682 // Note that the purpose of this is to PRE cache unread data,
683 // not cache already read data (since Cc already provides that), thus
684 // speeding initial access to the volume.
687 PUCHAR SectorCacheBuffer
;
688 CD_SECTOR_CACHE_CHUNK SecCacheChunks
[ CD_SEC_CACHE_CHUNKS
];
689 ULONG SecCacheLRUChunkIndex
;
692 KEVENT SectorCacheEvent
;
693 ERESOURCE SectorCacheResource
;
695 #ifdef CDFS_TELEMETRY_DATA
698 // An ID that is common across the volume stack used to correlate volume events and for telemetry purposes.
699 // It may have a different value than the VolumeGuid.
702 GUID VolumeCorrelationId
;
704 #endif // CDFS_TELEMETRY_DATA
708 ULONG SecCacheMisses
;
712 #define VCB_STATE_HSG (0x00000001)
713 #define VCB_STATE_ISO (0x00000002)
714 #define VCB_STATE_JOLIET (0x00000004)
715 #define VCB_STATE_LOCKED (0x00000010)
716 #define VCB_STATE_REMOVABLE_MEDIA (0x00000020)
717 #define VCB_STATE_CDXA (0x00000040)
718 #define VCB_STATE_AUDIO_DISK (0x00000080)
719 #define VCB_STATE_NOTIFY_REMOUNT (0x00000100)
720 #define VCB_STATE_VPB_NOT_ON_DEVICE (0x00000200)
721 #define VCB_STATE_SHUTDOWN (0x00000400)
722 #define VCB_STATE_DISMOUNTED (0x00000800)
726 // The Volume Device Object is an I/O system device object with a
727 // workqueue and an VCB record appended to the end. There are multiple
728 // of these records, one for every mounted volume, and are created during
729 // a volume mount operation. The work queue is for handling an overload
730 // of work requests to the volume.
733 typedef struct _VOLUME_DEVICE_OBJECT
{
735 DEVICE_OBJECT DeviceObject
;
738 // The following field tells how many requests for this volume have
739 // either been enqueued to ExWorker threads or are currently being
740 // serviced by ExWorker threads. If the number goes above
741 // a certain threshold, put the request on the overflow queue to be
745 __volatile LONG PostedRequestCount
; /* ReactOS Change: GCC "pointer targets in passing argument 1 of 'InterlockedDecrement' differ in signedness" */
748 // The following field indicates the number of IRP's waiting
749 // to be serviced in the overflow queue.
752 ULONG OverflowQueueCount
;
755 // The following field contains the queue header of the overflow queue.
756 // The Overflow queue is a list of IRP's linked via the IRP's ListEntry
760 LIST_ENTRY OverflowQueue
;
763 // The following spinlock protects access to all the above fields.
766 KSPIN_LOCK OverflowQueueSpinLock
;
769 // This is the file system specific volume control block.
774 } VOLUME_DEVICE_OBJECT
;
775 typedef VOLUME_DEVICE_OBJECT
*PVOLUME_DEVICE_OBJECT
;
779 // The following two structures are the separate union structures for
780 // data and index Fcb's. The path table is actually the same structure
781 // as the index Fcb since it uses the first few fields.
784 typedef enum _FCB_CONDITION
{
790 typedef struct _FCB_DATA
{
792 #if (NTDDI_VERSION < NTDDI_WIN8)
794 // The following field is used by the oplock module
795 // to maintain current oplock information.
802 // The following field is used by the filelock module
803 // to maintain current byte range locking information.
804 // A file lock is allocated as needed.
810 typedef FCB_DATA
*PFCB_DATA
;
812 typedef struct _FCB_INDEX
{
815 // Internal stream file.
818 PFILE_OBJECT FileObject
;
821 // Offset of first entry in stream. This is for case where directory
822 // or path table does not begin on a sector boundary. This value is
823 // added to all offset values to determine the real offset.
829 // List of child fcbs.
835 // Ordinal number for this directory. Combine this with the path table offset
836 // in the FileId and you have a starting point in the path table.
842 // Children path table start. This is the offset in the path table
843 // for the first child of the directory. A value of zero indicates
844 // that we haven't found the first child yet. If there are no child
845 // directories we will position at a point in the path table so that
846 // subsequent searches will fail quickly.
849 ULONG ChildPathTableOffset
;
853 // Root of splay trees for exact and ignore case prefix trees.
856 PRTL_SPLAY_LINKS ExactCaseRoot
;
857 PRTL_SPLAY_LINKS IgnoreCaseRoot
;
860 typedef FCB_INDEX
*PFCB_INDEX
;
862 typedef struct _FCB_NONPAGED
{
865 // Type and size of this record must be CDFS_NTC_FCB_NONPAGED
868 _Field_range_(==, CDFS_NTC_FCB_NONPAGED
) NODE_TYPE_CODE NodeTypeCode
;
869 NODE_BYTE_SIZE NodeByteSize
;
872 // The following field contains a record of special pointers used by
873 // MM and Cache to manipluate section objects. Note that the values
874 // are set outside of the file system. However the file system on an
875 // open/create will set the file object's SectionObject field to
876 // point to this field
879 SECTION_OBJECT_POINTERS SegmentObject
;
882 // This is the resource structure for this Fcb.
885 ERESOURCE FcbResource
;
888 // This is the FastMutex for this Fcb.
894 // This is the mutex that is inserted into the FCB_ADVANCED_HEADER
898 FAST_MUTEX AdvancedFcbHeaderMutex
;
901 typedef FCB_NONPAGED
*PFCB_NONPAGED
;
904 // The Fcb/Dcb record corresponds to every open file and directory, and to
905 // every directory on an opened path.
908 typedef struct _FCB
{
911 // The following field is used for fast I/O. It contains the node
912 // type code and size, indicates if fast I/O is possible, contains
913 // allocation, file, and valid data size, a resource, and call back
914 // pointers for FastIoRead and FastMdlRead.
917 // Node type codes for the Fcb must be one of the following.
919 // CDFS_NTC_FCB_PATH_TABLE
920 // CDFS_NTC_FCB_INDEX
925 // Common Fsrtl Header. The named header is for the fieldoff.c output. We
926 // use the unnamed header internally.
931 FSRTL_ADVANCED_FCB_HEADER Header
;
932 FSRTL_ADVANCED_FCB_HEADER
;
942 // Parent Fcb for this Fcb. This may be NULL if this file was opened
943 // by ID, also for the root Fcb.
946 struct _FCB
*ParentFcb
;
949 // Links to the queue of Fcb's in the parent.
955 // FileId for this file.
961 // Counts on this Fcb. Cleanup count represents the number of open handles
962 // on this Fcb. Reference count represents the number of reasons this Fcb
963 // is still present. It includes file objects, children Fcb and anyone
964 // who wants to prevent this Fcb from going away. Cleanup count is synchronized
965 // with the FcbResource. The reference count is synchronized with the
970 __volatile LONG FcbReference
; /* ReactOS Change: GCC 'pointer targets in passing argument 1 of 'InterlockedXxx' differ in signedness */
971 ULONG FcbUserReference
;
974 // State flags for this Fcb.
980 // NT style attributes for the Fcb.
983 ULONG FileAttributes
;
986 // CDXA attributes for this file.
992 // File number from the system use area.
998 // This is the thread and count for the thread which has locked this
1002 PVOID FcbLockThread
;
1006 // Pointer to the Fcb non-paged structures.
1009 PFCB_NONPAGED FcbNonpaged
;
1012 // Share access structure.
1015 SHARE_ACCESS ShareAccess
;
1018 // Mcb for the on disk mapping and a single map entry.
1021 CD_MCB_ENTRY McbEntry
;
1025 // Embed the prefix entry for the longname. Store an optional pointer
1026 // to a prefix structure for the short name.
1029 PPREFIX_ENTRY ShortNamePrefix
;
1030 PREFIX_ENTRY FileNamePrefix
;
1033 // Time stamp for this file.
1036 LONGLONG CreationTime
;
1048 #define FCB_STATE_INITIALIZED (0x00000001)
1049 #define FCB_STATE_IN_FCB_TABLE (0x00000002)
1050 #define FCB_STATE_MODE2FORM2_FILE (0x00000004)
1051 #define FCB_STATE_MODE2_FILE (0x00000008)
1052 #define FCB_STATE_DA_FILE (0x00000010)
1055 // These file types are read as raw 2352 byte sectors
1058 #define FCB_STATE_RAWSECTOR_MASK ( FCB_STATE_MODE2FORM2_FILE | \
1059 FCB_STATE_MODE2_FILE | \
1062 #define SIZEOF_FCB_DATA \
1063 (FIELD_OFFSET( FCB, FcbType ) + sizeof( FCB_DATA ))
1065 #define SIZEOF_FCB_INDEX \
1066 (FIELD_OFFSET( FCB, FcbType ) + sizeof( FCB_INDEX ))
1070 // The Ccb record is allocated for every file object
1073 typedef struct _CCB
{
1076 // Type and size of this record (must be CDFS_NTC_CCB)
1079 _Field_range_(==, CDFS_NTC_CCB
) NODE_TYPE_CODE NodeTypeCode
;
1080 NODE_BYTE_SIZE NodeByteSize
;
1083 // Flags. Indicates flags to apply for the current open.
1089 // Fcb for the file being opened.
1095 // We store state information in the Ccb for a directory
1096 // enumeration on this handle.
1100 // Offset in the directory stream to base the next enumeration.
1103 ULONG CurrentDirentOffset
;
1104 CD_NAME SearchExpression
;
1109 #define CCB_FLAG_OPEN_BY_ID (0x00000001)
1110 #define CCB_FLAG_OPEN_RELATIVE_BY_ID (0x00000002)
1111 #define CCB_FLAG_IGNORE_CASE (0x00000004)
1112 #define CCB_FLAG_OPEN_WITH_VERSION (0x00000008)
1113 #define CCB_FLAG_DISMOUNT_ON_CLOSE (0x00000010)
1114 #define CCB_FLAG_ALLOW_EXTENDED_DASD_IO (0x00000020)
1117 // Following flags refer to index enumeration.
1120 #define CCB_FLAG_ENUM_NAME_EXP_HAS_WILD (0x00010000)
1121 #define CCB_FLAG_ENUM_VERSION_EXP_HAS_WILD (0x00020000)
1122 #define CCB_FLAG_ENUM_MATCH_ALL (0x00040000)
1123 #define CCB_FLAG_ENUM_VERSION_MATCH_ALL (0x00080000)
1124 #define CCB_FLAG_ENUM_RETURN_NEXT (0x00100000)
1125 #define CCB_FLAG_ENUM_INITIALIZED (0x00200000)
1126 #define CCB_FLAG_ENUM_NOMATCH_CONSTANT_ENTRY (0x00400000)
1130 // The Irp Context record is allocated for every orginating Irp. It is
1131 // created by the Fsd dispatch routines, and deallocated by the CdComplete
1135 typedef struct _IRP_CONTEXT
{
1138 // Type and size of this record (must be CDFS_NTC_IRP_CONTEXT)
1141 _Field_range_(==, CDFS_NTC_IRP_CONTEXT
) NODE_TYPE_CODE NodeTypeCode
;
1142 NODE_BYTE_SIZE NodeByteSize
;
1145 // Originating Irp for the request.
1151 // Vcb for this operation. When this is NULL it means we were called
1152 // with our filesystem device object instead of a volume device object.
1153 // (Mount will fill this in once the Vcb is created)
1159 // Exception encountered during the request. Any error raised explicitly by
1160 // the file system will be stored here. Any other error raised by the system
1161 // is stored here after normalizing it.
1164 NTSTATUS ExceptionStatus
;
1165 ULONG RaisedAtLineFile
;
1168 // Flags for this request.
1174 // Real device object. This represents the physical device closest to the media.
1177 PDEVICE_OBJECT RealDevice
;
1180 // Io context for a read request.
1181 // Address of Fcb for teardown oplock in create case.
1186 struct _CD_IO_CONTEXT
*IoContext
;
1191 // Top level irp context for this thread.
1194 struct _IRP_CONTEXT
*TopLevel
;
1197 // Major and minor function codes.
1200 UCHAR MajorFunction
;
1201 UCHAR MinorFunction
;
1204 // Pointer to the top-level context if this IrpContext is responsible
1205 // for cleaning it up.
1208 struct _THREAD_CONTEXT
*ThreadContext
;
1211 // This structure is used for posting to the Ex worker threads.
1214 WORK_QUEUE_ITEM WorkQueueItem
;
1217 typedef IRP_CONTEXT
*PIRP_CONTEXT
;
1219 #define IRP_CONTEXT_FLAG_ON_STACK (0x00000001)
1220 #define IRP_CONTEXT_FLAG_MORE_PROCESSING (0x00000002)
1221 #define IRP_CONTEXT_FLAG_WAIT (0x00000004)
1222 #define IRP_CONTEXT_FLAG_FORCE_POST (0x00000008)
1223 #define IRP_CONTEXT_FLAG_TOP_LEVEL (0x00000010)
1224 #define IRP_CONTEXT_FLAG_TOP_LEVEL_CDFS (0x00000020)
1225 #define IRP_CONTEXT_FLAG_IN_FSP (0x00000040)
1226 #define IRP_CONTEXT_FLAG_IN_TEARDOWN (0x00000080)
1227 #define IRP_CONTEXT_FLAG_ALLOC_IO (0x00000100)
1228 #define IRP_CONTEXT_FLAG_DISABLE_POPUPS (0x00000200)
1229 #define IRP_CONTEXT_FLAG_FORCE_VERIFY (0x00000400)
1232 // Flags used for create.
1235 #define IRP_CONTEXT_FLAG_FULL_NAME (0x10000000)
1236 #define IRP_CONTEXT_FLAG_TRAIL_BACKSLASH (0x20000000)
1239 // The following flags need to be cleared when a request is posted.
1242 #define IRP_CONTEXT_FLAGS_CLEAR_ON_POST ( \
1243 IRP_CONTEXT_FLAG_MORE_PROCESSING | \
1244 IRP_CONTEXT_FLAG_WAIT | \
1245 IRP_CONTEXT_FLAG_FORCE_POST | \
1246 IRP_CONTEXT_FLAG_TOP_LEVEL | \
1247 IRP_CONTEXT_FLAG_TOP_LEVEL_CDFS | \
1248 IRP_CONTEXT_FLAG_IN_FSP | \
1249 IRP_CONTEXT_FLAG_IN_TEARDOWN | \
1250 IRP_CONTEXT_FLAG_DISABLE_POPUPS \
1254 // The following flags need to be cleared when a request is retried.
1257 #define IRP_CONTEXT_FLAGS_CLEAR_ON_RETRY ( \
1258 IRP_CONTEXT_FLAG_MORE_PROCESSING | \
1259 IRP_CONTEXT_FLAG_IN_TEARDOWN | \
1260 IRP_CONTEXT_FLAG_DISABLE_POPUPS \
1264 // The following flags are set each time through the Fsp loop.
1267 #define IRP_CONTEXT_FSP_FLAGS ( \
1268 IRP_CONTEXT_FLAG_WAIT | \
1269 IRP_CONTEXT_FLAG_TOP_LEVEL | \
1270 IRP_CONTEXT_FLAG_TOP_LEVEL_CDFS | \
1271 IRP_CONTEXT_FLAG_IN_FSP \
1276 // Following structure is used to queue a request to the delayed close queue.
1277 // This structure should be the minimum block allocation size.
1280 typedef struct _IRP_CONTEXT_LITE
{
1283 // Type and size of this record (must be CDFS_NTC_IRP_CONTEXT_LITE)
1286 _Field_range_(==, CDFS_NTC_IRP_CONTEXT_LITE
) NODE_TYPE_CODE NodeTypeCode
;
1287 NODE_BYTE_SIZE NodeByteSize
;
1290 // Fcb for the file object being closed.
1296 // List entry to attach to delayed close queue.
1299 LIST_ENTRY DelayedCloseLinks
;
1302 // User reference count for the file object being closed.
1305 ULONG UserReference
;
1308 // Real device object. This represents the physical device closest to the media.
1311 PDEVICE_OBJECT RealDevice
;
1314 typedef IRP_CONTEXT_LITE
*PIRP_CONTEXT_LITE
;
1318 // Context structure for asynchronous I/O calls. Most of these fields
1319 // are actually only required for the ReadMultiple routines, but
1320 // the caller must allocate one as a local variable anyway before knowing
1321 // whether there are multiple requests are not. Therefore, a single
1322 // structure is used for simplicity.
1325 typedef struct _CD_IO_CONTEXT
{
1328 // These two fields are used for multiple run Io
1331 __volatile LONG IrpCount
;
1333 __volatile NTSTATUS Status
;
1334 BOOLEAN AllocatedContext
;
1339 // This element handles the asynchronous non-cached Io
1344 PERESOURCE Resource
;
1345 ERESOURCE_THREAD ResourceThreadId
;
1346 ULONG RequestedByteCount
;
1350 // and this element handles the synchronous non-cached Io.
1357 typedef CD_IO_CONTEXT
*PCD_IO_CONTEXT
;
1361 // Following structure is used to track the top level request. Each Cdfs
1362 // Fsd and Fsp entry point will examine the top level irp location in the
1363 // thread local storage to determine if this request is top level and/or
1364 // top level Cdfs. The top level Cdfs request will remember the previous
1365 // value and update that location with a stack location. This location
1366 // can be accessed by recursive Cdfs entry points.
1369 typedef struct _THREAD_CONTEXT
{
1372 // CDFS signature. Used to confirm structure on stack is valid.
1378 // Previous value in top-level thread location. We restore this
1382 PIRP SavedTopLevelIrp
;
1385 // Top level Cdfs IrpContext. Initial Cdfs entry point on stack
1386 // will store the IrpContext for the request in this stack location.
1389 PIRP_CONTEXT TopLevelIrpContext
;
1392 typedef THREAD_CONTEXT
*PTHREAD_CONTEXT
;
1396 // The following structure is used for enumerating the entries in the
1397 // path table. We will always map this two sectors at a time so we don't
1398 // have to worry about entries which span sectors. We move through
1399 // one sector at a time though. We will unpin and remap after
1400 // crossing a sector boundary.
1402 // The only special case is where we span a cache view. In that case
1403 // we will allocate a buffer and read both pieces into it.
1405 // This strategy takes advantage of the CC enhancement which allows
1406 // overlapping ranges.
1409 typedef struct _PATH_ENUM_CONTEXT
{
1412 // Pointer to the current sector and the offset of this sector to
1413 // the beginning of the path table. The Data pointer may be
1414 // a pool block in the case where we cross a cache view
1415 // boundary. Also the length of the data for this block.
1423 // Bcb for the sector. (We may actually have pinned two sectors)
1424 // This will be NULL for the case where we needed to allocate a
1425 // buffer in the case where we span a cache view.
1431 // Offset to current entry within the current data block.
1437 // Did we allocate the buffer for the entry.
1440 BOOLEAN AllocatedData
;
1443 // End of Path Table. This tells us whether the current data
1444 // block includes the end of the path table. This is the
1445 // only block where we need to do a careful check about whether
1446 // the path table entry fits into the buffer.
1448 // Also once we have reached the end of the path table we don't
1449 // need to remap the data as we move into the final sector.
1450 // We always look at the last two sectors together.
1453 BOOLEAN LastDataBlock
;
1455 } PATH_ENUM_CONTEXT
;
1456 typedef PATH_ENUM_CONTEXT
*PPATH_ENUM_CONTEXT
;
1458 #define VACB_MAPPING_MASK (VACB_MAPPING_GRANULARITY - 1)
1459 #define LAST_VACB_SECTOR_OFFSET (VACB_MAPPING_GRANULARITY - SECTOR_SIZE)
1463 // Path Entry. This is our representation of the on disk data.
1466 typedef struct _PATH_ENTRY
{
1469 // Directory number and offset. This is the ordinal and the offset from
1470 // the beginning of the path table stream for this entry.
1475 ULONG PathTableOffset
;
1478 // Logical block Offset on the disk for this entry. We already bias
1479 // this by any Xar blocks.
1485 // Length of on-disk path table entry.
1488 ULONG PathEntryLength
;
1494 ULONG ParentOrdinal
;
1497 // DirName length and Id. Typically the pointer here points to the raw on-disk
1498 // bytes. We will point to a fixed self entry if this is the root directory.
1505 // Following are the flags used to cleanup this structure.
1511 // The following is the filename string and version number strings. We embed a buffer
1512 // large enough to hold two 8.3 names. One for exact case and one for case insensitive.
1516 CD_NAME CdCaseDirName
;
1518 WCHAR NameBuffer
[BYTE_COUNT_EMBEDDED_NAME
/ sizeof( WCHAR
) * 2];
1521 typedef PATH_ENTRY
*PPATH_ENTRY
;
1523 #define PATH_ENTRY_FLAG_ALLOC_BUFFER (0x00000001)
1527 // Compound path entry. This structure combines the on-disk entries
1528 // with the in-memory structures.
1531 typedef struct _COMPOUND_PATH_ENTRY
{
1533 PATH_ENUM_CONTEXT PathContext
;
1534 PATH_ENTRY PathEntry
;
1536 } COMPOUND_PATH_ENTRY
;
1537 typedef COMPOUND_PATH_ENTRY
*PCOMPOUND_PATH_ENTRY
;
1541 // The following is used for enumerating through a directory via the
1545 typedef struct _DIRENT_ENUM_CONTEXT
{
1548 // Pointer the current sector and the offset of this sector within
1549 // the directory file. Also the data length of this pinned block.
1557 // Bcb for the sector.
1563 // Offset to the current dirent within this sector.
1569 // Length to next dirent. A zero indicates to move to the next sector.
1572 ULONG NextDirentOffset
;
1574 } DIRENT_ENUM_CONTEXT
;
1575 typedef DIRENT_ENUM_CONTEXT
*PDIRENT_ENUM_CONTEXT
;
1579 // Following structure is used to smooth out the differences in the HSG, ISO
1580 // and Joliett directory entries.
1583 typedef struct _DIRENT
{
1586 // Offset in the Directory of this entry. Note this includes
1587 // any bytes added to the beginning of the directory to pad
1588 // down to a sector boundary.
1596 // Starting offset on the disk including any Xar blocks.
1599 ULONG StartingOffset
;
1602 // DataLength of the data. If not the last block then this should
1603 // be an integral number of logical blocks.
1609 // The following field is the time stamp out of the directory entry.
1610 // Use a pointer into the dirent for this.
1616 // The following field is the dirent file flags field.
1622 // Following field is a Cdfs flag field used to clean up this structure.
1628 // The following fields indicate the file unit size and interleave gap
1629 // for interleaved files. Each of these are in logical blocks.
1633 ULONG InterleaveGapSize
;
1636 // System use offset. Zero value indicates no system use area.
1639 ULONG SystemUseOffset
;
1642 // CDXA attributes and file number for this file.
1645 USHORT XAAttributes
;
1649 // Filename length and ID. We copy the length (in bytes) and keep
1650 // a pointer to the start of the name.
1657 // The following are the filenames stored by name and version numbers.
1658 // The fixed buffer here can hold two Unicode 8.3 names. This allows
1659 // us to upcase the name into a fixed buffer.
1663 CD_NAME CdCaseFileName
;
1666 // Data stream type. Indicates if this is audio, XA mode2 form2 or cooked sectors.
1669 XA_EXTENT_TYPE ExtentType
;
1671 WCHAR NameBuffer
[BYTE_COUNT_EMBEDDED_NAME
/ sizeof( WCHAR
) * 2];
1674 typedef DIRENT
*PDIRENT
;
1676 #define DIRENT_FLAG_ALLOC_BUFFER (0x01)
1677 #define DIRENT_FLAG_CONSTANT_ENTRY (0x02)
1679 #define DIRENT_FLAG_NOT_PERSISTENT (0)
1683 // Following structure combines the on-disk information with the normalized
1687 typedef struct _COMPOUND_DIRENT
{
1689 DIRENT_ENUM_CONTEXT DirContext
;
1693 typedef COMPOUND_DIRENT
*PCOMPOUND_DIRENT
;
1697 // The following structure is used to enumerate the files in a directory.
1698 // It contains three DirContext/Dirent pairs and then self pointers to
1699 // know which of these is begin used how.
1702 typedef struct _FILE_ENUM_CONTEXT
{
1705 // Pointers to the current compound dirents below.
1707 // PriorDirent - Initial dirent for the last file encountered.
1708 // InitialDirent - Initial dirent for the current file.
1709 // CurrentDirent - Second or later dirent for the current file.
1712 PCOMPOUND_DIRENT PriorDirent
;
1713 PCOMPOUND_DIRENT InitialDirent
;
1714 PCOMPOUND_DIRENT CurrentDirent
;
1717 // Flags indicating the state of the search.
1723 // This is an accumulation of the file sizes of the different extents
1724 // of a single file.
1730 // Short name for this file.
1734 WCHAR ShortNameBuffer
[ BYTE_COUNT_8_DOT_3
/ sizeof( WCHAR
) ];
1737 // Array of compound dirents.
1740 COMPOUND_DIRENT Dirents
[3];
1742 } FILE_ENUM_CONTEXT
;
1743 typedef FILE_ENUM_CONTEXT
*PFILE_ENUM_CONTEXT
;
1745 #define FILE_CONTEXT_MULTIPLE_DIRENTS (0x00000001)
1749 // RIFF header. Prepended to the data of a file containing XA sectors.
1750 // This is a hard-coded structure except that we bias the 'ChunkSize' and
1751 // 'RawSectors' fields with the file size. We also copy the attributes flag
1752 // from the system use area in the dirent. We always initialize this
1753 // structure by copying the XAFileHeader.
1756 typedef struct _RIFF_HEADER
{
1760 ULONG SignatureCDXA
;
1768 ULONG SignatureData
;
1772 typedef RIFF_HEADER
*PRIFF_HEADER
;
1775 // Audio play header for CDDA tracks.
1778 typedef struct _AUDIO_PLAY_HEADER
{
1782 ULONG SignatureCDDA
;
1788 ULONG StartingSector
;
1790 UCHAR TrackAddress
[4];
1791 UCHAR TrackLength
[4];
1793 } AUDIO_PLAY_HEADER
;
1794 typedef AUDIO_PLAY_HEADER
*PAUDIO_PLAY_HEADER
;
1798 // Some macros for supporting the use of a Generic Table
1799 // containing all the FCB/DCBs and indexed by their FileId.
1803 // The HighPart contains the path table offset of this directory in the
1806 // The LowPart contains zero except for the upper bit which is
1807 // set to indicate that this is a directory.
1811 // The HighPart contains the path table offset of the parent directory
1812 // in the path table.
1814 // The LowPart contains the byte offset of the dirent in the parent
1817 // A directory is always entered into the Fcb Table as if it's
1818 // dirent offset was zero. This enables any child to look in the FcbTable
1819 // for it's parent by searching with the same HighPart but with zero
1820 // as the value for LowPart.
1822 // The Id field is a LARGE_INTEGER where the High and Low parts can be
1823 // accessed separately.
1825 // The following macros are used to access the Fid fields.
1827 // CdQueryFidDirentOffset - Accesses the Dirent offset field
1828 // CdQueryFidPathTableNumber - Accesses the PathTable offset field
1829 // CdSetFidDirentOffset - Sets the Dirent offset field
1830 // CdSetFidPathTableNumber - Sets the PathTable ordinal field
1831 // CdFidIsDirectory - Queries if directory bit is set
1832 // CdFidSetDirectory - Sets directory bit
1835 #define FID_DIR_MASK 0x80000000 // high order bit means directory.
1837 #define CdQueryFidDirentOffset(I) ((I).LowPart & ~FID_DIR_MASK)
1838 #define CdQueryFidPathTableOffset(I) ((I).HighPart)
1839 #define CdSetFidDirentOffset(I,D) ((I).LowPart = D)
1840 #define CdSetFidPathTableOffset(I,P) ((I).HighPart = P)
1841 #define CdFidIsDirectory(I) FlagOn( (I).LowPart, FID_DIR_MASK )
1842 #define CdFidSetDirectory(I) SetFlag( (I).LowPart, FID_DIR_MASK )
1844 #define CdSetFidFromParentAndDirent(I,F,D) { \
1845 CdSetFidPathTableOffset( (I), CdQueryFidPathTableOffset( (F)->FileId )); \
1846 CdSetFidDirentOffset( (I), (D)->DirentOffset ); \
1847 if (FlagOn( (D)->DirentFlags, CD_ATTRIBUTE_DIRECTORY )) { \
1848 CdFidSetDirectory((I)); \
1852 #ifdef CDFS_TELEMETRY_DATA
1853 // ============================================================================
1854 // ============================================================================
1858 // ============================================================================
1859 // ============================================================================
1861 typedef struct _CDFS_TELEMETRY_DATA_CONTEXT
{
1864 // Number of times there was not enough stack space to generate telemetry
1867 volatile LONG MissedTelemetryPoints
;
1870 // System Time of the last periodic telemtry event. System Time
1871 // is according to KeQuerySystemTime()
1874 LARGE_INTEGER LastPeriodicTelemetrySystemTime
;
1877 // TickCount of the last periodic telemtry event. TickCount is
1878 // according to KeQueryTickCount()
1881 LARGE_INTEGER LastPeriodicTelemetryTickCount
;
1884 // Hint for Worker thread whether to generate
1885 // periodic telemetry or not
1888 BOOLEAN GeneratePeriodicTelemetry
;
1891 // Guid for ID parity with other file systems telemetry.
1900 // For DBG builds we want a machanism to change the frequency of
1904 LONGLONG PeriodicInterval
;
1909 // File system statistics at time of last period telemetry event
1912 FILESYSTEM_STATISTICS CommonStats
;
1914 } CDFS_TELEMETRY_DATA_CONTEXT
, *PCDFS_TELEMETRY_DATA_CONTEXT
;
1916 #endif // CDFS_TELEMETRY_DATA