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