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;
123 * For now disable the memory extent interface because there
124 * have been reports of data corruption.
126 memStatus.dwLength = sizeof(memStatus);
127 if (GlobalMemoryStatusEx(&memStatus)) {
129 * Use the memory extent interface in the afs redirector
130 * whenever the cache size is less than equal to 10% of
131 * physical memory. Do not use too much because this memory
132 * will be locked by the redirector so it can't be swapped
135 maxMemoryCacheSize = (DWORD)(memStatus.ullTotalPhys / 1024 / 10);
138 * If we can't determine the amount of physical memory
139 * in the system, be conservative and limit the use of
140 * memory extent interface to 64MB data caches.
142 maxMemoryCacheSize = 65536;
145 maxMemoryCacheSize = 0;
148 *pRedirInitInfoLen = (DWORD) (sizeof(AFSRedirectorInitInfo) + (cm_CachePathLen + TempPathLen) * sizeof(WCHAR));
149 *ppRedirInitInfo = (AFSRedirectorInitInfo *)malloc(*pRedirInitInfoLen);
150 (*ppRedirInitInfo)->Flags = smb_hideDotFiles ? AFS_REDIR_INIT_FLAG_HIDE_DOT_FILES : 0;
151 (*ppRedirInitInfo)->MaximumChunkLength = cm_data.chunkSize;
152 (*ppRedirInitInfo)->GlobalFileId.Cell = cm_data.rootFid.cell;
153 (*ppRedirInitInfo)->GlobalFileId.Volume = cm_data.rootFid.volume;
154 (*ppRedirInitInfo)->GlobalFileId.Vnode = cm_data.rootFid.vnode;
155 (*ppRedirInitInfo)->GlobalFileId.Unique = cm_data.rootFid.unique;
156 (*ppRedirInitInfo)->GlobalFileId.Hash = cm_data.rootFid.hash;
157 (*ppRedirInitInfo)->ExtentCount.QuadPart = cm_data.buf_nbuffers;
158 (*ppRedirInitInfo)->CacheBlockSize = cm_data.blockSize;
159 (*ppRedirInitInfo)->MaxPathLinkCount = 512; /* this needs to become a registry value */
160 (*ppRedirInitInfo)->NameArrayLength = 32; /* this needs to become a registry value */
161 if (cm_virtualCache || cm_data.bufferSize <= maxMemoryCacheSize) {
162 osi_Log0(afsd_logp, "RDR_SetInitParams Initializing Memory Extent Interface");
163 (*ppRedirInitInfo)->MemoryCacheOffset.QuadPart = (LONGLONG)cm_data.bufDataBaseAddress;
164 (*ppRedirInitInfo)->MemoryCacheLength.QuadPart = cm_data.bufEndOfData - cm_data.bufDataBaseAddress;
165 (*ppRedirInitInfo)->CacheFileNameLength = 0;
166 RDR_extentBaseAddress = cm_data.bufDataBaseAddress;
168 (*ppRedirInitInfo)->MemoryCacheOffset.QuadPart = 0;
169 (*ppRedirInitInfo)->MemoryCacheLength.QuadPart = 0;
170 (*ppRedirInitInfo)->CacheFileNameLength = (ULONG) (cm_CachePathLen * sizeof(WCHAR));
171 err = mbstowcs((*ppRedirInitInfo)->CacheFileName, cm_CachePath, (cm_CachePathLen + 1) *sizeof(WCHAR));
173 free(*ppRedirInitInfo);
174 osi_Log0(afsd_logp, "RDR_SetInitParams Invalid Object Name");
175 return STATUS_OBJECT_NAME_INVALID;
177 RDR_extentBaseAddress = cm_data.baseAddress;
179 (*ppRedirInitInfo)->DumpFileLocationOffset = FIELD_OFFSET(AFSRedirectorInitInfo, CacheFileName) + (*ppRedirInitInfo)->CacheFileNameLength;
180 (*ppRedirInitInfo)->DumpFileLocationLength = (TempPathLen - 1) * sizeof(WCHAR);
181 ExpandEnvironmentStringsW(L"%TEMP%",
182 (LPWSTR)(((PBYTE)(*ppRedirInitInfo)) + (*ppRedirInitInfo)->DumpFileLocationOffset),
185 osi_Log0(afsd_logp,"RDR_SetInitParams Success");
190 RDR_GetLocalSystemUser( void)
193 cm_user_t *userp = NULL;
194 wchar_t cname[MAX_COMPUTERNAME_LENGTH+1];
195 int cnamelen = MAX_COMPUTERNAME_LENGTH+1;
197 GetComputerNameW(cname, &cnamelen);
200 unp = smb_FindUserByName(NTSID_LOCAL_SYSTEM, cname, SMB_FLAG_CREATE);
201 lock_ObtainMutex(&unp->mx);
203 unp->userp = cm_NewUser();
204 unp->flags |= SMB_USERNAMEFLAG_SID;
205 lock_ReleaseMutex(&unp->mx);
208 smb_ReleaseUsername(unp);
211 userp = cm_rootUserp;
219 RDR_UserFromCommRequest( IN AFSCommRequest *RequestBuffer)
222 return RDR_UserFromAuthGroup( &RequestBuffer->AuthGroup);
226 RDR_UserFromAuthGroup( IN GUID *pGuid)
229 cm_user_t * userp = NULL;
230 RPC_WSTR UuidString = NULL;
231 wchar_t cname[MAX_COMPUTERNAME_LENGTH+1];
232 int cnamelen = MAX_COMPUTERNAME_LENGTH+1;
234 if (UuidToStringW((UUID *)pGuid, &UuidString) != RPC_S_OK)
237 GetComputerNameW(cname, &cnamelen);
240 unp = smb_FindUserByName(UuidString, cname, SMB_FLAG_CREATE);
241 lock_ObtainMutex(&unp->mx);
243 unp->userp = cm_NewUser();
244 memcpy(&unp->userp->authgroup, pGuid, sizeof(GUID));
246 unp->flags |= SMB_USERNAMEFLAG_SID;
247 lock_ReleaseMutex(&unp->mx);
250 smb_ReleaseUsername(unp);
254 userp = cm_rootUserp;
258 osi_Log2(afsd_logp, "RDR_UserFromCommRequest Guid %S userp = 0x%p",
259 osi_LogSaveStringW(afsd_logp, UuidString),
263 RpcStringFreeW(&UuidString);
269 RDR_ReleaseUser( IN cm_user_t *userp )
271 osi_Log1(afsd_logp, "RDR_ReleaseUser userp = 0x%p", userp);
272 cm_ReleaseUser(userp);
277 * RDR_FlagScpInUse flags the scp with CM_SCACHEFLAG_RDR_IN_USE
280 RDR_FlagScpInUse( IN cm_scache_t *scp, IN BOOL bLocked )
283 lock_ObtainWrite(&scp->rw);
285 lock_AssertWrite(&scp->rw);
286 scp->flags |= CM_SCACHEFLAG_RDR_IN_USE;
289 lock_ReleaseWrite(&scp->rw);
293 * Obtain the status information for the specified object using
294 * an inline bulk status rpc. cm_BPlusDirEnumBulkStatOne() will
295 * obtain current status for the directory object, the object
296 * which is the focus of the inquiry and as many other objects
297 * in the directory for which there are not callbacks registered
298 * since we are likely to be asked for other objects in the directory.
301 RDR_BulkStatLookup( cm_scache_t *dscp,
306 cm_direnum_t * enump = NULL;
310 code = cm_BeginDirOp(dscp, userp, reqp, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
312 code = cm_BPlusDirEnumerate(dscp, userp, reqp, TRUE, NULL, TRUE, &enump);
314 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BPlusDirEnumerate failure code=0x%x",
319 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BeginDirOp failure code=0x%x",
325 code = cm_BPlusDirEnumBulkStatOne(enump, scp);
327 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BPlusDirEnumBulkStatOne failure code=0x%x",
330 cm_BPlusDirFreeEnumeration(enump);
337 #define RDR_POP_FOLLOW_MOUNTPOINTS 0x01
338 #define RDR_POP_EVALUATE_SYMLINKS 0x02
339 #define RDR_POP_WOW64 0x04
340 #define RDR_POP_NO_GETSTATUS 0x08
343 RDR_PopulateCurrentEntry( IN AFSDirEnumEntry * pCurrentEntry,
344 IN DWORD dwMaxEntryLength,
345 IN cm_scache_t * dscp,
346 IN cm_scache_t * scp,
347 IN cm_user_t * userp,
350 IN wchar_t * shortName,
352 IN afs_uint32 cmError,
353 OUT AFSDirEnumEntry **ppNextEntry,
354 OUT DWORD * pdwRemainingLength)
357 WCHAR * wname, *wtarget;
360 afs_uint32 code = 0, code2 = 0;
361 BOOL bMustFake = FALSE;
363 osi_Log5(afsd_logp, "RDR_PopulateCurrentEntry dscp=0x%p scp=0x%p name=%S short=%S flags=0x%x",
364 dscp, scp, osi_LogSaveStringW(afsd_logp, name),
365 osi_LogSaveStringW(afsd_logp, shortName), dwFlags);
366 osi_Log1(afsd_logp, "... maxLength=%d", dwMaxEntryLength);
368 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
370 *ppNextEntry = pCurrentEntry;
371 if (pdwRemainingLength)
372 *pdwRemainingLength = dwMaxEntryLength;
373 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry Not Enough Room for Entry %d < %d",
374 dwMaxEntryLength, sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t));
375 return CM_ERROR_TOOBIG;
383 dwEntryLength = sizeof(AFSDirEnumEntry);
385 lock_ObtainWrite(&scp->rw);
386 if (dwFlags & RDR_POP_NO_GETSTATUS) {
387 if (!cm_HaveCallback(scp))
390 #ifdef AFS_FREELANCE_CLIENT
391 if (scp->fid.cell == AFS_FAKE_ROOT_CELL_ID && scp->fid.volume == AFS_FAKE_ROOT_VOL_ID) {
393 * If the FID is from the Freelance Local Root always perform
394 * a single item status check.
396 code = cm_SyncOp( scp, NULL, userp, reqp, 0,
397 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
399 lock_ReleaseWrite(&scp->rw);
400 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_SyncOp failed for scp=0x%p code=0x%x",
408 * For non-Freelance objects, check to see if we have current
409 * status information. If not, perform a bulk status lookup of multiple
410 * entries in order to reduce the number of RPCs issued to the file server.
412 if ((scp->flags & CM_SCACHEFLAG_EACCESS))
414 else if (!cm_HaveCallback(scp)) {
415 lock_ReleaseWrite(&scp->rw);
416 code = RDR_BulkStatLookup(dscp, scp, userp, reqp);
418 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry RDR_BulkStatLookup failed for scp=0x%p code=0x%x",
422 lock_ObtainWrite(&scp->rw);
424 * RDR_BulkStatLookup can succeed but it may be the case that there
425 * still is not valid status info. If we get this far, generate fake
428 if (!cm_HaveCallback(scp))
434 /* Populate the error code */
435 smb_MapNTError(cmError, &pCurrentEntry->NTStatus, TRUE);
437 /* Populate the real or fake data */
438 pCurrentEntry->FileId.Cell = scp->fid.cell;
439 pCurrentEntry->FileId.Volume = scp->fid.volume;
440 pCurrentEntry->FileId.Vnode = scp->fid.vnode;
441 pCurrentEntry->FileId.Unique = scp->fid.unique;
442 pCurrentEntry->FileId.Hash = scp->fid.hash;
444 pCurrentEntry->FileType = scp->fileType;
446 pCurrentEntry->DataVersion.QuadPart = scp->dataVersion;
448 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
449 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
450 cm_LargeSearchTimeFromUnixTime(&ft, MAX_AFS_UINT32);
452 cm_LargeSearchTimeFromUnixTime(&ft, scp->cbExpires);
454 pCurrentEntry->Expiration.LowPart = ft.dwLowDateTime;
455 pCurrentEntry->Expiration.HighPart = ft.dwHighDateTime;
458 /* 1969-12-31 23:59:59 +00 */
459 ft.dwHighDateTime = 0x19DB200;
460 ft.dwLowDateTime = 0x5BB78980;
462 cm_LargeSearchTimeFromUnixTime(&ft, scp->clientModTime);
463 pCurrentEntry->CreationTime.LowPart = ft.dwLowDateTime;
464 pCurrentEntry->CreationTime.HighPart = ft.dwHighDateTime;
465 pCurrentEntry->LastAccessTime = pCurrentEntry->CreationTime;
466 pCurrentEntry->LastWriteTime = pCurrentEntry->CreationTime;
467 pCurrentEntry->ChangeTime = pCurrentEntry->CreationTime;
469 pCurrentEntry->EndOfFile = scp->length;
470 pCurrentEntry->AllocationSize = scp->length;
473 switch (scp->fileType) {
474 case CM_SCACHETYPE_DIRECTORY:
475 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY;
477 case CM_SCACHETYPE_MOUNTPOINT:
478 case CM_SCACHETYPE_INVALID:
479 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY | SMB_ATTR_REPARSE_POINT;
481 case CM_SCACHETYPE_SYMLINK:
482 if (cm_TargetPerceivedAsDirectory(scp->mountPointStringp))
483 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY | SMB_ATTR_REPARSE_POINT;
485 pCurrentEntry->FileAttributes = SMB_ATTR_REPARSE_POINT;
488 /* if we get here we either have a normal file
489 * or we have a file for which we have never
490 * received status info. In this case, we can
491 * check the even/odd value of the entry's vnode.
492 * odd means it is to be treated as a directory
493 * and even means it is to be treated as a file.
495 if (scp->fid.vnode & 0x1)
496 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY;
498 pCurrentEntry->FileAttributes = SMB_ATTR_NORMAL;
501 pCurrentEntry->FileAttributes = smb_ExtAttributes(scp);
502 pCurrentEntry->EaSize = 0;
503 pCurrentEntry->Links = scp->linkCount;
505 len = wcslen(shortName);
506 wcsncpy(pCurrentEntry->ShortName, shortName, len);
507 pCurrentEntry->ShortNameLength = (CCHAR)(len * sizeof(WCHAR));
509 pCurrentEntry->FileNameOffset = sizeof(AFSDirEnumEntry);
511 wname = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->FileNameOffset);
512 wcsncpy(wname, name, len);
513 pCurrentEntry->FileNameLength = (ULONG)(sizeof(WCHAR) * len);
515 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntry scp=0x%p fileType=%d dv=%u",
516 scp, scp->fileType, (afs_uint32)scp->dataVersion);
518 if (!(dwFlags & RDR_POP_NO_GETSTATUS))
519 cm_SyncOpDone( scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
521 if ((dwFlags & RDR_POP_NO_GETSTATUS) || !cm_HaveCallback(scp)) {
522 pCurrentEntry->TargetNameOffset = 0;
523 pCurrentEntry->TargetNameLength = 0;
526 switch (scp->fileType) {
527 case CM_SCACHETYPE_MOUNTPOINT:
528 if (dwFlags & RDR_POP_FOLLOW_MOUNTPOINTS) {
529 if ((code2 = cm_ReadMountPoint(scp, userp, reqp)) == 0) {
530 cm_scache_t *targetScp = NULL;
532 pCurrentEntry->TargetNameOffset = pCurrentEntry->FileNameOffset + pCurrentEntry->FileNameLength;
533 len = strlen(scp->mountPointStringp);
534 wtarget = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->TargetNameOffset);
537 cch = MultiByteToWideChar( CP_UTF8, 0, scp->mountPointStringp,
540 len * sizeof(WCHAR));
542 mbstowcs(wtarget, scp->mountPointStringp, len);
544 pCurrentEntry->TargetNameLength = (ULONG)(sizeof(WCHAR) * len);
546 code2 = cm_FollowMountPoint(scp, dscp, userp, reqp, &targetScp);
549 pCurrentEntry->TargetFileId.Cell = targetScp->fid.cell;
550 pCurrentEntry->TargetFileId.Volume = targetScp->fid.volume;
551 pCurrentEntry->TargetFileId.Vnode = targetScp->fid.vnode;
552 pCurrentEntry->TargetFileId.Unique = targetScp->fid.unique;
553 pCurrentEntry->TargetFileId.Hash = targetScp->fid.hash;
555 osi_Log4(afsd_logp, "RDR_PopulateCurrentEntry target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
556 pCurrentEntry->TargetFileId.Cell, pCurrentEntry->TargetFileId.Volume,
557 pCurrentEntry->TargetFileId.Vnode, pCurrentEntry->TargetFileId.Unique);
559 cm_ReleaseSCache(targetScp);
561 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_FollowMountPoint failed scp=0x%p code=0x%x",
565 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_ReadMountPoint failed scp=0x%p code=0x%x",
570 case CM_SCACHETYPE_SYMLINK:
571 case CM_SCACHETYPE_DFSLINK:
573 pCurrentEntry->TargetNameOffset = pCurrentEntry->FileNameOffset + pCurrentEntry->FileNameLength;
574 wtarget = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->TargetNameOffset);
576 if (dwFlags & RDR_POP_EVALUATE_SYMLINKS) {
579 code2 = cm_HandleLink(scp, userp, reqp);
581 mp = scp->mountPointStringp;
584 /* Strip off the msdfs: prefix from the target name for the file system */
585 if (scp->fileType == CM_SCACHETYPE_DFSLINK) {
586 osi_Log0(afsd_logp, "RDR_PopulateCurrentEntry DFSLink Detected");
587 pCurrentEntry->FileType = scp->fileType;
589 if (!strncmp("msdfs:", mp, 6)) {
594 /* only send one slash to the redirector */
595 if (mp[0] == '\\' && mp[1] == '\\') {
600 cch = MultiByteToWideChar( CP_UTF8, 0, mp,
603 len * sizeof(WCHAR));
605 mbstowcs(wtarget, mp, len);
608 pCurrentEntry->TargetNameLength = (ULONG)(sizeof(WCHAR) * len);
610 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_HandleLink failed scp=0x%p code=0x%x",
619 pCurrentEntry->TargetNameOffset = 0;
620 pCurrentEntry->TargetNameLength = 0;
622 lock_ReleaseWrite(&scp->rw);
624 dwEntryLength += pCurrentEntry->FileNameLength + pCurrentEntry->TargetNameLength;
625 dwEntryLength += (dwEntryLength % 8) ? 8 - (dwEntryLength % 8) : 0; /* quad align */
627 *ppNextEntry = (AFSDirEnumEntry *)((PBYTE)pCurrentEntry + dwEntryLength);
628 if (pdwRemainingLength)
629 *pdwRemainingLength = dwMaxEntryLength - dwEntryLength;
631 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntry Success FileNameLength=%d TargetNameLength=%d RemainingLength=%d",
632 pCurrentEntry->FileNameLength, pCurrentEntry->TargetNameLength, *pdwRemainingLength);
638 RDR_PopulateCurrentEntryNoScp( IN AFSDirEnumEntry * pCurrentEntry,
639 IN DWORD dwMaxEntryLength,
640 IN cm_scache_t * dscp,
642 IN cm_user_t * userp,
645 IN wchar_t * shortName,
647 IN afs_uint32 cmError,
648 OUT AFSDirEnumEntry **ppNextEntry,
649 OUT DWORD * pdwRemainingLength)
655 afs_uint32 code = 0, code2 = 0;
657 osi_Log4(afsd_logp, "RDR_PopulateCurrentEntryNoEntry dscp=0x%p name=%S short=%S flags=0x%x",
658 dscp, osi_LogSaveStringW(afsd_logp, name),
659 osi_LogSaveStringW(afsd_logp, shortName), dwFlags);
660 osi_Log1(afsd_logp, "... maxLength=%d", dwMaxEntryLength);
662 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
664 *ppNextEntry = pCurrentEntry;
665 if (pdwRemainingLength)
666 *pdwRemainingLength = dwMaxEntryLength;
667 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntryNoEntry Not Enough Room for Entry %d < %d",
668 dwMaxEntryLength, sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t));
669 return CM_ERROR_TOOBIG;
677 dwEntryLength = sizeof(AFSDirEnumEntry);
679 /* Populate the error code */
680 smb_MapNTError(cmError, &pCurrentEntry->NTStatus, TRUE);
682 /* Populate the fake data */
683 pCurrentEntry->FileId.Cell = fidp->cell;
684 pCurrentEntry->FileId.Volume = fidp->volume;
685 pCurrentEntry->FileId.Vnode = fidp->vnode;
686 pCurrentEntry->FileId.Unique = fidp->unique;
687 pCurrentEntry->FileId.Hash = fidp->hash;
689 pCurrentEntry->FileType = CM_SCACHETYPE_UNKNOWN;
691 pCurrentEntry->DataVersion.QuadPart = CM_SCACHE_VERSION_BAD;
693 cm_LargeSearchTimeFromUnixTime(&ft, 0);
694 pCurrentEntry->Expiration.LowPart = ft.dwLowDateTime;
695 pCurrentEntry->Expiration.HighPart = ft.dwHighDateTime;
697 cm_LargeSearchTimeFromUnixTime(&ft, 0);
698 pCurrentEntry->CreationTime.LowPart = ft.dwLowDateTime;
699 pCurrentEntry->CreationTime.HighPart = ft.dwHighDateTime;
700 pCurrentEntry->LastAccessTime = pCurrentEntry->CreationTime;
701 pCurrentEntry->LastWriteTime = pCurrentEntry->CreationTime;
702 pCurrentEntry->ChangeTime = pCurrentEntry->CreationTime;
704 pCurrentEntry->EndOfFile.QuadPart = 0;
705 pCurrentEntry->AllocationSize.QuadPart = 0;
706 pCurrentEntry->FileAttributes = 0;
707 pCurrentEntry->EaSize = 0;
708 pCurrentEntry->Links = 0;
710 len = wcslen(shortName);
711 wcsncpy(pCurrentEntry->ShortName, shortName, len);
712 pCurrentEntry->ShortNameLength = (CCHAR)(len * sizeof(WCHAR));
714 pCurrentEntry->FileNameOffset = sizeof(AFSDirEnumEntry);
716 wname = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->FileNameOffset);
717 wcsncpy(wname, name, len);
718 pCurrentEntry->FileNameLength = (ULONG)(sizeof(WCHAR) * len);
720 pCurrentEntry->TargetNameOffset = 0;
721 pCurrentEntry->TargetNameLength = 0;
723 dwEntryLength += pCurrentEntry->FileNameLength + pCurrentEntry->TargetNameLength;
724 dwEntryLength += (dwEntryLength % 8) ? 8 - (dwEntryLength % 8) : 0; /* quad align */
726 *ppNextEntry = (AFSDirEnumEntry *)((PBYTE)pCurrentEntry + dwEntryLength);
727 if (pdwRemainingLength)
728 *pdwRemainingLength = dwMaxEntryLength - dwEntryLength;
730 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntryNoScp Success FileNameLength=%d TargetNameLength=%d RemainingLength=%d",
731 pCurrentEntry->FileNameLength, pCurrentEntry->TargetNameLength, *pdwRemainingLength);
737 RDR_EnumerateDirectory( IN cm_user_t *userp,
739 IN AFSDirQueryCB *QueryCB,
742 IN DWORD ResultBufferLength,
743 IN OUT AFSCommResult **ResultCB)
746 cm_direnum_t * enump = NULL;
747 AFSDirEnumResp * pDirEnumResp;
748 AFSDirEnumEntry * pCurrentEntry;
749 size_t size = ResultBufferLength ? sizeof(AFSCommResult) + ResultBufferLength - 1 : sizeof(AFSCommResult);
750 DWORD dwMaxEntryLength;
753 cm_scache_t * dscp = NULL;
758 req.flags |= CM_REQ_WOW64;
760 osi_Log4(afsd_logp, "RDR_EnumerateDirectory FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
761 DirID.Cell, DirID.Volume, DirID.Vnode, DirID.Unique);
763 *ResultCB = (AFSCommResult *)malloc(size);
765 osi_Log0(afsd_logp, "RDR_EnumerateDirectory Out of Memory");
769 memset(*ResultCB, 0, size);
771 if (QueryCB->EnumHandle == (ULONG_PTR)-1) {
772 osi_Log0(afsd_logp, "RDR_EnumerateDirectory No More Entries");
773 (*ResultCB)->ResultStatus = STATUS_NO_MORE_ENTRIES;
774 (*ResultCB)->ResultBufferLength = 0;
778 (*ResultCB)->ResultBufferLength = dwMaxEntryLength = ResultBufferLength;
779 if (ResultBufferLength) {
780 pDirEnumResp = (AFSDirEnumResp *)&(*ResultCB)->ResultData;
781 pCurrentEntry = (AFSDirEnumEntry *)&pDirEnumResp->Entry;
782 dwMaxEntryLength -= FIELD_OFFSET( AFSDirEnumResp, Entry); /* AFSDirEnumResp */
785 if (DirID.Cell != 0) {
786 fid.cell = DirID.Cell;
787 fid.volume = DirID.Volume;
788 fid.vnode = DirID.Vnode;
789 fid.unique = DirID.Unique;
790 fid.hash = DirID.Hash;
792 code = cm_GetSCache(&fid, &dscp, userp, &req);
794 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
795 (*ResultCB)->ResultStatus = status;
796 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_GetSCache failure code=0x%x status=0x%x",
801 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
802 osi_Log0(afsd_logp, "RDR_EnumerateDirectory Object Name Invalid - Cell = 0");
806 /* get the directory size */
807 lock_ObtainWrite(&dscp->rw);
808 code = cm_SyncOp(dscp, NULL, userp, &req, PRSFS_LOOKUP,
809 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
811 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
812 (*ResultCB)->ResultStatus = status;
813 lock_ReleaseWrite(&dscp->rw);
814 cm_ReleaseSCache(dscp);
815 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_SyncOp failure code=0x%x status=0x%x",
820 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
821 lock_ReleaseWrite(&dscp->rw);
823 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
824 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
825 cm_ReleaseSCache(dscp);
826 osi_Log1(afsd_logp, "RDR_EnumerateDirectory Not a Directory dscp=0x%p",
831 osi_Log1(afsd_logp, "RDR_EnumerateDirectory dv=%u", (afs_uint32)dscp->dataVersion);
834 * If there is no enumeration handle, then this is a new query
835 * and we must perform an enumeration for the specified object.
837 if (QueryCB->EnumHandle == (ULONG_PTR)NULL) {
840 code = cm_BeginDirOp(dscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
842 code = cm_BPlusDirEnumerate(dscp, userp, &req,
843 TRUE /* dir locked */, NULL /* no mask */,
844 TRUE /* fetch status? */, &enump);
846 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BPlusDirEnumerate failure code=0x%x",
851 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BeginDirOp failure code=0x%x",
855 enump = (cm_direnum_t *)QueryCB->EnumHandle;
859 if (ResultBufferLength == 0) {
860 code = cm_BPlusDirEnumBulkStat(enump);
862 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BPlusDirEnumBulkStat failure code=0x%x",
866 cm_direnum_entry_t * entryp = NULL;
868 pDirEnumResp->SnapshotDataVersion.QuadPart = enump->dataVersion;
871 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
872 osi_Log0(afsd_logp, "RDR_EnumerateDirectory out of space, returning");
876 code = cm_BPlusDirNextEnumEntry(enump, &entryp);
878 if ((code == 0 || code == CM_ERROR_STOPNOW) && entryp) {
879 cm_scache_t *scp = NULL;
880 int stopnow = (code == CM_ERROR_STOPNOW);
882 if ( !wcscmp(L".", entryp->name) || !wcscmp(L"..", entryp->name) ) {
883 osi_Log0(afsd_logp, "RDR_EnumerateDirectory skipping . or ..");
890 code = cm_GetSCache(&entryp->fid, &scp, userp, &req);
892 osi_Log5(afsd_logp, "RDR_EnumerateDirectory cm_GetSCache failure cell %u vol %u vnode %u uniq %u code=0x%x",
893 entryp->fid.cell, entryp->fid.volume, entryp->fid.vnode, entryp->fid.unique, code);
896 code = entryp->errorCode;
897 scp = code ? NULL : cm_FindSCache(&entryp->fid);
901 code = RDR_PopulateCurrentEntry( pCurrentEntry, dwMaxEntryLength,
902 dscp, scp, userp, &req,
904 cm_Is8Dot3(entryp->name) ? NULL : entryp->shortName,
905 (bWow64 ? RDR_POP_WOW64 : 0) |
906 (bSkipStatus ? RDR_POP_NO_GETSTATUS : 0),
908 &pCurrentEntry, &dwMaxEntryLength);
909 cm_ReleaseSCache(scp);
911 code = RDR_PopulateCurrentEntryNoScp( pCurrentEntry, dwMaxEntryLength,
912 dscp, &entryp->fid, userp, &req,
914 cm_Is8Dot3(entryp->name) ? NULL : entryp->shortName,
915 (bWow64 ? RDR_POP_WOW64 : 0),
917 &pCurrentEntry, &dwMaxEntryLength);
928 if (code || enump->next == enump->count || ResultBufferLength == 0) {
929 cm_BPlusDirFreeEnumeration(enump);
930 enump = (cm_direnum_t *)(ULONG_PTR)-1;
933 if (code == 0 || code == CM_ERROR_STOPNOW) {
934 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
935 osi_Log0(afsd_logp, "RDR_EnumerateDirectory SUCCESS");
937 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
938 (*ResultCB)->ResultStatus = status;
939 osi_Log2(afsd_logp, "RDR_EnumerateDirectory Failure code=0x%x status=0x%x",
943 if (ResultBufferLength) {
944 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwMaxEntryLength;
946 pDirEnumResp->EnumHandle = (ULONG_PTR) enump;
947 pDirEnumResp->CurrentDataVersion.QuadPart = dscp->dataVersion;
951 cm_ReleaseSCache(dscp);
957 RDR_EvaluateNodeByName( IN cm_user_t *userp,
958 IN AFSFileID ParentID,
959 IN WCHAR *FileNameCounted,
960 IN DWORD FileNameLength,
961 IN BOOL CaseSensitive,
965 IN DWORD ResultBufferLength,
966 IN OUT AFSCommResult **ResultCB)
968 AFSFileEvalResultCB *pEvalResultCB = NULL;
969 AFSDirEnumEntry * pCurrentEntry;
970 size_t size = ResultBufferLength ? sizeof(AFSCommResult) + ResultBufferLength - 1 : sizeof(AFSCommResult);
972 cm_scache_t * scp = NULL;
973 cm_scache_t * dscp = NULL;
978 WCHAR * wszName = NULL;
981 wchar_t FileName[260];
983 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
987 req.flags |= CM_REQ_WOW64;
989 osi_Log4(afsd_logp, "RDR_EvaluateNodeByName parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
990 ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
992 /* Allocate enough room to add a volume prefix if necessary */
993 cbName = FileNameLength + (CM_PREFIX_VOL_CCH + 1) * sizeof(WCHAR);
994 wszName = malloc(cbName);
996 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Out of Memory");
999 StringCbCopyNW(wszName, cbName, FileName, FileNameLength);
1000 osi_Log1(afsd_logp, "... name=%S", osi_LogSaveStringW(afsd_logp, wszName));
1002 *ResultCB = (AFSCommResult *)malloc(size);
1004 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Out of Memory");
1009 memset(*ResultCB, 0, size);
1010 (*ResultCB)->ResultBufferLength = 0;
1011 dwRemaining = ResultBufferLength;
1012 if (ResultBufferLength >= sizeof( AFSFileEvalResultCB)) {
1013 pEvalResultCB = (AFSFileEvalResultCB *)&(*ResultCB)->ResultData;
1014 pCurrentEntry = &pEvalResultCB->DirEnum;
1015 dwRemaining -= (sizeof( AFSFileEvalResultCB) - sizeof( AFSDirEnumEntry));
1018 if (ParentID.Cell != 0) {
1019 parentFid.cell = ParentID.Cell;
1020 parentFid.volume = ParentID.Volume;
1021 parentFid.vnode = ParentID.Vnode;
1022 parentFid.unique = ParentID.Unique;
1023 parentFid.hash = ParentID.Hash;
1025 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1027 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1028 (*ResultCB)->ResultStatus = status;
1029 if ( status == STATUS_INVALID_HANDLE)
1030 status = STATUS_OBJECT_PATH_INVALID;
1031 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName cm_GetSCache parentFID failure code=0x%x status=0x%x",
1037 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
1038 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Object Name Invalid - Cell = 0");
1042 /* get the directory size */
1043 lock_ObtainWrite(&dscp->rw);
1044 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1045 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1047 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1048 (*ResultCB)->ResultStatus = status;
1049 lock_ReleaseWrite(&dscp->rw);
1050 cm_ReleaseSCache(dscp);
1051 osi_Log3(afsd_logp, "RDR_EvaluateNodeByName cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1052 dscp, code, status);
1056 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1057 lock_ReleaseWrite(&dscp->rw);
1059 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1060 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1061 cm_ReleaseSCache(dscp);
1062 osi_Log1(afsd_logp, "RDR_EvaluateNodeByName Not a Directory dscp=0x%p",
1068 code = cm_Lookup(dscp, wszName, CM_FLAG_CHECKPATH, userp, &req, &scp);
1070 if ((code == CM_ERROR_NOSUCHPATH || code == CM_ERROR_NOSUCHFILE || code == CM_ERROR_BPLUS_NOMATCH) &&
1071 (wcschr(wszName, '%') != NULL || wcschr(wszName, '#') != NULL)) {
1073 * A volume reference: <cell>{%,#}<volume> -> @vol:<cell>{%,#}<volume>
1075 StringCchCopyNW(wszName, cbName, _C(CM_PREFIX_VOL), CM_PREFIX_VOL_CCH);
1076 StringCbCatNW(wszName, cbName, FileName, FileNameLength);
1077 cm_strlwr_utf16(wszName);
1080 code = cm_EvaluateVolumeReference(wszName, CM_FLAG_CHECKPATH, userp, &req, &scp);
1083 if (code == 0 && scp) {
1084 wchar_t shortName[13]=L"";
1087 cm_Gen8Dot3VolNameW(scp->fid.cell, scp->fid.volume, shortName, NULL);
1088 } else if (!cm_Is8Dot3(wszName)) {
1091 dfid.vnode = htonl(scp->fid.vnode);
1092 dfid.unique = htonl(scp->fid.unique);
1094 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1096 shortName[0] = '\0';
1099 code = RDR_PopulateCurrentEntry(pCurrentEntry, dwRemaining,
1100 dscp, scp, userp, &req,
1101 FileName, shortName,
1102 (bWow64 ? RDR_POP_WOW64 : 0) |
1103 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1104 0, NULL, &dwRemaining);
1106 RDR_FlagScpInUse( scp, FALSE );
1107 cm_ReleaseSCache(scp);
1110 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1111 (*ResultCB)->ResultStatus = status;
1112 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1115 pEvalResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1116 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1117 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1118 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName SUCCESS");
1121 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1122 (*ResultCB)->ResultStatus = status;
1123 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1126 (*ResultCB)->ResultStatus = STATUS_NO_SUCH_FILE;
1127 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName No Such File");
1129 cm_ReleaseSCache(dscp);
1136 RDR_EvaluateNodeByID( IN cm_user_t *userp,
1137 IN AFSFileID ParentID, /* not used */
1138 IN AFSFileID SourceID,
1142 IN DWORD ResultBufferLength,
1143 IN OUT AFSCommResult **ResultCB)
1145 AFSFileEvalResultCB *pEvalResultCB = NULL;
1146 AFSDirEnumEntry * pCurrentEntry = NULL;
1147 size_t size = ResultBufferLength ? sizeof(AFSCommResult) + ResultBufferLength - 1 : sizeof(AFSCommResult);
1148 afs_uint32 code = 0;
1149 cm_scache_t * scp = NULL;
1150 cm_scache_t * dscp = NULL;
1157 osi_Log4(afsd_logp, "RDR_EvaluateNodeByID source FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1158 SourceID.Cell, SourceID.Volume, SourceID.Vnode, SourceID.Unique);
1159 osi_Log4(afsd_logp, "... parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1160 ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1162 *ResultCB = (AFSCommResult *)malloc(size);
1164 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Out of Memory");
1168 memset(*ResultCB, 0, size);
1169 (*ResultCB)->ResultBufferLength = 0;
1170 dwRemaining = ResultBufferLength;
1171 if (ResultBufferLength >= sizeof( AFSFileEvalResultCB)) {
1172 pEvalResultCB = (AFSFileEvalResultCB *)&(*ResultCB)->ResultData;
1173 pCurrentEntry = &pEvalResultCB->DirEnum;
1174 dwRemaining -= (sizeof( AFSFileEvalResultCB) - sizeof( AFSDirEnumEntry));
1179 req.flags |= CM_REQ_WOW64;
1181 if (SourceID.Cell != 0) {
1182 Fid.cell = SourceID.Cell;
1183 Fid.volume = SourceID.Volume;
1184 Fid.vnode = SourceID.Vnode;
1185 Fid.unique = SourceID.Unique;
1186 Fid.hash = SourceID.Hash;
1188 code = cm_GetSCache(&Fid, &scp, userp, &req);
1190 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1191 (*ResultCB)->ResultStatus = status;
1192 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache SourceFID failure code=0x%x status=0x%x",
1197 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
1198 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Name Invalid - Cell = 0");
1202 if (ParentID.Cell != 0) {
1203 cm_SetFid(&parentFid, ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1204 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1206 cm_ReleaseSCache(scp);
1207 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1208 if ( status == STATUS_INVALID_HANDLE)
1209 status = STATUS_OBJECT_PATH_INVALID;
1210 (*ResultCB)->ResultStatus = status;
1211 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1215 } else if (SourceID.Vnode == 1) {
1217 cm_HoldSCache(dscp);
1218 } else if (scp->parentVnode) {
1219 cm_SetFid(&parentFid, SourceID.Cell, SourceID.Volume, scp->parentVnode, scp->parentUnique);
1220 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1222 cm_ReleaseSCache(scp);
1223 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1224 if ( status == STATUS_INVALID_HANDLE)
1225 status = STATUS_OBJECT_PATH_INVALID;
1226 (*ResultCB)->ResultStatus = status;
1227 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1232 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
1233 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Path Invalid - Unknown Parent");
1237 /* Make sure the directory is current */
1238 lock_ObtainWrite(&dscp->rw);
1239 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1240 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1242 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1243 (*ResultCB)->ResultStatus = status;
1244 lock_ReleaseWrite(&dscp->rw);
1245 cm_ReleaseSCache(dscp);
1246 cm_ReleaseSCache(scp);
1247 osi_Log3(afsd_logp, "RDR_EvaluateNodeByID cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1248 dscp, code, status);
1252 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1253 lock_ReleaseWrite(&dscp->rw);
1255 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1256 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1257 cm_ReleaseSCache(dscp);
1258 cm_ReleaseSCache(scp);
1259 osi_Log1(afsd_logp, "RDR_EvaluateNodeByID Not a Directory dscp=0x%p", dscp);
1263 code = RDR_PopulateCurrentEntry(pCurrentEntry, dwRemaining,
1264 dscp, scp, userp, &req, NULL, NULL,
1265 (bWow64 ? RDR_POP_WOW64 : 0) |
1266 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1267 0, NULL, &dwRemaining);
1270 RDR_FlagScpInUse( scp, FALSE );
1271 cm_ReleaseSCache(scp);
1272 cm_ReleaseSCache(dscp);
1275 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1276 (*ResultCB)->ResultStatus = status;
1277 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID FAILURE code=0x%x status=0x%x",
1280 pEvalResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1282 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1283 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1284 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID SUCCESS");
1290 RDR_CreateFileEntry( IN cm_user_t *userp,
1291 IN WCHAR *FileNameCounted,
1292 IN DWORD FileNameLength,
1293 IN AFSFileCreateCB *CreateCB,
1296 IN DWORD ResultBufferLength,
1297 IN OUT AFSCommResult **ResultCB)
1299 AFSFileCreateResultCB *pResultCB = NULL;
1300 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1303 cm_scache_t * dscp = NULL;
1304 afs_uint32 flags = 0;
1306 cm_scache_t * scp = NULL;
1309 wchar_t FileName[260];
1311 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1313 osi_Log4(afsd_logp, "RDR_CreateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1314 CreateCB->ParentId.Cell, CreateCB->ParentId.Volume,
1315 CreateCB->ParentId.Vnode, CreateCB->ParentId.Unique);
1316 osi_Log1(afsd_logp, "... name=%S", osi_LogSaveStringW(afsd_logp, FileName));
1320 req.flags |= CM_REQ_WOW64;
1321 memset(&setAttr, 0, sizeof(cm_attr_t));
1323 *ResultCB = (AFSCommResult *)malloc(size);
1325 osi_Log0(afsd_logp, "RDR_CreateFileEntry out of memory");
1333 parentFid.cell = CreateCB->ParentId.Cell;
1334 parentFid.volume = CreateCB->ParentId.Volume;
1335 parentFid.vnode = CreateCB->ParentId.Vnode;
1336 parentFid.unique = CreateCB->ParentId.Unique;
1337 parentFid.hash = CreateCB->ParentId.Hash;
1339 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1341 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1342 (*ResultCB)->ResultStatus = status;
1343 if ( status == STATUS_INVALID_HANDLE)
1344 status = STATUS_OBJECT_PATH_INVALID;
1345 osi_Log2(afsd_logp, "RDR_CreateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1350 lock_ObtainWrite(&dscp->rw);
1351 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1352 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1354 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1355 (*ResultCB)->ResultStatus = status;
1356 lock_ReleaseWrite(&dscp->rw);
1357 cm_ReleaseSCache(dscp);
1358 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (1) dscp=0x%p code=0x%x status=0x%x",
1359 dscp, code, status);
1363 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1364 lock_ReleaseWrite(&dscp->rw);
1366 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1367 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1368 cm_ReleaseSCache(dscp);
1369 osi_Log1(afsd_logp, "RDR_CreateFileEntry Not a Directory dscp=0x%p",
1374 /* Use current time */
1375 setAttr.mask = CM_ATTRMASK_CLIENTMODTIME;
1376 setAttr.clientModTime = time(NULL);
1378 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1379 if (smb_unixModeDefaultDir) {
1380 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1381 setAttr.unixModeBits = smb_unixModeDefaultDir;
1382 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1383 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1386 code = cm_MakeDir(dscp, FileName, flags, &setAttr, userp, &req, &scp);
1388 if (smb_unixModeDefaultFile) {
1389 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1390 setAttr.unixModeBits = smb_unixModeDefaultFile;
1391 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1392 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1395 setAttr.mask |= CM_ATTRMASK_LENGTH;
1396 setAttr.length.LowPart = CreateCB->AllocationSize.LowPart;
1397 setAttr.length.HighPart = CreateCB->AllocationSize.HighPart;
1398 code = cm_Create(dscp, FileName, flags, &setAttr, &scp, userp, &req);
1401 wchar_t shortName[13]=L"";
1405 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
1407 (*ResultCB)->ResultBufferLength = sizeof( AFSFileCreateResultCB);
1409 pResultCB = (AFSFileCreateResultCB *)(*ResultCB)->ResultData;
1411 dwRemaining = ResultBufferLength - sizeof( AFSFileCreateResultCB) + sizeof( AFSDirEnumEntry);
1413 lock_ObtainWrite(&dscp->rw);
1414 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1415 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1417 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1418 (*ResultCB)->ResultStatus = status;
1419 lock_ReleaseWrite(&dscp->rw);
1420 cm_ReleaseSCache(dscp);
1421 cm_ReleaseSCache(scp);
1422 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (2) dscp=0x%p code=0x%x status=0x%x",
1423 dscp, code, status);
1427 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1429 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1430 lock_ReleaseWrite(&dscp->rw);
1432 dfid.vnode = htonl(scp->fid.vnode);
1433 dfid.unique = htonl(scp->fid.unique);
1435 if (!cm_Is8Dot3(FileName))
1436 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1438 shortName[0] = '\0';
1440 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1441 dscp, scp, userp, &req, FileName, shortName,
1442 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1443 0, NULL, &dwRemaining);
1446 RDR_FlagScpInUse( scp, FALSE );
1447 cm_ReleaseSCache(scp);
1448 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1449 osi_Log0(afsd_logp, "RDR_CreateFileEntry SUCCESS");
1451 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1452 (*ResultCB)->ResultStatus = status;
1453 (*ResultCB)->ResultBufferLength = 0;
1454 osi_Log2(afsd_logp, "RDR_CreateFileEntry FAILURE code=0x%x status=0x%x",
1458 cm_ReleaseSCache(dscp);
1464 RDR_UpdateFileEntry( IN cm_user_t *userp,
1465 IN AFSFileID FileId,
1466 IN AFSFileUpdateCB *UpdateCB,
1468 IN DWORD ResultBufferLength,
1469 IN OUT AFSCommResult **ResultCB)
1471 AFSFileUpdateResultCB *pResultCB = NULL;
1472 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1476 afs_uint32 flags = 0;
1478 cm_scache_t * scp = NULL;
1479 cm_scache_t * dscp = NULL;
1481 time_t clientModTime;
1484 BOOL bScpLocked = FALSE;
1488 req.flags |= CM_REQ_WOW64;
1489 memset(&setAttr, 0, sizeof(cm_attr_t));
1491 osi_Log4(afsd_logp, "RDR_UpdateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1492 UpdateCB->ParentId.Cell, UpdateCB->ParentId.Volume,
1493 UpdateCB->ParentId.Vnode, UpdateCB->ParentId.Unique);
1494 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1495 FileId.Cell, FileId.Volume,
1496 FileId.Vnode, FileId.Unique);
1498 *ResultCB = (AFSCommResult *)malloc( size);
1500 osi_Log0(afsd_logp, "RDR_UpdateFileEntry Out of Memory");
1508 parentFid.cell = UpdateCB->ParentId.Cell;
1509 parentFid.volume = UpdateCB->ParentId.Volume;
1510 parentFid.vnode = UpdateCB->ParentId.Vnode;
1511 parentFid.unique = UpdateCB->ParentId.Unique;
1512 parentFid.hash = UpdateCB->ParentId.Hash;
1514 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1516 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1517 (*ResultCB)->ResultStatus = status;
1518 if ( status == STATUS_INVALID_HANDLE)
1519 status = STATUS_OBJECT_PATH_INVALID;
1520 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1525 lock_ObtainWrite(&dscp->rw);
1527 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1528 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1530 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1531 (*ResultCB)->ResultStatus = status;
1532 lock_ReleaseWrite(&dscp->rw);
1533 cm_ReleaseSCache(dscp);
1534 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1535 dscp, code, status);
1539 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1540 lock_ReleaseWrite(&dscp->rw);
1543 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1544 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1545 cm_ReleaseSCache(dscp);
1546 osi_Log1(afsd_logp, "RDR_UpdateFileEntry Not a Directory dscp=0x%p",
1551 Fid.cell = FileId.Cell;
1552 Fid.volume = FileId.Volume;
1553 Fid.vnode = FileId.Vnode;
1554 Fid.unique = FileId.Unique;
1555 Fid.hash = FileId.Hash;
1557 code = cm_GetSCache(&Fid, &scp, userp, &req);
1559 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1560 (*ResultCB)->ResultStatus = status;
1561 cm_ReleaseSCache(dscp);
1562 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache object FID failure code=0x%x status=0x%x",
1567 lock_ObtainWrite(&scp->rw);
1569 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1570 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1572 lock_ReleaseWrite(&scp->rw);
1573 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1574 (*ResultCB)->ResultStatus = status;
1575 (*ResultCB)->ResultBufferLength = 0;
1576 cm_ReleaseSCache(dscp);
1577 cm_ReleaseSCache(scp);
1578 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
1582 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1584 if (UpdateCB->ChangeTime.QuadPart) {
1586 if (scp->fileType == CM_SCACHETYPE_FILE) {
1587 /* Do not set length and other attributes at the same time */
1588 if (scp->length.QuadPart != UpdateCB->AllocationSize.QuadPart) {
1589 osi_Log2(afsd_logp, "RDR_UpdateFileEntry Length Change 0x%x -> 0x%x",
1590 (afs_uint32)scp->length.QuadPart, (afs_uint32)UpdateCB->AllocationSize.QuadPart);
1591 setAttr.mask |= CM_ATTRMASK_LENGTH;
1592 setAttr.length.LowPart = UpdateCB->AllocationSize.LowPart;
1593 setAttr.length.HighPart = UpdateCB->AllocationSize.HighPart;
1594 lock_ReleaseWrite(&scp->rw);
1596 code = cm_SetAttr(scp, &setAttr, userp, &req);
1604 lock_ObtainWrite(&scp->rw);
1607 if ((scp->unixModeBits & 0200) && (UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1608 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1609 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1610 } else if (!(scp->unixModeBits & 0200) && !(UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1611 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1612 setAttr.unixModeBits = scp->unixModeBits | 0222;
1616 if (UpdateCB->LastWriteTime.QuadPart) {
1617 ft.dwLowDateTime = UpdateCB->LastWriteTime.LowPart;
1618 ft.dwHighDateTime = UpdateCB->LastWriteTime.HighPart;
1620 cm_UnixTimeFromLargeSearchTime(& clientModTime, &ft);
1623 lock_ObtainWrite(&scp->rw);
1626 if (scp->clientModTime != clientModTime) {
1627 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1628 setAttr.clientModTime = clientModTime;
1633 lock_ReleaseWrite(&scp->rw);
1635 code = cm_SetAttr(scp, &setAttr, userp, &req);
1642 lock_ReleaseWrite(&scp->rw);
1646 DWORD dwRemaining = ResultBufferLength - sizeof( AFSFileUpdateResultCB) + sizeof( AFSDirEnumEntry);
1648 pResultCB = (AFSFileUpdateResultCB *)(*ResultCB)->ResultData;
1650 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1652 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1653 dscp, scp, userp, &req, NULL, NULL,
1654 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1655 0, NULL, &dwRemaining);
1656 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1657 osi_Log0(afsd_logp, "RDR_UpdateFileEntry SUCCESS");
1659 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1660 (*ResultCB)->ResultStatus = status;
1661 (*ResultCB)->ResultBufferLength = 0;
1662 osi_Log2(afsd_logp, "RDR_UpdateFileEntry FAILURE code=0x%x status=0x%x",
1665 cm_ReleaseSCache(scp);
1666 cm_ReleaseSCache(dscp);
1672 RDR_CleanupFileEntry( IN cm_user_t *userp,
1673 IN AFSFileID FileId,
1674 IN WCHAR *FileNameCounted,
1675 IN DWORD FileNameLength,
1676 IN AFSFileCleanupCB *CleanupCB,
1678 IN BOOL bLastHandle,
1679 IN BOOL bDeleteFile,
1680 IN BOOL bUnlockFile,
1681 IN DWORD ResultBufferLength,
1682 IN OUT AFSCommResult **ResultCB)
1684 AFSFileCleanupResultCB *pResultCB = NULL;
1685 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1688 afs_uint32 code = 0;
1689 afs_uint32 flags = 0;
1691 cm_scache_t * scp = NULL;
1692 cm_scache_t * dscp = NULL;
1694 time_t clientModTime;
1697 BOOL bScpLocked = FALSE;
1698 BOOL bDscpLocked = FALSE;
1699 BOOL bFlushFile = FALSE;
1704 req.flags |= CM_REQ_WOW64;
1705 memset(&setAttr, 0, sizeof(cm_attr_t));
1707 osi_Log4(afsd_logp, "RDR_CleanupFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1708 CleanupCB->ParentId.Cell, CleanupCB->ParentId.Volume,
1709 CleanupCB->ParentId.Vnode, CleanupCB->ParentId.Unique);
1710 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1711 FileId.Cell, FileId.Volume,
1712 FileId.Vnode, FileId.Unique);
1714 *ResultCB = (AFSCommResult *)malloc( size);
1716 osi_Log0(afsd_logp, "RDR_CleanupFileEntry Out of Memory");
1724 parentFid.cell = CleanupCB->ParentId.Cell;
1725 parentFid.volume = CleanupCB->ParentId.Volume;
1726 parentFid.vnode = CleanupCB->ParentId.Vnode;
1727 parentFid.unique = CleanupCB->ParentId.Unique;
1728 parentFid.hash = CleanupCB->ParentId.Hash;
1730 if (parentFid.cell) {
1731 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1733 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1734 if ( status == STATUS_INVALID_HANDLE)
1735 status = STATUS_OBJECT_PATH_INVALID;
1736 (*ResultCB)->ResultStatus = status;
1737 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1742 lock_ObtainWrite(&dscp->rw);
1744 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1745 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1747 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure dscp=0x%p code=0x%x",
1753 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1754 lock_ReleaseWrite(&dscp->rw);
1755 bDscpLocked = FALSE;
1757 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1758 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1759 cm_ReleaseSCache(dscp);
1760 osi_Log1(afsd_logp, "RDR_CleanupFileEntry Not a Directory dscp=0x%p",
1767 Fid.cell = FileId.Cell;
1768 Fid.volume = FileId.Volume;
1769 Fid.vnode = FileId.Vnode;
1770 Fid.unique = FileId.Unique;
1771 Fid.hash = FileId.Hash;
1773 code = cm_GetSCache(&Fid, &scp, userp, &req);
1775 osi_Log1(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache object FID failure code=0x%x",
1780 lock_ObtainWrite(&scp->rw);
1782 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1783 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1785 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure scp=0x%p code=0x%x",
1789 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1791 if ((bLastHandle || bFlushFile) &&
1792 scp->redirBufCount > 0)
1794 LARGE_INTEGER heldExtents;
1795 AFSFileExtentCB extentList[1024];
1796 DWORD extentCount = 0;
1801 heldExtents.QuadPart = 0;
1803 for ( srbp = redirq_to_cm_buf_t(scp->redirQueueT);
1805 srbp = redirq_to_cm_buf_t(osi_QPrev(&srbp->redirq)))
1807 extentList[extentCount].Flags = 0;
1808 extentList[extentCount].Length = cm_data.blockSize;
1809 extentList[extentCount].FileOffset.QuadPart = srbp->offset.QuadPart;
1810 extentList[extentCount].CacheOffset.QuadPart = srbp->datap - RDR_extentBaseAddress;
1811 lock_ObtainWrite(&buf_globalLock);
1812 srbp->redirReleaseRequested = now;
1813 lock_ReleaseWrite(&buf_globalLock);
1816 if (extentCount == 1024) {
1817 lock_ReleaseWrite(&scp->rw);
1818 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1820 if (code == CM_ERROR_RETRY) {
1822 * The redirector either is not holding the extents or cannot let them
1823 * go because they are otherwise in use. At the moment, do nothing.
1830 lock_ObtainWrite(&scp->rw);
1834 if (code == 0 && extentCount > 0) {
1836 lock_ReleaseWrite(&scp->rw);
1839 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1844 /* No longer in use by redirector */
1846 lock_ObtainWrite(&scp->rw);
1851 lock_AssertWrite(&scp->rw);
1852 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
1855 if (bLastHandle || bFlushFile) {
1857 lock_ObtainWrite(&scp->rw);
1860 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
1861 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1864 lock_ReleaseWrite(&scp->rw);
1868 code = cm_FSync(scp, userp, &req, bScpLocked);
1870 if (bLastHandle && code)
1874 if (bUnlockFile || bDeleteFile) {
1876 lock_ObtainWrite(&scp->rw);
1879 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1880 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1882 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp (2) failure scp=0x%p code=0x%x",
1887 key = cm_GenerateKey(CM_SESSION_IFS, CleanupCB->ProcessId, 0);
1889 /* the scp is now locked and current */
1890 code = cm_UnlockByKey(scp, key,
1891 bDeleteFile ? CM_UNLOCK_FLAG_BY_FID : 0,
1894 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1900 if (CleanupCB->ChangeTime.QuadPart) {
1902 if (scp->fileType == CM_SCACHETYPE_FILE) {
1903 /* Do not set length and other attributes at the same time */
1904 if (scp->length.QuadPart != CleanupCB->AllocationSize.QuadPart) {
1905 osi_Log2(afsd_logp, "RDR_CleanupFileEntry Length Change 0x%x -> 0x%x",
1906 (afs_uint32)scp->length.QuadPart, (afs_uint32)CleanupCB->AllocationSize.QuadPart);
1907 setAttr.mask |= CM_ATTRMASK_LENGTH;
1908 setAttr.length.LowPart = CleanupCB->AllocationSize.LowPart;
1909 setAttr.length.HighPart = CleanupCB->AllocationSize.HighPart;
1912 lock_ReleaseWrite(&scp->rw);
1915 code = cm_SetAttr(scp, &setAttr, userp, &req);
1923 lock_ObtainWrite(&scp->rw);
1927 if ((scp->unixModeBits & 0200) && (CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1928 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1929 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1930 } else if (!(scp->unixModeBits & 0200) && !(CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1931 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1932 setAttr.unixModeBits = scp->unixModeBits | 0222;
1936 if (CleanupCB->LastWriteTime.QuadPart) {
1937 ft.dwLowDateTime = CleanupCB->LastWriteTime.LowPart;
1938 ft.dwHighDateTime = CleanupCB->LastWriteTime.HighPart;
1940 cm_UnixTimeFromLargeSearchTime(&clientModTime, &ft);
1941 if (scp->clientModTime != clientModTime) {
1942 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1943 setAttr.clientModTime = clientModTime;
1949 lock_ReleaseWrite(&scp->rw);
1951 code = cm_SetAttr(scp, &setAttr, userp, &req);
1955 /* Now drop the lock enforcing the share access */
1956 if ( CleanupCB->FileAccess != AFS_FILE_ACCESS_NOLOCK) {
1957 unsigned int sLockType;
1958 LARGE_INTEGER LOffset, LLength;
1960 if (CleanupCB->FileAccess == AFS_FILE_ACCESS_SHARED)
1961 sLockType = LOCKING_ANDX_SHARED_LOCK;
1965 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, CleanupCB->Identifier);
1967 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
1968 LOffset.LowPart = SMB_FID_QLOCK_LOW;
1969 LLength.HighPart = 0;
1970 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
1973 lock_ObtainWrite(&scp->rw);
1977 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
1980 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
1982 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
1984 if (code == CM_ERROR_RANGE_NOT_LOCKED)
1986 osi_Log3(afsd_logp, "RDR_CleanupFileEntry Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
1987 CleanupCB->FileAccess, CleanupCB->ProcessId, CleanupCB->Identifier);
1995 lock_ReleaseWrite(&dscp->rw);
1997 lock_ReleaseWrite(&scp->rw);
1999 if (dscp && bDeleteFile) {
2000 WCHAR FileName[260];
2002 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
2004 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
2005 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
2007 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2010 if ( ResultBufferLength >= sizeof( AFSFileCleanupResultCB))
2012 (*ResultCB)->ResultBufferLength = sizeof( AFSFileCleanupResultCB);
2013 pResultCB = (AFSFileCleanupResultCB *)&(*ResultCB)->ResultData;
2014 pResultCB->ParentDataVersion.QuadPart = dscp ? dscp->dataVersion : 0;
2016 (*ResultCB)->ResultBufferLength = 0;
2020 (*ResultCB)->ResultStatus = 0;
2021 osi_Log0(afsd_logp, "RDR_CleanupFileEntry SUCCESS");
2023 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2024 (*ResultCB)->ResultStatus = status;
2025 osi_Log2(afsd_logp, "RDR_CleanupFileEntry FAILURE code=0x%x status=0x%x",
2029 cm_ReleaseSCache(scp);
2031 cm_ReleaseSCache(dscp);
2037 RDR_DeleteFileEntry( IN cm_user_t *userp,
2038 IN AFSFileID ParentId,
2039 IN ULONGLONG ProcessId,
2040 IN WCHAR *FileNameCounted,
2041 IN DWORD FileNameLength,
2044 IN DWORD ResultBufferLength,
2045 IN OUT AFSCommResult **ResultCB)
2048 AFSFileDeleteResultCB *pResultCB = NULL;
2049 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2052 cm_scache_t * dscp = NULL;
2053 cm_scache_t * scp = NULL;
2054 afs_uint32 flags = 0;
2058 wchar_t FileName[260];
2061 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
2063 osi_Log4(afsd_logp, "RDR_DeleteFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2064 ParentId.Cell, ParentId.Volume,
2065 ParentId.Vnode, ParentId.Unique);
2066 osi_Log2(afsd_logp, "... name=%S checkOnly=%x",
2067 osi_LogSaveStringW(afsd_logp, FileName),
2072 req.flags |= CM_REQ_WOW64;
2073 memset(&setAttr, 0, sizeof(cm_attr_t));
2075 *ResultCB = (AFSCommResult *)malloc( size);
2077 osi_Log0(afsd_logp, "RDR_DeleteFileEntry out of memory");
2085 parentFid.cell = ParentId.Cell;
2086 parentFid.volume = ParentId.Volume;
2087 parentFid.vnode = ParentId.Vnode;
2088 parentFid.unique = ParentId.Unique;
2089 parentFid.hash = ParentId.Hash;
2091 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
2093 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2094 if ( status == STATUS_INVALID_HANDLE)
2095 status = STATUS_OBJECT_PATH_INVALID;
2096 (*ResultCB)->ResultStatus = status;
2097 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
2102 lock_ObtainWrite(&dscp->rw);
2104 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
2105 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2107 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2108 (*ResultCB)->ResultStatus = status;
2109 (*ResultCB)->ResultBufferLength = 0;
2110 lock_ReleaseWrite(&dscp->rw);
2111 cm_ReleaseSCache(dscp);
2112 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
2113 dscp, code, status);
2117 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2118 lock_ReleaseWrite(&dscp->rw);
2120 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2121 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2122 cm_ReleaseSCache(dscp);
2123 osi_Log1(afsd_logp, "RDR_DeleteFileEntry Not a Directory dscp=0x%p",
2128 code = cm_Lookup(dscp, FileName, 0, userp, &req, &scp);
2130 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2131 (*ResultCB)->ResultStatus = status;
2132 (*ResultCB)->ResultBufferLength = 0;
2133 cm_ReleaseSCache(dscp);
2134 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_Lookup failure code=0x%x status=0x%x",
2139 lock_ObtainWrite(&scp->rw);
2140 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_DELETE,
2141 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2143 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2144 (*ResultCB)->ResultStatus = status;
2145 (*ResultCB)->ResultBufferLength = 0;
2146 lock_ReleaseWrite(&scp->rw);
2147 cm_ReleaseSCache(scp);
2148 cm_ReleaseSCache(dscp);
2149 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2155 /* Drop all locks since the file is being deleted */
2156 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2157 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2159 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2160 (*ResultCB)->ResultStatus = status;
2161 (*ResultCB)->ResultBufferLength = 0;
2162 lock_ReleaseWrite(&scp->rw);
2163 cm_ReleaseSCache(scp);
2164 cm_ReleaseSCache(dscp);
2165 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp Lock failure scp=0x%p code=0x%x status=0x%x",
2169 /* the scp is now locked and current */
2170 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId, 0);
2172 code = cm_UnlockByKey(scp, key,
2173 CM_UNLOCK_FLAG_BY_FID,
2176 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2177 lock_ReleaseWrite(&scp->rw);
2179 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
2180 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
2182 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2184 lock_ReleaseWrite(&scp->rw);
2188 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
2190 (*ResultCB)->ResultBufferLength = sizeof( AFSFileDeleteResultCB);
2192 pResultCB = (AFSFileDeleteResultCB *)(*ResultCB)->ResultData;
2194 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
2195 osi_Log0(afsd_logp, "RDR_DeleteFileEntry SUCCESS");
2197 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2198 (*ResultCB)->ResultStatus = status;
2199 (*ResultCB)->ResultBufferLength = 0;
2200 osi_Log2(afsd_logp, "RDR_DeleteFileEntry FAILURE code=0x%x status=0x%x",
2204 cm_ReleaseSCache(dscp);
2205 cm_ReleaseSCache(scp);
2211 RDR_RenameFileEntry( IN cm_user_t *userp,
2212 IN WCHAR *SourceFileNameCounted,
2213 IN DWORD SourceFileNameLength,
2214 IN AFSFileID SourceFileId,
2215 IN AFSFileRenameCB *pRenameCB,
2217 IN DWORD ResultBufferLength,
2218 IN OUT AFSCommResult **ResultCB)
2221 AFSFileRenameResultCB *pResultCB = NULL;
2222 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2223 AFSFileID SourceParentId = pRenameCB->SourceParentId;
2224 AFSFileID TargetParentId = pRenameCB->TargetParentId;
2225 WCHAR * TargetFileNameCounted = pRenameCB->TargetName;
2226 DWORD TargetFileNameLength = pRenameCB->TargetNameLength;
2227 cm_fid_t SourceParentFid;
2228 cm_fid_t TargetParentFid;
2230 cm_fid_t OrigTargetFid = {0,0,0,0,0};
2232 cm_scache_t * oldDscp;
2233 cm_scache_t * newDscp;
2235 wchar_t shortName[13];
2236 wchar_t SourceFileName[260];
2237 wchar_t TargetFileName[260];
2245 req.flags |= CM_REQ_WOW64;
2247 StringCchCopyNW(SourceFileName, 260, SourceFileNameCounted, SourceFileNameLength / sizeof(WCHAR));
2248 StringCchCopyNW(TargetFileName, 260, TargetFileNameCounted, TargetFileNameLength / sizeof(WCHAR));
2250 osi_Log4(afsd_logp, "RDR_RenameFileEntry Source Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2251 SourceParentId.Cell, SourceParentId.Volume,
2252 SourceParentId.Vnode, SourceParentId.Unique);
2253 osi_Log2(afsd_logp, "... Source Name=%S Length %u", osi_LogSaveStringW(afsd_logp, SourceFileName), SourceFileNameLength);
2254 osi_Log4(afsd_logp, "... Target Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2255 TargetParentId.Cell, TargetParentId.Volume,
2256 TargetParentId.Vnode, TargetParentId.Unique);
2257 osi_Log2(afsd_logp, "... Target Name=%S Length %u", osi_LogSaveStringW(afsd_logp, TargetFileName), TargetFileNameLength);
2259 *ResultCB = (AFSCommResult *)malloc( size);
2267 pResultCB = (AFSFileRenameResultCB *)(*ResultCB)->ResultData;
2269 if (SourceFileNameLength == 0 || TargetFileNameLength == 0)
2271 osi_Log2(afsd_logp, "RDR_RenameFileEntry Invalid Name Length: src %u target %u",
2272 SourceFileNameLength, TargetFileNameLength);
2273 (*ResultCB)->ResultStatus = STATUS_INVALID_PARAMETER;
2277 SourceParentFid.cell = SourceParentId.Cell;
2278 SourceParentFid.volume = SourceParentId.Volume;
2279 SourceParentFid.vnode = SourceParentId.Vnode;
2280 SourceParentFid.unique = SourceParentId.Unique;
2281 SourceParentFid.hash = SourceParentId.Hash;
2283 TargetParentFid.cell = TargetParentId.Cell;
2284 TargetParentFid.volume = TargetParentId.Volume;
2285 TargetParentFid.vnode = TargetParentId.Vnode;
2286 TargetParentFid.unique = TargetParentId.Unique;
2287 TargetParentFid.hash = TargetParentId.Hash;
2289 code = cm_GetSCache(&SourceParentFid, &oldDscp, userp, &req);
2291 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache source parent failed code 0x%x", code);
2292 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2293 if ( status == STATUS_INVALID_HANDLE)
2294 status = STATUS_OBJECT_PATH_INVALID;
2295 (*ResultCB)->ResultStatus = status;
2299 lock_ObtainWrite(&oldDscp->rw);
2300 code = cm_SyncOp(oldDscp, NULL, userp, &req, 0,
2301 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2303 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp oldDscp 0x%p failed code 0x%x", oldDscp, code);
2304 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2305 if ( status == STATUS_INVALID_HANDLE)
2306 status = STATUS_OBJECT_PATH_INVALID;
2307 (*ResultCB)->ResultStatus = status;
2308 lock_ReleaseWrite(&oldDscp->rw);
2309 cm_ReleaseSCache(oldDscp);
2313 cm_SyncOpDone(oldDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2314 lock_ReleaseWrite(&oldDscp->rw);
2317 if (oldDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2318 osi_Log1(afsd_logp, "RDR_RenameFileEntry oldDscp 0x%p not a directory", oldDscp);
2319 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2320 cm_ReleaseSCache(oldDscp);
2324 code = cm_GetSCache(&TargetParentFid, &newDscp, userp, &req);
2326 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target parent failed code 0x%x", code);
2327 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2328 (*ResultCB)->ResultStatus = status;
2329 cm_ReleaseSCache(oldDscp);
2333 lock_ObtainWrite(&newDscp->rw);
2334 code = cm_SyncOp(newDscp, NULL, userp, &req, 0,
2335 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2337 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp newDscp 0x%p failed code 0x%x", newDscp, code);
2338 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2339 (*ResultCB)->ResultStatus = status;
2340 lock_ReleaseWrite(&newDscp->rw);
2341 cm_ReleaseSCache(oldDscp);
2342 cm_ReleaseSCache(newDscp);
2346 cm_SyncOpDone(newDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2347 lock_ReleaseWrite(&newDscp->rw);
2350 if (newDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2351 osi_Log1(afsd_logp, "RDR_RenameFileEntry newDscp 0x%p not a directory", newDscp);
2352 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2353 cm_ReleaseSCache(oldDscp);
2354 cm_ReleaseSCache(newDscp);
2358 /* Obtain the original FID just for debugging purposes */
2359 code = cm_BeginDirOp( oldDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2361 code = cm_BPlusDirLookup(&dirop, SourceFileName, &SourceFid);
2362 code = cm_BPlusDirLookup(&dirop, TargetFileName, &OrigTargetFid);
2363 cm_EndDirOp(&dirop);
2366 code = cm_Rename( oldDscp, NULL, SourceFileName,
2367 newDscp, TargetFileName, userp, &req);
2369 cm_scache_t *scp = 0;
2372 (*ResultCB)->ResultBufferLength = ResultBufferLength;
2373 dwRemaining = ResultBufferLength - sizeof( AFSFileRenameResultCB) + sizeof( AFSDirEnumEntry);
2374 (*ResultCB)->ResultStatus = 0;
2376 pResultCB->SourceParentDataVersion.QuadPart = oldDscp->dataVersion;
2377 pResultCB->TargetParentDataVersion.QuadPart = newDscp->dataVersion;
2379 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p SUCCESS",
2382 code = cm_BeginDirOp( newDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2384 code = cm_BPlusDirLookup(&dirop, TargetFileName, &TargetFid);
2385 cm_EndDirOp(&dirop);
2389 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_BPlusDirLookup failed code 0x%x",
2391 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
2392 cm_ReleaseSCache(oldDscp);
2393 cm_ReleaseSCache(newDscp);
2397 osi_Log4(afsd_logp, "RDR_RenameFileEntry Target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2398 TargetFid.cell, TargetFid.volume,
2399 TargetFid.vnode, TargetFid.unique);
2401 code = cm_GetSCache(&TargetFid, &scp, userp, &req);
2403 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target failed code 0x%x", code);
2404 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2405 (*ResultCB)->ResultStatus = status;
2406 cm_ReleaseSCache(oldDscp);
2407 cm_ReleaseSCache(newDscp);
2411 /* Make sure the source vnode is current */
2412 lock_ObtainWrite(&scp->rw);
2413 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2414 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2416 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp scp 0x%p failed code 0x%x", scp, code);
2417 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2418 (*ResultCB)->ResultStatus = status;
2419 lock_ReleaseWrite(&scp->rw);
2420 cm_ReleaseSCache(oldDscp);
2421 cm_ReleaseSCache(newDscp);
2422 cm_ReleaseSCache(scp);
2426 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2427 lock_ReleaseWrite(&scp->rw);
2429 dfid.vnode = htonl(scp->fid.vnode);
2430 dfid.unique = htonl(scp->fid.unique);
2432 if (!cm_Is8Dot3(TargetFileName))
2433 cm_Gen8Dot3NameIntW(TargetFileName, &dfid, shortName, NULL);
2435 shortName[0] = '\0';
2437 RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
2438 newDscp, scp, userp, &req, TargetFileName, shortName,
2439 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
2440 0, NULL, &dwRemaining);
2441 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
2442 cm_ReleaseSCache(scp);
2444 osi_Log0(afsd_logp, "RDR_RenameFileEntry SUCCESS");
2446 osi_Log3(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p failed code 0x%x",
2447 oldDscp, newDscp, code);
2448 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2449 (*ResultCB)->ResultStatus = status;
2450 (*ResultCB)->ResultBufferLength = 0;
2453 cm_ReleaseSCache(oldDscp);
2454 cm_ReleaseSCache(newDscp);
2459 RDR_FlushFileEntry( IN cm_user_t *userp,
2460 IN AFSFileID FileId,
2462 IN DWORD ResultBufferLength,
2463 IN OUT AFSCommResult **ResultCB)
2465 cm_scache_t *scp = NULL;
2476 req.flags |= CM_REQ_WOW64;
2478 osi_Log4(afsd_logp, "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x",
2479 FileId.Cell, FileId.Volume,
2480 FileId.Vnode, FileId.Unique);
2482 snprintf( dbgstr, 1024,
2483 "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x\n",
2484 FileId.Cell, FileId.Volume,
2485 FileId.Vnode, FileId.Unique);
2486 OutputDebugStringA( dbgstr);
2489 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2491 osi_Log0(afsd_logp, "RDR_FlushFileEntry out of memory");
2497 sizeof( AFSCommResult));
2499 /* Process the release */
2500 Fid.cell = FileId.Cell;
2501 Fid.volume = FileId.Volume;
2502 Fid.vnode = FileId.Vnode;
2503 Fid.unique = FileId.Unique;
2504 Fid.hash = FileId.Hash;
2506 code = cm_GetSCache(&Fid, &scp, userp, &req);
2508 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2509 (*ResultCB)->ResultStatus = status;
2510 osi_Log2(afsd_logp, "RDR_FlushFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2515 lock_ObtainWrite(&scp->rw);
2516 if (scp->flags & CM_SCACHEFLAG_DELETED) {
2517 lock_ReleaseWrite(&scp->rw);
2518 (*ResultCB)->ResultStatus = STATUS_INVALID_HANDLE;
2522 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2523 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2525 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2526 (*ResultCB)->ResultStatus = status;
2527 lock_ReleaseWrite(&scp->rw);
2528 cm_ReleaseSCache(scp);
2529 osi_Log3(afsd_logp, "RDR_FlushFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2534 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2535 lock_ReleaseWrite(&scp->rw);
2537 code = cm_FSync(scp, userp, &req, FALSE);
2538 cm_ReleaseSCache(scp);
2541 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2542 (*ResultCB)->ResultStatus = status;
2543 osi_Log2(afsd_logp, "RDR_FlushFileEntry FAILURE code=0x%x status=0x%x",
2546 (*ResultCB)->ResultStatus = 0;
2547 osi_Log0(afsd_logp, "RDR_FlushFileEntry SUCCESS");
2549 (*ResultCB)->ResultBufferLength = 0;
2555 RDR_CheckAccess( IN cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp,
2559 ULONG afs_acc, afs_gr;
2561 afs_uint32 code = 0;
2563 file = (scp->fileType == CM_SCACHETYPE_FILE);
2566 /* access definitions from prs_fs.h */
2568 if (access & FILE_READ_DATA)
2569 afs_acc |= PRSFS_READ;
2570 if (access & FILE_READ_EA || access & FILE_READ_ATTRIBUTES)
2571 afs_acc |= PRSFS_READ;
2572 if (file && ((access & FILE_WRITE_DATA) || (access & FILE_APPEND_DATA)))
2573 afs_acc |= PRSFS_WRITE;
2574 if (access & FILE_WRITE_EA || access & FILE_WRITE_ATTRIBUTES)
2575 afs_acc |= PRSFS_WRITE;
2576 if (dir && ((access & FILE_ADD_FILE) || (access & FILE_ADD_SUBDIRECTORY)))
2577 afs_acc |= PRSFS_INSERT;
2578 if (dir && (access & FILE_LIST_DIRECTORY))
2579 afs_acc |= PRSFS_LOOKUP;
2580 if (file && (access & FILE_EXECUTE))
2581 afs_acc |= PRSFS_WRITE;
2582 if (dir && (access & FILE_TRAVERSE))
2583 afs_acc |= PRSFS_READ;
2584 if (dir && (access & FILE_DELETE_CHILD))
2585 afs_acc |= PRSFS_DELETE;
2586 if ((access & DELETE))
2587 afs_acc |= PRSFS_DELETE;
2589 /* check ACL with server */
2590 lock_ObtainWrite(&scp->rw);
2593 if (cm_HaveAccessRights(scp, userp, reqp, afs_acc, &afs_gr))
2599 /* we don't know the required access rights */
2600 code = cm_GetAccessRights(scp, userp, reqp);
2606 lock_ReleaseWrite(&(scp->rw));
2610 if (afs_gr & PRSFS_READ)
2611 *granted |= FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | FILE_EXECUTE;
2612 if (afs_gr & PRSFS_WRITE)
2613 *granted |= FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES | FILE_EXECUTE;
2614 if (afs_gr & PRSFS_INSERT)
2615 *granted |= (dir ? FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY : 0) | (file ? FILE_ADD_SUBDIRECTORY : 0);
2616 if (afs_gr & PRSFS_LOOKUP)
2617 *granted |= (dir ? FILE_LIST_DIRECTORY : 0);
2618 if (afs_gr & PRSFS_DELETE)
2619 *granted |= FILE_DELETE_CHILD | DELETE;
2620 if (afs_gr & PRSFS_LOCK)
2622 if (afs_gr & PRSFS_ADMINISTER)
2625 *granted |= SYNCHRONIZE | READ_CONTROL;
2627 /* don't give more access than what was requested */
2629 osi_Log3(afsd_logp, "RDR_CheckAccess SUCCESS scp=0x%p requested=0x%x granted=0x%x", scp, access, *granted);
2631 osi_Log2(afsd_logp, "RDR_CheckAccess FAILURE scp=0x%p code=0x%x",
2638 RDR_OpenFileEntry( IN cm_user_t *userp,
2639 IN AFSFileID FileId,
2640 IN AFSFileOpenCB *OpenCB,
2643 IN DWORD ResultBufferLength,
2644 IN OUT AFSCommResult **ResultCB)
2646 AFSFileOpenResultCB *pResultCB = NULL;
2647 cm_scache_t *scp = NULL;
2648 cm_user_t *sysUserp = NULL;
2650 cm_lock_data_t *ldp = NULL;
2657 req.flags |= CM_REQ_WOW64;
2659 osi_Log4(afsd_logp, "RDR_OpenFileEntry File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2660 FileId.Cell, FileId.Volume,
2661 FileId.Vnode, FileId.Unique);
2663 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2665 osi_Log0(afsd_logp, "RDR_OpenFileEntry out of memory");
2671 sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2673 pResultCB = (AFSFileOpenResultCB *)(*ResultCB)->ResultData;
2675 /* Process the release */
2676 Fid.cell = FileId.Cell;
2677 Fid.volume = FileId.Volume;
2678 Fid.vnode = FileId.Vnode;
2679 Fid.unique = FileId.Unique;
2680 Fid.hash = FileId.Hash;
2682 code = cm_GetSCache(&Fid, &scp, userp, &req);
2684 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2685 (*ResultCB)->ResultStatus = status;
2686 osi_Log2(afsd_logp, "RDR_OpenFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2691 lock_ObtainWrite(&scp->rw);
2692 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2693 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2695 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2696 (*ResultCB)->ResultStatus = status;
2697 lock_ReleaseWrite(&scp->rw);
2698 cm_ReleaseSCache(scp);
2699 osi_Log3(afsd_logp, "RDR_OpenFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2704 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2705 lock_ReleaseWrite(&scp->rw);
2707 sysUserp = RDR_GetLocalSystemUser();
2710 * Skip the open check if the request is coming from the local system account.
2711 * The local system has no tokens and therefore any requests sent to a file
2712 * server will fail. Unfortunately, there are special system processes that
2713 * perform actions on files and directories in preparation for memory mapping
2714 * executables. If the open check fails, the real request from the user process
2715 * will never be issued.
2717 * Permitting the file system to allow subsequent operations to proceed does
2718 * not compromise security. All requests to obtain file data or directory
2719 * enumerations will subsequently fail if they are not submitted under the
2720 * context of a process for that have access to the necessary credentials.
2723 if ( userp == sysUserp)
2725 osi_Log1(afsd_logp, "RDR_OpenFileEntry LOCAL_SYSTEM access check skipped scp=0x%p",
2727 pResultCB->GrantedAccess = OpenCB->DesiredAccess;
2728 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2739 "RDR_OpenFileEntry repeating open check scp=0x%p userp=0x%p code=0x%x",
2742 code = cm_CheckNTOpen(scp, OpenCB->DesiredAccess, OpenCB->ShareAccess,
2744 OpenCB->ProcessId, OpenCB->Identifier,
2747 code = RDR_CheckAccess(scp, userp, &req, OpenCB->DesiredAccess, &pResultCB->GrantedAccess);
2748 cm_CheckNTOpenDone(scp, userp, &req, &ldp);
2749 } while (count < 100 && (code == CM_ERROR_RETRY || code == CM_ERROR_WOULDBLOCK));
2753 * If we are restricting sharing, we should do so with a suitable
2756 if (code == 0 && scp->fileType == CM_SCACHETYPE_FILE && !(OpenCB->ShareAccess & FILE_SHARE_WRITE)) {
2758 LARGE_INTEGER LOffset, LLength;
2761 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2762 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2763 LLength.HighPart = 0;
2764 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2767 * If we are not opening the file for writing, then we don't
2768 * try to get an exclusive lock. No one else should be able to
2769 * get an exclusive lock on the file anyway, although someone
2770 * else can get a shared lock.
2772 if ((OpenCB->ShareAccess & FILE_SHARE_READ) || !(OpenCB->DesiredAccess & AFS_ACCESS_WRITE))
2774 sLockType = LOCKING_ANDX_SHARED_LOCK;
2779 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, OpenCB->Identifier);
2781 lock_ObtainWrite(&scp->rw);
2782 code = cm_Lock(scp, sLockType, LOffset, LLength, key, 0, userp, &req, NULL);
2783 lock_ReleaseWrite(&scp->rw);
2786 code = CM_ERROR_SHARING_VIOLATION;
2787 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2789 if (sLockType == LOCKING_ANDX_SHARED_LOCK)
2790 pResultCB->FileAccess = AFS_FILE_ACCESS_SHARED;
2792 pResultCB->FileAccess = AFS_FILE_ACCESS_EXCLUSIVE;
2795 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2798 cm_ReleaseUser(sysUserp);
2799 if (code == 0 && bHoldFid)
2800 RDR_FlagScpInUse( scp, FALSE );
2801 cm_ReleaseSCache(scp);
2804 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2805 (*ResultCB)->ResultStatus = status;
2806 osi_Log2(afsd_logp, "RDR_OpenFileEntry FAILURE code=0x%x status=0x%x",
2809 (*ResultCB)->ResultStatus = 0;
2810 (*ResultCB)->ResultBufferLength = sizeof( AFSFileOpenResultCB);
2811 osi_Log0(afsd_logp, "RDR_OpenFileEntry SUCCESS");
2817 RDR_ReleaseFileAccess( IN cm_user_t *userp,
2818 IN AFSFileID FileId,
2819 IN AFSFileAccessReleaseCB *ReleaseFileCB,
2821 IN DWORD ResultBufferLength,
2822 IN OUT AFSCommResult **ResultCB)
2825 unsigned int sLockType;
2826 LARGE_INTEGER LOffset, LLength;
2827 cm_scache_t *scp = NULL;
2835 req.flags |= CM_REQ_WOW64;
2837 osi_Log4(afsd_logp, "RDR_ReleaseFileAccess File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2838 FileId.Cell, FileId.Volume,
2839 FileId.Vnode, FileId.Unique);
2841 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2843 osi_Log0(afsd_logp, "RDR_ReleaseFileAccess out of memory");
2847 memset( *ResultCB, '\0', sizeof( AFSCommResult));
2849 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_NOLOCK)
2852 /* Process the release */
2853 Fid.cell = FileId.Cell;
2854 Fid.volume = FileId.Volume;
2855 Fid.vnode = FileId.Vnode;
2856 Fid.unique = FileId.Unique;
2857 Fid.hash = FileId.Hash;
2859 code = cm_GetSCache(&Fid, &scp, userp, &req);
2861 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2862 (*ResultCB)->ResultStatus = status;
2863 osi_Log2(afsd_logp, "RDR_ReleaseFileAccess cm_GetSCache FID failure code=0x%x status=0x%x",
2868 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_SHARED)
2869 sLockType = LOCKING_ANDX_SHARED_LOCK;
2873 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, ReleaseFileCB->Identifier);
2875 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2876 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2877 LLength.HighPart = 0;
2878 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2880 lock_ObtainWrite(&scp->rw);
2882 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
2885 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
2887 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
2889 if (code == CM_ERROR_RANGE_NOT_LOCKED)
2891 osi_Log3(afsd_logp, "RDR_ReleaseFileAccess Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
2892 ReleaseFileCB->FileAccess, ReleaseFileCB->ProcessId, ReleaseFileCB->Identifier);
2896 lock_ReleaseWrite(&scp->rw);
2898 osi_Log0(afsd_logp, "RDR_ReleaseFileAccessEntry SUCCESS");
2902 HexCheckSum(unsigned char * buf, int buflen, unsigned char * md5cksum)
2905 static char tr[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
2908 return "buffer length too small to HexCheckSum";
2910 for (i=0;i<16;i++) {
2913 buf[i*2] = tr[k / 16];
2914 buf[i*2+1] = tr[k % 16];
2922 * Extent requests from the file system are triggered when a file
2923 * page is not resident in the Windows cache. The file system is
2924 * responsible for loading the page but cannot block the request
2925 * while doing so. The AFS Redirector forwards the requests to
2926 * the AFS cache manager while indicating to Windows that the page
2927 * is not yet available. A polling operation will then ensue with
2928 * the AFS Redirector issuing a RDR_RequestFileExtentsXXX call for
2929 * each poll attempt. As each request is received and processed
2930 * by a separate worker thread in the service, this can lead to
2931 * contention by multiple threads attempting to claim the same
2932 * cm_buf_t objects. Therefore, it is important that
2934 * (a) the service avoid processing more than one overlapping
2935 * extent request at a time
2936 * (b) background daemon processing be used to avoid blocking
2939 * Beginning with the 20091122 build of the redirector, the redirector
2940 * will not issue an additional RDR_RequestFileExtentsXXX call for
2941 * each poll request. Instead, afsd_service is required to track
2942 * the requests and return them to the redirector or fail the
2943 * portions of the request that cannot be satisfied.
2945 * The request processing returns any extents that can be returned
2946 * immediately to the redirector. The rest of the requested range(s)
2947 * are queued as background operations using RDR_BkgFetch().
2950 /* do the background fetch. */
2952 RDR_BkgFetch(cm_scache_t *scp, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4,
2953 cm_user_t *userp, cm_req_t *reqp)
2959 osi_hyper_t fetched;
2960 osi_hyper_t tblocksize;
2963 cm_buf_t *bufp = NULL;
2964 DWORD dwResultBufferLength;
2965 AFSSetFileExtentsCB *pResultCB;
2969 int reportErrorToRedir = 0;
2970 int force_retry = 0;
2972 FileId.Cell = scp->fid.cell;
2973 FileId.Volume = scp->fid.volume;
2974 FileId.Vnode = scp->fid.vnode;
2975 FileId.Unique = scp->fid.unique;
2976 FileId.Hash = scp->fid.hash;
2978 if ((GetTickCount() - reqp->startTime) / 1000 > HardDeadtimeout * 5) {
2979 RDR_SetFileStatus( &scp->fid, &userp->authgroup, STATUS_IO_TIMEOUT);
2983 fetched.LowPart = 0;
2984 fetched.HighPart = 0;
2985 tblocksize = ConvertLongToLargeInteger(cm_data.buf_blockSize);
2988 length.LowPart = p3;
2989 length.HighPart = p4;
2991 end = LargeIntegerAdd(base, length);
2993 osi_Log5(afsd_logp, "Starting BKG Fetch scp 0x%p offset 0x%x:%x length 0x%x:%x",
2994 scp, p2, p1, p4, p3);
2997 * Make sure we have a callback.
2998 * This is necessary so that we can return access denied
2999 * if a callback cannot be granted.
3001 lock_ObtainWrite(&scp->rw);
3002 code = cm_SyncOp(scp, NULL, userp, reqp, PRSFS_READ,
3003 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3005 lock_ReleaseWrite(&scp->rw);
3006 osi_Log2(afsd_logp, "RDR_BkgFetch cm_SyncOp failure scp=0x%p code=0x%x",
3008 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
3009 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3012 lock_ReleaseWrite(&scp->rw);
3014 dwResultBufferLength = (DWORD)(sizeof( AFSSetFileExtentsCB) + sizeof( AFSSetFileExtentsCB) * (length.QuadPart / cm_data.blockSize + 1));
3015 pResultCB = (AFSSetFileExtentsCB *)malloc( dwResultBufferLength );
3017 return CM_ERROR_RETRY;
3019 memset( pResultCB, '\0', dwResultBufferLength );
3020 pResultCB->FileId = FileId;
3022 for ( code = 0, offset = base;
3023 code == 0 && LargeIntegerLessThan(offset, end);
3024 offset = LargeIntegerAdd(offset, tblocksize) )
3026 int bBufRelease = TRUE;
3029 lock_ReleaseWrite(&scp->rw);
3033 code = buf_Get(scp, &offset, reqp, &bufp);
3036 * any error from buf_Get() is non-fatal.
3037 * we need to re-queue this extent fetch.
3044 lock_ObtainWrite(&scp->rw);
3048 code = cm_GetBuffer(scp, bufp, NULL, userp, reqp);
3050 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3051 #ifdef VALIDATE_CHECK_SUM
3057 if (bufp->flags & CM_BUF_DIRTY)
3058 cm_BufWrite(scp, &bufp->offset, cm_data.buf_blockSize, CM_BUF_WRITE_SCP_LOCKED, userp, reqp);
3060 lock_ObtainWrite(&buf_globalLock);
3061 if (!(bufp->flags & CM_BUF_DIRTY) &&
3062 bufp->cmFlags == 0 &&
3063 !(bufp->qFlags & CM_BUF_QREDIR)) {
3064 buf_InsertToRedirQueue(scp, bufp);
3065 lock_ReleaseWrite(&buf_globalLock);
3067 #ifdef VALIDATE_CHECK_SUM
3068 buf_ComputeCheckSum(bufp);
3070 pResultCB->FileExtents[count].Flags = 0;
3071 pResultCB->FileExtents[count].FileOffset.QuadPart = bufp->offset.QuadPart;
3072 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3073 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3075 fetched = LargeIntegerAdd(fetched, tblocksize);
3076 bBufRelease = FALSE;
3078 #ifdef VALIDATE_CHECK_SUM
3080 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3081 snprintf( dbgstr, 1024,
3082 "RDR_BkgFetch md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3084 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3085 pResultCB->FileExtents[count].FileOffset.HighPart,
3086 pResultCB->FileExtents[count].FileOffset.LowPart,
3087 pResultCB->FileExtents[count].CacheOffset.HighPart,
3088 pResultCB->FileExtents[count].CacheOffset.LowPart);
3089 OutputDebugStringA( dbgstr);
3092 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3093 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3095 lock_ReleaseWrite(&buf_globalLock);
3096 if ((bufp->cmFlags != 0) || (bufp->flags & CM_BUF_DIRTY)) {
3097 /* An I/O operation is already in progress */
3099 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",
3100 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3102 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3103 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3107 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3108 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3112 * depending on what the error from cm_GetBuffer is
3113 * it may or may not be fatal. Only return fatal errors.
3114 * Re-queue a request for others.
3116 osi_Log5(afsd_logp, "RDR_BkgFetch Extent2FS FAILURE bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x code 0x%x",
3117 bufp, offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize, code);
3119 case CM_ERROR_NOACCESS:
3120 case CM_ERROR_NOSUCHFILE:
3121 case CM_ERROR_NOSUCHPATH:
3122 case CM_ERROR_NOSUCHVOLUME:
3123 case CM_ERROR_NOSUCHCELL:
3124 case CM_ERROR_INVAL:
3125 case CM_ERROR_BADFD:
3126 case CM_ERROR_CLOCKSKEW:
3128 case CM_ERROR_QUOTA:
3129 case CM_ERROR_LOCK_CONFLICT:
3131 * these are fatal errors. deliver what we can
3134 reportErrorToRedir = 1;
3138 * non-fatal errors. re-queue the exent
3140 code = CM_ERROR_RETRY;
3150 lock_ObtainWrite(&scp->rw);
3154 /* wakeup anyone who is waiting */
3155 if (scp->flags & CM_SCACHEFLAG_WAITING) {
3156 osi_Log1(afsd_logp, "RDR Bkg Fetch Waking scp 0x%p", scp);
3157 osi_Wakeup((LONG_PTR) &scp->flags);
3159 lock_ReleaseWrite(&scp->rw);
3162 pResultCB->ExtentCount = count;
3163 RDR_SetFileExtents( pResultCB, dwResultBufferLength);
3167 if (reportErrorToRedir) {
3168 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
3169 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3172 osi_Log4(afsd_logp, "Ending BKG Fetch scp 0x%p code 0x%x fetched 0x%x:%x",
3173 scp, code, fetched.HighPart, fetched.LowPart);
3175 return force_retry ? CM_ERROR_RETRY : code;
3180 RDR_RequestFileExtentsAsync( IN cm_user_t *userp,
3181 IN AFSFileID FileId,
3182 IN AFSRequestExtentsCB *RequestExtentsCB,
3184 IN OUT DWORD * ResultBufferLength,
3185 IN OUT AFSSetFileExtentsCB **ResultCB)
3187 AFSSetFileExtentsCB *pResultCB = NULL;
3191 cm_scache_t *scp = NULL;
3194 afs_uint32 code = 0;
3196 LARGE_INTEGER ByteOffset, BeginOffset, EndOffset, QueueOffset;
3197 afs_uint32 QueueLength;
3199 BOOLEAN bBufRelease = TRUE;
3203 req.flags |= CM_REQ_WOW64;
3204 req.flags |= CM_REQ_NORETRY;
3206 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3207 FileId.Cell, FileId.Volume,
3208 FileId.Vnode, FileId.Unique);
3209 osi_Log4(afsd_logp, "... Flags 0x%x ByteOffset 0x%x:%x Length 0x%x",
3210 RequestExtentsCB->Flags,
3211 RequestExtentsCB->ByteOffset.HighPart, RequestExtentsCB->ByteOffset.LowPart,
3212 RequestExtentsCB->Length);
3213 Length = sizeof( AFSSetFileExtentsCB) + sizeof( AFSFileExtentCB) * (RequestExtentsCB->Length / cm_data.blockSize + 1);
3215 pResultCB = *ResultCB = (AFSSetFileExtentsCB *)malloc( Length );
3216 if (*ResultCB == NULL) {
3217 *ResultBufferLength = 0;
3220 *ResultBufferLength = Length;
3222 memset( pResultCB, '\0', Length );
3223 pResultCB->FileId = FileId;
3225 Fid.cell = FileId.Cell;
3226 Fid.volume = FileId.Volume;
3227 Fid.vnode = FileId.Vnode;
3228 Fid.unique = FileId.Unique;
3229 Fid.hash = FileId.Hash;
3231 code = cm_GetSCache(&Fid, &scp, userp, &req);
3233 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync cm_GetSCache FID failure code=0x%x",
3235 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3240 * Make sure we have a callback.
3241 * This is necessary so that we can return access denied
3242 * if a callback cannot be granted.
3244 lock_ObtainWrite(&scp->rw);
3245 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_READ,
3246 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3247 lock_ReleaseWrite(&scp->rw);
3249 cm_ReleaseSCache(scp);
3250 osi_Log2(afsd_logp, "RDR_RequestFileExtentsAsync cm_SyncOp failure scp=0x%p code=0x%x",
3252 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3253 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3257 /* Allocate the extents from the buffer package */
3259 ByteOffset = BeginOffset = RequestExtentsCB->ByteOffset,
3260 EndOffset.QuadPart = ByteOffset.QuadPart + RequestExtentsCB->Length;
3261 code == 0 && ByteOffset.QuadPart < EndOffset.QuadPart;
3262 ByteOffset.QuadPart += cm_data.blockSize)
3264 BOOL bHaveBuffer = FALSE;
3267 thyper.QuadPart = ByteOffset.QuadPart;
3269 code = buf_Get(scp, &thyper, &req, &bufp);
3271 lock_ObtainMutex(&bufp->mx);
3274 if (bufp->qFlags & CM_BUF_QREDIR) {
3276 } else if (bufp->flags & CM_BUF_DIRTY) {
3277 bHaveBuffer = FALSE;
3279 code = buf_CleanAsyncLocked(scp, bufp, &req, 0, NULL);
3284 case CM_ERROR_RETRY:
3285 /* Couldn't flush it, obtain it asynchronously so we don't block the thread. */
3286 bHaveBuffer = FALSE;
3290 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3291 RDR_SetFileStatus(&FileId, &userp->authgroup, status);
3292 bHaveBuffer = FALSE;
3297 osi_hyper_t minLength; /* effective end of file */
3299 lock_ObtainRead(&scp->rw);
3300 bHaveBuffer = cm_HaveBuffer(scp, bufp, TRUE);
3302 if (LargeIntegerGreaterThan(scp->length, scp->serverLength))
3303 minLength = scp->serverLength;
3305 minLength = scp->length;
3308 LargeIntegerGreaterThanOrEqualTo(bufp->offset, minLength)) {
3309 memset(bufp->datap, 0, cm_data.buf_blockSize);
3310 bufp->dataVersion = scp->dataVersion;
3313 else if ((RequestExtentsCB->Flags & AFS_EXTENT_FLAG_CLEAN) &&
3314 ByteOffset.QuadPart <= bufp->offset.QuadPart &&
3315 EndOffset.QuadPart >= bufp->offset.QuadPart + cm_data.blockSize)
3317 memset(bufp->datap, 0, cm_data.blockSize);
3318 bufp->dataVersion = scp->dataVersion;
3319 buf_SetDirty(bufp, &req, 0, cm_data.blockSize, userp);
3322 lock_ReleaseRead(&scp->rw);
3326 * if this buffer is already up to date, skip it.
3329 if (ByteOffset.QuadPart == BeginOffset.QuadPart) {
3330 BeginOffset.QuadPart += cm_data.blockSize;
3332 QueueLength = (afs_uint32)(ByteOffset.QuadPart - BeginOffset.QuadPart);
3333 QueueOffset = BeginOffset;
3334 BeginOffset = ByteOffset;
3337 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3338 #ifdef VALIDATE_CHECK_SUM
3344 lock_ObtainWrite(&buf_globalLock);
3345 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3346 buf_InsertToRedirQueue(scp, bufp);
3347 lock_ReleaseWrite(&buf_globalLock);
3349 #ifdef VALIDATE_CHECK_SUM
3350 buf_ComputeCheckSum(bufp);
3352 /* we already have the buffer, return it now */
3353 pResultCB->FileExtents[count].Flags = 0;
3354 pResultCB->FileExtents[count].FileOffset = ByteOffset;
3355 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3356 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3359 bBufRelease = FALSE;
3361 #ifdef VALIDATE_CHECK_SUM
3363 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3364 snprintf( dbgstr, 1024,
3365 "RDR_RequestFileExtentsAsync md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3367 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3368 pResultCB->FileExtents[count].FileOffset.HighPart,
3369 pResultCB->FileExtents[count].FileOffset.LowPart,
3370 pResultCB->FileExtents[count].CacheOffset.HighPart,
3371 pResultCB->FileExtents[count].CacheOffset.LowPart);
3372 OutputDebugStringA( dbgstr);
3375 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3376 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3378 lock_ReleaseWrite(&buf_globalLock);
3383 * The service is not handing off the extent to the redirector in this pass.
3384 * However, we know the buffer is in recent use so move the buffer to the
3385 * front of the queue
3387 lock_ObtainWrite(&buf_globalLock);
3388 buf_MoveToHeadOfRedirQueue(scp, bufp);
3389 lock_ReleaseWrite(&buf_globalLock);
3391 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3392 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3396 lock_ReleaseMutex(&bufp->mx);
3401 cm_QueueBKGRequest(scp, RDR_BkgFetch, QueueOffset.LowPart, QueueOffset.HighPart,
3402 QueueLength, 0, userp, &req);
3403 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3404 QueueOffset.HighPart, QueueOffset.LowPart, QueueLength);
3407 /* No error from buf_Get() can be fatal */
3408 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync buf_Get FAILURE offset 0x%x:%x code 0x%x",
3409 BeginOffset.HighPart, BeginOffset.LowPart, code);
3413 if (BeginOffset.QuadPart != EndOffset.QuadPart) {
3414 afs_uint32 length = (afs_uint32)(EndOffset.QuadPart - BeginOffset.QuadPart);
3416 cm_QueueBKGRequest(scp, RDR_BkgFetch, BeginOffset.LowPart, BeginOffset.HighPart,
3417 length, 0, userp, &req);
3418 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3419 BeginOffset.HighPart, BeginOffset.LowPart, length);
3421 cm_ReleaseSCache(scp);
3423 (*ResultCB)->ExtentCount = count;
3424 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync replying with 0x%x extent records", count);
3429 * When processing an extent release the extents must be accepted back by
3430 * the service even if there is an error condition returned to the redirector.
3431 * For example, there may no longer be a callback present or the file may
3432 * have been deleted on the file server. Regardless, the extents must be
3433 * put back into the pool.
3436 RDR_ReleaseFileExtents( IN cm_user_t *userp,
3437 IN AFSFileID FileId,
3438 IN AFSReleaseExtentsCB *ReleaseExtentsCB,
3440 IN DWORD ResultBufferLength,
3441 IN OUT AFSCommResult **ResultCB)
3444 cm_scache_t *scp = NULL;
3455 #ifdef VALIDATE_CHECK_SUM
3456 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3463 req.flags |= CM_REQ_WOW64;
3465 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3466 FileId.Cell, FileId.Volume,
3467 FileId.Vnode, FileId.Unique);
3469 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
3475 sizeof( AFSCommResult));
3477 /* Process the release */
3478 Fid.cell = FileId.Cell;
3479 Fid.volume = FileId.Volume;
3480 Fid.vnode = FileId.Vnode;
3481 Fid.unique = FileId.Unique;
3482 Fid.hash = FileId.Hash;
3484 code = cm_GetSCache(&Fid, &scp, userp, &req);
3486 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3487 (*ResultCB)->ResultStatus = status;
3488 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents cm_GetSCache FID failure code=0x%x status=0x%x",
3492 deleted = scp && (scp->flags & CM_SCACHEFLAG_DELETED);
3495 * We do not stop processing as a result of being unable to find the cm_scache object.
3496 * If this occurs something really bad has happened since the cm_scache object must have
3497 * been recycled while extents were held by the redirector. However, we will be resilient
3498 * and carry on without it.
3500 * If the file is known to be deleted, there is no point attempting to ask the
3501 * file server about it or update the attributes.
3503 if (scp && ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart &&
3508 memset(&setAttr, 0, sizeof(cm_attr_t));
3509 lock_ObtainWrite(&scp->rw);
3510 if (ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3512 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents new length fid vol 0x%x vno 0x%x length 0x%x:%x",
3513 scp->fid.volume, scp->fid.vnode,
3514 ReleaseExtentsCB->AllocationSize.HighPart,
3515 ReleaseExtentsCB->AllocationSize.LowPart);
3517 setAttr.mask |= CM_ATTRMASK_LENGTH;
3518 setAttr.length.LowPart = ReleaseExtentsCB->AllocationSize.LowPart;
3519 setAttr.length.HighPart = ReleaseExtentsCB->AllocationSize.HighPart;
3521 lock_ReleaseWrite(&scp->rw);
3523 code = cm_SetAttr(scp, &setAttr, userp, &req);
3526 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3527 AFSFileExtentCB * pExtent = &ReleaseExtentsCB->FileExtents[count];
3529 thyper.QuadPart = pExtent->FileOffset.QuadPart;
3531 bufp = buf_Find(&Fid, &thyper);
3533 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
3534 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
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; previously released",
3540 pExtent->CacheOffset.HighPart,
3541 pExtent->CacheOffset.LowPart);
3543 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3544 Fid.volume, Fid.vnode,
3545 pExtent->FileOffset.HighPart,
3546 pExtent->FileOffset.LowPart);
3547 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
3548 pExtent->CacheOffset.HighPart,
3549 pExtent->CacheOffset.LowPart);
3555 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
3556 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3557 Fid.volume, Fid.vnode,
3558 pExtent->FileOffset.HighPart,
3559 pExtent->FileOffset.LowPart);
3560 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
3561 pExtent->CacheOffset.HighPart,
3562 pExtent->CacheOffset.LowPart);
3564 /* Move the buffer to the front of the queue */
3565 lock_ObtainWrite(&buf_globalLock);
3566 buf_MoveToHeadOfRedirQueue(scp, bufp);
3567 lock_ReleaseWrite(&buf_globalLock);
3572 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
3573 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3574 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x not held by file system",
3575 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
3576 pExtent->FileOffset.LowPart);
3577 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3578 pExtent->CacheOffset.HighPart,
3579 pExtent->CacheOffset.LowPart);
3581 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents bufp 0x%p vno 0x%x foffset 0x%x:%x",
3582 bufp, bufp->fid.vnode, pExtent->FileOffset.HighPart,
3583 pExtent->FileOffset.LowPart);
3584 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3585 pExtent->CacheOffset.HighPart,
3586 pExtent->CacheOffset.LowPart);
3588 if (pExtent->Flags || ReleaseExtentsCB->Flags) {
3589 lock_ObtainMutex(&bufp->mx);
3590 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
3591 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
3593 if (bufp->qFlags & CM_BUF_QREDIR) {
3594 lock_ObtainWrite(&buf_globalLock);
3595 if (bufp->qFlags & CM_BUF_QREDIR) {
3596 buf_RemoveFromRedirQueue(scp, bufp);
3597 buf_ReleaseLocked(bufp, TRUE);
3599 lock_ReleaseWrite(&buf_globalLock);
3602 snprintf( dbgstr, 1024,
3603 "RDR_ReleaseFileExtents releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3604 Fid.volume, Fid.vnode, Fid.unique,
3605 pExtent->FileOffset.HighPart,
3606 pExtent->FileOffset.LowPart,
3607 pExtent->CacheOffset.HighPart,
3608 pExtent->CacheOffset.LowPart);
3609 OutputDebugStringA( dbgstr);
3614 snprintf( dbgstr, 1024,
3615 "RDR_ReleaseFileExtents not releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3616 Fid.volume, Fid.vnode, Fid.unique,
3617 pExtent->FileOffset.HighPart,
3618 pExtent->FileOffset.LowPart,
3619 pExtent->CacheOffset.HighPart,
3620 pExtent->CacheOffset.LowPart);
3621 OutputDebugStringA( dbgstr);
3623 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
3624 Fid.volume, Fid.vnode,
3625 pExtent->FileOffset.HighPart,
3626 pExtent->FileOffset.LowPart);
3627 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3628 pExtent->CacheOffset.HighPart,
3629 pExtent->CacheOffset.LowPart);
3632 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
3633 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY) )
3635 #ifdef VALIDATE_CHECK_SUM
3637 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3641 * if the saved checksum matches the checksum of the current state of the buffer
3642 * then the buffer is the same as what was given to the kernel.
3644 if ( buf_ValidateCheckSum(bufp) ) {
3645 buf_ComputeCheckSum(bufp);
3647 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3650 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
3651 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3653 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3656 snprintf( dbgstr, 1024,
3657 "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",
3658 md5dbg, md5dbg2,md5dbg3,
3659 Fid.volume, Fid.vnode, Fid.unique,
3660 pExtent->FileOffset.HighPart,
3661 pExtent->FileOffset.LowPart,
3662 pExtent->CacheOffset.HighPart,
3663 pExtent->CacheOffset.LowPart);
3664 OutputDebugStringA( dbgstr);
3666 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
3667 Fid.volume, Fid.vnode,
3668 pExtent->FileOffset.HighPart,
3669 pExtent->FileOffset.LowPart);
3670 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3671 pExtent->CacheOffset.HighPart,
3672 pExtent->CacheOffset.LowPart);
3673 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3677 snprintf( dbgstr, 1024,
3678 "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",
3679 md5dbg, md5dbg2, md5dbg3,
3680 Fid.volume, Fid.vnode, Fid.unique,
3681 pExtent->FileOffset.HighPart,
3682 pExtent->FileOffset.LowPart,
3683 pExtent->CacheOffset.HighPart,
3684 pExtent->CacheOffset.LowPart);
3685 OutputDebugStringA( dbgstr);
3687 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3688 Fid.volume, Fid.vnode,
3689 pExtent->FileOffset.HighPart,
3690 pExtent->FileOffset.LowPart);
3691 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3692 pExtent->CacheOffset.HighPart,
3693 pExtent->CacheOffset.LowPart);
3697 snprintf( dbgstr, 1024,
3698 "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",
3699 Fid.volume, Fid.vnode, Fid.unique,
3700 pExtent->FileOffset.HighPart,
3701 pExtent->FileOffset.LowPart,
3702 pExtent->CacheOffset.HighPart,
3703 pExtent->CacheOffset.LowPart);
3704 OutputDebugStringA( dbgstr);
3706 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3707 Fid.volume, Fid.vnode,
3708 pExtent->FileOffset.HighPart,
3709 pExtent->FileOffset.LowPart);
3710 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3711 pExtent->CacheOffset.HighPart,
3712 pExtent->CacheOffset.LowPart);
3715 buf_ComputeCheckSum(bufp);
3717 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3719 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3720 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3722 snprintf( dbgstr, 1024,
3723 "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",
3724 md5dbg, md5dbg2,md5dbg3,
3725 Fid.volume, Fid.vnode, Fid.unique,
3726 pExtent->FileOffset.HighPart,
3727 pExtent->FileOffset.LowPart,
3728 pExtent->CacheOffset.HighPart,
3729 pExtent->CacheOffset.LowPart);
3730 OutputDebugStringA( dbgstr);
3732 snprintf( dbgstr, 1024,
3733 "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",
3734 md5dbg, md5dbg2,md5dbg3,
3735 Fid.volume, Fid.vnode, Fid.unique,
3736 pExtent->FileOffset.HighPart,
3737 pExtent->FileOffset.LowPart,
3738 pExtent->CacheOffset.HighPart,
3739 pExtent->CacheOffset.LowPart);
3740 OutputDebugStringA( dbgstr);
3743 snprintf( dbgstr, 1024,
3744 "RDR_ReleaseFileExtents dirty flag set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3745 Fid.volume, Fid.vnode, Fid.unique,
3746 pExtent->FileOffset.HighPart,
3747 pExtent->FileOffset.LowPart,
3748 pExtent->CacheOffset.HighPart,
3749 pExtent->CacheOffset.LowPart);
3750 OutputDebugStringA( dbgstr);
3753 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3756 #else /* !VALIDATE_CHECK_SUM */
3757 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3759 #endif /* VALIDATE_CHECK_SUM */
3761 #ifdef VALIDATE_CHECK_SUM
3764 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3766 if ( !buf_ValidateCheckSum(bufp) ) {
3767 buf_ComputeCheckSum(bufp);
3769 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3770 snprintf( dbgstr, 1024,
3771 "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",
3773 Fid.volume, Fid.vnode, Fid.unique,
3774 pExtent->FileOffset.HighPart,
3775 pExtent->FileOffset.LowPart,
3776 pExtent->CacheOffset.HighPart,
3777 pExtent->CacheOffset.LowPart);
3778 OutputDebugStringA( dbgstr);
3780 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set but extent has changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3781 Fid.volume, Fid.vnode,
3782 pExtent->FileOffset.HighPart,
3783 pExtent->FileOffset.LowPart);
3784 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3785 pExtent->CacheOffset.HighPart,
3786 pExtent->CacheOffset.LowPart);
3787 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3790 buf_ComputeCheckSum(bufp);
3792 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3793 snprintf( dbgstr, 1024,
3794 "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3795 Fid.volume, Fid.vnode, Fid.unique,
3796 pExtent->FileOffset.HighPart,
3797 pExtent->FileOffset.LowPart,
3798 pExtent->CacheOffset.HighPart,
3799 pExtent->CacheOffset.LowPart);
3800 OutputDebugStringA( dbgstr);
3802 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x foffset 0x%x:%x",
3803 Fid.volume, Fid.vnode,
3804 pExtent->FileOffset.HighPart,
3805 pExtent->FileOffset.LowPart);
3806 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3807 pExtent->CacheOffset.HighPart,
3808 pExtent->CacheOffset.LowPart);
3811 #endif /* VALIDATE_CHECK_SUM */
3812 lock_ReleaseMutex(&bufp->mx);
3817 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3820 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3821 if (wbp->datap == datap)
3826 snprintf( dbgstr, 1024,
3827 "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3828 Fid.volume, Fid.vnode, Fid.unique,
3829 pExtent->FileOffset.HighPart,
3830 pExtent->FileOffset.LowPart,
3831 pExtent->CacheOffset.HighPart,
3832 pExtent->CacheOffset.LowPart);
3833 OutputDebugStringA( dbgstr);
3835 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3836 Fid.volume, Fid.vnode,
3837 pExtent->FileOffset.HighPart,
3838 pExtent->FileOffset.LowPart);
3839 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3840 pExtent->CacheOffset.HighPart,
3841 pExtent->CacheOffset.LowPart);
3842 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3843 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3851 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3854 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3855 if (wbp->datap == datap)
3860 snprintf( dbgstr, 1024,
3861 "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3862 Fid.volume, Fid.vnode, Fid.unique,
3863 pExtent->FileOffset.HighPart,
3864 pExtent->FileOffset.LowPart,
3865 pExtent->CacheOffset.HighPart,
3866 pExtent->CacheOffset.LowPart);
3867 OutputDebugStringA( dbgstr);
3869 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3870 Fid.volume, Fid.vnode,
3871 pExtent->FileOffset.HighPart,
3872 pExtent->FileOffset.LowPart);
3873 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3874 pExtent->CacheOffset.HighPart,
3875 pExtent->CacheOffset.LowPart);
3876 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3877 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3882 if (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_FLUSH) {
3883 lock_ObtainWrite(&scp->rw);
3884 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3885 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3886 lock_ReleaseWrite(&scp->rw);
3888 code = cm_FSync(scp, userp, &req, FALSE);
3891 osi_hyper_t offset = {0,0};
3892 afs_uint32 length = 0;
3893 afs_uint32 rights = 0;
3895 lock_ObtainWrite(&scp->rw);
3896 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3897 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3898 lock_ReleaseWrite(&scp->rw);
3901 * there is at least one dirty extent on this file. queue up background store
3902 * requests for contiguous blocks
3904 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3905 if (ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart == offset.QuadPart + length &&
3906 length + cm_data.buf_blockSize <= cm_chunkSize)
3908 length += cm_data.buf_blockSize;
3910 if (!(offset.QuadPart == 0 && length == 0))
3911 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3912 length, 0, userp, &req);
3913 offset.QuadPart = ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart;
3914 length = cm_data.buf_blockSize;
3917 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3918 length, 0, userp, &req);
3921 cm_ReleaseSCache(scp);
3924 osi_Log5(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
3925 FileId.Cell, FileId.Volume,
3926 FileId.Vnode, FileId.Unique, released);
3927 if (code && code != CM_ERROR_WOULDBLOCK) {
3928 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3929 (*ResultCB)->ResultStatus = status;
3930 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents FAILURE code=0x%x status=0x%x",
3933 (*ResultCB)->ResultStatus = 0;
3934 osi_Log0(afsd_logp, "RDR_ReleaseFileExtents SUCCESS");
3936 (*ResultCB)->ResultBufferLength = 0;
3942 RDR_ProcessReleaseFileExtentsResult( IN AFSReleaseFileExtentsResultCB *ReleaseFileExtentsResultCB,
3943 IN DWORD ResultBufferLength)
3945 afs_uint32 code = 0;
3949 unsigned int fileno, extentno, total_extents = 0;
3950 AFSReleaseFileExtentsResultFileCB *pNextFileCB;
3952 #ifdef VALIDATE_CHECK_SUM
3953 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3959 for ( fileno = 0, pNextFileCB = &ReleaseFileExtentsResultCB->Files[0];
3960 fileno < ReleaseFileExtentsResultCB->FileCount;
3962 AFSReleaseFileExtentsResultFileCB *pFileCB = pNextFileCB;
3963 cm_user_t *userp = NULL;
3965 cm_scache_t * scp = NULL;
3971 userp = RDR_UserFromAuthGroup( &pFileCB->AuthGroup);
3973 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult %d.%d.%d.%d",
3974 pFileCB->FileId.Cell, pFileCB->FileId.Volume,
3975 pFileCB->FileId.Vnode, pFileCB->FileId.Unique);
3977 /* Process the release */
3978 Fid.cell = pFileCB->FileId.Cell;
3979 Fid.volume = pFileCB->FileId.Volume;
3980 Fid.vnode = pFileCB->FileId.Vnode;
3981 Fid.unique = pFileCB->FileId.Unique;
3982 Fid.hash = pFileCB->FileId.Hash;
3984 if (Fid.cell == 0) {
3985 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult Invalid FID %d.%d.%d.%d",
3986 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
3987 code = CM_ERROR_INVAL;
3991 code = cm_GetSCache(&Fid, &scp, userp, &req);
3993 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult cm_GetSCache FID failure code=0x%x",
3996 * A failure to find the cm_scache object cannot prevent the service
3997 * from accepting the extents back from the redirector.
4001 deleted = scp && (scp->flags & CM_SCACHEFLAG_DELETED);
4003 /* if the scp was not found, do not perform the length check */
4004 if (scp && (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart)) {
4007 memset(&setAttr, 0, sizeof(cm_attr_t));
4008 lock_ObtainWrite(&scp->rw);
4009 if (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart) {
4010 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult length change vol 0x%x vno 0x%x length 0x%x:%x",
4011 scp->fid.volume, scp->fid.vnode,
4012 pFileCB->AllocationSize.HighPart,
4013 pFileCB->AllocationSize.LowPart);
4014 setAttr.mask |= CM_ATTRMASK_LENGTH;
4015 setAttr.length.LowPart = pFileCB->AllocationSize.LowPart;
4016 setAttr.length.HighPart = pFileCB->AllocationSize.HighPart;
4018 lock_ReleaseWrite(&scp->rw);
4020 code = cm_SetAttr(scp, &setAttr, userp, &req);
4023 for ( extentno = 0; extentno < pFileCB->ExtentCount; total_extents++, extentno++ ) {
4024 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4026 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4028 bufp = buf_Find(&Fid, &thyper);
4030 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4031 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
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; previously released",
4037 pExtent->CacheOffset.HighPart,
4038 pExtent->CacheOffset.LowPart);
4040 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4041 Fid.volume, Fid.vnode,
4042 pExtent->FileOffset.HighPart,
4043 pExtent->FileOffset.LowPart);
4044 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
4045 pExtent->CacheOffset.HighPart,
4046 pExtent->CacheOffset.LowPart);
4052 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
4053 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4054 Fid.volume, Fid.vnode,
4055 pExtent->FileOffset.HighPart,
4056 pExtent->FileOffset.LowPart);
4057 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
4058 pExtent->CacheOffset.HighPart,
4059 pExtent->CacheOffset.LowPart);
4061 /* Move the buffer to the front of the queue */
4062 lock_ObtainWrite(&buf_globalLock);
4063 buf_MoveToHeadOfRedirQueue(scp, bufp);
4064 lock_ReleaseWrite(&buf_globalLock);
4069 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
4070 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
4071 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4072 Fid.volume, Fid.vnode,
4073 pExtent->FileOffset.HighPart,
4074 pExtent->FileOffset.LowPart);
4075 osi_Log2(afsd_logp, "... coffset 0x%x:%x not held by file system",
4076 pExtent->CacheOffset.HighPart,
4077 pExtent->CacheOffset.LowPart);
4079 snprintf(dbgstr, 1024,
4080 "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",
4081 ReleaseFileExtentsResultCB->Flags, pExtent->Flags,
4082 Fid.volume, Fid.vnode, Fid.unique,
4083 pExtent->FileOffset.HighPart,
4084 pExtent->FileOffset.LowPart,
4085 pExtent->CacheOffset.HighPart,
4086 pExtent->CacheOffset.LowPart);
4087 OutputDebugStringA( dbgstr);
4090 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4091 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4092 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4094 if (pExtent->Flags || ReleaseFileExtentsResultCB->Flags) {
4095 lock_ObtainMutex(&bufp->mx);
4096 if ( (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
4097 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
4099 if (bufp->qFlags & CM_BUF_QREDIR) {
4100 lock_ObtainWrite(&buf_globalLock);
4101 if (bufp->qFlags & CM_BUF_QREDIR) {
4102 buf_RemoveFromRedirQueue(scp, bufp);
4103 buf_ReleaseLocked(bufp, TRUE);
4105 lock_ReleaseWrite(&buf_globalLock);
4109 snprintf(dbgstr, 1024,
4110 "RDR_ProcessReleaseFileExtentsResult extent released: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4111 Fid.volume, Fid.vnode, Fid.unique,
4112 pExtent->FileOffset.HighPart,
4113 pExtent->FileOffset.LowPart,
4114 pExtent->CacheOffset.HighPart,
4115 pExtent->CacheOffset.LowPart);
4116 OutputDebugStringA( dbgstr);
4121 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
4122 Fid.volume, Fid.vnode,
4123 pExtent->FileOffset.HighPart,
4124 pExtent->FileOffset.LowPart);
4125 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4126 pExtent->CacheOffset.HighPart,
4127 pExtent->CacheOffset.LowPart);
4129 snprintf(dbgstr, 1024,
4130 "RDR_ProcessReleaseFileExtentsResult not released! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4131 Fid.volume, Fid.vnode, Fid.unique,
4132 pExtent->FileOffset.HighPart,
4133 pExtent->FileOffset.LowPart,
4134 pExtent->CacheOffset.HighPart,
4135 pExtent->CacheOffset.LowPart);
4136 OutputDebugStringA( dbgstr);
4140 if ((ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
4141 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY))
4143 #ifdef VALIDATE_CHECK_SUM
4144 if ( buf_ValidateCheckSum(bufp) ) {
4146 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4147 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4148 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
4150 buf_ComputeCheckSum(bufp);
4152 HexCheckSum(md5dbg3, sizeof(md5dbg), bufp->md5cksum);
4154 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4156 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
4159 snprintf(dbgstr, 1024,
4160 "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",
4162 Fid.volume, Fid.vnode, Fid.unique,
4163 pExtent->FileOffset.HighPart,
4164 pExtent->FileOffset.LowPart,
4165 pExtent->CacheOffset.HighPart,
4166 pExtent->CacheOffset.LowPart);
4167 OutputDebugStringA( dbgstr);
4170 "RDR_ProcessReleaseFileExtentsResult dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
4171 Fid.volume, Fid.vnode,
4172 pExtent->FileOffset.HighPart,
4173 pExtent->FileOffset.LowPart);
4175 "... coffset 0x%x:%x",
4176 pExtent->CacheOffset.HighPart,
4177 pExtent->CacheOffset.LowPart);
4180 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4185 snprintf(dbgstr, 1024,
4186 "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",
4187 md5dbg, md5dbg2, md5dbg3,
4188 Fid.volume, Fid.vnode, Fid.unique,
4189 pExtent->FileOffset.HighPart,
4190 pExtent->FileOffset.LowPart,
4191 pExtent->CacheOffset.HighPart,
4192 pExtent->CacheOffset.LowPart);
4193 OutputDebugStringA( dbgstr);
4196 "RDR_ProcessReleaseFileExtentsResult dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
4197 Fid.volume, Fid.vnode,
4198 pExtent->FileOffset.HighPart,
4199 pExtent->FileOffset.LowPart);
4201 "... coffset 0x%x:%x",
4202 pExtent->CacheOffset.HighPart,
4203 pExtent->CacheOffset.LowPart);
4207 #else /* !VALIDATE_CHECK_SUM */
4209 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4213 snprintf(dbgstr, 1024,
4214 "RDR_ProcessReleaseFileExtentsResult dirty! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4215 Fid.volume, Fid.vnode, Fid.unique,
4216 pExtent->FileOffset.HighPart,
4217 pExtent->FileOffset.LowPart,
4218 pExtent->CacheOffset.HighPart,
4219 pExtent->CacheOffset.LowPart);
4220 OutputDebugStringA( dbgstr);
4222 #endif /* VALIDATE_CHECK_SUM */
4224 #ifdef VALIDATE_CHECK_SUM
4227 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4229 if (!buf_ValidateCheckSum(bufp) ) {
4230 buf_ComputeCheckSum(bufp);
4232 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4233 snprintf(dbgstr, 1024,
4234 "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",
4236 Fid.volume, Fid.vnode, Fid.unique,
4237 pExtent->FileOffset.HighPart,
4238 pExtent->FileOffset.LowPart,
4239 pExtent->CacheOffset.HighPart,
4240 pExtent->CacheOffset.LowPart);
4241 OutputDebugStringA( dbgstr);
4243 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult dirty flag NOT set but extent has changed! vol 0x%x vno 0x%x foffset 0x%x:%x",
4244 Fid.volume, Fid.vnode,
4245 pExtent->FileOffset.HighPart,
4246 pExtent->FileOffset.LowPart);
4247 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4248 pExtent->CacheOffset.HighPart,
4249 pExtent->CacheOffset.LowPart);
4254 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4258 buf_ComputeCheckSum(bufp);
4260 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4261 snprintf(dbgstr, 1024,
4262 "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",
4264 Fid.volume, Fid.vnode, Fid.unique,
4265 pExtent->FileOffset.HighPart,
4266 pExtent->FileOffset.LowPart,
4267 pExtent->CacheOffset.HighPart,
4268 pExtent->CacheOffset.LowPart);
4269 OutputDebugStringA( dbgstr);
4273 #endif /* VALIDATE_CHECK_SUM */
4274 lock_ReleaseMutex(&bufp->mx);
4278 /* CacheOffset doesn't match bufp->datap */
4279 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
4282 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
4283 if (wbp->datap == datap)
4288 snprintf(dbgstr, 1024,
4289 "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",
4290 Fid.volume, Fid.vnode, Fid.unique,
4291 pExtent->FileOffset.HighPart,
4292 pExtent->FileOffset.LowPart,
4293 pExtent->CacheOffset.HighPart,
4294 pExtent->CacheOffset.LowPart,
4296 OutputDebugStringA( dbgstr);
4298 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4299 Fid.volume, Fid.vnode,
4300 pExtent->FileOffset.HighPart,
4301 pExtent->FileOffset.LowPart);
4302 osi_Log3(afsd_logp, "... coffset 0x%x:%x flags 0x%x",
4303 pExtent->CacheOffset.HighPart,
4304 pExtent->CacheOffset.LowPart,
4307 osi_Log5(afsd_logp, "... coffset belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
4308 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
4310 osi_Log0(afsd_logp, "... coffset cannot be found");
4317 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4318 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4319 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
4320 pExtent->FileOffset.LowPart);
4321 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; cm_buf not found -- recycled?",
4322 pExtent->CacheOffset.HighPart,
4323 pExtent->CacheOffset.LowPart);
4329 snprintf(dbgstr, 1024,
4330 "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4331 Fid.volume, Fid.vnode, Fid.unique,
4332 pExtent->FileOffset.HighPart,
4333 pExtent->FileOffset.LowPart,
4334 pExtent->CacheOffset.HighPart,
4335 pExtent->CacheOffset.LowPart);
4336 OutputDebugStringA( dbgstr);
4338 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x foffset 0x%x:%x",
4339 Fid.volume, Fid.vnode,
4340 pExtent->FileOffset.HighPart,
4341 pExtent->FileOffset.LowPart);
4342 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4343 pExtent->CacheOffset.HighPart,
4344 pExtent->CacheOffset.LowPart);
4349 osi_hyper_t offset = {0,0};
4350 afs_uint32 length = 0;
4353 * there is at least one dirty extent on this file. queue up background store
4354 * requests for contiguous blocks
4356 for ( extentno = 0; extentno < pFileCB->ExtentCount; extentno++ ) {
4357 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4358 if (pExtent->FileOffset.QuadPart == offset.QuadPart + length &&
4359 length < cm_chunkSize) {
4360 length += cm_data.buf_blockSize;
4362 if (!(offset.QuadPart == 0 && length == 0))
4363 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4364 length, 0, userp, &req);
4365 offset.QuadPart = pExtent->FileOffset.QuadPart;
4366 length = cm_data.buf_blockSize;
4369 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4370 length, 0, userp, &req);
4373 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
4374 Fid.cell, Fid.volume, Fid.vnode, Fid.unique, released);
4378 cm_ReleaseUser(userp);
4380 cm_ReleaseSCache(scp);
4382 p = (char *)pFileCB;
4383 p += sizeof(AFSReleaseFileExtentsResultFileCB);
4384 p += sizeof(AFSFileExtentCB) * (pFileCB->ExtentCount - 1);
4385 pNextFileCB = (AFSReleaseFileExtentsResultFileCB *)p;
4388 if (total_extents == 0) {
4389 osi_Log0(afsd_logp, "RDR_ProcessReleaseFileExtentsResult is empty");
4390 code = CM_ERROR_RETRY;
4394 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult FAILURE code=0x%x", code);
4396 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult DONE code=0x%x", code);
4402 RDR_ReleaseFailedSetFileExtents( IN cm_user_t *userp,
4403 IN AFSSetFileExtentsCB *SetFileExtentsResultCB,
4404 IN DWORD ResultBufferLength)
4406 afs_uint32 code = 0;
4408 unsigned int extentno;
4410 cm_scache_t * scp = NULL;
4415 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFileExtents %d.%d.%d.%d",
4416 SetFileExtentsResultCB->FileId.Cell, SetFileExtentsResultCB->FileId.Volume,
4417 SetFileExtentsResultCB->FileId.Vnode, SetFileExtentsResultCB->FileId.Unique);
4419 /* Process the release */
4420 Fid.cell = SetFileExtentsResultCB->FileId.Cell;
4421 Fid.volume = SetFileExtentsResultCB->FileId.Volume;
4422 Fid.vnode = SetFileExtentsResultCB->FileId.Vnode;
4423 Fid.unique = SetFileExtentsResultCB->FileId.Unique;
4424 Fid.hash = SetFileExtentsResultCB->FileId.Hash;
4426 if (Fid.cell == 0) {
4427 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFile Invalid FID %d.%d.%d.%d",
4428 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
4429 code = CM_ERROR_INVAL;
4433 code = cm_GetSCache(&Fid, &scp, userp, &req);
4435 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents cm_GetSCache FID failure code=0x%x",
4437 /* Failure to find the cm_scache object cannot block return of the extents */
4440 for ( extentno = 0; extentno < SetFileExtentsResultCB->ExtentCount; extentno++ ) {
4443 AFSFileExtentCB *pExtent = &SetFileExtentsResultCB->FileExtents[extentno];
4445 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4447 bufp = buf_Find(&Fid, &thyper);
4449 osi_Log5(afsd_logp, "RDR_ReleaseFailedSetFileExtents bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4450 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4451 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4453 lock_ObtainMutex(&bufp->mx);
4454 if (bufp->qFlags & CM_BUF_QREDIR) {
4455 lock_ObtainWrite(&buf_globalLock);
4456 if (bufp->qFlags & CM_BUF_QREDIR) {
4457 buf_RemoveFromRedirQueue(scp, bufp);
4458 buf_ReleaseLocked(bufp, TRUE);
4460 lock_ReleaseWrite(&buf_globalLock);
4462 lock_ReleaseMutex(&bufp->mx);
4469 cm_ReleaseUser(userp);
4471 cm_ReleaseSCache(scp);
4473 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents DONE code=0x%x", code);
4478 RDR_PioctlOpen( IN cm_user_t *userp,
4479 IN AFSFileID ParentId,
4480 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4482 IN DWORD ResultBufferLength,
4483 IN OUT AFSCommResult **ResultCB)
4488 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4494 sizeof( AFSCommResult));
4496 /* Get the active directory */
4497 ParentFid.cell = ParentId.Cell;
4498 ParentFid.volume = ParentId.Volume;
4499 ParentFid.vnode = ParentId.Vnode;
4500 ParentFid.unique = ParentId.Unique;
4501 ParentFid.hash = ParentId.Hash;
4503 /* Get the root directory */
4504 RootFid.cell = pPioctlCB->RootId.Cell;
4505 RootFid.volume = pPioctlCB->RootId.Volume;
4506 RootFid.vnode = pPioctlCB->RootId.Vnode;
4507 RootFid.unique = pPioctlCB->RootId.Unique;
4508 RootFid.hash = pPioctlCB->RootId.Hash;
4510 /* Create the pioctl index */
4511 RDR_SetupIoctl(pPioctlCB->RequestId, &ParentFid, &RootFid, userp);
4518 RDR_PioctlClose( IN cm_user_t *userp,
4519 IN AFSFileID ParentId,
4520 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4522 IN DWORD ResultBufferLength,
4523 IN OUT AFSCommResult **ResultCB)
4525 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4531 sizeof( AFSCommResult));
4533 /* Cleanup the pioctl index */
4534 RDR_CleanupIoctl(pPioctlCB->RequestId);
4541 RDR_PioctlWrite( IN cm_user_t *userp,
4542 IN AFSFileID ParentId,
4543 IN AFSPIOCtlIORequestCB *pPioctlCB,
4545 IN DWORD ResultBufferLength,
4546 IN OUT AFSCommResult **ResultCB)
4548 AFSPIOCtlIOResultCB *pResultCB;
4549 cm_scache_t *dscp = NULL;
4556 req.flags |= CM_REQ_WOW64;
4558 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4564 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4566 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4568 code = RDR_IoctlWrite(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer, &req);
4570 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4571 (*ResultCB)->ResultStatus = status;
4575 pResultCB->BytesProcessed = pPioctlCB->BufferLength;
4576 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4580 RDR_PioctlRead( IN cm_user_t *userp,
4581 IN AFSFileID ParentId,
4582 IN AFSPIOCtlIORequestCB *pPioctlCB,
4584 IN BOOL bIsLocalSystem,
4585 IN DWORD ResultBufferLength,
4586 IN OUT AFSCommResult **ResultCB)
4588 AFSPIOCtlIOResultCB *pResultCB;
4589 cm_scache_t *dscp = NULL;
4593 afs_uint32 pflags = (bIsLocalSystem ? AFSCALL_FLAG_LOCAL_SYSTEM : 0);
4597 req.flags |= CM_REQ_WOW64;
4599 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4605 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4607 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4609 code = RDR_IoctlRead(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer,
4610 &pResultCB->BytesProcessed, &req, pflags);
4612 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4613 (*ResultCB)->ResultStatus = status;
4617 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4621 RDR_ByteRangeLockSync( IN cm_user_t *userp,
4622 IN AFSFileID FileId,
4623 IN AFSByteRangeLockRequestCB *pBRLRequestCB,
4625 IN DWORD ResultBufferLength,
4626 IN OUT AFSCommResult **ResultCB)
4628 AFSByteRangeLockResultCB *pResultCB = NULL;
4629 LARGE_INTEGER ProcessId;
4631 cm_scache_t *scp = NULL;
4639 ProcessId.QuadPart = pBRLRequestCB->ProcessId;
4643 req.flags |= CM_REQ_WOW64;
4645 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4646 FileId.Cell, FileId.Volume,
4647 FileId.Vnode, FileId.Unique);
4648 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4649 ProcessId.HighPart, ProcessId.LowPart);
4651 Length = sizeof( AFSByteRangeLockResultCB) + ((pBRLRequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4652 if (Length > ResultBufferLength) {
4653 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4656 memset( *ResultCB, 0, sizeof(AFSCommResult));
4657 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4661 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4664 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4665 (*ResultCB)->ResultBufferLength = Length;
4667 pResultCB = (AFSByteRangeLockResultCB *)(*ResultCB)->ResultData;
4668 pResultCB->FileId = FileId;
4669 pResultCB->Count = pBRLRequestCB->Count;
4671 /* Allocate the extents from the buffer package */
4672 Fid.cell = FileId.Cell;
4673 Fid.volume = FileId.Volume;
4674 Fid.vnode = FileId.Vnode;
4675 Fid.unique = FileId.Unique;
4676 Fid.hash = FileId.Hash;
4678 code = cm_GetSCache(&Fid, &scp, userp, &req);
4680 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4681 (*ResultCB)->ResultStatus = status;
4682 (*ResultCB)->ResultBufferLength = 0;
4683 osi_Log2(afsd_logp, "RDR_ByteRangeLockSync cm_GetSCache FID failure code=0x%x status=0x%x",
4688 lock_ObtainWrite(&scp->rw);
4690 /* start by looking up the file's end */
4691 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4692 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4694 lock_ReleaseWrite(&scp->rw);
4695 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4696 (*ResultCB)->ResultStatus = status;
4697 (*ResultCB)->ResultBufferLength = 0;
4698 osi_Log3(afsd_logp, "RDR_ByteRangeLockSync cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4703 /* the scp is now locked and current */
4704 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4706 for ( i=0; i<pBRLRequestCB->Count; i++ ) {
4707 pResultCB->Result[i].LockType = pBRLRequestCB->Request[i].LockType;
4708 pResultCB->Result[i].Offset = pBRLRequestCB->Request[i].Offset;
4709 pResultCB->Result[i].Length = pBRLRequestCB->Request[i].Length;
4712 pBRLRequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4713 pBRLRequestCB->Request[i].Offset,
4714 pBRLRequestCB->Request[i].Length,
4715 key, 0, userp, &req, NULL);
4718 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4720 pBRLRequestCB->Request[i].LockType,
4721 pBRLRequestCB->Request[i].Offset.HighPart,
4722 pBRLRequestCB->Request[i].Offset.LowPart);
4723 osi_Log2(afsd_logp, "... length 0x%x:%x",
4724 pBRLRequestCB->Request[i].Length.HighPart,
4725 pBRLRequestCB->Request[i].Length.LowPart);
4730 pResultCB->Result[i].Status = 0;
4732 case CM_ERROR_WOULDBLOCK:
4733 pResultCB->Result[i].Status = STATUS_FILE_LOCK_CONFLICT;
4736 pResultCB->Result[i].Status = STATUS_LOCK_NOT_GRANTED;
4740 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4741 lock_ReleaseWrite(&scp->rw);
4742 cm_ReleaseSCache(scp);
4744 (*ResultCB)->ResultStatus = 0;
4745 osi_Log0(afsd_logp, "RDR_ByteRangeLockSync SUCCESS");
4750 RDR_ByteRangeUnlock( IN cm_user_t *userp,
4751 IN AFSFileID FileId,
4752 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4754 IN DWORD ResultBufferLength,
4755 IN OUT AFSCommResult **ResultCB)
4757 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4758 LARGE_INTEGER ProcessId;
4760 cm_scache_t *scp = NULL;
4768 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4772 req.flags |= CM_REQ_WOW64;
4774 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4775 FileId.Cell, FileId.Volume,
4776 FileId.Vnode, FileId.Unique);
4777 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4778 ProcessId.HighPart, ProcessId.LowPart);
4780 Length = sizeof( AFSByteRangeUnlockResultCB) + ((pBRURequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4781 if (Length > ResultBufferLength) {
4782 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4785 memset( *ResultCB, 0, sizeof(AFSCommResult));
4786 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4790 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4793 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4794 (*ResultCB)->ResultBufferLength = Length;
4796 pResultCB = (AFSByteRangeUnlockResultCB *)(*ResultCB)->ResultData;
4797 pResultCB->Count = pBRURequestCB->Count;
4799 /* Allocate the extents from the buffer package */
4800 Fid.cell = FileId.Cell;
4801 Fid.volume = FileId.Volume;
4802 Fid.vnode = FileId.Vnode;
4803 Fid.unique = FileId.Unique;
4804 Fid.hash = FileId.Hash;
4806 code = cm_GetSCache(&Fid, &scp, userp, &req);
4808 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4809 (*ResultCB)->ResultStatus = status;
4810 (*ResultCB)->ResultBufferLength = 0;
4811 osi_Log2(afsd_logp, "RDR_ByteRangeUnlock cm_GetSCache FID failure code=0x%x status=0x%x",
4816 lock_ObtainWrite(&scp->rw);
4818 /* start by looking up the file's end */
4819 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4820 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4822 lock_ReleaseWrite(&scp->rw);
4823 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4824 (*ResultCB)->ResultStatus = status;
4825 (*ResultCB)->ResultBufferLength = 0;
4826 osi_Log3(afsd_logp, "RDR_ByteRangeUnlock cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4831 /* the scp is now locked and current */
4832 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4834 for ( i=0; i<pBRURequestCB->Count; i++ ) {
4835 pResultCB->Result[i].LockType = pBRURequestCB->Request[i].LockType;
4836 pResultCB->Result[i].Offset = pBRURequestCB->Request[i].Offset;
4837 pResultCB->Result[i].Length = pBRURequestCB->Request[i].Length;
4839 code = cm_Unlock(scp,
4840 pBRURequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4841 pBRURequestCB->Request[i].Offset,
4842 pBRURequestCB->Request[i].Length,
4843 key, CM_UNLOCK_FLAG_MATCH_RANGE, userp, &req);
4846 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4847 code, pBRURequestCB->Request[i].LockType,
4848 pBRURequestCB->Request[i].Offset.HighPart,
4849 pBRURequestCB->Request[i].Offset.LowPart);
4850 osi_Log2(afsd_logp, "... length 0x%x:%x",
4851 pBRURequestCB->Request[i].Length.HighPart,
4852 pBRURequestCB->Request[i].Length.LowPart);
4854 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4855 pResultCB->Result[i].Status = status;
4858 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4859 lock_ReleaseWrite(&scp->rw);
4860 cm_ReleaseSCache(scp);
4862 (*ResultCB)->ResultStatus = 0;
4863 osi_Log0(afsd_logp, "RDR_ByteRangeUnlock SUCCESS");
4868 RDR_ByteRangeUnlockAll( IN cm_user_t *userp,
4869 IN AFSFileID FileId,
4870 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4872 IN DWORD ResultBufferLength,
4873 IN OUT AFSCommResult **ResultCB)
4875 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4876 LARGE_INTEGER ProcessId;
4877 cm_scache_t *scp = NULL;
4884 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4888 req.flags |= CM_REQ_WOW64;
4890 osi_Log4(afsd_logp, "RDR_ByteRangeUnlockAll File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4891 FileId.Cell, FileId.Volume,
4892 FileId.Vnode, FileId.Unique);
4893 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4894 ProcessId.HighPart, ProcessId.LowPart);
4896 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4899 memset( *ResultCB, '\0', sizeof( AFSCommResult));
4900 (*ResultCB)->ResultBufferLength = 0;
4902 /* Allocate the extents from the buffer package */
4903 Fid.cell = FileId.Cell;
4904 Fid.volume = FileId.Volume;
4905 Fid.vnode = FileId.Vnode;
4906 Fid.unique = FileId.Unique;
4907 Fid.hash = FileId.Hash;
4909 code = cm_GetSCache(&Fid, &scp, userp, &req);
4911 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4912 (*ResultCB)->ResultStatus = status;
4913 (*ResultCB)->ResultBufferLength = 0;
4914 osi_Log2(afsd_logp, "RDR_ByteRangeUnlockAll cm_GetSCache FID failure code=0x%x status=0x%x",
4919 lock_ObtainWrite(&scp->rw);
4921 /* start by looking up the file's end */
4922 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4923 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4925 lock_ReleaseWrite(&scp->rw);
4926 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4927 (*ResultCB)->ResultStatus = status;
4928 (*ResultCB)->ResultBufferLength = 0;
4929 osi_Log3(afsd_logp, "RDR_ByteRangeUnlockAll cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4934 /* the scp is now locked and current */
4935 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4937 code = cm_UnlockByKey(scp, key, 0, userp, &req);
4939 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4940 lock_ReleaseWrite(&scp->rw);
4941 cm_ReleaseSCache(scp);
4943 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4944 (*ResultCB)->ResultStatus = status;
4947 osi_Log1(afsd_logp, "RDR_ByteRangeUnlockAll FAILURE code 0x%x", code);
4949 osi_Log0(afsd_logp, "RDR_ByteRangeUnlockAll SUCCESS");
4955 RDR_GetVolumeInfo( IN cm_user_t *userp,
4956 IN AFSFileID FileId,
4958 IN DWORD ResultBufferLength,
4959 IN OUT AFSCommResult **ResultCB)
4961 AFSVolumeInfoCB *pResultCB = NULL;
4963 cm_scache_t *scp = NULL;
4964 cm_volume_t *volp = NULL;
4965 cm_vol_state_t *volstatep = NULL;
4967 cm_cell_t *cellp = NULL;
4972 FILETIME ft = {0x832cf000, 0x01abfcc4}; /* October 1, 1982 00:00:00 +0600 */
4974 char volName[32]="(unknown)";
4975 char offLineMsg[256]="server temporarily inaccessible";
4976 char motd[256]="server temporarily inaccessible";
4978 AFSFetchVolumeStatus volStat;
4982 struct rx_connection * rxconnp;
4986 req.flags |= CM_REQ_WOW64;
4988 osi_Log4(afsd_logp, "RDR_GetVolumeInfo File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4989 FileId.Cell, FileId.Volume,
4990 FileId.Vnode, FileId.Unique);
4992 Length = sizeof( AFSCommResult) + sizeof(AFSVolumeInfoCB);
4993 if (sizeof(AFSVolumeInfoCB) > ResultBufferLength) {
4994 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
4997 memset( *ResultCB, 0, sizeof(AFSCommResult));
4998 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5002 *ResultCB = (AFSCommResult *)malloc( Length );
5005 memset( *ResultCB, '\0', Length );
5006 (*ResultCB)->ResultBufferLength = sizeof(AFSVolumeInfoCB);
5007 pResultCB = (AFSVolumeInfoCB *)(*ResultCB)->ResultData;
5009 /* Allocate the extents from the buffer package */
5010 if (FileId.Cell != 0) {
5011 Fid.cell = FileId.Cell;
5012 Fid.volume = FileId.Volume;
5013 Fid.vnode = FileId.Vnode;
5014 Fid.unique = FileId.Unique;
5015 Fid.hash = FileId.Hash;
5017 code = cm_GetSCache(&Fid, &scp, userp, &req);
5019 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5020 (*ResultCB)->ResultStatus = status;
5021 (*ResultCB)->ResultBufferLength = 0;
5022 osi_Log2(afsd_logp, "RDR_GetVolumeInfo cm_GetSCache FID failure code=0x%x status=0x%x",
5027 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
5028 osi_Log0(afsd_logp, "RDR_GetVolumeInfo Object Name Invalid - Cell = 0");
5031 lock_ObtainWrite(&scp->rw);
5033 /* start by looking up the file's end */
5034 code = cm_SyncOp(scp, NULL, userp, &req, 0,
5035 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5037 lock_ReleaseWrite(&scp->rw);
5038 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5039 (*ResultCB)->ResultStatus = status;
5040 (*ResultCB)->ResultBufferLength = 0;
5041 osi_Log3(afsd_logp, "RDR_GetVolumeInfo cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
5047 pResultCB->SectorsPerAllocationUnit = 1;
5048 pResultCB->BytesPerSector = 1024;
5050 pResultCB->CellID = scp->fid.cell;
5051 pResultCB->VolumeID = scp->fid.volume;
5052 pResultCB->Characteristics = FILE_REMOTE_DEVICE;
5053 pResultCB->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK |
5054 FILE_SUPPORTS_REPARSE_POINTS;
5056 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
5057 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)
5059 pResultCB->TotalAllocationUnits.QuadPart = 100;
5060 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
5062 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5063 pResultCB->Characteristics |= FILE_READ_ONLY_DEVICE;
5065 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( "Freelance.Local.Root", -1, pResultCB->VolumeLabel,
5066 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5067 if ( pResultCB->VolumeLabelLength )
5068 pResultCB->VolumeLabelLength--;
5070 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
5072 volp = cm_GetVolumeByFID(&scp->fid);
5074 code = CM_ERROR_NOSUCHVOLUME;
5077 volstatep = cm_VolumeStateByID(volp, scp->fid.volume);
5078 volType = cm_VolumeType(volp, scp->fid.volume);
5080 pResultCB->Characteristics |= ((volType == ROVOL || volType == BACKVOL) ? FILE_READ_ONLY_DEVICE : 0);
5083 OfflineMsg = offLineMsg;
5085 lock_ReleaseWrite(&scp->rw);
5087 code = cm_ConnFromFID(&scp->fid, userp, &req, &connp);
5090 rxconnp = cm_GetRxConn(connp);
5091 code = RXAFS_GetVolumeStatus(rxconnp, scp->fid.volume,
5092 &volStat, &Name, &OfflineMsg, &MOTD);
5093 rx_PutConnection(rxconnp);
5095 } while (cm_Analyze(connp, userp, &req, &scp->fid, NULL, NULL, NULL, code));
5096 code = cm_MapRPCError(code, &req);
5098 pResultCB->TotalAllocationUnits.QuadPart = volStat.PartMaxBlocks;
5099 pResultCB->AvailableAllocationUnits.QuadPart = volStat.PartBlocksAvail;
5101 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( Name, -1, pResultCB->VolumeLabel,
5102 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5104 pResultCB->TotalAllocationUnits.QuadPart = 0x7FFFFFFF;
5105 pResultCB->AvailableAllocationUnits.QuadPart = (volType == ROVOL || volType == BACKVOL) ? 0 : 0x3F000000;
5107 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( volp->namep, -1, pResultCB->VolumeLabel,
5108 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5111 if ( pResultCB->VolumeLabelLength )
5112 pResultCB->VolumeLabelLength--;
5114 lock_ObtainWrite(&scp->rw);
5116 pResultCB->VolumeLabelLength *= sizeof(WCHAR); /* convert to bytes from chars */
5118 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5121 lock_ReleaseWrite(&scp->rw);
5124 cm_ReleaseSCache(scp);
5126 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5127 (*ResultCB)->ResultStatus = status;
5128 osi_Log0(afsd_logp, "RDR_GetVolumeInfo SUCCESS");
5133 RDR_HoldFid( IN cm_user_t *userp,
5134 IN AFSHoldFidRequestCB * pHoldFidCB,
5136 IN DWORD ResultBufferLength,
5137 IN OUT AFSCommResult **ResultCB)
5139 AFSHoldFidResultCB *pResultCB = NULL;
5146 osi_Log1(afsd_logp, "RDR_HoldFid Count=%u", pHoldFidCB->Count);
5148 Length = sizeof(AFSHoldFidResultCB) + (pHoldFidCB->Count-1) * sizeof(AFSFidResult);
5149 if (Length > ResultBufferLength) {
5150 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5153 memset( *ResultCB, 0, sizeof(AFSCommResult));
5154 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5157 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5160 memset( *ResultCB, '\0', Length );
5161 (*ResultCB)->ResultBufferLength = Length;
5162 pResultCB = (AFSHoldFidResultCB *)(*ResultCB)->ResultData;
5164 for ( index = 0; index < pHoldFidCB->Count; index++ )
5166 cm_scache_t *scp = NULL;
5169 Fid.cell = pResultCB->Result[index].FileID.Cell = pHoldFidCB->FileID[index].Cell;
5170 Fid.volume = pResultCB->Result[index].FileID.Volume = pHoldFidCB->FileID[index].Volume;
5171 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pHoldFidCB->FileID[index].Vnode;
5172 Fid.unique = pResultCB->Result[index].FileID.Unique = pHoldFidCB->FileID[index].Unique;
5173 Fid.hash = pResultCB->Result[index].FileID.Hash = pHoldFidCB->FileID[index].Hash;
5175 osi_Log4( afsd_logp,
5176 "RDR_HoldFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5177 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5179 scp = cm_FindSCache(&Fid);
5181 RDR_FlagScpInUse( scp, FALSE );
5182 cm_ReleaseSCache(scp);
5184 pResultCB->Result[index].Status = 0;
5187 (*ResultCB)->ResultStatus = 0;
5188 osi_Log0(afsd_logp, "RDR_HoldFid SUCCESS");
5193 RDR_ReleaseFid( IN cm_user_t *userp,
5194 IN AFSReleaseFidRequestCB * pReleaseFidCB,
5196 IN DWORD ResultBufferLength,
5197 IN OUT AFSCommResult **ResultCB)
5199 AFSReleaseFidResultCB *pResultCB = NULL;
5206 osi_Log1(afsd_logp, "RDR_ReleaseFid Count=%u", pReleaseFidCB->Count);
5208 Length = sizeof(AFSReleaseFidResultCB) + (pReleaseFidCB->Count ? pReleaseFidCB->Count-1 : 0) * sizeof(AFSFidResult);
5209 if (Length > ResultBufferLength) {
5210 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5213 memset( *ResultCB, 0, sizeof(AFSCommResult));
5214 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5217 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5220 memset( *ResultCB, '\0', Length );
5221 (*ResultCB)->ResultBufferLength = Length;
5222 pResultCB = (AFSReleaseFidResultCB *)(*ResultCB)->ResultData;
5224 for ( index = 0; index < pReleaseFidCB->Count; index++ )
5226 cm_scache_t *scp = NULL;
5229 Fid.cell = pResultCB->Result[index].FileID.Cell = pReleaseFidCB->FileID[index].Cell;
5230 Fid.volume = pResultCB->Result[index].FileID.Volume = pReleaseFidCB->FileID[index].Volume;
5231 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pReleaseFidCB->FileID[index].Vnode;
5232 Fid.unique = pResultCB->Result[index].FileID.Unique = pReleaseFidCB->FileID[index].Unique;
5233 Fid.hash = pResultCB->Result[index].FileID.Hash = pReleaseFidCB->FileID[index].Hash;
5235 osi_Log4( afsd_logp,
5236 "RDR_ReleaseFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5237 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5239 scp = cm_FindSCache(&Fid);
5241 lock_ObtainWrite(&scp->rw);
5242 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
5243 lock_ReleaseWrite(&scp->rw);
5245 cm_ReleaseSCache(scp);
5247 pResultCB->Result[index].Status = 0;
5249 pResultCB->Count = pReleaseFidCB->Count;
5251 (*ResultCB)->ResultStatus = 0;
5252 osi_Log0(afsd_logp, "RDR_ReleaseFid SUCCESS");
5257 * The redirector makes several assumptions regarding the
5258 * SRVSVC and WKSSVC pipes transactions. First, the interface
5259 * versions are those indicated below. Secondly, the encoding
5260 * will be performed using NDR version 2. These assumptions
5261 * may not hold in the future and end-to-end MSRPC Bind
5262 * negotiations may need to be supported. Of course, these
5263 * are the only interface versions that are supported by the
5266 #define MSRPC_PIPE_PREFIX L".\\"
5268 static const UUID MSRPC_SRVSVC_UUID = {0x4B324FC8, 0x1670, 0x01D3,
5269 {0x12, 0x78, 0x5A, 0x47, 0xBF, 0x6E, 0xE1, 0x88}};
5270 #define MSRPC_SRVSVC_NAME L"PIPE\\SRVSVC"
5271 #define MSRPC_SRVSVC_VERS 3
5273 static const UUID MSRPC_WKSSVC_UUID = {0x6BFFD098, 0xA112, 0x3610,
5274 {0x98, 0x33, 0x46, 0xC3, 0xF8, 0x7E, 0x34, 0x5A}};
5275 #define MSRPC_WKSSVC_NAME L"PIPE\\WKSSVC"
5276 #define MSRPC_WKSSVC_VERS 1
5278 static const UUID MSRPC_NDR_UUID = {0x8A885D04, 0x1CEB, 0x11C9,
5279 {0x9F, 0xE8, 0x08, 0x00, 0x2B, 0x10, 0x48, 0x60}};
5280 #define MSRPC_NDR_NAME L"NDR"
5281 #define MSRPC_NDR_VERS 2
5283 extern RPC_IF_HANDLE srvsvc_v3_0_s_ifspec;
5284 extern RPC_IF_HANDLE wkssvc_v1_0_s_ifspec;
5287 RDR_PipeOpen( IN cm_user_t *userp,
5288 IN AFSFileID ParentId,
5290 IN DWORD NameLength,
5291 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5293 IN DWORD ResultBufferLength,
5294 IN OUT AFSCommResult **ResultCB)
5299 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5305 sizeof( AFSCommResult));
5307 /* Get the active directory */
5308 ParentFid.cell = ParentId.Cell;
5309 ParentFid.volume = ParentId.Volume;
5310 ParentFid.vnode = ParentId.Vnode;
5311 ParentFid.unique = ParentId.Unique;
5312 ParentFid.hash = ParentId.Hash;
5314 /* Get the root directory */
5315 RootFid.cell = pPipe_CB->RootId.Cell;
5316 RootFid.volume = pPipe_CB->RootId.Volume;
5317 RootFid.vnode = pPipe_CB->RootId.Vnode;
5318 RootFid.unique = pPipe_CB->RootId.Unique;
5319 RootFid.hash = pPipe_CB->RootId.Hash;
5321 /* Create the pipe index */
5322 (*ResultCB)->ResultStatus =
5323 RDR_SetupPipe( pPipe_CB->RequestId, &ParentFid, &RootFid,
5324 Name, NameLength, userp);
5330 RDR_PipeClose( IN cm_user_t *userp,
5331 IN AFSFileID ParentId,
5332 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5334 IN DWORD ResultBufferLength,
5335 IN OUT AFSCommResult **ResultCB)
5337 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5343 sizeof( AFSCommResult));
5345 /* Cleanup the pipe index */
5346 RDR_CleanupPipe(pPipe_CB->RequestId);
5353 RDR_PipeWrite( IN cm_user_t *userp,
5354 IN AFSFileID ParentId,
5355 IN AFSPipeIORequestCB *pPipe_CB,
5356 IN BYTE *pPipe_Data,
5358 IN DWORD ResultBufferLength,
5359 IN OUT AFSCommResult **ResultCB)
5361 AFSPipeIOResultCB *pResultCB;
5362 cm_scache_t *dscp = NULL;
5369 req.flags |= CM_REQ_WOW64;
5371 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5377 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5379 pResultCB = (AFSPipeIOResultCB *)(*ResultCB)->ResultData;
5381 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_Data, &req, userp);
5383 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5384 (*ResultCB)->ResultStatus = status;
5388 pResultCB->BytesProcessed = pPipe_CB->BufferLength;
5389 (*ResultCB)->ResultBufferLength = sizeof( AFSPipeIOResultCB);
5394 RDR_PipeRead( IN cm_user_t *userp,
5395 IN AFSFileID ParentId,
5396 IN AFSPipeIORequestCB *pPipe_CB,
5398 IN DWORD ResultBufferLength,
5399 IN OUT AFSCommResult **ResultCB)
5402 cm_scache_t *dscp = NULL;
5409 req.flags |= CM_REQ_WOW64;
5411 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5417 sizeof( AFSCommResult));
5419 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5421 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_Data,
5422 &(*ResultCB)->ResultBufferLength, &req, userp);
5424 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5425 (*ResultCB)->ResultStatus = status;
5432 RDR_PipeSetInfo( IN cm_user_t *userp,
5433 IN AFSFileID ParentId,
5434 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5435 IN BYTE *pPipe_Data,
5437 IN DWORD ResultBufferLength,
5438 IN OUT AFSCommResult **ResultCB)
5440 cm_scache_t *dscp = NULL;
5446 req.flags |= CM_REQ_WOW64;
5448 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5454 sizeof( AFSCommResult));
5456 status = RDR_Pipe_SetInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5457 pPipeInfo_CB->BufferLength, pPipe_Data, &req, userp);
5459 (*ResultCB)->ResultStatus = status;
5464 RDR_PipeQueryInfo( IN cm_user_t *userp,
5465 IN AFSFileID ParentId,
5466 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5468 IN DWORD ResultBufferLength,
5469 IN OUT AFSCommResult **ResultCB)
5472 cm_scache_t *dscp = NULL;
5478 req.flags |= CM_REQ_WOW64;
5480 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5486 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5488 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5490 status = RDR_Pipe_QueryInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5491 ResultBufferLength, pPipe_Data,
5492 &(*ResultCB)->ResultBufferLength, &req, userp);
5494 (*ResultCB)->ResultStatus = status;
5498 RDR_PipeTransceive( IN cm_user_t *userp,
5499 IN AFSFileID ParentId,
5500 IN AFSPipeIORequestCB *pPipe_CB,
5501 IN BYTE *pPipe_InData,
5503 IN DWORD ResultBufferLength,
5504 IN OUT AFSCommResult **ResultCB)
5507 * This function processes a Pipe Service request
5508 * that would normally be sent to a LAN Manager server
5509 * across an authenticated SMB-PIPE/MSRPC/SVC request
5510 * stack. The request is being sent here because the
5511 * application (e.g., Explorer Shell or Common Control File
5512 * dialog) believes that because the UNC path it is
5513 * processing has specified a server name that is not
5514 * "." and that the Server is remote and that the Share
5515 * list cannot be obtained using the Network Provider
5518 * The file system driver is faking the Bind-Ack response
5519 * to the MSRPC Bind request but cannot decode the NDR
5520 * encoded Pipe Service requests. For that we will use
5521 * the service's MSRPC module. However, unlike the SMB
5522 * server usage we must fake the MSRPC Bind exchange and
5523 * map the PipeName to an interface instead of using the
5524 * GUID specified in the MSRPC Bind request.
5526 * None of the requests that are being processed by the
5527 * service require authentication. As a result the userp
5528 * parameter will be ignored.
5530 * Although there are dozens of Pipe Services, the only
5531 * ones that we are implementing are WKSSVC and SRVSVC.
5532 * These support NetShareEnum, NetShareGetInfo,
5533 * NetServerGetInfo, and NetWorkstaGetInfo which are
5534 * commonly queried by NET VIEW, the Explorer Shell,
5535 * and the Common Control File dialog.
5537 BYTE *pPipe_OutData;
5538 cm_scache_t *dscp = NULL;
5542 DWORD Length = ResultBufferLength + sizeof( AFSCommResult);
5546 req.flags |= CM_REQ_WOW64;
5548 *ResultCB = (AFSCommResult *)malloc( Length);
5551 memset( *ResultCB, '\0', Length );
5553 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_InData, &req, userp);
5555 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5556 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Write FAILURE code=0x%x status=0x%x",
5558 (*ResultCB)->ResultStatus = status;
5562 pPipe_OutData = (BYTE *)(*ResultCB)->ResultData;
5563 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_OutData,
5564 &(*ResultCB)->ResultBufferLength, &req, userp);
5566 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5567 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Read FAILURE code=0x%x status=0x%x",
5569 (*ResultCB)->ResultStatus = status;
5573 (*ResultCB)->ResultStatus = 0;
5574 osi_Log0(afsd_logp, "RDR_Pipe_Transceive SUCCESS");