1 ////////////////////////////////////////////////////////////////////
2 // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
4 // This file was released under the GPLv2 on June 2015.
5 ////////////////////////////////////////////////////////////////////
6 #ifndef __UDF_COMMON_STRUCT__H__
7 #define __UDF_COMMON_STRUCT__H__
9 typedef enum _UDFFSD_MEDIA_TYPE
{
21 #define MAX_UDFFSD_MEDIA_TYPE ((ULONG)MediaFloppy)
23 typedef struct _UDF_KEY_LIST
{
25 } UDF_KEY_LIST
, *PUDF_KEY_LIST
;
27 struct UDF_MEDIA_CLASS_NAMES
29 UDFFSD_MEDIA_TYPE MediaClass
;
33 extern struct UDF_MEDIA_CLASS_NAMES UDFMediaClassName
[];
35 #define MAX_ANCHOR_LOCATIONS 11
36 #define MAX_SPARING_TABLE_LOCATIONS 32
38 typedef struct _UDFVolumeControlBlock
{
40 #ifdef _UDF_STRUCTURES_H_
52 UDFIdentifier NodeIdentifier
;
53 // compatibility field
54 PtrUDFNTRequiredFCB NTRequiredFCB
;
55 // UDF related data (compatibility field)
57 // this FCB belongs to some mounted logical volume
58 // (compatibility field - pointer to itself)
59 struct _UDFVolumeControlBlock
* Vcb
;
60 // a global list of all FCB structures associated with the VCB
62 // some state information for the FCB is maintained using the
65 // all CCB's for this particular FCB are linked off the following
67 // For volume open operations, we do not create a FCB (we use the VCB
68 // directly instead). Therefore, all CCB structures for the volume
69 // open operation are linked directly off the VCB
70 LIST_ENTRY VolumeOpenListHead
; // CCB
71 // A count of the number of open files/directories
72 // As long as the count is != 0, the volume cannot
73 // be dismounted or locked.
74 uint32 VolumeOpenCount
;
79 ERESOURCE CcbListResource
;
81 struct _UDFFileControlBlock
* ParentFcb
;
82 // Pointer to IrpContextLite in delayed queue.
83 struct _UDFIrpContextLite
* IrpContextLite
;
94 uint32 VCBOpenCountRO
;
95 uint32 VCBHandleCount
;
96 // a resource to protect the fields contained within the VCB
97 ERESOURCE FcbListResource
;
98 ERESOURCE FlushResource
;
99 // each VCB is accessible off a global linked list
101 // each VCB points to a VPB structure created by the NT I/O Manager
103 // we will maintain a global list of IRP's that are pending
104 // because of a directory notify request.
105 LIST_ENTRY NextNotifyIRP
;
106 // the above list is protected only by the mutex declared below
107 PNOTIFY_SYNC NotifyIRPMutex
;
108 // for each mounted volume, we create a device object. Here then
109 // is a back pointer to that device object
110 PDEVICE_OBJECT VCBDeviceObject
;
111 BOOLEAN ShutdownRegistered
;
112 // We also retain a pointer to the physical device object on which we
113 // have mounted ourselves. The I/O Manager passes us a pointer to this
114 // device object when requesting a mount operation.
115 PDEVICE_OBJECT TargetDeviceObject
;
116 UNICODE_STRING TargetDevName
;
117 PWSTR DefaultRegName
;
118 // the volume structure contains a pointer to the root directory FCB
119 PtrUDFFCB RootDirFCB
;
120 // the complete name of the user visible drive letter we serve
121 PUCHAR PtrVolumePath
;
122 // Pointer to a stream file object created for the volume information
123 // to be more easily read from secondary storage (with the support of
124 // the NT Cache Manager).
125 /* PFILE_OBJECT PtrStreamFileObject;
126 // Required to use the Cache Manager.
128 struct _FILE_SYSTEM_STATISTICS
* Statistics
;
129 // Volume lock file object - used in Lock/Unlock routines
131 PFILE_OBJECT VolumeLockFileObject
;
132 DEVICE_TYPE FsDeviceType
;
134 // The following field tells how many requests for this volume have
135 // either been enqueued to ExWorker threads or are currently being
136 // serviced by ExWorker threads. If the number goes above
137 // a certain threshold, put the request on the overflow queue to be
139 ULONG PostedRequestCount
;
141 // The following field indicates the number of IRP's waiting
142 // to be serviced in the overflow queue.
143 ULONG OverflowQueueCount
;
144 // The following field contains the queue header of the overflow queue.
145 // The Overflow queue is a list of IRP's linked via the IRP's ListEntry
147 LIST_ENTRY OverflowQueue
;
148 // The following spinlock protects access to all the above fields.
149 KSPIN_LOCK OverflowQueueSpinLock
;
150 ULONG StopOverflowQueue
;
151 ULONG SystemCacheGran
;
157 // Eject Request waiter
158 struct _UDFEjectWaitContext
* EjectWaiter
;
159 KEVENT WaiterStopped
;
164 ULONG Tree_FlushTime
;
165 ULONG Tree_FlushPriod
;
166 ULONG SkipCountLimit
;
167 ULONG SkipEjectCountLimit
;
169 /* // XP CD Burner related data
170 UNICODE_STRING CDBurnerVolume;
171 BOOLEAN CDBurnerVolumeValid;
173 // Background writes counter
176 struct _UDFFileIDCacheItem
* FileIdCache
;
179 ULONG MediaLockCount
;
181 BOOLEAN IsVolumeJustMounted
;
189 PUDF_FILE_INFO RootFileInfo
;
193 #ifdef UDF_FORMAT_MEDIA
194 struct _UDFFmtState
* fms
;
195 #endif //UDF_FORMAT_MEDIA
198 PDEVICE_OBJECT TargetDeviceObject
;
202 #endif //_UDF_STRUCTURES_H_
205 LONGLONG TotalAllocUnits
;
206 LONGLONG FreeAllocUnits
;
207 LONGLONG EstimatedFreeUnits
;
209 // a resource to protect the fields contained within the VCB
210 ERESOURCE VCBResource
;
211 ERESOURCE BitMapResource1
;
212 ERESOURCE FileIdResource
;
213 ERESOURCE DlocResource
;
214 ERESOURCE DlocResource2
;
215 ERESOURCE PreallocResource
;
216 ERESOURCE IoResource
;
219 // Physical media parameters
224 ULONG WriteBlockSize
;
226 ULONG LBlockSizeBits
;
228 // Number of last session
231 ULONG FirstTrackNumLastSes
;
233 // First & Last LBA of the last session
235 ULONG FirstLBALastSes
;
238 ULONG LastPossibleLBA
;
239 // First writable LBA
242 struct _UDFTrackMap
* TrackMap
;
243 ULONG LastModifiedTrack
;
245 ULONG CdrwBufferSize
;
246 ULONG CdrwBufferSizeCounter
;
247 uint32 SavedFeatures
;
258 UCHAR PhMediaCapFlags
;
265 ULONG PhSerialNumber
;
268 SET_CD_SPEED_EX_USER_IN SpeedBuf
;
275 BOOLEAN WriteParamsReq
;
277 #define SYNC_CACHE_RECOVERY_NONE 0
278 #define SYNC_CACHE_RECOVERY_ATTEMPT 1
279 #define SYNC_CACHE_RECOVERY_RETRY 2
281 UCHAR SyncCacheState
;
285 ULONG WCacheMaxFrames
;
286 ULONG WCacheMaxBlocks
;
287 ULONG WCacheBlocksPerFrameSh
;
288 ULONG WCacheFramesToKeepFree
;
293 PSEND_OPC_INFO_HEADER_USER_IN OPCh
;
294 PGET_WRITE_MODE_USER_OUT WParams
;
295 PGET_LAST_ERROR_USER_OUT Error
;
297 ULONG IoErrorCounter
;
298 // Media change count (equal to the same field in CDFS VCB)
299 ULONG MediaChangeCount
;
301 #define INCREMENTAL_SEEK_NONE 0
302 #define INCREMENTAL_SEEK_WORKAROUND 1
303 #define INCREMENTAL_SEEK_DONE 2
305 UCHAR IncrementalSeekState
;
307 BOOLEAN VerifyOnWrite
;
308 BOOLEAN DoNotCompareBeforeWrite
;
309 BOOLEAN CacheChainedIo
;
311 ULONG MountPhErrorCount
;
313 // a set of flags that might mean something useful
324 ULONG Anchor
[MAX_ANCHOR_LOCATIONS
];
325 ULONG BadSeqLoc
[MAX_ANCHOR_LOCATIONS
*2];
326 OSSTATUS BadSeqStatus
[MAX_ANCHOR_LOCATIONS
*2];
327 ULONG BadSeqLocIndex
;
329 UNICODE_STRING VolIdent
;
330 // Volume creation time
331 int64 VolCreationTime
;
332 // Root & SystemStream lb_addr
334 lb_addr SysStreamLbAddr
;
335 // Number of partition
337 // Pointer to partition structures
338 PUDFPartMap Partitions
;
339 LogicalVolIntegrityDesc
*LVid
;
340 uint32 IntegrityType
;
341 uint32 origIntegrityType
;
344 // on-disk structure version control
345 uint16 CurrentUDFRev
;
346 uint16 minUDFReadRev
;
347 uint16 minUDFWriteRev
;
348 uint16 maxUDFWriteRev
;
349 // file/dir counters for Mac OS
357 PUDF_FILE_INFO VatFileInfo
;
359 ULONG SparingCountFree
;
361 ULONG SparingBlockSize
;
362 struct _SparingEntry
* SparingTable
;
363 uint32 SparingTableLoc
[MAX_SPARING_TABLE_LOCATIONS
];
364 uint32 SparingTableCount
;
365 uint32 SparingTableLength
;
366 uint32 SparingTableModified
;
368 ULONG FSBM_ByteCount
;
369 // the following 2 fields are equal to NTIFS's RTL_BITMAP structure
371 PCHAR FSBM_Bitmap
; // 0 - free, 1 - used
372 #ifdef UDF_TRACK_ONDISK_ALLOCATION_OWNERS
373 PULONG FSBM_Bitmap_owners
; // 0 - free
374 // -1 - used by unknown
375 // other - owner's FE location
376 #ifdef UDF_TRACK_FS_STRUCTURES
377 PEXTENT_MAP FsStructMap
;
378 PULONG FE_link_counts
; // 0 - free
379 #endif //UDF_TRACK_FS_STRUCTURES
380 #endif //UDF_TRACK_ONDISK_ALLOCATION_OWNERS
382 PCHAR FSBM_OldBitmap
; // 0 - free, 1 - used
383 ULONG BitmapModified
;
385 PCHAR ZSBM_Bitmap
; // 0 - data, 1 - zero-filleld
386 #endif //_BROWSE_UDF_
388 PCHAR BSBM_Bitmap
; // 0 - normal, 1 - bad-block
391 // pointers to Volume Descriptor Sequences
400 PUDF_FILE_INFO SysSDirFileInfo
;
402 PUDF_FILE_INFO NonAllocFileInfo
;
404 PUDF_FILE_INFO UniqueIDMapFileInfo
;
405 // Saved location of Primary Vol Descr (used for setting Label)
406 UDF_VDS_RECORD PVolDescAddr
;
407 UDF_VDS_RECORD PVolDescAddr2
;
411 ULONGLONG NextUniqueId
;
413 PUDF_DATALOC_INDEX DlocList
;
416 USHORT DefaultAllocMode
; // Default alloc mode (from registry)
417 BOOLEAN UseExtendedFE
;
418 BOOLEAN LowFreeSpace
;
419 UDFFSD_MEDIA_TYPE MediaTypeEx
;
422 ULONG DefaultAttr
; // Default file attributes (NT-style)
425 UCHAR PartitialDamagedVolumeAction
;
426 BOOLEAN NoFreeRelocationSpaceVolumeAction
;
427 BOOLEAN WriteSecurity
;
429 BOOLEAN ForgetVolume
;
435 ULONG PackDirThreshold
;
436 ULONG SparseThreshold
; // in blocks
438 PUDF_ALLOCATION_CACHE_ITEM FEChargeCache
;
439 ULONG FEChargeCacheMaxSize
;
441 PUDF_ALLOCATION_CACHE_ITEM PreallocCache
;
442 ULONG PreallocCacheMaxSize
;
444 UDF_VERIFY_CTX VerifyCtx
;
450 #endif //_BROWSE_UDF_
458 // some valid flags for the VCB
459 #define UDF_VCB_FLAGS_VOLUME_MOUNTED (0x00000001)
460 #define UDF_VCB_FLAGS_VOLUME_LOCKED (0x00000002)
461 #define UDF_VCB_FLAGS_BEING_DISMOUNTED (0x00000004)
462 #define UDF_VCB_FLAGS_SHUTDOWN (0x00000008)
463 #define UDF_VCB_FLAGS_VOLUME_READ_ONLY (0x00000010)
465 #define UDF_VCB_FLAGS_VCB_INITIALIZED (0x00000020)
466 #define UDF_VCB_FLAGS_OUR_DEVICE_DRIVER (0x00000040)
467 #define UDF_VCB_FLAGS_NO_SYNC_CACHE (0x00000080)
468 #define UDF_VCB_FLAGS_REMOVABLE_MEDIA (0x00000100)
469 #define UDF_VCB_FLAGS_MEDIA_LOCKED (0x00000200)
470 #define UDF_VCB_SKIP_EJECT_CHECK (0x00000400)
471 //#define UDF_VCB_FS_BITMAP_MODIFIED (0x00000800) // moved to separate flag
472 #define UDF_VCB_LAST_WRITE (0x00001000)
473 #define UDF_VCB_FLAGS_TRACKMAP (0x00002000)
474 #define UDF_VCB_ASSUME_ALL_USED (0x00004000)
476 #define UDF_VCB_FLAGS_RAW_DISK (0x00040000)
477 #define UDF_VCB_FLAGS_USE_STD (0x00080000)
479 #define UDF_VCB_FLAGS_STOP_WAITER_EVENT (0x00100000)
480 #define UDF_VCB_FLAGS_NO_DELAYED_CLOSE (0x00200000)
481 #define UDF_VCB_FLAGS_MEDIA_READ_ONLY (0x00400000)
483 #define UDF_VCB_FLAGS_FLUSH_BREAK_REQ (0x01000000)
484 #define UDF_VCB_FLAGS_EJECT_REQ (0x02000000)
485 #define UDF_VCB_FLAGS_FORCE_SYNC_CACHE (0x04000000)
487 #define UDF_VCB_FLAGS_USE_CAV (0x08000000)
488 #define UDF_VCB_FLAGS_UNSAFE_IOCTL (0x10000000)
489 #define UDF_VCB_FLAGS_DEAD (0x20000000) // device unexpectedly disappeared
492 // flags for FS Interface Compatibility
493 #define UDF_VCB_IC_UPDATE_ACCESS_TIME (0x00000001)
494 #define UDF_VCB_IC_UPDATE_MODIFY_TIME (0x00000002)
495 #define UDF_VCB_IC_UPDATE_ATTR_TIME (0x00000004)
496 #define UDF_VCB_IC_UPDATE_ARCH_BIT (0x00000008)
497 #define UDF_VCB_IC_UPDATE_DIR_WRITE (0x00000010)
498 #define UDF_VCB_IC_UPDATE_DIR_READ (0x00000020)
499 #define UDF_VCB_IC_WRITE_IN_RO_DIR (0x00000040)
500 #define UDF_VCB_IC_UPDATE_UCHG_DIR_ACCESS_TIME (0x00000080)
501 #define UDF_VCB_IC_W2K_COMPAT_ALLOC_DESCS (0x00000100)
502 #define UDF_VCB_IC_HW_RO (0x00000200)
503 #define UDF_VCB_IC_OS_NATIVE_DOS_NAME (0x00000400)
504 #define UDF_VCB_IC_FORCE_WRITE_THROUGH (0x00000800)
505 #define UDF_VCB_IC_FORCE_HW_RO (0x00001000)
506 #define UDF_VCB_IC_IGNORE_SEQUENTIAL_IO (0x00002000)
507 #define UDF_VCB_IC_NO_SYNCCACHE_AFTER_WRITE (0x00004000)
508 #define UDF_VCB_IC_BAD_RW_SEEK (0x00008000)
509 #define UDF_VCB_IC_FP_ADDR_PROBLEM (0x00010000)
510 #define UDF_VCB_IC_MRW_ADDR_PROBLEM (0x00020000)
511 #define UDF_VCB_IC_BAD_DVD_LAST_LBA (0x00040000)
512 #define UDF_VCB_IC_SYNCCACHE_BEFORE_READ (0x00080000)
513 #define UDF_VCB_IC_INSTANT_COMPAT_ALLOC_DESCS (0x00100000)
514 #define UDF_VCB_IC_SOFT_RO (0x00200000)
516 #define UDF_VCB_IC_DIRTY_RO (0x04000000)
517 #define UDF_VCB_IC_W2K_COMPAT_VLABEL (0x08000000)
518 #define UDF_VCB_IC_CACHE_BAD_VDS (0x10000000)
519 #define UDF_VCB_IC_WAIT_CD_SPINUP (0x20000000)
520 #define UDF_VCB_IC_SHOW_BLANK_CD (0x40000000)
521 #define UDF_VCB_IC_ADAPTEC_NONALLOC_COMPAT (0x80000000)
524 #define UDFIsDvdMedia(Vcb) (Vcb->DVD_Mode)
525 #define UDFIsWriteParamsReq(Vcb) (Vcb->WriteParamsReq && !Vcb->DVD_Mode)
527 /**************************************************************************
528 we will store all of our global variables in one structure.
529 Global variables are not specific to any mounted volume BUT
530 by definition are required for successful operation of the
532 **************************************************************************/
533 typedef struct _UDFData
{
535 #ifdef _UDF_STRUCTURES_H_
536 UDFIdentifier NodeIdentifier
;
537 // the fields in this list are protected by the following resource
538 ERESOURCE GlobalDataResource
;
539 // each driver has a driver object created for it by the NT I/O Mgr.
540 // we are no exception to this rule.
541 PDRIVER_OBJECT DriverObject
;
542 // we will create a device object for our FSD as well ...
543 // Although not really required, it helps if a helper application
544 // writen by us wishes to send us control information via
545 // IOCTL requests ...
546 PDEVICE_OBJECT UDFDeviceObject
;
547 PDEVICE_OBJECT UDFDeviceObject_CD
;
548 PDEVICE_OBJECT UDFDeviceObject_HDD
;
549 PDEVICE_OBJECT UDFDeviceObject_TAPE
;
550 PDEVICE_OBJECT UDFDeviceObject_OTHER
;
551 PDEVICE_OBJECT UDFFilterDeviceObject
;
552 // we will keep a list of all logical volumes for our UDF FSD
554 // the NT Cache Manager, the I/O Manager and we will conspire
555 // to bypass IRP usage using the function pointers contained
556 // in the following structure
557 FAST_IO_DISPATCH UDFFastIoDispatch
;
558 // The NT Cache Manager uses the following call backs to ensure
559 // correct locking hierarchy is maintained
560 CACHE_MANAGER_CALLBACKS CacheMgrCallBacks
;
561 // structures allocated from a zone need some fields here. Note
562 // that under version 4.0, it might be better to use lookaside
564 KSPIN_LOCK ZoneAllocationSpinLock
;
565 ZONE_HEADER ObjectNameZoneHeader
;
566 ZONE_HEADER CCBZoneHeader
;
567 ZONE_HEADER FCBZoneHeader
;
568 ZONE_HEADER IrpContextZoneHeader
;
569 // ZONE_HEADER FileInfoZoneHeader;
570 VOID
*ObjectNameZone
;
573 VOID
*IrpContextZone
;
574 // VOID *FileInfoZone;
575 // currently, there is a single default zone size value used for
576 // all zones. This should ideally be changed by you to be 1 per
577 // type of zone (e.g. a default size for the FCB zone might be
578 // different from the default size for the ByteLock zone).
580 #ifdef EVALUATION_TIME_LIMIT
581 UDF_KEY_LIST CurrentKeyHash
;
582 #endif //EVALUATION_TIME_LIMIT
583 // Of course, you will need to use different values (min/max)
584 // for lookaside lists (if you decide to use them instead)
585 uint32 DefaultZoneSizeInNumStructs
;
586 // Handle returned by the MUP is stored here.
589 // ERESOURCE IsSyncResource;
590 // Is operation synchronous flag
592 #ifdef EVALUATION_TIME_LIMIT
594 #endif //EVALUATION_TIME_LIMIT
596 // delayed close support
597 ERESOURCE DelayedCloseResource
;
598 ULONG MaxDelayedCloseCount
;
599 ULONG DelayedCloseCount
;
600 ULONG MinDelayedCloseCount
;
601 ULONG MaxDirDelayedCloseCount
;
602 ULONG DirDelayedCloseCount
;
603 ULONG MinDirDelayedCloseCount
;
604 LIST_ENTRY DelayedCloseQueue
;
605 LIST_ENTRY DirDelayedCloseQueue
;
606 WORK_QUEUE_ITEM CloseItem
;
607 WORK_QUEUE_ITEM LicenseKeyItem
;
608 BOOLEAN LicenseKeyItemStarted
;
609 BOOLEAN FspCloseActive
;
610 BOOLEAN ReduceDelayedClose
;
611 BOOLEAN ReduceDirDelayedClose
;
613 #ifdef EVALUATION_TIME_LIMIT
614 LARGE_INTEGER UDFCurrentTime
;
615 #endif //EVALUATION_TIME_LIMIT
617 LARGE_INTEGER UDFLargeZero
;
619 // mount event (for udf gui app)
622 #ifdef EVALUATION_TIME_LIMIT
623 WCHAR LicenseKeyW
[16+1];
625 #endif //EVALUATION_TIME_LIMIT
627 #endif //_UDF_STRUCTURES_H_
629 UNICODE_STRING SavedRegPath
;
630 UNICODE_STRING UnicodeStrRoot
;
631 UNICODE_STRING UnicodeStrSDir
;
632 UNICODE_STRING AclName
;
633 // WCHAR UnicodeStrRootBuffer[2];
634 #ifdef EVALUATION_TIME_LIMIT
638 #endif //EVALUATION_TIME_LIMIT
640 ULONG WCacheMaxFrames
;
641 ULONG WCacheMaxBlocks
;
642 ULONG WCacheBlocksPerFrameSh
;
643 ULONG WCacheFramesToKeepFree
;
645 #ifdef EVALUATION_TIME_LIMIT
646 UCHAR Page2Padding
[PAGE_SIZE
];
647 #endif //EVALUATION_TIME_LIMIT
649 // some state information is maintained in the flags field
652 PVOID AutoFormatCount
;
654 } UDFData
, *PtrUDFData
;
656 // valid flag values for the global data structure
657 #define UDF_DATA_FLAGS_RESOURCE_INITIALIZED (0x00000001)
658 #define UDF_DATA_FLAGS_ZONES_INITIALIZED (0x00000002)
659 #define UDF_DATA_FLAGS_BEING_UNLOADED (0x00000004)
660 #define UDF_DATA_FLAGS_UNREGISTERED (0x00000008)
664 extern VOID
UDFSetModified(
668 extern VOID
UDFPreClrModified(
672 extern VOID
UDFClrModified(
677 #define FILE_ID_CACHE_GRANULARITY 16
678 #define DLOC_LIST_GRANULARITY 16
680 typedef LONGLONG FILE_ID
;
681 typedef FILE_ID
*PFILE_ID
;
683 #endif //__UDF_COMMON_STRUCT__H__