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 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1644 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1645 dscp, scp, userp, &req, NULL, NULL,
1646 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1647 0, NULL, &dwRemaining);
1648 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1649 osi_Log0(afsd_logp, "RDR_UpdateFileEntry SUCCESS");
1651 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1652 (*ResultCB)->ResultStatus = status;
1653 (*ResultCB)->ResultBufferLength = 0;
1654 osi_Log2(afsd_logp, "RDR_UpdateFileEntry FAILURE code=0x%x status=0x%x",
1657 cm_ReleaseSCache(scp);
1658 cm_ReleaseSCache(dscp);
1664 RDR_CleanupFileEntry( IN cm_user_t *userp,
1665 IN AFSFileID FileId,
1666 IN WCHAR *FileNameCounted,
1667 IN DWORD FileNameLength,
1668 IN AFSFileCleanupCB *CleanupCB,
1670 IN BOOL bLastHandle,
1671 IN BOOL bDeleteFile,
1672 IN BOOL bUnlockFile,
1673 IN DWORD ResultBufferLength,
1674 IN OUT AFSCommResult **ResultCB)
1676 AFSFileCleanupResultCB *pResultCB = NULL;
1677 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1680 afs_uint32 code = 0;
1681 afs_uint32 flags = 0;
1683 cm_scache_t * scp = NULL;
1684 cm_scache_t * dscp = NULL;
1686 time_t clientModTime;
1689 BOOL bScpLocked = FALSE;
1690 BOOL bDscpLocked = FALSE;
1691 BOOL bFlushFile = FALSE;
1696 req.flags |= CM_REQ_WOW64;
1697 memset(&setAttr, 0, sizeof(cm_attr_t));
1699 osi_Log4(afsd_logp, "RDR_CleanupFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1700 CleanupCB->ParentId.Cell, CleanupCB->ParentId.Volume,
1701 CleanupCB->ParentId.Vnode, CleanupCB->ParentId.Unique);
1702 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1703 FileId.Cell, FileId.Volume,
1704 FileId.Vnode, FileId.Unique);
1706 *ResultCB = (AFSCommResult *)malloc( size);
1708 osi_Log0(afsd_logp, "RDR_CleanupFileEntry Out of Memory");
1716 parentFid.cell = CleanupCB->ParentId.Cell;
1717 parentFid.volume = CleanupCB->ParentId.Volume;
1718 parentFid.vnode = CleanupCB->ParentId.Vnode;
1719 parentFid.unique = CleanupCB->ParentId.Unique;
1720 parentFid.hash = CleanupCB->ParentId.Hash;
1722 if (parentFid.cell) {
1723 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1725 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1726 if ( status == STATUS_INVALID_HANDLE)
1727 status = STATUS_OBJECT_PATH_INVALID;
1728 (*ResultCB)->ResultStatus = status;
1729 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1734 lock_ObtainWrite(&dscp->rw);
1736 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1737 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1739 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure dscp=0x%p code=0x%x",
1745 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1746 lock_ReleaseWrite(&dscp->rw);
1747 bDscpLocked = FALSE;
1749 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1750 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1751 cm_ReleaseSCache(dscp);
1752 osi_Log1(afsd_logp, "RDR_CleanupFileEntry Not a Directory dscp=0x%p",
1759 Fid.cell = FileId.Cell;
1760 Fid.volume = FileId.Volume;
1761 Fid.vnode = FileId.Vnode;
1762 Fid.unique = FileId.Unique;
1763 Fid.hash = FileId.Hash;
1765 code = cm_GetSCache(&Fid, &scp, userp, &req);
1767 osi_Log1(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache object FID failure code=0x%x",
1772 lock_ObtainWrite(&scp->rw);
1774 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1775 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1777 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure scp=0x%p code=0x%x",
1781 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1783 if ((bLastHandle || bFlushFile) &&
1784 scp->redirBufCount > 0)
1786 LARGE_INTEGER heldExtents;
1787 AFSFileExtentCB extentList[1024];
1788 DWORD extentCount = 0;
1793 heldExtents.QuadPart = 0;
1795 for ( srbp = redirq_to_cm_buf_t(scp->redirQueueT);
1797 srbp = redirq_to_cm_buf_t(osi_QPrev(&srbp->redirq)))
1799 extentList[extentCount].Flags = 0;
1800 extentList[extentCount].Length = cm_data.blockSize;
1801 extentList[extentCount].FileOffset.QuadPart = srbp->offset.QuadPart;
1802 extentList[extentCount].CacheOffset.QuadPart = srbp->datap - RDR_extentBaseAddress;
1803 lock_ObtainWrite(&buf_globalLock);
1804 srbp->redirReleaseRequested = now;
1805 lock_ReleaseWrite(&buf_globalLock);
1808 if (extentCount == 1024) {
1809 lock_ReleaseWrite(&scp->rw);
1810 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1812 if (code == CM_ERROR_RETRY) {
1814 * The redirector either is not holding the extents or cannot let them
1815 * go because they are otherwise in use. At the moment, do nothing.
1822 lock_ObtainWrite(&scp->rw);
1826 if (code == 0 && extentCount > 0) {
1828 lock_ReleaseWrite(&scp->rw);
1831 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1836 /* No longer in use by redirector */
1838 lock_ObtainWrite(&scp->rw);
1843 lock_AssertWrite(&scp->rw);
1844 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
1847 if (bLastHandle || bFlushFile) {
1849 lock_ObtainWrite(&scp->rw);
1852 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
1853 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1856 lock_ReleaseWrite(&scp->rw);
1860 code = cm_FSync(scp, userp, &req, bScpLocked);
1862 if (bLastHandle && code)
1866 if (bUnlockFile || bDeleteFile) {
1868 lock_ObtainWrite(&scp->rw);
1871 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1872 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1874 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp (2) failure scp=0x%p code=0x%x",
1879 key = cm_GenerateKey(CM_SESSION_IFS, CleanupCB->ProcessId, 0);
1881 /* the scp is now locked and current */
1882 code = cm_UnlockByKey(scp, key,
1883 bDeleteFile ? CM_UNLOCK_FLAG_BY_FID : 0,
1886 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1892 if (CleanupCB->ChangeTime.QuadPart) {
1894 if (scp->fileType == CM_SCACHETYPE_FILE) {
1895 /* Do not set length and other attributes at the same time */
1896 if (scp->length.QuadPart != CleanupCB->AllocationSize.QuadPart) {
1897 osi_Log2(afsd_logp, "RDR_CleanupFileEntry Length Change 0x%x -> 0x%x",
1898 (afs_uint32)scp->length.QuadPart, (afs_uint32)CleanupCB->AllocationSize.QuadPart);
1899 setAttr.mask |= CM_ATTRMASK_LENGTH;
1900 setAttr.length.LowPart = CleanupCB->AllocationSize.LowPart;
1901 setAttr.length.HighPart = CleanupCB->AllocationSize.HighPart;
1904 lock_ReleaseWrite(&scp->rw);
1907 code = cm_SetAttr(scp, &setAttr, userp, &req);
1915 lock_ObtainWrite(&scp->rw);
1919 if ((scp->unixModeBits & 0200) && (CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1920 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1921 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1922 } else if (!(scp->unixModeBits & 0200) && !(CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1923 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1924 setAttr.unixModeBits = scp->unixModeBits | 0222;
1928 if (CleanupCB->LastWriteTime.QuadPart) {
1929 ft.dwLowDateTime = CleanupCB->LastWriteTime.LowPart;
1930 ft.dwHighDateTime = CleanupCB->LastWriteTime.HighPart;
1932 cm_UnixTimeFromLargeSearchTime(&clientModTime, &ft);
1933 if (scp->clientModTime != clientModTime) {
1934 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1935 setAttr.clientModTime = clientModTime;
1941 lock_ReleaseWrite(&scp->rw);
1943 code = cm_SetAttr(scp, &setAttr, userp, &req);
1947 /* Now drop the lock enforcing the share access */
1948 if ( CleanupCB->FileAccess != AFS_FILE_ACCESS_NOLOCK) {
1949 unsigned int sLockType;
1950 LARGE_INTEGER LOffset, LLength;
1952 if (CleanupCB->FileAccess == AFS_FILE_ACCESS_SHARED)
1953 sLockType = LOCKING_ANDX_SHARED_LOCK;
1957 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, CleanupCB->Identifier);
1959 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
1960 LOffset.LowPart = SMB_FID_QLOCK_LOW;
1961 LLength.HighPart = 0;
1962 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
1965 lock_ObtainWrite(&scp->rw);
1969 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
1972 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
1974 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
1976 if (code == CM_ERROR_RANGE_NOT_LOCKED)
1978 osi_Log3(afsd_logp, "RDR_CleanupFileEntry Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
1979 CleanupCB->FileAccess, CleanupCB->ProcessId, CleanupCB->Identifier);
1987 lock_ReleaseWrite(&dscp->rw);
1989 lock_ReleaseWrite(&scp->rw);
1991 if (dscp && bDeleteFile) {
1992 WCHAR FileName[260];
1994 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1996 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
1997 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
1999 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2002 if ( ResultBufferLength >= sizeof( AFSFileCleanupResultCB))
2004 (*ResultCB)->ResultBufferLength = sizeof( AFSFileCleanupResultCB);
2005 pResultCB = (AFSFileCleanupResultCB *)&(*ResultCB)->ResultData;
2006 pResultCB->ParentDataVersion.QuadPart = dscp ? dscp->dataVersion : 0;
2008 (*ResultCB)->ResultBufferLength = 0;
2012 (*ResultCB)->ResultStatus = 0;
2013 osi_Log0(afsd_logp, "RDR_CleanupFileEntry SUCCESS");
2015 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2016 (*ResultCB)->ResultStatus = status;
2017 osi_Log2(afsd_logp, "RDR_CleanupFileEntry FAILURE code=0x%x status=0x%x",
2021 cm_ReleaseSCache(scp);
2023 cm_ReleaseSCache(dscp);
2029 RDR_DeleteFileEntry( IN cm_user_t *userp,
2030 IN AFSFileID ParentId,
2031 IN ULONGLONG ProcessId,
2032 IN WCHAR *FileNameCounted,
2033 IN DWORD FileNameLength,
2036 IN DWORD ResultBufferLength,
2037 IN OUT AFSCommResult **ResultCB)
2040 AFSFileDeleteResultCB *pResultCB = NULL;
2041 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2044 cm_scache_t * dscp = NULL;
2045 cm_scache_t * scp = NULL;
2046 afs_uint32 flags = 0;
2050 wchar_t FileName[260];
2053 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
2055 osi_Log4(afsd_logp, "RDR_DeleteFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2056 ParentId.Cell, ParentId.Volume,
2057 ParentId.Vnode, ParentId.Unique);
2058 osi_Log2(afsd_logp, "... name=%S checkOnly=%x",
2059 osi_LogSaveStringW(afsd_logp, FileName),
2064 req.flags |= CM_REQ_WOW64;
2065 memset(&setAttr, 0, sizeof(cm_attr_t));
2067 *ResultCB = (AFSCommResult *)malloc( size);
2069 osi_Log0(afsd_logp, "RDR_DeleteFileEntry out of memory");
2077 parentFid.cell = ParentId.Cell;
2078 parentFid.volume = ParentId.Volume;
2079 parentFid.vnode = ParentId.Vnode;
2080 parentFid.unique = ParentId.Unique;
2081 parentFid.hash = ParentId.Hash;
2083 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
2085 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2086 if ( status == STATUS_INVALID_HANDLE)
2087 status = STATUS_OBJECT_PATH_INVALID;
2088 (*ResultCB)->ResultStatus = status;
2089 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
2094 lock_ObtainWrite(&dscp->rw);
2096 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
2097 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2099 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2100 (*ResultCB)->ResultStatus = status;
2101 (*ResultCB)->ResultBufferLength = 0;
2102 lock_ReleaseWrite(&dscp->rw);
2103 cm_ReleaseSCache(dscp);
2104 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
2105 dscp, code, status);
2109 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2110 lock_ReleaseWrite(&dscp->rw);
2112 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2113 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2114 cm_ReleaseSCache(dscp);
2115 osi_Log1(afsd_logp, "RDR_DeleteFileEntry Not a Directory dscp=0x%p",
2120 code = cm_Lookup(dscp, FileName, 0, userp, &req, &scp);
2122 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2123 (*ResultCB)->ResultStatus = status;
2124 (*ResultCB)->ResultBufferLength = 0;
2125 cm_ReleaseSCache(dscp);
2126 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_Lookup failure code=0x%x status=0x%x",
2131 lock_ObtainWrite(&scp->rw);
2132 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_DELETE,
2133 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2135 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2136 (*ResultCB)->ResultStatus = status;
2137 (*ResultCB)->ResultBufferLength = 0;
2138 lock_ReleaseWrite(&scp->rw);
2139 cm_ReleaseSCache(scp);
2140 cm_ReleaseSCache(dscp);
2141 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2147 /* Drop all locks since the file is being deleted */
2148 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2149 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2151 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2152 (*ResultCB)->ResultStatus = status;
2153 (*ResultCB)->ResultBufferLength = 0;
2154 lock_ReleaseWrite(&scp->rw);
2155 cm_ReleaseSCache(scp);
2156 cm_ReleaseSCache(dscp);
2157 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp Lock failure scp=0x%p code=0x%x status=0x%x",
2161 /* the scp is now locked and current */
2162 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId, 0);
2164 code = cm_UnlockByKey(scp, key,
2165 CM_UNLOCK_FLAG_BY_FID,
2168 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2169 lock_ReleaseWrite(&scp->rw);
2171 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
2172 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
2174 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2176 lock_ReleaseWrite(&scp->rw);
2180 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
2182 (*ResultCB)->ResultBufferLength = sizeof( AFSFileDeleteResultCB);
2184 pResultCB = (AFSFileDeleteResultCB *)(*ResultCB)->ResultData;
2186 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
2187 osi_Log0(afsd_logp, "RDR_DeleteFileEntry SUCCESS");
2189 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2190 (*ResultCB)->ResultStatus = status;
2191 (*ResultCB)->ResultBufferLength = 0;
2192 osi_Log2(afsd_logp, "RDR_DeleteFileEntry FAILURE code=0x%x status=0x%x",
2196 cm_ReleaseSCache(dscp);
2197 cm_ReleaseSCache(scp);
2203 RDR_RenameFileEntry( IN cm_user_t *userp,
2204 IN WCHAR *SourceFileNameCounted,
2205 IN DWORD SourceFileNameLength,
2206 IN AFSFileID SourceFileId,
2207 IN AFSFileRenameCB *pRenameCB,
2209 IN DWORD ResultBufferLength,
2210 IN OUT AFSCommResult **ResultCB)
2213 AFSFileRenameResultCB *pResultCB = NULL;
2214 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2215 AFSFileID SourceParentId = pRenameCB->SourceParentId;
2216 AFSFileID TargetParentId = pRenameCB->TargetParentId;
2217 WCHAR * TargetFileNameCounted = pRenameCB->TargetName;
2218 DWORD TargetFileNameLength = pRenameCB->TargetNameLength;
2219 cm_fid_t SourceParentFid;
2220 cm_fid_t TargetParentFid;
2222 cm_fid_t OrigTargetFid = {0,0,0,0,0};
2224 cm_scache_t * oldDscp;
2225 cm_scache_t * newDscp;
2227 wchar_t shortName[13];
2228 wchar_t SourceFileName[260];
2229 wchar_t TargetFileName[260];
2237 req.flags |= CM_REQ_WOW64;
2239 StringCchCopyNW(SourceFileName, 260, SourceFileNameCounted, SourceFileNameLength / sizeof(WCHAR));
2240 StringCchCopyNW(TargetFileName, 260, TargetFileNameCounted, TargetFileNameLength / sizeof(WCHAR));
2242 osi_Log4(afsd_logp, "RDR_RenameFileEntry Source Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2243 SourceParentId.Cell, SourceParentId.Volume,
2244 SourceParentId.Vnode, SourceParentId.Unique);
2245 osi_Log2(afsd_logp, "... Source Name=%S Length %u", osi_LogSaveStringW(afsd_logp, SourceFileName), SourceFileNameLength);
2246 osi_Log4(afsd_logp, "... Target Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2247 TargetParentId.Cell, TargetParentId.Volume,
2248 TargetParentId.Vnode, TargetParentId.Unique);
2249 osi_Log2(afsd_logp, "... Target Name=%S Length %u", osi_LogSaveStringW(afsd_logp, TargetFileName), TargetFileNameLength);
2251 *ResultCB = (AFSCommResult *)malloc( size);
2259 pResultCB = (AFSFileRenameResultCB *)(*ResultCB)->ResultData;
2261 if (SourceFileNameLength == 0 || TargetFileNameLength == 0)
2263 osi_Log2(afsd_logp, "RDR_RenameFileEntry Invalid Name Length: src %u target %u",
2264 SourceFileNameLength, TargetFileNameLength);
2265 (*ResultCB)->ResultStatus = STATUS_INVALID_PARAMETER;
2269 SourceParentFid.cell = SourceParentId.Cell;
2270 SourceParentFid.volume = SourceParentId.Volume;
2271 SourceParentFid.vnode = SourceParentId.Vnode;
2272 SourceParentFid.unique = SourceParentId.Unique;
2273 SourceParentFid.hash = SourceParentId.Hash;
2275 TargetParentFid.cell = TargetParentId.Cell;
2276 TargetParentFid.volume = TargetParentId.Volume;
2277 TargetParentFid.vnode = TargetParentId.Vnode;
2278 TargetParentFid.unique = TargetParentId.Unique;
2279 TargetParentFid.hash = TargetParentId.Hash;
2281 code = cm_GetSCache(&SourceParentFid, &oldDscp, userp, &req);
2283 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache source parent failed code 0x%x", code);
2284 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2285 if ( status == STATUS_INVALID_HANDLE)
2286 status = STATUS_OBJECT_PATH_INVALID;
2287 (*ResultCB)->ResultStatus = status;
2291 lock_ObtainWrite(&oldDscp->rw);
2292 code = cm_SyncOp(oldDscp, NULL, userp, &req, 0,
2293 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2295 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp oldDscp 0x%p failed code 0x%x", oldDscp, code);
2296 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2297 if ( status == STATUS_INVALID_HANDLE)
2298 status = STATUS_OBJECT_PATH_INVALID;
2299 (*ResultCB)->ResultStatus = status;
2300 lock_ReleaseWrite(&oldDscp->rw);
2301 cm_ReleaseSCache(oldDscp);
2305 cm_SyncOpDone(oldDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2306 lock_ReleaseWrite(&oldDscp->rw);
2309 if (oldDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2310 osi_Log1(afsd_logp, "RDR_RenameFileEntry oldDscp 0x%p not a directory", oldDscp);
2311 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2312 cm_ReleaseSCache(oldDscp);
2316 code = cm_GetSCache(&TargetParentFid, &newDscp, userp, &req);
2318 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target parent failed code 0x%x", code);
2319 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2320 (*ResultCB)->ResultStatus = status;
2321 cm_ReleaseSCache(oldDscp);
2325 lock_ObtainWrite(&newDscp->rw);
2326 code = cm_SyncOp(newDscp, NULL, userp, &req, 0,
2327 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2329 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp newDscp 0x%p failed code 0x%x", newDscp, code);
2330 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2331 (*ResultCB)->ResultStatus = status;
2332 lock_ReleaseWrite(&newDscp->rw);
2333 cm_ReleaseSCache(oldDscp);
2334 cm_ReleaseSCache(newDscp);
2338 cm_SyncOpDone(newDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2339 lock_ReleaseWrite(&newDscp->rw);
2342 if (newDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2343 osi_Log1(afsd_logp, "RDR_RenameFileEntry newDscp 0x%p not a directory", newDscp);
2344 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2345 cm_ReleaseSCache(oldDscp);
2346 cm_ReleaseSCache(newDscp);
2350 /* Obtain the original FID just for debugging purposes */
2351 code = cm_BeginDirOp( oldDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2353 code = cm_BPlusDirLookup(&dirop, SourceFileName, &SourceFid);
2354 code = cm_BPlusDirLookup(&dirop, TargetFileName, &OrigTargetFid);
2355 cm_EndDirOp(&dirop);
2358 code = cm_Rename( oldDscp, NULL, SourceFileName,
2359 newDscp, TargetFileName, userp, &req);
2361 cm_scache_t *scp = 0;
2364 (*ResultCB)->ResultBufferLength = ResultBufferLength;
2365 dwRemaining = ResultBufferLength - sizeof( AFSFileRenameResultCB) + sizeof( AFSDirEnumEntry);
2366 (*ResultCB)->ResultStatus = 0;
2368 pResultCB->SourceParentDataVersion.QuadPart = oldDscp->dataVersion;
2369 pResultCB->TargetParentDataVersion.QuadPart = newDscp->dataVersion;
2371 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p SUCCESS",
2374 code = cm_BeginDirOp( newDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2376 code = cm_BPlusDirLookup(&dirop, TargetFileName, &TargetFid);
2377 cm_EndDirOp(&dirop);
2381 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_BPlusDirLookup failed code 0x%x",
2383 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
2384 cm_ReleaseSCache(oldDscp);
2385 cm_ReleaseSCache(newDscp);
2389 osi_Log4(afsd_logp, "RDR_RenameFileEntry Target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2390 TargetFid.cell, TargetFid.volume,
2391 TargetFid.vnode, TargetFid.unique);
2393 code = cm_GetSCache(&TargetFid, &scp, userp, &req);
2395 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target failed code 0x%x", code);
2396 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2397 (*ResultCB)->ResultStatus = status;
2398 cm_ReleaseSCache(oldDscp);
2399 cm_ReleaseSCache(newDscp);
2403 /* Make sure the source vnode is current */
2404 lock_ObtainWrite(&scp->rw);
2405 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2406 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2408 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp scp 0x%p failed code 0x%x", scp, code);
2409 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2410 (*ResultCB)->ResultStatus = status;
2411 lock_ReleaseWrite(&scp->rw);
2412 cm_ReleaseSCache(oldDscp);
2413 cm_ReleaseSCache(newDscp);
2414 cm_ReleaseSCache(scp);
2418 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2419 lock_ReleaseWrite(&scp->rw);
2421 dfid.vnode = htonl(scp->fid.vnode);
2422 dfid.unique = htonl(scp->fid.unique);
2424 if (!cm_Is8Dot3(TargetFileName))
2425 cm_Gen8Dot3NameIntW(TargetFileName, &dfid, shortName, NULL);
2427 shortName[0] = '\0';
2429 RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
2430 newDscp, scp, userp, &req, TargetFileName, shortName,
2431 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
2432 0, NULL, &dwRemaining);
2433 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
2434 cm_ReleaseSCache(scp);
2436 osi_Log0(afsd_logp, "RDR_RenameFileEntry SUCCESS");
2438 osi_Log3(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p failed code 0x%x",
2439 oldDscp, newDscp, code);
2440 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2441 (*ResultCB)->ResultStatus = status;
2442 (*ResultCB)->ResultBufferLength = 0;
2445 cm_ReleaseSCache(oldDscp);
2446 cm_ReleaseSCache(newDscp);
2451 RDR_FlushFileEntry( IN cm_user_t *userp,
2452 IN AFSFileID FileId,
2454 IN DWORD ResultBufferLength,
2455 IN OUT AFSCommResult **ResultCB)
2457 cm_scache_t *scp = NULL;
2468 req.flags |= CM_REQ_WOW64;
2470 osi_Log4(afsd_logp, "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x",
2471 FileId.Cell, FileId.Volume,
2472 FileId.Vnode, FileId.Unique);
2474 snprintf( dbgstr, 1024,
2475 "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x\n",
2476 FileId.Cell, FileId.Volume,
2477 FileId.Vnode, FileId.Unique);
2478 OutputDebugStringA( dbgstr);
2481 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2483 osi_Log0(afsd_logp, "RDR_FlushFileEntry out of memory");
2489 sizeof( AFSCommResult));
2491 /* Process the release */
2492 Fid.cell = FileId.Cell;
2493 Fid.volume = FileId.Volume;
2494 Fid.vnode = FileId.Vnode;
2495 Fid.unique = FileId.Unique;
2496 Fid.hash = FileId.Hash;
2498 code = cm_GetSCache(&Fid, &scp, userp, &req);
2500 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2501 (*ResultCB)->ResultStatus = status;
2502 osi_Log2(afsd_logp, "RDR_FlushFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2507 lock_ObtainWrite(&scp->rw);
2508 if (scp->flags & CM_SCACHEFLAG_DELETED) {
2509 lock_ReleaseWrite(&scp->rw);
2510 (*ResultCB)->ResultStatus = STATUS_INVALID_HANDLE;
2514 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2515 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2517 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2518 (*ResultCB)->ResultStatus = status;
2519 lock_ReleaseWrite(&scp->rw);
2520 cm_ReleaseSCache(scp);
2521 osi_Log3(afsd_logp, "RDR_FlushFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2526 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2527 lock_ReleaseWrite(&scp->rw);
2529 code = cm_FSync(scp, userp, &req, FALSE);
2530 cm_ReleaseSCache(scp);
2533 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2534 (*ResultCB)->ResultStatus = status;
2535 osi_Log2(afsd_logp, "RDR_FlushFileEntry FAILURE code=0x%x status=0x%x",
2538 (*ResultCB)->ResultStatus = 0;
2539 osi_Log0(afsd_logp, "RDR_FlushFileEntry SUCCESS");
2541 (*ResultCB)->ResultBufferLength = 0;
2547 RDR_CheckAccess( IN cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp,
2551 ULONG afs_acc, afs_gr;
2553 afs_uint32 code = 0;
2555 file = (scp->fileType == CM_SCACHETYPE_FILE);
2558 /* access definitions from prs_fs.h */
2560 if (access & FILE_READ_DATA)
2561 afs_acc |= PRSFS_READ;
2562 if (access & FILE_READ_EA || access & FILE_READ_ATTRIBUTES)
2563 afs_acc |= PRSFS_READ;
2564 if (file && ((access & FILE_WRITE_DATA) || (access & FILE_APPEND_DATA)))
2565 afs_acc |= PRSFS_WRITE;
2566 if (access & FILE_WRITE_EA || access & FILE_WRITE_ATTRIBUTES)
2567 afs_acc |= PRSFS_WRITE;
2568 if (dir && ((access & FILE_ADD_FILE) || (access & FILE_ADD_SUBDIRECTORY)))
2569 afs_acc |= PRSFS_INSERT;
2570 if (dir && (access & FILE_LIST_DIRECTORY))
2571 afs_acc |= PRSFS_LOOKUP;
2572 if (file && (access & FILE_EXECUTE))
2573 afs_acc |= PRSFS_WRITE;
2574 if (dir && (access & FILE_TRAVERSE))
2575 afs_acc |= PRSFS_READ;
2576 if (dir && (access & FILE_DELETE_CHILD))
2577 afs_acc |= PRSFS_DELETE;
2578 if ((access & DELETE))
2579 afs_acc |= PRSFS_DELETE;
2581 /* check ACL with server */
2582 lock_ObtainWrite(&scp->rw);
2585 if (cm_HaveAccessRights(scp, userp, reqp, afs_acc, &afs_gr))
2591 /* we don't know the required access rights */
2592 code = cm_GetAccessRights(scp, userp, reqp);
2598 lock_ReleaseWrite(&(scp->rw));
2602 if (afs_gr & PRSFS_READ)
2603 *granted |= FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | FILE_EXECUTE;
2604 if (afs_gr & PRSFS_WRITE)
2605 *granted |= FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES | FILE_EXECUTE;
2606 if (afs_gr & PRSFS_INSERT)
2607 *granted |= (dir ? FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY : 0) | (file ? FILE_ADD_SUBDIRECTORY : 0);
2608 if (afs_gr & PRSFS_LOOKUP)
2609 *granted |= (dir ? FILE_LIST_DIRECTORY : 0);
2610 if (afs_gr & PRSFS_DELETE)
2611 *granted |= FILE_DELETE_CHILD | DELETE;
2612 if (afs_gr & PRSFS_LOCK)
2614 if (afs_gr & PRSFS_ADMINISTER)
2617 *granted |= SYNCHRONIZE | READ_CONTROL;
2619 /* don't give more access than what was requested */
2621 osi_Log3(afsd_logp, "RDR_CheckAccess SUCCESS scp=0x%p requested=0x%x granted=0x%x", scp, access, *granted);
2623 osi_Log2(afsd_logp, "RDR_CheckAccess FAILURE scp=0x%p code=0x%x",
2630 RDR_OpenFileEntry( IN cm_user_t *userp,
2631 IN AFSFileID FileId,
2632 IN AFSFileOpenCB *OpenCB,
2635 IN DWORD ResultBufferLength,
2636 IN OUT AFSCommResult **ResultCB)
2638 AFSFileOpenResultCB *pResultCB = NULL;
2639 cm_scache_t *scp = NULL;
2640 cm_user_t *sysUserp = NULL;
2642 cm_lock_data_t *ldp = NULL;
2649 req.flags |= CM_REQ_WOW64;
2651 osi_Log4(afsd_logp, "RDR_OpenFileEntry File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2652 FileId.Cell, FileId.Volume,
2653 FileId.Vnode, FileId.Unique);
2655 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2657 osi_Log0(afsd_logp, "RDR_OpenFileEntry out of memory");
2663 sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2665 pResultCB = (AFSFileOpenResultCB *)(*ResultCB)->ResultData;
2667 /* Process the release */
2668 Fid.cell = FileId.Cell;
2669 Fid.volume = FileId.Volume;
2670 Fid.vnode = FileId.Vnode;
2671 Fid.unique = FileId.Unique;
2672 Fid.hash = FileId.Hash;
2674 code = cm_GetSCache(&Fid, &scp, userp, &req);
2676 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2677 (*ResultCB)->ResultStatus = status;
2678 osi_Log2(afsd_logp, "RDR_OpenFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2683 lock_ObtainWrite(&scp->rw);
2684 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2685 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2687 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2688 (*ResultCB)->ResultStatus = status;
2689 lock_ReleaseWrite(&scp->rw);
2690 cm_ReleaseSCache(scp);
2691 osi_Log3(afsd_logp, "RDR_OpenFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2696 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2697 lock_ReleaseWrite(&scp->rw);
2699 sysUserp = RDR_GetLocalSystemUser();
2702 * Skip the open check if the request is coming from the local system account.
2703 * The local system has no tokens and therefore any requests sent to a file
2704 * server will fail. Unfortunately, there are special system processes that
2705 * perform actions on files and directories in preparation for memory mapping
2706 * executables. If the open check fails, the real request from the user process
2707 * will never be issued.
2709 * Permitting the file system to allow subsequent operations to proceed does
2710 * not compromise security. All requests to obtain file data or directory
2711 * enumerations will subsequently fail if they are not submitted under the
2712 * context of a process for that have access to the necessary credentials.
2715 if ( userp == sysUserp)
2717 osi_Log1(afsd_logp, "RDR_OpenFileEntry LOCAL_SYSTEM access check skipped scp=0x%p",
2719 pResultCB->GrantedAccess = OpenCB->DesiredAccess;
2720 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2731 "RDR_OpenFileEntry repeating open check scp=0x%p userp=0x%p code=0x%x",
2734 code = cm_CheckNTOpen(scp, OpenCB->DesiredAccess, OpenCB->ShareAccess,
2736 OpenCB->ProcessId, OpenCB->Identifier,
2739 code = RDR_CheckAccess(scp, userp, &req, OpenCB->DesiredAccess, &pResultCB->GrantedAccess);
2740 cm_CheckNTOpenDone(scp, userp, &req, &ldp);
2741 } while (count < 100 && (code == CM_ERROR_RETRY || code == CM_ERROR_WOULDBLOCK));
2745 * If we are restricting sharing, we should do so with a suitable
2748 if (code == 0 && scp->fileType == CM_SCACHETYPE_FILE && !(OpenCB->ShareAccess & FILE_SHARE_WRITE)) {
2750 LARGE_INTEGER LOffset, LLength;
2753 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2754 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2755 LLength.HighPart = 0;
2756 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2759 * If we are not opening the file for writing, then we don't
2760 * try to get an exclusive lock. No one else should be able to
2761 * get an exclusive lock on the file anyway, although someone
2762 * else can get a shared lock.
2764 if ((OpenCB->ShareAccess & FILE_SHARE_READ) || !(OpenCB->DesiredAccess & AFS_ACCESS_WRITE))
2766 sLockType = LOCKING_ANDX_SHARED_LOCK;
2771 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, OpenCB->Identifier);
2773 lock_ObtainWrite(&scp->rw);
2774 code = cm_Lock(scp, sLockType, LOffset, LLength, key, 0, userp, &req, NULL);
2775 lock_ReleaseWrite(&scp->rw);
2778 code = CM_ERROR_SHARING_VIOLATION;
2779 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2781 if (sLockType == LOCKING_ANDX_SHARED_LOCK)
2782 pResultCB->FileAccess = AFS_FILE_ACCESS_SHARED;
2784 pResultCB->FileAccess = AFS_FILE_ACCESS_EXCLUSIVE;
2787 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2790 cm_ReleaseUser(sysUserp);
2791 if (code == 0 && bHoldFid)
2792 RDR_FlagScpInUse( scp, FALSE );
2793 cm_ReleaseSCache(scp);
2796 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2797 (*ResultCB)->ResultStatus = status;
2798 osi_Log2(afsd_logp, "RDR_OpenFileEntry FAILURE code=0x%x status=0x%x",
2801 (*ResultCB)->ResultStatus = 0;
2802 (*ResultCB)->ResultBufferLength = sizeof( AFSFileOpenResultCB);
2803 osi_Log0(afsd_logp, "RDR_OpenFileEntry SUCCESS");
2809 RDR_ReleaseFileAccess( IN cm_user_t *userp,
2810 IN AFSFileID FileId,
2811 IN AFSFileAccessReleaseCB *ReleaseFileCB,
2813 IN DWORD ResultBufferLength,
2814 IN OUT AFSCommResult **ResultCB)
2817 unsigned int sLockType;
2818 LARGE_INTEGER LOffset, LLength;
2819 cm_scache_t *scp = NULL;
2827 req.flags |= CM_REQ_WOW64;
2829 osi_Log4(afsd_logp, "RDR_ReleaseFileAccess File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2830 FileId.Cell, FileId.Volume,
2831 FileId.Vnode, FileId.Unique);
2833 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2835 osi_Log0(afsd_logp, "RDR_ReleaseFileAccess out of memory");
2839 memset( *ResultCB, '\0', sizeof( AFSCommResult));
2841 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_NOLOCK)
2844 /* Process the release */
2845 Fid.cell = FileId.Cell;
2846 Fid.volume = FileId.Volume;
2847 Fid.vnode = FileId.Vnode;
2848 Fid.unique = FileId.Unique;
2849 Fid.hash = FileId.Hash;
2851 code = cm_GetSCache(&Fid, &scp, userp, &req);
2853 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2854 (*ResultCB)->ResultStatus = status;
2855 osi_Log2(afsd_logp, "RDR_ReleaseFileAccess cm_GetSCache FID failure code=0x%x status=0x%x",
2860 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_SHARED)
2861 sLockType = LOCKING_ANDX_SHARED_LOCK;
2865 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, ReleaseFileCB->Identifier);
2867 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2868 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2869 LLength.HighPart = 0;
2870 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2872 lock_ObtainWrite(&scp->rw);
2874 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
2877 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
2879 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
2881 if (code == CM_ERROR_RANGE_NOT_LOCKED)
2883 osi_Log3(afsd_logp, "RDR_ReleaseFileAccess Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
2884 ReleaseFileCB->FileAccess, ReleaseFileCB->ProcessId, ReleaseFileCB->Identifier);
2888 lock_ReleaseWrite(&scp->rw);
2890 osi_Log0(afsd_logp, "RDR_ReleaseFileAccessEntry SUCCESS");
2894 HexCheckSum(unsigned char * buf, int buflen, unsigned char * md5cksum)
2897 static char tr[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
2900 return "buffer length too small to HexCheckSum";
2902 for (i=0;i<16;i++) {
2905 buf[i*2] = tr[k / 16];
2906 buf[i*2+1] = tr[k % 16];
2914 * Extent requests from the file system are triggered when a file
2915 * page is not resident in the Windows cache. The file system is
2916 * responsible for loading the page but cannot block the request
2917 * while doing so. The AFS Redirector forwards the requests to
2918 * the AFS cache manager while indicating to Windows that the page
2919 * is not yet available. A polling operation will then ensue with
2920 * the AFS Redirector issuing a RDR_RequestFileExtentsXXX call for
2921 * each poll attempt. As each request is received and processed
2922 * by a separate worker thread in the service, this can lead to
2923 * contention by multiple threads attempting to claim the same
2924 * cm_buf_t objects. Therefore, it is important that
2926 * (a) the service avoid processing more than one overlapping
2927 * extent request at a time
2928 * (b) background daemon processing be used to avoid blocking
2931 * Beginning with the 20091122 build of the redirector, the redirector
2932 * will not issue an additional RDR_RequestFileExtentsXXX call for
2933 * each poll request. Instead, afsd_service is required to track
2934 * the requests and return them to the redirector or fail the
2935 * portions of the request that cannot be satisfied.
2937 * The request processing returns any extents that can be returned
2938 * immediately to the redirector. The rest of the requested range(s)
2939 * are queued as background operations using RDR_BkgFetch().
2942 /* do the background fetch. */
2944 RDR_BkgFetch(cm_scache_t *scp, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4,
2945 cm_user_t *userp, cm_req_t *reqp)
2951 osi_hyper_t fetched;
2952 osi_hyper_t tblocksize;
2955 cm_buf_t *bufp = NULL;
2956 DWORD dwResultBufferLength;
2957 AFSSetFileExtentsCB *pResultCB;
2961 int reportErrorToRedir = 0;
2962 int force_retry = 0;
2964 FileId.Cell = scp->fid.cell;
2965 FileId.Volume = scp->fid.volume;
2966 FileId.Vnode = scp->fid.vnode;
2967 FileId.Unique = scp->fid.unique;
2968 FileId.Hash = scp->fid.hash;
2970 if ((GetTickCount() - reqp->startTime) / 1000 > HardDeadtimeout * 5) {
2971 RDR_SetFileStatus( &scp->fid, &userp->authgroup, STATUS_IO_TIMEOUT);
2975 fetched.LowPart = 0;
2976 fetched.HighPart = 0;
2977 tblocksize = ConvertLongToLargeInteger(cm_data.buf_blockSize);
2980 length.LowPart = p3;
2981 length.HighPart = p4;
2983 end = LargeIntegerAdd(base, length);
2985 osi_Log5(afsd_logp, "Starting BKG Fetch scp 0x%p offset 0x%x:%x length 0x%x:%x",
2986 scp, p2, p1, p4, p3);
2989 * Make sure we have a callback.
2990 * This is necessary so that we can return access denied
2991 * if a callback cannot be granted.
2993 lock_ObtainWrite(&scp->rw);
2994 code = cm_SyncOp(scp, NULL, userp, reqp, PRSFS_READ,
2995 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2997 lock_ReleaseWrite(&scp->rw);
2998 osi_Log2(afsd_logp, "RDR_BkgFetch cm_SyncOp failure scp=0x%p code=0x%x",
3000 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
3001 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3004 lock_ReleaseWrite(&scp->rw);
3006 dwResultBufferLength = (DWORD)(sizeof( AFSSetFileExtentsCB) + sizeof( AFSSetFileExtentsCB) * (length.QuadPart / cm_data.blockSize + 1));
3007 pResultCB = (AFSSetFileExtentsCB *)malloc( dwResultBufferLength );
3009 return CM_ERROR_RETRY;
3011 memset( pResultCB, '\0', dwResultBufferLength );
3012 pResultCB->FileId = FileId;
3014 for ( code = 0, offset = base;
3015 code == 0 && LargeIntegerLessThan(offset, end);
3016 offset = LargeIntegerAdd(offset, tblocksize) )
3018 int bBufRelease = TRUE;
3021 lock_ReleaseWrite(&scp->rw);
3025 code = buf_Get(scp, &offset, reqp, &bufp);
3028 * any error from buf_Get() is non-fatal.
3029 * we need to re-queue this extent fetch.
3036 lock_ObtainWrite(&scp->rw);
3040 code = cm_GetBuffer(scp, bufp, NULL, userp, reqp);
3042 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3043 #ifdef VALIDATE_CHECK_SUM
3049 if (bufp->flags & CM_BUF_DIRTY)
3050 cm_BufWrite(scp, &bufp->offset, cm_data.buf_blockSize, CM_BUF_WRITE_SCP_LOCKED, userp, reqp);
3052 lock_ObtainWrite(&buf_globalLock);
3053 if (!(bufp->flags & CM_BUF_DIRTY) &&
3054 bufp->cmFlags == 0 &&
3055 !(bufp->qFlags & CM_BUF_QREDIR)) {
3056 buf_InsertToRedirQueue(scp, bufp);
3057 lock_ReleaseWrite(&buf_globalLock);
3059 #ifdef VALIDATE_CHECK_SUM
3060 buf_ComputeCheckSum(bufp);
3062 pResultCB->FileExtents[count].Flags = 0;
3063 pResultCB->FileExtents[count].FileOffset.QuadPart = bufp->offset.QuadPart;
3064 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3065 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3067 fetched = LargeIntegerAdd(fetched, tblocksize);
3068 bBufRelease = FALSE;
3070 #ifdef VALIDATE_CHECK_SUM
3072 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3073 snprintf( dbgstr, 1024,
3074 "RDR_BkgFetch md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3076 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3077 pResultCB->FileExtents[count].FileOffset.HighPart,
3078 pResultCB->FileExtents[count].FileOffset.LowPart,
3079 pResultCB->FileExtents[count].CacheOffset.HighPart,
3080 pResultCB->FileExtents[count].CacheOffset.LowPart);
3081 OutputDebugStringA( dbgstr);
3084 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3085 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3087 lock_ReleaseWrite(&buf_globalLock);
3088 if ((bufp->cmFlags != 0) || (bufp->flags & CM_BUF_DIRTY)) {
3089 /* An I/O operation is already in progress */
3091 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",
3092 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3094 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3095 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3099 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3100 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3104 * depending on what the error from cm_GetBuffer is
3105 * it may or may not be fatal. Only return fatal errors.
3106 * Re-queue a request for others.
3108 osi_Log5(afsd_logp, "RDR_BkgFetch Extent2FS FAILURE bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x code 0x%x",
3109 bufp, offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize, code);
3111 case CM_ERROR_NOACCESS:
3112 case CM_ERROR_NOSUCHFILE:
3113 case CM_ERROR_NOSUCHPATH:
3114 case CM_ERROR_NOSUCHVOLUME:
3115 case CM_ERROR_NOSUCHCELL:
3116 case CM_ERROR_INVAL:
3117 case CM_ERROR_BADFD:
3118 case CM_ERROR_CLOCKSKEW:
3120 case CM_ERROR_QUOTA:
3121 case CM_ERROR_LOCK_CONFLICT:
3123 * these are fatal errors. deliver what we can
3126 reportErrorToRedir = 1;
3130 * non-fatal errors. re-queue the exent
3132 code = CM_ERROR_RETRY;
3142 lock_ObtainWrite(&scp->rw);
3146 /* wakeup anyone who is waiting */
3147 if (scp->flags & CM_SCACHEFLAG_WAITING) {
3148 osi_Log1(afsd_logp, "RDR Bkg Fetch Waking scp 0x%p", scp);
3149 osi_Wakeup((LONG_PTR) &scp->flags);
3151 lock_ReleaseWrite(&scp->rw);
3154 pResultCB->ExtentCount = count;
3155 RDR_SetFileExtents( pResultCB, dwResultBufferLength);
3159 if (reportErrorToRedir) {
3160 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
3161 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3164 osi_Log4(afsd_logp, "Ending BKG Fetch scp 0x%p code 0x%x fetched 0x%x:%x",
3165 scp, code, fetched.HighPart, fetched.LowPart);
3167 return force_retry ? CM_ERROR_RETRY : code;
3172 RDR_RequestFileExtentsAsync( IN cm_user_t *userp,
3173 IN AFSFileID FileId,
3174 IN AFSRequestExtentsCB *RequestExtentsCB,
3176 IN OUT DWORD * ResultBufferLength,
3177 IN OUT AFSSetFileExtentsCB **ResultCB)
3179 AFSSetFileExtentsCB *pResultCB = NULL;
3183 cm_scache_t *scp = NULL;
3186 afs_uint32 code = 0;
3188 LARGE_INTEGER ByteOffset, BeginOffset, EndOffset, QueueOffset;
3189 afs_uint32 QueueLength;
3191 BOOLEAN bBufRelease = TRUE;
3195 req.flags |= CM_REQ_WOW64;
3196 req.flags |= CM_REQ_NORETRY;
3198 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3199 FileId.Cell, FileId.Volume,
3200 FileId.Vnode, FileId.Unique);
3201 osi_Log4(afsd_logp, "... Flags 0x%x ByteOffset 0x%x:%x Length 0x%x",
3202 RequestExtentsCB->Flags,
3203 RequestExtentsCB->ByteOffset.HighPart, RequestExtentsCB->ByteOffset.LowPart,
3204 RequestExtentsCB->Length);
3205 Length = sizeof( AFSSetFileExtentsCB) + sizeof( AFSFileExtentCB) * (RequestExtentsCB->Length / cm_data.blockSize + 1);
3207 pResultCB = *ResultCB = (AFSSetFileExtentsCB *)malloc( Length );
3208 if (*ResultCB == NULL) {
3209 *ResultBufferLength = 0;
3212 *ResultBufferLength = Length;
3214 memset( pResultCB, '\0', Length );
3215 pResultCB->FileId = FileId;
3217 Fid.cell = FileId.Cell;
3218 Fid.volume = FileId.Volume;
3219 Fid.vnode = FileId.Vnode;
3220 Fid.unique = FileId.Unique;
3221 Fid.hash = FileId.Hash;
3223 code = cm_GetSCache(&Fid, &scp, userp, &req);
3225 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync cm_GetSCache FID failure code=0x%x",
3227 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3232 * Make sure we have a callback.
3233 * This is necessary so that we can return access denied
3234 * if a callback cannot be granted.
3236 lock_ObtainWrite(&scp->rw);
3237 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_READ,
3238 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3239 lock_ReleaseWrite(&scp->rw);
3241 cm_ReleaseSCache(scp);
3242 osi_Log2(afsd_logp, "RDR_RequestFileExtentsAsync cm_SyncOp failure scp=0x%p code=0x%x",
3244 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3245 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3249 /* Allocate the extents from the buffer package */
3251 ByteOffset = BeginOffset = RequestExtentsCB->ByteOffset,
3252 EndOffset.QuadPart = ByteOffset.QuadPart + RequestExtentsCB->Length;
3253 code == 0 && ByteOffset.QuadPart < EndOffset.QuadPart;
3254 ByteOffset.QuadPart += cm_data.blockSize)
3256 BOOL bHaveBuffer = FALSE;
3259 thyper.QuadPart = ByteOffset.QuadPart;
3261 code = buf_Get(scp, &thyper, &req, &bufp);
3263 lock_ObtainMutex(&bufp->mx);
3266 if (bufp->qFlags & CM_BUF_QREDIR) {
3268 } else if (bufp->flags & CM_BUF_DIRTY) {
3269 bHaveBuffer = FALSE;
3271 code = buf_CleanAsyncLocked(scp, bufp, &req, 0, NULL);
3276 case CM_ERROR_RETRY:
3277 /* Couldn't flush it, obtain it asynchronously so we don't block the thread. */
3278 bHaveBuffer = FALSE;
3282 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3283 RDR_SetFileStatus(&FileId, &userp->authgroup, status);
3284 bHaveBuffer = FALSE;
3289 osi_hyper_t minLength; /* effective end of file */
3291 lock_ObtainRead(&scp->rw);
3292 bHaveBuffer = cm_HaveBuffer(scp, bufp, TRUE);
3294 if (LargeIntegerGreaterThan(scp->length, scp->serverLength))
3295 minLength = scp->serverLength;
3297 minLength = scp->length;
3300 LargeIntegerGreaterThanOrEqualTo(bufp->offset, minLength)) {
3301 memset(bufp->datap, 0, cm_data.buf_blockSize);
3302 bufp->dataVersion = scp->dataVersion;
3305 else if ((RequestExtentsCB->Flags & AFS_EXTENT_FLAG_CLEAN) &&
3306 ByteOffset.QuadPart <= bufp->offset.QuadPart &&
3307 EndOffset.QuadPart >= bufp->offset.QuadPart + cm_data.blockSize)
3309 memset(bufp->datap, 0, cm_data.blockSize);
3310 bufp->dataVersion = scp->dataVersion;
3311 buf_SetDirty(bufp, &req, 0, cm_data.blockSize, userp);
3314 lock_ReleaseRead(&scp->rw);
3318 * if this buffer is already up to date, skip it.
3321 if (ByteOffset.QuadPart == BeginOffset.QuadPart) {
3322 BeginOffset.QuadPart += cm_data.blockSize;
3324 QueueLength = (afs_uint32)(ByteOffset.QuadPart - BeginOffset.QuadPart);
3325 QueueOffset = BeginOffset;
3326 BeginOffset = ByteOffset;
3329 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3330 #ifdef VALIDATE_CHECK_SUM
3336 lock_ObtainWrite(&buf_globalLock);
3337 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3338 buf_InsertToRedirQueue(scp, bufp);
3339 lock_ReleaseWrite(&buf_globalLock);
3341 #ifdef VALIDATE_CHECK_SUM
3342 buf_ComputeCheckSum(bufp);
3344 /* we already have the buffer, return it now */
3345 pResultCB->FileExtents[count].Flags = 0;
3346 pResultCB->FileExtents[count].FileOffset = ByteOffset;
3347 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3348 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3351 bBufRelease = FALSE;
3353 #ifdef VALIDATE_CHECK_SUM
3355 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3356 snprintf( dbgstr, 1024,
3357 "RDR_RequestFileExtentsAsync md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3359 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3360 pResultCB->FileExtents[count].FileOffset.HighPart,
3361 pResultCB->FileExtents[count].FileOffset.LowPart,
3362 pResultCB->FileExtents[count].CacheOffset.HighPart,
3363 pResultCB->FileExtents[count].CacheOffset.LowPart);
3364 OutputDebugStringA( dbgstr);
3367 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3368 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3370 lock_ReleaseWrite(&buf_globalLock);
3375 * The service is not handing off the extent to the redirector in this pass.
3376 * However, we know the buffer is in recent use so move the buffer to the
3377 * front of the queue
3379 lock_ObtainWrite(&buf_globalLock);
3380 buf_MoveToHeadOfRedirQueue(scp, bufp);
3381 lock_ReleaseWrite(&buf_globalLock);
3383 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3384 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3388 lock_ReleaseMutex(&bufp->mx);
3393 cm_QueueBKGRequest(scp, RDR_BkgFetch, QueueOffset.LowPart, QueueOffset.HighPart,
3394 QueueLength, 0, userp, &req);
3395 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3396 QueueOffset.HighPart, QueueOffset.LowPart, QueueLength);
3399 /* No error from buf_Get() can be fatal */
3400 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync buf_Get FAILURE offset 0x%x:%x code 0x%x",
3401 BeginOffset.HighPart, BeginOffset.LowPart, code);
3405 if (BeginOffset.QuadPart != EndOffset.QuadPart) {
3406 afs_uint32 length = (afs_uint32)(EndOffset.QuadPart - BeginOffset.QuadPart);
3408 cm_QueueBKGRequest(scp, RDR_BkgFetch, BeginOffset.LowPart, BeginOffset.HighPart,
3409 length, 0, userp, &req);
3410 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3411 BeginOffset.HighPart, BeginOffset.LowPart, length);
3413 cm_ReleaseSCache(scp);
3415 (*ResultCB)->ExtentCount = count;
3416 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync replying with 0x%x extent records", count);
3421 * When processing an extent release the extents must be accepted back by
3422 * the service even if there is an error condition returned to the redirector.
3423 * For example, there may no longer be a callback present or the file may
3424 * have been deleted on the file server. Regardless, the extents must be
3425 * put back into the pool.
3428 RDR_ReleaseFileExtents( IN cm_user_t *userp,
3429 IN AFSFileID FileId,
3430 IN AFSReleaseExtentsCB *ReleaseExtentsCB,
3432 IN DWORD ResultBufferLength,
3433 IN OUT AFSCommResult **ResultCB)
3436 cm_scache_t *scp = NULL;
3447 #ifdef VALIDATE_CHECK_SUM
3448 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3455 req.flags |= CM_REQ_WOW64;
3457 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3458 FileId.Cell, FileId.Volume,
3459 FileId.Vnode, FileId.Unique);
3461 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
3467 sizeof( AFSCommResult));
3469 /* Process the release */
3470 Fid.cell = FileId.Cell;
3471 Fid.volume = FileId.Volume;
3472 Fid.vnode = FileId.Vnode;
3473 Fid.unique = FileId.Unique;
3474 Fid.hash = FileId.Hash;
3476 code = cm_GetSCache(&Fid, &scp, userp, &req);
3478 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3479 (*ResultCB)->ResultStatus = status;
3480 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents cm_GetSCache FID failure code=0x%x status=0x%x",
3484 deleted = scp && (scp->flags & CM_SCACHEFLAG_DELETED);
3487 * We do not stop processing as a result of being unable to find the cm_scache object.
3488 * If this occurs something really bad has happened since the cm_scache object must have
3489 * been recycled while extents were held by the redirector. However, we will be resilient
3490 * and carry on without it.
3492 * If the file is known to be deleted, there is no point attempting to ask the
3493 * file server about it or update the attributes.
3495 if (scp && ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart &&
3500 memset(&setAttr, 0, sizeof(cm_attr_t));
3501 lock_ObtainWrite(&scp->rw);
3502 if (ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3504 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents new length fid vol 0x%x vno 0x%x length 0x%x:%x",
3505 scp->fid.volume, scp->fid.vnode,
3506 ReleaseExtentsCB->AllocationSize.HighPart,
3507 ReleaseExtentsCB->AllocationSize.LowPart);
3509 setAttr.mask |= CM_ATTRMASK_LENGTH;
3510 setAttr.length.LowPart = ReleaseExtentsCB->AllocationSize.LowPart;
3511 setAttr.length.HighPart = ReleaseExtentsCB->AllocationSize.HighPart;
3513 lock_ReleaseWrite(&scp->rw);
3515 code = cm_SetAttr(scp, &setAttr, userp, &req);
3518 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3519 AFSFileExtentCB * pExtent = &ReleaseExtentsCB->FileExtents[count];
3521 thyper.QuadPart = pExtent->FileOffset.QuadPart;
3523 bufp = buf_Find(&Fid, &thyper);
3525 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
3526 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3527 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3528 Fid.volume, Fid.vnode,
3529 pExtent->FileOffset.HighPart,
3530 pExtent->FileOffset.LowPart);
3531 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
3532 pExtent->CacheOffset.HighPart,
3533 pExtent->CacheOffset.LowPart);
3535 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3536 Fid.volume, Fid.vnode,
3537 pExtent->FileOffset.HighPart,
3538 pExtent->FileOffset.LowPart);
3539 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
3540 pExtent->CacheOffset.HighPart,
3541 pExtent->CacheOffset.LowPart);
3547 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
3548 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3549 Fid.volume, Fid.vnode,
3550 pExtent->FileOffset.HighPart,
3551 pExtent->FileOffset.LowPart);
3552 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
3553 pExtent->CacheOffset.HighPart,
3554 pExtent->CacheOffset.LowPart);
3556 /* Move the buffer to the front of the queue */
3557 lock_ObtainWrite(&buf_globalLock);
3558 buf_MoveToHeadOfRedirQueue(scp, bufp);
3559 lock_ReleaseWrite(&buf_globalLock);
3564 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
3565 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3566 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x not held by file system",
3567 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
3568 pExtent->FileOffset.LowPart);
3569 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3570 pExtent->CacheOffset.HighPart,
3571 pExtent->CacheOffset.LowPart);
3573 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents bufp 0x%p vno 0x%x foffset 0x%x:%x",
3574 bufp, bufp->fid.vnode, pExtent->FileOffset.HighPart,
3575 pExtent->FileOffset.LowPart);
3576 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3577 pExtent->CacheOffset.HighPart,
3578 pExtent->CacheOffset.LowPart);
3580 if (pExtent->Flags || ReleaseExtentsCB->Flags) {
3581 lock_ObtainMutex(&bufp->mx);
3582 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
3583 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
3585 if (bufp->qFlags & CM_BUF_QREDIR) {
3586 lock_ObtainWrite(&buf_globalLock);
3587 if (bufp->qFlags & CM_BUF_QREDIR) {
3588 buf_RemoveFromRedirQueue(scp, bufp);
3589 buf_ReleaseLocked(bufp, TRUE);
3591 lock_ReleaseWrite(&buf_globalLock);
3594 snprintf( dbgstr, 1024,
3595 "RDR_ReleaseFileExtents releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3596 Fid.volume, Fid.vnode, Fid.unique,
3597 pExtent->FileOffset.HighPart,
3598 pExtent->FileOffset.LowPart,
3599 pExtent->CacheOffset.HighPart,
3600 pExtent->CacheOffset.LowPart);
3601 OutputDebugStringA( dbgstr);
3606 snprintf( dbgstr, 1024,
3607 "RDR_ReleaseFileExtents not releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3608 Fid.volume, Fid.vnode, Fid.unique,
3609 pExtent->FileOffset.HighPart,
3610 pExtent->FileOffset.LowPart,
3611 pExtent->CacheOffset.HighPart,
3612 pExtent->CacheOffset.LowPart);
3613 OutputDebugStringA( dbgstr);
3615 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
3616 Fid.volume, Fid.vnode,
3617 pExtent->FileOffset.HighPart,
3618 pExtent->FileOffset.LowPart);
3619 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3620 pExtent->CacheOffset.HighPart,
3621 pExtent->CacheOffset.LowPart);
3624 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
3625 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY) )
3627 #ifdef VALIDATE_CHECK_SUM
3629 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3633 * if the saved checksum matches the checksum of the current state of the buffer
3634 * then the buffer is the same as what was given to the kernel.
3636 if ( buf_ValidateCheckSum(bufp) ) {
3637 buf_ComputeCheckSum(bufp);
3639 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3642 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
3643 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3645 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3648 snprintf( dbgstr, 1024,
3649 "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",
3650 md5dbg, md5dbg2,md5dbg3,
3651 Fid.volume, Fid.vnode, Fid.unique,
3652 pExtent->FileOffset.HighPart,
3653 pExtent->FileOffset.LowPart,
3654 pExtent->CacheOffset.HighPart,
3655 pExtent->CacheOffset.LowPart);
3656 OutputDebugStringA( dbgstr);
3658 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
3659 Fid.volume, Fid.vnode,
3660 pExtent->FileOffset.HighPart,
3661 pExtent->FileOffset.LowPart);
3662 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3663 pExtent->CacheOffset.HighPart,
3664 pExtent->CacheOffset.LowPart);
3665 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3669 snprintf( dbgstr, 1024,
3670 "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",
3671 md5dbg, md5dbg2, md5dbg3,
3672 Fid.volume, Fid.vnode, Fid.unique,
3673 pExtent->FileOffset.HighPart,
3674 pExtent->FileOffset.LowPart,
3675 pExtent->CacheOffset.HighPart,
3676 pExtent->CacheOffset.LowPart);
3677 OutputDebugStringA( dbgstr);
3679 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3680 Fid.volume, Fid.vnode,
3681 pExtent->FileOffset.HighPart,
3682 pExtent->FileOffset.LowPart);
3683 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3684 pExtent->CacheOffset.HighPart,
3685 pExtent->CacheOffset.LowPart);
3689 snprintf( dbgstr, 1024,
3690 "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",
3691 Fid.volume, Fid.vnode, Fid.unique,
3692 pExtent->FileOffset.HighPart,
3693 pExtent->FileOffset.LowPart,
3694 pExtent->CacheOffset.HighPart,
3695 pExtent->CacheOffset.LowPart);
3696 OutputDebugStringA( dbgstr);
3698 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3699 Fid.volume, Fid.vnode,
3700 pExtent->FileOffset.HighPart,
3701 pExtent->FileOffset.LowPart);
3702 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3703 pExtent->CacheOffset.HighPart,
3704 pExtent->CacheOffset.LowPart);
3707 buf_ComputeCheckSum(bufp);
3709 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3711 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3712 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
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);
3724 snprintf( dbgstr, 1024,
3725 "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",
3726 md5dbg, md5dbg2,md5dbg3,
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 snprintf( dbgstr, 1024,
3736 "RDR_ReleaseFileExtents dirty flag set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3737 Fid.volume, Fid.vnode, Fid.unique,
3738 pExtent->FileOffset.HighPart,
3739 pExtent->FileOffset.LowPart,
3740 pExtent->CacheOffset.HighPart,
3741 pExtent->CacheOffset.LowPart);
3742 OutputDebugStringA( dbgstr);
3745 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3748 #else /* !VALIDATE_CHECK_SUM */
3749 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3751 #endif /* VALIDATE_CHECK_SUM */
3753 #ifdef VALIDATE_CHECK_SUM
3756 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3758 if ( !buf_ValidateCheckSum(bufp) ) {
3759 buf_ComputeCheckSum(bufp);
3761 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3762 snprintf( dbgstr, 1024,
3763 "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",
3765 Fid.volume, Fid.vnode, Fid.unique,
3766 pExtent->FileOffset.HighPart,
3767 pExtent->FileOffset.LowPart,
3768 pExtent->CacheOffset.HighPart,
3769 pExtent->CacheOffset.LowPart);
3770 OutputDebugStringA( dbgstr);
3772 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set but extent has changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3773 Fid.volume, Fid.vnode,
3774 pExtent->FileOffset.HighPart,
3775 pExtent->FileOffset.LowPart);
3776 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3777 pExtent->CacheOffset.HighPart,
3778 pExtent->CacheOffset.LowPart);
3779 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3782 buf_ComputeCheckSum(bufp);
3784 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3785 snprintf( dbgstr, 1024,
3786 "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3787 Fid.volume, Fid.vnode, Fid.unique,
3788 pExtent->FileOffset.HighPart,
3789 pExtent->FileOffset.LowPart,
3790 pExtent->CacheOffset.HighPart,
3791 pExtent->CacheOffset.LowPart);
3792 OutputDebugStringA( dbgstr);
3794 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x foffset 0x%x:%x",
3795 Fid.volume, Fid.vnode,
3796 pExtent->FileOffset.HighPart,
3797 pExtent->FileOffset.LowPart);
3798 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3799 pExtent->CacheOffset.HighPart,
3800 pExtent->CacheOffset.LowPart);
3803 #endif /* VALIDATE_CHECK_SUM */
3804 lock_ReleaseMutex(&bufp->mx);
3809 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3812 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3813 if (wbp->datap == datap)
3818 snprintf( dbgstr, 1024,
3819 "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3820 Fid.volume, Fid.vnode, Fid.unique,
3821 pExtent->FileOffset.HighPart,
3822 pExtent->FileOffset.LowPart,
3823 pExtent->CacheOffset.HighPart,
3824 pExtent->CacheOffset.LowPart);
3825 OutputDebugStringA( dbgstr);
3827 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3828 Fid.volume, Fid.vnode,
3829 pExtent->FileOffset.HighPart,
3830 pExtent->FileOffset.LowPart);
3831 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3832 pExtent->CacheOffset.HighPart,
3833 pExtent->CacheOffset.LowPart);
3834 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3835 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3843 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3846 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3847 if (wbp->datap == datap)
3852 snprintf( dbgstr, 1024,
3853 "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3854 Fid.volume, Fid.vnode, Fid.unique,
3855 pExtent->FileOffset.HighPart,
3856 pExtent->FileOffset.LowPart,
3857 pExtent->CacheOffset.HighPart,
3858 pExtent->CacheOffset.LowPart);
3859 OutputDebugStringA( dbgstr);
3861 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3862 Fid.volume, Fid.vnode,
3863 pExtent->FileOffset.HighPart,
3864 pExtent->FileOffset.LowPart);
3865 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3866 pExtent->CacheOffset.HighPart,
3867 pExtent->CacheOffset.LowPart);
3868 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3869 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3874 if (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_FLUSH) {
3875 lock_ObtainWrite(&scp->rw);
3876 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3877 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3878 lock_ReleaseWrite(&scp->rw);
3880 code = cm_FSync(scp, userp, &req, FALSE);
3883 osi_hyper_t offset = {0,0};
3884 afs_uint32 length = 0;
3885 afs_uint32 rights = 0;
3887 lock_ObtainWrite(&scp->rw);
3888 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3889 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3890 lock_ReleaseWrite(&scp->rw);
3893 * there is at least one dirty extent on this file. queue up background store
3894 * requests for contiguous blocks
3896 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3897 if (ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart == offset.QuadPart + length &&
3898 length + cm_data.buf_blockSize <= cm_chunkSize)
3900 length += cm_data.buf_blockSize;
3902 if (!(offset.QuadPart == 0 && length == 0))
3903 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3904 length, 0, userp, &req);
3905 offset.QuadPart = ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart;
3906 length = cm_data.buf_blockSize;
3909 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3910 length, 0, userp, &req);
3913 cm_ReleaseSCache(scp);
3916 osi_Log5(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
3917 FileId.Cell, FileId.Volume,
3918 FileId.Vnode, FileId.Unique, released);
3919 if (code && code != CM_ERROR_WOULDBLOCK) {
3920 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3921 (*ResultCB)->ResultStatus = status;
3922 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents FAILURE code=0x%x status=0x%x",
3925 (*ResultCB)->ResultStatus = 0;
3926 osi_Log0(afsd_logp, "RDR_ReleaseFileExtents SUCCESS");
3928 (*ResultCB)->ResultBufferLength = 0;
3934 RDR_ProcessReleaseFileExtentsResult( IN AFSReleaseFileExtentsResultCB *ReleaseFileExtentsResultCB,
3935 IN DWORD ResultBufferLength)
3937 afs_uint32 code = 0;
3941 unsigned int fileno, extentno, total_extents = 0;
3942 AFSReleaseFileExtentsResultFileCB *pNextFileCB;
3944 #ifdef VALIDATE_CHECK_SUM
3945 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3951 for ( fileno = 0, pNextFileCB = &ReleaseFileExtentsResultCB->Files[0];
3952 fileno < ReleaseFileExtentsResultCB->FileCount;
3954 AFSReleaseFileExtentsResultFileCB *pFileCB = pNextFileCB;
3955 cm_user_t *userp = NULL;
3957 cm_scache_t * scp = NULL;
3963 userp = RDR_UserFromAuthGroup( &pFileCB->AuthGroup);
3965 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult %d.%d.%d.%d",
3966 pFileCB->FileId.Cell, pFileCB->FileId.Volume,
3967 pFileCB->FileId.Vnode, pFileCB->FileId.Unique);
3969 /* Process the release */
3970 Fid.cell = pFileCB->FileId.Cell;
3971 Fid.volume = pFileCB->FileId.Volume;
3972 Fid.vnode = pFileCB->FileId.Vnode;
3973 Fid.unique = pFileCB->FileId.Unique;
3974 Fid.hash = pFileCB->FileId.Hash;
3976 if (Fid.cell == 0) {
3977 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult Invalid FID %d.%d.%d.%d",
3978 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
3979 code = CM_ERROR_INVAL;
3983 code = cm_GetSCache(&Fid, &scp, userp, &req);
3985 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult cm_GetSCache FID failure code=0x%x",
3988 * A failure to find the cm_scache object cannot prevent the service
3989 * from accepting the extents back from the redirector.
3993 deleted = scp && (scp->flags & CM_SCACHEFLAG_DELETED);
3995 /* if the scp was not found, do not perform the length check */
3996 if (scp && (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart)) {
3999 memset(&setAttr, 0, sizeof(cm_attr_t));
4000 lock_ObtainWrite(&scp->rw);
4001 if (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart) {
4002 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult length change vol 0x%x vno 0x%x length 0x%x:%x",
4003 scp->fid.volume, scp->fid.vnode,
4004 pFileCB->AllocationSize.HighPart,
4005 pFileCB->AllocationSize.LowPart);
4006 setAttr.mask |= CM_ATTRMASK_LENGTH;
4007 setAttr.length.LowPart = pFileCB->AllocationSize.LowPart;
4008 setAttr.length.HighPart = pFileCB->AllocationSize.HighPart;
4010 lock_ReleaseWrite(&scp->rw);
4012 code = cm_SetAttr(scp, &setAttr, userp, &req);
4015 for ( extentno = 0; extentno < pFileCB->ExtentCount; total_extents++, extentno++ ) {
4016 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4018 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4020 bufp = buf_Find(&Fid, &thyper);
4022 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4023 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
4024 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4025 Fid.volume, Fid.vnode,
4026 pExtent->FileOffset.HighPart,
4027 pExtent->FileOffset.LowPart);
4028 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
4029 pExtent->CacheOffset.HighPart,
4030 pExtent->CacheOffset.LowPart);
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 UNKNOWN to redirector; owned by redirector",
4037 pExtent->CacheOffset.HighPart,
4038 pExtent->CacheOffset.LowPart);
4044 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
4045 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4046 Fid.volume, Fid.vnode,
4047 pExtent->FileOffset.HighPart,
4048 pExtent->FileOffset.LowPart);
4049 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
4050 pExtent->CacheOffset.HighPart,
4051 pExtent->CacheOffset.LowPart);
4053 /* Move the buffer to the front of the queue */
4054 lock_ObtainWrite(&buf_globalLock);
4055 buf_MoveToHeadOfRedirQueue(scp, bufp);
4056 lock_ReleaseWrite(&buf_globalLock);
4061 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
4062 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
4063 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4064 Fid.volume, Fid.vnode,
4065 pExtent->FileOffset.HighPart,
4066 pExtent->FileOffset.LowPart);
4067 osi_Log2(afsd_logp, "... coffset 0x%x:%x not held by file system",
4068 pExtent->CacheOffset.HighPart,
4069 pExtent->CacheOffset.LowPart);
4071 snprintf(dbgstr, 1024,
4072 "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",
4073 ReleaseFileExtentsResultCB->Flags, pExtent->Flags,
4074 Fid.volume, Fid.vnode, Fid.unique,
4075 pExtent->FileOffset.HighPart,
4076 pExtent->FileOffset.LowPart,
4077 pExtent->CacheOffset.HighPart,
4078 pExtent->CacheOffset.LowPart);
4079 OutputDebugStringA( dbgstr);
4082 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4083 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4084 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4086 if (pExtent->Flags || ReleaseFileExtentsResultCB->Flags) {
4087 lock_ObtainMutex(&bufp->mx);
4088 if ( (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
4089 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
4091 if (bufp->qFlags & CM_BUF_QREDIR) {
4092 lock_ObtainWrite(&buf_globalLock);
4093 if (bufp->qFlags & CM_BUF_QREDIR) {
4094 buf_RemoveFromRedirQueue(scp, bufp);
4095 buf_ReleaseLocked(bufp, TRUE);
4097 lock_ReleaseWrite(&buf_globalLock);
4101 snprintf(dbgstr, 1024,
4102 "RDR_ProcessReleaseFileExtentsResult extent released: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4103 Fid.volume, Fid.vnode, Fid.unique,
4104 pExtent->FileOffset.HighPart,
4105 pExtent->FileOffset.LowPart,
4106 pExtent->CacheOffset.HighPart,
4107 pExtent->CacheOffset.LowPart);
4108 OutputDebugStringA( dbgstr);
4113 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
4114 Fid.volume, Fid.vnode,
4115 pExtent->FileOffset.HighPart,
4116 pExtent->FileOffset.LowPart);
4117 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4118 pExtent->CacheOffset.HighPart,
4119 pExtent->CacheOffset.LowPart);
4121 snprintf(dbgstr, 1024,
4122 "RDR_ProcessReleaseFileExtentsResult not released! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4123 Fid.volume, Fid.vnode, Fid.unique,
4124 pExtent->FileOffset.HighPart,
4125 pExtent->FileOffset.LowPart,
4126 pExtent->CacheOffset.HighPart,
4127 pExtent->CacheOffset.LowPart);
4128 OutputDebugStringA( dbgstr);
4132 if ((ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
4133 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY))
4135 #ifdef VALIDATE_CHECK_SUM
4136 if ( buf_ValidateCheckSum(bufp) ) {
4138 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4139 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4140 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
4142 buf_ComputeCheckSum(bufp);
4144 HexCheckSum(md5dbg3, sizeof(md5dbg), bufp->md5cksum);
4146 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4148 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
4151 snprintf(dbgstr, 1024,
4152 "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",
4154 Fid.volume, Fid.vnode, Fid.unique,
4155 pExtent->FileOffset.HighPart,
4156 pExtent->FileOffset.LowPart,
4157 pExtent->CacheOffset.HighPart,
4158 pExtent->CacheOffset.LowPart);
4159 OutputDebugStringA( dbgstr);
4162 "RDR_ProcessReleaseFileExtentsResult dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
4163 Fid.volume, Fid.vnode,
4164 pExtent->FileOffset.HighPart,
4165 pExtent->FileOffset.LowPart);
4167 "... coffset 0x%x:%x",
4168 pExtent->CacheOffset.HighPart,
4169 pExtent->CacheOffset.LowPart);
4172 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4177 snprintf(dbgstr, 1024,
4178 "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",
4179 md5dbg, md5dbg2, md5dbg3,
4180 Fid.volume, Fid.vnode, Fid.unique,
4181 pExtent->FileOffset.HighPart,
4182 pExtent->FileOffset.LowPart,
4183 pExtent->CacheOffset.HighPart,
4184 pExtent->CacheOffset.LowPart);
4185 OutputDebugStringA( dbgstr);
4188 "RDR_ProcessReleaseFileExtentsResult dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
4189 Fid.volume, Fid.vnode,
4190 pExtent->FileOffset.HighPart,
4191 pExtent->FileOffset.LowPart);
4193 "... coffset 0x%x:%x",
4194 pExtent->CacheOffset.HighPart,
4195 pExtent->CacheOffset.LowPart);
4199 #else /* !VALIDATE_CHECK_SUM */
4201 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4205 snprintf(dbgstr, 1024,
4206 "RDR_ProcessReleaseFileExtentsResult dirty! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4207 Fid.volume, Fid.vnode, Fid.unique,
4208 pExtent->FileOffset.HighPart,
4209 pExtent->FileOffset.LowPart,
4210 pExtent->CacheOffset.HighPart,
4211 pExtent->CacheOffset.LowPart);
4212 OutputDebugStringA( dbgstr);
4214 #endif /* VALIDATE_CHECK_SUM */
4216 #ifdef VALIDATE_CHECK_SUM
4219 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4221 if (!buf_ValidateCheckSum(bufp) ) {
4222 buf_ComputeCheckSum(bufp);
4224 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4225 snprintf(dbgstr, 1024,
4226 "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",
4228 Fid.volume, Fid.vnode, Fid.unique,
4229 pExtent->FileOffset.HighPart,
4230 pExtent->FileOffset.LowPart,
4231 pExtent->CacheOffset.HighPart,
4232 pExtent->CacheOffset.LowPart);
4233 OutputDebugStringA( dbgstr);
4235 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult dirty flag NOT set but extent has changed! vol 0x%x vno 0x%x foffset 0x%x:%x",
4236 Fid.volume, Fid.vnode,
4237 pExtent->FileOffset.HighPart,
4238 pExtent->FileOffset.LowPart);
4239 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4240 pExtent->CacheOffset.HighPart,
4241 pExtent->CacheOffset.LowPart);
4246 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4250 buf_ComputeCheckSum(bufp);
4252 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4253 snprintf(dbgstr, 1024,
4254 "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",
4256 Fid.volume, Fid.vnode, Fid.unique,
4257 pExtent->FileOffset.HighPart,
4258 pExtent->FileOffset.LowPart,
4259 pExtent->CacheOffset.HighPart,
4260 pExtent->CacheOffset.LowPart);
4261 OutputDebugStringA( dbgstr);
4265 #endif /* VALIDATE_CHECK_SUM */
4266 lock_ReleaseMutex(&bufp->mx);
4270 /* CacheOffset doesn't match bufp->datap */
4271 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
4274 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
4275 if (wbp->datap == datap)
4280 snprintf(dbgstr, 1024,
4281 "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",
4282 Fid.volume, Fid.vnode, Fid.unique,
4283 pExtent->FileOffset.HighPart,
4284 pExtent->FileOffset.LowPart,
4285 pExtent->CacheOffset.HighPart,
4286 pExtent->CacheOffset.LowPart,
4288 OutputDebugStringA( dbgstr);
4290 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4291 Fid.volume, Fid.vnode,
4292 pExtent->FileOffset.HighPart,
4293 pExtent->FileOffset.LowPart);
4294 osi_Log3(afsd_logp, "... coffset 0x%x:%x flags 0x%x",
4295 pExtent->CacheOffset.HighPart,
4296 pExtent->CacheOffset.LowPart,
4299 osi_Log5(afsd_logp, "... coffset belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
4300 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
4302 osi_Log0(afsd_logp, "... coffset cannot be found");
4309 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4310 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4311 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
4312 pExtent->FileOffset.LowPart);
4313 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; cm_buf not found -- recycled?",
4314 pExtent->CacheOffset.HighPart,
4315 pExtent->CacheOffset.LowPart);
4321 snprintf(dbgstr, 1024,
4322 "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4323 Fid.volume, Fid.vnode, Fid.unique,
4324 pExtent->FileOffset.HighPart,
4325 pExtent->FileOffset.LowPart,
4326 pExtent->CacheOffset.HighPart,
4327 pExtent->CacheOffset.LowPart);
4328 OutputDebugStringA( dbgstr);
4330 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x foffset 0x%x:%x",
4331 Fid.volume, Fid.vnode,
4332 pExtent->FileOffset.HighPart,
4333 pExtent->FileOffset.LowPart);
4334 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4335 pExtent->CacheOffset.HighPart,
4336 pExtent->CacheOffset.LowPart);
4341 osi_hyper_t offset = {0,0};
4342 afs_uint32 length = 0;
4345 * there is at least one dirty extent on this file. queue up background store
4346 * requests for contiguous blocks
4348 for ( extentno = 0; extentno < pFileCB->ExtentCount; extentno++ ) {
4349 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4350 if (pExtent->FileOffset.QuadPart == offset.QuadPart + length &&
4351 length < cm_chunkSize) {
4352 length += cm_data.buf_blockSize;
4354 if (!(offset.QuadPart == 0 && length == 0))
4355 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4356 length, 0, userp, &req);
4357 offset.QuadPart = pExtent->FileOffset.QuadPart;
4358 length = cm_data.buf_blockSize;
4361 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4362 length, 0, userp, &req);
4365 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
4366 Fid.cell, Fid.volume, Fid.vnode, Fid.unique, released);
4370 cm_ReleaseUser(userp);
4372 cm_ReleaseSCache(scp);
4374 p = (char *)pFileCB;
4375 p += sizeof(AFSReleaseFileExtentsResultFileCB);
4376 p += sizeof(AFSFileExtentCB) * (pFileCB->ExtentCount - 1);
4377 pNextFileCB = (AFSReleaseFileExtentsResultFileCB *)p;
4380 if (total_extents == 0) {
4381 osi_Log0(afsd_logp, "RDR_ProcessReleaseFileExtentsResult is empty");
4382 code = CM_ERROR_RETRY;
4386 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult FAILURE code=0x%x", code);
4388 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult DONE code=0x%x", code);
4394 RDR_ReleaseFailedSetFileExtents( IN cm_user_t *userp,
4395 IN AFSSetFileExtentsCB *SetFileExtentsResultCB,
4396 IN DWORD ResultBufferLength)
4398 afs_uint32 code = 0;
4400 unsigned int extentno;
4402 cm_scache_t * scp = NULL;
4407 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFileExtents %d.%d.%d.%d",
4408 SetFileExtentsResultCB->FileId.Cell, SetFileExtentsResultCB->FileId.Volume,
4409 SetFileExtentsResultCB->FileId.Vnode, SetFileExtentsResultCB->FileId.Unique);
4411 /* Process the release */
4412 Fid.cell = SetFileExtentsResultCB->FileId.Cell;
4413 Fid.volume = SetFileExtentsResultCB->FileId.Volume;
4414 Fid.vnode = SetFileExtentsResultCB->FileId.Vnode;
4415 Fid.unique = SetFileExtentsResultCB->FileId.Unique;
4416 Fid.hash = SetFileExtentsResultCB->FileId.Hash;
4418 if (Fid.cell == 0) {
4419 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFile Invalid FID %d.%d.%d.%d",
4420 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
4421 code = CM_ERROR_INVAL;
4425 code = cm_GetSCache(&Fid, &scp, userp, &req);
4427 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents cm_GetSCache FID failure code=0x%x",
4429 /* Failure to find the cm_scache object cannot block return of the extents */
4432 for ( extentno = 0; extentno < SetFileExtentsResultCB->ExtentCount; extentno++ ) {
4435 AFSFileExtentCB *pExtent = &SetFileExtentsResultCB->FileExtents[extentno];
4437 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4439 bufp = buf_Find(&Fid, &thyper);
4441 osi_Log5(afsd_logp, "RDR_ReleaseFailedSetFileExtents bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4442 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4443 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4445 lock_ObtainMutex(&bufp->mx);
4446 if (bufp->qFlags & CM_BUF_QREDIR) {
4447 lock_ObtainWrite(&buf_globalLock);
4448 if (bufp->qFlags & CM_BUF_QREDIR) {
4449 buf_RemoveFromRedirQueue(scp, bufp);
4450 buf_ReleaseLocked(bufp, TRUE);
4452 lock_ReleaseWrite(&buf_globalLock);
4454 lock_ReleaseMutex(&bufp->mx);
4461 cm_ReleaseUser(userp);
4463 cm_ReleaseSCache(scp);
4465 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents DONE code=0x%x", code);
4470 RDR_PioctlOpen( IN cm_user_t *userp,
4471 IN AFSFileID ParentId,
4472 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4474 IN DWORD ResultBufferLength,
4475 IN OUT AFSCommResult **ResultCB)
4480 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4486 sizeof( AFSCommResult));
4488 /* Get the active directory */
4489 ParentFid.cell = ParentId.Cell;
4490 ParentFid.volume = ParentId.Volume;
4491 ParentFid.vnode = ParentId.Vnode;
4492 ParentFid.unique = ParentId.Unique;
4493 ParentFid.hash = ParentId.Hash;
4495 /* Get the root directory */
4496 RootFid.cell = pPioctlCB->RootId.Cell;
4497 RootFid.volume = pPioctlCB->RootId.Volume;
4498 RootFid.vnode = pPioctlCB->RootId.Vnode;
4499 RootFid.unique = pPioctlCB->RootId.Unique;
4500 RootFid.hash = pPioctlCB->RootId.Hash;
4502 /* Create the pioctl index */
4503 RDR_SetupIoctl(pPioctlCB->RequestId, &ParentFid, &RootFid, userp);
4510 RDR_PioctlClose( IN cm_user_t *userp,
4511 IN AFSFileID ParentId,
4512 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4514 IN DWORD ResultBufferLength,
4515 IN OUT AFSCommResult **ResultCB)
4517 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4523 sizeof( AFSCommResult));
4525 /* Cleanup the pioctl index */
4526 RDR_CleanupIoctl(pPioctlCB->RequestId);
4533 RDR_PioctlWrite( IN cm_user_t *userp,
4534 IN AFSFileID ParentId,
4535 IN AFSPIOCtlIORequestCB *pPioctlCB,
4537 IN DWORD ResultBufferLength,
4538 IN OUT AFSCommResult **ResultCB)
4540 AFSPIOCtlIOResultCB *pResultCB;
4541 cm_scache_t *dscp = NULL;
4548 req.flags |= CM_REQ_WOW64;
4550 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4556 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4558 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4560 code = RDR_IoctlWrite(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer, &req);
4562 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4563 (*ResultCB)->ResultStatus = status;
4567 pResultCB->BytesProcessed = pPioctlCB->BufferLength;
4568 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4572 RDR_PioctlRead( IN cm_user_t *userp,
4573 IN AFSFileID ParentId,
4574 IN AFSPIOCtlIORequestCB *pPioctlCB,
4576 IN BOOL bIsLocalSystem,
4577 IN DWORD ResultBufferLength,
4578 IN OUT AFSCommResult **ResultCB)
4580 AFSPIOCtlIOResultCB *pResultCB;
4581 cm_scache_t *dscp = NULL;
4585 afs_uint32 pflags = (bIsLocalSystem ? AFSCALL_FLAG_LOCAL_SYSTEM : 0);
4589 req.flags |= CM_REQ_WOW64;
4591 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4597 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4599 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4601 code = RDR_IoctlRead(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer,
4602 &pResultCB->BytesProcessed, &req, pflags);
4604 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4605 (*ResultCB)->ResultStatus = status;
4609 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4613 RDR_ByteRangeLockSync( IN cm_user_t *userp,
4614 IN AFSFileID FileId,
4615 IN AFSByteRangeLockRequestCB *pBRLRequestCB,
4617 IN DWORD ResultBufferLength,
4618 IN OUT AFSCommResult **ResultCB)
4620 AFSByteRangeLockResultCB *pResultCB = NULL;
4621 LARGE_INTEGER ProcessId;
4623 cm_scache_t *scp = NULL;
4631 ProcessId.QuadPart = pBRLRequestCB->ProcessId;
4635 req.flags |= CM_REQ_WOW64;
4637 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4638 FileId.Cell, FileId.Volume,
4639 FileId.Vnode, FileId.Unique);
4640 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4641 ProcessId.HighPart, ProcessId.LowPart);
4643 Length = sizeof( AFSByteRangeLockResultCB) + ((pBRLRequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4644 if (Length > ResultBufferLength) {
4645 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4648 memset( *ResultCB, 0, sizeof(AFSCommResult));
4649 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4653 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4656 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4657 (*ResultCB)->ResultBufferLength = Length;
4659 pResultCB = (AFSByteRangeLockResultCB *)(*ResultCB)->ResultData;
4660 pResultCB->FileId = FileId;
4661 pResultCB->Count = pBRLRequestCB->Count;
4663 /* Allocate the extents from the buffer package */
4664 Fid.cell = FileId.Cell;
4665 Fid.volume = FileId.Volume;
4666 Fid.vnode = FileId.Vnode;
4667 Fid.unique = FileId.Unique;
4668 Fid.hash = FileId.Hash;
4670 code = cm_GetSCache(&Fid, &scp, userp, &req);
4672 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4673 (*ResultCB)->ResultStatus = status;
4674 (*ResultCB)->ResultBufferLength = 0;
4675 osi_Log2(afsd_logp, "RDR_ByteRangeLockSync cm_GetSCache FID failure code=0x%x status=0x%x",
4680 lock_ObtainWrite(&scp->rw);
4682 /* start by looking up the file's end */
4683 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4684 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4686 lock_ReleaseWrite(&scp->rw);
4687 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4688 (*ResultCB)->ResultStatus = status;
4689 (*ResultCB)->ResultBufferLength = 0;
4690 osi_Log3(afsd_logp, "RDR_ByteRangeLockSync cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4695 /* the scp is now locked and current */
4696 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4698 for ( i=0; i<pBRLRequestCB->Count; i++ ) {
4699 pResultCB->Result[i].LockType = pBRLRequestCB->Request[i].LockType;
4700 pResultCB->Result[i].Offset = pBRLRequestCB->Request[i].Offset;
4701 pResultCB->Result[i].Length = pBRLRequestCB->Request[i].Length;
4704 pBRLRequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4705 pBRLRequestCB->Request[i].Offset,
4706 pBRLRequestCB->Request[i].Length,
4707 key, 0, userp, &req, NULL);
4710 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4712 pBRLRequestCB->Request[i].LockType,
4713 pBRLRequestCB->Request[i].Offset.HighPart,
4714 pBRLRequestCB->Request[i].Offset.LowPart);
4715 osi_Log2(afsd_logp, "... length 0x%x:%x",
4716 pBRLRequestCB->Request[i].Length.HighPart,
4717 pBRLRequestCB->Request[i].Length.LowPart);
4722 pResultCB->Result[i].Status = 0;
4724 case CM_ERROR_WOULDBLOCK:
4725 pResultCB->Result[i].Status = STATUS_FILE_LOCK_CONFLICT;
4728 pResultCB->Result[i].Status = STATUS_LOCK_NOT_GRANTED;
4732 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4733 lock_ReleaseWrite(&scp->rw);
4734 cm_ReleaseSCache(scp);
4736 (*ResultCB)->ResultStatus = 0;
4737 osi_Log0(afsd_logp, "RDR_ByteRangeLockSync SUCCESS");
4742 RDR_ByteRangeUnlock( IN cm_user_t *userp,
4743 IN AFSFileID FileId,
4744 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4746 IN DWORD ResultBufferLength,
4747 IN OUT AFSCommResult **ResultCB)
4749 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4750 LARGE_INTEGER ProcessId;
4752 cm_scache_t *scp = NULL;
4760 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4764 req.flags |= CM_REQ_WOW64;
4766 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4767 FileId.Cell, FileId.Volume,
4768 FileId.Vnode, FileId.Unique);
4769 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4770 ProcessId.HighPart, ProcessId.LowPart);
4772 Length = sizeof( AFSByteRangeUnlockResultCB) + ((pBRURequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4773 if (Length > ResultBufferLength) {
4774 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4777 memset( *ResultCB, 0, sizeof(AFSCommResult));
4778 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4782 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4785 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4786 (*ResultCB)->ResultBufferLength = Length;
4788 pResultCB = (AFSByteRangeUnlockResultCB *)(*ResultCB)->ResultData;
4789 pResultCB->Count = pBRURequestCB->Count;
4791 /* Allocate the extents from the buffer package */
4792 Fid.cell = FileId.Cell;
4793 Fid.volume = FileId.Volume;
4794 Fid.vnode = FileId.Vnode;
4795 Fid.unique = FileId.Unique;
4796 Fid.hash = FileId.Hash;
4798 code = cm_GetSCache(&Fid, &scp, userp, &req);
4800 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4801 (*ResultCB)->ResultStatus = status;
4802 (*ResultCB)->ResultBufferLength = 0;
4803 osi_Log2(afsd_logp, "RDR_ByteRangeUnlock cm_GetSCache FID failure code=0x%x status=0x%x",
4808 lock_ObtainWrite(&scp->rw);
4810 /* start by looking up the file's end */
4811 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4812 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4814 lock_ReleaseWrite(&scp->rw);
4815 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4816 (*ResultCB)->ResultStatus = status;
4817 (*ResultCB)->ResultBufferLength = 0;
4818 osi_Log3(afsd_logp, "RDR_ByteRangeUnlock cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4823 /* the scp is now locked and current */
4824 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4826 for ( i=0; i<pBRURequestCB->Count; i++ ) {
4827 pResultCB->Result[i].LockType = pBRURequestCB->Request[i].LockType;
4828 pResultCB->Result[i].Offset = pBRURequestCB->Request[i].Offset;
4829 pResultCB->Result[i].Length = pBRURequestCB->Request[i].Length;
4831 code = cm_Unlock(scp,
4832 pBRURequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4833 pBRURequestCB->Request[i].Offset,
4834 pBRURequestCB->Request[i].Length,
4835 key, CM_UNLOCK_FLAG_MATCH_RANGE, userp, &req);
4838 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4839 code, pBRURequestCB->Request[i].LockType,
4840 pBRURequestCB->Request[i].Offset.HighPart,
4841 pBRURequestCB->Request[i].Offset.LowPart);
4842 osi_Log2(afsd_logp, "... length 0x%x:%x",
4843 pBRURequestCB->Request[i].Length.HighPart,
4844 pBRURequestCB->Request[i].Length.LowPart);
4846 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4847 pResultCB->Result[i].Status = status;
4850 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4851 lock_ReleaseWrite(&scp->rw);
4852 cm_ReleaseSCache(scp);
4854 (*ResultCB)->ResultStatus = 0;
4855 osi_Log0(afsd_logp, "RDR_ByteRangeUnlock SUCCESS");
4860 RDR_ByteRangeUnlockAll( IN cm_user_t *userp,
4861 IN AFSFileID FileId,
4862 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4864 IN DWORD ResultBufferLength,
4865 IN OUT AFSCommResult **ResultCB)
4867 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4868 LARGE_INTEGER ProcessId;
4869 cm_scache_t *scp = NULL;
4876 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4880 req.flags |= CM_REQ_WOW64;
4882 osi_Log4(afsd_logp, "RDR_ByteRangeUnlockAll File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4883 FileId.Cell, FileId.Volume,
4884 FileId.Vnode, FileId.Unique);
4885 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4886 ProcessId.HighPart, ProcessId.LowPart);
4888 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4891 memset( *ResultCB, '\0', sizeof( AFSCommResult));
4892 (*ResultCB)->ResultBufferLength = 0;
4894 /* Allocate the extents from the buffer package */
4895 Fid.cell = FileId.Cell;
4896 Fid.volume = FileId.Volume;
4897 Fid.vnode = FileId.Vnode;
4898 Fid.unique = FileId.Unique;
4899 Fid.hash = FileId.Hash;
4901 code = cm_GetSCache(&Fid, &scp, userp, &req);
4903 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4904 (*ResultCB)->ResultStatus = status;
4905 (*ResultCB)->ResultBufferLength = 0;
4906 osi_Log2(afsd_logp, "RDR_ByteRangeUnlockAll cm_GetSCache FID failure code=0x%x status=0x%x",
4911 lock_ObtainWrite(&scp->rw);
4913 /* start by looking up the file's end */
4914 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4915 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4917 lock_ReleaseWrite(&scp->rw);
4918 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4919 (*ResultCB)->ResultStatus = status;
4920 (*ResultCB)->ResultBufferLength = 0;
4921 osi_Log3(afsd_logp, "RDR_ByteRangeUnlockAll cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4926 /* the scp is now locked and current */
4927 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4929 code = cm_UnlockByKey(scp, key, 0, userp, &req);
4931 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4932 lock_ReleaseWrite(&scp->rw);
4933 cm_ReleaseSCache(scp);
4935 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4936 (*ResultCB)->ResultStatus = status;
4939 osi_Log1(afsd_logp, "RDR_ByteRangeUnlockAll FAILURE code 0x%x", code);
4941 osi_Log0(afsd_logp, "RDR_ByteRangeUnlockAll SUCCESS");
4947 RDR_GetVolumeInfo( IN cm_user_t *userp,
4948 IN AFSFileID FileId,
4950 IN DWORD ResultBufferLength,
4951 IN OUT AFSCommResult **ResultCB)
4953 AFSVolumeInfoCB *pResultCB = NULL;
4955 cm_scache_t *scp = NULL;
4956 cm_volume_t *volp = NULL;
4957 cm_vol_state_t *volstatep = NULL;
4959 cm_cell_t *cellp = NULL;
4964 FILETIME ft = {0x832cf000, 0x01abfcc4}; /* October 1, 1982 00:00:00 +0600 */
4966 char volName[32]="(unknown)";
4967 char offLineMsg[256]="server temporarily inaccessible";
4968 char motd[256]="server temporarily inaccessible";
4970 AFSFetchVolumeStatus volStat;
4974 struct rx_connection * rxconnp;
4978 req.flags |= CM_REQ_WOW64;
4980 osi_Log4(afsd_logp, "RDR_GetVolumeInfo File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4981 FileId.Cell, FileId.Volume,
4982 FileId.Vnode, FileId.Unique);
4984 Length = sizeof( AFSCommResult) + sizeof(AFSVolumeInfoCB);
4985 if (sizeof(AFSVolumeInfoCB) > ResultBufferLength) {
4986 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
4989 memset( *ResultCB, 0, sizeof(AFSCommResult));
4990 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4994 *ResultCB = (AFSCommResult *)malloc( Length );
4997 memset( *ResultCB, '\0', Length );
4998 (*ResultCB)->ResultBufferLength = sizeof(AFSVolumeInfoCB);
4999 pResultCB = (AFSVolumeInfoCB *)(*ResultCB)->ResultData;
5001 /* Allocate the extents from the buffer package */
5002 if (FileId.Cell != 0) {
5003 Fid.cell = FileId.Cell;
5004 Fid.volume = FileId.Volume;
5005 Fid.vnode = FileId.Vnode;
5006 Fid.unique = FileId.Unique;
5007 Fid.hash = FileId.Hash;
5009 code = cm_GetSCache(&Fid, &scp, userp, &req);
5011 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5012 (*ResultCB)->ResultStatus = status;
5013 (*ResultCB)->ResultBufferLength = 0;
5014 osi_Log2(afsd_logp, "RDR_GetVolumeInfo cm_GetSCache FID failure code=0x%x status=0x%x",
5019 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
5020 osi_Log0(afsd_logp, "RDR_GetVolumeInfo Object Name Invalid - Cell = 0");
5023 lock_ObtainWrite(&scp->rw);
5025 /* start by looking up the file's end */
5026 code = cm_SyncOp(scp, NULL, userp, &req, 0,
5027 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5029 lock_ReleaseWrite(&scp->rw);
5030 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5031 (*ResultCB)->ResultStatus = status;
5032 (*ResultCB)->ResultBufferLength = 0;
5033 osi_Log3(afsd_logp, "RDR_GetVolumeInfo cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
5039 pResultCB->SectorsPerAllocationUnit = 1;
5040 pResultCB->BytesPerSector = 1024;
5042 pResultCB->CellID = scp->fid.cell;
5043 pResultCB->VolumeID = scp->fid.volume;
5044 pResultCB->Characteristics = FILE_REMOTE_DEVICE;
5045 pResultCB->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK |
5046 FILE_SUPPORTS_REPARSE_POINTS;
5048 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
5049 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)
5051 pResultCB->TotalAllocationUnits.QuadPart = 100;
5052 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
5054 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5055 pResultCB->Characteristics |= FILE_READ_ONLY_DEVICE;
5057 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( "Freelance.Local.Root", -1, pResultCB->VolumeLabel,
5058 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5059 if ( pResultCB->VolumeLabelLength )
5060 pResultCB->VolumeLabelLength--;
5062 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
5064 volp = cm_GetVolumeByFID(&scp->fid);
5066 code = CM_ERROR_NOSUCHVOLUME;
5069 volstatep = cm_VolumeStateByID(volp, scp->fid.volume);
5070 volType = cm_VolumeType(volp, scp->fid.volume);
5072 pResultCB->Characteristics |= ((volType == ROVOL || volType == BACKVOL) ? FILE_READ_ONLY_DEVICE : 0);
5075 OfflineMsg = offLineMsg;
5077 lock_ReleaseWrite(&scp->rw);
5079 code = cm_ConnFromFID(&scp->fid, userp, &req, &connp);
5082 rxconnp = cm_GetRxConn(connp);
5083 code = RXAFS_GetVolumeStatus(rxconnp, scp->fid.volume,
5084 &volStat, &Name, &OfflineMsg, &MOTD);
5085 rx_PutConnection(rxconnp);
5087 } while (cm_Analyze(connp, userp, &req, &scp->fid, 0, NULL, NULL, NULL, code));
5088 code = cm_MapRPCError(code, &req);
5090 pResultCB->TotalAllocationUnits.QuadPart = volStat.PartMaxBlocks;
5091 pResultCB->AvailableAllocationUnits.QuadPart = volStat.PartBlocksAvail;
5093 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( Name, -1, pResultCB->VolumeLabel,
5094 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5096 pResultCB->TotalAllocationUnits.QuadPart = 0x7FFFFFFF;
5097 pResultCB->AvailableAllocationUnits.QuadPart = (volType == ROVOL || volType == BACKVOL) ? 0 : 0x3F000000;
5099 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( volp->namep, -1, pResultCB->VolumeLabel,
5100 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5103 if ( pResultCB->VolumeLabelLength )
5104 pResultCB->VolumeLabelLength--;
5106 lock_ObtainWrite(&scp->rw);
5108 pResultCB->VolumeLabelLength *= sizeof(WCHAR); /* convert to bytes from chars */
5110 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5113 lock_ReleaseWrite(&scp->rw);
5116 cm_ReleaseSCache(scp);
5118 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5119 (*ResultCB)->ResultStatus = status;
5120 osi_Log0(afsd_logp, "RDR_GetVolumeInfo SUCCESS");
5125 RDR_HoldFid( IN cm_user_t *userp,
5126 IN AFSHoldFidRequestCB * pHoldFidCB,
5128 IN DWORD ResultBufferLength,
5129 IN OUT AFSCommResult **ResultCB)
5131 AFSHoldFidResultCB *pResultCB = NULL;
5138 osi_Log1(afsd_logp, "RDR_HoldFid Count=%u", pHoldFidCB->Count);
5140 Length = sizeof(AFSHoldFidResultCB) + (pHoldFidCB->Count-1) * sizeof(AFSFidResult);
5141 if (Length > ResultBufferLength) {
5142 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5145 memset( *ResultCB, 0, sizeof(AFSCommResult));
5146 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5149 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5152 memset( *ResultCB, '\0', Length );
5153 (*ResultCB)->ResultBufferLength = Length;
5154 pResultCB = (AFSHoldFidResultCB *)(*ResultCB)->ResultData;
5156 for ( index = 0; index < pHoldFidCB->Count; index++ )
5158 cm_scache_t *scp = NULL;
5161 Fid.cell = pResultCB->Result[index].FileID.Cell = pHoldFidCB->FileID[index].Cell;
5162 Fid.volume = pResultCB->Result[index].FileID.Volume = pHoldFidCB->FileID[index].Volume;
5163 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pHoldFidCB->FileID[index].Vnode;
5164 Fid.unique = pResultCB->Result[index].FileID.Unique = pHoldFidCB->FileID[index].Unique;
5165 Fid.hash = pResultCB->Result[index].FileID.Hash = pHoldFidCB->FileID[index].Hash;
5167 osi_Log4( afsd_logp,
5168 "RDR_HoldFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5169 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5171 scp = cm_FindSCache(&Fid);
5173 RDR_FlagScpInUse( scp, FALSE );
5174 cm_ReleaseSCache(scp);
5176 pResultCB->Result[index].Status = 0;
5179 (*ResultCB)->ResultStatus = 0;
5180 osi_Log0(afsd_logp, "RDR_HoldFid SUCCESS");
5185 RDR_ReleaseFid( IN cm_user_t *userp,
5186 IN AFSReleaseFidRequestCB * pReleaseFidCB,
5188 IN DWORD ResultBufferLength,
5189 IN OUT AFSCommResult **ResultCB)
5191 AFSReleaseFidResultCB *pResultCB = NULL;
5198 osi_Log1(afsd_logp, "RDR_ReleaseFid Count=%u", pReleaseFidCB->Count);
5200 Length = sizeof(AFSReleaseFidResultCB) + (pReleaseFidCB->Count ? pReleaseFidCB->Count-1 : 0) * sizeof(AFSFidResult);
5201 if (Length > ResultBufferLength) {
5202 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5205 memset( *ResultCB, 0, sizeof(AFSCommResult));
5206 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5209 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5212 memset( *ResultCB, '\0', Length );
5213 (*ResultCB)->ResultBufferLength = Length;
5214 pResultCB = (AFSReleaseFidResultCB *)(*ResultCB)->ResultData;
5216 for ( index = 0; index < pReleaseFidCB->Count; index++ )
5218 cm_scache_t *scp = NULL;
5221 Fid.cell = pResultCB->Result[index].FileID.Cell = pReleaseFidCB->FileID[index].Cell;
5222 Fid.volume = pResultCB->Result[index].FileID.Volume = pReleaseFidCB->FileID[index].Volume;
5223 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pReleaseFidCB->FileID[index].Vnode;
5224 Fid.unique = pResultCB->Result[index].FileID.Unique = pReleaseFidCB->FileID[index].Unique;
5225 Fid.hash = pResultCB->Result[index].FileID.Hash = pReleaseFidCB->FileID[index].Hash;
5227 osi_Log4( afsd_logp,
5228 "RDR_ReleaseFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5229 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5231 scp = cm_FindSCache(&Fid);
5233 lock_ObtainWrite(&scp->rw);
5234 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
5235 lock_ReleaseWrite(&scp->rw);
5237 cm_ReleaseSCache(scp);
5239 pResultCB->Result[index].Status = 0;
5241 pResultCB->Count = pReleaseFidCB->Count;
5243 (*ResultCB)->ResultStatus = 0;
5244 osi_Log0(afsd_logp, "RDR_ReleaseFid SUCCESS");
5249 * The redirector makes several assumptions regarding the
5250 * SRVSVC and WKSSVC pipes transactions. First, the interface
5251 * versions are those indicated below. Secondly, the encoding
5252 * will be performed using NDR version 2. These assumptions
5253 * may not hold in the future and end-to-end MSRPC Bind
5254 * negotiations may need to be supported. Of course, these
5255 * are the only interface versions that are supported by the
5258 #define MSRPC_PIPE_PREFIX L".\\"
5260 static const UUID MSRPC_SRVSVC_UUID = {0x4B324FC8, 0x1670, 0x01D3,
5261 {0x12, 0x78, 0x5A, 0x47, 0xBF, 0x6E, 0xE1, 0x88}};
5262 #define MSRPC_SRVSVC_NAME L"PIPE\\SRVSVC"
5263 #define MSRPC_SRVSVC_VERS 3
5265 static const UUID MSRPC_WKSSVC_UUID = {0x6BFFD098, 0xA112, 0x3610,
5266 {0x98, 0x33, 0x46, 0xC3, 0xF8, 0x7E, 0x34, 0x5A}};
5267 #define MSRPC_WKSSVC_NAME L"PIPE\\WKSSVC"
5268 #define MSRPC_WKSSVC_VERS 1
5270 static const UUID MSRPC_NDR_UUID = {0x8A885D04, 0x1CEB, 0x11C9,
5271 {0x9F, 0xE8, 0x08, 0x00, 0x2B, 0x10, 0x48, 0x60}};
5272 #define MSRPC_NDR_NAME L"NDR"
5273 #define MSRPC_NDR_VERS 2
5275 extern RPC_IF_HANDLE srvsvc_v3_0_s_ifspec;
5276 extern RPC_IF_HANDLE wkssvc_v1_0_s_ifspec;
5279 RDR_PipeOpen( IN cm_user_t *userp,
5280 IN AFSFileID ParentId,
5282 IN DWORD NameLength,
5283 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5285 IN DWORD ResultBufferLength,
5286 IN OUT AFSCommResult **ResultCB)
5291 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5297 sizeof( AFSCommResult));
5299 /* Get the active directory */
5300 ParentFid.cell = ParentId.Cell;
5301 ParentFid.volume = ParentId.Volume;
5302 ParentFid.vnode = ParentId.Vnode;
5303 ParentFid.unique = ParentId.Unique;
5304 ParentFid.hash = ParentId.Hash;
5306 /* Get the root directory */
5307 RootFid.cell = pPipe_CB->RootId.Cell;
5308 RootFid.volume = pPipe_CB->RootId.Volume;
5309 RootFid.vnode = pPipe_CB->RootId.Vnode;
5310 RootFid.unique = pPipe_CB->RootId.Unique;
5311 RootFid.hash = pPipe_CB->RootId.Hash;
5313 /* Create the pipe index */
5314 (*ResultCB)->ResultStatus =
5315 RDR_SetupPipe( pPipe_CB->RequestId, &ParentFid, &RootFid,
5316 Name, NameLength, userp);
5322 RDR_PipeClose( IN cm_user_t *userp,
5323 IN AFSFileID ParentId,
5324 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5326 IN DWORD ResultBufferLength,
5327 IN OUT AFSCommResult **ResultCB)
5329 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5335 sizeof( AFSCommResult));
5337 /* Cleanup the pipe index */
5338 RDR_CleanupPipe(pPipe_CB->RequestId);
5345 RDR_PipeWrite( IN cm_user_t *userp,
5346 IN AFSFileID ParentId,
5347 IN AFSPipeIORequestCB *pPipe_CB,
5348 IN BYTE *pPipe_Data,
5350 IN DWORD ResultBufferLength,
5351 IN OUT AFSCommResult **ResultCB)
5353 AFSPipeIOResultCB *pResultCB;
5354 cm_scache_t *dscp = NULL;
5361 req.flags |= CM_REQ_WOW64;
5363 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5369 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5371 pResultCB = (AFSPipeIOResultCB *)(*ResultCB)->ResultData;
5373 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_Data, &req, userp);
5375 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5376 (*ResultCB)->ResultStatus = status;
5380 pResultCB->BytesProcessed = pPipe_CB->BufferLength;
5381 (*ResultCB)->ResultBufferLength = sizeof( AFSPipeIOResultCB);
5386 RDR_PipeRead( IN cm_user_t *userp,
5387 IN AFSFileID ParentId,
5388 IN AFSPipeIORequestCB *pPipe_CB,
5390 IN DWORD ResultBufferLength,
5391 IN OUT AFSCommResult **ResultCB)
5394 cm_scache_t *dscp = NULL;
5401 req.flags |= CM_REQ_WOW64;
5403 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5409 sizeof( AFSCommResult));
5411 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5413 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_Data,
5414 &(*ResultCB)->ResultBufferLength, &req, userp);
5416 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5417 (*ResultCB)->ResultStatus = status;
5424 RDR_PipeSetInfo( IN cm_user_t *userp,
5425 IN AFSFileID ParentId,
5426 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5427 IN BYTE *pPipe_Data,
5429 IN DWORD ResultBufferLength,
5430 IN OUT AFSCommResult **ResultCB)
5432 cm_scache_t *dscp = NULL;
5438 req.flags |= CM_REQ_WOW64;
5440 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5446 sizeof( AFSCommResult));
5448 status = RDR_Pipe_SetInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5449 pPipeInfo_CB->BufferLength, pPipe_Data, &req, userp);
5451 (*ResultCB)->ResultStatus = status;
5456 RDR_PipeQueryInfo( IN cm_user_t *userp,
5457 IN AFSFileID ParentId,
5458 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5460 IN DWORD ResultBufferLength,
5461 IN OUT AFSCommResult **ResultCB)
5464 cm_scache_t *dscp = NULL;
5470 req.flags |= CM_REQ_WOW64;
5472 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5478 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5480 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5482 status = RDR_Pipe_QueryInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5483 ResultBufferLength, pPipe_Data,
5484 &(*ResultCB)->ResultBufferLength, &req, userp);
5486 (*ResultCB)->ResultStatus = status;
5490 RDR_PipeTransceive( IN cm_user_t *userp,
5491 IN AFSFileID ParentId,
5492 IN AFSPipeIORequestCB *pPipe_CB,
5493 IN BYTE *pPipe_InData,
5495 IN DWORD ResultBufferLength,
5496 IN OUT AFSCommResult **ResultCB)
5499 * This function processes a Pipe Service request
5500 * that would normally be sent to a LAN Manager server
5501 * across an authenticated SMB-PIPE/MSRPC/SVC request
5502 * stack. The request is being sent here because the
5503 * application (e.g., Explorer Shell or Common Control File
5504 * dialog) believes that because the UNC path it is
5505 * processing has specified a server name that is not
5506 * "." and that the Server is remote and that the Share
5507 * list cannot be obtained using the Network Provider
5510 * The file system driver is faking the Bind-Ack response
5511 * to the MSRPC Bind request but cannot decode the NDR
5512 * encoded Pipe Service requests. For that we will use
5513 * the service's MSRPC module. However, unlike the SMB
5514 * server usage we must fake the MSRPC Bind exchange and
5515 * map the PipeName to an interface instead of using the
5516 * GUID specified in the MSRPC Bind request.
5518 * None of the requests that are being processed by the
5519 * service require authentication. As a result the userp
5520 * parameter will be ignored.
5522 * Although there are dozens of Pipe Services, the only
5523 * ones that we are implementing are WKSSVC and SRVSVC.
5524 * These support NetShareEnum, NetShareGetInfo,
5525 * NetServerGetInfo, and NetWorkstaGetInfo which are
5526 * commonly queried by NET VIEW, the Explorer Shell,
5527 * and the Common Control File dialog.
5529 BYTE *pPipe_OutData;
5530 cm_scache_t *dscp = NULL;
5534 DWORD Length = ResultBufferLength + sizeof( AFSCommResult);
5538 req.flags |= CM_REQ_WOW64;
5540 *ResultCB = (AFSCommResult *)malloc( Length);
5543 memset( *ResultCB, '\0', Length );
5545 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_InData, &req, userp);
5547 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5548 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Write FAILURE code=0x%x status=0x%x",
5550 (*ResultCB)->ResultStatus = status;
5554 pPipe_OutData = (BYTE *)(*ResultCB)->ResultData;
5555 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_OutData,
5556 &(*ResultCB)->ResultBufferLength, &req, userp);
5558 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5559 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Read FAILURE code=0x%x status=0x%x",
5561 (*ResultCB)->ResultStatus = status;
5565 (*ResultCB)->ResultStatus = 0;
5566 osi_Log0(afsd_logp, "RDR_Pipe_Transceive SUCCESS");