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 // Following are used to manage the async and delayed close queue.
355 // FspCloseActive - Indicates whether there is a thread processing the
357 // ReduceDelayedClose - Indicates that we have hit the upper threshold
358 // for the delayed close queue and need to reduce it to lower threshold.
360 // AsyncCloseQueue - Queue of IrpContext waiting for async close operation.
361 // AsyncCloseCount - Number of entries on the async close queue.
363 // DelayedCloseQueue - Queue of IrpContextLite waiting for delayed close
365 // MaxDelayedCloseCount - Trigger delay close work at this threshold.
366 // MinDelayedCloseCount - Turn off delay close work at this threshold.
367 // DelayedCloseCount - Number of entries on the delayed close queue.
369 // CloseItem - Workqueue item used to start FspClose thread.
372 LIST_ENTRY AsyncCloseQueue
;
373 ULONG AsyncCloseCount
;
374 BOOLEAN FspCloseActive
;
375 BOOLEAN ReduceDelayedClose
;
379 // The following fields describe the deferred close file objects.
382 LIST_ENTRY DelayedCloseQueue
;
383 ULONG DelayedCloseCount
;
384 ULONG MaxDelayedCloseCount
;
385 ULONG MinDelayedCloseCount
;
388 // Fast mutex used to lock the fields of this structure.
391 PVOID CdDataLockThread
;
392 FAST_MUTEX CdDataMutex
;
395 // A resource variable to control access to the global CDFS data record
398 ERESOURCE DataResource
;
401 // Cache manager call back structure, which must be passed on each call
402 // to CcInitializeCacheMap.
405 CACHE_MANAGER_CALLBACKS CacheManagerCallbacks
;
406 CACHE_MANAGER_CALLBACKS CacheManagerVolumeCallbacks
;
409 // This is the ExWorkerItem that does both kinds of deferred closes.
412 PIO_WORKITEM CloseItem
;
415 typedef CD_DATA
*PCD_DATA
;
419 // The Vcb (Volume control block) record corresponds to every
420 // volume mounted by the file system. They are ordered in a queue off
421 // of CdData.VcbQueue.
423 // The Vcb will be in several conditions during its lifespan.
425 // NotMounted - Disk is not currently mounted (i.e. removed
426 // from system) but cleanup and close operations are
429 // MountInProgress - State of the Vcb from the time it is
430 // created until it is successfully mounted or the mount
433 // Mounted - Volume is currently in the mounted state.
435 // Invalid - User has invalidated the volume. Only legal operations
436 // are cleanup and close.
438 // DismountInProgress - We have begun the process of tearing down the
439 // Vcb. It can be deleted when all the references to it
443 typedef enum _VCB_CONDITION
{
449 VcbDismountInProgress
453 typedef struct _VCB
{
456 // The type and size of this record (must be CDFS_NTC_VCB)
459 NODE_TYPE_CODE NodeTypeCode
;
460 NODE_BYTE_SIZE NodeByteSize
;
463 // Vpb for this volume.
469 // Device object for the driver below us.
472 PDEVICE_OBJECT TargetDeviceObject
;
475 // File object used to lock the volume.
478 PFILE_OBJECT VolumeLockFileObject
;
481 // Link into queue of Vcb's in the CdData structure. We will create a union with
482 // a LONGLONG to force the Vcb to be quad-aligned.
492 // State flags and condition for the Vcb.
496 VCB_CONDITION VcbCondition
;
499 // Various counts for this Vcb.
501 // VcbCleanup - Open handles left on this system.
502 // VcbReference - Number of reasons this Vcb is still present.
503 // VcbUserReference - Number of user file objects still present.
507 LONG VcbReference
; /* ReactOS Change: GCC 'pointer targets in passing argument 1 of 'InterlockedXxx' differ in signedness */
508 LONG VcbUserReference
; /* ReactOS Change: GCC 'pointer targets in passing argument 1 of 'InterlockedXxx' differ in signedness */
511 // Fcb for the Volume Dasd file, root directory and the Path Table.
514 struct _FCB
*VolumeDasdFcb
;
515 struct _FCB
*RootIndexFcb
;
516 struct _FCB
*PathTableFcb
;
519 // Location of current session and offset of volume descriptors.
523 ULONG VdSectorOffset
;
524 ULONG PrimaryVdSectorOffset
;
527 // Following is a sector from the last non-cached read of an XA file.
528 // Also the cooked offset on the disk.
532 LONGLONG XADiskOffset
;
535 // Vcb resource. This is used to synchronize open/cleanup/close operations.
538 ERESOURCE VcbResource
;
541 // File resource. This is used to synchronize all file operations except
542 // open/cleanup/close.
545 ERESOURCE FileResource
;
548 // Vcb fast mutex. This is used to synchronize the fields in the Vcb
549 // when modified when the Vcb is not held exclusively. Included here
550 // are the count fields and Fcb table.
552 // We also use this to synchronize changes to the Fcb reference field.
559 // The following is used to synchronize the dir notify package.
562 PNOTIFY_SYNC NotifySync
;
565 // The following is the head of a list of notify Irps.
568 LIST_ENTRY DirNotifyList
;
571 // Logical block size for this volume as well constant values
572 // associated with the block size.
576 ULONG BlockToSectorShift
;
577 ULONG BlockToByteShift
;
578 ULONG BlocksPerSector
;
580 ULONG BlockInverseMask
;
583 // Fcb table. Synchronized with the Vcb fast mutex.
586 RTL_GENERIC_TABLE FcbTable
;
589 // Volume TOC. Cache this information for quick lookup.
598 // Block factor to determine last session information.
604 // Media change count from device driver for bulletproof detection
608 ULONG MediaChangeCount
;
611 // For raw reads, CDFS must obey the port maximum transfer restrictions.
614 ULONG MaximumTransferRawSectors
;
615 ULONG MaximumPhysicalPages
;
618 // Preallocated VPB for swapout, so we are not forced to consider
619 // must succeed pool.
627 #define VCB_STATE_HSG (0x00000001)
628 #define VCB_STATE_ISO (0x00000002)
629 #define VCB_STATE_JOLIET (0x00000004)
630 #define VCB_STATE_LOCKED (0x00000010)
631 #define VCB_STATE_REMOVABLE_MEDIA (0x00000020)
632 #define VCB_STATE_CDXA (0x00000040)
633 #define VCB_STATE_AUDIO_DISK (0x00000080)
634 #define VCB_STATE_NOTIFY_REMOUNT (0x00000100)
635 #define VCB_STATE_VPB_NOT_ON_DEVICE (0x00000200)
639 // The Volume Device Object is an I/O system device object with a
640 // workqueue and an VCB record appended to the end. There are multiple
641 // of these records, one for every mounted volume, and are created during
642 // a volume mount operation. The work queue is for handling an overload
643 // of work requests to the volume.
646 typedef struct _VOLUME_DEVICE_OBJECT
{
648 DEVICE_OBJECT DeviceObject
;
651 // The following field tells how many requests for this volume have
652 // either been enqueued to ExWorker threads or are currently being
653 // serviced by ExWorker threads. If the number goes above
654 // a certain threshold, put the request on the overflow queue to be
658 LONG PostedRequestCount
; /* ReactOS Change: GCC "pointer targets in passing argument 1 of 'InterlockedDecrement' differ in signedness" */
661 // The following field indicates the number of IRP's waiting
662 // to be serviced in the overflow queue.
665 ULONG OverflowQueueCount
;
668 // The following field contains the queue header of the overflow queue.
669 // The Overflow queue is a list of IRP's linked via the IRP's ListEntry
673 LIST_ENTRY OverflowQueue
;
676 // The following spinlock protects access to all the above fields.
679 KSPIN_LOCK OverflowQueueSpinLock
;
682 // This is the file system specific volume control block.
687 } VOLUME_DEVICE_OBJECT
;
688 typedef VOLUME_DEVICE_OBJECT
*PVOLUME_DEVICE_OBJECT
;
692 // The following two structures are the separate union structures for
693 // data and index Fcb's. The path table is actually the same structure
694 // as the index Fcb since it uses the first few fields.
697 typedef enum _FCB_CONDITION
{
703 typedef struct _FCB_DATA
{
706 // The following field is used by the oplock module
707 // to maintain current oplock information.
713 // The following field is used by the filelock module
714 // to maintain current byte range locking information.
715 // A file lock is allocated as needed.
721 typedef FCB_DATA
*PFCB_DATA
;
723 typedef struct _FCB_INDEX
{
726 // Internal stream file.
729 PFILE_OBJECT FileObject
;
732 // Offset of first entry in stream. This is for case where directory
733 // or path table does not begin on a sector boundary. This value is
734 // added to all offset values to determine the real offset.
740 // List of child fcbs.
746 // Ordinal number for this directory. Combine this with the path table offset
747 // in the FileId and you have a starting point in the path table.
753 // Children path table start. This is the offset in the path table
754 // for the first child of the directory. A value of zero indicates
755 // that we haven't found the first child yet. If there are no child
756 // directories we will position at a point in the path table so that
757 // subsequent searches will fail quickly.
760 ULONG ChildPathTableOffset
;
764 // Root of splay trees for exact and ignore case prefix trees.
767 PRTL_SPLAY_LINKS ExactCaseRoot
;
768 PRTL_SPLAY_LINKS IgnoreCaseRoot
;
771 typedef FCB_INDEX
*PFCB_INDEX
;
773 typedef struct _FCB_NONPAGED
{
776 // Type and size of this record must be CDFS_NTC_FCB_NONPAGED
779 NODE_TYPE_CODE NodeTypeCode
;
780 NODE_BYTE_SIZE NodeByteSize
;
783 // The following field contains a record of special pointers used by
784 // MM and Cache to manipulate section objects. Note that the values
785 // are set outside of the file system. However the file system on an
786 // open/create will set the file object's SectionObject field to
787 // point to this field
790 SECTION_OBJECT_POINTERS SegmentObject
;
793 // This is the resource structure for this Fcb.
796 ERESOURCE FcbResource
;
799 // This is the FastMutex for this Fcb.
805 // This is the mutex that is inserted into the FCB_ADVANCED_HEADER
809 FAST_MUTEX AdvancedFcbHeaderMutex
;
812 typedef FCB_NONPAGED
*PFCB_NONPAGED
;
815 // The Fcb/Dcb record corresponds to every open file and directory, and to
816 // every directory on an opened path.
819 typedef struct _FCB
{
822 // The following field is used for fast I/O. It contains the node
823 // type code and size, indicates if fast I/O is possible, contains
824 // allocation, file, and valid data size, a resource, and call back
825 // pointers for FastIoRead and FastMdlRead.
828 // Node type codes for the Fcb must be one of the following.
830 // CDFS_NTC_FCB_PATH_TABLE
831 // CDFS_NTC_FCB_INDEX
836 // Common Fsrtl Header. The named header is for the fieldoff.c output. We
837 // use the unnamed header internally.
842 FSRTL_ADVANCED_FCB_HEADER Header
;
843 FSRTL_ADVANCED_FCB_HEADER
;
853 // Parent Fcb for this Fcb. This may be NULL if this file was opened
854 // by ID, also for the root Fcb.
857 struct _FCB
*ParentFcb
;
860 // Links to the queue of Fcb's in the parent.
866 // FileId for this file.
872 // Counts on this Fcb. Cleanup count represents the number of open handles
873 // on this Fcb. Reference count represents the number of reasons this Fcb
874 // is still present. It includes file objects, children Fcb and anyone
875 // who wants to prevent this Fcb from going away. Cleanup count is synchronized
876 // with the FcbResource. The reference count is synchronized with the
881 LONG FcbReference
; /* ReactOS Change: GCC 'pointer targets in passing argument 1 of 'InterlockedXxx' differ in signedness */
882 ULONG FcbUserReference
;
885 // State flags for this Fcb.
891 // NT style attributes for the Fcb.
894 ULONG FileAttributes
;
897 // CDXA attributes for this file.
903 // File number from the system use area.
909 // This is the thread and count for the thread which has locked this
917 // Pointer to the Fcb non-paged structures.
920 PFCB_NONPAGED FcbNonpaged
;
923 // Share access structure.
926 SHARE_ACCESS ShareAccess
;
929 // Mcb for the on disk mapping and a single map entry.
932 CD_MCB_ENTRY McbEntry
;
936 // Embed the prefix entry for the longname. Store an optional pointer
937 // to a prefix structure for the short name.
940 PPREFIX_ENTRY ShortNamePrefix
;
941 PREFIX_ENTRY FileNamePrefix
;
944 // Time stamp for this file.
947 LONGLONG CreationTime
;
959 #define FCB_STATE_INITIALIZED (0x00000001)
960 #define FCB_STATE_IN_FCB_TABLE (0x00000002)
961 #define FCB_STATE_MODE2FORM2_FILE (0x00000004)
962 #define FCB_STATE_MODE2_FILE (0x00000008)
963 #define FCB_STATE_DA_FILE (0x00000010)
966 // These file types are read as raw 2352 byte sectors
969 #define FCB_STATE_RAWSECTOR_MASK ( FCB_STATE_MODE2FORM2_FILE | \
970 FCB_STATE_MODE2_FILE | \
973 #define SIZEOF_FCB_DATA \
974 (FIELD_OFFSET( FCB, FcbType ) + sizeof( FCB_DATA ))
976 #define SIZEOF_FCB_INDEX \
977 (FIELD_OFFSET( FCB, FcbType ) + sizeof( FCB_INDEX ))
981 // The Ccb record is allocated for every file object
984 typedef struct _CCB
{
987 // Type and size of this record (must be CDFS_NTC_CCB)
990 NODE_TYPE_CODE NodeTypeCode
;
991 NODE_BYTE_SIZE NodeByteSize
;
994 // Flags. Indicates flags to apply for the current open.
1000 // Fcb for the file being opened.
1006 // We store state information in the Ccb for a directory
1007 // enumeration on this handle.
1011 // Offset in the directory stream to base the next enumeration.
1014 ULONG CurrentDirentOffset
;
1015 CD_NAME SearchExpression
;
1020 #define CCB_FLAG_OPEN_BY_ID (0x00000001)
1021 #define CCB_FLAG_OPEN_RELATIVE_BY_ID (0x00000002)
1022 #define CCB_FLAG_IGNORE_CASE (0x00000004)
1023 #define CCB_FLAG_OPEN_WITH_VERSION (0x00000008)
1024 #define CCB_FLAG_DISMOUNT_ON_CLOSE (0x00000010)
1027 // Following flags refer to index enumeration.
1030 #define CCB_FLAG_ENUM_NAME_EXP_HAS_WILD (0x00010000)
1031 #define CCB_FLAG_ENUM_VERSION_EXP_HAS_WILD (0x00020000)
1032 #define CCB_FLAG_ENUM_MATCH_ALL (0x00040000)
1033 #define CCB_FLAG_ENUM_VERSION_MATCH_ALL (0x00080000)
1034 #define CCB_FLAG_ENUM_RETURN_NEXT (0x00100000)
1035 #define CCB_FLAG_ENUM_INITIALIZED (0x00200000)
1036 #define CCB_FLAG_ENUM_NOMATCH_CONSTANT_ENTRY (0x00400000)
1040 // The Irp Context record is allocated for every originating Irp. It is
1041 // created by the Fsd dispatch routines, and deallocated by the CdComplete
1045 typedef struct _IRP_CONTEXT
{
1048 // Type and size of this record (must be CDFS_NTC_IRP_CONTEXT)
1051 NODE_TYPE_CODE NodeTypeCode
;
1052 NODE_BYTE_SIZE NodeByteSize
;
1055 // Originating Irp for the request.
1061 // Vcb for this operation. When this is NULL it means we were called
1062 // with our filesystem device object instead of a volume device object.
1063 // (Mount will fill this in once the Vcb is created)
1069 // Exception encountered during the request. Any error raised explicitly by
1070 // the file system will be stored here. Any other error raised by the system
1071 // is stored here after normalizing it.
1074 NTSTATUS ExceptionStatus
;
1075 ULONG RaisedAtLineFile
;
1078 // Flags for this request.
1084 // Real device object. This represents the physical device closest to the media.
1087 PDEVICE_OBJECT RealDevice
;
1090 // Io context for a read request.
1091 // Address of Fcb for teardown oplock in create case.
1096 struct _CD_IO_CONTEXT
*IoContext
;
1101 // Top level irp context for this thread.
1104 struct _IRP_CONTEXT
*TopLevel
;
1107 // Major and minor function codes.
1110 UCHAR MajorFunction
;
1111 UCHAR MinorFunction
;
1114 // Pointer to the top-level context if this IrpContext is responsible
1115 // for cleaning it up.
1118 struct _THREAD_CONTEXT
*ThreadContext
;
1121 // This structure is used for posting to the Ex worker threads.
1124 WORK_QUEUE_ITEM WorkQueueItem
;
1127 typedef IRP_CONTEXT
*PIRP_CONTEXT
;
1129 #define IRP_CONTEXT_FLAG_ON_STACK (0x00000001)
1130 #define IRP_CONTEXT_FLAG_MORE_PROCESSING (0x00000002)
1131 #define IRP_CONTEXT_FLAG_WAIT (0x00000004)
1132 #define IRP_CONTEXT_FLAG_FORCE_POST (0x00000008)
1133 #define IRP_CONTEXT_FLAG_TOP_LEVEL (0x00000010)
1134 #define IRP_CONTEXT_FLAG_TOP_LEVEL_CDFS (0x00000020)
1135 #define IRP_CONTEXT_FLAG_IN_FSP (0x00000040)
1136 #define IRP_CONTEXT_FLAG_IN_TEARDOWN (0x00000080)
1137 #define IRP_CONTEXT_FLAG_ALLOC_IO (0x00000100)
1138 #define IRP_CONTEXT_FLAG_DISABLE_POPUPS (0x00000200)
1139 #define IRP_CONTEXT_FLAG_FORCE_VERIFY (0x00000400)
1142 // Flags used for create.
1145 #define IRP_CONTEXT_FLAG_FULL_NAME (0x10000000)
1146 #define IRP_CONTEXT_FLAG_TRAIL_BACKSLASH (0x20000000)
1149 // The following flags need to be cleared when a request is posted.
1152 #define IRP_CONTEXT_FLAGS_CLEAR_ON_POST ( \
1153 IRP_CONTEXT_FLAG_MORE_PROCESSING | \
1154 IRP_CONTEXT_FLAG_WAIT | \
1155 IRP_CONTEXT_FLAG_FORCE_POST | \
1156 IRP_CONTEXT_FLAG_TOP_LEVEL | \
1157 IRP_CONTEXT_FLAG_TOP_LEVEL_CDFS | \
1158 IRP_CONTEXT_FLAG_IN_FSP | \
1159 IRP_CONTEXT_FLAG_IN_TEARDOWN | \
1160 IRP_CONTEXT_FLAG_DISABLE_POPUPS \
1164 // The following flags need to be cleared when a request is retried.
1167 #define IRP_CONTEXT_FLAGS_CLEAR_ON_RETRY ( \
1168 IRP_CONTEXT_FLAG_MORE_PROCESSING | \
1169 IRP_CONTEXT_FLAG_IN_TEARDOWN | \
1170 IRP_CONTEXT_FLAG_DISABLE_POPUPS \
1174 // The following flags are set each time through the Fsp loop.
1177 #define IRP_CONTEXT_FSP_FLAGS ( \
1178 IRP_CONTEXT_FLAG_WAIT | \
1179 IRP_CONTEXT_FLAG_TOP_LEVEL | \
1180 IRP_CONTEXT_FLAG_TOP_LEVEL_CDFS | \
1181 IRP_CONTEXT_FLAG_IN_FSP \
1186 // Following structure is used to queue a request to the delayed close queue.
1187 // This structure should be the minimum block allocation size.
1190 typedef struct _IRP_CONTEXT_LITE
{
1193 // Type and size of this record (must be CDFS_NTC_IRP_CONTEXT_LITE)
1196 NODE_TYPE_CODE NodeTypeCode
;
1197 NODE_BYTE_SIZE NodeByteSize
;
1200 // Fcb for the file object being closed.
1206 // List entry to attach to delayed close queue.
1209 LIST_ENTRY DelayedCloseLinks
;
1212 // User reference count for the file object being closed.
1215 ULONG UserReference
;
1218 // Real device object. This represents the physical device closest to the media.
1221 PDEVICE_OBJECT RealDevice
;
1224 typedef IRP_CONTEXT_LITE
*PIRP_CONTEXT_LITE
;
1228 // Context structure for asynchronous I/O calls. Most of these fields
1229 // are actually only required for the ReadMultiple routines, but
1230 // the caller must allocate one as a local variable anyway before knowing
1231 // whether there are multiple requests are not. Therefore, a single
1232 // structure is used for simplicity.
1235 typedef struct _CD_IO_CONTEXT
{
1238 // These two fields are used for multiple run Io
1244 BOOLEAN AllocatedContext
;
1249 // This element handles the asynchronous non-cached Io
1254 PERESOURCE Resource
;
1255 ERESOURCE_THREAD ResourceThreadId
;
1256 ULONG RequestedByteCount
;
1260 // and this element handles the synchronous non-cached Io.
1267 typedef CD_IO_CONTEXT
*PCD_IO_CONTEXT
;
1271 // Following structure is used to track the top level request. Each Cdfs
1272 // Fsd and Fsp entry point will examine the top level irp location in the
1273 // thread local storage to determine if this request is top level and/or
1274 // top level Cdfs. The top level Cdfs request will remember the previous
1275 // value and update that location with a stack location. This location
1276 // can be accessed by recursive Cdfs entry points.
1279 typedef struct _THREAD_CONTEXT
{
1282 // CDFS signature. Used to confirm structure on stack is valid.
1288 // Previous value in top-level thread location. We restore this
1292 PIRP SavedTopLevelIrp
;
1295 // Top level Cdfs IrpContext. Initial Cdfs entry point on stack
1296 // will store the IrpContext for the request in this stack location.
1299 PIRP_CONTEXT TopLevelIrpContext
;
1302 typedef THREAD_CONTEXT
*PTHREAD_CONTEXT
;
1306 // The following structure is used for enumerating the entries in the
1307 // path table. We will always map this two sectors at a time so we don't
1308 // have to worry about entries which span sectors. We move through
1309 // one sector at a time though. We will unpin and remap after
1310 // crossing a sector boundary.
1312 // The only special case is where we span a cache view. In that case
1313 // we will allocate a buffer and read both pieces into it.
1315 // This strategy takes advantage of the CC enhancement which allows
1316 // overlapping ranges.
1319 typedef struct _PATH_ENUM_CONTEXT
{
1322 // Pointer to the current sector and the offset of this sector to
1323 // the beginning of the path table. The Data pointer may be
1324 // a pool block in the case where we cross a cache view
1325 // boundary. Also the length of the data for this block.
1333 // Bcb for the sector. (We may actually have pinned two sectors)
1334 // This will be NULL for the case where we needed to allocate a
1335 // buffer in the case where we span a cache view.
1341 // Offset to current entry within the current data block.
1347 // Did we allocate the buffer for the entry.
1350 BOOLEAN AllocatedData
;
1353 // End of Path Table. This tells us whether the current data
1354 // block includes the end of the path table. This is the
1355 // only block where we need to do a careful check about whether
1356 // the path table entry fits into the buffer.
1358 // Also once we have reached the end of the path table we don't
1359 // need to remap the data as we move into the final sector.
1360 // We always look at the last two sectors together.
1363 BOOLEAN LastDataBlock
;
1365 } PATH_ENUM_CONTEXT
;
1366 typedef PATH_ENUM_CONTEXT
*PPATH_ENUM_CONTEXT
;
1368 #define VACB_MAPPING_MASK (VACB_MAPPING_GRANULARITY - 1)
1369 #define LAST_VACB_SECTOR_OFFSET (VACB_MAPPING_GRANULARITY - SECTOR_SIZE)
1373 // Path Entry. This is our representation of the on disk data.
1376 typedef struct _PATH_ENTRY
{
1379 // Directory number and offset. This is the ordinal and the offset from
1380 // the beginning of the path table stream for this entry.
1385 ULONG PathTableOffset
;
1388 // Logical block Offset on the disk for this entry. We already bias
1389 // this by any Xar blocks.
1395 // Length of on-disk path table entry.
1398 ULONG PathEntryLength
;
1404 ULONG ParentOrdinal
;
1407 // DirName length and Id. Typically the pointer here points to the raw on-disk
1408 // bytes. We will point to a fixed self entry if this is the root directory.
1415 // Following are the flags used to cleanup this structure.
1421 // The following is the filename string and version number strings. We embed a buffer
1422 // large enough to hold two 8.3 names. One for exact case and one for case insensitive.
1426 CD_NAME CdCaseDirName
;
1428 WCHAR NameBuffer
[BYTE_COUNT_EMBEDDED_NAME
/ sizeof( WCHAR
) * 2];
1431 typedef PATH_ENTRY
*PPATH_ENTRY
;
1433 #define PATH_ENTRY_FLAG_ALLOC_BUFFER (0x00000001)
1437 // Compound path entry. This structure combines the on-disk entries
1438 // with the in-memory structures.
1441 typedef struct _COMPOUND_PATH_ENTRY
{
1443 PATH_ENUM_CONTEXT PathContext
;
1444 PATH_ENTRY PathEntry
;
1446 } COMPOUND_PATH_ENTRY
;
1447 typedef COMPOUND_PATH_ENTRY
*PCOMPOUND_PATH_ENTRY
;
1451 // The following is used for enumerating through a directory via the
1455 typedef struct _DIRENT_ENUM_CONTEXT
{
1458 // Pointer the current sector and the offset of this sector within
1459 // the directory file. Also the data length of this pinned block.
1467 // Bcb for the sector.
1473 // Offset to the current dirent within this sector.
1479 // Length to next dirent. A zero indicates to move to the next sector.
1482 ULONG NextDirentOffset
;
1484 } DIRENT_ENUM_CONTEXT
;
1485 typedef DIRENT_ENUM_CONTEXT
*PDIRENT_ENUM_CONTEXT
;
1489 // Following structure is used to smooth out the differences in the HSG, ISO
1490 // and Joliet directory entries.
1493 typedef struct _DIRENT
{
1496 // Offset in the Directory of this entry. Note this includes
1497 // any bytes added to the beginning of the directory to pad
1498 // down to a sector boundary.
1506 // Starting offset on the disk including any Xar blocks.
1509 ULONG StartingOffset
;
1512 // DataLength of the data. If not the last block then this should
1513 // be an integral number of logical blocks.
1519 // The following field is the time stamp out of the directory entry.
1520 // Use a pointer into the dirent for this.
1526 // The following field is the dirent file flags field.
1532 // Following field is a Cdfs flag field used to clean up this structure.
1538 // The following fields indicate the file unit size and interleave gap
1539 // for interleaved files. Each of these are in logical blocks.
1543 ULONG InterleaveGapSize
;
1546 // System use offset. Zero value indicates no system use area.
1549 ULONG SystemUseOffset
;
1552 // CDXA attributes and file number for this file.
1555 USHORT XAAttributes
;
1559 // Filename length and ID. We copy the length (in bytes) and keep
1560 // a pointer to the start of the name.
1567 // The following are the filenames stored by name and version numbers.
1568 // The fixed buffer here can hold two Unicode 8.3 names. This allows
1569 // us to upcase the name into a fixed buffer.
1573 CD_NAME CdCaseFileName
;
1576 // Data stream type. Indicates if this is audio, XA mode2 form2 or cooked sectors.
1579 XA_EXTENT_TYPE ExtentType
;
1581 WCHAR NameBuffer
[BYTE_COUNT_EMBEDDED_NAME
/ sizeof( WCHAR
) * 2];
1584 typedef DIRENT
*PDIRENT
;
1586 #define DIRENT_FLAG_ALLOC_BUFFER (0x01)
1587 #define DIRENT_FLAG_CONSTANT_ENTRY (0x02)
1589 #define DIRENT_FLAG_NOT_PERSISTENT (0)
1593 // Following structure combines the on-disk information with the normalized
1597 typedef struct _COMPOUND_DIRENT
{
1599 DIRENT_ENUM_CONTEXT DirContext
;
1603 typedef COMPOUND_DIRENT
*PCOMPOUND_DIRENT
;
1607 // The following structure is used to enumerate the files in a directory.
1608 // It contains three DirContext/Dirent pairs and then self pointers to
1609 // know which of these is begin used how.
1612 typedef struct _FILE_ENUM_CONTEXT
{
1615 // Pointers to the current compound dirents below.
1617 // PriorDirent - Initial dirent for the last file encountered.
1618 // InitialDirent - Initial dirent for the current file.
1619 // CurrentDirent - Second or later dirent for the current file.
1622 PCOMPOUND_DIRENT PriorDirent
;
1623 PCOMPOUND_DIRENT InitialDirent
;
1624 PCOMPOUND_DIRENT CurrentDirent
;
1627 // Flags indicating the state of the search.
1633 // This is an accumulation of the file sizes of the different extents
1634 // of a single file.
1640 // Short name for this file.
1644 WCHAR ShortNameBuffer
[ BYTE_COUNT_8_DOT_3
/ sizeof( WCHAR
) ];
1647 // Array of compound dirents.
1650 COMPOUND_DIRENT Dirents
[3];
1652 } FILE_ENUM_CONTEXT
;
1653 typedef FILE_ENUM_CONTEXT
*PFILE_ENUM_CONTEXT
;
1655 #define FILE_CONTEXT_MULTIPLE_DIRENTS (0x00000001)
1659 // RIFF header. Prepended to the data of a file containing XA sectors.
1660 // This is a hard-coded structure except that we bias the 'ChunkSize' and
1661 // 'RawSectors' fields with the file size. We also copy the attributes flag
1662 // from the system use area in the dirent. We always initialize this
1663 // structure by copying the XAFileHeader.
1666 typedef struct _RIFF_HEADER
{
1670 ULONG SignatureCDXA
;
1678 ULONG SignatureData
;
1682 typedef RIFF_HEADER
*PRIFF_HEADER
;
1685 // Audio play header for CDDA tracks.
1688 typedef struct _AUDIO_PLAY_HEADER
{
1692 ULONG SignatureCDDA
;
1698 ULONG StartingSector
;
1700 UCHAR TrackAddress
[4];
1701 UCHAR TrackLength
[4];
1703 } AUDIO_PLAY_HEADER
;
1704 typedef AUDIO_PLAY_HEADER
*PAUDIO_PLAY_HEADER
;
1708 // Some macros for supporting the use of a Generic Table
1709 // containing all the FCB/DCBs and indexed by their FileId.
1713 // The HighPart contains the path table offset of this directory in the
1716 // The LowPart contains zero except for the upper bit which is
1717 // set to indicate that this is a directory.
1721 // The HighPart contains the path table offset of the parent directory
1722 // in the path table.
1724 // The LowPart contains the byte offset of the dirent in the parent
1727 // A directory is always entered into the Fcb Table as if it's
1728 // dirent offset was zero. This enables any child to look in the FcbTable
1729 // for it's parent by searching with the same HighPart but with zero
1730 // as the value for LowPart.
1732 // The Id field is a LARGE_INTEGER where the High and Low parts can be
1733 // accessed separately.
1735 // The following macros are used to access the Fid fields.
1737 // CdQueryFidDirentOffset - Accesses the Dirent offset field
1738 // CdQueryFidPathTableNumber - Accesses the PathTable offset field
1739 // CdSetFidDirentOffset - Sets the Dirent offset field
1740 // CdSetFidPathTableNumber - Sets the PathTable ordinal field
1741 // CdFidIsDirectory - Queries if directory bit is set
1742 // CdFidSetDirectory - Sets directory bit
1745 #define FID_DIR_MASK 0x80000000 // high order bit means directory.
1747 #define CdQueryFidDirentOffset(I) ((I).LowPart & ~FID_DIR_MASK)
1748 #define CdQueryFidPathTableOffset(I) ((I).HighPart)
1749 #define CdSetFidDirentOffset(I,D) ((I).LowPart = D)
1750 #define CdSetFidPathTableOffset(I,P) ((I).HighPart = P)
1751 #define CdFidIsDirectory(I) FlagOn( (I).LowPart, FID_DIR_MASK )
1752 #define CdFidSetDirectory(I) SetFlag( (I).LowPart, FID_DIR_MASK )
1754 #define CdSetFidFromParentAndDirent(I,F,D) { \
1755 CdSetFidPathTableOffset( (I), CdQueryFidPathTableOffset( (F)->FileId )); \
1756 CdSetFidDirentOffset( (I), (D)->DirentOffset ); \
1757 if (FlagOn( (D)->DirentFlags, CD_ATTRIBUTE_DIRECTORY )) { \
1758 CdFidSetDirectory((I)); \