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