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