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 using
286 * an inline bulk status rpc. cm_BPlusDirEnumBulkStatOne() will
287 * obtain current status for the directory object, the object
288 * which is the focus of the inquiry and as many other objects
289 * in the directory for which there are not callbacks registered
290 * since we are likely to be asked for other objects in the directory.
293 RDR_BulkStatLookup( cm_scache_t *dscp,
298 cm_direnum_t * enump = NULL;
302 code = cm_BeginDirOp(dscp, userp, reqp, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
304 code = cm_BPlusDirEnumerate(dscp, userp, reqp, TRUE, NULL, TRUE, &enump);
306 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BPlusDirEnumerate failure code=0x%x",
311 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BeginDirOp failure code=0x%x",
317 code = cm_BPlusDirEnumBulkStatOne(enump, scp);
319 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BPlusDirEnumBulkStatOne failure code=0x%x",
322 cm_BPlusDirFreeEnumeration(enump);
329 #define RDR_POP_FOLLOW_MOUNTPOINTS 0x01
330 #define RDR_POP_EVALUATE_SYMLINKS 0x02
331 #define RDR_POP_WOW64 0x04
332 #define RDR_POP_NO_GETSTATUS 0x08
335 RDR_PopulateCurrentEntry( IN AFSDirEnumEntry * pCurrentEntry,
336 IN DWORD dwMaxEntryLength,
337 IN cm_scache_t * dscp,
338 IN cm_scache_t * scp,
339 IN cm_user_t * userp,
342 IN wchar_t * shortName,
344 IN afs_uint32 cmError,
345 OUT AFSDirEnumEntry **ppNextEntry,
346 OUT DWORD * pdwRemainingLength)
349 WCHAR * wname, *wtarget;
352 afs_uint32 code = 0, code2 = 0;
353 BOOL bMustFake = FALSE;
355 osi_Log5(afsd_logp, "RDR_PopulateCurrentEntry dscp=0x%p scp=0x%p name=%S short=%S flags=0x%x",
356 dscp, scp, osi_LogSaveStringW(afsd_logp, name),
357 osi_LogSaveStringW(afsd_logp, shortName), dwFlags);
358 osi_Log1(afsd_logp, "... maxLength=%d", dwMaxEntryLength);
360 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
362 *ppNextEntry = pCurrentEntry;
363 if (pdwRemainingLength)
364 *pdwRemainingLength = dwMaxEntryLength;
365 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry Not Enough Room for Entry %d < %d",
366 dwMaxEntryLength, sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t));
367 return CM_ERROR_TOOBIG;
375 dwEntryLength = sizeof(AFSDirEnumEntry);
377 lock_ObtainWrite(&scp->rw);
378 if (dwFlags & RDR_POP_NO_GETSTATUS) {
379 if (!cm_HaveCallback(scp))
382 #ifdef AFS_FREELANCE_CLIENT
383 if (scp->fid.cell == AFS_FAKE_ROOT_CELL_ID && scp->fid.volume == AFS_FAKE_ROOT_VOL_ID) {
385 * If the FID is from the Freelance Local Root always perform
386 * a single item status check.
388 code = cm_SyncOp( scp, NULL, userp, reqp, 0,
389 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
391 lock_ReleaseWrite(&scp->rw);
392 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_SyncOp failed for scp=0x%p code=0x%x",
400 * For non-Freelance objects, check to see if we have current
401 * status information. If not, perform a bulk status lookup of multiple
402 * entries in order to reduce the number of RPCs issued to the file server.
404 if ((scp->flags & CM_SCACHEFLAG_EACCESS))
406 else if (!cm_HaveCallback(scp)) {
407 lock_ReleaseWrite(&scp->rw);
408 code = RDR_BulkStatLookup(dscp, scp, userp, reqp);
410 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry RDR_BulkStatLookup failed for scp=0x%p code=0x%x",
414 lock_ObtainWrite(&scp->rw);
416 * RDR_BulkStatLookup can succeed but it may be the case that there
417 * still is not valid status info. If we get this far, generate fake
420 if (!cm_HaveCallback(scp))
426 /* Populate the error code */
427 smb_MapNTError(cmError, &pCurrentEntry->NTStatus, TRUE);
429 /* Populate the real or fake data */
430 pCurrentEntry->FileId.Cell = scp->fid.cell;
431 pCurrentEntry->FileId.Volume = scp->fid.volume;
432 pCurrentEntry->FileId.Vnode = scp->fid.vnode;
433 pCurrentEntry->FileId.Unique = scp->fid.unique;
434 pCurrentEntry->FileId.Hash = scp->fid.hash;
436 pCurrentEntry->FileType = scp->fileType;
438 pCurrentEntry->DataVersion.QuadPart = scp->dataVersion;
440 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
441 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
442 cm_LargeSearchTimeFromUnixTime(&ft, MAX_AFS_UINT32);
444 cm_LargeSearchTimeFromUnixTime(&ft, scp->cbExpires);
446 pCurrentEntry->Expiration.LowPart = ft.dwLowDateTime;
447 pCurrentEntry->Expiration.HighPart = ft.dwHighDateTime;
450 /* 1969-12-31 23:59:59 +00 */
451 ft.dwHighDateTime = 0x19DB200;
452 ft.dwLowDateTime = 0x5BB78980;
454 cm_LargeSearchTimeFromUnixTime(&ft, scp->clientModTime);
455 pCurrentEntry->CreationTime.LowPart = ft.dwLowDateTime;
456 pCurrentEntry->CreationTime.HighPart = ft.dwHighDateTime;
457 pCurrentEntry->LastAccessTime = pCurrentEntry->CreationTime;
458 pCurrentEntry->LastWriteTime = pCurrentEntry->CreationTime;
459 pCurrentEntry->ChangeTime = pCurrentEntry->CreationTime;
461 pCurrentEntry->EndOfFile = scp->length;
462 pCurrentEntry->AllocationSize = scp->length;
465 switch (scp->fileType) {
466 case CM_SCACHETYPE_DIRECTORY:
467 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY;
469 case CM_SCACHETYPE_MOUNTPOINT:
470 case CM_SCACHETYPE_INVALID:
471 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY | SMB_ATTR_REPARSE_POINT;
473 case CM_SCACHETYPE_SYMLINK:
474 if (cm_TargetPerceivedAsDirectory(scp->mountPointStringp))
475 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY | SMB_ATTR_REPARSE_POINT;
477 pCurrentEntry->FileAttributes = SMB_ATTR_REPARSE_POINT;
480 /* if we get here we either have a normal file
481 * or we have a file for which we have never
482 * received status info. In this case, we can
483 * check the even/odd value of the entry's vnode.
484 * odd means it is to be treated as a directory
485 * and even means it is to be treated as a file.
487 if (scp->fid.vnode & 0x1)
488 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY;
490 pCurrentEntry->FileAttributes = SMB_ATTR_NORMAL;
493 pCurrentEntry->FileAttributes = smb_ExtAttributes(scp);
494 pCurrentEntry->EaSize = 0;
495 pCurrentEntry->Links = scp->linkCount;
497 len = wcslen(shortName);
498 wcsncpy(pCurrentEntry->ShortName, shortName, len);
499 pCurrentEntry->ShortNameLength = (CCHAR)(len * sizeof(WCHAR));
501 pCurrentEntry->FileNameOffset = sizeof(AFSDirEnumEntry);
503 wname = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->FileNameOffset);
504 wcsncpy(wname, name, len);
505 pCurrentEntry->FileNameLength = (ULONG)(sizeof(WCHAR) * len);
507 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntry scp=0x%p fileType=%d dv=%u",
508 scp, scp->fileType, (afs_uint32)scp->dataVersion);
510 if (!(dwFlags & RDR_POP_NO_GETSTATUS))
511 cm_SyncOpDone( scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
513 if ((dwFlags & RDR_POP_NO_GETSTATUS) || !cm_HaveCallback(scp)) {
514 pCurrentEntry->TargetNameOffset = 0;
515 pCurrentEntry->TargetNameLength = 0;
518 switch (scp->fileType) {
519 case CM_SCACHETYPE_MOUNTPOINT:
520 if (dwFlags & RDR_POP_FOLLOW_MOUNTPOINTS) {
521 if ((code2 = cm_ReadMountPoint(scp, userp, reqp)) == 0) {
522 cm_scache_t *targetScp = NULL;
524 pCurrentEntry->TargetNameOffset = pCurrentEntry->FileNameOffset + pCurrentEntry->FileNameLength;
525 len = strlen(scp->mountPointStringp);
526 wtarget = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->TargetNameOffset);
529 cch = MultiByteToWideChar( CP_UTF8, 0, scp->mountPointStringp,
532 len * sizeof(WCHAR));
534 mbstowcs(wtarget, scp->mountPointStringp, len);
536 pCurrentEntry->TargetNameLength = (ULONG)(sizeof(WCHAR) * len);
538 code2 = cm_FollowMountPoint(scp, dscp, userp, reqp, &targetScp);
541 pCurrentEntry->TargetFileId.Cell = targetScp->fid.cell;
542 pCurrentEntry->TargetFileId.Volume = targetScp->fid.volume;
543 pCurrentEntry->TargetFileId.Vnode = targetScp->fid.vnode;
544 pCurrentEntry->TargetFileId.Unique = targetScp->fid.unique;
545 pCurrentEntry->TargetFileId.Hash = targetScp->fid.hash;
547 osi_Log4(afsd_logp, "RDR_PopulateCurrentEntry target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
548 pCurrentEntry->TargetFileId.Cell, pCurrentEntry->TargetFileId.Volume,
549 pCurrentEntry->TargetFileId.Vnode, pCurrentEntry->TargetFileId.Unique);
551 cm_ReleaseSCache(targetScp);
553 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_FollowMountPoint failed scp=0x%p code=0x%x",
557 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_ReadMountPoint failed scp=0x%p code=0x%x",
562 case CM_SCACHETYPE_SYMLINK:
563 case CM_SCACHETYPE_DFSLINK:
565 pCurrentEntry->TargetNameOffset = pCurrentEntry->FileNameOffset + pCurrentEntry->FileNameLength;
566 wtarget = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->TargetNameOffset);
568 if (dwFlags & RDR_POP_EVALUATE_SYMLINKS) {
571 code2 = cm_HandleLink(scp, userp, reqp);
573 mp = scp->mountPointStringp;
576 /* Strip off the msdfs: prefix from the target name for the file system */
577 if (scp->fileType == CM_SCACHETYPE_DFSLINK) {
578 osi_Log0(afsd_logp, "RDR_PopulateCurrentEntry DFSLink Detected");
579 pCurrentEntry->FileType = scp->fileType;
581 if (!strncmp("msdfs:", mp, 6)) {
586 /* only send one slash to the redirector */
587 if (mp[0] == '\\' && mp[1] == '\\') {
592 cch = MultiByteToWideChar( CP_UTF8, 0, mp,
595 len * sizeof(WCHAR));
597 mbstowcs(wtarget, mp, len);
600 pCurrentEntry->TargetNameLength = (ULONG)(sizeof(WCHAR) * len);
602 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_HandleLink failed scp=0x%p code=0x%x",
611 pCurrentEntry->TargetNameOffset = 0;
612 pCurrentEntry->TargetNameLength = 0;
614 lock_ReleaseWrite(&scp->rw);
616 dwEntryLength += pCurrentEntry->FileNameLength + pCurrentEntry->TargetNameLength;
617 dwEntryLength += (dwEntryLength % 8) ? 8 - (dwEntryLength % 8) : 0; /* quad align */
619 *ppNextEntry = (AFSDirEnumEntry *)((PBYTE)pCurrentEntry + dwEntryLength);
620 if (pdwRemainingLength)
621 *pdwRemainingLength = dwMaxEntryLength - dwEntryLength;
623 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntry Success FileNameLength=%d TargetNameLength=%d RemainingLength=%d",
624 pCurrentEntry->FileNameLength, pCurrentEntry->TargetNameLength, *pdwRemainingLength);
630 RDR_PopulateCurrentEntryNoScp( IN AFSDirEnumEntry * pCurrentEntry,
631 IN DWORD dwMaxEntryLength,
632 IN cm_scache_t * dscp,
634 IN cm_user_t * userp,
637 IN wchar_t * shortName,
639 IN afs_uint32 cmError,
640 OUT AFSDirEnumEntry **ppNextEntry,
641 OUT DWORD * pdwRemainingLength)
647 afs_uint32 code = 0, code2 = 0;
649 osi_Log4(afsd_logp, "RDR_PopulateCurrentEntryNoEntry dscp=0x%p name=%S short=%S flags=0x%x",
650 dscp, osi_LogSaveStringW(afsd_logp, name),
651 osi_LogSaveStringW(afsd_logp, shortName), dwFlags);
652 osi_Log1(afsd_logp, "... maxLength=%d", dwMaxEntryLength);
654 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
656 *ppNextEntry = pCurrentEntry;
657 if (pdwRemainingLength)
658 *pdwRemainingLength = dwMaxEntryLength;
659 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntryNoEntry Not Enough Room for Entry %d < %d",
660 dwMaxEntryLength, sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t));
661 return CM_ERROR_TOOBIG;
669 dwEntryLength = sizeof(AFSDirEnumEntry);
671 /* Populate the error code */
672 smb_MapNTError(cmError, &pCurrentEntry->NTStatus, TRUE);
674 /* Populate the fake data */
675 pCurrentEntry->FileId.Cell = fidp->cell;
676 pCurrentEntry->FileId.Volume = fidp->volume;
677 pCurrentEntry->FileId.Vnode = fidp->vnode;
678 pCurrentEntry->FileId.Unique = fidp->unique;
679 pCurrentEntry->FileId.Hash = fidp->hash;
681 pCurrentEntry->FileType = CM_SCACHETYPE_UNKNOWN;
683 pCurrentEntry->DataVersion.QuadPart = CM_SCACHE_VERSION_BAD;
685 cm_LargeSearchTimeFromUnixTime(&ft, 0);
686 pCurrentEntry->Expiration.LowPart = ft.dwLowDateTime;
687 pCurrentEntry->Expiration.HighPart = ft.dwHighDateTime;
689 cm_LargeSearchTimeFromUnixTime(&ft, 0);
690 pCurrentEntry->CreationTime.LowPart = ft.dwLowDateTime;
691 pCurrentEntry->CreationTime.HighPart = ft.dwHighDateTime;
692 pCurrentEntry->LastAccessTime = pCurrentEntry->CreationTime;
693 pCurrentEntry->LastWriteTime = pCurrentEntry->CreationTime;
694 pCurrentEntry->ChangeTime = pCurrentEntry->CreationTime;
696 pCurrentEntry->EndOfFile.QuadPart = 0;
697 pCurrentEntry->AllocationSize.QuadPart = 0;
698 pCurrentEntry->FileAttributes = 0;
699 pCurrentEntry->EaSize = 0;
700 pCurrentEntry->Links = 0;
702 len = wcslen(shortName);
703 wcsncpy(pCurrentEntry->ShortName, shortName, len);
704 pCurrentEntry->ShortNameLength = (CCHAR)(len * sizeof(WCHAR));
706 pCurrentEntry->FileNameOffset = sizeof(AFSDirEnumEntry);
708 wname = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->FileNameOffset);
709 wcsncpy(wname, name, len);
710 pCurrentEntry->FileNameLength = (ULONG)(sizeof(WCHAR) * len);
712 pCurrentEntry->TargetNameOffset = 0;
713 pCurrentEntry->TargetNameLength = 0;
715 dwEntryLength += pCurrentEntry->FileNameLength + pCurrentEntry->TargetNameLength;
716 dwEntryLength += (dwEntryLength % 8) ? 8 - (dwEntryLength % 8) : 0; /* quad align */
718 *ppNextEntry = (AFSDirEnumEntry *)((PBYTE)pCurrentEntry + dwEntryLength);
719 if (pdwRemainingLength)
720 *pdwRemainingLength = dwMaxEntryLength - dwEntryLength;
722 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntryNoScp Success FileNameLength=%d TargetNameLength=%d RemainingLength=%d",
723 pCurrentEntry->FileNameLength, pCurrentEntry->TargetNameLength, *pdwRemainingLength);
729 RDR_EnumerateDirectory( IN cm_user_t *userp,
731 IN AFSDirQueryCB *QueryCB,
734 IN DWORD ResultBufferLength,
735 IN OUT AFSCommResult **ResultCB)
738 cm_direnum_t * enump = NULL;
739 AFSDirEnumResp * pDirEnumResp;
740 AFSDirEnumEntry * pCurrentEntry;
741 size_t size = ResultBufferLength ? sizeof(AFSCommResult) + ResultBufferLength - 1 : sizeof(AFSCommResult);
742 DWORD dwMaxEntryLength;
745 cm_scache_t * dscp = NULL;
750 req.flags |= CM_REQ_WOW64;
752 osi_Log4(afsd_logp, "RDR_EnumerateDirectory FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
753 DirID.Cell, DirID.Volume, DirID.Vnode, DirID.Unique);
755 *ResultCB = (AFSCommResult *)malloc(size);
757 osi_Log0(afsd_logp, "RDR_EnumerateDirectory Out of Memory");
761 memset(*ResultCB, 0, size);
763 if (QueryCB->EnumHandle == (ULONG_PTR)-1) {
764 osi_Log0(afsd_logp, "RDR_EnumerateDirectory No More Entries");
765 (*ResultCB)->ResultStatus = STATUS_NO_MORE_ENTRIES;
766 (*ResultCB)->ResultBufferLength = 0;
770 (*ResultCB)->ResultBufferLength = dwMaxEntryLength = ResultBufferLength;
771 if (ResultBufferLength) {
772 pDirEnumResp = (AFSDirEnumResp *)&(*ResultCB)->ResultData;
773 pCurrentEntry = (AFSDirEnumEntry *)&pDirEnumResp->Entry;
774 dwMaxEntryLength -= FIELD_OFFSET( AFSDirEnumResp, Entry); /* AFSDirEnumResp */
777 if (DirID.Cell != 0) {
778 fid.cell = DirID.Cell;
779 fid.volume = DirID.Volume;
780 fid.vnode = DirID.Vnode;
781 fid.unique = DirID.Unique;
782 fid.hash = DirID.Hash;
784 code = cm_GetSCache(&fid, &dscp, userp, &req);
786 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
787 (*ResultCB)->ResultStatus = status;
788 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_GetSCache failure code=0x%x status=0x%x",
793 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
794 osi_Log0(afsd_logp, "RDR_EnumerateDirectory Object Name Invalid - Cell = 0");
798 /* get the directory size */
799 lock_ObtainWrite(&dscp->rw);
800 code = cm_SyncOp(dscp, NULL, userp, &req, PRSFS_LOOKUP,
801 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
803 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
804 (*ResultCB)->ResultStatus = status;
805 lock_ReleaseWrite(&dscp->rw);
806 cm_ReleaseSCache(dscp);
807 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_SyncOp failure code=0x%x status=0x%x",
812 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
813 lock_ReleaseWrite(&dscp->rw);
815 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
816 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
817 cm_ReleaseSCache(dscp);
818 osi_Log1(afsd_logp, "RDR_EnumerateDirectory Not a Directory dscp=0x%p",
823 osi_Log1(afsd_logp, "RDR_EnumerateDirectory dv=%u", (afs_uint32)dscp->dataVersion);
826 * If there is no enumeration handle, then this is a new query
827 * and we must perform an enumeration for the specified object.
829 if (QueryCB->EnumHandle == (ULONG_PTR)NULL) {
832 code = cm_BeginDirOp(dscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
834 code = cm_BPlusDirEnumerate(dscp, userp, &req,
835 TRUE /* dir locked */, NULL /* no mask */,
836 TRUE /* fetch status? */, &enump);
838 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BPlusDirEnumerate failure code=0x%x",
843 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BeginDirOp failure code=0x%x",
847 enump = (cm_direnum_t *)QueryCB->EnumHandle;
851 if (ResultBufferLength == 0) {
852 code = cm_BPlusDirEnumBulkStat(enump);
854 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BPlusDirEnumBulkStat failure code=0x%x",
858 cm_direnum_entry_t * entryp = NULL;
860 pDirEnumResp->SnapshotDataVersion.QuadPart = enump->dataVersion;
863 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
864 osi_Log0(afsd_logp, "RDR_EnumerateDirectory out of space, returning");
868 code = cm_BPlusDirNextEnumEntry(enump, &entryp);
870 if ((code == 0 || code == CM_ERROR_STOPNOW) && entryp) {
871 cm_scache_t *scp = NULL;
872 int stopnow = (code == CM_ERROR_STOPNOW);
874 if ( !wcscmp(L".", entryp->name) || !wcscmp(L"..", entryp->name) ) {
875 osi_Log0(afsd_logp, "RDR_EnumerateDirectory skipping . or ..");
882 code = cm_GetSCache(&entryp->fid, &scp, userp, &req);
884 osi_Log5(afsd_logp, "RDR_EnumerateDirectory cm_GetSCache failure cell %u vol %u vnode %u uniq %u code=0x%x",
885 entryp->fid.cell, entryp->fid.volume, entryp->fid.vnode, entryp->fid.unique, code);
888 code = entryp->errorCode;
889 scp = code ? NULL : cm_FindSCache(&entryp->fid);
893 code = RDR_PopulateCurrentEntry( pCurrentEntry, dwMaxEntryLength,
894 dscp, scp, userp, &req,
896 cm_Is8Dot3(entryp->name) ? NULL : entryp->shortName,
897 (bWow64 ? RDR_POP_WOW64 : 0) |
898 (bSkipStatus ? RDR_POP_NO_GETSTATUS : 0),
900 &pCurrentEntry, &dwMaxEntryLength);
901 cm_ReleaseSCache(scp);
903 code = RDR_PopulateCurrentEntryNoScp( pCurrentEntry, dwMaxEntryLength,
904 dscp, &entryp->fid, userp, &req,
906 cm_Is8Dot3(entryp->name) ? NULL : entryp->shortName,
907 (bWow64 ? RDR_POP_WOW64 : 0),
909 &pCurrentEntry, &dwMaxEntryLength);
920 if (code || enump->next == enump->count || ResultBufferLength == 0) {
921 cm_BPlusDirFreeEnumeration(enump);
922 enump = (cm_direnum_t *)(ULONG_PTR)-1;
925 if (code == 0 || code == CM_ERROR_STOPNOW) {
926 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
927 osi_Log0(afsd_logp, "RDR_EnumerateDirectory SUCCESS");
929 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
930 (*ResultCB)->ResultStatus = status;
931 osi_Log2(afsd_logp, "RDR_EnumerateDirectory Failure code=0x%x status=0x%x",
935 if (ResultBufferLength) {
936 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwMaxEntryLength;
938 pDirEnumResp->EnumHandle = (ULONG_PTR) enump;
939 pDirEnumResp->CurrentDataVersion.QuadPart = dscp->dataVersion;
943 cm_ReleaseSCache(dscp);
949 RDR_EvaluateNodeByName( IN cm_user_t *userp,
950 IN AFSFileID ParentID,
951 IN WCHAR *FileNameCounted,
952 IN DWORD FileNameLength,
953 IN BOOL CaseSensitive,
957 IN DWORD ResultBufferLength,
958 IN OUT AFSCommResult **ResultCB)
960 AFSFileEvalResultCB *pEvalResultCB = NULL;
961 AFSDirEnumEntry * pCurrentEntry;
962 size_t size = ResultBufferLength ? sizeof(AFSCommResult) + ResultBufferLength - 1 : sizeof(AFSCommResult);
964 cm_scache_t * scp = NULL;
965 cm_scache_t * dscp = NULL;
970 WCHAR * wszName = NULL;
973 wchar_t FileName[260];
975 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
979 req.flags |= CM_REQ_WOW64;
981 osi_Log4(afsd_logp, "RDR_EvaluateNodeByName parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
982 ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
984 /* Allocate enough room to add a volume prefix if necessary */
985 cbName = FileNameLength + (CM_PREFIX_VOL_CCH + 1) * sizeof(WCHAR);
986 wszName = malloc(cbName);
988 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Out of Memory");
991 StringCbCopyNW(wszName, cbName, FileName, FileNameLength);
992 osi_Log1(afsd_logp, "... name=%S", osi_LogSaveStringW(afsd_logp, wszName));
994 *ResultCB = (AFSCommResult *)malloc(size);
996 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Out of Memory");
1001 memset(*ResultCB, 0, size);
1002 (*ResultCB)->ResultBufferLength = 0;
1003 dwRemaining = ResultBufferLength;
1004 if (ResultBufferLength >= sizeof( AFSFileEvalResultCB)) {
1005 pEvalResultCB = (AFSFileEvalResultCB *)&(*ResultCB)->ResultData;
1006 pCurrentEntry = &pEvalResultCB->DirEnum;
1007 dwRemaining -= (sizeof( AFSFileEvalResultCB) - sizeof( AFSDirEnumEntry));
1010 if (ParentID.Cell != 0) {
1011 parentFid.cell = ParentID.Cell;
1012 parentFid.volume = ParentID.Volume;
1013 parentFid.vnode = ParentID.Vnode;
1014 parentFid.unique = ParentID.Unique;
1015 parentFid.hash = ParentID.Hash;
1017 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1019 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1020 (*ResultCB)->ResultStatus = status;
1021 if ( status == STATUS_INVALID_HANDLE)
1022 status = STATUS_OBJECT_PATH_INVALID;
1023 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName cm_GetSCache parentFID failure code=0x%x status=0x%x",
1029 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
1030 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Object Name Invalid - Cell = 0");
1034 /* get the directory size */
1035 lock_ObtainWrite(&dscp->rw);
1036 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1037 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1039 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1040 (*ResultCB)->ResultStatus = status;
1041 lock_ReleaseWrite(&dscp->rw);
1042 cm_ReleaseSCache(dscp);
1043 osi_Log3(afsd_logp, "RDR_EvaluateNodeByName cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1044 dscp, code, status);
1048 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1049 lock_ReleaseWrite(&dscp->rw);
1051 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1052 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1053 cm_ReleaseSCache(dscp);
1054 osi_Log1(afsd_logp, "RDR_EvaluateNodeByName Not a Directory dscp=0x%p",
1060 code = cm_Lookup(dscp, wszName, CM_FLAG_CHECKPATH, userp, &req, &scp);
1062 if ((code == CM_ERROR_NOSUCHPATH || code == CM_ERROR_NOSUCHFILE || code == CM_ERROR_BPLUS_NOMATCH) &&
1063 (wcschr(wszName, '%') != NULL || wcschr(wszName, '#') != NULL)) {
1065 * A volume reference: <cell>{%,#}<volume> -> @vol:<cell>{%,#}<volume>
1067 StringCchCopyNW(wszName, cbName, _C(CM_PREFIX_VOL), CM_PREFIX_VOL_CCH);
1068 StringCbCatNW(wszName, cbName, FileName, FileNameLength);
1071 code = cm_EvaluateVolumeReference(wszName, CM_FLAG_CHECKPATH, userp, &req, &scp);
1074 if (code == 0 && scp) {
1075 wchar_t shortName[13]=L"";
1078 cm_Gen8Dot3VolNameW(scp->fid.cell, scp->fid.volume, shortName, NULL);
1079 } else if (!cm_Is8Dot3(wszName)) {
1082 dfid.vnode = htonl(scp->fid.vnode);
1083 dfid.unique = htonl(scp->fid.unique);
1085 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1087 shortName[0] = '\0';
1090 code = RDR_PopulateCurrentEntry(pCurrentEntry, dwRemaining,
1091 dscp, scp, userp, &req,
1092 FileName, shortName,
1093 (bWow64 ? RDR_POP_WOW64 : 0) |
1094 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1095 0, NULL, &dwRemaining);
1097 RDR_FlagScpInUse( scp, FALSE );
1098 cm_ReleaseSCache(scp);
1101 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1102 (*ResultCB)->ResultStatus = status;
1103 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1106 pEvalResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1107 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1108 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1109 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName SUCCESS");
1112 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1113 (*ResultCB)->ResultStatus = status;
1114 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1117 (*ResultCB)->ResultStatus = STATUS_NO_SUCH_FILE;
1118 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName No Such File");
1120 cm_ReleaseSCache(dscp);
1127 RDR_EvaluateNodeByID( IN cm_user_t *userp,
1128 IN AFSFileID ParentID, /* not used */
1129 IN AFSFileID SourceID,
1133 IN DWORD ResultBufferLength,
1134 IN OUT AFSCommResult **ResultCB)
1136 AFSFileEvalResultCB *pEvalResultCB = NULL;
1137 AFSDirEnumEntry * pCurrentEntry = NULL;
1138 size_t size = ResultBufferLength ? sizeof(AFSCommResult) + ResultBufferLength - 1 : sizeof(AFSCommResult);
1139 afs_uint32 code = 0;
1140 cm_scache_t * scp = NULL;
1141 cm_scache_t * dscp = NULL;
1148 osi_Log4(afsd_logp, "RDR_EvaluateNodeByID source FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1149 SourceID.Cell, SourceID.Volume, SourceID.Vnode, SourceID.Unique);
1150 osi_Log4(afsd_logp, "... parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1151 ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1153 *ResultCB = (AFSCommResult *)malloc(size);
1155 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Out of Memory");
1159 memset(*ResultCB, 0, size);
1160 (*ResultCB)->ResultBufferLength = 0;
1161 dwRemaining = ResultBufferLength;
1162 if (ResultBufferLength >= sizeof( AFSFileEvalResultCB)) {
1163 pEvalResultCB = (AFSFileEvalResultCB *)&(*ResultCB)->ResultData;
1164 pCurrentEntry = &pEvalResultCB->DirEnum;
1165 dwRemaining -= (sizeof( AFSFileEvalResultCB) - sizeof( AFSDirEnumEntry));
1170 req.flags |= CM_REQ_WOW64;
1172 if (SourceID.Cell != 0) {
1173 Fid.cell = SourceID.Cell;
1174 Fid.volume = SourceID.Volume;
1175 Fid.vnode = SourceID.Vnode;
1176 Fid.unique = SourceID.Unique;
1177 Fid.hash = SourceID.Hash;
1179 code = cm_GetSCache(&Fid, &scp, userp, &req);
1181 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1182 (*ResultCB)->ResultStatus = status;
1183 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache SourceFID failure code=0x%x status=0x%x",
1188 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
1189 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Name Invalid - Cell = 0");
1193 if (ParentID.Cell != 0) {
1194 cm_SetFid(&parentFid, ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1195 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1197 cm_ReleaseSCache(scp);
1198 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1199 if ( status == STATUS_INVALID_HANDLE)
1200 status = STATUS_OBJECT_PATH_INVALID;
1201 (*ResultCB)->ResultStatus = status;
1202 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1206 } else if (SourceID.Vnode == 1) {
1208 cm_HoldSCache(dscp);
1209 } else if (scp->parentVnode) {
1210 cm_SetFid(&parentFid, SourceID.Cell, SourceID.Volume, scp->parentVnode, scp->parentUnique);
1211 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1213 cm_ReleaseSCache(scp);
1214 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1215 if ( status == STATUS_INVALID_HANDLE)
1216 status = STATUS_OBJECT_PATH_INVALID;
1217 (*ResultCB)->ResultStatus = status;
1218 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1223 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
1224 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Path Invalid - Unknown Parent");
1228 /* Make sure the directory is current */
1229 lock_ObtainWrite(&dscp->rw);
1230 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1231 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1233 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1234 (*ResultCB)->ResultStatus = status;
1235 lock_ReleaseWrite(&dscp->rw);
1236 cm_ReleaseSCache(dscp);
1237 cm_ReleaseSCache(scp);
1238 osi_Log3(afsd_logp, "RDR_EvaluateNodeByID cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1239 dscp, code, status);
1243 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1244 lock_ReleaseWrite(&dscp->rw);
1246 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1247 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1248 cm_ReleaseSCache(dscp);
1249 cm_ReleaseSCache(scp);
1250 osi_Log1(afsd_logp, "RDR_EvaluateNodeByID Not a Directory dscp=0x%p", dscp);
1254 code = RDR_PopulateCurrentEntry(pCurrentEntry, dwRemaining,
1255 dscp, scp, userp, &req, NULL, NULL,
1256 (bWow64 ? RDR_POP_WOW64 : 0) |
1257 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1258 0, NULL, &dwRemaining);
1261 RDR_FlagScpInUse( scp, FALSE );
1262 cm_ReleaseSCache(scp);
1263 cm_ReleaseSCache(dscp);
1266 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1267 (*ResultCB)->ResultStatus = status;
1268 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID FAILURE code=0x%x status=0x%x",
1271 pEvalResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1273 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1274 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1275 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID SUCCESS");
1281 RDR_CreateFileEntry( IN cm_user_t *userp,
1282 IN WCHAR *FileNameCounted,
1283 IN DWORD FileNameLength,
1284 IN AFSFileCreateCB *CreateCB,
1287 IN DWORD ResultBufferLength,
1288 IN OUT AFSCommResult **ResultCB)
1290 AFSFileCreateResultCB *pResultCB = NULL;
1291 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1294 cm_scache_t * dscp = NULL;
1295 afs_uint32 flags = 0;
1297 cm_scache_t * scp = NULL;
1300 wchar_t FileName[260];
1302 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1304 osi_Log4(afsd_logp, "RDR_CreateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1305 CreateCB->ParentId.Cell, CreateCB->ParentId.Volume,
1306 CreateCB->ParentId.Vnode, CreateCB->ParentId.Unique);
1307 osi_Log1(afsd_logp, "... name=%S", osi_LogSaveStringW(afsd_logp, FileName));
1311 req.flags |= CM_REQ_WOW64;
1312 memset(&setAttr, 0, sizeof(cm_attr_t));
1314 *ResultCB = (AFSCommResult *)malloc(size);
1316 osi_Log0(afsd_logp, "RDR_CreateFileEntry out of memory");
1324 parentFid.cell = CreateCB->ParentId.Cell;
1325 parentFid.volume = CreateCB->ParentId.Volume;
1326 parentFid.vnode = CreateCB->ParentId.Vnode;
1327 parentFid.unique = CreateCB->ParentId.Unique;
1328 parentFid.hash = CreateCB->ParentId.Hash;
1330 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1332 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1333 (*ResultCB)->ResultStatus = status;
1334 if ( status == STATUS_INVALID_HANDLE)
1335 status = STATUS_OBJECT_PATH_INVALID;
1336 osi_Log2(afsd_logp, "RDR_CreateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1341 lock_ObtainWrite(&dscp->rw);
1342 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1343 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1345 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1346 (*ResultCB)->ResultStatus = status;
1347 lock_ReleaseWrite(&dscp->rw);
1348 cm_ReleaseSCache(dscp);
1349 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (1) dscp=0x%p code=0x%x status=0x%x",
1350 dscp, code, status);
1354 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1355 lock_ReleaseWrite(&dscp->rw);
1357 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1358 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1359 cm_ReleaseSCache(dscp);
1360 osi_Log1(afsd_logp, "RDR_CreateFileEntry Not a Directory dscp=0x%p",
1365 /* Use current time */
1366 setAttr.mask = CM_ATTRMASK_CLIENTMODTIME;
1367 setAttr.clientModTime = time(NULL);
1369 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1370 if (smb_unixModeDefaultDir) {
1371 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1372 setAttr.unixModeBits = smb_unixModeDefaultDir;
1373 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1374 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1377 code = cm_MakeDir(dscp, FileName, flags, &setAttr, userp, &req, &scp);
1379 if (smb_unixModeDefaultFile) {
1380 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1381 setAttr.unixModeBits = smb_unixModeDefaultFile;
1382 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1383 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1386 setAttr.mask |= CM_ATTRMASK_LENGTH;
1387 setAttr.length.LowPart = CreateCB->AllocationSize.LowPart;
1388 setAttr.length.HighPart = CreateCB->AllocationSize.HighPart;
1389 code = cm_Create(dscp, FileName, flags, &setAttr, &scp, userp, &req);
1392 wchar_t shortName[13]=L"";
1396 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
1398 (*ResultCB)->ResultBufferLength = sizeof( AFSFileCreateResultCB);
1400 pResultCB = (AFSFileCreateResultCB *)(*ResultCB)->ResultData;
1402 dwRemaining = ResultBufferLength - sizeof( AFSFileCreateResultCB) + sizeof( AFSDirEnumEntry);
1404 lock_ObtainWrite(&dscp->rw);
1405 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1406 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1408 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1409 (*ResultCB)->ResultStatus = status;
1410 lock_ReleaseWrite(&dscp->rw);
1411 cm_ReleaseSCache(dscp);
1412 cm_ReleaseSCache(scp);
1413 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (2) dscp=0x%p code=0x%x status=0x%x",
1414 dscp, code, status);
1418 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1420 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1421 lock_ReleaseWrite(&dscp->rw);
1423 dfid.vnode = htonl(scp->fid.vnode);
1424 dfid.unique = htonl(scp->fid.unique);
1426 if (!cm_Is8Dot3(FileName))
1427 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1429 shortName[0] = '\0';
1431 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1432 dscp, scp, userp, &req, FileName, shortName,
1433 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1434 0, NULL, &dwRemaining);
1437 RDR_FlagScpInUse( scp, FALSE );
1438 cm_ReleaseSCache(scp);
1439 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1440 osi_Log0(afsd_logp, "RDR_CreateFileEntry SUCCESS");
1442 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1443 (*ResultCB)->ResultStatus = status;
1444 (*ResultCB)->ResultBufferLength = 0;
1445 osi_Log2(afsd_logp, "RDR_CreateFileEntry FAILURE code=0x%x status=0x%x",
1449 cm_ReleaseSCache(dscp);
1455 RDR_UpdateFileEntry( IN cm_user_t *userp,
1456 IN AFSFileID FileId,
1457 IN AFSFileUpdateCB *UpdateCB,
1459 IN DWORD ResultBufferLength,
1460 IN OUT AFSCommResult **ResultCB)
1462 AFSFileUpdateResultCB *pResultCB = NULL;
1463 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1467 afs_uint32 flags = 0;
1469 cm_scache_t * scp = NULL;
1470 cm_scache_t * dscp = NULL;
1472 time_t clientModTime;
1475 BOOL bScpLocked = FALSE;
1479 req.flags |= CM_REQ_WOW64;
1480 memset(&setAttr, 0, sizeof(cm_attr_t));
1482 osi_Log4(afsd_logp, "RDR_UpdateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1483 UpdateCB->ParentId.Cell, UpdateCB->ParentId.Volume,
1484 UpdateCB->ParentId.Vnode, UpdateCB->ParentId.Unique);
1485 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1486 FileId.Cell, FileId.Volume,
1487 FileId.Vnode, FileId.Unique);
1489 *ResultCB = (AFSCommResult *)malloc( size);
1491 osi_Log0(afsd_logp, "RDR_UpdateFileEntry Out of Memory");
1499 parentFid.cell = UpdateCB->ParentId.Cell;
1500 parentFid.volume = UpdateCB->ParentId.Volume;
1501 parentFid.vnode = UpdateCB->ParentId.Vnode;
1502 parentFid.unique = UpdateCB->ParentId.Unique;
1503 parentFid.hash = UpdateCB->ParentId.Hash;
1505 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1507 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1508 (*ResultCB)->ResultStatus = status;
1509 if ( status == STATUS_INVALID_HANDLE)
1510 status = STATUS_OBJECT_PATH_INVALID;
1511 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1516 lock_ObtainWrite(&dscp->rw);
1518 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1519 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1521 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1522 (*ResultCB)->ResultStatus = status;
1523 lock_ReleaseWrite(&dscp->rw);
1524 cm_ReleaseSCache(dscp);
1525 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1526 dscp, code, status);
1530 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1531 lock_ReleaseWrite(&dscp->rw);
1534 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1535 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1536 cm_ReleaseSCache(dscp);
1537 osi_Log1(afsd_logp, "RDR_UpdateFileEntry Not a Directory dscp=0x%p",
1542 Fid.cell = FileId.Cell;
1543 Fid.volume = FileId.Volume;
1544 Fid.vnode = FileId.Vnode;
1545 Fid.unique = FileId.Unique;
1546 Fid.hash = FileId.Hash;
1548 code = cm_GetSCache(&Fid, &scp, userp, &req);
1550 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1551 (*ResultCB)->ResultStatus = status;
1552 cm_ReleaseSCache(dscp);
1553 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache object FID failure code=0x%x status=0x%x",
1558 lock_ObtainWrite(&scp->rw);
1560 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1561 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1563 lock_ReleaseWrite(&scp->rw);
1564 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1565 (*ResultCB)->ResultStatus = status;
1566 (*ResultCB)->ResultBufferLength = 0;
1567 cm_ReleaseSCache(dscp);
1568 cm_ReleaseSCache(scp);
1569 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
1573 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1575 if (UpdateCB->ChangeTime.QuadPart) {
1577 if (scp->fileType == CM_SCACHETYPE_FILE) {
1578 /* Do not set length and other attributes at the same time */
1579 if (scp->length.QuadPart != UpdateCB->AllocationSize.QuadPart) {
1580 osi_Log2(afsd_logp, "RDR_UpdateFileEntry Length Change 0x%x -> 0x%x",
1581 (afs_uint32)scp->length.QuadPart, (afs_uint32)UpdateCB->AllocationSize.QuadPart);
1582 setAttr.mask |= CM_ATTRMASK_LENGTH;
1583 setAttr.length.LowPart = UpdateCB->AllocationSize.LowPart;
1584 setAttr.length.HighPart = UpdateCB->AllocationSize.HighPart;
1585 lock_ReleaseWrite(&scp->rw);
1587 code = cm_SetAttr(scp, &setAttr, userp, &req);
1595 lock_ObtainWrite(&scp->rw);
1598 if ((scp->unixModeBits & 0200) && (UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1599 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1600 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1601 } else if (!(scp->unixModeBits & 0200) && !(UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1602 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1603 setAttr.unixModeBits = scp->unixModeBits | 0222;
1607 if (UpdateCB->LastWriteTime.QuadPart) {
1608 ft.dwLowDateTime = UpdateCB->LastWriteTime.LowPart;
1609 ft.dwHighDateTime = UpdateCB->LastWriteTime.HighPart;
1611 cm_UnixTimeFromLargeSearchTime(& clientModTime, &ft);
1614 lock_ObtainWrite(&scp->rw);
1617 if (scp->clientModTime != clientModTime) {
1618 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1619 setAttr.clientModTime = clientModTime;
1624 lock_ReleaseWrite(&scp->rw);
1626 code = cm_SetAttr(scp, &setAttr, userp, &req);
1633 lock_ReleaseWrite(&scp->rw);
1637 DWORD dwRemaining = ResultBufferLength - sizeof( AFSFileUpdateResultCB) + sizeof( AFSDirEnumEntry);
1639 pResultCB = (AFSFileUpdateResultCB *)(*ResultCB)->ResultData;
1641 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1643 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1644 dscp, scp, userp, &req, NULL, NULL,
1645 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1646 0, NULL, &dwRemaining);
1647 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1648 osi_Log0(afsd_logp, "RDR_UpdateFileEntry SUCCESS");
1650 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1651 (*ResultCB)->ResultStatus = status;
1652 (*ResultCB)->ResultBufferLength = 0;
1653 osi_Log2(afsd_logp, "RDR_UpdateFileEntry FAILURE code=0x%x status=0x%x",
1656 cm_ReleaseSCache(scp);
1657 cm_ReleaseSCache(dscp);
1663 RDR_CleanupFileEntry( IN cm_user_t *userp,
1664 IN AFSFileID FileId,
1665 IN WCHAR *FileNameCounted,
1666 IN DWORD FileNameLength,
1667 IN AFSFileCleanupCB *CleanupCB,
1669 IN BOOL bLastHandle,
1670 IN BOOL bDeleteFile,
1671 IN BOOL bUnlockFile,
1672 IN DWORD ResultBufferLength,
1673 IN OUT AFSCommResult **ResultCB)
1675 AFSFileCleanupResultCB *pResultCB = NULL;
1676 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1679 afs_uint32 code = 0;
1680 afs_uint32 flags = 0;
1682 cm_scache_t * scp = NULL;
1683 cm_scache_t * dscp = NULL;
1685 time_t clientModTime;
1688 BOOL bScpLocked = FALSE;
1689 BOOL bDscpLocked = FALSE;
1690 BOOL bFlushFile = FALSE;
1695 req.flags |= CM_REQ_WOW64;
1696 memset(&setAttr, 0, sizeof(cm_attr_t));
1698 osi_Log4(afsd_logp, "RDR_CleanupFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1699 CleanupCB->ParentId.Cell, CleanupCB->ParentId.Volume,
1700 CleanupCB->ParentId.Vnode, CleanupCB->ParentId.Unique);
1701 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1702 FileId.Cell, FileId.Volume,
1703 FileId.Vnode, FileId.Unique);
1705 *ResultCB = (AFSCommResult *)malloc( size);
1707 osi_Log0(afsd_logp, "RDR_CleanupFileEntry Out of Memory");
1715 parentFid.cell = CleanupCB->ParentId.Cell;
1716 parentFid.volume = CleanupCB->ParentId.Volume;
1717 parentFid.vnode = CleanupCB->ParentId.Vnode;
1718 parentFid.unique = CleanupCB->ParentId.Unique;
1719 parentFid.hash = CleanupCB->ParentId.Hash;
1721 if (parentFid.cell) {
1722 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1724 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1725 if ( status == STATUS_INVALID_HANDLE)
1726 status = STATUS_OBJECT_PATH_INVALID;
1727 (*ResultCB)->ResultStatus = status;
1728 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1733 lock_ObtainWrite(&dscp->rw);
1735 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1736 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1738 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure dscp=0x%p code=0x%x",
1744 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1745 lock_ReleaseWrite(&dscp->rw);
1746 bDscpLocked = FALSE;
1748 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1749 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1750 cm_ReleaseSCache(dscp);
1751 osi_Log1(afsd_logp, "RDR_CleanupFileEntry Not a Directory dscp=0x%p",
1758 Fid.cell = FileId.Cell;
1759 Fid.volume = FileId.Volume;
1760 Fid.vnode = FileId.Vnode;
1761 Fid.unique = FileId.Unique;
1762 Fid.hash = FileId.Hash;
1764 code = cm_GetSCache(&Fid, &scp, userp, &req);
1766 osi_Log1(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache object FID failure code=0x%x",
1771 lock_ObtainWrite(&scp->rw);
1773 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1774 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1776 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure scp=0x%p code=0x%x",
1780 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1782 if ((bLastHandle || bFlushFile) &&
1783 scp->redirBufCount > 0)
1785 LARGE_INTEGER heldExtents;
1786 AFSFileExtentCB extentList[1024];
1787 DWORD extentCount = 0;
1792 heldExtents.QuadPart = 0;
1794 for ( srbp = redirq_to_cm_buf_t(scp->redirQueueT);
1796 srbp = redirq_to_cm_buf_t(osi_QPrev(&srbp->redirq)))
1798 extentList[extentCount].Flags = 0;
1799 extentList[extentCount].Length = cm_data.blockSize;
1800 extentList[extentCount].FileOffset.QuadPart = srbp->offset.QuadPart;
1801 extentList[extentCount].CacheOffset.QuadPart = srbp->datap - RDR_extentBaseAddress;
1802 lock_ObtainWrite(&buf_globalLock);
1803 srbp->redirReleaseRequested = now;
1804 lock_ReleaseWrite(&buf_globalLock);
1807 if (extentCount == 1024) {
1808 lock_ReleaseWrite(&scp->rw);
1809 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1811 if (code == CM_ERROR_RETRY) {
1813 * The redirector either is not holding the extents or cannot let them
1814 * go because they are otherwise in use. At the moment, do nothing.
1821 lock_ObtainWrite(&scp->rw);
1825 if (code == 0 && extentCount > 0) {
1827 lock_ReleaseWrite(&scp->rw);
1830 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1835 /* No longer in use by redirector */
1837 lock_ObtainWrite(&scp->rw);
1842 lock_AssertWrite(&scp->rw);
1843 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
1846 if (bLastHandle || bFlushFile) {
1848 lock_ObtainWrite(&scp->rw);
1851 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
1852 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1855 lock_ReleaseWrite(&scp->rw);
1859 code = cm_FSync(scp, userp, &req, bScpLocked);
1861 if (bLastHandle && code)
1865 if (bUnlockFile || bDeleteFile) {
1867 lock_ObtainWrite(&scp->rw);
1870 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1871 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1873 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp (2) failure scp=0x%p code=0x%x",
1878 key = cm_GenerateKey(CM_SESSION_IFS, CleanupCB->ProcessId, 0);
1880 /* the scp is now locked and current */
1881 code = cm_UnlockByKey(scp, key,
1882 bDeleteFile ? CM_UNLOCK_FLAG_BY_FID : 0,
1885 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1891 if (CleanupCB->ChangeTime.QuadPart) {
1893 if (scp->fileType == CM_SCACHETYPE_FILE) {
1894 /* Do not set length and other attributes at the same time */
1895 if (scp->length.QuadPart != CleanupCB->AllocationSize.QuadPart) {
1896 osi_Log2(afsd_logp, "RDR_CleanupFileEntry Length Change 0x%x -> 0x%x",
1897 (afs_uint32)scp->length.QuadPart, (afs_uint32)CleanupCB->AllocationSize.QuadPart);
1898 setAttr.mask |= CM_ATTRMASK_LENGTH;
1899 setAttr.length.LowPart = CleanupCB->AllocationSize.LowPart;
1900 setAttr.length.HighPart = CleanupCB->AllocationSize.HighPart;
1903 lock_ReleaseWrite(&scp->rw);
1906 code = cm_SetAttr(scp, &setAttr, userp, &req);
1914 lock_ObtainWrite(&scp->rw);
1918 if ((scp->unixModeBits & 0200) && (CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1919 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1920 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1921 } else if (!(scp->unixModeBits & 0200) && !(CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1922 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1923 setAttr.unixModeBits = scp->unixModeBits | 0222;
1927 if (CleanupCB->LastWriteTime.QuadPart) {
1928 ft.dwLowDateTime = CleanupCB->LastWriteTime.LowPart;
1929 ft.dwHighDateTime = CleanupCB->LastWriteTime.HighPart;
1931 cm_UnixTimeFromLargeSearchTime(&clientModTime, &ft);
1932 if (scp->clientModTime != clientModTime) {
1933 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1934 setAttr.clientModTime = clientModTime;
1940 lock_ReleaseWrite(&scp->rw);
1942 code = cm_SetAttr(scp, &setAttr, userp, &req);
1946 /* Now drop the lock enforcing the share access */
1947 if ( CleanupCB->FileAccess != AFS_FILE_ACCESS_NOLOCK) {
1948 unsigned int sLockType;
1949 LARGE_INTEGER LOffset, LLength;
1951 if (CleanupCB->FileAccess == AFS_FILE_ACCESS_SHARED)
1952 sLockType = LOCKING_ANDX_SHARED_LOCK;
1956 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, CleanupCB->Identifier);
1958 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
1959 LOffset.LowPart = SMB_FID_QLOCK_LOW;
1960 LLength.HighPart = 0;
1961 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
1964 lock_ObtainWrite(&scp->rw);
1968 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
1971 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
1973 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
1975 if (code == CM_ERROR_RANGE_NOT_LOCKED)
1977 osi_Log3(afsd_logp, "RDR_CleanupFileEntry Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
1978 CleanupCB->FileAccess, CleanupCB->ProcessId, CleanupCB->Identifier);
1986 lock_ReleaseWrite(&dscp->rw);
1988 lock_ReleaseWrite(&scp->rw);
1990 if (dscp && bDeleteFile) {
1991 WCHAR FileName[260];
1993 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1995 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
1996 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
1998 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2001 if ( ResultBufferLength >= sizeof( AFSFileCleanupResultCB))
2003 (*ResultCB)->ResultBufferLength = sizeof( AFSFileCleanupResultCB);
2004 pResultCB = (AFSFileCleanupResultCB *)&(*ResultCB)->ResultData;
2005 pResultCB->ParentDataVersion.QuadPart = dscp ? dscp->dataVersion : 0;
2007 (*ResultCB)->ResultBufferLength = 0;
2011 (*ResultCB)->ResultStatus = 0;
2012 osi_Log0(afsd_logp, "RDR_CleanupFileEntry SUCCESS");
2014 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2015 (*ResultCB)->ResultStatus = status;
2016 osi_Log2(afsd_logp, "RDR_CleanupFileEntry FAILURE code=0x%x status=0x%x",
2020 cm_ReleaseSCache(scp);
2022 cm_ReleaseSCache(dscp);
2028 RDR_DeleteFileEntry( IN cm_user_t *userp,
2029 IN AFSFileID ParentId,
2030 IN ULONGLONG ProcessId,
2031 IN WCHAR *FileNameCounted,
2032 IN DWORD FileNameLength,
2035 IN DWORD ResultBufferLength,
2036 IN OUT AFSCommResult **ResultCB)
2039 AFSFileDeleteResultCB *pResultCB = NULL;
2040 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2043 cm_scache_t * dscp = NULL;
2044 cm_scache_t * scp = NULL;
2045 afs_uint32 flags = 0;
2049 wchar_t FileName[260];
2052 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
2054 osi_Log4(afsd_logp, "RDR_DeleteFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2055 ParentId.Cell, ParentId.Volume,
2056 ParentId.Vnode, ParentId.Unique);
2057 osi_Log2(afsd_logp, "... name=%S checkOnly=%x",
2058 osi_LogSaveStringW(afsd_logp, FileName),
2063 req.flags |= CM_REQ_WOW64;
2064 memset(&setAttr, 0, sizeof(cm_attr_t));
2066 *ResultCB = (AFSCommResult *)malloc( size);
2068 osi_Log0(afsd_logp, "RDR_DeleteFileEntry out of memory");
2076 parentFid.cell = ParentId.Cell;
2077 parentFid.volume = ParentId.Volume;
2078 parentFid.vnode = ParentId.Vnode;
2079 parentFid.unique = ParentId.Unique;
2080 parentFid.hash = ParentId.Hash;
2082 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
2084 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2085 if ( status == STATUS_INVALID_HANDLE)
2086 status = STATUS_OBJECT_PATH_INVALID;
2087 (*ResultCB)->ResultStatus = status;
2088 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
2093 lock_ObtainWrite(&dscp->rw);
2095 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
2096 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2098 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2099 (*ResultCB)->ResultStatus = status;
2100 (*ResultCB)->ResultBufferLength = 0;
2101 lock_ReleaseWrite(&dscp->rw);
2102 cm_ReleaseSCache(dscp);
2103 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
2104 dscp, code, status);
2108 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2109 lock_ReleaseWrite(&dscp->rw);
2111 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2112 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2113 cm_ReleaseSCache(dscp);
2114 osi_Log1(afsd_logp, "RDR_DeleteFileEntry Not a Directory dscp=0x%p",
2119 code = cm_Lookup(dscp, FileName, 0, userp, &req, &scp);
2121 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2122 (*ResultCB)->ResultStatus = status;
2123 (*ResultCB)->ResultBufferLength = 0;
2124 cm_ReleaseSCache(dscp);
2125 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_Lookup failure code=0x%x status=0x%x",
2130 lock_ObtainWrite(&scp->rw);
2131 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_DELETE,
2132 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2134 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2135 (*ResultCB)->ResultStatus = status;
2136 (*ResultCB)->ResultBufferLength = 0;
2137 lock_ReleaseWrite(&scp->rw);
2138 cm_ReleaseSCache(scp);
2139 cm_ReleaseSCache(dscp);
2140 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2146 /* Drop all locks since the file is being deleted */
2147 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2148 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2150 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2151 (*ResultCB)->ResultStatus = status;
2152 (*ResultCB)->ResultBufferLength = 0;
2153 lock_ReleaseWrite(&scp->rw);
2154 cm_ReleaseSCache(scp);
2155 cm_ReleaseSCache(dscp);
2156 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp Lock failure scp=0x%p code=0x%x status=0x%x",
2160 /* the scp is now locked and current */
2161 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId, 0);
2163 code = cm_UnlockByKey(scp, key,
2164 CM_UNLOCK_FLAG_BY_FID,
2167 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2168 lock_ReleaseWrite(&scp->rw);
2170 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
2171 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
2173 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2175 lock_ReleaseWrite(&scp->rw);
2179 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
2181 (*ResultCB)->ResultBufferLength = sizeof( AFSFileDeleteResultCB);
2183 pResultCB = (AFSFileDeleteResultCB *)(*ResultCB)->ResultData;
2185 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
2186 osi_Log0(afsd_logp, "RDR_DeleteFileEntry SUCCESS");
2188 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2189 (*ResultCB)->ResultStatus = status;
2190 (*ResultCB)->ResultBufferLength = 0;
2191 osi_Log2(afsd_logp, "RDR_DeleteFileEntry FAILURE code=0x%x status=0x%x",
2195 cm_ReleaseSCache(dscp);
2196 cm_ReleaseSCache(scp);
2202 RDR_RenameFileEntry( IN cm_user_t *userp,
2203 IN WCHAR *SourceFileNameCounted,
2204 IN DWORD SourceFileNameLength,
2205 IN AFSFileID SourceFileId,
2206 IN AFSFileRenameCB *pRenameCB,
2208 IN DWORD ResultBufferLength,
2209 IN OUT AFSCommResult **ResultCB)
2212 AFSFileRenameResultCB *pResultCB = NULL;
2213 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2214 AFSFileID SourceParentId = pRenameCB->SourceParentId;
2215 AFSFileID TargetParentId = pRenameCB->TargetParentId;
2216 WCHAR * TargetFileNameCounted = pRenameCB->TargetName;
2217 DWORD TargetFileNameLength = pRenameCB->TargetNameLength;
2218 cm_fid_t SourceParentFid;
2219 cm_fid_t TargetParentFid;
2221 cm_fid_t OrigTargetFid = {0,0,0,0,0};
2223 cm_scache_t * oldDscp;
2224 cm_scache_t * newDscp;
2226 wchar_t shortName[13];
2227 wchar_t SourceFileName[260];
2228 wchar_t TargetFileName[260];
2236 req.flags |= CM_REQ_WOW64;
2238 StringCchCopyNW(SourceFileName, 260, SourceFileNameCounted, SourceFileNameLength / sizeof(WCHAR));
2239 StringCchCopyNW(TargetFileName, 260, TargetFileNameCounted, TargetFileNameLength / sizeof(WCHAR));
2241 osi_Log4(afsd_logp, "RDR_RenameFileEntry Source Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2242 SourceParentId.Cell, SourceParentId.Volume,
2243 SourceParentId.Vnode, SourceParentId.Unique);
2244 osi_Log2(afsd_logp, "... Source Name=%S Length %u", osi_LogSaveStringW(afsd_logp, SourceFileName), SourceFileNameLength);
2245 osi_Log4(afsd_logp, "... Target Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2246 TargetParentId.Cell, TargetParentId.Volume,
2247 TargetParentId.Vnode, TargetParentId.Unique);
2248 osi_Log2(afsd_logp, "... Target Name=%S Length %u", osi_LogSaveStringW(afsd_logp, TargetFileName), TargetFileNameLength);
2250 *ResultCB = (AFSCommResult *)malloc( size);
2258 pResultCB = (AFSFileRenameResultCB *)(*ResultCB)->ResultData;
2260 if (SourceFileNameLength == 0 || TargetFileNameLength == 0)
2262 osi_Log2(afsd_logp, "RDR_RenameFileEntry Invalid Name Length: src %u target %u",
2263 SourceFileNameLength, TargetFileNameLength);
2264 (*ResultCB)->ResultStatus = STATUS_INVALID_PARAMETER;
2268 SourceParentFid.cell = SourceParentId.Cell;
2269 SourceParentFid.volume = SourceParentId.Volume;
2270 SourceParentFid.vnode = SourceParentId.Vnode;
2271 SourceParentFid.unique = SourceParentId.Unique;
2272 SourceParentFid.hash = SourceParentId.Hash;
2274 TargetParentFid.cell = TargetParentId.Cell;
2275 TargetParentFid.volume = TargetParentId.Volume;
2276 TargetParentFid.vnode = TargetParentId.Vnode;
2277 TargetParentFid.unique = TargetParentId.Unique;
2278 TargetParentFid.hash = TargetParentId.Hash;
2280 code = cm_GetSCache(&SourceParentFid, &oldDscp, userp, &req);
2282 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache source parent failed code 0x%x", code);
2283 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2284 if ( status == STATUS_INVALID_HANDLE)
2285 status = STATUS_OBJECT_PATH_INVALID;
2286 (*ResultCB)->ResultStatus = status;
2290 lock_ObtainWrite(&oldDscp->rw);
2291 code = cm_SyncOp(oldDscp, NULL, userp, &req, 0,
2292 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2294 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp oldDscp 0x%p failed code 0x%x", oldDscp, code);
2295 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2296 if ( status == STATUS_INVALID_HANDLE)
2297 status = STATUS_OBJECT_PATH_INVALID;
2298 (*ResultCB)->ResultStatus = status;
2299 lock_ReleaseWrite(&oldDscp->rw);
2300 cm_ReleaseSCache(oldDscp);
2304 cm_SyncOpDone(oldDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2305 lock_ReleaseWrite(&oldDscp->rw);
2308 if (oldDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2309 osi_Log1(afsd_logp, "RDR_RenameFileEntry oldDscp 0x%p not a directory", oldDscp);
2310 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2311 cm_ReleaseSCache(oldDscp);
2315 code = cm_GetSCache(&TargetParentFid, &newDscp, userp, &req);
2317 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target parent failed code 0x%x", code);
2318 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2319 (*ResultCB)->ResultStatus = status;
2320 cm_ReleaseSCache(oldDscp);
2324 lock_ObtainWrite(&newDscp->rw);
2325 code = cm_SyncOp(newDscp, NULL, userp, &req, 0,
2326 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2328 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp newDscp 0x%p failed code 0x%x", newDscp, code);
2329 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2330 (*ResultCB)->ResultStatus = status;
2331 lock_ReleaseWrite(&newDscp->rw);
2332 cm_ReleaseSCache(oldDscp);
2333 cm_ReleaseSCache(newDscp);
2337 cm_SyncOpDone(newDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2338 lock_ReleaseWrite(&newDscp->rw);
2341 if (newDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2342 osi_Log1(afsd_logp, "RDR_RenameFileEntry newDscp 0x%p not a directory", newDscp);
2343 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2344 cm_ReleaseSCache(oldDscp);
2345 cm_ReleaseSCache(newDscp);
2349 /* Obtain the original FID just for debugging purposes */
2350 code = cm_BeginDirOp( oldDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2352 code = cm_BPlusDirLookup(&dirop, SourceFileName, &SourceFid);
2353 code = cm_BPlusDirLookup(&dirop, TargetFileName, &OrigTargetFid);
2354 cm_EndDirOp(&dirop);
2357 code = cm_Rename( oldDscp, NULL, SourceFileName,
2358 newDscp, TargetFileName, userp, &req);
2360 cm_scache_t *scp = 0;
2363 (*ResultCB)->ResultBufferLength = ResultBufferLength;
2364 dwRemaining = ResultBufferLength - sizeof( AFSFileRenameResultCB) + sizeof( AFSDirEnumEntry);
2365 (*ResultCB)->ResultStatus = 0;
2367 pResultCB->SourceParentDataVersion.QuadPart = oldDscp->dataVersion;
2368 pResultCB->TargetParentDataVersion.QuadPart = newDscp->dataVersion;
2370 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p SUCCESS",
2373 code = cm_BeginDirOp( newDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2375 code = cm_BPlusDirLookup(&dirop, TargetFileName, &TargetFid);
2376 cm_EndDirOp(&dirop);
2380 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_BPlusDirLookup failed code 0x%x",
2382 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
2383 cm_ReleaseSCache(oldDscp);
2384 cm_ReleaseSCache(newDscp);
2388 osi_Log4(afsd_logp, "RDR_RenameFileEntry Target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2389 TargetFid.cell, TargetFid.volume,
2390 TargetFid.vnode, TargetFid.unique);
2392 code = cm_GetSCache(&TargetFid, &scp, userp, &req);
2394 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target failed code 0x%x", code);
2395 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2396 (*ResultCB)->ResultStatus = status;
2397 cm_ReleaseSCache(oldDscp);
2398 cm_ReleaseSCache(newDscp);
2402 /* Make sure the source vnode is current */
2403 lock_ObtainWrite(&scp->rw);
2404 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2405 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2407 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp scp 0x%p failed code 0x%x", scp, code);
2408 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2409 (*ResultCB)->ResultStatus = status;
2410 lock_ReleaseWrite(&scp->rw);
2411 cm_ReleaseSCache(oldDscp);
2412 cm_ReleaseSCache(newDscp);
2413 cm_ReleaseSCache(scp);
2417 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2418 lock_ReleaseWrite(&scp->rw);
2420 dfid.vnode = htonl(scp->fid.vnode);
2421 dfid.unique = htonl(scp->fid.unique);
2423 if (!cm_Is8Dot3(TargetFileName))
2424 cm_Gen8Dot3NameIntW(TargetFileName, &dfid, shortName, NULL);
2426 shortName[0] = '\0';
2428 RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
2429 newDscp, scp, userp, &req, TargetFileName, shortName,
2430 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
2431 0, NULL, &dwRemaining);
2432 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
2433 cm_ReleaseSCache(scp);
2435 osi_Log0(afsd_logp, "RDR_RenameFileEntry SUCCESS");
2437 osi_Log3(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p failed code 0x%x",
2438 oldDscp, newDscp, code);
2439 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2440 (*ResultCB)->ResultStatus = status;
2441 (*ResultCB)->ResultBufferLength = 0;
2444 cm_ReleaseSCache(oldDscp);
2445 cm_ReleaseSCache(newDscp);
2450 RDR_FlushFileEntry( IN cm_user_t *userp,
2451 IN AFSFileID FileId,
2453 IN DWORD ResultBufferLength,
2454 IN OUT AFSCommResult **ResultCB)
2456 cm_scache_t *scp = NULL;
2467 req.flags |= CM_REQ_WOW64;
2469 osi_Log4(afsd_logp, "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x",
2470 FileId.Cell, FileId.Volume,
2471 FileId.Vnode, FileId.Unique);
2473 snprintf( dbgstr, 1024,
2474 "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x\n",
2475 FileId.Cell, FileId.Volume,
2476 FileId.Vnode, FileId.Unique);
2477 OutputDebugStringA( dbgstr);
2480 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2482 osi_Log0(afsd_logp, "RDR_FlushFileEntry out of memory");
2488 sizeof( AFSCommResult));
2490 /* Process the release */
2491 Fid.cell = FileId.Cell;
2492 Fid.volume = FileId.Volume;
2493 Fid.vnode = FileId.Vnode;
2494 Fid.unique = FileId.Unique;
2495 Fid.hash = FileId.Hash;
2497 code = cm_GetSCache(&Fid, &scp, userp, &req);
2499 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2500 (*ResultCB)->ResultStatus = status;
2501 osi_Log2(afsd_logp, "RDR_FlushFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2506 lock_ObtainWrite(&scp->rw);
2507 if (scp->flags & CM_SCACHEFLAG_DELETED) {
2508 lock_ReleaseWrite(&scp->rw);
2509 (*ResultCB)->ResultStatus = STATUS_INVALID_HANDLE;
2513 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2514 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2516 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2517 (*ResultCB)->ResultStatus = status;
2518 lock_ReleaseWrite(&scp->rw);
2519 cm_ReleaseSCache(scp);
2520 osi_Log3(afsd_logp, "RDR_FlushFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2525 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2526 lock_ReleaseWrite(&scp->rw);
2528 code = cm_FSync(scp, userp, &req, FALSE);
2529 cm_ReleaseSCache(scp);
2532 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2533 (*ResultCB)->ResultStatus = status;
2534 osi_Log2(afsd_logp, "RDR_FlushFileEntry FAILURE code=0x%x status=0x%x",
2537 (*ResultCB)->ResultStatus = 0;
2538 osi_Log0(afsd_logp, "RDR_FlushFileEntry SUCCESS");
2540 (*ResultCB)->ResultBufferLength = 0;
2546 RDR_CheckAccess( IN cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp,
2550 ULONG afs_acc, afs_gr;
2552 afs_uint32 code = 0;
2554 file = (scp->fileType == CM_SCACHETYPE_FILE);
2557 /* access definitions from prs_fs.h */
2559 if (access & FILE_READ_DATA)
2560 afs_acc |= PRSFS_READ;
2561 if (access & FILE_READ_EA || access & FILE_READ_ATTRIBUTES)
2562 afs_acc |= PRSFS_READ;
2563 if (file && ((access & FILE_WRITE_DATA) || (access & FILE_APPEND_DATA)))
2564 afs_acc |= PRSFS_WRITE;
2565 if (access & FILE_WRITE_EA || access & FILE_WRITE_ATTRIBUTES)
2566 afs_acc |= PRSFS_WRITE;
2567 if (dir && ((access & FILE_ADD_FILE) || (access & FILE_ADD_SUBDIRECTORY)))
2568 afs_acc |= PRSFS_INSERT;
2569 if (dir && (access & FILE_LIST_DIRECTORY))
2570 afs_acc |= PRSFS_LOOKUP;
2571 if (file && (access & FILE_EXECUTE))
2572 afs_acc |= PRSFS_WRITE;
2573 if (dir && (access & FILE_TRAVERSE))
2574 afs_acc |= PRSFS_READ;
2575 if (dir && (access & FILE_DELETE_CHILD))
2576 afs_acc |= PRSFS_DELETE;
2577 if ((access & DELETE))
2578 afs_acc |= PRSFS_DELETE;
2580 /* check ACL with server */
2581 lock_ObtainWrite(&scp->rw);
2584 if (cm_HaveAccessRights(scp, userp, reqp, afs_acc, &afs_gr))
2590 /* we don't know the required access rights */
2591 code = cm_GetAccessRights(scp, userp, reqp);
2597 lock_ReleaseWrite(&(scp->rw));
2601 if (afs_gr & PRSFS_READ)
2602 *granted |= FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | FILE_EXECUTE;
2603 if (afs_gr & PRSFS_WRITE)
2604 *granted |= FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES | FILE_EXECUTE;
2605 if (afs_gr & PRSFS_INSERT)
2606 *granted |= (dir ? FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY : 0) | (file ? FILE_ADD_SUBDIRECTORY : 0);
2607 if (afs_gr & PRSFS_LOOKUP)
2608 *granted |= (dir ? FILE_LIST_DIRECTORY : 0);
2609 if (afs_gr & PRSFS_DELETE)
2610 *granted |= FILE_DELETE_CHILD | DELETE;
2611 if (afs_gr & PRSFS_LOCK)
2613 if (afs_gr & PRSFS_ADMINISTER)
2616 *granted |= SYNCHRONIZE | READ_CONTROL;
2618 /* don't give more access than what was requested */
2620 osi_Log3(afsd_logp, "RDR_CheckAccess SUCCESS scp=0x%p requested=0x%x granted=0x%x", scp, access, *granted);
2622 osi_Log2(afsd_logp, "RDR_CheckAccess FAILURE scp=0x%p code=0x%x",
2629 RDR_OpenFileEntry( IN cm_user_t *userp,
2630 IN AFSFileID FileId,
2631 IN AFSFileOpenCB *OpenCB,
2634 IN DWORD ResultBufferLength,
2635 IN OUT AFSCommResult **ResultCB)
2637 AFSFileOpenResultCB *pResultCB = NULL;
2638 cm_scache_t *scp = NULL;
2639 cm_user_t *sysUserp = NULL;
2641 cm_lock_data_t *ldp = NULL;
2648 req.flags |= CM_REQ_WOW64;
2650 osi_Log4(afsd_logp, "RDR_OpenFileEntry File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2651 FileId.Cell, FileId.Volume,
2652 FileId.Vnode, FileId.Unique);
2654 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2656 osi_Log0(afsd_logp, "RDR_OpenFileEntry out of memory");
2662 sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2664 pResultCB = (AFSFileOpenResultCB *)(*ResultCB)->ResultData;
2666 /* Process the release */
2667 Fid.cell = FileId.Cell;
2668 Fid.volume = FileId.Volume;
2669 Fid.vnode = FileId.Vnode;
2670 Fid.unique = FileId.Unique;
2671 Fid.hash = FileId.Hash;
2673 code = cm_GetSCache(&Fid, &scp, userp, &req);
2675 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2676 (*ResultCB)->ResultStatus = status;
2677 osi_Log2(afsd_logp, "RDR_OpenFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2682 lock_ObtainWrite(&scp->rw);
2683 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2684 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2686 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2687 (*ResultCB)->ResultStatus = status;
2688 lock_ReleaseWrite(&scp->rw);
2689 cm_ReleaseSCache(scp);
2690 osi_Log3(afsd_logp, "RDR_OpenFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2695 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2696 lock_ReleaseWrite(&scp->rw);
2698 sysUserp = RDR_GetLocalSystemUser();
2701 * Skip the open check if the request is coming from the local system account.
2702 * The local system has no tokens and therefore any requests sent to a file
2703 * server will fail. Unfortunately, there are special system processes that
2704 * perform actions on files and directories in preparation for memory mapping
2705 * executables. If the open check fails, the real request from the user process
2706 * will never be issued.
2708 * Permitting the file system to allow subsequent operations to proceed does
2709 * not compromise security. All requests to obtain file data or directory
2710 * enumerations will subsequently fail if they are not submitted under the
2711 * context of a process for that have access to the necessary credentials.
2714 if ( userp == sysUserp)
2716 osi_Log1(afsd_logp, "RDR_OpenFileEntry LOCAL_SYSTEM access check skipped scp=0x%p",
2718 pResultCB->GrantedAccess = OpenCB->DesiredAccess;
2719 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2730 "RDR_OpenFileEntry repeating open check scp=0x%p userp=0x%p code=0x%x",
2733 code = cm_CheckNTOpen(scp, OpenCB->DesiredAccess, OpenCB->ShareAccess,
2735 OpenCB->ProcessId, OpenCB->Identifier,
2738 code = RDR_CheckAccess(scp, userp, &req, OpenCB->DesiredAccess, &pResultCB->GrantedAccess);
2739 cm_CheckNTOpenDone(scp, userp, &req, &ldp);
2740 } while (count < 100 && (code == CM_ERROR_RETRY || code == CM_ERROR_WOULDBLOCK));
2744 * If we are restricting sharing, we should do so with a suitable
2747 if (code == 0 && scp->fileType == CM_SCACHETYPE_FILE && !(OpenCB->ShareAccess & FILE_SHARE_WRITE)) {
2749 LARGE_INTEGER LOffset, LLength;
2752 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2753 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2754 LLength.HighPart = 0;
2755 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2758 * If we are not opening the file for writing, then we don't
2759 * try to get an exclusive lock. No one else should be able to
2760 * get an exclusive lock on the file anyway, although someone
2761 * else can get a shared lock.
2763 if ((OpenCB->ShareAccess & FILE_SHARE_READ) || !(OpenCB->DesiredAccess & AFS_ACCESS_WRITE))
2765 sLockType = LOCKING_ANDX_SHARED_LOCK;
2770 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, OpenCB->Identifier);
2772 lock_ObtainWrite(&scp->rw);
2773 code = cm_Lock(scp, sLockType, LOffset, LLength, key, 0, userp, &req, NULL);
2774 lock_ReleaseWrite(&scp->rw);
2777 code = CM_ERROR_SHARING_VIOLATION;
2778 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2780 if (sLockType == LOCKING_ANDX_SHARED_LOCK)
2781 pResultCB->FileAccess = AFS_FILE_ACCESS_SHARED;
2783 pResultCB->FileAccess = AFS_FILE_ACCESS_EXCLUSIVE;
2786 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2789 cm_ReleaseUser(sysUserp);
2790 if (code == 0 && bHoldFid)
2791 RDR_FlagScpInUse( scp, FALSE );
2792 cm_ReleaseSCache(scp);
2795 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2796 (*ResultCB)->ResultStatus = status;
2797 osi_Log2(afsd_logp, "RDR_OpenFileEntry FAILURE code=0x%x status=0x%x",
2800 (*ResultCB)->ResultStatus = 0;
2801 (*ResultCB)->ResultBufferLength = sizeof( AFSFileOpenResultCB);
2802 osi_Log0(afsd_logp, "RDR_OpenFileEntry SUCCESS");
2808 RDR_ReleaseFileAccess( IN cm_user_t *userp,
2809 IN AFSFileID FileId,
2810 IN AFSFileAccessReleaseCB *ReleaseFileCB,
2812 IN DWORD ResultBufferLength,
2813 IN OUT AFSCommResult **ResultCB)
2816 unsigned int sLockType;
2817 LARGE_INTEGER LOffset, LLength;
2818 cm_scache_t *scp = NULL;
2826 req.flags |= CM_REQ_WOW64;
2828 osi_Log4(afsd_logp, "RDR_ReleaseFileAccess File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2829 FileId.Cell, FileId.Volume,
2830 FileId.Vnode, FileId.Unique);
2832 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2834 osi_Log0(afsd_logp, "RDR_ReleaseFileAccess out of memory");
2838 memset( *ResultCB, '\0', sizeof( AFSCommResult));
2840 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_NOLOCK)
2843 /* Process the release */
2844 Fid.cell = FileId.Cell;
2845 Fid.volume = FileId.Volume;
2846 Fid.vnode = FileId.Vnode;
2847 Fid.unique = FileId.Unique;
2848 Fid.hash = FileId.Hash;
2850 code = cm_GetSCache(&Fid, &scp, userp, &req);
2852 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2853 (*ResultCB)->ResultStatus = status;
2854 osi_Log2(afsd_logp, "RDR_ReleaseFileAccess cm_GetSCache FID failure code=0x%x status=0x%x",
2859 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_SHARED)
2860 sLockType = LOCKING_ANDX_SHARED_LOCK;
2864 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, ReleaseFileCB->Identifier);
2866 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2867 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2868 LLength.HighPart = 0;
2869 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2871 lock_ObtainWrite(&scp->rw);
2873 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
2876 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
2878 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
2880 if (code == CM_ERROR_RANGE_NOT_LOCKED)
2882 osi_Log3(afsd_logp, "RDR_ReleaseFileAccess Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
2883 ReleaseFileCB->FileAccess, ReleaseFileCB->ProcessId, ReleaseFileCB->Identifier);
2887 lock_ReleaseWrite(&scp->rw);
2889 osi_Log0(afsd_logp, "RDR_ReleaseFileAccessEntry SUCCESS");
2893 HexCheckSum(unsigned char * buf, int buflen, unsigned char * md5cksum)
2896 static char tr[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
2899 return "buffer length too small to HexCheckSum";
2901 for (i=0;i<16;i++) {
2904 buf[i*2] = tr[k / 16];
2905 buf[i*2+1] = tr[k % 16];
2913 * Extent requests from the file system are triggered when a file
2914 * page is not resident in the Windows cache. The file system is
2915 * responsible for loading the page but cannot block the request
2916 * while doing so. The AFS Redirector forwards the requests to
2917 * the AFS cache manager while indicating to Windows that the page
2918 * is not yet available. A polling operation will then ensue with
2919 * the AFS Redirector issuing a RDR_RequestFileExtentsXXX call for
2920 * each poll attempt. As each request is received and processed
2921 * by a separate worker thread in the service, this can lead to
2922 * contention by multiple threads attempting to claim the same
2923 * cm_buf_t objects. Therefore, it is important that
2925 * (a) the service avoid processing more than one overlapping
2926 * extent request at a time
2927 * (b) background daemon processing be used to avoid blocking
2930 * Beginning with the 20091122 build of the redirector, the redirector
2931 * will not issue an additional RDR_RequestFileExtentsXXX call for
2932 * each poll request. Instead, afsd_service is required to track
2933 * the requests and return them to the redirector or fail the
2934 * portions of the request that cannot be satisfied.
2936 * The request processing returns any extents that can be returned
2937 * immediately to the redirector. The rest of the requested range(s)
2938 * are queued as background operations using RDR_BkgFetch().
2941 /* do the background fetch. */
2943 RDR_BkgFetch(cm_scache_t *scp, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4,
2944 cm_user_t *userp, cm_req_t *reqp)
2950 osi_hyper_t fetched;
2951 osi_hyper_t tblocksize;
2954 cm_buf_t *bufp = NULL;
2955 DWORD dwResultBufferLength;
2956 AFSSetFileExtentsCB *pResultCB;
2960 int reportErrorToRedir = 0;
2961 int force_retry = 0;
2963 FileId.Cell = scp->fid.cell;
2964 FileId.Volume = scp->fid.volume;
2965 FileId.Vnode = scp->fid.vnode;
2966 FileId.Unique = scp->fid.unique;
2967 FileId.Hash = scp->fid.hash;
2969 if ((GetTickCount() - reqp->startTime) / 1000 > HardDeadtimeout * 5) {
2970 RDR_SetFileStatus( &scp->fid, &userp->authgroup, STATUS_IO_TIMEOUT);
2974 fetched.LowPart = 0;
2975 fetched.HighPart = 0;
2976 tblocksize = ConvertLongToLargeInteger(cm_data.buf_blockSize);
2979 length.LowPart = p3;
2980 length.HighPart = p4;
2982 end = LargeIntegerAdd(base, length);
2984 osi_Log5(afsd_logp, "Starting BKG Fetch scp 0x%p offset 0x%x:%x length 0x%x:%x",
2985 scp, p2, p1, p4, p3);
2988 * Make sure we have a callback.
2989 * This is necessary so that we can return access denied
2990 * if a callback cannot be granted.
2992 lock_ObtainWrite(&scp->rw);
2993 code = cm_SyncOp(scp, NULL, userp, reqp, PRSFS_READ,
2994 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2996 lock_ReleaseWrite(&scp->rw);
2997 osi_Log2(afsd_logp, "RDR_BkgFetch cm_SyncOp failure scp=0x%p code=0x%x",
2999 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
3000 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3003 lock_ReleaseWrite(&scp->rw);
3005 dwResultBufferLength = (DWORD)(sizeof( AFSSetFileExtentsCB) + sizeof( AFSSetFileExtentsCB) * (length.QuadPart / cm_data.blockSize + 1));
3006 pResultCB = (AFSSetFileExtentsCB *)malloc( dwResultBufferLength );
3008 return CM_ERROR_RETRY;
3010 memset( pResultCB, '\0', dwResultBufferLength );
3011 pResultCB->FileId = FileId;
3013 for ( code = 0, offset = base;
3014 code == 0 && LargeIntegerLessThan(offset, end);
3015 offset = LargeIntegerAdd(offset, tblocksize) )
3017 int bBufRelease = TRUE;
3020 lock_ReleaseWrite(&scp->rw);
3024 code = buf_Get(scp, &offset, reqp, &bufp);
3027 * any error from buf_Get() is non-fatal.
3028 * we need to re-queue this extent fetch.
3035 lock_ObtainWrite(&scp->rw);
3039 code = cm_GetBuffer(scp, bufp, NULL, userp, reqp);
3041 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3042 #ifdef VALIDATE_CHECK_SUM
3048 if (bufp->flags & CM_BUF_DIRTY)
3049 cm_BufWrite(scp, &bufp->offset, cm_data.buf_blockSize, CM_BUF_WRITE_SCP_LOCKED, userp, reqp);
3051 lock_ObtainWrite(&buf_globalLock);
3052 if (!(bufp->flags & CM_BUF_DIRTY) &&
3053 bufp->cmFlags == 0 &&
3054 !(bufp->qFlags & CM_BUF_QREDIR)) {
3055 buf_InsertToRedirQueue(scp, bufp);
3056 lock_ReleaseWrite(&buf_globalLock);
3058 #ifdef VALIDATE_CHECK_SUM
3059 buf_ComputeCheckSum(bufp);
3061 pResultCB->FileExtents[count].Flags = 0;
3062 pResultCB->FileExtents[count].FileOffset.QuadPart = bufp->offset.QuadPart;
3063 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3064 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3066 fetched = LargeIntegerAdd(fetched, tblocksize);
3067 bBufRelease = FALSE;
3069 #ifdef VALIDATE_CHECK_SUM
3071 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3072 snprintf( dbgstr, 1024,
3073 "RDR_BkgFetch md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3075 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3076 pResultCB->FileExtents[count].FileOffset.HighPart,
3077 pResultCB->FileExtents[count].FileOffset.LowPart,
3078 pResultCB->FileExtents[count].CacheOffset.HighPart,
3079 pResultCB->FileExtents[count].CacheOffset.LowPart);
3080 OutputDebugStringA( dbgstr);
3083 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3084 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3086 lock_ReleaseWrite(&buf_globalLock);
3087 if ((bufp->cmFlags != 0) || (bufp->flags & CM_BUF_DIRTY)) {
3088 /* An I/O operation is already in progress */
3090 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",
3091 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3093 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3094 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3098 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3099 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3103 * depending on what the error from cm_GetBuffer is
3104 * it may or may not be fatal. Only return fatal errors.
3105 * Re-queue a request for others.
3107 osi_Log5(afsd_logp, "RDR_BkgFetch Extent2FS FAILURE bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x code 0x%x",
3108 bufp, offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize, code);
3110 case CM_ERROR_NOACCESS:
3111 case CM_ERROR_NOSUCHFILE:
3112 case CM_ERROR_NOSUCHPATH:
3113 case CM_ERROR_NOSUCHVOLUME:
3114 case CM_ERROR_NOSUCHCELL:
3115 case CM_ERROR_INVAL:
3116 case CM_ERROR_BADFD:
3117 case CM_ERROR_CLOCKSKEW:
3119 case CM_ERROR_QUOTA:
3120 case CM_ERROR_LOCK_CONFLICT:
3122 * these are fatal errors. deliver what we can
3125 reportErrorToRedir = 1;
3129 * non-fatal errors. re-queue the exent
3131 code = CM_ERROR_RETRY;
3141 lock_ObtainWrite(&scp->rw);
3145 /* wakeup anyone who is waiting */
3146 if (scp->flags & CM_SCACHEFLAG_WAITING) {
3147 osi_Log1(afsd_logp, "RDR Bkg Fetch Waking scp 0x%p", scp);
3148 osi_Wakeup((LONG_PTR) &scp->flags);
3150 lock_ReleaseWrite(&scp->rw);
3153 pResultCB->ExtentCount = count;
3154 RDR_SetFileExtents( pResultCB, dwResultBufferLength);
3158 if (reportErrorToRedir) {
3159 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
3160 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3163 osi_Log4(afsd_logp, "Ending BKG Fetch scp 0x%p code 0x%x fetched 0x%x:%x",
3164 scp, code, fetched.HighPart, fetched.LowPart);
3166 return force_retry ? CM_ERROR_RETRY : code;
3171 RDR_RequestFileExtentsAsync( IN cm_user_t *userp,
3172 IN AFSFileID FileId,
3173 IN AFSRequestExtentsCB *RequestExtentsCB,
3175 IN OUT DWORD * ResultBufferLength,
3176 IN OUT AFSSetFileExtentsCB **ResultCB)
3178 AFSSetFileExtentsCB *pResultCB = NULL;
3182 cm_scache_t *scp = NULL;
3185 afs_uint32 code = 0;
3187 LARGE_INTEGER ByteOffset, BeginOffset, EndOffset, QueueOffset;
3188 afs_uint32 QueueLength;
3190 BOOLEAN bBufRelease = TRUE;
3194 req.flags |= CM_REQ_WOW64;
3195 req.flags |= CM_REQ_NORETRY;
3197 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3198 FileId.Cell, FileId.Volume,
3199 FileId.Vnode, FileId.Unique);
3200 osi_Log4(afsd_logp, "... Flags 0x%x ByteOffset 0x%x:%x Length 0x%x",
3201 RequestExtentsCB->Flags,
3202 RequestExtentsCB->ByteOffset.HighPart, RequestExtentsCB->ByteOffset.LowPart,
3203 RequestExtentsCB->Length);
3204 Length = sizeof( AFSSetFileExtentsCB) + sizeof( AFSFileExtentCB) * (RequestExtentsCB->Length / cm_data.blockSize + 1);
3206 pResultCB = *ResultCB = (AFSSetFileExtentsCB *)malloc( Length );
3207 if (*ResultCB == NULL) {
3208 *ResultBufferLength = 0;
3211 *ResultBufferLength = Length;
3213 memset( pResultCB, '\0', Length );
3214 pResultCB->FileId = FileId;
3216 Fid.cell = FileId.Cell;
3217 Fid.volume = FileId.Volume;
3218 Fid.vnode = FileId.Vnode;
3219 Fid.unique = FileId.Unique;
3220 Fid.hash = FileId.Hash;
3222 code = cm_GetSCache(&Fid, &scp, userp, &req);
3224 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync cm_GetSCache FID failure code=0x%x",
3226 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3231 * Make sure we have a callback.
3232 * This is necessary so that we can return access denied
3233 * if a callback cannot be granted.
3235 lock_ObtainWrite(&scp->rw);
3236 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_READ,
3237 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3238 lock_ReleaseWrite(&scp->rw);
3240 cm_ReleaseSCache(scp);
3241 osi_Log2(afsd_logp, "RDR_RequestFileExtentsAsync cm_SyncOp failure scp=0x%p code=0x%x",
3243 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3244 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3248 /* Allocate the extents from the buffer package */
3250 ByteOffset = BeginOffset = RequestExtentsCB->ByteOffset,
3251 EndOffset.QuadPart = ByteOffset.QuadPart + RequestExtentsCB->Length;
3252 code == 0 && ByteOffset.QuadPart < EndOffset.QuadPart;
3253 ByteOffset.QuadPart += cm_data.blockSize)
3255 BOOL bHaveBuffer = FALSE;
3258 thyper.QuadPart = ByteOffset.QuadPart;
3260 code = buf_Get(scp, &thyper, &req, &bufp);
3262 lock_ObtainMutex(&bufp->mx);
3265 if (bufp->qFlags & CM_BUF_QREDIR) {
3267 } else if (bufp->flags & CM_BUF_DIRTY) {
3268 bHaveBuffer = FALSE;
3270 code = buf_CleanAsyncLocked(scp, bufp, &req, 0, NULL);
3275 case CM_ERROR_RETRY:
3276 /* Couldn't flush it, obtain it asynchronously so we don't block the thread. */
3277 bHaveBuffer = FALSE;
3281 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3282 RDR_SetFileStatus(&FileId, &userp->authgroup, status);
3283 bHaveBuffer = FALSE;
3288 osi_hyper_t minLength; /* effective end of file */
3290 lock_ObtainRead(&scp->rw);
3291 bHaveBuffer = cm_HaveBuffer(scp, bufp, TRUE);
3293 if (LargeIntegerGreaterThan(scp->length, scp->serverLength))
3294 minLength = scp->serverLength;
3296 minLength = scp->length;
3299 LargeIntegerGreaterThanOrEqualTo(bufp->offset, minLength)) {
3300 memset(bufp->datap, 0, cm_data.buf_blockSize);
3301 bufp->dataVersion = scp->dataVersion;
3304 else if ((RequestExtentsCB->Flags & AFS_EXTENT_FLAG_CLEAN) &&
3305 ByteOffset.QuadPart <= bufp->offset.QuadPart &&
3306 EndOffset.QuadPart >= bufp->offset.QuadPart + cm_data.blockSize)
3308 memset(bufp->datap, 0, cm_data.blockSize);
3309 bufp->dataVersion = scp->dataVersion;
3310 buf_SetDirty(bufp, &req, 0, cm_data.blockSize, userp);
3313 lock_ReleaseRead(&scp->rw);
3317 * if this buffer is already up to date, skip it.
3320 if (ByteOffset.QuadPart == BeginOffset.QuadPart) {
3321 BeginOffset.QuadPart += cm_data.blockSize;
3323 QueueLength = (afs_uint32)(ByteOffset.QuadPart - BeginOffset.QuadPart);
3324 QueueOffset = BeginOffset;
3325 BeginOffset = ByteOffset;
3328 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3329 #ifdef VALIDATE_CHECK_SUM
3335 lock_ObtainWrite(&buf_globalLock);
3336 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3337 buf_InsertToRedirQueue(scp, bufp);
3338 lock_ReleaseWrite(&buf_globalLock);
3340 #ifdef VALIDATE_CHECK_SUM
3341 buf_ComputeCheckSum(bufp);
3343 /* we already have the buffer, return it now */
3344 pResultCB->FileExtents[count].Flags = 0;
3345 pResultCB->FileExtents[count].FileOffset = ByteOffset;
3346 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3347 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3350 bBufRelease = FALSE;
3352 #ifdef VALIDATE_CHECK_SUM
3354 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3355 snprintf( dbgstr, 1024,
3356 "RDR_RequestFileExtentsAsync md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3358 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3359 pResultCB->FileExtents[count].FileOffset.HighPart,
3360 pResultCB->FileExtents[count].FileOffset.LowPart,
3361 pResultCB->FileExtents[count].CacheOffset.HighPart,
3362 pResultCB->FileExtents[count].CacheOffset.LowPart);
3363 OutputDebugStringA( dbgstr);
3366 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3367 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3369 lock_ReleaseWrite(&buf_globalLock);
3374 * The service is not handing off the extent to the redirector in this pass.
3375 * However, we know the buffer is in recent use so move the buffer to the
3376 * front of the queue
3378 lock_ObtainWrite(&buf_globalLock);
3379 buf_MoveToHeadOfRedirQueue(scp, bufp);
3380 lock_ReleaseWrite(&buf_globalLock);
3382 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3383 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3387 lock_ReleaseMutex(&bufp->mx);
3392 cm_QueueBKGRequest(scp, RDR_BkgFetch, QueueOffset.LowPart, QueueOffset.HighPart,
3393 QueueLength, 0, userp, &req);
3394 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3395 QueueOffset.HighPart, QueueOffset.LowPart, QueueLength);
3398 /* No error from buf_Get() can be fatal */
3399 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync buf_Get FAILURE offset 0x%x:%x code 0x%x",
3400 BeginOffset.HighPart, BeginOffset.LowPart, code);
3404 if (BeginOffset.QuadPart != EndOffset.QuadPart) {
3405 afs_uint32 length = (afs_uint32)(EndOffset.QuadPart - BeginOffset.QuadPart);
3407 cm_QueueBKGRequest(scp, RDR_BkgFetch, BeginOffset.LowPart, BeginOffset.HighPart,
3408 length, 0, userp, &req);
3409 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3410 BeginOffset.HighPart, BeginOffset.LowPart, length);
3412 cm_ReleaseSCache(scp);
3414 (*ResultCB)->ExtentCount = count;
3415 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync replying with 0x%x extent records", count);
3420 * When processing an extent release the extents must be accepted back by
3421 * the service even if there is an error condition returned to the redirector.
3422 * For example, there may no longer be a callback present or the file may
3423 * have been deleted on the file server. Regardless, the extents must be
3424 * put back into the pool.
3427 RDR_ReleaseFileExtents( IN cm_user_t *userp,
3428 IN AFSFileID FileId,
3429 IN AFSReleaseExtentsCB *ReleaseExtentsCB,
3431 IN DWORD ResultBufferLength,
3432 IN OUT AFSCommResult **ResultCB)
3435 cm_scache_t *scp = NULL;
3446 #ifdef VALIDATE_CHECK_SUM
3447 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3454 req.flags |= CM_REQ_WOW64;
3456 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3457 FileId.Cell, FileId.Volume,
3458 FileId.Vnode, FileId.Unique);
3460 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
3466 sizeof( AFSCommResult));
3468 /* Process the release */
3469 Fid.cell = FileId.Cell;
3470 Fid.volume = FileId.Volume;
3471 Fid.vnode = FileId.Vnode;
3472 Fid.unique = FileId.Unique;
3473 Fid.hash = FileId.Hash;
3475 code = cm_GetSCache(&Fid, &scp, userp, &req);
3477 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3478 (*ResultCB)->ResultStatus = status;
3479 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents cm_GetSCache FID failure code=0x%x status=0x%x",
3483 deleted = scp && (scp->flags & CM_SCACHEFLAG_DELETED);
3486 * We do not stop processing as a result of being unable to find the cm_scache object.
3487 * If this occurs something really bad has happened since the cm_scache object must have
3488 * been recycled while extents were held by the redirector. However, we will be resilient
3489 * and carry on without it.
3491 * If the file is known to be deleted, there is no point attempting to ask the
3492 * file server about it or update the attributes.
3494 if (scp && ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart &&
3499 memset(&setAttr, 0, sizeof(cm_attr_t));
3500 lock_ObtainWrite(&scp->rw);
3501 if (ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3503 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents new length fid vol 0x%x vno 0x%x length 0x%x:%x",
3504 scp->fid.volume, scp->fid.vnode,
3505 ReleaseExtentsCB->AllocationSize.HighPart,
3506 ReleaseExtentsCB->AllocationSize.LowPart);
3508 setAttr.mask |= CM_ATTRMASK_LENGTH;
3509 setAttr.length.LowPart = ReleaseExtentsCB->AllocationSize.LowPart;
3510 setAttr.length.HighPart = ReleaseExtentsCB->AllocationSize.HighPart;
3512 lock_ReleaseWrite(&scp->rw);
3514 code = cm_SetAttr(scp, &setAttr, userp, &req);
3517 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3518 AFSFileExtentCB * pExtent = &ReleaseExtentsCB->FileExtents[count];
3520 thyper.QuadPart = pExtent->FileOffset.QuadPart;
3522 bufp = buf_Find(&Fid, &thyper);
3524 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
3525 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3526 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3527 Fid.volume, Fid.vnode,
3528 pExtent->FileOffset.HighPart,
3529 pExtent->FileOffset.LowPart);
3530 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
3531 pExtent->CacheOffset.HighPart,
3532 pExtent->CacheOffset.LowPart);
3534 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3535 Fid.volume, Fid.vnode,
3536 pExtent->FileOffset.HighPart,
3537 pExtent->FileOffset.LowPart);
3538 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
3539 pExtent->CacheOffset.HighPart,
3540 pExtent->CacheOffset.LowPart);
3546 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
3547 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3548 Fid.volume, Fid.vnode,
3549 pExtent->FileOffset.HighPart,
3550 pExtent->FileOffset.LowPart);
3551 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
3552 pExtent->CacheOffset.HighPart,
3553 pExtent->CacheOffset.LowPart);
3555 /* Move the buffer to the front of the queue */
3556 lock_ObtainWrite(&buf_globalLock);
3557 buf_MoveToHeadOfRedirQueue(scp, bufp);
3558 lock_ReleaseWrite(&buf_globalLock);
3563 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
3564 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3565 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x not held by file system",
3566 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
3567 pExtent->FileOffset.LowPart);
3568 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3569 pExtent->CacheOffset.HighPart,
3570 pExtent->CacheOffset.LowPart);
3572 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents bufp 0x%p vno 0x%x foffset 0x%x:%x",
3573 bufp, bufp->fid.vnode, pExtent->FileOffset.HighPart,
3574 pExtent->FileOffset.LowPart);
3575 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3576 pExtent->CacheOffset.HighPart,
3577 pExtent->CacheOffset.LowPart);
3579 if (pExtent->Flags || ReleaseExtentsCB->Flags) {
3580 lock_ObtainMutex(&bufp->mx);
3581 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
3582 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
3584 if (bufp->qFlags & CM_BUF_QREDIR) {
3585 lock_ObtainWrite(&buf_globalLock);
3586 if (bufp->qFlags & CM_BUF_QREDIR) {
3587 buf_RemoveFromRedirQueue(scp, bufp);
3588 buf_ReleaseLocked(bufp, TRUE);
3590 lock_ReleaseWrite(&buf_globalLock);
3593 snprintf( dbgstr, 1024,
3594 "RDR_ReleaseFileExtents releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3595 Fid.volume, Fid.vnode, Fid.unique,
3596 pExtent->FileOffset.HighPart,
3597 pExtent->FileOffset.LowPart,
3598 pExtent->CacheOffset.HighPart,
3599 pExtent->CacheOffset.LowPart);
3600 OutputDebugStringA( dbgstr);
3605 snprintf( dbgstr, 1024,
3606 "RDR_ReleaseFileExtents not releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3607 Fid.volume, Fid.vnode, Fid.unique,
3608 pExtent->FileOffset.HighPart,
3609 pExtent->FileOffset.LowPart,
3610 pExtent->CacheOffset.HighPart,
3611 pExtent->CacheOffset.LowPart);
3612 OutputDebugStringA( dbgstr);
3614 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
3615 Fid.volume, Fid.vnode,
3616 pExtent->FileOffset.HighPart,
3617 pExtent->FileOffset.LowPart);
3618 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3619 pExtent->CacheOffset.HighPart,
3620 pExtent->CacheOffset.LowPart);
3623 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
3624 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY) )
3626 #ifdef VALIDATE_CHECK_SUM
3628 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3632 * if the saved checksum matches the checksum of the current state of the buffer
3633 * then the buffer is the same as what was given to the kernel.
3635 if ( buf_ValidateCheckSum(bufp) ) {
3636 buf_ComputeCheckSum(bufp);
3638 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3641 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
3642 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3644 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3647 snprintf( dbgstr, 1024,
3648 "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",
3649 md5dbg, md5dbg2,md5dbg3,
3650 Fid.volume, Fid.vnode, Fid.unique,
3651 pExtent->FileOffset.HighPart,
3652 pExtent->FileOffset.LowPart,
3653 pExtent->CacheOffset.HighPart,
3654 pExtent->CacheOffset.LowPart);
3655 OutputDebugStringA( dbgstr);
3657 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
3658 Fid.volume, Fid.vnode,
3659 pExtent->FileOffset.HighPart,
3660 pExtent->FileOffset.LowPart);
3661 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3662 pExtent->CacheOffset.HighPart,
3663 pExtent->CacheOffset.LowPart);
3664 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3668 snprintf( dbgstr, 1024,
3669 "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",
3670 md5dbg, md5dbg2, md5dbg3,
3671 Fid.volume, Fid.vnode, Fid.unique,
3672 pExtent->FileOffset.HighPart,
3673 pExtent->FileOffset.LowPart,
3674 pExtent->CacheOffset.HighPart,
3675 pExtent->CacheOffset.LowPart);
3676 OutputDebugStringA( dbgstr);
3678 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3679 Fid.volume, Fid.vnode,
3680 pExtent->FileOffset.HighPart,
3681 pExtent->FileOffset.LowPart);
3682 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3683 pExtent->CacheOffset.HighPart,
3684 pExtent->CacheOffset.LowPart);
3688 snprintf( dbgstr, 1024,
3689 "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",
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 set but extent has not 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);
3706 buf_ComputeCheckSum(bufp);
3708 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3710 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3711 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3713 snprintf( dbgstr, 1024,
3714 "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",
3715 md5dbg, md5dbg2,md5dbg3,
3716 Fid.volume, Fid.vnode, Fid.unique,
3717 pExtent->FileOffset.HighPart,
3718 pExtent->FileOffset.LowPart,
3719 pExtent->CacheOffset.HighPart,
3720 pExtent->CacheOffset.LowPart);
3721 OutputDebugStringA( dbgstr);
3723 snprintf( dbgstr, 1024,
3724 "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",
3725 md5dbg, md5dbg2,md5dbg3,
3726 Fid.volume, Fid.vnode, Fid.unique,
3727 pExtent->FileOffset.HighPart,
3728 pExtent->FileOffset.LowPart,
3729 pExtent->CacheOffset.HighPart,
3730 pExtent->CacheOffset.LowPart);
3731 OutputDebugStringA( dbgstr);
3734 snprintf( dbgstr, 1024,
3735 "RDR_ReleaseFileExtents dirty flag set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3736 Fid.volume, Fid.vnode, Fid.unique,
3737 pExtent->FileOffset.HighPart,
3738 pExtent->FileOffset.LowPart,
3739 pExtent->CacheOffset.HighPart,
3740 pExtent->CacheOffset.LowPart);
3741 OutputDebugStringA( dbgstr);
3744 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3747 #else /* !VALIDATE_CHECK_SUM */
3748 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3750 #endif /* VALIDATE_CHECK_SUM */
3752 #ifdef VALIDATE_CHECK_SUM
3755 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3757 if ( !buf_ValidateCheckSum(bufp) ) {
3758 buf_ComputeCheckSum(bufp);
3760 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3761 snprintf( dbgstr, 1024,
3762 "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",
3764 Fid.volume, Fid.vnode, Fid.unique,
3765 pExtent->FileOffset.HighPart,
3766 pExtent->FileOffset.LowPart,
3767 pExtent->CacheOffset.HighPart,
3768 pExtent->CacheOffset.LowPart);
3769 OutputDebugStringA( dbgstr);
3771 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set but extent has changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3772 Fid.volume, Fid.vnode,
3773 pExtent->FileOffset.HighPart,
3774 pExtent->FileOffset.LowPart);
3775 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3776 pExtent->CacheOffset.HighPart,
3777 pExtent->CacheOffset.LowPart);
3778 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3781 buf_ComputeCheckSum(bufp);
3783 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3784 snprintf( dbgstr, 1024,
3785 "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3786 Fid.volume, Fid.vnode, Fid.unique,
3787 pExtent->FileOffset.HighPart,
3788 pExtent->FileOffset.LowPart,
3789 pExtent->CacheOffset.HighPart,
3790 pExtent->CacheOffset.LowPart);
3791 OutputDebugStringA( dbgstr);
3793 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x foffset 0x%x:%x",
3794 Fid.volume, Fid.vnode,
3795 pExtent->FileOffset.HighPart,
3796 pExtent->FileOffset.LowPart);
3797 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3798 pExtent->CacheOffset.HighPart,
3799 pExtent->CacheOffset.LowPart);
3802 #endif /* VALIDATE_CHECK_SUM */
3803 lock_ReleaseMutex(&bufp->mx);
3808 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3811 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3812 if (wbp->datap == datap)
3817 snprintf( dbgstr, 1024,
3818 "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3819 Fid.volume, Fid.vnode, Fid.unique,
3820 pExtent->FileOffset.HighPart,
3821 pExtent->FileOffset.LowPart,
3822 pExtent->CacheOffset.HighPart,
3823 pExtent->CacheOffset.LowPart);
3824 OutputDebugStringA( dbgstr);
3826 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3827 Fid.volume, Fid.vnode,
3828 pExtent->FileOffset.HighPart,
3829 pExtent->FileOffset.LowPart);
3830 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3831 pExtent->CacheOffset.HighPart,
3832 pExtent->CacheOffset.LowPart);
3833 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3834 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3842 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3845 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3846 if (wbp->datap == datap)
3851 snprintf( dbgstr, 1024,
3852 "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3853 Fid.volume, Fid.vnode, Fid.unique,
3854 pExtent->FileOffset.HighPart,
3855 pExtent->FileOffset.LowPart,
3856 pExtent->CacheOffset.HighPart,
3857 pExtent->CacheOffset.LowPart);
3858 OutputDebugStringA( dbgstr);
3860 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3861 Fid.volume, Fid.vnode,
3862 pExtent->FileOffset.HighPart,
3863 pExtent->FileOffset.LowPart);
3864 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3865 pExtent->CacheOffset.HighPart,
3866 pExtent->CacheOffset.LowPart);
3867 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3868 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3873 if (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_FLUSH) {
3874 lock_ObtainWrite(&scp->rw);
3875 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3876 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3877 lock_ReleaseWrite(&scp->rw);
3879 code = cm_FSync(scp, userp, &req, FALSE);
3882 osi_hyper_t offset = {0,0};
3883 afs_uint32 length = 0;
3884 afs_uint32 rights = 0;
3886 lock_ObtainWrite(&scp->rw);
3887 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3888 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3889 lock_ReleaseWrite(&scp->rw);
3892 * there is at least one dirty extent on this file. queue up background store
3893 * requests for contiguous blocks
3895 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3896 if (ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart == offset.QuadPart + length &&
3897 length + cm_data.buf_blockSize <= cm_chunkSize)
3899 length += cm_data.buf_blockSize;
3901 if (!(offset.QuadPart == 0 && length == 0))
3902 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3903 length, 0, userp, &req);
3904 offset.QuadPart = ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart;
3905 length = cm_data.buf_blockSize;
3908 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3909 length, 0, userp, &req);
3912 cm_ReleaseSCache(scp);
3915 osi_Log5(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
3916 FileId.Cell, FileId.Volume,
3917 FileId.Vnode, FileId.Unique, released);
3918 if (code && code != CM_ERROR_WOULDBLOCK) {
3919 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3920 (*ResultCB)->ResultStatus = status;
3921 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents FAILURE code=0x%x status=0x%x",
3924 (*ResultCB)->ResultStatus = 0;
3925 osi_Log0(afsd_logp, "RDR_ReleaseFileExtents SUCCESS");
3927 (*ResultCB)->ResultBufferLength = 0;
3933 RDR_ProcessReleaseFileExtentsResult( IN AFSReleaseFileExtentsResultCB *ReleaseFileExtentsResultCB,
3934 IN DWORD ResultBufferLength)
3936 afs_uint32 code = 0;
3940 unsigned int fileno, extentno, total_extents = 0;
3941 AFSReleaseFileExtentsResultFileCB *pNextFileCB;
3943 #ifdef VALIDATE_CHECK_SUM
3944 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3950 for ( fileno = 0, pNextFileCB = &ReleaseFileExtentsResultCB->Files[0];
3951 fileno < ReleaseFileExtentsResultCB->FileCount;
3953 AFSReleaseFileExtentsResultFileCB *pFileCB = pNextFileCB;
3954 cm_user_t *userp = NULL;
3956 cm_scache_t * scp = NULL;
3962 userp = RDR_UserFromAuthGroup( &pFileCB->AuthGroup);
3964 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult %d.%d.%d.%d",
3965 pFileCB->FileId.Cell, pFileCB->FileId.Volume,
3966 pFileCB->FileId.Vnode, pFileCB->FileId.Unique);
3968 /* Process the release */
3969 Fid.cell = pFileCB->FileId.Cell;
3970 Fid.volume = pFileCB->FileId.Volume;
3971 Fid.vnode = pFileCB->FileId.Vnode;
3972 Fid.unique = pFileCB->FileId.Unique;
3973 Fid.hash = pFileCB->FileId.Hash;
3975 if (Fid.cell == 0) {
3976 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult Invalid FID %d.%d.%d.%d",
3977 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
3978 code = CM_ERROR_INVAL;
3982 code = cm_GetSCache(&Fid, &scp, userp, &req);
3984 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult cm_GetSCache FID failure code=0x%x",
3987 * A failure to find the cm_scache object cannot prevent the service
3988 * from accepting the extents back from the redirector.
3992 deleted = scp && (scp->flags & CM_SCACHEFLAG_DELETED);
3994 /* if the scp was not found, do not perform the length check */
3995 if (scp && (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart)) {
3998 memset(&setAttr, 0, sizeof(cm_attr_t));
3999 lock_ObtainWrite(&scp->rw);
4000 if (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart) {
4001 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult length change vol 0x%x vno 0x%x length 0x%x:%x",
4002 scp->fid.volume, scp->fid.vnode,
4003 pFileCB->AllocationSize.HighPart,
4004 pFileCB->AllocationSize.LowPart);
4005 setAttr.mask |= CM_ATTRMASK_LENGTH;
4006 setAttr.length.LowPart = pFileCB->AllocationSize.LowPart;
4007 setAttr.length.HighPart = pFileCB->AllocationSize.HighPart;
4009 lock_ReleaseWrite(&scp->rw);
4011 code = cm_SetAttr(scp, &setAttr, userp, &req);
4014 for ( extentno = 0; extentno < pFileCB->ExtentCount; total_extents++, extentno++ ) {
4015 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4017 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4019 bufp = buf_Find(&Fid, &thyper);
4021 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4022 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
4023 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4024 Fid.volume, Fid.vnode,
4025 pExtent->FileOffset.HighPart,
4026 pExtent->FileOffset.LowPart);
4027 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
4028 pExtent->CacheOffset.HighPart,
4029 pExtent->CacheOffset.LowPart);
4031 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4032 Fid.volume, Fid.vnode,
4033 pExtent->FileOffset.HighPart,
4034 pExtent->FileOffset.LowPart);
4035 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
4036 pExtent->CacheOffset.HighPart,
4037 pExtent->CacheOffset.LowPart);
4043 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
4044 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4045 Fid.volume, Fid.vnode,
4046 pExtent->FileOffset.HighPart,
4047 pExtent->FileOffset.LowPart);
4048 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
4049 pExtent->CacheOffset.HighPart,
4050 pExtent->CacheOffset.LowPart);
4052 /* Move the buffer to the front of the queue */
4053 lock_ObtainWrite(&buf_globalLock);
4054 buf_MoveToHeadOfRedirQueue(scp, bufp);
4055 lock_ReleaseWrite(&buf_globalLock);
4060 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
4061 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
4062 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4063 Fid.volume, Fid.vnode,
4064 pExtent->FileOffset.HighPart,
4065 pExtent->FileOffset.LowPart);
4066 osi_Log2(afsd_logp, "... coffset 0x%x:%x not held by file system",
4067 pExtent->CacheOffset.HighPart,
4068 pExtent->CacheOffset.LowPart);
4070 snprintf(dbgstr, 1024,
4071 "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",
4072 ReleaseFileExtentsResultCB->Flags, pExtent->Flags,
4073 Fid.volume, Fid.vnode, Fid.unique,
4074 pExtent->FileOffset.HighPart,
4075 pExtent->FileOffset.LowPart,
4076 pExtent->CacheOffset.HighPart,
4077 pExtent->CacheOffset.LowPart);
4078 OutputDebugStringA( dbgstr);
4081 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4082 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4083 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4085 if (pExtent->Flags || ReleaseFileExtentsResultCB->Flags) {
4086 lock_ObtainMutex(&bufp->mx);
4087 if ( (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
4088 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
4090 if (bufp->qFlags & CM_BUF_QREDIR) {
4091 lock_ObtainWrite(&buf_globalLock);
4092 if (bufp->qFlags & CM_BUF_QREDIR) {
4093 buf_RemoveFromRedirQueue(scp, bufp);
4094 buf_ReleaseLocked(bufp, TRUE);
4096 lock_ReleaseWrite(&buf_globalLock);
4100 snprintf(dbgstr, 1024,
4101 "RDR_ProcessReleaseFileExtentsResult extent released: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4102 Fid.volume, Fid.vnode, Fid.unique,
4103 pExtent->FileOffset.HighPart,
4104 pExtent->FileOffset.LowPart,
4105 pExtent->CacheOffset.HighPart,
4106 pExtent->CacheOffset.LowPart);
4107 OutputDebugStringA( dbgstr);
4112 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
4113 Fid.volume, Fid.vnode,
4114 pExtent->FileOffset.HighPart,
4115 pExtent->FileOffset.LowPart);
4116 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4117 pExtent->CacheOffset.HighPart,
4118 pExtent->CacheOffset.LowPart);
4120 snprintf(dbgstr, 1024,
4121 "RDR_ProcessReleaseFileExtentsResult not released! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4122 Fid.volume, Fid.vnode, Fid.unique,
4123 pExtent->FileOffset.HighPart,
4124 pExtent->FileOffset.LowPart,
4125 pExtent->CacheOffset.HighPart,
4126 pExtent->CacheOffset.LowPart);
4127 OutputDebugStringA( dbgstr);
4131 if ((ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
4132 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY))
4134 #ifdef VALIDATE_CHECK_SUM
4135 if ( buf_ValidateCheckSum(bufp) ) {
4137 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4138 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4139 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
4141 buf_ComputeCheckSum(bufp);
4143 HexCheckSum(md5dbg3, sizeof(md5dbg), bufp->md5cksum);
4145 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4147 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
4150 snprintf(dbgstr, 1024,
4151 "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",
4153 Fid.volume, Fid.vnode, Fid.unique,
4154 pExtent->FileOffset.HighPart,
4155 pExtent->FileOffset.LowPart,
4156 pExtent->CacheOffset.HighPart,
4157 pExtent->CacheOffset.LowPart);
4158 OutputDebugStringA( dbgstr);
4161 "RDR_ProcessReleaseFileExtentsResult dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
4162 Fid.volume, Fid.vnode,
4163 pExtent->FileOffset.HighPart,
4164 pExtent->FileOffset.LowPart);
4166 "... coffset 0x%x:%x",
4167 pExtent->CacheOffset.HighPart,
4168 pExtent->CacheOffset.LowPart);
4171 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4176 snprintf(dbgstr, 1024,
4177 "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",
4178 md5dbg, md5dbg2, md5dbg3,
4179 Fid.volume, Fid.vnode, Fid.unique,
4180 pExtent->FileOffset.HighPart,
4181 pExtent->FileOffset.LowPart,
4182 pExtent->CacheOffset.HighPart,
4183 pExtent->CacheOffset.LowPart);
4184 OutputDebugStringA( dbgstr);
4187 "RDR_ProcessReleaseFileExtentsResult dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
4188 Fid.volume, Fid.vnode,
4189 pExtent->FileOffset.HighPart,
4190 pExtent->FileOffset.LowPart);
4192 "... coffset 0x%x:%x",
4193 pExtent->CacheOffset.HighPart,
4194 pExtent->CacheOffset.LowPart);
4198 #else /* !VALIDATE_CHECK_SUM */
4200 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4204 snprintf(dbgstr, 1024,
4205 "RDR_ProcessReleaseFileExtentsResult dirty! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4206 Fid.volume, Fid.vnode, Fid.unique,
4207 pExtent->FileOffset.HighPart,
4208 pExtent->FileOffset.LowPart,
4209 pExtent->CacheOffset.HighPart,
4210 pExtent->CacheOffset.LowPart);
4211 OutputDebugStringA( dbgstr);
4213 #endif /* VALIDATE_CHECK_SUM */
4215 #ifdef VALIDATE_CHECK_SUM
4218 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4220 if (!buf_ValidateCheckSum(bufp) ) {
4221 buf_ComputeCheckSum(bufp);
4223 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4224 snprintf(dbgstr, 1024,
4225 "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",
4227 Fid.volume, Fid.vnode, Fid.unique,
4228 pExtent->FileOffset.HighPart,
4229 pExtent->FileOffset.LowPart,
4230 pExtent->CacheOffset.HighPart,
4231 pExtent->CacheOffset.LowPart);
4232 OutputDebugStringA( dbgstr);
4234 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult dirty flag NOT set but extent has changed! vol 0x%x vno 0x%x foffset 0x%x:%x",
4235 Fid.volume, Fid.vnode,
4236 pExtent->FileOffset.HighPart,
4237 pExtent->FileOffset.LowPart);
4238 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4239 pExtent->CacheOffset.HighPart,
4240 pExtent->CacheOffset.LowPart);
4245 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4249 buf_ComputeCheckSum(bufp);
4251 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4252 snprintf(dbgstr, 1024,
4253 "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",
4255 Fid.volume, Fid.vnode, Fid.unique,
4256 pExtent->FileOffset.HighPart,
4257 pExtent->FileOffset.LowPart,
4258 pExtent->CacheOffset.HighPart,
4259 pExtent->CacheOffset.LowPart);
4260 OutputDebugStringA( dbgstr);
4264 #endif /* VALIDATE_CHECK_SUM */
4265 lock_ReleaseMutex(&bufp->mx);
4269 /* CacheOffset doesn't match bufp->datap */
4270 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
4273 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
4274 if (wbp->datap == datap)
4279 snprintf(dbgstr, 1024,
4280 "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",
4281 Fid.volume, Fid.vnode, Fid.unique,
4282 pExtent->FileOffset.HighPart,
4283 pExtent->FileOffset.LowPart,
4284 pExtent->CacheOffset.HighPart,
4285 pExtent->CacheOffset.LowPart,
4287 OutputDebugStringA( dbgstr);
4289 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4290 Fid.volume, Fid.vnode,
4291 pExtent->FileOffset.HighPart,
4292 pExtent->FileOffset.LowPart);
4293 osi_Log3(afsd_logp, "... coffset 0x%x:%x flags 0x%x",
4294 pExtent->CacheOffset.HighPart,
4295 pExtent->CacheOffset.LowPart,
4298 osi_Log5(afsd_logp, "... coffset belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
4299 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
4301 osi_Log0(afsd_logp, "... coffset cannot be found");
4308 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4309 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4310 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
4311 pExtent->FileOffset.LowPart);
4312 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; cm_buf not found -- recycled?",
4313 pExtent->CacheOffset.HighPart,
4314 pExtent->CacheOffset.LowPart);
4320 snprintf(dbgstr, 1024,
4321 "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4322 Fid.volume, Fid.vnode, Fid.unique,
4323 pExtent->FileOffset.HighPart,
4324 pExtent->FileOffset.LowPart,
4325 pExtent->CacheOffset.HighPart,
4326 pExtent->CacheOffset.LowPart);
4327 OutputDebugStringA( dbgstr);
4329 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x foffset 0x%x:%x",
4330 Fid.volume, Fid.vnode,
4331 pExtent->FileOffset.HighPart,
4332 pExtent->FileOffset.LowPart);
4333 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4334 pExtent->CacheOffset.HighPart,
4335 pExtent->CacheOffset.LowPart);
4340 osi_hyper_t offset = {0,0};
4341 afs_uint32 length = 0;
4344 * there is at least one dirty extent on this file. queue up background store
4345 * requests for contiguous blocks
4347 for ( extentno = 0; extentno < pFileCB->ExtentCount; extentno++ ) {
4348 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4349 if (pExtent->FileOffset.QuadPart == offset.QuadPart + length &&
4350 length < cm_chunkSize) {
4351 length += cm_data.buf_blockSize;
4353 if (!(offset.QuadPart == 0 && length == 0))
4354 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4355 length, 0, userp, &req);
4356 offset.QuadPart = pExtent->FileOffset.QuadPart;
4357 length = cm_data.buf_blockSize;
4360 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4361 length, 0, userp, &req);
4364 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
4365 Fid.cell, Fid.volume, Fid.vnode, Fid.unique, released);
4369 cm_ReleaseUser(userp);
4371 cm_ReleaseSCache(scp);
4373 p = (char *)pFileCB;
4374 p += sizeof(AFSReleaseFileExtentsResultFileCB);
4375 p += sizeof(AFSFileExtentCB) * (pFileCB->ExtentCount - 1);
4376 pNextFileCB = (AFSReleaseFileExtentsResultFileCB *)p;
4379 if (total_extents == 0) {
4380 osi_Log0(afsd_logp, "RDR_ProcessReleaseFileExtentsResult is empty");
4381 code = CM_ERROR_RETRY;
4385 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult FAILURE code=0x%x", code);
4387 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult DONE code=0x%x", code);
4393 RDR_ReleaseFailedSetFileExtents( IN cm_user_t *userp,
4394 IN AFSSetFileExtentsCB *SetFileExtentsResultCB,
4395 IN DWORD ResultBufferLength)
4397 afs_uint32 code = 0;
4399 unsigned int extentno;
4401 cm_scache_t * scp = NULL;
4406 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFileExtents %d.%d.%d.%d",
4407 SetFileExtentsResultCB->FileId.Cell, SetFileExtentsResultCB->FileId.Volume,
4408 SetFileExtentsResultCB->FileId.Vnode, SetFileExtentsResultCB->FileId.Unique);
4410 /* Process the release */
4411 Fid.cell = SetFileExtentsResultCB->FileId.Cell;
4412 Fid.volume = SetFileExtentsResultCB->FileId.Volume;
4413 Fid.vnode = SetFileExtentsResultCB->FileId.Vnode;
4414 Fid.unique = SetFileExtentsResultCB->FileId.Unique;
4415 Fid.hash = SetFileExtentsResultCB->FileId.Hash;
4417 if (Fid.cell == 0) {
4418 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFile Invalid FID %d.%d.%d.%d",
4419 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
4420 code = CM_ERROR_INVAL;
4424 code = cm_GetSCache(&Fid, &scp, userp, &req);
4426 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents cm_GetSCache FID failure code=0x%x",
4428 /* Failure to find the cm_scache object cannot block return of the extents */
4431 for ( extentno = 0; extentno < SetFileExtentsResultCB->ExtentCount; extentno++ ) {
4434 AFSFileExtentCB *pExtent = &SetFileExtentsResultCB->FileExtents[extentno];
4436 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4438 bufp = buf_Find(&Fid, &thyper);
4440 osi_Log5(afsd_logp, "RDR_ReleaseFailedSetFileExtents bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4441 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4442 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4444 lock_ObtainMutex(&bufp->mx);
4445 if (bufp->qFlags & CM_BUF_QREDIR) {
4446 lock_ObtainWrite(&buf_globalLock);
4447 if (bufp->qFlags & CM_BUF_QREDIR) {
4448 buf_RemoveFromRedirQueue(scp, bufp);
4449 buf_ReleaseLocked(bufp, TRUE);
4451 lock_ReleaseWrite(&buf_globalLock);
4453 lock_ReleaseMutex(&bufp->mx);
4460 cm_ReleaseUser(userp);
4462 cm_ReleaseSCache(scp);
4464 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents DONE code=0x%x", code);
4469 RDR_PioctlOpen( IN cm_user_t *userp,
4470 IN AFSFileID ParentId,
4471 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4473 IN DWORD ResultBufferLength,
4474 IN OUT AFSCommResult **ResultCB)
4479 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4485 sizeof( AFSCommResult));
4487 /* Get the active directory */
4488 ParentFid.cell = ParentId.Cell;
4489 ParentFid.volume = ParentId.Volume;
4490 ParentFid.vnode = ParentId.Vnode;
4491 ParentFid.unique = ParentId.Unique;
4492 ParentFid.hash = ParentId.Hash;
4494 /* Get the root directory */
4495 RootFid.cell = pPioctlCB->RootId.Cell;
4496 RootFid.volume = pPioctlCB->RootId.Volume;
4497 RootFid.vnode = pPioctlCB->RootId.Vnode;
4498 RootFid.unique = pPioctlCB->RootId.Unique;
4499 RootFid.hash = pPioctlCB->RootId.Hash;
4501 /* Create the pioctl index */
4502 RDR_SetupIoctl(pPioctlCB->RequestId, &ParentFid, &RootFid, userp);
4509 RDR_PioctlClose( IN cm_user_t *userp,
4510 IN AFSFileID ParentId,
4511 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4513 IN DWORD ResultBufferLength,
4514 IN OUT AFSCommResult **ResultCB)
4516 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4522 sizeof( AFSCommResult));
4524 /* Cleanup the pioctl index */
4525 RDR_CleanupIoctl(pPioctlCB->RequestId);
4532 RDR_PioctlWrite( IN cm_user_t *userp,
4533 IN AFSFileID ParentId,
4534 IN AFSPIOCtlIORequestCB *pPioctlCB,
4536 IN DWORD ResultBufferLength,
4537 IN OUT AFSCommResult **ResultCB)
4539 AFSPIOCtlIOResultCB *pResultCB;
4540 cm_scache_t *dscp = NULL;
4547 req.flags |= CM_REQ_WOW64;
4549 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4555 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4557 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4559 code = RDR_IoctlWrite(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer, &req);
4561 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4562 (*ResultCB)->ResultStatus = status;
4566 pResultCB->BytesProcessed = pPioctlCB->BufferLength;
4567 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4571 RDR_PioctlRead( IN cm_user_t *userp,
4572 IN AFSFileID ParentId,
4573 IN AFSPIOCtlIORequestCB *pPioctlCB,
4575 IN BOOL bIsLocalSystem,
4576 IN DWORD ResultBufferLength,
4577 IN OUT AFSCommResult **ResultCB)
4579 AFSPIOCtlIOResultCB *pResultCB;
4580 cm_scache_t *dscp = NULL;
4584 afs_uint32 pflags = (bIsLocalSystem ? AFSCALL_FLAG_LOCAL_SYSTEM : 0);
4588 req.flags |= CM_REQ_WOW64;
4590 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4596 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4598 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4600 code = RDR_IoctlRead(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer,
4601 &pResultCB->BytesProcessed, &req, pflags);
4603 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4604 (*ResultCB)->ResultStatus = status;
4608 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4612 RDR_ByteRangeLockSync( IN cm_user_t *userp,
4613 IN AFSFileID FileId,
4614 IN AFSByteRangeLockRequestCB *pBRLRequestCB,
4616 IN DWORD ResultBufferLength,
4617 IN OUT AFSCommResult **ResultCB)
4619 AFSByteRangeLockResultCB *pResultCB = NULL;
4620 LARGE_INTEGER ProcessId;
4622 cm_scache_t *scp = NULL;
4630 ProcessId.QuadPart = pBRLRequestCB->ProcessId;
4634 req.flags |= CM_REQ_WOW64;
4636 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4637 FileId.Cell, FileId.Volume,
4638 FileId.Vnode, FileId.Unique);
4639 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4640 ProcessId.HighPart, ProcessId.LowPart);
4642 Length = sizeof( AFSByteRangeLockResultCB) + ((pBRLRequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4643 if (Length > ResultBufferLength) {
4644 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4647 memset( *ResultCB, 0, sizeof(AFSCommResult));
4648 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4652 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4655 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4656 (*ResultCB)->ResultBufferLength = Length;
4658 pResultCB = (AFSByteRangeLockResultCB *)(*ResultCB)->ResultData;
4659 pResultCB->FileId = FileId;
4660 pResultCB->Count = pBRLRequestCB->Count;
4662 /* Allocate the extents from the buffer package */
4663 Fid.cell = FileId.Cell;
4664 Fid.volume = FileId.Volume;
4665 Fid.vnode = FileId.Vnode;
4666 Fid.unique = FileId.Unique;
4667 Fid.hash = FileId.Hash;
4669 code = cm_GetSCache(&Fid, &scp, userp, &req);
4671 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4672 (*ResultCB)->ResultStatus = status;
4673 (*ResultCB)->ResultBufferLength = 0;
4674 osi_Log2(afsd_logp, "RDR_ByteRangeLockSync cm_GetSCache FID failure code=0x%x status=0x%x",
4679 lock_ObtainWrite(&scp->rw);
4681 /* start by looking up the file's end */
4682 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4683 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4685 lock_ReleaseWrite(&scp->rw);
4686 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4687 (*ResultCB)->ResultStatus = status;
4688 (*ResultCB)->ResultBufferLength = 0;
4689 osi_Log3(afsd_logp, "RDR_ByteRangeLockSync cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4694 /* the scp is now locked and current */
4695 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4697 for ( i=0; i<pBRLRequestCB->Count; i++ ) {
4698 pResultCB->Result[i].LockType = pBRLRequestCB->Request[i].LockType;
4699 pResultCB->Result[i].Offset = pBRLRequestCB->Request[i].Offset;
4700 pResultCB->Result[i].Length = pBRLRequestCB->Request[i].Length;
4703 pBRLRequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4704 pBRLRequestCB->Request[i].Offset,
4705 pBRLRequestCB->Request[i].Length,
4706 key, 0, userp, &req, NULL);
4709 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4711 pBRLRequestCB->Request[i].LockType,
4712 pBRLRequestCB->Request[i].Offset.HighPart,
4713 pBRLRequestCB->Request[i].Offset.LowPart);
4714 osi_Log2(afsd_logp, "... length 0x%x:%x",
4715 pBRLRequestCB->Request[i].Length.HighPart,
4716 pBRLRequestCB->Request[i].Length.LowPart);
4721 pResultCB->Result[i].Status = 0;
4723 case CM_ERROR_WOULDBLOCK:
4724 pResultCB->Result[i].Status = STATUS_FILE_LOCK_CONFLICT;
4727 pResultCB->Result[i].Status = STATUS_LOCK_NOT_GRANTED;
4731 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4732 lock_ReleaseWrite(&scp->rw);
4733 cm_ReleaseSCache(scp);
4735 (*ResultCB)->ResultStatus = 0;
4736 osi_Log0(afsd_logp, "RDR_ByteRangeLockSync SUCCESS");
4741 RDR_ByteRangeUnlock( IN cm_user_t *userp,
4742 IN AFSFileID FileId,
4743 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4745 IN DWORD ResultBufferLength,
4746 IN OUT AFSCommResult **ResultCB)
4748 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4749 LARGE_INTEGER ProcessId;
4751 cm_scache_t *scp = NULL;
4759 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4763 req.flags |= CM_REQ_WOW64;
4765 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4766 FileId.Cell, FileId.Volume,
4767 FileId.Vnode, FileId.Unique);
4768 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4769 ProcessId.HighPart, ProcessId.LowPart);
4771 Length = sizeof( AFSByteRangeUnlockResultCB) + ((pBRURequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4772 if (Length > ResultBufferLength) {
4773 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4776 memset( *ResultCB, 0, sizeof(AFSCommResult));
4777 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4781 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4784 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4785 (*ResultCB)->ResultBufferLength = Length;
4787 pResultCB = (AFSByteRangeUnlockResultCB *)(*ResultCB)->ResultData;
4788 pResultCB->Count = pBRURequestCB->Count;
4790 /* Allocate the extents from the buffer package */
4791 Fid.cell = FileId.Cell;
4792 Fid.volume = FileId.Volume;
4793 Fid.vnode = FileId.Vnode;
4794 Fid.unique = FileId.Unique;
4795 Fid.hash = FileId.Hash;
4797 code = cm_GetSCache(&Fid, &scp, userp, &req);
4799 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4800 (*ResultCB)->ResultStatus = status;
4801 (*ResultCB)->ResultBufferLength = 0;
4802 osi_Log2(afsd_logp, "RDR_ByteRangeUnlock cm_GetSCache FID failure code=0x%x status=0x%x",
4807 lock_ObtainWrite(&scp->rw);
4809 /* start by looking up the file's end */
4810 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4811 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4813 lock_ReleaseWrite(&scp->rw);
4814 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4815 (*ResultCB)->ResultStatus = status;
4816 (*ResultCB)->ResultBufferLength = 0;
4817 osi_Log3(afsd_logp, "RDR_ByteRangeUnlock cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4822 /* the scp is now locked and current */
4823 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4825 for ( i=0; i<pBRURequestCB->Count; i++ ) {
4826 pResultCB->Result[i].LockType = pBRURequestCB->Request[i].LockType;
4827 pResultCB->Result[i].Offset = pBRURequestCB->Request[i].Offset;
4828 pResultCB->Result[i].Length = pBRURequestCB->Request[i].Length;
4830 code = cm_Unlock(scp,
4831 pBRURequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4832 pBRURequestCB->Request[i].Offset,
4833 pBRURequestCB->Request[i].Length,
4834 key, CM_UNLOCK_FLAG_MATCH_RANGE, userp, &req);
4837 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4838 code, pBRURequestCB->Request[i].LockType,
4839 pBRURequestCB->Request[i].Offset.HighPart,
4840 pBRURequestCB->Request[i].Offset.LowPart);
4841 osi_Log2(afsd_logp, "... length 0x%x:%x",
4842 pBRURequestCB->Request[i].Length.HighPart,
4843 pBRURequestCB->Request[i].Length.LowPart);
4845 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4846 pResultCB->Result[i].Status = status;
4849 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4850 lock_ReleaseWrite(&scp->rw);
4851 cm_ReleaseSCache(scp);
4853 (*ResultCB)->ResultStatus = 0;
4854 osi_Log0(afsd_logp, "RDR_ByteRangeUnlock SUCCESS");
4859 RDR_ByteRangeUnlockAll( IN cm_user_t *userp,
4860 IN AFSFileID FileId,
4861 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4863 IN DWORD ResultBufferLength,
4864 IN OUT AFSCommResult **ResultCB)
4866 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4867 LARGE_INTEGER ProcessId;
4868 cm_scache_t *scp = NULL;
4875 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4879 req.flags |= CM_REQ_WOW64;
4881 osi_Log4(afsd_logp, "RDR_ByteRangeUnlockAll File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4882 FileId.Cell, FileId.Volume,
4883 FileId.Vnode, FileId.Unique);
4884 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4885 ProcessId.HighPart, ProcessId.LowPart);
4887 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4890 memset( *ResultCB, '\0', sizeof( AFSCommResult));
4891 (*ResultCB)->ResultBufferLength = 0;
4893 /* Allocate the extents from the buffer package */
4894 Fid.cell = FileId.Cell;
4895 Fid.volume = FileId.Volume;
4896 Fid.vnode = FileId.Vnode;
4897 Fid.unique = FileId.Unique;
4898 Fid.hash = FileId.Hash;
4900 code = cm_GetSCache(&Fid, &scp, userp, &req);
4902 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4903 (*ResultCB)->ResultStatus = status;
4904 (*ResultCB)->ResultBufferLength = 0;
4905 osi_Log2(afsd_logp, "RDR_ByteRangeUnlockAll cm_GetSCache FID failure code=0x%x status=0x%x",
4910 lock_ObtainWrite(&scp->rw);
4912 /* start by looking up the file's end */
4913 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4914 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4916 lock_ReleaseWrite(&scp->rw);
4917 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4918 (*ResultCB)->ResultStatus = status;
4919 (*ResultCB)->ResultBufferLength = 0;
4920 osi_Log3(afsd_logp, "RDR_ByteRangeUnlockAll cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4925 /* the scp is now locked and current */
4926 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4928 code = cm_UnlockByKey(scp, key, 0, userp, &req);
4930 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4931 lock_ReleaseWrite(&scp->rw);
4932 cm_ReleaseSCache(scp);
4934 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4935 (*ResultCB)->ResultStatus = status;
4938 osi_Log1(afsd_logp, "RDR_ByteRangeUnlockAll FAILURE code 0x%x", code);
4940 osi_Log0(afsd_logp, "RDR_ByteRangeUnlockAll SUCCESS");
4946 RDR_GetVolumeInfo( IN cm_user_t *userp,
4947 IN AFSFileID FileId,
4949 IN DWORD ResultBufferLength,
4950 IN OUT AFSCommResult **ResultCB)
4952 AFSVolumeInfoCB *pResultCB = NULL;
4954 cm_scache_t *scp = NULL;
4955 cm_volume_t *volp = NULL;
4956 cm_vol_state_t *volstatep = NULL;
4958 cm_cell_t *cellp = NULL;
4963 FILETIME ft = {0x832cf000, 0x01abfcc4}; /* October 1, 1982 00:00:00 +0600 */
4965 char volName[32]="(unknown)";
4966 char offLineMsg[256]="server temporarily inaccessible";
4967 char motd[256]="server temporarily inaccessible";
4969 AFSFetchVolumeStatus volStat;
4973 struct rx_connection * rxconnp;
4977 req.flags |= CM_REQ_WOW64;
4979 osi_Log4(afsd_logp, "RDR_GetVolumeInfo File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4980 FileId.Cell, FileId.Volume,
4981 FileId.Vnode, FileId.Unique);
4983 Length = sizeof( AFSCommResult) + sizeof(AFSVolumeInfoCB);
4984 if (sizeof(AFSVolumeInfoCB) > ResultBufferLength) {
4985 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
4988 memset( *ResultCB, 0, sizeof(AFSCommResult));
4989 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4993 *ResultCB = (AFSCommResult *)malloc( Length );
4996 memset( *ResultCB, '\0', Length );
4997 (*ResultCB)->ResultBufferLength = sizeof(AFSVolumeInfoCB);
4998 pResultCB = (AFSVolumeInfoCB *)(*ResultCB)->ResultData;
5000 /* Allocate the extents from the buffer package */
5001 if (FileId.Cell != 0) {
5002 Fid.cell = FileId.Cell;
5003 Fid.volume = FileId.Volume;
5004 Fid.vnode = FileId.Vnode;
5005 Fid.unique = FileId.Unique;
5006 Fid.hash = FileId.Hash;
5008 code = cm_GetSCache(&Fid, &scp, userp, &req);
5010 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5011 (*ResultCB)->ResultStatus = status;
5012 (*ResultCB)->ResultBufferLength = 0;
5013 osi_Log2(afsd_logp, "RDR_GetVolumeInfo cm_GetSCache FID failure code=0x%x status=0x%x",
5018 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
5019 osi_Log0(afsd_logp, "RDR_GetVolumeInfo Object Name Invalid - Cell = 0");
5022 lock_ObtainWrite(&scp->rw);
5024 /* start by looking up the file's end */
5025 code = cm_SyncOp(scp, NULL, userp, &req, 0,
5026 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5028 lock_ReleaseWrite(&scp->rw);
5029 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5030 (*ResultCB)->ResultStatus = status;
5031 (*ResultCB)->ResultBufferLength = 0;
5032 osi_Log3(afsd_logp, "RDR_GetVolumeInfo cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
5038 pResultCB->SectorsPerAllocationUnit = 1;
5039 pResultCB->BytesPerSector = 1024;
5041 pResultCB->CellID = scp->fid.cell;
5042 pResultCB->VolumeID = scp->fid.volume;
5043 pResultCB->Characteristics = FILE_REMOTE_DEVICE;
5044 pResultCB->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK |
5045 FILE_SUPPORTS_REPARSE_POINTS;
5047 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
5048 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)
5050 pResultCB->TotalAllocationUnits.QuadPart = 100;
5051 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
5053 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5054 pResultCB->Characteristics |= FILE_READ_ONLY_DEVICE;
5056 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( "Freelance.Local.Root", -1, pResultCB->VolumeLabel,
5057 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5058 if ( pResultCB->VolumeLabelLength )
5059 pResultCB->VolumeLabelLength--;
5061 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
5063 volp = cm_GetVolumeByFID(&scp->fid);
5065 code = CM_ERROR_NOSUCHVOLUME;
5068 volstatep = cm_VolumeStateByID(volp, scp->fid.volume);
5069 volType = cm_VolumeType(volp, scp->fid.volume);
5071 pResultCB->Characteristics |= ((volType == ROVOL || volType == BACKVOL) ? FILE_READ_ONLY_DEVICE : 0);
5074 OfflineMsg = offLineMsg;
5076 lock_ReleaseWrite(&scp->rw);
5078 code = cm_ConnFromFID(&scp->fid, userp, &req, &connp);
5081 rxconnp = cm_GetRxConn(connp);
5082 code = RXAFS_GetVolumeStatus(rxconnp, scp->fid.volume,
5083 &volStat, &Name, &OfflineMsg, &MOTD);
5084 rx_PutConnection(rxconnp);
5086 } while (cm_Analyze(connp, userp, &req, &scp->fid, 0, NULL, NULL, NULL, code));
5087 code = cm_MapRPCError(code, &req);
5089 pResultCB->TotalAllocationUnits.QuadPart = volStat.PartMaxBlocks;
5090 pResultCB->AvailableAllocationUnits.QuadPart = volStat.PartBlocksAvail;
5092 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( Name, -1, pResultCB->VolumeLabel,
5093 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5095 pResultCB->TotalAllocationUnits.QuadPart = 0x7FFFFFFF;
5096 pResultCB->AvailableAllocationUnits.QuadPart = (volType == ROVOL || volType == BACKVOL) ? 0 : 0x3F000000;
5098 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( volp->namep, -1, pResultCB->VolumeLabel,
5099 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5102 if ( pResultCB->VolumeLabelLength )
5103 pResultCB->VolumeLabelLength--;
5105 lock_ObtainWrite(&scp->rw);
5107 pResultCB->VolumeLabelLength *= sizeof(WCHAR); /* convert to bytes from chars */
5109 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5112 lock_ReleaseWrite(&scp->rw);
5115 cm_ReleaseSCache(scp);
5117 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5118 (*ResultCB)->ResultStatus = status;
5119 osi_Log0(afsd_logp, "RDR_GetVolumeInfo SUCCESS");
5124 RDR_HoldFid( IN cm_user_t *userp,
5125 IN AFSHoldFidRequestCB * pHoldFidCB,
5127 IN DWORD ResultBufferLength,
5128 IN OUT AFSCommResult **ResultCB)
5130 AFSHoldFidResultCB *pResultCB = NULL;
5137 osi_Log1(afsd_logp, "RDR_HoldFid Count=%u", pHoldFidCB->Count);
5139 Length = sizeof(AFSHoldFidResultCB) + (pHoldFidCB->Count-1) * sizeof(AFSFidResult);
5140 if (Length > ResultBufferLength) {
5141 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5144 memset( *ResultCB, 0, sizeof(AFSCommResult));
5145 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5148 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5151 memset( *ResultCB, '\0', Length );
5152 (*ResultCB)->ResultBufferLength = Length;
5153 pResultCB = (AFSHoldFidResultCB *)(*ResultCB)->ResultData;
5155 for ( index = 0; index < pHoldFidCB->Count; index++ )
5157 cm_scache_t *scp = NULL;
5160 Fid.cell = pResultCB->Result[index].FileID.Cell = pHoldFidCB->FileID[index].Cell;
5161 Fid.volume = pResultCB->Result[index].FileID.Volume = pHoldFidCB->FileID[index].Volume;
5162 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pHoldFidCB->FileID[index].Vnode;
5163 Fid.unique = pResultCB->Result[index].FileID.Unique = pHoldFidCB->FileID[index].Unique;
5164 Fid.hash = pResultCB->Result[index].FileID.Hash = pHoldFidCB->FileID[index].Hash;
5166 osi_Log4( afsd_logp,
5167 "RDR_HoldFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5168 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5170 scp = cm_FindSCache(&Fid);
5172 RDR_FlagScpInUse( scp, FALSE );
5173 cm_ReleaseSCache(scp);
5175 pResultCB->Result[index].Status = 0;
5178 (*ResultCB)->ResultStatus = 0;
5179 osi_Log0(afsd_logp, "RDR_HoldFid SUCCESS");
5184 RDR_ReleaseFid( IN cm_user_t *userp,
5185 IN AFSReleaseFidRequestCB * pReleaseFidCB,
5187 IN DWORD ResultBufferLength,
5188 IN OUT AFSCommResult **ResultCB)
5190 AFSReleaseFidResultCB *pResultCB = NULL;
5197 osi_Log1(afsd_logp, "RDR_ReleaseFid Count=%u", pReleaseFidCB->Count);
5199 Length = sizeof(AFSReleaseFidResultCB) + (pReleaseFidCB->Count ? pReleaseFidCB->Count-1 : 0) * sizeof(AFSFidResult);
5200 if (Length > ResultBufferLength) {
5201 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5204 memset( *ResultCB, 0, sizeof(AFSCommResult));
5205 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5208 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5211 memset( *ResultCB, '\0', Length );
5212 (*ResultCB)->ResultBufferLength = Length;
5213 pResultCB = (AFSReleaseFidResultCB *)(*ResultCB)->ResultData;
5215 for ( index = 0; index < pReleaseFidCB->Count; index++ )
5217 cm_scache_t *scp = NULL;
5220 Fid.cell = pResultCB->Result[index].FileID.Cell = pReleaseFidCB->FileID[index].Cell;
5221 Fid.volume = pResultCB->Result[index].FileID.Volume = pReleaseFidCB->FileID[index].Volume;
5222 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pReleaseFidCB->FileID[index].Vnode;
5223 Fid.unique = pResultCB->Result[index].FileID.Unique = pReleaseFidCB->FileID[index].Unique;
5224 Fid.hash = pResultCB->Result[index].FileID.Hash = pReleaseFidCB->FileID[index].Hash;
5226 osi_Log4( afsd_logp,
5227 "RDR_ReleaseFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5228 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5230 scp = cm_FindSCache(&Fid);
5232 lock_ObtainWrite(&scp->rw);
5233 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
5234 lock_ReleaseWrite(&scp->rw);
5236 cm_ReleaseSCache(scp);
5238 pResultCB->Result[index].Status = 0;
5240 pResultCB->Count = pReleaseFidCB->Count;
5242 (*ResultCB)->ResultStatus = 0;
5243 osi_Log0(afsd_logp, "RDR_ReleaseFid SUCCESS");
5248 * The redirector makes several assumptions regarding the
5249 * SRVSVC and WKSSVC pipes transactions. First, the interface
5250 * versions are those indicated below. Secondly, the encoding
5251 * will be performed using NDR version 2. These assumptions
5252 * may not hold in the future and end-to-end MSRPC Bind
5253 * negotiations may need to be supported. Of course, these
5254 * are the only interface versions that are supported by the
5257 #define MSRPC_PIPE_PREFIX L".\\"
5259 static const UUID MSRPC_SRVSVC_UUID = {0x4B324FC8, 0x1670, 0x01D3,
5260 {0x12, 0x78, 0x5A, 0x47, 0xBF, 0x6E, 0xE1, 0x88}};
5261 #define MSRPC_SRVSVC_NAME L"PIPE\\SRVSVC"
5262 #define MSRPC_SRVSVC_VERS 3
5264 static const UUID MSRPC_WKSSVC_UUID = {0x6BFFD098, 0xA112, 0x3610,
5265 {0x98, 0x33, 0x46, 0xC3, 0xF8, 0x7E, 0x34, 0x5A}};
5266 #define MSRPC_WKSSVC_NAME L"PIPE\\WKSSVC"
5267 #define MSRPC_WKSSVC_VERS 1
5269 static const UUID MSRPC_NDR_UUID = {0x8A885D04, 0x1CEB, 0x11C9,
5270 {0x9F, 0xE8, 0x08, 0x00, 0x2B, 0x10, 0x48, 0x60}};
5271 #define MSRPC_NDR_NAME L"NDR"
5272 #define MSRPC_NDR_VERS 2
5274 extern RPC_IF_HANDLE srvsvc_v3_0_s_ifspec;
5275 extern RPC_IF_HANDLE wkssvc_v1_0_s_ifspec;
5278 RDR_PipeOpen( IN cm_user_t *userp,
5279 IN AFSFileID ParentId,
5281 IN DWORD NameLength,
5282 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5284 IN DWORD ResultBufferLength,
5285 IN OUT AFSCommResult **ResultCB)
5290 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5296 sizeof( AFSCommResult));
5298 /* Get the active directory */
5299 ParentFid.cell = ParentId.Cell;
5300 ParentFid.volume = ParentId.Volume;
5301 ParentFid.vnode = ParentId.Vnode;
5302 ParentFid.unique = ParentId.Unique;
5303 ParentFid.hash = ParentId.Hash;
5305 /* Get the root directory */
5306 RootFid.cell = pPipe_CB->RootId.Cell;
5307 RootFid.volume = pPipe_CB->RootId.Volume;
5308 RootFid.vnode = pPipe_CB->RootId.Vnode;
5309 RootFid.unique = pPipe_CB->RootId.Unique;
5310 RootFid.hash = pPipe_CB->RootId.Hash;
5312 /* Create the pipe index */
5313 (*ResultCB)->ResultStatus =
5314 RDR_SetupPipe( pPipe_CB->RequestId, &ParentFid, &RootFid,
5315 Name, NameLength, userp);
5321 RDR_PipeClose( IN cm_user_t *userp,
5322 IN AFSFileID ParentId,
5323 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5325 IN DWORD ResultBufferLength,
5326 IN OUT AFSCommResult **ResultCB)
5328 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5334 sizeof( AFSCommResult));
5336 /* Cleanup the pipe index */
5337 RDR_CleanupPipe(pPipe_CB->RequestId);
5344 RDR_PipeWrite( IN cm_user_t *userp,
5345 IN AFSFileID ParentId,
5346 IN AFSPipeIORequestCB *pPipe_CB,
5347 IN BYTE *pPipe_Data,
5349 IN DWORD ResultBufferLength,
5350 IN OUT AFSCommResult **ResultCB)
5352 AFSPipeIOResultCB *pResultCB;
5353 cm_scache_t *dscp = NULL;
5360 req.flags |= CM_REQ_WOW64;
5362 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5368 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5370 pResultCB = (AFSPipeIOResultCB *)(*ResultCB)->ResultData;
5372 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_Data, &req, userp);
5374 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5375 (*ResultCB)->ResultStatus = status;
5379 pResultCB->BytesProcessed = pPipe_CB->BufferLength;
5380 (*ResultCB)->ResultBufferLength = sizeof( AFSPipeIOResultCB);
5385 RDR_PipeRead( IN cm_user_t *userp,
5386 IN AFSFileID ParentId,
5387 IN AFSPipeIORequestCB *pPipe_CB,
5389 IN DWORD ResultBufferLength,
5390 IN OUT AFSCommResult **ResultCB)
5393 cm_scache_t *dscp = NULL;
5400 req.flags |= CM_REQ_WOW64;
5402 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5408 sizeof( AFSCommResult));
5410 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5412 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_Data,
5413 &(*ResultCB)->ResultBufferLength, &req, userp);
5415 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5416 (*ResultCB)->ResultStatus = status;
5423 RDR_PipeSetInfo( IN cm_user_t *userp,
5424 IN AFSFileID ParentId,
5425 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5426 IN BYTE *pPipe_Data,
5428 IN DWORD ResultBufferLength,
5429 IN OUT AFSCommResult **ResultCB)
5431 cm_scache_t *dscp = NULL;
5437 req.flags |= CM_REQ_WOW64;
5439 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5445 sizeof( AFSCommResult));
5447 status = RDR_Pipe_SetInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5448 pPipeInfo_CB->BufferLength, pPipe_Data, &req, userp);
5450 (*ResultCB)->ResultStatus = status;
5455 RDR_PipeQueryInfo( IN cm_user_t *userp,
5456 IN AFSFileID ParentId,
5457 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5459 IN DWORD ResultBufferLength,
5460 IN OUT AFSCommResult **ResultCB)
5463 cm_scache_t *dscp = NULL;
5469 req.flags |= CM_REQ_WOW64;
5471 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5477 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5479 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5481 status = RDR_Pipe_QueryInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5482 ResultBufferLength, pPipe_Data,
5483 &(*ResultCB)->ResultBufferLength, &req, userp);
5485 (*ResultCB)->ResultStatus = status;
5489 RDR_PipeTransceive( IN cm_user_t *userp,
5490 IN AFSFileID ParentId,
5491 IN AFSPipeIORequestCB *pPipe_CB,
5492 IN BYTE *pPipe_InData,
5494 IN DWORD ResultBufferLength,
5495 IN OUT AFSCommResult **ResultCB)
5498 * This function processes a Pipe Service request
5499 * that would normally be sent to a LAN Manager server
5500 * across an authenticated SMB-PIPE/MSRPC/SVC request
5501 * stack. The request is being sent here because the
5502 * application (e.g., Explorer Shell or Common Control File
5503 * dialog) believes that because the UNC path it is
5504 * processing has specified a server name that is not
5505 * "." and that the Server is remote and that the Share
5506 * list cannot be obtained using the Network Provider
5509 * The file system driver is faking the Bind-Ack response
5510 * to the MSRPC Bind request but cannot decode the NDR
5511 * encoded Pipe Service requests. For that we will use
5512 * the service's MSRPC module. However, unlike the SMB
5513 * server usage we must fake the MSRPC Bind exchange and
5514 * map the PipeName to an interface instead of using the
5515 * GUID specified in the MSRPC Bind request.
5517 * None of the requests that are being processed by the
5518 * service require authentication. As a result the userp
5519 * parameter will be ignored.
5521 * Although there are dozens of Pipe Services, the only
5522 * ones that we are implementing are WKSSVC and SRVSVC.
5523 * These support NetShareEnum, NetShareGetInfo,
5524 * NetServerGetInfo, and NetWorkstaGetInfo which are
5525 * commonly queried by NET VIEW, the Explorer Shell,
5526 * and the Common Control File dialog.
5528 BYTE *pPipe_OutData;
5529 cm_scache_t *dscp = NULL;
5533 DWORD Length = ResultBufferLength + sizeof( AFSCommResult);
5537 req.flags |= CM_REQ_WOW64;
5539 *ResultCB = (AFSCommResult *)malloc( Length);
5542 memset( *ResultCB, '\0', Length );
5544 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_InData, &req, userp);
5546 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5547 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Write FAILURE code=0x%x status=0x%x",
5549 (*ResultCB)->ResultStatus = status;
5553 pPipe_OutData = (BYTE *)(*ResultCB)->ResultData;
5554 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_OutData,
5555 &(*ResultCB)->ResultBufferLength, &req, userp);
5557 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5558 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Read FAILURE code=0x%x status=0x%x",
5560 (*ResultCB)->ResultStatus = status;
5564 (*ResultCB)->ResultStatus = 0;
5565 osi_Log0(afsd_logp, "RDR_Pipe_Transceive SUCCESS");