2 * Copyright (c) 2008 Secure Endpoints, Inc.
3 * Copyright (c) 2009-2011 Your File System, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
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.
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.
32 #include <afsconfig.h>
33 #include <afs/param.h>
36 #define _WIN32_WINNT 0x0500
38 #define _CRT_SECURE_NO_DEPRECATE
39 #define _CRT_NON_CONFORMING_SWPRINTFS
40 #define INITGUID /* define AFS_AUTH_GUID_NO_PAG */
43 #define WIN32_NO_STATUS
53 #pragma warning(disable: 4005)
57 #include "..\\Common\\AFSUserDefines.h"
58 #include "..\\Common\\AFSUserStructs.h"
76 #include <RDRPrototypes.h>
80 static CHAR * RDR_extentBaseAddress = NULL;
83 RDR_InitReq(cm_req_t *reqp)
86 reqp->flags |= CM_REQ_SOURCE_REDIR;
90 RDR_fid2FID( cm_fid_t *fid, AFSFileID *FileId)
92 FileId->Cell = fid->cell;
93 FileId->Volume = fid->volume;
94 FileId->Vnode = fid->vnode;
95 FileId->Unique = fid->unique;
96 FileId->Hash = fid->hash;
100 RDR_FID2fid( AFSFileID *FileId, cm_fid_t *fid)
102 fid->cell = FileId->Cell;
103 fid->volume = FileId->Volume;
104 fid->vnode = FileId->Vnode;
105 fid->unique = FileId->Unique;
106 fid->hash = FileId->Hash;
110 RDR_SetInitParams( OUT AFSRedirectorInitInfo **ppRedirInitInfo, OUT DWORD * pRedirInitInfoLen )
112 extern char cm_CachePath[];
113 extern cm_config_data_t cm_data;
114 extern int smb_hideDotFiles;
115 size_t cm_CachePathLen = strlen(cm_CachePath);
117 DWORD TempPathLen = ExpandEnvironmentStringsW(L"%TEMP%", NULL, 0);
118 MEMORYSTATUSEX memStatus;
119 DWORD maxMemoryCacheSize;
121 memStatus.dwLength = sizeof(memStatus);
122 if (GlobalMemoryStatusEx(&memStatus)) {
124 * Use the memory extent interface in the afs redirector
125 * whenever the cache size is less than equal to 10% of
126 * physical memory. Do not use too much because this memory
127 * will be locked by the redirector so it can't be swapped
130 maxMemoryCacheSize = (DWORD)(memStatus.ullTotalPhys / 1024 / 10);
133 * If we can't determine the amount of physical memory
134 * in the system, be conservative and limit the use of
135 * memory extent interface to 64MB data caches.
137 maxMemoryCacheSize = 65536;
140 *pRedirInitInfoLen = (DWORD) (sizeof(AFSRedirectorInitInfo) + (cm_CachePathLen + TempPathLen) * sizeof(WCHAR));
141 *ppRedirInitInfo = (AFSRedirectorInitInfo *)malloc(*pRedirInitInfoLen);
142 (*ppRedirInitInfo)->Flags = smb_hideDotFiles ? AFS_REDIR_INIT_FLAG_HIDE_DOT_FILES : 0;
143 (*ppRedirInitInfo)->MaximumChunkLength = cm_data.chunkSize;
144 (*ppRedirInitInfo)->GlobalFileId.Cell = cm_data.rootFid.cell;
145 (*ppRedirInitInfo)->GlobalFileId.Volume = cm_data.rootFid.volume;
146 (*ppRedirInitInfo)->GlobalFileId.Vnode = cm_data.rootFid.vnode;
147 (*ppRedirInitInfo)->GlobalFileId.Unique = cm_data.rootFid.unique;
148 (*ppRedirInitInfo)->GlobalFileId.Hash = cm_data.rootFid.hash;
149 (*ppRedirInitInfo)->ExtentCount.QuadPart = cm_data.buf_nbuffers;
150 (*ppRedirInitInfo)->CacheBlockSize = cm_data.blockSize;
151 (*ppRedirInitInfo)->MaxPathLinkCount = 512; /* this needs to become a registry value */
152 (*ppRedirInitInfo)->NameArrayLength = 32; /* this needs to become a registry value */
153 if (cm_virtualCache || cm_data.bufferSize <= maxMemoryCacheSize) {
154 osi_Log0(afsd_logp, "RDR_SetInitParams Initializing Memory Extent Interface");
155 (*ppRedirInitInfo)->MemoryCacheOffset.QuadPart = (LONGLONG)cm_data.bufDataBaseAddress;
156 (*ppRedirInitInfo)->MemoryCacheLength.QuadPart = cm_data.bufEndOfData - cm_data.bufDataBaseAddress;
157 (*ppRedirInitInfo)->CacheFileNameLength = 0;
158 RDR_extentBaseAddress = cm_data.bufDataBaseAddress;
160 (*ppRedirInitInfo)->MemoryCacheOffset.QuadPart = 0;
161 (*ppRedirInitInfo)->MemoryCacheLength.QuadPart = 0;
162 (*ppRedirInitInfo)->CacheFileNameLength = (ULONG) (cm_CachePathLen * sizeof(WCHAR));
163 err = mbstowcs((*ppRedirInitInfo)->CacheFileName, cm_CachePath, (cm_CachePathLen + 1) *sizeof(WCHAR));
165 free(*ppRedirInitInfo);
166 osi_Log0(afsd_logp, "RDR_SetInitParams Invalid Object Name");
167 return STATUS_OBJECT_NAME_INVALID;
169 RDR_extentBaseAddress = cm_data.baseAddress;
171 (*ppRedirInitInfo)->DumpFileLocationOffset = FIELD_OFFSET(AFSRedirectorInitInfo, CacheFileName) + (*ppRedirInitInfo)->CacheFileNameLength;
172 (*ppRedirInitInfo)->DumpFileLocationLength = (TempPathLen - 1) * sizeof(WCHAR);
173 ExpandEnvironmentStringsW(L"%TEMP%",
174 (LPWSTR)(((PBYTE)(*ppRedirInitInfo)) + (*ppRedirInitInfo)->DumpFileLocationOffset),
177 osi_Log0(afsd_logp,"RDR_SetInitParams Success");
182 RDR_GetLocalSystemUser( void)
185 cm_user_t *userp = NULL;
186 wchar_t cname[MAX_COMPUTERNAME_LENGTH+1];
187 int cnamelen = MAX_COMPUTERNAME_LENGTH+1;
189 GetComputerNameW(cname, &cnamelen);
192 unp = smb_FindUserByName(NTSID_LOCAL_SYSTEM, cname, SMB_FLAG_CREATE);
193 lock_ObtainMutex(&unp->mx);
195 unp->userp = cm_NewUser();
196 unp->flags |= SMB_USERNAMEFLAG_SID;
197 lock_ReleaseMutex(&unp->mx);
200 smb_ReleaseUsername(unp);
203 userp = cm_rootUserp;
211 RDR_UserFromCommRequest( IN AFSCommRequest *RequestBuffer)
214 return RDR_UserFromAuthGroup( &RequestBuffer->AuthGroup);
218 RDR_UserFromAuthGroup( IN GUID *pGuid)
221 cm_user_t * userp = NULL;
222 RPC_WSTR UuidString = NULL;
223 wchar_t cname[MAX_COMPUTERNAME_LENGTH+1];
224 int cnamelen = MAX_COMPUTERNAME_LENGTH+1;
226 if (UuidToStringW((UUID *)pGuid, &UuidString) != RPC_S_OK)
229 GetComputerNameW(cname, &cnamelen);
232 unp = smb_FindUserByName(UuidString, cname, SMB_FLAG_CREATE);
233 lock_ObtainMutex(&unp->mx);
235 unp->userp = cm_NewUser();
236 unp->flags |= SMB_USERNAMEFLAG_SID;
237 lock_ReleaseMutex(&unp->mx);
240 smb_ReleaseUsername(unp);
244 userp = cm_rootUserp;
248 osi_Log2(afsd_logp, "RDR_UserFromCommRequest Guid %S userp = 0x%p",
249 osi_LogSaveStringW(afsd_logp, UuidString),
253 RpcStringFreeW(&UuidString);
259 RDR_ReleaseUser( IN cm_user_t *userp )
261 osi_Log1(afsd_logp, "RDR_ReleaseUser userp = 0x%p", userp);
262 cm_ReleaseUser(userp);
267 * RDR_FlagScpInUse flags the scp with CM_SCACHEFLAG_RDR_IN_USE
270 RDR_FlagScpInUse( IN cm_scache_t *scp, IN BOOL bLocked )
273 lock_ObtainWrite(&scp->rw);
275 lock_AssertWrite(&scp->rw);
276 scp->flags |= CM_SCACHEFLAG_RDR_IN_USE;
279 lock_ReleaseWrite(&scp->rw);
283 * Obtain the status information for the specified object and
287 RDR_BulkStatLookup( cm_scache_t *dscp,
292 cm_direnum_t * enump = NULL;
296 code = cm_BeginDirOp(dscp, userp, reqp, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
298 code = cm_BPlusDirEnumerate(dscp, userp, reqp, TRUE, NULL, TRUE, &enump);
300 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BPlusDirEnumerate failure code=0x%x",
305 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BeginDirOp failure code=0x%x",
312 code = cm_BPlusDirEnumBulkStatOne(enump, scp);
314 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BPlusDirEnumBulkStatOne failure code=0x%x",
317 cm_BPlusDirFreeEnumeration(enump);
324 #define RDR_POP_FOLLOW_MOUNTPOINTS 0x01
325 #define RDR_POP_EVALUATE_SYMLINKS 0x02
326 #define RDR_POP_WOW64 0x04
327 #define RDR_POP_NO_GETSTATUS 0x08
330 RDR_PopulateCurrentEntry( IN AFSDirEnumEntry * pCurrentEntry,
331 IN DWORD dwMaxEntryLength,
332 IN cm_scache_t * dscp,
333 IN cm_scache_t * scp,
334 IN cm_user_t * userp,
337 IN wchar_t * shortName,
339 OUT AFSDirEnumEntry **ppNextEntry,
340 OUT DWORD * pdwRemainingLength)
343 WCHAR * wname, *wtarget;
346 afs_uint32 code = 0, code2 = 0;
347 BOOL bMustFake = FALSE;
349 osi_Log5(afsd_logp, "RDR_PopulateCurrentEntry dscp=0x%p scp=0x%p name=%S short=%S flags=0x%x",
350 dscp, scp, osi_LogSaveStringW(afsd_logp, name),
351 osi_LogSaveStringW(afsd_logp, shortName), dwFlags);
352 osi_Log1(afsd_logp, "... maxLength=%d", dwMaxEntryLength);
354 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
356 *ppNextEntry = pCurrentEntry;
357 if (pdwRemainingLength)
358 *pdwRemainingLength = dwMaxEntryLength;
359 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry Not Enough Room for Entry %d < %d",
360 dwMaxEntryLength, sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t));
361 return CM_ERROR_TOOBIG;
369 dwEntryLength = sizeof(AFSDirEnumEntry);
371 lock_ObtainWrite(&scp->rw);
372 if (dwFlags & RDR_POP_NO_GETSTATUS) {
373 if (!cm_HaveCallback(scp))
376 #ifdef AFS_FREELANCE_CLIENT
377 if (scp->fid.cell == AFS_FAKE_ROOT_CELL_ID && scp->fid.volume == AFS_FAKE_ROOT_VOL_ID) {
379 * If the FID is from the Freelance Local Root always perform
380 * a single item status check.
382 code = cm_SyncOp( scp, NULL, userp, reqp, 0,
383 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
385 lock_ReleaseWrite(&scp->rw);
386 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_SyncOp failed for scp=0x%p code=0x%x",
394 * For non-Freelance objects, check to see if we have current
395 * status information. If not, perform a bulk status lookup of multiple
396 * entries in order to reduce the number of RPCs issued to the file server.
398 if ((scp->flags & CM_SCACHEFLAG_EACCESS))
400 else if (!cm_HaveCallback(scp)) {
401 lock_ReleaseWrite(&scp->rw);
402 code = RDR_BulkStatLookup(dscp, scp, userp, reqp);
404 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry RXR_BulkStatLookup failed for scp=0x%p code=0x%x",
408 lock_ObtainWrite(&scp->rw);
410 * RDR_BulkStatLookup can succeed but it may be the case that there
411 * still is not valid status info. If we get this far, generate fake
414 if (!cm_HaveCallback(scp))
421 /* Populate the real or fake data */
422 pCurrentEntry->FileId.Cell = scp->fid.cell;
423 pCurrentEntry->FileId.Volume = scp->fid.volume;
424 pCurrentEntry->FileId.Vnode = scp->fid.vnode;
425 pCurrentEntry->FileId.Unique = scp->fid.unique;
426 pCurrentEntry->FileId.Hash = scp->fid.hash;
428 pCurrentEntry->FileType = scp->fileType;
430 pCurrentEntry->DataVersion.QuadPart = scp->dataVersion;
432 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
433 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
434 cm_LargeSearchTimeFromUnixTime(&ft, MAX_AFS_UINT32);
436 cm_LargeSearchTimeFromUnixTime(&ft, scp->cbExpires);
438 pCurrentEntry->Expiration.LowPart = ft.dwLowDateTime;
439 pCurrentEntry->Expiration.HighPart = ft.dwHighDateTime;
442 /* 1969-12-31 23:59:59 +00 */
443 ft.dwHighDateTime = 0x19DB200;
444 ft.dwLowDateTime = 0x5BB78980;
446 cm_LargeSearchTimeFromUnixTime(&ft, scp->clientModTime);
447 pCurrentEntry->CreationTime.LowPart = ft.dwLowDateTime;
448 pCurrentEntry->CreationTime.HighPart = ft.dwHighDateTime;
449 pCurrentEntry->LastAccessTime = pCurrentEntry->CreationTime;
450 pCurrentEntry->LastWriteTime = pCurrentEntry->CreationTime;
451 pCurrentEntry->ChangeTime = pCurrentEntry->CreationTime;
453 pCurrentEntry->EndOfFile = scp->length;
454 pCurrentEntry->AllocationSize = scp->length;
457 switch (scp->fileType) {
458 case CM_SCACHETYPE_DIRECTORY:
459 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY;
461 case CM_SCACHETYPE_MOUNTPOINT:
462 case CM_SCACHETYPE_INVALID:
463 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY | SMB_ATTR_REPARSE_POINT;
465 case CM_SCACHETYPE_SYMLINK:
466 if (cm_TargetPerceivedAsDirectory(scp->mountPointStringp))
467 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY | SMB_ATTR_REPARSE_POINT;
469 pCurrentEntry->FileAttributes = SMB_ATTR_REPARSE_POINT;
472 /* if we get here we either have a normal file
473 * or we have a file for which we have never
474 * received status info. In this case, we can
475 * check the even/odd value of the entry's vnode.
476 * odd means it is to be treated as a directory
477 * and even means it is to be treated as a file.
479 if (scp->fid.vnode & 0x1)
480 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY;
482 pCurrentEntry->FileAttributes = SMB_ATTR_NORMAL;
485 pCurrentEntry->FileAttributes = smb_ExtAttributes(scp);
486 pCurrentEntry->EaSize = 0;
487 pCurrentEntry->Links = scp->linkCount;
489 len = wcslen(shortName);
490 wcsncpy(pCurrentEntry->ShortName, shortName, len);
491 pCurrentEntry->ShortNameLength = (CCHAR)(len * sizeof(WCHAR));
493 pCurrentEntry->FileNameOffset = sizeof(AFSDirEnumEntry);
495 wname = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->FileNameOffset);
496 wcsncpy(wname, name, len);
497 pCurrentEntry->FileNameLength = (ULONG)(sizeof(WCHAR) * len);
499 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry scp=0x%p fileType=%d",
502 if (!(dwFlags & RDR_POP_NO_GETSTATUS))
503 cm_SyncOpDone( scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
505 if ((dwFlags & RDR_POP_NO_GETSTATUS) || !cm_HaveCallback(scp)) {
506 pCurrentEntry->TargetNameOffset = 0;
507 pCurrentEntry->TargetNameLength = 0;
510 switch (scp->fileType) {
511 case CM_SCACHETYPE_MOUNTPOINT:
512 if (dwFlags & RDR_POP_FOLLOW_MOUNTPOINTS) {
513 if ((code2 = cm_ReadMountPoint(scp, userp, reqp)) == 0) {
514 cm_scache_t *targetScp = NULL;
516 pCurrentEntry->TargetNameOffset = pCurrentEntry->FileNameOffset + pCurrentEntry->FileNameLength;
517 len = strlen(scp->mountPointStringp);
518 wtarget = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->TargetNameOffset);
521 cch = MultiByteToWideChar( CP_UTF8, 0, scp->mountPointStringp,
524 len * sizeof(WCHAR));
526 mbstowcs(wtarget, scp->mountPointStringp, len);
528 pCurrentEntry->TargetNameLength = (ULONG)(sizeof(WCHAR) * len);
530 code2 = cm_FollowMountPoint(scp, dscp, userp, reqp, &targetScp);
533 pCurrentEntry->TargetFileId.Cell = targetScp->fid.cell;
534 pCurrentEntry->TargetFileId.Volume = targetScp->fid.volume;
535 pCurrentEntry->TargetFileId.Vnode = targetScp->fid.vnode;
536 pCurrentEntry->TargetFileId.Unique = targetScp->fid.unique;
537 pCurrentEntry->TargetFileId.Hash = targetScp->fid.hash;
539 osi_Log4(afsd_logp, "RDR_PopulateCurrentEntry target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
540 pCurrentEntry->TargetFileId.Cell, pCurrentEntry->TargetFileId.Volume,
541 pCurrentEntry->TargetFileId.Vnode, pCurrentEntry->TargetFileId.Unique);
543 cm_ReleaseSCache(targetScp);
545 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_FollowMountPoint failed scp=0x%p code=0x%x",
549 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_ReadMountPoint failed scp=0x%p code=0x%x",
554 case CM_SCACHETYPE_SYMLINK:
555 case CM_SCACHETYPE_DFSLINK:
557 pCurrentEntry->TargetNameOffset = pCurrentEntry->FileNameOffset + pCurrentEntry->FileNameLength;
558 wtarget = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->TargetNameOffset);
560 if (dwFlags & RDR_POP_EVALUATE_SYMLINKS) {
563 code2 = cm_HandleLink(scp, userp, reqp);
565 mp = scp->mountPointStringp;
568 /* Strip off the msdfs: prefix from the target name for the file system */
569 if (scp->fileType == CM_SCACHETYPE_DFSLINK) {
570 osi_Log0(afsd_logp, "RDR_PopulateCurrentEntry DFSLink Detected");
571 pCurrentEntry->FileType = scp->fileType;
573 if (!strncmp("msdfs:", mp, 6)) {
578 /* only send one slash to the redirector */
579 if (mp[0] == '\\' && mp[1] == '\\') {
584 cch = MultiByteToWideChar( CP_UTF8, 0, mp,
587 len * sizeof(WCHAR));
589 mbstowcs(wtarget, mp, len);
592 pCurrentEntry->TargetNameLength = (ULONG)(sizeof(WCHAR) * len);
594 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_HandleLink failed scp=0x%p code=0x%x",
603 pCurrentEntry->TargetNameOffset = 0;
604 pCurrentEntry->TargetNameLength = 0;
606 lock_ReleaseWrite(&scp->rw);
608 dwEntryLength += pCurrentEntry->FileNameLength + pCurrentEntry->TargetNameLength;
609 dwEntryLength += (dwEntryLength % 8) ? 8 - (dwEntryLength % 8) : 0; /* quad align */
611 *ppNextEntry = (AFSDirEnumEntry *)((PBYTE)pCurrentEntry + dwEntryLength);
612 if (pdwRemainingLength)
613 *pdwRemainingLength = dwMaxEntryLength - dwEntryLength;
615 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntry Success FileNameLength=%d TargetNameLength=%d RemainingLength=%d",
616 pCurrentEntry->FileNameLength, pCurrentEntry->TargetNameLength, *pdwRemainingLength);
622 RDR_PopulateCurrentEntryNoScp( IN AFSDirEnumEntry * pCurrentEntry,
623 IN DWORD dwMaxEntryLength,
624 IN cm_scache_t * dscp,
626 IN cm_user_t * userp,
629 IN wchar_t * shortName,
631 OUT AFSDirEnumEntry **ppNextEntry,
632 OUT DWORD * pdwRemainingLength)
638 afs_uint32 code = 0, code2 = 0;
640 osi_Log4(afsd_logp, "RDR_PopulateCurrentEntryNoEntry dscp=0x%p name=%S short=%S flags=0x%x",
641 dscp, osi_LogSaveStringW(afsd_logp, name),
642 osi_LogSaveStringW(afsd_logp, shortName), dwFlags);
643 osi_Log1(afsd_logp, "... maxLength=%d", dwMaxEntryLength);
645 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
647 *ppNextEntry = pCurrentEntry;
648 if (pdwRemainingLength)
649 *pdwRemainingLength = dwMaxEntryLength;
650 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntryNoEntry Not Enough Room for Entry %d < %d",
651 dwMaxEntryLength, sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t));
652 return CM_ERROR_TOOBIG;
660 dwEntryLength = sizeof(AFSDirEnumEntry);
662 pCurrentEntry->FileId.Cell = fidp->cell;
663 pCurrentEntry->FileId.Volume = fidp->volume;
664 pCurrentEntry->FileId.Vnode = fidp->vnode;
665 pCurrentEntry->FileId.Unique = fidp->unique;
666 pCurrentEntry->FileId.Hash = fidp->hash;
668 pCurrentEntry->FileType = CM_SCACHETYPE_UNKNOWN;
670 pCurrentEntry->DataVersion.QuadPart = CM_SCACHE_VERSION_BAD;
672 cm_LargeSearchTimeFromUnixTime(&ft, 0);
673 pCurrentEntry->Expiration.LowPart = ft.dwLowDateTime;
674 pCurrentEntry->Expiration.HighPart = ft.dwHighDateTime;
676 cm_LargeSearchTimeFromUnixTime(&ft, 0);
677 pCurrentEntry->CreationTime.LowPart = ft.dwLowDateTime;
678 pCurrentEntry->CreationTime.HighPart = ft.dwHighDateTime;
679 pCurrentEntry->LastAccessTime = pCurrentEntry->CreationTime;
680 pCurrentEntry->LastWriteTime = pCurrentEntry->CreationTime;
681 pCurrentEntry->ChangeTime = pCurrentEntry->CreationTime;
683 pCurrentEntry->EndOfFile.QuadPart = 0;
684 pCurrentEntry->AllocationSize.QuadPart = 0;
685 pCurrentEntry->FileAttributes = 0;
686 pCurrentEntry->EaSize = 0;
687 pCurrentEntry->Links = 0;
689 len = wcslen(shortName);
690 wcsncpy(pCurrentEntry->ShortName, shortName, len);
691 pCurrentEntry->ShortNameLength = (CCHAR)(len * sizeof(WCHAR));
693 pCurrentEntry->FileNameOffset = sizeof(AFSDirEnumEntry);
695 wname = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->FileNameOffset);
696 wcsncpy(wname, name, len);
697 pCurrentEntry->FileNameLength = (ULONG)(sizeof(WCHAR) * len);
699 pCurrentEntry->TargetNameOffset = 0;
700 pCurrentEntry->TargetNameLength = 0;
702 dwEntryLength += pCurrentEntry->FileNameLength + pCurrentEntry->TargetNameLength;
703 dwEntryLength += (dwEntryLength % 8) ? 8 - (dwEntryLength % 8) : 0; /* quad align */
705 *ppNextEntry = (AFSDirEnumEntry *)((PBYTE)pCurrentEntry + dwEntryLength);
706 if (pdwRemainingLength)
707 *pdwRemainingLength = dwMaxEntryLength - dwEntryLength;
709 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntryNoScp Success FileNameLength=%d TargetNameLength=%d RemainingLength=%d",
710 pCurrentEntry->FileNameLength, pCurrentEntry->TargetNameLength, *pdwRemainingLength);
716 RDR_EnumerateDirectory( IN cm_user_t *userp,
718 IN AFSDirQueryCB *QueryCB,
721 IN DWORD ResultBufferLength,
722 IN OUT AFSCommResult **ResultCB)
725 cm_direnum_t * enump = NULL;
726 AFSDirEnumResp * pDirEnumResp;
727 AFSDirEnumEntry * pCurrentEntry;
728 size_t size = ResultBufferLength ? sizeof(AFSCommResult) + ResultBufferLength - 1 : sizeof(AFSCommResult);
729 DWORD dwMaxEntryLength;
732 cm_scache_t * dscp = NULL;
737 req.flags |= CM_REQ_WOW64;
739 osi_Log4(afsd_logp, "RDR_EnumerateDirectory FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
740 DirID.Cell, DirID.Volume, DirID.Vnode, DirID.Unique);
742 *ResultCB = (AFSCommResult *)malloc(size);
744 osi_Log0(afsd_logp, "RDR_EnumerateDirectory Out of Memory");
748 memset(*ResultCB, 0, size);
750 if (QueryCB->EnumHandle == (ULONG_PTR)-1) {
751 osi_Log0(afsd_logp, "RDR_EnumerateDirectory No More Entries");
752 (*ResultCB)->ResultStatus = STATUS_NO_MORE_ENTRIES;
753 (*ResultCB)->ResultBufferLength = 0;
757 (*ResultCB)->ResultBufferLength = dwMaxEntryLength = ResultBufferLength;
758 if (ResultBufferLength) {
759 pDirEnumResp = (AFSDirEnumResp *)&(*ResultCB)->ResultData;
760 pCurrentEntry = (AFSDirEnumEntry *)&pDirEnumResp->Entry;
761 dwMaxEntryLength -= FIELD_OFFSET( AFSDirEnumResp, Entry); /* AFSDirEnumResp */
764 if (DirID.Cell != 0) {
765 fid.cell = DirID.Cell;
766 fid.volume = DirID.Volume;
767 fid.vnode = DirID.Vnode;
768 fid.unique = DirID.Unique;
769 fid.hash = DirID.Hash;
771 code = cm_GetSCache(&fid, &dscp, userp, &req);
773 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
774 (*ResultCB)->ResultStatus = status;
775 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_GetSCache failure code=0x%x status=0x%x",
780 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
781 osi_Log0(afsd_logp, "RDR_EnumerateDirectory Object Name Invalid - Cell = 0");
785 /* get the directory size */
786 lock_ObtainWrite(&dscp->rw);
787 code = cm_SyncOp(dscp, NULL, userp, &req, PRSFS_LOOKUP,
788 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
790 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
791 (*ResultCB)->ResultStatus = status;
792 lock_ReleaseWrite(&dscp->rw);
793 cm_ReleaseSCache(dscp);
794 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_SyncOp failure code=0x%x status=0x%x",
799 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
800 lock_ReleaseWrite(&dscp->rw);
802 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
803 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
804 cm_ReleaseSCache(dscp);
805 osi_Log1(afsd_logp, "RDR_EnumerateDirectory Not a Directory dscp=0x%p",
811 * If there is no enumeration handle, then this is a new query
812 * and we must perform an enumeration for the specified object
814 if (QueryCB->EnumHandle == (ULONG_PTR)NULL) {
817 code = cm_BeginDirOp(dscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
819 code = cm_BPlusDirEnumerate(dscp, userp, &req, TRUE, NULL, !bSkipStatus, &enump);
821 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BPlusDirEnumerate failure code=0x%x",
826 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BeginDirOp failure code=0x%x",
830 enump = (cm_direnum_t *)QueryCB->EnumHandle;
833 if (enump && ResultBufferLength) {
834 cm_direnum_entry_t * entryp = NULL;
837 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
838 osi_Log0(afsd_logp, "RDR_EnumerateDirectory out of space, returning");
842 code = cm_BPlusDirNextEnumEntry(enump, &entryp);
844 if ((code == 0 || code == CM_ERROR_STOPNOW) && entryp) {
846 int stopnow = (code == CM_ERROR_STOPNOW);
848 if ( !wcscmp(L".", entryp->name) || !wcscmp(L"..", entryp->name) ) {
849 osi_Log0(afsd_logp, "RDR_EnumerateDirectory skipping . or ..");
855 if ( FALSE /* bSkipStatus */) {
856 scp = cm_FindSCache(&entryp->fid);
859 code = cm_GetSCache(&entryp->fid, &scp, userp, &req);
864 code = RDR_PopulateCurrentEntry(pCurrentEntry, dwMaxEntryLength,
865 dscp, scp, userp, &req,
867 cm_Is8Dot3(entryp->name) ? NULL : entryp->shortName,
868 (bWow64 ? RDR_POP_WOW64 : 0) |
869 (bSkipStatus ? RDR_POP_NO_GETSTATUS : 0),
870 &pCurrentEntry, &dwMaxEntryLength);
871 cm_ReleaseSCache(scp);
873 code = RDR_PopulateCurrentEntryNoScp( pCurrentEntry, dwMaxEntryLength,
874 dscp, &entryp->fid, userp, &req,
876 cm_Is8Dot3(entryp->name) ? NULL : entryp->shortName,
877 (bWow64 ? RDR_POP_WOW64 : 0),
878 &pCurrentEntry, &dwMaxEntryLength);
884 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_GetSCache failure scp=0x%p code=0x%x",
893 if (enump && ResultBufferLength == 0) {
894 code = cm_BPlusDirEnumBulkStat(enump);
896 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BPlusDirEnumBulkStat failure code=0x%x",
902 if (code || enump->next == enump->count || ResultBufferLength == 0) {
903 cm_BPlusDirFreeEnumeration(enump);
904 enump = (cm_direnum_t *)(ULONG_PTR)-1;
907 if (code == 0 || code == CM_ERROR_STOPNOW) {
908 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
909 osi_Log0(afsd_logp, "RDR_EnumerateDirectory SUCCESS");
911 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
912 (*ResultCB)->ResultStatus = status;
913 osi_Log2(afsd_logp, "RDR_EnumerateDirectory Failure code=0x%x status=0x%x",
917 if (ResultBufferLength) {
918 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwMaxEntryLength;
920 pDirEnumResp->EnumHandle = (ULONG_PTR) enump;
924 cm_ReleaseSCache(dscp);
930 RDR_EvaluateNodeByName( IN cm_user_t *userp,
931 IN AFSFileID ParentID,
932 IN WCHAR *FileNameCounted,
933 IN DWORD FileNameLength,
934 IN BOOL CaseSensitive,
938 IN DWORD ResultBufferLength,
939 IN OUT AFSCommResult **ResultCB)
941 AFSDirEnumEntry * pCurrentEntry;
942 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
944 cm_scache_t * scp = NULL;
945 cm_scache_t * dscp = NULL;
950 WCHAR * wszName = NULL;
953 wchar_t FileName[260];
955 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
959 req.flags |= CM_REQ_WOW64;
961 osi_Log4(afsd_logp, "RDR_EvaluateNodeByName parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
962 ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
964 /* Allocate enough room to add a volume prefix if necessary */
965 cbName = FileNameLength + (CM_PREFIX_VOL_CCH + 1) * sizeof(WCHAR);
966 wszName = malloc(cbName);
968 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Out of Memory");
971 StringCbCopyNW(wszName, cbName, FileName, FileNameLength);
972 osi_Log1(afsd_logp, "... name=%S", osi_LogSaveStringW(afsd_logp, wszName));
974 *ResultCB = (AFSCommResult *)malloc(size);
976 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Out of Memory");
981 memset(*ResultCB, 0, size);
982 (*ResultCB)->ResultBufferLength = ResultBufferLength;
983 if (ResultBufferLength)
984 pCurrentEntry = (AFSDirEnumEntry *)&(*ResultCB)->ResultData;
986 if (ParentID.Cell != 0) {
987 parentFid.cell = ParentID.Cell;
988 parentFid.volume = ParentID.Volume;
989 parentFid.vnode = ParentID.Vnode;
990 parentFid.unique = ParentID.Unique;
991 parentFid.hash = ParentID.Hash;
993 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
995 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
996 (*ResultCB)->ResultStatus = status;
997 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName cm_GetSCache parentFID failure code=0x%x status=0x%x",
1003 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
1004 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Object Name Invalid - Cell = 0");
1008 /* get the directory size */
1009 lock_ObtainWrite(&dscp->rw);
1010 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1011 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1013 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1014 (*ResultCB)->ResultStatus = status;
1015 lock_ReleaseWrite(&dscp->rw);
1016 cm_ReleaseSCache(dscp);
1017 osi_Log3(afsd_logp, "RDR_EvaluateNodeByName cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1018 dscp, code, status);
1022 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1023 lock_ReleaseWrite(&dscp->rw);
1025 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1026 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1027 cm_ReleaseSCache(dscp);
1028 osi_Log1(afsd_logp, "RDR_EvaluateNodeByName Not a Directory dscp=0x%p",
1034 code = cm_Lookup(dscp, wszName, CM_FLAG_CHECKPATH, userp, &req, &scp);
1036 if ((code == CM_ERROR_NOSUCHPATH || code == CM_ERROR_NOSUCHFILE || code == CM_ERROR_BPLUS_NOMATCH) &&
1037 (wcschr(wszName, '%') != NULL || wcschr(wszName, '#') != NULL)) {
1039 * A volume reference: <cell>{%,#}<volume> -> @vol:<cell>{%,#}<volume>
1041 StringCchCopyNW(wszName, cbName, _C(CM_PREFIX_VOL), CM_PREFIX_VOL_CCH);
1042 StringCbCatNW(wszName, cbName, FileName, FileNameLength);
1043 cm_strlwr_utf16(wszName);
1046 code = cm_EvaluateVolumeReference(wszName, CM_FLAG_CHECKPATH, userp, &req, &scp);
1049 if (code == 0 && scp) {
1050 wchar_t shortName[13]=L"";
1053 cm_Gen8Dot3VolNameW(scp->fid.cell, scp->fid.volume, shortName, NULL);
1054 } else if (!cm_Is8Dot3(wszName)) {
1057 dfid.vnode = htonl(scp->fid.vnode);
1058 dfid.unique = htonl(scp->fid.unique);
1060 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1062 shortName[0] = '\0';
1065 code = RDR_PopulateCurrentEntry(pCurrentEntry, ResultBufferLength,
1066 dscp, scp, userp, &req,
1067 FileName, shortName,
1068 (bWow64 ? RDR_POP_WOW64 : 0) |
1069 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1070 NULL, &dwRemaining);
1072 RDR_FlagScpInUse( scp, FALSE );
1073 cm_ReleaseSCache(scp);
1076 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1077 (*ResultCB)->ResultStatus = status;
1078 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1081 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1082 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1083 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName SUCCESS");
1086 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1087 (*ResultCB)->ResultStatus = status;
1088 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1091 (*ResultCB)->ResultStatus = STATUS_NO_SUCH_FILE;
1092 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName No Such File");
1094 cm_ReleaseSCache(dscp);
1101 RDR_EvaluateNodeByID( IN cm_user_t *userp,
1102 IN AFSFileID ParentID, /* not used */
1103 IN AFSFileID SourceID,
1107 IN DWORD ResultBufferLength,
1108 IN OUT AFSCommResult **ResultCB)
1110 AFSDirEnumEntry * pCurrentEntry;
1111 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1112 afs_uint32 code = 0;
1113 cm_scache_t * scp = NULL;
1114 cm_scache_t * dscp = NULL;
1121 osi_Log4(afsd_logp, "RDR_EvaluateNodeByID source FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1122 SourceID.Cell, SourceID.Volume, SourceID.Vnode, SourceID.Unique);
1123 osi_Log4(afsd_logp, "... parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1124 ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1126 *ResultCB = (AFSCommResult *)malloc(size);
1128 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Out of Memory");
1132 memset(*ResultCB, 0, size);
1133 (*ResultCB)->ResultBufferLength = ResultBufferLength;
1134 dwRemaining = ResultBufferLength;
1135 if (ResultBufferLength)
1136 pCurrentEntry = (AFSDirEnumEntry *)&(*ResultCB)->ResultData;
1140 req.flags |= CM_REQ_WOW64;
1142 if (SourceID.Cell != 0) {
1143 Fid.cell = SourceID.Cell;
1144 Fid.volume = SourceID.Volume;
1145 Fid.vnode = SourceID.Vnode;
1146 Fid.unique = SourceID.Unique;
1147 Fid.hash = SourceID.Hash;
1149 code = cm_GetSCache(&Fid, &scp, userp, &req);
1151 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1152 (*ResultCB)->ResultStatus = status;
1153 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache SourceFID failure code=0x%x status=0x%x",
1158 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
1159 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Name Invalid - Cell = 0");
1163 if (ParentID.Cell != 0) {
1164 cm_SetFid(&parentFid, ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1165 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1167 cm_ReleaseSCache(scp);
1168 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1169 (*ResultCB)->ResultStatus = status;
1170 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1174 } else if (SourceID.Vnode == 1) {
1176 cm_HoldSCache(dscp);
1177 } else if (scp->parentVnode) {
1178 cm_SetFid(&parentFid, SourceID.Cell, SourceID.Volume, scp->parentVnode, scp->parentUnique);
1179 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1181 cm_ReleaseSCache(scp);
1182 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1183 (*ResultCB)->ResultStatus = status;
1184 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1189 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
1190 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Path Invalid - Unknown Parent");
1194 /* Make sure the directory is current */
1195 lock_ObtainWrite(&dscp->rw);
1196 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1197 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1199 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1200 (*ResultCB)->ResultStatus = status;
1201 lock_ReleaseWrite(&dscp->rw);
1202 cm_ReleaseSCache(dscp);
1203 cm_ReleaseSCache(scp);
1204 osi_Log3(afsd_logp, "RDR_EvaluateNodeByID cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1205 dscp, code, status);
1209 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1210 lock_ReleaseWrite(&dscp->rw);
1212 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1213 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1214 cm_ReleaseSCache(dscp);
1215 cm_ReleaseSCache(scp);
1216 osi_Log1(afsd_logp, "RDR_EvaluateNodeByID Not a Directory dscp=0x%p", dscp);
1220 code = RDR_PopulateCurrentEntry(pCurrentEntry, ResultBufferLength,
1221 dscp, scp, userp, &req, NULL, NULL,
1222 (bWow64 ? RDR_POP_WOW64 : 0) |
1223 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1224 NULL, &dwRemaining);
1227 RDR_FlagScpInUse( scp, FALSE );
1228 cm_ReleaseSCache(scp);
1229 cm_ReleaseSCache(dscp);
1232 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1233 (*ResultCB)->ResultStatus = status;
1234 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID FAILURE code=0x%x status=0x%x",
1237 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1238 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1239 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID SUCCESS");
1245 RDR_CreateFileEntry( IN cm_user_t *userp,
1246 IN WCHAR *FileNameCounted,
1247 IN DWORD FileNameLength,
1248 IN AFSFileCreateCB *CreateCB,
1251 IN DWORD ResultBufferLength,
1252 IN OUT AFSCommResult **ResultCB)
1254 AFSFileCreateResultCB *pResultCB = NULL;
1255 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1258 cm_scache_t * dscp = NULL;
1259 afs_uint32 flags = 0;
1261 cm_scache_t * scp = NULL;
1264 wchar_t FileName[260];
1266 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1268 osi_Log4(afsd_logp, "RDR_CreateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1269 CreateCB->ParentId.Cell, CreateCB->ParentId.Volume,
1270 CreateCB->ParentId.Vnode, CreateCB->ParentId.Unique);
1271 osi_Log1(afsd_logp, "... name=%S", osi_LogSaveStringW(afsd_logp, FileName));
1275 req.flags |= CM_REQ_WOW64;
1276 memset(&setAttr, 0, sizeof(cm_attr_t));
1278 *ResultCB = (AFSCommResult *)malloc(size);
1280 osi_Log0(afsd_logp, "RDR_CreateFileEntry out of memory");
1288 parentFid.cell = CreateCB->ParentId.Cell;
1289 parentFid.volume = CreateCB->ParentId.Volume;
1290 parentFid.vnode = CreateCB->ParentId.Vnode;
1291 parentFid.unique = CreateCB->ParentId.Unique;
1292 parentFid.hash = CreateCB->ParentId.Hash;
1294 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1296 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1297 (*ResultCB)->ResultStatus = status;
1298 osi_Log2(afsd_logp, "RDR_CreateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1303 lock_ObtainWrite(&dscp->rw);
1304 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1305 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1307 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1308 (*ResultCB)->ResultStatus = status;
1309 lock_ReleaseWrite(&dscp->rw);
1310 cm_ReleaseSCache(dscp);
1311 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (1) dscp=0x%p code=0x%x status=0x%x",
1312 dscp, code, status);
1316 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1317 lock_ReleaseWrite(&dscp->rw);
1319 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1320 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1321 cm_ReleaseSCache(dscp);
1322 osi_Log1(afsd_logp, "RDR_CreateFileEntry Not a Directory dscp=0x%p",
1327 /* Use current time */
1328 setAttr.mask = CM_ATTRMASK_CLIENTMODTIME;
1329 setAttr.clientModTime = time(NULL);
1331 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1332 if (smb_unixModeDefaultDir) {
1333 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1334 setAttr.unixModeBits = smb_unixModeDefaultDir;
1335 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1336 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1339 code = cm_MakeDir(dscp, FileName, flags, &setAttr, userp, &req, &scp);
1341 if (smb_unixModeDefaultFile) {
1342 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1343 setAttr.unixModeBits = smb_unixModeDefaultFile;
1344 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1345 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1348 setAttr.mask |= CM_ATTRMASK_LENGTH;
1349 setAttr.length.LowPart = CreateCB->AllocationSize.LowPart;
1350 setAttr.length.HighPart = CreateCB->AllocationSize.HighPart;
1351 code = cm_Create(dscp, FileName, flags, &setAttr, &scp, userp, &req);
1354 wchar_t shortName[13]=L"";
1358 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
1360 (*ResultCB)->ResultBufferLength = sizeof( AFSFileCreateResultCB);
1362 pResultCB = (AFSFileCreateResultCB *)(*ResultCB)->ResultData;
1364 dwRemaining = ResultBufferLength - sizeof( AFSFileCreateResultCB) + sizeof( AFSDirEnumEntry);
1366 lock_ObtainWrite(&dscp->rw);
1367 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1368 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1370 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1371 (*ResultCB)->ResultStatus = status;
1372 lock_ReleaseWrite(&dscp->rw);
1373 cm_ReleaseSCache(dscp);
1374 cm_ReleaseSCache(scp);
1375 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (2) dscp=0x%p code=0x%x status=0x%x",
1376 dscp, code, status);
1380 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1382 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1383 lock_ReleaseWrite(&dscp->rw);
1385 dfid.vnode = htonl(scp->fid.vnode);
1386 dfid.unique = htonl(scp->fid.unique);
1388 if (!cm_Is8Dot3(FileName))
1389 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1391 shortName[0] = '\0';
1393 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1394 dscp, scp, userp, &req, FileName, shortName,
1395 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1396 NULL, &dwRemaining);
1399 RDR_FlagScpInUse( scp, FALSE );
1400 cm_ReleaseSCache(scp);
1401 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1402 osi_Log0(afsd_logp, "RDR_CreateFileEntry SUCCESS");
1404 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1405 (*ResultCB)->ResultStatus = status;
1406 (*ResultCB)->ResultBufferLength = 0;
1407 osi_Log2(afsd_logp, "RDR_CreateFileEntry FAILURE code=0x%x status=0x%x",
1411 cm_ReleaseSCache(dscp);
1417 RDR_UpdateFileEntry( IN cm_user_t *userp,
1418 IN AFSFileID FileId,
1419 IN AFSFileUpdateCB *UpdateCB,
1421 IN DWORD ResultBufferLength,
1422 IN OUT AFSCommResult **ResultCB)
1424 AFSFileUpdateResultCB *pResultCB = NULL;
1425 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1429 afs_uint32 flags = 0;
1431 cm_scache_t * scp = NULL;
1432 cm_scache_t * dscp = NULL;
1434 time_t clientModTime;
1437 BOOL bScpLocked = FALSE;
1441 req.flags |= CM_REQ_WOW64;
1442 memset(&setAttr, 0, sizeof(cm_attr_t));
1444 osi_Log4(afsd_logp, "RDR_UpdateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1445 UpdateCB->ParentId.Cell, UpdateCB->ParentId.Volume,
1446 UpdateCB->ParentId.Vnode, UpdateCB->ParentId.Unique);
1447 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1448 FileId.Cell, FileId.Volume,
1449 FileId.Vnode, FileId.Unique);
1451 *ResultCB = (AFSCommResult *)malloc( size);
1453 osi_Log0(afsd_logp, "RDR_UpdateFileEntry Out of Memory");
1461 parentFid.cell = UpdateCB->ParentId.Cell;
1462 parentFid.volume = UpdateCB->ParentId.Volume;
1463 parentFid.vnode = UpdateCB->ParentId.Vnode;
1464 parentFid.unique = UpdateCB->ParentId.Unique;
1465 parentFid.hash = UpdateCB->ParentId.Hash;
1467 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1469 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1470 (*ResultCB)->ResultStatus = status;
1471 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1476 lock_ObtainWrite(&dscp->rw);
1478 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1479 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1481 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1482 (*ResultCB)->ResultStatus = status;
1483 lock_ReleaseWrite(&dscp->rw);
1484 cm_ReleaseSCache(dscp);
1485 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1486 dscp, code, status);
1490 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1491 lock_ReleaseWrite(&dscp->rw);
1494 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1495 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1496 cm_ReleaseSCache(dscp);
1497 osi_Log1(afsd_logp, "RDR_UpdateFileEntry Not a Directory dscp=0x%p",
1502 Fid.cell = FileId.Cell;
1503 Fid.volume = FileId.Volume;
1504 Fid.vnode = FileId.Vnode;
1505 Fid.unique = FileId.Unique;
1506 Fid.hash = FileId.Hash;
1508 code = cm_GetSCache(&Fid, &scp, userp, &req);
1510 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1511 (*ResultCB)->ResultStatus = status;
1512 cm_ReleaseSCache(dscp);
1513 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache object FID failure code=0x%x status=0x%x",
1518 lock_ObtainWrite(&scp->rw);
1520 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1521 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1523 lock_ReleaseWrite(&scp->rw);
1524 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1525 (*ResultCB)->ResultStatus = status;
1526 (*ResultCB)->ResultBufferLength = 0;
1527 cm_ReleaseSCache(dscp);
1528 cm_ReleaseSCache(scp);
1529 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
1533 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1535 if (UpdateCB->ChangeTime.QuadPart) {
1537 if (scp->fileType == CM_SCACHETYPE_FILE) {
1538 /* Do not set length and other attributes at the same time */
1539 if (scp->length.QuadPart != UpdateCB->AllocationSize.QuadPart) {
1540 osi_Log2(afsd_logp, "RDR_UpdateFileEntry Length Change 0x%x -> 0x%x",
1541 (afs_uint32)scp->length.QuadPart, (afs_uint32)UpdateCB->AllocationSize.QuadPart);
1542 setAttr.mask |= CM_ATTRMASK_LENGTH;
1543 setAttr.length.LowPart = UpdateCB->AllocationSize.LowPart;
1544 setAttr.length.HighPart = UpdateCB->AllocationSize.HighPart;
1545 lock_ReleaseWrite(&scp->rw);
1547 code = cm_SetAttr(scp, &setAttr, userp, &req);
1555 lock_ObtainWrite(&scp->rw);
1558 if ((scp->unixModeBits & 0200) && (UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1559 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1560 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1561 } else if (!(scp->unixModeBits & 0200) && !(UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1562 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1563 setAttr.unixModeBits = scp->unixModeBits | 0222;
1567 if (UpdateCB->LastWriteTime.QuadPart) {
1568 ft.dwLowDateTime = UpdateCB->LastWriteTime.LowPart;
1569 ft.dwHighDateTime = UpdateCB->LastWriteTime.HighPart;
1571 cm_UnixTimeFromLargeSearchTime(& clientModTime, &ft);
1574 lock_ObtainWrite(&scp->rw);
1577 if (scp->clientModTime != clientModTime) {
1578 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1579 setAttr.clientModTime = clientModTime;
1584 lock_ReleaseWrite(&scp->rw);
1586 code = cm_SetAttr(scp, &setAttr, userp, &req);
1593 lock_ReleaseWrite(&scp->rw);
1597 DWORD dwRemaining = ResultBufferLength - sizeof( AFSFileUpdateResultCB) + sizeof( AFSDirEnumEntry);
1599 pResultCB = (AFSFileUpdateResultCB *)(*ResultCB)->ResultData;
1601 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1602 dscp, scp, userp, &req, NULL, NULL,
1603 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1604 NULL, &dwRemaining);
1605 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1606 osi_Log0(afsd_logp, "RDR_UpdateFileEntry SUCCESS");
1608 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1609 (*ResultCB)->ResultStatus = status;
1610 (*ResultCB)->ResultBufferLength = 0;
1611 osi_Log2(afsd_logp, "RDR_UpdateFileEntry FAILURE code=0x%x status=0x%x",
1614 cm_ReleaseSCache(scp);
1615 cm_ReleaseSCache(dscp);
1621 RDR_CleanupFileEntry( IN cm_user_t *userp,
1622 IN AFSFileID FileId,
1623 IN WCHAR *FileNameCounted,
1624 IN DWORD FileNameLength,
1625 IN AFSFileCleanupCB *CleanupCB,
1627 IN BOOL bLastHandle,
1628 IN BOOL bDeleteFile,
1629 IN BOOL bUnlockFile,
1630 IN DWORD ResultBufferLength,
1631 IN OUT AFSCommResult **ResultCB)
1633 size_t size = sizeof(AFSCommResult);
1636 afs_uint32 code = 0;
1637 afs_uint32 flags = 0;
1639 cm_scache_t * scp = NULL;
1640 cm_scache_t * dscp = NULL;
1642 time_t clientModTime;
1645 BOOL bScpLocked = FALSE;
1646 BOOL bDscpLocked = FALSE;
1647 BOOL bFlushFile = FALSE;
1652 req.flags |= CM_REQ_WOW64;
1653 memset(&setAttr, 0, sizeof(cm_attr_t));
1655 osi_Log4(afsd_logp, "RDR_CleanupFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1656 CleanupCB->ParentId.Cell, CleanupCB->ParentId.Volume,
1657 CleanupCB->ParentId.Vnode, CleanupCB->ParentId.Unique);
1658 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1659 FileId.Cell, FileId.Volume,
1660 FileId.Vnode, FileId.Unique);
1662 *ResultCB = (AFSCommResult *)malloc( size);
1664 osi_Log0(afsd_logp, "RDR_CleanupFileEntry Out of Memory");
1672 parentFid.cell = CleanupCB->ParentId.Cell;
1673 parentFid.volume = CleanupCB->ParentId.Volume;
1674 parentFid.vnode = CleanupCB->ParentId.Vnode;
1675 parentFid.unique = CleanupCB->ParentId.Unique;
1676 parentFid.hash = CleanupCB->ParentId.Hash;
1678 if (parentFid.cell) {
1679 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1681 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1682 (*ResultCB)->ResultStatus = status;
1683 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1688 lock_ObtainWrite(&dscp->rw);
1690 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1691 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1693 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure dscp=0x%p code=0x%x",
1699 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1700 lock_ReleaseWrite(&dscp->rw);
1701 bDscpLocked = FALSE;
1703 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1704 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1705 cm_ReleaseSCache(dscp);
1706 osi_Log1(afsd_logp, "RDR_CleanupFileEntry Not a Directory dscp=0x%p",
1713 Fid.cell = FileId.Cell;
1714 Fid.volume = FileId.Volume;
1715 Fid.vnode = FileId.Vnode;
1716 Fid.unique = FileId.Unique;
1717 Fid.hash = FileId.Hash;
1719 code = cm_GetSCache(&Fid, &scp, userp, &req);
1721 osi_Log1(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache object FID failure code=0x%x",
1726 lock_ObtainWrite(&scp->rw);
1728 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1729 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1731 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure scp=0x%p code=0x%x",
1735 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1737 if ((bLastHandle || bFlushFile) &&
1738 scp->redirBufCount > 0)
1740 LARGE_INTEGER heldExtents;
1741 AFSFileExtentCB extentList[1024];
1742 DWORD extentCount = 0;
1747 heldExtents.QuadPart = 0;
1749 for ( srbp = redirq_to_cm_buf_t(scp->redirQueueT);
1751 srbp = redirq_to_cm_buf_t(osi_QPrev(&srbp->redirq)))
1753 extentList[extentCount].Flags = 0;
1754 extentList[extentCount].Length = cm_data.blockSize;
1755 extentList[extentCount].FileOffset.QuadPart = srbp->offset.QuadPart;
1756 extentList[extentCount].CacheOffset.QuadPart = srbp->datap - RDR_extentBaseAddress;
1757 lock_ObtainWrite(&buf_globalLock);
1758 srbp->redirReleaseRequested = now;
1759 lock_ReleaseWrite(&buf_globalLock);
1762 if (extentCount == 1024) {
1763 lock_ReleaseWrite(&scp->rw);
1764 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1766 if (code == CM_ERROR_RETRY) {
1768 * The redirector either is not holding the extents or cannot let them
1769 * go because they are otherwise in use. At the moment, do nothing.
1776 lock_ObtainWrite(&scp->rw);
1780 if (code == 0 && extentCount > 0) {
1782 lock_ReleaseWrite(&scp->rw);
1785 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1790 /* No longer in use by redirector */
1792 lock_ObtainWrite(&scp->rw);
1797 lock_AssertWrite(&scp->rw);
1798 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
1801 if (bLastHandle || bFlushFile) {
1803 lock_ObtainWrite(&scp->rw);
1806 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
1807 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1810 lock_ReleaseWrite(&scp->rw);
1814 code = cm_FSync(scp, userp, &req, bScpLocked);
1816 if (bLastHandle && code)
1820 if (bUnlockFile || bDeleteFile) {
1822 lock_ObtainWrite(&scp->rw);
1825 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1826 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1828 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp (2) failure scp=0x%p code=0x%x",
1833 key = cm_GenerateKey(CM_SESSION_IFS, CleanupCB->ProcessId, 0);
1835 /* the scp is now locked and current */
1836 code = cm_UnlockByKey(scp, key,
1837 bDeleteFile ? CM_UNLOCK_FLAG_BY_FID : 0,
1840 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1846 if (CleanupCB->ChangeTime.QuadPart) {
1848 if (scp->fileType == CM_SCACHETYPE_FILE) {
1849 /* Do not set length and other attributes at the same time */
1850 if (scp->length.QuadPart != CleanupCB->AllocationSize.QuadPart) {
1851 osi_Log2(afsd_logp, "RDR_CleanupFileEntry Length Change 0x%x -> 0x%x",
1852 (afs_uint32)scp->length.QuadPart, (afs_uint32)CleanupCB->AllocationSize.QuadPart);
1853 setAttr.mask |= CM_ATTRMASK_LENGTH;
1854 setAttr.length.LowPart = CleanupCB->AllocationSize.LowPart;
1855 setAttr.length.HighPart = CleanupCB->AllocationSize.HighPart;
1858 lock_ReleaseWrite(&scp->rw);
1861 code = cm_SetAttr(scp, &setAttr, userp, &req);
1869 lock_ObtainWrite(&scp->rw);
1873 if ((scp->unixModeBits & 0200) && (CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1874 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1875 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1876 } else if (!(scp->unixModeBits & 0200) && !(CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1877 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1878 setAttr.unixModeBits = scp->unixModeBits | 0222;
1882 if (CleanupCB->LastWriteTime.QuadPart) {
1883 ft.dwLowDateTime = CleanupCB->LastWriteTime.LowPart;
1884 ft.dwHighDateTime = CleanupCB->LastWriteTime.HighPart;
1886 cm_UnixTimeFromLargeSearchTime(&clientModTime, &ft);
1887 if (scp->clientModTime != clientModTime) {
1888 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1889 setAttr.clientModTime = clientModTime;
1895 lock_ReleaseWrite(&scp->rw);
1897 code = cm_SetAttr(scp, &setAttr, userp, &req);
1901 /* Now drop the lock enforcing the share access */
1902 if ( CleanupCB->FileAccess != AFS_FILE_ACCESS_NOLOCK) {
1903 unsigned int sLockType;
1904 LARGE_INTEGER LOffset, LLength;
1906 if (CleanupCB->FileAccess == AFS_FILE_ACCESS_SHARED)
1907 sLockType = LOCKING_ANDX_SHARED_LOCK;
1911 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, CleanupCB->Identifier);
1913 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
1914 LOffset.LowPart = SMB_FID_QLOCK_LOW;
1915 LLength.HighPart = 0;
1916 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
1919 lock_ObtainWrite(&scp->rw);
1923 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
1926 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
1928 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
1930 if (code == CM_ERROR_RANGE_NOT_LOCKED)
1932 osi_Log3(afsd_logp, "RDR_CleanupFileEntry Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
1933 CleanupCB->FileAccess, CleanupCB->ProcessId, CleanupCB->Identifier);
1941 lock_ReleaseWrite(&dscp->rw);
1943 lock_ReleaseWrite(&scp->rw);
1945 if (dscp && bDeleteFile) {
1946 WCHAR FileName[260];
1948 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1950 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
1951 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
1953 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
1957 (*ResultCB)->ResultStatus = 0;
1958 (*ResultCB)->ResultBufferLength = 0;
1959 osi_Log0(afsd_logp, "RDR_CleanupFileEntry SUCCESS");
1961 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1962 (*ResultCB)->ResultStatus = status;
1963 (*ResultCB)->ResultBufferLength = 0;
1964 osi_Log2(afsd_logp, "RDR_CleanupFileEntry FAILURE code=0x%x status=0x%x",
1968 cm_ReleaseSCache(scp);
1970 cm_ReleaseSCache(dscp);
1976 RDR_DeleteFileEntry( IN cm_user_t *userp,
1977 IN AFSFileID ParentId,
1978 IN ULONGLONG ProcessId,
1979 IN WCHAR *FileNameCounted,
1980 IN DWORD FileNameLength,
1983 IN DWORD ResultBufferLength,
1984 IN OUT AFSCommResult **ResultCB)
1987 AFSFileDeleteResultCB *pResultCB = NULL;
1988 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1991 cm_scache_t * dscp = NULL;
1992 cm_scache_t * scp = NULL;
1993 afs_uint32 flags = 0;
1997 wchar_t FileName[260];
2000 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
2002 osi_Log4(afsd_logp, "RDR_DeleteFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2003 ParentId.Cell, ParentId.Volume,
2004 ParentId.Vnode, ParentId.Unique);
2005 osi_Log2(afsd_logp, "... name=%S checkOnly=%x",
2006 osi_LogSaveStringW(afsd_logp, FileName),
2011 req.flags |= CM_REQ_WOW64;
2012 memset(&setAttr, 0, sizeof(cm_attr_t));
2014 *ResultCB = (AFSCommResult *)malloc( size);
2016 osi_Log0(afsd_logp, "RDR_DeleteFileEntry out of memory");
2024 parentFid.cell = ParentId.Cell;
2025 parentFid.volume = ParentId.Volume;
2026 parentFid.vnode = ParentId.Vnode;
2027 parentFid.unique = ParentId.Unique;
2028 parentFid.hash = ParentId.Hash;
2030 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
2032 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2033 (*ResultCB)->ResultStatus = status;
2034 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
2039 lock_ObtainWrite(&dscp->rw);
2041 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
2042 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2044 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2045 (*ResultCB)->ResultStatus = status;
2046 (*ResultCB)->ResultBufferLength = 0;
2047 lock_ReleaseWrite(&dscp->rw);
2048 cm_ReleaseSCache(dscp);
2049 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
2050 dscp, code, status);
2054 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2055 lock_ReleaseWrite(&dscp->rw);
2057 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2058 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2059 cm_ReleaseSCache(dscp);
2060 osi_Log1(afsd_logp, "RDR_DeleteFileEntry Not a Directory dscp=0x%p",
2065 code = cm_Lookup(dscp, FileName, 0, userp, &req, &scp);
2067 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2068 (*ResultCB)->ResultStatus = status;
2069 (*ResultCB)->ResultBufferLength = 0;
2070 cm_ReleaseSCache(dscp);
2071 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_Lookup failure code=0x%x status=0x%x",
2076 lock_ObtainWrite(&scp->rw);
2077 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_DELETE,
2078 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2080 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2081 (*ResultCB)->ResultStatus = status;
2082 (*ResultCB)->ResultBufferLength = 0;
2083 lock_ReleaseWrite(&scp->rw);
2084 cm_ReleaseSCache(scp);
2085 cm_ReleaseSCache(dscp);
2086 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2092 /* Drop all locks since the file is being deleted */
2093 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2094 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2096 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2097 (*ResultCB)->ResultStatus = status;
2098 (*ResultCB)->ResultBufferLength = 0;
2099 lock_ReleaseWrite(&scp->rw);
2100 cm_ReleaseSCache(scp);
2101 cm_ReleaseSCache(dscp);
2102 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp Lock failure scp=0x%p code=0x%x status=0x%x",
2106 /* the scp is now locked and current */
2107 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId, 0);
2109 code = cm_UnlockByKey(scp, key,
2110 CM_UNLOCK_FLAG_BY_FID,
2113 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2114 lock_ReleaseWrite(&scp->rw);
2116 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
2117 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
2119 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2121 lock_ReleaseWrite(&scp->rw);
2125 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
2127 (*ResultCB)->ResultBufferLength = sizeof( AFSFileDeleteResultCB);
2129 pResultCB = (AFSFileDeleteResultCB *)(*ResultCB)->ResultData;
2131 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
2132 osi_Log0(afsd_logp, "RDR_DeleteFileEntry SUCCESS");
2134 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2135 (*ResultCB)->ResultStatus = status;
2136 (*ResultCB)->ResultBufferLength = 0;
2137 osi_Log2(afsd_logp, "RDR_DeleteFileEntry FAILURE code=0x%x status=0x%x",
2141 cm_ReleaseSCache(dscp);
2142 cm_ReleaseSCache(scp);
2148 RDR_RenameFileEntry( IN cm_user_t *userp,
2149 IN WCHAR *SourceFileNameCounted,
2150 IN DWORD SourceFileNameLength,
2151 IN AFSFileID SourceFileId,
2152 IN AFSFileRenameCB *pRenameCB,
2154 IN DWORD ResultBufferLength,
2155 IN OUT AFSCommResult **ResultCB)
2158 AFSFileRenameResultCB *pResultCB = NULL;
2159 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2160 AFSFileID SourceParentId = pRenameCB->SourceParentId;
2161 AFSFileID TargetParentId = pRenameCB->TargetParentId;
2162 WCHAR * TargetFileNameCounted = pRenameCB->TargetName;
2163 DWORD TargetFileNameLength = pRenameCB->TargetNameLength;
2164 cm_fid_t SourceParentFid;
2165 cm_fid_t TargetParentFid;
2166 cm_scache_t * oldDscp;
2167 cm_scache_t * newDscp;
2168 wchar_t shortName[13];
2169 wchar_t SourceFileName[260];
2170 wchar_t TargetFileName[260];
2178 req.flags |= CM_REQ_WOW64;
2180 StringCchCopyNW(SourceFileName, 260, SourceFileNameCounted, SourceFileNameLength / sizeof(WCHAR));
2181 StringCchCopyNW(TargetFileName, 260, TargetFileNameCounted, TargetFileNameLength / sizeof(WCHAR));
2183 osi_Log4(afsd_logp, "RDR_RenameFileEntry Source Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2184 SourceParentId.Cell, SourceParentId.Volume,
2185 SourceParentId.Vnode, SourceParentId.Unique);
2186 osi_Log2(afsd_logp, "... Source Name=%S Length %u", osi_LogSaveStringW(afsd_logp, SourceFileName), SourceFileNameLength);
2187 osi_Log4(afsd_logp, "... Target Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2188 TargetParentId.Cell, TargetParentId.Volume,
2189 TargetParentId.Vnode, TargetParentId.Unique);
2190 osi_Log2(afsd_logp, "... Target Name=%S Length %u", osi_LogSaveStringW(afsd_logp, TargetFileName), TargetFileNameLength);
2192 *ResultCB = (AFSCommResult *)malloc( size);
2200 pResultCB = (AFSFileRenameResultCB *)(*ResultCB)->ResultData;
2202 if (SourceFileNameLength == 0 || TargetFileNameLength == 0)
2204 osi_Log2(afsd_logp, "RDR_RenameFileEntry Invalid Name Length: src %u target %u",
2205 SourceFileNameLength, TargetFileNameLength);
2206 (*ResultCB)->ResultStatus = STATUS_INVALID_PARAMETER;
2210 SourceParentFid.cell = SourceParentId.Cell;
2211 SourceParentFid.volume = SourceParentId.Volume;
2212 SourceParentFid.vnode = SourceParentId.Vnode;
2213 SourceParentFid.unique = SourceParentId.Unique;
2214 SourceParentFid.hash = SourceParentId.Hash;
2216 TargetParentFid.cell = TargetParentId.Cell;
2217 TargetParentFid.volume = TargetParentId.Volume;
2218 TargetParentFid.vnode = TargetParentId.Vnode;
2219 TargetParentFid.unique = TargetParentId.Unique;
2220 TargetParentFid.hash = TargetParentId.Hash;
2222 code = cm_GetSCache(&SourceParentFid, &oldDscp, userp, &req);
2224 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache source parent failed code 0x%x", code);
2225 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2226 (*ResultCB)->ResultStatus = status;
2230 lock_ObtainWrite(&oldDscp->rw);
2231 code = cm_SyncOp(oldDscp, NULL, userp, &req, 0,
2232 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2234 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp oldDscp 0x%p failed code 0x%x", oldDscp, code);
2235 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2236 (*ResultCB)->ResultStatus = status;
2237 lock_ReleaseWrite(&oldDscp->rw);
2238 cm_ReleaseSCache(oldDscp);
2242 cm_SyncOpDone(oldDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2243 lock_ReleaseWrite(&oldDscp->rw);
2246 if (oldDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2247 osi_Log1(afsd_logp, "RDR_RenameFileEntry oldDscp 0x%p not a directory", oldDscp);
2248 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2249 cm_ReleaseSCache(oldDscp);
2253 code = cm_GetSCache(&TargetParentFid, &newDscp, userp, &req);
2255 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target parent failed code 0x%x", code);
2256 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2257 (*ResultCB)->ResultStatus = status;
2258 cm_ReleaseSCache(oldDscp);
2262 lock_ObtainWrite(&newDscp->rw);
2263 code = cm_SyncOp(newDscp, NULL, userp, &req, 0,
2264 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2266 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp newDscp 0x%p failed code 0x%x", newDscp, code);
2267 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2268 (*ResultCB)->ResultStatus = status;
2269 lock_ReleaseWrite(&newDscp->rw);
2270 cm_ReleaseSCache(oldDscp);
2271 cm_ReleaseSCache(newDscp);
2275 cm_SyncOpDone(newDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2276 lock_ReleaseWrite(&newDscp->rw);
2279 if (newDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2280 osi_Log1(afsd_logp, "RDR_RenameFileEntry newDscp 0x%p not a directory", newDscp);
2281 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2282 cm_ReleaseSCache(oldDscp);
2283 cm_ReleaseSCache(newDscp);
2287 code = cm_Rename( oldDscp, NULL, SourceFileName,
2288 newDscp, TargetFileName, userp, &req);
2292 cm_scache_t *scp = 0;
2295 (*ResultCB)->ResultBufferLength = ResultBufferLength;
2296 dwRemaining = ResultBufferLength - sizeof( AFSFileRenameResultCB) + sizeof( AFSDirEnumEntry);
2297 (*ResultCB)->ResultStatus = 0;
2299 pResultCB->SourceParentDataVersion.QuadPart = oldDscp->dataVersion;
2300 pResultCB->TargetParentDataVersion.QuadPart = newDscp->dataVersion;
2302 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p SUCCESS",
2305 code = cm_BeginDirOp( newDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2307 code = cm_BPlusDirLookup(&dirop, TargetFileName, &targetFid);
2308 cm_EndDirOp(&dirop);
2312 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_BPlusDirLookup failed code 0x%x",
2314 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
2315 cm_ReleaseSCache(oldDscp);
2316 cm_ReleaseSCache(newDscp);
2320 osi_Log4(afsd_logp, "RDR_RenameFileEntry Target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2321 targetFid.cell, targetFid.volume,
2322 targetFid.vnode, targetFid.unique);
2324 code = cm_GetSCache(&targetFid, &scp, userp, &req);
2326 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target failed code 0x%x", code);
2327 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2328 (*ResultCB)->ResultStatus = status;
2329 cm_ReleaseSCache(oldDscp);
2330 cm_ReleaseSCache(newDscp);
2334 /* Make sure the source vnode is current */
2335 lock_ObtainWrite(&scp->rw);
2336 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2337 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2339 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp scp 0x%p failed code 0x%x", scp, code);
2340 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2341 (*ResultCB)->ResultStatus = status;
2342 lock_ReleaseWrite(&scp->rw);
2343 cm_ReleaseSCache(oldDscp);
2344 cm_ReleaseSCache(newDscp);
2345 cm_ReleaseSCache(scp);
2349 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2350 lock_ReleaseWrite(&scp->rw);
2352 dfid.vnode = htonl(scp->fid.vnode);
2353 dfid.unique = htonl(scp->fid.unique);
2355 if (!cm_Is8Dot3(TargetFileName))
2356 cm_Gen8Dot3NameIntW(TargetFileName, &dfid, shortName, NULL);
2358 shortName[0] = '\0';
2360 RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
2361 newDscp, scp, userp, &req, TargetFileName, shortName,
2362 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
2363 NULL, &dwRemaining);
2364 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
2365 cm_ReleaseSCache(scp);
2367 osi_Log0(afsd_logp, "RDR_RenameFileEntry SUCCESS");
2369 osi_Log3(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p failed code 0x%x",
2370 oldDscp, newDscp, code);
2371 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2372 (*ResultCB)->ResultStatus = status;
2373 (*ResultCB)->ResultBufferLength = 0;
2376 cm_ReleaseSCache(oldDscp);
2377 cm_ReleaseSCache(newDscp);
2382 RDR_FlushFileEntry( IN cm_user_t *userp,
2383 IN AFSFileID FileId,
2385 IN DWORD ResultBufferLength,
2386 IN OUT AFSCommResult **ResultCB)
2388 cm_scache_t *scp = NULL;
2399 req.flags |= CM_REQ_WOW64;
2401 osi_Log4(afsd_logp, "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x",
2402 FileId.Cell, FileId.Volume,
2403 FileId.Vnode, FileId.Unique);
2405 snprintf( dbgstr, 1024,
2406 "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x\n",
2407 FileId.Cell, FileId.Volume,
2408 FileId.Vnode, FileId.Unique);
2409 OutputDebugStringA( dbgstr);
2412 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2414 osi_Log0(afsd_logp, "RDR_FlushFileEntry out of memory");
2420 sizeof( AFSCommResult));
2422 /* Process the release */
2423 Fid.cell = FileId.Cell;
2424 Fid.volume = FileId.Volume;
2425 Fid.vnode = FileId.Vnode;
2426 Fid.unique = FileId.Unique;
2427 Fid.hash = FileId.Hash;
2429 code = cm_GetSCache(&Fid, &scp, userp, &req);
2431 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2432 (*ResultCB)->ResultStatus = status;
2433 osi_Log2(afsd_logp, "RDR_FlushFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2438 lock_ObtainWrite(&scp->rw);
2439 if (scp->flags & CM_SCACHEFLAG_DELETED) {
2440 lock_ReleaseWrite(&scp->rw);
2441 (*ResultCB)->ResultStatus = STATUS_INVALID_HANDLE;
2445 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2446 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2448 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2449 (*ResultCB)->ResultStatus = status;
2450 lock_ReleaseWrite(&scp->rw);
2451 cm_ReleaseSCache(scp);
2452 osi_Log3(afsd_logp, "RDR_FlushFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2457 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2458 lock_ReleaseWrite(&scp->rw);
2460 code = cm_FSync(scp, userp, &req, FALSE);
2461 cm_ReleaseSCache(scp);
2464 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2465 (*ResultCB)->ResultStatus = status;
2466 osi_Log2(afsd_logp, "RDR_FlushFileEntry FAILURE code=0x%x status=0x%x",
2469 (*ResultCB)->ResultStatus = 0;
2470 osi_Log0(afsd_logp, "RDR_FlushFileEntry SUCCESS");
2472 (*ResultCB)->ResultBufferLength = 0;
2478 RDR_CheckAccess( IN cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp,
2482 ULONG afs_acc, afs_gr;
2484 afs_uint32 code = 0;
2486 file = (scp->fileType == CM_SCACHETYPE_FILE);
2489 /* access definitions from prs_fs.h */
2491 if (access & FILE_READ_DATA)
2492 afs_acc |= PRSFS_READ;
2493 if (access & FILE_READ_EA || access & FILE_READ_ATTRIBUTES)
2494 afs_acc |= PRSFS_READ;
2495 if (file && ((access & FILE_WRITE_DATA) || (access & FILE_APPEND_DATA)))
2496 afs_acc |= PRSFS_WRITE;
2497 if (access & FILE_WRITE_EA || access & FILE_WRITE_ATTRIBUTES)
2498 afs_acc |= PRSFS_WRITE;
2499 if (dir && ((access & FILE_ADD_FILE) || (access & FILE_ADD_SUBDIRECTORY)))
2500 afs_acc |= PRSFS_INSERT;
2501 if (dir && (access & FILE_LIST_DIRECTORY))
2502 afs_acc |= PRSFS_LOOKUP;
2503 if (file && (access & FILE_EXECUTE))
2504 afs_acc |= PRSFS_WRITE;
2505 if (dir && (access & FILE_TRAVERSE))
2506 afs_acc |= PRSFS_READ;
2507 if (dir && (access & FILE_DELETE_CHILD))
2508 afs_acc |= PRSFS_DELETE;
2509 if ((access & DELETE))
2510 afs_acc |= PRSFS_DELETE;
2512 /* check ACL with server */
2513 lock_ObtainWrite(&scp->rw);
2516 if (cm_HaveAccessRights(scp, userp, reqp, afs_acc, &afs_gr))
2522 /* we don't know the required access rights */
2523 code = cm_GetAccessRights(scp, userp, reqp);
2529 lock_ReleaseWrite(&(scp->rw));
2533 if (afs_gr & PRSFS_READ)
2534 *granted |= FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | FILE_EXECUTE;
2535 if (afs_gr & PRSFS_WRITE)
2536 *granted |= FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES | FILE_EXECUTE;
2537 if (afs_gr & PRSFS_INSERT)
2538 *granted |= (dir ? FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY : 0) | (file ? FILE_ADD_SUBDIRECTORY : 0);
2539 if (afs_gr & PRSFS_LOOKUP)
2540 *granted |= (dir ? FILE_LIST_DIRECTORY : 0);
2541 if (afs_gr & PRSFS_DELETE)
2542 *granted |= FILE_DELETE_CHILD | DELETE;
2543 if (afs_gr & PRSFS_LOCK)
2545 if (afs_gr & PRSFS_ADMINISTER)
2548 *granted |= SYNCHRONIZE | READ_CONTROL;
2550 /* don't give more access than what was requested */
2552 osi_Log3(afsd_logp, "RDR_CheckAccess SUCCESS scp=0x%p requested=0x%x granted=0x%x", scp, access, *granted);
2554 osi_Log2(afsd_logp, "RDR_CheckAccess FAILURE scp=0x%p code=0x%x",
2561 RDR_OpenFileEntry( IN cm_user_t *userp,
2562 IN AFSFileID FileId,
2563 IN AFSFileOpenCB *OpenCB,
2566 IN DWORD ResultBufferLength,
2567 IN OUT AFSCommResult **ResultCB)
2569 AFSFileOpenResultCB *pResultCB = NULL;
2570 cm_scache_t *scp = NULL;
2571 cm_user_t *sysUserp = NULL;
2573 cm_lock_data_t *ldp = NULL;
2580 req.flags |= CM_REQ_WOW64;
2582 osi_Log4(afsd_logp, "RDR_OpenFileEntry File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2583 FileId.Cell, FileId.Volume,
2584 FileId.Vnode, FileId.Unique);
2586 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2588 osi_Log0(afsd_logp, "RDR_OpenFileEntry out of memory");
2594 sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2596 pResultCB = (AFSFileOpenResultCB *)(*ResultCB)->ResultData;
2598 /* Process the release */
2599 Fid.cell = FileId.Cell;
2600 Fid.volume = FileId.Volume;
2601 Fid.vnode = FileId.Vnode;
2602 Fid.unique = FileId.Unique;
2603 Fid.hash = FileId.Hash;
2605 code = cm_GetSCache(&Fid, &scp, userp, &req);
2607 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2608 (*ResultCB)->ResultStatus = status;
2609 osi_Log2(afsd_logp, "RDR_OpenFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2614 lock_ObtainWrite(&scp->rw);
2615 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2616 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2618 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2619 (*ResultCB)->ResultStatus = status;
2620 lock_ReleaseWrite(&scp->rw);
2621 cm_ReleaseSCache(scp);
2622 osi_Log3(afsd_logp, "RDR_OpenFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2627 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2628 lock_ReleaseWrite(&scp->rw);
2630 sysUserp = RDR_GetLocalSystemUser();
2633 * Skip the open check if the request is coming from the local system account.
2634 * The local system has no tokens and therefore any requests sent to a file
2635 * server will fail. Unfortunately, there are special system processes that
2636 * perform actions on files and directories in preparation for memory mapping
2637 * executables. If the open check fails, the real request from the user process
2638 * will never be issued.
2640 * Permitting the file system to allow subsequent operations to proceed does
2641 * not compromise security. All requests to obtain file data or directory
2642 * enumerations will subsequently fail if they are not submitted under the
2643 * context of a process for that have access to the necessary credentials.
2646 if ( userp == sysUserp)
2648 osi_Log1(afsd_logp, "RDR_OpenFileEntry LOCAL_SYSTEM access check skipped scp=0x%p",
2650 pResultCB->GrantedAccess = OpenCB->DesiredAccess;
2651 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2662 "RDR_OpenFileEntry repeating open check scp=0x%p userp=0x%p code=0x%x",
2665 code = cm_CheckNTOpen(scp, OpenCB->DesiredAccess, OpenCB->ShareAccess,
2667 OpenCB->ProcessId, OpenCB->Identifier,
2670 code = RDR_CheckAccess(scp, userp, &req, OpenCB->DesiredAccess, &pResultCB->GrantedAccess);
2671 cm_CheckNTOpenDone(scp, userp, &req, &ldp);
2672 } while (count < 100 && (code == CM_ERROR_RETRY || code == CM_ERROR_WOULDBLOCK));
2676 * If we are restricting sharing, we should do so with a suitable
2679 if (code == 0 && scp->fileType == CM_SCACHETYPE_FILE && !(OpenCB->ShareAccess & FILE_SHARE_WRITE)) {
2681 LARGE_INTEGER LOffset, LLength;
2684 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2685 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2686 LLength.HighPart = 0;
2687 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2690 * If we are not opening the file for writing, then we don't
2691 * try to get an exclusive lock. No one else should be able to
2692 * get an exclusive lock on the file anyway, although someone
2693 * else can get a shared lock.
2695 if ((OpenCB->ShareAccess & FILE_SHARE_READ) || !(OpenCB->DesiredAccess & AFS_ACCESS_WRITE))
2697 sLockType = LOCKING_ANDX_SHARED_LOCK;
2702 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, OpenCB->Identifier);
2704 lock_ObtainWrite(&scp->rw);
2705 code = cm_Lock(scp, sLockType, LOffset, LLength, key, 0, userp, &req, NULL);
2706 lock_ReleaseWrite(&scp->rw);
2709 code = CM_ERROR_SHARING_VIOLATION;
2710 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2712 if (sLockType == LOCKING_ANDX_SHARED_LOCK)
2713 pResultCB->FileAccess = AFS_FILE_ACCESS_SHARED;
2715 pResultCB->FileAccess = AFS_FILE_ACCESS_EXCLUSIVE;
2718 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2721 cm_ReleaseUser(sysUserp);
2722 if (code == 0 && bHoldFid)
2723 RDR_FlagScpInUse( scp, FALSE );
2724 cm_ReleaseSCache(scp);
2727 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2728 (*ResultCB)->ResultStatus = status;
2729 osi_Log2(afsd_logp, "RDR_OpenFileEntry FAILURE code=0x%x status=0x%x",
2732 (*ResultCB)->ResultStatus = 0;
2733 (*ResultCB)->ResultBufferLength = sizeof( AFSFileOpenResultCB);
2734 osi_Log0(afsd_logp, "RDR_OpenFileEntry SUCCESS");
2740 RDR_ReleaseFileAccess( IN cm_user_t *userp,
2741 IN AFSFileID FileId,
2742 IN AFSFileAccessReleaseCB *ReleaseFileCB,
2744 IN DWORD ResultBufferLength,
2745 IN OUT AFSCommResult **ResultCB)
2748 unsigned int sLockType;
2749 LARGE_INTEGER LOffset, LLength;
2750 cm_scache_t *scp = NULL;
2758 req.flags |= CM_REQ_WOW64;
2760 osi_Log4(afsd_logp, "RDR_ReleaseFileAccess File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2761 FileId.Cell, FileId.Volume,
2762 FileId.Vnode, FileId.Unique);
2764 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2766 osi_Log0(afsd_logp, "RDR_ReleaseFileAccess out of memory");
2770 memset( *ResultCB, '\0', sizeof( AFSCommResult));
2772 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_NOLOCK)
2775 /* Process the release */
2776 Fid.cell = FileId.Cell;
2777 Fid.volume = FileId.Volume;
2778 Fid.vnode = FileId.Vnode;
2779 Fid.unique = FileId.Unique;
2780 Fid.hash = FileId.Hash;
2782 code = cm_GetSCache(&Fid, &scp, userp, &req);
2784 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2785 (*ResultCB)->ResultStatus = status;
2786 osi_Log2(afsd_logp, "RDR_ReleaseFileAccess cm_GetSCache FID failure code=0x%x status=0x%x",
2791 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_SHARED)
2792 sLockType = LOCKING_ANDX_SHARED_LOCK;
2796 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, ReleaseFileCB->Identifier);
2798 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2799 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2800 LLength.HighPart = 0;
2801 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2803 lock_ObtainWrite(&scp->rw);
2805 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
2808 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
2810 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
2812 if (code == CM_ERROR_RANGE_NOT_LOCKED)
2814 osi_Log3(afsd_logp, "RDR_ReleaseFileAccess Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
2815 ReleaseFileCB->FileAccess, ReleaseFileCB->ProcessId, ReleaseFileCB->Identifier);
2819 lock_ReleaseWrite(&scp->rw);
2821 osi_Log0(afsd_logp, "RDR_ReleaseFileAccessEntry SUCCESS");
2825 HexCheckSum(unsigned char * buf, int buflen, unsigned char * md5cksum)
2828 static char tr[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
2831 return "buffer length too small to HexCheckSum";
2833 for (i=0;i<16;i++) {
2836 buf[i*2] = tr[k / 16];
2837 buf[i*2+1] = tr[k % 16];
2845 * Extent requests from the file system are triggered when a file
2846 * page is not resident in the Windows cache. The file system is
2847 * responsible for loading the page but cannot block the request
2848 * while doing so. The AFS Redirector forwards the requests to
2849 * the AFS cache manager while indicating to Windows that the page
2850 * is not yet available. A polling operation will then ensue with
2851 * the AFS Redirector issuing a RDR_RequestFileExtentsXXX call for
2852 * each poll attempt. As each request is received and processed
2853 * by a separate worker thread in the service, this can lead to
2854 * contention by multiple threads attempting to claim the same
2855 * cm_buf_t objects. Therefore, it is important that
2857 * (a) the service avoid processing more than one overlapping
2858 * extent request at a time
2859 * (b) background daemon processing be used to avoid blocking
2862 * Beginning with the 20091122 build of the redirector, the redirector
2863 * will not issue an additional RDR_RequestFileExtentsXXX call for
2864 * each poll request. Instead, afsd_service is required to track
2865 * the requests and return them to the redirector or fail the
2866 * portions of the request that cannot be satisfied.
2868 * The request processing returns any extents that can be returned
2869 * immediately to the redirector. The rest of the requested range(s)
2870 * are queued as background operations using RDR_BkgFetch().
2873 /* do the background fetch. */
2875 RDR_BkgFetch(cm_scache_t *scp, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4,
2876 cm_user_t *userp, cm_req_t *reqp)
2882 osi_hyper_t fetched;
2883 osi_hyper_t tblocksize;
2886 cm_buf_t *bufp = NULL;
2887 DWORD dwResultBufferLength;
2888 AFSSetFileExtentsCB *pResultCB;
2892 int reportErrorToRedir = 0;
2893 int force_retry = 0;
2895 FileId.Cell = scp->fid.cell;
2896 FileId.Volume = scp->fid.volume;
2897 FileId.Vnode = scp->fid.vnode;
2898 FileId.Unique = scp->fid.unique;
2899 FileId.Hash = scp->fid.hash;
2901 if ((GetTickCount() - reqp->startTime) / 1000 > HardDeadtimeout * 5) {
2902 RDR_SetFileStatus( &scp->fid, STATUS_IO_TIMEOUT);
2906 fetched.LowPart = 0;
2907 fetched.HighPart = 0;
2908 tblocksize = ConvertLongToLargeInteger(cm_data.buf_blockSize);
2911 length.LowPart = p3;
2912 length.HighPart = p4;
2914 end = LargeIntegerAdd(base, length);
2916 osi_Log5(afsd_logp, "Starting BKG Fetch scp 0x%p offset 0x%x:%x length 0x%x:%x",
2917 scp, p2, p1, p4, p3);
2920 * Make sure we have a callback.
2921 * This is necessary so that we can return access denied
2922 * if a callback cannot be granted.
2924 lock_ObtainWrite(&scp->rw);
2925 code = cm_SyncOp(scp, NULL, userp, reqp, PRSFS_READ,
2926 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2928 lock_ReleaseWrite(&scp->rw);
2929 osi_Log2(afsd_logp, "RDR_BkgFetch cm_SyncOp failure scp=0x%p code=0x%x",
2931 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
2932 RDR_SetFileStatus( &scp->fid, status);
2935 lock_ReleaseWrite(&scp->rw);
2937 dwResultBufferLength = (DWORD)(sizeof( AFSSetFileExtentsCB) + sizeof( AFSSetFileExtentsCB) * (length.QuadPart / cm_data.blockSize + 1));
2938 pResultCB = (AFSSetFileExtentsCB *)malloc( dwResultBufferLength );
2940 return CM_ERROR_RETRY;
2942 memset( pResultCB, '\0', dwResultBufferLength );
2943 pResultCB->FileId = FileId;
2945 for ( code = 0, offset = base;
2946 code == 0 && LargeIntegerLessThan(offset, end);
2947 offset = LargeIntegerAdd(offset, tblocksize) )
2949 int bBufRelease = TRUE;
2952 lock_ReleaseWrite(&scp->rw);
2956 code = buf_Get(scp, &offset, reqp, &bufp);
2959 * any error from buf_Get() is non-fatal.
2960 * we need to re-queue this extent fetch.
2967 lock_ObtainWrite(&scp->rw);
2971 code = cm_GetBuffer(scp, bufp, NULL, userp, reqp);
2973 if (bufp->flags & CM_BUF_DIRTY)
2974 cm_BufWrite(scp, &bufp->offset, cm_chunkSize, CM_BUF_WRITE_SCP_LOCKED, userp, reqp);
2976 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
2977 #ifdef VALIDATE_CHECK_SUM
2983 lock_ObtainWrite(&buf_globalLock);
2984 if (!(bufp->flags & CM_BUF_DIRTY) &&
2985 bufp->cmFlags == 0 &&
2986 !(bufp->qFlags & CM_BUF_QREDIR)) {
2987 buf_InsertToRedirQueue(scp, bufp);
2988 lock_ReleaseWrite(&buf_globalLock);
2990 #ifdef VALIDATE_CHECK_SUM
2991 buf_ComputeCheckSum(bufp);
2993 pResultCB->FileExtents[count].Flags = 0;
2994 pResultCB->FileExtents[count].FileOffset.QuadPart = bufp->offset.QuadPart;
2995 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
2996 pResultCB->FileExtents[count].Length = cm_data.blockSize;
2998 fetched = LargeIntegerAdd(fetched, tblocksize);
2999 bBufRelease = FALSE;
3001 #ifdef VALIDATE_CHECK_SUM
3003 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3004 snprintf( dbgstr, 1024,
3005 "RDR_BkgFetch md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3007 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3008 pResultCB->FileExtents[count].FileOffset.HighPart,
3009 pResultCB->FileExtents[count].FileOffset.LowPart,
3010 pResultCB->FileExtents[count].CacheOffset.HighPart,
3011 pResultCB->FileExtents[count].CacheOffset.LowPart);
3012 OutputDebugStringA( dbgstr);
3015 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3016 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3018 lock_ReleaseWrite(&buf_globalLock);
3019 if ((bufp->cmFlags != 0) || (bufp->flags & CM_BUF_DIRTY)) {
3020 /* An I/O operation is already in progress */
3022 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Not delivering to Redirector Dirty or Busy bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3023 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3025 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3026 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3030 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3031 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3035 * depending on what the error from cm_GetBuffer is
3036 * it may or may not be fatal. Only return fatal errors.
3037 * Re-queue a request for others.
3039 osi_Log5(afsd_logp, "RDR_BkgFetch Extent2FS FAILURE bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x code 0x%x",
3040 bufp, offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize, code);
3042 case CM_ERROR_NOACCESS:
3043 case CM_ERROR_NOSUCHFILE:
3044 case CM_ERROR_NOSUCHPATH:
3045 case CM_ERROR_NOSUCHVOLUME:
3046 case CM_ERROR_NOSUCHCELL:
3047 case CM_ERROR_INVAL:
3048 case CM_ERROR_BADFD:
3049 case CM_ERROR_CLOCKSKEW:
3051 case CM_ERROR_QUOTA:
3052 case CM_ERROR_LOCK_CONFLICT:
3054 * these are fatal errors. deliver what we can
3057 reportErrorToRedir = 1;
3061 * non-fatal errors. re-queue the exent
3063 code = CM_ERROR_RETRY;
3072 lock_ObtainWrite(&scp->rw);
3076 /* wakeup anyone who is waiting */
3077 if (scp->flags & CM_SCACHEFLAG_WAITING) {
3078 osi_Log1(afsd_logp, "RDR Bkg Fetch Waking scp 0x%p", scp);
3079 osi_Wakeup((LONG_PTR) &scp->flags);
3081 lock_ReleaseWrite(&scp->rw);
3084 pResultCB->ExtentCount = count;
3085 RDR_SetFileExtents( pResultCB, dwResultBufferLength);
3089 if (reportErrorToRedir) {
3090 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
3091 RDR_SetFileStatus( &scp->fid, status);
3094 osi_Log4(afsd_logp, "Ending BKG Fetch scp 0x%p code 0x%x fetched 0x%x:%x",
3095 scp, code, fetched.HighPart, fetched.LowPart);
3097 return force_retry ? CM_ERROR_RETRY : code;
3102 RDR_RequestFileExtentsAsync( IN cm_user_t *userp,
3103 IN AFSFileID FileId,
3104 IN AFSRequestExtentsCB *RequestExtentsCB,
3106 IN OUT DWORD * ResultBufferLength,
3107 IN OUT AFSSetFileExtentsCB **ResultCB)
3109 AFSSetFileExtentsCB *pResultCB = NULL;
3113 cm_scache_t *scp = NULL;
3116 afs_uint32 code = 0;
3118 LARGE_INTEGER ByteOffset, BeginOffset, EndOffset, QueueOffset;
3119 afs_uint32 QueueLength;
3121 BOOLEAN bBufRelease = TRUE;
3125 req.flags |= CM_REQ_WOW64;
3126 req.flags |= CM_REQ_NORETRY;
3128 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3129 FileId.Cell, FileId.Volume,
3130 FileId.Vnode, FileId.Unique);
3131 osi_Log4(afsd_logp, "... Flags 0x%x ByteOffset 0x%x:%x Length 0x%x",
3132 RequestExtentsCB->Flags,
3133 RequestExtentsCB->ByteOffset.HighPart, RequestExtentsCB->ByteOffset.LowPart,
3134 RequestExtentsCB->Length);
3135 Length = sizeof( AFSSetFileExtentsCB) + sizeof( AFSFileExtentCB) * (RequestExtentsCB->Length / cm_data.blockSize + 1);
3137 pResultCB = *ResultCB = (AFSSetFileExtentsCB *)malloc( Length );
3138 if (*ResultCB == NULL) {
3139 *ResultBufferLength = 0;
3142 *ResultBufferLength = Length;
3144 memset( pResultCB, '\0', Length );
3145 pResultCB->FileId = FileId;
3147 Fid.cell = FileId.Cell;
3148 Fid.volume = FileId.Volume;
3149 Fid.vnode = FileId.Vnode;
3150 Fid.unique = FileId.Unique;
3151 Fid.hash = FileId.Hash;
3153 code = cm_GetSCache(&Fid, &scp, userp, &req);
3155 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync cm_GetSCache FID failure code=0x%x",
3157 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3162 * Make sure we have a callback.
3163 * This is necessary so that we can return access denied
3164 * if a callback cannot be granted.
3166 lock_ObtainWrite(&scp->rw);
3167 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_READ,
3168 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3169 lock_ReleaseWrite(&scp->rw);
3171 cm_ReleaseSCache(scp);
3172 osi_Log2(afsd_logp, "RDR_RequestFileExtentsAsync cm_SyncOp failure scp=0x%p code=0x%x",
3174 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3175 RDR_SetFileStatus( &scp->fid, status);
3179 /* Allocate the extents from the buffer package */
3181 ByteOffset = BeginOffset = RequestExtentsCB->ByteOffset,
3182 EndOffset.QuadPart = ByteOffset.QuadPart + RequestExtentsCB->Length;
3183 code == 0 && ByteOffset.QuadPart < EndOffset.QuadPart;
3184 ByteOffset.QuadPart += cm_data.blockSize)
3186 BOOL bHaveBuffer = FALSE;
3189 thyper.QuadPart = ByteOffset.QuadPart;
3191 code = buf_Get(scp, &thyper, &req, &bufp);
3193 lock_ObtainMutex(&bufp->mx);
3196 if (bufp->qFlags & CM_BUF_QREDIR) {
3198 } else if (bufp->flags & CM_BUF_DIRTY) {
3199 bHaveBuffer = FALSE;
3201 code = buf_CleanAsyncLocked(scp, bufp, &req, 0, NULL);
3206 case CM_ERROR_RETRY:
3207 /* Couldn't flush it, obtain it asynchronously so we don't block the thread. */
3208 bHaveBuffer = FALSE;
3212 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3213 RDR_SetFileStatus(&FileId, status);
3214 bHaveBuffer = FALSE;
3219 osi_hyper_t minLength; /* effective end of file */
3221 lock_ObtainRead(&scp->rw);
3222 bHaveBuffer = cm_HaveBuffer(scp, bufp, TRUE);
3224 if (LargeIntegerGreaterThan(scp->length, scp->serverLength))
3225 minLength = scp->serverLength;
3227 minLength = scp->length;
3230 LargeIntegerGreaterThanOrEqualTo(bufp->offset, minLength)) {
3231 memset(bufp->datap, 0, cm_data.buf_blockSize);
3232 bufp->dataVersion = scp->dataVersion;
3235 else if ((RequestExtentsCB->Flags & AFS_EXTENT_FLAG_CLEAN) &&
3236 ByteOffset.QuadPart <= bufp->offset.QuadPart &&
3237 EndOffset.QuadPart >= bufp->offset.QuadPart + cm_data.blockSize)
3239 memset(bufp->datap, 0, cm_data.blockSize);
3240 bufp->dataVersion = scp->dataVersion;
3241 buf_SetDirty(bufp, &req, 0, cm_data.blockSize, userp);
3244 lock_ReleaseRead(&scp->rw);
3248 * if this buffer is already up to date, skip it.
3251 if (ByteOffset.QuadPart == BeginOffset.QuadPart) {
3252 BeginOffset.QuadPart += cm_data.blockSize;
3254 QueueLength = (afs_uint32)(ByteOffset.QuadPart - BeginOffset.QuadPart);
3255 QueueOffset = BeginOffset;
3256 BeginOffset = ByteOffset;
3259 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3260 #ifdef VALIDATE_CHECK_SUM
3266 lock_ObtainWrite(&buf_globalLock);
3267 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3268 buf_InsertToRedirQueue(scp, bufp);
3269 lock_ReleaseWrite(&buf_globalLock);
3271 #ifdef VALIDATE_CHECK_SUM
3272 buf_ComputeCheckSum(bufp);
3274 /* we already have the buffer, return it now */
3275 pResultCB->FileExtents[count].Flags = 0;
3276 pResultCB->FileExtents[count].FileOffset = ByteOffset;
3277 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3278 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3281 bBufRelease = FALSE;
3283 #ifdef VALIDATE_CHECK_SUM
3285 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3286 snprintf( dbgstr, 1024,
3287 "RDR_RequestFileExtentsAsync md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3289 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3290 pResultCB->FileExtents[count].FileOffset.HighPart,
3291 pResultCB->FileExtents[count].FileOffset.LowPart,
3292 pResultCB->FileExtents[count].CacheOffset.HighPart,
3293 pResultCB->FileExtents[count].CacheOffset.LowPart);
3294 OutputDebugStringA( dbgstr);
3297 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3298 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3300 lock_ReleaseWrite(&buf_globalLock);
3305 * The service is not handing off the extent to the redirector in this pass.
3306 * However, we know the buffer is in recent use so move the buffer to the
3307 * front of the queue
3309 lock_ObtainWrite(&buf_globalLock);
3310 buf_MoveToHeadOfRedirQueue(scp, bufp);
3311 lock_ReleaseWrite(&buf_globalLock);
3313 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3314 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3318 lock_ReleaseMutex(&bufp->mx);
3323 cm_QueueBKGRequest(scp, RDR_BkgFetch, QueueOffset.LowPart, QueueOffset.HighPart,
3324 QueueLength, 0, userp, &req);
3325 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3326 QueueOffset.HighPart, QueueOffset.LowPart, QueueLength);
3329 /* No error from buf_Get() can be fatal */
3330 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync buf_Get FAILURE offset 0x%x:%x code 0x%x",
3331 BeginOffset.HighPart, BeginOffset.LowPart, code);
3335 if (BeginOffset.QuadPart != EndOffset.QuadPart) {
3336 afs_uint32 length = (afs_uint32)(EndOffset.QuadPart - BeginOffset.QuadPart);
3338 cm_QueueBKGRequest(scp, RDR_BkgFetch, BeginOffset.LowPart, BeginOffset.HighPart,
3339 length, 0, userp, &req);
3340 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3341 BeginOffset.HighPart, BeginOffset.LowPart, length);
3343 cm_ReleaseSCache(scp);
3345 (*ResultCB)->ExtentCount = count;
3346 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync replying with 0x%x extent records", count);
3351 * When processing an extent release the extents must be accepted back by
3352 * the service even if there is an error condition returned to the redirector.
3353 * For example, there may no longer be a callback present or the file may
3354 * have been deleted on the file server. Regardless, the extents must be
3355 * put back into the pool.
3358 RDR_ReleaseFileExtents( IN cm_user_t *userp,
3359 IN AFSFileID FileId,
3360 IN AFSReleaseExtentsCB *ReleaseExtentsCB,
3362 IN DWORD ResultBufferLength,
3363 IN OUT AFSCommResult **ResultCB)
3366 cm_scache_t *scp = NULL;
3376 #ifdef VALIDATE_CHECK_SUM
3377 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3384 req.flags |= CM_REQ_WOW64;
3386 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3387 FileId.Cell, FileId.Volume,
3388 FileId.Vnode, FileId.Unique);
3390 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
3396 sizeof( AFSCommResult));
3398 /* Process the release */
3399 Fid.cell = FileId.Cell;
3400 Fid.volume = FileId.Volume;
3401 Fid.vnode = FileId.Vnode;
3402 Fid.unique = FileId.Unique;
3403 Fid.hash = FileId.Hash;
3405 code = cm_GetSCache(&Fid, &scp, userp, &req);
3407 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3408 (*ResultCB)->ResultStatus = status;
3409 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents cm_GetSCache FID failure code=0x%x status=0x%x",
3414 * We do not stop processing as a result of being unable to find the cm_scache object.
3415 * If this occurs something really bad has happened since the cm_scache object must have
3416 * been recycled while extents were held by the redirector. However, we will be resilient
3417 * and carry on without it.
3419 if (scp && ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3422 memset(&setAttr, 0, sizeof(cm_attr_t));
3423 lock_ObtainWrite(&scp->rw);
3424 if (ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3426 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents new length fid vol 0x%x vno 0x%x length 0x%x:%x",
3427 scp->fid.volume, scp->fid.vnode,
3428 ReleaseExtentsCB->AllocationSize.HighPart,
3429 ReleaseExtentsCB->AllocationSize.LowPart);
3431 setAttr.mask |= CM_ATTRMASK_LENGTH;
3432 setAttr.length.LowPart = ReleaseExtentsCB->AllocationSize.LowPart;
3433 setAttr.length.HighPart = ReleaseExtentsCB->AllocationSize.HighPart;
3435 lock_ReleaseWrite(&scp->rw);
3437 code = cm_SetAttr(scp, &setAttr, userp, &req);
3440 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3441 AFSFileExtentCB * pExtent = &ReleaseExtentsCB->FileExtents[count];
3443 thyper.QuadPart = pExtent->FileOffset.QuadPart;
3445 bufp = buf_Find(&Fid, &thyper);
3447 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
3448 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3449 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3450 Fid.volume, Fid.vnode,
3451 pExtent->FileOffset.HighPart,
3452 pExtent->FileOffset.LowPart);
3453 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
3454 pExtent->CacheOffset.HighPart,
3455 pExtent->CacheOffset.LowPart);
3457 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3458 Fid.volume, Fid.vnode,
3459 pExtent->FileOffset.HighPart,
3460 pExtent->FileOffset.LowPart);
3461 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
3462 pExtent->CacheOffset.HighPart,
3463 pExtent->CacheOffset.LowPart);
3469 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
3470 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3471 Fid.volume, Fid.vnode,
3472 pExtent->FileOffset.HighPart,
3473 pExtent->FileOffset.LowPart);
3474 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
3475 pExtent->CacheOffset.HighPart,
3476 pExtent->CacheOffset.LowPart);
3478 /* Move the buffer to the front of the queue */
3479 lock_ObtainWrite(&buf_globalLock);
3480 buf_MoveToHeadOfRedirQueue(scp, bufp);
3481 lock_ReleaseWrite(&buf_globalLock);
3486 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
3487 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3488 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x not held by file system",
3489 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
3490 pExtent->FileOffset.LowPart);
3491 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3492 pExtent->CacheOffset.HighPart,
3493 pExtent->CacheOffset.LowPart);
3495 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents bufp 0x%p vno 0x%x foffset 0x%x:%x",
3496 bufp, bufp->fid.vnode, pExtent->FileOffset.HighPart,
3497 pExtent->FileOffset.LowPart);
3498 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3499 pExtent->CacheOffset.HighPart,
3500 pExtent->CacheOffset.LowPart);
3502 if (pExtent->Flags || ReleaseExtentsCB->Flags) {
3503 lock_ObtainMutex(&bufp->mx);
3504 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
3505 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
3507 if (bufp->qFlags & CM_BUF_QREDIR) {
3508 lock_ObtainWrite(&buf_globalLock);
3509 if (bufp->qFlags & CM_BUF_QREDIR) {
3510 buf_RemoveFromRedirQueue(scp, bufp);
3511 buf_ReleaseLocked(bufp, TRUE);
3513 lock_ReleaseWrite(&buf_globalLock);
3516 snprintf( dbgstr, 1024,
3517 "RDR_ReleaseFileExtents releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3518 Fid.volume, Fid.vnode, Fid.unique,
3519 pExtent->FileOffset.HighPart,
3520 pExtent->FileOffset.LowPart,
3521 pExtent->CacheOffset.HighPart,
3522 pExtent->CacheOffset.LowPart);
3523 OutputDebugStringA( dbgstr);
3528 snprintf( dbgstr, 1024,
3529 "RDR_ReleaseFileExtents not releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3530 Fid.volume, Fid.vnode, Fid.unique,
3531 pExtent->FileOffset.HighPart,
3532 pExtent->FileOffset.LowPart,
3533 pExtent->CacheOffset.HighPart,
3534 pExtent->CacheOffset.LowPart);
3535 OutputDebugStringA( dbgstr);
3537 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
3538 Fid.volume, Fid.vnode,
3539 pExtent->FileOffset.HighPart,
3540 pExtent->FileOffset.LowPart);
3541 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3542 pExtent->CacheOffset.HighPart,
3543 pExtent->CacheOffset.LowPart);
3546 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
3547 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY) )
3549 #ifdef VALIDATE_CHECK_SUM
3551 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3555 * if the saved checksum matches the checksum of the current state of the buffer
3556 * then the buffer is the same as what was given to the kernel.
3558 if ( buf_ValidateCheckSum(bufp) ) {
3559 buf_ComputeCheckSum(bufp);
3561 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3564 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
3565 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3567 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3570 snprintf( dbgstr, 1024,
3571 "RDR_ReleaseFileExtents dirty flag set but not dirty and user != kernel: old %s kernel %s new %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3572 md5dbg, md5dbg2,md5dbg3,
3573 Fid.volume, Fid.vnode, Fid.unique,
3574 pExtent->FileOffset.HighPart,
3575 pExtent->FileOffset.LowPart,
3576 pExtent->CacheOffset.HighPart,
3577 pExtent->CacheOffset.LowPart);
3578 OutputDebugStringA( dbgstr);
3580 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
3581 Fid.volume, Fid.vnode,
3582 pExtent->FileOffset.HighPart,
3583 pExtent->FileOffset.LowPart);
3584 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3585 pExtent->CacheOffset.HighPart,
3586 pExtent->CacheOffset.LowPart);
3587 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3591 snprintf( dbgstr, 1024,
3592 "RDR_ReleaseFileExtents dirty flag set but not dirty and user == kernel: old %s kernel %s new %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3593 md5dbg, md5dbg2, md5dbg3,
3594 Fid.volume, Fid.vnode, Fid.unique,
3595 pExtent->FileOffset.HighPart,
3596 pExtent->FileOffset.LowPart,
3597 pExtent->CacheOffset.HighPart,
3598 pExtent->CacheOffset.LowPart);
3599 OutputDebugStringA( dbgstr);
3601 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3602 Fid.volume, Fid.vnode,
3603 pExtent->FileOffset.HighPart,
3604 pExtent->FileOffset.LowPart);
3605 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3606 pExtent->CacheOffset.HighPart,
3607 pExtent->CacheOffset.LowPart);
3611 snprintf( dbgstr, 1024,
3612 "RDR_ReleaseFileExtents dirty flag set but not dirty: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3613 Fid.volume, Fid.vnode, Fid.unique,
3614 pExtent->FileOffset.HighPart,
3615 pExtent->FileOffset.LowPart,
3616 pExtent->CacheOffset.HighPart,
3617 pExtent->CacheOffset.LowPart);
3618 OutputDebugStringA( dbgstr);
3620 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3621 Fid.volume, Fid.vnode,
3622 pExtent->FileOffset.HighPart,
3623 pExtent->FileOffset.LowPart);
3624 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3625 pExtent->CacheOffset.HighPart,
3626 pExtent->CacheOffset.LowPart);
3629 buf_ComputeCheckSum(bufp);
3631 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3633 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3634 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3636 snprintf( dbgstr, 1024,
3637 "RDR_ReleaseFileExtents dirty flag set and dirty and user != kernel: old %s kernel %s new %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3638 md5dbg, md5dbg2,md5dbg3,
3639 Fid.volume, Fid.vnode, Fid.unique,
3640 pExtent->FileOffset.HighPart,
3641 pExtent->FileOffset.LowPart,
3642 pExtent->CacheOffset.HighPart,
3643 pExtent->CacheOffset.LowPart);
3644 OutputDebugStringA( dbgstr);
3646 snprintf( dbgstr, 1024,
3647 "RDR_ReleaseFileExtents dirty flag set and dirty and user == kernel: old %s kernel %s new %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3648 md5dbg, md5dbg2,md5dbg3,
3649 Fid.volume, Fid.vnode, Fid.unique,
3650 pExtent->FileOffset.HighPart,
3651 pExtent->FileOffset.LowPart,
3652 pExtent->CacheOffset.HighPart,
3653 pExtent->CacheOffset.LowPart);
3654 OutputDebugStringA( dbgstr);
3657 snprintf( dbgstr, 1024,
3658 "RDR_ReleaseFileExtents dirty flag set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3659 Fid.volume, Fid.vnode, Fid.unique,
3660 pExtent->FileOffset.HighPart,
3661 pExtent->FileOffset.LowPart,
3662 pExtent->CacheOffset.HighPart,
3663 pExtent->CacheOffset.LowPart);
3664 OutputDebugStringA( dbgstr);
3667 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3670 #else /* !VALIDATE_CHECK_SUM */
3671 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3673 #endif /* VALIDATE_CHECK_SUM */
3675 #ifdef VALIDATE_CHECK_SUM
3678 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3680 if ( !buf_ValidateCheckSum(bufp) ) {
3681 buf_ComputeCheckSum(bufp);
3683 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3684 snprintf( dbgstr, 1024,
3685 "RDR_ReleaseFileExtents dirty flag not set but dirty! old %s new %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3687 Fid.volume, Fid.vnode, Fid.unique,
3688 pExtent->FileOffset.HighPart,
3689 pExtent->FileOffset.LowPart,
3690 pExtent->CacheOffset.HighPart,
3691 pExtent->CacheOffset.LowPart);
3692 OutputDebugStringA( dbgstr);
3694 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set but extent has changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3695 Fid.volume, Fid.vnode,
3696 pExtent->FileOffset.HighPart,
3697 pExtent->FileOffset.LowPart);
3698 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3699 pExtent->CacheOffset.HighPart,
3700 pExtent->CacheOffset.LowPart);
3701 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3704 buf_ComputeCheckSum(bufp);
3706 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3707 snprintf( dbgstr, 1024,
3708 "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3709 Fid.volume, Fid.vnode, Fid.unique,
3710 pExtent->FileOffset.HighPart,
3711 pExtent->FileOffset.LowPart,
3712 pExtent->CacheOffset.HighPart,
3713 pExtent->CacheOffset.LowPart);
3714 OutputDebugStringA( dbgstr);
3716 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x foffset 0x%x:%x",
3717 Fid.volume, Fid.vnode,
3718 pExtent->FileOffset.HighPart,
3719 pExtent->FileOffset.LowPart);
3720 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3721 pExtent->CacheOffset.HighPart,
3722 pExtent->CacheOffset.LowPart);
3725 #endif /* VALIDATE_CHECK_SUM */
3726 lock_ReleaseMutex(&bufp->mx);
3731 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3734 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3735 if (wbp->datap == datap)
3740 snprintf( dbgstr, 1024,
3741 "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3742 Fid.volume, Fid.vnode, Fid.unique,
3743 pExtent->FileOffset.HighPart,
3744 pExtent->FileOffset.LowPart,
3745 pExtent->CacheOffset.HighPart,
3746 pExtent->CacheOffset.LowPart);
3747 OutputDebugStringA( dbgstr);
3749 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3750 Fid.volume, Fid.vnode,
3751 pExtent->FileOffset.HighPart,
3752 pExtent->FileOffset.LowPart);
3753 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3754 pExtent->CacheOffset.HighPart,
3755 pExtent->CacheOffset.LowPart);
3756 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3757 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3765 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3768 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3769 if (wbp->datap == datap)
3774 snprintf( dbgstr, 1024,
3775 "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3776 Fid.volume, Fid.vnode, Fid.unique,
3777 pExtent->FileOffset.HighPart,
3778 pExtent->FileOffset.LowPart,
3779 pExtent->CacheOffset.HighPart,
3780 pExtent->CacheOffset.LowPart);
3781 OutputDebugStringA( dbgstr);
3783 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3784 Fid.volume, Fid.vnode,
3785 pExtent->FileOffset.HighPart,
3786 pExtent->FileOffset.LowPart);
3787 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3788 pExtent->CacheOffset.HighPart,
3789 pExtent->CacheOffset.LowPart);
3790 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3791 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3796 if (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_FLUSH) {
3797 lock_ObtainWrite(&scp->rw);
3798 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3799 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3800 lock_ReleaseWrite(&scp->rw);
3802 code = cm_FSync(scp, userp, &req, FALSE);
3805 osi_hyper_t offset = {0,0};
3806 afs_uint32 length = 0;
3807 afs_uint32 rights = 0;
3809 lock_ObtainWrite(&scp->rw);
3810 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3811 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3812 lock_ReleaseWrite(&scp->rw);
3815 * there is at least one dirty extent on this file. queue up background store
3816 * requests for contiguous blocks
3818 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3819 if (ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart == offset.QuadPart + length &&
3820 length + cm_data.buf_blockSize <= cm_chunkSize)
3822 length += cm_data.buf_blockSize;
3824 if (!(offset.QuadPart == 0 && length == 0))
3825 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3826 length, 0, userp, &req);
3827 offset.QuadPart = ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart;
3828 length = cm_data.buf_blockSize;
3831 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3832 length, 0, userp, &req);
3835 cm_ReleaseSCache(scp);
3838 osi_Log5(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
3839 FileId.Cell, FileId.Volume,
3840 FileId.Vnode, FileId.Unique, released);
3841 if (code && code != CM_ERROR_WOULDBLOCK) {
3842 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3843 (*ResultCB)->ResultStatus = status;
3844 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents FAILURE code=0x%x status=0x%x",
3847 (*ResultCB)->ResultStatus = 0;
3848 osi_Log0(afsd_logp, "RDR_ReleaseFileExtents SUCCESS");
3850 (*ResultCB)->ResultBufferLength = 0;
3856 RDR_ProcessReleaseFileExtentsResult( IN AFSReleaseFileExtentsResultCB *ReleaseFileExtentsResultCB,
3857 IN DWORD ResultBufferLength)
3859 afs_uint32 code = 0;
3863 unsigned int fileno, extentno, total_extents = 0;
3864 AFSReleaseFileExtentsResultFileCB *pNextFileCB;
3866 #ifdef VALIDATE_CHECK_SUM
3867 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3873 for ( fileno = 0, pNextFileCB = &ReleaseFileExtentsResultCB->Files[0];
3874 fileno < ReleaseFileExtentsResultCB->FileCount;
3876 AFSReleaseFileExtentsResultFileCB *pFileCB = pNextFileCB;
3877 cm_user_t *userp = NULL;
3879 cm_scache_t * scp = NULL;
3884 userp = RDR_UserFromAuthGroup( &pFileCB->AuthGroup);
3886 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult %d.%d.%d.%d",
3887 pFileCB->FileId.Cell, pFileCB->FileId.Volume,
3888 pFileCB->FileId.Vnode, pFileCB->FileId.Unique);
3890 /* Process the release */
3891 Fid.cell = pFileCB->FileId.Cell;
3892 Fid.volume = pFileCB->FileId.Volume;
3893 Fid.vnode = pFileCB->FileId.Vnode;
3894 Fid.unique = pFileCB->FileId.Unique;
3895 Fid.hash = pFileCB->FileId.Hash;
3897 if (Fid.cell == 0) {
3898 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult Invalid FID %d.%d.%d.%d",
3899 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
3900 code = CM_ERROR_INVAL;
3904 code = cm_GetSCache(&Fid, &scp, userp, &req);
3906 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult cm_GetSCache FID failure code=0x%x",
3909 * A failure to find the cm_scache object cannot prevent the service
3910 * from accepting the extents back from the redirector.
3914 /* if the scp was not found, do not perform the length check */
3915 if (scp && (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart)) {
3918 memset(&setAttr, 0, sizeof(cm_attr_t));
3919 lock_ObtainWrite(&scp->rw);
3920 if (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3921 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult length change vol 0x%x vno 0x%x length 0x%x:%x",
3922 scp->fid.volume, scp->fid.vnode,
3923 pFileCB->AllocationSize.HighPart,
3924 pFileCB->AllocationSize.LowPart);
3925 setAttr.mask |= CM_ATTRMASK_LENGTH;
3926 setAttr.length.LowPart = pFileCB->AllocationSize.LowPart;
3927 setAttr.length.HighPart = pFileCB->AllocationSize.HighPart;
3929 lock_ReleaseWrite(&scp->rw);
3931 code = cm_SetAttr(scp, &setAttr, userp, &req);
3934 for ( extentno = 0; extentno < pFileCB->ExtentCount; total_extents++, extentno++ ) {
3935 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
3937 thyper.QuadPart = pExtent->FileOffset.QuadPart;
3939 bufp = buf_Find(&Fid, &thyper);
3941 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
3942 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3943 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3944 Fid.volume, Fid.vnode,
3945 pExtent->FileOffset.HighPart,
3946 pExtent->FileOffset.LowPart);
3947 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
3948 pExtent->CacheOffset.HighPart,
3949 pExtent->CacheOffset.LowPart);
3951 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3952 Fid.volume, Fid.vnode,
3953 pExtent->FileOffset.HighPart,
3954 pExtent->FileOffset.LowPart);
3955 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
3956 pExtent->CacheOffset.HighPart,
3957 pExtent->CacheOffset.LowPart);
3963 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
3964 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3965 Fid.volume, Fid.vnode,
3966 pExtent->FileOffset.HighPart,
3967 pExtent->FileOffset.LowPart);
3968 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
3969 pExtent->CacheOffset.HighPart,
3970 pExtent->CacheOffset.LowPart);
3972 /* Move the buffer to the front of the queue */
3973 lock_ObtainWrite(&buf_globalLock);
3974 buf_MoveToHeadOfRedirQueue(scp, bufp);
3975 lock_ReleaseWrite(&buf_globalLock);
3980 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
3981 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3982 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3983 Fid.volume, Fid.vnode,
3984 pExtent->FileOffset.HighPart,
3985 pExtent->FileOffset.LowPart);
3986 osi_Log2(afsd_logp, "... coffset 0x%x:%x not held by file system",
3987 pExtent->CacheOffset.HighPart,
3988 pExtent->CacheOffset.LowPart);
3990 snprintf(dbgstr, 1024,
3991 "RDR_ProcessReleaseFileExtentsResult not held by redirector! flags 0x%x:%x vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3992 ReleaseFileExtentsResultCB->Flags, pExtent->Flags,
3993 Fid.volume, Fid.vnode, Fid.unique,
3994 pExtent->FileOffset.HighPart,
3995 pExtent->FileOffset.LowPart,
3996 pExtent->CacheOffset.HighPart,
3997 pExtent->CacheOffset.LowPart);
3998 OutputDebugStringA( dbgstr);
4001 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4002 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4003 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4005 if (pExtent->Flags || ReleaseFileExtentsResultCB->Flags) {
4006 lock_ObtainMutex(&bufp->mx);
4007 if ( (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
4008 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
4010 if (bufp->qFlags & CM_BUF_QREDIR) {
4011 lock_ObtainWrite(&buf_globalLock);
4012 if (bufp->qFlags & CM_BUF_QREDIR) {
4013 buf_RemoveFromRedirQueue(scp, bufp);
4014 buf_ReleaseLocked(bufp, TRUE);
4016 lock_ReleaseWrite(&buf_globalLock);
4020 snprintf(dbgstr, 1024,
4021 "RDR_ProcessReleaseFileExtentsResult extent released: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4022 Fid.volume, Fid.vnode, Fid.unique,
4023 pExtent->FileOffset.HighPart,
4024 pExtent->FileOffset.LowPart,
4025 pExtent->CacheOffset.HighPart,
4026 pExtent->CacheOffset.LowPart);
4027 OutputDebugStringA( dbgstr);
4032 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
4033 Fid.volume, Fid.vnode,
4034 pExtent->FileOffset.HighPart,
4035 pExtent->FileOffset.LowPart);
4036 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4037 pExtent->CacheOffset.HighPart,
4038 pExtent->CacheOffset.LowPart);
4040 snprintf(dbgstr, 1024,
4041 "RDR_ProcessReleaseFileExtentsResult not released! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4042 Fid.volume, Fid.vnode, Fid.unique,
4043 pExtent->FileOffset.HighPart,
4044 pExtent->FileOffset.LowPart,
4045 pExtent->CacheOffset.HighPart,
4046 pExtent->CacheOffset.LowPart);
4047 OutputDebugStringA( dbgstr);
4051 if ( (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
4052 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY) )
4054 #ifdef VALIDATE_CHECK_SUM
4055 if ( buf_ValidateCheckSum(bufp) ) {
4057 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4058 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4059 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
4061 buf_ComputeCheckSum(bufp);
4063 HexCheckSum(md5dbg3, sizeof(md5dbg), bufp->md5cksum);
4065 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4067 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
4070 snprintf(dbgstr, 1024,
4071 "RDR_ProcessReleaseFileExtentsResult dirty flag set and checksums do not match! user %s kernel %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4073 Fid.volume, Fid.vnode, Fid.unique,
4074 pExtent->FileOffset.HighPart,
4075 pExtent->FileOffset.LowPart,
4076 pExtent->CacheOffset.HighPart,
4077 pExtent->CacheOffset.LowPart);
4078 OutputDebugStringA( dbgstr);
4081 "RDR_ProcessReleaseFileExtentsResult dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
4082 Fid.volume, Fid.vnode,
4083 pExtent->FileOffset.HighPart,
4084 pExtent->FileOffset.LowPart);
4086 "... coffset 0x%x:%x",
4087 pExtent->CacheOffset.HighPart,
4088 pExtent->CacheOffset.LowPart);
4090 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4094 snprintf(dbgstr, 1024,
4095 "RDR_ProcessReleaseFileExtentsResult dirty flag set but extent has not changed! old %s kernel %s new %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4096 md5dbg, md5dbg2, md5dbg3,
4097 Fid.volume, Fid.vnode, Fid.unique,
4098 pExtent->FileOffset.HighPart,
4099 pExtent->FileOffset.LowPart,
4100 pExtent->CacheOffset.HighPart,
4101 pExtent->CacheOffset.LowPart);
4102 OutputDebugStringA( dbgstr);
4105 "RDR_ProcessReleaseFileExtentsResult dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
4106 Fid.volume, Fid.vnode,
4107 pExtent->FileOffset.HighPart,
4108 pExtent->FileOffset.LowPart);
4110 "... coffset 0x%x:%x",
4111 pExtent->CacheOffset.HighPart,
4112 pExtent->CacheOffset.LowPart);
4116 #else /* !VALIDATE_CHECK_SUM */
4117 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4120 snprintf(dbgstr, 1024,
4121 "RDR_ProcessReleaseFileExtentsResult dirty! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4122 Fid.volume, Fid.vnode, Fid.unique,
4123 pExtent->FileOffset.HighPart,
4124 pExtent->FileOffset.LowPart,
4125 pExtent->CacheOffset.HighPart,
4126 pExtent->CacheOffset.LowPart);
4127 OutputDebugStringA( dbgstr);
4129 #endif /* VALIDATE_CHECK_SUM */
4131 #ifdef VALIDATE_CHECK_SUM
4134 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4136 if ( !buf_ValidateCheckSum(bufp) ) {
4137 buf_ComputeCheckSum(bufp);
4139 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4140 snprintf(dbgstr, 1024,
4141 "RDR_ProcessReleaseFileExtentsResult dirty flag not set but dirty! old %s new %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4143 Fid.volume, Fid.vnode, Fid.unique,
4144 pExtent->FileOffset.HighPart,
4145 pExtent->FileOffset.LowPart,
4146 pExtent->CacheOffset.HighPart,
4147 pExtent->CacheOffset.LowPart);
4148 OutputDebugStringA( dbgstr);
4150 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult dirty flag NOT set but extent has changed! vol 0x%x vno 0x%x foffset 0x%x:%x",
4151 Fid.volume, Fid.vnode,
4152 pExtent->FileOffset.HighPart,
4153 pExtent->FileOffset.LowPart);
4154 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4155 pExtent->CacheOffset.HighPart,
4156 pExtent->CacheOffset.LowPart);
4160 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4163 buf_ComputeCheckSum(bufp);
4165 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4166 snprintf(dbgstr, 1024,
4167 "RDR_ProcessReleaseFileExtentsResult dirty flag not set and not dirty! old %s new %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4169 Fid.volume, Fid.vnode, Fid.unique,
4170 pExtent->FileOffset.HighPart,
4171 pExtent->FileOffset.LowPart,
4172 pExtent->CacheOffset.HighPart,
4173 pExtent->CacheOffset.LowPart);
4174 OutputDebugStringA( dbgstr);
4178 #endif /* VALIDATE_CHECK_SUM */
4179 lock_ReleaseMutex(&bufp->mx);
4183 /* CacheOffset doesn't match bufp->datap */
4184 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
4187 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
4188 if (wbp->datap == datap)
4193 snprintf(dbgstr, 1024,
4194 "RDR_ProcessReleaseFileExtentsResult non-matching extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x flags 0x%x\n",
4195 Fid.volume, Fid.vnode, Fid.unique,
4196 pExtent->FileOffset.HighPart,
4197 pExtent->FileOffset.LowPart,
4198 pExtent->CacheOffset.HighPart,
4199 pExtent->CacheOffset.LowPart,
4201 OutputDebugStringA( dbgstr);
4203 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4204 Fid.volume, Fid.vnode,
4205 pExtent->FileOffset.HighPart,
4206 pExtent->FileOffset.LowPart);
4207 osi_Log3(afsd_logp, "... coffset 0x%x:%x flags 0x%x",
4208 pExtent->CacheOffset.HighPart,
4209 pExtent->CacheOffset.LowPart,
4212 osi_Log5(afsd_logp, "... coffset belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
4213 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
4215 osi_Log0(afsd_logp, "... coffset cannot be found");
4222 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4223 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4224 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
4225 pExtent->FileOffset.LowPart);
4226 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; cm_buf not found -- recycled?",
4227 pExtent->CacheOffset.HighPart,
4228 pExtent->CacheOffset.LowPart);
4234 snprintf(dbgstr, 1024,
4235 "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4236 Fid.volume, Fid.vnode, Fid.unique,
4237 pExtent->FileOffset.HighPart,
4238 pExtent->FileOffset.LowPart,
4239 pExtent->CacheOffset.HighPart,
4240 pExtent->CacheOffset.LowPart);
4241 OutputDebugStringA( dbgstr);
4243 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x foffset 0x%x:%x",
4244 Fid.volume, Fid.vnode,
4245 pExtent->FileOffset.HighPart,
4246 pExtent->FileOffset.LowPart);
4247 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4248 pExtent->CacheOffset.HighPart,
4249 pExtent->CacheOffset.LowPart);
4254 osi_hyper_t offset = {0,0};
4255 afs_uint32 length = 0;
4258 * there is at least one dirty extent on this file. queue up background store
4259 * requests for contiguous blocks
4261 for ( extentno = 0; extentno < pFileCB->ExtentCount; extentno++ ) {
4262 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4263 if (pExtent->FileOffset.QuadPart == offset.QuadPart + length &&
4264 length < cm_chunkSize) {
4265 length += cm_data.buf_blockSize;
4267 if (!(offset.QuadPart == 0 && length == 0))
4268 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4269 length, 0, userp, &req);
4270 offset.QuadPart = pExtent->FileOffset.QuadPart;
4271 length = cm_data.buf_blockSize;
4274 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4275 length, 0, userp, &req);
4278 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
4279 Fid.cell, Fid.volume, Fid.vnode, Fid.unique, released);
4283 cm_ReleaseUser(userp);
4285 cm_ReleaseSCache(scp);
4287 p = (char *)pFileCB;
4288 p += sizeof(AFSReleaseFileExtentsResultFileCB);
4289 p += sizeof(AFSFileExtentCB) * (pFileCB->ExtentCount - 1);
4290 pNextFileCB = (AFSReleaseFileExtentsResultFileCB *)p;
4293 if (total_extents == 0) {
4294 osi_Log0(afsd_logp, "RDR_ProcessReleaseFileExtentsResult is empty");
4295 code = CM_ERROR_RETRY;
4299 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult FAILURE code=0x%x", code);
4301 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult DONE code=0x%x", code);
4307 RDR_ReleaseFailedSetFileExtents( IN cm_user_t *userp,
4308 IN AFSSetFileExtentsCB *SetFileExtentsResultCB,
4309 IN DWORD ResultBufferLength)
4311 afs_uint32 code = 0;
4313 unsigned int extentno;
4315 cm_scache_t * scp = NULL;
4320 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFileExtents %d.%d.%d.%d",
4321 SetFileExtentsResultCB->FileId.Cell, SetFileExtentsResultCB->FileId.Volume,
4322 SetFileExtentsResultCB->FileId.Vnode, SetFileExtentsResultCB->FileId.Unique);
4324 /* Process the release */
4325 Fid.cell = SetFileExtentsResultCB->FileId.Cell;
4326 Fid.volume = SetFileExtentsResultCB->FileId.Volume;
4327 Fid.vnode = SetFileExtentsResultCB->FileId.Vnode;
4328 Fid.unique = SetFileExtentsResultCB->FileId.Unique;
4329 Fid.hash = SetFileExtentsResultCB->FileId.Hash;
4331 if (Fid.cell == 0) {
4332 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFile Invalid FID %d.%d.%d.%d",
4333 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
4334 code = CM_ERROR_INVAL;
4338 code = cm_GetSCache(&Fid, &scp, userp, &req);
4340 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents cm_GetSCache FID failure code=0x%x",
4342 /* Failure to find the cm_scache object cannot block return of the extents */
4345 for ( extentno = 0; extentno < SetFileExtentsResultCB->ExtentCount; extentno++ ) {
4348 AFSFileExtentCB *pExtent = &SetFileExtentsResultCB->FileExtents[extentno];
4350 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4352 bufp = buf_Find(&Fid, &thyper);
4354 osi_Log5(afsd_logp, "RDR_ReleaseFailedSetFileExtents bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4355 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4356 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4358 lock_ObtainMutex(&bufp->mx);
4359 if (bufp->qFlags & CM_BUF_QREDIR) {
4360 lock_ObtainWrite(&buf_globalLock);
4361 if (bufp->qFlags & CM_BUF_QREDIR) {
4362 buf_RemoveFromRedirQueue(scp, bufp);
4363 buf_ReleaseLocked(bufp, TRUE);
4365 lock_ReleaseWrite(&buf_globalLock);
4367 lock_ReleaseMutex(&bufp->mx);
4374 cm_ReleaseUser(userp);
4376 cm_ReleaseSCache(scp);
4378 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents DONE code=0x%x", code);
4383 RDR_PioctlOpen( IN cm_user_t *userp,
4384 IN AFSFileID ParentId,
4385 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4387 IN DWORD ResultBufferLength,
4388 IN OUT AFSCommResult **ResultCB)
4393 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4399 sizeof( AFSCommResult));
4401 /* Get the active directory */
4402 ParentFid.cell = ParentId.Cell;
4403 ParentFid.volume = ParentId.Volume;
4404 ParentFid.vnode = ParentId.Vnode;
4405 ParentFid.unique = ParentId.Unique;
4406 ParentFid.hash = ParentId.Hash;
4408 /* Get the root directory */
4409 RootFid.cell = pPioctlCB->RootId.Cell;
4410 RootFid.volume = pPioctlCB->RootId.Volume;
4411 RootFid.vnode = pPioctlCB->RootId.Vnode;
4412 RootFid.unique = pPioctlCB->RootId.Unique;
4413 RootFid.hash = pPioctlCB->RootId.Hash;
4415 /* Create the pioctl index */
4416 RDR_SetupIoctl(pPioctlCB->RequestId, &ParentFid, &RootFid, userp);
4423 RDR_PioctlClose( IN cm_user_t *userp,
4424 IN AFSFileID ParentId,
4425 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4427 IN DWORD ResultBufferLength,
4428 IN OUT AFSCommResult **ResultCB)
4430 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4436 sizeof( AFSCommResult));
4438 /* Cleanup the pioctl index */
4439 RDR_CleanupIoctl(pPioctlCB->RequestId);
4446 RDR_PioctlWrite( IN cm_user_t *userp,
4447 IN AFSFileID ParentId,
4448 IN AFSPIOCtlIORequestCB *pPioctlCB,
4450 IN DWORD ResultBufferLength,
4451 IN OUT AFSCommResult **ResultCB)
4453 AFSPIOCtlIOResultCB *pResultCB;
4454 cm_scache_t *dscp = NULL;
4461 req.flags |= CM_REQ_WOW64;
4463 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4469 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4471 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4473 code = RDR_IoctlWrite(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer, &req);
4475 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4476 (*ResultCB)->ResultStatus = status;
4480 pResultCB->BytesProcessed = pPioctlCB->BufferLength;
4481 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4485 RDR_PioctlRead( IN cm_user_t *userp,
4486 IN AFSFileID ParentId,
4487 IN AFSPIOCtlIORequestCB *pPioctlCB,
4489 IN BOOL bIsLocalSystem,
4490 IN DWORD ResultBufferLength,
4491 IN OUT AFSCommResult **ResultCB)
4493 AFSPIOCtlIOResultCB *pResultCB;
4494 cm_scache_t *dscp = NULL;
4498 afs_uint32 pflags = (bIsLocalSystem ? AFSCALL_FLAG_LOCAL_SYSTEM : 0);
4502 req.flags |= CM_REQ_WOW64;
4504 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4510 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4512 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4514 code = RDR_IoctlRead(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer,
4515 &pResultCB->BytesProcessed, &req, pflags);
4517 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4518 (*ResultCB)->ResultStatus = status;
4522 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4526 RDR_ByteRangeLockSync( IN cm_user_t *userp,
4527 IN AFSFileID FileId,
4528 IN AFSByteRangeLockRequestCB *pBRLRequestCB,
4530 IN DWORD ResultBufferLength,
4531 IN OUT AFSCommResult **ResultCB)
4533 AFSByteRangeLockResultCB *pResultCB = NULL;
4534 LARGE_INTEGER ProcessId;
4536 cm_scache_t *scp = NULL;
4544 ProcessId.QuadPart = pBRLRequestCB->ProcessId;
4548 req.flags |= CM_REQ_WOW64;
4550 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4551 FileId.Cell, FileId.Volume,
4552 FileId.Vnode, FileId.Unique);
4553 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4554 ProcessId.HighPart, ProcessId.LowPart);
4556 Length = sizeof( AFSByteRangeLockResultCB) + ((pBRLRequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4557 if (Length > ResultBufferLength) {
4558 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4561 memset( *ResultCB, 0, sizeof(AFSCommResult));
4562 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4566 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4569 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4570 (*ResultCB)->ResultBufferLength = Length;
4572 pResultCB = (AFSByteRangeLockResultCB *)(*ResultCB)->ResultData;
4573 pResultCB->FileId = FileId;
4574 pResultCB->Count = pBRLRequestCB->Count;
4576 /* Allocate the extents from the buffer package */
4577 Fid.cell = FileId.Cell;
4578 Fid.volume = FileId.Volume;
4579 Fid.vnode = FileId.Vnode;
4580 Fid.unique = FileId.Unique;
4581 Fid.hash = FileId.Hash;
4583 code = cm_GetSCache(&Fid, &scp, userp, &req);
4585 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4586 (*ResultCB)->ResultStatus = status;
4587 (*ResultCB)->ResultBufferLength = 0;
4588 osi_Log2(afsd_logp, "RDR_ByteRangeLockSync cm_GetSCache FID failure code=0x%x status=0x%x",
4593 lock_ObtainWrite(&scp->rw);
4595 /* start by looking up the file's end */
4596 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4597 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4599 lock_ReleaseWrite(&scp->rw);
4600 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4601 (*ResultCB)->ResultStatus = status;
4602 (*ResultCB)->ResultBufferLength = 0;
4603 osi_Log3(afsd_logp, "RDR_ByteRangeLockSync cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4608 /* the scp is now locked and current */
4609 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4611 for ( i=0; i<pBRLRequestCB->Count; i++ ) {
4612 pResultCB->Result[i].LockType = pBRLRequestCB->Request[i].LockType;
4613 pResultCB->Result[i].Offset = pBRLRequestCB->Request[i].Offset;
4614 pResultCB->Result[i].Length = pBRLRequestCB->Request[i].Length;
4617 pBRLRequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4618 pBRLRequestCB->Request[i].Offset,
4619 pBRLRequestCB->Request[i].Length,
4620 key, 0, userp, &req, NULL);
4623 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4625 pBRLRequestCB->Request[i].LockType,
4626 pBRLRequestCB->Request[i].Offset.HighPart,
4627 pBRLRequestCB->Request[i].Offset.LowPart);
4628 osi_Log2(afsd_logp, "... length 0x%x:%x",
4629 pBRLRequestCB->Request[i].Length.HighPart,
4630 pBRLRequestCB->Request[i].Length.LowPart);
4635 pResultCB->Result[i].Status = 0;
4637 case CM_ERROR_WOULDBLOCK:
4638 pResultCB->Result[i].Status = STATUS_FILE_LOCK_CONFLICT;
4641 pResultCB->Result[i].Status = STATUS_LOCK_NOT_GRANTED;
4645 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4646 lock_ReleaseWrite(&scp->rw);
4647 cm_ReleaseSCache(scp);
4649 (*ResultCB)->ResultStatus = 0;
4650 osi_Log0(afsd_logp, "RDR_ByteRangeLockSync SUCCESS");
4655 RDR_ByteRangeUnlock( IN cm_user_t *userp,
4656 IN AFSFileID FileId,
4657 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4659 IN DWORD ResultBufferLength,
4660 IN OUT AFSCommResult **ResultCB)
4662 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4663 LARGE_INTEGER ProcessId;
4665 cm_scache_t *scp = NULL;
4673 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4677 req.flags |= CM_REQ_WOW64;
4679 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4680 FileId.Cell, FileId.Volume,
4681 FileId.Vnode, FileId.Unique);
4682 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4683 ProcessId.HighPart, ProcessId.LowPart);
4685 Length = sizeof( AFSByteRangeUnlockResultCB) + ((pBRURequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4686 if (Length > ResultBufferLength) {
4687 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4690 memset( *ResultCB, 0, sizeof(AFSCommResult));
4691 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4695 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4698 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4699 (*ResultCB)->ResultBufferLength = Length;
4701 pResultCB = (AFSByteRangeUnlockResultCB *)(*ResultCB)->ResultData;
4702 pResultCB->Count = pBRURequestCB->Count;
4704 /* Allocate the extents from the buffer package */
4705 Fid.cell = FileId.Cell;
4706 Fid.volume = FileId.Volume;
4707 Fid.vnode = FileId.Vnode;
4708 Fid.unique = FileId.Unique;
4709 Fid.hash = FileId.Hash;
4711 code = cm_GetSCache(&Fid, &scp, userp, &req);
4713 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4714 (*ResultCB)->ResultStatus = status;
4715 (*ResultCB)->ResultBufferLength = 0;
4716 osi_Log2(afsd_logp, "RDR_ByteRangeUnlock cm_GetSCache FID failure code=0x%x status=0x%x",
4721 lock_ObtainWrite(&scp->rw);
4723 /* start by looking up the file's end */
4724 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4725 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4727 lock_ReleaseWrite(&scp->rw);
4728 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4729 (*ResultCB)->ResultStatus = status;
4730 (*ResultCB)->ResultBufferLength = 0;
4731 osi_Log3(afsd_logp, "RDR_ByteRangeUnlock cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4736 /* the scp is now locked and current */
4737 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4739 for ( i=0; i<pBRURequestCB->Count; i++ ) {
4740 pResultCB->Result[i].LockType = pBRURequestCB->Request[i].LockType;
4741 pResultCB->Result[i].Offset = pBRURequestCB->Request[i].Offset;
4742 pResultCB->Result[i].Length = pBRURequestCB->Request[i].Length;
4744 code = cm_Unlock(scp,
4745 pBRURequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4746 pBRURequestCB->Request[i].Offset,
4747 pBRURequestCB->Request[i].Length,
4748 key, CM_UNLOCK_FLAG_MATCH_RANGE, userp, &req);
4751 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4752 code, pBRURequestCB->Request[i].LockType,
4753 pBRURequestCB->Request[i].Offset.HighPart,
4754 pBRURequestCB->Request[i].Offset.LowPart);
4755 osi_Log2(afsd_logp, "... length 0x%x:%x",
4756 pBRURequestCB->Request[i].Length.HighPart,
4757 pBRURequestCB->Request[i].Length.LowPart);
4759 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4760 pResultCB->Result[i].Status = status;
4763 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4764 lock_ReleaseWrite(&scp->rw);
4765 cm_ReleaseSCache(scp);
4767 (*ResultCB)->ResultStatus = 0;
4768 osi_Log0(afsd_logp, "RDR_ByteRangeUnlock SUCCESS");
4773 RDR_ByteRangeUnlockAll( IN cm_user_t *userp,
4774 IN AFSFileID FileId,
4775 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4777 IN DWORD ResultBufferLength,
4778 IN OUT AFSCommResult **ResultCB)
4780 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4781 LARGE_INTEGER ProcessId;
4782 cm_scache_t *scp = NULL;
4789 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4793 req.flags |= CM_REQ_WOW64;
4795 osi_Log4(afsd_logp, "RDR_ByteRangeUnlockAll File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4796 FileId.Cell, FileId.Volume,
4797 FileId.Vnode, FileId.Unique);
4798 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4799 ProcessId.HighPart, ProcessId.LowPart);
4801 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4804 memset( *ResultCB, '\0', sizeof( AFSCommResult));
4805 (*ResultCB)->ResultBufferLength = 0;
4807 /* Allocate the extents from the buffer package */
4808 Fid.cell = FileId.Cell;
4809 Fid.volume = FileId.Volume;
4810 Fid.vnode = FileId.Vnode;
4811 Fid.unique = FileId.Unique;
4812 Fid.hash = FileId.Hash;
4814 code = cm_GetSCache(&Fid, &scp, userp, &req);
4816 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4817 (*ResultCB)->ResultStatus = status;
4818 (*ResultCB)->ResultBufferLength = 0;
4819 osi_Log2(afsd_logp, "RDR_ByteRangeUnlockAll cm_GetSCache FID failure code=0x%x status=0x%x",
4824 lock_ObtainWrite(&scp->rw);
4826 /* start by looking up the file's end */
4827 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4828 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4830 lock_ReleaseWrite(&scp->rw);
4831 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4832 (*ResultCB)->ResultStatus = status;
4833 (*ResultCB)->ResultBufferLength = 0;
4834 osi_Log3(afsd_logp, "RDR_ByteRangeUnlockAll cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4839 /* the scp is now locked and current */
4840 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4842 code = cm_UnlockByKey(scp, key, 0, userp, &req);
4844 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4845 lock_ReleaseWrite(&scp->rw);
4846 cm_ReleaseSCache(scp);
4848 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4849 (*ResultCB)->ResultStatus = status;
4852 osi_Log1(afsd_logp, "RDR_ByteRangeUnlockAll FAILURE code 0x%x", code);
4854 osi_Log0(afsd_logp, "RDR_ByteRangeUnlockAll SUCCESS");
4860 RDR_GetVolumeInfo( IN cm_user_t *userp,
4861 IN AFSFileID FileId,
4863 IN DWORD ResultBufferLength,
4864 IN OUT AFSCommResult **ResultCB)
4866 AFSVolumeInfoCB *pResultCB = NULL;
4868 cm_scache_t *scp = NULL;
4869 cm_volume_t *volp = NULL;
4870 cm_vol_state_t *volstatep = NULL;
4872 cm_cell_t *cellp = NULL;
4877 FILETIME ft = {0x832cf000, 0x01abfcc4}; /* October 1, 1982 00:00:00 +0600 */
4879 char volName[32]="(unknown)";
4880 char offLineMsg[256]="server temporarily inaccessible";
4881 char motd[256]="server temporarily inaccessible";
4883 AFSFetchVolumeStatus volStat;
4887 struct rx_connection * rxconnp;
4891 req.flags |= CM_REQ_WOW64;
4893 osi_Log4(afsd_logp, "RDR_GetVolumeInfo File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4894 FileId.Cell, FileId.Volume,
4895 FileId.Vnode, FileId.Unique);
4897 Length = sizeof( AFSCommResult) + sizeof(AFSVolumeInfoCB);
4898 if (sizeof(AFSVolumeInfoCB) > ResultBufferLength) {
4899 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
4902 memset( *ResultCB, 0, sizeof(AFSCommResult));
4903 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4907 *ResultCB = (AFSCommResult *)malloc( Length );
4910 memset( *ResultCB, '\0', Length );
4911 (*ResultCB)->ResultBufferLength = sizeof(AFSVolumeInfoCB);
4912 pResultCB = (AFSVolumeInfoCB *)(*ResultCB)->ResultData;
4914 /* Allocate the extents from the buffer package */
4915 if (FileId.Cell != 0) {
4916 Fid.cell = FileId.Cell;
4917 Fid.volume = FileId.Volume;
4918 Fid.vnode = FileId.Vnode;
4919 Fid.unique = FileId.Unique;
4920 Fid.hash = FileId.Hash;
4922 code = cm_GetSCache(&Fid, &scp, userp, &req);
4924 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4925 (*ResultCB)->ResultStatus = status;
4926 (*ResultCB)->ResultBufferLength = 0;
4927 osi_Log2(afsd_logp, "RDR_GetVolumeInfo cm_GetSCache FID failure code=0x%x status=0x%x",
4932 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
4933 osi_Log0(afsd_logp, "RDR_GetVolumeInfo Object Name Invalid - Cell = 0");
4936 lock_ObtainWrite(&scp->rw);
4938 /* start by looking up the file's end */
4939 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4940 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
4942 lock_ReleaseWrite(&scp->rw);
4943 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4944 (*ResultCB)->ResultStatus = status;
4945 (*ResultCB)->ResultBufferLength = 0;
4946 osi_Log3(afsd_logp, "RDR_GetVolumeInfo cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4952 pResultCB->SectorsPerAllocationUnit = 1;
4953 pResultCB->BytesPerSector = 1024;
4955 pResultCB->CellID = scp->fid.cell;
4956 pResultCB->VolumeID = scp->fid.volume;
4957 pResultCB->Characteristics = FILE_REMOTE_DEVICE;
4958 pResultCB->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK |
4959 FILE_SUPPORTS_REPARSE_POINTS;
4961 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
4962 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)
4964 pResultCB->TotalAllocationUnits.QuadPart = 100;
4965 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
4967 pResultCB->AvailableAllocationUnits.QuadPart = 0;
4968 pResultCB->Characteristics |= FILE_READ_ONLY_DEVICE;
4970 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( "Freelance.Local.Root", -1, pResultCB->VolumeLabel,
4971 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
4972 if ( pResultCB->VolumeLabelLength )
4973 pResultCB->VolumeLabelLength--;
4975 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
4977 volp = cm_GetVolumeByFID(&scp->fid);
4979 code = CM_ERROR_NOSUCHVOLUME;
4982 volstatep = cm_VolumeStateByID(volp, scp->fid.volume);
4983 volType = cm_VolumeType(volp, scp->fid.volume);
4985 pResultCB->Characteristics |= ((volType == ROVOL || volType == BACKVOL) ? FILE_READ_ONLY_DEVICE : 0);
4988 OfflineMsg = offLineMsg;
4990 lock_ReleaseWrite(&scp->rw);
4992 code = cm_ConnFromFID(&scp->fid, userp, &req, &connp);
4995 rxconnp = cm_GetRxConn(connp);
4996 code = RXAFS_GetVolumeStatus(rxconnp, scp->fid.volume,
4997 &volStat, &Name, &OfflineMsg, &MOTD);
4998 rx_PutConnection(rxconnp);
5000 } while (cm_Analyze(connp, userp, &req, &scp->fid, NULL, NULL, NULL, code));
5001 code = cm_MapRPCError(code, &req);
5003 pResultCB->TotalAllocationUnits.QuadPart = volStat.PartMaxBlocks;
5004 pResultCB->AvailableAllocationUnits.QuadPart = volStat.PartBlocksAvail;
5006 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( Name, -1, pResultCB->VolumeLabel,
5007 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5009 pResultCB->TotalAllocationUnits.QuadPart = 0x7FFFFFFF;
5010 pResultCB->AvailableAllocationUnits.QuadPart = (volType == ROVOL || volType == BACKVOL) ? 0 : 0x3F000000;
5012 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( volp->namep, -1, pResultCB->VolumeLabel,
5013 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5016 if ( pResultCB->VolumeLabelLength )
5017 pResultCB->VolumeLabelLength--;
5019 lock_ObtainWrite(&scp->rw);
5021 pResultCB->VolumeLabelLength *= sizeof(WCHAR); /* convert to bytes from chars */
5023 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5026 lock_ReleaseWrite(&scp->rw);
5029 cm_ReleaseSCache(scp);
5031 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5032 (*ResultCB)->ResultStatus = status;
5033 osi_Log0(afsd_logp, "RDR_GetVolumeInfo SUCCESS");
5038 RDR_HoldFid( IN cm_user_t *userp,
5039 IN AFSHoldFidRequestCB * pHoldFidCB,
5041 IN DWORD ResultBufferLength,
5042 IN OUT AFSCommResult **ResultCB)
5044 AFSHoldFidResultCB *pResultCB = NULL;
5051 osi_Log1(afsd_logp, "RDR_HoldFid Count=%u", pHoldFidCB->Count);
5053 Length = sizeof(AFSHoldFidResultCB) + (pHoldFidCB->Count-1) * sizeof(AFSFidResult);
5054 if (Length > ResultBufferLength) {
5055 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5058 memset( *ResultCB, 0, sizeof(AFSCommResult));
5059 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5062 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5065 memset( *ResultCB, '\0', Length );
5066 (*ResultCB)->ResultBufferLength = Length;
5067 pResultCB = (AFSHoldFidResultCB *)(*ResultCB)->ResultData;
5069 for ( index = 0; index < pHoldFidCB->Count; index++ )
5071 cm_scache_t *scp = NULL;
5074 Fid.cell = pResultCB->Result[index].FileID.Cell = pHoldFidCB->FileID[index].Cell;
5075 Fid.volume = pResultCB->Result[index].FileID.Volume = pHoldFidCB->FileID[index].Volume;
5076 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pHoldFidCB->FileID[index].Vnode;
5077 Fid.unique = pResultCB->Result[index].FileID.Unique = pHoldFidCB->FileID[index].Unique;
5078 Fid.hash = pResultCB->Result[index].FileID.Hash = pHoldFidCB->FileID[index].Hash;
5080 osi_Log4( afsd_logp,
5081 "RDR_HoldFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5082 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5084 scp = cm_FindSCache(&Fid);
5086 RDR_FlagScpInUse( scp, FALSE );
5087 cm_ReleaseSCache(scp);
5089 pResultCB->Result[index].Status = 0;
5092 (*ResultCB)->ResultStatus = 0;
5093 osi_Log0(afsd_logp, "RDR_HoldFid SUCCESS");
5098 RDR_ReleaseFid( IN cm_user_t *userp,
5099 IN AFSReleaseFidRequestCB * pReleaseFidCB,
5101 IN DWORD ResultBufferLength,
5102 IN OUT AFSCommResult **ResultCB)
5104 AFSReleaseFidResultCB *pResultCB = NULL;
5111 osi_Log1(afsd_logp, "RDR_ReleaseFid Count=%u", pReleaseFidCB->Count);
5113 Length = sizeof(AFSReleaseFidResultCB) + (pReleaseFidCB->Count ? pReleaseFidCB->Count-1 : 0) * sizeof(AFSFidResult);
5114 if (Length > ResultBufferLength) {
5115 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5118 memset( *ResultCB, 0, sizeof(AFSCommResult));
5119 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5122 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5125 memset( *ResultCB, '\0', Length );
5126 (*ResultCB)->ResultBufferLength = Length;
5127 pResultCB = (AFSReleaseFidResultCB *)(*ResultCB)->ResultData;
5129 for ( index = 0; index < pReleaseFidCB->Count; index++ )
5131 cm_scache_t *scp = NULL;
5134 Fid.cell = pResultCB->Result[index].FileID.Cell = pReleaseFidCB->FileID[index].Cell;
5135 Fid.volume = pResultCB->Result[index].FileID.Volume = pReleaseFidCB->FileID[index].Volume;
5136 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pReleaseFidCB->FileID[index].Vnode;
5137 Fid.unique = pResultCB->Result[index].FileID.Unique = pReleaseFidCB->FileID[index].Unique;
5138 Fid.hash = pResultCB->Result[index].FileID.Hash = pReleaseFidCB->FileID[index].Hash;
5140 osi_Log4( afsd_logp,
5141 "RDR_ReleaseFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5142 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5144 scp = cm_FindSCache(&Fid);
5146 lock_ObtainWrite(&scp->rw);
5147 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
5148 lock_ReleaseWrite(&scp->rw);
5150 cm_ReleaseSCache(scp);
5152 pResultCB->Result[index].Status = 0;
5154 pResultCB->Count = pReleaseFidCB->Count;
5156 (*ResultCB)->ResultStatus = 0;
5157 osi_Log0(afsd_logp, "RDR_ReleaseFid SUCCESS");
5162 * The redirector makes several assumptions regarding the
5163 * SRVSVC and WKSSVC pipes transactions. First, the interface
5164 * versions are those indicated below. Secondly, the encoding
5165 * will be performed using NDR version 2. These assumptions
5166 * may not hold in the future and end-to-end MSRPC Bind
5167 * negotiations may need to be supported. Of course, these
5168 * are the only interface versions that are supported by the
5171 #define MSRPC_PIPE_PREFIX L".\\"
5173 static const UUID MSRPC_SRVSVC_UUID = {0x4B324FC8, 0x1670, 0x01D3,
5174 {0x12, 0x78, 0x5A, 0x47, 0xBF, 0x6E, 0xE1, 0x88}};
5175 #define MSRPC_SRVSVC_NAME L"PIPE\\SRVSVC"
5176 #define MSRPC_SRVSVC_VERS 3
5178 static const UUID MSRPC_WKSSVC_UUID = {0x6BFFD098, 0xA112, 0x3610,
5179 {0x98, 0x33, 0x46, 0xC3, 0xF8, 0x7E, 0x34, 0x5A}};
5180 #define MSRPC_WKSSVC_NAME L"PIPE\\WKSSVC"
5181 #define MSRPC_WKSSVC_VERS 1
5183 static const UUID MSRPC_NDR_UUID = {0x8A885D04, 0x1CEB, 0x11C9,
5184 {0x9F, 0xE8, 0x08, 0x00, 0x2B, 0x10, 0x48, 0x60}};
5185 #define MSRPC_NDR_NAME L"NDR"
5186 #define MSRPC_NDR_VERS 2
5188 extern RPC_IF_HANDLE srvsvc_v3_0_s_ifspec;
5189 extern RPC_IF_HANDLE wkssvc_v1_0_s_ifspec;
5192 RDR_PipeOpen( IN cm_user_t *userp,
5193 IN AFSFileID ParentId,
5195 IN DWORD NameLength,
5196 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5198 IN DWORD ResultBufferLength,
5199 IN OUT AFSCommResult **ResultCB)
5204 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5210 sizeof( AFSCommResult));
5212 /* Get the active directory */
5213 ParentFid.cell = ParentId.Cell;
5214 ParentFid.volume = ParentId.Volume;
5215 ParentFid.vnode = ParentId.Vnode;
5216 ParentFid.unique = ParentId.Unique;
5217 ParentFid.hash = ParentId.Hash;
5219 /* Get the root directory */
5220 RootFid.cell = pPipe_CB->RootId.Cell;
5221 RootFid.volume = pPipe_CB->RootId.Volume;
5222 RootFid.vnode = pPipe_CB->RootId.Vnode;
5223 RootFid.unique = pPipe_CB->RootId.Unique;
5224 RootFid.hash = pPipe_CB->RootId.Hash;
5226 /* Create the pipe index */
5227 (*ResultCB)->ResultStatus =
5228 RDR_SetupPipe( pPipe_CB->RequestId, &ParentFid, &RootFid,
5229 Name, NameLength, userp);
5235 RDR_PipeClose( IN cm_user_t *userp,
5236 IN AFSFileID ParentId,
5237 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5239 IN DWORD ResultBufferLength,
5240 IN OUT AFSCommResult **ResultCB)
5242 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5248 sizeof( AFSCommResult));
5250 /* Cleanup the pipe index */
5251 RDR_CleanupPipe(pPipe_CB->RequestId);
5258 RDR_PipeWrite( IN cm_user_t *userp,
5259 IN AFSFileID ParentId,
5260 IN AFSPipeIORequestCB *pPipe_CB,
5261 IN BYTE *pPipe_Data,
5263 IN DWORD ResultBufferLength,
5264 IN OUT AFSCommResult **ResultCB)
5266 AFSPipeIOResultCB *pResultCB;
5267 cm_scache_t *dscp = NULL;
5274 req.flags |= CM_REQ_WOW64;
5276 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5282 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5284 pResultCB = (AFSPipeIOResultCB *)(*ResultCB)->ResultData;
5286 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_Data, &req, userp);
5288 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5289 (*ResultCB)->ResultStatus = status;
5293 pResultCB->BytesProcessed = pPipe_CB->BufferLength;
5294 (*ResultCB)->ResultBufferLength = sizeof( AFSPipeIOResultCB);
5299 RDR_PipeRead( IN cm_user_t *userp,
5300 IN AFSFileID ParentId,
5301 IN AFSPipeIORequestCB *pPipe_CB,
5303 IN DWORD ResultBufferLength,
5304 IN OUT AFSCommResult **ResultCB)
5307 cm_scache_t *dscp = NULL;
5314 req.flags |= CM_REQ_WOW64;
5316 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5322 sizeof( AFSCommResult));
5324 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5326 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_Data,
5327 &(*ResultCB)->ResultBufferLength, &req, userp);
5329 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5330 (*ResultCB)->ResultStatus = status;
5337 RDR_PipeSetInfo( IN cm_user_t *userp,
5338 IN AFSFileID ParentId,
5339 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5340 IN BYTE *pPipe_Data,
5342 IN DWORD ResultBufferLength,
5343 IN OUT AFSCommResult **ResultCB)
5345 cm_scache_t *dscp = NULL;
5351 req.flags |= CM_REQ_WOW64;
5353 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5359 sizeof( AFSCommResult));
5361 status = RDR_Pipe_SetInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5362 pPipeInfo_CB->BufferLength, pPipe_Data, &req, userp);
5364 (*ResultCB)->ResultStatus = status;
5369 RDR_PipeQueryInfo( IN cm_user_t *userp,
5370 IN AFSFileID ParentId,
5371 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5373 IN DWORD ResultBufferLength,
5374 IN OUT AFSCommResult **ResultCB)
5377 cm_scache_t *dscp = NULL;
5383 req.flags |= CM_REQ_WOW64;
5385 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5391 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5393 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5395 status = RDR_Pipe_QueryInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5396 ResultBufferLength, pPipe_Data,
5397 &(*ResultCB)->ResultBufferLength, &req, userp);
5399 (*ResultCB)->ResultStatus = status;
5403 RDR_PipeTransceive( IN cm_user_t *userp,
5404 IN AFSFileID ParentId,
5405 IN AFSPipeIORequestCB *pPipe_CB,
5406 IN BYTE *pPipe_InData,
5408 IN DWORD ResultBufferLength,
5409 IN OUT AFSCommResult **ResultCB)
5412 * This function processes a Pipe Service request
5413 * that would normally be sent to a LAN Manager server
5414 * across an authenticated SMB-PIPE/MSRPC/SVC request
5415 * stack. The request is being sent here because the
5416 * application (e.g., Explorer Shell or Common Control File
5417 * dialog) believes that because the UNC path it is
5418 * processing has specified a server name that is not
5419 * "." and that the Server is remote and that the Share
5420 * list cannot be obtained using the Network Provider
5423 * The file system driver is faking the Bind-Ack response
5424 * to the MSRPC Bind request but cannot decode the NDR
5425 * encoded Pipe Service requests. For that we will use
5426 * the service's MSRPC module. However, unlike the SMB
5427 * server usage we must fake the MSRPC Bind exchange and
5428 * map the PipeName to an interface instead of using the
5429 * GUID specified in the MSRPC Bind request.
5431 * None of the requests that are being processed by the
5432 * service require authentication. As a result the userp
5433 * parameter will be ignored.
5435 * Although there are dozens of Pipe Services, the only
5436 * ones that we are implementing are WKSSVC and SRVSVC.
5437 * These support NetShareEnum, NetShareGetInfo,
5438 * NetServerGetInfo, and NetWorkstaGetInfo which are
5439 * commonly queried by NET VIEW, the Explorer Shell,
5440 * and the Common Control File dialog.
5442 BYTE *pPipe_OutData;
5443 cm_scache_t *dscp = NULL;
5447 DWORD Length = ResultBufferLength + sizeof( AFSCommResult);
5451 req.flags |= CM_REQ_WOW64;
5453 *ResultCB = (AFSCommResult *)malloc( Length);
5456 memset( *ResultCB, '\0', Length );
5458 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_InData, &req, userp);
5460 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5461 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Write FAILURE code=0x%x status=0x%x",
5463 (*ResultCB)->ResultStatus = status;
5467 pPipe_OutData = (BYTE *)(*ResultCB)->ResultData;
5468 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_OutData,
5469 &(*ResultCB)->ResultBufferLength, &req, userp);
5471 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5472 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Read FAILURE code=0x%x status=0x%x",
5474 (*ResultCB)->ResultStatus = status;
5478 (*ResultCB)->ResultStatus = 0;
5479 osi_Log0(afsd_logp, "RDR_Pipe_Transceive SUCCESS");