ReactOS  0.4.13-dev-544-gede3fdd
deviosup.c File Reference
#include "cdprocs.h"
Include dependency graph for deviosup.c:

Go to the source code of this file.

Classes

struct  _IO_RUN
 

Macros

#define BugCheckFileId   (CDFS_BUG_CHECK_DEVIOSUP)
 
#define MAX_PARALLEL_IOS   5
 

Typedefs

typedef struct _IO_RUN IO_RUN
 
typedef IO_RUNPIO_RUN
 

Functions

 _Requires_lock_held_ (_Global_critical_region_)
 
__inline TRACK_MODE_TYPE CdFileTrackMode (_In_ PFCB Fcb)
 
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)
 
NTSTATUS CdCreateUserMdl (_In_ PIRP_CONTEXT IrpContext, _In_ ULONG BufferLength, _In_ BOOLEAN RaiseOnError, _In_ LOCK_OPERATION Operation)
 
NTSTATUS CdPerformDevIoCtrlEx (_In_ PIRP_CONTEXT IrpContext, _In_ ULONG IoControlCode, _In_ PDEVICE_OBJECT Device, _In_reads_bytes_opt_(InputBufferLength) PVOID InputBuffer, _In_ ULONG InputBufferLength, _Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer, _In_ ULONG OutputBufferLength, _In_ BOOLEAN InternalDeviceIoControl, _In_ BOOLEAN OverrideVerify, _Out_opt_ PIO_STATUS_BLOCK Iosb)
 
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)
 
BOOLEAN CdFinishBuffers (_In_ PIRP_CONTEXT IrpContext, _Inout_ PIO_RUN IoRuns, _In_ ULONG RunCount, _In_ BOOLEAN FinalCleanup, _In_ BOOLEAN SaveXABuffer)
 
NTSTATUS NTAPI CdSyncCompletionRoutine (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Contxt)
 
VOID CdMultipleXAAsync (_In_ PIRP_CONTEXT IrpContext, _In_ ULONG RunCount, _Inout_ PIO_RUN IoRuns, _In_ PRAW_READ_INFO RawReads, _In_ TRACK_MODE_TYPE TrackMode)
 
VOID CdWaitSync (_In_ PIRP_CONTEXT IrpContext)
 
NTSTATUS NTAPI CdMultiSyncCompletionRoutine (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
 
NTSTATUS NTAPI CdMultiAsyncCompletionRoutine (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
 
NTSTATUS NTAPI CdSingleSyncCompletionRoutine (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
 
NTSTATUS NTAPI CdSingleAsyncCompletionRoutine (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
 
 _When_ (SafeNodeType(Fcb) !=CDFS_NTC_FCB_PATH_TABLE &&StartingOffset==0, _At_(ByteCount, _In_range_(>=, CdAudioDirentSize+sizeof(RAW_DIRENT))))
 
NTSTATUS CdHijackIrpAndFlushDevice (_In_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp, _In_ PDEVICE_OBJECT TargetDeviceObject)
 

Variables

IO_COMPLETION_ROUTINE CdSyncCompletionRoutine
 

Macro Definition Documentation

◆ BugCheckFileId

#define BugCheckFileId   (CDFS_BUG_CHECK_DEVIOSUP)

Definition at line 22 of file deviosup.c.

◆ MAX_PARALLEL_IOS

#define MAX_PARALLEL_IOS   5

Definition at line 96 of file deviosup.c.

Typedef Documentation

◆ IO_RUN

◆ PIO_RUN

typedef IO_RUN* PIO_RUN

Definition at line 94 of file deviosup.c.

Function Documentation

◆ _Requires_lock_held_()

_Requires_lock_held_ ( _Global_critical_region_  )

Definition at line 102 of file deviosup.c.

243 {
244  PAGED_CODE();
245 
246  Blocks += 150; // Lbn 0 == 00:02:00, 1sec == 75 frames.
247 
248  Msf[0] = (UCHAR)(Blocks % 75); // Frames
249  Blocks /= 75; // -> Seconds
250  Msf[1] = (UCHAR)(Blocks % 60); // Seconds
251  Blocks /= 60; // -> Minutes
252  Msf[2] = (UCHAR)Blocks; // Minutes
253 }
#define PAGED_CODE()
Definition: video.h:57
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by _Requires_lock_held_().

◆ _When_()

Definition at line 3785 of file deviosup.c.

3821 {
3822  PRAW_PATH_ISO RawPath;
3823  PRAW_DIRENT RawDirent;
3824 
3825  ULONG CurrentTrack;
3827  ULONG EntryCount;
3828  UCHAR TrackOnes;
3829  UCHAR TrackTens;
3830  PTRACK_DATA ThisTrack;
3831 
3832  LONGLONG CurrentOffset;
3833 
3834  PVOID CurrentSector;
3835 
3836  PSYSTEM_USE_XA SystemUse;
3837 
3839 
3840  UCHAR LocalBuffer[FIELD_OFFSET( RAW_DIRENT, FileId ) + 12];
3841 
3842  PAGED_CODE();
3843 
3844  //
3845  // If this is the path table then we just need a single entry.
3846  //
3847 
3849 
3850  //
3851  // Sanity check that the offset is zero.
3852  //
3853 
3854  NT_ASSERT( StartingOffset == 0 );
3855 
3856  //
3857  // Store a pseudo path entry in our local buffer.
3858  //
3859 
3860  RawPath = (PRAW_PATH_ISO) LocalBuffer;
3861 
3862  RtlZeroMemory( RawPath, sizeof( LocalBuffer ));
3863 
3864  RawPath->DirIdLen = 1;
3865  RawPath->ParentNum = 1;
3866  RawPath->DirId[0] = '\0';
3867 
3868  //
3869  // Now copy to the user's buffer.
3870  //
3871 
3872  BytesToCopy = FIELD_OFFSET( RAW_PATH_ISO, DirId ) + 2;
3873 
3874  if (BytesToCopy > ByteCount) {
3875 
3877  }
3878 
3879  RtlCopyMemory( SystemBuffer,
3880  RawPath,
3881  BytesToCopy );
3882 
3883  //
3884  // We need to deal with the multiple sector case for the root directory.
3885  //
3886 
3887  } else {
3888 
3889  //
3890  // Initialize the first track to return to our caller.
3891  //
3892 
3893  CurrentTrack = 0;
3894 
3895  //
3896  // If the offset is zero then store the entries for the self and parent
3897  // entries.
3898  //
3899 
3900  if (StartingOffset == 0) {
3901 
3902  RawDirent = SystemBuffer;
3903 
3904  //
3905  // Clear all of the fields initially.
3906  //
3907 
3908  RtlZeroMemory( RawDirent, FIELD_OFFSET( RAW_DIRENT, FileId ));
3909 
3910  //
3911  // Now fill in the interesting fields.
3912  //
3913 
3914  RawDirent->DirLen = FIELD_OFFSET( RAW_DIRENT, FileId ) + 1;
3915  RawDirent->FileIdLen = 1;
3916  RawDirent->FileId[0] = '\0';
3917  SetFlag( RawDirent->FlagsISO, CD_ATTRIBUTE_DIRECTORY );
3918 
3919  //
3920  // Set the time stamp to be Jan 1, 1995
3921  //
3922 
3923  RawDirent->RecordTime[0] = 95;
3924  RawDirent->RecordTime[1] = 1;
3925  RawDirent->RecordTime[2] = 1;
3926 
3927  SectorOffset = RawDirent->DirLen;
3928 
3929  RawDirent = Add2Ptr( RawDirent, SectorOffset, PRAW_DIRENT );
3930 
3931  //
3932  // Clear all of the fields initially.
3933  //
3934 
3935  RtlZeroMemory( RawDirent, FIELD_OFFSET( RAW_DIRENT, FileId ));
3936 
3937  //
3938  // Now fill in the interesting fields.
3939  //
3940 
3941  RawDirent->DirLen = FIELD_OFFSET( RAW_DIRENT, FileId ) + 1;
3942  RawDirent->FileIdLen = 1;
3943  RawDirent->FileId[0] = '\1';
3944  SetFlag( RawDirent->FlagsISO, CD_ATTRIBUTE_DIRECTORY );
3945 
3946  //
3947  // Set the time stamp to be Jan 1, 1995
3948  //
3949 
3950  RawDirent->RecordTime[0] = 95;
3951  RawDirent->RecordTime[1] = 1;
3952  RawDirent->RecordTime[2] = 1;
3953 
3954  SectorOffset += RawDirent->DirLen;
3955  EntryCount = 2;
3956 
3957  //
3958  // Otherwise compute the starting track to write to the buffer.
3959  //
3960 
3961  } else {
3962 
3963  //
3964  // Count the tracks in each preceding sector.
3965  //
3966 
3967  CurrentOffset = 0;
3968 
3969  do {
3970 
3971  CurrentTrack += CdAudioDirentsPerSector;
3972  CurrentOffset += SECTOR_SIZE;
3973 
3974  } while (CurrentOffset < StartingOffset);
3975 
3976  //
3977  // Bias the track count to reflect the two default entries.
3978  //
3979 
3980  CurrentTrack -= 2;
3981 
3982  SectorOffset = 0;
3983  EntryCount = 0;
3984  }
3985 
3986  //
3987  // We now know the first track to return as well as where we are in
3988  // the current sector. We will walk through sector by sector adding
3989  // the entries for the separate tracks in the TOC. We will zero
3990  // any sectors or partial sectors without data.
3991  //
3992 
3993  CurrentSector = SystemBuffer;
3995 
3996  //
3997  // Loop for each sector.
3998  //
3999 
4000  do {
4001 
4002  //
4003  // Add entries until we reach our threshold for each sector.
4004  //
4005 
4006  do {
4007 
4008  //
4009  // If we are beyond the entries in the TOC then exit.
4010  //
4011 
4012  if (CurrentTrack >= IrpContext->Vcb->TrackCount) {
4013 
4014  break;
4015  }
4016 
4017  ThisTrack = &IrpContext->Vcb->CdromToc->TrackData[CurrentTrack];
4018 
4019  //
4020  // Point to the current position in the buffer.
4021  //
4022 
4023  RawDirent = Add2Ptr( CurrentSector, SectorOffset, PRAW_DIRENT );
4024 
4025  //
4026  // Clear all of the fields initially.
4027  //
4028 
4029  RtlZeroMemory( RawDirent, CdAudioDirentSize );
4030 
4031  //
4032  // Now fill in the interesting fields.
4033  //
4034 
4035  RawDirent->DirLen = (UCHAR) CdAudioDirentSize;
4036  RawDirent->FileIdLen = CdAudioFileNameLength;
4037 
4038  RtlCopyMemory( RawDirent->FileId,
4041 
4042  //
4043  // Set the time stamp to be Jan 1, 1995 00:00
4044  //
4045 
4046  RawDirent->RecordTime[0] = 95;
4047  RawDirent->RecordTime[1] = 1;
4048  RawDirent->RecordTime[2] = 1;
4049 
4050  //
4051  // Put the track number into the file name.
4052  //
4053 
4054  TrackTens = TrackOnes = ThisTrack->TrackNumber;
4055 
4056  TrackOnes = (TrackOnes % 10) + '0';
4057 
4058  TrackTens /= 10;
4059  TrackTens = (TrackTens % 10) + '0';
4060 
4061  RawDirent->FileId[AUDIO_NAME_TENS_OFFSET] = TrackTens;
4062  RawDirent->FileId[AUDIO_NAME_ONES_OFFSET] = TrackOnes;
4063 
4064  SystemUse = Add2Ptr( RawDirent, CdAudioSystemUseOffset, PSYSTEM_USE_XA );
4065 
4066  SystemUse->Attributes = SYSTEM_USE_XA_DA;
4067  SystemUse->Signature = SYSTEM_XA_SIGNATURE;
4068 
4069  //
4070  // Store the track number as the file number.
4071  //
4072 
4073  SystemUse->FileNumber = (UCHAR) CurrentTrack;
4074 
4075  EntryCount += 1;
4077  CurrentTrack += 1;
4078 
4079  } while (EntryCount < CdAudioDirentsPerSector);
4080 
4081  //
4082  // Zero the remaining portion of this buffer.
4083  //
4084 
4085  RtlZeroMemory( Add2Ptr( CurrentSector, SectorOffset, PVOID ),
4087 
4088  //
4089  // Prepare for the next sector.
4090  //
4091 
4092  EntryCount = 0;
4094  SectorOffset = 0;
4095  CurrentSector = Add2Ptr( CurrentSector, SECTOR_SIZE, PVOID );
4096 
4097  } while (BytesToCopy <= ByteCount);
4098  }
4099 
4100  return;
4101 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
UCHAR DirLen
Definition: cd.h:332
USHORT Attributes
Definition: cd.h:493
#define Add2Ptr(PTR, INC)
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:282
#define SafeNodeType(Ptr)
Definition: nodetype.h:54
#define AUDIO_NAME_TENS_OFFSET
Definition: cddata.h:81
#define SYSTEM_USE_XA_DA
Definition: cd.h:518
ULONG CdAudioDirentSize
Definition: cddata.c:78
#define CDFS_NTC_FCB_PATH_TABLE
Definition: nodetype.h:29
#define PAGED_CODE()
Definition: video.h:57
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
RAW_PATH_ISO * PRAW_PATH_ISO
Definition: cd.h:428
UCHAR FileIdLen
Definition: cd.h:345
#define SECTOR_SIZE
Definition: winldr.h:34
USHORT ParentNum
Definition: cd.h:424
#define CD_ATTRIBUTE_DIRECTORY
Definition: cd.h:354
USHORT Signature
Definition: cd.h:499
ULONG CdAudioSystemUseOffset
Definition: cddata.c:80
#define SectorOffset(L)
Definition: cdprocs.h:1632
CHAR CdAudioFileName[]
Definition: cddata.c:76
UCHAR FileId[MAX_FILE_ID_LENGTH]
Definition: cd.h:346
int64_t LONGLONG
Definition: typedefs.h:66
ULONG CdAudioDirentsPerSector
Definition: cddata.c:79
#define SYSTEM_XA_SIGNATURE
Definition: cd.h:520
unsigned char UCHAR
Definition: xmlstorage.h:181
UCHAR RecordTime[6]
Definition: cd.h:338
UCHAR CdAudioFileNameLength
Definition: cddata.c:77
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1060
#define AUDIO_NAME_ONES_OFFSET
Definition: cddata.h:80
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
UCHAR TrackNumber
Definition: ntddcdrm.h:106
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
UCHAR FlagsISO
Definition: cd.h:340
_In_ PFCB Fcb
Definition: cdprocs.h:151
UCHAR DirIdLen
Definition: cd.h:421
UCHAR FileNumber
Definition: cd.h:505
UCHAR DirId[MAX_FILE_ID_LENGTH]
Definition: cd.h:425
#define NT_ASSERT
Definition: rtlfuncs.h:3312

◆ CdCreateUserMdl()

NTSTATUS CdCreateUserMdl ( _In_ PIRP_CONTEXT  IrpContext,
_In_ ULONG  BufferLength,
_In_ BOOLEAN  RaiseOnError,
_In_ LOCK_OPERATION  Operation 
)

Definition at line 1221 of file deviosup.c.

1255 {
1257  PMDL Mdl;
1258 
1259  PAGED_CODE();
1260 
1262  UNREFERENCED_PARAMETER( IrpContext );
1263 
1264  ASSERT_IRP_CONTEXT( IrpContext );
1265  ASSERT_IRP( IrpContext->Irp );
1266  NT_ASSERT( IrpContext->Irp->MdlAddress == NULL );
1267 
1268  //
1269  // Allocate the Mdl, and Raise if we fail.
1270  //
1271 
1272  Mdl = IoAllocateMdl( IrpContext->Irp->UserBuffer,
1273  BufferLength,
1274  FALSE,
1275  FALSE,
1276  IrpContext->Irp );
1277 
1278  if (Mdl != NULL) {
1279 
1280  //
1281  // Now probe the buffer described by the Irp. If we get an exception,
1282  // deallocate the Mdl and return the appropriate "expected" status.
1283  //
1284 
1285  _SEH2_TRY {
1286 
1287  MmProbeAndLockPages( Mdl, IrpContext->Irp->RequestorMode, IoWriteAccess );
1288 
1290 
1291 #ifdef _MSC_VER
1292 #pragma warning(suppress: 6320)
1293 #endif
1295 
1297 
1298  IoFreeMdl( Mdl );
1299  IrpContext->Irp->MdlAddress = NULL;
1300 
1301  if (!FsRtlIsNtstatusExpected( Status )) {
1302 
1304  }
1305  } _SEH2_END;
1306  }
1307 
1308  //
1309  // Check if we are to raise or return
1310  //
1311 
1312  if (Status != STATUS_SUCCESS) {
1313 
1314  if (RaiseOnError) {
1315 
1316  CdRaiseStatus( IrpContext, Status );
1317  }
1318  }
1319 
1320  //
1321  // Return the status code.
1322  //
1323 
1324  return Status;
1325 }
BOOLEAN NTAPI FsRtlIsNtstatusExpected(IN NTSTATUS NtStatus)
Definition: filter.c:61
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define ASSERT_IRP_CONTEXT(IC)
Definition: cddata.h:249
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define STATUS_INVALID_USER_BUFFER
Definition: udferr_usr.h:166
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
Status
Definition: gdiplustypes.h:24
#define ASSERT_IRP(I)
Definition: cddata.h:251
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
_SEH2_END
Definition: create.c:4424
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
#define CdRaiseStatus(IC, S)
Definition: cdprocs.h:1869
_Inout_ PFCB _In_ BOOLEAN RaiseOnError
Definition: cdprocs.h:1214
_In_ FLT_SET_CONTEXT_OPERATION Operation
Definition: fltkernel.h:1468
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2777
#define NT_ASSERT
Definition: rtlfuncs.h:3312

◆ CdFileTrackMode()

__inline TRACK_MODE_TYPE CdFileTrackMode ( _In_ PFCB  Fcb)

Definition at line 258 of file deviosup.c.

278 {
282 
284 
285  return XAForm2;
286 
287  } else if (FlagOn( Fcb->FcbState, FCB_STATE_DA_FILE )) {
288 
289  return CDDA;
290 
291  }
292 
293  //
294  // FCB_STATE_MODE2_FILE
295  //
296 
297  return YellowMode2;
298 }
#define FCB_STATE_MODE2FORM2_FILE
Definition: cdstruc.h:1050
#define FCB_STATE_DA_FILE
Definition: cdstruc.h:1052
Definition: ntddcdrm.h:348
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define FCB_STATE_MODE2_FILE
Definition: cdstruc.h:1051
_In_ PFCB Fcb
Definition: cdprocs.h:151
ULONG FcbState
Definition: cdstruc.h:977
#define NT_ASSERT
Definition: rtlfuncs.h:3312

◆ CdFinishBuffers()

BOOLEAN CdFinishBuffers ( _In_ PIRP_CONTEXT  IrpContext,
_Inout_ PIO_RUN  IoRuns,
_In_ ULONG  RunCount,
_In_ BOOLEAN  FinalCleanup,
_In_ BOOLEAN  SaveXABuffer 
)

Definition at line 2219 of file deviosup.c.

2263 {
2264  BOOLEAN FlushIoBuffers = FALSE;
2265 
2266  ULONG RemainingEntries = RunCount;
2267  PIO_RUN ThisIoRun = &IoRuns[RunCount - 1];
2268  PVCB Vcb;
2269 
2270  PAGED_CODE();
2271 
2272  //
2273  // Walk through each entry in the IoRun array.
2274  //
2275 
2276  while (RemainingEntries != 0) {
2277 
2278  //
2279  // We only need to deal with the case of an unaligned transfer.
2280  //
2281 
2282  if (ThisIoRun->TransferByteCount != 0) {
2283 
2284  //
2285  // If not the final cleanup then transfer the data to the
2286  // user's buffer and remember that we will need to flush
2287  // the user's buffer to memory.
2288  //
2289 
2290  if (!FinalCleanup) {
2291 
2292  RtlCopyMemory( ThisIoRun->UserBuffer,
2293  Add2Ptr( ThisIoRun->TransferBuffer,
2294  ThisIoRun->TransferBufferOffset,
2295  PVOID ),
2296  ThisIoRun->TransferByteCount );
2297 
2298  FlushIoBuffers = TRUE;
2299  }
2300 
2301  //
2302  // Free any Mdl we may have allocated. If the Mdl isn't
2303  // present then we must have failed during the allocation
2304  // phase.
2305  //
2306 
2307  if (ThisIoRun->TransferMdl != IrpContext->Irp->MdlAddress) {
2308 
2309  if (ThisIoRun->TransferMdl != NULL) {
2310 
2311  IoFreeMdl( ThisIoRun->TransferMdl );
2312  }
2313 
2314  //
2315  // Now free any buffer we may have allocated. If the Mdl
2316  // doesn't match the original Mdl then free the buffer.
2317  //
2318 
2319  if (ThisIoRun->TransferBuffer != NULL) {
2320 
2321  //
2322  // If this is the final buffer for an XA read then store this buffer
2323  // into the Vcb so that we will have it when reading any remaining
2324  // portion of this buffer.
2325  //
2326 
2327  if (SaveXABuffer) {
2328 
2329  Vcb = IrpContext->Vcb;
2330 
2331  CdLockVcb( IrpContext, Vcb );
2332 
2333  if (Vcb->XASector != NULL) {
2334 
2335  CdFreePool( &Vcb->XASector );
2336  }
2337 
2338  Vcb->XASector = ThisIoRun->TransferBuffer;
2339  Vcb->XADiskOffset = ThisIoRun->DiskOffset;
2340 
2341  SaveXABuffer = FALSE;
2342 
2343  CdUnlockVcb( IrpContext, Vcb );
2344 
2345  //
2346  // Otherwise just free the buffer.
2347  //
2348 
2349  } else {
2350 
2351  CdFreePool( &ThisIoRun->TransferBuffer );
2352  }
2353  }
2354  }
2355  }
2356 
2357  //
2358  // Now handle the case where we failed in the process
2359  // of allocating associated Irps and Mdls.
2360  //
2361 
2362  if (ThisIoRun->SavedIrp != NULL) {
2363 
2364  if (ThisIoRun->SavedIrp->MdlAddress != NULL) {
2365 
2366  IoFreeMdl( ThisIoRun->SavedIrp->MdlAddress );
2367  }
2368 
2369  IoFreeIrp( ThisIoRun->SavedIrp );
2370  }
2371 
2372  //
2373  // Move to the previous IoRun entry.
2374  //
2375 
2376  ThisIoRun -= 1;
2377  RemainingEntries -= 1;
2378  }
2379 
2380  //
2381  // If we copied any data then flush the Io buffers.
2382  //
2383 
2384  return FlushIoBuffers;
2385 }
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define Add2Ptr(PTR, INC)
Definition: cdstruc.h:504
#define PAGED_CODE()
Definition: video.h:57
ULONG TransferByteCount
Definition: deviosup.c:72
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
LONGLONG DiskOffset
Definition: deviosup.c:41
#define CdUnlockVcb(IC, V)
Definition: cdprocs.h:1033
#define Vcb
Definition: cdprocs.h:1425
PMDL TransferMdl
Definition: deviosup.c:84
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
#define CdLockVcb(IC, V)
Definition: cdprocs.h:1028
PVOID UserBuffer
Definition: deviosup.c:49
ULONG TransferBufferOffset
Definition: deviosup.c:73
PIRP SavedIrp
Definition: deviosup.c:91
#define CdFreePool(x)
Definition: cdprocs.h:2200
PVOID TransferBuffer
Definition: deviosup.c:71
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
unsigned int ULONG
Definition: retypes.h:1

◆ CdHijackIrpAndFlushDevice()

NTSTATUS CdHijackIrpAndFlushDevice ( _In_ PIRP_CONTEXT  IrpContext,
_Inout_ PIRP  Irp,
_In_ PDEVICE_OBJECT  TargetDeviceObject 
)

Definition at line 4105 of file deviosup.c.

4134 {
4135  KEVENT Event;
4136  NTSTATUS Status;
4137  PIO_STACK_LOCATION NextIrpSp;
4138 
4139  PAGED_CODE();
4140 
4141  UNREFERENCED_PARAMETER( IrpContext );
4142 
4143  //
4144  // Get the next stack location, and copy over the stack location
4145  //
4146 
4147  NextIrpSp = IoGetNextIrpStackLocation( Irp );
4148 
4149  *NextIrpSp = *IoGetCurrentIrpStackLocation( Irp );
4150 
4151  NextIrpSp->MajorFunction = IRP_MJ_FLUSH_BUFFERS;
4152  NextIrpSp->MinorFunction = 0;
4153 
4154  //
4155  // Set up the completion routine
4156  //
4157 
4159 
4162  &Event,
4163  TRUE,
4164  TRUE,
4165  TRUE );
4166 
4167  //
4168  // Send the request.
4169  //
4170 
4172 
4173  if (Status == STATUS_PENDING) {
4174 
4176 
4177  Status = Irp->IoStatus.Status;
4178  }
4179 
4180  //
4181  // If the driver doesn't support flushes, return SUCCESS.
4182  //
4183 
4185 
4187  }
4188 
4189  Irp->IoStatus.Status = 0;
4190  Irp->IoStatus.Information = 0;
4191 
4192  return Status;
4193 }
#define TRUE
Definition: types.h:120
#define IRP_MJ_FLUSH_BUFFERS
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_PENDING
Definition: ntstatus.h:82
#define VOID
Definition: acefi.h:82
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
IO_COMPLETION_ROUTINE CdSyncCompletionRoutine
Definition: deviosup.c:2388
IN OUT PVCB IN PDEVICE_OBJECT TargetDeviceObject
Definition: fatprocs.h:1664
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by _Requires_lock_held_().

◆ CdMultiAsyncCompletionRoutine()

NTSTATUS NTAPI CdMultiAsyncCompletionRoutine ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PVOID  Context 
)

Definition at line 3526 of file deviosup.c.

3561 {
3562  PCD_IO_CONTEXT IoContext = Context;
3565 
3567 
3568  //
3569  // If we got an error (or verify required), remember it in the Irp
3570  //
3571 
3572  if (!NT_SUCCESS( Irp->IoStatus.Status )) {
3573 
3574  InterlockedExchange( &IoContext->Status, Irp->IoStatus.Status );
3575  }
3576 
3577  //
3578  // Decrement IrpCount and see if it goes to zero.
3579  //
3580 
3581  if (InterlockedDecrement( &IoContext->IrpCount ) == 0) {
3582 
3583  //
3584  // Mark the master Irp pending
3585  //
3586 
3587  IoMarkIrpPending( IoContext->MasterIrp );
3588 
3589  //
3590  // Update the Master Irp with any error status from the associated Irps.
3591  //
3592 
3593  IoContext->MasterIrp->IoStatus.Status = IoContext->Status;
3594 
3595  //
3596  // Update the information field with the correct value.
3597  //
3598 
3599  IoContext->MasterIrp->IoStatus.Information = 0;
3600 
3601  if (NT_SUCCESS( IoContext->MasterIrp->IoStatus.Status )) {
3602 
3603  IoContext->MasterIrp->IoStatus.Information = IoContext->RequestedByteCount;
3604  }
3605 
3606  //
3607  // Now release the resource
3608  //
3609 
3611  ExReleaseResourceForThreadLite( IoContext->Resource, IoContext->ResourceThreadId );
3612 
3613  //
3614  // and finally, free the context record.
3615  //
3616 
3617  CdFreeIoContext( IoContext );
3618 
3619  //
3620  // Return success in this case.
3621  //
3622 
3623  return STATUS_SUCCESS;
3624 
3625  } else {
3626 
3627  //
3628  // We need to cleanup the associated Irp and its Mdl.
3629  //
3630 
3631  IoFreeMdl( Irp->MdlAddress );
3632  IoFreeIrp( Irp );
3633 
3635  }
3636 
3637 }
#define AssertVerifyDeviceIrp(I)
Definition: cdprocs.h:1821
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define _Analysis_assume_lock_held_(lock)
Definition: no_sal2.h:682
__volatile LONG IrpCount
Definition: cdstruc.h:1331
ULONG RequestedByteCount
Definition: cdstruc.h:1346
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
__volatile NTSTATUS Status
Definition: cdstruc.h:1333
PERESOURCE Resource
Definition: cdstruc.h:1344
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
#define CdFreeIoContext(IO)
Definition: cdprocs.h:1354
PIRP MasterIrp
Definition: cdstruc.h:1332
#define InterlockedDecrement
Definition: armddk.h:52
ERESOURCE_THREAD ResourceThreadId
Definition: cdstruc.h:1345
#define InterlockedExchange
Definition: armddk.h:54
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
struct tagContext Context
Definition: acpixf.h:1012
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
return STATUS_SUCCESS
Definition: btrfs.c:2777
IoMarkIrpPending(Irp)
#define _Analysis_assume_(expr)
Definition: no_sal2.h:10

◆ CdMultipleXAAsync()

VOID CdMultipleXAAsync ( _In_ PIRP_CONTEXT  IrpContext,
_In_ ULONG  RunCount,
_Inout_ PIO_RUN  IoRuns,
_In_ PRAW_READ_INFO  RawReads,
_In_ TRACK_MODE_TYPE  TrackMode 
)

Definition at line 3044 of file deviosup.c.

3096 {
3098  PMDL Mdl;
3099  PIRP Irp;
3100  PIRP MasterIrp;
3101  ULONG UnwindRunCount;
3102  ULONG RawByteCount;
3103 
3104  PIO_RUN ThisIoRun = IoRuns;
3105  PRAW_READ_INFO ThisRawRead = RawReads;
3106 
3107  PAGED_CODE();
3108 
3109  //
3110  // Initialize some local variables.
3111  //
3112 
3113  MasterIrp = IrpContext->Irp;
3114 
3115  //
3116  // Itterate through the runs, doing everything that can fail.
3117  // We let the cleanup in CdFinishBuffers clean up on error.
3118  //
3119 
3120  for (UnwindRunCount = 0;
3121  UnwindRunCount < RunCount;
3122  UnwindRunCount += 1, ThisIoRun += 1, ThisRawRead += 1) {
3123 
3124  //
3125  // Create an associated IRP, making sure there is one stack entry for
3126  // us, as well.
3127  //
3128 
3129  ThisIoRun->SavedIrp =
3130  Irp = IoMakeAssociatedIrp( MasterIrp, (CCHAR)(IrpContext->Vcb->TargetDeviceObject->StackSize + 1) );
3131 
3132  if (Irp == NULL) {
3133 
3134  IrpContext->Irp->IoStatus.Information = 0;
3136  }
3137 
3138  //
3139  // Should have been passed a byte count of at least one sector, and
3140  // must be a multiple of sector size
3141  //
3142 
3143  NT_ASSERT( ThisIoRun->DiskByteCount && !SectorOffset(ThisIoRun->DiskByteCount));
3144 
3145  RawByteCount = SectorsFromBytes( ThisIoRun->DiskByteCount) * RAW_SECTOR_SIZE;
3146 
3147  //
3148  // Allocate and build a partial Mdl for the request.
3149  //
3150 
3151  Mdl = IoAllocateMdl( ThisIoRun->TransferVirtualAddress,
3152  RawByteCount,
3153  FALSE,
3154  FALSE,
3155  Irp );
3156 
3157  if (Mdl == NULL) {
3158 
3159  IrpContext->Irp->IoStatus.Information = 0;
3161  }
3162 
3163  IoBuildPartialMdl( ThisIoRun->TransferMdl,
3164  Mdl,
3165  ThisIoRun->TransferVirtualAddress,
3166  RawByteCount);
3167  //
3168  // Get the first IRP stack location in the associated Irp
3169  //
3170 
3173 
3174  //
3175  // Setup the Stack location to describe our read (using cooked values)
3176  // These values won't be used for the raw read in any case.
3177  //
3178 
3180  IrpSp->Parameters.Read.Length = ThisIoRun->DiskByteCount;
3181  IrpSp->Parameters.Read.ByteOffset.QuadPart = ThisIoRun->DiskOffset;
3182 
3183  //
3184  // Set up the completion routine address in our stack frame.
3185  //
3186 
3189  IrpContext->IoContext,
3190  TRUE,
3191  TRUE,
3192  TRUE );
3193 
3194  //
3195  // Setup the next IRP stack location in the associated Irp for the disk
3196  // driver beneath us.
3197  //
3198 
3200 
3201  //
3202  // Setup the stack location to do a read of raw sectors at this location.
3203  // Note that the storage stack always reads multiples of whole XA sectors.
3204  //
3205 
3206  ThisRawRead->DiskOffset.QuadPart = ThisIoRun->DiskOffset;
3207  ThisRawRead->SectorCount = ThisIoRun->DiskByteCount >> SECTOR_SHIFT;
3208  ThisRawRead->TrackMode = TrackMode;
3209 
3211 
3212  IrpSp->Parameters.DeviceIoControl.OutputBufferLength = ThisRawRead->SectorCount * RAW_SECTOR_SIZE;
3213  Irp->UserBuffer = ThisIoRun->TransferVirtualAddress;
3214 
3215  IrpSp->Parameters.DeviceIoControl.InputBufferLength = sizeof( RAW_READ_INFO );
3216  IrpSp->Parameters.DeviceIoControl.Type3InputBuffer = ThisRawRead;
3217 
3218  IrpSp->Parameters.DeviceIoControl.IoControlCode = IOCTL_CDROM_RAW_READ;
3219  }
3220 
3221  //
3222  // We only need to set the associated IRP count in the master irp to
3223  // make it a master IRP. But we set the count to one more than our
3224  // caller requested, because we do not want the I/O system to complete
3225  // the I/O. We also set our own count.
3226  //
3227 
3228  IrpContext->IoContext->IrpCount = RunCount;
3229  IrpContext->IoContext->MasterIrp = MasterIrp;
3230 
3231  //
3232  // We set the count in the master Irp to 1 since typically we
3233  // will clean up the associated irps ourselves. Setting this to one
3234  // means completing the last associated Irp with SUCCESS (in the async
3235  // case) will complete the master irp.
3236  //
3237 
3238  MasterIrp->AssociatedIrp.IrpCount = 1;
3239 
3240  //
3241  // Now that all the dangerous work is done, issue the Io requests
3242  //
3243 
3244  for (UnwindRunCount = 0;
3245  UnwindRunCount < RunCount;
3246  UnwindRunCount++) {
3247 
3248  Irp = IoRuns[UnwindRunCount].SavedIrp;
3249  IoRuns[UnwindRunCount].SavedIrp = NULL;
3250 
3251  //
3252  //
3253  // If IoCallDriver returns an error, it has completed the Irp
3254  // and the error will be caught by our completion routines
3255  // and dealt with as a normal IO error.
3256  //
3257 
3258  (VOID) IoCallDriver( IrpContext->Vcb->TargetDeviceObject, Irp );
3259  }
3260 
3261  return;
3262 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
#define SECTOR_SHIFT
Definition: cd.h:32
ULONG SectorCount
Definition: ntddcdrm.h:353
#define PAGED_CODE()
Definition: video.h:57
#define IOCTL_CDROM_RAW_READ
Definition: ntddcdrm.h:64
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
VOID NTAPI IoBuildPartialMdl(IN PMDL SourceMdl, IN PMDL TargetMdl, IN PVOID VirtualAddress, IN ULONG Length)
Definition: iomdl.c:96
#define SectorOffset(L)
Definition: cdprocs.h:1632
smooth NULL
Definition: ftsmooth.c:416
struct __RAW_READ_INFO RAW_READ_INFO
PIRP NTAPI IoMakeAssociatedIrp(IN PIRP Irp, IN CCHAR StackSize)
Definition: irp.c:1925
LONGLONG DiskOffset
Definition: deviosup.c:41
TRACK_MODE_TYPE TrackMode
Definition: ntddcdrm.h:354
char CCHAR
Definition: typedefs.h:50
PMDL TransferMdl
Definition: deviosup.c:84
#define VOID
Definition: acefi.h:82
NTSTATUS NTAPI CdMultiSyncCompletionRoutine(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: deviosup.c:3438
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PIRP SavedIrp
Definition: deviosup.c:91
#define CdRaiseStatus(IC, S)
Definition: cdprocs.h:1869
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define SectorsFromBytes(L)
Definition: cdprocs.h:1610
unsigned int ULONG
Definition: retypes.h:1
#define RAW_SECTOR_SIZE
Definition: mcicda.c:50
LARGE_INTEGER DiskOffset
Definition: ntddcdrm.h:352
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
PVOID TransferVirtualAddress
Definition: deviosup.c:85
FORCEINLINE VOID IoSetNextIrpStackLocation(_Inout_ PIRP Irp)
Definition: iofuncs.h:2632
LONGLONG QuadPart
Definition: typedefs.h:112
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define NT_ASSERT
Definition: rtlfuncs.h:3312
ULONG DiskByteCount
Definition: deviosup.c:42

◆ CdMultiSyncCompletionRoutine()

NTSTATUS NTAPI CdMultiSyncCompletionRoutine ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PVOID  Context 
)

Definition at line 3438 of file deviosup.c.

3480 {
3481  PCD_IO_CONTEXT IoContext = Context;
3483 
3485 
3486  //
3487  // If we got an error (or verify required), remember it in the Irp
3488  //
3489 
3490  if (!NT_SUCCESS( Irp->IoStatus.Status )) {
3491 
3492  InterlockedExchange( &IoContext->Status, Irp->IoStatus.Status );
3493  IoContext->MasterIrp->IoStatus.Information = 0;
3494  }
3495 
3496  //
3497  // We must do this here since IoCompleteRequest won't get a chance
3498  // on this associated Irp.
3499  //
3500 
3501  IoFreeMdl( Irp->MdlAddress );
3502  IoFreeIrp( Irp );
3503 
3504  if (InterlockedDecrement( &IoContext->IrpCount ) == 0) {
3505 
3506  //
3507  // Update the Master Irp with any error status from the associated Irps.
3508  //
3509 
3510  IoContext->MasterIrp->IoStatus.Status = IoContext->Status;
3511  KeSetEvent( &IoContext->SyncEvent, 0, FALSE );
3512  }
3513 
3515 
3517 }
#define AssertVerifyDeviceIrp(I)
Definition: cdprocs.h:1821
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
KEVENT SyncEvent
Definition: cdstruc.h:1353
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
__volatile LONG IrpCount
Definition: cdstruc.h:1331
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
__volatile NTSTATUS Status
Definition: cdstruc.h:1333
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
PIRP MasterIrp
Definition: cdstruc.h:1332
#define InterlockedDecrement
Definition: armddk.h:52
#define InterlockedExchange
Definition: armddk.h:54
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
struct tagContext Context
Definition: acpixf.h:1012
#define _Analysis_assume_(expr)
Definition: no_sal2.h:10

Referenced by CdMultipleXAAsync().

◆ CdPerformDevIoCtrl()

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 
)

Definition at line 1446 of file deviosup.c.

1456 {
1457  PAGED_CODE();
1458 
1459  return CdPerformDevIoCtrlEx( IrpContext,
1460  IoControlCode,
1461  Device,
1462  NULL,
1463  0,
1464  OutputBuffer,
1467  OverrideVerify,
1468  Iosb);
1469 }
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
_In_ PIRP _In_ PDEVICE_OBJECT Device
Definition: fatprocs.h:2020
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID _In_ ULONG _In_ BOOLEAN InternalDeviceIoControl
Definition: iofuncs.h:713
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS CdPerformDevIoCtrlEx(_In_ PIRP_CONTEXT IrpContext, _In_ ULONG IoControlCode, _In_ PDEVICE_OBJECT Device, _In_reads_bytes_opt_(InputBufferLength) PVOID InputBuffer, _In_ ULONG InputBufferLength, _Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer, _In_ ULONG OutputBufferLength, _In_ BOOLEAN InternalDeviceIoControl, _In_ BOOLEAN OverrideVerify, _Out_opt_ PIO_STATUS_BLOCK Iosb)
Definition: deviosup.c:1329
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
return Iosb
Definition: create.c:4426

Referenced by _Success_(), and CdVerifyVcb().

◆ CdPerformDevIoCtrlEx()

NTSTATUS CdPerformDevIoCtrlEx ( _In_ PIRP_CONTEXT  IrpContext,
_In_ ULONG  IoControlCode,
_In_ PDEVICE_OBJECT  Device,
_In_reads_bytes_opt_(InputBufferLength) PVOID  InputBuffer,
_In_ ULONG  InputBufferLength,
_Out_writes_bytes_opt_(OutputBufferLength) PVOID  OutputBuffer,
_In_ ULONG  OutputBufferLength,
_In_ BOOLEAN  InternalDeviceIoControl,
_In_ BOOLEAN  OverrideVerify,
_Out_opt_ PIO_STATUS_BLOCK  Iosb 
)

Definition at line 1329 of file deviosup.c.

1374 {
1375  NTSTATUS Status;
1376  PIRP Irp;
1377  KEVENT Event;
1378  IO_STATUS_BLOCK LocalIosb;
1379  PIO_STATUS_BLOCK IosbToUse = &LocalIosb;
1380 
1381  PAGED_CODE();
1382 
1383  UNREFERENCED_PARAMETER( IrpContext );
1384 
1385  //
1386  // Check if the user gave us an Iosb.
1387  //
1388 
1389  if (ARGUMENT_PRESENT( Iosb )) {
1390 
1391  IosbToUse = Iosb;
1392  }
1393 
1394  IosbToUse->Status = 0;
1395  IosbToUse->Information = 0;
1396 
1398 
1400  Device,
1401  InputBuffer,
1403  OutputBuffer,
1406  &Event,
1407  IosbToUse );
1408 
1409  if (Irp == NULL) {
1410 
1412  }
1413 
1414  if (OverrideVerify) {
1415 
1417  }
1418 
1419  Status = IoCallDriver( Device, Irp );
1420 
1421  //
1422  // We check for device not ready by first checking Status
1423  // and then if status pending was returned, the Iosb status
1424  // value.
1425  //
1426 
1427  if (Status == STATUS_PENDING) {
1428 
1430  Executive,
1431  KernelMode,
1432  FALSE,
1433  (PLARGE_INTEGER)NULL );
1434 
1435  Status = IosbToUse->Status;
1436  }
1437 
1438  NT_ASSERT( !(OverrideVerify && (STATUS_VERIFY_REQUIRED == Status)));
1439 
1440  return Status;
1441 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
_In_ PIRP _In_ PDEVICE_OBJECT Device
Definition: fatprocs.h:2020
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID _In_ ULONG _In_ BOOLEAN InternalDeviceIoControl
Definition: iofuncs.h:713
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
#define STATUS_VERIFY_REQUIRED
Definition: udferr_usr.h:130
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
CHAR InputBuffer[80]
Definition: conmgr.c:33
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
smooth NULL
Definition: ftsmooth.c:416
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1779
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
return Iosb
Definition: create.c:4426
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ARGUMENT_PRESENT(ArgumentPointer)
#define VOID
Definition: acefi.h:82
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
Status
Definition: gdiplustypes.h:24
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by CdPerformDevIoCtrl(), and CdProcessToc().

◆ CdReadSectors()

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 
)

Definition at line 1080 of file deviosup.c.

1126 {
1127  NTSTATUS Status;
1128  KEVENT Event;
1129  PIRP Irp;
1130 
1131  PAGED_CODE();
1132 
1133  //
1134  // Initialize the event.
1135  //
1136 
1138 
1139  //
1140  // Attempt to allocate the IRP. If unsuccessful, raise
1141  // STATUS_INSUFFICIENT_RESOURCES.
1142  //
1143 
1146  Buffer,
1147  ByteCount,
1149  &Event,
1150  &IrpContext->Irp->IoStatus );
1151 
1152  if (Irp == NULL) {
1153 
1155  }
1156 
1157  //
1158  // Ignore the change line (verify) for mount and verify requests
1159  //
1160 
1162 
1163  //
1164  // Send the request down to the driver. If an error occurs return
1165  // it to the caller.
1166  //
1167 
1169 
1170  //
1171  // If the status was STATUS_PENDING then wait on the event.
1172  //
1173 
1174  if (Status == STATUS_PENDING) {
1175 
1177  Executive,
1178  KernelMode,
1179  FALSE,
1180  NULL );
1181 
1182  //
1183  // On a successful wait pull the status out of the IoStatus block.
1184  //
1185 
1186  if (NT_SUCCESS( Status )) {
1187 
1188  Status = IrpContext->Irp->IoStatus.Status;
1189  }
1190  }
1191 
1192  //
1193  // Check whether we should raise in the error case.
1194  //
1195 
1196  if (!NT_SUCCESS( Status )) {
1197 
1198  if (!ReturnError) {
1199 
1200  CdNormalizeAndRaiseStatus( IrpContext, Status );
1201  }
1202 
1203  //
1204  // We don't raise, but return FALSE to indicate an error.
1205  //
1206 
1207  return FALSE;
1208 
1209  //
1210  // The operation completed successfully.
1211  //
1212 
1213  } else {
1214 
1215  return TRUE;
1216  }
1217 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:282
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
smooth NULL
Definition: ftsmooth.c:416
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1779
Definition: bufpool.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1060
Status
Definition: gdiplustypes.h:24
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define CdRaiseStatus(IC, S)
Definition: cdprocs.h:1869
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define CdNormalizeAndRaiseStatus(IC, S)
Definition: cdprocs.h:1870
IN OUT PVCB IN PDEVICE_OBJECT TargetDeviceObject
Definition: fatprocs.h:1664

Referenced by _Success_(), and CdFindActiveVolDescriptor().

◆ CdSingleAsyncCompletionRoutine()

NTSTATUS NTAPI CdSingleAsyncCompletionRoutine ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PVOID  Context 
)

Definition at line 3710 of file deviosup.c.

3739 {
3740  PCD_IO_CONTEXT IoContext = Context;
3741 
3743 
3744  _Analysis_assume_(IoContext != NULL);
3746 
3747  //
3748  // Update the information field with the correct value for bytes read.
3749  //
3750 
3751  Irp->IoStatus.Information = 0;
3752 
3753  if (NT_SUCCESS( Irp->IoStatus.Status )) {
3754 
3755  Irp->IoStatus.Information = IoContext->RequestedByteCount;
3756  }
3757 
3758  //
3759  // Mark the Irp pending
3760  //
3761 
3762  IoMarkIrpPending( Irp );
3763 
3764  //
3765  // Now release the resource
3766  //
3767 
3769  ExReleaseResourceForThreadLite( IoContext->Resource, IoContext->ResourceThreadId );
3770 
3771  //
3772  // and finally, free the context record.
3773  //
3774 
3775  CdFreeIoContext( IoContext );
3776  return STATUS_SUCCESS;
3777 
3778 }
#define AssertVerifyDeviceIrp(I)
Definition: cdprocs.h:1821
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define _Analysis_assume_lock_held_(lock)
Definition: no_sal2.h:682
ULONG RequestedByteCount
Definition: cdstruc.h:1346
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PERESOURCE Resource
Definition: cdstruc.h:1344
#define CdFreeIoContext(IO)
Definition: cdprocs.h:1354
ERESOURCE_THREAD ResourceThreadId
Definition: cdstruc.h:1345
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
struct tagContext Context
Definition: acpixf.h:1012
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
return STATUS_SUCCESS
Definition: btrfs.c:2777
IoMarkIrpPending(Irp)
#define _Analysis_assume_(expr)
Definition: no_sal2.h:10

◆ CdSingleSyncCompletionRoutine()

NTSTATUS NTAPI CdSingleSyncCompletionRoutine ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PVOID  Context 
)

Definition at line 3646 of file deviosup.c.

3682 {
3684 
3686 
3688 
3689  //
3690  // Store the correct information field into the Irp.
3691  //
3692 
3693  if (!NT_SUCCESS( Irp->IoStatus.Status )) {
3694 
3695  Irp->IoStatus.Information = 0;
3696  }
3697 
3698  KeSetEvent( &((PCD_IO_CONTEXT)Context)->SyncEvent, 0, FALSE );
3699 
3701 }
#define AssertVerifyDeviceIrp(I)
Definition: cdprocs.h:1821
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define _Analysis_assume_(expr)
Definition: no_sal2.h:10

◆ CdSyncCompletionRoutine()

NTSTATUS NTAPI CdSyncCompletionRoutine ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PVOID  Contxt 
)

Definition at line 2392 of file deviosup.c.

2414 {
2415  PKEVENT Event = (PKEVENT)Contxt;
2416  _Analysis_assume_(Contxt != NULL);
2417 
2420 
2421  KeSetEvent( Event, 0, FALSE );
2422 
2423  //
2424  // We don't want IO to get our IRP and free it.
2425  //
2426 
2428 }
struct _KEVENT * PKEVENT
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
smooth NULL
Definition: ftsmooth.c:416
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define _Analysis_assume_(expr)
Definition: no_sal2.h:10

◆ CdWaitSync()

VOID CdWaitSync ( _In_ PIRP_CONTEXT  IrpContext)

Definition at line 3399 of file deviosup.c.

3418 {
3419  PAGED_CODE();
3420 
3421 
3422  (VOID)KeWaitForSingleObject( &IrpContext->IoContext->SyncEvent,
3423  Executive,
3424  KernelMode,
3425  FALSE,
3426  NULL );
3427 
3428  KeClearEvent( &IrpContext->IoContext->SyncEvent );
3429 }
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
smooth NULL
Definition: ftsmooth.c:416
#define VOID
Definition: acefi.h:82
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22

Variable Documentation

◆ CdSyncCompletionRoutine

IO_COMPLETION_ROUTINE CdSyncCompletionRoutine

Definition at line 2388 of file deviosup.c.

Referenced by CdHijackIrpAndFlushDevice().