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 not a readonly object, flush dirty data and update metadata */
1845 if (!(scp->flags & CM_SCACHEFLAG_RO)) {
1846 if ((bLastHandle || bFlushFile) &&
1847 buf_DirtyBuffersExist(&scp->fid)) {
1849 lock_ObtainWrite(&scp->rw);
1852 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
1853 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1856 lock_ReleaseWrite(&scp->rw);
1860 code = cm_FSync(scp, userp, &req, bScpLocked);
1862 if (bLastHandle && code)
1866 if (CleanupCB->ChangeTime.QuadPart) {
1868 if (scp->fileType == CM_SCACHETYPE_FILE) {
1869 /* Do not set length and other attributes at the same time */
1870 if (scp->length.QuadPart != CleanupCB->AllocationSize.QuadPart) {
1871 osi_Log2(afsd_logp, "RDR_CleanupFileEntry Length Change 0x%x -> 0x%x",
1872 (afs_uint32)scp->length.QuadPart, (afs_uint32)CleanupCB->AllocationSize.QuadPart);
1873 setAttr.mask |= CM_ATTRMASK_LENGTH;
1874 setAttr.length.LowPart = CleanupCB->AllocationSize.LowPart;
1875 setAttr.length.HighPart = CleanupCB->AllocationSize.HighPart;
1878 lock_ReleaseWrite(&scp->rw);
1881 code = cm_SetAttr(scp, &setAttr, userp, &req);
1889 lock_ObtainWrite(&scp->rw);
1893 if ((scp->unixModeBits & 0200) && (CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1894 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1895 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1896 } else if (!(scp->unixModeBits & 0200) && !(CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1897 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1898 setAttr.unixModeBits = scp->unixModeBits | 0222;
1902 if (CleanupCB->LastWriteTime.QuadPart) {
1903 ft.dwLowDateTime = CleanupCB->LastWriteTime.LowPart;
1904 ft.dwHighDateTime = CleanupCB->LastWriteTime.HighPart;
1906 cm_UnixTimeFromLargeSearchTime(&clientModTime, &ft);
1907 if (scp->clientModTime != clientModTime) {
1908 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1909 setAttr.clientModTime = clientModTime;
1915 lock_ReleaseWrite(&scp->rw);
1917 code = cm_SetAttr(scp, &setAttr, userp, &req);
1923 /* Now drop the lock enforcing the share access */
1924 if ( CleanupCB->FileAccess != AFS_FILE_ACCESS_NOLOCK) {
1925 unsigned int sLockType;
1926 LARGE_INTEGER LOffset, LLength;
1928 if (CleanupCB->FileAccess == AFS_FILE_ACCESS_SHARED)
1929 sLockType = LOCKING_ANDX_SHARED_LOCK;
1933 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, CleanupCB->Identifier);
1935 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
1936 LOffset.LowPart = SMB_FID_QLOCK_LOW;
1937 LLength.HighPart = 0;
1938 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
1941 lock_ObtainWrite(&scp->rw);
1945 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
1948 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
1950 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
1952 if (code == CM_ERROR_RANGE_NOT_LOCKED)
1954 osi_Log3(afsd_logp, "RDR_CleanupFileEntry Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
1955 CleanupCB->FileAccess, CleanupCB->ProcessId, CleanupCB->Identifier);
1961 if (bUnlockFile || bDeleteFile) {
1963 lock_ObtainWrite(&scp->rw);
1966 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1967 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1969 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp (2) failure scp=0x%p code=0x%x",
1974 key = cm_GenerateKey(CM_SESSION_IFS, CleanupCB->ProcessId, 0);
1976 /* the scp is now locked and current */
1977 code = cm_UnlockByKey(scp, key,
1978 bDeleteFile ? CM_UNLOCK_FLAG_BY_FID : 0,
1981 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1989 lock_ReleaseWrite(&dscp->rw);
1991 lock_ReleaseWrite(&scp->rw);
1993 if (code == 0 && dscp && bDeleteFile) {
1994 WCHAR FileName[260];
1996 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1998 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
1999 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
2001 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2005 if ( ResultBufferLength >= sizeof( AFSFileCleanupResultCB))
2007 (*ResultCB)->ResultBufferLength = sizeof( AFSFileCleanupResultCB);
2008 pResultCB = (AFSFileCleanupResultCB *)&(*ResultCB)->ResultData;
2009 pResultCB->ParentDataVersion.QuadPart = dscp ? dscp->dataVersion : 0;
2011 (*ResultCB)->ResultBufferLength = 0;
2014 (*ResultCB)->ResultStatus = 0;
2015 osi_Log0(afsd_logp, "RDR_CleanupFileEntry SUCCESS");
2017 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2018 (*ResultCB)->ResultStatus = status;
2019 osi_Log2(afsd_logp, "RDR_CleanupFileEntry FAILURE code=0x%x status=0x%x",
2024 cm_ReleaseSCache(scp);
2026 cm_ReleaseSCache(dscp);
2032 RDR_DeleteFileEntry( IN cm_user_t *userp,
2033 IN AFSFileID ParentId,
2034 IN ULONGLONG ProcessId,
2035 IN WCHAR *FileNameCounted,
2036 IN DWORD FileNameLength,
2039 IN DWORD ResultBufferLength,
2040 IN OUT AFSCommResult **ResultCB)
2043 AFSFileDeleteResultCB *pResultCB = NULL;
2044 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2047 cm_scache_t * dscp = NULL;
2048 cm_scache_t * scp = NULL;
2049 afs_uint32 flags = 0;
2053 wchar_t FileName[260];
2056 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
2058 osi_Log4(afsd_logp, "RDR_DeleteFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2059 ParentId.Cell, ParentId.Volume,
2060 ParentId.Vnode, ParentId.Unique);
2061 osi_Log2(afsd_logp, "... name=%S checkOnly=%x",
2062 osi_LogSaveStringW(afsd_logp, FileName),
2067 req.flags |= CM_REQ_WOW64;
2068 memset(&setAttr, 0, sizeof(cm_attr_t));
2070 *ResultCB = (AFSCommResult *)malloc( size);
2072 osi_Log0(afsd_logp, "RDR_DeleteFileEntry out of memory");
2080 parentFid.cell = ParentId.Cell;
2081 parentFid.volume = ParentId.Volume;
2082 parentFid.vnode = ParentId.Vnode;
2083 parentFid.unique = ParentId.Unique;
2084 parentFid.hash = ParentId.Hash;
2086 code = cm_GetSCache(&parentFid, NULL, &dscp, userp, &req);
2088 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2089 if ( status == STATUS_INVALID_HANDLE)
2090 status = STATUS_OBJECT_PATH_INVALID;
2091 (*ResultCB)->ResultStatus = status;
2092 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
2097 lock_ObtainWrite(&dscp->rw);
2099 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
2100 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2102 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2103 (*ResultCB)->ResultStatus = status;
2104 (*ResultCB)->ResultBufferLength = 0;
2105 lock_ReleaseWrite(&dscp->rw);
2106 cm_ReleaseSCache(dscp);
2107 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
2108 dscp, code, status);
2112 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2113 lock_ReleaseWrite(&dscp->rw);
2115 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2116 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2117 cm_ReleaseSCache(dscp);
2118 osi_Log1(afsd_logp, "RDR_DeleteFileEntry Not a Directory dscp=0x%p",
2123 code = cm_Lookup(dscp, FileName, 0, userp, &req, &scp);
2125 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2126 (*ResultCB)->ResultStatus = status;
2127 (*ResultCB)->ResultBufferLength = 0;
2128 cm_ReleaseSCache(dscp);
2129 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_Lookup failure code=0x%x status=0x%x",
2134 lock_ObtainWrite(&scp->rw);
2135 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_DELETE,
2136 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2138 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2139 (*ResultCB)->ResultStatus = status;
2140 (*ResultCB)->ResultBufferLength = 0;
2141 lock_ReleaseWrite(&scp->rw);
2142 cm_ReleaseSCache(scp);
2143 cm_ReleaseSCache(dscp);
2144 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2150 /* Drop all locks since the file is being deleted */
2151 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2152 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2154 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2155 (*ResultCB)->ResultStatus = status;
2156 (*ResultCB)->ResultBufferLength = 0;
2157 lock_ReleaseWrite(&scp->rw);
2158 cm_ReleaseSCache(scp);
2159 cm_ReleaseSCache(dscp);
2160 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp Lock failure scp=0x%p code=0x%x status=0x%x",
2164 /* the scp is now locked and current */
2165 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId, 0);
2167 code = cm_UnlockByKey(scp, key,
2168 CM_UNLOCK_FLAG_BY_FID,
2171 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2172 lock_ReleaseWrite(&scp->rw);
2174 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
2175 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
2177 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2179 lock_ReleaseWrite(&scp->rw);
2183 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
2185 (*ResultCB)->ResultBufferLength = sizeof( AFSFileDeleteResultCB);
2187 pResultCB = (AFSFileDeleteResultCB *)(*ResultCB)->ResultData;
2189 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
2190 osi_Log0(afsd_logp, "RDR_DeleteFileEntry SUCCESS");
2192 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2193 (*ResultCB)->ResultStatus = status;
2194 (*ResultCB)->ResultBufferLength = 0;
2195 osi_Log2(afsd_logp, "RDR_DeleteFileEntry FAILURE code=0x%x status=0x%x",
2199 cm_ReleaseSCache(dscp);
2200 cm_ReleaseSCache(scp);
2206 RDR_RenameFileEntry( IN cm_user_t *userp,
2207 IN WCHAR *SourceFileNameCounted,
2208 IN DWORD SourceFileNameLength,
2209 IN AFSFileID SourceFileId,
2210 IN AFSFileRenameCB *pRenameCB,
2212 IN DWORD ResultBufferLength,
2213 IN OUT AFSCommResult **ResultCB)
2216 AFSFileRenameResultCB *pResultCB = NULL;
2217 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2218 AFSFileID SourceParentId = pRenameCB->SourceParentId;
2219 AFSFileID TargetParentId = pRenameCB->TargetParentId;
2220 WCHAR * TargetFileNameCounted = pRenameCB->TargetName;
2221 DWORD TargetFileNameLength = pRenameCB->TargetNameLength;
2222 cm_fid_t SourceParentFid;
2223 cm_fid_t TargetParentFid;
2225 cm_fid_t OrigTargetFid = {0,0,0,0,0};
2227 cm_scache_t * oldDscp;
2228 cm_scache_t * newDscp;
2230 wchar_t shortName[13];
2231 wchar_t SourceFileName[260];
2232 wchar_t TargetFileName[260];
2240 req.flags |= CM_REQ_WOW64;
2242 StringCchCopyNW(SourceFileName, 260, SourceFileNameCounted, SourceFileNameLength / sizeof(WCHAR));
2243 StringCchCopyNW(TargetFileName, 260, TargetFileNameCounted, TargetFileNameLength / sizeof(WCHAR));
2245 osi_Log4(afsd_logp, "RDR_RenameFileEntry Source Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2246 SourceParentId.Cell, SourceParentId.Volume,
2247 SourceParentId.Vnode, SourceParentId.Unique);
2248 osi_Log2(afsd_logp, "... Source Name=%S Length %u", osi_LogSaveStringW(afsd_logp, SourceFileName), SourceFileNameLength);
2249 osi_Log4(afsd_logp, "... Target Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2250 TargetParentId.Cell, TargetParentId.Volume,
2251 TargetParentId.Vnode, TargetParentId.Unique);
2252 osi_Log2(afsd_logp, "... Target Name=%S Length %u", osi_LogSaveStringW(afsd_logp, TargetFileName), TargetFileNameLength);
2254 *ResultCB = (AFSCommResult *)malloc( size);
2262 pResultCB = (AFSFileRenameResultCB *)(*ResultCB)->ResultData;
2264 if (SourceFileNameLength == 0 || TargetFileNameLength == 0)
2266 osi_Log2(afsd_logp, "RDR_RenameFileEntry Invalid Name Length: src %u target %u",
2267 SourceFileNameLength, TargetFileNameLength);
2268 (*ResultCB)->ResultStatus = STATUS_INVALID_PARAMETER;
2272 SourceParentFid.cell = SourceParentId.Cell;
2273 SourceParentFid.volume = SourceParentId.Volume;
2274 SourceParentFid.vnode = SourceParentId.Vnode;
2275 SourceParentFid.unique = SourceParentId.Unique;
2276 SourceParentFid.hash = SourceParentId.Hash;
2278 TargetParentFid.cell = TargetParentId.Cell;
2279 TargetParentFid.volume = TargetParentId.Volume;
2280 TargetParentFid.vnode = TargetParentId.Vnode;
2281 TargetParentFid.unique = TargetParentId.Unique;
2282 TargetParentFid.hash = TargetParentId.Hash;
2284 code = cm_GetSCache(&SourceParentFid, NULL, &oldDscp, userp, &req);
2286 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache source parent failed code 0x%x", code);
2287 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2288 if ( status == STATUS_INVALID_HANDLE)
2289 status = STATUS_OBJECT_PATH_INVALID;
2290 (*ResultCB)->ResultStatus = status;
2294 lock_ObtainWrite(&oldDscp->rw);
2295 code = cm_SyncOp(oldDscp, NULL, userp, &req, 0,
2296 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2298 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp oldDscp 0x%p failed code 0x%x", oldDscp, code);
2299 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2300 if ( status == STATUS_INVALID_HANDLE)
2301 status = STATUS_OBJECT_PATH_INVALID;
2302 (*ResultCB)->ResultStatus = status;
2303 lock_ReleaseWrite(&oldDscp->rw);
2304 cm_ReleaseSCache(oldDscp);
2308 cm_SyncOpDone(oldDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2309 lock_ReleaseWrite(&oldDscp->rw);
2312 if (oldDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2313 osi_Log1(afsd_logp, "RDR_RenameFileEntry oldDscp 0x%p not a directory", oldDscp);
2314 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2315 cm_ReleaseSCache(oldDscp);
2319 code = cm_GetSCache(&TargetParentFid, NULL, &newDscp, userp, &req);
2321 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target parent failed code 0x%x", code);
2322 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2323 (*ResultCB)->ResultStatus = status;
2324 cm_ReleaseSCache(oldDscp);
2328 lock_ObtainWrite(&newDscp->rw);
2329 code = cm_SyncOp(newDscp, NULL, userp, &req, 0,
2330 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2332 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp newDscp 0x%p failed code 0x%x", newDscp, code);
2333 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2334 (*ResultCB)->ResultStatus = status;
2335 lock_ReleaseWrite(&newDscp->rw);
2336 cm_ReleaseSCache(oldDscp);
2337 cm_ReleaseSCache(newDscp);
2341 cm_SyncOpDone(newDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2342 lock_ReleaseWrite(&newDscp->rw);
2345 if (newDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2346 osi_Log1(afsd_logp, "RDR_RenameFileEntry newDscp 0x%p not a directory", newDscp);
2347 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2348 cm_ReleaseSCache(oldDscp);
2349 cm_ReleaseSCache(newDscp);
2353 /* Obtain the original FID just for debugging purposes */
2354 code = cm_BeginDirOp( oldDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2356 code = cm_BPlusDirLookup(&dirop, SourceFileName, &SourceFid);
2357 code = cm_BPlusDirLookup(&dirop, TargetFileName, &OrigTargetFid);
2358 cm_EndDirOp(&dirop);
2361 code = cm_Rename( oldDscp, NULL, SourceFileName,
2362 newDscp, TargetFileName, userp, &req);
2364 cm_scache_t *scp = 0;
2367 (*ResultCB)->ResultBufferLength = ResultBufferLength;
2368 dwRemaining = ResultBufferLength - sizeof( AFSFileRenameResultCB) + sizeof( AFSDirEnumEntry);
2369 (*ResultCB)->ResultStatus = 0;
2371 pResultCB->SourceParentDataVersion.QuadPart = oldDscp->dataVersion;
2372 pResultCB->TargetParentDataVersion.QuadPart = newDscp->dataVersion;
2374 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p SUCCESS",
2377 code = cm_BeginDirOp( newDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2379 code = cm_BPlusDirLookup(&dirop, TargetFileName, &TargetFid);
2380 cm_EndDirOp(&dirop);
2384 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_BPlusDirLookup failed code 0x%x",
2386 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
2387 cm_ReleaseSCache(oldDscp);
2388 cm_ReleaseSCache(newDscp);
2392 osi_Log4(afsd_logp, "RDR_RenameFileEntry Target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2393 TargetFid.cell, TargetFid.volume,
2394 TargetFid.vnode, TargetFid.unique);
2396 code = cm_GetSCache(&TargetFid, &newDscp->fid, &scp, userp, &req);
2398 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target failed code 0x%x", code);
2399 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2400 (*ResultCB)->ResultStatus = status;
2401 cm_ReleaseSCache(oldDscp);
2402 cm_ReleaseSCache(newDscp);
2406 /* Make sure the source vnode is current */
2407 lock_ObtainWrite(&scp->rw);
2408 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2409 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2411 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp scp 0x%p failed code 0x%x", scp, code);
2412 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2413 (*ResultCB)->ResultStatus = status;
2414 lock_ReleaseWrite(&scp->rw);
2415 cm_ReleaseSCache(oldDscp);
2416 cm_ReleaseSCache(newDscp);
2417 cm_ReleaseSCache(scp);
2421 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2422 lock_ReleaseWrite(&scp->rw);
2424 dfid.vnode = htonl(scp->fid.vnode);
2425 dfid.unique = htonl(scp->fid.unique);
2427 if (!cm_Is8Dot3(TargetFileName))
2428 cm_Gen8Dot3NameIntW(TargetFileName, &dfid, shortName, NULL);
2430 shortName[0] = '\0';
2432 RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
2433 newDscp, scp, userp, &req, TargetFileName, shortName,
2434 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
2435 0, NULL, &dwRemaining);
2436 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
2437 cm_ReleaseSCache(scp);
2439 osi_Log0(afsd_logp, "RDR_RenameFileEntry SUCCESS");
2441 osi_Log3(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p failed code 0x%x",
2442 oldDscp, newDscp, code);
2443 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2444 (*ResultCB)->ResultStatus = status;
2445 (*ResultCB)->ResultBufferLength = 0;
2448 cm_ReleaseSCache(oldDscp);
2449 cm_ReleaseSCache(newDscp);
2454 RDR_FlushFileEntry( IN cm_user_t *userp,
2455 IN AFSFileID FileId,
2457 IN DWORD ResultBufferLength,
2458 IN OUT AFSCommResult **ResultCB)
2460 cm_scache_t *scp = NULL;
2471 req.flags |= CM_REQ_WOW64;
2473 osi_Log4(afsd_logp, "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x",
2474 FileId.Cell, FileId.Volume,
2475 FileId.Vnode, FileId.Unique);
2477 snprintf( dbgstr, 1024,
2478 "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x\n",
2479 FileId.Cell, FileId.Volume,
2480 FileId.Vnode, FileId.Unique);
2481 OutputDebugStringA( dbgstr);
2484 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2486 osi_Log0(afsd_logp, "RDR_FlushFileEntry out of memory");
2492 sizeof( AFSCommResult));
2494 /* Process the release */
2495 Fid.cell = FileId.Cell;
2496 Fid.volume = FileId.Volume;
2497 Fid.vnode = FileId.Vnode;
2498 Fid.unique = FileId.Unique;
2499 Fid.hash = FileId.Hash;
2501 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
2503 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2504 (*ResultCB)->ResultStatus = status;
2505 osi_Log2(afsd_logp, "RDR_FlushFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2510 lock_ObtainWrite(&scp->rw);
2511 if (scp->flags & CM_SCACHEFLAG_DELETED) {
2512 lock_ReleaseWrite(&scp->rw);
2513 (*ResultCB)->ResultStatus = STATUS_INVALID_HANDLE;
2517 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2518 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2520 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2521 (*ResultCB)->ResultStatus = status;
2522 lock_ReleaseWrite(&scp->rw);
2523 cm_ReleaseSCache(scp);
2524 osi_Log3(afsd_logp, "RDR_FlushFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2529 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2530 lock_ReleaseWrite(&scp->rw);
2532 code = cm_FSync(scp, userp, &req, FALSE);
2533 cm_ReleaseSCache(scp);
2536 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2537 (*ResultCB)->ResultStatus = status;
2538 osi_Log2(afsd_logp, "RDR_FlushFileEntry FAILURE code=0x%x status=0x%x",
2541 (*ResultCB)->ResultStatus = 0;
2542 osi_Log0(afsd_logp, "RDR_FlushFileEntry SUCCESS");
2544 (*ResultCB)->ResultBufferLength = 0;
2550 RDR_CheckAccess( IN cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp,
2554 ULONG afs_acc, afs_gr;
2556 afs_uint32 code = 0;
2558 file = (scp->fileType == CM_SCACHETYPE_FILE);
2561 /* access definitions from prs_fs.h */
2563 if (access & FILE_READ_DATA)
2564 afs_acc |= PRSFS_READ;
2565 if (access & FILE_READ_EA || access & FILE_READ_ATTRIBUTES)
2566 afs_acc |= PRSFS_READ;
2567 if (file && ((access & FILE_WRITE_DATA) || (access & FILE_APPEND_DATA)))
2568 afs_acc |= PRSFS_WRITE;
2569 if (access & FILE_WRITE_EA || access & FILE_WRITE_ATTRIBUTES)
2570 afs_acc |= PRSFS_WRITE;
2571 if (dir && ((access & FILE_ADD_FILE) || (access & FILE_ADD_SUBDIRECTORY)))
2572 afs_acc |= PRSFS_INSERT;
2573 if (dir && (access & FILE_LIST_DIRECTORY))
2574 afs_acc |= PRSFS_LOOKUP;
2575 if (file && (access & FILE_EXECUTE))
2576 afs_acc |= PRSFS_WRITE;
2577 if (dir && (access & FILE_TRAVERSE))
2578 afs_acc |= PRSFS_READ;
2579 if (dir && (access & FILE_DELETE_CHILD))
2580 afs_acc |= PRSFS_DELETE;
2581 if ((access & DELETE))
2582 afs_acc |= PRSFS_DELETE;
2584 /* check ACL with server */
2585 lock_ObtainWrite(&scp->rw);
2588 if (cm_HaveAccessRights(scp, userp, reqp, afs_acc, &afs_gr))
2594 /* we don't know the required access rights */
2595 code = cm_GetAccessRights(scp, userp, reqp);
2601 lock_ReleaseWrite(&(scp->rw));
2605 if (afs_gr & PRSFS_READ)
2606 *granted |= FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | FILE_EXECUTE;
2607 if (afs_gr & PRSFS_WRITE)
2608 *granted |= FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES | FILE_EXECUTE;
2609 if (afs_gr & PRSFS_INSERT)
2610 *granted |= (dir ? FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY : 0) | (file ? FILE_ADD_SUBDIRECTORY : 0);
2611 if (afs_gr & PRSFS_LOOKUP)
2612 *granted |= (dir ? FILE_LIST_DIRECTORY : 0);
2613 if (afs_gr & PRSFS_DELETE)
2614 *granted |= FILE_DELETE_CHILD | DELETE;
2615 if (afs_gr & PRSFS_LOCK)
2617 if (afs_gr & PRSFS_ADMINISTER)
2620 *granted |= SYNCHRONIZE | READ_CONTROL;
2622 /* don't give more access than what was requested */
2624 osi_Log3(afsd_logp, "RDR_CheckAccess SUCCESS scp=0x%p requested=0x%x granted=0x%x", scp, access, *granted);
2626 osi_Log2(afsd_logp, "RDR_CheckAccess FAILURE scp=0x%p code=0x%x",
2633 RDR_OpenFileEntry( IN cm_user_t *userp,
2634 IN AFSFileID FileId,
2635 IN AFSFileOpenCB *OpenCB,
2638 IN DWORD ResultBufferLength,
2639 IN OUT AFSCommResult **ResultCB)
2641 AFSFileOpenResultCB *pResultCB = NULL;
2642 cm_scache_t *scp = NULL;
2643 cm_user_t *sysUserp = NULL;
2645 cm_lock_data_t *ldp = NULL;
2652 req.flags |= CM_REQ_WOW64;
2654 osi_Log4(afsd_logp, "RDR_OpenFileEntry File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2655 FileId.Cell, FileId.Volume,
2656 FileId.Vnode, FileId.Unique);
2658 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2660 osi_Log0(afsd_logp, "RDR_OpenFileEntry out of memory");
2666 sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2668 pResultCB = (AFSFileOpenResultCB *)(*ResultCB)->ResultData;
2670 /* Process the release */
2671 Fid.cell = FileId.Cell;
2672 Fid.volume = FileId.Volume;
2673 Fid.vnode = FileId.Vnode;
2674 Fid.unique = FileId.Unique;
2675 Fid.hash = FileId.Hash;
2677 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
2679 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2680 (*ResultCB)->ResultStatus = status;
2681 osi_Log2(afsd_logp, "RDR_OpenFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2686 lock_ObtainWrite(&scp->rw);
2687 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2688 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2690 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2691 (*ResultCB)->ResultStatus = status;
2692 lock_ReleaseWrite(&scp->rw);
2693 cm_ReleaseSCache(scp);
2694 osi_Log3(afsd_logp, "RDR_OpenFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2699 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2700 lock_ReleaseWrite(&scp->rw);
2702 sysUserp = RDR_GetLocalSystemUser();
2705 * Skip the open check if the request is coming from the local system account.
2706 * The local system has no tokens and therefore any requests sent to a file
2707 * server will fail. Unfortunately, there are special system processes that
2708 * perform actions on files and directories in preparation for memory mapping
2709 * executables. If the open check fails, the real request from the user process
2710 * will never be issued.
2712 * Permitting the file system to allow subsequent operations to proceed does
2713 * not compromise security. All requests to obtain file data or directory
2714 * enumerations will subsequently fail if they are not submitted under the
2715 * context of a process for that have access to the necessary credentials.
2718 if ( userp == sysUserp)
2720 osi_Log1(afsd_logp, "RDR_OpenFileEntry LOCAL_SYSTEM access check skipped scp=0x%p",
2722 pResultCB->GrantedAccess = OpenCB->DesiredAccess;
2723 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2734 "RDR_OpenFileEntry repeating open check scp=0x%p userp=0x%p code=0x%x",
2737 code = cm_CheckNTOpen(scp, OpenCB->DesiredAccess, OpenCB->ShareAccess,
2739 OpenCB->ProcessId, OpenCB->Identifier,
2742 code = RDR_CheckAccess(scp, userp, &req, OpenCB->DesiredAccess, &pResultCB->GrantedAccess);
2743 cm_CheckNTOpenDone(scp, userp, &req, &ldp);
2744 } while (count < 100 && (code == CM_ERROR_RETRY || code == CM_ERROR_WOULDBLOCK));
2748 * If we are restricting sharing, we should do so with a suitable
2751 if (code == 0 && scp->fileType == CM_SCACHETYPE_FILE && !(OpenCB->ShareAccess & FILE_SHARE_WRITE)) {
2753 LARGE_INTEGER LOffset, LLength;
2756 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2757 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2758 LLength.HighPart = 0;
2759 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2762 * If we are not opening the file for writing, then we don't
2763 * try to get an exclusive lock. No one else should be able to
2764 * get an exclusive lock on the file anyway, although someone
2765 * else can get a shared lock.
2767 if ((OpenCB->ShareAccess & FILE_SHARE_READ) || !(OpenCB->DesiredAccess & AFS_ACCESS_WRITE))
2769 sLockType = LOCKING_ANDX_SHARED_LOCK;
2774 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, OpenCB->Identifier);
2776 lock_ObtainWrite(&scp->rw);
2777 code = cm_Lock(scp, sLockType, LOffset, LLength, key, 0, userp, &req, NULL);
2778 lock_ReleaseWrite(&scp->rw);
2781 code = CM_ERROR_SHARING_VIOLATION;
2782 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2784 if (sLockType == LOCKING_ANDX_SHARED_LOCK)
2785 pResultCB->FileAccess = AFS_FILE_ACCESS_SHARED;
2787 pResultCB->FileAccess = AFS_FILE_ACCESS_EXCLUSIVE;
2790 pResultCB->FileAccess = AFS_FILE_ACCESS_NOLOCK;
2793 cm_ReleaseUser(sysUserp);
2794 if (code == 0 && bHoldFid)
2795 RDR_FlagScpInUse( scp, FALSE );
2796 cm_ReleaseSCache(scp);
2799 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2800 (*ResultCB)->ResultStatus = status;
2801 osi_Log2(afsd_logp, "RDR_OpenFileEntry FAILURE code=0x%x status=0x%x",
2804 (*ResultCB)->ResultStatus = 0;
2805 (*ResultCB)->ResultBufferLength = sizeof( AFSFileOpenResultCB);
2806 osi_Log0(afsd_logp, "RDR_OpenFileEntry SUCCESS");
2812 RDR_ReleaseFileAccess( IN cm_user_t *userp,
2813 IN AFSFileID FileId,
2814 IN AFSFileAccessReleaseCB *ReleaseFileCB,
2816 IN DWORD ResultBufferLength,
2817 IN OUT AFSCommResult **ResultCB)
2820 unsigned int sLockType;
2821 LARGE_INTEGER LOffset, LLength;
2822 cm_scache_t *scp = NULL;
2830 req.flags |= CM_REQ_WOW64;
2832 osi_Log4(afsd_logp, "RDR_ReleaseFileAccess File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2833 FileId.Cell, FileId.Volume,
2834 FileId.Vnode, FileId.Unique);
2836 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2838 osi_Log0(afsd_logp, "RDR_ReleaseFileAccess out of memory");
2842 memset( *ResultCB, '\0', sizeof( AFSCommResult));
2844 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_NOLOCK)
2847 /* Process the release */
2848 Fid.cell = FileId.Cell;
2849 Fid.volume = FileId.Volume;
2850 Fid.vnode = FileId.Vnode;
2851 Fid.unique = FileId.Unique;
2852 Fid.hash = FileId.Hash;
2854 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
2856 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2857 (*ResultCB)->ResultStatus = status;
2858 osi_Log2(afsd_logp, "RDR_ReleaseFileAccess cm_GetSCache FID failure code=0x%x status=0x%x",
2863 if (ReleaseFileCB->FileAccess == AFS_FILE_ACCESS_SHARED)
2864 sLockType = LOCKING_ANDX_SHARED_LOCK;
2868 key = cm_GenerateKey(CM_SESSION_IFS, SMB_FID_QLOCK_PID, ReleaseFileCB->Identifier);
2870 LOffset.HighPart = SMB_FID_QLOCK_HIGH;
2871 LOffset.LowPart = SMB_FID_QLOCK_LOW;
2872 LLength.HighPart = 0;
2873 LLength.LowPart = SMB_FID_QLOCK_LENGTH;
2875 lock_ObtainWrite(&scp->rw);
2877 code = cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_LOCK);
2880 code = cm_Unlock(scp, sLockType, LOffset, LLength, key, 0, userp, &req);
2882 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_LOCK);
2884 if (code == CM_ERROR_RANGE_NOT_LOCKED)
2886 osi_Log3(afsd_logp, "RDR_ReleaseFileAccess Range Not Locked -- FileAccess 0x%x ProcessId 0x%x HandleId 0x%x",
2887 ReleaseFileCB->FileAccess, ReleaseFileCB->ProcessId, ReleaseFileCB->Identifier);
2891 lock_ReleaseWrite(&scp->rw);
2893 osi_Log0(afsd_logp, "RDR_ReleaseFileAccessEntry SUCCESS");
2897 HexCheckSum(unsigned char * buf, int buflen, unsigned char * md5cksum)
2900 static char tr[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
2903 return "buffer length too small to HexCheckSum";
2905 for (i=0;i<16;i++) {
2908 buf[i*2] = tr[k / 16];
2909 buf[i*2+1] = tr[k % 16];
2917 * Extent requests from the file system are triggered when a file
2918 * page is not resident in the Windows cache. The file system is
2919 * responsible for loading the page but cannot block the request
2920 * while doing so. The AFS Redirector forwards the requests to
2921 * the AFS cache manager while indicating to Windows that the page
2922 * is not yet available. A polling operation will then ensue with
2923 * the AFS Redirector issuing a RDR_RequestFileExtentsXXX call for
2924 * each poll attempt. As each request is received and processed
2925 * by a separate worker thread in the service, this can lead to
2926 * contention by multiple threads attempting to claim the same
2927 * cm_buf_t objects. Therefore, it is important that
2929 * (a) the service avoid processing more than one overlapping
2930 * extent request at a time
2931 * (b) background daemon processing be used to avoid blocking
2934 * Beginning with the 20091122 build of the redirector, the redirector
2935 * will not issue an additional RDR_RequestFileExtentsXXX call for
2936 * each poll request. Instead, afsd_service is required to track
2937 * the requests and return them to the redirector or fail the
2938 * portions of the request that cannot be satisfied.
2940 * The request processing returns any extents that can be returned
2941 * immediately to the redirector. The rest of the requested range(s)
2942 * are queued as background operations using RDR_BkgFetch().
2945 /* do the background fetch. */
2947 RDR_BkgFetch(cm_scache_t *scp, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4,
2948 cm_user_t *userp, cm_req_t *reqp)
2954 osi_hyper_t fetched;
2955 osi_hyper_t tblocksize;
2958 cm_buf_t *bufp = NULL;
2959 DWORD dwResultBufferLength;
2960 AFSSetFileExtentsCB *pResultCB;
2964 int reportErrorToRedir = 0;
2965 int force_retry = 0;
2967 FileId.Cell = scp->fid.cell;
2968 FileId.Volume = scp->fid.volume;
2969 FileId.Vnode = scp->fid.vnode;
2970 FileId.Unique = scp->fid.unique;
2971 FileId.Hash = scp->fid.hash;
2973 if ((GetTickCount() - reqp->startTime) / 1000 > HardDeadtimeout * 5) {
2974 RDR_SetFileStatus( &scp->fid, &userp->authgroup, STATUS_IO_TIMEOUT);
2978 fetched.LowPart = 0;
2979 fetched.HighPart = 0;
2980 tblocksize = ConvertLongToLargeInteger(cm_data.buf_blockSize);
2983 length.LowPart = p3;
2984 length.HighPart = p4;
2986 end = LargeIntegerAdd(base, length);
2988 osi_Log5(afsd_logp, "Starting BKG Fetch scp 0x%p offset 0x%x:%x length 0x%x:%x",
2989 scp, p2, p1, p4, p3);
2992 * Make sure we have a callback.
2993 * This is necessary so that we can return access denied
2994 * if a callback cannot be granted.
2996 lock_ObtainWrite(&scp->rw);
2997 code = cm_SyncOp(scp, NULL, userp, reqp, PRSFS_READ,
2998 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3000 lock_ReleaseWrite(&scp->rw);
3001 osi_Log2(afsd_logp, "RDR_BkgFetch cm_SyncOp failure scp=0x%p code=0x%x",
3003 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
3004 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3007 lock_ReleaseWrite(&scp->rw);
3009 dwResultBufferLength = (DWORD)(sizeof( AFSSetFileExtentsCB) + sizeof( AFSSetFileExtentsCB) * (length.QuadPart / cm_data.blockSize + 1));
3010 pResultCB = (AFSSetFileExtentsCB *)malloc( dwResultBufferLength );
3012 return CM_ERROR_RETRY;
3014 memset( pResultCB, '\0', dwResultBufferLength );
3015 pResultCB->FileId = FileId;
3017 for ( code = 0, offset = base;
3018 code == 0 && LargeIntegerLessThan(offset, end);
3019 offset = LargeIntegerAdd(offset, tblocksize) )
3021 int bBufRelease = TRUE;
3024 lock_ReleaseWrite(&scp->rw);
3028 code = buf_Get(scp, &offset, reqp, &bufp);
3031 * any error from buf_Get() is non-fatal.
3032 * we need to re-queue this extent fetch.
3039 lock_ObtainWrite(&scp->rw);
3043 code = cm_GetBuffer(scp, bufp, NULL, userp, reqp);
3045 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3046 #ifdef VALIDATE_CHECK_SUM
3052 if (bufp->flags & CM_BUF_DIRTY)
3053 cm_BufWrite(scp, &bufp->offset, cm_data.buf_blockSize, CM_BUF_WRITE_SCP_LOCKED, userp, reqp);
3055 lock_ObtainWrite(&buf_globalLock);
3056 if (!(bufp->flags & CM_BUF_DIRTY) &&
3057 bufp->cmFlags == 0 &&
3058 !(bufp->qFlags & CM_BUF_QREDIR)) {
3059 buf_InsertToRedirQueue(scp, bufp);
3060 lock_ReleaseWrite(&buf_globalLock);
3062 #ifdef VALIDATE_CHECK_SUM
3063 buf_ComputeCheckSum(bufp);
3065 pResultCB->FileExtents[count].Flags = 0;
3066 pResultCB->FileExtents[count].FileOffset.QuadPart = bufp->offset.QuadPart;
3067 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3068 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3070 fetched = LargeIntegerAdd(fetched, tblocksize);
3071 bBufRelease = FALSE;
3073 #ifdef VALIDATE_CHECK_SUM
3075 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3076 snprintf( dbgstr, 1024,
3077 "RDR_BkgFetch md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3079 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3080 pResultCB->FileExtents[count].FileOffset.HighPart,
3081 pResultCB->FileExtents[count].FileOffset.LowPart,
3082 pResultCB->FileExtents[count].CacheOffset.HighPart,
3083 pResultCB->FileExtents[count].CacheOffset.LowPart);
3084 OutputDebugStringA( dbgstr);
3087 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3088 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3090 lock_ReleaseWrite(&buf_globalLock);
3091 if ((bufp->cmFlags != 0) || (bufp->flags & CM_BUF_DIRTY)) {
3092 /* An I/O operation is already in progress */
3094 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",
3095 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 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3103 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3107 * depending on what the error from cm_GetBuffer is
3108 * it may or may not be fatal. Only return fatal errors.
3109 * Re-queue a request for others.
3111 osi_Log5(afsd_logp, "RDR_BkgFetch Extent2FS FAILURE bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x code 0x%x",
3112 bufp, offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize, code);
3114 case CM_ERROR_NOACCESS:
3115 case CM_ERROR_NOSUCHFILE:
3116 case CM_ERROR_NOSUCHPATH:
3117 case CM_ERROR_NOSUCHVOLUME:
3118 case CM_ERROR_NOSUCHCELL:
3119 case CM_ERROR_INVAL:
3120 case CM_ERROR_BADFD:
3121 case CM_ERROR_CLOCKSKEW:
3123 case CM_ERROR_QUOTA:
3124 case CM_ERROR_LOCK_CONFLICT:
3126 * these are fatal errors. deliver what we can
3129 reportErrorToRedir = 1;
3133 * non-fatal errors. re-queue the exent
3135 code = CM_ERROR_RETRY;
3145 lock_ObtainWrite(&scp->rw);
3149 /* wakeup anyone who is waiting */
3150 if (scp->flags & CM_SCACHEFLAG_WAITING) {
3151 osi_Log1(afsd_logp, "RDR Bkg Fetch Waking scp 0x%p", scp);
3152 osi_Wakeup((LONG_PTR) &scp->flags);
3154 lock_ReleaseWrite(&scp->rw);
3157 pResultCB->ExtentCount = count;
3158 RDR_SetFileExtents( pResultCB, dwResultBufferLength);
3162 if (reportErrorToRedir) {
3163 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
3164 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3167 osi_Log4(afsd_logp, "Ending BKG Fetch scp 0x%p code 0x%x fetched 0x%x:%x",
3168 scp, code, fetched.HighPart, fetched.LowPart);
3170 return force_retry ? CM_ERROR_RETRY : code;
3175 RDR_RequestFileExtentsAsync( IN cm_user_t *userp,
3176 IN AFSFileID FileId,
3177 IN AFSRequestExtentsCB *RequestExtentsCB,
3179 IN OUT DWORD * ResultBufferLength,
3180 IN OUT AFSSetFileExtentsCB **ResultCB)
3182 AFSSetFileExtentsCB *pResultCB = NULL;
3186 cm_scache_t *scp = NULL;
3189 afs_uint32 code = 0;
3191 LARGE_INTEGER ByteOffset, BeginOffset, EndOffset, QueueOffset;
3192 afs_uint32 QueueLength;
3194 BOOLEAN bBufRelease = TRUE;
3198 req.flags |= CM_REQ_WOW64;
3199 req.flags |= CM_REQ_NORETRY;
3201 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3202 FileId.Cell, FileId.Volume,
3203 FileId.Vnode, FileId.Unique);
3204 osi_Log4(afsd_logp, "... Flags 0x%x ByteOffset 0x%x:%x Length 0x%x",
3205 RequestExtentsCB->Flags,
3206 RequestExtentsCB->ByteOffset.HighPart, RequestExtentsCB->ByteOffset.LowPart,
3207 RequestExtentsCB->Length);
3208 Length = sizeof( AFSSetFileExtentsCB) + sizeof( AFSFileExtentCB) * (RequestExtentsCB->Length / cm_data.blockSize + 1);
3210 pResultCB = *ResultCB = (AFSSetFileExtentsCB *)malloc( Length );
3211 if (*ResultCB == NULL) {
3212 *ResultBufferLength = 0;
3215 *ResultBufferLength = Length;
3217 memset( pResultCB, '\0', Length );
3218 pResultCB->FileId = FileId;
3220 Fid.cell = FileId.Cell;
3221 Fid.volume = FileId.Volume;
3222 Fid.vnode = FileId.Vnode;
3223 Fid.unique = FileId.Unique;
3224 Fid.hash = FileId.Hash;
3226 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
3228 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync cm_GetSCache FID failure code=0x%x",
3230 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3235 * Make sure we have a callback.
3236 * This is necessary so that we can return access denied
3237 * if a callback cannot be granted.
3239 lock_ObtainWrite(&scp->rw);
3240 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_READ,
3241 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3242 lock_ReleaseWrite(&scp->rw);
3244 cm_ReleaseSCache(scp);
3245 osi_Log2(afsd_logp, "RDR_RequestFileExtentsAsync cm_SyncOp failure scp=0x%p code=0x%x",
3247 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3248 RDR_SetFileStatus( &scp->fid, &userp->authgroup, status);
3252 /* Allocate the extents from the buffer package */
3254 ByteOffset = BeginOffset = RequestExtentsCB->ByteOffset,
3255 EndOffset.QuadPart = ByteOffset.QuadPart + RequestExtentsCB->Length;
3256 code == 0 && ByteOffset.QuadPart < EndOffset.QuadPart;
3257 ByteOffset.QuadPart += cm_data.blockSize)
3259 BOOL bHaveBuffer = FALSE;
3262 thyper.QuadPart = ByteOffset.QuadPart;
3264 code = buf_Get(scp, &thyper, &req, &bufp);
3266 lock_ObtainMutex(&bufp->mx);
3269 if (bufp->qFlags & CM_BUF_QREDIR) {
3271 } else if (bufp->flags & CM_BUF_DIRTY) {
3272 bHaveBuffer = FALSE;
3274 code = buf_CleanAsyncLocked(scp, bufp, &req, 0, NULL);
3279 case CM_ERROR_RETRY:
3280 /* Couldn't flush it, obtain it asynchronously so we don't block the thread. */
3281 bHaveBuffer = FALSE;
3285 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3286 RDR_SetFileStatus(&FileId, &userp->authgroup, status);
3287 bHaveBuffer = FALSE;
3292 osi_hyper_t minLength; /* effective end of file */
3294 lock_ObtainRead(&scp->rw);
3295 bHaveBuffer = cm_HaveBuffer(scp, bufp, TRUE);
3297 if (LargeIntegerGreaterThan(scp->length, scp->serverLength))
3298 minLength = scp->serverLength;
3300 minLength = scp->length;
3302 if (LargeIntegerGreaterThanOrEqualTo(bufp->offset, minLength)) {
3304 memset(bufp->datap, 0, cm_data.buf_blockSize);
3305 bufp->dataVersion = scp->dataVersion;
3308 else if (bufp->dataVersion == CM_BUF_VERSION_BAD) {
3309 bufp->dataVersion = scp->dataVersion;
3312 else if ((RequestExtentsCB->Flags & AFS_EXTENT_FLAG_CLEAN) &&
3313 ByteOffset.QuadPart <= bufp->offset.QuadPart &&
3314 EndOffset.QuadPart >= bufp->offset.QuadPart + cm_data.blockSize)
3316 memset(bufp->datap, 0, cm_data.blockSize);
3317 bufp->dataVersion = scp->dataVersion;
3318 buf_SetDirty(bufp, &req, 0, cm_data.blockSize, userp);
3321 lock_ReleaseRead(&scp->rw);
3325 * if this buffer is already up to date, skip it.
3328 if (ByteOffset.QuadPart == BeginOffset.QuadPart) {
3329 BeginOffset.QuadPart += cm_data.blockSize;
3331 QueueLength = (afs_uint32)(ByteOffset.QuadPart - BeginOffset.QuadPart);
3332 QueueOffset = BeginOffset;
3333 BeginOffset = ByteOffset;
3336 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3337 #ifdef VALIDATE_CHECK_SUM
3343 lock_ObtainWrite(&buf_globalLock);
3344 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3345 buf_InsertToRedirQueue(scp, bufp);
3346 lock_ReleaseWrite(&buf_globalLock);
3348 #ifdef VALIDATE_CHECK_SUM
3349 buf_ComputeCheckSum(bufp);
3351 /* we already have the buffer, return it now */
3352 pResultCB->FileExtents[count].Flags = 0;
3353 pResultCB->FileExtents[count].FileOffset = ByteOffset;
3354 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3355 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3358 bBufRelease = FALSE;
3360 #ifdef VALIDATE_CHECK_SUM
3362 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3363 snprintf( dbgstr, 1024,
3364 "RDR_RequestFileExtentsAsync md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3366 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3367 pResultCB->FileExtents[count].FileOffset.HighPart,
3368 pResultCB->FileExtents[count].FileOffset.LowPart,
3369 pResultCB->FileExtents[count].CacheOffset.HighPart,
3370 pResultCB->FileExtents[count].CacheOffset.LowPart);
3371 OutputDebugStringA( dbgstr);
3374 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3375 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3377 lock_ReleaseWrite(&buf_globalLock);
3382 * The service is not handing off the extent to the redirector in this pass.
3383 * However, we know the buffer is in recent use so move the buffer to the
3384 * front of the queue
3386 lock_ObtainWrite(&buf_globalLock);
3387 buf_MoveToHeadOfRedirQueue(scp, bufp);
3388 lock_ReleaseWrite(&buf_globalLock);
3390 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3391 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3395 lock_ReleaseMutex(&bufp->mx);
3400 cm_QueueBKGRequest(scp, RDR_BkgFetch, QueueOffset.LowPart, QueueOffset.HighPart,
3401 QueueLength, 0, userp, &req);
3402 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3403 QueueOffset.HighPart, QueueOffset.LowPart, QueueLength);
3406 /* No error from buf_Get() can be fatal */
3407 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync buf_Get FAILURE offset 0x%x:%x code 0x%x",
3408 BeginOffset.HighPart, BeginOffset.LowPart, code);
3412 if (BeginOffset.QuadPart != EndOffset.QuadPart) {
3413 afs_uint32 length = (afs_uint32)(EndOffset.QuadPart - BeginOffset.QuadPart);
3415 cm_QueueBKGRequest(scp, RDR_BkgFetch, BeginOffset.LowPart, BeginOffset.HighPart,
3416 length, 0, userp, &req);
3417 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3418 BeginOffset.HighPart, BeginOffset.LowPart, length);
3420 cm_ReleaseSCache(scp);
3422 (*ResultCB)->ExtentCount = count;
3423 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync replying with 0x%x extent records", count);
3428 * When processing an extent release the extents must be accepted back by
3429 * the service even if there is an error condition returned to the redirector.
3430 * For example, there may no longer be a callback present or the file may
3431 * have been deleted on the file server. Regardless, the extents must be
3432 * put back into the pool.
3435 RDR_ReleaseFileExtents( IN cm_user_t *userp,
3436 IN AFSFileID FileId,
3437 IN AFSReleaseExtentsCB *ReleaseExtentsCB,
3439 IN DWORD ResultBufferLength,
3440 IN OUT AFSCommResult **ResultCB)
3443 cm_scache_t *scp = NULL;
3454 #ifdef VALIDATE_CHECK_SUM
3455 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3462 req.flags |= CM_REQ_WOW64;
3464 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3465 FileId.Cell, FileId.Volume,
3466 FileId.Vnode, FileId.Unique);
3468 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
3474 sizeof( AFSCommResult));
3476 /* Process the release */
3477 Fid.cell = FileId.Cell;
3478 Fid.volume = FileId.Volume;
3479 Fid.vnode = FileId.Vnode;
3480 Fid.unique = FileId.Unique;
3481 Fid.hash = FileId.Hash;
3483 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
3485 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3486 (*ResultCB)->ResultStatus = status;
3487 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents cm_GetSCache FID failure code=0x%x status=0x%x",
3491 deleted = scp && (scp->flags & CM_SCACHEFLAG_DELETED);
3494 * We do not stop processing as a result of being unable to find the cm_scache object.
3495 * If this occurs something really bad has happened since the cm_scache object must have
3496 * been recycled while extents were held by the redirector. However, we will be resilient
3497 * and carry on without it.
3499 * If the file is known to be deleted, there is no point attempting to ask the
3500 * file server about it or update the attributes.
3502 if (scp && ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart &&
3507 memset(&setAttr, 0, sizeof(cm_attr_t));
3508 lock_ObtainWrite(&scp->rw);
3509 if (ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3511 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents new length fid vol 0x%x vno 0x%x length 0x%x:%x",
3512 scp->fid.volume, scp->fid.vnode,
3513 ReleaseExtentsCB->AllocationSize.HighPart,
3514 ReleaseExtentsCB->AllocationSize.LowPart);
3516 setAttr.mask |= CM_ATTRMASK_LENGTH;
3517 setAttr.length.LowPart = ReleaseExtentsCB->AllocationSize.LowPart;
3518 setAttr.length.HighPart = ReleaseExtentsCB->AllocationSize.HighPart;
3520 lock_ReleaseWrite(&scp->rw);
3522 code = cm_SetAttr(scp, &setAttr, userp, &req);
3525 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3526 AFSFileExtentCB * pExtent = &ReleaseExtentsCB->FileExtents[count];
3528 thyper.QuadPart = pExtent->FileOffset.QuadPart;
3530 bufp = buf_Find(&Fid, &thyper);
3532 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
3533 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3534 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3535 Fid.volume, Fid.vnode,
3536 pExtent->FileOffset.HighPart,
3537 pExtent->FileOffset.LowPart);
3538 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
3539 pExtent->CacheOffset.HighPart,
3540 pExtent->CacheOffset.LowPart);
3542 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3543 Fid.volume, Fid.vnode,
3544 pExtent->FileOffset.HighPart,
3545 pExtent->FileOffset.LowPart);
3546 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
3547 pExtent->CacheOffset.HighPart,
3548 pExtent->CacheOffset.LowPart);
3554 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
3555 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3556 Fid.volume, Fid.vnode,
3557 pExtent->FileOffset.HighPart,
3558 pExtent->FileOffset.LowPart);
3559 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
3560 pExtent->CacheOffset.HighPart,
3561 pExtent->CacheOffset.LowPart);
3563 /* Move the buffer to the front of the queue */
3564 lock_ObtainWrite(&buf_globalLock);
3565 buf_MoveToHeadOfRedirQueue(scp, bufp);
3566 lock_ReleaseWrite(&buf_globalLock);
3571 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
3572 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3573 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x not held by file system",
3574 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
3575 pExtent->FileOffset.LowPart);
3576 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3577 pExtent->CacheOffset.HighPart,
3578 pExtent->CacheOffset.LowPart);
3580 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents bufp 0x%p vno 0x%x foffset 0x%x:%x",
3581 bufp, bufp->fid.vnode, pExtent->FileOffset.HighPart,
3582 pExtent->FileOffset.LowPart);
3583 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3584 pExtent->CacheOffset.HighPart,
3585 pExtent->CacheOffset.LowPart);
3587 if (pExtent->Flags || ReleaseExtentsCB->Flags) {
3588 lock_ObtainMutex(&bufp->mx);
3589 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
3590 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
3592 if (bufp->qFlags & CM_BUF_QREDIR) {
3593 lock_ObtainWrite(&buf_globalLock);
3594 if (bufp->qFlags & CM_BUF_QREDIR) {
3595 buf_RemoveFromRedirQueue(scp, bufp);
3596 buf_ReleaseLocked(bufp, TRUE);
3598 lock_ReleaseWrite(&buf_globalLock);
3601 snprintf( dbgstr, 1024,
3602 "RDR_ReleaseFileExtents releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3603 Fid.volume, Fid.vnode, Fid.unique,
3604 pExtent->FileOffset.HighPart,
3605 pExtent->FileOffset.LowPart,
3606 pExtent->CacheOffset.HighPart,
3607 pExtent->CacheOffset.LowPart);
3608 OutputDebugStringA( dbgstr);
3613 snprintf( dbgstr, 1024,
3614 "RDR_ReleaseFileExtents not releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3615 Fid.volume, Fid.vnode, Fid.unique,
3616 pExtent->FileOffset.HighPart,
3617 pExtent->FileOffset.LowPart,
3618 pExtent->CacheOffset.HighPart,
3619 pExtent->CacheOffset.LowPart);
3620 OutputDebugStringA( dbgstr);
3622 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
3623 Fid.volume, Fid.vnode,
3624 pExtent->FileOffset.HighPart,
3625 pExtent->FileOffset.LowPart);
3626 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3627 pExtent->CacheOffset.HighPart,
3628 pExtent->CacheOffset.LowPart);
3631 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
3632 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY) )
3634 #ifdef VALIDATE_CHECK_SUM
3636 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3640 * if the saved checksum matches the checksum of the current state of the buffer
3641 * then the buffer is the same as what was given to the kernel.
3643 if ( buf_ValidateCheckSum(bufp) ) {
3644 buf_ComputeCheckSum(bufp);
3646 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3649 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
3650 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3652 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3655 snprintf( dbgstr, 1024,
3656 "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",
3657 md5dbg, md5dbg2,md5dbg3,
3658 Fid.volume, Fid.vnode, Fid.unique,
3659 pExtent->FileOffset.HighPart,
3660 pExtent->FileOffset.LowPart,
3661 pExtent->CacheOffset.HighPart,
3662 pExtent->CacheOffset.LowPart);
3663 OutputDebugStringA( dbgstr);
3665 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
3666 Fid.volume, Fid.vnode,
3667 pExtent->FileOffset.HighPart,
3668 pExtent->FileOffset.LowPart);
3669 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3670 pExtent->CacheOffset.HighPart,
3671 pExtent->CacheOffset.LowPart);
3672 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3676 snprintf( dbgstr, 1024,
3677 "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",
3678 md5dbg, md5dbg2, md5dbg3,
3679 Fid.volume, Fid.vnode, Fid.unique,
3680 pExtent->FileOffset.HighPart,
3681 pExtent->FileOffset.LowPart,
3682 pExtent->CacheOffset.HighPart,
3683 pExtent->CacheOffset.LowPart);
3684 OutputDebugStringA( dbgstr);
3686 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3687 Fid.volume, Fid.vnode,
3688 pExtent->FileOffset.HighPart,
3689 pExtent->FileOffset.LowPart);
3690 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3691 pExtent->CacheOffset.HighPart,
3692 pExtent->CacheOffset.LowPart);
3696 snprintf( dbgstr, 1024,
3697 "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",
3698 Fid.volume, Fid.vnode, Fid.unique,
3699 pExtent->FileOffset.HighPart,
3700 pExtent->FileOffset.LowPart,
3701 pExtent->CacheOffset.HighPart,
3702 pExtent->CacheOffset.LowPart);
3703 OutputDebugStringA( dbgstr);
3705 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3706 Fid.volume, Fid.vnode,
3707 pExtent->FileOffset.HighPart,
3708 pExtent->FileOffset.LowPart);
3709 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3710 pExtent->CacheOffset.HighPart,
3711 pExtent->CacheOffset.LowPart);
3714 buf_ComputeCheckSum(bufp);
3716 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3718 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3719 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3721 snprintf( dbgstr, 1024,
3722 "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",
3723 md5dbg, md5dbg2,md5dbg3,
3724 Fid.volume, Fid.vnode, Fid.unique,
3725 pExtent->FileOffset.HighPart,
3726 pExtent->FileOffset.LowPart,
3727 pExtent->CacheOffset.HighPart,
3728 pExtent->CacheOffset.LowPart);
3729 OutputDebugStringA( dbgstr);
3731 snprintf( dbgstr, 1024,
3732 "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",
3733 md5dbg, md5dbg2,md5dbg3,
3734 Fid.volume, Fid.vnode, Fid.unique,
3735 pExtent->FileOffset.HighPart,
3736 pExtent->FileOffset.LowPart,
3737 pExtent->CacheOffset.HighPart,
3738 pExtent->CacheOffset.LowPart);
3739 OutputDebugStringA( dbgstr);
3742 snprintf( dbgstr, 1024,
3743 "RDR_ReleaseFileExtents dirty flag set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3744 Fid.volume, Fid.vnode, Fid.unique,
3745 pExtent->FileOffset.HighPart,
3746 pExtent->FileOffset.LowPart,
3747 pExtent->CacheOffset.HighPart,
3748 pExtent->CacheOffset.LowPart);
3749 OutputDebugStringA( dbgstr);
3752 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3755 #else /* !VALIDATE_CHECK_SUM */
3756 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3758 #endif /* VALIDATE_CHECK_SUM */
3760 #ifdef VALIDATE_CHECK_SUM
3763 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3765 if ( !buf_ValidateCheckSum(bufp) ) {
3766 buf_ComputeCheckSum(bufp);
3768 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3769 snprintf( dbgstr, 1024,
3770 "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",
3772 Fid.volume, Fid.vnode, Fid.unique,
3773 pExtent->FileOffset.HighPart,
3774 pExtent->FileOffset.LowPart,
3775 pExtent->CacheOffset.HighPart,
3776 pExtent->CacheOffset.LowPart);
3777 OutputDebugStringA( dbgstr);
3779 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set but extent has changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3780 Fid.volume, Fid.vnode,
3781 pExtent->FileOffset.HighPart,
3782 pExtent->FileOffset.LowPart);
3783 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3784 pExtent->CacheOffset.HighPart,
3785 pExtent->CacheOffset.LowPart);
3786 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3789 buf_ComputeCheckSum(bufp);
3791 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3792 snprintf( dbgstr, 1024,
3793 "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3794 Fid.volume, Fid.vnode, Fid.unique,
3795 pExtent->FileOffset.HighPart,
3796 pExtent->FileOffset.LowPart,
3797 pExtent->CacheOffset.HighPart,
3798 pExtent->CacheOffset.LowPart);
3799 OutputDebugStringA( dbgstr);
3801 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x foffset 0x%x:%x",
3802 Fid.volume, Fid.vnode,
3803 pExtent->FileOffset.HighPart,
3804 pExtent->FileOffset.LowPart);
3805 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3806 pExtent->CacheOffset.HighPart,
3807 pExtent->CacheOffset.LowPart);
3810 #endif /* VALIDATE_CHECK_SUM */
3811 lock_ReleaseMutex(&bufp->mx);
3816 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3819 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3820 if (wbp->datap == datap)
3825 snprintf( dbgstr, 1024,
3826 "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3827 Fid.volume, Fid.vnode, Fid.unique,
3828 pExtent->FileOffset.HighPart,
3829 pExtent->FileOffset.LowPart,
3830 pExtent->CacheOffset.HighPart,
3831 pExtent->CacheOffset.LowPart);
3832 OutputDebugStringA( dbgstr);
3834 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3835 Fid.volume, Fid.vnode,
3836 pExtent->FileOffset.HighPart,
3837 pExtent->FileOffset.LowPart);
3838 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3839 pExtent->CacheOffset.HighPart,
3840 pExtent->CacheOffset.LowPart);
3841 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3842 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3850 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3853 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3854 if (wbp->datap == datap)
3859 snprintf( dbgstr, 1024,
3860 "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3861 Fid.volume, Fid.vnode, Fid.unique,
3862 pExtent->FileOffset.HighPart,
3863 pExtent->FileOffset.LowPart,
3864 pExtent->CacheOffset.HighPart,
3865 pExtent->CacheOffset.LowPart);
3866 OutputDebugStringA( dbgstr);
3868 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3869 Fid.volume, Fid.vnode,
3870 pExtent->FileOffset.HighPart,
3871 pExtent->FileOffset.LowPart);
3872 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3873 pExtent->CacheOffset.HighPart,
3874 pExtent->CacheOffset.LowPart);
3875 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3876 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3881 if (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_FLUSH) {
3882 lock_ObtainWrite(&scp->rw);
3883 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3884 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3885 lock_ReleaseWrite(&scp->rw);
3887 code = cm_FSync(scp, userp, &req, FALSE);
3890 osi_hyper_t offset = {0,0};
3891 afs_uint32 length = 0;
3892 afs_uint32 rights = 0;
3894 lock_ObtainWrite(&scp->rw);
3895 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3896 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3897 lock_ReleaseWrite(&scp->rw);
3900 * there is at least one dirty extent on this file. queue up background store
3901 * requests for contiguous blocks
3903 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3904 if (ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart == offset.QuadPart + length &&
3905 length + cm_data.buf_blockSize <= cm_chunkSize)
3907 length += cm_data.buf_blockSize;
3909 if (!(offset.QuadPart == 0 && length == 0))
3910 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3911 length, 0, userp, &req);
3912 offset.QuadPart = ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart;
3913 length = cm_data.buf_blockSize;
3916 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3917 length, 0, userp, &req);
3920 cm_ReleaseSCache(scp);
3923 osi_Log5(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
3924 FileId.Cell, FileId.Volume,
3925 FileId.Vnode, FileId.Unique, released);
3926 if (code && code != CM_ERROR_WOULDBLOCK) {
3927 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3928 (*ResultCB)->ResultStatus = status;
3929 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents FAILURE code=0x%x status=0x%x",
3932 (*ResultCB)->ResultStatus = 0;
3933 osi_Log0(afsd_logp, "RDR_ReleaseFileExtents SUCCESS");
3935 (*ResultCB)->ResultBufferLength = 0;
3941 RDR_ProcessReleaseFileExtentsResult( IN AFSReleaseFileExtentsResultCB *ReleaseFileExtentsResultCB,
3942 IN DWORD ResultBufferLength)
3944 afs_uint32 code = 0;
3948 unsigned int fileno, extentno, total_extents = 0;
3949 AFSReleaseFileExtentsResultFileCB *pNextFileCB;
3951 #ifdef VALIDATE_CHECK_SUM
3952 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3958 for ( fileno = 0, pNextFileCB = &ReleaseFileExtentsResultCB->Files[0];
3959 fileno < ReleaseFileExtentsResultCB->FileCount;
3961 AFSReleaseFileExtentsResultFileCB *pFileCB = pNextFileCB;
3962 cm_user_t *userp = NULL;
3964 cm_scache_t * scp = NULL;
3970 userp = RDR_UserFromAuthGroup( &pFileCB->AuthGroup);
3972 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult %d.%d.%d.%d",
3973 pFileCB->FileId.Cell, pFileCB->FileId.Volume,
3974 pFileCB->FileId.Vnode, pFileCB->FileId.Unique);
3976 /* Process the release */
3977 Fid.cell = pFileCB->FileId.Cell;
3978 Fid.volume = pFileCB->FileId.Volume;
3979 Fid.vnode = pFileCB->FileId.Vnode;
3980 Fid.unique = pFileCB->FileId.Unique;
3981 Fid.hash = pFileCB->FileId.Hash;
3983 if (Fid.cell == 0) {
3984 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult Invalid FID %d.%d.%d.%d",
3985 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
3986 code = CM_ERROR_INVAL;
3990 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
3992 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult cm_GetSCache FID failure code=0x%x",
3995 * A failure to find the cm_scache object cannot prevent the service
3996 * from accepting the extents back from the redirector.
4000 deleted = scp && (scp->flags & CM_SCACHEFLAG_DELETED);
4002 /* if the scp was not found, do not perform the length check */
4003 if (scp && (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart)) {
4006 memset(&setAttr, 0, sizeof(cm_attr_t));
4007 lock_ObtainWrite(&scp->rw);
4008 if (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart) {
4009 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult length change vol 0x%x vno 0x%x length 0x%x:%x",
4010 scp->fid.volume, scp->fid.vnode,
4011 pFileCB->AllocationSize.HighPart,
4012 pFileCB->AllocationSize.LowPart);
4013 setAttr.mask |= CM_ATTRMASK_LENGTH;
4014 setAttr.length.LowPart = pFileCB->AllocationSize.LowPart;
4015 setAttr.length.HighPart = pFileCB->AllocationSize.HighPart;
4017 lock_ReleaseWrite(&scp->rw);
4019 code = cm_SetAttr(scp, &setAttr, userp, &req);
4022 for ( extentno = 0; extentno < pFileCB->ExtentCount; total_extents++, extentno++ ) {
4023 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4025 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4027 bufp = buf_Find(&Fid, &thyper);
4029 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4030 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
4031 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4032 Fid.volume, Fid.vnode,
4033 pExtent->FileOffset.HighPart,
4034 pExtent->FileOffset.LowPart);
4035 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
4036 pExtent->CacheOffset.HighPart,
4037 pExtent->CacheOffset.LowPart);
4039 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4040 Fid.volume, Fid.vnode,
4041 pExtent->FileOffset.HighPart,
4042 pExtent->FileOffset.LowPart);
4043 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
4044 pExtent->CacheOffset.HighPart,
4045 pExtent->CacheOffset.LowPart);
4051 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
4052 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4053 Fid.volume, Fid.vnode,
4054 pExtent->FileOffset.HighPart,
4055 pExtent->FileOffset.LowPart);
4056 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
4057 pExtent->CacheOffset.HighPart,
4058 pExtent->CacheOffset.LowPart);
4060 /* Move the buffer to the front of the queue */
4061 lock_ObtainWrite(&buf_globalLock);
4062 buf_MoveToHeadOfRedirQueue(scp, bufp);
4063 lock_ReleaseWrite(&buf_globalLock);
4068 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
4069 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
4070 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4071 Fid.volume, Fid.vnode,
4072 pExtent->FileOffset.HighPart,
4073 pExtent->FileOffset.LowPart);
4074 osi_Log2(afsd_logp, "... coffset 0x%x:%x not held by file system",
4075 pExtent->CacheOffset.HighPart,
4076 pExtent->CacheOffset.LowPart);
4078 snprintf(dbgstr, 1024,
4079 "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",
4080 ReleaseFileExtentsResultCB->Flags, pExtent->Flags,
4081 Fid.volume, Fid.vnode, Fid.unique,
4082 pExtent->FileOffset.HighPart,
4083 pExtent->FileOffset.LowPart,
4084 pExtent->CacheOffset.HighPart,
4085 pExtent->CacheOffset.LowPart);
4086 OutputDebugStringA( dbgstr);
4089 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4090 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4091 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4093 if (pExtent->Flags || ReleaseFileExtentsResultCB->Flags) {
4094 lock_ObtainMutex(&bufp->mx);
4095 if ( (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
4096 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
4098 if (bufp->qFlags & CM_BUF_QREDIR) {
4099 lock_ObtainWrite(&buf_globalLock);
4100 if (bufp->qFlags & CM_BUF_QREDIR) {
4101 buf_RemoveFromRedirQueue(scp, bufp);
4102 buf_ReleaseLocked(bufp, TRUE);
4104 lock_ReleaseWrite(&buf_globalLock);
4108 snprintf(dbgstr, 1024,
4109 "RDR_ProcessReleaseFileExtentsResult extent released: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4110 Fid.volume, Fid.vnode, Fid.unique,
4111 pExtent->FileOffset.HighPart,
4112 pExtent->FileOffset.LowPart,
4113 pExtent->CacheOffset.HighPart,
4114 pExtent->CacheOffset.LowPart);
4115 OutputDebugStringA( dbgstr);
4120 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
4121 Fid.volume, Fid.vnode,
4122 pExtent->FileOffset.HighPart,
4123 pExtent->FileOffset.LowPart);
4124 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4125 pExtent->CacheOffset.HighPart,
4126 pExtent->CacheOffset.LowPart);
4128 snprintf(dbgstr, 1024,
4129 "RDR_ProcessReleaseFileExtentsResult not released! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4130 Fid.volume, Fid.vnode, Fid.unique,
4131 pExtent->FileOffset.HighPart,
4132 pExtent->FileOffset.LowPart,
4133 pExtent->CacheOffset.HighPart,
4134 pExtent->CacheOffset.LowPart);
4135 OutputDebugStringA( dbgstr);
4139 if ((ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
4140 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY))
4142 #ifdef VALIDATE_CHECK_SUM
4143 if ( buf_ValidateCheckSum(bufp) ) {
4145 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4146 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4147 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
4149 buf_ComputeCheckSum(bufp);
4151 HexCheckSum(md5dbg3, sizeof(md5dbg), bufp->md5cksum);
4153 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
4155 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
4158 snprintf(dbgstr, 1024,
4159 "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",
4161 Fid.volume, Fid.vnode, Fid.unique,
4162 pExtent->FileOffset.HighPart,
4163 pExtent->FileOffset.LowPart,
4164 pExtent->CacheOffset.HighPart,
4165 pExtent->CacheOffset.LowPart);
4166 OutputDebugStringA( dbgstr);
4169 "RDR_ProcessReleaseFileExtentsResult dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
4170 Fid.volume, Fid.vnode,
4171 pExtent->FileOffset.HighPart,
4172 pExtent->FileOffset.LowPart);
4174 "... coffset 0x%x:%x",
4175 pExtent->CacheOffset.HighPart,
4176 pExtent->CacheOffset.LowPart);
4179 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4184 snprintf(dbgstr, 1024,
4185 "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",
4186 md5dbg, md5dbg2, md5dbg3,
4187 Fid.volume, Fid.vnode, Fid.unique,
4188 pExtent->FileOffset.HighPart,
4189 pExtent->FileOffset.LowPart,
4190 pExtent->CacheOffset.HighPart,
4191 pExtent->CacheOffset.LowPart);
4192 OutputDebugStringA( dbgstr);
4195 "RDR_ProcessReleaseFileExtentsResult dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
4196 Fid.volume, Fid.vnode,
4197 pExtent->FileOffset.HighPart,
4198 pExtent->FileOffset.LowPart);
4200 "... coffset 0x%x:%x",
4201 pExtent->CacheOffset.HighPart,
4202 pExtent->CacheOffset.LowPart);
4206 #else /* !VALIDATE_CHECK_SUM */
4208 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4212 snprintf(dbgstr, 1024,
4213 "RDR_ProcessReleaseFileExtentsResult dirty! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4214 Fid.volume, Fid.vnode, Fid.unique,
4215 pExtent->FileOffset.HighPart,
4216 pExtent->FileOffset.LowPart,
4217 pExtent->CacheOffset.HighPart,
4218 pExtent->CacheOffset.LowPart);
4219 OutputDebugStringA( dbgstr);
4221 #endif /* VALIDATE_CHECK_SUM */
4223 #ifdef VALIDATE_CHECK_SUM
4226 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
4228 if (!buf_ValidateCheckSum(bufp) ) {
4229 buf_ComputeCheckSum(bufp);
4231 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4232 snprintf(dbgstr, 1024,
4233 "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",
4235 Fid.volume, Fid.vnode, Fid.unique,
4236 pExtent->FileOffset.HighPart,
4237 pExtent->FileOffset.LowPart,
4238 pExtent->CacheOffset.HighPart,
4239 pExtent->CacheOffset.LowPart);
4240 OutputDebugStringA( dbgstr);
4242 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult dirty flag NOT set but extent has changed! vol 0x%x vno 0x%x foffset 0x%x:%x",
4243 Fid.volume, Fid.vnode,
4244 pExtent->FileOffset.HighPart,
4245 pExtent->FileOffset.LowPart);
4246 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4247 pExtent->CacheOffset.HighPart,
4248 pExtent->CacheOffset.LowPart);
4253 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4257 buf_ComputeCheckSum(bufp);
4259 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4260 snprintf(dbgstr, 1024,
4261 "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",
4263 Fid.volume, Fid.vnode, Fid.unique,
4264 pExtent->FileOffset.HighPart,
4265 pExtent->FileOffset.LowPart,
4266 pExtent->CacheOffset.HighPart,
4267 pExtent->CacheOffset.LowPart);
4268 OutputDebugStringA( dbgstr);
4272 #endif /* VALIDATE_CHECK_SUM */
4273 lock_ReleaseMutex(&bufp->mx);
4277 /* CacheOffset doesn't match bufp->datap */
4278 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
4281 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
4282 if (wbp->datap == datap)
4287 snprintf(dbgstr, 1024,
4288 "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",
4289 Fid.volume, Fid.vnode, Fid.unique,
4290 pExtent->FileOffset.HighPart,
4291 pExtent->FileOffset.LowPart,
4292 pExtent->CacheOffset.HighPart,
4293 pExtent->CacheOffset.LowPart,
4295 OutputDebugStringA( dbgstr);
4297 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4298 Fid.volume, Fid.vnode,
4299 pExtent->FileOffset.HighPart,
4300 pExtent->FileOffset.LowPart);
4301 osi_Log3(afsd_logp, "... coffset 0x%x:%x flags 0x%x",
4302 pExtent->CacheOffset.HighPart,
4303 pExtent->CacheOffset.LowPart,
4306 osi_Log5(afsd_logp, "... coffset belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
4307 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
4309 osi_Log0(afsd_logp, "... coffset cannot be found");
4316 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4317 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4318 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
4319 pExtent->FileOffset.LowPart);
4320 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; cm_buf not found -- recycled?",
4321 pExtent->CacheOffset.HighPart,
4322 pExtent->CacheOffset.LowPart);
4328 snprintf(dbgstr, 1024,
4329 "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4330 Fid.volume, Fid.vnode, Fid.unique,
4331 pExtent->FileOffset.HighPart,
4332 pExtent->FileOffset.LowPart,
4333 pExtent->CacheOffset.HighPart,
4334 pExtent->CacheOffset.LowPart);
4335 OutputDebugStringA( dbgstr);
4337 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x foffset 0x%x:%x",
4338 Fid.volume, Fid.vnode,
4339 pExtent->FileOffset.HighPart,
4340 pExtent->FileOffset.LowPart);
4341 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4342 pExtent->CacheOffset.HighPart,
4343 pExtent->CacheOffset.LowPart);
4348 osi_hyper_t offset = {0,0};
4349 afs_uint32 length = 0;
4352 * there is at least one dirty extent on this file. queue up background store
4353 * requests for contiguous blocks
4355 for ( extentno = 0; extentno < pFileCB->ExtentCount; extentno++ ) {
4356 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4357 if (pExtent->FileOffset.QuadPart == offset.QuadPart + length &&
4358 length < cm_chunkSize) {
4359 length += cm_data.buf_blockSize;
4361 if (!(offset.QuadPart == 0 && length == 0))
4362 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4363 length, 0, userp, &req);
4364 offset.QuadPart = pExtent->FileOffset.QuadPart;
4365 length = cm_data.buf_blockSize;
4368 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4369 length, 0, userp, &req);
4372 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
4373 Fid.cell, Fid.volume, Fid.vnode, Fid.unique, released);
4377 cm_ReleaseUser(userp);
4379 cm_ReleaseSCache(scp);
4381 p = (char *)pFileCB;
4382 p += sizeof(AFSReleaseFileExtentsResultFileCB);
4383 p += sizeof(AFSFileExtentCB) * (pFileCB->ExtentCount - 1);
4384 pNextFileCB = (AFSReleaseFileExtentsResultFileCB *)p;
4387 if (total_extents == 0) {
4388 osi_Log0(afsd_logp, "RDR_ProcessReleaseFileExtentsResult is empty");
4389 code = CM_ERROR_RETRY;
4393 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult FAILURE code=0x%x", code);
4395 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult DONE code=0x%x", code);
4401 RDR_ReleaseFailedSetFileExtents( IN cm_user_t *userp,
4402 IN AFSSetFileExtentsCB *SetFileExtentsResultCB,
4403 IN DWORD ResultBufferLength)
4405 afs_uint32 code = 0;
4407 unsigned int extentno;
4409 cm_scache_t * scp = NULL;
4414 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFileExtents %d.%d.%d.%d",
4415 SetFileExtentsResultCB->FileId.Cell, SetFileExtentsResultCB->FileId.Volume,
4416 SetFileExtentsResultCB->FileId.Vnode, SetFileExtentsResultCB->FileId.Unique);
4418 /* Process the release */
4419 Fid.cell = SetFileExtentsResultCB->FileId.Cell;
4420 Fid.volume = SetFileExtentsResultCB->FileId.Volume;
4421 Fid.vnode = SetFileExtentsResultCB->FileId.Vnode;
4422 Fid.unique = SetFileExtentsResultCB->FileId.Unique;
4423 Fid.hash = SetFileExtentsResultCB->FileId.Hash;
4425 if (Fid.cell == 0) {
4426 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFile Invalid FID %d.%d.%d.%d",
4427 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
4428 code = CM_ERROR_INVAL;
4432 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
4434 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents cm_GetSCache FID failure code=0x%x",
4436 /* Failure to find the cm_scache object cannot block return of the extents */
4439 for ( extentno = 0; extentno < SetFileExtentsResultCB->ExtentCount; extentno++ ) {
4442 AFSFileExtentCB *pExtent = &SetFileExtentsResultCB->FileExtents[extentno];
4444 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4446 bufp = buf_Find(&Fid, &thyper);
4448 osi_Log5(afsd_logp, "RDR_ReleaseFailedSetFileExtents bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4449 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4450 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4452 lock_ObtainMutex(&bufp->mx);
4453 if (bufp->qFlags & CM_BUF_QREDIR) {
4454 lock_ObtainWrite(&buf_globalLock);
4455 if (bufp->qFlags & CM_BUF_QREDIR) {
4456 buf_RemoveFromRedirQueue(scp, bufp);
4457 buf_ReleaseLocked(bufp, TRUE);
4459 lock_ReleaseWrite(&buf_globalLock);
4461 lock_ReleaseMutex(&bufp->mx);
4468 cm_ReleaseUser(userp);
4470 cm_ReleaseSCache(scp);
4472 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents DONE code=0x%x", code);
4477 RDR_PioctlOpen( IN cm_user_t *userp,
4478 IN AFSFileID ParentId,
4479 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4481 IN DWORD ResultBufferLength,
4482 IN OUT AFSCommResult **ResultCB)
4487 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4493 sizeof( AFSCommResult));
4495 /* Get the active directory */
4496 ParentFid.cell = ParentId.Cell;
4497 ParentFid.volume = ParentId.Volume;
4498 ParentFid.vnode = ParentId.Vnode;
4499 ParentFid.unique = ParentId.Unique;
4500 ParentFid.hash = ParentId.Hash;
4502 /* Get the root directory */
4503 RootFid.cell = pPioctlCB->RootId.Cell;
4504 RootFid.volume = pPioctlCB->RootId.Volume;
4505 RootFid.vnode = pPioctlCB->RootId.Vnode;
4506 RootFid.unique = pPioctlCB->RootId.Unique;
4507 RootFid.hash = pPioctlCB->RootId.Hash;
4509 /* Create the pioctl index */
4510 RDR_SetupIoctl(pPioctlCB->RequestId, &ParentFid, &RootFid, userp);
4517 RDR_PioctlClose( IN cm_user_t *userp,
4518 IN AFSFileID ParentId,
4519 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4521 IN DWORD ResultBufferLength,
4522 IN OUT AFSCommResult **ResultCB)
4524 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4530 sizeof( AFSCommResult));
4532 /* Cleanup the pioctl index */
4533 RDR_CleanupIoctl(pPioctlCB->RequestId);
4540 RDR_PioctlWrite( IN cm_user_t *userp,
4541 IN AFSFileID ParentId,
4542 IN AFSPIOCtlIORequestCB *pPioctlCB,
4544 IN DWORD ResultBufferLength,
4545 IN OUT AFSCommResult **ResultCB)
4547 AFSPIOCtlIOResultCB *pResultCB;
4548 cm_scache_t *dscp = NULL;
4555 req.flags |= CM_REQ_WOW64;
4557 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4563 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4565 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4567 code = RDR_IoctlWrite(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer, &req);
4569 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4570 (*ResultCB)->ResultStatus = status;
4574 pResultCB->BytesProcessed = pPioctlCB->BufferLength;
4575 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4579 RDR_PioctlRead( IN cm_user_t *userp,
4580 IN AFSFileID ParentId,
4581 IN AFSPIOCtlIORequestCB *pPioctlCB,
4583 IN BOOL bIsLocalSystem,
4584 IN DWORD ResultBufferLength,
4585 IN OUT AFSCommResult **ResultCB)
4587 AFSPIOCtlIOResultCB *pResultCB;
4588 cm_scache_t *dscp = NULL;
4592 afs_uint32 pflags = (bIsLocalSystem ? AFSCALL_FLAG_LOCAL_SYSTEM : 0);
4596 req.flags |= CM_REQ_WOW64;
4598 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4604 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4606 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4608 code = RDR_IoctlRead(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer,
4609 &pResultCB->BytesProcessed, &req, pflags);
4611 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4612 (*ResultCB)->ResultStatus = status;
4616 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4620 RDR_ByteRangeLockSync( IN cm_user_t *userp,
4621 IN AFSFileID FileId,
4622 IN AFSByteRangeLockRequestCB *pBRLRequestCB,
4624 IN DWORD ResultBufferLength,
4625 IN OUT AFSCommResult **ResultCB)
4627 AFSByteRangeLockResultCB *pResultCB = NULL;
4628 LARGE_INTEGER ProcessId;
4630 cm_scache_t *scp = NULL;
4638 ProcessId.QuadPart = pBRLRequestCB->ProcessId;
4642 req.flags |= CM_REQ_WOW64;
4644 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4645 FileId.Cell, FileId.Volume,
4646 FileId.Vnode, FileId.Unique);
4647 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4648 ProcessId.HighPart, ProcessId.LowPart);
4650 Length = sizeof( AFSByteRangeLockResultCB) + ((pBRLRequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4651 if (Length > ResultBufferLength) {
4652 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4655 memset( *ResultCB, 0, sizeof(AFSCommResult));
4656 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4660 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4663 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4664 (*ResultCB)->ResultBufferLength = Length;
4666 pResultCB = (AFSByteRangeLockResultCB *)(*ResultCB)->ResultData;
4667 pResultCB->FileId = FileId;
4668 pResultCB->Count = pBRLRequestCB->Count;
4670 /* Allocate the extents from the buffer package */
4671 Fid.cell = FileId.Cell;
4672 Fid.volume = FileId.Volume;
4673 Fid.vnode = FileId.Vnode;
4674 Fid.unique = FileId.Unique;
4675 Fid.hash = FileId.Hash;
4677 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
4679 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4680 (*ResultCB)->ResultStatus = status;
4681 (*ResultCB)->ResultBufferLength = 0;
4682 osi_Log2(afsd_logp, "RDR_ByteRangeLockSync cm_GetSCache FID failure code=0x%x status=0x%x",
4687 lock_ObtainWrite(&scp->rw);
4689 /* start by looking up the file's end */
4690 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4691 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4693 lock_ReleaseWrite(&scp->rw);
4694 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4695 (*ResultCB)->ResultStatus = status;
4696 (*ResultCB)->ResultBufferLength = 0;
4697 osi_Log3(afsd_logp, "RDR_ByteRangeLockSync cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4702 /* the scp is now locked and current */
4703 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4705 for ( i=0; i<pBRLRequestCB->Count; i++ ) {
4706 pResultCB->Result[i].LockType = pBRLRequestCB->Request[i].LockType;
4707 pResultCB->Result[i].Offset = pBRLRequestCB->Request[i].Offset;
4708 pResultCB->Result[i].Length = pBRLRequestCB->Request[i].Length;
4711 pBRLRequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4712 pBRLRequestCB->Request[i].Offset,
4713 pBRLRequestCB->Request[i].Length,
4714 key, 0, userp, &req, NULL);
4717 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4719 pBRLRequestCB->Request[i].LockType,
4720 pBRLRequestCB->Request[i].Offset.HighPart,
4721 pBRLRequestCB->Request[i].Offset.LowPart);
4722 osi_Log2(afsd_logp, "... length 0x%x:%x",
4723 pBRLRequestCB->Request[i].Length.HighPart,
4724 pBRLRequestCB->Request[i].Length.LowPart);
4729 pResultCB->Result[i].Status = 0;
4731 case CM_ERROR_WOULDBLOCK:
4732 pResultCB->Result[i].Status = STATUS_FILE_LOCK_CONFLICT;
4735 pResultCB->Result[i].Status = STATUS_LOCK_NOT_GRANTED;
4739 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4740 lock_ReleaseWrite(&scp->rw);
4741 cm_ReleaseSCache(scp);
4743 (*ResultCB)->ResultStatus = 0;
4744 osi_Log0(afsd_logp, "RDR_ByteRangeLockSync SUCCESS");
4749 RDR_ByteRangeUnlock( IN cm_user_t *userp,
4750 IN AFSFileID FileId,
4751 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4753 IN DWORD ResultBufferLength,
4754 IN OUT AFSCommResult **ResultCB)
4756 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4757 LARGE_INTEGER ProcessId;
4759 cm_scache_t *scp = NULL;
4767 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4771 req.flags |= CM_REQ_WOW64;
4773 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4774 FileId.Cell, FileId.Volume,
4775 FileId.Vnode, FileId.Unique);
4776 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4777 ProcessId.HighPart, ProcessId.LowPart);
4779 Length = sizeof( AFSByteRangeUnlockResultCB) + ((pBRURequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4780 if (Length > ResultBufferLength) {
4781 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4784 memset( *ResultCB, 0, sizeof(AFSCommResult));
4785 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4789 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4792 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4793 (*ResultCB)->ResultBufferLength = Length;
4795 pResultCB = (AFSByteRangeUnlockResultCB *)(*ResultCB)->ResultData;
4796 pResultCB->Count = pBRURequestCB->Count;
4798 /* Allocate the extents from the buffer package */
4799 Fid.cell = FileId.Cell;
4800 Fid.volume = FileId.Volume;
4801 Fid.vnode = FileId.Vnode;
4802 Fid.unique = FileId.Unique;
4803 Fid.hash = FileId.Hash;
4805 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
4807 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4808 (*ResultCB)->ResultStatus = status;
4809 (*ResultCB)->ResultBufferLength = 0;
4810 osi_Log2(afsd_logp, "RDR_ByteRangeUnlock cm_GetSCache FID failure code=0x%x status=0x%x",
4815 lock_ObtainWrite(&scp->rw);
4817 /* start by looking up the file's end */
4818 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4819 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4821 lock_ReleaseWrite(&scp->rw);
4822 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4823 (*ResultCB)->ResultStatus = status;
4824 (*ResultCB)->ResultBufferLength = 0;
4825 osi_Log3(afsd_logp, "RDR_ByteRangeUnlock cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4830 /* the scp is now locked and current */
4831 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4833 for ( i=0; i<pBRURequestCB->Count; i++ ) {
4834 pResultCB->Result[i].LockType = pBRURequestCB->Request[i].LockType;
4835 pResultCB->Result[i].Offset = pBRURequestCB->Request[i].Offset;
4836 pResultCB->Result[i].Length = pBRURequestCB->Request[i].Length;
4838 code = cm_Unlock(scp,
4839 pBRURequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4840 pBRURequestCB->Request[i].Offset,
4841 pBRURequestCB->Request[i].Length,
4842 key, CM_UNLOCK_FLAG_MATCH_RANGE, userp, &req);
4845 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4846 code, pBRURequestCB->Request[i].LockType,
4847 pBRURequestCB->Request[i].Offset.HighPart,
4848 pBRURequestCB->Request[i].Offset.LowPart);
4849 osi_Log2(afsd_logp, "... length 0x%x:%x",
4850 pBRURequestCB->Request[i].Length.HighPart,
4851 pBRURequestCB->Request[i].Length.LowPart);
4853 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4854 pResultCB->Result[i].Status = status;
4857 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4858 lock_ReleaseWrite(&scp->rw);
4859 cm_ReleaseSCache(scp);
4861 (*ResultCB)->ResultStatus = 0;
4862 osi_Log0(afsd_logp, "RDR_ByteRangeUnlock SUCCESS");
4867 RDR_ByteRangeUnlockAll( IN cm_user_t *userp,
4868 IN AFSFileID FileId,
4869 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4871 IN DWORD ResultBufferLength,
4872 IN OUT AFSCommResult **ResultCB)
4874 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4875 LARGE_INTEGER ProcessId;
4876 cm_scache_t *scp = NULL;
4883 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4887 req.flags |= CM_REQ_WOW64;
4889 osi_Log4(afsd_logp, "RDR_ByteRangeUnlockAll File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4890 FileId.Cell, FileId.Volume,
4891 FileId.Vnode, FileId.Unique);
4892 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4893 ProcessId.HighPart, ProcessId.LowPart);
4895 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4898 memset( *ResultCB, '\0', sizeof( AFSCommResult));
4899 (*ResultCB)->ResultBufferLength = 0;
4901 /* Allocate the extents from the buffer package */
4902 Fid.cell = FileId.Cell;
4903 Fid.volume = FileId.Volume;
4904 Fid.vnode = FileId.Vnode;
4905 Fid.unique = FileId.Unique;
4906 Fid.hash = FileId.Hash;
4908 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
4910 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4911 (*ResultCB)->ResultStatus = status;
4912 (*ResultCB)->ResultBufferLength = 0;
4913 osi_Log2(afsd_logp, "RDR_ByteRangeUnlockAll cm_GetSCache FID failure code=0x%x status=0x%x",
4918 lock_ObtainWrite(&scp->rw);
4920 /* start by looking up the file's end */
4921 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4922 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4924 lock_ReleaseWrite(&scp->rw);
4925 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4926 (*ResultCB)->ResultStatus = status;
4927 (*ResultCB)->ResultBufferLength = 0;
4928 osi_Log3(afsd_logp, "RDR_ByteRangeUnlockAll cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4933 /* the scp is now locked and current */
4934 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4936 code = cm_UnlockByKey(scp, key, 0, userp, &req);
4938 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4939 lock_ReleaseWrite(&scp->rw);
4940 cm_ReleaseSCache(scp);
4942 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4943 (*ResultCB)->ResultStatus = status;
4946 osi_Log1(afsd_logp, "RDR_ByteRangeUnlockAll FAILURE code 0x%x", code);
4948 osi_Log0(afsd_logp, "RDR_ByteRangeUnlockAll SUCCESS");
4954 RDR_GetVolumeInfo( IN cm_user_t *userp,
4955 IN AFSFileID FileId,
4957 IN DWORD ResultBufferLength,
4958 IN OUT AFSCommResult **ResultCB)
4960 AFSVolumeInfoCB *pResultCB = NULL;
4962 cm_scache_t *scp = NULL;
4963 cm_volume_t *volp = NULL;
4964 cm_vol_state_t *volstatep = NULL;
4966 cm_cell_t *cellp = NULL;
4971 FILETIME ft = {0x832cf000, 0x01abfcc4}; /* October 1, 1982 00:00:00 +0600 */
4973 char volName[32]="(unknown)";
4974 char offLineMsg[256]="server temporarily inaccessible";
4975 char motd[256]="server temporarily inaccessible";
4977 AFSFetchVolumeStatus volStat;
4981 struct rx_connection * rxconnp;
4985 req.flags |= CM_REQ_WOW64;
4987 osi_Log4(afsd_logp, "RDR_GetVolumeInfo File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4988 FileId.Cell, FileId.Volume,
4989 FileId.Vnode, FileId.Unique);
4991 Length = sizeof( AFSCommResult) + sizeof(AFSVolumeInfoCB);
4992 if (sizeof(AFSVolumeInfoCB) > ResultBufferLength) {
4993 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
4996 memset( *ResultCB, 0, sizeof(AFSCommResult));
4997 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5001 *ResultCB = (AFSCommResult *)malloc( Length );
5004 memset( *ResultCB, '\0', Length );
5005 (*ResultCB)->ResultBufferLength = sizeof(AFSVolumeInfoCB);
5006 pResultCB = (AFSVolumeInfoCB *)(*ResultCB)->ResultData;
5008 if (FileId.Cell != 0) {
5009 cm_SetFid(&Fid, FileId.Cell, FileId.Volume, 1, 1);
5010 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
5012 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5013 (*ResultCB)->ResultStatus = status;
5014 (*ResultCB)->ResultBufferLength = 0;
5015 osi_Log2(afsd_logp, "RDR_GetVolumeInfo cm_GetSCache FID failure code=0x%x status=0x%x",
5020 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
5021 osi_Log0(afsd_logp, "RDR_GetVolumeInfo Object Name Invalid - Cell = 0");
5024 lock_ObtainWrite(&scp->rw);
5026 code = cm_SyncOp(scp, NULL, userp, &req, 0,
5027 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5029 lock_ReleaseWrite(&scp->rw);
5030 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5031 (*ResultCB)->ResultStatus = status;
5032 (*ResultCB)->ResultBufferLength = 0;
5033 osi_Log3(afsd_logp, "RDR_GetVolumeInfo cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
5038 pResultCB->SectorsPerAllocationUnit = 1;
5039 pResultCB->BytesPerSector = 1024;
5041 pResultCB->CellID = scp->fid.cell;
5042 pResultCB->VolumeID = scp->fid.volume;
5043 pResultCB->Characteristics = FILE_REMOTE_DEVICE;
5044 pResultCB->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK |
5045 FILE_SUPPORTS_REPARSE_POINTS;
5047 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
5048 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)
5050 pResultCB->TotalAllocationUnits.QuadPart = 100;
5051 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
5053 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5054 pResultCB->Characteristics |= FILE_READ_ONLY_DEVICE;
5056 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( "Freelance.Local.Root", -1, pResultCB->VolumeLabel,
5057 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5058 if ( pResultCB->VolumeLabelLength )
5059 pResultCB->VolumeLabelLength--;
5061 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
5063 volp = cm_GetVolumeByFID(&scp->fid);
5065 code = CM_ERROR_NOSUCHVOLUME;
5068 volstatep = cm_VolumeStateByID(volp, scp->fid.volume);
5069 volType = cm_VolumeType(volp, scp->fid.volume);
5071 pResultCB->Characteristics |= ((volType == ROVOL || volType == BACKVOL) ? FILE_READ_ONLY_DEVICE : 0);
5074 OfflineMsg = offLineMsg;
5076 lock_ReleaseWrite(&scp->rw);
5078 code = cm_ConnFromFID(&scp->fid, userp, &req, &connp);
5081 rxconnp = cm_GetRxConn(connp);
5082 code = RXAFS_GetVolumeStatus(rxconnp, scp->fid.volume,
5083 &volStat, &Name, &OfflineMsg, &MOTD);
5084 rx_PutConnection(rxconnp);
5086 } while (cm_Analyze(connp, userp, &req, &scp->fid, 0, NULL, NULL, NULL, code));
5087 code = cm_MapRPCError(code, &req);
5089 if (volStat.MaxQuota)
5091 pResultCB->TotalAllocationUnits.QuadPart = volStat.MaxQuota;
5092 if (volType == ROVOL || volType == BACKVOL) {
5093 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5097 pResultCB->AvailableAllocationUnits.QuadPart =
5098 min(volStat.MaxQuota - volStat.BlocksInUse, volStat.PartBlocksAvail);
5103 pResultCB->TotalAllocationUnits.QuadPart = volStat.PartMaxBlocks;
5104 if (volType == ROVOL || volType == BACKVOL) {
5105 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5109 pResultCB->AvailableAllocationUnits.QuadPart = volStat.PartBlocksAvail;
5113 pResultCB->TotalAllocationUnits.QuadPart = 0x7FFFFFFF;
5114 pResultCB->AvailableAllocationUnits.QuadPart = (volType == ROVOL || volType == BACKVOL) ? 0 : 0x3F000000;
5116 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( volp->namep, -1, pResultCB->VolumeLabel,
5117 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
5120 if ( pResultCB->VolumeLabelLength )
5121 pResultCB->VolumeLabelLength--;
5123 lock_ObtainWrite(&scp->rw);
5125 pResultCB->VolumeLabelLength *= sizeof(WCHAR); /* convert to bytes from chars */
5127 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5130 lock_ReleaseWrite(&scp->rw);
5133 cm_ReleaseSCache(scp);
5135 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5136 (*ResultCB)->ResultStatus = status;
5137 osi_Log0(afsd_logp, "RDR_GetVolumeInfo SUCCESS");
5142 RDR_GetVolumeSizeInfo( IN cm_user_t *userp,
5143 IN AFSFileID FileId,
5145 IN DWORD ResultBufferLength,
5146 IN OUT AFSCommResult **ResultCB)
5148 AFSVolumeSizeInfoCB *pResultCB = NULL;
5150 cm_scache_t *scp = NULL;
5151 cm_volume_t *volp = NULL;
5153 cm_cell_t *cellp = NULL;
5159 char volName[32]="(unknown)";
5160 char offLineMsg[256]="server temporarily inaccessible";
5161 char motd[256]="server temporarily inaccessible";
5163 AFSFetchVolumeStatus volStat;
5167 struct rx_connection * rxconnp;
5171 req.flags |= CM_REQ_WOW64;
5173 osi_Log4(afsd_logp, "RDR_GetVolumeSizeInfo File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5174 FileId.Cell, FileId.Volume,
5175 FileId.Vnode, FileId.Unique);
5177 Length = sizeof( AFSCommResult) + sizeof(AFSVolumeSizeInfoCB);
5178 if (sizeof(AFSVolumeSizeInfoCB) > ResultBufferLength) {
5179 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5182 memset( *ResultCB, 0, sizeof(AFSCommResult));
5183 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5187 *ResultCB = (AFSCommResult *)malloc( Length );
5190 memset( *ResultCB, '\0', Length );
5191 (*ResultCB)->ResultBufferLength = sizeof(AFSVolumeSizeInfoCB);
5192 pResultCB = (AFSVolumeSizeInfoCB *)(*ResultCB)->ResultData;
5194 if (FileId.Cell != 0) {
5195 cm_SetFid(&Fid, FileId.Cell, FileId.Volume, 1, 1);
5196 code = cm_GetSCache(&Fid, NULL, &scp, userp, &req);
5198 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5199 (*ResultCB)->ResultStatus = status;
5200 (*ResultCB)->ResultBufferLength = 0;
5201 osi_Log2(afsd_logp, "RDR_GetVolumeSizeInfo cm_GetSCache FID failure code=0x%x status=0x%x",
5206 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
5207 osi_Log0(afsd_logp, "RDR_GetVolumeSizeInfo Object Name Invalid - Cell = 0");
5210 lock_ObtainWrite(&scp->rw);
5212 code = cm_SyncOp(scp, NULL, userp, &req, 0,
5213 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5215 lock_ReleaseWrite(&scp->rw);
5216 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5217 (*ResultCB)->ResultStatus = status;
5218 (*ResultCB)->ResultBufferLength = 0;
5219 osi_Log3(afsd_logp, "RDR_GetVolumeSizeInfo cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
5224 pResultCB->SectorsPerAllocationUnit = 1;
5225 pResultCB->BytesPerSector = 1024;
5227 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
5228 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)
5230 pResultCB->TotalAllocationUnits.QuadPart = 100;
5231 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5233 volp = cm_GetVolumeByFID(&scp->fid);
5235 code = CM_ERROR_NOSUCHVOLUME;
5239 volType = cm_VolumeType(volp, scp->fid.volume);
5241 OfflineMsg = offLineMsg;
5243 lock_ReleaseWrite(&scp->rw);
5245 code = cm_ConnFromFID(&scp->fid, userp, &req, &connp);
5248 rxconnp = cm_GetRxConn(connp);
5249 code = RXAFS_GetVolumeStatus(rxconnp, scp->fid.volume,
5250 &volStat, &Name, &OfflineMsg, &MOTD);
5251 rx_PutConnection(rxconnp);
5253 } while (cm_Analyze(connp, userp, &req, &scp->fid, 0, NULL, NULL, NULL, code));
5254 code = cm_MapRPCError(code, &req);
5256 if (volStat.MaxQuota)
5258 pResultCB->TotalAllocationUnits.QuadPart = volStat.MaxQuota;
5259 if (volType == ROVOL || volType == BACKVOL) {
5260 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5264 pResultCB->AvailableAllocationUnits.QuadPart =
5265 min(volStat.MaxQuota - volStat.BlocksInUse, volStat.PartBlocksAvail);
5270 pResultCB->TotalAllocationUnits.QuadPart = volStat.PartMaxBlocks;
5271 if (volType == ROVOL || volType == BACKVOL) {
5272 pResultCB->AvailableAllocationUnits.QuadPart = 0;
5276 pResultCB->AvailableAllocationUnits.QuadPart = volStat.PartBlocksAvail;
5281 pResultCB->TotalAllocationUnits.QuadPart = 0x7FFFFFFF;
5282 pResultCB->AvailableAllocationUnits.QuadPart = (volType == ROVOL || volType == BACKVOL) ? 0 : 0x3F000000;
5285 lock_ObtainWrite(&scp->rw);
5288 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
5291 lock_ReleaseWrite(&scp->rw);
5294 cm_ReleaseSCache(scp);
5296 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5297 (*ResultCB)->ResultStatus = status;
5298 osi_Log0(afsd_logp, "RDR_GetVolumeSizeInfo SUCCESS");
5303 RDR_HoldFid( IN cm_user_t *userp,
5304 IN AFSHoldFidRequestCB * pHoldFidCB,
5306 IN DWORD ResultBufferLength,
5307 IN OUT AFSCommResult **ResultCB)
5309 AFSHoldFidResultCB *pResultCB = NULL;
5316 osi_Log1(afsd_logp, "RDR_HoldFid Count=%u", pHoldFidCB->Count);
5318 Length = sizeof(AFSHoldFidResultCB) + (pHoldFidCB->Count-1) * sizeof(AFSFidResult);
5319 if (Length > ResultBufferLength) {
5320 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5323 memset( *ResultCB, 0, sizeof(AFSCommResult));
5324 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5327 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5330 memset( *ResultCB, '\0', Length );
5331 (*ResultCB)->ResultBufferLength = Length;
5332 pResultCB = (AFSHoldFidResultCB *)(*ResultCB)->ResultData;
5334 for ( index = 0; index < pHoldFidCB->Count; index++ )
5336 cm_scache_t *scp = NULL;
5339 Fid.cell = pResultCB->Result[index].FileID.Cell = pHoldFidCB->FileID[index].Cell;
5340 Fid.volume = pResultCB->Result[index].FileID.Volume = pHoldFidCB->FileID[index].Volume;
5341 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pHoldFidCB->FileID[index].Vnode;
5342 Fid.unique = pResultCB->Result[index].FileID.Unique = pHoldFidCB->FileID[index].Unique;
5343 Fid.hash = pResultCB->Result[index].FileID.Hash = pHoldFidCB->FileID[index].Hash;
5345 osi_Log4( afsd_logp,
5346 "RDR_HoldFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5347 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5349 scp = cm_FindSCache(&Fid);
5351 RDR_FlagScpInUse( scp, FALSE );
5352 cm_ReleaseSCache(scp);
5354 pResultCB->Result[index].Status = 0;
5357 (*ResultCB)->ResultStatus = 0;
5358 osi_Log0(afsd_logp, "RDR_HoldFid SUCCESS");
5363 RDR_ReleaseFid( IN cm_user_t *userp,
5364 IN AFSReleaseFidRequestCB * pReleaseFidCB,
5366 IN DWORD ResultBufferLength,
5367 IN OUT AFSCommResult **ResultCB)
5369 AFSReleaseFidResultCB *pResultCB = NULL;
5376 osi_Log1(afsd_logp, "RDR_ReleaseFid Count=%u", pReleaseFidCB->Count);
5378 Length = sizeof(AFSReleaseFidResultCB) + (pReleaseFidCB->Count ? pReleaseFidCB->Count-1 : 0) * sizeof(AFSFidResult);
5379 if (Length > ResultBufferLength) {
5380 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
5383 memset( *ResultCB, 0, sizeof(AFSCommResult));
5384 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
5387 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
5390 memset( *ResultCB, '\0', Length );
5391 (*ResultCB)->ResultBufferLength = Length;
5392 pResultCB = (AFSReleaseFidResultCB *)(*ResultCB)->ResultData;
5394 for ( index = 0; index < pReleaseFidCB->Count; index++ )
5396 cm_scache_t *scp = NULL;
5399 Fid.cell = pResultCB->Result[index].FileID.Cell = pReleaseFidCB->FileID[index].Cell;
5400 Fid.volume = pResultCB->Result[index].FileID.Volume = pReleaseFidCB->FileID[index].Volume;
5401 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pReleaseFidCB->FileID[index].Vnode;
5402 Fid.unique = pResultCB->Result[index].FileID.Unique = pReleaseFidCB->FileID[index].Unique;
5403 Fid.hash = pResultCB->Result[index].FileID.Hash = pReleaseFidCB->FileID[index].Hash;
5405 osi_Log4( afsd_logp,
5406 "RDR_ReleaseFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5407 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5409 scp = cm_FindSCache(&Fid);
5411 lock_ObtainWrite(&scp->rw);
5412 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
5413 lock_ReleaseWrite(&scp->rw);
5415 cm_ReleaseSCache(scp);
5417 pResultCB->Result[index].Status = 0;
5419 pResultCB->Count = pReleaseFidCB->Count;
5421 (*ResultCB)->ResultStatus = 0;
5422 osi_Log0(afsd_logp, "RDR_ReleaseFid SUCCESS");
5427 * The redirector makes several assumptions regarding the
5428 * SRVSVC and WKSSVC pipes transactions. First, the interface
5429 * versions are those indicated below. Secondly, the encoding
5430 * will be performed using NDR version 2. These assumptions
5431 * may not hold in the future and end-to-end MSRPC Bind
5432 * negotiations may need to be supported. Of course, these
5433 * are the only interface versions that are supported by the
5436 #define MSRPC_PIPE_PREFIX L".\\"
5438 static const UUID MSRPC_SRVSVC_UUID = {0x4B324FC8, 0x1670, 0x01D3,
5439 {0x12, 0x78, 0x5A, 0x47, 0xBF, 0x6E, 0xE1, 0x88}};
5440 #define MSRPC_SRVSVC_NAME L"PIPE\\SRVSVC"
5441 #define MSRPC_SRVSVC_VERS 3
5443 static const UUID MSRPC_WKSSVC_UUID = {0x6BFFD098, 0xA112, 0x3610,
5444 {0x98, 0x33, 0x46, 0xC3, 0xF8, 0x7E, 0x34, 0x5A}};
5445 #define MSRPC_WKSSVC_NAME L"PIPE\\WKSSVC"
5446 #define MSRPC_WKSSVC_VERS 1
5448 static const UUID MSRPC_NDR_UUID = {0x8A885D04, 0x1CEB, 0x11C9,
5449 {0x9F, 0xE8, 0x08, 0x00, 0x2B, 0x10, 0x48, 0x60}};
5450 #define MSRPC_NDR_NAME L"NDR"
5451 #define MSRPC_NDR_VERS 2
5453 extern RPC_IF_HANDLE srvsvc_v3_0_s_ifspec;
5454 extern RPC_IF_HANDLE wkssvc_v1_0_s_ifspec;
5457 RDR_PipeOpen( IN cm_user_t *userp,
5458 IN AFSFileID ParentId,
5460 IN DWORD NameLength,
5461 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5463 IN DWORD ResultBufferLength,
5464 IN OUT AFSCommResult **ResultCB)
5469 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5475 sizeof( AFSCommResult));
5477 /* Get the active directory */
5478 ParentFid.cell = ParentId.Cell;
5479 ParentFid.volume = ParentId.Volume;
5480 ParentFid.vnode = ParentId.Vnode;
5481 ParentFid.unique = ParentId.Unique;
5482 ParentFid.hash = ParentId.Hash;
5484 /* Get the root directory */
5485 RootFid.cell = pPipe_CB->RootId.Cell;
5486 RootFid.volume = pPipe_CB->RootId.Volume;
5487 RootFid.vnode = pPipe_CB->RootId.Vnode;
5488 RootFid.unique = pPipe_CB->RootId.Unique;
5489 RootFid.hash = pPipe_CB->RootId.Hash;
5491 /* Create the pipe index */
5492 (*ResultCB)->ResultStatus =
5493 RDR_SetupPipe( pPipe_CB->RequestId, &ParentFid, &RootFid,
5494 Name, NameLength, userp);
5500 RDR_PipeClose( IN cm_user_t *userp,
5501 IN AFSFileID ParentId,
5502 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5504 IN DWORD ResultBufferLength,
5505 IN OUT AFSCommResult **ResultCB)
5507 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5513 sizeof( AFSCommResult));
5515 /* Cleanup the pipe index */
5516 RDR_CleanupPipe(pPipe_CB->RequestId);
5523 RDR_PipeWrite( IN cm_user_t *userp,
5524 IN AFSFileID ParentId,
5525 IN AFSPipeIORequestCB *pPipe_CB,
5526 IN BYTE *pPipe_Data,
5528 IN DWORD ResultBufferLength,
5529 IN OUT AFSCommResult **ResultCB)
5531 AFSPipeIOResultCB *pResultCB;
5532 cm_scache_t *dscp = NULL;
5539 req.flags |= CM_REQ_WOW64;
5541 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5547 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5549 pResultCB = (AFSPipeIOResultCB *)(*ResultCB)->ResultData;
5551 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_Data, &req, userp);
5553 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5554 (*ResultCB)->ResultStatus = status;
5558 pResultCB->BytesProcessed = pPipe_CB->BufferLength;
5559 (*ResultCB)->ResultBufferLength = sizeof( AFSPipeIOResultCB);
5564 RDR_PipeRead( IN cm_user_t *userp,
5565 IN AFSFileID ParentId,
5566 IN AFSPipeIORequestCB *pPipe_CB,
5568 IN DWORD ResultBufferLength,
5569 IN OUT AFSCommResult **ResultCB)
5572 cm_scache_t *dscp = NULL;
5579 req.flags |= CM_REQ_WOW64;
5581 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5587 sizeof( AFSCommResult));
5589 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5591 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_Data,
5592 &(*ResultCB)->ResultBufferLength, &req, userp);
5594 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5595 (*ResultCB)->ResultStatus = status;
5602 RDR_PipeSetInfo( IN cm_user_t *userp,
5603 IN AFSFileID ParentId,
5604 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5605 IN BYTE *pPipe_Data,
5607 IN DWORD ResultBufferLength,
5608 IN OUT AFSCommResult **ResultCB)
5610 cm_scache_t *dscp = NULL;
5616 req.flags |= CM_REQ_WOW64;
5618 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5624 sizeof( AFSCommResult));
5626 status = RDR_Pipe_SetInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5627 pPipeInfo_CB->BufferLength, pPipe_Data, &req, userp);
5629 (*ResultCB)->ResultStatus = status;
5634 RDR_PipeQueryInfo( IN cm_user_t *userp,
5635 IN AFSFileID ParentId,
5636 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5638 IN DWORD ResultBufferLength,
5639 IN OUT AFSCommResult **ResultCB)
5642 cm_scache_t *dscp = NULL;
5648 req.flags |= CM_REQ_WOW64;
5650 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5656 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5658 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5660 status = RDR_Pipe_QueryInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5661 ResultBufferLength, pPipe_Data,
5662 &(*ResultCB)->ResultBufferLength, &req, userp);
5664 (*ResultCB)->ResultStatus = status;
5668 RDR_PipeTransceive( IN cm_user_t *userp,
5669 IN AFSFileID ParentId,
5670 IN AFSPipeIORequestCB *pPipe_CB,
5671 IN BYTE *pPipe_InData,
5673 IN DWORD ResultBufferLength,
5674 IN OUT AFSCommResult **ResultCB)
5677 * This function processes a Pipe Service request
5678 * that would normally be sent to a LAN Manager server
5679 * across an authenticated SMB-PIPE/MSRPC/SVC request
5680 * stack. The request is being sent here because the
5681 * application (e.g., Explorer Shell or Common Control File
5682 * dialog) believes that because the UNC path it is
5683 * processing has specified a server name that is not
5684 * "." and that the Server is remote and that the Share
5685 * list cannot be obtained using the Network Provider
5688 * The file system driver is faking the Bind-Ack response
5689 * to the MSRPC Bind request but cannot decode the NDR
5690 * encoded Pipe Service requests. For that we will use
5691 * the service's MSRPC module. However, unlike the SMB
5692 * server usage we must fake the MSRPC Bind exchange and
5693 * map the PipeName to an interface instead of using the
5694 * GUID specified in the MSRPC Bind request.
5696 * None of the requests that are being processed by the
5697 * service require authentication. As a result the userp
5698 * parameter will be ignored.
5700 * Although there are dozens of Pipe Services, the only
5701 * ones that we are implementing are WKSSVC and SRVSVC.
5702 * These support NetShareEnum, NetShareGetInfo,
5703 * NetServerGetInfo, and NetWorkstaGetInfo which are
5704 * commonly queried by NET VIEW, the Explorer Shell,
5705 * and the Common Control File dialog.
5707 BYTE *pPipe_OutData;
5708 cm_scache_t *dscp = NULL;
5712 DWORD Length = ResultBufferLength + sizeof( AFSCommResult);
5716 req.flags |= CM_REQ_WOW64;
5718 *ResultCB = (AFSCommResult *)malloc( Length);
5721 memset( *ResultCB, '\0', Length );
5723 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_InData, &req, userp);
5725 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5726 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Write FAILURE code=0x%x status=0x%x",
5728 (*ResultCB)->ResultStatus = status;
5732 pPipe_OutData = (BYTE *)(*ResultCB)->ResultData;
5733 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_OutData,
5734 &(*ResultCB)->ResultBufferLength, &req, userp);
5736 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5737 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Read FAILURE code=0x%x status=0x%x",
5739 (*ResultCB)->ResultStatus = status;
5743 (*ResultCB)->ResultStatus = 0;
5744 osi_Log0(afsd_logp, "RDR_Pipe_Transceive SUCCESS");