Sample Code
windows driver samples/ cdfs file system driver/ C++/ devctrl.c/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | /*++ Copyright (c) 1989-2000 Microsoft Corporation Module Name: DevCtrl.c Abstract: This module implements the File System Device Control routines for Cdfs called by the dispatch driver. --*/ #include "CdProcs.h" // // The Bug check file id for this module // #define BugCheckFileId (CDFS_BUG_CHECK_DEVCTRL) // // Local support routines // // Tell prefast this is a completion routine IO_COMPLETION_ROUTINE CdDevCtrlCompletionRoutine; NTSTATUS CdDevCtrlCompletionRoutine ( _In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_reads_opt_(_Inexpressible_( "varies" )) PVOID Contxt ); #ifdef ALLOC_PRAGMA #pragma alloc_text(PAGE, CdCommonDevControl) #endif
NTSTATUS CdCommonDevControl ( _Inout_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp ) /*++ Routine Description: Arguments: Return Value: --*/ { NTSTATUS Status; TYPE_OF_OPEN TypeOfOpen; PFCB Fcb; PCCB Ccb; PIO_STACK_LOCATION IrpSp; PIO_STACK_LOCATION NextIrpSp; PAGED_CODE(); // // Extract and decode the file object. // IrpSp = IoGetCurrentIrpStackLocation( Irp ); TypeOfOpen = CdDecodeFileObject( IrpContext, IrpSp->FileObject, &Fcb, &Ccb ); // // The only type of opens we accept are user volume opens. // if (TypeOfOpen != UserVolumeOpen) { CdCompleteRequest( IrpContext, Irp, STATUS_INVALID_PARAMETER ); return STATUS_INVALID_PARAMETER; } if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_CDROM_READ_TOC) { // // Verify the Vcb in this case to detect if the volume has changed. // CdVerifyVcb( IrpContext, Fcb->Vcb ); // // Handle the case of the disk type ourselves. // } else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_CDROM_DISK_TYPE) { // // Verify the Vcb in this case to detect if the volume has changed. // CdVerifyVcb( IrpContext, Fcb->Vcb ); // // Check the size of the output buffer. // if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength < sizeof ( CDROM_DISK_DATA )) { CdCompleteRequest( IrpContext, Irp, STATUS_BUFFER_TOO_SMALL ); return STATUS_BUFFER_TOO_SMALL; } // // Copy the data from the Vcb. // ((PCDROM_DISK_DATA) Irp->AssociatedIrp.SystemBuffer)->DiskData = Fcb->Vcb->DiskFlags; Irp->IoStatus.Information = sizeof ( CDROM_DISK_DATA ); CdCompleteRequest( IrpContext, Irp, STATUS_SUCCESS ); return STATUS_SUCCESS; } // // Get the next stack location, and copy over the stack parameter // information. // NextIrpSp = IoGetNextIrpStackLocation( Irp ); *NextIrpSp = *IrpSp; // // Set up the completion routine // IoSetCompletionRoutine( Irp, CdDevCtrlCompletionRoutine, NULL, TRUE, TRUE, TRUE ); // // Send the request. // Status = IoCallDriver( IrpContext->Vcb->TargetDeviceObject, Irp ); // // Cleanup our Irp Context. The driver has completed the Irp. // CdCompleteRequest( IrpContext, NULL, STATUS_SUCCESS ); return Status; }
// // Local support routine // NTSTATUS CdDevCtrlCompletionRoutine ( _In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_reads_opt_(_Inexpressible_( "varies" )) PVOID Contxt ) { // // Add the hack-o-ramma to fix formats. // if (Irp->PendingReturned) { IoMarkIrpPending( Irp ); } return STATUS_SUCCESS; UNREFERENCED_PARAMETER( DeviceObject ); UNREFERENCED_PARAMETER( Contxt ); } |
Our Services
-
What our customers say about us?
Read our customer testimonials to find out why our clients keep returning for their projects.
View Testimonials