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 exclusively 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)
175 // The CD_MCB is used to store the mapping of logical file offset to
176 // logical disk offset. NOTE - This package only deals with the
177 // logical 2048 sectors. Translating to 'raw' sectors happens in
178 // software. We will embed a single MCB_ENTRY in the Fcb since this
179 // will be the typical case.
182 typedef struct _CD_MCB
{
185 // Size and current count of the Mcb entries.
188 ULONG MaximumEntryCount
;
189 ULONG CurrentEntryCount
;
192 // Pointer to the start of the Mcb entries.
195 struct _CD_MCB_ENTRY
*McbArray
;
198 typedef CD_MCB
*PCD_MCB
;
200 typedef struct _CD_MCB_ENTRY
{
203 // Starting offset and number of bytes described by this entry.
204 // The Byte count is rounded to a logical block boundary if this is
212 // Starting offset in the file of mapping described by this dirent.
218 // Data length and block length. Data length is the length of each
219 // data block. Total length is the length of each data block and
223 LONGLONG DataBlockByteCount
;
224 LONGLONG TotalBlockByteCount
;
227 typedef CD_MCB_ENTRY
*PCD_MCB_ENTRY
;
231 // Cd name structure. The following structure is used to represent the
232 // full Cdrom name. This name can be stored in either Unicode or ANSI
236 typedef struct _CD_NAME
{
239 // String containing name without the version number.
240 // The maximum length field for filename indicates the
241 // size of the buffer allocated for the two parts of the name.
244 UNICODE_STRING FileName
;
247 // String containing the version number.
250 UNICODE_STRING VersionString
;
253 typedef CD_NAME
*PCD_NAME
;
256 // Following is the splay link structure for the prefix lookup.
257 // The names can be in either Unicode string or Ansi string format.
260 typedef struct _NAME_LINK
{
262 RTL_SPLAY_LINKS Links
;
263 UNICODE_STRING FileName
;
266 typedef NAME_LINK
*PNAME_LINK
;
270 // Prefix entry. There is one of these for each name in the prefix table.
271 // An Fcb will have one of these embedded for the long name and an optional
272 // pointer to the short name entry.
275 typedef struct _PREFIX_ENTRY
{
278 // Pointer to the Fcb for this entry.
284 // Flags field. Used to indicate if the name is in the prefix table.
290 // Exact case name match.
293 NAME_LINK ExactCaseName
;
296 // Case-insensitive name link.
299 NAME_LINK IgnoreCaseName
;
301 WCHAR FileNameBuffer
[ BYTE_COUNT_EMBEDDED_NAME
];
304 typedef PREFIX_ENTRY
*PPREFIX_ENTRY
;
306 #define PREFIX_FLAG_EXACT_CASE_IN_TREE (0x00000001)
307 #define PREFIX_FLAG_IGNORE_CASE_IN_TREE (0x00000002)
311 // The CD_DATA record is the top record in the CDROM file system in-memory
312 // data structure. This structure must be allocated from non-paged pool.
315 typedef struct _CD_DATA
{
318 // The type and size of this record (must be CDFS_NTC_DATA_HEADER)
321 NODE_TYPE_CODE NodeTypeCode
;
322 NODE_BYTE_SIZE NodeByteSize
;
325 // A pointer to the Driver object we were initialized with
328 PDRIVER_OBJECT DriverObject
;
337 // The following fields are used to allocate IRP context structures
338 // using a lookaside list, and other fixed sized structures from a
339 // small cache. We use the CdData mutex to protext these structures.
342 ULONG IrpContextDepth
;
343 ULONG IrpContextMaxDepth
;
344 SINGLE_LIST_ENTRY IrpContextList
;
347 // Filesystem device object for CDFS.
350 PDEVICE_OBJECT FileSystemDeviceObject
;
353 PDEVICE_OBJECT HddFileSystemDeviceObject
;
357 // Following are used to manage the async and delayed close queue.
359 // FspCloseActive - Indicates whether there is a thread processing the
361 // ReduceDelayedClose - Indicates that we have hit the upper threshold
362 // for the delayed close queue and need to reduce it to lower threshold.
364 // AsyncCloseQueue - Queue of IrpContext waiting for async close operation.
365 // AsyncCloseCount - Number of entries on the async close queue.
367 // DelayedCloseQueue - Queue of IrpContextLite waiting for delayed close
369 // MaxDelayedCloseCount - Trigger delay close work at this threshold.
370 // MinDelayedCloseCount - Turn off delay close work at this threshold.
371 // DelayedCloseCount - Number of entries on the delayed close queue.
373 // CloseItem - Workqueue item used to start FspClose thread.
376 LIST_ENTRY AsyncCloseQueue
;
377 ULONG AsyncCloseCount
;
378 BOOLEAN FspCloseActive
;
379 BOOLEAN ReduceDelayedClose
;
383 // The following fields describe the deferred close file objects.
386 LIST_ENTRY DelayedCloseQueue
;
387 ULONG DelayedCloseCount
;
388 ULONG MaxDelayedCloseCount
;
389 ULONG MinDelayedCloseCount
;
392 // Fast mutex used to lock the fields of this structure.
395 PVOID CdDataLockThread
;
396 FAST_MUTEX CdDataMutex
;
399 // A resource variable to control access to the global CDFS data record
402 ERESOURCE DataResource
;
405 // Cache manager call back structure, which must be passed on each call
406 // to CcInitializeCacheMap.
409 CACHE_MANAGER_CALLBACKS CacheManagerCallbacks
;
410 CACHE_MANAGER_CALLBACKS CacheManagerVolumeCallbacks
;
413 // This is the ExWorkerItem that does both kinds of deferred closes.
416 PIO_WORKITEM CloseItem
;
419 typedef CD_DATA
*PCD_DATA
;
423 // The Vcb (Volume control block) record corresponds to every
424 // volume mounted by the file system. They are ordered in a queue off
425 // of CdData.VcbQueue.
427 // The Vcb will be in several conditions during its lifespan.
429 // NotMounted - Disk is not currently mounted (i.e. removed
430 // from system) but cleanup and close operations are
433 // MountInProgress - State of the Vcb from the time it is
434 // created until it is successfully mounted or the mount
437 // Mounted - Volume is currently in the mounted state.
439 // Invalid - User has invalidated the volume. Only legal operations
440 // are cleanup and close.
442 // DismountInProgress - We have begun the process of tearing down the
443 // Vcb. It can be deleted when all the references to it
447 typedef enum _VCB_CONDITION
{
453 VcbDismountInProgress
457 typedef struct _VCB
{
460 // The type and size of this record (must be CDFS_NTC_VCB)
463 NODE_TYPE_CODE NodeTypeCode
;
464 NODE_BYTE_SIZE NodeByteSize
;
467 // Vpb for this volume.
473 // Device object for the driver below us.
476 PDEVICE_OBJECT TargetDeviceObject
;
479 // File object used to lock the volume.
482 PFILE_OBJECT VolumeLockFileObject
;
485 // Link into queue of Vcb's in the CdData structure. We will create a union with
486 // a LONGLONG to force the Vcb to be quad-aligned.
496 // State flags and condition for the Vcb.
500 VCB_CONDITION VcbCondition
;
503 // Various counts for this Vcb.
505 // VcbCleanup - Open handles left on this system.
506 // VcbReference - Number of reasons this Vcb is still present.
507 // VcbUserReference - Number of user file objects still present.
511 LONG VcbReference
; /* ReactOS Change: GCC 'pointer targets in passing argument 1 of 'InterlockedXxx' differ in signedness */
512 LONG VcbUserReference
; /* ReactOS Change: GCC 'pointer targets in passing argument 1 of 'InterlockedXxx' differ in signedness */
515 // Fcb for the Volume Dasd file, root directory and the Path Table.
518 struct _FCB
*VolumeDasdFcb
;
519 struct _FCB
*RootIndexFcb
;
520 struct _FCB
*PathTableFcb
;
523 // Location of current session and offset of volume descriptors.
527 ULONG VdSectorOffset
;
528 ULONG PrimaryVdSectorOffset
;
531 // Following is a sector from the last non-cached read of an XA file.
532 // Also the cooked offset on the disk.
536 LONGLONG XADiskOffset
;
539 // Vcb resource. This is used to synchronize open/cleanup/close operations.
542 ERESOURCE VcbResource
;
545 // File resource. This is used to synchronize all file operations except
546 // open/cleanup/close.
549 ERESOURCE FileResource
;
552 // Vcb fast mutex. This is used to synchronize the fields in the Vcb
553 // when modified when the Vcb is not held exclusively. Included here
554 // are the count fields and Fcb table.
556 // We also use this to synchronize changes to the Fcb reference field.
563 // The following is used to synchronize the dir notify package.
566 PNOTIFY_SYNC NotifySync
;
569 // The following is the head of a list of notify Irps.
572 LIST_ENTRY DirNotifyList
;
575 // Logical block size for this volume as well constant values
576 // associated with the block size.
580 ULONG BlockToSectorShift
;
581 ULONG BlockToByteShift
;
582 ULONG BlocksPerSector
;
584 ULONG BlockInverseMask
;
587 // Fcb table. Synchronized with the Vcb fast mutex.
590 RTL_GENERIC_TABLE FcbTable
;
593 // Volume TOC. Cache this information for quick lookup.
602 // Block factor to determine last session information.
608 // Media change count from device driver for bulletproof detection
612 ULONG MediaChangeCount
;
615 // For raw reads, CDFS must obey the port maximum transfer restrictions.
618 ULONG MaximumTransferRawSectors
;
619 ULONG MaximumPhysicalPages
;
622 // Preallocated VPB for swapout, so we are not forced to consider
623 // must succeed pool.
631 #define VCB_STATE_HSG (0x00000001)
632 #define VCB_STATE_ISO (0x00000002)
633 #define VCB_STATE_JOLIET (0x00000004)
634 #define VCB_STATE_LOCKED (0x00000010)
635 #define VCB_STATE_REMOVABLE_MEDIA (0x00000020)
636 #define VCB_STATE_CDXA (0x00000040)
637 #define VCB_STATE_AUDIO_DISK (0x00000080)
638 #define VCB_STATE_NOTIFY_REMOUNT (0x00000100)
639 #define VCB_STATE_VPB_NOT_ON_DEVICE (0x00000200)
643 // The Volume Device Object is an I/O system device object with a
644 // workqueue and an VCB record appended to the end. There are multiple
645 // of these records, one for every mounted volume, and are created during
646 // a volume mount operation. The work queue is for handling an overload
647 // of work requests to the volume.
650 typedef struct _VOLUME_DEVICE_OBJECT
{
652 DEVICE_OBJECT DeviceObject
;
655 // The following field tells how many requests for this volume have
656 // either been enqueued to ExWorker threads or are currently being
657 // serviced by ExWorker threads. If the number goes above
658 // a certain threshold, put the request on the overflow queue to be
662 LONG PostedRequestCount
; /* ReactOS Change: GCC "pointer targets in passing argument 1 of 'InterlockedDecrement' differ in signedness" */
665 // The following field indicates the number of IRP's waiting
666 // to be serviced in the overflow queue.
669 ULONG OverflowQueueCount
;
672 // The following field contains the queue header of the overflow queue.
673 // The Overflow queue is a list of IRP's linked via the IRP's ListEntry
677 LIST_ENTRY OverflowQueue
;
680 // The following spinlock protects access to all the above fields.
683 KSPIN_LOCK OverflowQueueSpinLock
;
686 // This is the file system specific volume control block.
691 } VOLUME_DEVICE_OBJECT
;
692 typedef VOLUME_DEVICE_OBJECT
*PVOLUME_DEVICE_OBJECT
;
696 // The following two structures are the separate union structures for
697 // data and index Fcb's. The path table is actually the same structure
698 // as the index Fcb since it uses the first few fields.
701 typedef enum _FCB_CONDITION
{
707 typedef struct _FCB_DATA
{
710 // The following field is used by the oplock module
711 // to maintain current oplock information.
717 // The following field is used by the filelock module
718 // to maintain current byte range locking information.
719 // A file lock is allocated as needed.
725 typedef FCB_DATA
*PFCB_DATA
;
727 typedef struct _FCB_INDEX
{
730 // Internal stream file.
733 PFILE_OBJECT FileObject
;
736 // Offset of first entry in stream. This is for case where directory
737 // or path table does not begin on a sector boundary. This value is
738 // added to all offset values to determine the real offset.
744 // List of child fcbs.
750 // Ordinal number for this directory. Combine this with the path table offset
751 // in the FileId and you have a starting point in the path table.
757 // Children path table start. This is the offset in the path table
758 // for the first child of the directory. A value of zero indicates
759 // that we haven't found the first child yet. If there are no child
760 // directories we will position at a point in the path table so that
761 // subsequent searches will fail quickly.
764 ULONG ChildPathTableOffset
;
768 // Root of splay trees for exact and ignore case prefix trees.
771 PRTL_SPLAY_LINKS ExactCaseRoot
;
772 PRTL_SPLAY_LINKS IgnoreCaseRoot
;
775 typedef FCB_INDEX
*PFCB_INDEX
;
777 typedef struct _FCB_NONPAGED
{
780 // Type and size of this record must be CDFS_NTC_FCB_NONPAGED
783 NODE_TYPE_CODE NodeTypeCode
;
784 NODE_BYTE_SIZE NodeByteSize
;
787 // The following field contains a record of special pointers used by
788 // MM and Cache to manipulate section objects. Note that the values
789 // are set outside of the file system. However the file system on an
790 // open/create will set the file object's SectionObject field to
791 // point to this field
794 SECTION_OBJECT_POINTERS SegmentObject
;
797 // This is the resource structure for this Fcb.
800 ERESOURCE FcbResource
;
803 // This is the FastMutex for this Fcb.
809 // This is the mutex that is inserted into the FCB_ADVANCED_HEADER
813 FAST_MUTEX AdvancedFcbHeaderMutex
;
816 typedef FCB_NONPAGED
*PFCB_NONPAGED
;
819 // The Fcb/Dcb record corresponds to every open file and directory, and to
820 // every directory on an opened path.
823 typedef struct _FCB
{
826 // The following field is used for fast I/O. It contains the node
827 // type code and size, indicates if fast I/O is possible, contains
828 // allocation, file, and valid data size, a resource, and call back
829 // pointers for FastIoRead and FastMdlRead.
832 // Node type codes for the Fcb must be one of the following.
834 // CDFS_NTC_FCB_PATH_TABLE
835 // CDFS_NTC_FCB_INDEX
840 // Common Fsrtl Header. The named header is for the fieldoff.c output. We
841 // use the unnamed header internally.
846 FSRTL_ADVANCED_FCB_HEADER Header
;
847 FSRTL_ADVANCED_FCB_HEADER
;
857 // Parent Fcb for this Fcb. This may be NULL if this file was opened
858 // by ID, also for the root Fcb.
861 struct _FCB
*ParentFcb
;
864 // Links to the queue of Fcb's in the parent.
870 // FileId for this file.
876 // Counts on this Fcb. Cleanup count represents the number of open handles
877 // on this Fcb. Reference count represents the number of reasons this Fcb
878 // is still present. It includes file objects, children Fcb and anyone
879 // who wants to prevent this Fcb from going away. Cleanup count is synchronized
880 // with the FcbResource. The reference count is synchronized with the
885 LONG FcbReference
; /* ReactOS Change: GCC 'pointer targets in passing argument 1 of 'InterlockedXxx' differ in signedness */
886 ULONG FcbUserReference
;
889 // State flags for this Fcb.
895 // NT style attributes for the Fcb.
898 ULONG FileAttributes
;
901 // CDXA attributes for this file.
907 // File number from the system use area.
913 // This is the thread and count for the thread which has locked this
921 // Pointer to the Fcb non-paged structures.
924 PFCB_NONPAGED FcbNonpaged
;
927 // Share access structure.
930 SHARE_ACCESS ShareAccess
;
933 // Mcb for the on disk mapping and a single map entry.
936 CD_MCB_ENTRY McbEntry
;
940 // Embed the prefix entry for the longname. Store an optional pointer
941 // to a prefix structure for the short name.
944 PPREFIX_ENTRY ShortNamePrefix
;
945 PREFIX_ENTRY FileNamePrefix
;
948 // Time stamp for this file.
951 LONGLONG CreationTime
;
963 #define FCB_STATE_INITIALIZED (0x00000001)
964 #define FCB_STATE_IN_FCB_TABLE (0x00000002)
965 #define FCB_STATE_MODE2FORM2_FILE (0x00000004)
966 #define FCB_STATE_MODE2_FILE (0x00000008)
967 #define FCB_STATE_DA_FILE (0x00000010)
970 // These file types are read as raw 2352 byte sectors
973 #define FCB_STATE_RAWSECTOR_MASK ( FCB_STATE_MODE2FORM2_FILE | \
974 FCB_STATE_MODE2_FILE | \
977 #define SIZEOF_FCB_DATA \
978 (FIELD_OFFSET( FCB, FcbType ) + sizeof( FCB_DATA ))
980 #define SIZEOF_FCB_INDEX \
981 (FIELD_OFFSET( FCB, FcbType ) + sizeof( FCB_INDEX ))
985 // The Ccb record is allocated for every file object
988 typedef struct _CCB
{
991 // Type and size of this record (must be CDFS_NTC_CCB)
994 NODE_TYPE_CODE NodeTypeCode
;
995 NODE_BYTE_SIZE NodeByteSize
;
998 // Flags. Indicates flags to apply for the current open.
1004 // Fcb for the file being opened.
1010 // We store state information in the Ccb for a directory
1011 // enumeration on this handle.
1015 // Offset in the directory stream to base the next enumeration.
1018 ULONG CurrentDirentOffset
;
1019 CD_NAME SearchExpression
;
1024 #define CCB_FLAG_OPEN_BY_ID (0x00000001)
1025 #define CCB_FLAG_OPEN_RELATIVE_BY_ID (0x00000002)
1026 #define CCB_FLAG_IGNORE_CASE (0x00000004)
1027 #define CCB_FLAG_OPEN_WITH_VERSION (0x00000008)
1028 #define CCB_FLAG_DISMOUNT_ON_CLOSE (0x00000010)
1031 // Following flags refer to index enumeration.
1034 #define CCB_FLAG_ENUM_NAME_EXP_HAS_WILD (0x00010000)
1035 #define CCB_FLAG_ENUM_VERSION_EXP_HAS_WILD (0x00020000)
1036 #define CCB_FLAG_ENUM_MATCH_ALL (0x00040000)
1037 #define CCB_FLAG_ENUM_VERSION_MATCH_ALL (0x00080000)
1038 #define CCB_FLAG_ENUM_RETURN_NEXT (0x00100000)
1039 #define CCB_FLAG_ENUM_INITIALIZED (0x00200000)
1040 #define CCB_FLAG_ENUM_NOMATCH_CONSTANT_ENTRY (0x00400000)
1044 // The Irp Context record is allocated for every originating Irp. It is
1045 // created by the Fsd dispatch routines, and deallocated by the CdComplete
1049 typedef struct _IRP_CONTEXT
{
1052 // Type and size of this record (must be CDFS_NTC_IRP_CONTEXT)
1055 NODE_TYPE_CODE NodeTypeCode
;
1056 NODE_BYTE_SIZE NodeByteSize
;
1059 // Originating Irp for the request.
1065 // Vcb for this operation. When this is NULL it means we were called
1066 // with our filesystem device object instead of a volume device object.
1067 // (Mount will fill this in once the Vcb is created)
1073 // Exception encountered during the request. Any error raised explicitly by
1074 // the file system will be stored here. Any other error raised by the system
1075 // is stored here after normalizing it.
1078 NTSTATUS ExceptionStatus
;
1079 ULONG RaisedAtLineFile
;
1082 // Flags for this request.
1088 // Real device object. This represents the physical device closest to the media.
1091 PDEVICE_OBJECT RealDevice
;
1094 // Io context for a read request.
1095 // Address of Fcb for teardown oplock in create case.
1100 struct _CD_IO_CONTEXT
*IoContext
;
1105 // Top level irp context for this thread.
1108 struct _IRP_CONTEXT
*TopLevel
;
1111 // Major and minor function codes.
1114 UCHAR MajorFunction
;
1115 UCHAR MinorFunction
;
1118 // Pointer to the top-level context if this IrpContext is responsible
1119 // for cleaning it up.
1122 struct _THREAD_CONTEXT
*ThreadContext
;
1125 // This structure is used for posting to the Ex worker threads.
1128 WORK_QUEUE_ITEM WorkQueueItem
;
1131 typedef IRP_CONTEXT
*PIRP_CONTEXT
;
1133 #define IRP_CONTEXT_FLAG_ON_STACK (0x00000001)
1134 #define IRP_CONTEXT_FLAG_MORE_PROCESSING (0x00000002)
1135 #define IRP_CONTEXT_FLAG_WAIT (0x00000004)
1136 #define IRP_CONTEXT_FLAG_FORCE_POST (0x00000008)
1137 #define IRP_CONTEXT_FLAG_TOP_LEVEL (0x00000010)
1138 #define IRP_CONTEXT_FLAG_TOP_LEVEL_CDFS (0x00000020)
1139 #define IRP_CONTEXT_FLAG_IN_FSP (0x00000040)
1140 #define IRP_CONTEXT_FLAG_IN_TEARDOWN (0x00000080)
1141 #define IRP_CONTEXT_FLAG_ALLOC_IO (0x00000100)
1142 #define IRP_CONTEXT_FLAG_DISABLE_POPUPS (0x00000200)
1143 #define IRP_CONTEXT_FLAG_FORCE_VERIFY (0x00000400)
1146 // Flags used for create.
1149 #define IRP_CONTEXT_FLAG_FULL_NAME (0x10000000)
1150 #define IRP_CONTEXT_FLAG_TRAIL_BACKSLASH (0x20000000)
1153 // The following flags need to be cleared when a request is posted.
1156 #define IRP_CONTEXT_FLAGS_CLEAR_ON_POST ( \
1157 IRP_CONTEXT_FLAG_MORE_PROCESSING | \
1158 IRP_CONTEXT_FLAG_WAIT | \
1159 IRP_CONTEXT_FLAG_FORCE_POST | \
1160 IRP_CONTEXT_FLAG_TOP_LEVEL | \
1161 IRP_CONTEXT_FLAG_TOP_LEVEL_CDFS | \
1162 IRP_CONTEXT_FLAG_IN_FSP | \
1163 IRP_CONTEXT_FLAG_IN_TEARDOWN | \
1164 IRP_CONTEXT_FLAG_DISABLE_POPUPS \
1168 // The following flags need to be cleared when a request is retried.
1171 #define IRP_CONTEXT_FLAGS_CLEAR_ON_RETRY ( \
1172 IRP_CONTEXT_FLAG_MORE_PROCESSING | \
1173 IRP_CONTEXT_FLAG_IN_TEARDOWN | \
1174 IRP_CONTEXT_FLAG_DISABLE_POPUPS \
1178 // The following flags are set each time through the Fsp loop.
1181 #define IRP_CONTEXT_FSP_FLAGS ( \
1182 IRP_CONTEXT_FLAG_WAIT | \
1183 IRP_CONTEXT_FLAG_TOP_LEVEL | \
1184 IRP_CONTEXT_FLAG_TOP_LEVEL_CDFS | \
1185 IRP_CONTEXT_FLAG_IN_FSP \
1190 // Following structure is used to queue a request to the delayed close queue.
1191 // This structure should be the minimum block allocation size.
1194 typedef struct _IRP_CONTEXT_LITE
{
1197 // Type and size of this record (must be CDFS_NTC_IRP_CONTEXT_LITE)
1200 NODE_TYPE_CODE NodeTypeCode
;
1201 NODE_BYTE_SIZE NodeByteSize
;
1204 // Fcb for the file object being closed.
1210 // List entry to attach to delayed close queue.
1213 LIST_ENTRY DelayedCloseLinks
;
1216 // User reference count for the file object being closed.
1219 ULONG UserReference
;
1222 // Real device object. This represents the physical device closest to the media.
1225 PDEVICE_OBJECT RealDevice
;
1228 typedef IRP_CONTEXT_LITE
*PIRP_CONTEXT_LITE
;
1232 // Context structure for asynchronous I/O calls. Most of these fields
1233 // are actually only required for the ReadMultiple routines, but
1234 // the caller must allocate one as a local variable anyway before knowing
1235 // whether there are multiple requests are not. Therefore, a single
1236 // structure is used for simplicity.
1239 typedef struct _CD_IO_CONTEXT
{
1242 // These two fields are used for multiple run Io
1248 BOOLEAN AllocatedContext
;
1253 // This element handles the asynchronous non-cached Io
1258 PERESOURCE Resource
;
1259 ERESOURCE_THREAD ResourceThreadId
;
1260 ULONG RequestedByteCount
;
1264 // and this element handles the synchronous non-cached Io.
1271 typedef CD_IO_CONTEXT
*PCD_IO_CONTEXT
;
1275 // Following structure is used to track the top level request. Each Cdfs
1276 // Fsd and Fsp entry point will examine the top level irp location in the
1277 // thread local storage to determine if this request is top level and/or
1278 // top level Cdfs. The top level Cdfs request will remember the previous
1279 // value and update that location with a stack location. This location
1280 // can be accessed by recursive Cdfs entry points.
1283 typedef struct _THREAD_CONTEXT
{
1286 // CDFS signature. Used to confirm structure on stack is valid.
1292 // Previous value in top-level thread location. We restore this
1296 PIRP SavedTopLevelIrp
;
1299 // Top level Cdfs IrpContext. Initial Cdfs entry point on stack
1300 // will store the IrpContext for the request in this stack location.
1303 PIRP_CONTEXT TopLevelIrpContext
;
1306 typedef THREAD_CONTEXT
*PTHREAD_CONTEXT
;
1310 // The following structure is used for enumerating the entries in the
1311 // path table. We will always map this two sectors at a time so we don't
1312 // have to worry about entries which span sectors. We move through
1313 // one sector at a time though. We will unpin and remap after
1314 // crossing a sector boundary.
1316 // The only special case is where we span a cache view. In that case
1317 // we will allocate a buffer and read both pieces into it.
1319 // This strategy takes advantage of the CC enhancement which allows
1320 // overlapping ranges.
1323 typedef struct _PATH_ENUM_CONTEXT
{
1326 // Pointer to the current sector and the offset of this sector to
1327 // the beginning of the path table. The Data pointer may be
1328 // a pool block in the case where we cross a cache view
1329 // boundary. Also the length of the data for this block.
1337 // Bcb for the sector. (We may actually have pinned two sectors)
1338 // This will be NULL for the case where we needed to allocate a
1339 // buffer in the case where we span a cache view.
1345 // Offset to current entry within the current data block.
1351 // Did we allocate the buffer for the entry.
1354 BOOLEAN AllocatedData
;
1357 // End of Path Table. This tells us whether the current data
1358 // block includes the end of the path table. This is the
1359 // only block where we need to do a careful check about whether
1360 // the path table entry fits into the buffer.
1362 // Also once we have reached the end of the path table we don't
1363 // need to remap the data as we move into the final sector.
1364 // We always look at the last two sectors together.
1367 BOOLEAN LastDataBlock
;
1369 } PATH_ENUM_CONTEXT
;
1370 typedef PATH_ENUM_CONTEXT
*PPATH_ENUM_CONTEXT
;
1372 #define VACB_MAPPING_MASK (VACB_MAPPING_GRANULARITY - 1)
1373 #define LAST_VACB_SECTOR_OFFSET (VACB_MAPPING_GRANULARITY - SECTOR_SIZE)
1377 // Path Entry. This is our representation of the on disk data.
1380 typedef struct _PATH_ENTRY
{
1383 // Directory number and offset. This is the ordinal and the offset from
1384 // the beginning of the path table stream for this entry.
1389 ULONG PathTableOffset
;
1392 // Logical block Offset on the disk for this entry. We already bias
1393 // this by any Xar blocks.
1399 // Length of on-disk path table entry.
1402 ULONG PathEntryLength
;
1408 ULONG ParentOrdinal
;
1411 // DirName length and Id. Typically the pointer here points to the raw on-disk
1412 // bytes. We will point to a fixed self entry if this is the root directory.
1419 // Following are the flags used to cleanup this structure.
1425 // The following is the filename string and version number strings. We embed a buffer
1426 // large enough to hold two 8.3 names. One for exact case and one for case insensitive.
1430 CD_NAME CdCaseDirName
;
1432 WCHAR NameBuffer
[BYTE_COUNT_EMBEDDED_NAME
/ sizeof( WCHAR
) * 2];
1435 typedef PATH_ENTRY
*PPATH_ENTRY
;
1437 #define PATH_ENTRY_FLAG_ALLOC_BUFFER (0x00000001)
1441 // Compound path entry. This structure combines the on-disk entries
1442 // with the in-memory structures.
1445 typedef struct _COMPOUND_PATH_ENTRY
{
1447 PATH_ENUM_CONTEXT PathContext
;
1448 PATH_ENTRY PathEntry
;
1450 } COMPOUND_PATH_ENTRY
;
1451 typedef COMPOUND_PATH_ENTRY
*PCOMPOUND_PATH_ENTRY
;
1455 // The following is used for enumerating through a directory via the
1459 typedef struct _DIRENT_ENUM_CONTEXT
{
1462 // Pointer the current sector and the offset of this sector within
1463 // the directory file. Also the data length of this pinned block.
1471 // Bcb for the sector.
1477 // Offset to the current dirent within this sector.
1483 // Length to next dirent. A zero indicates to move to the next sector.
1486 ULONG NextDirentOffset
;
1488 } DIRENT_ENUM_CONTEXT
;
1489 typedef DIRENT_ENUM_CONTEXT
*PDIRENT_ENUM_CONTEXT
;
1493 // Following structure is used to smooth out the differences in the HSG, ISO
1494 // and Joliet directory entries.
1497 typedef struct _DIRENT
{
1500 // Offset in the Directory of this entry. Note this includes
1501 // any bytes added to the beginning of the directory to pad
1502 // down to a sector boundary.
1510 // Starting offset on the disk including any Xar blocks.
1513 ULONG StartingOffset
;
1516 // DataLength of the data. If not the last block then this should
1517 // be an integral number of logical blocks.
1523 // The following field is the time stamp out of the directory entry.
1524 // Use a pointer into the dirent for this.
1530 // The following field is the dirent file flags field.
1536 // Following field is a Cdfs flag field used to clean up this structure.
1542 // The following fields indicate the file unit size and interleave gap
1543 // for interleaved files. Each of these are in logical blocks.
1547 ULONG InterleaveGapSize
;
1550 // System use offset. Zero value indicates no system use area.
1553 ULONG SystemUseOffset
;
1556 // CDXA attributes and file number for this file.
1559 USHORT XAAttributes
;
1563 // Filename length and ID. We copy the length (in bytes) and keep
1564 // a pointer to the start of the name.
1571 // The following are the filenames stored by name and version numbers.
1572 // The fixed buffer here can hold two Unicode 8.3 names. This allows
1573 // us to upcase the name into a fixed buffer.
1577 CD_NAME CdCaseFileName
;
1580 // Data stream type. Indicates if this is audio, XA mode2 form2 or cooked sectors.
1583 XA_EXTENT_TYPE ExtentType
;
1585 WCHAR NameBuffer
[BYTE_COUNT_EMBEDDED_NAME
/ sizeof( WCHAR
) * 2];
1588 typedef DIRENT
*PDIRENT
;
1590 #define DIRENT_FLAG_ALLOC_BUFFER (0x01)
1591 #define DIRENT_FLAG_CONSTANT_ENTRY (0x02)
1593 #define DIRENT_FLAG_NOT_PERSISTENT (0)
1597 // Following structure combines the on-disk information with the normalized
1601 typedef struct _COMPOUND_DIRENT
{
1603 DIRENT_ENUM_CONTEXT DirContext
;
1607 typedef COMPOUND_DIRENT
*PCOMPOUND_DIRENT
;
1611 // The following structure is used to enumerate the files in a directory.
1612 // It contains three DirContext/Dirent pairs and then self pointers to
1613 // know which of these is begin used how.
1616 typedef struct _FILE_ENUM_CONTEXT
{
1619 // Pointers to the current compound dirents below.
1621 // PriorDirent - Initial dirent for the last file encountered.
1622 // InitialDirent - Initial dirent for the current file.
1623 // CurrentDirent - Second or later dirent for the current file.
1626 PCOMPOUND_DIRENT PriorDirent
;
1627 PCOMPOUND_DIRENT InitialDirent
;
1628 PCOMPOUND_DIRENT CurrentDirent
;
1631 // Flags indicating the state of the search.
1637 // This is an accumulation of the file sizes of the different extents
1638 // of a single file.
1644 // Short name for this file.
1648 WCHAR ShortNameBuffer
[ BYTE_COUNT_8_DOT_3
/ sizeof( WCHAR
) ];
1651 // Array of compound dirents.
1654 COMPOUND_DIRENT Dirents
[3];
1656 } FILE_ENUM_CONTEXT
;
1657 typedef FILE_ENUM_CONTEXT
*PFILE_ENUM_CONTEXT
;
1659 #define FILE_CONTEXT_MULTIPLE_DIRENTS (0x00000001)
1663 // RIFF header. Prepended to the data of a file containing XA sectors.
1664 // This is a hard-coded structure except that we bias the 'ChunkSize' and
1665 // 'RawSectors' fields with the file size. We also copy the attributes flag
1666 // from the system use area in the dirent. We always initialize this
1667 // structure by copying the XAFileHeader.
1670 typedef struct _RIFF_HEADER
{
1674 ULONG SignatureCDXA
;
1682 ULONG SignatureData
;
1686 typedef RIFF_HEADER
*PRIFF_HEADER
;
1689 // Audio play header for CDDA tracks.
1692 typedef struct _AUDIO_PLAY_HEADER
{
1696 ULONG SignatureCDDA
;
1702 ULONG StartingSector
;
1704 UCHAR TrackAddress
[4];
1705 UCHAR TrackLength
[4];
1707 } AUDIO_PLAY_HEADER
;
1708 typedef AUDIO_PLAY_HEADER
*PAUDIO_PLAY_HEADER
;
1712 // Some macros for supporting the use of a Generic Table
1713 // containing all the FCB/DCBs and indexed by their FileId.
1717 // The HighPart contains the path table offset of this directory in the
1720 // The LowPart contains zero except for the upper bit which is
1721 // set to indicate that this is a directory.
1725 // The HighPart contains the path table offset of the parent directory
1726 // in the path table.
1728 // The LowPart contains the byte offset of the dirent in the parent
1731 // A directory is always entered into the Fcb Table as if it's
1732 // dirent offset was zero. This enables any child to look in the FcbTable
1733 // for it's parent by searching with the same HighPart but with zero
1734 // as the value for LowPart.
1736 // The Id field is a LARGE_INTEGER where the High and Low parts can be
1737 // accessed separately.
1739 // The following macros are used to access the Fid fields.
1741 // CdQueryFidDirentOffset - Accesses the Dirent offset field
1742 // CdQueryFidPathTableNumber - Accesses the PathTable offset field
1743 // CdSetFidDirentOffset - Sets the Dirent offset field
1744 // CdSetFidPathTableNumber - Sets the PathTable ordinal field
1745 // CdFidIsDirectory - Queries if directory bit is set
1746 // CdFidSetDirectory - Sets directory bit
1749 #define FID_DIR_MASK 0x80000000 // high order bit means directory.
1751 #define CdQueryFidDirentOffset(I) ((I).LowPart & ~FID_DIR_MASK)
1752 #define CdQueryFidPathTableOffset(I) ((I).HighPart)
1753 #define CdSetFidDirentOffset(I,D) ((I).LowPart = D)
1754 #define CdSetFidPathTableOffset(I,P) ((I).HighPart = P)
1755 #define CdFidIsDirectory(I) FlagOn( (I).LowPart, FID_DIR_MASK )
1756 #define CdFidSetDirectory(I) SetFlag( (I).LowPart, FID_DIR_MASK )
1758 #define CdSetFidFromParentAndDirent(I,F,D) { \
1759 CdSetFidPathTableOffset( (I), CdQueryFidPathTableOffset( (F)->FileId )); \
1760 CdSetFidDirentOffset( (I), (D)->DirentOffset ); \
1761 if (FlagOn( (D)->DirentFlags, CD_ATTRIBUTE_DIRECTORY )) { \
1762 CdFidSetDirectory((I)); \