23#define BugCheckFileId (CDFS_BUG_CHECK_FSCTRL)
126CdScanForDismountedVcb (
157#pragma alloc_text(PAGE, CdCommonFsControl)
158#pragma alloc_text(PAGE, CdDismountVolume)
159#pragma alloc_text(PAGE, CdFindActiveVolDescriptor)
160#pragma alloc_text(PAGE, CdFindPrimaryVd)
161#pragma alloc_text(PAGE, CdIsPathnameValid)
162#pragma alloc_text(PAGE, CdIsRemount)
163#pragma alloc_text(PAGE, CdIsVolumeDirty)
164#pragma alloc_text(PAGE, CdIsVolumeMounted)
165#pragma alloc_text(PAGE, CdLockVolume)
166#pragma alloc_text(PAGE, CdMountVolume)
167#pragma alloc_text(PAGE, CdOplockRequest)
168#pragma alloc_text(PAGE, CdAllowExtendedDasdIo)
169#pragma alloc_text(PAGE, CdScanForDismountedVcb)
170#pragma alloc_text(PAGE, CdUnlockVolume)
171#pragma alloc_text(PAGE, CdUserFsctl)
172#pragma alloc_text(PAGE, CdVerifyVolume)
183CdLockVolumeInternal (
227 CdPurgeVolume( IrpContext,
Vcb,
FALSE );
272 (
Vcb->VcbCleanup == RemainingUserReferences) &&
336 Vcb->VolumeLockFileObject =
NULL;
392 Status = CdMountVolume( IrpContext,
Irp );
397 Status = CdVerifyVolume( IrpContext,
Irp );
459 Status = CdOplockRequest( IrpContext,
Irp );
464 Status = CdLockVolume( IrpContext,
Irp );
469 Status = CdUnlockVolume( IrpContext,
Irp );
474 Status = CdDismountVolume( IrpContext,
Irp );
494 Status = CdInvalidateVolumes( IrpContext,
Irp );
536#pragma prefast(suppress: 28175, "this is a filesystem driver, touching the vpb is allowed")
538 NewVcb->Vpb->RealDevice->Vpb = OldVcb->Vpb;
540 OldVcb->Vpb->RealDevice = NewVcb->Vpb->RealDevice;
541 OldVcb->TargetDeviceObject = DeviceObjectWeTalkTo;
548 Buffer = OldVcb->SectorCacheBuffer = NewVcb->SectorCacheBuffer;
549 NewVcb->SectorCacheBuffer =
NULL;
556 OldVcb->SecCacheChunks[
Index].BaseLbn = (
ULONG)-1;
640 ULONG TocTrackCount = 0;
641 ULONG TocDiskFlags = 0;
642 ULONG MediaChangeCount = 0;
648#ifdef CDFS_TELEMETRY_DATA
650 GUID VolumeCorrelationId = { 0 };
672#ifdef CDFS_TELEMETRY_DATA
686 IrpContext->RealDevice =
Vpb->RealDevice;
720 DeviceObjectWeTalkTo,
739 MediaChangeCount = 0;
753 DeviceObjectWeTalkTo,
811 CdScanForDismountedVcb( IrpContext );
823 FilesystemDeviceType,
866 DeviceObjectWeTalkTo,
910 DeviceObjectWeTalkTo,
928#ifdef CDFS_TELEMETRY_DATA
934 if (
NT_SUCCESS( IoVolumeDeviceToGuid(
Vcb->TargetDeviceObject, &VolumeGuid ))) {
947 if (
NT_SUCCESS( FsRtlVolumeDeviceToCorrelationId(
Vcb->TargetDeviceObject, &VolumeCorrelationId ) )) {
965 IrpContext->Vcb =
Vcb;
974 Vcb->Vpb->ReferenceCount += 1;
997 FoundPvd = CdFindPrimaryVd( IrpContext,
1070 ((
Vcb->CdromToc->LastTrack -
Vcb->CdromToc->FirstTrack) == 0)) {
1073 ((
Vcb->CdromToc->LastTrack -
Vcb->CdromToc->FirstTrack) == 0))) {
1095 if (
Vcb->SectorCacheIrp ==
NULL) {
1113 if (CdIsRemount( IrpContext,
Vcb, &OldVcb )) {
1126 DeviceObjectWeTalkTo);
1161 if (
Vcb->RootIndexFcb) {
1163 FileObjectToNotify =
Vcb->RootIndexFcb->FileObject;
1174 DeviceObjectWeTalkTo,
1193 Vcb->MaximumPhysicalPages = 16;
1219 if (CdromToc !=
NULL) {
1228 if (RawIsoVd !=
NULL) {
1238 SetDoVerifyOnFail) {
1255 IrpContext->Vcb =
NULL;
1259 if (CdDismountVcb( IrpContext,
Vcb )) {
1264 }
else if (VolDo !=
NULL) {
1280 if (FileObjectToNotify) {
1286#ifdef CDFS_TELEMETRY_DATA
1341 ULONG TocLength = 0;
1342 ULONG TocTrackCount = 0;
1343 ULONG TocDiskFlags = 0;
1345 ULONG MediaChangeCount =
Vcb->MediaChangeCount;
1358 ULONG VolumeLabelLength;
1378 IrpContext->RealDevice =
Vpb->RealDevice;
1408 Vcb->TargetDeviceObject,
1430 if (
Iosb.Information !=
sizeof(
ULONG)) {
1436 MediaChangeCount = 0;
1444 if (MediaChangeCount == 0 ||
1445 (
Vcb->MediaChangeCount != MediaChangeCount)) {
1462 Vcb->TargetDeviceObject,
1493 }
else if ((
Vcb->TocLength != TocLength) ||
1494 (
Vcb->TrackCount != TocTrackCount) ||
1495 (
Vcb->DiskFlags != TocDiskFlags) ||
1525 ReturnError =
FALSE;
1532 if (!CdFindPrimaryVd( IrpContext,
1594 UnicodeLabel.
Buffer = VolumeLabel;
1601 VolumeLabelLength = 0;
1607 VolumeLabelLength = UnicodeLabel.
Length;
1619 (
PCHAR) VolumeLabel );
1632 if ((VolumeLabel[
Index - 1 ] !=
L'\0') &&
1633 (VolumeLabel[
Index - 1 ] !=
L' ')) {
1650 if ((
Vpb->VolumeLabelLength != VolumeLabelLength) ||
1653 VolumeLabelLength )) {
1678 FileObjectToNotify =
Vcb->RootIndexFcb->FileObject;
1712 Vcb->XADiskOffset = 0;
1715 CdFreeDirCache( IrpContext);
1722 if (
Vcb->VcbCleanup == 0) {
1726 ReleaseVcb = CdCheckForDismount( IrpContext,
Vcb,
FALSE );
1737 if (CdromToc !=
NULL) {
1742 if (RawIsoVd !=
NULL) {
1762 if (FileObjectToNotify) {
1810 ULONG OplockCount = 0;
1819 if (CdDecodeFileObject( IrpContext,
1854#if (NTDDI_VERSION >= NTDDI_WIN7)
1855 OplockCount = (
ULONG) FsRtlAreThereCurrentOrInProgressFileLocks(
Fcb->
FileLock );
2239#if (NTDDI_VERSION >= NTDDI_WIN8)
2241 FsRtlDismountComplete(
Vcb->TargetDeviceObject,
Status );
2302 if (
Irp->AssociatedIrp.SystemBuffer !=
NULL) {
2348 Irp->IoStatus.Information =
sizeof(
ULONG );
2457CdInvalidateVolumes (
2530#if defined(_WIN64) && BUILD_WOW64_ENABLED
2532 if (IoIs32bitProcess(
Irp )) {
2560 (
PVOID*)&FileToMarkBad,
2573 DeviceToMarkBad = FileToMarkBad->DeviceObject;
2612 Links = Links->
Flink;
2621 if (
Vcb->Vpb->RealDevice == DeviceToMarkBad) {
2632#pragma prefast(suppress: 28175, "this is a filesystem driver, touching the vpb is allowed")
2634 if (DeviceToMarkBad->Vpb ==
Vcb->Vpb) {
2648#pragma prefast(push)
2649#pragma prefast(disable: 28175, "this is a filesystem driver, touching the vpb is allowed")
2652 DeviceToMarkBad->Vpb = NewVpb;
2671 CdPurgeVolume( IrpContext,
Vcb,
FALSE );
2673 UnlockVcb = CdCheckForDismount( IrpContext,
Vcb,
FALSE );
2763CdScanForDismountedVcb (
2803 Links = Links->
Flink;
2814 CdCheckForDismount( IrpContext,
Vcb,
FALSE );
2913 while (!FoundVd && (ThisPass <= 2)) {
2922 if (ThisPass == 1) {
2948 Vcb->TargetDeviceObject,
2983 Dest = (
PCHAR) &BaseSector;
2996 BaseSector /= BlockFactor;
3044 (
BOOLEAN) ((ThisPass == 1) || ReturnOnError),
3046 Vcb->TargetDeviceObject )) {
3099 if (!VerifyVolume) {
3112 Vcb->BaseSector = BaseSector;
3215 if (
Vcb == *OldVcb) {
continue; }
3221 OldVpb = (*OldVcb)->Vpb;
3223 if ((OldVpb !=
Vpb) &&
3241 if ((
Vcb->TocLength != (*OldVcb)->TocLength) ||
3242 ((
Vcb->TocLength != 0) &&
3244 (*OldVcb)->CdromToc,
3245 Vcb->TocLength ))) {
3261 (
Vcb->TocLength == (*OldVcb)->TocLength) &&
3263 (*OldVcb)->CdromToc,
3264 Vcb->TocLength )) &&
3268 Vpb->VolumeLabelLength ))) {
3360 Vcb->TargetDeviceObject );
3390 if (!VerifyVolume) {
3402 FoundSecondaryVd =
TRUE;
3418 if (!FoundSecondaryVd) {
3459 Vcb->Vpb->VolumeLabelLength = 0;
3492 if ((
Vcb->Vpb->VolumeLabel[
Index - 1 ] !=
L'\0') &&
3493 (
Vcb->Vpb->VolumeLabel[
Index - 1 ] !=
L' ')) {
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define STATUS_PRIVILEGE_NOT_HELD
#define CdRvdVersion(R, F)
#define CdRvdDescType(R, F)
VOID CdCompleteRequest(_Inout_opt_ PIRP_CONTEXT IrpContext, _Inout_opt_ PIRP Irp, _In_ NTSTATUS Status)
ULONG CdSerial32(_In_reads_bytes_(ByteCount) PCHAR Buffer, _In_ ULONG ByteCount)
#define CDFS_RESIDUAL_USER_REFERENCE
#define CDFS_RESIDUAL_REFERENCE
NTSTATUS CdIsPathnameValid(_Inout_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp)
VOID CdFindActiveVolDescriptor(_In_ PIRP_CONTEXT IrpContext, _In_ PVCB Vcb, _Inout_updates_bytes_(ROUND_TO_PAGES(SECTOR_SIZE)) PCHAR RawIsoVd, _In_ BOOLEAN VerifyVolume)
NTSTATUS CdUnlockVolumeInternal(_In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb, _In_opt_ PFILE_OBJECT FileObject)
NTSTATUS CdAllowExtendedDasdIo(_Inout_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp)
NTSTATUS CdIsVolumeMounted(_Inout_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp)
NTSTATUS CdIsVolumeDirty(_Inout_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp)
VOID CdReMountOldVcb(_In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB OldVcb, _Inout_ PVCB NewVcb, _In_ PDEVICE_OBJECT DeviceObjectWeTalkTo)
#define CdUpdateMediaChangeCount(V, C)
#define CdAcquireCdData(IC)
VOID CdFspClose(_In_opt_ PVCB Vcb)
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN TypeOfOpen
#define CdAcquireFcbShared(IC, F, I)
#define CdUpdateVcbCondition(V, C)
VOID CdConvertBigToLittleEndian(_In_ PIRP_CONTEXT IrpContext, _In_reads_bytes_(ByteCount) PCHAR BigEndian, _In_ ULONG ByteCount, _Out_writes_bytes_(ByteCount) PCHAR LittleEndian)
#define CdReleaseVcb(IC, V)
#define CdReleaseFcb(IC, F)
VOID CdVerifyVcb(_In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb)
#define CdTelemetryMountSafe(...)
#define CdGetFcbOplock(F)
#define CdRealDevNeedsVerify(DO)
#define CdReleaseCdData(IC)
VOID CdInitializeVcb(_In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb, _In_ __drv_aliasesMem PDEVICE_OBJECT TargetDeviceObject, _In_ __drv_aliasesMem PVPB Vpb, _In_ __drv_aliasesMem PCDROM_TOC_LARGE CdromToc, _In_ ULONG TocLength, _In_ ULONG TocTrackCount, _In_ ULONG TocDiskFlags, _In_ ULONG BlockFactor, _In_ ULONG MediaChangeCount)
#define CdMarkRealDevVerifyOk(DO)
#define CdUnlockVcb(IC, V)
#define LlBytesFromSectors(L)
BOOLEAN CdReadSectors(_In_ PIRP_CONTEXT IrpContext, _In_ LONGLONG StartingOffset, _In_ ULONG ByteCount, _In_ BOOLEAN ReturnError, _Out_writes_bytes_(ByteCount) PVOID Buffer, _In_ PDEVICE_OBJECT TargetDeviceObject)
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
#define CdAcquireVcbExclusive(IC, V, I)
BOOLEAN CdVerifyFcbOperation(_In_opt_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb)
#define CdMarkRealDevForVerify(DO)
#define CdAcquireFcbExclusive(IC, F, I)
NTSTATUS CdProcessToc(_In_ PIRP_CONTEXT IrpContext, _In_ PDEVICE_OBJECT TargetDeviceObject, _In_ PCDROM_TOC_LARGE CdromToc, _Inout_ PULONG Length, _Out_ PULONG TrackCount, _Inout_ PULONG DiskFlags)
enum _TYPE_OF_OPEN TYPE_OF_OPEN
NTSTATUS FASTCALL CdPerformDevIoCtrl(_In_ PIRP_CONTEXT IrpContext, _In_ ULONG IoControlCode, _In_ PDEVICE_OBJECT Device, _Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer, _In_ ULONG OutputBufferLength, _In_ BOOLEAN InternalDeviceIoControl, _In_ BOOLEAN OverrideVerify, _Out_opt_ PIO_STATUS_BLOCK Iosb)
#define CdIsRawDevice(IC, S)
#define CdIsFastIoPossible(F)
VOID CdUpdateVcbFromVolDescriptor(_In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb, _In_reads_bytes_opt_(SECTOR_SIZE) PCHAR RawIsoVd)
#define CdUnlockFcb(IC, F)
#define CdRaiseStatus(IC, S)
#define IOCTL_DISK_CHECK_VERIFY
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
#define CCB_FLAG_ALLOW_EXTENDED_DASD_IO
#define IRP_CONTEXT_FLAG_FORCE_POST
#define CCB_FLAG_DISMOUNT_ON_CLOSE
#define CD_FLAGS_SHUTDOWN
#define VCB_STATE_VPB_NOT_ON_DEVICE
#define IRP_CONTEXT_FLAG_WAIT
#define VCB_STATE_AUDIO_DISK
VOLUME_DEVICE_OBJECT * PVOLUME_DEVICE_OBJECT
#define CD_SEC_CACHE_CHUNKS
#define VCB_STATE_DISMOUNTED
#define CD_SEC_CHUNK_BLOCKS
#define IRP_CONTEXT_FLAG_DISABLE_POPUPS
#define VCB_STATE_NOTIFY_REMOUNT
#define _Analysis_assume_lock_not_held_(lock)
#define _Requires_lock_held_(lock)
#define _Analysis_suppress_lock_checking_(lock)
#define NT_SUCCESS(StatCode)
_In_ PIO_STACK_LOCATION IrpSp
NTSTATUS ExInitializeResourceLite(PULONG res)
struct _DEVICE_OBJECT * PDEVICE_OBJECT
#define KeInitializeEvent(pEvt, foo, foo2)
#define DO_DEVICE_INITIALIZING
#define InitializeListHead(ListHead)
#define KeInitializeSpinLock(sl)
#define ClearFlag(_F, _SF)
#define BooleanFlagOn(F, SF)
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
IN PVCB IN FAT_VOLUME_STATE VolumeState
#define FsRtlAreThereCurrentFileLocks(FL)
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
POBJECT_TYPE IoFileObjectType
#define Add2Ptr(PTR, INC)
#define RtlEqualMemory(dst, src, len)
NTSTATUS NTAPI CcWaitForCurrentLazyWriterActivity(VOID)
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
_Use_decl_annotations_ NTSTATUS NTAPI RtlOemToUnicodeN(_Out_ PWCHAR UnicodeString, _In_ ULONG UnicodeSize, _Out_opt_ PULONG ResultSize, _In_ PCCH OemString, _In_ ULONG OemSize)
#define _Inout_updates_bytes_(s)
#define _Out_writes_bytes_(s)
#define FSCTL_OPLOCK_BREAK_NOTIFY
#define FSCTL_LOCK_VOLUME
#define FSCTL_OPLOCK_BREAK_ACKNOWLEDGE
#define FSCTL_REQUEST_OPLOCK_LEVEL_1
#define FSCTL_REQUEST_FILTER_OPLOCK
#define FSCTL_INVALIDATE_VOLUMES
#define FSCTL_IS_PATHNAME_VALID
#define FSCTL_UNLOCK_VOLUME
#define FSCTL_REQUEST_BATCH_OPLOCK
#define FSCTL_OPBATCH_ACK_CLOSE_PENDING
#define FSCTL_OPLOCK_BREAK_ACK_NO_2
#define FSCTL_IS_VOLUME_MOUNTED
#define FSCTL_REQUEST_OPLOCK_LEVEL_2
#define FSCTL_DISMOUNT_VOLUME
#define UNREFERENCED_PARAMETER(P)
#define IOCTL_CDROM_GET_LAST_SESSION
#define IOCTL_CDROM_CHECK_VERIFY
#define CDROM_DISK_AUDIO_TRACK
#define IOCTL_CDROM_GET_DRIVE_GEOMETRY
_In_ ULONG _In_ ULONG _In_ ULONG Length
#define FSRTL_VOLUME_UNLOCK
#define FSRTL_VOLUME_LOCK
#define FSRTL_VOLUME_DISMOUNT
#define FSRTL_VOLUME_MOUNT
#define VPB_REMOVE_PENDING
#define FSRTL_VOLUME_LOCK_FAILED
PVOID NTAPI FsRtlAllocatePool(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes)
PVOID NTAPI FsRtlAllocatePoolWithTag(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes, IN ULONG Tag)
NTSTATUS NTAPI FsRtlNotifyVolumeEvent(IN PFILE_OBJECT FileObject, IN ULONG EventCode)
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
VOID NTAPI IoInitializeIrp(IN PIRP Irp, IN USHORT PacketSize, IN CCHAR StackSize)
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
VOID NTAPI IoReleaseVpbSpinLock(IN KIRQL Irql)
VOID NTAPI IoAcquireVpbSpinLock(OUT PKIRQL Irql)
BOOLEAN NTAPI SeSinglePrivilegeCheck(_In_ LUID PrivilegeValue, _In_ KPROCESSOR_MODE PreviousMode)
Checks if a single privilege is present in the context of the calling thread.
#define STATUS_SYSTEM_SHUTDOWN
#define STATUS_VOLUME_DISMOUNTED
#define STATUS_NOT_LOCKED
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
NTSTATUS NTAPI FsRtlOplockFsctrl(IN POPLOCK Oplock, IN PIRP Irp, IN ULONG OpenCount)
#define FILE_DEVICE_DISK_FILE_SYSTEM
#define FSCTL_IS_VOLUME_DIRTY
#define FILE_DEVICE_CD_ROM
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
#define _SEH2_AbnormalTermination()
#define FSCTL_ALLOW_EXTENDED_DASD_IO
#define IOCTL_SCSI_GET_CAPABILITIES
NTSTATUS NTAPI RtlOemStringToCountedUnicodeString(IN OUT PUNICODE_STRING UniDest, IN PCOEM_STRING OemSource, IN BOOLEAN AllocateDestinationString)
#define __analysis_assert(e)
TRACK_DATA TrackData[MAXIMUM_NUMBER_TRACKS_LARGE]
PDRIVER_OBJECT DriverObject
PDEVICE_OBJECT FileSystemDeviceObject
ULONG AlignmentRequirement
PDEVICE_OBJECT DeviceObject
struct _IO_STACK_LOCATION::@3979::@3994 FileSystemControl
union _IO_STACK_LOCATION::@1580 Parameters
struct _IO_STACK_LOCATION::@3979::@4000 VerifyVolume
struct _IO_STACK_LOCATION::@3979::@3999 MountVolume
struct _LIST_ENTRY * Flink
struct _FCB * RootIndexFcb
VCB_CONDITION VcbCondition
__volatile LONG PostedRequestCount
DEVICE_OBJECT DeviceObject
KSPIN_LOCK OverflowQueueSpinLock
WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH/sizeof(WCHAR)]
struct _DEVICE_OBJECT * RealDevice
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define CONTAINING_RECORD(address, type, field)
#define STATUS_INVALID_DEVICE_REQUEST
#define STATUS_ACCESS_DENIED
#define STATUS_INVALID_PARAMETER
#define STATUS_UNRECOGNIZED_VOLUME
#define STATUS_WRONG_VOLUME
#define STATUS_INVALID_USER_BUFFER
#define STATUS_DEVICE_BUSY
#define STATUS_INSUFFICIENT_RESOURCES
static int Link(const char **args)
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
#define IoSizeOfIrp(_StackSize)
#define IRP_MN_VERIFY_VOLUME
#define IRP_MN_USER_FS_REQUEST
#define SL_ALLOW_RAW_MOUNT
#define MAXIMUM_VOLUME_LABEL_LENGTH
#define IRP_MN_MOUNT_VOLUME
#define ROUND_TO_PAGES(Size)
#define ObDereferenceObject
#define ObReferenceObject