Windows: Move Authenticated field to CommResultCB
[openafs.git] / src / WINNT / afsrdr / user / RDRInit.cpp
1 /*
2  * Copyright (c) 2008 Secure Endpoints, Inc.
3  * Copyright (c) 2009-2013 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 are met:
8  *
9  * - Redistributions of source code must retain the above copyright notice,
10  *   this list of conditions and the following disclaimer.
11  * - Redistributions in binary form must reproduce the above copyright notice,
12  *   this list of conditions and the following disclaimer in the documentation
13  *   and/or other materials provided with the distribution.
14  * - Neither the name of Secure Endpoints Inc. nor the names of its contributors
15  *   may be used to endorse or promote products derived from this software without
16  *   specific prior written permission from Secure Endpoints, Inc. and
17  *   Your File System, Inc.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
23  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 extern "C" {
33 #include <afsconfig.h>
34 #include <afs/param.h>
35 #include <afs/stds.h>
36 }
37
38 #ifndef _WIN32_WINNT
39 #define _WIN32_WINNT 0x0500
40 #endif
41 #define _CRT_SECURE_NO_DEPRECATE
42 #define _CRT_NON_CONFORMING_SWPRINTFS
43 #define UNICODE 1
44 #define STRSAFE_NO_DEPRECATE
45
46 #include <ntstatus.h>
47 #define WIN32_NO_STATUS
48 #include <windows.h>
49 typedef LONG NTSTATUS, *PNTSTATUS;      // not declared in ntstatus.h
50
51 #include <roken.h>
52
53 #include <devioctl.h>
54
55 #include <tchar.h>
56 #include <winbase.h>
57 #include <winreg.h>
58 #include <strsafe.h>
59
60 #include "..\\Common\\AFSUserDefines.h"
61 #include "..\\Common\\AFSUserIoctl.h"
62 #include "..\\Common\\AFSUserStructs.h"
63
64 extern "C" {
65 #include <osilog.h>
66 extern osi_log_t *afsd_logp;
67
68 #include <WINNT/afsreg.h>
69 #include <afs/cm_config.h>
70 #include <afs/cm_error.h>
71 #include <afs/cm_nls.h>
72 #include <afs/cm_user.h>
73 }
74 #include <RDRPrototypes.h>
75
76 static DWORD
77 RDR_SetFileStatus2( AFSFileID * pFileId,
78                     GUID *pAuthGroup,
79                     DWORD dwStatus);
80
81 #ifndef FlagOn
82 #define FlagOn(_F,_SF)        ((_F) & (_SF))
83 #endif
84
85 #ifndef BooleanFlagOn
86 #define BooleanFlagOn(F,SF)   ((BOOLEAN)(((F) & (SF)) != 0))
87 #endif
88
89 #ifndef SetFlag
90 #define SetFlag(_F,_SF)       ((_F) |= (_SF))
91 #endif
92
93 #ifndef ClearFlag
94 #define ClearFlag(_F,_SF)     ((_F) &= ~(_SF))
95 #endif
96
97 #define QuadAlign(Ptr) (                \
98     ((((ULONG)(Ptr)) + 7) & 0xfffffff8) \
99     )
100
101 #define MIN_WORKER_THREADS 5
102 #define MAX_WORKER_THREADS 512
103
104 typedef struct _worker_thread_info {
105
106     HANDLE hThread;
107
108     ULONG  Flags;
109
110     HANDLE hEvent;
111
112 } WorkerThreadInfo;
113
114 WorkerThreadInfo glWorkerThreadInfo[ MAX_WORKER_THREADS];
115
116 UINT   glThreadHandleIndex = 0;
117
118 HANDLE glDevHandle = INVALID_HANDLE_VALUE;
119
120 static DWORD Exit = false;
121
122 static DWORD ExitPending = false;
123
124 DWORD  dwOvEvIdx = 0;
125
126 extern "C" wchar_t RDR_UNCName[64]=L"AFS";
127
128 HANDLE RDR_SuspendEvent = INVALID_HANDLE_VALUE;
129
130 /* returns 0 on success */
131 extern "C" DWORD
132 RDR_Initialize(void)
133 {
134
135     DWORD dwRet = 0;
136     HKEY parmKey;
137     DWORD dummyLen;
138     DWORD numSvThreads = CM_CONFIGDEFAULT_SVTHREADS;
139
140     // Initialize the Suspend Event
141     RDR_SuspendEvent = CreateEvent( NULL,
142                                     TRUE, // manual reset event
143                                     TRUE, // signaled
144                                     NULL);
145
146     dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
147                          0, KEY_QUERY_VALUE, &parmKey);
148     if (dwRet == ERROR_SUCCESS) {
149         dummyLen = sizeof(numSvThreads);
150         dwRet = RegQueryValueEx(parmKey, TEXT("ServerThreads"), NULL, NULL,
151                                 (BYTE *) &numSvThreads, &dummyLen);
152
153         dummyLen = sizeof(RDR_UNCName);
154         dwRet = RegQueryValueExW(parmKey, L"NetbiosName", NULL, NULL,
155                                  (BYTE *) RDR_UNCName, &dummyLen);
156
157         RegCloseKey (parmKey);
158     }
159
160     // Initialize the Thread local storage index for the overlapped i/o
161     // Event Handle
162     dwOvEvIdx = TlsAlloc();
163
164     Exit = false;
165
166     //
167     // Launch our workers down to the
168     // filters control device for processing requests
169     //
170
171     dwRet = RDR_ProcessWorkerThreads(numSvThreads);
172
173     if (dwRet == ERROR_SUCCESS) {
174
175         RDR_InitIoctl();
176         RDR_InitPipe();
177     }
178
179     return dwRet;
180 }
181
182 BOOL RDR_DeviceIoControl( HANDLE hDevice,
183                           DWORD dwIoControlCode,
184                           LPVOID lpInBuffer,
185                           DWORD nInBufferSize,
186                           LPVOID lpOutBuffer,
187                           DWORD nOutBufferSize,
188                           LPDWORD lpBytesReturned )
189 {
190     OVERLAPPED ov;
191     HANDLE hEvent;
192     BOOL rc = FALSE;
193     DWORD gle;
194
195     ZeroMemory(&ov, sizeof(OVERLAPPED));
196
197     hEvent = (HANDLE)TlsGetValue(dwOvEvIdx);
198     if (hEvent == NULL) {
199         hEvent = CreateEvent( NULL, TRUE, TRUE, NULL );
200         if (hEvent == INVALID_HANDLE_VALUE || hEvent == NULL)
201             return FALSE;
202         TlsSetValue( dwOvEvIdx, (LPVOID) hEvent );
203     }
204
205     ResetEvent( hEvent);
206     ov.hEvent = hEvent;
207     *lpBytesReturned = 0;
208
209     rc = DeviceIoControl( hDevice,
210                           dwIoControlCode,
211                           lpInBuffer,
212                           nInBufferSize,
213                           lpOutBuffer,
214                           nOutBufferSize,
215                           lpBytesReturned,
216                           &ov );
217     if ( !rc ) {
218         gle = GetLastError();
219
220         if ( gle == ERROR_IO_PENDING )
221             rc = GetOverlappedResult( hDevice, &ov, lpBytesReturned, TRUE );
222     }
223
224     return rc;
225 }
226
227 extern "C" DWORD
228 RDR_ShutdownFinal(void)
229 {
230
231     DWORD dwIndex = 0;
232
233     Exit = true;
234
235     //
236     // Close all the worker thread handles
237     //
238
239     while( dwIndex < glThreadHandleIndex)
240     {
241
242         CloseHandle( glWorkerThreadInfo[ dwIndex].hThread);
243
244         dwIndex++;
245     }
246
247     if( glDevHandle != INVALID_HANDLE_VALUE)
248     {
249
250         CloseHandle( glDevHandle);
251     }
252
253     return 0;
254 }
255
256 extern "C" DWORD
257 RDR_ShutdownNotify(void)
258 {
259
260     HANDLE hDevHandle = NULL;
261     DWORD bytesReturned;
262
263     //
264     // We use the global handle to the control device instance
265     //
266
267     hDevHandle = glDevHandle;
268
269
270     //
271     // First, notify the file system driver that
272     // we are shutting down.
273     //
274
275     ExitPending = true;
276
277     if( !RDR_DeviceIoControl( hDevHandle,
278                               IOCTL_AFS_SHUTDOWN,
279                               NULL,
280                               0,
281                               NULL,
282                               0,
283                               &bytesReturned ))
284     {
285         // log the error, nothing to do
286     }
287
288
289     RDR_ShutdownIoctl();
290     RDR_ShutdownPipe();
291
292     return 0;
293 }
294
295 //
296 // Here we launch the worker threads for the given volume
297 //
298
299 DWORD
300 RDR_ProcessWorkerThreads(DWORD numThreads)
301 {
302     DWORD WorkerID;
303     HANDLE hEvent;
304     DWORD index = 0;
305     DWORD bytesReturned = 0;
306     DWORD dwRedirInitInfo;
307     AFSRedirectorInitInfo * redirInitInfo = NULL;
308     DWORD dwErr;
309
310     if (dwErr = RDR_SetInitParams(&redirInitInfo, &dwRedirInitInfo))
311         return dwErr;
312
313     glDevHandle = CreateFile( AFS_SYMLINK_W,
314                               GENERIC_READ | GENERIC_WRITE,
315                               FILE_SHARE_READ | FILE_SHARE_WRITE,
316                               NULL,
317                               OPEN_EXISTING,
318                               FILE_FLAG_OVERLAPPED,
319                               NULL);
320
321     if( glDevHandle == INVALID_HANDLE_VALUE)
322     {
323         free(redirInitInfo);
324         return GetLastError();
325     }
326
327     //
328     // Now call down to initialize the pool.
329     //
330
331     if( !RDR_DeviceIoControl( glDevHandle,
332                               IOCTL_AFS_INITIALIZE_CONTROL_DEVICE,
333                               NULL,
334                               0,
335                               NULL,
336                               0,
337                               &bytesReturned ))
338     {
339
340         CloseHandle( glDevHandle);
341
342         glDevHandle = NULL;
343
344         free(redirInitInfo);
345
346         return GetLastError();
347     }
348
349     //
350     // OK, now launch the workers
351     //
352
353     hEvent = CreateEvent( NULL,
354                           TRUE,
355                           FALSE,
356                           NULL);
357
358     //
359     // Here we create a pool of worker threads but you can create the pool with as many requests
360     // as you want
361     //
362
363     if (numThreads < MIN_WORKER_THREADS)
364         numThreads = MIN_WORKER_THREADS;
365     else if (numThreads > MAX_WORKER_THREADS)
366         numThreads = MAX_WORKER_THREADS;
367
368     for (index = 0; index < numThreads; index++)
369     {
370         //
371         // 20% of worker threads should be reserved for release extent
372         // event processing
373         //
374         glWorkerThreadInfo[ glThreadHandleIndex].Flags =
375             (glThreadHandleIndex % 5) ? 0 : AFS_REQUEST_RELEASE_THREAD;
376         glWorkerThreadInfo[ glThreadHandleIndex].hEvent = hEvent;
377         glWorkerThreadInfo[ glThreadHandleIndex].hThread =
378             CreateThread( NULL,
379                           0,
380                           RDR_RequestWorkerThread,
381                           (void *)&glWorkerThreadInfo[ glThreadHandleIndex],
382                           0,
383                           &WorkerID);
384
385         if( glWorkerThreadInfo[ glThreadHandleIndex].hThread != NULL)
386         {
387
388             //
389             // Wait for the thread to signal it is ready for processing
390             //
391
392             WaitForSingleObject( hEvent,
393                                  INFINITE);
394
395             glThreadHandleIndex++;
396
397             ResetEvent( hEvent);
398         }
399         else
400         {
401
402             //
403             // Perform cleanup specific to your application
404             //
405
406         }
407     }
408
409     if( !RDR_DeviceIoControl( glDevHandle,
410                               IOCTL_AFS_INITIALIZE_REDIRECTOR_DEVICE,
411                               redirInitInfo,
412                               dwRedirInitInfo,
413                               NULL,
414                               0,
415                               &bytesReturned ))
416     {
417
418         CloseHandle( glDevHandle);
419
420         glDevHandle = NULL;
421
422         free(redirInitInfo);
423
424         return GetLastError();
425     }
426
427     free(redirInitInfo);
428
429     return 0;
430 }
431
432 //
433 // Entry point for the worker thread
434 //
435
436 DWORD
437 WINAPI
438 RDR_RequestWorkerThread( LPVOID lpParameter)
439 {
440
441     HANDLE hDevHandle = NULL;
442     DWORD bytesReturned;
443     AFSCommRequest *requestBuffer;
444     bool bError = false;
445     WorkerThreadInfo * pInfo = (WorkerThreadInfo *)lpParameter;
446
447     //
448     // We use the global handle to the control device instance
449     //
450
451     hDevHandle = glDevHandle;
452
453     //
454     // Allocate a request buffer.
455     //
456
457     requestBuffer = (AFSCommRequest *)malloc( sizeof( AFSCommRequest) + AFS_PAYLOAD_BUFFER_SIZE);
458
459     if( requestBuffer)
460     {
461
462         //
463         // Here we simply signal back to the main thread that we ahve started
464         //
465
466         SetEvent( pInfo->hEvent);
467
468         //
469         // Process requests until we are told to stop
470         //
471
472         while( !Exit)
473         {
474
475             memset( requestBuffer, '\0', sizeof( AFSCommRequest) + AFS_PAYLOAD_BUFFER_SIZE);
476
477             requestBuffer->RequestFlags = pInfo->Flags;
478
479             if( RDR_DeviceIoControl( hDevHandle,
480                                       IOCTL_AFS_PROCESS_IRP_REQUEST,
481                                       (void *)requestBuffer,
482                                       sizeof( AFSCommRequest),
483                                       (void *)requestBuffer,
484                                       sizeof( AFSCommRequest) + AFS_PAYLOAD_BUFFER_SIZE,
485                                       &bytesReturned ))
486             {
487
488                 WaitForSingleObject( RDR_SuspendEvent, INFINITE);
489
490                 //
491                 // Go process the request
492                 //
493
494                 if (!Exit)
495                     RDR_ProcessRequest( requestBuffer);
496             }
497             else
498             {
499
500                 if (afsd_logp->enabled) {
501                     WCHAR wchBuffer[256];
502                     DWORD gle = GetLastError();
503
504                     swprintf( wchBuffer,
505                               L"Failed to post IOCTL_AFS_IRP_REQUEST gle 0x%x", gle);
506                     osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
507                 }
508             }
509         }
510
511         free( requestBuffer);
512     }
513
514     ExitThread( 0);
515
516     return 0;
517 }
518
519 //
520 // This is the entry point for the worker threads to process the request from the TC Filter driver
521 //
522
523 void
524 RDR_ProcessRequest( AFSCommRequest *RequestBuffer)
525 {
526
527     DWORD               bytesReturned;
528     DWORD               result = 0;
529     ULONG               ulIndex = 0;
530     ULONG               ulCreateFlags = 0;
531     AFSCommResult *     pResultCB = NULL;
532     AFSCommResult       stResultCB;
533     DWORD               dwResultBufferLength = 0;
534     AFSSetFileExtentsCB * SetFileExtentsResultCB = NULL;
535     AFSSetByteRangeLockResultCB *SetByteRangeLockResultCB = NULL;
536     WCHAR               wchBuffer[1024];
537     char *pBuffer = (char *)wchBuffer;
538     DWORD gle;
539     cm_user_t *         userp = NULL;
540     BOOL                bWow64 = (RequestBuffer->RequestFlags & AFS_REQUEST_FLAG_WOW64) ? TRUE : FALSE;
541     BOOL                bFast  = (RequestBuffer->RequestFlags & AFS_REQUEST_FLAG_FAST_REQUEST) ? TRUE : FALSE;
542     BOOL                bHoldFid = (RequestBuffer->RequestFlags & AFS_REQUEST_FLAG_HOLD_FID) ? TRUE : FALSE;
543     BOOL                bFlushFile = (RequestBuffer->RequestFlags & AFS_REQUEST_FLAG_FLUSH_FILE) ? TRUE : FALSE;
544     BOOL                bDeleteFile = (RequestBuffer->RequestFlags & AFS_REQUEST_FLAG_FILE_DELETED) ? TRUE : FALSE;
545     BOOL                bUnlockFile = (RequestBuffer->RequestFlags & AFS_REQUEST_FLAG_BYTE_RANGE_UNLOCK_ALL) ? TRUE : FALSE;
546     BOOL                bCheckOnly = (RequestBuffer->RequestFlags & AFS_REQUEST_FLAG_CHECK_ONLY) ? TRUE : FALSE;
547     BOOL                bRetry = FALSE;
548     BOOL                bUnsupported = FALSE;
549     BOOL                bIsLocalSystem = (RequestBuffer->RequestFlags & AFS_REQUEST_LOCAL_SYSTEM_PAG) ? TRUE : FALSE;
550
551     userp = RDR_UserFromCommRequest(RequestBuffer);
552
553   retry:
554     //
555     // Build up the string to display based on the request type.
556     //
557
558     switch( RequestBuffer->RequestType)
559     {
560
561         case AFS_REQUEST_TYPE_DIR_ENUM:
562         {
563
564             AFSDirQueryCB *pQueryCB = (AFSDirQueryCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
565
566             if (afsd_logp->enabled) {
567                 swprintf( wchBuffer,
568                           L"ProcessRequest Processing AFS_REQUEST_TYPE_DIR_ENUM Index %08lX",
569                           RequestBuffer->RequestIndex);
570
571                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
572             }
573
574             //
575             // Here is where the content of the specific directory is enumerated.
576             //
577
578             RDR_EnumerateDirectory( userp, RequestBuffer->FileId,
579                                     pQueryCB, bWow64, bFast,
580                                     RequestBuffer->ResultBufferLength,
581                                     &pResultCB);
582             break;
583         }
584
585         case AFS_REQUEST_TYPE_EVAL_TARGET_BY_ID:
586         {
587             AFSEvalTargetCB *pEvalTargetCB = (AFSEvalTargetCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
588
589             if (afsd_logp->enabled) {
590                 swprintf( wchBuffer,
591                           L"ProcessRequest Processing AFS_REQUEST_TYPE_EVAL_TARGET_BY_ID Index %08lX",
592                           RequestBuffer->RequestIndex);
593
594                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
595             }
596             //
597             // Here is where the specified node is evaluated.
598             //
599
600             RDR_EvaluateNodeByID( userp, pEvalTargetCB->ParentId,
601                                   RequestBuffer->FileId,
602                                   bWow64, bFast, bHoldFid,
603                                   RequestBuffer->ResultBufferLength,
604                                   &pResultCB);
605             break;
606         }
607
608         case AFS_REQUEST_TYPE_EVAL_TARGET_BY_NAME:
609         {
610             AFSEvalTargetCB *pEvalTargetCB = (AFSEvalTargetCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
611
612             if (afsd_logp->enabled) {
613                 swprintf( wchBuffer,
614                           L"ProcessRequest Processing AFS_REQUEST_TYPE_EVAL_TARGET_BY_NAME Index %08lX",
615                           RequestBuffer->RequestIndex);
616
617                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
618             }
619             //
620             // Here is where the specified node is evaluated.
621             //
622
623             RDR_EvaluateNodeByName( userp, pEvalTargetCB->ParentId,
624                                     RequestBuffer->Name,
625                                     RequestBuffer->NameLength,
626                                     RequestBuffer->RequestFlags & AFS_REQUEST_FLAG_CASE_SENSITIVE ? TRUE : FALSE,
627                                     bWow64, bFast, bHoldFid,
628                                     RequestBuffer->ResultBufferLength,
629                                     &pResultCB);
630             break;
631         }
632
633         case AFS_REQUEST_TYPE_CREATE_FILE:
634         {
635
636             AFSFileCreateCB *pCreateCB = (AFSFileCreateCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
637
638             WCHAR wchFileName[ 256];
639
640             if (afsd_logp->enabled) {
641                 memset( wchFileName, '\0', 256 * sizeof( WCHAR));
642
643                 memcpy( wchFileName,
644                         RequestBuffer->Name,
645                         RequestBuffer->NameLength);
646
647                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_CREATE_FILE Index %08lX File %S",
648                           RequestBuffer->RequestIndex, wchFileName);
649
650                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
651             }
652
653             RDR_CreateFileEntry( userp,
654                                  RequestBuffer->Name,
655                                  RequestBuffer->NameLength,
656                                  pCreateCB,
657                                  bWow64,
658                                  bHoldFid,
659                                  RequestBuffer->ResultBufferLength,
660                                  &pResultCB);
661
662             break;
663         }
664
665         case AFS_REQUEST_TYPE_UPDATE_FILE:
666         {
667
668             AFSFileUpdateCB *pUpdateCB = (AFSFileUpdateCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
669
670             if (afsd_logp->enabled) {
671                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_UPDATE_FILE Index %08lX File %08lX.%08lX.%08lX.%08lX",
672                           RequestBuffer->RequestIndex,
673                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
674                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
675
676                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
677             }
678
679             RDR_UpdateFileEntry( userp, RequestBuffer->FileId,
680                                  pUpdateCB,
681                                  bWow64,
682                                  RequestBuffer->ResultBufferLength,
683                                  &pResultCB);
684
685             break;
686         }
687
688         case AFS_REQUEST_TYPE_DELETE_FILE:
689         {
690
691             AFSFileDeleteCB *pDeleteCB = (AFSFileDeleteCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
692
693             if (afsd_logp->enabled) {
694                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_DELETE_FILE Index %08lX %08lX.%08lX.%08lX.%08lX CheckOnly %X",
695                           RequestBuffer->RequestIndex,
696                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
697                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique,
698                           bCheckOnly);
699
700                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
701             }
702
703             RDR_DeleteFileEntry( userp,
704                                  pDeleteCB->ParentId,
705                                  pDeleteCB->ProcessId,
706                                  RequestBuffer->Name,
707                                  RequestBuffer->NameLength,
708                                  bWow64,
709                                  bCheckOnly,
710                                  RequestBuffer->ResultBufferLength,
711                                  &pResultCB);
712
713             break;
714         }
715
716         case AFS_REQUEST_TYPE_RENAME_FILE:
717         {
718
719             AFSFileRenameCB *pFileRenameCB = (AFSFileRenameCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
720
721             if (afsd_logp->enabled) {
722                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_RENAME_FILE Index %08lX File %08lX.%08lX.%08lX.%08lX NameLength %08lX Name %*S TargetLength %08lX Target %*S",
723                           RequestBuffer->RequestIndex,
724                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
725                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique,
726                           RequestBuffer->NameLength, (int)RequestBuffer->NameLength, RequestBuffer->Name,
727                           pFileRenameCB->TargetNameLength, (int)pFileRenameCB->TargetNameLength, pFileRenameCB->TargetName);
728
729                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
730             }
731
732             RDR_RenameFileEntry( userp,
733                                  RequestBuffer->Name,
734                                  RequestBuffer->NameLength,
735                                  RequestBuffer->FileId,
736                                  pFileRenameCB,
737                                  bWow64,
738                                  RequestBuffer->ResultBufferLength,
739                                  &pResultCB);
740
741             break;
742         }
743
744         case AFS_REQUEST_TYPE_HARDLINK_FILE:
745         {
746
747             AFSFileHardLinkCB *pFileHardLinkCB = (AFSFileHardLinkCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
748
749             if (afsd_logp->enabled) {
750                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_HARDLINK_FILE Index %08lX File %08lX.%08lX.%08lX.%08lX NameLength %08lX Name %*S TargetLength %08lX Target %*S",
751                           RequestBuffer->RequestIndex,
752                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
753                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique,
754                           RequestBuffer->NameLength, (int)RequestBuffer->NameLength, RequestBuffer->Name,
755                           pFileHardLinkCB->TargetNameLength, (int)pFileHardLinkCB->TargetNameLength, pFileHardLinkCB->TargetName);
756
757                     osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
758                 }
759
760                 RDR_HardLinkFileEntry( userp,
761                                        RequestBuffer->Name,
762                                        RequestBuffer->NameLength,
763                                        RequestBuffer->FileId,
764                                        pFileHardLinkCB,
765                                        bWow64,
766                                        RequestBuffer->ResultBufferLength,
767                                        &pResultCB);
768
769             break;
770         }
771
772         case AFS_REQUEST_TYPE_REQUEST_FILE_EXTENTS:
773         {
774
775             AFSRequestExtentsCB *pFileRequestExtentsCB = (AFSRequestExtentsCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
776
777             if (afsd_logp->enabled) {
778                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_REQUEST_FILE_EXTENTS Index %08lX File %08lX.%08lX.%08lX.%08lX %S",
779                           RequestBuffer->RequestIndex,
780                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
781                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique,
782                           BooleanFlagOn( RequestBuffer->RequestFlags, AFS_REQUEST_FLAG_SYNCHRONOUS) ? L"Sync" : L"Async");
783
784                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
785             }
786
787             if (BooleanFlagOn( RequestBuffer->RequestFlags, AFS_REQUEST_FLAG_SYNCHRONOUS))
788                 osi_panic("SYNCHRONOUS AFS_REQUEST_TYPE_REQUEST_FILE_EXTENTS not supported",
789                           __FILE__, __LINE__);
790             else
791                 bRetry = RDR_RequestFileExtentsAsync( userp, RequestBuffer->FileId,
792                                                       pFileRequestExtentsCB,
793                                                       bWow64,
794                                                       &dwResultBufferLength,
795                                                       &SetFileExtentsResultCB );
796             break;
797         }
798
799         case AFS_REQUEST_TYPE_RELEASE_FILE_EXTENTS:
800         {
801
802             AFSReleaseExtentsCB *pFileReleaseExtentsCB = (AFSReleaseExtentsCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
803
804             if (afsd_logp->enabled) {
805                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_RELEASE_FILE_EXTENTS Index %08lX File %08lX.%08lX.%08lX.%08lX",
806                           RequestBuffer->RequestIndex,
807                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
808                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
809
810                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
811             }
812
813             RDR_ReleaseFileExtents( userp, RequestBuffer->FileId,
814                                     pFileReleaseExtentsCB,
815                                     bWow64,
816                                     RequestBuffer->ResultBufferLength,
817                                     &pResultCB);
818
819             break;
820         }
821
822         case AFS_REQUEST_TYPE_FLUSH_FILE:
823         {
824             if (afsd_logp->enabled) {
825                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_FLUSH_FILE Index %08lX File %08lX.%08lX.%08lX.%08lX",
826                           RequestBuffer->RequestIndex,
827                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
828                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
829
830                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
831             }
832
833             RDR_FlushFileEntry( userp, RequestBuffer->FileId,
834                                 bWow64,
835                                 RequestBuffer->ResultBufferLength,
836                                 &pResultCB);
837             break;
838         }
839
840         case AFS_REQUEST_TYPE_OPEN_FILE:
841         {
842             AFSFileOpenCB *pFileOpenCB = (AFSFileOpenCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
843
844             if (afsd_logp->enabled) {
845                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_OPEN_FILE Index %08lX File %08lX.%08lX.%08lX.%08lX",
846                           RequestBuffer->RequestIndex,
847                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
848                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
849
850                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
851             }
852
853             RDR_OpenFileEntry( userp, RequestBuffer->FileId,
854                                pFileOpenCB,
855                                bWow64,
856                                bHoldFid,
857                                RequestBuffer->ResultBufferLength,
858                                &pResultCB);
859
860             break;
861         }
862
863         case AFS_REQUEST_TYPE_RELEASE_FILE_ACCESS:
864         {
865             AFSFileAccessReleaseCB *pFileAccessReleaseCB = (AFSFileAccessReleaseCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
866
867             if (afsd_logp->enabled) {
868                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_RELEASE_FILE_ACCESS Index %08lX File %08lX.%08lX.%08lX.%08lX",
869                           RequestBuffer->RequestIndex,
870                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
871                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
872
873                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
874             }
875
876             RDR_ReleaseFileAccess( userp,
877                                    RequestBuffer->FileId,
878                                    pFileAccessReleaseCB,
879                                    bWow64,
880                                    RequestBuffer->ResultBufferLength,
881                                    &pResultCB);
882
883             break;
884         }
885
886         case AFS_REQUEST_TYPE_PIOCTL_OPEN:
887         {
888             AFSPIOCtlOpenCloseRequestCB *pPioctlCB = (AFSPIOCtlOpenCloseRequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
889
890             if (afsd_logp->enabled) {
891                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_PIOCTL_OPEN Index %08lX Parent %08lX.%08lX.%08lX.%08lX",
892                           RequestBuffer->RequestIndex,
893                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
894                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
895
896                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
897             }
898
899             RDR_PioctlOpen( userp,
900                             RequestBuffer->FileId,
901                             pPioctlCB,
902                             bWow64,
903                             RequestBuffer->ResultBufferLength,
904                             &pResultCB);
905             break;
906         }
907
908         case AFS_REQUEST_TYPE_PIOCTL_WRITE:
909         {
910             AFSPIOCtlIORequestCB *pPioctlCB = (AFSPIOCtlIORequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
911
912             if (afsd_logp->enabled) {
913                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_PIOCTL_WRITE Index %08lX Parent %08lX.%08lX.%08lX.%08lX",
914                           RequestBuffer->RequestIndex,
915                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
916                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
917
918                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
919             }
920
921             RDR_PioctlWrite( userp,
922                              RequestBuffer->FileId,
923                              pPioctlCB,
924                              bWow64,
925                              RequestBuffer->ResultBufferLength,
926                              &pResultCB);
927             break;
928         }
929
930         case AFS_REQUEST_TYPE_PIOCTL_READ:
931         {
932             AFSPIOCtlIORequestCB *pPioctlCB = (AFSPIOCtlIORequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
933
934             if (afsd_logp->enabled) {
935                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_PIOCTL_READ Index %08lX Parent %08lX.%08lX.%08lX.%08lX",
936                           RequestBuffer->RequestIndex,
937                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
938                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
939
940                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
941             }
942
943             RDR_PioctlRead( userp,
944                             RequestBuffer->FileId,
945                             pPioctlCB,
946                             bWow64,
947                             bIsLocalSystem,
948                             RequestBuffer->ResultBufferLength,
949                             &pResultCB);
950             break;
951         }
952
953         case AFS_REQUEST_TYPE_PIOCTL_CLOSE:
954         {
955             AFSPIOCtlOpenCloseRequestCB *pPioctlCB = (AFSPIOCtlOpenCloseRequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
956
957             if (afsd_logp->enabled) {
958                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_PIOCTL_CLOSE Index %08lX Parent %08lX.%08lX.%08lX.%08lX",
959                           RequestBuffer->RequestIndex,
960                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
961                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
962
963                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
964             }
965
966             RDR_PioctlClose( userp,
967                              RequestBuffer->FileId,
968                              pPioctlCB,
969                              bWow64,
970                              RequestBuffer->ResultBufferLength,
971                              &pResultCB);
972             break;
973         }
974
975
976         case AFS_REQUEST_TYPE_BYTE_RANGE_LOCK:
977         {
978             if (afsd_logp->enabled) {
979                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_BYTE_RANGE_LOCK Index %08lX File %08lX.%08lX.%08lX.%08lX %S",
980                           RequestBuffer->RequestIndex,
981                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
982                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique,
983                           BooleanFlagOn( RequestBuffer->RequestFlags, AFS_REQUEST_FLAG_SYNCHRONOUS) ? L"Sync" : L"Async");
984
985                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
986             }
987
988             AFSByteRangeLockRequestCB *pBRLRequestCB = (AFSByteRangeLockRequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
989
990             RDR_ByteRangeLockSync( userp,
991                                    RequestBuffer->FileId,
992                                    pBRLRequestCB,
993                                    bWow64,
994                                    RequestBuffer->ResultBufferLength,
995                                    &pResultCB);
996
997             break;
998         }
999
1000         case AFS_REQUEST_TYPE_BYTE_RANGE_UNLOCK:
1001         {
1002             AFSByteRangeUnlockRequestCB *pBRURequestCB = (AFSByteRangeUnlockRequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
1003
1004             if (afsd_logp->enabled) {
1005                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_BYTE_RANGE_UNLOCK Index %08lX File %08lX.%08lX.%08lX.%08lX",
1006                           RequestBuffer->RequestIndex,
1007                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
1008                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
1009
1010                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1011             }
1012
1013             RDR_ByteRangeUnlock( userp,
1014                                  RequestBuffer->FileId,
1015                                  pBRURequestCB,
1016                                  bWow64,
1017                                  RequestBuffer->ResultBufferLength,
1018                                  &pResultCB);
1019             break;
1020         }
1021
1022         case AFS_REQUEST_TYPE_BYTE_RANGE_UNLOCK_ALL:
1023         {
1024             AFSByteRangeUnlockRequestCB *pBRURequestCB = (AFSByteRangeUnlockRequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
1025
1026             if (afsd_logp->enabled) {
1027                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_BYTE_RANGE_UNLOCK_ALL Index %08lX File %08lX.%08lX.%08lX.%08lX",
1028                           RequestBuffer->RequestIndex,
1029                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
1030                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
1031
1032                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1033             }
1034
1035             RDR_ByteRangeUnlockAll( userp,
1036                                     RequestBuffer->FileId,
1037                                     pBRURequestCB,
1038                                     bWow64,
1039                                     RequestBuffer->ResultBufferLength,
1040                                     &pResultCB);
1041             break;
1042         }
1043
1044         case AFS_REQUEST_TYPE_GET_VOLUME_INFO:
1045         {
1046             if (afsd_logp->enabled) {
1047                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_GET_VOLUME_INFO Index %08lX File %08lX.%08lX.%08lX.%08lX",
1048                           RequestBuffer->RequestIndex,
1049                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
1050                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
1051
1052                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1053             }
1054
1055             RDR_GetVolumeInfo( userp,
1056                                RequestBuffer->FileId,
1057                                bWow64,
1058                                RequestBuffer->ResultBufferLength,
1059                                &pResultCB);
1060             break;
1061         }
1062
1063         case AFS_REQUEST_TYPE_GET_VOLUME_SIZE_INFO:
1064         {
1065             if (afsd_logp->enabled) {
1066                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_GET_VOLUME_SIZE_INFO Index %08lX File %08lX.%08lX.%08lX.%08lX",
1067                           RequestBuffer->RequestIndex,
1068                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
1069                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
1070
1071                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1072             }
1073
1074             RDR_GetVolumeSizeInfo( userp,
1075                                    RequestBuffer->FileId,
1076                                    bWow64,
1077                                    RequestBuffer->ResultBufferLength,
1078                                    &pResultCB);
1079             break;
1080         }
1081
1082         case AFS_REQUEST_TYPE_HOLD_FID:
1083         {
1084
1085             AFSHoldFidRequestCB *pHoldFidCB = (AFSHoldFidRequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
1086
1087             if (afsd_logp->enabled) {
1088                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_HOLD_FID Index %08lX",
1089                           RequestBuffer->RequestIndex);
1090
1091                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1092             }
1093
1094             RDR_HoldFid( userp,
1095                          pHoldFidCB,
1096                          bFast,
1097                          RequestBuffer->ResultBufferLength,
1098                          &pResultCB);
1099
1100             break;
1101         }
1102
1103         case AFS_REQUEST_TYPE_RELEASE_FID:
1104         {
1105
1106             AFSReleaseFidRequestCB *pReleaseFidCB = (AFSReleaseFidRequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
1107
1108             if (afsd_logp->enabled) {
1109                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_RELEASE_FID Index %08lX",
1110                           RequestBuffer->RequestIndex);
1111
1112                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1113             }
1114
1115             RDR_ReleaseFid( userp,
1116                             pReleaseFidCB,
1117                             bFast,
1118                             RequestBuffer->ResultBufferLength,
1119                             &pResultCB);
1120
1121             break;
1122         }
1123
1124         case AFS_REQUEST_TYPE_CLEANUP_PROCESSING:
1125         {
1126
1127             AFSFileCleanupCB *pCleanupCB = (AFSFileCleanupCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
1128
1129             if (afsd_logp->enabled) {
1130                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_CLEANUP_FILE Index %08lX File %08lX.%08lX.%08lX.%08lX",
1131                           RequestBuffer->RequestIndex,
1132                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
1133                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
1134
1135                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1136             }
1137
1138             RDR_CleanupFileEntry( userp,
1139                                   RequestBuffer->FileId,
1140                                   RequestBuffer->Name,
1141                                   RequestBuffer->NameLength,
1142                                   pCleanupCB,
1143                                   bWow64,
1144                                   bFlushFile,
1145                                   bDeleteFile,
1146                                   bUnlockFile,
1147                                   RequestBuffer->ResultBufferLength,
1148                                   &pResultCB);
1149
1150             break;
1151         }
1152
1153         case AFS_REQUEST_TYPE_PIPE_OPEN:
1154         {
1155             AFSPipeOpenCloseRequestCB *pPipeCB = (AFSPipeOpenCloseRequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
1156
1157             if (afsd_logp->enabled) {
1158                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_PIPE_OPEN Index %08lX Parent %08lX.%08lX.%08lX.%08lX",
1159                           RequestBuffer->RequestIndex,
1160                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
1161                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
1162
1163                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1164             }
1165
1166             RDR_PipeOpen( userp,
1167                           RequestBuffer->FileId,
1168                           RequestBuffer->Name,
1169                           RequestBuffer->NameLength,
1170                           pPipeCB,
1171                           bWow64,
1172                           RequestBuffer->ResultBufferLength,
1173                           &pResultCB);
1174             break;
1175         }
1176
1177         case AFS_REQUEST_TYPE_PIPE_WRITE:
1178         {
1179             AFSPipeIORequestCB *pPipeCB = (AFSPipeIORequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
1180             BYTE *pPipeData = ((BYTE *)RequestBuffer->Name + RequestBuffer->DataOffset + sizeof(AFSPipeIORequestCB));
1181
1182             if (afsd_logp->enabled) {
1183                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_PIPE_WRITE Index %08lX Parent %08lX.%08lX.%08lX.%08lX",
1184                           RequestBuffer->RequestIndex,
1185                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
1186                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
1187
1188                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1189             }
1190
1191             RDR_PipeWrite( userp,
1192                            RequestBuffer->FileId,
1193                            pPipeCB,
1194                            pPipeData,
1195                            bWow64,
1196                            RequestBuffer->ResultBufferLength,
1197                            &pResultCB);
1198             break;
1199         }
1200
1201         case AFS_REQUEST_TYPE_PIPE_READ:
1202         {
1203             AFSPipeIORequestCB *pPipeCB = (AFSPipeIORequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
1204
1205             if (afsd_logp->enabled) {
1206                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_PIPE_READ Index %08lX Parent %08lX.%08lX.%08lX.%08lX",
1207                           RequestBuffer->RequestIndex,
1208                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
1209                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
1210
1211                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1212             }
1213
1214             RDR_PipeRead( userp,
1215                           RequestBuffer->FileId,
1216                           pPipeCB,
1217                           bWow64,
1218                           RequestBuffer->ResultBufferLength,
1219                           &pResultCB);
1220             break;
1221         }
1222
1223         case AFS_REQUEST_TYPE_PIPE_CLOSE:
1224         {
1225             AFSPipeOpenCloseRequestCB *pPipeCB = (AFSPipeOpenCloseRequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
1226
1227             if (afsd_logp->enabled) {
1228                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_PIPE_CLOSE Index %08lX Parent %08lX.%08lX.%08lX.%08lX",
1229                           RequestBuffer->RequestIndex,
1230                           RequestBuffer->FileId.Cell, RequestBuffer->FileId.Volume,
1231                           RequestBuffer->FileId.Vnode, RequestBuffer->FileId.Unique);
1232
1233                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1234             }
1235
1236             RDR_PipeClose( userp,
1237                            RequestBuffer->FileId,
1238                            pPipeCB,
1239                            bWow64,
1240                            RequestBuffer->ResultBufferLength,
1241                            &pResultCB);
1242             break;
1243         }
1244
1245
1246         case AFS_REQUEST_TYPE_PIPE_TRANSCEIVE:
1247         {
1248             AFSPipeIORequestCB *pPipeCB = (AFSPipeIORequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
1249             BYTE *pPipeData = ((BYTE *)RequestBuffer->Name + RequestBuffer->DataOffset + sizeof(AFSPipeIORequestCB));
1250
1251             if (afsd_logp->enabled) {
1252                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_PIPE_TRANSCEIVE Index %08lX",
1253                           RequestBuffer->RequestIndex);
1254
1255                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1256             }
1257
1258             RDR_PipeTransceive( userp,
1259                                 RequestBuffer->FileId,
1260                                 pPipeCB,
1261                                 pPipeData,
1262                                 bWow64,
1263                                 RequestBuffer->ResultBufferLength,
1264                                 &pResultCB);
1265             break;
1266         }
1267
1268         case AFS_REQUEST_TYPE_PIPE_QUERY_INFO:
1269         {
1270             AFSPipeInfoRequestCB *pPipeInfoCB = (AFSPipeInfoRequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
1271
1272             if (afsd_logp->enabled) {
1273                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_PIPE_QUERY_INFO Index %08lX",
1274                           RequestBuffer->RequestIndex);
1275
1276                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1277             }
1278
1279             RDR_PipeQueryInfo( userp,
1280                                RequestBuffer->FileId,
1281                                pPipeInfoCB,
1282                                bWow64,
1283                                RequestBuffer->ResultBufferLength,
1284                                &pResultCB);
1285             break;
1286         }
1287
1288         case AFS_REQUEST_TYPE_PIPE_SET_INFO:
1289         {
1290             AFSPipeInfoRequestCB *pPipeInfoCB = (AFSPipeInfoRequestCB *)((char *)RequestBuffer->Name + RequestBuffer->DataOffset);
1291             BYTE *pPipeData = ((BYTE *)RequestBuffer->Name + RequestBuffer->DataOffset + sizeof(AFSPipeInfoRequestCB));
1292
1293             if (afsd_logp->enabled) {
1294                 swprintf( wchBuffer, L"ProcessRequest Processing AFS_REQUEST_TYPE_PIPE_SET_INFO Index %08lX",
1295                           RequestBuffer->RequestIndex);
1296
1297                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1298             }
1299
1300             RDR_PipeSetInfo( userp,
1301                              RequestBuffer->FileId,
1302                              pPipeInfoCB,
1303                              pPipeData,
1304                              bWow64,
1305                              RequestBuffer->ResultBufferLength,
1306                              &pResultCB);
1307
1308             break;
1309         }
1310
1311         default:
1312             bUnsupported = TRUE;
1313
1314             if (afsd_logp->enabled) {
1315                 swprintf( wchBuffer, L"ProcessRequest Received unknown request type %08lX Index %08lX",
1316                           RequestBuffer->RequestType,
1317                           RequestBuffer->RequestIndex);
1318
1319                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1320             }
1321
1322             break;
1323     }
1324
1325     if (userp) {
1326         pResultCB->Authenticated = cm_HaveToken( userp,
1327                                                  RequestBuffer->FileId.Cell);
1328     }
1329
1330     if( BooleanFlagOn( RequestBuffer->RequestFlags, AFS_REQUEST_FLAG_SYNCHRONOUS))
1331     {
1332         if (pResultCB == NULL) {
1333             // We failed probably due to a memory allocation error
1334             // unless the unsupported flag was set.
1335             pResultCB = &stResultCB;
1336             memset(&stResultCB, 0, sizeof(stResultCB));
1337             if ( bUnsupported )
1338                 pResultCB->ResultStatus = STATUS_NOT_IMPLEMENTED;
1339             else
1340                 pResultCB->ResultStatus = STATUS_NO_MEMORY;
1341         }
1342
1343         //
1344         // This is how the filter associates the response information passed in the IOCtl below to the
1345         // original call. This request index is setup by the filter and should not be modified, otherwise the
1346         // filter will not be able to locate the request in its internal queue and the blocking thread will
1347         // not be awakened
1348         //
1349
1350         pResultCB->RequestIndex = RequestBuffer->RequestIndex;
1351
1352         if (afsd_logp->enabled) {
1353             swprintf( wchBuffer,
1354                       L"ProcessRequest Responding to Index %08lX Length %08lX",
1355                       pResultCB->RequestIndex,
1356                       pResultCB->ResultBufferLength);
1357
1358             osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1359         }
1360
1361         //
1362         // Now post the result back to the driver.
1363         //
1364
1365         if( !RDR_DeviceIoControl( glDevHandle,
1366                                   IOCTL_AFS_PROCESS_IRP_RESULT,
1367                                   (void *)pResultCB,
1368                                   sizeof( AFSCommResult) + pResultCB->ResultBufferLength,
1369                                   (void *)NULL,
1370                                   0,
1371                                   &bytesReturned ))
1372         {
1373             char *pBuffer = (char *)wchBuffer;
1374             gle = GetLastError();
1375             if (afsd_logp->enabled) {
1376                 swprintf( wchBuffer,
1377                           L"Failed to post IOCTL_AFS_PROCESS_IRP_RESULT gle %X", gle);
1378                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1379             }
1380
1381             if (gle != ERROR_NOT_READY) {
1382                 sprintf( pBuffer,
1383                          "Failed to post IOCTL_AFS_PROCESS_IRP_RESULT gle %X",
1384                          GetLastError());
1385                 osi_panic(pBuffer, __FILE__, __LINE__);
1386             }
1387         }
1388
1389     }
1390     else if (RequestBuffer->RequestType == AFS_REQUEST_TYPE_REQUEST_FILE_EXTENTS) {
1391
1392         if (SetFileExtentsResultCB) {
1393
1394             if (1 || afsd_logp->enabled) {
1395                 if (SetFileExtentsResultCB->ResultStatus != 0)
1396                     swprintf( wchBuffer,
1397                           L"ProcessRequest Responding Asynchronously with FAILURE to REQUEST_FILE_EXTENTS Index %08lX Count %08lX Status %08lX",
1398                           RequestBuffer->RequestIndex, SetFileExtentsResultCB->ExtentCount, SetFileExtentsResultCB->ResultStatus);
1399                 else
1400                     swprintf( wchBuffer,
1401                           L"ProcessRequest Responding Asynchronously with SUCCESS to REQUEST_FILE_EXTENTS Index %08lX Count %08lX",
1402                           RequestBuffer->RequestIndex, SetFileExtentsResultCB->ExtentCount);
1403
1404                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1405             }
1406
1407             if( (SetFileExtentsResultCB->ExtentCount != 0 ||
1408                  SetFileExtentsResultCB->ResultStatus != 0) &&
1409                 !RDR_DeviceIoControl( glDevHandle,
1410                                        IOCTL_AFS_SET_FILE_EXTENTS,
1411                                       (void *)SetFileExtentsResultCB,
1412                                       dwResultBufferLength,
1413                                       (void *)NULL,
1414                                       0,
1415                                       &bytesReturned ))
1416             {
1417                 gle = GetLastError();
1418                 if (afsd_logp->enabled) {
1419                     swprintf( wchBuffer,
1420                               L"Failed to post IOCTL_AFS_SET_FILE_EXTENTS gle %X",
1421                               gle);
1422                     osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1423                 }
1424
1425                 // The file system returns an error when it can't find the FID
1426                 // This is a bug in the file system but we should try to avoid
1427                 // the crash and clean up our own memory space.
1428                 //
1429                 // Since we couldn't deliver the extents to the file system
1430                 // we should release them.
1431                 if ( SetFileExtentsResultCB->ExtentCount != 0)
1432                 {
1433                     RDR_ReleaseFailedSetFileExtents( userp,
1434                                                  SetFileExtentsResultCB,
1435                                                  dwResultBufferLength);
1436                 }
1437
1438                 if (gle != ERROR_GEN_FAILURE &&
1439                     gle != ERROR_NOT_READY) {
1440                     sprintf( pBuffer,
1441                              "Failed to post IOCTL_AFS_SET_FILE_EXTENTS gle %X",
1442                              gle);
1443                     osi_panic(pBuffer, __FILE__, __LINE__);
1444                 }
1445             }
1446
1447             free(SetFileExtentsResultCB);
1448
1449       } else {
1450           /* Must be out of memory */
1451           if (afsd_logp->enabled) {
1452               swprintf( wchBuffer,
1453                         L"ProcessRequest Responding Asynchronously STATUS_NO_MEMORY to REQUEST_FILE_EXTENTS Index %08lX",
1454                         RequestBuffer->RequestIndex);
1455
1456               osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1457           }
1458
1459           RDR_SetFileStatus2( &RequestBuffer->FileId, &RequestBuffer->AuthGroup, STATUS_NO_MEMORY);
1460        }
1461     }
1462     else if (RequestBuffer->RequestType == AFS_REQUEST_TYPE_BYTE_RANGE_LOCK) {
1463
1464         if (afsd_logp->enabled) {
1465             swprintf( wchBuffer,
1466                       L"ProcessRequest Responding Asynchronously to REQUEST_TYPE_BYTE_RANGELOCK Index %08lX",
1467                       RequestBuffer->RequestIndex);
1468
1469             osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1470         }
1471
1472
1473         if (SetByteRangeLockResultCB) {
1474
1475             if( !RDR_DeviceIoControl( glDevHandle,
1476                                   IOCTL_AFS_SET_BYTE_RANGE_LOCKS,
1477                                   (void *)SetByteRangeLockResultCB,
1478                                   dwResultBufferLength,
1479                                   (void *)NULL,
1480                                   0,
1481                                   &bytesReturned ))
1482             {
1483                 gle = GetLastError();
1484
1485                 if (afsd_logp->enabled) {
1486                     swprintf( wchBuffer,
1487                               L"Failed to post IOCTL_AFS_SET_BYTE_RANGE_LOCKS gle 0x%x", gle);
1488                     osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1489                 }
1490
1491
1492                 if (gle != ERROR_NOT_READY) {
1493                     // TODO - instead of a panic we should release the locks
1494                     sprintf( pBuffer,
1495                              "Failed to post IOCTL_AFS_SET_BYTE_RANGE_LOCKS gle %X", gle);
1496                     osi_panic(pBuffer, __FILE__, __LINE__);
1497                 }
1498             }
1499
1500             free(SetByteRangeLockResultCB);
1501         } else {
1502             /* Must be out of memory */
1503             AFSSetByteRangeLockResultCB SetByteRangeLockResultCB;
1504
1505             dwResultBufferLength = sizeof(AFSSetByteRangeLockResultCB);
1506             memset( &SetByteRangeLockResultCB, '\0', dwResultBufferLength );
1507             SetByteRangeLockResultCB.FileId = RequestBuffer->FileId;
1508             SetByteRangeLockResultCB.Result[0].Status = STATUS_NO_MEMORY;
1509
1510             if( !RDR_DeviceIoControl( glDevHandle,
1511                                       IOCTL_AFS_SET_BYTE_RANGE_LOCKS,
1512                                       (void *)&SetByteRangeLockResultCB,
1513                                       dwResultBufferLength,
1514                                       (void *)NULL,
1515                                       0,
1516                                       &bytesReturned ))
1517             {
1518                 gle = GetLastError();
1519
1520                 if (afsd_logp->enabled) {
1521                     swprintf( wchBuffer,
1522                               L"Failed to post IOCTL_AFS_SET_BYTE_RANGE_LOCKS gle 0x%x", gle);
1523                     osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1524                 }
1525
1526                 /* We were out of memory - nothing to do */
1527             }
1528         }
1529     }
1530     else {
1531
1532         if (afsd_logp->enabled) {
1533             swprintf( wchBuffer,
1534                       L"ProcessRequest Not responding to async Index %08lX",
1535                       RequestBuffer->RequestIndex);
1536
1537             osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1538         }
1539     }
1540
1541     if (bRetry)
1542         goto retry;
1543
1544     if (userp)
1545         RDR_ReleaseUser(userp);
1546
1547
1548     if( pResultCB && pResultCB != &stResultCB)
1549     {
1550
1551         free( pResultCB);
1552     }
1553     return;
1554 }
1555
1556
1557 extern "C" DWORD
1558 RDR_SetFileExtents( AFSSetFileExtentsCB *pSetFileExtentsResultCB,
1559                     DWORD dwResultBufferLength)
1560 {
1561     WCHAR wchBuffer[1024];
1562     DWORD bytesReturned;
1563     DWORD gle;
1564
1565     if (1 || afsd_logp->enabled) {
1566         if (pSetFileExtentsResultCB->ResultStatus != 0)
1567             swprintf( wchBuffer,
1568                L"RDR_SetFileExtents IOCTL_AFS_SET_FILE_EXTENTS FAILURE Count %08lX Status %08lX",
1569                pSetFileExtentsResultCB->ExtentCount, pSetFileExtentsResultCB->ResultStatus);
1570         else
1571             swprintf( wchBuffer,
1572                L"RDR_SetFileExtents IOCTL_AFS_SET_FILE_EXTENTS SUCCESS Count %08lX",
1573                pSetFileExtentsResultCB->ExtentCount);
1574
1575         osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1576     }
1577
1578     if( !RDR_DeviceIoControl( glDevHandle,
1579                               IOCTL_AFS_SET_FILE_EXTENTS,
1580                               (void *)pSetFileExtentsResultCB,
1581                               dwResultBufferLength,
1582                               (void *)NULL,
1583                               0,
1584                               &bytesReturned ))
1585     {
1586         gle = GetLastError();
1587         return gle;
1588     }
1589
1590     return 0;
1591 }
1592
1593
1594 extern "C" DWORD
1595 RDR_SetFileStatus( cm_fid_t *fidp,
1596                    GUID *pAuthGroup,
1597                    DWORD dwStatus)
1598 {
1599     WCHAR               wchBuffer[1024];
1600     AFSExtentFailureCB  SetFileStatusCB;
1601     DWORD               bytesReturned;
1602     DWORD               gle;
1603
1604     RDR_fid2FID(fidp, &SetFileStatusCB.FileId);
1605     memcpy(&SetFileStatusCB.AuthGroup, pAuthGroup, sizeof(GUID));
1606     SetFileStatusCB.FailureStatus = dwStatus;
1607
1608     if (afsd_logp->enabled) {
1609         swprintf( wchBuffer, L"RDR_SetFileStatus IOCTL_AFS_EXTENT_FAILURE_CB Fid %08lX.%08lX.%08lX.%08lX Status 0x%lX",
1610                   SetFileStatusCB.FileId.Cell, SetFileStatusCB.FileId.Volume,
1611                   SetFileStatusCB.FileId.Vnode, SetFileStatusCB.FileId.Unique,
1612                   dwStatus);
1613
1614         osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1615     }
1616
1617     if( !RDR_DeviceIoControl( glDevHandle,
1618                               IOCTL_AFS_SET_FILE_EXTENT_FAILURE,
1619                               (void *)&SetFileStatusCB,
1620                               sizeof(AFSExtentFailureCB),
1621                               (void *)NULL,
1622                               0,
1623                               &bytesReturned ))
1624     {
1625         gle = GetLastError();
1626         return gle;
1627     }
1628
1629     return 0;
1630 }
1631
1632 static DWORD
1633 RDR_SetFileStatus2( AFSFileID *pFileId,
1634                    GUID *pAuthGroup,
1635                    DWORD dwStatus)
1636 {
1637     WCHAR               wchBuffer[1024];
1638     AFSExtentFailureCB  SetFileStatusCB;
1639     DWORD               bytesReturned;
1640     DWORD               gle;
1641
1642     memcpy(&SetFileStatusCB.FileId, pFileId, sizeof(AFSFileID));
1643     memcpy(&SetFileStatusCB.AuthGroup, pAuthGroup, sizeof(GUID));
1644     SetFileStatusCB.FailureStatus = dwStatus;
1645
1646     if (afsd_logp->enabled) {
1647         swprintf( wchBuffer, L"RDR_SetFileStatus2 IOCTL_AFS_EXTENT_FAILURE_CB Fid %08lX.%08lX.%08lX.%08lX Status 0x%lX",
1648                   SetFileStatusCB.FileId.Cell, SetFileStatusCB.FileId.Volume,
1649                   SetFileStatusCB.FileId.Vnode, SetFileStatusCB.FileId.Unique,
1650                   dwStatus);
1651
1652         osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1653     }
1654
1655     if( !RDR_DeviceIoControl( glDevHandle,
1656                               IOCTL_AFS_SET_FILE_EXTENT_FAILURE,
1657                               (void *)&SetFileStatusCB,
1658                               sizeof(AFSExtentFailureCB),
1659                               (void *)NULL,
1660                               0,
1661                               &bytesReturned ))
1662     {
1663         gle = GetLastError();
1664         return gle;
1665     }
1666
1667     return 0;
1668 }
1669
1670 extern "C" DWORD
1671 RDR_RequestExtentRelease(cm_fid_t *fidp, LARGE_INTEGER numOfHeldExtents, DWORD numOfExtents, AFSFileExtentCB *extentList)
1672 {
1673
1674     HANDLE hDevHandle = NULL;
1675     DWORD bytesReturned;
1676     AFSReleaseFileExtentsCB *requestBuffer = NULL;
1677     AFSReleaseFileExtentsResultCB *responseBuffer = NULL;
1678     DWORD requestBufferLen, responseBufferLen;
1679     bool bError = false;
1680     DWORD rc = 0;
1681     WCHAR wchBuffer[256];
1682     DWORD gle;
1683
1684     if (ExitPending) {
1685         if (afsd_logp->enabled) {
1686             swprintf( wchBuffer,
1687                       L"IOCTL_AFS_RELEASE_FILE_EXTENTS request ignored due to shutdown pending");
1688
1689             osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1690         }
1691
1692         OutputDebugString(L"RDR_RequestExtentRequest ignored - shutdown pending\n");
1693         return CM_ERROR_WOULDBLOCK;
1694     }
1695
1696     if (afsd_logp->enabled) {
1697         swprintf( wchBuffer,
1698                   L"IOCTL_AFS_RELEASE_FILE_EXTENTS request - number %08lX",
1699                   numOfExtents);
1700
1701         osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1702     }
1703
1704     //
1705     // We use the global handle to the control device instance
1706     //
1707
1708     hDevHandle = glDevHandle;
1709
1710     //
1711     // Allocate a request buffer.
1712     //
1713
1714     requestBufferLen = sizeof( AFSReleaseFileExtentsCB) + sizeof(AFSFileExtentCB) * numOfExtents;
1715     requestBuffer = (AFSReleaseFileExtentsCB *)malloc( requestBufferLen);
1716     responseBufferLen = (sizeof( AFSReleaseFileExtentsResultCB) + sizeof( AFSReleaseFileExtentsResultFileCB)) * numOfExtents;
1717     responseBuffer = (AFSReleaseFileExtentsResultCB *)malloc( responseBufferLen);
1718
1719
1720     if( requestBuffer && responseBuffer)
1721     {
1722
1723         memset( requestBuffer, '\0', sizeof( AFSReleaseFileExtentsCB));
1724         memset( responseBuffer, '\0', responseBufferLen);
1725
1726         // If there is a FID provided, use it
1727         if (fidp && extentList)
1728         {
1729             RDR_fid2FID( fidp, &requestBuffer->FileId);
1730
1731             memcpy(&requestBuffer->FileExtents, extentList, numOfExtents * sizeof(AFSFileExtentCB));
1732
1733             requestBuffer->Flags = 0;
1734         } else {
1735
1736             requestBuffer->Flags = AFS_RELEASE_EXTENTS_FLAGS_RELEASE_ALL;
1737         }
1738
1739         // Set the number of extents to be freed
1740         // Leave the rest of the structure as zeros to indicate free anything
1741         requestBuffer->ExtentCount = numOfExtents;
1742
1743         requestBuffer->HeldExtentCount = numOfHeldExtents;
1744
1745         if( !RDR_DeviceIoControl( hDevHandle,
1746                                   IOCTL_AFS_RELEASE_FILE_EXTENTS,
1747                                   (void *)requestBuffer,
1748                                   requestBufferLen,
1749                                   (void *)responseBuffer,
1750                                   responseBufferLen,
1751                                   &bytesReturned ))
1752         {
1753             //
1754             // Error condition back from driver
1755             //
1756             if (afsd_logp->enabled) {
1757                 gle = GetLastError();
1758                 swprintf( wchBuffer,
1759                           L"Failed to post IOCTL_AFS_RELEASE_FILE_EXTENTS - gle 0x%x", gle);
1760                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1761             }
1762             rc = -1;
1763             goto cleanup;
1764         }
1765
1766         //
1767         // Go process the request
1768         //
1769
1770         if (afsd_logp->enabled) {
1771             swprintf( wchBuffer,
1772                       L"IOCTL_AFS_RELEASE_FILE_EXTENTS returns - serial number %08lX flags %lX FileCount %lX",
1773                       responseBuffer->SerialNumber, responseBuffer->Flags, responseBuffer->FileCount);
1774             osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1775         }
1776
1777         rc = RDR_ProcessReleaseFileExtentsResult( responseBuffer, bytesReturned);
1778     } else {
1779
1780         rc = ENOMEM;
1781     }
1782
1783   cleanup:
1784     if (requestBuffer)
1785         free( requestBuffer);
1786     if (responseBuffer)
1787         free( responseBuffer);
1788
1789     return rc;
1790 }
1791
1792
1793 extern "C" DWORD
1794 RDR_NetworkStatus(BOOLEAN status)
1795 {
1796
1797     HANDLE hDevHandle = NULL;
1798     DWORD bytesReturned;
1799     AFSNetworkStatusCB *requestBuffer = NULL;
1800     DWORD rc = 0;
1801     WCHAR wchBuffer[256];
1802     DWORD gle;
1803
1804     if (afsd_logp->enabled) {
1805         swprintf( wchBuffer,
1806                   L"IOCTL_AFS_NETWORK_STATUS request - status %d",
1807                   status);
1808
1809         osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1810     }
1811
1812     //
1813     // We use the global handle to the control device instance
1814     //
1815
1816     hDevHandle = glDevHandle;
1817
1818     //
1819     // Allocate a request buffer.
1820     //
1821
1822     requestBuffer = (AFSNetworkStatusCB *)malloc( sizeof( AFSNetworkStatusCB));
1823
1824
1825     if( requestBuffer)
1826     {
1827
1828         memset( requestBuffer, '\0', sizeof( AFSNetworkStatusCB));
1829
1830         // Set the number of extents to be freed
1831         // Leave the rest of the structure as zeros to indicate free anything
1832         requestBuffer->Online = status;
1833
1834         if( !RDR_DeviceIoControl( hDevHandle,
1835                                   IOCTL_AFS_NETWORK_STATUS,
1836                                   (void *)requestBuffer,
1837                                   sizeof( AFSNetworkStatusCB),
1838                                   NULL,
1839                                   0,
1840                                   &bytesReturned ))
1841         {
1842             //
1843             // Error condition back from driver
1844             //
1845             if (afsd_logp->enabled) {
1846                 gle = GetLastError();
1847                 swprintf( wchBuffer,
1848                           L"Failed to post IOCTL_AFS_NETWORK_STATUS gle 0x%x",
1849                           gle);
1850                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1851             }
1852
1853             rc = -1;
1854             goto cleanup;
1855         }
1856     } else
1857         rc = ENOMEM;
1858
1859   cleanup:
1860     if (requestBuffer)
1861         free( requestBuffer);
1862
1863     return rc;
1864 }
1865
1866
1867
1868 extern "C" DWORD
1869 RDR_VolumeStatus(ULONG cellID, ULONG volID, BOOLEAN online)
1870 {
1871
1872     HANDLE hDevHandle = NULL;
1873     DWORD bytesReturned;
1874     AFSVolumeStatusCB *requestBuffer = NULL;
1875     DWORD rc = 0;
1876     WCHAR wchBuffer[256];
1877     DWORD gle;
1878
1879     if (afsd_logp->enabled) {
1880         swprintf( wchBuffer,
1881                   L"IOCTL_AFS_VOLUME_STATUS request - cell 0x%x vol 0x%x online %d",
1882                   cellID, volID, online);
1883
1884         osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1885     }
1886
1887     //
1888     // We use the global handle to the control device instance
1889     //
1890
1891     hDevHandle = glDevHandle;
1892
1893     //
1894     // Allocate a request buffer.
1895     //
1896
1897     requestBuffer = (AFSVolumeStatusCB *)malloc( sizeof( AFSVolumeStatusCB));
1898
1899
1900     if( requestBuffer)
1901     {
1902
1903         memset( requestBuffer, '\0', sizeof( AFSVolumeStatusCB));
1904
1905         requestBuffer->FileID.Cell = cellID;
1906         requestBuffer->FileID.Volume = volID;
1907         requestBuffer->Online = online;
1908
1909         if( !RDR_DeviceIoControl( hDevHandle,
1910                                   IOCTL_AFS_VOLUME_STATUS,
1911                                   (void *)requestBuffer,
1912                                   sizeof( AFSVolumeStatusCB),
1913                                   NULL,
1914                                   0,
1915                                   &bytesReturned ))
1916         {
1917             //
1918             // Error condition back from driver
1919             //
1920
1921             if (afsd_logp->enabled) {
1922                 gle = GetLastError();
1923                 swprintf( wchBuffer,
1924                           L"Failed to post IOCTL_AFS_VOLUME_STATUS gle 0x%x", gle);
1925                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1926             }
1927
1928             rc = -1;
1929             goto cleanup;
1930         }
1931     } else
1932         rc = ENOMEM;
1933
1934   cleanup:
1935     if (requestBuffer)
1936         free( requestBuffer);
1937
1938     return rc;
1939 }
1940
1941 extern "C" DWORD
1942 RDR_NetworkAddrChange(void)
1943 {
1944     return 0;
1945 }
1946
1947
1948 extern "C" DWORD
1949 RDR_InvalidateVolume(ULONG cellID, ULONG volID, ULONG reason)
1950 {
1951
1952     HANDLE hDevHandle = NULL;
1953     DWORD bytesReturned;
1954     AFSInvalidateCacheCB *requestBuffer = NULL;
1955     DWORD rc = 0;
1956     WCHAR wchBuffer[256];
1957     DWORD gle;
1958
1959     if (afsd_logp->enabled) {
1960         swprintf( wchBuffer,
1961                   L"IOCTL_AFS_INVALIDATE_CACHE (vol) request - cell 0x%x vol 0x%x reason %d",
1962                   cellID, volID, reason);
1963
1964         osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
1965     }
1966
1967     //
1968     // We use the global handle to the control device instance
1969     //
1970
1971     hDevHandle = glDevHandle;
1972
1973     //
1974     // Allocate a request buffer.
1975     //
1976
1977     requestBuffer = (AFSInvalidateCacheCB *)malloc( sizeof( AFSInvalidateCacheCB));
1978
1979
1980     if( requestBuffer)
1981     {
1982
1983         memset( requestBuffer, '\0', sizeof( AFSInvalidateCacheCB));
1984
1985         requestBuffer->FileID.Cell = cellID;
1986         requestBuffer->FileID.Volume = volID;
1987         requestBuffer->WholeVolume = TRUE;
1988         requestBuffer->Reason = reason;
1989
1990         if( !RDR_DeviceIoControl( hDevHandle,
1991                                   IOCTL_AFS_INVALIDATE_CACHE,
1992                                   (void *)requestBuffer,
1993                                   sizeof( AFSInvalidateCacheCB),
1994                                   NULL,
1995                                   0,
1996                                   &bytesReturned ))
1997         {
1998             //
1999             // Error condition back from driver
2000             //
2001
2002             if (afsd_logp->enabled) {
2003                 gle = GetLastError();
2004                 swprintf( wchBuffer,
2005                           L"Failed to post IOCTL_AFS_INVALIDATE_VOLUME gle 0x%x", gle);
2006                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
2007             }
2008
2009             rc = -1;
2010             goto cleanup;
2011         }
2012     } else
2013         rc = ENOMEM;
2014
2015   cleanup:
2016     if (requestBuffer)
2017         free( requestBuffer);
2018
2019     return rc;
2020 }
2021
2022
2023 extern "C" DWORD
2024 RDR_InvalidateObject(ULONG cellID, ULONG volID, ULONG vnode, ULONG uniq, ULONG hash, ULONG fileType, ULONG reason)
2025 {
2026
2027     HANDLE hDevHandle = NULL;
2028     DWORD bytesReturned;
2029     AFSInvalidateCacheCB *requestBuffer = NULL;
2030     DWORD rc = 0;
2031     WCHAR wchBuffer[256];
2032     DWORD gle;
2033
2034     if (afsd_logp->enabled) {
2035         swprintf( wchBuffer,
2036                   L"IOCTL_AFS_INVALIDATE_CACHE (obj) request - cell 0x%x vol 0x%x vn 0x%x uniq 0x%x hash 0x%x type 0x%x reason %d",
2037                   cellID, volID, vnode, uniq, hash, fileType, reason);
2038
2039         osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
2040     }
2041
2042     //
2043     // We use the global handle to the control device instance
2044     //
2045
2046     hDevHandle = glDevHandle;
2047
2048     //
2049     // Allocate a request buffer.
2050     //
2051
2052     requestBuffer = (AFSInvalidateCacheCB *)malloc( sizeof( AFSInvalidateCacheCB));
2053
2054
2055     if( requestBuffer)
2056     {
2057
2058         memset( requestBuffer, '\0', sizeof( AFSInvalidateCacheCB));
2059
2060         requestBuffer->FileID.Cell = cellID;
2061         requestBuffer->FileID.Volume = volID;
2062         requestBuffer->FileID.Vnode = vnode;
2063         requestBuffer->FileID.Unique = uniq;
2064         requestBuffer->FileID.Hash = hash;
2065         requestBuffer->FileType = fileType;
2066         requestBuffer->WholeVolume = FALSE;
2067         requestBuffer->Reason = reason;
2068
2069         if( !RDR_DeviceIoControl( hDevHandle,
2070                                   IOCTL_AFS_INVALIDATE_CACHE,
2071                                   (void *)requestBuffer,
2072                                   sizeof( AFSInvalidateCacheCB),
2073                                   NULL,
2074                                   0,
2075                                   &bytesReturned ))
2076         {
2077             //
2078             // Error condition back from driver
2079             //
2080             if (afsd_logp->enabled) {
2081                 gle = GetLastError();
2082                 swprintf( wchBuffer,
2083                           L"Failed to post IOCTL_AFS_INVALIDATE_CACHE gle 0x%x", gle);
2084                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
2085             }
2086
2087             rc = -1;
2088             goto cleanup;
2089         }
2090     } else
2091         rc = ENOMEM;
2092
2093   cleanup:
2094     if (requestBuffer)
2095         free( requestBuffer);
2096
2097     return rc;
2098 }
2099
2100
2101
2102 extern "C" DWORD
2103 RDR_SysName(ULONG Architecture, ULONG Count, WCHAR **NameList)
2104 {
2105
2106     HANDLE hDevHandle = NULL;
2107     DWORD bytesReturned;
2108     AFSSysNameNotificationCB *requestBuffer = NULL;
2109     DWORD rc = 0;
2110     WCHAR wchBuffer[256];
2111     DWORD Length;
2112     DWORD gle;
2113
2114     if (afsd_logp->enabled) {
2115         swprintf( wchBuffer,
2116                   L"IOCTL_AFS_SYSNAME_NOTIFICATION request - Arch %d Count %d",
2117                   Architecture, Count);
2118
2119         osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
2120     }
2121
2122     if (Count <= 0 || NameList == NULL)
2123         return -1;
2124
2125     //
2126     // We use the global handle to the control device instance
2127     //
2128
2129     hDevHandle = glDevHandle;
2130
2131     //
2132     // Allocate a request buffer.
2133     //
2134
2135     Length = sizeof (AFSSysNameNotificationCB) + (Count - 1) * sizeof (AFSSysName);
2136     requestBuffer = (AFSSysNameNotificationCB *)malloc( Length );
2137
2138
2139     if( requestBuffer)
2140     {
2141         unsigned int i;
2142
2143         memset( requestBuffer, '\0', Length);
2144
2145         requestBuffer->Architecture = Architecture;
2146         requestBuffer->NumberOfNames = Count;
2147         for ( i=0 ; i<Count; i++) {
2148             size_t len = wcslen(NameList[i]);
2149             requestBuffer->SysNames[i].Length = (ULONG) (len * sizeof(WCHAR));
2150             StringCchCopyNW(requestBuffer->SysNames[i].String, AFS_MAX_SYSNAME_LENGTH,
2151                             NameList[i], len);
2152         }
2153
2154         if( !RDR_DeviceIoControl( hDevHandle,
2155                                   IOCTL_AFS_SYSNAME_NOTIFICATION,
2156                                   (void *)requestBuffer,
2157                                   Length,
2158                                   NULL,
2159                                   0,
2160                                   &bytesReturned ))
2161         {
2162             //
2163             // Error condition back from driver
2164             //
2165             if (afsd_logp->enabled) {
2166                 gle = GetLastError();
2167                 swprintf( wchBuffer,
2168                           L"Failed to post IOCTL_AFS_SYSNAME_NOTIFICATION gle 0x%x", gle);
2169                 osi_Log1(afsd_logp, "%S", osi_LogSaveStringW(afsd_logp, wchBuffer));
2170             }
2171
2172             rc = -1;
2173             goto cleanup;
2174         }
2175     } else
2176         rc = ENOMEM;
2177
2178   cleanup:
2179     if (requestBuffer)
2180         free( requestBuffer);
2181
2182     return rc;
2183 }
2184
2185 extern "C" VOID
2186 RDR_Suspend( VOID)
2187 {
2188     ResetEvent( RDR_SuspendEvent);
2189 }
2190
2191 extern "C" VOID
2192 RDR_Resume( VOID)
2193 {
2194     SetEvent( RDR_SuspendEvent);
2195 }