[CDFS_NEW] Fix headers inclusion so that it can work on a *nix platform
[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 NTSTATUS
30 CdDevCtrlCompletionRoutine (
31 IN PDEVICE_OBJECT DeviceObject,
32 IN PIRP Irp,
33 IN PVOID Contxt
34 );
35
36 #ifdef ALLOC_PRAGMA
37 #pragma alloc_text(PAGE, CdCommonDevControl)
38 #endif
39
40 \f
41 NTSTATUS
42 CdCommonDevControl (
43 IN PIRP_CONTEXT IrpContext,
44 IN PIRP Irp
45 )
46
47 /*++
48
49 Routine Description:
50
51 Arguments:
52
53 Return Value:
54
55 --*/
56
57 {
58 NTSTATUS Status;
59
60 TYPE_OF_OPEN TypeOfOpen;
61 PFCB Fcb;
62 PCCB Ccb;
63
64 PIO_STACK_LOCATION IrpSp;
65 PIO_STACK_LOCATION NextIrpSp;
66
67 // PVOID TargetBuffer = NULL; /* ReactOS Change: GCC unused variable */
68
69 PAGED_CODE();
70
71 //
72 // Extract and decode the file object.
73 //
74
75 IrpSp = IoGetCurrentIrpStackLocation( Irp );
76
77 TypeOfOpen = CdDecodeFileObject( IrpContext,
78 IrpSp->FileObject,
79 &Fcb,
80 &Ccb );
81
82 //
83 // The only type of opens we accept are user volume opens.
84 //
85
86 if (TypeOfOpen != UserVolumeOpen) {
87
88 CdCompleteRequest( IrpContext, Irp, STATUS_INVALID_PARAMETER );
89 return STATUS_INVALID_PARAMETER;
90 }
91
92 if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_CDROM_READ_TOC) {
93
94 //
95 // Verify the Vcb in this case to detect if the volume has changed.
96 //
97
98 CdVerifyVcb( IrpContext, Fcb->Vcb );
99
100 //
101 // Handle the case of the disk type ourselves.
102 //
103
104 } else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_CDROM_DISK_TYPE) {
105
106 //
107 // Verify the Vcb in this case to detect if the volume has changed.
108 //
109
110 CdVerifyVcb( IrpContext, Fcb->Vcb );
111
112 //
113 // Check the size of the output buffer.
114 //
115
116 if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength < sizeof( CDROM_DISK_DATA )) {
117
118 CdCompleteRequest( IrpContext, Irp, STATUS_BUFFER_TOO_SMALL );
119 return STATUS_BUFFER_TOO_SMALL;
120 }
121
122 //
123 // Copy the data from the Vcb.
124 //
125
126 ((PCDROM_DISK_DATA) Irp->AssociatedIrp.SystemBuffer)->DiskData = Fcb->Vcb->DiskFlags;
127
128 Irp->IoStatus.Information = sizeof( CDROM_DISK_DATA );
129 CdCompleteRequest( IrpContext, Irp, STATUS_SUCCESS );
130 return STATUS_SUCCESS;
131 }
132
133 //
134 // Get the next stack location, and copy over the stack parameter
135 // information.
136 //
137
138 NextIrpSp = IoGetNextIrpStackLocation( Irp );
139
140 *NextIrpSp = *IrpSp;
141
142 //
143 // Set up the completion routine
144 //
145
146 IoSetCompletionRoutine( Irp,
147 CdDevCtrlCompletionRoutine,
148 NULL,
149 TRUE,
150 TRUE,
151 TRUE );
152
153 //
154 // Send the request.
155 //
156
157 Status = IoCallDriver( IrpContext->Vcb->TargetDeviceObject, Irp );
158
159 //
160 // Cleanup our Irp Context. The driver has completed the Irp.
161 //
162
163 CdCompleteRequest( IrpContext, NULL, STATUS_SUCCESS );
164
165 return Status;
166 }
167
168 \f
169 //
170 // Local support routine
171 //
172
173 NTSTATUS
174 CdDevCtrlCompletionRoutine (
175 IN PDEVICE_OBJECT DeviceObject,
176 IN PIRP Irp,
177 IN PVOID Contxt
178 )
179
180 {
181 //
182 // Add the hack-o-ramma to fix formats.
183 //
184
185 if (Irp->PendingReturned) {
186
187 IoMarkIrpPending( Irp );
188 }
189
190 return STATUS_SUCCESS;
191
192 UNREFERENCED_PARAMETER( DeviceObject );
193 UNREFERENCED_PARAMETER( Contxt );
194 }
195
196