2 * Copyright (c) 2008 Secure Endpoints, Inc.
3 * Copyright (c) 2009-2011 Your File System, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * - Neither the name of Secure Endpoints Inc. nor the names of its contributors
15 * may be used to endorse or promote products derived from this software without
16 * specific prior written permission from Secure Endpoints, Inc. and
17 * Your File System, Inc.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
23 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <afsconfig.h>
33 #include <afs/param.h>
36 #define _WIN32_WINNT 0x0500
38 #define _CRT_SECURE_NO_DEPRECATE
39 #define _CRT_NON_CONFORMING_SWPRINTFS
40 #define INITGUID /* define AFS_AUTH_GUID_NO_PAG */
43 #define WIN32_NO_STATUS
53 #pragma warning(disable: 4005)
57 #include "..\\Common\\AFSUserDefines.h"
58 #include "..\\Common\\AFSUserStructs.h"
76 #include <RDRPrototypes.h>
80 static CHAR * RDR_extentBaseAddress = NULL;
83 RDR_InitReq(cm_req_t *reqp)
86 reqp->flags |= CM_REQ_SOURCE_REDIR;
90 RDR_fid2FID( cm_fid_t *fid, AFSFileID *FileId)
92 FileId->Cell = fid->cell;
93 FileId->Volume = fid->volume;
94 FileId->Vnode = fid->vnode;
95 FileId->Unique = fid->unique;
96 FileId->Hash = fid->hash;
100 RDR_FID2fid( AFSFileID *FileId, cm_fid_t *fid)
102 fid->cell = FileId->Cell;
103 fid->volume = FileId->Volume;
104 fid->vnode = FileId->Vnode;
105 fid->unique = FileId->Unique;
106 fid->hash = FileId->Hash;
110 RDR_SetInitParams( OUT AFSRedirectorInitInfo **ppRedirInitInfo, OUT DWORD * pRedirInitInfoLen )
112 extern char cm_CachePath[];
113 extern cm_config_data_t cm_data;
114 extern int smb_hideDotFiles;
115 size_t cm_CachePathLen = strlen(cm_CachePath);
117 DWORD TempPathLen = ExpandEnvironmentStringsW(L"%TEMP%", NULL, 0);
118 MEMORYSTATUSEX memStatus;
119 DWORD maxMemoryCacheSize;
121 memStatus.dwLength = sizeof(memStatus);
122 if (GlobalMemoryStatusEx(&memStatus)) {
124 * Use the memory extent interface in the afs redirector
125 * whenever the cache size is less than equal to 10% of
126 * physical memory. Do not use too much because this memory
127 * will be locked by the redirector so it can't be swapped
130 maxMemoryCacheSize = (DWORD)(memStatus.ullTotalPhys / 1024 / 10);
133 * If we can't determine the amount of physical memory
134 * in the system, be conservative and limit the use of
135 * memory extent interface to 64MB data caches.
137 maxMemoryCacheSize = 65536;
140 *pRedirInitInfoLen = (DWORD) (sizeof(AFSRedirectorInitInfo) + (cm_CachePathLen + TempPathLen) * sizeof(WCHAR));
141 *ppRedirInitInfo = (AFSRedirectorInitInfo *)malloc(*pRedirInitInfoLen);
142 (*ppRedirInitInfo)->Flags = smb_hideDotFiles ? AFS_REDIR_INIT_FLAG_HIDE_DOT_FILES : 0;
143 (*ppRedirInitInfo)->MaximumChunkLength = cm_data.chunkSize;
144 (*ppRedirInitInfo)->GlobalFileId.Cell = cm_data.rootFid.cell;
145 (*ppRedirInitInfo)->GlobalFileId.Volume = cm_data.rootFid.volume;
146 (*ppRedirInitInfo)->GlobalFileId.Vnode = cm_data.rootFid.vnode;
147 (*ppRedirInitInfo)->GlobalFileId.Unique = cm_data.rootFid.unique;
148 (*ppRedirInitInfo)->GlobalFileId.Hash = cm_data.rootFid.hash;
149 (*ppRedirInitInfo)->ExtentCount.QuadPart = cm_data.buf_nbuffers;
150 (*ppRedirInitInfo)->CacheBlockSize = cm_data.blockSize;
151 (*ppRedirInitInfo)->MaxPathLinkCount = 512; /* this needs to become a registry value */
152 (*ppRedirInitInfo)->NameArrayLength = 32; /* this needs to become a registry value */
153 if (cm_virtualCache || cm_data.bufferSize <= maxMemoryCacheSize) {
154 osi_Log0(afsd_logp, "RDR_SetInitParams Initializing Memory Extent Interface");
155 (*ppRedirInitInfo)->MemoryCacheOffset.QuadPart = (LONGLONG)cm_data.bufDataBaseAddress;
156 (*ppRedirInitInfo)->MemoryCacheLength.QuadPart = cm_data.bufEndOfData - cm_data.bufDataBaseAddress;
157 (*ppRedirInitInfo)->CacheFileNameLength = 0;
158 RDR_extentBaseAddress = cm_data.bufDataBaseAddress;
160 (*ppRedirInitInfo)->MemoryCacheOffset.QuadPart = 0;
161 (*ppRedirInitInfo)->MemoryCacheLength.QuadPart = 0;
162 (*ppRedirInitInfo)->CacheFileNameLength = (ULONG) (cm_CachePathLen * sizeof(WCHAR));
163 err = mbstowcs((*ppRedirInitInfo)->CacheFileName, cm_CachePath, (cm_CachePathLen + 1) *sizeof(WCHAR));
165 free(*ppRedirInitInfo);
166 osi_Log0(afsd_logp, "RDR_SetInitParams Invalid Object Name");
167 return STATUS_OBJECT_NAME_INVALID;
169 RDR_extentBaseAddress = cm_data.baseAddress;
171 (*ppRedirInitInfo)->DumpFileLocationOffset = FIELD_OFFSET(AFSRedirectorInitInfo, CacheFileName) + (*ppRedirInitInfo)->CacheFileNameLength;
172 (*ppRedirInitInfo)->DumpFileLocationLength = (TempPathLen - 1) * sizeof(WCHAR);
173 ExpandEnvironmentStringsW(L"%TEMP%",
174 (LPWSTR)(((PBYTE)(*ppRedirInitInfo)) + (*ppRedirInitInfo)->DumpFileLocationOffset),
177 osi_Log0(afsd_logp,"RDR_SetInitParams Success");
181 static wchar_t cname[MAX_COMPUTERNAME_LENGTH+1] = L"";
184 RDR_GetLocalSystemUser( void)
187 cm_user_t *userp = NULL;
189 if ( cname[0] == '\0') {
190 int len = MAX_COMPUTERNAME_LENGTH+1;
191 GetComputerNameW(cname, &len);
194 unp = smb_FindUserByName(NTSID_LOCAL_SYSTEM, cname, SMB_FLAG_CREATE);
195 lock_ObtainMutex(&unp->mx);
197 unp->userp = cm_NewUser();
198 unp->flags |= SMB_USERNAMEFLAG_SID;
199 lock_ReleaseMutex(&unp->mx);
202 smb_ReleaseUsername(unp);
205 userp = cm_rootUserp;
213 RDR_UserFromCommRequest( IN AFSCommRequest *RequestBuffer)
216 return RDR_UserFromAuthGroup( &RequestBuffer->AuthGroup);
220 RDR_UserFromAuthGroup( IN GUID *pGuid)
223 cm_user_t * userp = NULL;
224 RPC_WSTR UuidString = NULL;
226 if (UuidToStringW((UUID *)pGuid, &UuidString) != RPC_S_OK)
229 if ( cname[0] == '\0') {
230 int len = MAX_COMPUTERNAME_LENGTH+1;
231 GetComputerNameW(cname, &len);
235 unp = smb_FindUserByName(UuidString, cname, SMB_FLAG_CREATE);
236 lock_ObtainMutex(&unp->mx);
238 unp->userp = cm_NewUser();
239 memcpy(&unp->userp->authgroup, pGuid, sizeof(GUID));
241 unp->flags |= SMB_USERNAMEFLAG_SID;
242 lock_ReleaseMutex(&unp->mx);
245 smb_ReleaseUsername(unp);
249 userp = cm_rootUserp;
253 osi_Log2(afsd_logp, "RDR_UserFromCommRequest Guid %S userp = 0x%p",
254 osi_LogSaveStringW(afsd_logp, UuidString),
258 RpcStringFreeW(&UuidString);
264 RDR_ReleaseUser( IN cm_user_t *userp )
266 osi_Log1(afsd_logp, "RDR_ReleaseUser userp = 0x%p", userp);
267 cm_ReleaseUser(userp);
272 * RDR_FlagScpInUse flags the scp with CM_SCACHEFLAG_RDR_IN_USE
275 RDR_FlagScpInUse( IN cm_scache_t *scp, IN BOOL bLocked )
278 lock_ObtainWrite(&scp->rw);
280 lock_AssertWrite(&scp->rw);
281 scp->flags |= CM_SCACHEFLAG_RDR_IN_USE;
284 lock_ReleaseWrite(&scp->rw);
288 * Obtain the status information for the specified object using
289 * an inline bulk status rpc. cm_BPlusDirEnumBulkStatOne() will
290 * obtain current status for the directory object, the object
291 * which is the focus of the inquiry and as many other objects
292 * in the directory for which there are not callbacks registered
293 * since we are likely to be asked for other objects in the directory.
296 RDR_BulkStatLookup( cm_scache_t *dscp,
301 cm_direnum_t * enump = NULL;
305 code = cm_BeginDirOp(dscp, userp, reqp, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
307 code = cm_BPlusDirEnumerate(dscp, userp, reqp, TRUE, NULL, TRUE, &enump);
309 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BPlusDirEnumerate failure code=0x%x",
314 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BeginDirOp failure code=0x%x",
320 code = cm_BPlusDirEnumBulkStatOne(enump, scp);
322 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BPlusDirEnumBulkStatOne failure code=0x%x",
325 cm_BPlusDirFreeEnumeration(enump);
332 #define RDR_POP_FOLLOW_MOUNTPOINTS 0x01
333 #define RDR_POP_EVALUATE_SYMLINKS 0x02
334 #define RDR_POP_WOW64 0x04
335 #define RDR_POP_NO_GETSTATUS 0x08
338 RDR_PopulateCurrentEntry( IN AFSDirEnumEntry * pCurrentEntry,
339 IN DWORD dwMaxEntryLength,
340 IN cm_scache_t * dscp,
341 IN cm_scache_t * scp,
342 IN cm_user_t * userp,
345 IN wchar_t * shortName,
347 IN afs_uint32 cmError,
348 OUT AFSDirEnumEntry **ppNextEntry,
349 OUT DWORD * pdwRemainingLength)
352 WCHAR * wname, *wtarget;
355 afs_uint32 code = 0, code2 = 0;
356 BOOL bMustFake = FALSE;
358 osi_Log5(afsd_logp, "RDR_PopulateCurrentEntry dscp=0x%p scp=0x%p name=%S short=%S flags=0x%x",
359 dscp, scp, osi_LogSaveStringW(afsd_logp, name),
360 osi_LogSaveStringW(afsd_logp, shortName), dwFlags);
361 osi_Log1(afsd_logp, "... maxLength=%d", dwMaxEntryLength);
363 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
365 *ppNextEntry = pCurrentEntry;
366 if (pdwRemainingLength)
367 *pdwRemainingLength = dwMaxEntryLength;
368 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry Not Enough Room for Entry %d < %d",
369 dwMaxEntryLength, sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t));
370 return CM_ERROR_TOOBIG;
378 dwEntryLength = sizeof(AFSDirEnumEntry);
380 lock_ObtainWrite(&scp->rw);
381 if (dwFlags & RDR_POP_NO_GETSTATUS) {
382 if (!cm_HaveCallback(scp))
385 #ifdef AFS_FREELANCE_CLIENT
386 if (scp->fid.cell == AFS_FAKE_ROOT_CELL_ID && scp->fid.volume == AFS_FAKE_ROOT_VOL_ID) {
388 * If the FID is from the Freelance Local Root always perform
389 * a single item status check.
391 code = cm_SyncOp( scp, NULL, userp, reqp, 0,
392 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
394 lock_ReleaseWrite(&scp->rw);
395 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_SyncOp failed for scp=0x%p code=0x%x",
403 * For non-Freelance objects, check to see if we have current
404 * status information. If not, perform a bulk status lookup of multiple
405 * entries in order to reduce the number of RPCs issued to the file server.
407 if (cm_EAccesFindEntry(userp, &scp->fid))
409 else if (!cm_HaveCallback(scp)) {
410 lock_ReleaseWrite(&scp->rw);
411 code = RDR_BulkStatLookup(dscp, scp, userp, reqp);
413 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry RDR_BulkStatLookup failed for scp=0x%p code=0x%x",
417 lock_ObtainWrite(&scp->rw);
419 * RDR_BulkStatLookup can succeed but it may be the case that there
420 * still is not valid status info. If we get this far, generate fake
423 if (!cm_HaveCallback(scp))
429 /* Populate the error code */
430 smb_MapNTError(cmError, &pCurrentEntry->NTStatus, TRUE);
432 /* Populate the real or fake data */
433 pCurrentEntry->FileId.Cell = scp->fid.cell;
434 pCurrentEntry->FileId.Volume = scp->fid.volume;
435 pCurrentEntry->FileId.Vnode = scp->fid.vnode;
436 pCurrentEntry->FileId.Unique = scp->fid.unique;
437 pCurrentEntry->FileId.Hash = scp->fid.hash;
439 pCurrentEntry->FileType = scp->fileType;
441 pCurrentEntry->DataVersion.QuadPart = scp->dataVersion;
443 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
444 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
445 cm_LargeSearchTimeFromUnixTime(&ft, MAX_AFS_UINT32);
447 cm_LargeSearchTimeFromUnixTime(&ft, scp->cbExpires);
449 pCurrentEntry->Expiration.LowPart = ft.dwLowDateTime;
450 pCurrentEntry->Expiration.HighPart = ft.dwHighDateTime;
453 /* 1969-12-31 23:59:59 +00 */
454 ft.dwHighDateTime = 0x19DB200;
455 ft.dwLowDateTime = 0x5BB78980;
457 cm_LargeSearchTimeFromUnixTime(&ft, scp->clientModTime);
458 pCurrentEntry->CreationTime.LowPart = ft.dwLowDateTime;
459 pCurrentEntry->CreationTime.HighPart = ft.dwHighDateTime;
460 pCurrentEntry->LastAccessTime = pCurrentEntry->CreationTime;
461 pCurrentEntry->LastWriteTime = pCurrentEntry->CreationTime;
462 pCurrentEntry->ChangeTime = pCurrentEntry->CreationTime;
464 pCurrentEntry->EndOfFile = scp->length;
465 pCurrentEntry->AllocationSize = scp->length;
468 switch (scp->fileType) {
469 case CM_SCACHETYPE_DIRECTORY:
470 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY;
472 case CM_SCACHETYPE_MOUNTPOINT:
473 case CM_SCACHETYPE_INVALID:
474 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY | SMB_ATTR_REPARSE_POINT;
476 case CM_SCACHETYPE_SYMLINK:
477 if (cm_TargetPerceivedAsDirectory(scp->mountPointStringp))
478 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY | SMB_ATTR_REPARSE_POINT;
480 pCurrentEntry->FileAttributes = SMB_ATTR_REPARSE_POINT;
483 /* if we get here we either have a normal file
484 * or we have a file for which we have never
485 * received status info. In this case, we can
486 * check the even/odd value of the entry's vnode.
487 * odd means it is to be treated as a directory
488 * and even means it is to be treated as a file.
490 if (scp->fid.vnode & 0x1)
491 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY;
493 pCurrentEntry->FileAttributes = SMB_ATTR_NORMAL;
496 pCurrentEntry->FileAttributes = smb_ExtAttributes(scp);
497 pCurrentEntry->EaSize = 0;
498 pCurrentEntry->Links = scp->linkCount;
500 len = wcslen(shortName);
501 wcsncpy(pCurrentEntry->ShortName, shortName, len);
502 pCurrentEntry->ShortNameLength = (CCHAR)(len * sizeof(WCHAR));
504 pCurrentEntry->FileNameOffset = sizeof(AFSDirEnumEntry);
506 wname = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->FileNameOffset);
507 wcsncpy(wname, name, len);
508 pCurrentEntry->FileNameLength = (ULONG)(sizeof(WCHAR) * len);
510 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntry scp=0x%p fileType=%d dv=%u",
511 scp, scp->fileType, (afs_uint32)scp->dataVersion);
513 if (!(dwFlags & RDR_POP_NO_GETSTATUS))
514 cm_SyncOpDone( scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
516 if ((dwFlags & RDR_POP_NO_GETSTATUS) || !cm_HaveCallback(scp)) {
517 pCurrentEntry->TargetNameOffset = 0;
518 pCurrentEntry->TargetNameLength = 0;
521 switch (scp->fileType) {
522 case CM_SCACHETYPE_MOUNTPOINT:
523 if (dwFlags & RDR_POP_FOLLOW_MOUNTPOINTS) {
524 if ((code2 = cm_ReadMountPoint(scp, userp, reqp)) == 0) {
525 cm_scache_t *targetScp = NULL;
527 pCurrentEntry->TargetNameOffset = pCurrentEntry->FileNameOffset + pCurrentEntry->FileNameLength;
528 len = strlen(scp->mountPointStringp);
529 wtarget = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->TargetNameOffset);
532 cch = MultiByteToWideChar( CP_UTF8, 0, scp->mountPointStringp,
535 len * sizeof(WCHAR));
537 mbstowcs(wtarget, scp->mountPointStringp, len);
539 pCurrentEntry->TargetNameLength = (ULONG)(sizeof(WCHAR) * len);
541 code2 = cm_FollowMountPoint(scp, dscp, userp, reqp, &targetScp);
544 pCurrentEntry->TargetFileId.Cell = targetScp->fid.cell;
545 pCurrentEntry->TargetFileId.Volume = targetScp->fid.volume;
546 pCurrentEntry->TargetFileId.Vnode = targetScp->fid.vnode;
547 pCurrentEntry->TargetFileId.Unique = targetScp->fid.unique;
548 pCurrentEntry->TargetFileId.Hash = targetScp->fid.hash;
550 osi_Log4(afsd_logp, "RDR_PopulateCurrentEntry target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
551 pCurrentEntry->TargetFileId.Cell, pCurrentEntry->TargetFileId.Volume,
552 pCurrentEntry->TargetFileId.Vnode, pCurrentEntry->TargetFileId.Unique);
554 cm_ReleaseSCache(targetScp);
556 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_FollowMountPoint failed scp=0x%p code=0x%x",
560 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_ReadMountPoint failed scp=0x%p code=0x%x",
565 case CM_SCACHETYPE_SYMLINK:
566 case CM_SCACHETYPE_DFSLINK:
568 pCurrentEntry->TargetNameOffset = pCurrentEntry->FileNameOffset + pCurrentEntry->FileNameLength;
569 wtarget = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->TargetNameOffset);
571 if (dwFlags & RDR_POP_EVALUATE_SYMLINKS) {
574 code2 = cm_HandleLink(scp, userp, reqp);
576 mp = scp->mountPointStringp;
579 /* Strip off the msdfs: prefix from the target name for the file system */
580 if (scp->fileType == CM_SCACHETYPE_DFSLINK) {
581 osi_Log0(afsd_logp, "RDR_PopulateCurrentEntry DFSLink Detected");
582 pCurrentEntry->FileType = scp->fileType;
584 if (!strncmp("msdfs:", mp, 6)) {
589 /* only send one slash to the redirector */
590 if (mp[0] == '\\' && mp[1] == '\\') {
595 cch = MultiByteToWideChar( CP_UTF8, 0, mp,
598 len * sizeof(WCHAR));
600 mbstowcs(wtarget, mp, len);
603 pCurrentEntry->TargetNameLength = (ULONG)(sizeof(WCHAR) * len);
605 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_HandleLink failed scp=0x%p code=0x%x",
614 pCurrentEntry->TargetNameOffset = 0;
615 pCurrentEntry->TargetNameLength = 0;
617 lock_ReleaseWrite(&scp->rw);
619 dwEntryLength += pCurrentEntry->FileNameLength + pCurrentEntry->TargetNameLength;
620 dwEntryLength += (dwEntryLength % 8) ? 8 - (dwEntryLength % 8) : 0; /* quad align */
622 *ppNextEntry = (AFSDirEnumEntry *)((PBYTE)pCurrentEntry + dwEntryLength);
623 if (pdwRemainingLength)
624 *pdwRemainingLength = dwMaxEntryLength - dwEntryLength;
626 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntry Success FileNameLength=%d TargetNameLength=%d RemainingLength=%d",
627 pCurrentEntry->FileNameLength, pCurrentEntry->TargetNameLength, *pdwRemainingLength);
633 RDR_PopulateCurrentEntryNoScp( IN AFSDirEnumEntry * pCurrentEntry,
634 IN DWORD dwMaxEntryLength,
635 IN cm_scache_t * dscp,
637 IN cm_user_t * userp,
640 IN wchar_t * shortName,
642 IN afs_uint32 cmError,
643 OUT AFSDirEnumEntry **ppNextEntry,
644 OUT DWORD * pdwRemainingLength)
650 afs_uint32 code = 0, code2 = 0;
652 osi_Log4(afsd_logp, "RDR_PopulateCurrentEntryNoEntry dscp=0x%p name=%S short=%S flags=0x%x",
653 dscp, osi_LogSaveStringW(afsd_logp, name),
654 osi_LogSaveStringW(afsd_logp, shortName), dwFlags);
655 osi_Log1(afsd_logp, "... maxLength=%d", dwMaxEntryLength);
657 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
659 *ppNextEntry = pCurrentEntry;
660 if (pdwRemainingLength)
661 *pdwRemainingLength = dwMaxEntryLength;
662 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntryNoEntry Not Enough Room for Entry %d < %d",
663 dwMaxEntryLength, sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t));
664 return CM_ERROR_TOOBIG;
672 dwEntryLength = sizeof(AFSDirEnumEntry);
674 /* Populate the error code */
675 smb_MapNTError(cmError, &pCurrentEntry->NTStatus, TRUE);
677 /* Populate the fake data */
678 pCurrentEntry->FileId.Cell = fidp->cell;
679 pCurrentEntry->FileId.Volume = fidp->volume;
680 pCurrentEntry->FileId.Vnode = fidp->vnode;
681 pCurrentEntry->FileId.Unique = fidp->unique;
682 pCurrentEntry->FileId.Hash = fidp->hash;
684 pCurrentEntry->FileType = CM_SCACHETYPE_UNKNOWN;
686 pCurrentEntry->DataVersion.QuadPart = CM_SCACHE_VERSION_BAD;
688 cm_LargeSearchTimeFromUnixTime(&ft, 0);
689 pCurrentEntry->Expiration.LowPart = ft.dwLowDateTime;
690 pCurrentEntry->Expiration.HighPart = ft.dwHighDateTime;
692 cm_LargeSearchTimeFromUnixTime(&ft, 0);
693 pCurrentEntry->CreationTime.LowPart = ft.dwLowDateTime;
694 pCurrentEntry->CreationTime.HighPart = ft.dwHighDateTime;
695 pCurrentEntry->LastAccessTime = pCurrentEntry->CreationTime;
696 pCurrentEntry->LastWriteTime = pCurrentEntry->CreationTime;
697 pCurrentEntry->ChangeTime = pCurrentEntry->CreationTime;
699 pCurrentEntry->EndOfFile.QuadPart = 0;
700 pCurrentEntry->AllocationSize.QuadPart = 0;
701 pCurrentEntry->FileAttributes = 0;
702 pCurrentEntry->EaSize = 0;
703 pCurrentEntry->Links = 0;
705 len = wcslen(shortName);
706 wcsncpy(pCurrentEntry->ShortName, shortName, len);
707 pCurrentEntry->ShortNameLength = (CCHAR)(len * sizeof(WCHAR));
709 pCurrentEntry->FileNameOffset = sizeof(AFSDirEnumEntry);
711 wname = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->FileNameOffset);
712 wcsncpy(wname, name, len);
713 pCurrentEntry->FileNameLength = (ULONG)(sizeof(WCHAR) * len);
715 pCurrentEntry->TargetNameOffset = 0;
716 pCurrentEntry->TargetNameLength = 0;
718 dwEntryLength += pCurrentEntry->FileNameLength + pCurrentEntry->TargetNameLength;
719 dwEntryLength += (dwEntryLength % 8) ? 8 - (dwEntryLength % 8) : 0; /* quad align */
721 *ppNextEntry = (AFSDirEnumEntry *)((PBYTE)pCurrentEntry + dwEntryLength);
722 if (pdwRemainingLength)
723 *pdwRemainingLength = dwMaxEntryLength - dwEntryLength;
725 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntryNoScp Success FileNameLength=%d TargetNameLength=%d RemainingLength=%d",
726 pCurrentEntry->FileNameLength, pCurrentEntry->TargetNameLength, *pdwRemainingLength);
732 RDR_EnumerateDirectory( IN cm_user_t *userp,
734 IN AFSDirQueryCB *QueryCB,
737 IN DWORD ResultBufferLength,
738 IN OUT AFSCommResult **ResultCB)
741 cm_direnum_t * enump = NULL;
742 AFSDirEnumResp * pDirEnumResp;
743 AFSDirEnumEntry * pCurrentEntry;
744 size_t size = ResultBufferLength ? sizeof(AFSCommResult) + ResultBufferLength - 1 : sizeof(AFSCommResult);
745 DWORD dwMaxEntryLength;
748 cm_scache_t * dscp = NULL;
753 req.flags |= CM_REQ_WOW64;
755 osi_Log4(afsd_logp, "RDR_EnumerateDirectory FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
756 DirID.Cell, DirID.Volume, DirID.Vnode, DirID.Unique);
758 *ResultCB = (AFSCommResult *)malloc(size);
760 osi_Log0(afsd_logp, "RDR_EnumerateDirectory Out of Memory");
764 memset(*ResultCB, 0, size);
766 if (QueryCB->EnumHandle == (ULONG_PTR)-1) {
767 osi_Log0(afsd_logp, "RDR_EnumerateDirectory No More Entries");
768 (*ResultCB)->ResultStatus = STATUS_NO_MORE_ENTRIES;
769 (*ResultCB)->ResultBufferLength = 0;
773 (*ResultCB)->ResultBufferLength = dwMaxEntryLength = ResultBufferLength;
774 if (ResultBufferLength) {
775 pDirEnumResp = (AFSDirEnumResp *)&(*ResultCB)->ResultData;
776 pCurrentEntry = (AFSDirEnumEntry *)&pDirEnumResp->Entry;
777 dwMaxEntryLength -= FIELD_OFFSET( AFSDirEnumResp, Entry); /* AFSDirEnumResp */
780 if (DirID.Cell != 0) {
781 fid.cell = DirID.Cell;
782 fid.volume = DirID.Volume;
783 fid.vnode = DirID.Vnode;
784 fid.unique = DirID.Unique;
785 fid.hash = DirID.Hash;
787 code = cm_GetSCache(&fid, NULL, &dscp, userp, &req);
789 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
790 (*ResultCB)->ResultStatus = status;
791 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_GetSCache failure code=0x%x status=0x%x",
796 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
797 osi_Log0(afsd_logp, "RDR_EnumerateDirectory Object Name Invalid - Cell = 0");
801 /* get the directory size */
802 lock_ObtainWrite(&dscp->rw);
803 code = cm_SyncOp(dscp, NULL, userp, &req, PRSFS_LOOKUP,
804 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
806 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
807 (*ResultCB)->ResultStatus = status;
808 lock_ReleaseWrite(&dscp->rw);
809 cm_ReleaseSCache(dscp);
810 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_SyncOp failure code=0x%x status=0x%x",
815 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
816 lock_ReleaseWrite(&dscp->rw);
818 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
819 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
820 cm_ReleaseSCache(dscp);
821 osi_Log1(afsd_logp, "RDR_EnumerateDirectory Not a Directory dscp=0x%p",
826 osi_Log1(afsd_logp, "RDR_EnumerateDirectory dv=%u", (afs_uint32)dscp->dataVersion);
829 * If there is no enumeration handle, then this is a new query
830 * and we must perform an enumeration for the specified object.
832 if (QueryCB->EnumHandle == (ULONG_PTR)NULL) {
835 code = cm_BeginDirOp(dscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
837 code = cm_BPlusDirEnumerate(dscp, userp, &req,
838 TRUE /* dir locked */, NULL /* no mask */,
839 TRUE /* fetch status? */, &enump);
841 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BPlusDirEnumerate failure code=0x%x",
846 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BeginDirOp failure code=0x%x",
850 enump = (cm_direnum_t *)QueryCB->EnumHandle;
854 if (ResultBufferLength == 0) {
855 code = cm_BPlusDirEnumBulkStat(enump);
857 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BPlusDirEnumBulkStat failure code=0x%x",
861 cm_direnum_entry_t * entryp = NULL;
863 pDirEnumResp->SnapshotDataVersion.QuadPart = enump->dataVersion;
866 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
867 osi_Log0(afsd_logp, "RDR_EnumerateDirectory out of space, returning");
871 code = cm_BPlusDirNextEnumEntry(enump, &entryp);
873 if ((code == 0 || code == CM_ERROR_STOPNOW) && entryp) {
874 cm_scache_t *scp = NULL;
875 int stopnow = (code == CM_ERROR_STOPNOW);
877 if ( !wcscmp(L".", entryp->name) || !wcscmp(L"..", entryp->name) ) {
878 osi_Log0(afsd_logp, "RDR_EnumerateDirectory skipping . or ..");
885 code = cm_GetSCache(&entryp->fid, &dscp->fid, &scp, userp, &req);
887 osi_Log5(afsd_logp, "RDR_EnumerateDirectory cm_GetSCache failure cell %u vol %u vnode %u uniq %u code=0x%x",
888 entryp->fid.cell, entryp->fid.volume, entryp->fid.vnode, entryp->fid.unique, code);
891 code = entryp->errorCode;
892 scp = code ? NULL : cm_FindSCache(&entryp->fid);
896 code = RDR_PopulateCurrentEntry( pCurrentEntry, dwMaxEntryLength,
897 dscp, scp, userp, &req,
899 cm_Is8Dot3(entryp->name) ? NULL : entryp->shortName,
900 (bWow64 ? RDR_POP_WOW64 : 0) |
901 (bSkipStatus ? RDR_POP_NO_GETSTATUS : 0),
903 &pCurrentEntry, &dwMaxEntryLength);
904 cm_ReleaseSCache(scp);
906 code = RDR_PopulateCurrentEntryNoScp( pCurrentEntry, dwMaxEntryLength,
907 dscp, &entryp->fid, userp, &req,
909 cm_Is8Dot3(entryp->name) ? NULL : entryp->shortName,
910 (bWow64 ? RDR_POP_WOW64 : 0),
912 &pCurrentEntry, &dwMaxEntryLength);
923 if (code || enump->next == enump->count || ResultBufferLength == 0) {
924 cm_BPlusDirFreeEnumeration(enump);
925 enump = (cm_direnum_t *)(ULONG_PTR)-1;
928 if (code == 0 || code == CM_ERROR_STOPNOW) {
929 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
930 osi_Log0(afsd_logp, "RDR_EnumerateDirectory SUCCESS");
932 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
933 (*ResultCB)->ResultStatus = status;
934 osi_Log2(afsd_logp, "RDR_EnumerateDirectory Failure code=0x%x status=0x%x",
938 if (ResultBufferLength) {
939 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwMaxEntryLength;
941 pDirEnumResp->EnumHandle = (ULONG_PTR) enump;
942 pDirEnumResp->CurrentDataVersion.QuadPart = dscp->dataVersion;
946 cm_ReleaseSCache(dscp);
952 RDR_EvaluateNodeByName( IN cm_user_t *userp,
953 IN AFSFileID ParentID,
954 IN WCHAR *FileNameCounted,
955 IN DWORD FileNameLength,
956 IN BOOL CaseSensitive,
960 IN DWORD ResultBufferLength,
961 IN OUT AFSCommResult **ResultCB)
963 AFSFileEvalResultCB *pEvalResultCB = NULL;
964 AFSDirEnumEntry * pCurrentEntry;
965 size_t size = ResultBufferLength ? sizeof(AFSCommResult) + ResultBufferLength - 1 : sizeof(AFSCommResult);
967 cm_scache_t * scp = NULL;
968 cm_scache_t * dscp = NULL;
973 WCHAR * wszName = NULL;
976 wchar_t FileName[260];
978 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
982 req.flags |= CM_REQ_WOW64;
984 osi_Log4(afsd_logp, "RDR_EvaluateNodeByName parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
985 ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
987 /* Allocate enough room to add a volume prefix if necessary */
988 cbName = FileNameLength + (CM_PREFIX_VOL_CCH + 1) * sizeof(WCHAR);
989 wszName = malloc(cbName);
991 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Out of Memory");
994 StringCbCopyNW(wszName, cbName, FileName, FileNameLength);
995 osi_Log1(afsd_logp, "... name=%S", osi_LogSaveStringW(afsd_logp, wszName));
997 *ResultCB = (AFSCommResult *)malloc(size);
999 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Out of Memory");
1004 memset(*ResultCB, 0, size);
1005 (*ResultCB)->ResultBufferLength = 0;
1006 dwRemaining = ResultBufferLength;
1007 if (ResultBufferLength >= sizeof( AFSFileEvalResultCB)) {
1008 pEvalResultCB = (AFSFileEvalResultCB *)&(*ResultCB)->ResultData;
1009 pCurrentEntry = &pEvalResultCB->DirEnum;
1010 dwRemaining -= (sizeof( AFSFileEvalResultCB) - sizeof( AFSDirEnumEntry));
1013 if (ParentID.Cell != 0) {
1014 parentFid.cell = ParentID.Cell;
1015 parentFid.volume = ParentID.Volume;
1016 parentFid.vnode = ParentID.Vnode;
1017 parentFid.unique = ParentID.Unique;
1018 parentFid.hash = ParentID.Hash;
1020 code = cm_GetSCache(&parentFid, NULL, &dscp, userp, &req);
1022 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1023 (*ResultCB)->ResultStatus = status;
1024 if ( status == STATUS_INVALID_HANDLE)
1025 status = STATUS_OBJECT_PATH_INVALID;
1026 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName cm_GetSCache parentFID failure code=0x%x status=0x%x",
1032 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
1033 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Object Name Invalid - Cell = 0");
1037 /* get the directory size */
1038 lock_ObtainWrite(&dscp->rw);
1039 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1040 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1042 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1043 (*ResultCB)->ResultStatus = status;
1044 lock_ReleaseWrite(&dscp->rw);
1045 cm_ReleaseSCache(dscp);
1046 osi_Log3(afsd_logp, "RDR_EvaluateNodeByName cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1047 dscp, code, status);
1051 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1052 lock_ReleaseWrite(&dscp->rw);
1054 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1055 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1056 cm_ReleaseSCache(dscp);
1057 osi_Log1(afsd_logp, "RDR_EvaluateNodeByName Not a Directory dscp=0x%p",
1063 code = cm_Lookup(dscp, wszName, CM_FLAG_CHECKPATH, userp, &req, &scp);
1065 if ((code == CM_ERROR_NOSUCHPATH || code == CM_ERROR_NOSUCHFILE || code == CM_ERROR_BPLUS_NOMATCH) &&
1066 (wcschr(wszName, '%') != NULL || wcschr(wszName, '#') != NULL)) {
1068 * A volume reference: <cell>{%,#}<volume> -> @vol:<cell>{%,#}<volume>
1070 StringCchCopyNW(wszName, cbName, _C(CM_PREFIX_VOL), CM_PREFIX_VOL_CCH);
1071 StringCbCatNW(wszName, cbName, FileName, FileNameLength);
1074 code = cm_EvaluateVolumeReference(wszName, CM_FLAG_CHECKPATH, userp, &req, &scp);
1077 if (code == 0 && scp) {
1078 wchar_t shortName[13]=L"";
1081 cm_Gen8Dot3VolNameW(scp->fid.cell, scp->fid.volume, shortName, NULL);
1082 } else if (!cm_Is8Dot3(wszName)) {
1085 dfid.vnode = htonl(scp->fid.vnode);
1086 dfid.unique = htonl(scp->fid.unique);
1088 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1090 shortName[0] = '\0';
1093 code = RDR_PopulateCurrentEntry(pCurrentEntry, dwRemaining,
1094 dscp, scp, userp, &req,
1095 FileName, shortName,
1096 (bWow64 ? RDR_POP_WOW64 : 0) |
1097 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1098 0, NULL, &dwRemaining);
1100 RDR_FlagScpInUse( scp, FALSE );
1101 cm_ReleaseSCache(scp);
1104 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1105 (*ResultCB)->ResultStatus = status;
1106 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1109 pEvalResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1110 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1111 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1112 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName SUCCESS");
1115 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1116 (*ResultCB)->ResultStatus = status;
1117 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1120 (*ResultCB)->ResultStatus = STATUS_NO_SUCH_FILE;
1121 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName No Such File");
1123 cm_ReleaseSCache(dscp);
1130 RDR_EvaluateNodeByID( IN cm_user_t *userp,
1131 IN AFSFileID ParentID, /* not used */
1132 IN AFSFileID SourceID,
1136 IN DWORD ResultBufferLength,
1137 IN OUT AFSCommResult **ResultCB)
1139 AFSFileEvalResultCB *pEvalResultCB = NULL;
1140 AFSDirEnumEntry * pCurrentEntry = NULL;
1141 size_t size = ResultBufferLength ? sizeof(AFSCommResult) + ResultBufferLength - 1 : sizeof(AFSCommResult);
1142 afs_uint32 code = 0;
1143 cm_scache_t * scp = NULL;
1144 cm_scache_t * dscp = NULL;
1151 osi_Log4(afsd_logp, "RDR_EvaluateNodeByID source FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1152 SourceID.Cell, SourceID.Volume, SourceID.Vnode, SourceID.Unique);
1153 osi_Log4(afsd_logp, "... parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1154 ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1156 *ResultCB = (AFSCommResult *)malloc(size);
1158 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Out of Memory");
1162 memset(*ResultCB, 0, size);
1163 (*ResultCB)->ResultBufferLength = 0;
1164 dwRemaining = ResultBufferLength;
1165 if (ResultBufferLength >= sizeof( AFSFileEvalResultCB)) {
1166 pEvalResultCB = (AFSFileEvalResultCB *)&(*ResultCB)->ResultData;
1167 pCurrentEntry = &pEvalResultCB->DirEnum;
1168 dwRemaining -= (sizeof( AFSFileEvalResultCB) - sizeof( AFSDirEnumEntry));
1173 req.flags |= CM_REQ_WOW64;
1175 if (SourceID.Cell != 0) {
1176 cm_SetFid(&Fid, SourceID.Cell, SourceID.Volume, SourceID.Vnode, SourceID.Unique);
1177 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
1179 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1180 (*ResultCB)->ResultStatus = status;
1181 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache SourceFID failure code=0x%x status=0x%x",
1186 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
1187 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Name Invalid - Cell = 0");
1191 if (ParentID.Cell != 0) {
1192 cm_SetFid(&parentFid, ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1193 code = cm_GetSCache(&parentFid, NULL, &dscp, userp, &req);
1195 cm_ReleaseSCache(scp);
1196 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1197 if ( status == STATUS_INVALID_HANDLE)
1198 status = STATUS_OBJECT_PATH_INVALID;
1199 (*ResultCB)->ResultStatus = status;
1200 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1204 } else if (SourceID.Vnode == 1) {
1206 cm_HoldSCache(dscp);
1207 } else if (scp->parentVnode) {
1208 cm_SetFid(&parentFid, SourceID.Cell, SourceID.Volume, scp->parentVnode, scp->parentUnique);
1209 code = cm_GetSCache(&parentFid, NULL, &dscp, userp, &req);
1211 cm_ReleaseSCache(scp);
1212 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1213 if ( status == STATUS_INVALID_HANDLE)
1214 status = STATUS_OBJECT_PATH_INVALID;
1215 (*ResultCB)->ResultStatus = status;
1216 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1221 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
1222 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Path Invalid - Unknown Parent");
1226 /* Make sure the directory is current */
1227 lock_ObtainWrite(&dscp->rw);
1228 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1229 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1231 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1232 (*ResultCB)->ResultStatus = status;
1233 lock_ReleaseWrite(&dscp->rw);
1234 cm_ReleaseSCache(dscp);
1235 cm_ReleaseSCache(scp);
1236 osi_Log3(afsd_logp, "RDR_EvaluateNodeByID cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1237 dscp, code, status);
1241 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1242 lock_ReleaseWrite(&dscp->rw);
1244 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1245 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1246 cm_ReleaseSCache(dscp);
1247 cm_ReleaseSCache(scp);
1248 osi_Log1(afsd_logp, "RDR_EvaluateNodeByID Not a Directory dscp=0x%p", dscp);
1252 code = RDR_PopulateCurrentEntry(pCurrentEntry, dwRemaining,
1253 dscp, scp, userp, &req, NULL, NULL,
1254 (bWow64 ? RDR_POP_WOW64 : 0) |
1255 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1256 0, NULL, &dwRemaining);
1259 RDR_FlagScpInUse( scp, FALSE );
1260 cm_ReleaseSCache(scp);
1261 cm_ReleaseSCache(dscp);
1264 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1265 (*ResultCB)->ResultStatus = status;
1266 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID FAILURE code=0x%x status=0x%x",
1269 pEvalResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1271 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1272 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1273 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID SUCCESS");
1279 RDR_CreateFileEntry( IN cm_user_t *userp,
1280 IN WCHAR *FileNameCounted,
1281 IN DWORD FileNameLength,
1282 IN AFSFileCreateCB *CreateCB,
1285 IN DWORD ResultBufferLength,
1286 IN OUT AFSCommResult **ResultCB)
1288 AFSFileCreateResultCB *pResultCB = NULL;
1289 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1292 cm_scache_t * dscp = NULL;
1293 afs_uint32 flags = 0;
1295 cm_scache_t * scp = NULL;
1298 wchar_t FileName[260];
1300 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1302 osi_Log4(afsd_logp, "RDR_CreateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1303 CreateCB->ParentId.Cell, CreateCB->ParentId.Volume,
1304 CreateCB->ParentId.Vnode, CreateCB->ParentId.Unique);
1305 osi_Log1(afsd_logp, "... name=%S", osi_LogSaveStringW(afsd_logp, FileName));
1309 req.flags |= CM_REQ_WOW64;
1310 memset(&setAttr, 0, sizeof(cm_attr_t));
1312 *ResultCB = (AFSCommResult *)malloc(size);
1314 osi_Log0(afsd_logp, "RDR_CreateFileEntry out of memory");
1322 parentFid.cell = CreateCB->ParentId.Cell;
1323 parentFid.volume = CreateCB->ParentId.Volume;
1324 parentFid.vnode = CreateCB->ParentId.Vnode;
1325 parentFid.unique = CreateCB->ParentId.Unique;
1326 parentFid.hash = CreateCB->ParentId.Hash;
1328 code = cm_GetSCache(&parentFid, NULL, &dscp, userp, &req);
1330 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1331 (*ResultCB)->ResultStatus = status;
1332 if ( status == STATUS_INVALID_HANDLE)
1333 status = STATUS_OBJECT_PATH_INVALID;
1334 osi_Log2(afsd_logp, "RDR_CreateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1339 lock_ObtainWrite(&dscp->rw);
1340 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1341 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1343 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1344 (*ResultCB)->ResultStatus = status;
1345 lock_ReleaseWrite(&dscp->rw);
1346 cm_ReleaseSCache(dscp);
1347 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (1) dscp=0x%p code=0x%x status=0x%x",
1348 dscp, code, status);
1352 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1353 lock_ReleaseWrite(&dscp->rw);
1355 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1356 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1357 cm_ReleaseSCache(dscp);
1358 osi_Log1(afsd_logp, "RDR_CreateFileEntry Not a Directory dscp=0x%p",
1363 /* Use current time */
1364 setAttr.mask = CM_ATTRMASK_CLIENTMODTIME;
1365 setAttr.clientModTime = time(NULL);
1367 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1368 if (smb_unixModeDefaultDir) {
1369 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1370 setAttr.unixModeBits = smb_unixModeDefaultDir;
1371 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1372 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1375 code = cm_MakeDir(dscp, FileName, flags, &setAttr, userp, &req, &scp);
1377 if (smb_unixModeDefaultFile) {
1378 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1379 setAttr.unixModeBits = smb_unixModeDefaultFile;
1380 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1381 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1384 setAttr.mask |= CM_ATTRMASK_LENGTH;
1385 setAttr.length.LowPart = CreateCB->AllocationSize.LowPart;
1386 setAttr.length.HighPart = CreateCB->AllocationSize.HighPart;
1387 code = cm_Create(dscp, FileName, flags, &setAttr, &scp, userp, &req);
1390 wchar_t shortName[13]=L"";
1394 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
1396 (*ResultCB)->ResultBufferLength = sizeof( AFSFileCreateResultCB);
1398 pResultCB = (AFSFileCreateResultCB *)(*ResultCB)->ResultData;
1400 dwRemaining = ResultBufferLength - sizeof( AFSFileCreateResultCB) + sizeof( AFSDirEnumEntry);
1402 lock_ObtainWrite(&dscp->rw);
1403 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1404 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1406 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1407 (*ResultCB)->ResultStatus = status;
1408 lock_ReleaseWrite(&dscp->rw);
1409 cm_ReleaseSCache(dscp);
1410 cm_ReleaseSCache(scp);
1411 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (2) dscp=0x%p code=0x%x status=0x%x",
1412 dscp, code, status);
1416 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1418 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1419 lock_ReleaseWrite(&dscp->rw);
1421 dfid.vnode = htonl(scp->fid.vnode);
1422 dfid.unique = htonl(scp->fid.unique);
1424 if (!cm_Is8Dot3(FileName))
1425 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1427 shortName[0] = '\0';
1429 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1430 dscp, scp, userp, &req, FileName, shortName,
1431 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1432 0, NULL, &dwRemaining);
1435 RDR_FlagScpInUse( scp, FALSE );
1436 cm_ReleaseSCache(scp);
1437 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1438 osi_Log0(afsd_logp, "RDR_CreateFileEntry SUCCESS");
1440 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1441 (*ResultCB)->ResultStatus = status;
1442 (*ResultCB)->ResultBufferLength = 0;
1443 osi_Log2(afsd_logp, "RDR_CreateFileEntry FAILURE code=0x%x status=0x%x",
1447 cm_ReleaseSCache(dscp);
1453 RDR_UpdateFileEntry( IN cm_user_t *userp,
1454 IN AFSFileID FileId,
1455 IN AFSFileUpdateCB *UpdateCB,
1457 IN DWORD ResultBufferLength,
1458 IN OUT AFSCommResult **ResultCB)
1460 AFSFileUpdateResultCB *pResultCB = NULL;
1461 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1465 afs_uint32 flags = 0;
1467 cm_scache_t * scp = NULL;
1468 cm_scache_t * dscp = NULL;
1470 time_t clientModTime;
1473 BOOL bScpLocked = FALSE;
1477 req.flags |= CM_REQ_WOW64;
1478 memset(&setAttr, 0, sizeof(cm_attr_t));
1480 osi_Log4(afsd_logp, "RDR_UpdateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1481 UpdateCB->ParentId.Cell, UpdateCB->ParentId.Volume,
1482 UpdateCB->ParentId.Vnode, UpdateCB->ParentId.Unique);
1483 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1484 FileId.Cell, FileId.Volume,
1485 FileId.Vnode, FileId.Unique);
1487 *ResultCB = (AFSCommResult *)malloc( size);
1489 osi_Log0(afsd_logp, "RDR_UpdateFileEntry Out of Memory");
1497 parentFid.cell = UpdateCB->ParentId.Cell;
1498 parentFid.volume = UpdateCB->ParentId.Volume;
1499 parentFid.vnode = UpdateCB->ParentId.Vnode;
1500 parentFid.unique = UpdateCB->ParentId.Unique;
1501 parentFid.hash = UpdateCB->ParentId.Hash;
1503 code = cm_GetSCache(&parentFid, NULL, &dscp, userp, &req);
1505 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1506 (*ResultCB)->ResultStatus = status;
1507 if ( status == STATUS_INVALID_HANDLE)
1508 status = STATUS_OBJECT_PATH_INVALID;
1509 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1514 lock_ObtainWrite(&dscp->rw);
1516 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1517 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1519 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1520 (*ResultCB)->ResultStatus = status;
1521 lock_ReleaseWrite(&dscp->rw);
1522 cm_ReleaseSCache(dscp);
1523 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1524 dscp, code, status);
1528 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1529 lock_ReleaseWrite(&dscp->rw);
1532 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1533 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1534 cm_ReleaseSCache(dscp);
1535 osi_Log1(afsd_logp, "RDR_UpdateFileEntry Not a Directory dscp=0x%p",
1540 Fid.cell = FileId.Cell;
1541 Fid.volume = FileId.Volume;
1542 Fid.vnode = FileId.Vnode;
1543 Fid.unique = FileId.Unique;
1544 Fid.hash = FileId.Hash;
1546 code = cm_GetSCache(&Fid, &dscp->fid, &scp, userp, &req);
1548 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1549 (*ResultCB)->ResultStatus = status;
1550 cm_ReleaseSCache(dscp);
1551 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache object FID failure code=0x%x status=0x%x",
1556 lock_ObtainWrite(&scp->rw);
1558 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1559 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1561 lock_ReleaseWrite(&scp->rw);
1562 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1563 (*ResultCB)->ResultStatus = status;
1564 (*ResultCB)->ResultBufferLength = 0;
1565 cm_ReleaseSCache(dscp);
1566 cm_ReleaseSCache(scp);
1567 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
1571 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1573 if (UpdateCB->ChangeTime.QuadPart) {
1575 if (scp->fileType == CM_SCACHETYPE_FILE) {
1576 /* Do not set length and other attributes at the same time */
1577 if (scp->length.QuadPart != UpdateCB->AllocationSize.QuadPart) {
1578 osi_Log2(afsd_logp, "RDR_UpdateFileEntry Length Change 0x%x -> 0x%x",
1579 (afs_uint32)scp->length.QuadPart, (afs_uint32)UpdateCB->AllocationSize.QuadPart);
1580 setAttr.mask |= CM_ATTRMASK_LENGTH;
1581 setAttr.length.LowPart = UpdateCB->AllocationSize.LowPart;
1582 setAttr.length.HighPart = UpdateCB->AllocationSize.HighPart;
1583 lock_ReleaseWrite(&scp->rw);
1585 code = cm_SetAttr(scp, &setAttr, userp, &req);
1593 lock_ObtainWrite(&scp->rw);
1596 if ((scp->unixModeBits & 0200) && (UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1597 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1598 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1599 } else if (!(scp->unixModeBits & 0200) && !(UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1600 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1601 setAttr.unixModeBits = scp->unixModeBits | 0222;
1605 if (UpdateCB->LastWriteTime.QuadPart) {
1606 ft.dwLowDateTime = UpdateCB->LastWriteTime.LowPart;
1607 ft.dwHighDateTime = UpdateCB->LastWriteTime.HighPart;
1609 cm_UnixTimeFromLargeSearchTime(& clientModTime, &ft);
1612 lock_ObtainWrite(&scp->rw);
1615 if (scp->clientModTime != clientModTime) {
1616 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1617 setAttr.clientModTime = clientModTime;
1622 lock_ReleaseWrite(&scp->rw);
1624 code = cm_SetAttr(scp, &setAttr, userp, &req);
1631 lock_ReleaseWrite(&scp->rw);
1635 DWORD dwRemaining = ResultBufferLength - sizeof( AFSFileUpdateResultCB) + sizeof( AFSDirEnumEntry);
1637 pResultCB = (AFSFileUpdateResultCB *)(*ResultCB)->ResultData;
1639 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1641 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1642 dscp, scp, userp, &req, NULL, NULL,
1643 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1644 0, NULL, &dwRemaining);
1645 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1646 osi_Log0(afsd_logp, "RDR_UpdateFileEntry SUCCESS");
1648 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1649 (*ResultCB)->ResultStatus = status;
1650 (*ResultCB)->ResultBufferLength = 0;
1651 osi_Log2(afsd_logp, "RDR_UpdateFileEntry FAILURE code=0x%x status=0x%x",
1654 cm_ReleaseSCache(scp);
1655 cm_ReleaseSCache(dscp);
1661 RDR_CleanupFileEntry( IN cm_user_t *userp,
1662 IN AFSFileID FileId,
1663 IN WCHAR *FileNameCounted,
1664 IN DWORD FileNameLength,
1665 IN AFSFileCleanupCB *CleanupCB,
1667 IN BOOL bLastHandle,
1668 IN BOOL bDeleteFile,
1669 IN BOOL bUnlockFile,
1670 IN DWORD ResultBufferLength,
1671 IN OUT AFSCommResult **ResultCB)
1673 AFSFileCleanupResultCB *pResultCB = NULL;
1674 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1677 afs_uint32 code = 0;
1678 afs_uint32 flags = 0;
1680 cm_scache_t * scp = NULL;
1681 cm_scache_t * dscp = NULL;
1683 time_t clientModTime;
1686 BOOL bScpLocked = FALSE;
1687 BOOL bDscpLocked = FALSE;
1688 BOOL bFlushFile = FALSE;
1693 req.flags |= CM_REQ_WOW64;
1694 memset(&setAttr, 0, sizeof(cm_attr_t));
1696 osi_Log4(afsd_logp, "RDR_CleanupFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1697 CleanupCB->ParentId.Cell, CleanupCB->ParentId.Volume,
1698 CleanupCB->ParentId.Vnode, CleanupCB->ParentId.Unique);
1699 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1700 FileId.Cell, FileId.Volume,
1701 FileId.Vnode, FileId.Unique);
1703 *ResultCB = (AFSCommResult *)malloc( size);
1705 osi_Log0(afsd_logp, "RDR_CleanupFileEntry Out of Memory");
1713 parentFid.cell = CleanupCB->ParentId.Cell;
1714 parentFid.volume = CleanupCB->ParentId.Volume;
1715 parentFid.vnode = CleanupCB->ParentId.Vnode;
1716 parentFid.unique = CleanupCB->ParentId.Unique;
1717 parentFid.hash = CleanupCB->ParentId.Hash;
1719 if (parentFid.cell) {
1720 code = cm_GetSCache(&parentFid, NULL, &dscp, userp, &req);
1722 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1723 if ( status == STATUS_INVALID_HANDLE)
1724 status = STATUS_OBJECT_PATH_INVALID;
1725 (*ResultCB)->ResultStatus = status;
1726 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1731 lock_ObtainWrite(&dscp->rw);
1733 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1734 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1736 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure dscp=0x%p code=0x%x",
1742 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1743 lock_ReleaseWrite(&dscp->rw);
1744 bDscpLocked = FALSE;
1746 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1747 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1748 cm_ReleaseSCache(dscp);
1749 osi_Log1(afsd_logp, "RDR_CleanupFileEntry Not a Directory dscp=0x%p",
1756 Fid.cell = FileId.Cell;
1757 Fid.volume = FileId.Volume;
1758 Fid.vnode = FileId.Vnode;
1759 Fid.unique = FileId.Unique;
1760 Fid.hash = FileId.Hash;
1762 code = cm_GetSCache(&Fid, dscp ? &dscp->fid : NULL, &scp, userp, &req);
1764 osi_Log1(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache object FID failure code=0x%x",
1769 lock_ObtainWrite(&scp->rw);
1771 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1772 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1774 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure scp=0x%p code=0x%x",
1778 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1780 if ((bLastHandle || bFlushFile) &&
1781 scp->redirBufCount > 0)
1783 LARGE_INTEGER heldExtents;
1784 AFSFileExtentCB extentList[1024];
1785 DWORD extentCount = 0;
1790 heldExtents.QuadPart = 0;
1792 for ( srbp = redirq_to_cm_buf_t(scp->redirQueueT);
1794 srbp = redirq_to_cm_buf_t(osi_QPrev(&srbp->redirq)))
1796 extentList[extentCount].Flags = 0;
1797 extentList[extentCount].Length = cm_data.blockSize;
1798 extentList[extentCount].FileOffset.QuadPart = srbp->offset.QuadPart;
1799 extentList[extentCount].CacheOffset.QuadPart = srbp->datap - RDR_extentBaseAddress;
1800 lock_ObtainWrite(&buf_globalLock);
1801 srbp->redirReleaseRequested = now;
1802 lock_ReleaseWrite(&buf_globalLock);
1805 if (extentCount == 1024) {
1806 lock_ReleaseWrite(&scp->rw);
1807 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1809 if (code == CM_ERROR_RETRY) {
1811 * The redirector either is not holding the extents or cannot let them
1812 * go because they are otherwise in use. At the moment, do nothing.
1819 lock_ObtainWrite(&scp->rw);
1823 if (code == 0 && extentCount > 0) {
1825 lock_ReleaseWrite(&scp->rw);
1828 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1833 /* No longer in use by redirector */
1835 lock_ObtainWrite(&scp->rw);
1840 lock_AssertWrite(&scp->rw);
1841 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
1844 if (bLastHandle || bFlushFile) {
1846 lock_ObtainWrite(&scp->rw);
1849 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
1850 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1853 lock_ReleaseWrite(&scp->rw);
1857 code = cm_FSync(scp, userp, &req, bScpLocked);
1859 if (bLastHandle && code)
1863 if (bUnlockFile || bDeleteFile) {
1865 lock_ObtainWrite(&scp->rw);
1868 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1869 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1871 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp (2) failure scp=0x%p code=0x%x",
1876 key = cm_GenerateKey(CM_SESSION_IFS, CleanupCB->ProcessId, 0);
1878 /* the scp is now locked and current */
1879 code = cm_UnlockByKey(scp, key,
1880 bDeleteFile ? CM_UNLOCK_FLAG_BY_FID : 0,
1883 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1889 if (CleanupCB->ChangeTime.QuadPart) {
1891 if (scp->fileType == CM_SCACHETYPE_FILE) {
1892 /* Do not set length and other attributes at the same time */
1893 if (scp->length.QuadPart != CleanupCB->AllocationSize.QuadPart) {
1894 osi_Log2(afsd_logp, "RDR_CleanupFileEntry Length Change 0x%x -> 0x%x",
1895 (afs_uint32)scp->length.QuadPart, (afs_uint32)CleanupCB->AllocationSize.QuadPart);
1896 setAttr.mask |= CM_ATTRMASK_LENGTH;
1897 setAttr.length.LowPart = CleanupCB->AllocationSize.LowPart;
1898 setAttr.length.HighPart = CleanupCB->AllocationSize.HighPart;
1901 lock_ReleaseWrite(&scp->rw);
1904 code = cm_SetAttr(scp, &setAttr, userp, &req);
1912 lock_ObtainWrite(&scp->rw);
1916 if ((scp->unixModeBits & 0200) && (CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1917 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1918 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1919 } else if (!(scp->unixModeBits & 0200) && !(CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1920 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1921 setAttr.unixModeBits = scp->unixModeBits | 0222;
1925 if (CleanupCB->LastWriteTime.QuadPart) {
1926 ft.dwLowDateTime = CleanupCB->LastWriteTime.LowPart;
1927 ft.dwHighDateTime = CleanupCB->LastWriteTime.HighPart;
1929 cm_UnixTimeFromLargeSearchTime(&clientModTime, &ft);
1930 if (scp->clientModTime != clientModTime) {
1931 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1932 setAttr.clientModTime = clientModTime;
1938 lock_ReleaseWrite(&scp->rw);
1940 code = cm_SetAttr(scp, &setAttr, userp, &req);
1944 /* Now drop the lock enforcing the share access */
1945 if ( CleanupCB->FileAccess != AFS_FILE_ACCESS_NOLOCK) {
1946 unsigned int sLockType;
1947 LARGE_INTEGER LOffset, LLength;
1949 if (CleanupCB->FileAccess == AFS_FILE_ACCESS_SHARED)
1950 sLockType = LOCKING_ANDX_SHARED_LOCK;
1954 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, CleanupCB->Identifier);
1956 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
1957 LOffset.LowPart = SMB_FID_QLOCK_LOW;
1958 LLength.HighPart = 0;
1959 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
1962 lock_ObtainWrite(&scp->rw);
1966 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
1969 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
1971 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
1973 if (code == CM_ERROR_RANGE_NOT_LOCKED)
1975 osi_Log3(afsd_logp, "RDR_CleanupFileEntry Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
1976 CleanupCB->FileAccess, CleanupCB->ProcessId, CleanupCB->Identifier);
1984 lock_ReleaseWrite(&dscp->rw);
1986 lock_ReleaseWrite(&scp->rw);
1988 if (code == 0 && dscp && bDeleteFile) {
1989 WCHAR FileName[260];
1991 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1993 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
1994 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
1996 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2000 if ( ResultBufferLength >= sizeof( AFSFileCleanupResultCB))
2002 (*ResultCB)->ResultBufferLength = sizeof( AFSFileCleanupResultCB);
2003 pResultCB = (AFSFileCleanupResultCB *)&(*ResultCB)->ResultData;
2004 pResultCB->ParentDataVersion.QuadPart = dscp ? dscp->dataVersion : 0;
2006 (*ResultCB)->ResultBufferLength = 0;
2009 (*ResultCB)->ResultStatus = 0;
2010 osi_Log0(afsd_logp, "RDR_CleanupFileEntry SUCCESS");
2012 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2013 (*ResultCB)->ResultStatus = status;
2014 osi_Log2(afsd_logp, "RDR_CleanupFileEntry FAILURE code=0x%x status=0x%x",
2019 cm_ReleaseSCache(scp);
2021 cm_ReleaseSCache(dscp);
2027 RDR_DeleteFileEntry( IN cm_user_t *userp,
2028 IN AFSFileID ParentId,
2029 IN ULONGLONG ProcessId,
2030 IN WCHAR *FileNameCounted,
2031 IN DWORD FileNameLength,
2034 IN DWORD ResultBufferLength,
2035 IN OUT AFSCommResult **ResultCB)
2038 AFSFileDeleteResultCB *pResultCB = NULL;
2039 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2042 cm_scache_t * dscp = NULL;
2043 cm_scache_t * scp = NULL;
2044 afs_uint32 flags = 0;
2048 wchar_t FileName[260];
2051 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
2053 osi_Log4(afsd_logp, "RDR_DeleteFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2054 ParentId.Cell, ParentId.Volume,
2055 ParentId.Vnode, ParentId.Unique);
2056 osi_Log2(afsd_logp, "... name=%S checkOnly=%x",
2057 osi_LogSaveStringW(afsd_logp, FileName),
2062 req.flags |= CM_REQ_WOW64;
2063 memset(&setAttr, 0, sizeof(cm_attr_t));
2065 *ResultCB = (AFSCommResult *)malloc( size);
2067 osi_Log0(afsd_logp, "RDR_DeleteFileEntry out of memory");
2075 parentFid.cell = ParentId.Cell;
2076 parentFid.volume = ParentId.Volume;
2077 parentFid.vnode = ParentId.Vnode;
2078 parentFid.unique = ParentId.Unique;
2079 parentFid.hash = ParentId.Hash;
2081 code = cm_GetSCache(&parentFid, NULL, &dscp, userp, &req);
2083 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2084 if ( status == STATUS_INVALID_HANDLE)
2085 status = STATUS_OBJECT_PATH_INVALID;
2086 (*ResultCB)->ResultStatus = status;
2087 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
2092 lock_ObtainWrite(&dscp->rw);
2094 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
2095 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2097 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2098 (*ResultCB)->ResultStatus = status;
2099 (*ResultCB)->ResultBufferLength = 0;
2100 lock_ReleaseWrite(&dscp->rw);
2101 cm_ReleaseSCache(dscp);
2102 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
2103 dscp, code, status);
2107 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2108 lock_ReleaseWrite(&dscp->rw);
2110 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2111 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2112 cm_ReleaseSCache(dscp);
2113 osi_Log1(afsd_logp, "RDR_DeleteFileEntry Not a Directory dscp=0x%p",
2118 code = cm_Lookup(dscp, FileName, 0, userp, &req, &scp);
2120 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2121 (*ResultCB)->ResultStatus = status;
2122 (*ResultCB)->ResultBufferLength = 0;
2123 cm_ReleaseSCache(dscp);
2124 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_Lookup failure code=0x%x status=0x%x",
2129 lock_ObtainWrite(&scp->rw);
2130 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_DELETE,
2131 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2133 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2134 (*ResultCB)->ResultStatus = status;
2135 (*ResultCB)->ResultBufferLength = 0;
2136 lock_ReleaseWrite(&scp->rw);
2137 cm_ReleaseSCache(scp);
2138 cm_ReleaseSCache(dscp);
2139 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2145 /* Drop all locks since the file is being deleted */
2146 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2147 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2149 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2150 (*ResultCB)->ResultStatus = status;
2151 (*ResultCB)->ResultBufferLength = 0;
2152 lock_ReleaseWrite(&scp->rw);
2153 cm_ReleaseSCache(scp);
2154 cm_ReleaseSCache(dscp);
2155 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp Lock failure scp=0x%p code=0x%x status=0x%x",
2159 /* the scp is now locked and current */
2160 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId, 0);
2162 code = cm_UnlockByKey(scp, key,
2163 CM_UNLOCK_FLAG_BY_FID,
2166 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2167 lock_ReleaseWrite(&scp->rw);
2169 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
2170 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
2172 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2174 lock_ReleaseWrite(&scp->rw);
2178 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
2180 (*ResultCB)->ResultBufferLength = sizeof( AFSFileDeleteResultCB);
2182 pResultCB = (AFSFileDeleteResultCB *)(*ResultCB)->ResultData;
2184 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
2185 osi_Log0(afsd_logp, "RDR_DeleteFileEntry SUCCESS");
2187 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2188 (*ResultCB)->ResultStatus = status;
2189 (*ResultCB)->ResultBufferLength = 0;
2190 osi_Log2(afsd_logp, "RDR_DeleteFileEntry FAILURE code=0x%x status=0x%x",
2194 cm_ReleaseSCache(dscp);
2195 cm_ReleaseSCache(scp);
2201 RDR_RenameFileEntry( IN cm_user_t *userp,
2202 IN WCHAR *SourceFileNameCounted,
2203 IN DWORD SourceFileNameLength,
2204 IN AFSFileID SourceFileId,
2205 IN AFSFileRenameCB *pRenameCB,
2207 IN DWORD ResultBufferLength,
2208 IN OUT AFSCommResult **ResultCB)
2211 AFSFileRenameResultCB *pResultCB = NULL;
2212 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2213 AFSFileID SourceParentId = pRenameCB->SourceParentId;
2214 AFSFileID TargetParentId = pRenameCB->TargetParentId;
2215 WCHAR * TargetFileNameCounted = pRenameCB->TargetName;
2216 DWORD TargetFileNameLength = pRenameCB->TargetNameLength;
2217 cm_fid_t SourceParentFid;
2218 cm_fid_t TargetParentFid;
2220 cm_fid_t OrigTargetFid = {0,0,0,0,0};
2222 cm_scache_t * oldDscp;
2223 cm_scache_t * newDscp;
2225 wchar_t shortName[13];
2226 wchar_t SourceFileName[260];
2227 wchar_t TargetFileName[260];
2235 req.flags |= CM_REQ_WOW64;
2237 StringCchCopyNW(SourceFileName, 260, SourceFileNameCounted, SourceFileNameLength / sizeof(WCHAR));
2238 StringCchCopyNW(TargetFileName, 260, TargetFileNameCounted, TargetFileNameLength / sizeof(WCHAR));
2240 osi_Log4(afsd_logp, "RDR_RenameFileEntry Source Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2241 SourceParentId.Cell, SourceParentId.Volume,
2242 SourceParentId.Vnode, SourceParentId.Unique);
2243 osi_Log2(afsd_logp, "... Source Name=%S Length %u", osi_LogSaveStringW(afsd_logp, SourceFileName), SourceFileNameLength);
2244 osi_Log4(afsd_logp, "... Target Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2245 TargetParentId.Cell, TargetParentId.Volume,
2246 TargetParentId.Vnode, TargetParentId.Unique);
2247 osi_Log2(afsd_logp, "... Target Name=%S Length %u", osi_LogSaveStringW(afsd_logp, TargetFileName), TargetFileNameLength);
2249 *ResultCB = (AFSCommResult *)malloc( size);
2257 pResultCB = (AFSFileRenameResultCB *)(*ResultCB)->ResultData;
2259 if (SourceFileNameLength == 0 || TargetFileNameLength == 0)
2261 osi_Log2(afsd_logp, "RDR_RenameFileEntry Invalid Name Length: src %u target %u",
2262 SourceFileNameLength, TargetFileNameLength);
2263 (*ResultCB)->ResultStatus = STATUS_INVALID_PARAMETER;
2267 SourceParentFid.cell = SourceParentId.Cell;
2268 SourceParentFid.volume = SourceParentId.Volume;
2269 SourceParentFid.vnode = SourceParentId.Vnode;
2270 SourceParentFid.unique = SourceParentId.Unique;
2271 SourceParentFid.hash = SourceParentId.Hash;
2273 TargetParentFid.cell = TargetParentId.Cell;
2274 TargetParentFid.volume = TargetParentId.Volume;
2275 TargetParentFid.vnode = TargetParentId.Vnode;
2276 TargetParentFid.unique = TargetParentId.Unique;
2277 TargetParentFid.hash = TargetParentId.Hash;
2279 code = cm_GetSCache(&SourceParentFid, NULL, &oldDscp, userp, &req);
2281 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache source parent failed code 0x%x", code);
2282 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2283 if ( status == STATUS_INVALID_HANDLE)
2284 status = STATUS_OBJECT_PATH_INVALID;
2285 (*ResultCB)->ResultStatus = status;
2289 lock_ObtainWrite(&oldDscp->rw);
2290 code = cm_SyncOp(oldDscp, NULL, userp, &req, 0,
2291 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2293 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp oldDscp 0x%p failed code 0x%x", oldDscp, code);
2294 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2295 if ( status == STATUS_INVALID_HANDLE)
2296 status = STATUS_OBJECT_PATH_INVALID;
2297 (*ResultCB)->ResultStatus = status;
2298 lock_ReleaseWrite(&oldDscp->rw);
2299 cm_ReleaseSCache(oldDscp);
2303 cm_SyncOpDone(oldDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2304 lock_ReleaseWrite(&oldDscp->rw);
2307 if (oldDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2308 osi_Log1(afsd_logp, "RDR_RenameFileEntry oldDscp 0x%p not a directory", oldDscp);
2309 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2310 cm_ReleaseSCache(oldDscp);
2314 code = cm_GetSCache(&TargetParentFid, NULL, &newDscp, userp, &req);
2316 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target parent failed code 0x%x", code);
2317 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2318 (*ResultCB)->ResultStatus = status;
2319 cm_ReleaseSCache(oldDscp);
2323 lock_ObtainWrite(&newDscp->rw);
2324 code = cm_SyncOp(newDscp, NULL, userp, &req, 0,
2325 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2327 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp newDscp 0x%p failed code 0x%x", newDscp, code);
2328 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2329 (*ResultCB)->ResultStatus = status;
2330 lock_ReleaseWrite(&newDscp->rw);
2331 cm_ReleaseSCache(oldDscp);
2332 cm_ReleaseSCache(newDscp);
2336 cm_SyncOpDone(newDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2337 lock_ReleaseWrite(&newDscp->rw);
2340 if (newDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2341 osi_Log1(afsd_logp, "RDR_RenameFileEntry newDscp 0x%p not a directory", newDscp);
2342 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2343 cm_ReleaseSCache(oldDscp);
2344 cm_ReleaseSCache(newDscp);
2348 /* Obtain the original FID just for debugging purposes */
2349 code = cm_BeginDirOp( oldDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2351 code = cm_BPlusDirLookup(&dirop, SourceFileName, &SourceFid);
2352 code = cm_BPlusDirLookup(&dirop, TargetFileName, &OrigTargetFid);
2353 cm_EndDirOp(&dirop);
2356 code = cm_Rename( oldDscp, NULL, SourceFileName,
2357 newDscp, TargetFileName, userp, &req);
2359 cm_scache_t *scp = 0;
2362 (*ResultCB)->ResultBufferLength = ResultBufferLength;
2363 dwRemaining = ResultBufferLength - sizeof( AFSFileRenameResultCB) + sizeof( AFSDirEnumEntry);
2364 (*ResultCB)->ResultStatus = 0;
2366 pResultCB->SourceParentDataVersion.QuadPart = oldDscp->dataVersion;
2367 pResultCB->TargetParentDataVersion.QuadPart = newDscp->dataVersion;
2369 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p SUCCESS",
2372 code = cm_BeginDirOp( newDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2374 code = cm_BPlusDirLookup(&dirop, TargetFileName, &TargetFid);
2375 cm_EndDirOp(&dirop);
2379 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_BPlusDirLookup failed code 0x%x",
2381 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
2382 cm_ReleaseSCache(oldDscp);
2383 cm_ReleaseSCache(newDscp);
2387 osi_Log4(afsd_logp, "RDR_RenameFileEntry Target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2388 TargetFid.cell, TargetFid.volume,
2389 TargetFid.vnode, TargetFid.unique);
2391 code = cm_GetSCache(&TargetFid, &newDscp->fid, &scp, userp, &req);
2393 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target failed code 0x%x", code);
2394 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2395 (*ResultCB)->ResultStatus = status;
2396 cm_ReleaseSCache(oldDscp);
2397 cm_ReleaseSCache(newDscp);
2401 /* Make sure the source vnode is current */
2402 lock_ObtainWrite(&scp->rw);
2403 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2404 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2406 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp scp 0x%p failed code 0x%x", scp, code);
2407 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2408 (*ResultCB)->ResultStatus = status;
2409 lock_ReleaseWrite(&scp->rw);
2410 cm_ReleaseSCache(oldDscp);
2411 cm_ReleaseSCache(newDscp);
2412 cm_ReleaseSCache(scp);
2416 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2417 lock_ReleaseWrite(&scp->rw);
2419 dfid.vnode = htonl(scp->fid.vnode);
2420 dfid.unique = htonl(scp->fid.unique);
2422 if (!cm_Is8Dot3(TargetFileName))
2423 cm_Gen8Dot3NameIntW(TargetFileName, &dfid, shortName, NULL);
2425 shortName[0] = '\0';
2427 RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
2428 newDscp, scp, userp, &req, TargetFileName, shortName,
2429 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
2430 0, NULL, &dwRemaining);
2431 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
2432 cm_ReleaseSCache(scp);
2434 osi_Log0(afsd_logp, "RDR_RenameFileEntry SUCCESS");
2436 osi_Log3(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p failed code 0x%x",
2437 oldDscp, newDscp, code);
2438 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2439 (*ResultCB)->ResultStatus = status;
2440 (*ResultCB)->ResultBufferLength = 0;
2443 cm_ReleaseSCache(oldDscp);
2444 cm_ReleaseSCache(newDscp);
2449 RDR_FlushFileEntry( IN cm_user_t *userp,
2450 IN AFSFileID FileId,
2452 IN DWORD ResultBufferLength,
2453 IN OUT AFSCommResult **ResultCB)
2455 cm_scache_t *scp = NULL;
2466 req.flags |= CM_REQ_WOW64;
2468 osi_Log4(afsd_logp, "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x",
2469 FileId.Cell, FileId.Volume,
2470 FileId.Vnode, FileId.Unique);
2472 snprintf( dbgstr, 1024,
2473 "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x\n",
2474 FileId.Cell, FileId.Volume,
2475 FileId.Vnode, FileId.Unique);
2476 OutputDebugStringA( dbgstr);
2479 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2481 osi_Log0(afsd_logp, "RDR_FlushFileEntry out of memory");
2487 sizeof( AFSCommResult));
2489 /* Process the release */
2490 Fid.cell = FileId.Cell;
2491 Fid.volume = FileId.Volume;
2492 Fid.vnode = FileId.Vnode;
2493 Fid.unique = FileId.Unique;
2494 Fid.hash = FileId.Hash;
2496 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
2498 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2499 (*ResultCB)->ResultStatus = status;
2500 osi_Log2(afsd_logp, "RDR_FlushFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2505 lock_ObtainWrite(&scp->rw);
2506 if (scp->flags & CM_SCACHEFLAG_DELETED) {
2507 lock_ReleaseWrite(&scp->rw);
2508 (*ResultCB)->ResultStatus = STATUS_INVALID_HANDLE;
2512 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2513 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2515 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2516 (*ResultCB)->ResultStatus = status;
2517 lock_ReleaseWrite(&scp->rw);
2518 cm_ReleaseSCache(scp);
2519 osi_Log3(afsd_logp, "RDR_FlushFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2524 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2525 lock_ReleaseWrite(&scp->rw);
2527 code = cm_FSync(scp, userp, &req, FALSE);
2528 cm_ReleaseSCache(scp);
2531 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2532 (*ResultCB)->ResultStatus = status;
2533 osi_Log2(afsd_logp, "RDR_FlushFileEntry FAILURE code=0x%x status=0x%x",
2536 (*ResultCB)->ResultStatus = 0;
2537 osi_Log0(afsd_logp, "RDR_FlushFileEntry SUCCESS");
2539 (*ResultCB)->ResultBufferLength = 0;
2545 RDR_CheckAccess( IN cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp,
2549 ULONG afs_acc, afs_gr;
2551 afs_uint32 code = 0;
2553 file = (scp->fileType == CM_SCACHETYPE_FILE);
2556 /* access definitions from prs_fs.h */
2558 if (access & FILE_READ_DATA)
2559 afs_acc |= PRSFS_READ;
2560 if (access & FILE_READ_EA || access & FILE_READ_ATTRIBUTES)
2561 afs_acc |= PRSFS_READ;
2562 if (file && ((access & FILE_WRITE_DATA) || (access & FILE_APPEND_DATA)))
2563 afs_acc |= PRSFS_WRITE;
2564 if (access & FILE_WRITE_EA || access & FILE_WRITE_ATTRIBUTES)
2565 afs_acc |= PRSFS_WRITE;
2566 if (dir && ((access & FILE_ADD_FILE) || (access & FILE_ADD_SUBDIRECTORY)))
2567 afs_acc |= PRSFS_INSERT;
2568 if (dir && (access & FILE_LIST_DIRECTORY))
2569 afs_acc |= PRSFS_LOOKUP;
2570 if (file && (access & FILE_EXECUTE))
2571 afs_acc |= PRSFS_WRITE;
2572 if (dir && (access & FILE_TRAVERSE))
2573 afs_acc |= PRSFS_READ;
2574 if (dir && (access & FILE_DELETE_CHILD))
2575 afs_acc |= PRSFS_DELETE;
2576 if ((access & DELETE))
2577 afs_acc |= PRSFS_DELETE;
2579 /* check ACL with server */
2580 lock_ObtainWrite(&scp->rw);
2583 if (cm_HaveAccessRights(scp, userp, reqp, afs_acc, &afs_gr))
2589 /* we don't know the required access rights */
2590 code = cm_GetAccessRights(scp, userp, reqp);
2596 lock_ReleaseWrite(&(scp->rw));
2600 if (afs_gr & PRSFS_READ)
2601 *granted |= FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | FILE_EXECUTE;
2602 if (afs_gr & PRSFS_WRITE)
2603 *granted |= FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES | FILE_EXECUTE;
2604 if (afs_gr & PRSFS_INSERT)
2605 *granted |= (dir ? FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY : 0) | (file ? FILE_ADD_SUBDIRECTORY : 0);
2606 if (afs_gr & PRSFS_LOOKUP)
2607 *granted |= (dir ? FILE_LIST_DIRECTORY : 0);
2608 if (afs_gr & PRSFS_DELETE)
2609 *granted |= FILE_DELETE_CHILD | DELETE;
2610 if (afs_gr & PRSFS_LOCK)
2612 if (afs_gr & PRSFS_ADMINISTER)
2615 *granted |= SYNCHRONIZE | READ_CONTROL;
2617 /* don't give more access than what was requested */
2619 osi_Log3(afsd_logp, "RDR_CheckAccess SUCCESS scp=0x%p requested=0x%x granted=0x%x", scp, access, *granted);
2621 osi_Log2(afsd_logp, "RDR_CheckAccess FAILURE scp=0x%p code=0x%x",
2628 RDR_OpenFileEntry( IN cm_user_t *userp,
2629 IN AFSFileID FileId,
2630 IN AFSFileOpenCB *OpenCB,
2633 IN DWORD ResultBufferLength,
2634 IN OUT AFSCommResult **ResultCB)
2636 AFSFileOpenResultCB *pResultCB = NULL;
2637 cm_scache_t *scp = NULL;
2638 cm_user_t *sysUserp = NULL;
2640 cm_lock_data_t *ldp = NULL;
2647 req.flags |= CM_REQ_WOW64;
2649 osi_Log4(afsd_logp, "RDR_OpenFileEntry File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2650 FileId.Cell, FileId.Volume,
2651 FileId.Vnode, FileId.Unique);
2653 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2655 osi_Log0(afsd_logp, "RDR_OpenFileEntry out of memory");
2661 sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2663 pResultCB = (AFSFileOpenResultCB *)(*ResultCB)->ResultData;
2665 /* Process the release */
2666 Fid.cell = FileId.Cell;
2667 Fid.volume = FileId.Volume;
2668 Fid.vnode = FileId.Vnode;
2669 Fid.unique = FileId.Unique;
2670 Fid.hash = FileId.Hash;
2672 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
2674 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2675 (*ResultCB)->ResultStatus = status;
2676 osi_Log2(afsd_logp, "RDR_OpenFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2681 lock_ObtainWrite(&scp->rw);
2682 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2683 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2685 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2686 (*ResultCB)->ResultStatus = status;
2687 lock_ReleaseWrite(&scp->rw);
2688 cm_ReleaseSCache(scp);
2689 osi_Log3(afsd_logp, "RDR_OpenFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2694 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2695 lock_ReleaseWrite(&scp->rw);
2697 sysUserp = RDR_GetLocalSystemUser();
2700 * Skip the open check if the request is coming from the local system account.
2701 * The local system has no tokens and therefore any requests sent to a file
2702 * server will fail. Unfortunately, there are special system processes that
2703 * perform actions on files and directories in preparation for memory mapping
2704 * executables. If the open check fails, the real request from the user process
2705 * will never be issued.
2707 * Permitting the file system to allow subsequent operations to proceed does
2708 * not compromise security. All requests to obtain file data or directory
2709 * enumerations will subsequently fail if they are not submitted under the
2710 * context of a process for that have access to the necessary credentials.
2713 if ( userp == sysUserp)
2715 osi_Log1(afsd_logp, "RDR_OpenFileEntry LOCAL_SYSTEM access check skipped scp=0x%p",
2717 pResultCB->GrantedAccess = OpenCB->DesiredAccess;
2718 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2729 "RDR_OpenFileEntry repeating open check scp=0x%p userp=0x%p code=0x%x",
2732 code = cm_CheckNTOpen(scp, OpenCB->DesiredAccess, OpenCB->ShareAccess,
2734 OpenCB->ProcessId, OpenCB->Identifier,
2737 code = RDR_CheckAccess(scp, userp, &req, OpenCB->DesiredAccess, &pResultCB->GrantedAccess);
2738 cm_CheckNTOpenDone(scp, userp, &req, &ldp);
2739 } while (count < 100 && (code == CM_ERROR_RETRY || code == CM_ERROR_WOULDBLOCK));
2743 * If we are restricting sharing, we should do so with a suitable
2746 if (code == 0 && scp->fileType == CM_SCACHETYPE_FILE && !(OpenCB->ShareAccess & FILE_SHARE_WRITE)) {
2748 LARGE_INTEGER LOffset, LLength;
2751 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2752 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2753 LLength.HighPart = 0;
2754 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2757 * If we are not opening the file for writing, then we don't
2758 * try to get an exclusive lock. No one else should be able to
2759 * get an exclusive lock on the file anyway, although someone
2760 * else can get a shared lock.
2762 if ((OpenCB->ShareAccess & FILE_SHARE_READ) || !(OpenCB->DesiredAccess & AFS_ACCESS_WRITE))
2764 sLockType = LOCKING_ANDX_SHARED_LOCK;
2769 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, OpenCB->Identifier);
2771 lock_ObtainWrite(&scp->rw);
2772 code = cm_Lock(scp, sLockType, LOffset, LLength, key, 0, userp, &req, NULL);
2773 lock_ReleaseWrite(&scp->rw);
2776 code = CM_ERROR_SHARING_VIOLATION;
2777 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2779 if (sLockType == LOCKING_ANDX_SHARED_LOCK)
2780 pResultCB->FileAccess = AFS_FILE_ACCESS_SHARED;
2782 pResultCB->FileAccess = AFS_FILE_ACCESS_EXCLUSIVE;
2785 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2788 cm_ReleaseUser(sysUserp);
2789 if (code == 0 && bHoldFid)
2790 RDR_FlagScpInUse( scp, FALSE );
2791 cm_ReleaseSCache(scp);
2794 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2795 (*ResultCB)->ResultStatus = status;
2796 osi_Log2(afsd_logp, "RDR_OpenFileEntry FAILURE code=0x%x status=0x%x",
2799 (*ResultCB)->ResultStatus = 0;
2800 (*ResultCB)->ResultBufferLength = sizeof( AFSFileOpenResultCB);
2801 osi_Log0(afsd_logp, "RDR_OpenFileEntry SUCCESS");
2807 RDR_ReleaseFileAccess( IN cm_user_t *userp,
2808 IN AFSFileID FileId,
2809 IN AFSFileAccessReleaseCB *ReleaseFileCB,
2811 IN DWORD ResultBufferLength,
2812 IN OUT AFSCommResult **ResultCB)
2815 unsigned int sLockType;
2816 LARGE_INTEGER LOffset, LLength;
2817 cm_scache_t *scp = NULL;
2825 req.flags |= CM_REQ_WOW64;
2827 osi_Log4(afsd_logp, "RDR_ReleaseFileAccess File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2828 FileId.Cell, FileId.Volume,
2829 FileId.Vnode, FileId.Unique);
2831 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2833 osi_Log0(afsd_logp, "RDR_ReleaseFileAccess out of memory");
2837 memset( *ResultCB, '\0', sizeof( AFSCommResult));
2839 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_NOLOCK)
2842 /* Process the release */
2843 Fid.cell = FileId.Cell;
2844 Fid.volume = FileId.Volume;
2845 Fid.vnode = FileId.Vnode;
2846 Fid.unique = FileId.Unique;
2847 Fid.hash = FileId.Hash;
2849 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
2851 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2852 (*ResultCB)->ResultStatus = status;
2853 osi_Log2(afsd_logp, "RDR_ReleaseFileAccess cm_GetSCache FID failure code=0x%x status=0x%x",
2858 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_SHARED)
2859 sLockType = LOCKING_ANDX_SHARED_LOCK;
2863 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, ReleaseFileCB->Identifier);
2865 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2866 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2867 LLength.HighPart = 0;
2868 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2870 lock_ObtainWrite(&scp->rw);
2872 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
2875 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
2877 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
2879 if (code == CM_ERROR_RANGE_NOT_LOCKED)
2881 osi_Log3(afsd_logp, "RDR_ReleaseFileAccess Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
2882 ReleaseFileCB->FileAccess, ReleaseFileCB->ProcessId, ReleaseFileCB->Identifier);
2886 lock_ReleaseWrite(&scp->rw);
2888 osi_Log0(afsd_logp, "RDR_ReleaseFileAccessEntry SUCCESS");
2892 HexCheckSum(unsigned char * buf, int buflen, unsigned char * md5cksum)
2895 static char tr[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
2898 return "buffer length too small to HexCheckSum";
2900 for (i=0;i<16;i++) {
2903 buf[i*2] = tr[k / 16];
2904 buf[i*2+1] = tr[k % 16];
2912 * Extent requests from the file system are triggered when a file
2913 * page is not resident in the Windows cache. The file system is
2914 * responsible for loading the page but cannot block the request
2915 * while doing so. The AFS Redirector forwards the requests to
2916 * the AFS cache manager while indicating to Windows that the page
2917 * is not yet available. A polling operation will then ensue with
2918 * the AFS Redirector issuing a RDR_RequestFileExtentsXXX call for
2919 * each poll attempt. As each request is received and processed
2920 * by a separate worker thread in the service, this can lead to
2921 * contention by multiple threads attempting to claim the same
2922 * cm_buf_t objects. Therefore, it is important that
2924 * (a) the service avoid processing more than one overlapping
2925 * extent request at a time
2926 * (b) background daemon processing be used to avoid blocking
2929 * Beginning with the 20091122 build of the redirector, the redirector
2930 * will not issue an additional RDR_RequestFileExtentsXXX call for
2931 * each poll request. Instead, afsd_service is required to track
2932 * the requests and return them to the redirector or fail the
2933 * portions of the request that cannot be satisfied.
2935 * The request processing returns any extents that can be returned
2936 * immediately to the redirector. The rest of the requested range(s)
2937 * are queued as background operations using RDR_BkgFetch().
2940 /* do the background fetch. */
2942 RDR_BkgFetch(cm_scache_t *scp, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4,
2943 cm_user_t *userp, cm_req_t *reqp)
2949 osi_hyper_t fetched;
2950 osi_hyper_t tblocksize;
2953 cm_buf_t *bufp = NULL;
2954 DWORD dwResultBufferLength;
2955 AFSSetFileExtentsCB *pResultCB;
2959 int reportErrorToRedir = 0;
2960 int force_retry = 0;
2962 FileId.Cell = scp->fid.cell;
2963 FileId.Volume = scp->fid.volume;
2964 FileId.Vnode = scp->fid.vnode;
2965 FileId.Unique = scp->fid.unique;
2966 FileId.Hash = scp->fid.hash;
2968 if ((GetTickCount() - reqp->startTime) / 1000 > HardDeadtimeout * 5) {
2969 RDR_SetFileStatus( &scp->fid, &userp->authgroup, STATUS_IO_TIMEOUT);
2973 fetched.LowPart = 0;
2974 fetched.HighPart = 0;
2975 tblocksize = ConvertLongToLargeInteger(cm_data.buf_blockSize);
2978 length.LowPart = p3;
2979 length.HighPart = p4;
2981 end = LargeIntegerAdd(base, length);
2983 osi_Log5(afsd_logp, "Starting BKG Fetch scp 0x%p offset 0x%x:%x length 0x%x:%x",
2984 scp, p2, p1, p4, p3);
2987 * Make sure we have a callback.
2988 * This is necessary so that we can return access denied
2989 * if a callback cannot be granted.
2991 lock_ObtainWrite(&scp->rw);
2992 code = cm_SyncOp(scp, NULL, userp, reqp, PRSFS_READ,
2993 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2995 lock_ReleaseWrite(&scp->rw);
2996 osi_Log2(afsd_logp, "RDR_BkgFetch cm_SyncOp failure scp=0x%p code=0x%x",
2998 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
2999 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3002 lock_ReleaseWrite(&scp->rw);
3004 dwResultBufferLength = (DWORD)(sizeof( AFSSetFileExtentsCB) + sizeof( AFSSetFileExtentsCB) * (length.QuadPart / cm_data.blockSize + 1));
3005 pResultCB = (AFSSetFileExtentsCB *)malloc( dwResultBufferLength );
3007 return CM_ERROR_RETRY;
3009 memset( pResultCB, '\0', dwResultBufferLength );
3010 pResultCB->FileId = FileId;
3012 for ( code = 0, offset = base;
3013 code == 0 && LargeIntegerLessThan(offset, end);
3014 offset = LargeIntegerAdd(offset, tblocksize) )
3016 int bBufRelease = TRUE;
3019 lock_ReleaseWrite(&scp->rw);
3023 code = buf_Get(scp, &offset, reqp, &bufp);
3026 * any error from buf_Get() is non-fatal.
3027 * we need to re-queue this extent fetch.
3034 lock_ObtainWrite(&scp->rw);
3038 code = cm_GetBuffer(scp, bufp, NULL, userp, reqp);
3040 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3041 #ifdef VALIDATE_CHECK_SUM
3047 if (bufp->flags & CM_BUF_DIRTY)
3048 cm_BufWrite(scp, &bufp->offset, cm_data.buf_blockSize, CM_BUF_WRITE_SCP_LOCKED, userp, reqp);
3050 lock_ObtainWrite(&buf_globalLock);
3051 if (!(bufp->flags & CM_BUF_DIRTY) &&
3052 bufp->cmFlags == 0 &&
3053 !(bufp->qFlags & CM_BUF_QREDIR)) {
3054 buf_InsertToRedirQueue(scp, bufp);
3055 lock_ReleaseWrite(&buf_globalLock);
3057 #ifdef VALIDATE_CHECK_SUM
3058 buf_ComputeCheckSum(bufp);
3060 pResultCB->FileExtents[count].Flags = 0;
3061 pResultCB->FileExtents[count].FileOffset.QuadPart = bufp->offset.QuadPart;
3062 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3063 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3065 fetched = LargeIntegerAdd(fetched, tblocksize);
3066 bBufRelease = FALSE;
3068 #ifdef VALIDATE_CHECK_SUM
3070 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3071 snprintf( dbgstr, 1024,
3072 "RDR_BkgFetch md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3074 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3075 pResultCB->FileExtents[count].FileOffset.HighPart,
3076 pResultCB->FileExtents[count].FileOffset.LowPart,
3077 pResultCB->FileExtents[count].CacheOffset.HighPart,
3078 pResultCB->FileExtents[count].CacheOffset.LowPart);
3079 OutputDebugStringA( dbgstr);
3082 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3083 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3085 lock_ReleaseWrite(&buf_globalLock);
3086 if ((bufp->cmFlags != 0) || (bufp->flags & CM_BUF_DIRTY)) {
3087 /* An I/O operation is already in progress */
3089 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Not delivering to Redirector Dirty or Busy bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3090 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3092 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3093 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3097 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3098 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3102 * depending on what the error from cm_GetBuffer is
3103 * it may or may not be fatal. Only return fatal errors.
3104 * Re-queue a request for others.
3106 osi_Log5(afsd_logp, "RDR_BkgFetch Extent2FS FAILURE bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x code 0x%x",
3107 bufp, offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize, code);
3109 case CM_ERROR_NOACCESS:
3110 case CM_ERROR_NOSUCHFILE:
3111 case CM_ERROR_NOSUCHPATH:
3112 case CM_ERROR_NOSUCHVOLUME:
3113 case CM_ERROR_NOSUCHCELL:
3114 case CM_ERROR_INVAL:
3115 case CM_ERROR_BADFD:
3116 case CM_ERROR_CLOCKSKEW:
3118 case CM_ERROR_QUOTA:
3119 case CM_ERROR_LOCK_CONFLICT:
3121 * these are fatal errors. deliver what we can
3124 reportErrorToRedir = 1;
3128 * non-fatal errors. re-queue the exent
3130 code = CM_ERROR_RETRY;
3140 lock_ObtainWrite(&scp->rw);
3144 /* wakeup anyone who is waiting */
3145 if (scp->flags & CM_SCACHEFLAG_WAITING) {
3146 osi_Log1(afsd_logp, "RDR Bkg Fetch Waking scp 0x%p", scp);
3147 osi_Wakeup((LONG_PTR) &scp->flags);
3149 lock_ReleaseWrite(&scp->rw);
3152 pResultCB->ExtentCount = count;
3153 RDR_SetFileExtents( pResultCB, dwResultBufferLength);
3157 if (reportErrorToRedir) {
3158 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
3159 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3162 osi_Log4(afsd_logp, "Ending BKG Fetch scp 0x%p code 0x%x fetched 0x%x:%x",
3163 scp, code, fetched.HighPart, fetched.LowPart);
3165 return force_retry ? CM_ERROR_RETRY : code;
3170 RDR_RequestFileExtentsAsync( IN cm_user_t *userp,
3171 IN AFSFileID FileId,
3172 IN AFSRequestExtentsCB *RequestExtentsCB,
3174 IN OUT DWORD * ResultBufferLength,
3175 IN OUT AFSSetFileExtentsCB **ResultCB)
3177 AFSSetFileExtentsCB *pResultCB = NULL;
3181 cm_scache_t *scp = NULL;
3184 afs_uint32 code = 0;
3186 LARGE_INTEGER ByteOffset, BeginOffset, EndOffset, QueueOffset;
3187 afs_uint32 QueueLength;
3189 BOOLEAN bBufRelease = TRUE;
3193 req.flags |= CM_REQ_WOW64;
3194 req.flags |= CM_REQ_NORETRY;
3196 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3197 FileId.Cell, FileId.Volume,
3198 FileId.Vnode, FileId.Unique);
3199 osi_Log4(afsd_logp, "... Flags 0x%x ByteOffset 0x%x:%x Length 0x%x",
3200 RequestExtentsCB->Flags,
3201 RequestExtentsCB->ByteOffset.HighPart, RequestExtentsCB->ByteOffset.LowPart,
3202 RequestExtentsCB->Length);
3203 Length = sizeof( AFSSetFileExtentsCB) + sizeof( AFSFileExtentCB) * (RequestExtentsCB->Length / cm_data.blockSize + 1);
3205 pResultCB = *ResultCB = (AFSSetFileExtentsCB *)malloc( Length );
3206 if (*ResultCB == NULL) {
3207 *ResultBufferLength = 0;
3210 *ResultBufferLength = Length;
3212 memset( pResultCB, '\0', Length );
3213 pResultCB->FileId = FileId;
3215 Fid.cell = FileId.Cell;
3216 Fid.volume = FileId.Volume;
3217 Fid.vnode = FileId.Vnode;
3218 Fid.unique = FileId.Unique;
3219 Fid.hash = FileId.Hash;
3221 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
3223 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync cm_GetSCache FID failure code=0x%x",
3225 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3230 * Make sure we have a callback.
3231 * This is necessary so that we can return access denied
3232 * if a callback cannot be granted.
3234 lock_ObtainWrite(&scp->rw);
3235 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_READ,
3236 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3237 lock_ReleaseWrite(&scp->rw);
3239 cm_ReleaseSCache(scp);
3240 osi_Log2(afsd_logp, "RDR_RequestFileExtentsAsync cm_SyncOp failure scp=0x%p code=0x%x",
3242 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3243 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3247 /* Allocate the extents from the buffer package */
3249 ByteOffset = BeginOffset = RequestExtentsCB->ByteOffset,
3250 EndOffset.QuadPart = ByteOffset.QuadPart + RequestExtentsCB->Length;
3251 code == 0 && ByteOffset.QuadPart < EndOffset.QuadPart;
3252 ByteOffset.QuadPart += cm_data.blockSize)
3254 BOOL bHaveBuffer = FALSE;
3257 thyper.QuadPart = ByteOffset.QuadPart;
3259 code = buf_Get(scp, &thyper, &req, &bufp);
3261 lock_ObtainMutex(&bufp->mx);
3264 if (bufp->qFlags & CM_BUF_QREDIR) {
3266 } else if (bufp->flags & CM_BUF_DIRTY) {
3267 bHaveBuffer = FALSE;
3269 code = buf_CleanAsyncLocked(scp, bufp, &req, 0, NULL);
3274 case CM_ERROR_RETRY:
3275 /* Couldn't flush it, obtain it asynchronously so we don't block the thread. */
3276 bHaveBuffer = FALSE;
3280 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3281 RDR_SetFileStatus(&FileId, &userp->authgroup, status);
3282 bHaveBuffer = FALSE;
3287 osi_hyper_t minLength; /* effective end of file */
3289 lock_ObtainRead(&scp->rw);
3290 bHaveBuffer = cm_HaveBuffer(scp, bufp, TRUE);
3292 if (LargeIntegerGreaterThan(scp->length, scp->serverLength))
3293 minLength = scp->serverLength;
3295 minLength = scp->length;
3298 LargeIntegerGreaterThanOrEqualTo(bufp->offset, minLength)) {
3299 memset(bufp->datap, 0, cm_data.buf_blockSize);
3300 bufp->dataVersion = scp->dataVersion;
3303 else if ((RequestExtentsCB->Flags & AFS_EXTENT_FLAG_CLEAN) &&
3304 ByteOffset.QuadPart <= bufp->offset.QuadPart &&
3305 EndOffset.QuadPart >= bufp->offset.QuadPart + cm_data.blockSize)
3307 memset(bufp->datap, 0, cm_data.blockSize);
3308 bufp->dataVersion = scp->dataVersion;
3309 buf_SetDirty(bufp, &req, 0, cm_data.blockSize, userp);
3312 lock_ReleaseRead(&scp->rw);
3316 * if this buffer is already up to date, skip it.
3319 if (ByteOffset.QuadPart == BeginOffset.QuadPart) {
3320 BeginOffset.QuadPart += cm_data.blockSize;
3322 QueueLength = (afs_uint32)(ByteOffset.QuadPart - BeginOffset.QuadPart);
3323 QueueOffset = BeginOffset;
3324 BeginOffset = ByteOffset;
3327 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3328 #ifdef VALIDATE_CHECK_SUM
3334 lock_ObtainWrite(&buf_globalLock);
3335 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3336 buf_InsertToRedirQueue(scp, bufp);
3337 lock_ReleaseWrite(&buf_globalLock);
3339 #ifdef VALIDATE_CHECK_SUM
3340 buf_ComputeCheckSum(bufp);
3342 /* we already have the buffer, return it now */
3343 pResultCB->FileExtents[count].Flags = 0;
3344 pResultCB->FileExtents[count].FileOffset = ByteOffset;
3345 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3346 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3349 bBufRelease = FALSE;
3351 #ifdef VALIDATE_CHECK_SUM
3353 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3354 snprintf( dbgstr, 1024,
3355 "RDR_RequestFileExtentsAsync md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3357 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3358 pResultCB->FileExtents[count].FileOffset.HighPart,
3359 pResultCB->FileExtents[count].FileOffset.LowPart,
3360 pResultCB->FileExtents[count].CacheOffset.HighPart,
3361 pResultCB->FileExtents[count].CacheOffset.LowPart);
3362 OutputDebugStringA( dbgstr);
3365 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3366 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3368 lock_ReleaseWrite(&buf_globalLock);
3373 * The service is not handing off the extent to the redirector in this pass.
3374 * However, we know the buffer is in recent use so move the buffer to the
3375 * front of the queue
3377 lock_ObtainWrite(&buf_globalLock);
3378 buf_MoveToHeadOfRedirQueue(scp, bufp);
3379 lock_ReleaseWrite(&buf_globalLock);
3381 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3382 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3386 lock_ReleaseMutex(&bufp->mx);
3391 cm_QueueBKGRequest(scp, RDR_BkgFetch, QueueOffset.LowPart, QueueOffset.HighPart,
3392 QueueLength, 0, userp, &req);
3393 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3394 QueueOffset.HighPart, QueueOffset.LowPart, QueueLength);
3397 /* No error from buf_Get() can be fatal */
3398 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync buf_Get FAILURE offset 0x%x:%x code 0x%x",
3399 BeginOffset.HighPart, BeginOffset.LowPart, code);
3403 if (BeginOffset.QuadPart != EndOffset.QuadPart) {
3404 afs_uint32 length = (afs_uint32)(EndOffset.QuadPart - BeginOffset.QuadPart);
3406 cm_QueueBKGRequest(scp, RDR_BkgFetch, BeginOffset.LowPart, BeginOffset.HighPart,
3407 length, 0, userp, &req);
3408 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3409 BeginOffset.HighPart, BeginOffset.LowPart, length);
3411 cm_ReleaseSCache(scp);
3413 (*ResultCB)->ExtentCount = count;
3414 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync replying with 0x%x extent records", count);
3419 * When processing an extent release the extents must be accepted back by
3420 * the service even if there is an error condition returned to the redirector.
3421 * For example, there may no longer be a callback present or the file may
3422 * have been deleted on the file server. Regardless, the extents must be
3423 * put back into the pool.
3426 RDR_ReleaseFileExtents( IN cm_user_t *userp,
3427 IN AFSFileID FileId,
3428 IN AFSReleaseExtentsCB *ReleaseExtentsCB,
3430 IN DWORD ResultBufferLength,
3431 IN OUT AFSCommResult **ResultCB)
3434 cm_scache_t *scp = NULL;
3445 #ifdef VALIDATE_CHECK_SUM
3446 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3453 req.flags |= CM_REQ_WOW64;
3455 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3456 FileId.Cell, FileId.Volume,
3457 FileId.Vnode, FileId.Unique);
3459 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
3465 sizeof( AFSCommResult));
3467 /* Process the release */
3468 Fid.cell = FileId.Cell;
3469 Fid.volume = FileId.Volume;
3470 Fid.vnode = FileId.Vnode;
3471 Fid.unique = FileId.Unique;
3472 Fid.hash = FileId.Hash;
3474 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
3476 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3477 (*ResultCB)->ResultStatus = status;
3478 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents cm_GetSCache FID failure code=0x%x status=0x%x",
3482 deleted = scp && (scp->flags & CM_SCACHEFLAG_DELETED);
3485 * We do not stop processing as a result of being unable to find the cm_scache object.
3486 * If this occurs something really bad has happened since the cm_scache object must have
3487 * been recycled while extents were held by the redirector. However, we will be resilient
3488 * and carry on without it.
3490 * If the file is known to be deleted, there is no point attempting to ask the
3491 * file server about it or update the attributes.
3493 if (scp && ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart &&
3498 memset(&setAttr, 0, sizeof(cm_attr_t));
3499 lock_ObtainWrite(&scp->rw);
3500 if (ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3502 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents new length fid vol 0x%x vno 0x%x length 0x%x:%x",
3503 scp->fid.volume, scp->fid.vnode,
3504 ReleaseExtentsCB->AllocationSize.HighPart,
3505 ReleaseExtentsCB->AllocationSize.LowPart);
3507 setAttr.mask |= CM_ATTRMASK_LENGTH;
3508 setAttr.length.LowPart = ReleaseExtentsCB->AllocationSize.LowPart;
3509 setAttr.length.HighPart = ReleaseExtentsCB->AllocationSize.HighPart;
3511 lock_ReleaseWrite(&scp->rw);
3513 code = cm_SetAttr(scp, &setAttr, userp, &req);
3516 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3517 AFSFileExtentCB * pExtent = &ReleaseExtentsCB->FileExtents[count];
3519 thyper.QuadPart = pExtent->FileOffset.QuadPart;
3521 bufp = buf_Find(&Fid, &thyper);
3523 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
3524 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3525 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3526 Fid.volume, Fid.vnode,
3527 pExtent->FileOffset.HighPart,
3528 pExtent->FileOffset.LowPart);
3529 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
3530 pExtent->CacheOffset.HighPart,
3531 pExtent->CacheOffset.LowPart);
3533 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3534 Fid.volume, Fid.vnode,
3535 pExtent->FileOffset.HighPart,
3536 pExtent->FileOffset.LowPart);
3537 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
3538 pExtent->CacheOffset.HighPart,
3539 pExtent->CacheOffset.LowPart);
3545 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
3546 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3547 Fid.volume, Fid.vnode,
3548 pExtent->FileOffset.HighPart,
3549 pExtent->FileOffset.LowPart);
3550 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
3551 pExtent->CacheOffset.HighPart,
3552 pExtent->CacheOffset.LowPart);
3554 /* Move the buffer to the front of the queue */
3555 lock_ObtainWrite(&buf_globalLock);
3556 buf_MoveToHeadOfRedirQueue(scp, bufp);
3557 lock_ReleaseWrite(&buf_globalLock);
3562 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
3563 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3564 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x not held by file system",
3565 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
3566 pExtent->FileOffset.LowPart);
3567 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3568 pExtent->CacheOffset.HighPart,
3569 pExtent->CacheOffset.LowPart);
3571 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents bufp 0x%p vno 0x%x foffset 0x%x:%x",
3572 bufp, bufp->fid.vnode, pExtent->FileOffset.HighPart,
3573 pExtent->FileOffset.LowPart);
3574 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3575 pExtent->CacheOffset.HighPart,
3576 pExtent->CacheOffset.LowPart);
3578 if (pExtent->Flags || ReleaseExtentsCB->Flags) {
3579 lock_ObtainMutex(&bufp->mx);
3580 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
3581 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
3583 if (bufp->qFlags & CM_BUF_QREDIR) {
3584 lock_ObtainWrite(&buf_globalLock);
3585 if (bufp->qFlags & CM_BUF_QREDIR) {
3586 buf_RemoveFromRedirQueue(scp, bufp);
3587 buf_ReleaseLocked(bufp, TRUE);
3589 lock_ReleaseWrite(&buf_globalLock);
3592 snprintf( dbgstr, 1024,
3593 "RDR_ReleaseFileExtents releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3594 Fid.volume, Fid.vnode, Fid.unique,
3595 pExtent->FileOffset.HighPart,
3596 pExtent->FileOffset.LowPart,
3597 pExtent->CacheOffset.HighPart,
3598 pExtent->CacheOffset.LowPart);
3599 OutputDebugStringA( dbgstr);
3604 snprintf( dbgstr, 1024,
3605 "RDR_ReleaseFileExtents not releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3606 Fid.volume, Fid.vnode, Fid.unique,
3607 pExtent->FileOffset.HighPart,
3608 pExtent->FileOffset.LowPart,
3609 pExtent->CacheOffset.HighPart,
3610 pExtent->CacheOffset.LowPart);
3611 OutputDebugStringA( dbgstr);
3613 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
3614 Fid.volume, Fid.vnode,
3615 pExtent->FileOffset.HighPart,
3616 pExtent->FileOffset.LowPart);
3617 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3618 pExtent->CacheOffset.HighPart,
3619 pExtent->CacheOffset.LowPart);
3622 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
3623 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY) )
3625 #ifdef VALIDATE_CHECK_SUM
3627 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3631 * if the saved checksum matches the checksum of the current state of the buffer
3632 * then the buffer is the same as what was given to the kernel.
3634 if ( buf_ValidateCheckSum(bufp) ) {
3635 buf_ComputeCheckSum(bufp);
3637 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3640 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
3641 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3643 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3646 snprintf( dbgstr, 1024,
3647 "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",
3648 md5dbg, md5dbg2,md5dbg3,
3649 Fid.volume, Fid.vnode, Fid.unique,
3650 pExtent->FileOffset.HighPart,
3651 pExtent->FileOffset.LowPart,
3652 pExtent->CacheOffset.HighPart,
3653 pExtent->CacheOffset.LowPart);
3654 OutputDebugStringA( dbgstr);
3656 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
3657 Fid.volume, Fid.vnode,
3658 pExtent->FileOffset.HighPart,
3659 pExtent->FileOffset.LowPart);
3660 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3661 pExtent->CacheOffset.HighPart,
3662 pExtent->CacheOffset.LowPart);
3663 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3667 snprintf( dbgstr, 1024,
3668 "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",
3669 md5dbg, md5dbg2, md5dbg3,
3670 Fid.volume, Fid.vnode, Fid.unique,
3671 pExtent->FileOffset.HighPart,
3672 pExtent->FileOffset.LowPart,
3673 pExtent->CacheOffset.HighPart,
3674 pExtent->CacheOffset.LowPart);
3675 OutputDebugStringA( dbgstr);
3677 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3678 Fid.volume, Fid.vnode,
3679 pExtent->FileOffset.HighPart,
3680 pExtent->FileOffset.LowPart);
3681 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3682 pExtent->CacheOffset.HighPart,
3683 pExtent->CacheOffset.LowPart);
3687 snprintf( dbgstr, 1024,
3688 "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",
3689 Fid.volume, Fid.vnode, Fid.unique,
3690 pExtent->FileOffset.HighPart,
3691 pExtent->FileOffset.LowPart,
3692 pExtent->CacheOffset.HighPart,
3693 pExtent->CacheOffset.LowPart);
3694 OutputDebugStringA( dbgstr);
3696 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3697 Fid.volume, Fid.vnode,
3698 pExtent->FileOffset.HighPart,
3699 pExtent->FileOffset.LowPart);
3700 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3701 pExtent->CacheOffset.HighPart,
3702 pExtent->CacheOffset.LowPart);
3705 buf_ComputeCheckSum(bufp);
3707 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3709 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3710 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3712 snprintf( dbgstr, 1024,
3713 "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",
3714 md5dbg, md5dbg2,md5dbg3,
3715 Fid.volume, Fid.vnode, Fid.unique,
3716 pExtent->FileOffset.HighPart,
3717 pExtent->FileOffset.LowPart,
3718 pExtent->CacheOffset.HighPart,
3719 pExtent->CacheOffset.LowPart);
3720 OutputDebugStringA( dbgstr);
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);
3733 snprintf( dbgstr, 1024,
3734 "RDR_ReleaseFileExtents dirty flag set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
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 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3746 #else /* !VALIDATE_CHECK_SUM */
3747 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3749 #endif /* VALIDATE_CHECK_SUM */
3751 #ifdef VALIDATE_CHECK_SUM
3754 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3756 if ( !buf_ValidateCheckSum(bufp) ) {
3757 buf_ComputeCheckSum(bufp);
3759 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3760 snprintf( dbgstr, 1024,
3761 "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",
3763 Fid.volume, Fid.vnode, Fid.unique,
3764 pExtent->FileOffset.HighPart,
3765 pExtent->FileOffset.LowPart,
3766 pExtent->CacheOffset.HighPart,
3767 pExtent->CacheOffset.LowPart);
3768 OutputDebugStringA( dbgstr);
3770 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set but extent has changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3771 Fid.volume, Fid.vnode,
3772 pExtent->FileOffset.HighPart,
3773 pExtent->FileOffset.LowPart);
3774 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3775 pExtent->CacheOffset.HighPart,
3776 pExtent->CacheOffset.LowPart);
3777 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3780 buf_ComputeCheckSum(bufp);
3782 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3783 snprintf( dbgstr, 1024,
3784 "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3785 Fid.volume, Fid.vnode, Fid.unique,
3786 pExtent->FileOffset.HighPart,
3787 pExtent->FileOffset.LowPart,
3788 pExtent->CacheOffset.HighPart,
3789 pExtent->CacheOffset.LowPart);
3790 OutputDebugStringA( dbgstr);
3792 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x foffset 0x%x:%x",
3793 Fid.volume, Fid.vnode,
3794 pExtent->FileOffset.HighPart,
3795 pExtent->FileOffset.LowPart);
3796 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3797 pExtent->CacheOffset.HighPart,
3798 pExtent->CacheOffset.LowPart);
3801 #endif /* VALIDATE_CHECK_SUM */
3802 lock_ReleaseMutex(&bufp->mx);
3807 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3810 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3811 if (wbp->datap == datap)
3816 snprintf( dbgstr, 1024,
3817 "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3818 Fid.volume, Fid.vnode, Fid.unique,
3819 pExtent->FileOffset.HighPart,
3820 pExtent->FileOffset.LowPart,
3821 pExtent->CacheOffset.HighPart,
3822 pExtent->CacheOffset.LowPart);
3823 OutputDebugStringA( dbgstr);
3825 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3826 Fid.volume, Fid.vnode,
3827 pExtent->FileOffset.HighPart,
3828 pExtent->FileOffset.LowPart);
3829 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3830 pExtent->CacheOffset.HighPart,
3831 pExtent->CacheOffset.LowPart);
3832 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3833 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3841 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3844 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3845 if (wbp->datap == datap)
3850 snprintf( dbgstr, 1024,
3851 "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3852 Fid.volume, Fid.vnode, Fid.unique,
3853 pExtent->FileOffset.HighPart,
3854 pExtent->FileOffset.LowPart,
3855 pExtent->CacheOffset.HighPart,
3856 pExtent->CacheOffset.LowPart);
3857 OutputDebugStringA( dbgstr);
3859 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3860 Fid.volume, Fid.vnode,
3861 pExtent->FileOffset.HighPart,
3862 pExtent->FileOffset.LowPart);
3863 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3864 pExtent->CacheOffset.HighPart,
3865 pExtent->CacheOffset.LowPart);
3866 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3867 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3872 if (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_FLUSH) {
3873 lock_ObtainWrite(&scp->rw);
3874 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3875 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3876 lock_ReleaseWrite(&scp->rw);
3878 code = cm_FSync(scp, userp, &req, FALSE);
3881 osi_hyper_t offset = {0,0};
3882 afs_uint32 length = 0;
3883 afs_uint32 rights = 0;
3885 lock_ObtainWrite(&scp->rw);
3886 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3887 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3888 lock_ReleaseWrite(&scp->rw);
3891 * there is at least one dirty extent on this file. queue up background store
3892 * requests for contiguous blocks
3894 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3895 if (ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart == offset.QuadPart + length &&
3896 length + cm_data.buf_blockSize <= cm_chunkSize)
3898 length += cm_data.buf_blockSize;
3900 if (!(offset.QuadPart == 0 && length == 0))
3901 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3902 length, 0, userp, &req);
3903 offset.QuadPart = ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart;
3904 length = cm_data.buf_blockSize;
3907 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3908 length, 0, userp, &req);
3911 cm_ReleaseSCache(scp);
3914 osi_Log5(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
3915 FileId.Cell, FileId.Volume,
3916 FileId.Vnode, FileId.Unique, released);
3917 if (code && code != CM_ERROR_WOULDBLOCK) {
3918 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3919 (*ResultCB)->ResultStatus = status;
3920 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents FAILURE code=0x%x status=0x%x",
3923 (*ResultCB)->ResultStatus = 0;
3924 osi_Log0(afsd_logp, "RDR_ReleaseFileExtents SUCCESS");
3926 (*ResultCB)->ResultBufferLength = 0;
3932 RDR_ProcessReleaseFileExtentsResult( IN AFSReleaseFileExtentsResultCB *ReleaseFileExtentsResultCB,
3933 IN DWORD ResultBufferLength)
3935 afs_uint32 code = 0;
3939 unsigned int fileno, extentno, total_extents = 0;
3940 AFSReleaseFileExtentsResultFileCB *pNextFileCB;
3942 #ifdef VALIDATE_CHECK_SUM
3943 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3949 for ( fileno = 0, pNextFileCB = &ReleaseFileExtentsResultCB->Files[0];
3950 fileno < ReleaseFileExtentsResultCB->FileCount;
3952 AFSReleaseFileExtentsResultFileCB *pFileCB = pNextFileCB;
3953 cm_user_t *userp = NULL;
3955 cm_scache_t * scp = NULL;
3961 userp = RDR_UserFromAuthGroup( &pFileCB->AuthGroup);
3963 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult %d.%d.%d.%d",
3964 pFileCB->FileId.Cell, pFileCB->FileId.Volume,
3965 pFileCB->FileId.Vnode, pFileCB->FileId.Unique);
3967 /* Process the release */
3968 Fid.cell = pFileCB->FileId.Cell;
3969 Fid.volume = pFileCB->FileId.Volume;
3970 Fid.vnode = pFileCB->FileId.Vnode;
3971 Fid.unique = pFileCB->FileId.Unique;
3972 Fid.hash = pFileCB->FileId.Hash;
3974 if (Fid.cell == 0) {
3975 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult Invalid FID %d.%d.%d.%d",
3976 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
3977 code = CM_ERROR_INVAL;
3981 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
3983 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult cm_GetSCache FID failure code=0x%x",
3986 * A failure to find the cm_scache object cannot prevent the service
3987 * from accepting the extents back from the redirector.
3991 deleted = scp && (scp->flags & CM_SCACHEFLAG_DELETED);
3993 /* if the scp was not found, do not perform the length check */
3994 if (scp && (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart)) {
3997 memset(&setAttr, 0, sizeof(cm_attr_t));
3998 lock_ObtainWrite(&scp->rw);
3999 if (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart) {
4000 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult length change vol 0x%x vno 0x%x length 0x%x:%x",
4001 scp->fid.volume, scp->fid.vnode,
4002 pFileCB->AllocationSize.HighPart,
4003 pFileCB->AllocationSize.LowPart);
4004 setAttr.mask |= CM_ATTRMASK_LENGTH;
4005 setAttr.length.LowPart = pFileCB->AllocationSize.LowPart;
4006 setAttr.length.HighPart = pFileCB->AllocationSize.HighPart;
4008 lock_ReleaseWrite(&scp->rw);
4010 code = cm_SetAttr(scp, &setAttr, userp, &req);
4013 for ( extentno = 0; extentno < pFileCB->ExtentCount; total_extents++, extentno++ ) {
4014 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4016 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4018 bufp = buf_Find(&Fid, &thyper);
4020 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4021 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
4022 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4023 Fid.volume, Fid.vnode,
4024 pExtent->FileOffset.HighPart,
4025 pExtent->FileOffset.LowPart);
4026 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
4027 pExtent->CacheOffset.HighPart,
4028 pExtent->CacheOffset.LowPart);
4030 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4031 Fid.volume, Fid.vnode,
4032 pExtent->FileOffset.HighPart,
4033 pExtent->FileOffset.LowPart);
4034 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
4035 pExtent->CacheOffset.HighPart,
4036 pExtent->CacheOffset.LowPart);
4042 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
4043 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4044 Fid.volume, Fid.vnode,
4045 pExtent->FileOffset.HighPart,
4046 pExtent->FileOffset.LowPart);
4047 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
4048 pExtent->CacheOffset.HighPart,
4049 pExtent->CacheOffset.LowPart);
4051 /* Move the buffer to the front of the queue */
4052 lock_ObtainWrite(&buf_globalLock);
4053 buf_MoveToHeadOfRedirQueue(scp, bufp);
4054 lock_ReleaseWrite(&buf_globalLock);
4059 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
4060 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
4061 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4062 Fid.volume, Fid.vnode,
4063 pExtent->FileOffset.HighPart,
4064 pExtent->FileOffset.LowPart);
4065 osi_Log2(afsd_logp, "... coffset 0x%x:%x not held by file system",
4066 pExtent->CacheOffset.HighPart,
4067 pExtent->CacheOffset.LowPart);
4069 snprintf(dbgstr, 1024,
4070 "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",
4071 ReleaseFileExtentsResultCB->Flags, pExtent->Flags,
4072 Fid.volume, Fid.vnode, Fid.unique,
4073 pExtent->FileOffset.HighPart,
4074 pExtent->FileOffset.LowPart,
4075 pExtent->CacheOffset.HighPart,
4076 pExtent->CacheOffset.LowPart);
4077 OutputDebugStringA( dbgstr);
4080 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4081 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4082 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4084 if (pExtent->Flags || ReleaseFileExtentsResultCB->Flags) {
4085 lock_ObtainMutex(&bufp->mx);
4086 if ( (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
4087 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
4089 if (bufp->qFlags & CM_BUF_QREDIR) {
4090 lock_ObtainWrite(&buf_globalLock);
4091 if (bufp->qFlags & CM_BUF_QREDIR) {
4092 buf_RemoveFromRedirQueue(scp, bufp);
4093 buf_ReleaseLocked(bufp, TRUE);
4095 lock_ReleaseWrite(&buf_globalLock);
4099 snprintf(dbgstr, 1024,
4100 "RDR_ProcessReleaseFileExtentsResult extent released: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4101 Fid.volume, Fid.vnode, Fid.unique,
4102 pExtent->FileOffset.HighPart,
4103 pExtent->FileOffset.LowPart,
4104 pExtent->CacheOffset.HighPart,
4105 pExtent->CacheOffset.LowPart);
4106 OutputDebugStringA( dbgstr);
4111 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
4112 Fid.volume, Fid.vnode,
4113 pExtent->FileOffset.HighPart,
4114 pExtent->FileOffset.LowPart);
4115 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4116 pExtent->CacheOffset.HighPart,
4117 pExtent->CacheOffset.LowPart);
4119 snprintf(dbgstr, 1024,
4120 "RDR_ProcessReleaseFileExtentsResult not released! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4121 Fid.volume, Fid.vnode, Fid.unique,
4122 pExtent->FileOffset.HighPart,
4123 pExtent->FileOffset.LowPart,
4124 pExtent->CacheOffset.HighPart,
4125 pExtent->CacheOffset.LowPart);
4126 OutputDebugStringA( dbgstr);
4130 if ((ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
4131 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY))
4133 #ifdef VALIDATE_CHECK_SUM
4134 if ( buf_ValidateCheckSum(bufp) ) {
4136 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4137 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4138 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
4140 buf_ComputeCheckSum(bufp);
4142 HexCheckSum(md5dbg3, sizeof(md5dbg), bufp->md5cksum);
4144 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4146 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
4149 snprintf(dbgstr, 1024,
4150 "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",
4152 Fid.volume, Fid.vnode, Fid.unique,
4153 pExtent->FileOffset.HighPart,
4154 pExtent->FileOffset.LowPart,
4155 pExtent->CacheOffset.HighPart,
4156 pExtent->CacheOffset.LowPart);
4157 OutputDebugStringA( dbgstr);
4160 "RDR_ProcessReleaseFileExtentsResult dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
4161 Fid.volume, Fid.vnode,
4162 pExtent->FileOffset.HighPart,
4163 pExtent->FileOffset.LowPart);
4165 "... coffset 0x%x:%x",
4166 pExtent->CacheOffset.HighPart,
4167 pExtent->CacheOffset.LowPart);
4170 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4175 snprintf(dbgstr, 1024,
4176 "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",
4177 md5dbg, md5dbg2, md5dbg3,
4178 Fid.volume, Fid.vnode, Fid.unique,
4179 pExtent->FileOffset.HighPart,
4180 pExtent->FileOffset.LowPart,
4181 pExtent->CacheOffset.HighPart,
4182 pExtent->CacheOffset.LowPart);
4183 OutputDebugStringA( dbgstr);
4186 "RDR_ProcessReleaseFileExtentsResult dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
4187 Fid.volume, Fid.vnode,
4188 pExtent->FileOffset.HighPart,
4189 pExtent->FileOffset.LowPart);
4191 "... coffset 0x%x:%x",
4192 pExtent->CacheOffset.HighPart,
4193 pExtent->CacheOffset.LowPart);
4197 #else /* !VALIDATE_CHECK_SUM */
4199 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4203 snprintf(dbgstr, 1024,
4204 "RDR_ProcessReleaseFileExtentsResult dirty! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4205 Fid.volume, Fid.vnode, Fid.unique,
4206 pExtent->FileOffset.HighPart,
4207 pExtent->FileOffset.LowPart,
4208 pExtent->CacheOffset.HighPart,
4209 pExtent->CacheOffset.LowPart);
4210 OutputDebugStringA( dbgstr);
4212 #endif /* VALIDATE_CHECK_SUM */
4214 #ifdef VALIDATE_CHECK_SUM
4217 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4219 if (!buf_ValidateCheckSum(bufp) ) {
4220 buf_ComputeCheckSum(bufp);
4222 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4223 snprintf(dbgstr, 1024,
4224 "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",
4226 Fid.volume, Fid.vnode, Fid.unique,
4227 pExtent->FileOffset.HighPart,
4228 pExtent->FileOffset.LowPart,
4229 pExtent->CacheOffset.HighPart,
4230 pExtent->CacheOffset.LowPart);
4231 OutputDebugStringA( dbgstr);
4233 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult dirty flag NOT set but extent has changed! vol 0x%x vno 0x%x foffset 0x%x:%x",
4234 Fid.volume, Fid.vnode,
4235 pExtent->FileOffset.HighPart,
4236 pExtent->FileOffset.LowPart);
4237 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4238 pExtent->CacheOffset.HighPart,
4239 pExtent->CacheOffset.LowPart);
4244 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4248 buf_ComputeCheckSum(bufp);
4250 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4251 snprintf(dbgstr, 1024,
4252 "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",
4254 Fid.volume, Fid.vnode, Fid.unique,
4255 pExtent->FileOffset.HighPart,
4256 pExtent->FileOffset.LowPart,
4257 pExtent->CacheOffset.HighPart,
4258 pExtent->CacheOffset.LowPart);
4259 OutputDebugStringA( dbgstr);
4263 #endif /* VALIDATE_CHECK_SUM */
4264 lock_ReleaseMutex(&bufp->mx);
4268 /* CacheOffset doesn't match bufp->datap */
4269 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
4272 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
4273 if (wbp->datap == datap)
4278 snprintf(dbgstr, 1024,
4279 "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",
4280 Fid.volume, Fid.vnode, Fid.unique,
4281 pExtent->FileOffset.HighPart,
4282 pExtent->FileOffset.LowPart,
4283 pExtent->CacheOffset.HighPart,
4284 pExtent->CacheOffset.LowPart,
4286 OutputDebugStringA( dbgstr);
4288 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4289 Fid.volume, Fid.vnode,
4290 pExtent->FileOffset.HighPart,
4291 pExtent->FileOffset.LowPart);
4292 osi_Log3(afsd_logp, "... coffset 0x%x:%x flags 0x%x",
4293 pExtent->CacheOffset.HighPart,
4294 pExtent->CacheOffset.LowPart,
4297 osi_Log5(afsd_logp, "... coffset belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
4298 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
4300 osi_Log0(afsd_logp, "... coffset cannot be found");
4307 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4308 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4309 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
4310 pExtent->FileOffset.LowPart);
4311 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; cm_buf not found -- recycled?",
4312 pExtent->CacheOffset.HighPart,
4313 pExtent->CacheOffset.LowPart);
4319 snprintf(dbgstr, 1024,
4320 "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4321 Fid.volume, Fid.vnode, Fid.unique,
4322 pExtent->FileOffset.HighPart,
4323 pExtent->FileOffset.LowPart,
4324 pExtent->CacheOffset.HighPart,
4325 pExtent->CacheOffset.LowPart);
4326 OutputDebugStringA( dbgstr);
4328 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x foffset 0x%x:%x",
4329 Fid.volume, Fid.vnode,
4330 pExtent->FileOffset.HighPart,
4331 pExtent->FileOffset.LowPart);
4332 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4333 pExtent->CacheOffset.HighPart,
4334 pExtent->CacheOffset.LowPart);
4339 osi_hyper_t offset = {0,0};
4340 afs_uint32 length = 0;
4343 * there is at least one dirty extent on this file. queue up background store
4344 * requests for contiguous blocks
4346 for ( extentno = 0; extentno < pFileCB->ExtentCount; extentno++ ) {
4347 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4348 if (pExtent->FileOffset.QuadPart == offset.QuadPart + length &&
4349 length < cm_chunkSize) {
4350 length += cm_data.buf_blockSize;
4352 if (!(offset.QuadPart == 0 && length == 0))
4353 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4354 length, 0, userp, &req);
4355 offset.QuadPart = pExtent->FileOffset.QuadPart;
4356 length = cm_data.buf_blockSize;
4359 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4360 length, 0, userp, &req);
4363 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
4364 Fid.cell, Fid.volume, Fid.vnode, Fid.unique, released);
4368 cm_ReleaseUser(userp);
4370 cm_ReleaseSCache(scp);
4372 p = (char *)pFileCB;
4373 p += sizeof(AFSReleaseFileExtentsResultFileCB);
4374 p += sizeof(AFSFileExtentCB) * (pFileCB->ExtentCount - 1);
4375 pNextFileCB = (AFSReleaseFileExtentsResultFileCB *)p;
4378 if (total_extents == 0) {
4379 osi_Log0(afsd_logp, "RDR_ProcessReleaseFileExtentsResult is empty");
4380 code = CM_ERROR_RETRY;
4384 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult FAILURE code=0x%x", code);
4386 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult DONE code=0x%x", code);
4392 RDR_ReleaseFailedSetFileExtents( IN cm_user_t *userp,
4393 IN AFSSetFileExtentsCB *SetFileExtentsResultCB,
4394 IN DWORD ResultBufferLength)
4396 afs_uint32 code = 0;
4398 unsigned int extentno;
4400 cm_scache_t * scp = NULL;
4405 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFileExtents %d.%d.%d.%d",
4406 SetFileExtentsResultCB->FileId.Cell, SetFileExtentsResultCB->FileId.Volume,
4407 SetFileExtentsResultCB->FileId.Vnode, SetFileExtentsResultCB->FileId.Unique);
4409 /* Process the release */
4410 Fid.cell = SetFileExtentsResultCB->FileId.Cell;
4411 Fid.volume = SetFileExtentsResultCB->FileId.Volume;
4412 Fid.vnode = SetFileExtentsResultCB->FileId.Vnode;
4413 Fid.unique = SetFileExtentsResultCB->FileId.Unique;
4414 Fid.hash = SetFileExtentsResultCB->FileId.Hash;
4416 if (Fid.cell == 0) {
4417 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFile Invalid FID %d.%d.%d.%d",
4418 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
4419 code = CM_ERROR_INVAL;
4423 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
4425 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents cm_GetSCache FID failure code=0x%x",
4427 /* Failure to find the cm_scache object cannot block return of the extents */
4430 for ( extentno = 0; extentno < SetFileExtentsResultCB->ExtentCount; extentno++ ) {
4433 AFSFileExtentCB *pExtent = &SetFileExtentsResultCB->FileExtents[extentno];
4435 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4437 bufp = buf_Find(&Fid, &thyper);
4439 osi_Log5(afsd_logp, "RDR_ReleaseFailedSetFileExtents bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4440 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4441 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4443 lock_ObtainMutex(&bufp->mx);
4444 if (bufp->qFlags & CM_BUF_QREDIR) {
4445 lock_ObtainWrite(&buf_globalLock);
4446 if (bufp->qFlags & CM_BUF_QREDIR) {
4447 buf_RemoveFromRedirQueue(scp, bufp);
4448 buf_ReleaseLocked(bufp, TRUE);
4450 lock_ReleaseWrite(&buf_globalLock);
4452 lock_ReleaseMutex(&bufp->mx);
4459 cm_ReleaseUser(userp);
4461 cm_ReleaseSCache(scp);
4463 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents DONE code=0x%x", code);
4468 RDR_PioctlOpen( IN cm_user_t *userp,
4469 IN AFSFileID ParentId,
4470 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4472 IN DWORD ResultBufferLength,
4473 IN OUT AFSCommResult **ResultCB)
4478 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4484 sizeof( AFSCommResult));
4486 /* Get the active directory */
4487 ParentFid.cell = ParentId.Cell;
4488 ParentFid.volume = ParentId.Volume;
4489 ParentFid.vnode = ParentId.Vnode;
4490 ParentFid.unique = ParentId.Unique;
4491 ParentFid.hash = ParentId.Hash;
4493 /* Get the root directory */
4494 RootFid.cell = pPioctlCB->RootId.Cell;
4495 RootFid.volume = pPioctlCB->RootId.Volume;
4496 RootFid.vnode = pPioctlCB->RootId.Vnode;
4497 RootFid.unique = pPioctlCB->RootId.Unique;
4498 RootFid.hash = pPioctlCB->RootId.Hash;
4500 /* Create the pioctl index */
4501 RDR_SetupIoctl(pPioctlCB->RequestId, &ParentFid, &RootFid, userp);
4508 RDR_PioctlClose( IN cm_user_t *userp,
4509 IN AFSFileID ParentId,
4510 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4512 IN DWORD ResultBufferLength,
4513 IN OUT AFSCommResult **ResultCB)
4515 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4521 sizeof( AFSCommResult));
4523 /* Cleanup the pioctl index */
4524 RDR_CleanupIoctl(pPioctlCB->RequestId);
4531 RDR_PioctlWrite( IN cm_user_t *userp,
4532 IN AFSFileID ParentId,
4533 IN AFSPIOCtlIORequestCB *pPioctlCB,
4535 IN DWORD ResultBufferLength,
4536 IN OUT AFSCommResult **ResultCB)
4538 AFSPIOCtlIOResultCB *pResultCB;
4539 cm_scache_t *dscp = NULL;
4546 req.flags |= CM_REQ_WOW64;
4548 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4554 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4556 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4558 code = RDR_IoctlWrite(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer, &req);
4560 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4561 (*ResultCB)->ResultStatus = status;
4565 pResultCB->BytesProcessed = pPioctlCB->BufferLength;
4566 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4570 RDR_PioctlRead( IN cm_user_t *userp,
4571 IN AFSFileID ParentId,
4572 IN AFSPIOCtlIORequestCB *pPioctlCB,
4574 IN BOOL bIsLocalSystem,
4575 IN DWORD ResultBufferLength,
4576 IN OUT AFSCommResult **ResultCB)
4578 AFSPIOCtlIOResultCB *pResultCB;
4579 cm_scache_t *dscp = NULL;
4583 afs_uint32 pflags = (bIsLocalSystem ? AFSCALL_FLAG_LOCAL_SYSTEM : 0);
4587 req.flags |= CM_REQ_WOW64;
4589 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4595 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4597 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4599 code = RDR_IoctlRead(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer,
4600 &pResultCB->BytesProcessed, &req, pflags);
4602 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4603 (*ResultCB)->ResultStatus = status;
4607 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4611 RDR_ByteRangeLockSync( IN cm_user_t *userp,
4612 IN AFSFileID FileId,
4613 IN AFSByteRangeLockRequestCB *pBRLRequestCB,
4615 IN DWORD ResultBufferLength,
4616 IN OUT AFSCommResult **ResultCB)
4618 AFSByteRangeLockResultCB *pResultCB = NULL;
4619 LARGE_INTEGER ProcessId;
4621 cm_scache_t *scp = NULL;
4629 ProcessId.QuadPart = pBRLRequestCB->ProcessId;
4633 req.flags |= CM_REQ_WOW64;
4635 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4636 FileId.Cell, FileId.Volume,
4637 FileId.Vnode, FileId.Unique);
4638 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4639 ProcessId.HighPart, ProcessId.LowPart);
4641 Length = sizeof( AFSByteRangeLockResultCB) + ((pBRLRequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4642 if (Length > ResultBufferLength) {
4643 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4646 memset( *ResultCB, 0, sizeof(AFSCommResult));
4647 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4651 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4654 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4655 (*ResultCB)->ResultBufferLength = Length;
4657 pResultCB = (AFSByteRangeLockResultCB *)(*ResultCB)->ResultData;
4658 pResultCB->FileId = FileId;
4659 pResultCB->Count = pBRLRequestCB->Count;
4661 /* Allocate the extents from the buffer package */
4662 Fid.cell = FileId.Cell;
4663 Fid.volume = FileId.Volume;
4664 Fid.vnode = FileId.Vnode;
4665 Fid.unique = FileId.Unique;
4666 Fid.hash = FileId.Hash;
4668 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
4670 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4671 (*ResultCB)->ResultStatus = status;
4672 (*ResultCB)->ResultBufferLength = 0;
4673 osi_Log2(afsd_logp, "RDR_ByteRangeLockSync cm_GetSCache FID failure code=0x%x status=0x%x",
4678 lock_ObtainWrite(&scp->rw);
4680 /* start by looking up the file's end */
4681 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4682 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4684 lock_ReleaseWrite(&scp->rw);
4685 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4686 (*ResultCB)->ResultStatus = status;
4687 (*ResultCB)->ResultBufferLength = 0;
4688 osi_Log3(afsd_logp, "RDR_ByteRangeLockSync cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4693 /* the scp is now locked and current */
4694 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4696 for ( i=0; i<pBRLRequestCB->Count; i++ ) {
4697 pResultCB->Result[i].LockType = pBRLRequestCB->Request[i].LockType;
4698 pResultCB->Result[i].Offset = pBRLRequestCB->Request[i].Offset;
4699 pResultCB->Result[i].Length = pBRLRequestCB->Request[i].Length;
4702 pBRLRequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4703 pBRLRequestCB->Request[i].Offset,
4704 pBRLRequestCB->Request[i].Length,
4705 key, 0, userp, &req, NULL);
4708 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4710 pBRLRequestCB->Request[i].LockType,
4711 pBRLRequestCB->Request[i].Offset.HighPart,
4712 pBRLRequestCB->Request[i].Offset.LowPart);
4713 osi_Log2(afsd_logp, "... length 0x%x:%x",
4714 pBRLRequestCB->Request[i].Length.HighPart,
4715 pBRLRequestCB->Request[i].Length.LowPart);
4720 pResultCB->Result[i].Status = 0;
4722 case CM_ERROR_WOULDBLOCK:
4723 pResultCB->Result[i].Status = STATUS_FILE_LOCK_CONFLICT;
4726 pResultCB->Result[i].Status = STATUS_LOCK_NOT_GRANTED;
4730 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4731 lock_ReleaseWrite(&scp->rw);
4732 cm_ReleaseSCache(scp);
4734 (*ResultCB)->ResultStatus = 0;
4735 osi_Log0(afsd_logp, "RDR_ByteRangeLockSync SUCCESS");
4740 RDR_ByteRangeUnlock( IN cm_user_t *userp,
4741 IN AFSFileID FileId,
4742 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4744 IN DWORD ResultBufferLength,
4745 IN OUT AFSCommResult **ResultCB)
4747 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4748 LARGE_INTEGER ProcessId;
4750 cm_scache_t *scp = NULL;
4758 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4762 req.flags |= CM_REQ_WOW64;
4764 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4765 FileId.Cell, FileId.Volume,
4766 FileId.Vnode, FileId.Unique);
4767 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4768 ProcessId.HighPart, ProcessId.LowPart);
4770 Length = sizeof( AFSByteRangeUnlockResultCB) + ((pBRURequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4771 if (Length > ResultBufferLength) {
4772 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4775 memset( *ResultCB, 0, sizeof(AFSCommResult));
4776 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4780 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4783 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4784 (*ResultCB)->ResultBufferLength = Length;
4786 pResultCB = (AFSByteRangeUnlockResultCB *)(*ResultCB)->ResultData;
4787 pResultCB->Count = pBRURequestCB->Count;
4789 /* Allocate the extents from the buffer package */
4790 Fid.cell = FileId.Cell;
4791 Fid.volume = FileId.Volume;
4792 Fid.vnode = FileId.Vnode;
4793 Fid.unique = FileId.Unique;
4794 Fid.hash = FileId.Hash;
4796 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
4798 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4799 (*ResultCB)->ResultStatus = status;
4800 (*ResultCB)->ResultBufferLength = 0;
4801 osi_Log2(afsd_logp, "RDR_ByteRangeUnlock cm_GetSCache FID failure code=0x%x status=0x%x",
4806 lock_ObtainWrite(&scp->rw);
4808 /* start by looking up the file's end */
4809 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4810 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4812 lock_ReleaseWrite(&scp->rw);
4813 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4814 (*ResultCB)->ResultStatus = status;
4815 (*ResultCB)->ResultBufferLength = 0;
4816 osi_Log3(afsd_logp, "RDR_ByteRangeUnlock cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4821 /* the scp is now locked and current */
4822 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4824 for ( i=0; i<pBRURequestCB->Count; i++ ) {
4825 pResultCB->Result[i].LockType = pBRURequestCB->Request[i].LockType;
4826 pResultCB->Result[i].Offset = pBRURequestCB->Request[i].Offset;
4827 pResultCB->Result[i].Length = pBRURequestCB->Request[i].Length;
4829 code = cm_Unlock(scp,
4830 pBRURequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4831 pBRURequestCB->Request[i].Offset,
4832 pBRURequestCB->Request[i].Length,
4833 key, CM_UNLOCK_FLAG_MATCH_RANGE, userp, &req);
4836 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4837 code, pBRURequestCB->Request[i].LockType,
4838 pBRURequestCB->Request[i].Offset.HighPart,
4839 pBRURequestCB->Request[i].Offset.LowPart);
4840 osi_Log2(afsd_logp, "... length 0x%x:%x",
4841 pBRURequestCB->Request[i].Length.HighPart,
4842 pBRURequestCB->Request[i].Length.LowPart);
4844 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4845 pResultCB->Result[i].Status = status;
4848 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4849 lock_ReleaseWrite(&scp->rw);
4850 cm_ReleaseSCache(scp);
4852 (*ResultCB)->ResultStatus = 0;
4853 osi_Log0(afsd_logp, "RDR_ByteRangeUnlock SUCCESS");
4858 RDR_ByteRangeUnlockAll( IN cm_user_t *userp,
4859 IN AFSFileID FileId,
4860 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4862 IN DWORD ResultBufferLength,
4863 IN OUT AFSCommResult **ResultCB)
4865 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4866 LARGE_INTEGER ProcessId;
4867 cm_scache_t *scp = NULL;
4874 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4878 req.flags |= CM_REQ_WOW64;
4880 osi_Log4(afsd_logp, "RDR_ByteRangeUnlockAll File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4881 FileId.Cell, FileId.Volume,
4882 FileId.Vnode, FileId.Unique);
4883 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4884 ProcessId.HighPart, ProcessId.LowPart);
4886 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4889 memset( *ResultCB, '\0', sizeof( AFSCommResult));
4890 (*ResultCB)->ResultBufferLength = 0;
4892 /* Allocate the extents from the buffer package */
4893 Fid.cell = FileId.Cell;
4894 Fid.volume = FileId.Volume;
4895 Fid.vnode = FileId.Vnode;
4896 Fid.unique = FileId.Unique;
4897 Fid.hash = FileId.Hash;
4899 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
4901 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4902 (*ResultCB)->ResultStatus = status;
4903 (*ResultCB)->ResultBufferLength = 0;
4904 osi_Log2(afsd_logp, "RDR_ByteRangeUnlockAll cm_GetSCache FID failure code=0x%x status=0x%x",
4909 lock_ObtainWrite(&scp->rw);
4911 /* start by looking up the file's end */
4912 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4913 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4915 lock_ReleaseWrite(&scp->rw);
4916 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4917 (*ResultCB)->ResultStatus = status;
4918 (*ResultCB)->ResultBufferLength = 0;
4919 osi_Log3(afsd_logp, "RDR_ByteRangeUnlockAll cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4924 /* the scp is now locked and current */
4925 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4927 code = cm_UnlockByKey(scp, key, 0, userp, &req);
4929 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4930 lock_ReleaseWrite(&scp->rw);
4931 cm_ReleaseSCache(scp);
4933 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4934 (*ResultCB)->ResultStatus = status;
4937 osi_Log1(afsd_logp, "RDR_ByteRangeUnlockAll FAILURE code 0x%x", code);
4939 osi_Log0(afsd_logp, "RDR_ByteRangeUnlockAll SUCCESS");
4945 RDR_GetVolumeInfo( IN cm_user_t *userp,
4946 IN AFSFileID FileId,
4948 IN DWORD ResultBufferLength,
4949 IN OUT AFSCommResult **ResultCB)
4951 AFSVolumeInfoCB *pResultCB = NULL;
4953 cm_scache_t *scp = NULL;
4954 cm_volume_t *volp = NULL;
4955 cm_vol_state_t *volstatep = NULL;
4957 cm_cell_t *cellp = NULL;
4962 FILETIME ft = {0x832cf000, 0x01abfcc4}; /* October 1, 1982 00:00:00 +0600 */
4964 char volName[32]="(unknown)";
4965 char offLineMsg[256]="server temporarily inaccessible";
4966 char motd[256]="server temporarily inaccessible";
4968 AFSFetchVolumeStatus volStat;
4972 struct rx_connection * rxconnp;
4976 req.flags |= CM_REQ_WOW64;
4978 osi_Log4(afsd_logp, "RDR_GetVolumeInfo File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4979 FileId.Cell, FileId.Volume,
4980 FileId.Vnode, FileId.Unique);
4982 Length = sizeof( AFSCommResult) + sizeof(AFSVolumeInfoCB);
4983 if (sizeof(AFSVolumeInfoCB) > ResultBufferLength) {
4984 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
4987 memset( *ResultCB, 0, sizeof(AFSCommResult));
4988 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4992 *ResultCB = (AFSCommResult *)malloc( Length );
4995 memset( *ResultCB, '\0', Length );
4996 (*ResultCB)->ResultBufferLength = sizeof(AFSVolumeInfoCB);
4997 pResultCB = (AFSVolumeInfoCB *)(*ResultCB)->ResultData;
4999 if (FileId.Cell != 0) {
5000 cm_SetFid(&Fid, FileId.Cell, FileId.Volume, 1, 1);
5001 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
5003 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5004 (*ResultCB)->ResultStatus = status;
5005 (*ResultCB)->ResultBufferLength = 0;
5006 osi_Log2(afsd_logp, "RDR_GetVolumeInfo cm_GetSCache FID failure code=0x%x status=0x%x",
5011 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
5012 osi_Log0(afsd_logp, "RDR_GetVolumeInfo Object Name Invalid - Cell = 0");
5015 lock_ObtainWrite(&scp->rw);
5017 code = cm_SyncOp(scp, NULL, userp, &req, 0,
5018 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5020 lock_ReleaseWrite(&scp->rw);
5021 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5022 (*ResultCB)->ResultStatus = status;
5023 (*ResultCB)->ResultBufferLength = 0;
5024 osi_Log3(afsd_logp, "RDR_GetVolumeInfo cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
5029 pResultCB->SectorsPerAllocationUnit = 1;
5030 pResultCB->BytesPerSector = 1024;
5032 pResultCB->CellID = scp->fid.cell;
5033 pResultCB->VolumeID = scp->fid.volume;
5034 pResultCB->Characteristics = FILE_REMOTE_DEVICE;
5035 pResultCB->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK |
5036 FILE_SUPPORTS_REPARSE_POINTS;
5038 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
5039 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)
5041 pResultCB->TotalAllocationUnits.QuadPart = 100;
5042 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
5044 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5045 pResultCB->Characteristics |= FILE_READ_ONLY_DEVICE;
5047 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( "Freelance.Local.Root", -1, pResultCB->VolumeLabel,
5048 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5049 if ( pResultCB->VolumeLabelLength )
5050 pResultCB->VolumeLabelLength--;
5052 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
5054 volp = cm_GetVolumeByFID(&scp->fid);
5056 code = CM_ERROR_NOSUCHVOLUME;
5059 volstatep = cm_VolumeStateByID(volp, scp->fid.volume);
5060 volType = cm_VolumeType(volp, scp->fid.volume);
5062 pResultCB->Characteristics |= ((volType == ROVOL || volType == BACKVOL) ? FILE_READ_ONLY_DEVICE : 0);
5065 OfflineMsg = offLineMsg;
5067 lock_ReleaseWrite(&scp->rw);
5069 code = cm_ConnFromFID(&scp->fid, userp, &req, &connp);
5072 rxconnp = cm_GetRxConn(connp);
5073 code = RXAFS_GetVolumeStatus(rxconnp, scp->fid.volume,
5074 &volStat, &Name, &OfflineMsg, &MOTD);
5075 rx_PutConnection(rxconnp);
5077 } while (cm_Analyze(connp, userp, &req, &scp->fid, 0, NULL, NULL, NULL, code));
5078 code = cm_MapRPCError(code, &req);
5080 if (volStat.MaxQuota)
5082 pResultCB->TotalAllocationUnits.QuadPart = volStat.MaxQuota;
5083 if (volType == ROVOL || volType == BACKVOL) {
5084 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5088 pResultCB->AvailableAllocationUnits.QuadPart =
5089 min(volStat.MaxQuota - volStat.BlocksInUse, volStat.PartBlocksAvail);
5094 pResultCB->TotalAllocationUnits.QuadPart = volStat.PartMaxBlocks;
5095 if (volType == ROVOL || volType == BACKVOL) {
5096 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5100 pResultCB->AvailableAllocationUnits.QuadPart = volStat.PartBlocksAvail;
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_GetVolumeSizeInfo( IN cm_user_t *userp,
5134 IN AFSFileID FileId,
5136 IN DWORD ResultBufferLength,
5137 IN OUT AFSCommResult **ResultCB)
5139 AFSVolumeSizeInfoCB *pResultCB = NULL;
5141 cm_scache_t *scp = NULL;
5142 cm_volume_t *volp = NULL;
5144 cm_cell_t *cellp = NULL;
5150 char volName[32]="(unknown)";
5151 char offLineMsg[256]="server temporarily inaccessible";
5152 char motd[256]="server temporarily inaccessible";
5154 AFSFetchVolumeStatus volStat;
5158 struct rx_connection * rxconnp;
5162 req.flags |= CM_REQ_WOW64;
5164 osi_Log4(afsd_logp, "RDR_GetVolumeSizeInfo File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5165 FileId.Cell, FileId.Volume,
5166 FileId.Vnode, FileId.Unique);
5168 Length = sizeof( AFSCommResult) + sizeof(AFSVolumeSizeInfoCB);
5169 if (sizeof(AFSVolumeSizeInfoCB) > ResultBufferLength) {
5170 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5173 memset( *ResultCB, 0, sizeof(AFSCommResult));
5174 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5178 *ResultCB = (AFSCommResult *)malloc( Length );
5181 memset( *ResultCB, '\0', Length );
5182 (*ResultCB)->ResultBufferLength = sizeof(AFSVolumeSizeInfoCB);
5183 pResultCB = (AFSVolumeSizeInfoCB *)(*ResultCB)->ResultData;
5185 if (FileId.Cell != 0) {
5186 cm_SetFid(&Fid, FileId.Cell, FileId.Volume, 1, 1);
5187 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
5189 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5190 (*ResultCB)->ResultStatus = status;
5191 (*ResultCB)->ResultBufferLength = 0;
5192 osi_Log2(afsd_logp, "RDR_GetVolumeSizeInfo cm_GetSCache FID failure code=0x%x status=0x%x",
5197 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
5198 osi_Log0(afsd_logp, "RDR_GetVolumeSizeInfo Object Name Invalid - Cell = 0");
5201 lock_ObtainWrite(&scp->rw);
5203 code = cm_SyncOp(scp, NULL, userp, &req, 0,
5204 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5206 lock_ReleaseWrite(&scp->rw);
5207 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5208 (*ResultCB)->ResultStatus = status;
5209 (*ResultCB)->ResultBufferLength = 0;
5210 osi_Log3(afsd_logp, "RDR_GetVolumeSizeInfo cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
5215 pResultCB->SectorsPerAllocationUnit = 1;
5216 pResultCB->BytesPerSector = 1024;
5218 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
5219 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)
5221 pResultCB->TotalAllocationUnits.QuadPart = 100;
5222 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5224 volp = cm_GetVolumeByFID(&scp->fid);
5226 code = CM_ERROR_NOSUCHVOLUME;
5230 volType = cm_VolumeType(volp, scp->fid.volume);
5232 OfflineMsg = offLineMsg;
5234 lock_ReleaseWrite(&scp->rw);
5236 code = cm_ConnFromFID(&scp->fid, userp, &req, &connp);
5239 rxconnp = cm_GetRxConn(connp);
5240 code = RXAFS_GetVolumeStatus(rxconnp, scp->fid.volume,
5241 &volStat, &Name, &OfflineMsg, &MOTD);
5242 rx_PutConnection(rxconnp);
5244 } while (cm_Analyze(connp, userp, &req, &scp->fid, 0, NULL, NULL, NULL, code));
5245 code = cm_MapRPCError(code, &req);
5247 if (volStat.MaxQuota)
5249 pResultCB->TotalAllocationUnits.QuadPart = volStat.MaxQuota;
5250 if (volType == ROVOL || volType == BACKVOL) {
5251 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5255 pResultCB->AvailableAllocationUnits.QuadPart =
5256 min(volStat.MaxQuota - volStat.BlocksInUse, volStat.PartBlocksAvail);
5261 pResultCB->TotalAllocationUnits.QuadPart = volStat.PartMaxBlocks;
5262 if (volType == ROVOL || volType == BACKVOL) {
5263 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5267 pResultCB->AvailableAllocationUnits.QuadPart = volStat.PartBlocksAvail;
5272 pResultCB->TotalAllocationUnits.QuadPart = 0x7FFFFFFF;
5273 pResultCB->AvailableAllocationUnits.QuadPart = (volType == ROVOL || volType == BACKVOL) ? 0 : 0x3F000000;
5276 lock_ObtainWrite(&scp->rw);
5279 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5282 lock_ReleaseWrite(&scp->rw);
5285 cm_ReleaseSCache(scp);
5287 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5288 (*ResultCB)->ResultStatus = status;
5289 osi_Log0(afsd_logp, "RDR_GetVolumeSizeInfo SUCCESS");
5294 RDR_HoldFid( IN cm_user_t *userp,
5295 IN AFSHoldFidRequestCB * pHoldFidCB,
5297 IN DWORD ResultBufferLength,
5298 IN OUT AFSCommResult **ResultCB)
5300 AFSHoldFidResultCB *pResultCB = NULL;
5307 osi_Log1(afsd_logp, "RDR_HoldFid Count=%u", pHoldFidCB->Count);
5309 Length = sizeof(AFSHoldFidResultCB) + (pHoldFidCB->Count-1) * sizeof(AFSFidResult);
5310 if (Length > ResultBufferLength) {
5311 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5314 memset( *ResultCB, 0, sizeof(AFSCommResult));
5315 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5318 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5321 memset( *ResultCB, '\0', Length );
5322 (*ResultCB)->ResultBufferLength = Length;
5323 pResultCB = (AFSHoldFidResultCB *)(*ResultCB)->ResultData;
5325 for ( index = 0; index < pHoldFidCB->Count; index++ )
5327 cm_scache_t *scp = NULL;
5330 Fid.cell = pResultCB->Result[index].FileID.Cell = pHoldFidCB->FileID[index].Cell;
5331 Fid.volume = pResultCB->Result[index].FileID.Volume = pHoldFidCB->FileID[index].Volume;
5332 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pHoldFidCB->FileID[index].Vnode;
5333 Fid.unique = pResultCB->Result[index].FileID.Unique = pHoldFidCB->FileID[index].Unique;
5334 Fid.hash = pResultCB->Result[index].FileID.Hash = pHoldFidCB->FileID[index].Hash;
5336 osi_Log4( afsd_logp,
5337 "RDR_HoldFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5338 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5340 scp = cm_FindSCache(&Fid);
5342 RDR_FlagScpInUse( scp, FALSE );
5343 cm_ReleaseSCache(scp);
5345 pResultCB->Result[index].Status = 0;
5348 (*ResultCB)->ResultStatus = 0;
5349 osi_Log0(afsd_logp, "RDR_HoldFid SUCCESS");
5354 RDR_ReleaseFid( IN cm_user_t *userp,
5355 IN AFSReleaseFidRequestCB * pReleaseFidCB,
5357 IN DWORD ResultBufferLength,
5358 IN OUT AFSCommResult **ResultCB)
5360 AFSReleaseFidResultCB *pResultCB = NULL;
5367 osi_Log1(afsd_logp, "RDR_ReleaseFid Count=%u", pReleaseFidCB->Count);
5369 Length = sizeof(AFSReleaseFidResultCB) + (pReleaseFidCB->Count ? pReleaseFidCB->Count-1 : 0) * sizeof(AFSFidResult);
5370 if (Length > ResultBufferLength) {
5371 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5374 memset( *ResultCB, 0, sizeof(AFSCommResult));
5375 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5378 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5381 memset( *ResultCB, '\0', Length );
5382 (*ResultCB)->ResultBufferLength = Length;
5383 pResultCB = (AFSReleaseFidResultCB *)(*ResultCB)->ResultData;
5385 for ( index = 0; index < pReleaseFidCB->Count; index++ )
5387 cm_scache_t *scp = NULL;
5390 Fid.cell = pResultCB->Result[index].FileID.Cell = pReleaseFidCB->FileID[index].Cell;
5391 Fid.volume = pResultCB->Result[index].FileID.Volume = pReleaseFidCB->FileID[index].Volume;
5392 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pReleaseFidCB->FileID[index].Vnode;
5393 Fid.unique = pResultCB->Result[index].FileID.Unique = pReleaseFidCB->FileID[index].Unique;
5394 Fid.hash = pResultCB->Result[index].FileID.Hash = pReleaseFidCB->FileID[index].Hash;
5396 osi_Log4( afsd_logp,
5397 "RDR_ReleaseFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5398 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5400 scp = cm_FindSCache(&Fid);
5402 lock_ObtainWrite(&scp->rw);
5403 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
5404 lock_ReleaseWrite(&scp->rw);
5406 cm_ReleaseSCache(scp);
5408 pResultCB->Result[index].Status = 0;
5410 pResultCB->Count = pReleaseFidCB->Count;
5412 (*ResultCB)->ResultStatus = 0;
5413 osi_Log0(afsd_logp, "RDR_ReleaseFid SUCCESS");
5418 * The redirector makes several assumptions regarding the
5419 * SRVSVC and WKSSVC pipes transactions. First, the interface
5420 * versions are those indicated below. Secondly, the encoding
5421 * will be performed using NDR version 2. These assumptions
5422 * may not hold in the future and end-to-end MSRPC Bind
5423 * negotiations may need to be supported. Of course, these
5424 * are the only interface versions that are supported by the
5427 #define MSRPC_PIPE_PREFIX L".\\"
5429 static const UUID MSRPC_SRVSVC_UUID = {0x4B324FC8, 0x1670, 0x01D3,
5430 {0x12, 0x78, 0x5A, 0x47, 0xBF, 0x6E, 0xE1, 0x88}};
5431 #define MSRPC_SRVSVC_NAME L"PIPE\\SRVSVC"
5432 #define MSRPC_SRVSVC_VERS 3
5434 static const UUID MSRPC_WKSSVC_UUID = {0x6BFFD098, 0xA112, 0x3610,
5435 {0x98, 0x33, 0x46, 0xC3, 0xF8, 0x7E, 0x34, 0x5A}};
5436 #define MSRPC_WKSSVC_NAME L"PIPE\\WKSSVC"
5437 #define MSRPC_WKSSVC_VERS 1
5439 static const UUID MSRPC_NDR_UUID = {0x8A885D04, 0x1CEB, 0x11C9,
5440 {0x9F, 0xE8, 0x08, 0x00, 0x2B, 0x10, 0x48, 0x60}};
5441 #define MSRPC_NDR_NAME L"NDR"
5442 #define MSRPC_NDR_VERS 2
5444 extern RPC_IF_HANDLE srvsvc_v3_0_s_ifspec;
5445 extern RPC_IF_HANDLE wkssvc_v1_0_s_ifspec;
5448 RDR_PipeOpen( IN cm_user_t *userp,
5449 IN AFSFileID ParentId,
5451 IN DWORD NameLength,
5452 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5454 IN DWORD ResultBufferLength,
5455 IN OUT AFSCommResult **ResultCB)
5460 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5466 sizeof( AFSCommResult));
5468 /* Get the active directory */
5469 ParentFid.cell = ParentId.Cell;
5470 ParentFid.volume = ParentId.Volume;
5471 ParentFid.vnode = ParentId.Vnode;
5472 ParentFid.unique = ParentId.Unique;
5473 ParentFid.hash = ParentId.Hash;
5475 /* Get the root directory */
5476 RootFid.cell = pPipe_CB->RootId.Cell;
5477 RootFid.volume = pPipe_CB->RootId.Volume;
5478 RootFid.vnode = pPipe_CB->RootId.Vnode;
5479 RootFid.unique = pPipe_CB->RootId.Unique;
5480 RootFid.hash = pPipe_CB->RootId.Hash;
5482 /* Create the pipe index */
5483 (*ResultCB)->ResultStatus =
5484 RDR_SetupPipe( pPipe_CB->RequestId, &ParentFid, &RootFid,
5485 Name, NameLength, userp);
5491 RDR_PipeClose( IN cm_user_t *userp,
5492 IN AFSFileID ParentId,
5493 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5495 IN DWORD ResultBufferLength,
5496 IN OUT AFSCommResult **ResultCB)
5498 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5504 sizeof( AFSCommResult));
5506 /* Cleanup the pipe index */
5507 RDR_CleanupPipe(pPipe_CB->RequestId);
5514 RDR_PipeWrite( IN cm_user_t *userp,
5515 IN AFSFileID ParentId,
5516 IN AFSPipeIORequestCB *pPipe_CB,
5517 IN BYTE *pPipe_Data,
5519 IN DWORD ResultBufferLength,
5520 IN OUT AFSCommResult **ResultCB)
5522 AFSPipeIOResultCB *pResultCB;
5523 cm_scache_t *dscp = NULL;
5530 req.flags |= CM_REQ_WOW64;
5532 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5538 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5540 pResultCB = (AFSPipeIOResultCB *)(*ResultCB)->ResultData;
5542 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_Data, &req, userp);
5544 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5545 (*ResultCB)->ResultStatus = status;
5549 pResultCB->BytesProcessed = pPipe_CB->BufferLength;
5550 (*ResultCB)->ResultBufferLength = sizeof( AFSPipeIOResultCB);
5555 RDR_PipeRead( IN cm_user_t *userp,
5556 IN AFSFileID ParentId,
5557 IN AFSPipeIORequestCB *pPipe_CB,
5559 IN DWORD ResultBufferLength,
5560 IN OUT AFSCommResult **ResultCB)
5563 cm_scache_t *dscp = NULL;
5570 req.flags |= CM_REQ_WOW64;
5572 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5578 sizeof( AFSCommResult));
5580 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5582 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_Data,
5583 &(*ResultCB)->ResultBufferLength, &req, userp);
5585 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5586 (*ResultCB)->ResultStatus = status;
5593 RDR_PipeSetInfo( IN cm_user_t *userp,
5594 IN AFSFileID ParentId,
5595 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5596 IN BYTE *pPipe_Data,
5598 IN DWORD ResultBufferLength,
5599 IN OUT AFSCommResult **ResultCB)
5601 cm_scache_t *dscp = NULL;
5607 req.flags |= CM_REQ_WOW64;
5609 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5615 sizeof( AFSCommResult));
5617 status = RDR_Pipe_SetInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5618 pPipeInfo_CB->BufferLength, pPipe_Data, &req, userp);
5620 (*ResultCB)->ResultStatus = status;
5625 RDR_PipeQueryInfo( IN cm_user_t *userp,
5626 IN AFSFileID ParentId,
5627 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5629 IN DWORD ResultBufferLength,
5630 IN OUT AFSCommResult **ResultCB)
5633 cm_scache_t *dscp = NULL;
5639 req.flags |= CM_REQ_WOW64;
5641 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5647 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5649 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5651 status = RDR_Pipe_QueryInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5652 ResultBufferLength, pPipe_Data,
5653 &(*ResultCB)->ResultBufferLength, &req, userp);
5655 (*ResultCB)->ResultStatus = status;
5659 RDR_PipeTransceive( IN cm_user_t *userp,
5660 IN AFSFileID ParentId,
5661 IN AFSPipeIORequestCB *pPipe_CB,
5662 IN BYTE *pPipe_InData,
5664 IN DWORD ResultBufferLength,
5665 IN OUT AFSCommResult **ResultCB)
5668 * This function processes a Pipe Service request
5669 * that would normally be sent to a LAN Manager server
5670 * across an authenticated SMB-PIPE/MSRPC/SVC request
5671 * stack. The request is being sent here because the
5672 * application (e.g., Explorer Shell or Common Control File
5673 * dialog) believes that because the UNC path it is
5674 * processing has specified a server name that is not
5675 * "." and that the Server is remote and that the Share
5676 * list cannot be obtained using the Network Provider
5679 * The file system driver is faking the Bind-Ack response
5680 * to the MSRPC Bind request but cannot decode the NDR
5681 * encoded Pipe Service requests. For that we will use
5682 * the service's MSRPC module. However, unlike the SMB
5683 * server usage we must fake the MSRPC Bind exchange and
5684 * map the PipeName to an interface instead of using the
5685 * GUID specified in the MSRPC Bind request.
5687 * None of the requests that are being processed by the
5688 * service require authentication. As a result the userp
5689 * parameter will be ignored.
5691 * Although there are dozens of Pipe Services, the only
5692 * ones that we are implementing are WKSSVC and SRVSVC.
5693 * These support NetShareEnum, NetShareGetInfo,
5694 * NetServerGetInfo, and NetWorkstaGetInfo which are
5695 * commonly queried by NET VIEW, the Explorer Shell,
5696 * and the Common Control File dialog.
5698 BYTE *pPipe_OutData;
5699 cm_scache_t *dscp = NULL;
5703 DWORD Length = ResultBufferLength + sizeof( AFSCommResult);
5707 req.flags |= CM_REQ_WOW64;
5709 *ResultCB = (AFSCommResult *)malloc( Length);
5712 memset( *ResultCB, '\0', Length );
5714 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_InData, &req, userp);
5716 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5717 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Write FAILURE code=0x%x status=0x%x",
5719 (*ResultCB)->ResultStatus = status;
5723 pPipe_OutData = (BYTE *)(*ResultCB)->ResultData;
5724 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_OutData,
5725 &(*ResultCB)->ResultBufferLength, &req, userp);
5727 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5728 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Read FAILURE code=0x%x status=0x%x",
5730 (*ResultCB)->ResultStatus = status;
5734 (*ResultCB)->ResultStatus = 0;
5735 osi_Log0(afsd_logp, "RDR_Pipe_Transceive SUCCESS");