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 memcpy(&unp->userp->authgroup, pGuid, sizeof(GUID));
238 unp->flags |= SMB_USERNAMEFLAG_SID;
239 lock_ReleaseMutex(&unp->mx);
242 smb_ReleaseUsername(unp);
246 userp = cm_rootUserp;
250 osi_Log2(afsd_logp, "RDR_UserFromCommRequest Guid %S userp = 0x%p",
251 osi_LogSaveStringW(afsd_logp, UuidString),
255 RpcStringFreeW(&UuidString);
261 RDR_ReleaseUser( IN cm_user_t *userp )
263 osi_Log1(afsd_logp, "RDR_ReleaseUser userp = 0x%p", userp);
264 cm_ReleaseUser(userp);
269 * RDR_FlagScpInUse flags the scp with CM_SCACHEFLAG_RDR_IN_USE
272 RDR_FlagScpInUse( IN cm_scache_t *scp, IN BOOL bLocked )
275 lock_ObtainWrite(&scp->rw);
277 lock_AssertWrite(&scp->rw);
278 scp->flags |= CM_SCACHEFLAG_RDR_IN_USE;
281 lock_ReleaseWrite(&scp->rw);
285 * Obtain the status information for the specified object and
289 RDR_BulkStatLookup( cm_scache_t *dscp,
294 cm_direnum_t * enump = NULL;
298 code = cm_BeginDirOp(dscp, userp, reqp, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
300 code = cm_BPlusDirEnumerate(dscp, userp, reqp, TRUE, NULL, TRUE, &enump);
302 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BPlusDirEnumerate failure code=0x%x",
307 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BeginDirOp failure code=0x%x",
314 code = cm_BPlusDirEnumBulkStatOne(enump, scp);
316 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BPlusDirEnumBulkStatOne failure code=0x%x",
319 cm_BPlusDirFreeEnumeration(enump);
326 #define RDR_POP_FOLLOW_MOUNTPOINTS 0x01
327 #define RDR_POP_EVALUATE_SYMLINKS 0x02
328 #define RDR_POP_WOW64 0x04
329 #define RDR_POP_NO_GETSTATUS 0x08
332 RDR_PopulateCurrentEntry( IN AFSDirEnumEntry * pCurrentEntry,
333 IN DWORD dwMaxEntryLength,
334 IN cm_scache_t * dscp,
335 IN cm_scache_t * scp,
336 IN cm_user_t * userp,
339 IN wchar_t * shortName,
341 OUT AFSDirEnumEntry **ppNextEntry,
342 OUT DWORD * pdwRemainingLength)
345 WCHAR * wname, *wtarget;
348 afs_uint32 code = 0, code2 = 0;
349 BOOL bMustFake = FALSE;
351 osi_Log5(afsd_logp, "RDR_PopulateCurrentEntry dscp=0x%p scp=0x%p name=%S short=%S flags=0x%x",
352 dscp, scp, osi_LogSaveStringW(afsd_logp, name),
353 osi_LogSaveStringW(afsd_logp, shortName), dwFlags);
354 osi_Log1(afsd_logp, "... maxLength=%d", dwMaxEntryLength);
356 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
358 *ppNextEntry = pCurrentEntry;
359 if (pdwRemainingLength)
360 *pdwRemainingLength = dwMaxEntryLength;
361 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry Not Enough Room for Entry %d < %d",
362 dwMaxEntryLength, sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t));
363 return CM_ERROR_TOOBIG;
371 dwEntryLength = sizeof(AFSDirEnumEntry);
373 lock_ObtainWrite(&scp->rw);
374 if (dwFlags & RDR_POP_NO_GETSTATUS) {
375 if (!cm_HaveCallback(scp))
378 #ifdef AFS_FREELANCE_CLIENT
379 if (scp->fid.cell == AFS_FAKE_ROOT_CELL_ID && scp->fid.volume == AFS_FAKE_ROOT_VOL_ID) {
381 * If the FID is from the Freelance Local Root always perform
382 * a single item status check.
384 code = cm_SyncOp( scp, NULL, userp, reqp, 0,
385 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
387 lock_ReleaseWrite(&scp->rw);
388 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_SyncOp failed for scp=0x%p code=0x%x",
396 * For non-Freelance objects, check to see if we have current
397 * status information. If not, perform a bulk status lookup of multiple
398 * entries in order to reduce the number of RPCs issued to the file server.
400 if ((scp->flags & CM_SCACHEFLAG_EACCESS))
402 else if (!cm_HaveCallback(scp)) {
403 lock_ReleaseWrite(&scp->rw);
404 code = RDR_BulkStatLookup(dscp, scp, userp, reqp);
406 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry RXR_BulkStatLookup failed for scp=0x%p code=0x%x",
410 lock_ObtainWrite(&scp->rw);
412 * RDR_BulkStatLookup can succeed but it may be the case that there
413 * still is not valid status info. If we get this far, generate fake
416 if (!cm_HaveCallback(scp))
423 /* Populate the real or fake data */
424 pCurrentEntry->FileId.Cell = scp->fid.cell;
425 pCurrentEntry->FileId.Volume = scp->fid.volume;
426 pCurrentEntry->FileId.Vnode = scp->fid.vnode;
427 pCurrentEntry->FileId.Unique = scp->fid.unique;
428 pCurrentEntry->FileId.Hash = scp->fid.hash;
430 pCurrentEntry->FileType = scp->fileType;
432 pCurrentEntry->DataVersion.QuadPart = scp->dataVersion;
434 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
435 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
436 cm_LargeSearchTimeFromUnixTime(&ft, MAX_AFS_UINT32);
438 cm_LargeSearchTimeFromUnixTime(&ft, scp->cbExpires);
440 pCurrentEntry->Expiration.LowPart = ft.dwLowDateTime;
441 pCurrentEntry->Expiration.HighPart = ft.dwHighDateTime;
444 /* 1969-12-31 23:59:59 +00 */
445 ft.dwHighDateTime = 0x19DB200;
446 ft.dwLowDateTime = 0x5BB78980;
448 cm_LargeSearchTimeFromUnixTime(&ft, scp->clientModTime);
449 pCurrentEntry->CreationTime.LowPart = ft.dwLowDateTime;
450 pCurrentEntry->CreationTime.HighPart = ft.dwHighDateTime;
451 pCurrentEntry->LastAccessTime = pCurrentEntry->CreationTime;
452 pCurrentEntry->LastWriteTime = pCurrentEntry->CreationTime;
453 pCurrentEntry->ChangeTime = pCurrentEntry->CreationTime;
455 pCurrentEntry->EndOfFile = scp->length;
456 pCurrentEntry->AllocationSize = scp->length;
459 switch (scp->fileType) {
460 case CM_SCACHETYPE_DIRECTORY:
461 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY;
463 case CM_SCACHETYPE_MOUNTPOINT:
464 case CM_SCACHETYPE_INVALID:
465 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY | SMB_ATTR_REPARSE_POINT;
467 case CM_SCACHETYPE_SYMLINK:
468 if (cm_TargetPerceivedAsDirectory(scp->mountPointStringp))
469 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY | SMB_ATTR_REPARSE_POINT;
471 pCurrentEntry->FileAttributes = SMB_ATTR_REPARSE_POINT;
474 /* if we get here we either have a normal file
475 * or we have a file for which we have never
476 * received status info. In this case, we can
477 * check the even/odd value of the entry's vnode.
478 * odd means it is to be treated as a directory
479 * and even means it is to be treated as a file.
481 if (scp->fid.vnode & 0x1)
482 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY;
484 pCurrentEntry->FileAttributes = SMB_ATTR_NORMAL;
487 pCurrentEntry->FileAttributes = smb_ExtAttributes(scp);
488 pCurrentEntry->EaSize = 0;
489 pCurrentEntry->Links = scp->linkCount;
491 len = wcslen(shortName);
492 wcsncpy(pCurrentEntry->ShortName, shortName, len);
493 pCurrentEntry->ShortNameLength = (CCHAR)(len * sizeof(WCHAR));
495 pCurrentEntry->FileNameOffset = sizeof(AFSDirEnumEntry);
497 wname = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->FileNameOffset);
498 wcsncpy(wname, name, len);
499 pCurrentEntry->FileNameLength = (ULONG)(sizeof(WCHAR) * len);
501 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry scp=0x%p fileType=%d",
504 if (!(dwFlags & RDR_POP_NO_GETSTATUS))
505 cm_SyncOpDone( scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
507 if ((dwFlags & RDR_POP_NO_GETSTATUS) || !cm_HaveCallback(scp)) {
508 pCurrentEntry->TargetNameOffset = 0;
509 pCurrentEntry->TargetNameLength = 0;
512 switch (scp->fileType) {
513 case CM_SCACHETYPE_MOUNTPOINT:
514 if (dwFlags & RDR_POP_FOLLOW_MOUNTPOINTS) {
515 if ((code2 = cm_ReadMountPoint(scp, userp, reqp)) == 0) {
516 cm_scache_t *targetScp = NULL;
518 pCurrentEntry->TargetNameOffset = pCurrentEntry->FileNameOffset + pCurrentEntry->FileNameLength;
519 len = strlen(scp->mountPointStringp);
520 wtarget = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->TargetNameOffset);
523 cch = MultiByteToWideChar( CP_UTF8, 0, scp->mountPointStringp,
526 len * sizeof(WCHAR));
528 mbstowcs(wtarget, scp->mountPointStringp, len);
530 pCurrentEntry->TargetNameLength = (ULONG)(sizeof(WCHAR) * len);
532 code2 = cm_FollowMountPoint(scp, dscp, userp, reqp, &targetScp);
535 pCurrentEntry->TargetFileId.Cell = targetScp->fid.cell;
536 pCurrentEntry->TargetFileId.Volume = targetScp->fid.volume;
537 pCurrentEntry->TargetFileId.Vnode = targetScp->fid.vnode;
538 pCurrentEntry->TargetFileId.Unique = targetScp->fid.unique;
539 pCurrentEntry->TargetFileId.Hash = targetScp->fid.hash;
541 osi_Log4(afsd_logp, "RDR_PopulateCurrentEntry target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
542 pCurrentEntry->TargetFileId.Cell, pCurrentEntry->TargetFileId.Volume,
543 pCurrentEntry->TargetFileId.Vnode, pCurrentEntry->TargetFileId.Unique);
545 cm_ReleaseSCache(targetScp);
547 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_FollowMountPoint failed scp=0x%p code=0x%x",
551 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_ReadMountPoint failed scp=0x%p code=0x%x",
556 case CM_SCACHETYPE_SYMLINK:
557 case CM_SCACHETYPE_DFSLINK:
559 pCurrentEntry->TargetNameOffset = pCurrentEntry->FileNameOffset + pCurrentEntry->FileNameLength;
560 wtarget = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->TargetNameOffset);
562 if (dwFlags & RDR_POP_EVALUATE_SYMLINKS) {
565 code2 = cm_HandleLink(scp, userp, reqp);
567 mp = scp->mountPointStringp;
570 /* Strip off the msdfs: prefix from the target name for the file system */
571 if (scp->fileType == CM_SCACHETYPE_DFSLINK) {
572 osi_Log0(afsd_logp, "RDR_PopulateCurrentEntry DFSLink Detected");
573 pCurrentEntry->FileType = scp->fileType;
575 if (!strncmp("msdfs:", mp, 6)) {
580 /* only send one slash to the redirector */
581 if (mp[0] == '\\' && mp[1] == '\\') {
586 cch = MultiByteToWideChar( CP_UTF8, 0, mp,
589 len * sizeof(WCHAR));
591 mbstowcs(wtarget, mp, len);
594 pCurrentEntry->TargetNameLength = (ULONG)(sizeof(WCHAR) * len);
596 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_HandleLink failed scp=0x%p code=0x%x",
605 pCurrentEntry->TargetNameOffset = 0;
606 pCurrentEntry->TargetNameLength = 0;
608 lock_ReleaseWrite(&scp->rw);
610 dwEntryLength += pCurrentEntry->FileNameLength + pCurrentEntry->TargetNameLength;
611 dwEntryLength += (dwEntryLength % 8) ? 8 - (dwEntryLength % 8) : 0; /* quad align */
613 *ppNextEntry = (AFSDirEnumEntry *)((PBYTE)pCurrentEntry + dwEntryLength);
614 if (pdwRemainingLength)
615 *pdwRemainingLength = dwMaxEntryLength - dwEntryLength;
617 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntry Success FileNameLength=%d TargetNameLength=%d RemainingLength=%d",
618 pCurrentEntry->FileNameLength, pCurrentEntry->TargetNameLength, *pdwRemainingLength);
624 RDR_PopulateCurrentEntryNoScp( IN AFSDirEnumEntry * pCurrentEntry,
625 IN DWORD dwMaxEntryLength,
626 IN cm_scache_t * dscp,
628 IN cm_user_t * userp,
631 IN wchar_t * shortName,
633 OUT AFSDirEnumEntry **ppNextEntry,
634 OUT DWORD * pdwRemainingLength)
640 afs_uint32 code = 0, code2 = 0;
642 osi_Log4(afsd_logp, "RDR_PopulateCurrentEntryNoEntry dscp=0x%p name=%S short=%S flags=0x%x",
643 dscp, osi_LogSaveStringW(afsd_logp, name),
644 osi_LogSaveStringW(afsd_logp, shortName), dwFlags);
645 osi_Log1(afsd_logp, "... maxLength=%d", dwMaxEntryLength);
647 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
649 *ppNextEntry = pCurrentEntry;
650 if (pdwRemainingLength)
651 *pdwRemainingLength = dwMaxEntryLength;
652 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntryNoEntry Not Enough Room for Entry %d < %d",
653 dwMaxEntryLength, sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t));
654 return CM_ERROR_TOOBIG;
662 dwEntryLength = sizeof(AFSDirEnumEntry);
664 pCurrentEntry->FileId.Cell = fidp->cell;
665 pCurrentEntry->FileId.Volume = fidp->volume;
666 pCurrentEntry->FileId.Vnode = fidp->vnode;
667 pCurrentEntry->FileId.Unique = fidp->unique;
668 pCurrentEntry->FileId.Hash = fidp->hash;
670 pCurrentEntry->FileType = CM_SCACHETYPE_UNKNOWN;
672 pCurrentEntry->DataVersion.QuadPart = CM_SCACHE_VERSION_BAD;
674 cm_LargeSearchTimeFromUnixTime(&ft, 0);
675 pCurrentEntry->Expiration.LowPart = ft.dwLowDateTime;
676 pCurrentEntry->Expiration.HighPart = ft.dwHighDateTime;
678 cm_LargeSearchTimeFromUnixTime(&ft, 0);
679 pCurrentEntry->CreationTime.LowPart = ft.dwLowDateTime;
680 pCurrentEntry->CreationTime.HighPart = ft.dwHighDateTime;
681 pCurrentEntry->LastAccessTime = pCurrentEntry->CreationTime;
682 pCurrentEntry->LastWriteTime = pCurrentEntry->CreationTime;
683 pCurrentEntry->ChangeTime = pCurrentEntry->CreationTime;
685 pCurrentEntry->EndOfFile.QuadPart = 0;
686 pCurrentEntry->AllocationSize.QuadPart = 0;
687 pCurrentEntry->FileAttributes = 0;
688 pCurrentEntry->EaSize = 0;
689 pCurrentEntry->Links = 0;
691 len = wcslen(shortName);
692 wcsncpy(pCurrentEntry->ShortName, shortName, len);
693 pCurrentEntry->ShortNameLength = (CCHAR)(len * sizeof(WCHAR));
695 pCurrentEntry->FileNameOffset = sizeof(AFSDirEnumEntry);
697 wname = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->FileNameOffset);
698 wcsncpy(wname, name, len);
699 pCurrentEntry->FileNameLength = (ULONG)(sizeof(WCHAR) * len);
701 pCurrentEntry->TargetNameOffset = 0;
702 pCurrentEntry->TargetNameLength = 0;
704 dwEntryLength += pCurrentEntry->FileNameLength + pCurrentEntry->TargetNameLength;
705 dwEntryLength += (dwEntryLength % 8) ? 8 - (dwEntryLength % 8) : 0; /* quad align */
707 *ppNextEntry = (AFSDirEnumEntry *)((PBYTE)pCurrentEntry + dwEntryLength);
708 if (pdwRemainingLength)
709 *pdwRemainingLength = dwMaxEntryLength - dwEntryLength;
711 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntryNoScp Success FileNameLength=%d TargetNameLength=%d RemainingLength=%d",
712 pCurrentEntry->FileNameLength, pCurrentEntry->TargetNameLength, *pdwRemainingLength);
718 RDR_EnumerateDirectory( IN cm_user_t *userp,
720 IN AFSDirQueryCB *QueryCB,
723 IN DWORD ResultBufferLength,
724 IN OUT AFSCommResult **ResultCB)
727 cm_direnum_t * enump = NULL;
728 AFSDirEnumResp * pDirEnumResp;
729 AFSDirEnumEntry * pCurrentEntry;
730 size_t size = ResultBufferLength ? sizeof(AFSCommResult) + ResultBufferLength - 1 : sizeof(AFSCommResult);
731 DWORD dwMaxEntryLength;
734 cm_scache_t * dscp = NULL;
739 req.flags |= CM_REQ_WOW64;
741 osi_Log4(afsd_logp, "RDR_EnumerateDirectory FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
742 DirID.Cell, DirID.Volume, DirID.Vnode, DirID.Unique);
744 *ResultCB = (AFSCommResult *)malloc(size);
746 osi_Log0(afsd_logp, "RDR_EnumerateDirectory Out of Memory");
750 memset(*ResultCB, 0, size);
752 if (QueryCB->EnumHandle == (ULONG_PTR)-1) {
753 osi_Log0(afsd_logp, "RDR_EnumerateDirectory No More Entries");
754 (*ResultCB)->ResultStatus = STATUS_NO_MORE_ENTRIES;
755 (*ResultCB)->ResultBufferLength = 0;
759 (*ResultCB)->ResultBufferLength = dwMaxEntryLength = ResultBufferLength;
760 if (ResultBufferLength) {
761 pDirEnumResp = (AFSDirEnumResp *)&(*ResultCB)->ResultData;
762 pCurrentEntry = (AFSDirEnumEntry *)&pDirEnumResp->Entry;
763 dwMaxEntryLength -= FIELD_OFFSET( AFSDirEnumResp, Entry); /* AFSDirEnumResp */
766 if (DirID.Cell != 0) {
767 fid.cell = DirID.Cell;
768 fid.volume = DirID.Volume;
769 fid.vnode = DirID.Vnode;
770 fid.unique = DirID.Unique;
771 fid.hash = DirID.Hash;
773 code = cm_GetSCache(&fid, &dscp, userp, &req);
775 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
776 (*ResultCB)->ResultStatus = status;
777 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_GetSCache failure code=0x%x status=0x%x",
782 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
783 osi_Log0(afsd_logp, "RDR_EnumerateDirectory Object Name Invalid - Cell = 0");
787 /* get the directory size */
788 lock_ObtainWrite(&dscp->rw);
789 code = cm_SyncOp(dscp, NULL, userp, &req, PRSFS_LOOKUP,
790 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
792 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
793 (*ResultCB)->ResultStatus = status;
794 lock_ReleaseWrite(&dscp->rw);
795 cm_ReleaseSCache(dscp);
796 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_SyncOp failure code=0x%x status=0x%x",
801 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
802 lock_ReleaseWrite(&dscp->rw);
804 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
805 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
806 cm_ReleaseSCache(dscp);
807 osi_Log1(afsd_logp, "RDR_EnumerateDirectory Not a Directory dscp=0x%p",
813 * If there is no enumeration handle, then this is a new query
814 * and we must perform an enumeration for the specified object
816 if (QueryCB->EnumHandle == (ULONG_PTR)NULL) {
819 code = cm_BeginDirOp(dscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
821 code = cm_BPlusDirEnumerate(dscp, userp, &req, TRUE, NULL, !bSkipStatus, &enump);
823 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BPlusDirEnumerate failure code=0x%x",
828 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BeginDirOp failure code=0x%x",
832 enump = (cm_direnum_t *)QueryCB->EnumHandle;
835 if (enump && ResultBufferLength) {
836 cm_direnum_entry_t * entryp = NULL;
839 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
840 osi_Log0(afsd_logp, "RDR_EnumerateDirectory out of space, returning");
844 code = cm_BPlusDirNextEnumEntry(enump, &entryp);
846 if ((code == 0 || code == CM_ERROR_STOPNOW) && entryp) {
848 int stopnow = (code == CM_ERROR_STOPNOW);
850 if ( !wcscmp(L".", entryp->name) || !wcscmp(L"..", entryp->name) ) {
851 osi_Log0(afsd_logp, "RDR_EnumerateDirectory skipping . or ..");
857 if ( FALSE /* bSkipStatus */) {
858 scp = cm_FindSCache(&entryp->fid);
861 code = cm_GetSCache(&entryp->fid, &scp, userp, &req);
866 code = RDR_PopulateCurrentEntry(pCurrentEntry, dwMaxEntryLength,
867 dscp, scp, userp, &req,
869 cm_Is8Dot3(entryp->name) ? NULL : entryp->shortName,
870 (bWow64 ? RDR_POP_WOW64 : 0) |
871 (bSkipStatus ? RDR_POP_NO_GETSTATUS : 0),
872 &pCurrentEntry, &dwMaxEntryLength);
873 cm_ReleaseSCache(scp);
875 code = RDR_PopulateCurrentEntryNoScp( pCurrentEntry, dwMaxEntryLength,
876 dscp, &entryp->fid, userp, &req,
878 cm_Is8Dot3(entryp->name) ? NULL : entryp->shortName,
879 (bWow64 ? RDR_POP_WOW64 : 0),
880 &pCurrentEntry, &dwMaxEntryLength);
886 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_GetSCache failure scp=0x%p code=0x%x",
895 if (enump && ResultBufferLength == 0) {
896 code = cm_BPlusDirEnumBulkStat(enump);
898 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BPlusDirEnumBulkStat failure code=0x%x",
904 if (code || enump->next == enump->count || ResultBufferLength == 0) {
905 cm_BPlusDirFreeEnumeration(enump);
906 enump = (cm_direnum_t *)(ULONG_PTR)-1;
909 if (code == 0 || code == CM_ERROR_STOPNOW) {
910 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
911 osi_Log0(afsd_logp, "RDR_EnumerateDirectory SUCCESS");
913 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
914 (*ResultCB)->ResultStatus = status;
915 osi_Log2(afsd_logp, "RDR_EnumerateDirectory Failure code=0x%x status=0x%x",
919 if (ResultBufferLength) {
920 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwMaxEntryLength;
922 pDirEnumResp->EnumHandle = (ULONG_PTR) enump;
926 cm_ReleaseSCache(dscp);
932 RDR_EvaluateNodeByName( IN cm_user_t *userp,
933 IN AFSFileID ParentID,
934 IN WCHAR *FileNameCounted,
935 IN DWORD FileNameLength,
936 IN BOOL CaseSensitive,
940 IN DWORD ResultBufferLength,
941 IN OUT AFSCommResult **ResultCB)
943 AFSDirEnumEntry * pCurrentEntry;
944 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
946 cm_scache_t * scp = NULL;
947 cm_scache_t * dscp = NULL;
952 WCHAR * wszName = NULL;
955 wchar_t FileName[260];
957 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
961 req.flags |= CM_REQ_WOW64;
963 osi_Log4(afsd_logp, "RDR_EvaluateNodeByName parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
964 ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
966 /* Allocate enough room to add a volume prefix if necessary */
967 cbName = FileNameLength + (CM_PREFIX_VOL_CCH + 1) * sizeof(WCHAR);
968 wszName = malloc(cbName);
970 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Out of Memory");
973 StringCbCopyNW(wszName, cbName, FileName, FileNameLength);
974 osi_Log1(afsd_logp, "... name=%S", osi_LogSaveStringW(afsd_logp, wszName));
976 *ResultCB = (AFSCommResult *)malloc(size);
978 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Out of Memory");
983 memset(*ResultCB, 0, size);
984 (*ResultCB)->ResultBufferLength = ResultBufferLength;
985 if (ResultBufferLength)
986 pCurrentEntry = (AFSDirEnumEntry *)&(*ResultCB)->ResultData;
988 if (ParentID.Cell != 0) {
989 parentFid.cell = ParentID.Cell;
990 parentFid.volume = ParentID.Volume;
991 parentFid.vnode = ParentID.Vnode;
992 parentFid.unique = ParentID.Unique;
993 parentFid.hash = ParentID.Hash;
995 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
997 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
998 (*ResultCB)->ResultStatus = status;
999 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName cm_GetSCache parentFID failure code=0x%x status=0x%x",
1005 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
1006 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Object Name Invalid - Cell = 0");
1010 /* get the directory size */
1011 lock_ObtainWrite(&dscp->rw);
1012 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1013 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1015 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1016 (*ResultCB)->ResultStatus = status;
1017 lock_ReleaseWrite(&dscp->rw);
1018 cm_ReleaseSCache(dscp);
1019 osi_Log3(afsd_logp, "RDR_EvaluateNodeByName cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1020 dscp, code, status);
1024 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1025 lock_ReleaseWrite(&dscp->rw);
1027 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1028 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1029 cm_ReleaseSCache(dscp);
1030 osi_Log1(afsd_logp, "RDR_EvaluateNodeByName Not a Directory dscp=0x%p",
1036 code = cm_Lookup(dscp, wszName, CM_FLAG_CHECKPATH, userp, &req, &scp);
1038 if ((code == CM_ERROR_NOSUCHPATH || code == CM_ERROR_NOSUCHFILE || code == CM_ERROR_BPLUS_NOMATCH) &&
1039 (wcschr(wszName, '%') != NULL || wcschr(wszName, '#') != NULL)) {
1041 * A volume reference: <cell>{%,#}<volume> -> @vol:<cell>{%,#}<volume>
1043 StringCchCopyNW(wszName, cbName, _C(CM_PREFIX_VOL), CM_PREFIX_VOL_CCH);
1044 StringCbCatNW(wszName, cbName, FileName, FileNameLength);
1045 cm_strlwr_utf16(wszName);
1048 code = cm_EvaluateVolumeReference(wszName, CM_FLAG_CHECKPATH, userp, &req, &scp);
1051 if (code == 0 && scp) {
1052 wchar_t shortName[13]=L"";
1055 cm_Gen8Dot3VolNameW(scp->fid.cell, scp->fid.volume, shortName, NULL);
1056 } else if (!cm_Is8Dot3(wszName)) {
1059 dfid.vnode = htonl(scp->fid.vnode);
1060 dfid.unique = htonl(scp->fid.unique);
1062 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1064 shortName[0] = '\0';
1067 code = RDR_PopulateCurrentEntry(pCurrentEntry, ResultBufferLength,
1068 dscp, scp, userp, &req,
1069 FileName, shortName,
1070 (bWow64 ? RDR_POP_WOW64 : 0) |
1071 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1072 NULL, &dwRemaining);
1074 RDR_FlagScpInUse( scp, FALSE );
1075 cm_ReleaseSCache(scp);
1078 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1079 (*ResultCB)->ResultStatus = status;
1080 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1083 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1084 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1085 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName SUCCESS");
1088 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1089 (*ResultCB)->ResultStatus = status;
1090 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1093 (*ResultCB)->ResultStatus = STATUS_NO_SUCH_FILE;
1094 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName No Such File");
1096 cm_ReleaseSCache(dscp);
1103 RDR_EvaluateNodeByID( IN cm_user_t *userp,
1104 IN AFSFileID ParentID, /* not used */
1105 IN AFSFileID SourceID,
1109 IN DWORD ResultBufferLength,
1110 IN OUT AFSCommResult **ResultCB)
1112 AFSDirEnumEntry * pCurrentEntry;
1113 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1114 afs_uint32 code = 0;
1115 cm_scache_t * scp = NULL;
1116 cm_scache_t * dscp = NULL;
1123 osi_Log4(afsd_logp, "RDR_EvaluateNodeByID source FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1124 SourceID.Cell, SourceID.Volume, SourceID.Vnode, SourceID.Unique);
1125 osi_Log4(afsd_logp, "... parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1126 ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1128 *ResultCB = (AFSCommResult *)malloc(size);
1130 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Out of Memory");
1134 memset(*ResultCB, 0, size);
1135 (*ResultCB)->ResultBufferLength = ResultBufferLength;
1136 dwRemaining = ResultBufferLength;
1137 if (ResultBufferLength)
1138 pCurrentEntry = (AFSDirEnumEntry *)&(*ResultCB)->ResultData;
1142 req.flags |= CM_REQ_WOW64;
1144 if (SourceID.Cell != 0) {
1145 Fid.cell = SourceID.Cell;
1146 Fid.volume = SourceID.Volume;
1147 Fid.vnode = SourceID.Vnode;
1148 Fid.unique = SourceID.Unique;
1149 Fid.hash = SourceID.Hash;
1151 code = cm_GetSCache(&Fid, &scp, userp, &req);
1153 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1154 (*ResultCB)->ResultStatus = status;
1155 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache SourceFID failure code=0x%x status=0x%x",
1160 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
1161 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Name Invalid - Cell = 0");
1165 if (ParentID.Cell != 0) {
1166 cm_SetFid(&parentFid, ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1167 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1169 cm_ReleaseSCache(scp);
1170 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1171 (*ResultCB)->ResultStatus = status;
1172 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1176 } else if (SourceID.Vnode == 1) {
1178 cm_HoldSCache(dscp);
1179 } else if (scp->parentVnode) {
1180 cm_SetFid(&parentFid, SourceID.Cell, SourceID.Volume, scp->parentVnode, scp->parentUnique);
1181 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1183 cm_ReleaseSCache(scp);
1184 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1185 (*ResultCB)->ResultStatus = status;
1186 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1191 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
1192 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Path Invalid - Unknown Parent");
1196 /* Make sure the directory is current */
1197 lock_ObtainWrite(&dscp->rw);
1198 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1199 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1201 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1202 (*ResultCB)->ResultStatus = status;
1203 lock_ReleaseWrite(&dscp->rw);
1204 cm_ReleaseSCache(dscp);
1205 cm_ReleaseSCache(scp);
1206 osi_Log3(afsd_logp, "RDR_EvaluateNodeByID cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1207 dscp, code, status);
1211 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1212 lock_ReleaseWrite(&dscp->rw);
1214 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1215 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1216 cm_ReleaseSCache(dscp);
1217 cm_ReleaseSCache(scp);
1218 osi_Log1(afsd_logp, "RDR_EvaluateNodeByID Not a Directory dscp=0x%p", dscp);
1222 code = RDR_PopulateCurrentEntry(pCurrentEntry, ResultBufferLength,
1223 dscp, scp, userp, &req, NULL, NULL,
1224 (bWow64 ? RDR_POP_WOW64 : 0) |
1225 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1226 NULL, &dwRemaining);
1229 RDR_FlagScpInUse( scp, FALSE );
1230 cm_ReleaseSCache(scp);
1231 cm_ReleaseSCache(dscp);
1234 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1235 (*ResultCB)->ResultStatus = status;
1236 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID FAILURE code=0x%x status=0x%x",
1239 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1240 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1241 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID SUCCESS");
1247 RDR_CreateFileEntry( IN cm_user_t *userp,
1248 IN WCHAR *FileNameCounted,
1249 IN DWORD FileNameLength,
1250 IN AFSFileCreateCB *CreateCB,
1253 IN DWORD ResultBufferLength,
1254 IN OUT AFSCommResult **ResultCB)
1256 AFSFileCreateResultCB *pResultCB = NULL;
1257 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1260 cm_scache_t * dscp = NULL;
1261 afs_uint32 flags = 0;
1263 cm_scache_t * scp = NULL;
1266 wchar_t FileName[260];
1268 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1270 osi_Log4(afsd_logp, "RDR_CreateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1271 CreateCB->ParentId.Cell, CreateCB->ParentId.Volume,
1272 CreateCB->ParentId.Vnode, CreateCB->ParentId.Unique);
1273 osi_Log1(afsd_logp, "... name=%S", osi_LogSaveStringW(afsd_logp, FileName));
1277 req.flags |= CM_REQ_WOW64;
1278 memset(&setAttr, 0, sizeof(cm_attr_t));
1280 *ResultCB = (AFSCommResult *)malloc(size);
1282 osi_Log0(afsd_logp, "RDR_CreateFileEntry out of memory");
1290 parentFid.cell = CreateCB->ParentId.Cell;
1291 parentFid.volume = CreateCB->ParentId.Volume;
1292 parentFid.vnode = CreateCB->ParentId.Vnode;
1293 parentFid.unique = CreateCB->ParentId.Unique;
1294 parentFid.hash = CreateCB->ParentId.Hash;
1296 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1298 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1299 (*ResultCB)->ResultStatus = status;
1300 osi_Log2(afsd_logp, "RDR_CreateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1305 lock_ObtainWrite(&dscp->rw);
1306 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1307 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1309 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1310 (*ResultCB)->ResultStatus = status;
1311 lock_ReleaseWrite(&dscp->rw);
1312 cm_ReleaseSCache(dscp);
1313 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (1) dscp=0x%p code=0x%x status=0x%x",
1314 dscp, code, status);
1318 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1319 lock_ReleaseWrite(&dscp->rw);
1321 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1322 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1323 cm_ReleaseSCache(dscp);
1324 osi_Log1(afsd_logp, "RDR_CreateFileEntry Not a Directory dscp=0x%p",
1329 /* Use current time */
1330 setAttr.mask = CM_ATTRMASK_CLIENTMODTIME;
1331 setAttr.clientModTime = time(NULL);
1333 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1334 if (smb_unixModeDefaultDir) {
1335 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1336 setAttr.unixModeBits = smb_unixModeDefaultDir;
1337 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1338 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1341 code = cm_MakeDir(dscp, FileName, flags, &setAttr, userp, &req, &scp);
1343 if (smb_unixModeDefaultFile) {
1344 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1345 setAttr.unixModeBits = smb_unixModeDefaultFile;
1346 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1347 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1350 setAttr.mask |= CM_ATTRMASK_LENGTH;
1351 setAttr.length.LowPart = CreateCB->AllocationSize.LowPart;
1352 setAttr.length.HighPart = CreateCB->AllocationSize.HighPart;
1353 code = cm_Create(dscp, FileName, flags, &setAttr, &scp, userp, &req);
1356 wchar_t shortName[13]=L"";
1360 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
1362 (*ResultCB)->ResultBufferLength = sizeof( AFSFileCreateResultCB);
1364 pResultCB = (AFSFileCreateResultCB *)(*ResultCB)->ResultData;
1366 dwRemaining = ResultBufferLength - sizeof( AFSFileCreateResultCB) + sizeof( AFSDirEnumEntry);
1368 lock_ObtainWrite(&dscp->rw);
1369 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1370 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1372 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1373 (*ResultCB)->ResultStatus = status;
1374 lock_ReleaseWrite(&dscp->rw);
1375 cm_ReleaseSCache(dscp);
1376 cm_ReleaseSCache(scp);
1377 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (2) dscp=0x%p code=0x%x status=0x%x",
1378 dscp, code, status);
1382 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1384 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1385 lock_ReleaseWrite(&dscp->rw);
1387 dfid.vnode = htonl(scp->fid.vnode);
1388 dfid.unique = htonl(scp->fid.unique);
1390 if (!cm_Is8Dot3(FileName))
1391 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1393 shortName[0] = '\0';
1395 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1396 dscp, scp, userp, &req, FileName, shortName,
1397 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1398 NULL, &dwRemaining);
1401 RDR_FlagScpInUse( scp, FALSE );
1402 cm_ReleaseSCache(scp);
1403 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1404 osi_Log0(afsd_logp, "RDR_CreateFileEntry SUCCESS");
1406 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1407 (*ResultCB)->ResultStatus = status;
1408 (*ResultCB)->ResultBufferLength = 0;
1409 osi_Log2(afsd_logp, "RDR_CreateFileEntry FAILURE code=0x%x status=0x%x",
1413 cm_ReleaseSCache(dscp);
1419 RDR_UpdateFileEntry( IN cm_user_t *userp,
1420 IN AFSFileID FileId,
1421 IN AFSFileUpdateCB *UpdateCB,
1423 IN DWORD ResultBufferLength,
1424 IN OUT AFSCommResult **ResultCB)
1426 AFSFileUpdateResultCB *pResultCB = NULL;
1427 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1431 afs_uint32 flags = 0;
1433 cm_scache_t * scp = NULL;
1434 cm_scache_t * dscp = NULL;
1436 time_t clientModTime;
1439 BOOL bScpLocked = FALSE;
1443 req.flags |= CM_REQ_WOW64;
1444 memset(&setAttr, 0, sizeof(cm_attr_t));
1446 osi_Log4(afsd_logp, "RDR_UpdateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1447 UpdateCB->ParentId.Cell, UpdateCB->ParentId.Volume,
1448 UpdateCB->ParentId.Vnode, UpdateCB->ParentId.Unique);
1449 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1450 FileId.Cell, FileId.Volume,
1451 FileId.Vnode, FileId.Unique);
1453 *ResultCB = (AFSCommResult *)malloc( size);
1455 osi_Log0(afsd_logp, "RDR_UpdateFileEntry Out of Memory");
1463 parentFid.cell = UpdateCB->ParentId.Cell;
1464 parentFid.volume = UpdateCB->ParentId.Volume;
1465 parentFid.vnode = UpdateCB->ParentId.Vnode;
1466 parentFid.unique = UpdateCB->ParentId.Unique;
1467 parentFid.hash = UpdateCB->ParentId.Hash;
1469 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1471 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1472 (*ResultCB)->ResultStatus = status;
1473 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1478 lock_ObtainWrite(&dscp->rw);
1480 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1481 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1483 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1484 (*ResultCB)->ResultStatus = status;
1485 lock_ReleaseWrite(&dscp->rw);
1486 cm_ReleaseSCache(dscp);
1487 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1488 dscp, code, status);
1492 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1493 lock_ReleaseWrite(&dscp->rw);
1496 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1497 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1498 cm_ReleaseSCache(dscp);
1499 osi_Log1(afsd_logp, "RDR_UpdateFileEntry Not a Directory dscp=0x%p",
1504 Fid.cell = FileId.Cell;
1505 Fid.volume = FileId.Volume;
1506 Fid.vnode = FileId.Vnode;
1507 Fid.unique = FileId.Unique;
1508 Fid.hash = FileId.Hash;
1510 code = cm_GetSCache(&Fid, &scp, userp, &req);
1512 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1513 (*ResultCB)->ResultStatus = status;
1514 cm_ReleaseSCache(dscp);
1515 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache object FID failure code=0x%x status=0x%x",
1520 lock_ObtainWrite(&scp->rw);
1522 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1523 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1525 lock_ReleaseWrite(&scp->rw);
1526 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1527 (*ResultCB)->ResultStatus = status;
1528 (*ResultCB)->ResultBufferLength = 0;
1529 cm_ReleaseSCache(dscp);
1530 cm_ReleaseSCache(scp);
1531 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
1535 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1537 if (UpdateCB->ChangeTime.QuadPart) {
1539 if (scp->fileType == CM_SCACHETYPE_FILE) {
1540 /* Do not set length and other attributes at the same time */
1541 if (scp->length.QuadPart != UpdateCB->AllocationSize.QuadPart) {
1542 osi_Log2(afsd_logp, "RDR_UpdateFileEntry Length Change 0x%x -> 0x%x",
1543 (afs_uint32)scp->length.QuadPart, (afs_uint32)UpdateCB->AllocationSize.QuadPart);
1544 setAttr.mask |= CM_ATTRMASK_LENGTH;
1545 setAttr.length.LowPart = UpdateCB->AllocationSize.LowPart;
1546 setAttr.length.HighPart = UpdateCB->AllocationSize.HighPart;
1547 lock_ReleaseWrite(&scp->rw);
1549 code = cm_SetAttr(scp, &setAttr, userp, &req);
1557 lock_ObtainWrite(&scp->rw);
1560 if ((scp->unixModeBits & 0200) && (UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1561 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1562 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1563 } else if (!(scp->unixModeBits & 0200) && !(UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1564 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1565 setAttr.unixModeBits = scp->unixModeBits | 0222;
1569 if (UpdateCB->LastWriteTime.QuadPart) {
1570 ft.dwLowDateTime = UpdateCB->LastWriteTime.LowPart;
1571 ft.dwHighDateTime = UpdateCB->LastWriteTime.HighPart;
1573 cm_UnixTimeFromLargeSearchTime(& clientModTime, &ft);
1576 lock_ObtainWrite(&scp->rw);
1579 if (scp->clientModTime != clientModTime) {
1580 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1581 setAttr.clientModTime = clientModTime;
1586 lock_ReleaseWrite(&scp->rw);
1588 code = cm_SetAttr(scp, &setAttr, userp, &req);
1595 lock_ReleaseWrite(&scp->rw);
1599 DWORD dwRemaining = ResultBufferLength - sizeof( AFSFileUpdateResultCB) + sizeof( AFSDirEnumEntry);
1601 pResultCB = (AFSFileUpdateResultCB *)(*ResultCB)->ResultData;
1603 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1604 dscp, scp, userp, &req, NULL, NULL,
1605 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1606 NULL, &dwRemaining);
1607 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1608 osi_Log0(afsd_logp, "RDR_UpdateFileEntry SUCCESS");
1610 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1611 (*ResultCB)->ResultStatus = status;
1612 (*ResultCB)->ResultBufferLength = 0;
1613 osi_Log2(afsd_logp, "RDR_UpdateFileEntry FAILURE code=0x%x status=0x%x",
1616 cm_ReleaseSCache(scp);
1617 cm_ReleaseSCache(dscp);
1623 RDR_CleanupFileEntry( IN cm_user_t *userp,
1624 IN AFSFileID FileId,
1625 IN WCHAR *FileNameCounted,
1626 IN DWORD FileNameLength,
1627 IN AFSFileCleanupCB *CleanupCB,
1629 IN BOOL bLastHandle,
1630 IN BOOL bDeleteFile,
1631 IN BOOL bUnlockFile,
1632 IN DWORD ResultBufferLength,
1633 IN OUT AFSCommResult **ResultCB)
1635 size_t size = sizeof(AFSCommResult);
1638 afs_uint32 code = 0;
1639 afs_uint32 flags = 0;
1641 cm_scache_t * scp = NULL;
1642 cm_scache_t * dscp = NULL;
1644 time_t clientModTime;
1647 BOOL bScpLocked = FALSE;
1648 BOOL bDscpLocked = FALSE;
1649 BOOL bFlushFile = FALSE;
1654 req.flags |= CM_REQ_WOW64;
1655 memset(&setAttr, 0, sizeof(cm_attr_t));
1657 osi_Log4(afsd_logp, "RDR_CleanupFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1658 CleanupCB->ParentId.Cell, CleanupCB->ParentId.Volume,
1659 CleanupCB->ParentId.Vnode, CleanupCB->ParentId.Unique);
1660 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1661 FileId.Cell, FileId.Volume,
1662 FileId.Vnode, FileId.Unique);
1664 *ResultCB = (AFSCommResult *)malloc( size);
1666 osi_Log0(afsd_logp, "RDR_CleanupFileEntry Out of Memory");
1674 parentFid.cell = CleanupCB->ParentId.Cell;
1675 parentFid.volume = CleanupCB->ParentId.Volume;
1676 parentFid.vnode = CleanupCB->ParentId.Vnode;
1677 parentFid.unique = CleanupCB->ParentId.Unique;
1678 parentFid.hash = CleanupCB->ParentId.Hash;
1680 if (parentFid.cell) {
1681 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1683 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1684 (*ResultCB)->ResultStatus = status;
1685 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1690 lock_ObtainWrite(&dscp->rw);
1692 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1693 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1695 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure dscp=0x%p code=0x%x",
1701 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1702 lock_ReleaseWrite(&dscp->rw);
1703 bDscpLocked = FALSE;
1705 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1706 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1707 cm_ReleaseSCache(dscp);
1708 osi_Log1(afsd_logp, "RDR_CleanupFileEntry Not a Directory dscp=0x%p",
1715 Fid.cell = FileId.Cell;
1716 Fid.volume = FileId.Volume;
1717 Fid.vnode = FileId.Vnode;
1718 Fid.unique = FileId.Unique;
1719 Fid.hash = FileId.Hash;
1721 code = cm_GetSCache(&Fid, &scp, userp, &req);
1723 osi_Log1(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache object FID failure code=0x%x",
1728 lock_ObtainWrite(&scp->rw);
1730 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1731 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1733 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure scp=0x%p code=0x%x",
1737 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1739 if ((bLastHandle || bFlushFile) &&
1740 scp->redirBufCount > 0)
1742 LARGE_INTEGER heldExtents;
1743 AFSFileExtentCB extentList[1024];
1744 DWORD extentCount = 0;
1749 heldExtents.QuadPart = 0;
1751 for ( srbp = redirq_to_cm_buf_t(scp->redirQueueT);
1753 srbp = redirq_to_cm_buf_t(osi_QPrev(&srbp->redirq)))
1755 extentList[extentCount].Flags = 0;
1756 extentList[extentCount].Length = cm_data.blockSize;
1757 extentList[extentCount].FileOffset.QuadPart = srbp->offset.QuadPart;
1758 extentList[extentCount].CacheOffset.QuadPart = srbp->datap - RDR_extentBaseAddress;
1759 lock_ObtainWrite(&buf_globalLock);
1760 srbp->redirReleaseRequested = now;
1761 lock_ReleaseWrite(&buf_globalLock);
1764 if (extentCount == 1024) {
1765 lock_ReleaseWrite(&scp->rw);
1766 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1768 if (code == CM_ERROR_RETRY) {
1770 * The redirector either is not holding the extents or cannot let them
1771 * go because they are otherwise in use. At the moment, do nothing.
1778 lock_ObtainWrite(&scp->rw);
1782 if (code == 0 && extentCount > 0) {
1784 lock_ReleaseWrite(&scp->rw);
1787 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1792 /* No longer in use by redirector */
1794 lock_ObtainWrite(&scp->rw);
1799 lock_AssertWrite(&scp->rw);
1800 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
1803 if (bLastHandle || bFlushFile) {
1805 lock_ObtainWrite(&scp->rw);
1808 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
1809 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1812 lock_ReleaseWrite(&scp->rw);
1816 code = cm_FSync(scp, userp, &req, bScpLocked);
1818 if (bLastHandle && code)
1822 if (bUnlockFile || bDeleteFile) {
1824 lock_ObtainWrite(&scp->rw);
1827 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1828 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1830 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp (2) failure scp=0x%p code=0x%x",
1835 key = cm_GenerateKey(CM_SESSION_IFS, CleanupCB->ProcessId, 0);
1837 /* the scp is now locked and current */
1838 code = cm_UnlockByKey(scp, key,
1839 bDeleteFile ? CM_UNLOCK_FLAG_BY_FID : 0,
1842 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1848 if (CleanupCB->ChangeTime.QuadPart) {
1850 if (scp->fileType == CM_SCACHETYPE_FILE) {
1851 /* Do not set length and other attributes at the same time */
1852 if (scp->length.QuadPart != CleanupCB->AllocationSize.QuadPart) {
1853 osi_Log2(afsd_logp, "RDR_CleanupFileEntry Length Change 0x%x -> 0x%x",
1854 (afs_uint32)scp->length.QuadPart, (afs_uint32)CleanupCB->AllocationSize.QuadPart);
1855 setAttr.mask |= CM_ATTRMASK_LENGTH;
1856 setAttr.length.LowPart = CleanupCB->AllocationSize.LowPart;
1857 setAttr.length.HighPart = CleanupCB->AllocationSize.HighPart;
1860 lock_ReleaseWrite(&scp->rw);
1863 code = cm_SetAttr(scp, &setAttr, userp, &req);
1871 lock_ObtainWrite(&scp->rw);
1875 if ((scp->unixModeBits & 0200) && (CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1876 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1877 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1878 } else if (!(scp->unixModeBits & 0200) && !(CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1879 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1880 setAttr.unixModeBits = scp->unixModeBits | 0222;
1884 if (CleanupCB->LastWriteTime.QuadPart) {
1885 ft.dwLowDateTime = CleanupCB->LastWriteTime.LowPart;
1886 ft.dwHighDateTime = CleanupCB->LastWriteTime.HighPart;
1888 cm_UnixTimeFromLargeSearchTime(&clientModTime, &ft);
1889 if (scp->clientModTime != clientModTime) {
1890 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1891 setAttr.clientModTime = clientModTime;
1897 lock_ReleaseWrite(&scp->rw);
1899 code = cm_SetAttr(scp, &setAttr, userp, &req);
1903 /* Now drop the lock enforcing the share access */
1904 if ( CleanupCB->FileAccess != AFS_FILE_ACCESS_NOLOCK) {
1905 unsigned int sLockType;
1906 LARGE_INTEGER LOffset, LLength;
1908 if (CleanupCB->FileAccess == AFS_FILE_ACCESS_SHARED)
1909 sLockType = LOCKING_ANDX_SHARED_LOCK;
1913 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, CleanupCB->Identifier);
1915 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
1916 LOffset.LowPart = SMB_FID_QLOCK_LOW;
1917 LLength.HighPart = 0;
1918 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
1921 lock_ObtainWrite(&scp->rw);
1925 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
1928 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
1930 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
1932 if (code == CM_ERROR_RANGE_NOT_LOCKED)
1934 osi_Log3(afsd_logp, "RDR_CleanupFileEntry Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
1935 CleanupCB->FileAccess, CleanupCB->ProcessId, CleanupCB->Identifier);
1943 lock_ReleaseWrite(&dscp->rw);
1945 lock_ReleaseWrite(&scp->rw);
1947 if (dscp && bDeleteFile) {
1948 WCHAR FileName[260];
1950 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1952 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
1953 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
1955 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
1959 (*ResultCB)->ResultStatus = 0;
1960 (*ResultCB)->ResultBufferLength = 0;
1961 osi_Log0(afsd_logp, "RDR_CleanupFileEntry SUCCESS");
1963 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1964 (*ResultCB)->ResultStatus = status;
1965 (*ResultCB)->ResultBufferLength = 0;
1966 osi_Log2(afsd_logp, "RDR_CleanupFileEntry FAILURE code=0x%x status=0x%x",
1970 cm_ReleaseSCache(scp);
1972 cm_ReleaseSCache(dscp);
1978 RDR_DeleteFileEntry( IN cm_user_t *userp,
1979 IN AFSFileID ParentId,
1980 IN ULONGLONG ProcessId,
1981 IN WCHAR *FileNameCounted,
1982 IN DWORD FileNameLength,
1985 IN DWORD ResultBufferLength,
1986 IN OUT AFSCommResult **ResultCB)
1989 AFSFileDeleteResultCB *pResultCB = NULL;
1990 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1993 cm_scache_t * dscp = NULL;
1994 cm_scache_t * scp = NULL;
1995 afs_uint32 flags = 0;
1999 wchar_t FileName[260];
2002 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
2004 osi_Log4(afsd_logp, "RDR_DeleteFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2005 ParentId.Cell, ParentId.Volume,
2006 ParentId.Vnode, ParentId.Unique);
2007 osi_Log2(afsd_logp, "... name=%S checkOnly=%x",
2008 osi_LogSaveStringW(afsd_logp, FileName),
2013 req.flags |= CM_REQ_WOW64;
2014 memset(&setAttr, 0, sizeof(cm_attr_t));
2016 *ResultCB = (AFSCommResult *)malloc( size);
2018 osi_Log0(afsd_logp, "RDR_DeleteFileEntry out of memory");
2026 parentFid.cell = ParentId.Cell;
2027 parentFid.volume = ParentId.Volume;
2028 parentFid.vnode = ParentId.Vnode;
2029 parentFid.unique = ParentId.Unique;
2030 parentFid.hash = ParentId.Hash;
2032 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
2034 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2035 (*ResultCB)->ResultStatus = status;
2036 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
2041 lock_ObtainWrite(&dscp->rw);
2043 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
2044 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2046 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2047 (*ResultCB)->ResultStatus = status;
2048 (*ResultCB)->ResultBufferLength = 0;
2049 lock_ReleaseWrite(&dscp->rw);
2050 cm_ReleaseSCache(dscp);
2051 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
2052 dscp, code, status);
2056 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2057 lock_ReleaseWrite(&dscp->rw);
2059 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2060 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2061 cm_ReleaseSCache(dscp);
2062 osi_Log1(afsd_logp, "RDR_DeleteFileEntry Not a Directory dscp=0x%p",
2067 code = cm_Lookup(dscp, FileName, 0, userp, &req, &scp);
2069 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2070 (*ResultCB)->ResultStatus = status;
2071 (*ResultCB)->ResultBufferLength = 0;
2072 cm_ReleaseSCache(dscp);
2073 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_Lookup failure code=0x%x status=0x%x",
2078 lock_ObtainWrite(&scp->rw);
2079 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_DELETE,
2080 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2082 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2083 (*ResultCB)->ResultStatus = status;
2084 (*ResultCB)->ResultBufferLength = 0;
2085 lock_ReleaseWrite(&scp->rw);
2086 cm_ReleaseSCache(scp);
2087 cm_ReleaseSCache(dscp);
2088 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2094 /* Drop all locks since the file is being deleted */
2095 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2096 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2098 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2099 (*ResultCB)->ResultStatus = status;
2100 (*ResultCB)->ResultBufferLength = 0;
2101 lock_ReleaseWrite(&scp->rw);
2102 cm_ReleaseSCache(scp);
2103 cm_ReleaseSCache(dscp);
2104 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp Lock failure scp=0x%p code=0x%x status=0x%x",
2108 /* the scp is now locked and current */
2109 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId, 0);
2111 code = cm_UnlockByKey(scp, key,
2112 CM_UNLOCK_FLAG_BY_FID,
2115 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2116 lock_ReleaseWrite(&scp->rw);
2118 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
2119 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
2121 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2123 lock_ReleaseWrite(&scp->rw);
2127 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
2129 (*ResultCB)->ResultBufferLength = sizeof( AFSFileDeleteResultCB);
2131 pResultCB = (AFSFileDeleteResultCB *)(*ResultCB)->ResultData;
2133 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
2134 osi_Log0(afsd_logp, "RDR_DeleteFileEntry SUCCESS");
2136 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2137 (*ResultCB)->ResultStatus = status;
2138 (*ResultCB)->ResultBufferLength = 0;
2139 osi_Log2(afsd_logp, "RDR_DeleteFileEntry FAILURE code=0x%x status=0x%x",
2143 cm_ReleaseSCache(dscp);
2144 cm_ReleaseSCache(scp);
2150 RDR_RenameFileEntry( IN cm_user_t *userp,
2151 IN WCHAR *SourceFileNameCounted,
2152 IN DWORD SourceFileNameLength,
2153 IN AFSFileID SourceFileId,
2154 IN AFSFileRenameCB *pRenameCB,
2156 IN DWORD ResultBufferLength,
2157 IN OUT AFSCommResult **ResultCB)
2160 AFSFileRenameResultCB *pResultCB = NULL;
2161 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2162 AFSFileID SourceParentId = pRenameCB->SourceParentId;
2163 AFSFileID TargetParentId = pRenameCB->TargetParentId;
2164 WCHAR * TargetFileNameCounted = pRenameCB->TargetName;
2165 DWORD TargetFileNameLength = pRenameCB->TargetNameLength;
2166 cm_fid_t SourceParentFid;
2167 cm_fid_t TargetParentFid;
2168 cm_scache_t * oldDscp;
2169 cm_scache_t * newDscp;
2170 wchar_t shortName[13];
2171 wchar_t SourceFileName[260];
2172 wchar_t TargetFileName[260];
2180 req.flags |= CM_REQ_WOW64;
2182 StringCchCopyNW(SourceFileName, 260, SourceFileNameCounted, SourceFileNameLength / sizeof(WCHAR));
2183 StringCchCopyNW(TargetFileName, 260, TargetFileNameCounted, TargetFileNameLength / sizeof(WCHAR));
2185 osi_Log4(afsd_logp, "RDR_RenameFileEntry Source Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2186 SourceParentId.Cell, SourceParentId.Volume,
2187 SourceParentId.Vnode, SourceParentId.Unique);
2188 osi_Log2(afsd_logp, "... Source Name=%S Length %u", osi_LogSaveStringW(afsd_logp, SourceFileName), SourceFileNameLength);
2189 osi_Log4(afsd_logp, "... Target Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2190 TargetParentId.Cell, TargetParentId.Volume,
2191 TargetParentId.Vnode, TargetParentId.Unique);
2192 osi_Log2(afsd_logp, "... Target Name=%S Length %u", osi_LogSaveStringW(afsd_logp, TargetFileName), TargetFileNameLength);
2194 *ResultCB = (AFSCommResult *)malloc( size);
2202 pResultCB = (AFSFileRenameResultCB *)(*ResultCB)->ResultData;
2204 if (SourceFileNameLength == 0 || TargetFileNameLength == 0)
2206 osi_Log2(afsd_logp, "RDR_RenameFileEntry Invalid Name Length: src %u target %u",
2207 SourceFileNameLength, TargetFileNameLength);
2208 (*ResultCB)->ResultStatus = STATUS_INVALID_PARAMETER;
2212 SourceParentFid.cell = SourceParentId.Cell;
2213 SourceParentFid.volume = SourceParentId.Volume;
2214 SourceParentFid.vnode = SourceParentId.Vnode;
2215 SourceParentFid.unique = SourceParentId.Unique;
2216 SourceParentFid.hash = SourceParentId.Hash;
2218 TargetParentFid.cell = TargetParentId.Cell;
2219 TargetParentFid.volume = TargetParentId.Volume;
2220 TargetParentFid.vnode = TargetParentId.Vnode;
2221 TargetParentFid.unique = TargetParentId.Unique;
2222 TargetParentFid.hash = TargetParentId.Hash;
2224 code = cm_GetSCache(&SourceParentFid, &oldDscp, userp, &req);
2226 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache source parent failed code 0x%x", code);
2227 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2228 (*ResultCB)->ResultStatus = status;
2232 lock_ObtainWrite(&oldDscp->rw);
2233 code = cm_SyncOp(oldDscp, NULL, userp, &req, 0,
2234 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2236 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp oldDscp 0x%p failed code 0x%x", oldDscp, code);
2237 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2238 (*ResultCB)->ResultStatus = status;
2239 lock_ReleaseWrite(&oldDscp->rw);
2240 cm_ReleaseSCache(oldDscp);
2244 cm_SyncOpDone(oldDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2245 lock_ReleaseWrite(&oldDscp->rw);
2248 if (oldDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2249 osi_Log1(afsd_logp, "RDR_RenameFileEntry oldDscp 0x%p not a directory", oldDscp);
2250 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2251 cm_ReleaseSCache(oldDscp);
2255 code = cm_GetSCache(&TargetParentFid, &newDscp, userp, &req);
2257 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target parent failed code 0x%x", code);
2258 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2259 (*ResultCB)->ResultStatus = status;
2260 cm_ReleaseSCache(oldDscp);
2264 lock_ObtainWrite(&newDscp->rw);
2265 code = cm_SyncOp(newDscp, NULL, userp, &req, 0,
2266 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2268 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp newDscp 0x%p failed code 0x%x", newDscp, code);
2269 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2270 (*ResultCB)->ResultStatus = status;
2271 lock_ReleaseWrite(&newDscp->rw);
2272 cm_ReleaseSCache(oldDscp);
2273 cm_ReleaseSCache(newDscp);
2277 cm_SyncOpDone(newDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2278 lock_ReleaseWrite(&newDscp->rw);
2281 if (newDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2282 osi_Log1(afsd_logp, "RDR_RenameFileEntry newDscp 0x%p not a directory", newDscp);
2283 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2284 cm_ReleaseSCache(oldDscp);
2285 cm_ReleaseSCache(newDscp);
2289 code = cm_Rename( oldDscp, NULL, SourceFileName,
2290 newDscp, TargetFileName, userp, &req);
2294 cm_scache_t *scp = 0;
2297 (*ResultCB)->ResultBufferLength = ResultBufferLength;
2298 dwRemaining = ResultBufferLength - sizeof( AFSFileRenameResultCB) + sizeof( AFSDirEnumEntry);
2299 (*ResultCB)->ResultStatus = 0;
2301 pResultCB->SourceParentDataVersion.QuadPart = oldDscp->dataVersion;
2302 pResultCB->TargetParentDataVersion.QuadPart = newDscp->dataVersion;
2304 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p SUCCESS",
2307 code = cm_BeginDirOp( newDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2309 code = cm_BPlusDirLookup(&dirop, TargetFileName, &targetFid);
2310 cm_EndDirOp(&dirop);
2314 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_BPlusDirLookup failed code 0x%x",
2316 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
2317 cm_ReleaseSCache(oldDscp);
2318 cm_ReleaseSCache(newDscp);
2322 osi_Log4(afsd_logp, "RDR_RenameFileEntry Target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2323 targetFid.cell, targetFid.volume,
2324 targetFid.vnode, targetFid.unique);
2326 code = cm_GetSCache(&targetFid, &scp, userp, &req);
2328 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target failed code 0x%x", code);
2329 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2330 (*ResultCB)->ResultStatus = status;
2331 cm_ReleaseSCache(oldDscp);
2332 cm_ReleaseSCache(newDscp);
2336 /* Make sure the source vnode is current */
2337 lock_ObtainWrite(&scp->rw);
2338 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2339 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2341 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp scp 0x%p failed code 0x%x", scp, code);
2342 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2343 (*ResultCB)->ResultStatus = status;
2344 lock_ReleaseWrite(&scp->rw);
2345 cm_ReleaseSCache(oldDscp);
2346 cm_ReleaseSCache(newDscp);
2347 cm_ReleaseSCache(scp);
2351 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2352 lock_ReleaseWrite(&scp->rw);
2354 dfid.vnode = htonl(scp->fid.vnode);
2355 dfid.unique = htonl(scp->fid.unique);
2357 if (!cm_Is8Dot3(TargetFileName))
2358 cm_Gen8Dot3NameIntW(TargetFileName, &dfid, shortName, NULL);
2360 shortName[0] = '\0';
2362 RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
2363 newDscp, scp, userp, &req, TargetFileName, shortName,
2364 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
2365 NULL, &dwRemaining);
2366 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
2367 cm_ReleaseSCache(scp);
2369 osi_Log0(afsd_logp, "RDR_RenameFileEntry SUCCESS");
2371 osi_Log3(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p failed code 0x%x",
2372 oldDscp, newDscp, code);
2373 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2374 (*ResultCB)->ResultStatus = status;
2375 (*ResultCB)->ResultBufferLength = 0;
2378 cm_ReleaseSCache(oldDscp);
2379 cm_ReleaseSCache(newDscp);
2384 RDR_FlushFileEntry( IN cm_user_t *userp,
2385 IN AFSFileID FileId,
2387 IN DWORD ResultBufferLength,
2388 IN OUT AFSCommResult **ResultCB)
2390 cm_scache_t *scp = NULL;
2401 req.flags |= CM_REQ_WOW64;
2403 osi_Log4(afsd_logp, "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x",
2404 FileId.Cell, FileId.Volume,
2405 FileId.Vnode, FileId.Unique);
2407 snprintf( dbgstr, 1024,
2408 "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x\n",
2409 FileId.Cell, FileId.Volume,
2410 FileId.Vnode, FileId.Unique);
2411 OutputDebugStringA( dbgstr);
2414 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2416 osi_Log0(afsd_logp, "RDR_FlushFileEntry out of memory");
2422 sizeof( AFSCommResult));
2424 /* Process the release */
2425 Fid.cell = FileId.Cell;
2426 Fid.volume = FileId.Volume;
2427 Fid.vnode = FileId.Vnode;
2428 Fid.unique = FileId.Unique;
2429 Fid.hash = FileId.Hash;
2431 code = cm_GetSCache(&Fid, &scp, userp, &req);
2433 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2434 (*ResultCB)->ResultStatus = status;
2435 osi_Log2(afsd_logp, "RDR_FlushFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2440 lock_ObtainWrite(&scp->rw);
2441 if (scp->flags & CM_SCACHEFLAG_DELETED) {
2442 lock_ReleaseWrite(&scp->rw);
2443 (*ResultCB)->ResultStatus = STATUS_INVALID_HANDLE;
2447 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2448 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2450 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2451 (*ResultCB)->ResultStatus = status;
2452 lock_ReleaseWrite(&scp->rw);
2453 cm_ReleaseSCache(scp);
2454 osi_Log3(afsd_logp, "RDR_FlushFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2459 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2460 lock_ReleaseWrite(&scp->rw);
2462 code = cm_FSync(scp, userp, &req, FALSE);
2463 cm_ReleaseSCache(scp);
2466 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2467 (*ResultCB)->ResultStatus = status;
2468 osi_Log2(afsd_logp, "RDR_FlushFileEntry FAILURE code=0x%x status=0x%x",
2471 (*ResultCB)->ResultStatus = 0;
2472 osi_Log0(afsd_logp, "RDR_FlushFileEntry SUCCESS");
2474 (*ResultCB)->ResultBufferLength = 0;
2480 RDR_CheckAccess( IN cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp,
2484 ULONG afs_acc, afs_gr;
2486 afs_uint32 code = 0;
2488 file = (scp->fileType == CM_SCACHETYPE_FILE);
2491 /* access definitions from prs_fs.h */
2493 if (access & FILE_READ_DATA)
2494 afs_acc |= PRSFS_READ;
2495 if (access & FILE_READ_EA || access & FILE_READ_ATTRIBUTES)
2496 afs_acc |= PRSFS_READ;
2497 if (file && ((access & FILE_WRITE_DATA) || (access & FILE_APPEND_DATA)))
2498 afs_acc |= PRSFS_WRITE;
2499 if (access & FILE_WRITE_EA || access & FILE_WRITE_ATTRIBUTES)
2500 afs_acc |= PRSFS_WRITE;
2501 if (dir && ((access & FILE_ADD_FILE) || (access & FILE_ADD_SUBDIRECTORY)))
2502 afs_acc |= PRSFS_INSERT;
2503 if (dir && (access & FILE_LIST_DIRECTORY))
2504 afs_acc |= PRSFS_LOOKUP;
2505 if (file && (access & FILE_EXECUTE))
2506 afs_acc |= PRSFS_WRITE;
2507 if (dir && (access & FILE_TRAVERSE))
2508 afs_acc |= PRSFS_READ;
2509 if (dir && (access & FILE_DELETE_CHILD))
2510 afs_acc |= PRSFS_DELETE;
2511 if ((access & DELETE))
2512 afs_acc |= PRSFS_DELETE;
2514 /* check ACL with server */
2515 lock_ObtainWrite(&scp->rw);
2518 if (cm_HaveAccessRights(scp, userp, reqp, afs_acc, &afs_gr))
2524 /* we don't know the required access rights */
2525 code = cm_GetAccessRights(scp, userp, reqp);
2531 lock_ReleaseWrite(&(scp->rw));
2535 if (afs_gr & PRSFS_READ)
2536 *granted |= FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | FILE_EXECUTE;
2537 if (afs_gr & PRSFS_WRITE)
2538 *granted |= FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES | FILE_EXECUTE;
2539 if (afs_gr & PRSFS_INSERT)
2540 *granted |= (dir ? FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY : 0) | (file ? FILE_ADD_SUBDIRECTORY : 0);
2541 if (afs_gr & PRSFS_LOOKUP)
2542 *granted |= (dir ? FILE_LIST_DIRECTORY : 0);
2543 if (afs_gr & PRSFS_DELETE)
2544 *granted |= FILE_DELETE_CHILD | DELETE;
2545 if (afs_gr & PRSFS_LOCK)
2547 if (afs_gr & PRSFS_ADMINISTER)
2550 *granted |= SYNCHRONIZE | READ_CONTROL;
2552 /* don't give more access than what was requested */
2554 osi_Log3(afsd_logp, "RDR_CheckAccess SUCCESS scp=0x%p requested=0x%x granted=0x%x", scp, access, *granted);
2556 osi_Log2(afsd_logp, "RDR_CheckAccess FAILURE scp=0x%p code=0x%x",
2563 RDR_OpenFileEntry( IN cm_user_t *userp,
2564 IN AFSFileID FileId,
2565 IN AFSFileOpenCB *OpenCB,
2568 IN DWORD ResultBufferLength,
2569 IN OUT AFSCommResult **ResultCB)
2571 AFSFileOpenResultCB *pResultCB = NULL;
2572 cm_scache_t *scp = NULL;
2573 cm_user_t *sysUserp = NULL;
2575 cm_lock_data_t *ldp = NULL;
2582 req.flags |= CM_REQ_WOW64;
2584 osi_Log4(afsd_logp, "RDR_OpenFileEntry File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2585 FileId.Cell, FileId.Volume,
2586 FileId.Vnode, FileId.Unique);
2588 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2590 osi_Log0(afsd_logp, "RDR_OpenFileEntry out of memory");
2596 sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2598 pResultCB = (AFSFileOpenResultCB *)(*ResultCB)->ResultData;
2600 /* Process the release */
2601 Fid.cell = FileId.Cell;
2602 Fid.volume = FileId.Volume;
2603 Fid.vnode = FileId.Vnode;
2604 Fid.unique = FileId.Unique;
2605 Fid.hash = FileId.Hash;
2607 code = cm_GetSCache(&Fid, &scp, userp, &req);
2609 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2610 (*ResultCB)->ResultStatus = status;
2611 osi_Log2(afsd_logp, "RDR_OpenFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2616 lock_ObtainWrite(&scp->rw);
2617 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2618 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2620 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2621 (*ResultCB)->ResultStatus = status;
2622 lock_ReleaseWrite(&scp->rw);
2623 cm_ReleaseSCache(scp);
2624 osi_Log3(afsd_logp, "RDR_OpenFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2629 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2630 lock_ReleaseWrite(&scp->rw);
2632 sysUserp = RDR_GetLocalSystemUser();
2635 * Skip the open check if the request is coming from the local system account.
2636 * The local system has no tokens and therefore any requests sent to a file
2637 * server will fail. Unfortunately, there are special system processes that
2638 * perform actions on files and directories in preparation for memory mapping
2639 * executables. If the open check fails, the real request from the user process
2640 * will never be issued.
2642 * Permitting the file system to allow subsequent operations to proceed does
2643 * not compromise security. All requests to obtain file data or directory
2644 * enumerations will subsequently fail if they are not submitted under the
2645 * context of a process for that have access to the necessary credentials.
2648 if ( userp == sysUserp)
2650 osi_Log1(afsd_logp, "RDR_OpenFileEntry LOCAL_SYSTEM access check skipped scp=0x%p",
2652 pResultCB->GrantedAccess = OpenCB->DesiredAccess;
2653 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2664 "RDR_OpenFileEntry repeating open check scp=0x%p userp=0x%p code=0x%x",
2667 code = cm_CheckNTOpen(scp, OpenCB->DesiredAccess, OpenCB->ShareAccess,
2669 OpenCB->ProcessId, OpenCB->Identifier,
2672 code = RDR_CheckAccess(scp, userp, &req, OpenCB->DesiredAccess, &pResultCB->GrantedAccess);
2673 cm_CheckNTOpenDone(scp, userp, &req, &ldp);
2674 } while (count < 100 && (code == CM_ERROR_RETRY || code == CM_ERROR_WOULDBLOCK));
2678 * If we are restricting sharing, we should do so with a suitable
2681 if (code == 0 && scp->fileType == CM_SCACHETYPE_FILE && !(OpenCB->ShareAccess & FILE_SHARE_WRITE)) {
2683 LARGE_INTEGER LOffset, LLength;
2686 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2687 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2688 LLength.HighPart = 0;
2689 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2692 * If we are not opening the file for writing, then we don't
2693 * try to get an exclusive lock. No one else should be able to
2694 * get an exclusive lock on the file anyway, although someone
2695 * else can get a shared lock.
2697 if ((OpenCB->ShareAccess & FILE_SHARE_READ) || !(OpenCB->DesiredAccess & AFS_ACCESS_WRITE))
2699 sLockType = LOCKING_ANDX_SHARED_LOCK;
2704 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, OpenCB->Identifier);
2706 lock_ObtainWrite(&scp->rw);
2707 code = cm_Lock(scp, sLockType, LOffset, LLength, key, 0, userp, &req, NULL);
2708 lock_ReleaseWrite(&scp->rw);
2711 code = CM_ERROR_SHARING_VIOLATION;
2712 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2714 if (sLockType == LOCKING_ANDX_SHARED_LOCK)
2715 pResultCB->FileAccess = AFS_FILE_ACCESS_SHARED;
2717 pResultCB->FileAccess = AFS_FILE_ACCESS_EXCLUSIVE;
2720 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2723 cm_ReleaseUser(sysUserp);
2724 if (code == 0 && bHoldFid)
2725 RDR_FlagScpInUse( scp, FALSE );
2726 cm_ReleaseSCache(scp);
2729 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2730 (*ResultCB)->ResultStatus = status;
2731 osi_Log2(afsd_logp, "RDR_OpenFileEntry FAILURE code=0x%x status=0x%x",
2734 (*ResultCB)->ResultStatus = 0;
2735 (*ResultCB)->ResultBufferLength = sizeof( AFSFileOpenResultCB);
2736 osi_Log0(afsd_logp, "RDR_OpenFileEntry SUCCESS");
2742 RDR_ReleaseFileAccess( IN cm_user_t *userp,
2743 IN AFSFileID FileId,
2744 IN AFSFileAccessReleaseCB *ReleaseFileCB,
2746 IN DWORD ResultBufferLength,
2747 IN OUT AFSCommResult **ResultCB)
2750 unsigned int sLockType;
2751 LARGE_INTEGER LOffset, LLength;
2752 cm_scache_t *scp = NULL;
2760 req.flags |= CM_REQ_WOW64;
2762 osi_Log4(afsd_logp, "RDR_ReleaseFileAccess File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2763 FileId.Cell, FileId.Volume,
2764 FileId.Vnode, FileId.Unique);
2766 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2768 osi_Log0(afsd_logp, "RDR_ReleaseFileAccess out of memory");
2772 memset( *ResultCB, '\0', sizeof( AFSCommResult));
2774 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_NOLOCK)
2777 /* Process the release */
2778 Fid.cell = FileId.Cell;
2779 Fid.volume = FileId.Volume;
2780 Fid.vnode = FileId.Vnode;
2781 Fid.unique = FileId.Unique;
2782 Fid.hash = FileId.Hash;
2784 code = cm_GetSCache(&Fid, &scp, userp, &req);
2786 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2787 (*ResultCB)->ResultStatus = status;
2788 osi_Log2(afsd_logp, "RDR_ReleaseFileAccess cm_GetSCache FID failure code=0x%x status=0x%x",
2793 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_SHARED)
2794 sLockType = LOCKING_ANDX_SHARED_LOCK;
2798 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, ReleaseFileCB->Identifier);
2800 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2801 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2802 LLength.HighPart = 0;
2803 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2805 lock_ObtainWrite(&scp->rw);
2807 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
2810 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
2812 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
2814 if (code == CM_ERROR_RANGE_NOT_LOCKED)
2816 osi_Log3(afsd_logp, "RDR_ReleaseFileAccess Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
2817 ReleaseFileCB->FileAccess, ReleaseFileCB->ProcessId, ReleaseFileCB->Identifier);
2821 lock_ReleaseWrite(&scp->rw);
2823 osi_Log0(afsd_logp, "RDR_ReleaseFileAccessEntry SUCCESS");
2827 HexCheckSum(unsigned char * buf, int buflen, unsigned char * md5cksum)
2830 static char tr[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
2833 return "buffer length too small to HexCheckSum";
2835 for (i=0;i<16;i++) {
2838 buf[i*2] = tr[k / 16];
2839 buf[i*2+1] = tr[k % 16];
2847 * Extent requests from the file system are triggered when a file
2848 * page is not resident in the Windows cache. The file system is
2849 * responsible for loading the page but cannot block the request
2850 * while doing so. The AFS Redirector forwards the requests to
2851 * the AFS cache manager while indicating to Windows that the page
2852 * is not yet available. A polling operation will then ensue with
2853 * the AFS Redirector issuing a RDR_RequestFileExtentsXXX call for
2854 * each poll attempt. As each request is received and processed
2855 * by a separate worker thread in the service, this can lead to
2856 * contention by multiple threads attempting to claim the same
2857 * cm_buf_t objects. Therefore, it is important that
2859 * (a) the service avoid processing more than one overlapping
2860 * extent request at a time
2861 * (b) background daemon processing be used to avoid blocking
2864 * Beginning with the 20091122 build of the redirector, the redirector
2865 * will not issue an additional RDR_RequestFileExtentsXXX call for
2866 * each poll request. Instead, afsd_service is required to track
2867 * the requests and return them to the redirector or fail the
2868 * portions of the request that cannot be satisfied.
2870 * The request processing returns any extents that can be returned
2871 * immediately to the redirector. The rest of the requested range(s)
2872 * are queued as background operations using RDR_BkgFetch().
2875 /* do the background fetch. */
2877 RDR_BkgFetch(cm_scache_t *scp, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4,
2878 cm_user_t *userp, cm_req_t *reqp)
2884 osi_hyper_t fetched;
2885 osi_hyper_t tblocksize;
2888 cm_buf_t *bufp = NULL;
2889 DWORD dwResultBufferLength;
2890 AFSSetFileExtentsCB *pResultCB;
2894 int reportErrorToRedir = 0;
2895 int force_retry = 0;
2897 FileId.Cell = scp->fid.cell;
2898 FileId.Volume = scp->fid.volume;
2899 FileId.Vnode = scp->fid.vnode;
2900 FileId.Unique = scp->fid.unique;
2901 FileId.Hash = scp->fid.hash;
2903 if ((GetTickCount() - reqp->startTime) / 1000 > HardDeadtimeout * 5) {
2904 RDR_SetFileStatus( &scp->fid, &userp->authgroup, STATUS_IO_TIMEOUT);
2908 fetched.LowPart = 0;
2909 fetched.HighPart = 0;
2910 tblocksize = ConvertLongToLargeInteger(cm_data.buf_blockSize);
2913 length.LowPart = p3;
2914 length.HighPart = p4;
2916 end = LargeIntegerAdd(base, length);
2918 osi_Log5(afsd_logp, "Starting BKG Fetch scp 0x%p offset 0x%x:%x length 0x%x:%x",
2919 scp, p2, p1, p4, p3);
2922 * Make sure we have a callback.
2923 * This is necessary so that we can return access denied
2924 * if a callback cannot be granted.
2926 lock_ObtainWrite(&scp->rw);
2927 code = cm_SyncOp(scp, NULL, userp, reqp, PRSFS_READ,
2928 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2930 lock_ReleaseWrite(&scp->rw);
2931 osi_Log2(afsd_logp, "RDR_BkgFetch cm_SyncOp failure scp=0x%p code=0x%x",
2933 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
2934 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
2937 lock_ReleaseWrite(&scp->rw);
2939 dwResultBufferLength = (DWORD)(sizeof( AFSSetFileExtentsCB) + sizeof( AFSSetFileExtentsCB) * (length.QuadPart / cm_data.blockSize + 1));
2940 pResultCB = (AFSSetFileExtentsCB *)malloc( dwResultBufferLength );
2942 return CM_ERROR_RETRY;
2944 memset( pResultCB, '\0', dwResultBufferLength );
2945 pResultCB->FileId = FileId;
2947 for ( code = 0, offset = base;
2948 code == 0 && LargeIntegerLessThan(offset, end);
2949 offset = LargeIntegerAdd(offset, tblocksize) )
2951 int bBufRelease = TRUE;
2954 lock_ReleaseWrite(&scp->rw);
2958 code = buf_Get(scp, &offset, reqp, &bufp);
2961 * any error from buf_Get() is non-fatal.
2962 * we need to re-queue this extent fetch.
2969 lock_ObtainWrite(&scp->rw);
2973 code = cm_GetBuffer(scp, bufp, NULL, userp, reqp);
2975 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
2976 #ifdef VALIDATE_CHECK_SUM
2982 if (bufp->flags & CM_BUF_DIRTY)
2983 cm_BufWrite(scp, &bufp->offset, cm_data.buf_blockSize, CM_BUF_WRITE_SCP_LOCKED, userp, reqp);
2985 lock_ObtainWrite(&buf_globalLock);
2986 if (!(bufp->flags & CM_BUF_DIRTY) &&
2987 bufp->cmFlags == 0 &&
2988 !(bufp->qFlags & CM_BUF_QREDIR)) {
2989 buf_InsertToRedirQueue(scp, bufp);
2990 lock_ReleaseWrite(&buf_globalLock);
2992 #ifdef VALIDATE_CHECK_SUM
2993 buf_ComputeCheckSum(bufp);
2995 pResultCB->FileExtents[count].Flags = 0;
2996 pResultCB->FileExtents[count].FileOffset.QuadPart = bufp->offset.QuadPart;
2997 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
2998 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3000 fetched = LargeIntegerAdd(fetched, tblocksize);
3001 bBufRelease = FALSE;
3003 #ifdef VALIDATE_CHECK_SUM
3005 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3006 snprintf( dbgstr, 1024,
3007 "RDR_BkgFetch md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3009 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3010 pResultCB->FileExtents[count].FileOffset.HighPart,
3011 pResultCB->FileExtents[count].FileOffset.LowPart,
3012 pResultCB->FileExtents[count].CacheOffset.HighPart,
3013 pResultCB->FileExtents[count].CacheOffset.LowPart);
3014 OutputDebugStringA( dbgstr);
3017 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3018 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3020 lock_ReleaseWrite(&buf_globalLock);
3021 if ((bufp->cmFlags != 0) || (bufp->flags & CM_BUF_DIRTY)) {
3022 /* An I/O operation is already in progress */
3024 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",
3025 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3027 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3028 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3032 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3033 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3037 * depending on what the error from cm_GetBuffer is
3038 * it may or may not be fatal. Only return fatal errors.
3039 * Re-queue a request for others.
3041 osi_Log5(afsd_logp, "RDR_BkgFetch Extent2FS FAILURE bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x code 0x%x",
3042 bufp, offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize, code);
3044 case CM_ERROR_NOACCESS:
3045 case CM_ERROR_NOSUCHFILE:
3046 case CM_ERROR_NOSUCHPATH:
3047 case CM_ERROR_NOSUCHVOLUME:
3048 case CM_ERROR_NOSUCHCELL:
3049 case CM_ERROR_INVAL:
3050 case CM_ERROR_BADFD:
3051 case CM_ERROR_CLOCKSKEW:
3053 case CM_ERROR_QUOTA:
3054 case CM_ERROR_LOCK_CONFLICT:
3056 * these are fatal errors. deliver what we can
3059 reportErrorToRedir = 1;
3063 * non-fatal errors. re-queue the exent
3065 code = CM_ERROR_RETRY;
3075 lock_ObtainWrite(&scp->rw);
3079 /* wakeup anyone who is waiting */
3080 if (scp->flags & CM_SCACHEFLAG_WAITING) {
3081 osi_Log1(afsd_logp, "RDR Bkg Fetch Waking scp 0x%p", scp);
3082 osi_Wakeup((LONG_PTR) &scp->flags);
3084 lock_ReleaseWrite(&scp->rw);
3087 pResultCB->ExtentCount = count;
3088 RDR_SetFileExtents( pResultCB, dwResultBufferLength);
3092 if (reportErrorToRedir) {
3093 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
3094 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3097 osi_Log4(afsd_logp, "Ending BKG Fetch scp 0x%p code 0x%x fetched 0x%x:%x",
3098 scp, code, fetched.HighPart, fetched.LowPart);
3100 return force_retry ? CM_ERROR_RETRY : code;
3105 RDR_RequestFileExtentsAsync( IN cm_user_t *userp,
3106 IN AFSFileID FileId,
3107 IN AFSRequestExtentsCB *RequestExtentsCB,
3109 IN OUT DWORD * ResultBufferLength,
3110 IN OUT AFSSetFileExtentsCB **ResultCB)
3112 AFSSetFileExtentsCB *pResultCB = NULL;
3116 cm_scache_t *scp = NULL;
3119 afs_uint32 code = 0;
3121 LARGE_INTEGER ByteOffset, BeginOffset, EndOffset, QueueOffset;
3122 afs_uint32 QueueLength;
3124 BOOLEAN bBufRelease = TRUE;
3128 req.flags |= CM_REQ_WOW64;
3129 req.flags |= CM_REQ_NORETRY;
3131 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3132 FileId.Cell, FileId.Volume,
3133 FileId.Vnode, FileId.Unique);
3134 osi_Log4(afsd_logp, "... Flags 0x%x ByteOffset 0x%x:%x Length 0x%x",
3135 RequestExtentsCB->Flags,
3136 RequestExtentsCB->ByteOffset.HighPart, RequestExtentsCB->ByteOffset.LowPart,
3137 RequestExtentsCB->Length);
3138 Length = sizeof( AFSSetFileExtentsCB) + sizeof( AFSFileExtentCB) * (RequestExtentsCB->Length / cm_data.blockSize + 1);
3140 pResultCB = *ResultCB = (AFSSetFileExtentsCB *)malloc( Length );
3141 if (*ResultCB == NULL) {
3142 *ResultBufferLength = 0;
3145 *ResultBufferLength = Length;
3147 memset( pResultCB, '\0', Length );
3148 pResultCB->FileId = FileId;
3150 Fid.cell = FileId.Cell;
3151 Fid.volume = FileId.Volume;
3152 Fid.vnode = FileId.Vnode;
3153 Fid.unique = FileId.Unique;
3154 Fid.hash = FileId.Hash;
3156 code = cm_GetSCache(&Fid, &scp, userp, &req);
3158 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync cm_GetSCache FID failure code=0x%x",
3160 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3165 * Make sure we have a callback.
3166 * This is necessary so that we can return access denied
3167 * if a callback cannot be granted.
3169 lock_ObtainWrite(&scp->rw);
3170 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_READ,
3171 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3172 lock_ReleaseWrite(&scp->rw);
3174 cm_ReleaseSCache(scp);
3175 osi_Log2(afsd_logp, "RDR_RequestFileExtentsAsync cm_SyncOp failure scp=0x%p code=0x%x",
3177 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3178 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3182 /* Allocate the extents from the buffer package */
3184 ByteOffset = BeginOffset = RequestExtentsCB->ByteOffset,
3185 EndOffset.QuadPart = ByteOffset.QuadPart + RequestExtentsCB->Length;
3186 code == 0 && ByteOffset.QuadPart < EndOffset.QuadPart;
3187 ByteOffset.QuadPart += cm_data.blockSize)
3189 BOOL bHaveBuffer = FALSE;
3192 thyper.QuadPart = ByteOffset.QuadPart;
3194 code = buf_Get(scp, &thyper, &req, &bufp);
3196 lock_ObtainMutex(&bufp->mx);
3199 if (bufp->qFlags & CM_BUF_QREDIR) {
3201 } else if (bufp->flags & CM_BUF_DIRTY) {
3202 bHaveBuffer = FALSE;
3204 code = buf_CleanAsyncLocked(scp, bufp, &req, 0, NULL);
3209 case CM_ERROR_RETRY:
3210 /* Couldn't flush it, obtain it asynchronously so we don't block the thread. */
3211 bHaveBuffer = FALSE;
3215 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3216 RDR_SetFileStatus(&FileId, &userp->authgroup, status);
3217 bHaveBuffer = FALSE;
3222 osi_hyper_t minLength; /* effective end of file */
3224 lock_ObtainRead(&scp->rw);
3225 bHaveBuffer = cm_HaveBuffer(scp, bufp, TRUE);
3227 if (LargeIntegerGreaterThan(scp->length, scp->serverLength))
3228 minLength = scp->serverLength;
3230 minLength = scp->length;
3233 LargeIntegerGreaterThanOrEqualTo(bufp->offset, minLength)) {
3234 memset(bufp->datap, 0, cm_data.buf_blockSize);
3235 bufp->dataVersion = scp->dataVersion;
3238 else if ((RequestExtentsCB->Flags & AFS_EXTENT_FLAG_CLEAN) &&
3239 ByteOffset.QuadPart <= bufp->offset.QuadPart &&
3240 EndOffset.QuadPart >= bufp->offset.QuadPart + cm_data.blockSize)
3242 memset(bufp->datap, 0, cm_data.blockSize);
3243 bufp->dataVersion = scp->dataVersion;
3244 buf_SetDirty(bufp, &req, 0, cm_data.blockSize, userp);
3247 lock_ReleaseRead(&scp->rw);
3251 * if this buffer is already up to date, skip it.
3254 if (ByteOffset.QuadPart == BeginOffset.QuadPart) {
3255 BeginOffset.QuadPart += cm_data.blockSize;
3257 QueueLength = (afs_uint32)(ByteOffset.QuadPart - BeginOffset.QuadPart);
3258 QueueOffset = BeginOffset;
3259 BeginOffset = ByteOffset;
3262 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3263 #ifdef VALIDATE_CHECK_SUM
3269 lock_ObtainWrite(&buf_globalLock);
3270 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3271 buf_InsertToRedirQueue(scp, bufp);
3272 lock_ReleaseWrite(&buf_globalLock);
3274 #ifdef VALIDATE_CHECK_SUM
3275 buf_ComputeCheckSum(bufp);
3277 /* we already have the buffer, return it now */
3278 pResultCB->FileExtents[count].Flags = 0;
3279 pResultCB->FileExtents[count].FileOffset = ByteOffset;
3280 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3281 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3284 bBufRelease = FALSE;
3286 #ifdef VALIDATE_CHECK_SUM
3288 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3289 snprintf( dbgstr, 1024,
3290 "RDR_RequestFileExtentsAsync md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3292 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3293 pResultCB->FileExtents[count].FileOffset.HighPart,
3294 pResultCB->FileExtents[count].FileOffset.LowPart,
3295 pResultCB->FileExtents[count].CacheOffset.HighPart,
3296 pResultCB->FileExtents[count].CacheOffset.LowPart);
3297 OutputDebugStringA( dbgstr);
3300 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3301 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3303 lock_ReleaseWrite(&buf_globalLock);
3308 * The service is not handing off the extent to the redirector in this pass.
3309 * However, we know the buffer is in recent use so move the buffer to the
3310 * front of the queue
3312 lock_ObtainWrite(&buf_globalLock);
3313 buf_MoveToHeadOfRedirQueue(scp, bufp);
3314 lock_ReleaseWrite(&buf_globalLock);
3316 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3317 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3321 lock_ReleaseMutex(&bufp->mx);
3326 cm_QueueBKGRequest(scp, RDR_BkgFetch, QueueOffset.LowPart, QueueOffset.HighPart,
3327 QueueLength, 0, userp, &req);
3328 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3329 QueueOffset.HighPart, QueueOffset.LowPart, QueueLength);
3332 /* No error from buf_Get() can be fatal */
3333 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync buf_Get FAILURE offset 0x%x:%x code 0x%x",
3334 BeginOffset.HighPart, BeginOffset.LowPart, code);
3338 if (BeginOffset.QuadPart != EndOffset.QuadPart) {
3339 afs_uint32 length = (afs_uint32)(EndOffset.QuadPart - BeginOffset.QuadPart);
3341 cm_QueueBKGRequest(scp, RDR_BkgFetch, BeginOffset.LowPart, BeginOffset.HighPart,
3342 length, 0, userp, &req);
3343 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3344 BeginOffset.HighPart, BeginOffset.LowPart, length);
3346 cm_ReleaseSCache(scp);
3348 (*ResultCB)->ExtentCount = count;
3349 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync replying with 0x%x extent records", count);
3354 * When processing an extent release the extents must be accepted back by
3355 * the service even if there is an error condition returned to the redirector.
3356 * For example, there may no longer be a callback present or the file may
3357 * have been deleted on the file server. Regardless, the extents must be
3358 * put back into the pool.
3361 RDR_ReleaseFileExtents( IN cm_user_t *userp,
3362 IN AFSFileID FileId,
3363 IN AFSReleaseExtentsCB *ReleaseExtentsCB,
3365 IN DWORD ResultBufferLength,
3366 IN OUT AFSCommResult **ResultCB)
3369 cm_scache_t *scp = NULL;
3379 #ifdef VALIDATE_CHECK_SUM
3380 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3387 req.flags |= CM_REQ_WOW64;
3389 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3390 FileId.Cell, FileId.Volume,
3391 FileId.Vnode, FileId.Unique);
3393 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
3399 sizeof( AFSCommResult));
3401 /* Process the release */
3402 Fid.cell = FileId.Cell;
3403 Fid.volume = FileId.Volume;
3404 Fid.vnode = FileId.Vnode;
3405 Fid.unique = FileId.Unique;
3406 Fid.hash = FileId.Hash;
3408 code = cm_GetSCache(&Fid, &scp, userp, &req);
3410 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3411 (*ResultCB)->ResultStatus = status;
3412 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents cm_GetSCache FID failure code=0x%x status=0x%x",
3417 * We do not stop processing as a result of being unable to find the cm_scache object.
3418 * If this occurs something really bad has happened since the cm_scache object must have
3419 * been recycled while extents were held by the redirector. However, we will be resilient
3420 * and carry on without it.
3422 if (scp && ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3425 memset(&setAttr, 0, sizeof(cm_attr_t));
3426 lock_ObtainWrite(&scp->rw);
3427 if (ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3429 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents new length fid vol 0x%x vno 0x%x length 0x%x:%x",
3430 scp->fid.volume, scp->fid.vnode,
3431 ReleaseExtentsCB->AllocationSize.HighPart,
3432 ReleaseExtentsCB->AllocationSize.LowPart);
3434 setAttr.mask |= CM_ATTRMASK_LENGTH;
3435 setAttr.length.LowPart = ReleaseExtentsCB->AllocationSize.LowPart;
3436 setAttr.length.HighPart = ReleaseExtentsCB->AllocationSize.HighPart;
3438 lock_ReleaseWrite(&scp->rw);
3440 code = cm_SetAttr(scp, &setAttr, userp, &req);
3443 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3444 AFSFileExtentCB * pExtent = &ReleaseExtentsCB->FileExtents[count];
3446 thyper.QuadPart = pExtent->FileOffset.QuadPart;
3448 bufp = buf_Find(&Fid, &thyper);
3450 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
3451 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3452 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3453 Fid.volume, Fid.vnode,
3454 pExtent->FileOffset.HighPart,
3455 pExtent->FileOffset.LowPart);
3456 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
3457 pExtent->CacheOffset.HighPart,
3458 pExtent->CacheOffset.LowPart);
3460 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3461 Fid.volume, Fid.vnode,
3462 pExtent->FileOffset.HighPart,
3463 pExtent->FileOffset.LowPart);
3464 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
3465 pExtent->CacheOffset.HighPart,
3466 pExtent->CacheOffset.LowPart);
3472 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
3473 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3474 Fid.volume, Fid.vnode,
3475 pExtent->FileOffset.HighPart,
3476 pExtent->FileOffset.LowPart);
3477 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
3478 pExtent->CacheOffset.HighPart,
3479 pExtent->CacheOffset.LowPart);
3481 /* Move the buffer to the front of the queue */
3482 lock_ObtainWrite(&buf_globalLock);
3483 buf_MoveToHeadOfRedirQueue(scp, bufp);
3484 lock_ReleaseWrite(&buf_globalLock);
3489 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
3490 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3491 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x not held by file system",
3492 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
3493 pExtent->FileOffset.LowPart);
3494 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3495 pExtent->CacheOffset.HighPart,
3496 pExtent->CacheOffset.LowPart);
3498 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents bufp 0x%p vno 0x%x foffset 0x%x:%x",
3499 bufp, bufp->fid.vnode, pExtent->FileOffset.HighPart,
3500 pExtent->FileOffset.LowPart);
3501 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3502 pExtent->CacheOffset.HighPart,
3503 pExtent->CacheOffset.LowPart);
3505 if (pExtent->Flags || ReleaseExtentsCB->Flags) {
3506 lock_ObtainMutex(&bufp->mx);
3507 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
3508 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
3510 if (bufp->qFlags & CM_BUF_QREDIR) {
3511 lock_ObtainWrite(&buf_globalLock);
3512 if (bufp->qFlags & CM_BUF_QREDIR) {
3513 buf_RemoveFromRedirQueue(scp, bufp);
3514 buf_ReleaseLocked(bufp, TRUE);
3516 lock_ReleaseWrite(&buf_globalLock);
3519 snprintf( dbgstr, 1024,
3520 "RDR_ReleaseFileExtents releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3521 Fid.volume, Fid.vnode, Fid.unique,
3522 pExtent->FileOffset.HighPart,
3523 pExtent->FileOffset.LowPart,
3524 pExtent->CacheOffset.HighPart,
3525 pExtent->CacheOffset.LowPart);
3526 OutputDebugStringA( dbgstr);
3531 snprintf( dbgstr, 1024,
3532 "RDR_ReleaseFileExtents not releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3533 Fid.volume, Fid.vnode, Fid.unique,
3534 pExtent->FileOffset.HighPart,
3535 pExtent->FileOffset.LowPart,
3536 pExtent->CacheOffset.HighPart,
3537 pExtent->CacheOffset.LowPart);
3538 OutputDebugStringA( dbgstr);
3540 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
3541 Fid.volume, Fid.vnode,
3542 pExtent->FileOffset.HighPart,
3543 pExtent->FileOffset.LowPart);
3544 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3545 pExtent->CacheOffset.HighPart,
3546 pExtent->CacheOffset.LowPart);
3549 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
3550 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY) )
3552 #ifdef VALIDATE_CHECK_SUM
3554 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3558 * if the saved checksum matches the checksum of the current state of the buffer
3559 * then the buffer is the same as what was given to the kernel.
3561 if ( buf_ValidateCheckSum(bufp) ) {
3562 buf_ComputeCheckSum(bufp);
3564 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3567 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
3568 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3570 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3573 snprintf( dbgstr, 1024,
3574 "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",
3575 md5dbg, md5dbg2,md5dbg3,
3576 Fid.volume, Fid.vnode, Fid.unique,
3577 pExtent->FileOffset.HighPart,
3578 pExtent->FileOffset.LowPart,
3579 pExtent->CacheOffset.HighPart,
3580 pExtent->CacheOffset.LowPart);
3581 OutputDebugStringA( dbgstr);
3583 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
3584 Fid.volume, Fid.vnode,
3585 pExtent->FileOffset.HighPart,
3586 pExtent->FileOffset.LowPart);
3587 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3588 pExtent->CacheOffset.HighPart,
3589 pExtent->CacheOffset.LowPart);
3590 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3594 snprintf( dbgstr, 1024,
3595 "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",
3596 md5dbg, md5dbg2, md5dbg3,
3597 Fid.volume, Fid.vnode, Fid.unique,
3598 pExtent->FileOffset.HighPart,
3599 pExtent->FileOffset.LowPart,
3600 pExtent->CacheOffset.HighPart,
3601 pExtent->CacheOffset.LowPart);
3602 OutputDebugStringA( dbgstr);
3604 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3605 Fid.volume, Fid.vnode,
3606 pExtent->FileOffset.HighPart,
3607 pExtent->FileOffset.LowPart);
3608 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3609 pExtent->CacheOffset.HighPart,
3610 pExtent->CacheOffset.LowPart);
3614 snprintf( dbgstr, 1024,
3615 "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",
3616 Fid.volume, Fid.vnode, Fid.unique,
3617 pExtent->FileOffset.HighPart,
3618 pExtent->FileOffset.LowPart,
3619 pExtent->CacheOffset.HighPart,
3620 pExtent->CacheOffset.LowPart);
3621 OutputDebugStringA( dbgstr);
3623 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3624 Fid.volume, Fid.vnode,
3625 pExtent->FileOffset.HighPart,
3626 pExtent->FileOffset.LowPart);
3627 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3628 pExtent->CacheOffset.HighPart,
3629 pExtent->CacheOffset.LowPart);
3632 buf_ComputeCheckSum(bufp);
3634 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3636 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3637 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3639 snprintf( dbgstr, 1024,
3640 "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",
3641 md5dbg, md5dbg2,md5dbg3,
3642 Fid.volume, Fid.vnode, Fid.unique,
3643 pExtent->FileOffset.HighPart,
3644 pExtent->FileOffset.LowPart,
3645 pExtent->CacheOffset.HighPart,
3646 pExtent->CacheOffset.LowPart);
3647 OutputDebugStringA( dbgstr);
3649 snprintf( dbgstr, 1024,
3650 "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",
3651 md5dbg, md5dbg2,md5dbg3,
3652 Fid.volume, Fid.vnode, Fid.unique,
3653 pExtent->FileOffset.HighPart,
3654 pExtent->FileOffset.LowPart,
3655 pExtent->CacheOffset.HighPart,
3656 pExtent->CacheOffset.LowPart);
3657 OutputDebugStringA( dbgstr);
3660 snprintf( dbgstr, 1024,
3661 "RDR_ReleaseFileExtents dirty flag set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3662 Fid.volume, Fid.vnode, Fid.unique,
3663 pExtent->FileOffset.HighPart,
3664 pExtent->FileOffset.LowPart,
3665 pExtent->CacheOffset.HighPart,
3666 pExtent->CacheOffset.LowPart);
3667 OutputDebugStringA( dbgstr);
3670 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3673 #else /* !VALIDATE_CHECK_SUM */
3674 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3676 #endif /* VALIDATE_CHECK_SUM */
3678 #ifdef VALIDATE_CHECK_SUM
3681 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3683 if ( !buf_ValidateCheckSum(bufp) ) {
3684 buf_ComputeCheckSum(bufp);
3686 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3687 snprintf( dbgstr, 1024,
3688 "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",
3690 Fid.volume, Fid.vnode, Fid.unique,
3691 pExtent->FileOffset.HighPart,
3692 pExtent->FileOffset.LowPart,
3693 pExtent->CacheOffset.HighPart,
3694 pExtent->CacheOffset.LowPart);
3695 OutputDebugStringA( dbgstr);
3697 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set but extent has changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3698 Fid.volume, Fid.vnode,
3699 pExtent->FileOffset.HighPart,
3700 pExtent->FileOffset.LowPart);
3701 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3702 pExtent->CacheOffset.HighPart,
3703 pExtent->CacheOffset.LowPart);
3704 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3707 buf_ComputeCheckSum(bufp);
3709 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3710 snprintf( dbgstr, 1024,
3711 "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3712 Fid.volume, Fid.vnode, Fid.unique,
3713 pExtent->FileOffset.HighPart,
3714 pExtent->FileOffset.LowPart,
3715 pExtent->CacheOffset.HighPart,
3716 pExtent->CacheOffset.LowPart);
3717 OutputDebugStringA( dbgstr);
3719 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x foffset 0x%x:%x",
3720 Fid.volume, Fid.vnode,
3721 pExtent->FileOffset.HighPart,
3722 pExtent->FileOffset.LowPart);
3723 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3724 pExtent->CacheOffset.HighPart,
3725 pExtent->CacheOffset.LowPart);
3728 #endif /* VALIDATE_CHECK_SUM */
3729 lock_ReleaseMutex(&bufp->mx);
3734 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3737 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3738 if (wbp->datap == datap)
3743 snprintf( dbgstr, 1024,
3744 "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3745 Fid.volume, Fid.vnode, Fid.unique,
3746 pExtent->FileOffset.HighPart,
3747 pExtent->FileOffset.LowPart,
3748 pExtent->CacheOffset.HighPart,
3749 pExtent->CacheOffset.LowPart);
3750 OutputDebugStringA( dbgstr);
3752 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3753 Fid.volume, Fid.vnode,
3754 pExtent->FileOffset.HighPart,
3755 pExtent->FileOffset.LowPart);
3756 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3757 pExtent->CacheOffset.HighPart,
3758 pExtent->CacheOffset.LowPart);
3759 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3760 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3768 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3771 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3772 if (wbp->datap == datap)
3777 snprintf( dbgstr, 1024,
3778 "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3779 Fid.volume, Fid.vnode, Fid.unique,
3780 pExtent->FileOffset.HighPart,
3781 pExtent->FileOffset.LowPart,
3782 pExtent->CacheOffset.HighPart,
3783 pExtent->CacheOffset.LowPart);
3784 OutputDebugStringA( dbgstr);
3786 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3787 Fid.volume, Fid.vnode,
3788 pExtent->FileOffset.HighPart,
3789 pExtent->FileOffset.LowPart);
3790 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3791 pExtent->CacheOffset.HighPart,
3792 pExtent->CacheOffset.LowPart);
3793 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3794 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3799 if (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_FLUSH) {
3800 lock_ObtainWrite(&scp->rw);
3801 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3802 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3803 lock_ReleaseWrite(&scp->rw);
3805 code = cm_FSync(scp, userp, &req, FALSE);
3808 osi_hyper_t offset = {0,0};
3809 afs_uint32 length = 0;
3810 afs_uint32 rights = 0;
3812 lock_ObtainWrite(&scp->rw);
3813 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3814 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3815 lock_ReleaseWrite(&scp->rw);
3818 * there is at least one dirty extent on this file. queue up background store
3819 * requests for contiguous blocks
3821 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3822 if (ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart == offset.QuadPart + length &&
3823 length + cm_data.buf_blockSize <= cm_chunkSize)
3825 length += cm_data.buf_blockSize;
3827 if (!(offset.QuadPart == 0 && length == 0))
3828 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3829 length, 0, userp, &req);
3830 offset.QuadPart = ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart;
3831 length = cm_data.buf_blockSize;
3834 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3835 length, 0, userp, &req);
3838 cm_ReleaseSCache(scp);
3841 osi_Log5(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
3842 FileId.Cell, FileId.Volume,
3843 FileId.Vnode, FileId.Unique, released);
3844 if (code && code != CM_ERROR_WOULDBLOCK) {
3845 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3846 (*ResultCB)->ResultStatus = status;
3847 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents FAILURE code=0x%x status=0x%x",
3850 (*ResultCB)->ResultStatus = 0;
3851 osi_Log0(afsd_logp, "RDR_ReleaseFileExtents SUCCESS");
3853 (*ResultCB)->ResultBufferLength = 0;
3859 RDR_ProcessReleaseFileExtentsResult( IN AFSReleaseFileExtentsResultCB *ReleaseFileExtentsResultCB,
3860 IN DWORD ResultBufferLength)
3862 afs_uint32 code = 0;
3866 unsigned int fileno, extentno, total_extents = 0;
3867 AFSReleaseFileExtentsResultFileCB *pNextFileCB;
3869 #ifdef VALIDATE_CHECK_SUM
3870 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3876 for ( fileno = 0, pNextFileCB = &ReleaseFileExtentsResultCB->Files[0];
3877 fileno < ReleaseFileExtentsResultCB->FileCount;
3879 AFSReleaseFileExtentsResultFileCB *pFileCB = pNextFileCB;
3880 cm_user_t *userp = NULL;
3882 cm_scache_t * scp = NULL;
3887 userp = RDR_UserFromAuthGroup( &pFileCB->AuthGroup);
3889 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult %d.%d.%d.%d",
3890 pFileCB->FileId.Cell, pFileCB->FileId.Volume,
3891 pFileCB->FileId.Vnode, pFileCB->FileId.Unique);
3893 /* Process the release */
3894 Fid.cell = pFileCB->FileId.Cell;
3895 Fid.volume = pFileCB->FileId.Volume;
3896 Fid.vnode = pFileCB->FileId.Vnode;
3897 Fid.unique = pFileCB->FileId.Unique;
3898 Fid.hash = pFileCB->FileId.Hash;
3900 if (Fid.cell == 0) {
3901 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult Invalid FID %d.%d.%d.%d",
3902 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
3903 code = CM_ERROR_INVAL;
3907 code = cm_GetSCache(&Fid, &scp, userp, &req);
3909 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult cm_GetSCache FID failure code=0x%x",
3912 * A failure to find the cm_scache object cannot prevent the service
3913 * from accepting the extents back from the redirector.
3917 /* if the scp was not found, do not perform the length check */
3918 if (scp && (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart)) {
3921 memset(&setAttr, 0, sizeof(cm_attr_t));
3922 lock_ObtainWrite(&scp->rw);
3923 if (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3924 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult length change vol 0x%x vno 0x%x length 0x%x:%x",
3925 scp->fid.volume, scp->fid.vnode,
3926 pFileCB->AllocationSize.HighPart,
3927 pFileCB->AllocationSize.LowPart);
3928 setAttr.mask |= CM_ATTRMASK_LENGTH;
3929 setAttr.length.LowPart = pFileCB->AllocationSize.LowPart;
3930 setAttr.length.HighPart = pFileCB->AllocationSize.HighPart;
3932 lock_ReleaseWrite(&scp->rw);
3934 code = cm_SetAttr(scp, &setAttr, userp, &req);
3937 for ( extentno = 0; extentno < pFileCB->ExtentCount; total_extents++, extentno++ ) {
3938 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
3940 thyper.QuadPart = pExtent->FileOffset.QuadPart;
3942 bufp = buf_Find(&Fid, &thyper);
3944 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
3945 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3946 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3947 Fid.volume, Fid.vnode,
3948 pExtent->FileOffset.HighPart,
3949 pExtent->FileOffset.LowPart);
3950 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
3951 pExtent->CacheOffset.HighPart,
3952 pExtent->CacheOffset.LowPart);
3954 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3955 Fid.volume, Fid.vnode,
3956 pExtent->FileOffset.HighPart,
3957 pExtent->FileOffset.LowPart);
3958 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
3959 pExtent->CacheOffset.HighPart,
3960 pExtent->CacheOffset.LowPart);
3966 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
3967 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3968 Fid.volume, Fid.vnode,
3969 pExtent->FileOffset.HighPart,
3970 pExtent->FileOffset.LowPart);
3971 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
3972 pExtent->CacheOffset.HighPart,
3973 pExtent->CacheOffset.LowPart);
3975 /* Move the buffer to the front of the queue */
3976 lock_ObtainWrite(&buf_globalLock);
3977 buf_MoveToHeadOfRedirQueue(scp, bufp);
3978 lock_ReleaseWrite(&buf_globalLock);
3983 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
3984 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3985 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3986 Fid.volume, Fid.vnode,
3987 pExtent->FileOffset.HighPart,
3988 pExtent->FileOffset.LowPart);
3989 osi_Log2(afsd_logp, "... coffset 0x%x:%x not held by file system",
3990 pExtent->CacheOffset.HighPart,
3991 pExtent->CacheOffset.LowPart);
3993 snprintf(dbgstr, 1024,
3994 "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",
3995 ReleaseFileExtentsResultCB->Flags, pExtent->Flags,
3996 Fid.volume, Fid.vnode, Fid.unique,
3997 pExtent->FileOffset.HighPart,
3998 pExtent->FileOffset.LowPart,
3999 pExtent->CacheOffset.HighPart,
4000 pExtent->CacheOffset.LowPart);
4001 OutputDebugStringA( dbgstr);
4004 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4005 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4006 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4008 if (pExtent->Flags || ReleaseFileExtentsResultCB->Flags) {
4009 lock_ObtainMutex(&bufp->mx);
4010 if ( (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
4011 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
4013 if (bufp->qFlags & CM_BUF_QREDIR) {
4014 lock_ObtainWrite(&buf_globalLock);
4015 if (bufp->qFlags & CM_BUF_QREDIR) {
4016 buf_RemoveFromRedirQueue(scp, bufp);
4017 buf_ReleaseLocked(bufp, TRUE);
4019 lock_ReleaseWrite(&buf_globalLock);
4023 snprintf(dbgstr, 1024,
4024 "RDR_ProcessReleaseFileExtentsResult extent released: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4025 Fid.volume, Fid.vnode, Fid.unique,
4026 pExtent->FileOffset.HighPart,
4027 pExtent->FileOffset.LowPart,
4028 pExtent->CacheOffset.HighPart,
4029 pExtent->CacheOffset.LowPart);
4030 OutputDebugStringA( dbgstr);
4035 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
4036 Fid.volume, Fid.vnode,
4037 pExtent->FileOffset.HighPart,
4038 pExtent->FileOffset.LowPart);
4039 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4040 pExtent->CacheOffset.HighPart,
4041 pExtent->CacheOffset.LowPart);
4043 snprintf(dbgstr, 1024,
4044 "RDR_ProcessReleaseFileExtentsResult not released! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4045 Fid.volume, Fid.vnode, Fid.unique,
4046 pExtent->FileOffset.HighPart,
4047 pExtent->FileOffset.LowPart,
4048 pExtent->CacheOffset.HighPart,
4049 pExtent->CacheOffset.LowPart);
4050 OutputDebugStringA( dbgstr);
4054 if ( (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
4055 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY) )
4057 #ifdef VALIDATE_CHECK_SUM
4058 if ( buf_ValidateCheckSum(bufp) ) {
4060 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4061 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4062 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
4064 buf_ComputeCheckSum(bufp);
4066 HexCheckSum(md5dbg3, sizeof(md5dbg), bufp->md5cksum);
4068 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4070 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
4073 snprintf(dbgstr, 1024,
4074 "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",
4076 Fid.volume, Fid.vnode, Fid.unique,
4077 pExtent->FileOffset.HighPart,
4078 pExtent->FileOffset.LowPart,
4079 pExtent->CacheOffset.HighPart,
4080 pExtent->CacheOffset.LowPart);
4081 OutputDebugStringA( dbgstr);
4084 "RDR_ProcessReleaseFileExtentsResult dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
4085 Fid.volume, Fid.vnode,
4086 pExtent->FileOffset.HighPart,
4087 pExtent->FileOffset.LowPart);
4089 "... coffset 0x%x:%x",
4090 pExtent->CacheOffset.HighPart,
4091 pExtent->CacheOffset.LowPart);
4093 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4097 snprintf(dbgstr, 1024,
4098 "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",
4099 md5dbg, md5dbg2, md5dbg3,
4100 Fid.volume, Fid.vnode, Fid.unique,
4101 pExtent->FileOffset.HighPart,
4102 pExtent->FileOffset.LowPart,
4103 pExtent->CacheOffset.HighPart,
4104 pExtent->CacheOffset.LowPart);
4105 OutputDebugStringA( dbgstr);
4108 "RDR_ProcessReleaseFileExtentsResult dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
4109 Fid.volume, Fid.vnode,
4110 pExtent->FileOffset.HighPart,
4111 pExtent->FileOffset.LowPart);
4113 "... coffset 0x%x:%x",
4114 pExtent->CacheOffset.HighPart,
4115 pExtent->CacheOffset.LowPart);
4119 #else /* !VALIDATE_CHECK_SUM */
4120 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4123 snprintf(dbgstr, 1024,
4124 "RDR_ProcessReleaseFileExtentsResult dirty! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4125 Fid.volume, Fid.vnode, Fid.unique,
4126 pExtent->FileOffset.HighPart,
4127 pExtent->FileOffset.LowPart,
4128 pExtent->CacheOffset.HighPart,
4129 pExtent->CacheOffset.LowPart);
4130 OutputDebugStringA( dbgstr);
4132 #endif /* VALIDATE_CHECK_SUM */
4134 #ifdef VALIDATE_CHECK_SUM
4137 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4139 if ( !buf_ValidateCheckSum(bufp) ) {
4140 buf_ComputeCheckSum(bufp);
4142 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4143 snprintf(dbgstr, 1024,
4144 "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",
4146 Fid.volume, Fid.vnode, Fid.unique,
4147 pExtent->FileOffset.HighPart,
4148 pExtent->FileOffset.LowPart,
4149 pExtent->CacheOffset.HighPart,
4150 pExtent->CacheOffset.LowPart);
4151 OutputDebugStringA( dbgstr);
4153 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult dirty flag NOT set but extent has changed! vol 0x%x vno 0x%x foffset 0x%x:%x",
4154 Fid.volume, Fid.vnode,
4155 pExtent->FileOffset.HighPart,
4156 pExtent->FileOffset.LowPart);
4157 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4158 pExtent->CacheOffset.HighPart,
4159 pExtent->CacheOffset.LowPart);
4163 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4166 buf_ComputeCheckSum(bufp);
4168 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4169 snprintf(dbgstr, 1024,
4170 "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",
4172 Fid.volume, Fid.vnode, Fid.unique,
4173 pExtent->FileOffset.HighPart,
4174 pExtent->FileOffset.LowPart,
4175 pExtent->CacheOffset.HighPart,
4176 pExtent->CacheOffset.LowPart);
4177 OutputDebugStringA( dbgstr);
4181 #endif /* VALIDATE_CHECK_SUM */
4182 lock_ReleaseMutex(&bufp->mx);
4186 /* CacheOffset doesn't match bufp->datap */
4187 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
4190 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
4191 if (wbp->datap == datap)
4196 snprintf(dbgstr, 1024,
4197 "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",
4198 Fid.volume, Fid.vnode, Fid.unique,
4199 pExtent->FileOffset.HighPart,
4200 pExtent->FileOffset.LowPart,
4201 pExtent->CacheOffset.HighPart,
4202 pExtent->CacheOffset.LowPart,
4204 OutputDebugStringA( dbgstr);
4206 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4207 Fid.volume, Fid.vnode,
4208 pExtent->FileOffset.HighPart,
4209 pExtent->FileOffset.LowPart);
4210 osi_Log3(afsd_logp, "... coffset 0x%x:%x flags 0x%x",
4211 pExtent->CacheOffset.HighPart,
4212 pExtent->CacheOffset.LowPart,
4215 osi_Log5(afsd_logp, "... coffset belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
4216 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
4218 osi_Log0(afsd_logp, "... coffset cannot be found");
4225 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4226 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4227 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
4228 pExtent->FileOffset.LowPart);
4229 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; cm_buf not found -- recycled?",
4230 pExtent->CacheOffset.HighPart,
4231 pExtent->CacheOffset.LowPart);
4237 snprintf(dbgstr, 1024,
4238 "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4239 Fid.volume, Fid.vnode, Fid.unique,
4240 pExtent->FileOffset.HighPart,
4241 pExtent->FileOffset.LowPart,
4242 pExtent->CacheOffset.HighPart,
4243 pExtent->CacheOffset.LowPart);
4244 OutputDebugStringA( dbgstr);
4246 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x foffset 0x%x:%x",
4247 Fid.volume, Fid.vnode,
4248 pExtent->FileOffset.HighPart,
4249 pExtent->FileOffset.LowPart);
4250 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4251 pExtent->CacheOffset.HighPart,
4252 pExtent->CacheOffset.LowPart);
4257 osi_hyper_t offset = {0,0};
4258 afs_uint32 length = 0;
4261 * there is at least one dirty extent on this file. queue up background store
4262 * requests for contiguous blocks
4264 for ( extentno = 0; extentno < pFileCB->ExtentCount; extentno++ ) {
4265 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4266 if (pExtent->FileOffset.QuadPart == offset.QuadPart + length &&
4267 length < cm_chunkSize) {
4268 length += cm_data.buf_blockSize;
4270 if (!(offset.QuadPart == 0 && length == 0))
4271 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4272 length, 0, userp, &req);
4273 offset.QuadPart = pExtent->FileOffset.QuadPart;
4274 length = cm_data.buf_blockSize;
4277 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4278 length, 0, userp, &req);
4281 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
4282 Fid.cell, Fid.volume, Fid.vnode, Fid.unique, released);
4286 cm_ReleaseUser(userp);
4288 cm_ReleaseSCache(scp);
4290 p = (char *)pFileCB;
4291 p += sizeof(AFSReleaseFileExtentsResultFileCB);
4292 p += sizeof(AFSFileExtentCB) * (pFileCB->ExtentCount - 1);
4293 pNextFileCB = (AFSReleaseFileExtentsResultFileCB *)p;
4296 if (total_extents == 0) {
4297 osi_Log0(afsd_logp, "RDR_ProcessReleaseFileExtentsResult is empty");
4298 code = CM_ERROR_RETRY;
4302 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult FAILURE code=0x%x", code);
4304 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult DONE code=0x%x", code);
4310 RDR_ReleaseFailedSetFileExtents( IN cm_user_t *userp,
4311 IN AFSSetFileExtentsCB *SetFileExtentsResultCB,
4312 IN DWORD ResultBufferLength)
4314 afs_uint32 code = 0;
4316 unsigned int extentno;
4318 cm_scache_t * scp = NULL;
4323 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFileExtents %d.%d.%d.%d",
4324 SetFileExtentsResultCB->FileId.Cell, SetFileExtentsResultCB->FileId.Volume,
4325 SetFileExtentsResultCB->FileId.Vnode, SetFileExtentsResultCB->FileId.Unique);
4327 /* Process the release */
4328 Fid.cell = SetFileExtentsResultCB->FileId.Cell;
4329 Fid.volume = SetFileExtentsResultCB->FileId.Volume;
4330 Fid.vnode = SetFileExtentsResultCB->FileId.Vnode;
4331 Fid.unique = SetFileExtentsResultCB->FileId.Unique;
4332 Fid.hash = SetFileExtentsResultCB->FileId.Hash;
4334 if (Fid.cell == 0) {
4335 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFile Invalid FID %d.%d.%d.%d",
4336 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
4337 code = CM_ERROR_INVAL;
4341 code = cm_GetSCache(&Fid, &scp, userp, &req);
4343 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents cm_GetSCache FID failure code=0x%x",
4345 /* Failure to find the cm_scache object cannot block return of the extents */
4348 for ( extentno = 0; extentno < SetFileExtentsResultCB->ExtentCount; extentno++ ) {
4351 AFSFileExtentCB *pExtent = &SetFileExtentsResultCB->FileExtents[extentno];
4353 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4355 bufp = buf_Find(&Fid, &thyper);
4357 osi_Log5(afsd_logp, "RDR_ReleaseFailedSetFileExtents bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4358 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4359 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4361 lock_ObtainMutex(&bufp->mx);
4362 if (bufp->qFlags & CM_BUF_QREDIR) {
4363 lock_ObtainWrite(&buf_globalLock);
4364 if (bufp->qFlags & CM_BUF_QREDIR) {
4365 buf_RemoveFromRedirQueue(scp, bufp);
4366 buf_ReleaseLocked(bufp, TRUE);
4368 lock_ReleaseWrite(&buf_globalLock);
4370 lock_ReleaseMutex(&bufp->mx);
4377 cm_ReleaseUser(userp);
4379 cm_ReleaseSCache(scp);
4381 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents DONE code=0x%x", code);
4386 RDR_PioctlOpen( IN cm_user_t *userp,
4387 IN AFSFileID ParentId,
4388 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4390 IN DWORD ResultBufferLength,
4391 IN OUT AFSCommResult **ResultCB)
4396 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4402 sizeof( AFSCommResult));
4404 /* Get the active directory */
4405 ParentFid.cell = ParentId.Cell;
4406 ParentFid.volume = ParentId.Volume;
4407 ParentFid.vnode = ParentId.Vnode;
4408 ParentFid.unique = ParentId.Unique;
4409 ParentFid.hash = ParentId.Hash;
4411 /* Get the root directory */
4412 RootFid.cell = pPioctlCB->RootId.Cell;
4413 RootFid.volume = pPioctlCB->RootId.Volume;
4414 RootFid.vnode = pPioctlCB->RootId.Vnode;
4415 RootFid.unique = pPioctlCB->RootId.Unique;
4416 RootFid.hash = pPioctlCB->RootId.Hash;
4418 /* Create the pioctl index */
4419 RDR_SetupIoctl(pPioctlCB->RequestId, &ParentFid, &RootFid, userp);
4426 RDR_PioctlClose( IN cm_user_t *userp,
4427 IN AFSFileID ParentId,
4428 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4430 IN DWORD ResultBufferLength,
4431 IN OUT AFSCommResult **ResultCB)
4433 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4439 sizeof( AFSCommResult));
4441 /* Cleanup the pioctl index */
4442 RDR_CleanupIoctl(pPioctlCB->RequestId);
4449 RDR_PioctlWrite( IN cm_user_t *userp,
4450 IN AFSFileID ParentId,
4451 IN AFSPIOCtlIORequestCB *pPioctlCB,
4453 IN DWORD ResultBufferLength,
4454 IN OUT AFSCommResult **ResultCB)
4456 AFSPIOCtlIOResultCB *pResultCB;
4457 cm_scache_t *dscp = NULL;
4464 req.flags |= CM_REQ_WOW64;
4466 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4472 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4474 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4476 code = RDR_IoctlWrite(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer, &req);
4478 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4479 (*ResultCB)->ResultStatus = status;
4483 pResultCB->BytesProcessed = pPioctlCB->BufferLength;
4484 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4488 RDR_PioctlRead( IN cm_user_t *userp,
4489 IN AFSFileID ParentId,
4490 IN AFSPIOCtlIORequestCB *pPioctlCB,
4492 IN BOOL bIsLocalSystem,
4493 IN DWORD ResultBufferLength,
4494 IN OUT AFSCommResult **ResultCB)
4496 AFSPIOCtlIOResultCB *pResultCB;
4497 cm_scache_t *dscp = NULL;
4501 afs_uint32 pflags = (bIsLocalSystem ? AFSCALL_FLAG_LOCAL_SYSTEM : 0);
4505 req.flags |= CM_REQ_WOW64;
4507 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4513 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4515 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4517 code = RDR_IoctlRead(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer,
4518 &pResultCB->BytesProcessed, &req, pflags);
4520 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4521 (*ResultCB)->ResultStatus = status;
4525 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4529 RDR_ByteRangeLockSync( IN cm_user_t *userp,
4530 IN AFSFileID FileId,
4531 IN AFSByteRangeLockRequestCB *pBRLRequestCB,
4533 IN DWORD ResultBufferLength,
4534 IN OUT AFSCommResult **ResultCB)
4536 AFSByteRangeLockResultCB *pResultCB = NULL;
4537 LARGE_INTEGER ProcessId;
4539 cm_scache_t *scp = NULL;
4547 ProcessId.QuadPart = pBRLRequestCB->ProcessId;
4551 req.flags |= CM_REQ_WOW64;
4553 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4554 FileId.Cell, FileId.Volume,
4555 FileId.Vnode, FileId.Unique);
4556 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4557 ProcessId.HighPart, ProcessId.LowPart);
4559 Length = sizeof( AFSByteRangeLockResultCB) + ((pBRLRequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4560 if (Length > ResultBufferLength) {
4561 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4564 memset( *ResultCB, 0, sizeof(AFSCommResult));
4565 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4569 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4572 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4573 (*ResultCB)->ResultBufferLength = Length;
4575 pResultCB = (AFSByteRangeLockResultCB *)(*ResultCB)->ResultData;
4576 pResultCB->FileId = FileId;
4577 pResultCB->Count = pBRLRequestCB->Count;
4579 /* Allocate the extents from the buffer package */
4580 Fid.cell = FileId.Cell;
4581 Fid.volume = FileId.Volume;
4582 Fid.vnode = FileId.Vnode;
4583 Fid.unique = FileId.Unique;
4584 Fid.hash = FileId.Hash;
4586 code = cm_GetSCache(&Fid, &scp, userp, &req);
4588 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4589 (*ResultCB)->ResultStatus = status;
4590 (*ResultCB)->ResultBufferLength = 0;
4591 osi_Log2(afsd_logp, "RDR_ByteRangeLockSync cm_GetSCache FID failure code=0x%x status=0x%x",
4596 lock_ObtainWrite(&scp->rw);
4598 /* start by looking up the file's end */
4599 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4600 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4602 lock_ReleaseWrite(&scp->rw);
4603 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4604 (*ResultCB)->ResultStatus = status;
4605 (*ResultCB)->ResultBufferLength = 0;
4606 osi_Log3(afsd_logp, "RDR_ByteRangeLockSync cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4611 /* the scp is now locked and current */
4612 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4614 for ( i=0; i<pBRLRequestCB->Count; i++ ) {
4615 pResultCB->Result[i].LockType = pBRLRequestCB->Request[i].LockType;
4616 pResultCB->Result[i].Offset = pBRLRequestCB->Request[i].Offset;
4617 pResultCB->Result[i].Length = pBRLRequestCB->Request[i].Length;
4620 pBRLRequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4621 pBRLRequestCB->Request[i].Offset,
4622 pBRLRequestCB->Request[i].Length,
4623 key, 0, userp, &req, NULL);
4626 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4628 pBRLRequestCB->Request[i].LockType,
4629 pBRLRequestCB->Request[i].Offset.HighPart,
4630 pBRLRequestCB->Request[i].Offset.LowPart);
4631 osi_Log2(afsd_logp, "... length 0x%x:%x",
4632 pBRLRequestCB->Request[i].Length.HighPart,
4633 pBRLRequestCB->Request[i].Length.LowPart);
4638 pResultCB->Result[i].Status = 0;
4640 case CM_ERROR_WOULDBLOCK:
4641 pResultCB->Result[i].Status = STATUS_FILE_LOCK_CONFLICT;
4644 pResultCB->Result[i].Status = STATUS_LOCK_NOT_GRANTED;
4648 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4649 lock_ReleaseWrite(&scp->rw);
4650 cm_ReleaseSCache(scp);
4652 (*ResultCB)->ResultStatus = 0;
4653 osi_Log0(afsd_logp, "RDR_ByteRangeLockSync SUCCESS");
4658 RDR_ByteRangeUnlock( IN cm_user_t *userp,
4659 IN AFSFileID FileId,
4660 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4662 IN DWORD ResultBufferLength,
4663 IN OUT AFSCommResult **ResultCB)
4665 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4666 LARGE_INTEGER ProcessId;
4668 cm_scache_t *scp = NULL;
4676 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4680 req.flags |= CM_REQ_WOW64;
4682 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4683 FileId.Cell, FileId.Volume,
4684 FileId.Vnode, FileId.Unique);
4685 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4686 ProcessId.HighPart, ProcessId.LowPart);
4688 Length = sizeof( AFSByteRangeUnlockResultCB) + ((pBRURequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4689 if (Length > ResultBufferLength) {
4690 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4693 memset( *ResultCB, 0, sizeof(AFSCommResult));
4694 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4698 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4701 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4702 (*ResultCB)->ResultBufferLength = Length;
4704 pResultCB = (AFSByteRangeUnlockResultCB *)(*ResultCB)->ResultData;
4705 pResultCB->Count = pBRURequestCB->Count;
4707 /* Allocate the extents from the buffer package */
4708 Fid.cell = FileId.Cell;
4709 Fid.volume = FileId.Volume;
4710 Fid.vnode = FileId.Vnode;
4711 Fid.unique = FileId.Unique;
4712 Fid.hash = FileId.Hash;
4714 code = cm_GetSCache(&Fid, &scp, userp, &req);
4716 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4717 (*ResultCB)->ResultStatus = status;
4718 (*ResultCB)->ResultBufferLength = 0;
4719 osi_Log2(afsd_logp, "RDR_ByteRangeUnlock cm_GetSCache FID failure code=0x%x status=0x%x",
4724 lock_ObtainWrite(&scp->rw);
4726 /* start by looking up the file's end */
4727 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4728 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4730 lock_ReleaseWrite(&scp->rw);
4731 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4732 (*ResultCB)->ResultStatus = status;
4733 (*ResultCB)->ResultBufferLength = 0;
4734 osi_Log3(afsd_logp, "RDR_ByteRangeUnlock cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4739 /* the scp is now locked and current */
4740 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4742 for ( i=0; i<pBRURequestCB->Count; i++ ) {
4743 pResultCB->Result[i].LockType = pBRURequestCB->Request[i].LockType;
4744 pResultCB->Result[i].Offset = pBRURequestCB->Request[i].Offset;
4745 pResultCB->Result[i].Length = pBRURequestCB->Request[i].Length;
4747 code = cm_Unlock(scp,
4748 pBRURequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4749 pBRURequestCB->Request[i].Offset,
4750 pBRURequestCB->Request[i].Length,
4751 key, CM_UNLOCK_FLAG_MATCH_RANGE, userp, &req);
4754 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4755 code, pBRURequestCB->Request[i].LockType,
4756 pBRURequestCB->Request[i].Offset.HighPart,
4757 pBRURequestCB->Request[i].Offset.LowPart);
4758 osi_Log2(afsd_logp, "... length 0x%x:%x",
4759 pBRURequestCB->Request[i].Length.HighPart,
4760 pBRURequestCB->Request[i].Length.LowPart);
4762 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4763 pResultCB->Result[i].Status = status;
4766 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4767 lock_ReleaseWrite(&scp->rw);
4768 cm_ReleaseSCache(scp);
4770 (*ResultCB)->ResultStatus = 0;
4771 osi_Log0(afsd_logp, "RDR_ByteRangeUnlock SUCCESS");
4776 RDR_ByteRangeUnlockAll( IN cm_user_t *userp,
4777 IN AFSFileID FileId,
4778 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4780 IN DWORD ResultBufferLength,
4781 IN OUT AFSCommResult **ResultCB)
4783 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4784 LARGE_INTEGER ProcessId;
4785 cm_scache_t *scp = NULL;
4792 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4796 req.flags |= CM_REQ_WOW64;
4798 osi_Log4(afsd_logp, "RDR_ByteRangeUnlockAll File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4799 FileId.Cell, FileId.Volume,
4800 FileId.Vnode, FileId.Unique);
4801 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4802 ProcessId.HighPart, ProcessId.LowPart);
4804 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4807 memset( *ResultCB, '\0', sizeof( AFSCommResult));
4808 (*ResultCB)->ResultBufferLength = 0;
4810 /* Allocate the extents from the buffer package */
4811 Fid.cell = FileId.Cell;
4812 Fid.volume = FileId.Volume;
4813 Fid.vnode = FileId.Vnode;
4814 Fid.unique = FileId.Unique;
4815 Fid.hash = FileId.Hash;
4817 code = cm_GetSCache(&Fid, &scp, userp, &req);
4819 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4820 (*ResultCB)->ResultStatus = status;
4821 (*ResultCB)->ResultBufferLength = 0;
4822 osi_Log2(afsd_logp, "RDR_ByteRangeUnlockAll cm_GetSCache FID failure code=0x%x status=0x%x",
4827 lock_ObtainWrite(&scp->rw);
4829 /* start by looking up the file's end */
4830 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4831 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4833 lock_ReleaseWrite(&scp->rw);
4834 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4835 (*ResultCB)->ResultStatus = status;
4836 (*ResultCB)->ResultBufferLength = 0;
4837 osi_Log3(afsd_logp, "RDR_ByteRangeUnlockAll cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4842 /* the scp is now locked and current */
4843 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4845 code = cm_UnlockByKey(scp, key, 0, userp, &req);
4847 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4848 lock_ReleaseWrite(&scp->rw);
4849 cm_ReleaseSCache(scp);
4851 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4852 (*ResultCB)->ResultStatus = status;
4855 osi_Log1(afsd_logp, "RDR_ByteRangeUnlockAll FAILURE code 0x%x", code);
4857 osi_Log0(afsd_logp, "RDR_ByteRangeUnlockAll SUCCESS");
4863 RDR_GetVolumeInfo( IN cm_user_t *userp,
4864 IN AFSFileID FileId,
4866 IN DWORD ResultBufferLength,
4867 IN OUT AFSCommResult **ResultCB)
4869 AFSVolumeInfoCB *pResultCB = NULL;
4871 cm_scache_t *scp = NULL;
4872 cm_volume_t *volp = NULL;
4873 cm_vol_state_t *volstatep = NULL;
4875 cm_cell_t *cellp = NULL;
4880 FILETIME ft = {0x832cf000, 0x01abfcc4}; /* October 1, 1982 00:00:00 +0600 */
4882 char volName[32]="(unknown)";
4883 char offLineMsg[256]="server temporarily inaccessible";
4884 char motd[256]="server temporarily inaccessible";
4886 AFSFetchVolumeStatus volStat;
4890 struct rx_connection * rxconnp;
4894 req.flags |= CM_REQ_WOW64;
4896 osi_Log4(afsd_logp, "RDR_GetVolumeInfo File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4897 FileId.Cell, FileId.Volume,
4898 FileId.Vnode, FileId.Unique);
4900 Length = sizeof( AFSCommResult) + sizeof(AFSVolumeInfoCB);
4901 if (sizeof(AFSVolumeInfoCB) > ResultBufferLength) {
4902 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
4905 memset( *ResultCB, 0, sizeof(AFSCommResult));
4906 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4910 *ResultCB = (AFSCommResult *)malloc( Length );
4913 memset( *ResultCB, '\0', Length );
4914 (*ResultCB)->ResultBufferLength = sizeof(AFSVolumeInfoCB);
4915 pResultCB = (AFSVolumeInfoCB *)(*ResultCB)->ResultData;
4917 /* Allocate the extents from the buffer package */
4918 if (FileId.Cell != 0) {
4919 Fid.cell = FileId.Cell;
4920 Fid.volume = FileId.Volume;
4921 Fid.vnode = FileId.Vnode;
4922 Fid.unique = FileId.Unique;
4923 Fid.hash = FileId.Hash;
4925 code = cm_GetSCache(&Fid, &scp, userp, &req);
4927 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4928 (*ResultCB)->ResultStatus = status;
4929 (*ResultCB)->ResultBufferLength = 0;
4930 osi_Log2(afsd_logp, "RDR_GetVolumeInfo cm_GetSCache FID failure code=0x%x status=0x%x",
4935 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
4936 osi_Log0(afsd_logp, "RDR_GetVolumeInfo Object Name Invalid - Cell = 0");
4939 lock_ObtainWrite(&scp->rw);
4941 /* start by looking up the file's end */
4942 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4943 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
4945 lock_ReleaseWrite(&scp->rw);
4946 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4947 (*ResultCB)->ResultStatus = status;
4948 (*ResultCB)->ResultBufferLength = 0;
4949 osi_Log3(afsd_logp, "RDR_GetVolumeInfo cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4955 pResultCB->SectorsPerAllocationUnit = 1;
4956 pResultCB->BytesPerSector = 1024;
4958 pResultCB->CellID = scp->fid.cell;
4959 pResultCB->VolumeID = scp->fid.volume;
4960 pResultCB->Characteristics = FILE_REMOTE_DEVICE;
4961 pResultCB->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK |
4962 FILE_SUPPORTS_REPARSE_POINTS;
4964 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
4965 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)
4967 pResultCB->TotalAllocationUnits.QuadPart = 100;
4968 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
4970 pResultCB->AvailableAllocationUnits.QuadPart = 0;
4971 pResultCB->Characteristics |= FILE_READ_ONLY_DEVICE;
4973 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( "Freelance.Local.Root", -1, pResultCB->VolumeLabel,
4974 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
4975 if ( pResultCB->VolumeLabelLength )
4976 pResultCB->VolumeLabelLength--;
4978 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
4980 volp = cm_GetVolumeByFID(&scp->fid);
4982 code = CM_ERROR_NOSUCHVOLUME;
4985 volstatep = cm_VolumeStateByID(volp, scp->fid.volume);
4986 volType = cm_VolumeType(volp, scp->fid.volume);
4988 pResultCB->Characteristics |= ((volType == ROVOL || volType == BACKVOL) ? FILE_READ_ONLY_DEVICE : 0);
4991 OfflineMsg = offLineMsg;
4993 lock_ReleaseWrite(&scp->rw);
4995 code = cm_ConnFromFID(&scp->fid, userp, &req, &connp);
4998 rxconnp = cm_GetRxConn(connp);
4999 code = RXAFS_GetVolumeStatus(rxconnp, scp->fid.volume,
5000 &volStat, &Name, &OfflineMsg, &MOTD);
5001 rx_PutConnection(rxconnp);
5003 } while (cm_Analyze(connp, userp, &req, &scp->fid, NULL, NULL, NULL, code));
5004 code = cm_MapRPCError(code, &req);
5006 pResultCB->TotalAllocationUnits.QuadPart = volStat.PartMaxBlocks;
5007 pResultCB->AvailableAllocationUnits.QuadPart = volStat.PartBlocksAvail;
5009 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( Name, -1, pResultCB->VolumeLabel,
5010 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5012 pResultCB->TotalAllocationUnits.QuadPart = 0x7FFFFFFF;
5013 pResultCB->AvailableAllocationUnits.QuadPart = (volType == ROVOL || volType == BACKVOL) ? 0 : 0x3F000000;
5015 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( volp->namep, -1, pResultCB->VolumeLabel,
5016 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5019 if ( pResultCB->VolumeLabelLength )
5020 pResultCB->VolumeLabelLength--;
5022 lock_ObtainWrite(&scp->rw);
5024 pResultCB->VolumeLabelLength *= sizeof(WCHAR); /* convert to bytes from chars */
5026 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5029 lock_ReleaseWrite(&scp->rw);
5032 cm_ReleaseSCache(scp);
5034 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5035 (*ResultCB)->ResultStatus = status;
5036 osi_Log0(afsd_logp, "RDR_GetVolumeInfo SUCCESS");
5041 RDR_HoldFid( IN cm_user_t *userp,
5042 IN AFSHoldFidRequestCB * pHoldFidCB,
5044 IN DWORD ResultBufferLength,
5045 IN OUT AFSCommResult **ResultCB)
5047 AFSHoldFidResultCB *pResultCB = NULL;
5054 osi_Log1(afsd_logp, "RDR_HoldFid Count=%u", pHoldFidCB->Count);
5056 Length = sizeof(AFSHoldFidResultCB) + (pHoldFidCB->Count-1) * sizeof(AFSFidResult);
5057 if (Length > ResultBufferLength) {
5058 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5061 memset( *ResultCB, 0, sizeof(AFSCommResult));
5062 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5065 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5068 memset( *ResultCB, '\0', Length );
5069 (*ResultCB)->ResultBufferLength = Length;
5070 pResultCB = (AFSHoldFidResultCB *)(*ResultCB)->ResultData;
5072 for ( index = 0; index < pHoldFidCB->Count; index++ )
5074 cm_scache_t *scp = NULL;
5077 Fid.cell = pResultCB->Result[index].FileID.Cell = pHoldFidCB->FileID[index].Cell;
5078 Fid.volume = pResultCB->Result[index].FileID.Volume = pHoldFidCB->FileID[index].Volume;
5079 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pHoldFidCB->FileID[index].Vnode;
5080 Fid.unique = pResultCB->Result[index].FileID.Unique = pHoldFidCB->FileID[index].Unique;
5081 Fid.hash = pResultCB->Result[index].FileID.Hash = pHoldFidCB->FileID[index].Hash;
5083 osi_Log4( afsd_logp,
5084 "RDR_HoldFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5085 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5087 scp = cm_FindSCache(&Fid);
5089 RDR_FlagScpInUse( scp, FALSE );
5090 cm_ReleaseSCache(scp);
5092 pResultCB->Result[index].Status = 0;
5095 (*ResultCB)->ResultStatus = 0;
5096 osi_Log0(afsd_logp, "RDR_HoldFid SUCCESS");
5101 RDR_ReleaseFid( IN cm_user_t *userp,
5102 IN AFSReleaseFidRequestCB * pReleaseFidCB,
5104 IN DWORD ResultBufferLength,
5105 IN OUT AFSCommResult **ResultCB)
5107 AFSReleaseFidResultCB *pResultCB = NULL;
5114 osi_Log1(afsd_logp, "RDR_ReleaseFid Count=%u", pReleaseFidCB->Count);
5116 Length = sizeof(AFSReleaseFidResultCB) + (pReleaseFidCB->Count ? pReleaseFidCB->Count-1 : 0) * sizeof(AFSFidResult);
5117 if (Length > ResultBufferLength) {
5118 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5121 memset( *ResultCB, 0, sizeof(AFSCommResult));
5122 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5125 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5128 memset( *ResultCB, '\0', Length );
5129 (*ResultCB)->ResultBufferLength = Length;
5130 pResultCB = (AFSReleaseFidResultCB *)(*ResultCB)->ResultData;
5132 for ( index = 0; index < pReleaseFidCB->Count; index++ )
5134 cm_scache_t *scp = NULL;
5137 Fid.cell = pResultCB->Result[index].FileID.Cell = pReleaseFidCB->FileID[index].Cell;
5138 Fid.volume = pResultCB->Result[index].FileID.Volume = pReleaseFidCB->FileID[index].Volume;
5139 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pReleaseFidCB->FileID[index].Vnode;
5140 Fid.unique = pResultCB->Result[index].FileID.Unique = pReleaseFidCB->FileID[index].Unique;
5141 Fid.hash = pResultCB->Result[index].FileID.Hash = pReleaseFidCB->FileID[index].Hash;
5143 osi_Log4( afsd_logp,
5144 "RDR_ReleaseFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5145 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5147 scp = cm_FindSCache(&Fid);
5149 lock_ObtainWrite(&scp->rw);
5150 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
5151 lock_ReleaseWrite(&scp->rw);
5153 cm_ReleaseSCache(scp);
5155 pResultCB->Result[index].Status = 0;
5157 pResultCB->Count = pReleaseFidCB->Count;
5159 (*ResultCB)->ResultStatus = 0;
5160 osi_Log0(afsd_logp, "RDR_ReleaseFid SUCCESS");
5165 * The redirector makes several assumptions regarding the
5166 * SRVSVC and WKSSVC pipes transactions. First, the interface
5167 * versions are those indicated below. Secondly, the encoding
5168 * will be performed using NDR version 2. These assumptions
5169 * may not hold in the future and end-to-end MSRPC Bind
5170 * negotiations may need to be supported. Of course, these
5171 * are the only interface versions that are supported by the
5174 #define MSRPC_PIPE_PREFIX L".\\"
5176 static const UUID MSRPC_SRVSVC_UUID = {0x4B324FC8, 0x1670, 0x01D3,
5177 {0x12, 0x78, 0x5A, 0x47, 0xBF, 0x6E, 0xE1, 0x88}};
5178 #define MSRPC_SRVSVC_NAME L"PIPE\\SRVSVC"
5179 #define MSRPC_SRVSVC_VERS 3
5181 static const UUID MSRPC_WKSSVC_UUID = {0x6BFFD098, 0xA112, 0x3610,
5182 {0x98, 0x33, 0x46, 0xC3, 0xF8, 0x7E, 0x34, 0x5A}};
5183 #define MSRPC_WKSSVC_NAME L"PIPE\\WKSSVC"
5184 #define MSRPC_WKSSVC_VERS 1
5186 static const UUID MSRPC_NDR_UUID = {0x8A885D04, 0x1CEB, 0x11C9,
5187 {0x9F, 0xE8, 0x08, 0x00, 0x2B, 0x10, 0x48, 0x60}};
5188 #define MSRPC_NDR_NAME L"NDR"
5189 #define MSRPC_NDR_VERS 2
5191 extern RPC_IF_HANDLE srvsvc_v3_0_s_ifspec;
5192 extern RPC_IF_HANDLE wkssvc_v1_0_s_ifspec;
5195 RDR_PipeOpen( IN cm_user_t *userp,
5196 IN AFSFileID ParentId,
5198 IN DWORD NameLength,
5199 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5201 IN DWORD ResultBufferLength,
5202 IN OUT AFSCommResult **ResultCB)
5207 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5213 sizeof( AFSCommResult));
5215 /* Get the active directory */
5216 ParentFid.cell = ParentId.Cell;
5217 ParentFid.volume = ParentId.Volume;
5218 ParentFid.vnode = ParentId.Vnode;
5219 ParentFid.unique = ParentId.Unique;
5220 ParentFid.hash = ParentId.Hash;
5222 /* Get the root directory */
5223 RootFid.cell = pPipe_CB->RootId.Cell;
5224 RootFid.volume = pPipe_CB->RootId.Volume;
5225 RootFid.vnode = pPipe_CB->RootId.Vnode;
5226 RootFid.unique = pPipe_CB->RootId.Unique;
5227 RootFid.hash = pPipe_CB->RootId.Hash;
5229 /* Create the pipe index */
5230 (*ResultCB)->ResultStatus =
5231 RDR_SetupPipe( pPipe_CB->RequestId, &ParentFid, &RootFid,
5232 Name, NameLength, userp);
5238 RDR_PipeClose( IN cm_user_t *userp,
5239 IN AFSFileID ParentId,
5240 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5242 IN DWORD ResultBufferLength,
5243 IN OUT AFSCommResult **ResultCB)
5245 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5251 sizeof( AFSCommResult));
5253 /* Cleanup the pipe index */
5254 RDR_CleanupPipe(pPipe_CB->RequestId);
5261 RDR_PipeWrite( IN cm_user_t *userp,
5262 IN AFSFileID ParentId,
5263 IN AFSPipeIORequestCB *pPipe_CB,
5264 IN BYTE *pPipe_Data,
5266 IN DWORD ResultBufferLength,
5267 IN OUT AFSCommResult **ResultCB)
5269 AFSPipeIOResultCB *pResultCB;
5270 cm_scache_t *dscp = NULL;
5277 req.flags |= CM_REQ_WOW64;
5279 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5285 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5287 pResultCB = (AFSPipeIOResultCB *)(*ResultCB)->ResultData;
5289 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_Data, &req, userp);
5291 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5292 (*ResultCB)->ResultStatus = status;
5296 pResultCB->BytesProcessed = pPipe_CB->BufferLength;
5297 (*ResultCB)->ResultBufferLength = sizeof( AFSPipeIOResultCB);
5302 RDR_PipeRead( IN cm_user_t *userp,
5303 IN AFSFileID ParentId,
5304 IN AFSPipeIORequestCB *pPipe_CB,
5306 IN DWORD ResultBufferLength,
5307 IN OUT AFSCommResult **ResultCB)
5310 cm_scache_t *dscp = NULL;
5317 req.flags |= CM_REQ_WOW64;
5319 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5325 sizeof( AFSCommResult));
5327 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5329 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_Data,
5330 &(*ResultCB)->ResultBufferLength, &req, userp);
5332 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5333 (*ResultCB)->ResultStatus = status;
5340 RDR_PipeSetInfo( IN cm_user_t *userp,
5341 IN AFSFileID ParentId,
5342 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5343 IN BYTE *pPipe_Data,
5345 IN DWORD ResultBufferLength,
5346 IN OUT AFSCommResult **ResultCB)
5348 cm_scache_t *dscp = NULL;
5354 req.flags |= CM_REQ_WOW64;
5356 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5362 sizeof( AFSCommResult));
5364 status = RDR_Pipe_SetInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5365 pPipeInfo_CB->BufferLength, pPipe_Data, &req, userp);
5367 (*ResultCB)->ResultStatus = status;
5372 RDR_PipeQueryInfo( IN cm_user_t *userp,
5373 IN AFSFileID ParentId,
5374 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5376 IN DWORD ResultBufferLength,
5377 IN OUT AFSCommResult **ResultCB)
5380 cm_scache_t *dscp = NULL;
5386 req.flags |= CM_REQ_WOW64;
5388 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5394 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5396 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5398 status = RDR_Pipe_QueryInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5399 ResultBufferLength, pPipe_Data,
5400 &(*ResultCB)->ResultBufferLength, &req, userp);
5402 (*ResultCB)->ResultStatus = status;
5406 RDR_PipeTransceive( IN cm_user_t *userp,
5407 IN AFSFileID ParentId,
5408 IN AFSPipeIORequestCB *pPipe_CB,
5409 IN BYTE *pPipe_InData,
5411 IN DWORD ResultBufferLength,
5412 IN OUT AFSCommResult **ResultCB)
5415 * This function processes a Pipe Service request
5416 * that would normally be sent to a LAN Manager server
5417 * across an authenticated SMB-PIPE/MSRPC/SVC request
5418 * stack. The request is being sent here because the
5419 * application (e.g., Explorer Shell or Common Control File
5420 * dialog) believes that because the UNC path it is
5421 * processing has specified a server name that is not
5422 * "." and that the Server is remote and that the Share
5423 * list cannot be obtained using the Network Provider
5426 * The file system driver is faking the Bind-Ack response
5427 * to the MSRPC Bind request but cannot decode the NDR
5428 * encoded Pipe Service requests. For that we will use
5429 * the service's MSRPC module. However, unlike the SMB
5430 * server usage we must fake the MSRPC Bind exchange and
5431 * map the PipeName to an interface instead of using the
5432 * GUID specified in the MSRPC Bind request.
5434 * None of the requests that are being processed by the
5435 * service require authentication. As a result the userp
5436 * parameter will be ignored.
5438 * Although there are dozens of Pipe Services, the only
5439 * ones that we are implementing are WKSSVC and SRVSVC.
5440 * These support NetShareEnum, NetShareGetInfo,
5441 * NetServerGetInfo, and NetWorkstaGetInfo which are
5442 * commonly queried by NET VIEW, the Explorer Shell,
5443 * and the Common Control File dialog.
5445 BYTE *pPipe_OutData;
5446 cm_scache_t *dscp = NULL;
5450 DWORD Length = ResultBufferLength + sizeof( AFSCommResult);
5454 req.flags |= CM_REQ_WOW64;
5456 *ResultCB = (AFSCommResult *)malloc( Length);
5459 memset( *ResultCB, '\0', Length );
5461 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_InData, &req, userp);
5463 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5464 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Write FAILURE code=0x%x status=0x%x",
5466 (*ResultCB)->ResultStatus = status;
5470 pPipe_OutData = (BYTE *)(*ResultCB)->ResultData;
5471 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_OutData,
5472 &(*ResultCB)->ResultBufferLength, &req, userp);
5474 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5475 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Read FAILURE code=0x%x status=0x%x",
5477 (*ResultCB)->ResultStatus = status;
5481 (*ResultCB)->ResultStatus = 0;
5482 osi_Log0(afsd_logp, "RDR_Pipe_Transceive SUCCESS");