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);
1069 cm_strlwr_utf16(wszName);
1072 code = cm_EvaluateVolumeReference(wszName, CM_FLAG_CHECKPATH, userp, &req, &scp);
1075 if (code == 0 && scp) {
1076 wchar_t shortName[13]=L"";
1079 cm_Gen8Dot3VolNameW(scp->fid.cell, scp->fid.volume, shortName, NULL);
1080 } else if (!cm_Is8Dot3(wszName)) {
1083 dfid.vnode = htonl(scp->fid.vnode);
1084 dfid.unique = htonl(scp->fid.unique);
1086 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1088 shortName[0] = '\0';
1091 code = RDR_PopulateCurrentEntry(pCurrentEntry, dwRemaining,
1092 dscp, scp, userp, &req,
1093 FileName, shortName,
1094 (bWow64 ? RDR_POP_WOW64 : 0) |
1095 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1096 0, NULL, &dwRemaining);
1098 RDR_FlagScpInUse( scp, FALSE );
1099 cm_ReleaseSCache(scp);
1102 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1103 (*ResultCB)->ResultStatus = status;
1104 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1107 pEvalResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1108 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1109 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1110 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName SUCCESS");
1113 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1114 (*ResultCB)->ResultStatus = status;
1115 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1118 (*ResultCB)->ResultStatus = STATUS_NO_SUCH_FILE;
1119 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName No Such File");
1121 cm_ReleaseSCache(dscp);
1128 RDR_EvaluateNodeByID( IN cm_user_t *userp,
1129 IN AFSFileID ParentID, /* not used */
1130 IN AFSFileID SourceID,
1134 IN DWORD ResultBufferLength,
1135 IN OUT AFSCommResult **ResultCB)
1137 AFSFileEvalResultCB *pEvalResultCB = NULL;
1138 AFSDirEnumEntry * pCurrentEntry = NULL;
1139 size_t size = ResultBufferLength ? sizeof(AFSCommResult) + ResultBufferLength - 1 : sizeof(AFSCommResult);
1140 afs_uint32 code = 0;
1141 cm_scache_t * scp = NULL;
1142 cm_scache_t * dscp = NULL;
1149 osi_Log4(afsd_logp, "RDR_EvaluateNodeByID source FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1150 SourceID.Cell, SourceID.Volume, SourceID.Vnode, SourceID.Unique);
1151 osi_Log4(afsd_logp, "... parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1152 ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1154 *ResultCB = (AFSCommResult *)malloc(size);
1156 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Out of Memory");
1160 memset(*ResultCB, 0, size);
1161 (*ResultCB)->ResultBufferLength = 0;
1162 dwRemaining = ResultBufferLength;
1163 if (ResultBufferLength >= sizeof( AFSFileEvalResultCB)) {
1164 pEvalResultCB = (AFSFileEvalResultCB *)&(*ResultCB)->ResultData;
1165 pCurrentEntry = &pEvalResultCB->DirEnum;
1166 dwRemaining -= (sizeof( AFSFileEvalResultCB) - sizeof( AFSDirEnumEntry));
1171 req.flags |= CM_REQ_WOW64;
1173 if (SourceID.Cell != 0) {
1174 Fid.cell = SourceID.Cell;
1175 Fid.volume = SourceID.Volume;
1176 Fid.vnode = SourceID.Vnode;
1177 Fid.unique = SourceID.Unique;
1178 Fid.hash = SourceID.Hash;
1180 code = cm_GetSCache(&Fid, &scp, userp, &req);
1182 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1183 (*ResultCB)->ResultStatus = status;
1184 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache SourceFID failure code=0x%x status=0x%x",
1189 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
1190 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Name Invalid - Cell = 0");
1194 if (ParentID.Cell != 0) {
1195 cm_SetFid(&parentFid, ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1196 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1198 cm_ReleaseSCache(scp);
1199 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1200 if ( status == STATUS_INVALID_HANDLE)
1201 status = STATUS_OBJECT_PATH_INVALID;
1202 (*ResultCB)->ResultStatus = status;
1203 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1207 } else if (SourceID.Vnode == 1) {
1209 cm_HoldSCache(dscp);
1210 } else if (scp->parentVnode) {
1211 cm_SetFid(&parentFid, SourceID.Cell, SourceID.Volume, scp->parentVnode, scp->parentUnique);
1212 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1214 cm_ReleaseSCache(scp);
1215 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1216 if ( status == STATUS_INVALID_HANDLE)
1217 status = STATUS_OBJECT_PATH_INVALID;
1218 (*ResultCB)->ResultStatus = status;
1219 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1224 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
1225 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Path Invalid - Unknown Parent");
1229 /* Make sure the directory is current */
1230 lock_ObtainWrite(&dscp->rw);
1231 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1232 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1234 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1235 (*ResultCB)->ResultStatus = status;
1236 lock_ReleaseWrite(&dscp->rw);
1237 cm_ReleaseSCache(dscp);
1238 cm_ReleaseSCache(scp);
1239 osi_Log3(afsd_logp, "RDR_EvaluateNodeByID cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1240 dscp, code, status);
1244 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1245 lock_ReleaseWrite(&dscp->rw);
1247 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1248 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1249 cm_ReleaseSCache(dscp);
1250 cm_ReleaseSCache(scp);
1251 osi_Log1(afsd_logp, "RDR_EvaluateNodeByID Not a Directory dscp=0x%p", dscp);
1255 code = RDR_PopulateCurrentEntry(pCurrentEntry, dwRemaining,
1256 dscp, scp, userp, &req, NULL, NULL,
1257 (bWow64 ? RDR_POP_WOW64 : 0) |
1258 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1259 0, NULL, &dwRemaining);
1262 RDR_FlagScpInUse( scp, FALSE );
1263 cm_ReleaseSCache(scp);
1264 cm_ReleaseSCache(dscp);
1267 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1268 (*ResultCB)->ResultStatus = status;
1269 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID FAILURE code=0x%x status=0x%x",
1272 pEvalResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1274 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1275 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1276 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID SUCCESS");
1282 RDR_CreateFileEntry( IN cm_user_t *userp,
1283 IN WCHAR *FileNameCounted,
1284 IN DWORD FileNameLength,
1285 IN AFSFileCreateCB *CreateCB,
1288 IN DWORD ResultBufferLength,
1289 IN OUT AFSCommResult **ResultCB)
1291 AFSFileCreateResultCB *pResultCB = NULL;
1292 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1295 cm_scache_t * dscp = NULL;
1296 afs_uint32 flags = 0;
1298 cm_scache_t * scp = NULL;
1301 wchar_t FileName[260];
1303 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1305 osi_Log4(afsd_logp, "RDR_CreateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1306 CreateCB->ParentId.Cell, CreateCB->ParentId.Volume,
1307 CreateCB->ParentId.Vnode, CreateCB->ParentId.Unique);
1308 osi_Log1(afsd_logp, "... name=%S", osi_LogSaveStringW(afsd_logp, FileName));
1312 req.flags |= CM_REQ_WOW64;
1313 memset(&setAttr, 0, sizeof(cm_attr_t));
1315 *ResultCB = (AFSCommResult *)malloc(size);
1317 osi_Log0(afsd_logp, "RDR_CreateFileEntry out of memory");
1325 parentFid.cell = CreateCB->ParentId.Cell;
1326 parentFid.volume = CreateCB->ParentId.Volume;
1327 parentFid.vnode = CreateCB->ParentId.Vnode;
1328 parentFid.unique = CreateCB->ParentId.Unique;
1329 parentFid.hash = CreateCB->ParentId.Hash;
1331 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1333 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1334 (*ResultCB)->ResultStatus = status;
1335 if ( status == STATUS_INVALID_HANDLE)
1336 status = STATUS_OBJECT_PATH_INVALID;
1337 osi_Log2(afsd_logp, "RDR_CreateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1342 lock_ObtainWrite(&dscp->rw);
1343 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1344 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1346 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1347 (*ResultCB)->ResultStatus = status;
1348 lock_ReleaseWrite(&dscp->rw);
1349 cm_ReleaseSCache(dscp);
1350 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (1) dscp=0x%p code=0x%x status=0x%x",
1351 dscp, code, status);
1355 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1356 lock_ReleaseWrite(&dscp->rw);
1358 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1359 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1360 cm_ReleaseSCache(dscp);
1361 osi_Log1(afsd_logp, "RDR_CreateFileEntry Not a Directory dscp=0x%p",
1366 /* Use current time */
1367 setAttr.mask = CM_ATTRMASK_CLIENTMODTIME;
1368 setAttr.clientModTime = time(NULL);
1370 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1371 if (smb_unixModeDefaultDir) {
1372 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1373 setAttr.unixModeBits = smb_unixModeDefaultDir;
1374 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1375 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1378 code = cm_MakeDir(dscp, FileName, flags, &setAttr, userp, &req, &scp);
1380 if (smb_unixModeDefaultFile) {
1381 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1382 setAttr.unixModeBits = smb_unixModeDefaultFile;
1383 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1384 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1387 setAttr.mask |= CM_ATTRMASK_LENGTH;
1388 setAttr.length.LowPart = CreateCB->AllocationSize.LowPart;
1389 setAttr.length.HighPart = CreateCB->AllocationSize.HighPart;
1390 code = cm_Create(dscp, FileName, flags, &setAttr, &scp, userp, &req);
1393 wchar_t shortName[13]=L"";
1397 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
1399 (*ResultCB)->ResultBufferLength = sizeof( AFSFileCreateResultCB);
1401 pResultCB = (AFSFileCreateResultCB *)(*ResultCB)->ResultData;
1403 dwRemaining = ResultBufferLength - sizeof( AFSFileCreateResultCB) + sizeof( AFSDirEnumEntry);
1405 lock_ObtainWrite(&dscp->rw);
1406 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1407 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1409 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1410 (*ResultCB)->ResultStatus = status;
1411 lock_ReleaseWrite(&dscp->rw);
1412 cm_ReleaseSCache(dscp);
1413 cm_ReleaseSCache(scp);
1414 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (2) dscp=0x%p code=0x%x status=0x%x",
1415 dscp, code, status);
1419 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1421 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1422 lock_ReleaseWrite(&dscp->rw);
1424 dfid.vnode = htonl(scp->fid.vnode);
1425 dfid.unique = htonl(scp->fid.unique);
1427 if (!cm_Is8Dot3(FileName))
1428 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1430 shortName[0] = '\0';
1432 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1433 dscp, scp, userp, &req, FileName, shortName,
1434 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1435 0, NULL, &dwRemaining);
1438 RDR_FlagScpInUse( scp, FALSE );
1439 cm_ReleaseSCache(scp);
1440 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1441 osi_Log0(afsd_logp, "RDR_CreateFileEntry SUCCESS");
1443 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1444 (*ResultCB)->ResultStatus = status;
1445 (*ResultCB)->ResultBufferLength = 0;
1446 osi_Log2(afsd_logp, "RDR_CreateFileEntry FAILURE code=0x%x status=0x%x",
1450 cm_ReleaseSCache(dscp);
1456 RDR_UpdateFileEntry( IN cm_user_t *userp,
1457 IN AFSFileID FileId,
1458 IN AFSFileUpdateCB *UpdateCB,
1460 IN DWORD ResultBufferLength,
1461 IN OUT AFSCommResult **ResultCB)
1463 AFSFileUpdateResultCB *pResultCB = NULL;
1464 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1468 afs_uint32 flags = 0;
1470 cm_scache_t * scp = NULL;
1471 cm_scache_t * dscp = NULL;
1473 time_t clientModTime;
1476 BOOL bScpLocked = FALSE;
1480 req.flags |= CM_REQ_WOW64;
1481 memset(&setAttr, 0, sizeof(cm_attr_t));
1483 osi_Log4(afsd_logp, "RDR_UpdateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1484 UpdateCB->ParentId.Cell, UpdateCB->ParentId.Volume,
1485 UpdateCB->ParentId.Vnode, UpdateCB->ParentId.Unique);
1486 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1487 FileId.Cell, FileId.Volume,
1488 FileId.Vnode, FileId.Unique);
1490 *ResultCB = (AFSCommResult *)malloc( size);
1492 osi_Log0(afsd_logp, "RDR_UpdateFileEntry Out of Memory");
1500 parentFid.cell = UpdateCB->ParentId.Cell;
1501 parentFid.volume = UpdateCB->ParentId.Volume;
1502 parentFid.vnode = UpdateCB->ParentId.Vnode;
1503 parentFid.unique = UpdateCB->ParentId.Unique;
1504 parentFid.hash = UpdateCB->ParentId.Hash;
1506 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1508 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1509 (*ResultCB)->ResultStatus = status;
1510 if ( status == STATUS_INVALID_HANDLE)
1511 status = STATUS_OBJECT_PATH_INVALID;
1512 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1517 lock_ObtainWrite(&dscp->rw);
1519 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1520 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1522 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1523 (*ResultCB)->ResultStatus = status;
1524 lock_ReleaseWrite(&dscp->rw);
1525 cm_ReleaseSCache(dscp);
1526 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1527 dscp, code, status);
1531 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1532 lock_ReleaseWrite(&dscp->rw);
1535 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1536 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1537 cm_ReleaseSCache(dscp);
1538 osi_Log1(afsd_logp, "RDR_UpdateFileEntry Not a Directory dscp=0x%p",
1543 Fid.cell = FileId.Cell;
1544 Fid.volume = FileId.Volume;
1545 Fid.vnode = FileId.Vnode;
1546 Fid.unique = FileId.Unique;
1547 Fid.hash = FileId.Hash;
1549 code = cm_GetSCache(&Fid, &scp, userp, &req);
1551 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1552 (*ResultCB)->ResultStatus = status;
1553 cm_ReleaseSCache(dscp);
1554 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache object FID failure code=0x%x status=0x%x",
1559 lock_ObtainWrite(&scp->rw);
1561 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1562 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1564 lock_ReleaseWrite(&scp->rw);
1565 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1566 (*ResultCB)->ResultStatus = status;
1567 (*ResultCB)->ResultBufferLength = 0;
1568 cm_ReleaseSCache(dscp);
1569 cm_ReleaseSCache(scp);
1570 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
1574 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1576 if (UpdateCB->ChangeTime.QuadPart) {
1578 if (scp->fileType == CM_SCACHETYPE_FILE) {
1579 /* Do not set length and other attributes at the same time */
1580 if (scp->length.QuadPart != UpdateCB->AllocationSize.QuadPart) {
1581 osi_Log2(afsd_logp, "RDR_UpdateFileEntry Length Change 0x%x -> 0x%x",
1582 (afs_uint32)scp->length.QuadPart, (afs_uint32)UpdateCB->AllocationSize.QuadPart);
1583 setAttr.mask |= CM_ATTRMASK_LENGTH;
1584 setAttr.length.LowPart = UpdateCB->AllocationSize.LowPart;
1585 setAttr.length.HighPart = UpdateCB->AllocationSize.HighPart;
1586 lock_ReleaseWrite(&scp->rw);
1588 code = cm_SetAttr(scp, &setAttr, userp, &req);
1596 lock_ObtainWrite(&scp->rw);
1599 if ((scp->unixModeBits & 0200) && (UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1600 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1601 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1602 } else if (!(scp->unixModeBits & 0200) && !(UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1603 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1604 setAttr.unixModeBits = scp->unixModeBits | 0222;
1608 if (UpdateCB->LastWriteTime.QuadPart) {
1609 ft.dwLowDateTime = UpdateCB->LastWriteTime.LowPart;
1610 ft.dwHighDateTime = UpdateCB->LastWriteTime.HighPart;
1612 cm_UnixTimeFromLargeSearchTime(& clientModTime, &ft);
1615 lock_ObtainWrite(&scp->rw);
1618 if (scp->clientModTime != clientModTime) {
1619 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1620 setAttr.clientModTime = clientModTime;
1625 lock_ReleaseWrite(&scp->rw);
1627 code = cm_SetAttr(scp, &setAttr, userp, &req);
1634 lock_ReleaseWrite(&scp->rw);
1638 DWORD dwRemaining = ResultBufferLength - sizeof( AFSFileUpdateResultCB) + sizeof( AFSDirEnumEntry);
1640 pResultCB = (AFSFileUpdateResultCB *)(*ResultCB)->ResultData;
1642 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1643 dscp, scp, userp, &req, NULL, NULL,
1644 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1645 0, NULL, &dwRemaining);
1646 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1647 osi_Log0(afsd_logp, "RDR_UpdateFileEntry SUCCESS");
1649 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1650 (*ResultCB)->ResultStatus = status;
1651 (*ResultCB)->ResultBufferLength = 0;
1652 osi_Log2(afsd_logp, "RDR_UpdateFileEntry FAILURE code=0x%x status=0x%x",
1655 cm_ReleaseSCache(scp);
1656 cm_ReleaseSCache(dscp);
1662 RDR_CleanupFileEntry( IN cm_user_t *userp,
1663 IN AFSFileID FileId,
1664 IN WCHAR *FileNameCounted,
1665 IN DWORD FileNameLength,
1666 IN AFSFileCleanupCB *CleanupCB,
1668 IN BOOL bLastHandle,
1669 IN BOOL bDeleteFile,
1670 IN BOOL bUnlockFile,
1671 IN DWORD ResultBufferLength,
1672 IN OUT AFSCommResult **ResultCB)
1674 AFSFileCleanupResultCB *pResultCB = NULL;
1675 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1678 afs_uint32 code = 0;
1679 afs_uint32 flags = 0;
1681 cm_scache_t * scp = NULL;
1682 cm_scache_t * dscp = NULL;
1684 time_t clientModTime;
1687 BOOL bScpLocked = FALSE;
1688 BOOL bDscpLocked = FALSE;
1689 BOOL bFlushFile = FALSE;
1694 req.flags |= CM_REQ_WOW64;
1695 memset(&setAttr, 0, sizeof(cm_attr_t));
1697 osi_Log4(afsd_logp, "RDR_CleanupFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1698 CleanupCB->ParentId.Cell, CleanupCB->ParentId.Volume,
1699 CleanupCB->ParentId.Vnode, CleanupCB->ParentId.Unique);
1700 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1701 FileId.Cell, FileId.Volume,
1702 FileId.Vnode, FileId.Unique);
1704 *ResultCB = (AFSCommResult *)malloc( size);
1706 osi_Log0(afsd_logp, "RDR_CleanupFileEntry Out of Memory");
1714 parentFid.cell = CleanupCB->ParentId.Cell;
1715 parentFid.volume = CleanupCB->ParentId.Volume;
1716 parentFid.vnode = CleanupCB->ParentId.Vnode;
1717 parentFid.unique = CleanupCB->ParentId.Unique;
1718 parentFid.hash = CleanupCB->ParentId.Hash;
1720 if (parentFid.cell) {
1721 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1723 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1724 if ( status == STATUS_INVALID_HANDLE)
1725 status = STATUS_OBJECT_PATH_INVALID;
1726 (*ResultCB)->ResultStatus = status;
1727 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1732 lock_ObtainWrite(&dscp->rw);
1734 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1735 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1737 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure dscp=0x%p code=0x%x",
1743 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1744 lock_ReleaseWrite(&dscp->rw);
1745 bDscpLocked = FALSE;
1747 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1748 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1749 cm_ReleaseSCache(dscp);
1750 osi_Log1(afsd_logp, "RDR_CleanupFileEntry Not a Directory dscp=0x%p",
1757 Fid.cell = FileId.Cell;
1758 Fid.volume = FileId.Volume;
1759 Fid.vnode = FileId.Vnode;
1760 Fid.unique = FileId.Unique;
1761 Fid.hash = FileId.Hash;
1763 code = cm_GetSCache(&Fid, &scp, userp, &req);
1765 osi_Log1(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache object FID failure code=0x%x",
1770 lock_ObtainWrite(&scp->rw);
1772 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1773 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1775 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure scp=0x%p code=0x%x",
1779 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1781 if ((bLastHandle || bFlushFile) &&
1782 scp->redirBufCount > 0)
1784 LARGE_INTEGER heldExtents;
1785 AFSFileExtentCB extentList[1024];
1786 DWORD extentCount = 0;
1791 heldExtents.QuadPart = 0;
1793 for ( srbp = redirq_to_cm_buf_t(scp->redirQueueT);
1795 srbp = redirq_to_cm_buf_t(osi_QPrev(&srbp->redirq)))
1797 extentList[extentCount].Flags = 0;
1798 extentList[extentCount].Length = cm_data.blockSize;
1799 extentList[extentCount].FileOffset.QuadPart = srbp->offset.QuadPart;
1800 extentList[extentCount].CacheOffset.QuadPart = srbp->datap - RDR_extentBaseAddress;
1801 lock_ObtainWrite(&buf_globalLock);
1802 srbp->redirReleaseRequested = now;
1803 lock_ReleaseWrite(&buf_globalLock);
1806 if (extentCount == 1024) {
1807 lock_ReleaseWrite(&scp->rw);
1808 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1810 if (code == CM_ERROR_RETRY) {
1812 * The redirector either is not holding the extents or cannot let them
1813 * go because they are otherwise in use. At the moment, do nothing.
1820 lock_ObtainWrite(&scp->rw);
1824 if (code == 0 && extentCount > 0) {
1826 lock_ReleaseWrite(&scp->rw);
1829 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1834 /* No longer in use by redirector */
1836 lock_ObtainWrite(&scp->rw);
1841 lock_AssertWrite(&scp->rw);
1842 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
1845 if (bLastHandle || bFlushFile) {
1847 lock_ObtainWrite(&scp->rw);
1850 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
1851 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1854 lock_ReleaseWrite(&scp->rw);
1858 code = cm_FSync(scp, userp, &req, bScpLocked);
1860 if (bLastHandle && code)
1864 if (bUnlockFile || bDeleteFile) {
1866 lock_ObtainWrite(&scp->rw);
1869 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1870 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1872 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp (2) failure scp=0x%p code=0x%x",
1877 key = cm_GenerateKey(CM_SESSION_IFS, CleanupCB->ProcessId, 0);
1879 /* the scp is now locked and current */
1880 code = cm_UnlockByKey(scp, key,
1881 bDeleteFile ? CM_UNLOCK_FLAG_BY_FID : 0,
1884 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1890 if (CleanupCB->ChangeTime.QuadPart) {
1892 if (scp->fileType == CM_SCACHETYPE_FILE) {
1893 /* Do not set length and other attributes at the same time */
1894 if (scp->length.QuadPart != CleanupCB->AllocationSize.QuadPart) {
1895 osi_Log2(afsd_logp, "RDR_CleanupFileEntry Length Change 0x%x -> 0x%x",
1896 (afs_uint32)scp->length.QuadPart, (afs_uint32)CleanupCB->AllocationSize.QuadPart);
1897 setAttr.mask |= CM_ATTRMASK_LENGTH;
1898 setAttr.length.LowPart = CleanupCB->AllocationSize.LowPart;
1899 setAttr.length.HighPart = CleanupCB->AllocationSize.HighPart;
1902 lock_ReleaseWrite(&scp->rw);
1905 code = cm_SetAttr(scp, &setAttr, userp, &req);
1913 lock_ObtainWrite(&scp->rw);
1917 if ((scp->unixModeBits & 0200) && (CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1918 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1919 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1920 } else if (!(scp->unixModeBits & 0200) && !(CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1921 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1922 setAttr.unixModeBits = scp->unixModeBits | 0222;
1926 if (CleanupCB->LastWriteTime.QuadPart) {
1927 ft.dwLowDateTime = CleanupCB->LastWriteTime.LowPart;
1928 ft.dwHighDateTime = CleanupCB->LastWriteTime.HighPart;
1930 cm_UnixTimeFromLargeSearchTime(&clientModTime, &ft);
1931 if (scp->clientModTime != clientModTime) {
1932 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1933 setAttr.clientModTime = clientModTime;
1939 lock_ReleaseWrite(&scp->rw);
1941 code = cm_SetAttr(scp, &setAttr, userp, &req);
1945 /* Now drop the lock enforcing the share access */
1946 if ( CleanupCB->FileAccess != AFS_FILE_ACCESS_NOLOCK) {
1947 unsigned int sLockType;
1948 LARGE_INTEGER LOffset, LLength;
1950 if (CleanupCB->FileAccess == AFS_FILE_ACCESS_SHARED)
1951 sLockType = LOCKING_ANDX_SHARED_LOCK;
1955 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, CleanupCB->Identifier);
1957 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
1958 LOffset.LowPart = SMB_FID_QLOCK_LOW;
1959 LLength.HighPart = 0;
1960 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
1963 lock_ObtainWrite(&scp->rw);
1967 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
1970 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
1972 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
1974 if (code == CM_ERROR_RANGE_NOT_LOCKED)
1976 osi_Log3(afsd_logp, "RDR_CleanupFileEntry Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
1977 CleanupCB->FileAccess, CleanupCB->ProcessId, CleanupCB->Identifier);
1985 lock_ReleaseWrite(&dscp->rw);
1987 lock_ReleaseWrite(&scp->rw);
1989 if (dscp && bDeleteFile) {
1990 WCHAR FileName[260];
1992 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1994 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
1995 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
1997 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2000 if ( ResultBufferLength >= sizeof( AFSFileCleanupResultCB))
2002 (*ResultCB)->ResultBufferLength = sizeof( AFSFileCleanupResultCB);
2003 pResultCB = (AFSFileCleanupResultCB *)&(*ResultCB)->ResultData;
2004 pResultCB->ParentDataVersion.QuadPart = dscp ? dscp->dataVersion : 0;
2006 (*ResultCB)->ResultBufferLength = 0;
2010 (*ResultCB)->ResultStatus = 0;
2011 osi_Log0(afsd_logp, "RDR_CleanupFileEntry SUCCESS");
2013 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2014 (*ResultCB)->ResultStatus = status;
2015 osi_Log2(afsd_logp, "RDR_CleanupFileEntry FAILURE code=0x%x status=0x%x",
2019 cm_ReleaseSCache(scp);
2021 cm_ReleaseSCache(dscp);
2027 RDR_DeleteFileEntry( IN cm_user_t *userp,
2028 IN AFSFileID ParentId,
2029 IN ULONGLONG ProcessId,
2030 IN WCHAR *FileNameCounted,
2031 IN DWORD FileNameLength,
2034 IN DWORD ResultBufferLength,
2035 IN OUT AFSCommResult **ResultCB)
2038 AFSFileDeleteResultCB *pResultCB = NULL;
2039 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2042 cm_scache_t * dscp = NULL;
2043 cm_scache_t * scp = NULL;
2044 afs_uint32 flags = 0;
2048 wchar_t FileName[260];
2051 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
2053 osi_Log4(afsd_logp, "RDR_DeleteFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2054 ParentId.Cell, ParentId.Volume,
2055 ParentId.Vnode, ParentId.Unique);
2056 osi_Log2(afsd_logp, "... name=%S checkOnly=%x",
2057 osi_LogSaveStringW(afsd_logp, FileName),
2062 req.flags |= CM_REQ_WOW64;
2063 memset(&setAttr, 0, sizeof(cm_attr_t));
2065 *ResultCB = (AFSCommResult *)malloc( size);
2067 osi_Log0(afsd_logp, "RDR_DeleteFileEntry out of memory");
2075 parentFid.cell = ParentId.Cell;
2076 parentFid.volume = ParentId.Volume;
2077 parentFid.vnode = ParentId.Vnode;
2078 parentFid.unique = ParentId.Unique;
2079 parentFid.hash = ParentId.Hash;
2081 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
2083 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2084 if ( status == STATUS_INVALID_HANDLE)
2085 status = STATUS_OBJECT_PATH_INVALID;
2086 (*ResultCB)->ResultStatus = status;
2087 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
2092 lock_ObtainWrite(&dscp->rw);
2094 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
2095 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2097 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2098 (*ResultCB)->ResultStatus = status;
2099 (*ResultCB)->ResultBufferLength = 0;
2100 lock_ReleaseWrite(&dscp->rw);
2101 cm_ReleaseSCache(dscp);
2102 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
2103 dscp, code, status);
2107 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2108 lock_ReleaseWrite(&dscp->rw);
2110 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2111 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2112 cm_ReleaseSCache(dscp);
2113 osi_Log1(afsd_logp, "RDR_DeleteFileEntry Not a Directory dscp=0x%p",
2118 code = cm_Lookup(dscp, FileName, 0, userp, &req, &scp);
2120 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2121 (*ResultCB)->ResultStatus = status;
2122 (*ResultCB)->ResultBufferLength = 0;
2123 cm_ReleaseSCache(dscp);
2124 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_Lookup failure code=0x%x status=0x%x",
2129 lock_ObtainWrite(&scp->rw);
2130 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_DELETE,
2131 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2133 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2134 (*ResultCB)->ResultStatus = status;
2135 (*ResultCB)->ResultBufferLength = 0;
2136 lock_ReleaseWrite(&scp->rw);
2137 cm_ReleaseSCache(scp);
2138 cm_ReleaseSCache(dscp);
2139 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2145 /* Drop all locks since the file is being deleted */
2146 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2147 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2149 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2150 (*ResultCB)->ResultStatus = status;
2151 (*ResultCB)->ResultBufferLength = 0;
2152 lock_ReleaseWrite(&scp->rw);
2153 cm_ReleaseSCache(scp);
2154 cm_ReleaseSCache(dscp);
2155 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp Lock failure scp=0x%p code=0x%x status=0x%x",
2159 /* the scp is now locked and current */
2160 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId, 0);
2162 code = cm_UnlockByKey(scp, key,
2163 CM_UNLOCK_FLAG_BY_FID,
2166 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2167 lock_ReleaseWrite(&scp->rw);
2169 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
2170 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
2172 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2174 lock_ReleaseWrite(&scp->rw);
2178 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
2180 (*ResultCB)->ResultBufferLength = sizeof( AFSFileDeleteResultCB);
2182 pResultCB = (AFSFileDeleteResultCB *)(*ResultCB)->ResultData;
2184 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
2185 osi_Log0(afsd_logp, "RDR_DeleteFileEntry SUCCESS");
2187 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2188 (*ResultCB)->ResultStatus = status;
2189 (*ResultCB)->ResultBufferLength = 0;
2190 osi_Log2(afsd_logp, "RDR_DeleteFileEntry FAILURE code=0x%x status=0x%x",
2194 cm_ReleaseSCache(dscp);
2195 cm_ReleaseSCache(scp);
2201 RDR_RenameFileEntry( IN cm_user_t *userp,
2202 IN WCHAR *SourceFileNameCounted,
2203 IN DWORD SourceFileNameLength,
2204 IN AFSFileID SourceFileId,
2205 IN AFSFileRenameCB *pRenameCB,
2207 IN DWORD ResultBufferLength,
2208 IN OUT AFSCommResult **ResultCB)
2211 AFSFileRenameResultCB *pResultCB = NULL;
2212 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2213 AFSFileID SourceParentId = pRenameCB->SourceParentId;
2214 AFSFileID TargetParentId = pRenameCB->TargetParentId;
2215 WCHAR * TargetFileNameCounted = pRenameCB->TargetName;
2216 DWORD TargetFileNameLength = pRenameCB->TargetNameLength;
2217 cm_fid_t SourceParentFid;
2218 cm_fid_t TargetParentFid;
2220 cm_fid_t OrigTargetFid = {0,0,0,0,0};
2222 cm_scache_t * oldDscp;
2223 cm_scache_t * newDscp;
2225 wchar_t shortName[13];
2226 wchar_t SourceFileName[260];
2227 wchar_t TargetFileName[260];
2235 req.flags |= CM_REQ_WOW64;
2237 StringCchCopyNW(SourceFileName, 260, SourceFileNameCounted, SourceFileNameLength / sizeof(WCHAR));
2238 StringCchCopyNW(TargetFileName, 260, TargetFileNameCounted, TargetFileNameLength / sizeof(WCHAR));
2240 osi_Log4(afsd_logp, "RDR_RenameFileEntry Source Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2241 SourceParentId.Cell, SourceParentId.Volume,
2242 SourceParentId.Vnode, SourceParentId.Unique);
2243 osi_Log2(afsd_logp, "... Source Name=%S Length %u", osi_LogSaveStringW(afsd_logp, SourceFileName), SourceFileNameLength);
2244 osi_Log4(afsd_logp, "... Target Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2245 TargetParentId.Cell, TargetParentId.Volume,
2246 TargetParentId.Vnode, TargetParentId.Unique);
2247 osi_Log2(afsd_logp, "... Target Name=%S Length %u", osi_LogSaveStringW(afsd_logp, TargetFileName), TargetFileNameLength);
2249 *ResultCB = (AFSCommResult *)malloc( size);
2257 pResultCB = (AFSFileRenameResultCB *)(*ResultCB)->ResultData;
2259 if (SourceFileNameLength == 0 || TargetFileNameLength == 0)
2261 osi_Log2(afsd_logp, "RDR_RenameFileEntry Invalid Name Length: src %u target %u",
2262 SourceFileNameLength, TargetFileNameLength);
2263 (*ResultCB)->ResultStatus = STATUS_INVALID_PARAMETER;
2267 SourceParentFid.cell = SourceParentId.Cell;
2268 SourceParentFid.volume = SourceParentId.Volume;
2269 SourceParentFid.vnode = SourceParentId.Vnode;
2270 SourceParentFid.unique = SourceParentId.Unique;
2271 SourceParentFid.hash = SourceParentId.Hash;
2273 TargetParentFid.cell = TargetParentId.Cell;
2274 TargetParentFid.volume = TargetParentId.Volume;
2275 TargetParentFid.vnode = TargetParentId.Vnode;
2276 TargetParentFid.unique = TargetParentId.Unique;
2277 TargetParentFid.hash = TargetParentId.Hash;
2279 code = cm_GetSCache(&SourceParentFid, &oldDscp, userp, &req);
2281 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache source parent failed code 0x%x", code);
2282 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2283 if ( status == STATUS_INVALID_HANDLE)
2284 status = STATUS_OBJECT_PATH_INVALID;
2285 (*ResultCB)->ResultStatus = status;
2289 lock_ObtainWrite(&oldDscp->rw);
2290 code = cm_SyncOp(oldDscp, NULL, userp, &req, 0,
2291 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2293 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp oldDscp 0x%p failed code 0x%x", oldDscp, code);
2294 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2295 if ( status == STATUS_INVALID_HANDLE)
2296 status = STATUS_OBJECT_PATH_INVALID;
2297 (*ResultCB)->ResultStatus = status;
2298 lock_ReleaseWrite(&oldDscp->rw);
2299 cm_ReleaseSCache(oldDscp);
2303 cm_SyncOpDone(oldDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2304 lock_ReleaseWrite(&oldDscp->rw);
2307 if (oldDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2308 osi_Log1(afsd_logp, "RDR_RenameFileEntry oldDscp 0x%p not a directory", oldDscp);
2309 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2310 cm_ReleaseSCache(oldDscp);
2314 code = cm_GetSCache(&TargetParentFid, &newDscp, userp, &req);
2316 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target parent failed code 0x%x", code);
2317 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2318 (*ResultCB)->ResultStatus = status;
2319 cm_ReleaseSCache(oldDscp);
2323 lock_ObtainWrite(&newDscp->rw);
2324 code = cm_SyncOp(newDscp, NULL, userp, &req, 0,
2325 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2327 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp newDscp 0x%p failed code 0x%x", newDscp, code);
2328 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2329 (*ResultCB)->ResultStatus = status;
2330 lock_ReleaseWrite(&newDscp->rw);
2331 cm_ReleaseSCache(oldDscp);
2332 cm_ReleaseSCache(newDscp);
2336 cm_SyncOpDone(newDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2337 lock_ReleaseWrite(&newDscp->rw);
2340 if (newDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2341 osi_Log1(afsd_logp, "RDR_RenameFileEntry newDscp 0x%p not a directory", newDscp);
2342 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2343 cm_ReleaseSCache(oldDscp);
2344 cm_ReleaseSCache(newDscp);
2348 /* Obtain the original FID just for debugging purposes */
2349 code = cm_BeginDirOp( oldDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2351 code = cm_BPlusDirLookup(&dirop, SourceFileName, &SourceFid);
2352 code = cm_BPlusDirLookup(&dirop, TargetFileName, &OrigTargetFid);
2353 cm_EndDirOp(&dirop);
2356 code = cm_Rename( oldDscp, NULL, SourceFileName,
2357 newDscp, TargetFileName, userp, &req);
2359 cm_scache_t *scp = 0;
2362 (*ResultCB)->ResultBufferLength = ResultBufferLength;
2363 dwRemaining = ResultBufferLength - sizeof( AFSFileRenameResultCB) + sizeof( AFSDirEnumEntry);
2364 (*ResultCB)->ResultStatus = 0;
2366 pResultCB->SourceParentDataVersion.QuadPart = oldDscp->dataVersion;
2367 pResultCB->TargetParentDataVersion.QuadPart = newDscp->dataVersion;
2369 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p SUCCESS",
2372 code = cm_BeginDirOp( newDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2374 code = cm_BPlusDirLookup(&dirop, TargetFileName, &TargetFid);
2375 cm_EndDirOp(&dirop);
2379 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_BPlusDirLookup failed code 0x%x",
2381 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
2382 cm_ReleaseSCache(oldDscp);
2383 cm_ReleaseSCache(newDscp);
2387 osi_Log4(afsd_logp, "RDR_RenameFileEntry Target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2388 TargetFid.cell, TargetFid.volume,
2389 TargetFid.vnode, TargetFid.unique);
2391 code = cm_GetSCache(&TargetFid, &scp, userp, &req);
2393 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target failed code 0x%x", code);
2394 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2395 (*ResultCB)->ResultStatus = status;
2396 cm_ReleaseSCache(oldDscp);
2397 cm_ReleaseSCache(newDscp);
2401 /* Make sure the source vnode is current */
2402 lock_ObtainWrite(&scp->rw);
2403 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2404 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2406 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp scp 0x%p failed code 0x%x", scp, code);
2407 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2408 (*ResultCB)->ResultStatus = status;
2409 lock_ReleaseWrite(&scp->rw);
2410 cm_ReleaseSCache(oldDscp);
2411 cm_ReleaseSCache(newDscp);
2412 cm_ReleaseSCache(scp);
2416 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2417 lock_ReleaseWrite(&scp->rw);
2419 dfid.vnode = htonl(scp->fid.vnode);
2420 dfid.unique = htonl(scp->fid.unique);
2422 if (!cm_Is8Dot3(TargetFileName))
2423 cm_Gen8Dot3NameIntW(TargetFileName, &dfid, shortName, NULL);
2425 shortName[0] = '\0';
2427 RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
2428 newDscp, scp, userp, &req, TargetFileName, shortName,
2429 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
2430 0, NULL, &dwRemaining);
2431 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
2432 cm_ReleaseSCache(scp);
2434 osi_Log0(afsd_logp, "RDR_RenameFileEntry SUCCESS");
2436 osi_Log3(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p failed code 0x%x",
2437 oldDscp, newDscp, code);
2438 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2439 (*ResultCB)->ResultStatus = status;
2440 (*ResultCB)->ResultBufferLength = 0;
2443 cm_ReleaseSCache(oldDscp);
2444 cm_ReleaseSCache(newDscp);
2449 RDR_FlushFileEntry( IN cm_user_t *userp,
2450 IN AFSFileID FileId,
2452 IN DWORD ResultBufferLength,
2453 IN OUT AFSCommResult **ResultCB)
2455 cm_scache_t *scp = NULL;
2466 req.flags |= CM_REQ_WOW64;
2468 osi_Log4(afsd_logp, "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x",
2469 FileId.Cell, FileId.Volume,
2470 FileId.Vnode, FileId.Unique);
2472 snprintf( dbgstr, 1024,
2473 "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x\n",
2474 FileId.Cell, FileId.Volume,
2475 FileId.Vnode, FileId.Unique);
2476 OutputDebugStringA( dbgstr);
2479 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2481 osi_Log0(afsd_logp, "RDR_FlushFileEntry out of memory");
2487 sizeof( AFSCommResult));
2489 /* Process the release */
2490 Fid.cell = FileId.Cell;
2491 Fid.volume = FileId.Volume;
2492 Fid.vnode = FileId.Vnode;
2493 Fid.unique = FileId.Unique;
2494 Fid.hash = FileId.Hash;
2496 code = cm_GetSCache(&Fid, &scp, userp, &req);
2498 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2499 (*ResultCB)->ResultStatus = status;
2500 osi_Log2(afsd_logp, "RDR_FlushFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2505 lock_ObtainWrite(&scp->rw);
2506 if (scp->flags & CM_SCACHEFLAG_DELETED) {
2507 lock_ReleaseWrite(&scp->rw);
2508 (*ResultCB)->ResultStatus = STATUS_INVALID_HANDLE;
2512 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2513 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2515 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2516 (*ResultCB)->ResultStatus = status;
2517 lock_ReleaseWrite(&scp->rw);
2518 cm_ReleaseSCache(scp);
2519 osi_Log3(afsd_logp, "RDR_FlushFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2524 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2525 lock_ReleaseWrite(&scp->rw);
2527 code = cm_FSync(scp, userp, &req, FALSE);
2528 cm_ReleaseSCache(scp);
2531 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2532 (*ResultCB)->ResultStatus = status;
2533 osi_Log2(afsd_logp, "RDR_FlushFileEntry FAILURE code=0x%x status=0x%x",
2536 (*ResultCB)->ResultStatus = 0;
2537 osi_Log0(afsd_logp, "RDR_FlushFileEntry SUCCESS");
2539 (*ResultCB)->ResultBufferLength = 0;
2545 RDR_CheckAccess( IN cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp,
2549 ULONG afs_acc, afs_gr;
2551 afs_uint32 code = 0;
2553 file = (scp->fileType == CM_SCACHETYPE_FILE);
2556 /* access definitions from prs_fs.h */
2558 if (access & FILE_READ_DATA)
2559 afs_acc |= PRSFS_READ;
2560 if (access & FILE_READ_EA || access & FILE_READ_ATTRIBUTES)
2561 afs_acc |= PRSFS_READ;
2562 if (file && ((access & FILE_WRITE_DATA) || (access & FILE_APPEND_DATA)))
2563 afs_acc |= PRSFS_WRITE;
2564 if (access & FILE_WRITE_EA || access & FILE_WRITE_ATTRIBUTES)
2565 afs_acc |= PRSFS_WRITE;
2566 if (dir && ((access & FILE_ADD_FILE) || (access & FILE_ADD_SUBDIRECTORY)))
2567 afs_acc |= PRSFS_INSERT;
2568 if (dir && (access & FILE_LIST_DIRECTORY))
2569 afs_acc |= PRSFS_LOOKUP;
2570 if (file && (access & FILE_EXECUTE))
2571 afs_acc |= PRSFS_WRITE;
2572 if (dir && (access & FILE_TRAVERSE))
2573 afs_acc |= PRSFS_READ;
2574 if (dir && (access & FILE_DELETE_CHILD))
2575 afs_acc |= PRSFS_DELETE;
2576 if ((access & DELETE))
2577 afs_acc |= PRSFS_DELETE;
2579 /* check ACL with server */
2580 lock_ObtainWrite(&scp->rw);
2583 if (cm_HaveAccessRights(scp, userp, reqp, afs_acc, &afs_gr))
2589 /* we don't know the required access rights */
2590 code = cm_GetAccessRights(scp, userp, reqp);
2596 lock_ReleaseWrite(&(scp->rw));
2600 if (afs_gr & PRSFS_READ)
2601 *granted |= FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | FILE_EXECUTE;
2602 if (afs_gr & PRSFS_WRITE)
2603 *granted |= FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES | FILE_EXECUTE;
2604 if (afs_gr & PRSFS_INSERT)
2605 *granted |= (dir ? FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY : 0) | (file ? FILE_ADD_SUBDIRECTORY : 0);
2606 if (afs_gr & PRSFS_LOOKUP)
2607 *granted |= (dir ? FILE_LIST_DIRECTORY : 0);
2608 if (afs_gr & PRSFS_DELETE)
2609 *granted |= FILE_DELETE_CHILD | DELETE;
2610 if (afs_gr & PRSFS_LOCK)
2612 if (afs_gr & PRSFS_ADMINISTER)
2615 *granted |= SYNCHRONIZE | READ_CONTROL;
2617 /* don't give more access than what was requested */
2619 osi_Log3(afsd_logp, "RDR_CheckAccess SUCCESS scp=0x%p requested=0x%x granted=0x%x", scp, access, *granted);
2621 osi_Log2(afsd_logp, "RDR_CheckAccess FAILURE scp=0x%p code=0x%x",
2628 RDR_OpenFileEntry( IN cm_user_t *userp,
2629 IN AFSFileID FileId,
2630 IN AFSFileOpenCB *OpenCB,
2633 IN DWORD ResultBufferLength,
2634 IN OUT AFSCommResult **ResultCB)
2636 AFSFileOpenResultCB *pResultCB = NULL;
2637 cm_scache_t *scp = NULL;
2638 cm_user_t *sysUserp = NULL;
2640 cm_lock_data_t *ldp = NULL;
2647 req.flags |= CM_REQ_WOW64;
2649 osi_Log4(afsd_logp, "RDR_OpenFileEntry File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2650 FileId.Cell, FileId.Volume,
2651 FileId.Vnode, FileId.Unique);
2653 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2655 osi_Log0(afsd_logp, "RDR_OpenFileEntry out of memory");
2661 sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2663 pResultCB = (AFSFileOpenResultCB *)(*ResultCB)->ResultData;
2665 /* Process the release */
2666 Fid.cell = FileId.Cell;
2667 Fid.volume = FileId.Volume;
2668 Fid.vnode = FileId.Vnode;
2669 Fid.unique = FileId.Unique;
2670 Fid.hash = FileId.Hash;
2672 code = cm_GetSCache(&Fid, &scp, userp, &req);
2674 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2675 (*ResultCB)->ResultStatus = status;
2676 osi_Log2(afsd_logp, "RDR_OpenFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2681 lock_ObtainWrite(&scp->rw);
2682 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2683 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2685 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2686 (*ResultCB)->ResultStatus = status;
2687 lock_ReleaseWrite(&scp->rw);
2688 cm_ReleaseSCache(scp);
2689 osi_Log3(afsd_logp, "RDR_OpenFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2694 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2695 lock_ReleaseWrite(&scp->rw);
2697 sysUserp = RDR_GetLocalSystemUser();
2700 * Skip the open check if the request is coming from the local system account.
2701 * The local system has no tokens and therefore any requests sent to a file
2702 * server will fail. Unfortunately, there are special system processes that
2703 * perform actions on files and directories in preparation for memory mapping
2704 * executables. If the open check fails, the real request from the user process
2705 * will never be issued.
2707 * Permitting the file system to allow subsequent operations to proceed does
2708 * not compromise security. All requests to obtain file data or directory
2709 * enumerations will subsequently fail if they are not submitted under the
2710 * context of a process for that have access to the necessary credentials.
2713 if ( userp == sysUserp)
2715 osi_Log1(afsd_logp, "RDR_OpenFileEntry LOCAL_SYSTEM access check skipped scp=0x%p",
2717 pResultCB->GrantedAccess = OpenCB->DesiredAccess;
2718 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2729 "RDR_OpenFileEntry repeating open check scp=0x%p userp=0x%p code=0x%x",
2732 code = cm_CheckNTOpen(scp, OpenCB->DesiredAccess, OpenCB->ShareAccess,
2734 OpenCB->ProcessId, OpenCB->Identifier,
2737 code = RDR_CheckAccess(scp, userp, &req, OpenCB->DesiredAccess, &pResultCB->GrantedAccess);
2738 cm_CheckNTOpenDone(scp, userp, &req, &ldp);
2739 } while (count < 100 && (code == CM_ERROR_RETRY || code == CM_ERROR_WOULDBLOCK));
2743 * If we are restricting sharing, we should do so with a suitable
2746 if (code == 0 && scp->fileType == CM_SCACHETYPE_FILE && !(OpenCB->ShareAccess & FILE_SHARE_WRITE)) {
2748 LARGE_INTEGER LOffset, LLength;
2751 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2752 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2753 LLength.HighPart = 0;
2754 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2757 * If we are not opening the file for writing, then we don't
2758 * try to get an exclusive lock. No one else should be able to
2759 * get an exclusive lock on the file anyway, although someone
2760 * else can get a shared lock.
2762 if ((OpenCB->ShareAccess & FILE_SHARE_READ) || !(OpenCB->DesiredAccess & AFS_ACCESS_WRITE))
2764 sLockType = LOCKING_ANDX_SHARED_LOCK;
2769 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, OpenCB->Identifier);
2771 lock_ObtainWrite(&scp->rw);
2772 code = cm_Lock(scp, sLockType, LOffset, LLength, key, 0, userp, &req, NULL);
2773 lock_ReleaseWrite(&scp->rw);
2776 code = CM_ERROR_SHARING_VIOLATION;
2777 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2779 if (sLockType == LOCKING_ANDX_SHARED_LOCK)
2780 pResultCB->FileAccess = AFS_FILE_ACCESS_SHARED;
2782 pResultCB->FileAccess = AFS_FILE_ACCESS_EXCLUSIVE;
2785 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2788 cm_ReleaseUser(sysUserp);
2789 if (code == 0 && bHoldFid)
2790 RDR_FlagScpInUse( scp, FALSE );
2791 cm_ReleaseSCache(scp);
2794 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2795 (*ResultCB)->ResultStatus = status;
2796 osi_Log2(afsd_logp, "RDR_OpenFileEntry FAILURE code=0x%x status=0x%x",
2799 (*ResultCB)->ResultStatus = 0;
2800 (*ResultCB)->ResultBufferLength = sizeof( AFSFileOpenResultCB);
2801 osi_Log0(afsd_logp, "RDR_OpenFileEntry SUCCESS");
2807 RDR_ReleaseFileAccess( IN cm_user_t *userp,
2808 IN AFSFileID FileId,
2809 IN AFSFileAccessReleaseCB *ReleaseFileCB,
2811 IN DWORD ResultBufferLength,
2812 IN OUT AFSCommResult **ResultCB)
2815 unsigned int sLockType;
2816 LARGE_INTEGER LOffset, LLength;
2817 cm_scache_t *scp = NULL;
2825 req.flags |= CM_REQ_WOW64;
2827 osi_Log4(afsd_logp, "RDR_ReleaseFileAccess File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2828 FileId.Cell, FileId.Volume,
2829 FileId.Vnode, FileId.Unique);
2831 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2833 osi_Log0(afsd_logp, "RDR_ReleaseFileAccess out of memory");
2837 memset( *ResultCB, '\0', sizeof( AFSCommResult));
2839 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_NOLOCK)
2842 /* Process the release */
2843 Fid.cell = FileId.Cell;
2844 Fid.volume = FileId.Volume;
2845 Fid.vnode = FileId.Vnode;
2846 Fid.unique = FileId.Unique;
2847 Fid.hash = FileId.Hash;
2849 code = cm_GetSCache(&Fid, &scp, userp, &req);
2851 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2852 (*ResultCB)->ResultStatus = status;
2853 osi_Log2(afsd_logp, "RDR_ReleaseFileAccess cm_GetSCache FID failure code=0x%x status=0x%x",
2858 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_SHARED)
2859 sLockType = LOCKING_ANDX_SHARED_LOCK;
2863 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, ReleaseFileCB->Identifier);
2865 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2866 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2867 LLength.HighPart = 0;
2868 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2870 lock_ObtainWrite(&scp->rw);
2872 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
2875 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
2877 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
2879 if (code == CM_ERROR_RANGE_NOT_LOCKED)
2881 osi_Log3(afsd_logp, "RDR_ReleaseFileAccess Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
2882 ReleaseFileCB->FileAccess, ReleaseFileCB->ProcessId, ReleaseFileCB->Identifier);
2886 lock_ReleaseWrite(&scp->rw);
2888 osi_Log0(afsd_logp, "RDR_ReleaseFileAccessEntry SUCCESS");
2892 HexCheckSum(unsigned char * buf, int buflen, unsigned char * md5cksum)
2895 static char tr[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
2898 return "buffer length too small to HexCheckSum";
2900 for (i=0;i<16;i++) {
2903 buf[i*2] = tr[k / 16];
2904 buf[i*2+1] = tr[k % 16];
2912 * Extent requests from the file system are triggered when a file
2913 * page is not resident in the Windows cache. The file system is
2914 * responsible for loading the page but cannot block the request
2915 * while doing so. The AFS Redirector forwards the requests to
2916 * the AFS cache manager while indicating to Windows that the page
2917 * is not yet available. A polling operation will then ensue with
2918 * the AFS Redirector issuing a RDR_RequestFileExtentsXXX call for
2919 * each poll attempt. As each request is received and processed
2920 * by a separate worker thread in the service, this can lead to
2921 * contention by multiple threads attempting to claim the same
2922 * cm_buf_t objects. Therefore, it is important that
2924 * (a) the service avoid processing more than one overlapping
2925 * extent request at a time
2926 * (b) background daemon processing be used to avoid blocking
2929 * Beginning with the 20091122 build of the redirector, the redirector
2930 * will not issue an additional RDR_RequestFileExtentsXXX call for
2931 * each poll request. Instead, afsd_service is required to track
2932 * the requests and return them to the redirector or fail the
2933 * portions of the request that cannot be satisfied.
2935 * The request processing returns any extents that can be returned
2936 * immediately to the redirector. The rest of the requested range(s)
2937 * are queued as background operations using RDR_BkgFetch().
2940 /* do the background fetch. */
2942 RDR_BkgFetch(cm_scache_t *scp, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4,
2943 cm_user_t *userp, cm_req_t *reqp)
2949 osi_hyper_t fetched;
2950 osi_hyper_t tblocksize;
2953 cm_buf_t *bufp = NULL;
2954 DWORD dwResultBufferLength;
2955 AFSSetFileExtentsCB *pResultCB;
2959 int reportErrorToRedir = 0;
2960 int force_retry = 0;
2962 FileId.Cell = scp->fid.cell;
2963 FileId.Volume = scp->fid.volume;
2964 FileId.Vnode = scp->fid.vnode;
2965 FileId.Unique = scp->fid.unique;
2966 FileId.Hash = scp->fid.hash;
2968 if ((GetTickCount() - reqp->startTime) / 1000 > HardDeadtimeout * 5) {
2969 RDR_SetFileStatus( &scp->fid, &userp->authgroup, STATUS_IO_TIMEOUT);
2973 fetched.LowPart = 0;
2974 fetched.HighPart = 0;
2975 tblocksize = ConvertLongToLargeInteger(cm_data.buf_blockSize);
2978 length.LowPart = p3;
2979 length.HighPart = p4;
2981 end = LargeIntegerAdd(base, length);
2983 osi_Log5(afsd_logp, "Starting BKG Fetch scp 0x%p offset 0x%x:%x length 0x%x:%x",
2984 scp, p2, p1, p4, p3);
2987 * Make sure we have a callback.
2988 * This is necessary so that we can return access denied
2989 * if a callback cannot be granted.
2991 lock_ObtainWrite(&scp->rw);
2992 code = cm_SyncOp(scp, NULL, userp, reqp, PRSFS_READ,
2993 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2995 lock_ReleaseWrite(&scp->rw);
2996 osi_Log2(afsd_logp, "RDR_BkgFetch cm_SyncOp failure scp=0x%p code=0x%x",
2998 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
2999 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3002 lock_ReleaseWrite(&scp->rw);
3004 dwResultBufferLength = (DWORD)(sizeof( AFSSetFileExtentsCB) + sizeof( AFSSetFileExtentsCB) * (length.QuadPart / cm_data.blockSize + 1));
3005 pResultCB = (AFSSetFileExtentsCB *)malloc( dwResultBufferLength );
3007 return CM_ERROR_RETRY;
3009 memset( pResultCB, '\0', dwResultBufferLength );
3010 pResultCB->FileId = FileId;
3012 for ( code = 0, offset = base;
3013 code == 0 && LargeIntegerLessThan(offset, end);
3014 offset = LargeIntegerAdd(offset, tblocksize) )
3016 int bBufRelease = TRUE;
3019 lock_ReleaseWrite(&scp->rw);
3023 code = buf_Get(scp, &offset, reqp, &bufp);
3026 * any error from buf_Get() is non-fatal.
3027 * we need to re-queue this extent fetch.
3034 lock_ObtainWrite(&scp->rw);
3038 code = cm_GetBuffer(scp, bufp, NULL, userp, reqp);
3040 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3041 #ifdef VALIDATE_CHECK_SUM
3047 if (bufp->flags & CM_BUF_DIRTY)
3048 cm_BufWrite(scp, &bufp->offset, cm_data.buf_blockSize, CM_BUF_WRITE_SCP_LOCKED, userp, reqp);
3050 lock_ObtainWrite(&buf_globalLock);
3051 if (!(bufp->flags & CM_BUF_DIRTY) &&
3052 bufp->cmFlags == 0 &&
3053 !(bufp->qFlags & CM_BUF_QREDIR)) {
3054 buf_InsertToRedirQueue(scp, bufp);
3055 lock_ReleaseWrite(&buf_globalLock);
3057 #ifdef VALIDATE_CHECK_SUM
3058 buf_ComputeCheckSum(bufp);
3060 pResultCB->FileExtents[count].Flags = 0;
3061 pResultCB->FileExtents[count].FileOffset.QuadPart = bufp->offset.QuadPart;
3062 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3063 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3065 fetched = LargeIntegerAdd(fetched, tblocksize);
3066 bBufRelease = FALSE;
3068 #ifdef VALIDATE_CHECK_SUM
3070 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3071 snprintf( dbgstr, 1024,
3072 "RDR_BkgFetch md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3074 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3075 pResultCB->FileExtents[count].FileOffset.HighPart,
3076 pResultCB->FileExtents[count].FileOffset.LowPart,
3077 pResultCB->FileExtents[count].CacheOffset.HighPart,
3078 pResultCB->FileExtents[count].CacheOffset.LowPart);
3079 OutputDebugStringA( dbgstr);
3082 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3083 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3085 lock_ReleaseWrite(&buf_globalLock);
3086 if ((bufp->cmFlags != 0) || (bufp->flags & CM_BUF_DIRTY)) {
3087 /* An I/O operation is already in progress */
3089 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",
3090 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3092 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3093 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3097 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3098 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3102 * depending on what the error from cm_GetBuffer is
3103 * it may or may not be fatal. Only return fatal errors.
3104 * Re-queue a request for others.
3106 osi_Log5(afsd_logp, "RDR_BkgFetch Extent2FS FAILURE bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x code 0x%x",
3107 bufp, offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize, code);
3109 case CM_ERROR_NOACCESS:
3110 case CM_ERROR_NOSUCHFILE:
3111 case CM_ERROR_NOSUCHPATH:
3112 case CM_ERROR_NOSUCHVOLUME:
3113 case CM_ERROR_NOSUCHCELL:
3114 case CM_ERROR_INVAL:
3115 case CM_ERROR_BADFD:
3116 case CM_ERROR_CLOCKSKEW:
3118 case CM_ERROR_QUOTA:
3119 case CM_ERROR_LOCK_CONFLICT:
3121 * these are fatal errors. deliver what we can
3124 reportErrorToRedir = 1;
3128 * non-fatal errors. re-queue the exent
3130 code = CM_ERROR_RETRY;
3140 lock_ObtainWrite(&scp->rw);
3144 /* wakeup anyone who is waiting */
3145 if (scp->flags & CM_SCACHEFLAG_WAITING) {
3146 osi_Log1(afsd_logp, "RDR Bkg Fetch Waking scp 0x%p", scp);
3147 osi_Wakeup((LONG_PTR) &scp->flags);
3149 lock_ReleaseWrite(&scp->rw);
3152 pResultCB->ExtentCount = count;
3153 RDR_SetFileExtents( pResultCB, dwResultBufferLength);
3157 if (reportErrorToRedir) {
3158 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
3159 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3162 osi_Log4(afsd_logp, "Ending BKG Fetch scp 0x%p code 0x%x fetched 0x%x:%x",
3163 scp, code, fetched.HighPart, fetched.LowPart);
3165 return force_retry ? CM_ERROR_RETRY : code;
3170 RDR_RequestFileExtentsAsync( IN cm_user_t *userp,
3171 IN AFSFileID FileId,
3172 IN AFSRequestExtentsCB *RequestExtentsCB,
3174 IN OUT DWORD * ResultBufferLength,
3175 IN OUT AFSSetFileExtentsCB **ResultCB)
3177 AFSSetFileExtentsCB *pResultCB = NULL;
3181 cm_scache_t *scp = NULL;
3184 afs_uint32 code = 0;
3186 LARGE_INTEGER ByteOffset, BeginOffset, EndOffset, QueueOffset;
3187 afs_uint32 QueueLength;
3189 BOOLEAN bBufRelease = TRUE;
3193 req.flags |= CM_REQ_WOW64;
3194 req.flags |= CM_REQ_NORETRY;
3196 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3197 FileId.Cell, FileId.Volume,
3198 FileId.Vnode, FileId.Unique);
3199 osi_Log4(afsd_logp, "... Flags 0x%x ByteOffset 0x%x:%x Length 0x%x",
3200 RequestExtentsCB->Flags,
3201 RequestExtentsCB->ByteOffset.HighPart, RequestExtentsCB->ByteOffset.LowPart,
3202 RequestExtentsCB->Length);
3203 Length = sizeof( AFSSetFileExtentsCB) + sizeof( AFSFileExtentCB) * (RequestExtentsCB->Length / cm_data.blockSize + 1);
3205 pResultCB = *ResultCB = (AFSSetFileExtentsCB *)malloc( Length );
3206 if (*ResultCB == NULL) {
3207 *ResultBufferLength = 0;
3210 *ResultBufferLength = Length;
3212 memset( pResultCB, '\0', Length );
3213 pResultCB->FileId = FileId;
3215 Fid.cell = FileId.Cell;
3216 Fid.volume = FileId.Volume;
3217 Fid.vnode = FileId.Vnode;
3218 Fid.unique = FileId.Unique;
3219 Fid.hash = FileId.Hash;
3221 code = cm_GetSCache(&Fid, &scp, userp, &req);
3223 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync cm_GetSCache FID failure code=0x%x",
3225 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3230 * Make sure we have a callback.
3231 * This is necessary so that we can return access denied
3232 * if a callback cannot be granted.
3234 lock_ObtainWrite(&scp->rw);
3235 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_READ,
3236 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3237 lock_ReleaseWrite(&scp->rw);
3239 cm_ReleaseSCache(scp);
3240 osi_Log2(afsd_logp, "RDR_RequestFileExtentsAsync cm_SyncOp failure scp=0x%p code=0x%x",
3242 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3243 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3247 /* Allocate the extents from the buffer package */
3249 ByteOffset = BeginOffset = RequestExtentsCB->ByteOffset,
3250 EndOffset.QuadPart = ByteOffset.QuadPart + RequestExtentsCB->Length;
3251 code == 0 && ByteOffset.QuadPart < EndOffset.QuadPart;
3252 ByteOffset.QuadPart += cm_data.blockSize)
3254 BOOL bHaveBuffer = FALSE;
3257 thyper.QuadPart = ByteOffset.QuadPart;
3259 code = buf_Get(scp, &thyper, &req, &bufp);
3261 lock_ObtainMutex(&bufp->mx);
3264 if (bufp->qFlags & CM_BUF_QREDIR) {
3266 } else if (bufp->flags & CM_BUF_DIRTY) {
3267 bHaveBuffer = FALSE;
3269 code = buf_CleanAsyncLocked(scp, bufp, &req, 0, NULL);
3274 case CM_ERROR_RETRY:
3275 /* Couldn't flush it, obtain it asynchronously so we don't block the thread. */
3276 bHaveBuffer = FALSE;
3280 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3281 RDR_SetFileStatus(&FileId, &userp->authgroup, status);
3282 bHaveBuffer = FALSE;
3287 osi_hyper_t minLength; /* effective end of file */
3289 lock_ObtainRead(&scp->rw);
3290 bHaveBuffer = cm_HaveBuffer(scp, bufp, TRUE);
3292 if (LargeIntegerGreaterThan(scp->length, scp->serverLength))
3293 minLength = scp->serverLength;
3295 minLength = scp->length;
3298 LargeIntegerGreaterThanOrEqualTo(bufp->offset, minLength)) {
3299 memset(bufp->datap, 0, cm_data.buf_blockSize);
3300 bufp->dataVersion = scp->dataVersion;
3303 else if ((RequestExtentsCB->Flags & AFS_EXTENT_FLAG_CLEAN) &&
3304 ByteOffset.QuadPart <= bufp->offset.QuadPart &&
3305 EndOffset.QuadPart >= bufp->offset.QuadPart + cm_data.blockSize)
3307 memset(bufp->datap, 0, cm_data.blockSize);
3308 bufp->dataVersion = scp->dataVersion;
3309 buf_SetDirty(bufp, &req, 0, cm_data.blockSize, userp);
3312 lock_ReleaseRead(&scp->rw);
3316 * if this buffer is already up to date, skip it.
3319 if (ByteOffset.QuadPart == BeginOffset.QuadPart) {
3320 BeginOffset.QuadPart += cm_data.blockSize;
3322 QueueLength = (afs_uint32)(ByteOffset.QuadPart - BeginOffset.QuadPart);
3323 QueueOffset = BeginOffset;
3324 BeginOffset = ByteOffset;
3327 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3328 #ifdef VALIDATE_CHECK_SUM
3334 lock_ObtainWrite(&buf_globalLock);
3335 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3336 buf_InsertToRedirQueue(scp, bufp);
3337 lock_ReleaseWrite(&buf_globalLock);
3339 #ifdef VALIDATE_CHECK_SUM
3340 buf_ComputeCheckSum(bufp);
3342 /* we already have the buffer, return it now */
3343 pResultCB->FileExtents[count].Flags = 0;
3344 pResultCB->FileExtents[count].FileOffset = ByteOffset;
3345 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3346 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3349 bBufRelease = FALSE;
3351 #ifdef VALIDATE_CHECK_SUM
3353 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3354 snprintf( dbgstr, 1024,
3355 "RDR_RequestFileExtentsAsync md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3357 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3358 pResultCB->FileExtents[count].FileOffset.HighPart,
3359 pResultCB->FileExtents[count].FileOffset.LowPart,
3360 pResultCB->FileExtents[count].CacheOffset.HighPart,
3361 pResultCB->FileExtents[count].CacheOffset.LowPart);
3362 OutputDebugStringA( dbgstr);
3365 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3366 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3368 lock_ReleaseWrite(&buf_globalLock);
3373 * The service is not handing off the extent to the redirector in this pass.
3374 * However, we know the buffer is in recent use so move the buffer to the
3375 * front of the queue
3377 lock_ObtainWrite(&buf_globalLock);
3378 buf_MoveToHeadOfRedirQueue(scp, bufp);
3379 lock_ReleaseWrite(&buf_globalLock);
3381 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3382 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3386 lock_ReleaseMutex(&bufp->mx);
3391 cm_QueueBKGRequest(scp, RDR_BkgFetch, QueueOffset.LowPart, QueueOffset.HighPart,
3392 QueueLength, 0, userp, &req);
3393 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3394 QueueOffset.HighPart, QueueOffset.LowPart, QueueLength);
3397 /* No error from buf_Get() can be fatal */
3398 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync buf_Get FAILURE offset 0x%x:%x code 0x%x",
3399 BeginOffset.HighPart, BeginOffset.LowPart, code);
3403 if (BeginOffset.QuadPart != EndOffset.QuadPart) {
3404 afs_uint32 length = (afs_uint32)(EndOffset.QuadPart - BeginOffset.QuadPart);
3406 cm_QueueBKGRequest(scp, RDR_BkgFetch, BeginOffset.LowPart, BeginOffset.HighPart,
3407 length, 0, userp, &req);
3408 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3409 BeginOffset.HighPart, BeginOffset.LowPart, length);
3411 cm_ReleaseSCache(scp);
3413 (*ResultCB)->ExtentCount = count;
3414 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync replying with 0x%x extent records", count);
3419 * When processing an extent release the extents must be accepted back by
3420 * the service even if there is an error condition returned to the redirector.
3421 * For example, there may no longer be a callback present or the file may
3422 * have been deleted on the file server. Regardless, the extents must be
3423 * put back into the pool.
3426 RDR_ReleaseFileExtents( IN cm_user_t *userp,
3427 IN AFSFileID FileId,
3428 IN AFSReleaseExtentsCB *ReleaseExtentsCB,
3430 IN DWORD ResultBufferLength,
3431 IN OUT AFSCommResult **ResultCB)
3434 cm_scache_t *scp = NULL;
3444 #ifdef VALIDATE_CHECK_SUM
3445 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3452 req.flags |= CM_REQ_WOW64;
3454 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3455 FileId.Cell, FileId.Volume,
3456 FileId.Vnode, FileId.Unique);
3458 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
3464 sizeof( AFSCommResult));
3466 /* Process the release */
3467 Fid.cell = FileId.Cell;
3468 Fid.volume = FileId.Volume;
3469 Fid.vnode = FileId.Vnode;
3470 Fid.unique = FileId.Unique;
3471 Fid.hash = FileId.Hash;
3473 code = cm_GetSCache(&Fid, &scp, userp, &req);
3475 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3476 (*ResultCB)->ResultStatus = status;
3477 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents cm_GetSCache FID failure code=0x%x status=0x%x",
3482 * We do not stop processing as a result of being unable to find the cm_scache object.
3483 * If this occurs something really bad has happened since the cm_scache object must have
3484 * been recycled while extents were held by the redirector. However, we will be resilient
3485 * and carry on without it.
3487 if (scp && ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3490 memset(&setAttr, 0, sizeof(cm_attr_t));
3491 lock_ObtainWrite(&scp->rw);
3492 if (ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3494 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents new length fid vol 0x%x vno 0x%x length 0x%x:%x",
3495 scp->fid.volume, scp->fid.vnode,
3496 ReleaseExtentsCB->AllocationSize.HighPart,
3497 ReleaseExtentsCB->AllocationSize.LowPart);
3499 setAttr.mask |= CM_ATTRMASK_LENGTH;
3500 setAttr.length.LowPart = ReleaseExtentsCB->AllocationSize.LowPart;
3501 setAttr.length.HighPart = ReleaseExtentsCB->AllocationSize.HighPart;
3503 lock_ReleaseWrite(&scp->rw);
3505 code = cm_SetAttr(scp, &setAttr, userp, &req);
3508 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3509 AFSFileExtentCB * pExtent = &ReleaseExtentsCB->FileExtents[count];
3511 thyper.QuadPart = pExtent->FileOffset.QuadPart;
3513 bufp = buf_Find(&Fid, &thyper);
3515 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
3516 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3517 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3518 Fid.volume, Fid.vnode,
3519 pExtent->FileOffset.HighPart,
3520 pExtent->FileOffset.LowPart);
3521 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
3522 pExtent->CacheOffset.HighPart,
3523 pExtent->CacheOffset.LowPart);
3525 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3526 Fid.volume, Fid.vnode,
3527 pExtent->FileOffset.HighPart,
3528 pExtent->FileOffset.LowPart);
3529 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
3530 pExtent->CacheOffset.HighPart,
3531 pExtent->CacheOffset.LowPart);
3537 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
3538 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3539 Fid.volume, Fid.vnode,
3540 pExtent->FileOffset.HighPart,
3541 pExtent->FileOffset.LowPart);
3542 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
3543 pExtent->CacheOffset.HighPart,
3544 pExtent->CacheOffset.LowPart);
3546 /* Move the buffer to the front of the queue */
3547 lock_ObtainWrite(&buf_globalLock);
3548 buf_MoveToHeadOfRedirQueue(scp, bufp);
3549 lock_ReleaseWrite(&buf_globalLock);
3554 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
3555 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3556 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x not held by file system",
3557 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
3558 pExtent->FileOffset.LowPart);
3559 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3560 pExtent->CacheOffset.HighPart,
3561 pExtent->CacheOffset.LowPart);
3563 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents bufp 0x%p vno 0x%x foffset 0x%x:%x",
3564 bufp, bufp->fid.vnode, pExtent->FileOffset.HighPart,
3565 pExtent->FileOffset.LowPart);
3566 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3567 pExtent->CacheOffset.HighPart,
3568 pExtent->CacheOffset.LowPart);
3570 if (pExtent->Flags || ReleaseExtentsCB->Flags) {
3571 lock_ObtainMutex(&bufp->mx);
3572 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
3573 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
3575 if (bufp->qFlags & CM_BUF_QREDIR) {
3576 lock_ObtainWrite(&buf_globalLock);
3577 if (bufp->qFlags & CM_BUF_QREDIR) {
3578 buf_RemoveFromRedirQueue(scp, bufp);
3579 buf_ReleaseLocked(bufp, TRUE);
3581 lock_ReleaseWrite(&buf_globalLock);
3584 snprintf( dbgstr, 1024,
3585 "RDR_ReleaseFileExtents releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3586 Fid.volume, Fid.vnode, Fid.unique,
3587 pExtent->FileOffset.HighPart,
3588 pExtent->FileOffset.LowPart,
3589 pExtent->CacheOffset.HighPart,
3590 pExtent->CacheOffset.LowPart);
3591 OutputDebugStringA( dbgstr);
3596 snprintf( dbgstr, 1024,
3597 "RDR_ReleaseFileExtents not releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3598 Fid.volume, Fid.vnode, Fid.unique,
3599 pExtent->FileOffset.HighPart,
3600 pExtent->FileOffset.LowPart,
3601 pExtent->CacheOffset.HighPart,
3602 pExtent->CacheOffset.LowPart);
3603 OutputDebugStringA( dbgstr);
3605 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
3606 Fid.volume, Fid.vnode,
3607 pExtent->FileOffset.HighPart,
3608 pExtent->FileOffset.LowPart);
3609 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3610 pExtent->CacheOffset.HighPart,
3611 pExtent->CacheOffset.LowPart);
3614 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
3615 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY) )
3617 #ifdef VALIDATE_CHECK_SUM
3619 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3623 * if the saved checksum matches the checksum of the current state of the buffer
3624 * then the buffer is the same as what was given to the kernel.
3626 if ( buf_ValidateCheckSum(bufp) ) {
3627 buf_ComputeCheckSum(bufp);
3629 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3632 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
3633 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3635 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3638 snprintf( dbgstr, 1024,
3639 "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",
3640 md5dbg, md5dbg2,md5dbg3,
3641 Fid.volume, Fid.vnode, Fid.unique,
3642 pExtent->FileOffset.HighPart,
3643 pExtent->FileOffset.LowPart,
3644 pExtent->CacheOffset.HighPart,
3645 pExtent->CacheOffset.LowPart);
3646 OutputDebugStringA( dbgstr);
3648 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
3649 Fid.volume, Fid.vnode,
3650 pExtent->FileOffset.HighPart,
3651 pExtent->FileOffset.LowPart);
3652 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3653 pExtent->CacheOffset.HighPart,
3654 pExtent->CacheOffset.LowPart);
3655 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3659 snprintf( dbgstr, 1024,
3660 "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",
3661 md5dbg, md5dbg2, md5dbg3,
3662 Fid.volume, Fid.vnode, Fid.unique,
3663 pExtent->FileOffset.HighPart,
3664 pExtent->FileOffset.LowPart,
3665 pExtent->CacheOffset.HighPart,
3666 pExtent->CacheOffset.LowPart);
3667 OutputDebugStringA( dbgstr);
3669 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3670 Fid.volume, Fid.vnode,
3671 pExtent->FileOffset.HighPart,
3672 pExtent->FileOffset.LowPart);
3673 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3674 pExtent->CacheOffset.HighPart,
3675 pExtent->CacheOffset.LowPart);
3679 snprintf( dbgstr, 1024,
3680 "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",
3681 Fid.volume, Fid.vnode, Fid.unique,
3682 pExtent->FileOffset.HighPart,
3683 pExtent->FileOffset.LowPart,
3684 pExtent->CacheOffset.HighPart,
3685 pExtent->CacheOffset.LowPart);
3686 OutputDebugStringA( dbgstr);
3688 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3689 Fid.volume, Fid.vnode,
3690 pExtent->FileOffset.HighPart,
3691 pExtent->FileOffset.LowPart);
3692 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3693 pExtent->CacheOffset.HighPart,
3694 pExtent->CacheOffset.LowPart);
3697 buf_ComputeCheckSum(bufp);
3699 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3701 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3702 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3704 snprintf( dbgstr, 1024,
3705 "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",
3706 md5dbg, md5dbg2,md5dbg3,
3707 Fid.volume, Fid.vnode, Fid.unique,
3708 pExtent->FileOffset.HighPart,
3709 pExtent->FileOffset.LowPart,
3710 pExtent->CacheOffset.HighPart,
3711 pExtent->CacheOffset.LowPart);
3712 OutputDebugStringA( dbgstr);
3714 snprintf( dbgstr, 1024,
3715 "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",
3716 md5dbg, md5dbg2,md5dbg3,
3717 Fid.volume, Fid.vnode, Fid.unique,
3718 pExtent->FileOffset.HighPart,
3719 pExtent->FileOffset.LowPart,
3720 pExtent->CacheOffset.HighPart,
3721 pExtent->CacheOffset.LowPart);
3722 OutputDebugStringA( dbgstr);
3725 snprintf( dbgstr, 1024,
3726 "RDR_ReleaseFileExtents dirty flag set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3727 Fid.volume, Fid.vnode, Fid.unique,
3728 pExtent->FileOffset.HighPart,
3729 pExtent->FileOffset.LowPart,
3730 pExtent->CacheOffset.HighPart,
3731 pExtent->CacheOffset.LowPart);
3732 OutputDebugStringA( dbgstr);
3735 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3738 #else /* !VALIDATE_CHECK_SUM */
3739 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3741 #endif /* VALIDATE_CHECK_SUM */
3743 #ifdef VALIDATE_CHECK_SUM
3746 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3748 if ( !buf_ValidateCheckSum(bufp) ) {
3749 buf_ComputeCheckSum(bufp);
3751 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3752 snprintf( dbgstr, 1024,
3753 "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",
3755 Fid.volume, Fid.vnode, Fid.unique,
3756 pExtent->FileOffset.HighPart,
3757 pExtent->FileOffset.LowPart,
3758 pExtent->CacheOffset.HighPart,
3759 pExtent->CacheOffset.LowPart);
3760 OutputDebugStringA( dbgstr);
3762 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set but extent has changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3763 Fid.volume, Fid.vnode,
3764 pExtent->FileOffset.HighPart,
3765 pExtent->FileOffset.LowPart);
3766 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3767 pExtent->CacheOffset.HighPart,
3768 pExtent->CacheOffset.LowPart);
3769 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3772 buf_ComputeCheckSum(bufp);
3774 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3775 snprintf( dbgstr, 1024,
3776 "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3777 Fid.volume, Fid.vnode, Fid.unique,
3778 pExtent->FileOffset.HighPart,
3779 pExtent->FileOffset.LowPart,
3780 pExtent->CacheOffset.HighPart,
3781 pExtent->CacheOffset.LowPart);
3782 OutputDebugStringA( dbgstr);
3784 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x foffset 0x%x:%x",
3785 Fid.volume, Fid.vnode,
3786 pExtent->FileOffset.HighPart,
3787 pExtent->FileOffset.LowPart);
3788 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3789 pExtent->CacheOffset.HighPart,
3790 pExtent->CacheOffset.LowPart);
3793 #endif /* VALIDATE_CHECK_SUM */
3794 lock_ReleaseMutex(&bufp->mx);
3799 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3802 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3803 if (wbp->datap == datap)
3808 snprintf( dbgstr, 1024,
3809 "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3810 Fid.volume, Fid.vnode, Fid.unique,
3811 pExtent->FileOffset.HighPart,
3812 pExtent->FileOffset.LowPart,
3813 pExtent->CacheOffset.HighPart,
3814 pExtent->CacheOffset.LowPart);
3815 OutputDebugStringA( dbgstr);
3817 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3818 Fid.volume, Fid.vnode,
3819 pExtent->FileOffset.HighPart,
3820 pExtent->FileOffset.LowPart);
3821 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3822 pExtent->CacheOffset.HighPart,
3823 pExtent->CacheOffset.LowPart);
3824 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3825 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3833 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3836 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3837 if (wbp->datap == datap)
3842 snprintf( dbgstr, 1024,
3843 "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3844 Fid.volume, Fid.vnode, Fid.unique,
3845 pExtent->FileOffset.HighPart,
3846 pExtent->FileOffset.LowPart,
3847 pExtent->CacheOffset.HighPart,
3848 pExtent->CacheOffset.LowPart);
3849 OutputDebugStringA( dbgstr);
3851 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3852 Fid.volume, Fid.vnode,
3853 pExtent->FileOffset.HighPart,
3854 pExtent->FileOffset.LowPart);
3855 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3856 pExtent->CacheOffset.HighPart,
3857 pExtent->CacheOffset.LowPart);
3858 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3859 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3864 if (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_FLUSH) {
3865 lock_ObtainWrite(&scp->rw);
3866 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3867 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3868 lock_ReleaseWrite(&scp->rw);
3870 code = cm_FSync(scp, userp, &req, FALSE);
3873 osi_hyper_t offset = {0,0};
3874 afs_uint32 length = 0;
3875 afs_uint32 rights = 0;
3877 lock_ObtainWrite(&scp->rw);
3878 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3879 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3880 lock_ReleaseWrite(&scp->rw);
3883 * there is at least one dirty extent on this file. queue up background store
3884 * requests for contiguous blocks
3886 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3887 if (ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart == offset.QuadPart + length &&
3888 length + cm_data.buf_blockSize <= cm_chunkSize)
3890 length += cm_data.buf_blockSize;
3892 if (!(offset.QuadPart == 0 && length == 0))
3893 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3894 length, 0, userp, &req);
3895 offset.QuadPart = ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart;
3896 length = cm_data.buf_blockSize;
3899 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3900 length, 0, userp, &req);
3903 cm_ReleaseSCache(scp);
3906 osi_Log5(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
3907 FileId.Cell, FileId.Volume,
3908 FileId.Vnode, FileId.Unique, released);
3909 if (code && code != CM_ERROR_WOULDBLOCK) {
3910 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3911 (*ResultCB)->ResultStatus = status;
3912 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents FAILURE code=0x%x status=0x%x",
3915 (*ResultCB)->ResultStatus = 0;
3916 osi_Log0(afsd_logp, "RDR_ReleaseFileExtents SUCCESS");
3918 (*ResultCB)->ResultBufferLength = 0;
3924 RDR_ProcessReleaseFileExtentsResult( IN AFSReleaseFileExtentsResultCB *ReleaseFileExtentsResultCB,
3925 IN DWORD ResultBufferLength)
3927 afs_uint32 code = 0;
3931 unsigned int fileno, extentno, total_extents = 0;
3932 AFSReleaseFileExtentsResultFileCB *pNextFileCB;
3934 #ifdef VALIDATE_CHECK_SUM
3935 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3941 for ( fileno = 0, pNextFileCB = &ReleaseFileExtentsResultCB->Files[0];
3942 fileno < ReleaseFileExtentsResultCB->FileCount;
3944 AFSReleaseFileExtentsResultFileCB *pFileCB = pNextFileCB;
3945 cm_user_t *userp = NULL;
3947 cm_scache_t * scp = NULL;
3952 userp = RDR_UserFromAuthGroup( &pFileCB->AuthGroup);
3954 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult %d.%d.%d.%d",
3955 pFileCB->FileId.Cell, pFileCB->FileId.Volume,
3956 pFileCB->FileId.Vnode, pFileCB->FileId.Unique);
3958 /* Process the release */
3959 Fid.cell = pFileCB->FileId.Cell;
3960 Fid.volume = pFileCB->FileId.Volume;
3961 Fid.vnode = pFileCB->FileId.Vnode;
3962 Fid.unique = pFileCB->FileId.Unique;
3963 Fid.hash = pFileCB->FileId.Hash;
3965 if (Fid.cell == 0) {
3966 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult Invalid FID %d.%d.%d.%d",
3967 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
3968 code = CM_ERROR_INVAL;
3972 code = cm_GetSCache(&Fid, &scp, userp, &req);
3974 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult cm_GetSCache FID failure code=0x%x",
3977 * A failure to find the cm_scache object cannot prevent the service
3978 * from accepting the extents back from the redirector.
3982 /* if the scp was not found, do not perform the length check */
3983 if (scp && (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart)) {
3986 memset(&setAttr, 0, sizeof(cm_attr_t));
3987 lock_ObtainWrite(&scp->rw);
3988 if (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3989 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult length change vol 0x%x vno 0x%x length 0x%x:%x",
3990 scp->fid.volume, scp->fid.vnode,
3991 pFileCB->AllocationSize.HighPart,
3992 pFileCB->AllocationSize.LowPart);
3993 setAttr.mask |= CM_ATTRMASK_LENGTH;
3994 setAttr.length.LowPart = pFileCB->AllocationSize.LowPart;
3995 setAttr.length.HighPart = pFileCB->AllocationSize.HighPart;
3997 lock_ReleaseWrite(&scp->rw);
3999 code = cm_SetAttr(scp, &setAttr, userp, &req);
4002 for ( extentno = 0; extentno < pFileCB->ExtentCount; total_extents++, extentno++ ) {
4003 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4005 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4007 bufp = buf_Find(&Fid, &thyper);
4009 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4010 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
4011 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4012 Fid.volume, Fid.vnode,
4013 pExtent->FileOffset.HighPart,
4014 pExtent->FileOffset.LowPart);
4015 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
4016 pExtent->CacheOffset.HighPart,
4017 pExtent->CacheOffset.LowPart);
4019 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4020 Fid.volume, Fid.vnode,
4021 pExtent->FileOffset.HighPart,
4022 pExtent->FileOffset.LowPart);
4023 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
4024 pExtent->CacheOffset.HighPart,
4025 pExtent->CacheOffset.LowPart);
4031 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
4032 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4033 Fid.volume, Fid.vnode,
4034 pExtent->FileOffset.HighPart,
4035 pExtent->FileOffset.LowPart);
4036 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
4037 pExtent->CacheOffset.HighPart,
4038 pExtent->CacheOffset.LowPart);
4040 /* Move the buffer to the front of the queue */
4041 lock_ObtainWrite(&buf_globalLock);
4042 buf_MoveToHeadOfRedirQueue(scp, bufp);
4043 lock_ReleaseWrite(&buf_globalLock);
4048 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
4049 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
4050 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4051 Fid.volume, Fid.vnode,
4052 pExtent->FileOffset.HighPart,
4053 pExtent->FileOffset.LowPart);
4054 osi_Log2(afsd_logp, "... coffset 0x%x:%x not held by file system",
4055 pExtent->CacheOffset.HighPart,
4056 pExtent->CacheOffset.LowPart);
4058 snprintf(dbgstr, 1024,
4059 "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",
4060 ReleaseFileExtentsResultCB->Flags, pExtent->Flags,
4061 Fid.volume, Fid.vnode, Fid.unique,
4062 pExtent->FileOffset.HighPart,
4063 pExtent->FileOffset.LowPart,
4064 pExtent->CacheOffset.HighPart,
4065 pExtent->CacheOffset.LowPart);
4066 OutputDebugStringA( dbgstr);
4069 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4070 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4071 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4073 if (pExtent->Flags || ReleaseFileExtentsResultCB->Flags) {
4074 lock_ObtainMutex(&bufp->mx);
4075 if ( (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
4076 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
4078 if (bufp->qFlags & CM_BUF_QREDIR) {
4079 lock_ObtainWrite(&buf_globalLock);
4080 if (bufp->qFlags & CM_BUF_QREDIR) {
4081 buf_RemoveFromRedirQueue(scp, bufp);
4082 buf_ReleaseLocked(bufp, TRUE);
4084 lock_ReleaseWrite(&buf_globalLock);
4088 snprintf(dbgstr, 1024,
4089 "RDR_ProcessReleaseFileExtentsResult extent released: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4090 Fid.volume, Fid.vnode, Fid.unique,
4091 pExtent->FileOffset.HighPart,
4092 pExtent->FileOffset.LowPart,
4093 pExtent->CacheOffset.HighPart,
4094 pExtent->CacheOffset.LowPart);
4095 OutputDebugStringA( dbgstr);
4100 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
4101 Fid.volume, Fid.vnode,
4102 pExtent->FileOffset.HighPart,
4103 pExtent->FileOffset.LowPart);
4104 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4105 pExtent->CacheOffset.HighPart,
4106 pExtent->CacheOffset.LowPart);
4108 snprintf(dbgstr, 1024,
4109 "RDR_ProcessReleaseFileExtentsResult not released! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4110 Fid.volume, Fid.vnode, Fid.unique,
4111 pExtent->FileOffset.HighPart,
4112 pExtent->FileOffset.LowPart,
4113 pExtent->CacheOffset.HighPart,
4114 pExtent->CacheOffset.LowPart);
4115 OutputDebugStringA( dbgstr);
4119 if ( (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
4120 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY) )
4122 #ifdef VALIDATE_CHECK_SUM
4123 if ( buf_ValidateCheckSum(bufp) ) {
4125 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4126 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4127 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
4129 buf_ComputeCheckSum(bufp);
4131 HexCheckSum(md5dbg3, sizeof(md5dbg), bufp->md5cksum);
4133 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4135 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
4138 snprintf(dbgstr, 1024,
4139 "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",
4141 Fid.volume, Fid.vnode, Fid.unique,
4142 pExtent->FileOffset.HighPart,
4143 pExtent->FileOffset.LowPart,
4144 pExtent->CacheOffset.HighPart,
4145 pExtent->CacheOffset.LowPart);
4146 OutputDebugStringA( dbgstr);
4149 "RDR_ProcessReleaseFileExtentsResult dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
4150 Fid.volume, Fid.vnode,
4151 pExtent->FileOffset.HighPart,
4152 pExtent->FileOffset.LowPart);
4154 "... coffset 0x%x:%x",
4155 pExtent->CacheOffset.HighPart,
4156 pExtent->CacheOffset.LowPart);
4158 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4162 snprintf(dbgstr, 1024,
4163 "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",
4164 md5dbg, md5dbg2, md5dbg3,
4165 Fid.volume, Fid.vnode, Fid.unique,
4166 pExtent->FileOffset.HighPart,
4167 pExtent->FileOffset.LowPart,
4168 pExtent->CacheOffset.HighPart,
4169 pExtent->CacheOffset.LowPart);
4170 OutputDebugStringA( dbgstr);
4173 "RDR_ProcessReleaseFileExtentsResult dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
4174 Fid.volume, Fid.vnode,
4175 pExtent->FileOffset.HighPart,
4176 pExtent->FileOffset.LowPart);
4178 "... coffset 0x%x:%x",
4179 pExtent->CacheOffset.HighPart,
4180 pExtent->CacheOffset.LowPart);
4184 #else /* !VALIDATE_CHECK_SUM */
4185 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4188 snprintf(dbgstr, 1024,
4189 "RDR_ProcessReleaseFileExtentsResult dirty! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4190 Fid.volume, Fid.vnode, Fid.unique,
4191 pExtent->FileOffset.HighPart,
4192 pExtent->FileOffset.LowPart,
4193 pExtent->CacheOffset.HighPart,
4194 pExtent->CacheOffset.LowPart);
4195 OutputDebugStringA( dbgstr);
4197 #endif /* VALIDATE_CHECK_SUM */
4199 #ifdef VALIDATE_CHECK_SUM
4202 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4204 if ( !buf_ValidateCheckSum(bufp) ) {
4205 buf_ComputeCheckSum(bufp);
4207 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4208 snprintf(dbgstr, 1024,
4209 "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",
4211 Fid.volume, Fid.vnode, Fid.unique,
4212 pExtent->FileOffset.HighPart,
4213 pExtent->FileOffset.LowPart,
4214 pExtent->CacheOffset.HighPart,
4215 pExtent->CacheOffset.LowPart);
4216 OutputDebugStringA( dbgstr);
4218 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult dirty flag NOT set but extent has changed! vol 0x%x vno 0x%x foffset 0x%x:%x",
4219 Fid.volume, Fid.vnode,
4220 pExtent->FileOffset.HighPart,
4221 pExtent->FileOffset.LowPart);
4222 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4223 pExtent->CacheOffset.HighPart,
4224 pExtent->CacheOffset.LowPart);
4228 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4231 buf_ComputeCheckSum(bufp);
4233 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4234 snprintf(dbgstr, 1024,
4235 "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",
4237 Fid.volume, Fid.vnode, Fid.unique,
4238 pExtent->FileOffset.HighPart,
4239 pExtent->FileOffset.LowPart,
4240 pExtent->CacheOffset.HighPart,
4241 pExtent->CacheOffset.LowPart);
4242 OutputDebugStringA( dbgstr);
4246 #endif /* VALIDATE_CHECK_SUM */
4247 lock_ReleaseMutex(&bufp->mx);
4251 /* CacheOffset doesn't match bufp->datap */
4252 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
4255 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
4256 if (wbp->datap == datap)
4261 snprintf(dbgstr, 1024,
4262 "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",
4263 Fid.volume, Fid.vnode, Fid.unique,
4264 pExtent->FileOffset.HighPart,
4265 pExtent->FileOffset.LowPart,
4266 pExtent->CacheOffset.HighPart,
4267 pExtent->CacheOffset.LowPart,
4269 OutputDebugStringA( dbgstr);
4271 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4272 Fid.volume, Fid.vnode,
4273 pExtent->FileOffset.HighPart,
4274 pExtent->FileOffset.LowPart);
4275 osi_Log3(afsd_logp, "... coffset 0x%x:%x flags 0x%x",
4276 pExtent->CacheOffset.HighPart,
4277 pExtent->CacheOffset.LowPart,
4280 osi_Log5(afsd_logp, "... coffset belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
4281 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
4283 osi_Log0(afsd_logp, "... coffset cannot be found");
4290 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4291 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4292 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
4293 pExtent->FileOffset.LowPart);
4294 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; cm_buf not found -- recycled?",
4295 pExtent->CacheOffset.HighPart,
4296 pExtent->CacheOffset.LowPart);
4302 snprintf(dbgstr, 1024,
4303 "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4304 Fid.volume, Fid.vnode, Fid.unique,
4305 pExtent->FileOffset.HighPart,
4306 pExtent->FileOffset.LowPart,
4307 pExtent->CacheOffset.HighPart,
4308 pExtent->CacheOffset.LowPart);
4309 OutputDebugStringA( dbgstr);
4311 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x foffset 0x%x:%x",
4312 Fid.volume, Fid.vnode,
4313 pExtent->FileOffset.HighPart,
4314 pExtent->FileOffset.LowPart);
4315 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4316 pExtent->CacheOffset.HighPart,
4317 pExtent->CacheOffset.LowPart);
4322 osi_hyper_t offset = {0,0};
4323 afs_uint32 length = 0;
4326 * there is at least one dirty extent on this file. queue up background store
4327 * requests for contiguous blocks
4329 for ( extentno = 0; extentno < pFileCB->ExtentCount; extentno++ ) {
4330 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4331 if (pExtent->FileOffset.QuadPart == offset.QuadPart + length &&
4332 length < cm_chunkSize) {
4333 length += cm_data.buf_blockSize;
4335 if (!(offset.QuadPart == 0 && length == 0))
4336 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4337 length, 0, userp, &req);
4338 offset.QuadPart = pExtent->FileOffset.QuadPart;
4339 length = cm_data.buf_blockSize;
4342 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4343 length, 0, userp, &req);
4346 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
4347 Fid.cell, Fid.volume, Fid.vnode, Fid.unique, released);
4351 cm_ReleaseUser(userp);
4353 cm_ReleaseSCache(scp);
4355 p = (char *)pFileCB;
4356 p += sizeof(AFSReleaseFileExtentsResultFileCB);
4357 p += sizeof(AFSFileExtentCB) * (pFileCB->ExtentCount - 1);
4358 pNextFileCB = (AFSReleaseFileExtentsResultFileCB *)p;
4361 if (total_extents == 0) {
4362 osi_Log0(afsd_logp, "RDR_ProcessReleaseFileExtentsResult is empty");
4363 code = CM_ERROR_RETRY;
4367 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult FAILURE code=0x%x", code);
4369 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult DONE code=0x%x", code);
4375 RDR_ReleaseFailedSetFileExtents( IN cm_user_t *userp,
4376 IN AFSSetFileExtentsCB *SetFileExtentsResultCB,
4377 IN DWORD ResultBufferLength)
4379 afs_uint32 code = 0;
4381 unsigned int extentno;
4383 cm_scache_t * scp = NULL;
4388 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFileExtents %d.%d.%d.%d",
4389 SetFileExtentsResultCB->FileId.Cell, SetFileExtentsResultCB->FileId.Volume,
4390 SetFileExtentsResultCB->FileId.Vnode, SetFileExtentsResultCB->FileId.Unique);
4392 /* Process the release */
4393 Fid.cell = SetFileExtentsResultCB->FileId.Cell;
4394 Fid.volume = SetFileExtentsResultCB->FileId.Volume;
4395 Fid.vnode = SetFileExtentsResultCB->FileId.Vnode;
4396 Fid.unique = SetFileExtentsResultCB->FileId.Unique;
4397 Fid.hash = SetFileExtentsResultCB->FileId.Hash;
4399 if (Fid.cell == 0) {
4400 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFile Invalid FID %d.%d.%d.%d",
4401 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
4402 code = CM_ERROR_INVAL;
4406 code = cm_GetSCache(&Fid, &scp, userp, &req);
4408 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents cm_GetSCache FID failure code=0x%x",
4410 /* Failure to find the cm_scache object cannot block return of the extents */
4413 for ( extentno = 0; extentno < SetFileExtentsResultCB->ExtentCount; extentno++ ) {
4416 AFSFileExtentCB *pExtent = &SetFileExtentsResultCB->FileExtents[extentno];
4418 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4420 bufp = buf_Find(&Fid, &thyper);
4422 osi_Log5(afsd_logp, "RDR_ReleaseFailedSetFileExtents bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4423 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4424 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4426 lock_ObtainMutex(&bufp->mx);
4427 if (bufp->qFlags & CM_BUF_QREDIR) {
4428 lock_ObtainWrite(&buf_globalLock);
4429 if (bufp->qFlags & CM_BUF_QREDIR) {
4430 buf_RemoveFromRedirQueue(scp, bufp);
4431 buf_ReleaseLocked(bufp, TRUE);
4433 lock_ReleaseWrite(&buf_globalLock);
4435 lock_ReleaseMutex(&bufp->mx);
4442 cm_ReleaseUser(userp);
4444 cm_ReleaseSCache(scp);
4446 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents DONE code=0x%x", code);
4451 RDR_PioctlOpen( IN cm_user_t *userp,
4452 IN AFSFileID ParentId,
4453 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4455 IN DWORD ResultBufferLength,
4456 IN OUT AFSCommResult **ResultCB)
4461 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4467 sizeof( AFSCommResult));
4469 /* Get the active directory */
4470 ParentFid.cell = ParentId.Cell;
4471 ParentFid.volume = ParentId.Volume;
4472 ParentFid.vnode = ParentId.Vnode;
4473 ParentFid.unique = ParentId.Unique;
4474 ParentFid.hash = ParentId.Hash;
4476 /* Get the root directory */
4477 RootFid.cell = pPioctlCB->RootId.Cell;
4478 RootFid.volume = pPioctlCB->RootId.Volume;
4479 RootFid.vnode = pPioctlCB->RootId.Vnode;
4480 RootFid.unique = pPioctlCB->RootId.Unique;
4481 RootFid.hash = pPioctlCB->RootId.Hash;
4483 /* Create the pioctl index */
4484 RDR_SetupIoctl(pPioctlCB->RequestId, &ParentFid, &RootFid, userp);
4491 RDR_PioctlClose( IN cm_user_t *userp,
4492 IN AFSFileID ParentId,
4493 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4495 IN DWORD ResultBufferLength,
4496 IN OUT AFSCommResult **ResultCB)
4498 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4504 sizeof( AFSCommResult));
4506 /* Cleanup the pioctl index */
4507 RDR_CleanupIoctl(pPioctlCB->RequestId);
4514 RDR_PioctlWrite( IN cm_user_t *userp,
4515 IN AFSFileID ParentId,
4516 IN AFSPIOCtlIORequestCB *pPioctlCB,
4518 IN DWORD ResultBufferLength,
4519 IN OUT AFSCommResult **ResultCB)
4521 AFSPIOCtlIOResultCB *pResultCB;
4522 cm_scache_t *dscp = NULL;
4529 req.flags |= CM_REQ_WOW64;
4531 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4537 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4539 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4541 code = RDR_IoctlWrite(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer, &req);
4543 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4544 (*ResultCB)->ResultStatus = status;
4548 pResultCB->BytesProcessed = pPioctlCB->BufferLength;
4549 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4553 RDR_PioctlRead( IN cm_user_t *userp,
4554 IN AFSFileID ParentId,
4555 IN AFSPIOCtlIORequestCB *pPioctlCB,
4557 IN BOOL bIsLocalSystem,
4558 IN DWORD ResultBufferLength,
4559 IN OUT AFSCommResult **ResultCB)
4561 AFSPIOCtlIOResultCB *pResultCB;
4562 cm_scache_t *dscp = NULL;
4566 afs_uint32 pflags = (bIsLocalSystem ? AFSCALL_FLAG_LOCAL_SYSTEM : 0);
4570 req.flags |= CM_REQ_WOW64;
4572 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4578 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4580 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4582 code = RDR_IoctlRead(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer,
4583 &pResultCB->BytesProcessed, &req, pflags);
4585 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4586 (*ResultCB)->ResultStatus = status;
4590 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4594 RDR_ByteRangeLockSync( IN cm_user_t *userp,
4595 IN AFSFileID FileId,
4596 IN AFSByteRangeLockRequestCB *pBRLRequestCB,
4598 IN DWORD ResultBufferLength,
4599 IN OUT AFSCommResult **ResultCB)
4601 AFSByteRangeLockResultCB *pResultCB = NULL;
4602 LARGE_INTEGER ProcessId;
4604 cm_scache_t *scp = NULL;
4612 ProcessId.QuadPart = pBRLRequestCB->ProcessId;
4616 req.flags |= CM_REQ_WOW64;
4618 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4619 FileId.Cell, FileId.Volume,
4620 FileId.Vnode, FileId.Unique);
4621 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4622 ProcessId.HighPart, ProcessId.LowPart);
4624 Length = sizeof( AFSByteRangeLockResultCB) + ((pBRLRequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4625 if (Length > ResultBufferLength) {
4626 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4629 memset( *ResultCB, 0, sizeof(AFSCommResult));
4630 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4634 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4637 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4638 (*ResultCB)->ResultBufferLength = Length;
4640 pResultCB = (AFSByteRangeLockResultCB *)(*ResultCB)->ResultData;
4641 pResultCB->FileId = FileId;
4642 pResultCB->Count = pBRLRequestCB->Count;
4644 /* Allocate the extents from the buffer package */
4645 Fid.cell = FileId.Cell;
4646 Fid.volume = FileId.Volume;
4647 Fid.vnode = FileId.Vnode;
4648 Fid.unique = FileId.Unique;
4649 Fid.hash = FileId.Hash;
4651 code = cm_GetSCache(&Fid, &scp, userp, &req);
4653 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4654 (*ResultCB)->ResultStatus = status;
4655 (*ResultCB)->ResultBufferLength = 0;
4656 osi_Log2(afsd_logp, "RDR_ByteRangeLockSync cm_GetSCache FID failure code=0x%x status=0x%x",
4661 lock_ObtainWrite(&scp->rw);
4663 /* start by looking up the file's end */
4664 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4665 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4667 lock_ReleaseWrite(&scp->rw);
4668 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4669 (*ResultCB)->ResultStatus = status;
4670 (*ResultCB)->ResultBufferLength = 0;
4671 osi_Log3(afsd_logp, "RDR_ByteRangeLockSync cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4676 /* the scp is now locked and current */
4677 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4679 for ( i=0; i<pBRLRequestCB->Count; i++ ) {
4680 pResultCB->Result[i].LockType = pBRLRequestCB->Request[i].LockType;
4681 pResultCB->Result[i].Offset = pBRLRequestCB->Request[i].Offset;
4682 pResultCB->Result[i].Length = pBRLRequestCB->Request[i].Length;
4685 pBRLRequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4686 pBRLRequestCB->Request[i].Offset,
4687 pBRLRequestCB->Request[i].Length,
4688 key, 0, userp, &req, NULL);
4691 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4693 pBRLRequestCB->Request[i].LockType,
4694 pBRLRequestCB->Request[i].Offset.HighPart,
4695 pBRLRequestCB->Request[i].Offset.LowPart);
4696 osi_Log2(afsd_logp, "... length 0x%x:%x",
4697 pBRLRequestCB->Request[i].Length.HighPart,
4698 pBRLRequestCB->Request[i].Length.LowPart);
4703 pResultCB->Result[i].Status = 0;
4705 case CM_ERROR_WOULDBLOCK:
4706 pResultCB->Result[i].Status = STATUS_FILE_LOCK_CONFLICT;
4709 pResultCB->Result[i].Status = STATUS_LOCK_NOT_GRANTED;
4713 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4714 lock_ReleaseWrite(&scp->rw);
4715 cm_ReleaseSCache(scp);
4717 (*ResultCB)->ResultStatus = 0;
4718 osi_Log0(afsd_logp, "RDR_ByteRangeLockSync SUCCESS");
4723 RDR_ByteRangeUnlock( IN cm_user_t *userp,
4724 IN AFSFileID FileId,
4725 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4727 IN DWORD ResultBufferLength,
4728 IN OUT AFSCommResult **ResultCB)
4730 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4731 LARGE_INTEGER ProcessId;
4733 cm_scache_t *scp = NULL;
4741 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4745 req.flags |= CM_REQ_WOW64;
4747 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4748 FileId.Cell, FileId.Volume,
4749 FileId.Vnode, FileId.Unique);
4750 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4751 ProcessId.HighPart, ProcessId.LowPart);
4753 Length = sizeof( AFSByteRangeUnlockResultCB) + ((pBRURequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4754 if (Length > ResultBufferLength) {
4755 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4758 memset( *ResultCB, 0, sizeof(AFSCommResult));
4759 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4763 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4766 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4767 (*ResultCB)->ResultBufferLength = Length;
4769 pResultCB = (AFSByteRangeUnlockResultCB *)(*ResultCB)->ResultData;
4770 pResultCB->Count = pBRURequestCB->Count;
4772 /* Allocate the extents from the buffer package */
4773 Fid.cell = FileId.Cell;
4774 Fid.volume = FileId.Volume;
4775 Fid.vnode = FileId.Vnode;
4776 Fid.unique = FileId.Unique;
4777 Fid.hash = FileId.Hash;
4779 code = cm_GetSCache(&Fid, &scp, userp, &req);
4781 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4782 (*ResultCB)->ResultStatus = status;
4783 (*ResultCB)->ResultBufferLength = 0;
4784 osi_Log2(afsd_logp, "RDR_ByteRangeUnlock cm_GetSCache FID failure code=0x%x status=0x%x",
4789 lock_ObtainWrite(&scp->rw);
4791 /* start by looking up the file's end */
4792 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4793 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4795 lock_ReleaseWrite(&scp->rw);
4796 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4797 (*ResultCB)->ResultStatus = status;
4798 (*ResultCB)->ResultBufferLength = 0;
4799 osi_Log3(afsd_logp, "RDR_ByteRangeUnlock cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4804 /* the scp is now locked and current */
4805 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4807 for ( i=0; i<pBRURequestCB->Count; i++ ) {
4808 pResultCB->Result[i].LockType = pBRURequestCB->Request[i].LockType;
4809 pResultCB->Result[i].Offset = pBRURequestCB->Request[i].Offset;
4810 pResultCB->Result[i].Length = pBRURequestCB->Request[i].Length;
4812 code = cm_Unlock(scp,
4813 pBRURequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4814 pBRURequestCB->Request[i].Offset,
4815 pBRURequestCB->Request[i].Length,
4816 key, CM_UNLOCK_FLAG_MATCH_RANGE, userp, &req);
4819 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4820 code, pBRURequestCB->Request[i].LockType,
4821 pBRURequestCB->Request[i].Offset.HighPart,
4822 pBRURequestCB->Request[i].Offset.LowPart);
4823 osi_Log2(afsd_logp, "... length 0x%x:%x",
4824 pBRURequestCB->Request[i].Length.HighPart,
4825 pBRURequestCB->Request[i].Length.LowPart);
4827 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4828 pResultCB->Result[i].Status = status;
4831 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4832 lock_ReleaseWrite(&scp->rw);
4833 cm_ReleaseSCache(scp);
4835 (*ResultCB)->ResultStatus = 0;
4836 osi_Log0(afsd_logp, "RDR_ByteRangeUnlock SUCCESS");
4841 RDR_ByteRangeUnlockAll( IN cm_user_t *userp,
4842 IN AFSFileID FileId,
4843 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4845 IN DWORD ResultBufferLength,
4846 IN OUT AFSCommResult **ResultCB)
4848 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4849 LARGE_INTEGER ProcessId;
4850 cm_scache_t *scp = NULL;
4857 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4861 req.flags |= CM_REQ_WOW64;
4863 osi_Log4(afsd_logp, "RDR_ByteRangeUnlockAll File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4864 FileId.Cell, FileId.Volume,
4865 FileId.Vnode, FileId.Unique);
4866 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4867 ProcessId.HighPart, ProcessId.LowPart);
4869 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4872 memset( *ResultCB, '\0', sizeof( AFSCommResult));
4873 (*ResultCB)->ResultBufferLength = 0;
4875 /* Allocate the extents from the buffer package */
4876 Fid.cell = FileId.Cell;
4877 Fid.volume = FileId.Volume;
4878 Fid.vnode = FileId.Vnode;
4879 Fid.unique = FileId.Unique;
4880 Fid.hash = FileId.Hash;
4882 code = cm_GetSCache(&Fid, &scp, userp, &req);
4884 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4885 (*ResultCB)->ResultStatus = status;
4886 (*ResultCB)->ResultBufferLength = 0;
4887 osi_Log2(afsd_logp, "RDR_ByteRangeUnlockAll cm_GetSCache FID failure code=0x%x status=0x%x",
4892 lock_ObtainWrite(&scp->rw);
4894 /* start by looking up the file's end */
4895 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4896 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4898 lock_ReleaseWrite(&scp->rw);
4899 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4900 (*ResultCB)->ResultStatus = status;
4901 (*ResultCB)->ResultBufferLength = 0;
4902 osi_Log3(afsd_logp, "RDR_ByteRangeUnlockAll cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4907 /* the scp is now locked and current */
4908 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4910 code = cm_UnlockByKey(scp, key, 0, userp, &req);
4912 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4913 lock_ReleaseWrite(&scp->rw);
4914 cm_ReleaseSCache(scp);
4916 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4917 (*ResultCB)->ResultStatus = status;
4920 osi_Log1(afsd_logp, "RDR_ByteRangeUnlockAll FAILURE code 0x%x", code);
4922 osi_Log0(afsd_logp, "RDR_ByteRangeUnlockAll SUCCESS");
4928 RDR_GetVolumeInfo( IN cm_user_t *userp,
4929 IN AFSFileID FileId,
4931 IN DWORD ResultBufferLength,
4932 IN OUT AFSCommResult **ResultCB)
4934 AFSVolumeInfoCB *pResultCB = NULL;
4936 cm_scache_t *scp = NULL;
4937 cm_volume_t *volp = NULL;
4938 cm_vol_state_t *volstatep = NULL;
4940 cm_cell_t *cellp = NULL;
4945 FILETIME ft = {0x832cf000, 0x01abfcc4}; /* October 1, 1982 00:00:00 +0600 */
4947 char volName[32]="(unknown)";
4948 char offLineMsg[256]="server temporarily inaccessible";
4949 char motd[256]="server temporarily inaccessible";
4951 AFSFetchVolumeStatus volStat;
4955 struct rx_connection * rxconnp;
4959 req.flags |= CM_REQ_WOW64;
4961 osi_Log4(afsd_logp, "RDR_GetVolumeInfo File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4962 FileId.Cell, FileId.Volume,
4963 FileId.Vnode, FileId.Unique);
4965 Length = sizeof( AFSCommResult) + sizeof(AFSVolumeInfoCB);
4966 if (sizeof(AFSVolumeInfoCB) > ResultBufferLength) {
4967 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
4970 memset( *ResultCB, 0, sizeof(AFSCommResult));
4971 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4975 *ResultCB = (AFSCommResult *)malloc( Length );
4978 memset( *ResultCB, '\0', Length );
4979 (*ResultCB)->ResultBufferLength = sizeof(AFSVolumeInfoCB);
4980 pResultCB = (AFSVolumeInfoCB *)(*ResultCB)->ResultData;
4982 /* Allocate the extents from the buffer package */
4983 if (FileId.Cell != 0) {
4984 Fid.cell = FileId.Cell;
4985 Fid.volume = FileId.Volume;
4986 Fid.vnode = FileId.Vnode;
4987 Fid.unique = FileId.Unique;
4988 Fid.hash = FileId.Hash;
4990 code = cm_GetSCache(&Fid, &scp, userp, &req);
4992 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4993 (*ResultCB)->ResultStatus = status;
4994 (*ResultCB)->ResultBufferLength = 0;
4995 osi_Log2(afsd_logp, "RDR_GetVolumeInfo cm_GetSCache FID failure code=0x%x status=0x%x",
5000 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
5001 osi_Log0(afsd_logp, "RDR_GetVolumeInfo Object Name Invalid - Cell = 0");
5004 lock_ObtainWrite(&scp->rw);
5006 /* start by looking up the file's end */
5007 code = cm_SyncOp(scp, NULL, userp, &req, 0,
5008 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5010 lock_ReleaseWrite(&scp->rw);
5011 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5012 (*ResultCB)->ResultStatus = status;
5013 (*ResultCB)->ResultBufferLength = 0;
5014 osi_Log3(afsd_logp, "RDR_GetVolumeInfo cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
5020 pResultCB->SectorsPerAllocationUnit = 1;
5021 pResultCB->BytesPerSector = 1024;
5023 pResultCB->CellID = scp->fid.cell;
5024 pResultCB->VolumeID = scp->fid.volume;
5025 pResultCB->Characteristics = FILE_REMOTE_DEVICE;
5026 pResultCB->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK |
5027 FILE_SUPPORTS_REPARSE_POINTS;
5029 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
5030 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)
5032 pResultCB->TotalAllocationUnits.QuadPart = 100;
5033 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
5035 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5036 pResultCB->Characteristics |= FILE_READ_ONLY_DEVICE;
5038 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( "Freelance.Local.Root", -1, pResultCB->VolumeLabel,
5039 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5040 if ( pResultCB->VolumeLabelLength )
5041 pResultCB->VolumeLabelLength--;
5043 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
5045 volp = cm_GetVolumeByFID(&scp->fid);
5047 code = CM_ERROR_NOSUCHVOLUME;
5050 volstatep = cm_VolumeStateByID(volp, scp->fid.volume);
5051 volType = cm_VolumeType(volp, scp->fid.volume);
5053 pResultCB->Characteristics |= ((volType == ROVOL || volType == BACKVOL) ? FILE_READ_ONLY_DEVICE : 0);
5056 OfflineMsg = offLineMsg;
5058 lock_ReleaseWrite(&scp->rw);
5060 code = cm_ConnFromFID(&scp->fid, userp, &req, &connp);
5063 rxconnp = cm_GetRxConn(connp);
5064 code = RXAFS_GetVolumeStatus(rxconnp, scp->fid.volume,
5065 &volStat, &Name, &OfflineMsg, &MOTD);
5066 rx_PutConnection(rxconnp);
5068 } while (cm_Analyze(connp, userp, &req, &scp->fid, NULL, NULL, NULL, code));
5069 code = cm_MapRPCError(code, &req);
5071 pResultCB->TotalAllocationUnits.QuadPart = volStat.PartMaxBlocks;
5072 pResultCB->AvailableAllocationUnits.QuadPart = volStat.PartBlocksAvail;
5074 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( Name, -1, pResultCB->VolumeLabel,
5075 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5077 pResultCB->TotalAllocationUnits.QuadPart = 0x7FFFFFFF;
5078 pResultCB->AvailableAllocationUnits.QuadPart = (volType == ROVOL || volType == BACKVOL) ? 0 : 0x3F000000;
5080 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( volp->namep, -1, pResultCB->VolumeLabel,
5081 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5084 if ( pResultCB->VolumeLabelLength )
5085 pResultCB->VolumeLabelLength--;
5087 lock_ObtainWrite(&scp->rw);
5089 pResultCB->VolumeLabelLength *= sizeof(WCHAR); /* convert to bytes from chars */
5091 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5094 lock_ReleaseWrite(&scp->rw);
5097 cm_ReleaseSCache(scp);
5099 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5100 (*ResultCB)->ResultStatus = status;
5101 osi_Log0(afsd_logp, "RDR_GetVolumeInfo SUCCESS");
5106 RDR_HoldFid( IN cm_user_t *userp,
5107 IN AFSHoldFidRequestCB * pHoldFidCB,
5109 IN DWORD ResultBufferLength,
5110 IN OUT AFSCommResult **ResultCB)
5112 AFSHoldFidResultCB *pResultCB = NULL;
5119 osi_Log1(afsd_logp, "RDR_HoldFid Count=%u", pHoldFidCB->Count);
5121 Length = sizeof(AFSHoldFidResultCB) + (pHoldFidCB->Count-1) * sizeof(AFSFidResult);
5122 if (Length > ResultBufferLength) {
5123 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5126 memset( *ResultCB, 0, sizeof(AFSCommResult));
5127 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5130 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5133 memset( *ResultCB, '\0', Length );
5134 (*ResultCB)->ResultBufferLength = Length;
5135 pResultCB = (AFSHoldFidResultCB *)(*ResultCB)->ResultData;
5137 for ( index = 0; index < pHoldFidCB->Count; index++ )
5139 cm_scache_t *scp = NULL;
5142 Fid.cell = pResultCB->Result[index].FileID.Cell = pHoldFidCB->FileID[index].Cell;
5143 Fid.volume = pResultCB->Result[index].FileID.Volume = pHoldFidCB->FileID[index].Volume;
5144 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pHoldFidCB->FileID[index].Vnode;
5145 Fid.unique = pResultCB->Result[index].FileID.Unique = pHoldFidCB->FileID[index].Unique;
5146 Fid.hash = pResultCB->Result[index].FileID.Hash = pHoldFidCB->FileID[index].Hash;
5148 osi_Log4( afsd_logp,
5149 "RDR_HoldFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5150 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5152 scp = cm_FindSCache(&Fid);
5154 RDR_FlagScpInUse( scp, FALSE );
5155 cm_ReleaseSCache(scp);
5157 pResultCB->Result[index].Status = 0;
5160 (*ResultCB)->ResultStatus = 0;
5161 osi_Log0(afsd_logp, "RDR_HoldFid SUCCESS");
5166 RDR_ReleaseFid( IN cm_user_t *userp,
5167 IN AFSReleaseFidRequestCB * pReleaseFidCB,
5169 IN DWORD ResultBufferLength,
5170 IN OUT AFSCommResult **ResultCB)
5172 AFSReleaseFidResultCB *pResultCB = NULL;
5179 osi_Log1(afsd_logp, "RDR_ReleaseFid Count=%u", pReleaseFidCB->Count);
5181 Length = sizeof(AFSReleaseFidResultCB) + (pReleaseFidCB->Count ? pReleaseFidCB->Count-1 : 0) * sizeof(AFSFidResult);
5182 if (Length > ResultBufferLength) {
5183 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5186 memset( *ResultCB, 0, sizeof(AFSCommResult));
5187 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5190 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5193 memset( *ResultCB, '\0', Length );
5194 (*ResultCB)->ResultBufferLength = Length;
5195 pResultCB = (AFSReleaseFidResultCB *)(*ResultCB)->ResultData;
5197 for ( index = 0; index < pReleaseFidCB->Count; index++ )
5199 cm_scache_t *scp = NULL;
5202 Fid.cell = pResultCB->Result[index].FileID.Cell = pReleaseFidCB->FileID[index].Cell;
5203 Fid.volume = pResultCB->Result[index].FileID.Volume = pReleaseFidCB->FileID[index].Volume;
5204 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pReleaseFidCB->FileID[index].Vnode;
5205 Fid.unique = pResultCB->Result[index].FileID.Unique = pReleaseFidCB->FileID[index].Unique;
5206 Fid.hash = pResultCB->Result[index].FileID.Hash = pReleaseFidCB->FileID[index].Hash;
5208 osi_Log4( afsd_logp,
5209 "RDR_ReleaseFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5210 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5212 scp = cm_FindSCache(&Fid);
5214 lock_ObtainWrite(&scp->rw);
5215 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
5216 lock_ReleaseWrite(&scp->rw);
5218 cm_ReleaseSCache(scp);
5220 pResultCB->Result[index].Status = 0;
5222 pResultCB->Count = pReleaseFidCB->Count;
5224 (*ResultCB)->ResultStatus = 0;
5225 osi_Log0(afsd_logp, "RDR_ReleaseFid SUCCESS");
5230 * The redirector makes several assumptions regarding the
5231 * SRVSVC and WKSSVC pipes transactions. First, the interface
5232 * versions are those indicated below. Secondly, the encoding
5233 * will be performed using NDR version 2. These assumptions
5234 * may not hold in the future and end-to-end MSRPC Bind
5235 * negotiations may need to be supported. Of course, these
5236 * are the only interface versions that are supported by the
5239 #define MSRPC_PIPE_PREFIX L".\\"
5241 static const UUID MSRPC_SRVSVC_UUID = {0x4B324FC8, 0x1670, 0x01D3,
5242 {0x12, 0x78, 0x5A, 0x47, 0xBF, 0x6E, 0xE1, 0x88}};
5243 #define MSRPC_SRVSVC_NAME L"PIPE\\SRVSVC"
5244 #define MSRPC_SRVSVC_VERS 3
5246 static const UUID MSRPC_WKSSVC_UUID = {0x6BFFD098, 0xA112, 0x3610,
5247 {0x98, 0x33, 0x46, 0xC3, 0xF8, 0x7E, 0x34, 0x5A}};
5248 #define MSRPC_WKSSVC_NAME L"PIPE\\WKSSVC"
5249 #define MSRPC_WKSSVC_VERS 1
5251 static const UUID MSRPC_NDR_UUID = {0x8A885D04, 0x1CEB, 0x11C9,
5252 {0x9F, 0xE8, 0x08, 0x00, 0x2B, 0x10, 0x48, 0x60}};
5253 #define MSRPC_NDR_NAME L"NDR"
5254 #define MSRPC_NDR_VERS 2
5256 extern RPC_IF_HANDLE srvsvc_v3_0_s_ifspec;
5257 extern RPC_IF_HANDLE wkssvc_v1_0_s_ifspec;
5260 RDR_PipeOpen( IN cm_user_t *userp,
5261 IN AFSFileID ParentId,
5263 IN DWORD NameLength,
5264 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5266 IN DWORD ResultBufferLength,
5267 IN OUT AFSCommResult **ResultCB)
5272 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5278 sizeof( AFSCommResult));
5280 /* Get the active directory */
5281 ParentFid.cell = ParentId.Cell;
5282 ParentFid.volume = ParentId.Volume;
5283 ParentFid.vnode = ParentId.Vnode;
5284 ParentFid.unique = ParentId.Unique;
5285 ParentFid.hash = ParentId.Hash;
5287 /* Get the root directory */
5288 RootFid.cell = pPipe_CB->RootId.Cell;
5289 RootFid.volume = pPipe_CB->RootId.Volume;
5290 RootFid.vnode = pPipe_CB->RootId.Vnode;
5291 RootFid.unique = pPipe_CB->RootId.Unique;
5292 RootFid.hash = pPipe_CB->RootId.Hash;
5294 /* Create the pipe index */
5295 (*ResultCB)->ResultStatus =
5296 RDR_SetupPipe( pPipe_CB->RequestId, &ParentFid, &RootFid,
5297 Name, NameLength, userp);
5303 RDR_PipeClose( IN cm_user_t *userp,
5304 IN AFSFileID ParentId,
5305 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5307 IN DWORD ResultBufferLength,
5308 IN OUT AFSCommResult **ResultCB)
5310 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5316 sizeof( AFSCommResult));
5318 /* Cleanup the pipe index */
5319 RDR_CleanupPipe(pPipe_CB->RequestId);
5326 RDR_PipeWrite( IN cm_user_t *userp,
5327 IN AFSFileID ParentId,
5328 IN AFSPipeIORequestCB *pPipe_CB,
5329 IN BYTE *pPipe_Data,
5331 IN DWORD ResultBufferLength,
5332 IN OUT AFSCommResult **ResultCB)
5334 AFSPipeIOResultCB *pResultCB;
5335 cm_scache_t *dscp = NULL;
5342 req.flags |= CM_REQ_WOW64;
5344 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5350 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5352 pResultCB = (AFSPipeIOResultCB *)(*ResultCB)->ResultData;
5354 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_Data, &req, userp);
5356 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5357 (*ResultCB)->ResultStatus = status;
5361 pResultCB->BytesProcessed = pPipe_CB->BufferLength;
5362 (*ResultCB)->ResultBufferLength = sizeof( AFSPipeIOResultCB);
5367 RDR_PipeRead( IN cm_user_t *userp,
5368 IN AFSFileID ParentId,
5369 IN AFSPipeIORequestCB *pPipe_CB,
5371 IN DWORD ResultBufferLength,
5372 IN OUT AFSCommResult **ResultCB)
5375 cm_scache_t *dscp = NULL;
5382 req.flags |= CM_REQ_WOW64;
5384 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5390 sizeof( AFSCommResult));
5392 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5394 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_Data,
5395 &(*ResultCB)->ResultBufferLength, &req, userp);
5397 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5398 (*ResultCB)->ResultStatus = status;
5405 RDR_PipeSetInfo( IN cm_user_t *userp,
5406 IN AFSFileID ParentId,
5407 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5408 IN BYTE *pPipe_Data,
5410 IN DWORD ResultBufferLength,
5411 IN OUT AFSCommResult **ResultCB)
5413 cm_scache_t *dscp = NULL;
5419 req.flags |= CM_REQ_WOW64;
5421 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5427 sizeof( AFSCommResult));
5429 status = RDR_Pipe_SetInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5430 pPipeInfo_CB->BufferLength, pPipe_Data, &req, userp);
5432 (*ResultCB)->ResultStatus = status;
5437 RDR_PipeQueryInfo( IN cm_user_t *userp,
5438 IN AFSFileID ParentId,
5439 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5441 IN DWORD ResultBufferLength,
5442 IN OUT AFSCommResult **ResultCB)
5445 cm_scache_t *dscp = NULL;
5451 req.flags |= CM_REQ_WOW64;
5453 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5459 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5461 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5463 status = RDR_Pipe_QueryInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5464 ResultBufferLength, pPipe_Data,
5465 &(*ResultCB)->ResultBufferLength, &req, userp);
5467 (*ResultCB)->ResultStatus = status;
5471 RDR_PipeTransceive( IN cm_user_t *userp,
5472 IN AFSFileID ParentId,
5473 IN AFSPipeIORequestCB *pPipe_CB,
5474 IN BYTE *pPipe_InData,
5476 IN DWORD ResultBufferLength,
5477 IN OUT AFSCommResult **ResultCB)
5480 * This function processes a Pipe Service request
5481 * that would normally be sent to a LAN Manager server
5482 * across an authenticated SMB-PIPE/MSRPC/SVC request
5483 * stack. The request is being sent here because the
5484 * application (e.g., Explorer Shell or Common Control File
5485 * dialog) believes that because the UNC path it is
5486 * processing has specified a server name that is not
5487 * "." and that the Server is remote and that the Share
5488 * list cannot be obtained using the Network Provider
5491 * The file system driver is faking the Bind-Ack response
5492 * to the MSRPC Bind request but cannot decode the NDR
5493 * encoded Pipe Service requests. For that we will use
5494 * the service's MSRPC module. However, unlike the SMB
5495 * server usage we must fake the MSRPC Bind exchange and
5496 * map the PipeName to an interface instead of using the
5497 * GUID specified in the MSRPC Bind request.
5499 * None of the requests that are being processed by the
5500 * service require authentication. As a result the userp
5501 * parameter will be ignored.
5503 * Although there are dozens of Pipe Services, the only
5504 * ones that we are implementing are WKSSVC and SRVSVC.
5505 * These support NetShareEnum, NetShareGetInfo,
5506 * NetServerGetInfo, and NetWorkstaGetInfo which are
5507 * commonly queried by NET VIEW, the Explorer Shell,
5508 * and the Common Control File dialog.
5510 BYTE *pPipe_OutData;
5511 cm_scache_t *dscp = NULL;
5515 DWORD Length = ResultBufferLength + sizeof( AFSCommResult);
5519 req.flags |= CM_REQ_WOW64;
5521 *ResultCB = (AFSCommResult *)malloc( Length);
5524 memset( *ResultCB, '\0', Length );
5526 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_InData, &req, userp);
5528 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5529 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Write FAILURE code=0x%x status=0x%x",
5531 (*ResultCB)->ResultStatus = status;
5535 pPipe_OutData = (BYTE *)(*ResultCB)->ResultData;
5536 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_OutData,
5537 &(*ResultCB)->ResultBufferLength, &req, userp);
5539 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5540 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Read FAILURE code=0x%x status=0x%x",
5542 (*ResultCB)->ResultStatus = status;
5546 (*ResultCB)->ResultStatus = 0;
5547 osi_Log0(afsd_logp, "RDR_Pipe_Transceive SUCCESS");