Windows: Fcb sectionObjectResource
[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 SectionObject lock %08lX EXCL %08lX\n",
198                   &pFcb->NPFcb->SectionObjectResource,
199                   PsGetCurrentThread());
200
201     AFSAcquireExcl( &pFcb->NPFcb->SectionObjectResource,
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->SectionObjectResource))
214     {
215
216         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
217                       AFS_TRACE_LEVEL_VERBOSE,
218                       "AFSFastIoReleaseFile Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
219                       &pFcb->NPFcb->SectionObjectResource,
220                       PsGetCurrentThread());
221
222         AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
223     }
224
225     return;
226 }
227
228 VOID
229 AFSFastIoDetachDevice( IN struct _DEVICE_OBJECT *SourceDevice,
230                        IN struct _DEVICE_OBJECT *TargetDevice)
231 {
232
233     return;
234 }
235
236 BOOLEAN
237 AFSFastIoQueryNetworkOpenInfo( IN struct _FILE_OBJECT *FileObject,
238                                IN BOOLEAN Wait,
239                                OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
240                                OUT struct _IO_STATUS_BLOCK *IoStatus,
241                                IN struct _DEVICE_OBJECT *DeviceObject)
242 {
243
244     BOOLEAN bStatus = FALSE;
245
246     return bStatus;
247 }
248
249 BOOLEAN
250 AFSFastIoMdlRead( IN struct _FILE_OBJECT *FileObject,
251                   IN PLARGE_INTEGER FileOffset,
252                   IN ULONG Length,
253                   IN ULONG LockKey,
254                   OUT PMDL *MdlChain,
255                   OUT PIO_STATUS_BLOCK IoStatus,
256                   IN struct _DEVICE_OBJECT *DeviceObject)
257 {
258
259     BOOLEAN bStatus = FALSE;
260
261     return bStatus;
262 }
263
264 BOOLEAN
265 AFSFastIoMdlReadComplete( IN struct _FILE_OBJECT *FileObject,
266                           IN PMDL MdlChain,
267                           IN struct _DEVICE_OBJECT *DeviceObject)
268 {
269
270     BOOLEAN bStatus = FALSE;
271
272     return bStatus;
273 }
274
275 BOOLEAN
276 AFSFastIoPrepareMdlWrite( IN struct _FILE_OBJECT *FileObject,
277                           IN PLARGE_INTEGER FileOffset,
278                           IN ULONG Length,
279                           IN ULONG LockKey,
280                           OUT PMDL *MdlChain,
281                           OUT PIO_STATUS_BLOCK IoStatus,
282                           IN struct _DEVICE_OBJECT *DeviceObject)
283 {
284
285     BOOLEAN bStatus = FALSE;
286
287     return bStatus;
288 }
289
290 BOOLEAN
291 AFSFastIoMdlWriteComplete( IN struct _FILE_OBJECT *FileObject,
292                            IN PLARGE_INTEGER FileOffset,
293                            IN PMDL MdlChain,
294                            IN struct _DEVICE_OBJECT *DeviceObject)
295 {
296
297     BOOLEAN bStatus = FALSE;
298
299     return bStatus;
300 }
301
302 NTSTATUS
303 AFSFastIoAcquireForModWrite( IN struct _FILE_OBJECT *FileObject,
304                              IN PLARGE_INTEGER EndingOffset,
305                              OUT struct _ERESOURCE **ResourceToRelease,
306                              IN struct _DEVICE_OBJECT *DeviceObject)
307 {
308
309     NTSTATUS ntStatus = STATUS_FILE_LOCK_CONFLICT;
310     AFSFcb *pFcb = (AFSFcb *)FileObject->FsContext;
311
312     __Enter
313     {
314
315         if( AFSAcquireExcl( &pFcb->NPFcb->Resource,
316                             BooleanFlagOn( FileObject->Flags, FO_SYNCHRONOUS_IO)))
317         {
318
319             AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
320                           AFS_TRACE_LEVEL_VERBOSE,
321                           "AFSFastIoAcquireForModWrite Acquired Fcb SectionObject lock %08lX EXCL %08lX\n",
322                           &pFcb->NPFcb->SectionObjectResource,
323                           PsGetCurrentThread());
324
325             ntStatus = STATUS_SUCCESS;
326
327             *ResourceToRelease = &pFcb->NPFcb->SectionObjectResource;
328         }
329     }
330
331     return ntStatus;
332 }
333
334 NTSTATUS
335 AFSFastIoReleaseForModWrite( IN struct _FILE_OBJECT *FileObject,
336                              IN struct _ERESOURCE *ResourceToRelease,
337                              IN struct _DEVICE_OBJECT *DeviceObject)
338 {
339
340     NTSTATUS ntStatus = STATUS_SUCCESS;
341
342     AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
343                   AFS_TRACE_LEVEL_VERBOSE,
344                   "AFSFastIoReleaseForModWrite Releasing lock %08lX EXCL %08lX\n",
345                   ResourceToRelease,
346                   PsGetCurrentThread());
347
348     AFSReleaseResource( ResourceToRelease);
349
350     return ntStatus;
351 }
352
353 NTSTATUS
354 AFSFastIoAcquireForCCFlush( IN struct _FILE_OBJECT *FileObject,
355                             IN struct _DEVICE_OBJECT *DeviceObject)
356 {
357
358     NTSTATUS ntStatus = STATUS_FILE_LOCK_CONFLICT;
359     AFSFcb *pFcb = (AFSFcb *)FileObject->FsContext;
360
361     AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
362                   AFS_TRACE_LEVEL_VERBOSE,
363                   "AFSFastIoAcquireForCCFlush Acquiring Fcb PagingIo lock %08lX SHARED %08lX\n",
364                   &pFcb->NPFcb->PagingResource,
365                   PsGetCurrentThread());
366
367     AFSAcquireShared( &pFcb->NPFcb->PagingResource,
368                       TRUE);
369
370     if( !ExIsResourceAcquiredSharedLite( &pFcb->NPFcb->SectionObjectResource))
371     {
372
373         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
374                       AFS_TRACE_LEVEL_VERBOSE,
375                       "AFSFastIoAcquireForCCFlush Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
376                       &pFcb->NPFcb->SectionObjectResource,
377                       PsGetCurrentThread());
378
379         AFSAcquireExcl( &pFcb->NPFcb->SectionObjectResource,
380                         TRUE);
381     }
382     else
383     {
384
385         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
386                       AFS_TRACE_LEVEL_VERBOSE,
387                       "AFSFastIoAcquireForCCFlush Acquiring Fcb SectionObject lock %08lX SHARED %08lX\n",
388                       &pFcb->NPFcb->SectionObjectResource,
389                       PsGetCurrentThread());
390
391         AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
392                           TRUE);
393     }
394
395     ntStatus = STATUS_SUCCESS;
396
397     //
398     // Set the TopLevelIrp field for this caller
399     //
400
401     if( IoGetTopLevelIrp() == NULL)
402     {
403
404         IoSetTopLevelIrp( (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
405     }
406
407     return ntStatus;
408 }
409
410 NTSTATUS
411 AFSFastIoReleaseForCCFlush( IN struct _FILE_OBJECT *FileObject,
412                             IN struct _DEVICE_OBJECT *DeviceObject)
413 {
414
415     NTSTATUS ntStatus = STATUS_SUCCESS;
416     AFSFcb *pFcb = (AFSFcb *)FileObject->FsContext;
417
418     if( IoGetTopLevelIrp() == (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP)
419     {
420
421         IoSetTopLevelIrp( NULL);
422     }
423
424     if( ExIsResourceAcquiredSharedLite( &pFcb->NPFcb->PagingResource))
425     {
426
427         AFSReleaseResource( &pFcb->NPFcb->PagingResource);
428     }
429     else
430     {
431
432         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
433                       AFS_TRACE_LEVEL_ERROR,
434                       "AFSFastIoReleaseForCCFlush Called for non-acquired paging resource Fcb\n");
435     }
436
437     if( ExIsResourceAcquiredExclusiveLite( &pFcb->NPFcb->SectionObjectResource) ||
438         ExIsResourceAcquiredSharedLite( &pFcb->NPFcb->SectionObjectResource))
439     {
440
441         AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
442     }
443     else
444     {
445
446         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
447                       AFS_TRACE_LEVEL_ERROR,
448                       "AFSFastIoReleaseForCCFlush Called for non-acquired SectionObject resource Fcb\n");
449     }
450
451     return ntStatus;
452 }
453
454 BOOLEAN
455 AFSFastIoReadCompressed( IN struct _FILE_OBJECT *FileObject,
456                          IN PLARGE_INTEGER FileOffset,
457                          IN ULONG Length,
458                          IN ULONG LockKey,
459                          OUT PVOID Buffer,
460                          OUT PMDL *MdlChain,
461                          OUT PIO_STATUS_BLOCK IoStatus,
462                          OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
463                          IN ULONG CompressedDataInfoLength,
464                          IN struct _DEVICE_OBJECT *DeviceObject)
465 {
466
467     BOOLEAN bStatus = FALSE;
468
469     return bStatus;
470 }
471
472 BOOLEAN
473 AFSFastIoWriteCompressed( IN struct _FILE_OBJECT *FileObject,
474                           IN PLARGE_INTEGER FileOffset,
475                           IN ULONG Length,
476                           IN ULONG LockKey,
477                           IN PVOID Buffer,
478                           OUT PMDL *MdlChain,
479                           OUT PIO_STATUS_BLOCK IoStatus,
480                           IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
481                           IN ULONG CompressedDataInfoLength,
482                           IN struct _DEVICE_OBJECT *DeviceObject)
483 {
484
485     BOOLEAN bStatus = FALSE;
486
487     return bStatus;
488 }
489
490 BOOLEAN
491 AFSFastIoMdlReadCompleteCompressed( IN struct _FILE_OBJECT *FileObject,
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 AFSFastIoMdlWriteCompleteCompressed( IN struct _FILE_OBJECT *FileObject,
503                                      IN PLARGE_INTEGER FileOffset,
504                                      IN PMDL MdlChain,
505                                      IN struct _DEVICE_OBJECT *DeviceObject)
506 {
507
508     BOOLEAN bStatus = FALSE;
509
510     return bStatus;
511 }
512
513 BOOLEAN
514 AFSFastIoQueryOpen( IN struct _IRP *Irp,
515                     OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
516                     IN struct _DEVICE_OBJECT *DeviceObject)
517 {
518
519     BOOLEAN bStatus = FALSE;
520
521     return bStatus;
522 }