Windows: RDR File System Framework driver
[openafs.git] / src / WINNT / afsrdr / kernel / fs / AFSFastIoSupport.cpp
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011 Kernel Drivers, LLC.
3  * Copyright (c) 2009, 2010, 2011 Your File System, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * - Redistributions of source code must retain the above copyright notice,
11  *   this list of conditions and the following disclaimer.
12  * - Redistributions in binary form must reproduce the above copyright
13  *   notice,
14  *   this list of conditions and the following disclaimer in the
15  *   documentation
16  *   and/or other materials provided with the distribution.
17  * - Neither the names of Kernel Drivers, LLC and Your File System, Inc.
18  *   nor the names of their contributors may be used to endorse or promote
19  *   products derived from this software without specific prior written
20  *   permission from Kernel Drivers, LLC and Your File System, Inc.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 //
36 // File: AFSFastIoSupport.cpp
37 //
38
39 #include "AFSCommon.h"
40
41 BOOLEAN
42 AFSFastIoCheckIfPossible( IN struct _FILE_OBJECT *FileObject,
43                           IN PLARGE_INTEGER FileOffset,
44                           IN ULONG Length,
45                           IN BOOLEAN Wait,
46                           IN ULONG LockKey,
47                           IN BOOLEAN CheckForReadOperation,
48                           OUT PIO_STATUS_BLOCK IoStatus,
49                           IN struct _DEVICE_OBJECT *DeviceObject)
50 {
51
52     BOOLEAN bStatus = FALSE;
53
54     return bStatus;
55 }
56
57 BOOLEAN
58 AFSFastIoRead( IN struct _FILE_OBJECT *FileObject,
59                IN PLARGE_INTEGER FileOffset,
60                IN ULONG Length,
61                IN BOOLEAN Wait,
62                IN ULONG LockKey,
63                OUT PVOID Buffer,
64                OUT PIO_STATUS_BLOCK IoStatus,
65                IN struct _DEVICE_OBJECT *DeviceObject)
66 {
67
68     BOOLEAN bStatus = FALSE;
69
70     return bStatus;
71 }
72
73 BOOLEAN
74 AFSFastIoWrite( IN struct _FILE_OBJECT *FileObject,
75                 IN PLARGE_INTEGER FileOffset,
76                 IN ULONG Length,
77                 IN BOOLEAN Wait,
78                 IN ULONG LockKey,
79                 IN PVOID Buffer,
80                 OUT PIO_STATUS_BLOCK IoStatus,
81                 IN struct _DEVICE_OBJECT *DeviceObject)
82 {
83
84     BOOLEAN bStatus = FALSE;
85
86     return bStatus;
87 }
88
89 BOOLEAN
90 AFSFastIoQueryBasicInfo( IN struct _FILE_OBJECT *FileObject,
91                          IN BOOLEAN Wait,
92                          OUT PFILE_BASIC_INFORMATION Buffer,
93                          OUT PIO_STATUS_BLOCK IoStatus,
94                          IN struct _DEVICE_OBJECT *DeviceObject)
95 {
96
97     BOOLEAN bStatus = FALSE;
98
99     return bStatus;
100 }
101
102 BOOLEAN
103 AFSFastIoQueryStandardInfo( IN struct _FILE_OBJECT *FileObject,
104                             IN BOOLEAN Wait,
105                             OUT PFILE_STANDARD_INFORMATION Buffer,
106                             OUT PIO_STATUS_BLOCK IoStatus,
107                             IN struct _DEVICE_OBJECT *DeviceObject)
108 {
109
110     BOOLEAN bStatus = FALSE;
111
112     return bStatus;
113 }
114
115 BOOLEAN
116 AFSFastIoLock( IN struct _FILE_OBJECT *FileObject,
117                IN PLARGE_INTEGER FileOffset,
118                IN PLARGE_INTEGER Length,
119                IN PEPROCESS ProcessId,
120                IN ULONG Key,
121                IN BOOLEAN FailImmediately,
122                IN BOOLEAN ExclusiveLock,
123                OUT PIO_STATUS_BLOCK IoStatus,
124                IN struct _DEVICE_OBJECT *DeviceObject)
125 {
126
127     BOOLEAN bStatus = FALSE;
128
129     return bStatus;
130 }
131
132 BOOLEAN
133 AFSFastIoUnlockSingle( IN struct _FILE_OBJECT *FileObject,
134                        IN PLARGE_INTEGER FileOffset,
135                        IN PLARGE_INTEGER Length,
136                        IN PEPROCESS ProcessId,
137                        IN ULONG Key,
138                        OUT PIO_STATUS_BLOCK IoStatus,
139                        IN struct _DEVICE_OBJECT *DeviceObject)
140 {
141
142     BOOLEAN bStatus = FALSE;
143
144     return bStatus;
145 }
146
147 BOOLEAN
148 AFSFastIoUnlockAll( IN struct _FILE_OBJECT *FileObject,
149                     IN PEPROCESS ProcessId,
150                     OUT PIO_STATUS_BLOCK IoStatus,
151                     IN struct _DEVICE_OBJECT *DeviceObject)
152 {
153
154     BOOLEAN bStatus = FALSE;
155
156     return bStatus;
157 }
158
159 BOOLEAN
160 AFSFastIoUnlockAllByKey( IN struct _FILE_OBJECT *FileObject,
161                          IN PVOID ProcessId,
162                          IN ULONG Key,
163                          OUT PIO_STATUS_BLOCK IoStatus,
164                          IN struct _DEVICE_OBJECT *DeviceObject)
165 {
166
167     BOOLEAN bStatus = FALSE;
168
169     return bStatus;
170 }
171
172 BOOLEAN
173 AFSFastIoDevCtrl( IN struct _FILE_OBJECT *FileObject,
174                   IN BOOLEAN Wait,
175                   IN PVOID InputBuffer OPTIONAL,
176                   IN ULONG InputBufferLength,
177                   OUT PVOID OutputBuffer OPTIONAL,
178                   IN ULONG OutputBufferLength,
179                   IN ULONG IoControlCode,
180                   OUT PIO_STATUS_BLOCK IoStatus,
181                   IN struct _DEVICE_OBJECT *DeviceObject)
182 {
183
184     BOOLEAN bStatus = FALSE;
185
186     return bStatus;
187 }
188
189 void
190 AFSFastIoAcquireFile( IN struct _FILE_OBJECT *FileObject)
191 {
192
193     AFSFcb *pFcb = (AFSFcb *)FileObject->FsContext;
194
195     AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
196                   AFS_TRACE_LEVEL_VERBOSE,
197                   "AFSFastIoAcquireFile Acquiring Fcb lock %08lX EXCL %08lX\n",
198                   &pFcb->NPFcb->Resource,
199                   PsGetCurrentThread());
200
201     AFSAcquireExcl( &pFcb->NPFcb->Resource,
202                     TRUE);
203
204     return;
205 }
206
207 void
208 AFSFastIoReleaseFile( IN struct _FILE_OBJECT *FileObject)
209 {
210
211     AFSFcb *pFcb = (AFSFcb *)FileObject->FsContext;
212
213     if( ExIsResourceAcquiredExclusiveLite( &pFcb->NPFcb->Resource))
214     {
215
216         AFSReleaseResource( &pFcb->NPFcb->Resource);
217     }
218
219     return;
220 }
221
222 VOID
223 AFSFastIoDetachDevice( IN struct _DEVICE_OBJECT *SourceDevice,
224                        IN struct _DEVICE_OBJECT *TargetDevice)
225 {
226
227     return;
228 }
229
230 BOOLEAN
231 AFSFastIoQueryNetworkOpenInfo( IN struct _FILE_OBJECT *FileObject,
232                                IN BOOLEAN Wait,
233                                OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
234                                OUT struct _IO_STATUS_BLOCK *IoStatus,
235                                IN struct _DEVICE_OBJECT *DeviceObject)
236 {
237
238     BOOLEAN bStatus = FALSE;
239
240     return bStatus;
241 }
242
243 BOOLEAN
244 AFSFastIoMdlRead( IN struct _FILE_OBJECT *FileObject,
245                   IN PLARGE_INTEGER FileOffset,
246                   IN ULONG Length,
247                   IN ULONG LockKey,
248                   OUT PMDL *MdlChain,
249                   OUT PIO_STATUS_BLOCK IoStatus,
250                   IN struct _DEVICE_OBJECT *DeviceObject)
251 {
252
253     BOOLEAN bStatus = FALSE;
254
255     return bStatus;
256 }
257
258 BOOLEAN
259 AFSFastIoMdlReadComplete( IN struct _FILE_OBJECT *FileObject,
260                           IN PMDL MdlChain,
261                           IN struct _DEVICE_OBJECT *DeviceObject)
262 {
263
264     BOOLEAN bStatus = FALSE;
265
266     return bStatus;
267 }
268
269 BOOLEAN
270 AFSFastIoPrepareMdlWrite( IN struct _FILE_OBJECT *FileObject,
271                           IN PLARGE_INTEGER FileOffset,
272                           IN ULONG Length,
273                           IN ULONG LockKey,
274                           OUT PMDL *MdlChain,
275                           OUT PIO_STATUS_BLOCK IoStatus,
276                           IN struct _DEVICE_OBJECT *DeviceObject)
277 {
278
279     BOOLEAN bStatus = FALSE;
280
281     return bStatus;
282 }
283
284 BOOLEAN
285 AFSFastIoMdlWriteComplete( IN struct _FILE_OBJECT *FileObject,
286                            IN PLARGE_INTEGER FileOffset,
287                            IN PMDL MdlChain,
288                            IN struct _DEVICE_OBJECT *DeviceObject)
289 {
290
291     BOOLEAN bStatus = FALSE;
292
293     return bStatus;
294 }
295
296 NTSTATUS
297 AFSFastIoAcquireForModWrite( IN struct _FILE_OBJECT *FileObject,
298                              IN PLARGE_INTEGER EndingOffset,
299                              OUT struct _ERESOURCE **ResourceToRelease,
300                              IN struct _DEVICE_OBJECT *DeviceObject)
301 {
302
303     NTSTATUS ntStatus = STATUS_FILE_LOCK_CONFLICT;
304     AFSFcb *pFcb = (AFSFcb *)FileObject->FsContext;
305
306     __Enter
307     {
308
309         if( AFSAcquireExcl( &pFcb->NPFcb->Resource,
310                             BooleanFlagOn( FileObject->Flags, FO_SYNCHRONOUS_IO)))
311         {
312
313             AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
314                           AFS_TRACE_LEVEL_VERBOSE,
315                           "AFSFastIoAcquireForModWrite Acquired Fcb lock %08lX EXCL %08lX\n",
316                           &pFcb->NPFcb->Resource,
317                           PsGetCurrentThread());
318
319             ntStatus = STATUS_SUCCESS;
320
321             *ResourceToRelease = &pFcb->NPFcb->Resource;
322         }
323     }
324
325     return ntStatus;
326 }
327
328 NTSTATUS
329 AFSFastIoReleaseForModWrite( IN struct _FILE_OBJECT *FileObject,
330                              IN struct _ERESOURCE *ResourceToRelease,
331                              IN struct _DEVICE_OBJECT *DeviceObject)
332 {
333
334     NTSTATUS ntStatus = STATUS_SUCCESS;
335
336     AFSReleaseResource( ResourceToRelease);
337
338     return ntStatus;
339 }
340
341 NTSTATUS
342 AFSFastIoAcquireForCCFlush( IN struct _FILE_OBJECT *FileObject,
343                             IN struct _DEVICE_OBJECT *DeviceObject)
344 {
345
346     NTSTATUS ntStatus = STATUS_FILE_LOCK_CONFLICT;
347     AFSFcb *pFcb = (AFSFcb *)FileObject->FsContext;
348
349     if( !ExIsResourceAcquiredSharedLite( &pFcb->NPFcb->Resource))
350     {
351
352         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
353                       AFS_TRACE_LEVEL_VERBOSE,
354                       "AFSFastIoAcquireForCCFlush Acquiring Fcb lock %08lX EXCL %08lX\n",
355                       &pFcb->NPFcb->Resource,
356                       PsGetCurrentThread());
357
358         AFSAcquireExcl( &pFcb->NPFcb->Resource,
359                         TRUE);
360     }
361     else
362     {
363
364         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
365                       AFS_TRACE_LEVEL_VERBOSE,
366                       "AFSFastIoAcquireForCCFlush Acquiring Fcb lock %08lX SHARED %08lX\n",
367                       &pFcb->NPFcb->Resource,
368                       PsGetCurrentThread());
369
370         AFSAcquireShared( &pFcb->NPFcb->Resource,
371                           TRUE);
372     }
373
374     ntStatus = STATUS_SUCCESS;
375
376     AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
377                   AFS_TRACE_LEVEL_VERBOSE,
378                   "AFSFastIoAcquireForCCFlush Acquiring Fcb PagingIo lock %08lX SHARED %08lX\n",
379                   &pFcb->NPFcb->PagingResource,
380                   PsGetCurrentThread());
381
382     AFSAcquireShared( &pFcb->NPFcb->PagingResource,
383                       TRUE);
384
385     //
386     // Set the TopLevelIrp field for this caller
387     //
388
389     if( IoGetTopLevelIrp() == NULL)
390     {
391
392         IoSetTopLevelIrp( (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
393     }
394
395     return ntStatus;
396 }
397
398 NTSTATUS
399 AFSFastIoReleaseForCCFlush( IN struct _FILE_OBJECT *FileObject,
400                             IN struct _DEVICE_OBJECT *DeviceObject)
401 {
402
403     NTSTATUS ntStatus = STATUS_SUCCESS;
404     AFSFcb *pFcb = (AFSFcb *)FileObject->FsContext;
405
406     if( IoGetTopLevelIrp() == (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP)
407     {
408
409         IoSetTopLevelIrp( NULL);
410     }
411
412     if( ExIsResourceAcquiredExclusiveLite( &pFcb->NPFcb->Resource) ||
413         ExIsResourceAcquiredSharedLite( &pFcb->NPFcb->Resource))
414     {
415
416         AFSReleaseResource( &pFcb->NPFcb->Resource);
417     }
418     else
419     {
420
421         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
422                       AFS_TRACE_LEVEL_ERROR,
423                       "AFSFastIoReleaseForCCFlush Called for non-acquired main resource Fcb\n");
424     }
425
426     if( ExIsResourceAcquiredSharedLite( &pFcb->NPFcb->PagingResource))
427     {
428
429         AFSReleaseResource( &pFcb->NPFcb->PagingResource);
430     }
431     else
432     {
433
434         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
435                       AFS_TRACE_LEVEL_ERROR,
436                       "AFSFastIoReleaseForCCFlush Called for non-acquired paging resource Fcb\n");
437     }
438
439     return ntStatus;
440 }
441
442 BOOLEAN
443 AFSFastIoReadCompressed( IN struct _FILE_OBJECT *FileObject,
444                          IN PLARGE_INTEGER FileOffset,
445                          IN ULONG Length,
446                          IN ULONG LockKey,
447                          OUT PVOID Buffer,
448                          OUT PMDL *MdlChain,
449                          OUT PIO_STATUS_BLOCK IoStatus,
450                          OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
451                          IN ULONG CompressedDataInfoLength,
452                          IN struct _DEVICE_OBJECT *DeviceObject)
453 {
454
455     BOOLEAN bStatus = FALSE;
456
457     return bStatus;
458 }
459
460 BOOLEAN
461 AFSFastIoWriteCompressed( IN struct _FILE_OBJECT *FileObject,
462                           IN PLARGE_INTEGER FileOffset,
463                           IN ULONG Length,
464                           IN ULONG LockKey,
465                           IN PVOID Buffer,
466                           OUT PMDL *MdlChain,
467                           OUT PIO_STATUS_BLOCK IoStatus,
468                           IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
469                           IN ULONG CompressedDataInfoLength,
470                           IN struct _DEVICE_OBJECT *DeviceObject)
471 {
472
473     BOOLEAN bStatus = FALSE;
474
475     return bStatus;
476 }
477
478 BOOLEAN
479 AFSFastIoMdlReadCompleteCompressed( IN struct _FILE_OBJECT *FileObject,
480                                     IN PMDL MdlChain,
481                                     IN struct _DEVICE_OBJECT *DeviceObject)
482 {
483
484     BOOLEAN bStatus = FALSE;
485
486     return bStatus;
487 }
488
489 BOOLEAN
490 AFSFastIoMdlWriteCompleteCompressed( IN struct _FILE_OBJECT *FileObject,
491                                      IN PLARGE_INTEGER FileOffset,
492                                      IN PMDL MdlChain,
493                                      IN struct _DEVICE_OBJECT *DeviceObject)
494 {
495
496     BOOLEAN bStatus = FALSE;
497
498     return bStatus;
499 }
500
501 BOOLEAN
502 AFSFastIoQueryOpen( IN struct _IRP *Irp,
503                     OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
504                     IN struct _DEVICE_OBJECT *DeviceObject)
505 {
506
507     BOOLEAN bStatus = FALSE;
508
509     return bStatus;
510 }