2 * Copyright (c) 2008 Secure Endpoints, Inc.
3 * Copyright (c) 2009-2011 Your File System, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * - Neither the name of Secure Endpoints Inc. nor the names of its contributors
15 * may be used to endorse or promote products derived from this software without
16 * specific prior written permission from Secure Endpoints, Inc. and
17 * Your File System, Inc.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
23 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <afsconfig.h>
33 #include <afs/param.h>
36 #define _WIN32_WINNT 0x0500
38 #define _CRT_SECURE_NO_DEPRECATE
39 #define _CRT_NON_CONFORMING_SWPRINTFS
40 #define INITGUID /* define AFS_AUTH_GUID_NO_PAG */
43 #define WIN32_NO_STATUS
53 #pragma warning(disable: 4005)
57 #include "..\\Common\\AFSUserDefines.h"
58 #include "..\\Common\\AFSUserStructs.h"
76 #include <RDRPrototypes.h>
80 static CHAR * RDR_extentBaseAddress = NULL;
83 RDR_InitReq(cm_req_t *reqp)
86 reqp->flags |= CM_REQ_SOURCE_REDIR;
90 RDR_fid2FID( cm_fid_t *fid, AFSFileID *FileId)
92 FileId->Cell = fid->cell;
93 FileId->Volume = fid->volume;
94 FileId->Vnode = fid->vnode;
95 FileId->Unique = fid->unique;
96 FileId->Hash = fid->hash;
100 RDR_FID2fid( AFSFileID *FileId, cm_fid_t *fid)
102 fid->cell = FileId->Cell;
103 fid->volume = FileId->Volume;
104 fid->vnode = FileId->Vnode;
105 fid->unique = FileId->Unique;
106 fid->hash = FileId->Hash;
110 RDR_SetInitParams( OUT AFSRedirectorInitInfo **ppRedirInitInfo, OUT DWORD * pRedirInitInfoLen )
112 extern char cm_CachePath[];
113 extern cm_config_data_t cm_data;
114 extern int smb_hideDotFiles;
115 size_t cm_CachePathLen = strlen(cm_CachePath);
117 DWORD TempPathLen = ExpandEnvironmentStringsW(L"%TEMP%", NULL, 0);
118 MEMORYSTATUSEX memStatus;
119 DWORD maxMemoryCacheSize;
121 memStatus.dwLength = sizeof(memStatus);
122 if (GlobalMemoryStatusEx(&memStatus)) {
124 * Use the memory extent interface in the afs redirector
125 * whenever the cache size is less than equal to 10% of
126 * physical memory. Do not use too much because this memory
127 * will be locked by the redirector so it can't be swapped
130 maxMemoryCacheSize = (DWORD)(memStatus.ullTotalPhys / 1024 / 10);
133 * If we can't determine the amount of physical memory
134 * in the system, be conservative and limit the use of
135 * memory extent interface to 64MB data caches.
137 maxMemoryCacheSize = 65536;
140 *pRedirInitInfoLen = (DWORD) (sizeof(AFSRedirectorInitInfo) + (cm_CachePathLen + TempPathLen) * sizeof(WCHAR));
141 *ppRedirInitInfo = (AFSRedirectorInitInfo *)malloc(*pRedirInitInfoLen);
142 (*ppRedirInitInfo)->Flags = smb_hideDotFiles ? AFS_REDIR_INIT_FLAG_HIDE_DOT_FILES : 0;
143 (*ppRedirInitInfo)->MaximumChunkLength = cm_data.chunkSize;
144 (*ppRedirInitInfo)->GlobalFileId.Cell = cm_data.rootFid.cell;
145 (*ppRedirInitInfo)->GlobalFileId.Volume = cm_data.rootFid.volume;
146 (*ppRedirInitInfo)->GlobalFileId.Vnode = cm_data.rootFid.vnode;
147 (*ppRedirInitInfo)->GlobalFileId.Unique = cm_data.rootFid.unique;
148 (*ppRedirInitInfo)->GlobalFileId.Hash = cm_data.rootFid.hash;
149 (*ppRedirInitInfo)->ExtentCount.QuadPart = cm_data.buf_nbuffers;
150 (*ppRedirInitInfo)->CacheBlockSize = cm_data.blockSize;
151 (*ppRedirInitInfo)->MaxPathLinkCount = 512; /* this needs to become a registry value */
152 (*ppRedirInitInfo)->NameArrayLength = 32; /* this needs to become a registry value */
153 if (cm_virtualCache || cm_data.bufferSize <= maxMemoryCacheSize) {
154 osi_Log0(afsd_logp, "RDR_SetInitParams Initializing Memory Extent Interface");
155 (*ppRedirInitInfo)->MemoryCacheOffset.QuadPart = (LONGLONG)cm_data.bufDataBaseAddress;
156 (*ppRedirInitInfo)->MemoryCacheLength.QuadPart = cm_data.bufEndOfData - cm_data.bufDataBaseAddress;
157 (*ppRedirInitInfo)->CacheFileNameLength = 0;
158 RDR_extentBaseAddress = cm_data.bufDataBaseAddress;
160 (*ppRedirInitInfo)->MemoryCacheOffset.QuadPart = 0;
161 (*ppRedirInitInfo)->MemoryCacheLength.QuadPart = 0;
162 (*ppRedirInitInfo)->CacheFileNameLength = (ULONG) (cm_CachePathLen * sizeof(WCHAR));
163 err = mbstowcs((*ppRedirInitInfo)->CacheFileName, cm_CachePath, (cm_CachePathLen + 1) *sizeof(WCHAR));
165 free(*ppRedirInitInfo);
166 osi_Log0(afsd_logp, "RDR_SetInitParams Invalid Object Name");
167 return STATUS_OBJECT_NAME_INVALID;
169 RDR_extentBaseAddress = cm_data.baseAddress;
171 (*ppRedirInitInfo)->DumpFileLocationOffset = FIELD_OFFSET(AFSRedirectorInitInfo, CacheFileName) + (*ppRedirInitInfo)->CacheFileNameLength;
172 (*ppRedirInitInfo)->DumpFileLocationLength = (TempPathLen - 1) * sizeof(WCHAR);
173 ExpandEnvironmentStringsW(L"%TEMP%",
174 (LPWSTR)(((PBYTE)(*ppRedirInitInfo)) + (*ppRedirInitInfo)->DumpFileLocationOffset),
177 osi_Log0(afsd_logp,"RDR_SetInitParams Success");
182 RDR_GetLocalSystemUser( void)
185 cm_user_t *userp = NULL;
186 wchar_t cname[MAX_COMPUTERNAME_LENGTH+1];
187 int cnamelen = MAX_COMPUTERNAME_LENGTH+1;
189 GetComputerNameW(cname, &cnamelen);
192 unp = smb_FindUserByName(NTSID_LOCAL_SYSTEM, cname, SMB_FLAG_CREATE);
193 lock_ObtainMutex(&unp->mx);
195 unp->userp = cm_NewUser();
196 unp->flags |= SMB_USERNAMEFLAG_SID;
197 lock_ReleaseMutex(&unp->mx);
200 smb_ReleaseUsername(unp);
203 userp = cm_rootUserp;
211 RDR_UserFromCommRequest( IN AFSCommRequest *RequestBuffer)
214 return RDR_UserFromAuthGroup( &RequestBuffer->AuthGroup);
218 RDR_UserFromAuthGroup( IN GUID *pGuid)
221 cm_user_t * userp = NULL;
222 RPC_WSTR UuidString = NULL;
223 wchar_t cname[MAX_COMPUTERNAME_LENGTH+1];
224 int cnamelen = MAX_COMPUTERNAME_LENGTH+1;
226 if (UuidToStringW((UUID *)pGuid, &UuidString) != RPC_S_OK)
229 GetComputerNameW(cname, &cnamelen);
232 unp = smb_FindUserByName(UuidString, cname, SMB_FLAG_CREATE);
233 lock_ObtainMutex(&unp->mx);
235 unp->userp = cm_NewUser();
236 unp->flags |= SMB_USERNAMEFLAG_SID;
237 lock_ReleaseMutex(&unp->mx);
240 smb_ReleaseUsername(unp);
244 userp = cm_rootUserp;
248 osi_Log2(afsd_logp, "RDR_UserFromCommRequest Guid %S userp = 0x%p",
249 osi_LogSaveStringW(afsd_logp, UuidString),
253 RpcStringFreeW(&UuidString);
259 RDR_ReleaseUser( IN cm_user_t *userp )
261 osi_Log1(afsd_logp, "RDR_ReleaseUser userp = 0x%p", userp);
262 cm_ReleaseUser(userp);
267 * RDR_FlagScpInUse flags the scp with CM_SCACHEFLAG_RDR_IN_USE
270 RDR_FlagScpInUse( IN cm_scache_t *scp, IN BOOL bLocked )
273 lock_ObtainWrite(&scp->rw);
275 lock_AssertWrite(&scp->rw);
276 scp->flags |= CM_SCACHEFLAG_RDR_IN_USE;
279 lock_ReleaseWrite(&scp->rw);
283 * Obtain the status information for the specified object and
287 RDR_BulkStatLookup( cm_scache_t *dscp,
292 cm_direnum_t * enump = NULL;
296 code = cm_BeginDirOp(dscp, userp, reqp, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
298 code = cm_BPlusDirEnumerate(dscp, userp, reqp, TRUE, NULL, TRUE, &enump);
300 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BPlusDirEnumerate failure code=0x%x",
305 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BeginDirOp failure code=0x%x",
312 code = cm_BPlusDirEnumBulkStatOne(enump, scp);
314 osi_Log1(afsd_logp, "RDR_BulkStatLookup cm_BPlusDirEnumBulkStatOne failure code=0x%x",
317 cm_BPlusDirFreeEnumeration(enump);
324 #define RDR_POP_FOLLOW_MOUNTPOINTS 0x01
325 #define RDR_POP_EVALUATE_SYMLINKS 0x02
326 #define RDR_POP_WOW64 0x04
327 #define RDR_POP_NO_GETSTATUS 0x08
330 RDR_PopulateCurrentEntry( IN AFSDirEnumEntry * pCurrentEntry,
331 IN DWORD dwMaxEntryLength,
332 IN cm_scache_t * dscp,
333 IN cm_scache_t * scp,
334 IN cm_user_t * userp,
337 IN wchar_t * shortName,
339 OUT AFSDirEnumEntry **ppNextEntry,
340 OUT DWORD * pdwRemainingLength)
343 WCHAR * wname, *wtarget;
346 afs_uint32 code = 0, code2 = 0;
347 BOOL bMustFake = FALSE;
349 osi_Log5(afsd_logp, "RDR_PopulateCurrentEntry dscp=0x%p scp=0x%p name=%S short=%S flags=0x%x",
350 dscp, scp, osi_LogSaveStringW(afsd_logp, name),
351 osi_LogSaveStringW(afsd_logp, shortName), dwFlags);
352 osi_Log1(afsd_logp, "... maxLength=%d", dwMaxEntryLength);
354 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
356 *ppNextEntry = pCurrentEntry;
357 if (pdwRemainingLength)
358 *pdwRemainingLength = dwMaxEntryLength;
359 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry Not Enough Room for Entry %d < %d",
360 dwMaxEntryLength, sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t));
361 return CM_ERROR_TOOBIG;
369 dwEntryLength = sizeof(AFSDirEnumEntry);
371 lock_ObtainWrite(&scp->rw);
372 if (dwFlags & RDR_POP_NO_GETSTATUS) {
373 if (!cm_HaveCallback(scp))
376 #ifdef AFS_FREELANCE_CLIENT
377 if (scp->fid.cell == AFS_FAKE_ROOT_CELL_ID && scp->fid.volume == AFS_FAKE_ROOT_VOL_ID) {
379 * If the FID is from the Freelance Local Root always perform
380 * a single item status check.
382 code = cm_SyncOp( scp, NULL, userp, reqp, 0,
383 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
385 lock_ReleaseWrite(&scp->rw);
386 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_SyncOp failed for scp=0x%p code=0x%x",
394 * For non-Freelance objects, check to see if we have current
395 * status information. If not, perform a bulk status lookup of multiple
396 * entries in order to reduce the number of RPCs issued to the file server.
398 if ((scp->flags & CM_SCACHEFLAG_EACCESS))
400 else if (!cm_HaveCallback(scp)) {
401 lock_ReleaseWrite(&scp->rw);
402 code = RDR_BulkStatLookup(dscp, scp, userp, reqp);
404 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry RXR_BulkStatLookup failed for scp=0x%p code=0x%x",
408 lock_ObtainWrite(&scp->rw);
410 * RDR_BulkStatLookup can succeed but it may be the case that there
411 * still is not valid status info. If we get this far, generate fake
414 if (!cm_HaveCallback(scp))
421 /* Populate the real or fake data */
422 pCurrentEntry->FileId.Cell = scp->fid.cell;
423 pCurrentEntry->FileId.Volume = scp->fid.volume;
424 pCurrentEntry->FileId.Vnode = scp->fid.vnode;
425 pCurrentEntry->FileId.Unique = scp->fid.unique;
426 pCurrentEntry->FileId.Hash = scp->fid.hash;
428 pCurrentEntry->FileType = scp->fileType;
430 pCurrentEntry->DataVersion.QuadPart = scp->dataVersion;
432 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
433 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
434 cm_LargeSearchTimeFromUnixTime(&ft, MAX_AFS_UINT32);
436 cm_LargeSearchTimeFromUnixTime(&ft, scp->cbExpires);
438 pCurrentEntry->Expiration.LowPart = ft.dwLowDateTime;
439 pCurrentEntry->Expiration.HighPart = ft.dwHighDateTime;
442 /* 1969-12-31 23:59:59 +00 */
443 ft.dwHighDateTime = 0x19DB200;
444 ft.dwLowDateTime = 0x5BB78980;
446 cm_LargeSearchTimeFromUnixTime(&ft, scp->clientModTime);
447 pCurrentEntry->CreationTime.LowPart = ft.dwLowDateTime;
448 pCurrentEntry->CreationTime.HighPart = ft.dwHighDateTime;
449 pCurrentEntry->LastAccessTime = pCurrentEntry->CreationTime;
450 pCurrentEntry->LastWriteTime = pCurrentEntry->CreationTime;
451 pCurrentEntry->ChangeTime = pCurrentEntry->CreationTime;
453 pCurrentEntry->EndOfFile = scp->length;
454 pCurrentEntry->AllocationSize = scp->length;
457 switch (scp->fileType) {
458 case CM_SCACHETYPE_DIRECTORY:
459 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY;
461 case CM_SCACHETYPE_MOUNTPOINT:
462 case CM_SCACHETYPE_INVALID:
463 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY | SMB_ATTR_REPARSE_POINT;
465 case CM_SCACHETYPE_SYMLINK:
466 if (cm_TargetPerceivedAsDirectory(scp->mountPointStringp))
467 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY | SMB_ATTR_REPARSE_POINT;
469 pCurrentEntry->FileAttributes = SMB_ATTR_REPARSE_POINT;
472 /* if we get here we either have a normal file
473 * or we have a file for which we have never
474 * received status info. In this case, we can
475 * check the even/odd value of the entry's vnode.
476 * odd means it is to be treated as a directory
477 * and even means it is to be treated as a file.
479 if (scp->fid.vnode & 0x1)
480 pCurrentEntry->FileAttributes = SMB_ATTR_DIRECTORY;
482 pCurrentEntry->FileAttributes = SMB_ATTR_NORMAL;
485 pCurrentEntry->FileAttributes = smb_ExtAttributes(scp);
486 pCurrentEntry->EaSize = 0;
487 pCurrentEntry->Links = scp->linkCount;
489 len = wcslen(shortName);
490 wcsncpy(pCurrentEntry->ShortName, shortName, len);
491 pCurrentEntry->ShortNameLength = (CCHAR)(len * sizeof(WCHAR));
493 pCurrentEntry->FileNameOffset = sizeof(AFSDirEnumEntry);
495 wname = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->FileNameOffset);
496 wcsncpy(wname, name, len);
497 pCurrentEntry->FileNameLength = (ULONG)(sizeof(WCHAR) * len);
499 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry scp=0x%p fileType=%d",
502 if (!(dwFlags & RDR_POP_NO_GETSTATUS))
503 cm_SyncOpDone( scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
505 if ((dwFlags & RDR_POP_NO_GETSTATUS) || !cm_HaveCallback(scp)) {
506 pCurrentEntry->TargetNameOffset = 0;
507 pCurrentEntry->TargetNameLength = 0;
510 switch (scp->fileType) {
511 case CM_SCACHETYPE_MOUNTPOINT:
512 if (dwFlags & RDR_POP_FOLLOW_MOUNTPOINTS) {
513 if ((code2 = cm_ReadMountPoint(scp, userp, reqp)) == 0) {
514 cm_scache_t *targetScp = NULL;
516 pCurrentEntry->TargetNameOffset = pCurrentEntry->FileNameOffset + pCurrentEntry->FileNameLength;
517 len = strlen(scp->mountPointStringp);
518 wtarget = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->TargetNameOffset);
521 cch = MultiByteToWideChar( CP_UTF8, 0, scp->mountPointStringp,
524 len * sizeof(WCHAR));
526 mbstowcs(wtarget, scp->mountPointStringp, len);
528 pCurrentEntry->TargetNameLength = (ULONG)(sizeof(WCHAR) * len);
530 code2 = cm_FollowMountPoint(scp, dscp, userp, reqp, &targetScp);
533 pCurrentEntry->TargetFileId.Cell = targetScp->fid.cell;
534 pCurrentEntry->TargetFileId.Volume = targetScp->fid.volume;
535 pCurrentEntry->TargetFileId.Vnode = targetScp->fid.vnode;
536 pCurrentEntry->TargetFileId.Unique = targetScp->fid.unique;
537 pCurrentEntry->TargetFileId.Hash = targetScp->fid.hash;
539 osi_Log4(afsd_logp, "RDR_PopulateCurrentEntry target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
540 pCurrentEntry->TargetFileId.Cell, pCurrentEntry->TargetFileId.Volume,
541 pCurrentEntry->TargetFileId.Vnode, pCurrentEntry->TargetFileId.Unique);
543 cm_ReleaseSCache(targetScp);
545 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_FollowMountPoint failed scp=0x%p code=0x%x",
549 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_ReadMountPoint failed scp=0x%p code=0x%x",
554 case CM_SCACHETYPE_SYMLINK:
555 case CM_SCACHETYPE_DFSLINK:
557 pCurrentEntry->TargetNameOffset = pCurrentEntry->FileNameOffset + pCurrentEntry->FileNameLength;
558 wtarget = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->TargetNameOffset);
560 if (dwFlags & RDR_POP_EVALUATE_SYMLINKS) {
563 code2 = cm_HandleLink(scp, userp, reqp);
565 mp = scp->mountPointStringp;
568 /* Strip off the msdfs: prefix from the target name for the file system */
569 if (scp->fileType == CM_SCACHETYPE_DFSLINK) {
570 osi_Log0(afsd_logp, "RDR_PopulateCurrentEntry DFSLink Detected");
571 pCurrentEntry->FileType = scp->fileType;
573 if (!strncmp("msdfs:", mp, 6)) {
578 /* only send one slash to the redirector */
579 if (mp[0] == '\\' && mp[1] == '\\') {
584 cch = MultiByteToWideChar( CP_UTF8, 0, mp,
587 len * sizeof(WCHAR));
589 mbstowcs(wtarget, mp, len);
592 pCurrentEntry->TargetNameLength = (ULONG)(sizeof(WCHAR) * len);
594 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntry cm_HandleLink failed scp=0x%p code=0x%x",
603 pCurrentEntry->TargetNameOffset = 0;
604 pCurrentEntry->TargetNameLength = 0;
606 lock_ReleaseWrite(&scp->rw);
608 dwEntryLength += pCurrentEntry->FileNameLength + pCurrentEntry->TargetNameLength;
609 dwEntryLength += (dwEntryLength % 8) ? 8 - (dwEntryLength % 8) : 0; /* quad align */
611 *ppNextEntry = (AFSDirEnumEntry *)((PBYTE)pCurrentEntry + dwEntryLength);
612 if (pdwRemainingLength)
613 *pdwRemainingLength = dwMaxEntryLength - dwEntryLength;
615 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntry Success FileNameLength=%d TargetNameLength=%d RemainingLength=%d",
616 pCurrentEntry->FileNameLength, pCurrentEntry->TargetNameLength, *pdwRemainingLength);
622 RDR_PopulateCurrentEntryNoScp( IN AFSDirEnumEntry * pCurrentEntry,
623 IN DWORD dwMaxEntryLength,
624 IN cm_scache_t * dscp,
626 IN cm_user_t * userp,
629 IN wchar_t * shortName,
631 OUT AFSDirEnumEntry **ppNextEntry,
632 OUT DWORD * pdwRemainingLength)
638 afs_uint32 code = 0, code2 = 0;
640 osi_Log4(afsd_logp, "RDR_PopulateCurrentEntryNoEntry dscp=0x%p name=%S short=%S flags=0x%x",
641 dscp, osi_LogSaveStringW(afsd_logp, name),
642 osi_LogSaveStringW(afsd_logp, shortName), dwFlags);
643 osi_Log1(afsd_logp, "... maxLength=%d", dwMaxEntryLength);
645 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
647 *ppNextEntry = pCurrentEntry;
648 if (pdwRemainingLength)
649 *pdwRemainingLength = dwMaxEntryLength;
650 osi_Log2(afsd_logp, "RDR_PopulateCurrentEntryNoEntry Not Enough Room for Entry %d < %d",
651 dwMaxEntryLength, sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t));
652 return CM_ERROR_TOOBIG;
660 dwEntryLength = sizeof(AFSDirEnumEntry);
662 pCurrentEntry->FileId.Cell = fidp->cell;
663 pCurrentEntry->FileId.Volume = fidp->volume;
664 pCurrentEntry->FileId.Vnode = fidp->vnode;
665 pCurrentEntry->FileId.Unique = fidp->unique;
666 pCurrentEntry->FileId.Hash = fidp->hash;
668 pCurrentEntry->FileType = CM_SCACHETYPE_UNKNOWN;
670 pCurrentEntry->DataVersion.QuadPart = CM_SCACHE_VERSION_BAD;
672 cm_LargeSearchTimeFromUnixTime(&ft, 0);
673 pCurrentEntry->Expiration.LowPart = ft.dwLowDateTime;
674 pCurrentEntry->Expiration.HighPart = ft.dwHighDateTime;
676 cm_LargeSearchTimeFromUnixTime(&ft, 0);
677 pCurrentEntry->CreationTime.LowPart = ft.dwLowDateTime;
678 pCurrentEntry->CreationTime.HighPart = ft.dwHighDateTime;
679 pCurrentEntry->LastAccessTime = pCurrentEntry->CreationTime;
680 pCurrentEntry->LastWriteTime = pCurrentEntry->CreationTime;
681 pCurrentEntry->ChangeTime = pCurrentEntry->CreationTime;
683 pCurrentEntry->EndOfFile.QuadPart = 0;
684 pCurrentEntry->AllocationSize.QuadPart = 0;
685 pCurrentEntry->FileAttributes = 0;
686 pCurrentEntry->EaSize = 0;
687 pCurrentEntry->Links = 0;
689 len = wcslen(shortName);
690 wcsncpy(pCurrentEntry->ShortName, shortName, len);
691 pCurrentEntry->ShortNameLength = (CCHAR)(len * sizeof(WCHAR));
693 pCurrentEntry->FileNameOffset = sizeof(AFSDirEnumEntry);
695 wname = (WCHAR *)((PBYTE)pCurrentEntry + pCurrentEntry->FileNameOffset);
696 wcsncpy(wname, name, len);
697 pCurrentEntry->FileNameLength = (ULONG)(sizeof(WCHAR) * len);
699 pCurrentEntry->TargetNameOffset = 0;
700 pCurrentEntry->TargetNameLength = 0;
702 dwEntryLength += pCurrentEntry->FileNameLength + pCurrentEntry->TargetNameLength;
703 dwEntryLength += (dwEntryLength % 8) ? 8 - (dwEntryLength % 8) : 0; /* quad align */
705 *ppNextEntry = (AFSDirEnumEntry *)((PBYTE)pCurrentEntry + dwEntryLength);
706 if (pdwRemainingLength)
707 *pdwRemainingLength = dwMaxEntryLength - dwEntryLength;
709 osi_Log3(afsd_logp, "RDR_PopulateCurrentEntryNoScp Success FileNameLength=%d TargetNameLength=%d RemainingLength=%d",
710 pCurrentEntry->FileNameLength, pCurrentEntry->TargetNameLength, *pdwRemainingLength);
716 RDR_EnumerateDirectory( IN cm_user_t *userp,
718 IN AFSDirQueryCB *QueryCB,
721 IN DWORD ResultBufferLength,
722 IN OUT AFSCommResult **ResultCB)
725 cm_direnum_t * enump = NULL;
726 AFSDirEnumResp * pDirEnumResp;
727 AFSDirEnumEntry * pCurrentEntry;
728 size_t size = ResultBufferLength ? sizeof(AFSCommResult) + ResultBufferLength - 1 : sizeof(AFSCommResult);
729 DWORD dwMaxEntryLength;
732 cm_scache_t * dscp = NULL;
737 req.flags |= CM_REQ_WOW64;
739 osi_Log4(afsd_logp, "RDR_EnumerateDirectory FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
740 DirID.Cell, DirID.Volume, DirID.Vnode, DirID.Unique);
742 *ResultCB = (AFSCommResult *)malloc(size);
744 osi_Log0(afsd_logp, "RDR_EnumerateDirectory Out of Memory");
748 memset(*ResultCB, 0, size);
750 if (QueryCB->EnumHandle == (ULONG_PTR)-1) {
751 osi_Log0(afsd_logp, "RDR_EnumerateDirectory No More Entries");
752 (*ResultCB)->ResultStatus = STATUS_NO_MORE_ENTRIES;
753 (*ResultCB)->ResultBufferLength = 0;
757 (*ResultCB)->ResultBufferLength = dwMaxEntryLength = ResultBufferLength;
758 if (ResultBufferLength) {
759 pDirEnumResp = (AFSDirEnumResp *)&(*ResultCB)->ResultData;
760 pCurrentEntry = (AFSDirEnumEntry *)&pDirEnumResp->Entry;
761 dwMaxEntryLength -= FIELD_OFFSET( AFSDirEnumResp, Entry); /* AFSDirEnumResp */
764 if (DirID.Cell != 0) {
765 fid.cell = DirID.Cell;
766 fid.volume = DirID.Volume;
767 fid.vnode = DirID.Vnode;
768 fid.unique = DirID.Unique;
769 fid.hash = DirID.Hash;
771 code = cm_GetSCache(&fid, &dscp, userp, &req);
773 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
774 (*ResultCB)->ResultStatus = status;
775 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_GetSCache failure code=0x%x status=0x%x",
780 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
781 osi_Log0(afsd_logp, "RDR_EnumerateDirectory Object Name Invalid - Cell = 0");
785 /* get the directory size */
786 lock_ObtainWrite(&dscp->rw);
787 code = cm_SyncOp(dscp, NULL, userp, &req, PRSFS_LOOKUP,
788 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
790 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
791 (*ResultCB)->ResultStatus = status;
792 lock_ReleaseWrite(&dscp->rw);
793 cm_ReleaseSCache(dscp);
794 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_SyncOp failure code=0x%x status=0x%x",
799 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
800 lock_ReleaseWrite(&dscp->rw);
802 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
803 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
804 cm_ReleaseSCache(dscp);
805 osi_Log1(afsd_logp, "RDR_EnumerateDirectory Not a Directory dscp=0x%p",
811 * If there is no enumeration handle, then this is a new query
812 * and we must perform an enumeration for the specified object
814 if (QueryCB->EnumHandle == (ULONG_PTR)NULL) {
817 code = cm_BeginDirOp(dscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
819 code = cm_BPlusDirEnumerate(dscp, userp, &req, TRUE, NULL, !bSkipStatus, &enump);
821 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BPlusDirEnumerate failure code=0x%x",
826 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BeginDirOp failure code=0x%x",
830 enump = (cm_direnum_t *)QueryCB->EnumHandle;
833 if (enump && ResultBufferLength) {
834 cm_direnum_entry_t * entryp = NULL;
837 if (dwMaxEntryLength < sizeof(AFSDirEnumEntry) + (MAX_PATH + MOUNTPOINTLEN) * sizeof(wchar_t)) {
838 osi_Log0(afsd_logp, "RDR_EnumerateDirectory out of space, returning");
842 code = cm_BPlusDirNextEnumEntry(enump, &entryp);
844 if ((code == 0 || code == CM_ERROR_STOPNOW) && entryp) {
846 int stopnow = (code == CM_ERROR_STOPNOW);
848 if ( !wcscmp(L".", entryp->name) || !wcscmp(L"..", entryp->name) ) {
849 osi_Log0(afsd_logp, "RDR_EnumerateDirectory skipping . or ..");
855 if ( FALSE /* bSkipStatus */) {
856 scp = cm_FindSCache(&entryp->fid);
859 code = cm_GetSCache(&entryp->fid, &scp, userp, &req);
864 code = RDR_PopulateCurrentEntry(pCurrentEntry, dwMaxEntryLength,
865 dscp, scp, userp, &req,
867 cm_Is8Dot3(entryp->name) ? NULL : entryp->shortName,
868 (bWow64 ? RDR_POP_WOW64 : 0) |
869 (bSkipStatus ? RDR_POP_NO_GETSTATUS : 0),
870 &pCurrentEntry, &dwMaxEntryLength);
871 cm_ReleaseSCache(scp);
873 code = RDR_PopulateCurrentEntryNoScp( pCurrentEntry, dwMaxEntryLength,
874 dscp, &entryp->fid, userp, &req,
876 cm_Is8Dot3(entryp->name) ? NULL : entryp->shortName,
877 (bWow64 ? RDR_POP_WOW64 : 0),
878 &pCurrentEntry, &dwMaxEntryLength);
884 osi_Log2(afsd_logp, "RDR_EnumerateDirectory cm_GetSCache failure scp=0x%p code=0x%x",
893 if (enump && ResultBufferLength == 0) {
894 code = cm_BPlusDirEnumBulkStat(enump);
896 osi_Log1(afsd_logp, "RDR_EnumerateDirectory cm_BPlusDirEnumBulkStat failure code=0x%x",
902 if (code || enump->next == enump->count || ResultBufferLength == 0) {
903 cm_BPlusDirFreeEnumeration(enump);
904 enump = (cm_direnum_t *)(ULONG_PTR)-1;
907 if (code == 0 || code == CM_ERROR_STOPNOW) {
908 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
909 osi_Log0(afsd_logp, "RDR_EnumerateDirectory SUCCESS");
911 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
912 (*ResultCB)->ResultStatus = status;
913 osi_Log2(afsd_logp, "RDR_EnumerateDirectory Failure code=0x%x status=0x%x",
917 if (ResultBufferLength) {
918 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwMaxEntryLength;
920 pDirEnumResp->EnumHandle = (ULONG_PTR) enump;
924 cm_ReleaseSCache(dscp);
930 RDR_EvaluateNodeByName( IN cm_user_t *userp,
931 IN AFSFileID ParentID,
932 IN WCHAR *FileNameCounted,
933 IN DWORD FileNameLength,
934 IN BOOL CaseSensitive,
938 IN DWORD ResultBufferLength,
939 IN OUT AFSCommResult **ResultCB)
941 AFSDirEnumEntry * pCurrentEntry;
942 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
944 cm_scache_t * scp = NULL;
945 cm_scache_t * dscp = NULL;
950 WCHAR * wszName = NULL;
953 wchar_t FileName[260];
955 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
959 req.flags |= CM_REQ_WOW64;
961 osi_Log4(afsd_logp, "RDR_EvaluateNodeByName parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
962 ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
964 /* Allocate enough room to add a volume prefix if necessary */
965 cbName = FileNameLength + (CM_PREFIX_VOL_CCH + 1) * sizeof(WCHAR);
966 wszName = malloc(cbName);
968 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Out of Memory");
971 StringCbCopyNW(wszName, cbName, FileName, FileNameLength);
972 osi_Log1(afsd_logp, "... name=%S", osi_LogSaveStringW(afsd_logp, wszName));
974 *ResultCB = (AFSCommResult *)malloc(size);
976 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Out of Memory");
981 memset(*ResultCB, 0, size);
982 (*ResultCB)->ResultBufferLength = ResultBufferLength;
983 if (ResultBufferLength)
984 pCurrentEntry = (AFSDirEnumEntry *)&(*ResultCB)->ResultData;
986 if (ParentID.Cell != 0) {
987 parentFid.cell = ParentID.Cell;
988 parentFid.volume = ParentID.Volume;
989 parentFid.vnode = ParentID.Vnode;
990 parentFid.unique = ParentID.Unique;
991 parentFid.hash = ParentID.Hash;
993 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
995 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
996 (*ResultCB)->ResultStatus = status;
997 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName cm_GetSCache parentFID failure code=0x%x status=0x%x",
1003 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
1004 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName Object Name Invalid - Cell = 0");
1008 /* get the directory size */
1009 lock_ObtainWrite(&dscp->rw);
1010 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1011 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1013 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1014 (*ResultCB)->ResultStatus = status;
1015 lock_ReleaseWrite(&dscp->rw);
1016 cm_ReleaseSCache(dscp);
1017 osi_Log3(afsd_logp, "RDR_EvaluateNodeByName cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1018 dscp, code, status);
1022 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1023 lock_ReleaseWrite(&dscp->rw);
1025 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1026 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1027 cm_ReleaseSCache(dscp);
1028 osi_Log1(afsd_logp, "RDR_EvaluateNodeByName Not a Directory dscp=0x%p",
1034 code = cm_Lookup(dscp, wszName, CM_FLAG_CHECKPATH, userp, &req, &scp);
1036 if ((code == CM_ERROR_NOSUCHPATH || code == CM_ERROR_NOSUCHFILE || code == CM_ERROR_BPLUS_NOMATCH) &&
1037 (wcschr(wszName, '%') != NULL || wcschr(wszName, '#') != NULL)) {
1039 * A volume reference: <cell>{%,#}<volume> -> @vol:<cell>{%,#}<volume>
1041 StringCchCopyNW(wszName, cbName, _C(CM_PREFIX_VOL), CM_PREFIX_VOL_CCH);
1042 StringCbCatNW(wszName, cbName, FileName, FileNameLength);
1043 cm_strlwr_utf16(wszName);
1046 code = cm_EvaluateVolumeReference(wszName, CM_FLAG_CHECKPATH, userp, &req, &scp);
1049 if (code == 0 && scp) {
1050 wchar_t shortName[13]=L"";
1053 cm_Gen8Dot3VolNameW(scp->fid.cell, scp->fid.volume, shortName, NULL);
1054 } else if (!cm_Is8Dot3(wszName)) {
1057 dfid.vnode = htonl(scp->fid.vnode);
1058 dfid.unique = htonl(scp->fid.unique);
1060 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1062 shortName[0] = '\0';
1065 code = RDR_PopulateCurrentEntry(pCurrentEntry, ResultBufferLength,
1066 dscp, scp, userp, &req,
1067 FileName, shortName,
1068 (bWow64 ? RDR_POP_WOW64 : 0) |
1069 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1070 NULL, &dwRemaining);
1072 RDR_FlagScpInUse( scp, FALSE );
1073 cm_ReleaseSCache(scp);
1076 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1077 (*ResultCB)->ResultStatus = status;
1078 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1081 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1082 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1083 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName SUCCESS");
1086 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1087 (*ResultCB)->ResultStatus = status;
1088 osi_Log2(afsd_logp, "RDR_EvaluateNodeByName FAILURE code=0x%x status=0x%x",
1091 (*ResultCB)->ResultStatus = STATUS_NO_SUCH_FILE;
1092 osi_Log0(afsd_logp, "RDR_EvaluateNodeByName No Such File");
1094 cm_ReleaseSCache(dscp);
1101 RDR_EvaluateNodeByID( IN cm_user_t *userp,
1102 IN AFSFileID ParentID, /* not used */
1103 IN AFSFileID SourceID,
1107 IN DWORD ResultBufferLength,
1108 IN OUT AFSCommResult **ResultCB)
1110 AFSDirEnumEntry * pCurrentEntry;
1111 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1112 afs_uint32 code = 0;
1113 cm_scache_t * scp = NULL;
1114 cm_scache_t * dscp = NULL;
1121 osi_Log4(afsd_logp, "RDR_EvaluateNodeByID source FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1122 SourceID.Cell, SourceID.Volume, SourceID.Vnode, SourceID.Unique);
1123 osi_Log4(afsd_logp, "... parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1124 ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1126 *ResultCB = (AFSCommResult *)malloc(size);
1128 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Out of Memory");
1132 memset(*ResultCB, 0, size);
1133 (*ResultCB)->ResultBufferLength = ResultBufferLength;
1134 dwRemaining = ResultBufferLength;
1135 if (ResultBufferLength)
1136 pCurrentEntry = (AFSDirEnumEntry *)&(*ResultCB)->ResultData;
1140 req.flags |= CM_REQ_WOW64;
1142 if (SourceID.Cell != 0) {
1143 Fid.cell = SourceID.Cell;
1144 Fid.volume = SourceID.Volume;
1145 Fid.vnode = SourceID.Vnode;
1146 Fid.unique = SourceID.Unique;
1147 Fid.hash = SourceID.Hash;
1149 code = cm_GetSCache(&Fid, &scp, userp, &req);
1151 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1152 (*ResultCB)->ResultStatus = status;
1153 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache SourceFID failure code=0x%x status=0x%x",
1158 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
1159 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Name Invalid - Cell = 0");
1163 if (ParentID.Cell != 0) {
1164 cm_SetFid(&parentFid, ParentID.Cell, ParentID.Volume, ParentID.Vnode, ParentID.Unique);
1165 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1167 cm_ReleaseSCache(scp);
1168 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1169 (*ResultCB)->ResultStatus = status;
1170 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1174 } else if (SourceID.Vnode == 1) {
1176 cm_HoldSCache(dscp);
1177 } else if (scp->parentVnode) {
1178 cm_SetFid(&parentFid, SourceID.Cell, SourceID.Volume, scp->parentVnode, scp->parentUnique);
1179 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1181 cm_ReleaseSCache(scp);
1182 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1183 (*ResultCB)->ResultStatus = status;
1184 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID cm_GetSCache parentFID failure code=0x%x status=0x%x",
1189 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
1190 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID Object Path Invalid - Unknown Parent");
1194 /* Make sure the directory is current */
1195 lock_ObtainWrite(&dscp->rw);
1196 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1197 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1199 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1200 (*ResultCB)->ResultStatus = status;
1201 lock_ReleaseWrite(&dscp->rw);
1202 cm_ReleaseSCache(dscp);
1203 cm_ReleaseSCache(scp);
1204 osi_Log3(afsd_logp, "RDR_EvaluateNodeByID cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1205 dscp, code, status);
1209 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1210 lock_ReleaseWrite(&dscp->rw);
1212 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1213 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1214 cm_ReleaseSCache(dscp);
1215 cm_ReleaseSCache(scp);
1216 osi_Log1(afsd_logp, "RDR_EvaluateNodeByID Not a Directory dscp=0x%p", dscp);
1220 code = RDR_PopulateCurrentEntry(pCurrentEntry, ResultBufferLength,
1221 dscp, scp, userp, &req, NULL, NULL,
1222 (bWow64 ? RDR_POP_WOW64 : 0) |
1223 (bNoFollow ? 0 : (RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS)),
1224 NULL, &dwRemaining);
1227 RDR_FlagScpInUse( scp, FALSE );
1228 cm_ReleaseSCache(scp);
1229 cm_ReleaseSCache(dscp);
1232 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1233 (*ResultCB)->ResultStatus = status;
1234 osi_Log2(afsd_logp, "RDR_EvaluateNodeByID FAILURE code=0x%x status=0x%x",
1237 (*ResultCB)->ResultStatus = STATUS_SUCCESS;
1238 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1239 osi_Log0(afsd_logp, "RDR_EvaluateNodeByID SUCCESS");
1245 RDR_CreateFileEntry( IN cm_user_t *userp,
1246 IN WCHAR *FileNameCounted,
1247 IN DWORD FileNameLength,
1248 IN AFSFileCreateCB *CreateCB,
1251 IN DWORD ResultBufferLength,
1252 IN OUT AFSCommResult **ResultCB)
1254 AFSFileCreateResultCB *pResultCB = NULL;
1255 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1258 cm_scache_t * dscp = NULL;
1259 afs_uint32 flags = 0;
1261 cm_scache_t * scp = NULL;
1264 wchar_t FileName[260];
1266 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1268 osi_Log4(afsd_logp, "RDR_CreateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1269 CreateCB->ParentId.Cell, CreateCB->ParentId.Volume,
1270 CreateCB->ParentId.Vnode, CreateCB->ParentId.Unique);
1271 osi_Log1(afsd_logp, "... name=%S", osi_LogSaveStringW(afsd_logp, FileName));
1275 req.flags |= CM_REQ_WOW64;
1276 memset(&setAttr, 0, sizeof(cm_attr_t));
1278 *ResultCB = (AFSCommResult *)malloc(size);
1280 osi_Log0(afsd_logp, "RDR_CreateFileEntry out of memory");
1288 parentFid.cell = CreateCB->ParentId.Cell;
1289 parentFid.volume = CreateCB->ParentId.Volume;
1290 parentFid.vnode = CreateCB->ParentId.Vnode;
1291 parentFid.unique = CreateCB->ParentId.Unique;
1292 parentFid.hash = CreateCB->ParentId.Hash;
1294 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1296 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1297 (*ResultCB)->ResultStatus = status;
1298 osi_Log2(afsd_logp, "RDR_CreateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1303 lock_ObtainWrite(&dscp->rw);
1304 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1305 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1307 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1308 (*ResultCB)->ResultStatus = status;
1309 lock_ReleaseWrite(&dscp->rw);
1310 cm_ReleaseSCache(dscp);
1311 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (1) dscp=0x%p code=0x%x status=0x%x",
1312 dscp, code, status);
1316 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1317 lock_ReleaseWrite(&dscp->rw);
1319 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1320 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1321 cm_ReleaseSCache(dscp);
1322 osi_Log1(afsd_logp, "RDR_CreateFileEntry Not a Directory dscp=0x%p",
1327 /* Use current time */
1328 setAttr.mask = CM_ATTRMASK_CLIENTMODTIME;
1329 setAttr.clientModTime = time(NULL);
1331 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1332 if (smb_unixModeDefaultDir) {
1333 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1334 setAttr.unixModeBits = smb_unixModeDefaultDir;
1335 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1336 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1339 code = cm_MakeDir(dscp, FileName, flags, &setAttr, userp, &req, &scp);
1341 if (smb_unixModeDefaultFile) {
1342 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1343 setAttr.unixModeBits = smb_unixModeDefaultFile;
1344 if (CreateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)
1345 setAttr.unixModeBits &= ~0222; /* disable the write bits */
1348 setAttr.mask |= CM_ATTRMASK_LENGTH;
1349 setAttr.length.LowPart = CreateCB->AllocationSize.LowPart;
1350 setAttr.length.HighPart = CreateCB->AllocationSize.HighPart;
1351 code = cm_Create(dscp, FileName, flags, &setAttr, &scp, userp, &req);
1354 wchar_t shortName[13]=L"";
1358 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
1360 (*ResultCB)->ResultBufferLength = sizeof( AFSFileCreateResultCB);
1362 pResultCB = (AFSFileCreateResultCB *)(*ResultCB)->ResultData;
1364 dwRemaining = ResultBufferLength - sizeof( AFSFileCreateResultCB) + sizeof( AFSDirEnumEntry);
1366 lock_ObtainWrite(&dscp->rw);
1367 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1368 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1370 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1371 (*ResultCB)->ResultStatus = status;
1372 lock_ReleaseWrite(&dscp->rw);
1373 cm_ReleaseSCache(dscp);
1374 cm_ReleaseSCache(scp);
1375 osi_Log3(afsd_logp, "RDR_CreateFileEntry cm_SyncOp failure (2) dscp=0x%p code=0x%x status=0x%x",
1376 dscp, code, status);
1380 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
1382 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1383 lock_ReleaseWrite(&dscp->rw);
1385 dfid.vnode = htonl(scp->fid.vnode);
1386 dfid.unique = htonl(scp->fid.unique);
1388 if (!cm_Is8Dot3(FileName))
1389 cm_Gen8Dot3NameIntW(FileName, &dfid, shortName, NULL);
1391 shortName[0] = '\0';
1393 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1394 dscp, scp, userp, &req, FileName, shortName,
1395 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1396 NULL, &dwRemaining);
1399 RDR_FlagScpInUse( scp, FALSE );
1400 cm_ReleaseSCache(scp);
1401 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1402 osi_Log0(afsd_logp, "RDR_CreateFileEntry SUCCESS");
1404 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1405 (*ResultCB)->ResultStatus = status;
1406 (*ResultCB)->ResultBufferLength = 0;
1407 osi_Log2(afsd_logp, "RDR_CreateFileEntry FAILURE code=0x%x status=0x%x",
1411 cm_ReleaseSCache(dscp);
1417 RDR_UpdateFileEntry( IN cm_user_t *userp,
1418 IN AFSFileID FileId,
1419 IN AFSFileUpdateCB *UpdateCB,
1421 IN DWORD ResultBufferLength,
1422 IN OUT AFSCommResult **ResultCB)
1424 AFSFileUpdateResultCB *pResultCB = NULL;
1425 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1429 afs_uint32 flags = 0;
1431 cm_scache_t * scp = NULL;
1432 cm_scache_t * dscp = NULL;
1434 time_t clientModTime;
1437 BOOL bScpLocked = FALSE;
1441 req.flags |= CM_REQ_WOW64;
1442 memset(&setAttr, 0, sizeof(cm_attr_t));
1444 osi_Log4(afsd_logp, "RDR_UpdateFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1445 UpdateCB->ParentId.Cell, UpdateCB->ParentId.Volume,
1446 UpdateCB->ParentId.Vnode, UpdateCB->ParentId.Unique);
1447 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1448 FileId.Cell, FileId.Volume,
1449 FileId.Vnode, FileId.Unique);
1451 *ResultCB = (AFSCommResult *)malloc( size);
1453 osi_Log0(afsd_logp, "RDR_UpdateFileEntry Out of Memory");
1461 parentFid.cell = UpdateCB->ParentId.Cell;
1462 parentFid.volume = UpdateCB->ParentId.Volume;
1463 parentFid.vnode = UpdateCB->ParentId.Vnode;
1464 parentFid.unique = UpdateCB->ParentId.Unique;
1465 parentFid.hash = UpdateCB->ParentId.Hash;
1467 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1469 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1470 (*ResultCB)->ResultStatus = status;
1471 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1476 lock_ObtainWrite(&dscp->rw);
1478 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1479 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1481 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1482 (*ResultCB)->ResultStatus = status;
1483 lock_ReleaseWrite(&dscp->rw);
1484 cm_ReleaseSCache(dscp);
1485 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
1486 dscp, code, status);
1490 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1491 lock_ReleaseWrite(&dscp->rw);
1494 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1495 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1496 cm_ReleaseSCache(dscp);
1497 osi_Log1(afsd_logp, "RDR_UpdateFileEntry Not a Directory dscp=0x%p",
1502 Fid.cell = FileId.Cell;
1503 Fid.volume = FileId.Volume;
1504 Fid.vnode = FileId.Vnode;
1505 Fid.unique = FileId.Unique;
1506 Fid.hash = FileId.Hash;
1508 code = cm_GetSCache(&Fid, &scp, userp, &req);
1510 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1511 (*ResultCB)->ResultStatus = status;
1512 cm_ReleaseSCache(dscp);
1513 osi_Log2(afsd_logp, "RDR_UpdateFileEntry cm_GetSCache object FID failure code=0x%x status=0x%x",
1518 lock_ObtainWrite(&scp->rw);
1520 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1521 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1523 lock_ReleaseWrite(&scp->rw);
1524 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1525 (*ResultCB)->ResultStatus = status;
1526 (*ResultCB)->ResultBufferLength = 0;
1527 cm_ReleaseSCache(dscp);
1528 cm_ReleaseSCache(scp);
1529 osi_Log3(afsd_logp, "RDR_UpdateFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
1533 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1535 if (UpdateCB->ChangeTime.QuadPart) {
1537 if (scp->fileType == CM_SCACHETYPE_FILE) {
1538 /* Do not set length and other attributes at the same time */
1539 if (scp->length.QuadPart != UpdateCB->AllocationSize.QuadPart) {
1540 osi_Log2(afsd_logp, "RDR_UpdateFileEntry Length Change 0x%x -> 0x%x",
1541 (afs_uint32)scp->length.QuadPart, (afs_uint32)UpdateCB->AllocationSize.QuadPart);
1542 setAttr.mask |= CM_ATTRMASK_LENGTH;
1543 setAttr.length.LowPart = UpdateCB->AllocationSize.LowPart;
1544 setAttr.length.HighPart = UpdateCB->AllocationSize.HighPart;
1545 lock_ReleaseWrite(&scp->rw);
1547 code = cm_SetAttr(scp, &setAttr, userp, &req);
1555 lock_ObtainWrite(&scp->rw);
1558 if ((scp->unixModeBits & 0200) && (UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1559 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1560 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1561 } else if (!(scp->unixModeBits & 0200) && !(UpdateCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1562 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1563 setAttr.unixModeBits = scp->unixModeBits | 0222;
1567 if (UpdateCB->LastWriteTime.QuadPart) {
1568 ft.dwLowDateTime = UpdateCB->LastWriteTime.LowPart;
1569 ft.dwHighDateTime = UpdateCB->LastWriteTime.HighPart;
1571 cm_UnixTimeFromLargeSearchTime(& clientModTime, &ft);
1574 lock_ObtainWrite(&scp->rw);
1577 if (scp->clientModTime != clientModTime) {
1578 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1579 setAttr.clientModTime = clientModTime;
1584 lock_ReleaseWrite(&scp->rw);
1586 code = cm_SetAttr(scp, &setAttr, userp, &req);
1593 lock_ReleaseWrite(&scp->rw);
1597 DWORD dwRemaining = ResultBufferLength - sizeof( AFSFileUpdateResultCB) + sizeof( AFSDirEnumEntry);
1599 pResultCB = (AFSFileUpdateResultCB *)(*ResultCB)->ResultData;
1601 code = RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
1602 dscp, scp, userp, &req, NULL, NULL,
1603 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
1604 NULL, &dwRemaining);
1605 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
1606 osi_Log0(afsd_logp, "RDR_UpdateFileEntry SUCCESS");
1608 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1609 (*ResultCB)->ResultStatus = status;
1610 (*ResultCB)->ResultBufferLength = 0;
1611 osi_Log2(afsd_logp, "RDR_UpdateFileEntry FAILURE code=0x%x status=0x%x",
1614 cm_ReleaseSCache(scp);
1615 cm_ReleaseSCache(dscp);
1621 RDR_CleanupFileEntry( IN cm_user_t *userp,
1622 IN AFSFileID FileId,
1623 IN WCHAR *FileNameCounted,
1624 IN DWORD FileNameLength,
1625 IN AFSFileCleanupCB *CleanupCB,
1627 IN BOOL bLastHandle,
1628 IN BOOL bDeleteFile,
1629 IN BOOL bUnlockFile,
1630 IN DWORD ResultBufferLength,
1631 IN OUT AFSCommResult **ResultCB)
1633 size_t size = sizeof(AFSCommResult);
1636 afs_uint32 code = 0;
1637 afs_uint32 flags = 0;
1639 cm_scache_t * scp = NULL;
1640 cm_scache_t * dscp = NULL;
1642 time_t clientModTime;
1645 BOOL bScpLocked = FALSE;
1646 BOOL bDscpLocked = FALSE;
1647 BOOL bFlushFile = FALSE;
1651 req.flags |= CM_REQ_WOW64;
1652 memset(&setAttr, 0, sizeof(cm_attr_t));
1654 osi_Log4(afsd_logp, "RDR_CleanupFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1655 CleanupCB->ParentId.Cell, CleanupCB->ParentId.Volume,
1656 CleanupCB->ParentId.Vnode, CleanupCB->ParentId.Unique);
1657 osi_Log4(afsd_logp, "... object FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1658 FileId.Cell, FileId.Volume,
1659 FileId.Vnode, FileId.Unique);
1661 *ResultCB = (AFSCommResult *)malloc( size);
1663 osi_Log0(afsd_logp, "RDR_CleanupFileEntry Out of Memory");
1671 parentFid.cell = CleanupCB->ParentId.Cell;
1672 parentFid.volume = CleanupCB->ParentId.Volume;
1673 parentFid.vnode = CleanupCB->ParentId.Vnode;
1674 parentFid.unique = CleanupCB->ParentId.Unique;
1675 parentFid.hash = CleanupCB->ParentId.Hash;
1677 if (parentFid.cell) {
1678 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1680 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1681 (*ResultCB)->ResultStatus = status;
1682 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1687 lock_ObtainWrite(&dscp->rw);
1689 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1690 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1692 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure dscp=0x%p code=0x%x",
1698 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1699 lock_ReleaseWrite(&dscp->rw);
1700 bDscpLocked = FALSE;
1702 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
1703 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
1704 cm_ReleaseSCache(dscp);
1705 osi_Log1(afsd_logp, "RDR_CleanupFileEntry Not a Directory dscp=0x%p",
1712 Fid.cell = FileId.Cell;
1713 Fid.volume = FileId.Volume;
1714 Fid.vnode = FileId.Vnode;
1715 Fid.unique = FileId.Unique;
1716 Fid.hash = FileId.Hash;
1718 code = cm_GetSCache(&Fid, &scp, userp, &req);
1720 osi_Log1(afsd_logp, "RDR_CleanupFileEntry cm_GetSCache object FID failure code=0x%x",
1725 lock_ObtainWrite(&scp->rw);
1727 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1728 CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK);
1730 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp failure scp=0x%p code=0x%x",
1734 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1736 if (scp->redirBufCount > 0) {
1737 LARGE_INTEGER heldExtents;
1738 AFSFileExtentCB extentList[1024];
1739 DWORD extentCount = 0;
1744 heldExtents.QuadPart = 0;
1746 for ( srbp = redirq_to_cm_buf_t(scp->redirQueueT);
1748 srbp = redirq_to_cm_buf_t(osi_QPrev(&srbp->redirq)))
1750 extentList[extentCount].Flags = 0;
1751 extentList[extentCount].Length = cm_data.blockSize;
1752 extentList[extentCount].FileOffset.QuadPart = srbp->offset.QuadPart;
1753 extentList[extentCount].CacheOffset.QuadPart = srbp->datap - RDR_extentBaseAddress;
1754 lock_ObtainWrite(&buf_globalLock);
1755 srbp->redirReleaseRequested = now;
1756 lock_ReleaseWrite(&buf_globalLock);
1759 if (extentCount == 1024) {
1760 lock_ReleaseWrite(&scp->rw);
1761 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1763 if (code == CM_ERROR_RETRY) {
1765 * The redirector either is not holding the extents or cannot let them
1766 * go because they are otherwise in use. At the moment, do nothing.
1773 lock_ObtainWrite(&scp->rw);
1777 if (code == 0 && extentCount > 0) {
1779 lock_ReleaseWrite(&scp->rw);
1782 code = RDR_RequestExtentRelease(&scp->fid, heldExtents, extentCount, extentList);
1787 /* No longer in use by redirector */
1789 lock_ObtainWrite(&scp->rw);
1794 lock_AssertWrite(&scp->rw);
1795 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
1798 if (bLastHandle || bFlushFile) {
1800 lock_ReleaseWrite(&scp->rw);
1803 code = buf_CleanVnode(scp, userp, &req);
1804 if (bLastHandle && code)
1808 if (bUnlockFile || bDeleteFile) {
1812 lock_ObtainWrite(&scp->rw);
1815 code = cm_SyncOp(scp, NULL, userp, &req, 0,
1816 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1818 osi_Log2(afsd_logp, "RDR_CleanupFileEntry cm_SyncOp (2) failure scp=0x%p code=0x%x",
1823 /* the scp is now locked and current */
1824 key = cm_GenerateKey(CM_SESSION_IFS, CleanupCB->ProcessId, 0);
1826 code = cm_UnlockByKey(scp, key,
1827 bDeleteFile ? CM_UNLOCK_FLAG_BY_FID : 0,
1830 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
1836 if (CleanupCB->ChangeTime.QuadPart) {
1838 if (scp->fileType == CM_SCACHETYPE_FILE) {
1839 /* Do not set length and other attributes at the same time */
1840 if (scp->length.QuadPart != CleanupCB->AllocationSize.QuadPart) {
1841 osi_Log2(afsd_logp, "RDR_CleanupFileEntry Length Change 0x%x -> 0x%x",
1842 (afs_uint32)scp->length.QuadPart, (afs_uint32)CleanupCB->AllocationSize.QuadPart);
1843 setAttr.mask |= CM_ATTRMASK_LENGTH;
1844 setAttr.length.LowPart = CleanupCB->AllocationSize.LowPart;
1845 setAttr.length.HighPart = CleanupCB->AllocationSize.HighPart;
1848 lock_ReleaseWrite(&scp->rw);
1851 code = cm_SetAttr(scp, &setAttr, userp, &req);
1859 lock_ObtainWrite(&scp->rw);
1863 if ((scp->unixModeBits & 0200) && (CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1864 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1865 setAttr.unixModeBits = scp->unixModeBits & ~0222;
1866 } else if (!(scp->unixModeBits & 0200) && !(CleanupCB->FileAttributes & FILE_ATTRIBUTE_READONLY)) {
1867 setAttr.mask |= CM_ATTRMASK_UNIXMODEBITS;
1868 setAttr.unixModeBits = scp->unixModeBits | 0222;
1872 if (CleanupCB->LastWriteTime.QuadPart) {
1873 ft.dwLowDateTime = CleanupCB->LastWriteTime.LowPart;
1874 ft.dwHighDateTime = CleanupCB->LastWriteTime.HighPart;
1876 cm_UnixTimeFromLargeSearchTime(&clientModTime, &ft);
1877 if (scp->clientModTime != clientModTime) {
1878 setAttr.mask |= CM_ATTRMASK_CLIENTMODTIME;
1879 setAttr.clientModTime = clientModTime;
1885 lock_ReleaseWrite(&scp->rw);
1887 code = cm_SetAttr(scp, &setAttr, userp, &req);
1893 lock_ReleaseWrite(&dscp->rw);
1895 lock_ReleaseWrite(&scp->rw);
1897 if (dscp && bDeleteFile) {
1898 WCHAR FileName[260];
1900 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1902 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
1903 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
1905 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
1909 (*ResultCB)->ResultStatus = 0;
1910 (*ResultCB)->ResultBufferLength = 0;
1911 osi_Log0(afsd_logp, "RDR_CleanupFileEntry SUCCESS");
1913 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1914 (*ResultCB)->ResultStatus = status;
1915 (*ResultCB)->ResultBufferLength = 0;
1916 osi_Log2(afsd_logp, "RDR_CleanupFileEntry FAILURE code=0x%x status=0x%x",
1920 cm_ReleaseSCache(scp);
1922 cm_ReleaseSCache(dscp);
1928 RDR_DeleteFileEntry( IN cm_user_t *userp,
1929 IN AFSFileID ParentId,
1930 IN ULONGLONG ProcessId,
1931 IN WCHAR *FileNameCounted,
1932 IN DWORD FileNameLength,
1935 IN DWORD ResultBufferLength,
1936 IN OUT AFSCommResult **ResultCB)
1939 AFSFileDeleteResultCB *pResultCB = NULL;
1940 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
1943 cm_scache_t * dscp = NULL;
1944 cm_scache_t * scp = NULL;
1945 afs_uint32 flags = 0;
1949 wchar_t FileName[260];
1952 StringCchCopyNW(FileName, 260, FileNameCounted, FileNameLength / sizeof(WCHAR));
1954 osi_Log4(afsd_logp, "RDR_DeleteFileEntry parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
1955 ParentId.Cell, ParentId.Volume,
1956 ParentId.Vnode, ParentId.Unique);
1957 osi_Log2(afsd_logp, "... name=%S checkOnly=%x",
1958 osi_LogSaveStringW(afsd_logp, FileName),
1963 req.flags |= CM_REQ_WOW64;
1964 memset(&setAttr, 0, sizeof(cm_attr_t));
1966 *ResultCB = (AFSCommResult *)malloc( size);
1968 osi_Log0(afsd_logp, "RDR_DeleteFileEntry out of memory");
1976 parentFid.cell = ParentId.Cell;
1977 parentFid.volume = ParentId.Volume;
1978 parentFid.vnode = ParentId.Vnode;
1979 parentFid.unique = ParentId.Unique;
1980 parentFid.hash = ParentId.Hash;
1982 code = cm_GetSCache(&parentFid, &dscp, userp, &req);
1984 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1985 (*ResultCB)->ResultStatus = status;
1986 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_GetSCache ParentFID failure code=0x%x status=0x%x",
1991 lock_ObtainWrite(&dscp->rw);
1993 code = cm_SyncOp(dscp, NULL, userp, &req, 0,
1994 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
1996 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
1997 (*ResultCB)->ResultStatus = status;
1998 (*ResultCB)->ResultBufferLength = 0;
1999 lock_ReleaseWrite(&dscp->rw);
2000 cm_ReleaseSCache(dscp);
2001 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure dscp=0x%p code=0x%x status=0x%x",
2002 dscp, code, status);
2006 cm_SyncOpDone(dscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2007 lock_ReleaseWrite(&dscp->rw);
2009 if (dscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2010 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2011 cm_ReleaseSCache(dscp);
2012 osi_Log1(afsd_logp, "RDR_DeleteFileEntry Not a Directory dscp=0x%p",
2017 code = cm_Lookup(dscp, FileName, 0, userp, &req, &scp);
2019 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2020 (*ResultCB)->ResultStatus = status;
2021 (*ResultCB)->ResultBufferLength = 0;
2022 cm_ReleaseSCache(dscp);
2023 osi_Log2(afsd_logp, "RDR_DeleteFileEntry cm_Lookup failure code=0x%x status=0x%x",
2028 lock_ObtainWrite(&scp->rw);
2029 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_DELETE,
2030 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2032 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2033 (*ResultCB)->ResultStatus = status;
2034 (*ResultCB)->ResultBufferLength = 0;
2035 lock_ReleaseWrite(&scp->rw);
2036 cm_ReleaseSCache(scp);
2037 cm_ReleaseSCache(dscp);
2038 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2044 /* Drop all locks since the file is being deleted */
2045 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2046 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2048 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2049 (*ResultCB)->ResultStatus = status;
2050 (*ResultCB)->ResultBufferLength = 0;
2051 lock_ReleaseWrite(&scp->rw);
2052 cm_ReleaseSCache(scp);
2053 cm_ReleaseSCache(dscp);
2054 osi_Log3(afsd_logp, "RDR_DeleteFileEntry cm_SyncOp Lock failure scp=0x%p code=0x%x status=0x%x",
2058 /* the scp is now locked and current */
2059 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId, 0);
2061 code = cm_UnlockByKey(scp, key,
2062 CM_UNLOCK_FLAG_BY_FID,
2065 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
2066 lock_ReleaseWrite(&scp->rw);
2068 if (scp->fileType == CM_SCACHETYPE_DIRECTORY)
2069 code = cm_RemoveDir(dscp, NULL, FileName, userp, &req);
2071 code = cm_Unlink(dscp, NULL, FileName, userp, &req);
2073 lock_ReleaseWrite(&scp->rw);
2077 (*ResultCB)->ResultStatus = 0; // We will be able to fit all the data in here
2079 (*ResultCB)->ResultBufferLength = sizeof( AFSFileDeleteResultCB);
2081 pResultCB = (AFSFileDeleteResultCB *)(*ResultCB)->ResultData;
2083 pResultCB->ParentDataVersion.QuadPart = dscp->dataVersion;
2084 osi_Log0(afsd_logp, "RDR_DeleteFileEntry SUCCESS");
2086 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2087 (*ResultCB)->ResultStatus = status;
2088 (*ResultCB)->ResultBufferLength = 0;
2089 osi_Log2(afsd_logp, "RDR_DeleteFileEntry FAILURE code=0x%x status=0x%x",
2093 cm_ReleaseSCache(dscp);
2094 cm_ReleaseSCache(scp);
2100 RDR_RenameFileEntry( IN cm_user_t *userp,
2101 IN WCHAR *SourceFileNameCounted,
2102 IN DWORD SourceFileNameLength,
2103 IN AFSFileID SourceFileId,
2104 IN AFSFileRenameCB *pRenameCB,
2106 IN DWORD ResultBufferLength,
2107 IN OUT AFSCommResult **ResultCB)
2110 AFSFileRenameResultCB *pResultCB = NULL;
2111 size_t size = sizeof(AFSCommResult) + ResultBufferLength - 1;
2112 AFSFileID SourceParentId = pRenameCB->SourceParentId;
2113 AFSFileID TargetParentId = pRenameCB->TargetParentId;
2114 WCHAR * TargetFileNameCounted = pRenameCB->TargetName;
2115 DWORD TargetFileNameLength = pRenameCB->TargetNameLength;
2116 cm_fid_t SourceParentFid;
2117 cm_fid_t TargetParentFid;
2118 cm_scache_t * oldDscp;
2119 cm_scache_t * newDscp;
2120 wchar_t shortName[13];
2121 wchar_t SourceFileName[260];
2122 wchar_t TargetFileName[260];
2130 req.flags |= CM_REQ_WOW64;
2132 StringCchCopyNW(SourceFileName, 260, SourceFileNameCounted, SourceFileNameLength / sizeof(WCHAR));
2133 StringCchCopyNW(TargetFileName, 260, TargetFileNameCounted, TargetFileNameLength / sizeof(WCHAR));
2135 osi_Log4(afsd_logp, "RDR_RenameFileEntry Source Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2136 SourceParentId.Cell, SourceParentId.Volume,
2137 SourceParentId.Vnode, SourceParentId.Unique);
2138 osi_Log2(afsd_logp, "... Source Name=%S Length %u", osi_LogSaveStringW(afsd_logp, SourceFileName), SourceFileNameLength);
2139 osi_Log4(afsd_logp, "... Target Parent FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2140 TargetParentId.Cell, TargetParentId.Volume,
2141 TargetParentId.Vnode, TargetParentId.Unique);
2142 osi_Log2(afsd_logp, "... Target Name=%S Length %u", osi_LogSaveStringW(afsd_logp, TargetFileName), TargetFileNameLength);
2144 *ResultCB = (AFSCommResult *)malloc( size);
2152 pResultCB = (AFSFileRenameResultCB *)(*ResultCB)->ResultData;
2154 if (SourceFileNameLength == 0 || TargetFileNameLength == 0)
2156 osi_Log2(afsd_logp, "RDR_RenameFileEntry Invalid Name Length: src %u target %u",
2157 SourceFileNameLength, TargetFileNameLength);
2158 (*ResultCB)->ResultStatus = STATUS_INVALID_PARAMETER;
2162 SourceParentFid.cell = SourceParentId.Cell;
2163 SourceParentFid.volume = SourceParentId.Volume;
2164 SourceParentFid.vnode = SourceParentId.Vnode;
2165 SourceParentFid.unique = SourceParentId.Unique;
2166 SourceParentFid.hash = SourceParentId.Hash;
2168 TargetParentFid.cell = TargetParentId.Cell;
2169 TargetParentFid.volume = TargetParentId.Volume;
2170 TargetParentFid.vnode = TargetParentId.Vnode;
2171 TargetParentFid.unique = TargetParentId.Unique;
2172 TargetParentFid.hash = TargetParentId.Hash;
2174 code = cm_GetSCache(&SourceParentFid, &oldDscp, userp, &req);
2176 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache source parent failed code 0x%x", code);
2177 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2178 (*ResultCB)->ResultStatus = status;
2182 lock_ObtainWrite(&oldDscp->rw);
2183 code = cm_SyncOp(oldDscp, NULL, userp, &req, 0,
2184 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2186 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp oldDscp 0x%p failed code 0x%x", oldDscp, code);
2187 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2188 (*ResultCB)->ResultStatus = status;
2189 lock_ReleaseWrite(&oldDscp->rw);
2190 cm_ReleaseSCache(oldDscp);
2194 cm_SyncOpDone(oldDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2195 lock_ReleaseWrite(&oldDscp->rw);
2198 if (oldDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2199 osi_Log1(afsd_logp, "RDR_RenameFileEntry oldDscp 0x%p not a directory", oldDscp);
2200 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2201 cm_ReleaseSCache(oldDscp);
2205 code = cm_GetSCache(&TargetParentFid, &newDscp, userp, &req);
2207 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target parent failed code 0x%x", code);
2208 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2209 (*ResultCB)->ResultStatus = status;
2210 cm_ReleaseSCache(oldDscp);
2214 lock_ObtainWrite(&newDscp->rw);
2215 code = cm_SyncOp(newDscp, NULL, userp, &req, 0,
2216 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2218 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp newDscp 0x%p failed code 0x%x", newDscp, code);
2219 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2220 (*ResultCB)->ResultStatus = status;
2221 lock_ReleaseWrite(&newDscp->rw);
2222 cm_ReleaseSCache(oldDscp);
2223 cm_ReleaseSCache(newDscp);
2227 cm_SyncOpDone(newDscp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2228 lock_ReleaseWrite(&newDscp->rw);
2231 if (newDscp->fileType != CM_SCACHETYPE_DIRECTORY) {
2232 osi_Log1(afsd_logp, "RDR_RenameFileEntry newDscp 0x%p not a directory", newDscp);
2233 (*ResultCB)->ResultStatus = STATUS_NOT_A_DIRECTORY;
2234 cm_ReleaseSCache(oldDscp);
2235 cm_ReleaseSCache(newDscp);
2239 code = cm_Rename( oldDscp, NULL, SourceFileName,
2240 newDscp, TargetFileName, userp, &req);
2244 cm_scache_t *scp = 0;
2247 (*ResultCB)->ResultBufferLength = ResultBufferLength;
2248 dwRemaining = ResultBufferLength - sizeof( AFSFileRenameResultCB) + sizeof( AFSDirEnumEntry);
2249 (*ResultCB)->ResultStatus = 0;
2251 pResultCB->SourceParentDataVersion.QuadPart = oldDscp->dataVersion;
2252 pResultCB->TargetParentDataVersion.QuadPart = newDscp->dataVersion;
2254 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p SUCCESS",
2257 code = cm_BeginDirOp( newDscp, userp, &req, CM_DIRLOCK_READ, CM_DIROP_FLAG_NONE, &dirop);
2259 code = cm_BPlusDirLookup(&dirop, TargetFileName, &targetFid);
2260 cm_EndDirOp(&dirop);
2264 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_BPlusDirLookup failed code 0x%x",
2266 (*ResultCB)->ResultStatus = STATUS_OBJECT_PATH_INVALID;
2267 cm_ReleaseSCache(oldDscp);
2268 cm_ReleaseSCache(newDscp);
2272 osi_Log4(afsd_logp, "RDR_RenameFileEntry Target FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2273 targetFid.cell, targetFid.volume,
2274 targetFid.vnode, targetFid.unique);
2276 code = cm_GetSCache(&targetFid, &scp, userp, &req);
2278 osi_Log1(afsd_logp, "RDR_RenameFileEntry cm_GetSCache target failed code 0x%x", code);
2279 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2280 (*ResultCB)->ResultStatus = status;
2281 cm_ReleaseSCache(oldDscp);
2282 cm_ReleaseSCache(newDscp);
2286 /* Make sure the source vnode is current */
2287 lock_ObtainWrite(&scp->rw);
2288 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2289 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2291 osi_Log2(afsd_logp, "RDR_RenameFileEntry cm_SyncOp scp 0x%p failed code 0x%x", scp, code);
2292 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2293 (*ResultCB)->ResultStatus = status;
2294 lock_ReleaseWrite(&scp->rw);
2295 cm_ReleaseSCache(oldDscp);
2296 cm_ReleaseSCache(newDscp);
2297 cm_ReleaseSCache(scp);
2301 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2302 lock_ReleaseWrite(&scp->rw);
2304 dfid.vnode = htonl(scp->fid.vnode);
2305 dfid.unique = htonl(scp->fid.unique);
2307 if (!cm_Is8Dot3(TargetFileName))
2308 cm_Gen8Dot3NameIntW(TargetFileName, &dfid, shortName, NULL);
2310 shortName[0] = '\0';
2312 RDR_PopulateCurrentEntry(&pResultCB->DirEnum, dwRemaining,
2313 newDscp, scp, userp, &req, TargetFileName, shortName,
2314 RDR_POP_FOLLOW_MOUNTPOINTS | RDR_POP_EVALUATE_SYMLINKS,
2315 NULL, &dwRemaining);
2316 (*ResultCB)->ResultBufferLength = ResultBufferLength - dwRemaining;
2317 cm_ReleaseSCache(scp);
2319 osi_Log0(afsd_logp, "RDR_RenameFileEntry SUCCESS");
2321 osi_Log3(afsd_logp, "RDR_RenameFileEntry cm_Rename oldDscp 0x%p newDscp 0x%p failed code 0x%x",
2322 oldDscp, newDscp, code);
2323 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2324 (*ResultCB)->ResultStatus = status;
2325 (*ResultCB)->ResultBufferLength = 0;
2328 cm_ReleaseSCache(oldDscp);
2329 cm_ReleaseSCache(newDscp);
2334 RDR_FlushFileEntry( IN cm_user_t *userp,
2335 IN AFSFileID FileId,
2337 IN DWORD ResultBufferLength,
2338 IN OUT AFSCommResult **ResultCB)
2340 cm_scache_t *scp = NULL;
2351 req.flags |= CM_REQ_WOW64;
2353 osi_Log4(afsd_logp, "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x",
2354 FileId.Cell, FileId.Volume,
2355 FileId.Vnode, FileId.Unique);
2357 snprintf( dbgstr, 1024,
2358 "RDR_FlushFileEntry File FID cell 0x%x vol 0x%x vno 0x%x uniq 0x%x\n",
2359 FileId.Cell, FileId.Volume,
2360 FileId.Vnode, FileId.Unique);
2361 OutputDebugStringA( dbgstr);
2364 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
2366 osi_Log0(afsd_logp, "RDR_FlushFileEntry out of memory");
2372 sizeof( AFSCommResult));
2374 /* Process the release */
2375 Fid.cell = FileId.Cell;
2376 Fid.volume = FileId.Volume;
2377 Fid.vnode = FileId.Vnode;
2378 Fid.unique = FileId.Unique;
2379 Fid.hash = FileId.Hash;
2381 code = cm_GetSCache(&Fid, &scp, userp, &req);
2383 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2384 (*ResultCB)->ResultStatus = status;
2385 osi_Log2(afsd_logp, "RDR_FlushFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2390 lock_ObtainWrite(&scp->rw);
2391 if (scp->flags & CM_SCACHEFLAG_DELETED) {
2392 lock_ReleaseWrite(&scp->rw);
2393 (*ResultCB)->ResultStatus = STATUS_INVALID_HANDLE;
2397 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2398 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2400 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2401 (*ResultCB)->ResultStatus = status;
2402 lock_ReleaseWrite(&scp->rw);
2403 cm_ReleaseSCache(scp);
2404 osi_Log3(afsd_logp, "RDR_FlushFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2409 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2410 lock_ReleaseWrite(&scp->rw);
2412 code = cm_FSync(scp, userp, &req, FALSE);
2413 cm_ReleaseSCache(scp);
2416 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2417 (*ResultCB)->ResultStatus = status;
2418 osi_Log2(afsd_logp, "RDR_FlushFileEntry FAILURE code=0x%x status=0x%x",
2421 (*ResultCB)->ResultStatus = 0;
2422 osi_Log0(afsd_logp, "RDR_FlushFileEntry SUCCESS");
2424 (*ResultCB)->ResultBufferLength = 0;
2430 RDR_CheckAccess( IN cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp,
2434 ULONG afs_acc, afs_gr;
2436 afs_uint32 code = 0;
2438 file = (scp->fileType == CM_SCACHETYPE_FILE);
2441 /* access definitions from prs_fs.h */
2443 if (access & FILE_READ_DATA)
2444 afs_acc |= PRSFS_READ;
2445 if (access & FILE_READ_EA || access & FILE_READ_ATTRIBUTES)
2446 afs_acc |= PRSFS_READ;
2447 if (file && ((access & FILE_WRITE_DATA) || (access & FILE_APPEND_DATA)))
2448 afs_acc |= PRSFS_WRITE;
2449 if (access & FILE_WRITE_EA || access & FILE_WRITE_ATTRIBUTES)
2450 afs_acc |= PRSFS_WRITE;
2451 if (dir && ((access & FILE_ADD_FILE) || (access & FILE_ADD_SUBDIRECTORY)))
2452 afs_acc |= PRSFS_INSERT;
2453 if (dir && (access & FILE_LIST_DIRECTORY))
2454 afs_acc |= PRSFS_LOOKUP;
2455 if (file && (access & FILE_EXECUTE))
2456 afs_acc |= PRSFS_WRITE;
2457 if (dir && (access & FILE_TRAVERSE))
2458 afs_acc |= PRSFS_READ;
2459 if (dir && (access & FILE_DELETE_CHILD))
2460 afs_acc |= PRSFS_DELETE;
2461 if ((access & DELETE))
2462 afs_acc |= PRSFS_DELETE;
2464 /* check ACL with server */
2465 lock_ObtainWrite(&scp->rw);
2468 if (cm_HaveAccessRights(scp, userp, reqp, afs_acc, &afs_gr))
2474 /* we don't know the required access rights */
2475 code = cm_GetAccessRights(scp, userp, reqp);
2481 lock_ReleaseWrite(&(scp->rw));
2485 if (afs_gr & PRSFS_READ)
2486 *granted |= FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | FILE_EXECUTE;
2487 if (afs_gr & PRSFS_WRITE)
2488 *granted |= FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES | FILE_EXECUTE;
2489 if (afs_gr & PRSFS_INSERT)
2490 *granted |= (dir ? FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY : 0) | (file ? FILE_ADD_SUBDIRECTORY : 0);
2491 if (afs_gr & PRSFS_LOOKUP)
2492 *granted |= (dir ? FILE_LIST_DIRECTORY : 0);
2493 if (afs_gr & PRSFS_DELETE)
2494 *granted |= FILE_DELETE_CHILD | DELETE;
2495 if (afs_gr & PRSFS_LOCK)
2497 if (afs_gr & PRSFS_ADMINISTER)
2500 *granted |= SYNCHRONIZE | READ_CONTROL;
2502 /* don't give more access than what was requested */
2504 osi_Log3(afsd_logp, "RDR_CheckAccess SUCCESS scp=0x%p requested=0x%x granted=0x%x", scp, access, *granted);
2506 osi_Log2(afsd_logp, "RDR_CheckAccess FAILURE scp=0x%p code=0x%x",
2513 RDR_OpenFileEntry( IN cm_user_t *userp,
2514 IN AFSFileID FileId,
2515 IN AFSFileOpenCB *OpenCB,
2518 IN DWORD ResultBufferLength,
2519 IN OUT AFSCommResult **ResultCB)
2521 AFSFileOpenResultCB *pResultCB = NULL;
2522 cm_scache_t *scp = NULL;
2523 cm_user_t *sysUserp = NULL;
2525 cm_lock_data_t *ldp = NULL;
2532 req.flags |= CM_REQ_WOW64;
2534 osi_Log4(afsd_logp, "RDR_OpenFileEntry File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2535 FileId.Cell, FileId.Volume,
2536 FileId.Vnode, FileId.Unique);
2538 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2540 osi_Log0(afsd_logp, "RDR_OpenFileEntry out of memory");
2546 sizeof( AFSCommResult) + sizeof( AFSFileOpenResultCB));
2548 pResultCB = (AFSFileOpenResultCB *)(*ResultCB)->ResultData;
2550 /* Process the release */
2551 Fid.cell = FileId.Cell;
2552 Fid.volume = FileId.Volume;
2553 Fid.vnode = FileId.Vnode;
2554 Fid.unique = FileId.Unique;
2555 Fid.hash = FileId.Hash;
2557 code = cm_GetSCache(&Fid, &scp, userp, &req);
2559 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2560 (*ResultCB)->ResultStatus = status;
2561 osi_Log2(afsd_logp, "RDR_OpenFileEntry cm_GetSCache FID failure code=0x%x status=0x%x",
2566 lock_ObtainWrite(&scp->rw);
2567 code = cm_SyncOp(scp, NULL, userp, &req, 0,
2568 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2570 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2571 (*ResultCB)->ResultStatus = status;
2572 lock_ReleaseWrite(&scp->rw);
2573 cm_ReleaseSCache(scp);
2574 osi_Log3(afsd_logp, "RDR_OpenFileEntry cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
2579 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2580 lock_ReleaseWrite(&scp->rw);
2582 sysUserp = RDR_GetLocalSystemUser();
2585 * Skip the open check if the request is coming from the local system account.
2586 * The local system has no tokens and therefore any requests sent to a file
2587 * server will fail. Unfortunately, there are special system processes that
2588 * perform actions on files and directories in preparation for memory mapping
2589 * executables. If the open check fails, the real request from the user process
2590 * will never be issued.
2592 * Permitting the file system to allow subsequent operations to proceed does
2593 * not compromise security. All requests to obtain file data or directory
2594 * enumerations will subsequently fail if they are not submitted under the
2595 * context of a process for that have access to the necessary credentials.
2598 if ( userp == sysUserp)
2600 osi_Log1(afsd_logp, "RDR_OpenFileEntry LOCAL_SYSTEM access check skipped scp=0x%p",
2602 pResultCB->GrantedAccess = OpenCB->DesiredAccess;
2610 "RDR_OpenFileEntry repeating open check scp=0x%p userp=0x%p code=0x%x",
2613 code = cm_CheckNTOpen(scp, OpenCB->DesiredAccess, OPEN_ALWAYS, userp, &req, &ldp);
2615 code = RDR_CheckAccess(scp, userp, &req, OpenCB->DesiredAccess, &pResultCB->GrantedAccess);
2616 cm_CheckNTOpenDone(scp, userp, &req, &ldp);
2617 } while (count < 100 && (code == CM_ERROR_RETRY || code == CM_ERROR_WOULDBLOCK));
2620 cm_ReleaseUser(sysUserp);
2622 RDR_FlagScpInUse( scp, FALSE );
2623 cm_ReleaseSCache(scp);
2626 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2627 (*ResultCB)->ResultStatus = status;
2628 osi_Log2(afsd_logp, "RDR_OpenFileEntry FAILURE code=0x%x status=0x%x",
2631 (*ResultCB)->ResultStatus = 0;
2632 (*ResultCB)->ResultBufferLength = sizeof( AFSFileOpenResultCB);
2633 osi_Log0(afsd_logp, "RDR_OpenFileEntry SUCCESS");
2639 HexCheckSum(unsigned char * buf, int buflen, unsigned char * md5cksum)
2642 static char tr[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
2645 return "buffer length too small to HexCheckSum";
2647 for (i=0;i<16;i++) {
2650 buf[i*2] = tr[k / 16];
2651 buf[i*2+1] = tr[k % 16];
2659 * Extent requests from the file system are triggered when a file
2660 * page is not resident in the Windows cache. The file system is
2661 * responsible for loading the page but cannot block the request
2662 * while doing so. The AFS Redirector forwards the requests to
2663 * the AFS cache manager while indicating to Windows that the page
2664 * is not yet available. A polling operation will then ensue with
2665 * the AFS Redirector issuing a RDR_RequestFileExtentsXXX call for
2666 * each poll attempt. As each request is received and processed
2667 * by a separate worker thread in the service, this can lead to
2668 * contention by multiple threads attempting to claim the same
2669 * cm_buf_t objects. Therefore, it is important that
2671 * (a) the service avoid processing more than one overlapping
2672 * extent request at a time
2673 * (b) background daemon processing be used to avoid blocking
2676 * Beginning with the 20091122 build of the redirector, the redirector
2677 * will not issue an additional RDR_RequestFileExtentsXXX call for
2678 * each poll request. Instead, afsd_service is required to track
2679 * the requests and return them to the redirector or fail the
2680 * portions of the request that cannot be satisfied.
2682 * The request processing returns any extents that can be returned
2683 * immediately to the redirector. The rest of the requested range(s)
2684 * are queued as background operations using RDR_BkgFetch().
2687 /* do the background fetch. */
2689 RDR_BkgFetch(cm_scache_t *scp, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4,
2690 cm_user_t *userp, cm_req_t *reqp)
2696 osi_hyper_t fetched;
2697 osi_hyper_t tblocksize;
2700 cm_buf_t *bufp = NULL;
2701 DWORD dwResultBufferLength;
2702 AFSSetFileExtentsCB *pResultCB;
2706 int reportErrorToRedir = 0;
2707 int force_retry = 0;
2709 FileId.Cell = scp->fid.cell;
2710 FileId.Volume = scp->fid.volume;
2711 FileId.Vnode = scp->fid.vnode;
2712 FileId.Unique = scp->fid.unique;
2713 FileId.Hash = scp->fid.hash;
2715 if ((GetTickCount() - reqp->startTime) / 1000 > HardDeadtimeout * 5) {
2716 RDR_SetFileStatus( &scp->fid, STATUS_IO_TIMEOUT);
2720 fetched.LowPart = 0;
2721 fetched.HighPart = 0;
2722 tblocksize = ConvertLongToLargeInteger(cm_data.buf_blockSize);
2725 length.LowPart = p3;
2726 length.HighPart = p4;
2728 end = LargeIntegerAdd(base, length);
2730 osi_Log5(afsd_logp, "Starting BKG Fetch scp 0x%p offset 0x%x:%x length 0x%x:%x",
2731 scp, p2, p1, p4, p3);
2734 * Make sure we have a callback.
2735 * This is necessary so that we can return access denied
2736 * if a callback cannot be granted.
2738 lock_ObtainWrite(&scp->rw);
2739 code = cm_SyncOp(scp, NULL, userp, reqp, PRSFS_READ,
2740 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
2742 lock_ReleaseWrite(&scp->rw);
2743 osi_Log2(afsd_logp, "RDR_BkgFetch cm_SyncOp failure scp=0x%p code=0x%x",
2745 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
2746 RDR_SetFileStatus( &scp->fid, status);
2749 lock_ReleaseWrite(&scp->rw);
2751 dwResultBufferLength = (DWORD)(sizeof( AFSSetFileExtentsCB) + sizeof( AFSSetFileExtentsCB) * (length.QuadPart / cm_data.blockSize + 1));
2752 pResultCB = (AFSSetFileExtentsCB *)malloc( dwResultBufferLength );
2754 return CM_ERROR_RETRY;
2756 memset( pResultCB, '\0', dwResultBufferLength );
2757 pResultCB->FileId = FileId;
2759 for ( code = 0, offset = base;
2760 code == 0 && LargeIntegerLessThan(offset, end);
2761 offset = LargeIntegerAdd(offset, tblocksize) )
2763 int bBufRelease = TRUE;
2766 lock_ReleaseWrite(&scp->rw);
2770 code = buf_Get(scp, &offset, reqp, &bufp);
2773 * any error from buf_Get() is non-fatal.
2774 * we need to re-queue this extent fetch.
2781 lock_ObtainWrite(&scp->rw);
2785 code = cm_GetBuffer(scp, bufp, NULL, userp, reqp);
2787 if (bufp->flags & CM_BUF_DIRTY) {
2789 lock_ReleaseWrite(&scp->rw);
2792 cm_BufWrite(scp, &bufp->offset, cm_chunkSize, 0, userp, reqp);
2795 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
2796 #ifdef VALIDATE_CHECK_SUM
2803 lock_ObtainWrite(&scp->rw);
2806 lock_ObtainWrite(&buf_globalLock);
2807 if (!(bufp->flags & CM_BUF_DIRTY) &&
2808 bufp->cmFlags == 0 &&
2809 !(bufp->qFlags & CM_BUF_QREDIR)) {
2810 buf_InsertToRedirQueue(scp, bufp);
2811 lock_ReleaseWrite(&buf_globalLock);
2812 lock_ReleaseWrite(&scp->rw);
2815 #ifdef VALIDATE_CHECK_SUM
2816 buf_ComputeCheckSum(bufp);
2818 pResultCB->FileExtents[count].Flags = 0;
2819 pResultCB->FileExtents[count].FileOffset.QuadPart = bufp->offset.QuadPart;
2820 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
2821 pResultCB->FileExtents[count].Length = cm_data.blockSize;
2823 fetched = LargeIntegerAdd(fetched, tblocksize);
2824 bBufRelease = FALSE;
2826 #ifdef VALIDATE_CHECK_SUM
2828 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
2829 snprintf( dbgstr, 1024,
2830 "RDR_BkgFetch md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
2832 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
2833 pResultCB->FileExtents[count].FileOffset.HighPart,
2834 pResultCB->FileExtents[count].FileOffset.LowPart,
2835 pResultCB->FileExtents[count].CacheOffset.HighPart,
2836 pResultCB->FileExtents[count].CacheOffset.LowPart);
2837 OutputDebugStringA( dbgstr);
2840 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
2841 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
2843 lock_ReleaseWrite(&buf_globalLock);
2844 if ((bufp->cmFlags != 0) || (bufp->flags & CM_BUF_DIRTY)) {
2845 /* An I/O operation is already in progress */
2847 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",
2848 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
2850 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
2851 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
2855 osi_Log4(afsd_logp, "RDR_BkgFetch Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
2856 bufp, bufp->offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
2860 lock_ReleaseWrite(&scp->rw);
2866 * depending on what the error from cm_GetBuffer is
2867 * it may or may not be fatal. Only return fatal errors.
2868 * Re-queue a request for others.
2870 osi_Log5(afsd_logp, "RDR_BkgFetch Extent2FS FAILURE bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x code 0x%x",
2871 bufp, offset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize, code);
2873 case CM_ERROR_NOACCESS:
2874 case CM_ERROR_NOSUCHFILE:
2875 case CM_ERROR_NOSUCHPATH:
2876 case CM_ERROR_NOSUCHVOLUME:
2877 case CM_ERROR_NOSUCHCELL:
2878 case CM_ERROR_INVAL:
2879 case CM_ERROR_BADFD:
2880 case CM_ERROR_CLOCKSKEW:
2882 case CM_ERROR_QUOTA:
2883 case CM_ERROR_LOCK_CONFLICT:
2885 * these are fatal errors. deliver what we can
2888 reportErrorToRedir = 1;
2892 * non-fatal errors. re-queue the exent
2894 code = CM_ERROR_RETRY;
2903 lock_ObtainWrite(&scp->rw);
2907 /* wakeup anyone who is waiting */
2908 if (scp->flags & CM_SCACHEFLAG_WAITING) {
2909 osi_Log1(afsd_logp, "RDR Bkg Fetch Waking scp 0x%p", scp);
2910 osi_Wakeup((LONG_PTR) &scp->flags);
2912 lock_ReleaseWrite(&scp->rw);
2915 pResultCB->ExtentCount = count;
2916 RDR_SetFileExtents( pResultCB, dwResultBufferLength);
2920 if (reportErrorToRedir) {
2921 smb_MapNTError(cm_MapRPCError(code, reqp), &status, TRUE);
2922 RDR_SetFileStatus( &scp->fid, status);
2925 osi_Log4(afsd_logp, "Ending BKG Fetch scp 0x%p code 0x%x fetched 0x%x:%x",
2926 scp, code, fetched.HighPart, fetched.LowPart);
2928 return force_retry ? CM_ERROR_RETRY : code;
2933 RDR_RequestFileExtentsAsync( IN cm_user_t *userp,
2934 IN AFSFileID FileId,
2935 IN AFSRequestExtentsCB *RequestExtentsCB,
2937 IN OUT DWORD * ResultBufferLength,
2938 IN OUT AFSSetFileExtentsCB **ResultCB)
2940 AFSSetFileExtentsCB *pResultCB = NULL;
2944 cm_scache_t *scp = NULL;
2947 afs_uint32 code = 0;
2949 LARGE_INTEGER ByteOffset, BeginOffset, EndOffset, QueueOffset;
2950 afs_uint32 QueueLength;
2952 BOOLEAN bBufRelease = TRUE;
2956 req.flags |= CM_REQ_WOW64;
2957 req.flags |= CM_REQ_NORETRY;
2959 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
2960 FileId.Cell, FileId.Volume,
2961 FileId.Vnode, FileId.Unique);
2962 osi_Log4(afsd_logp, "... Flags 0x%x ByteOffset 0x%x:%x Length 0x%x",
2963 RequestExtentsCB->Flags,
2964 RequestExtentsCB->ByteOffset.HighPart, RequestExtentsCB->ByteOffset.LowPart,
2965 RequestExtentsCB->Length);
2966 Length = sizeof( AFSSetFileExtentsCB) + sizeof( AFSFileExtentCB) * (RequestExtentsCB->Length / cm_data.blockSize + 1);
2968 pResultCB = *ResultCB = (AFSSetFileExtentsCB *)malloc( Length );
2969 if (*ResultCB == NULL) {
2970 *ResultBufferLength = 0;
2973 *ResultBufferLength = Length;
2975 memset( pResultCB, '\0', Length );
2976 pResultCB->FileId = FileId;
2978 Fid.cell = FileId.Cell;
2979 Fid.volume = FileId.Volume;
2980 Fid.vnode = FileId.Vnode;
2981 Fid.unique = FileId.Unique;
2982 Fid.hash = FileId.Hash;
2984 code = cm_GetSCache(&Fid, &scp, userp, &req);
2986 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync cm_GetSCache FID failure code=0x%x",
2988 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
2989 RDR_SetFileStatus( &scp->fid, status);
2994 * Make sure we have a callback.
2995 * This is necessary so that we can return access denied
2996 * if a callback cannot be granted.
2998 lock_ObtainWrite(&scp->rw);
2999 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_READ,
3000 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3001 lock_ReleaseWrite(&scp->rw);
3003 cm_ReleaseSCache(scp);
3004 osi_Log2(afsd_logp, "RDR_RequestFileExtentsAsync cm_SyncOp failure scp=0x%p code=0x%x",
3006 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3007 RDR_SetFileStatus( &scp->fid, status);
3011 /* Allocate the extents from the buffer package */
3013 ByteOffset = BeginOffset = RequestExtentsCB->ByteOffset,
3014 EndOffset.QuadPart = ByteOffset.QuadPart + RequestExtentsCB->Length;
3015 code == 0 && ByteOffset.QuadPart < EndOffset.QuadPart;
3016 ByteOffset.QuadPart += cm_data.blockSize)
3018 BOOL bHaveBuffer = FALSE;
3021 thyper.QuadPart = ByteOffset.QuadPart;
3023 code = buf_Get(scp, &thyper, &req, &bufp);
3025 lock_ObtainMutex(&bufp->mx);
3028 if (bufp->qFlags & CM_BUF_QREDIR) {
3030 } else if (bufp->flags & CM_BUF_DIRTY) {
3031 bHaveBuffer = FALSE;
3033 code = buf_CleanAsyncLocked(scp, bufp, &req, 0, NULL);
3038 case CM_ERROR_RETRY:
3039 /* Couldn't flush it, obtain it asynchronously so we don't block the thread. */
3040 bHaveBuffer = FALSE;
3044 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3045 RDR_SetFileStatus(&FileId, status);
3046 bHaveBuffer = FALSE;
3051 osi_hyper_t minLength; /* effective end of file */
3053 lock_ObtainRead(&scp->rw);
3054 bHaveBuffer = cm_HaveBuffer(scp, bufp, TRUE);
3056 if (LargeIntegerGreaterThan(scp->length, scp->serverLength))
3057 minLength = scp->serverLength;
3059 minLength = scp->length;
3061 if (LargeIntegerGreaterThanOrEqualTo(bufp->offset, minLength)) {
3062 memset(bufp->datap, 0, cm_data.buf_blockSize);
3063 bufp->dataVersion = scp->dataVersion;
3066 lock_ReleaseRead(&scp->rw);
3068 if ((RequestExtentsCB->Flags & AFS_EXTENT_FLAG_CLEAN) &&
3069 ByteOffset.QuadPart <= bufp->offset.QuadPart &&
3070 EndOffset.QuadPart >= bufp->offset.QuadPart + cm_data.blockSize) {
3071 memset(bufp->datap, 0, cm_data.blockSize);
3072 bufp->dataVersion = scp->dataVersion;
3073 buf_SetDirty(bufp, &req, 0, cm_data.blockSize, userp);
3079 * if this buffer is already up to date, skip it.
3082 if (ByteOffset.QuadPart == BeginOffset.QuadPart) {
3083 BeginOffset.QuadPart += cm_data.blockSize;
3085 QueueLength = (afs_uint32)(ByteOffset.QuadPart - BeginOffset.QuadPart);
3086 QueueOffset = BeginOffset;
3087 BeginOffset = ByteOffset;
3090 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3091 #ifdef VALIDATE_CHECK_SUM
3097 lock_ObtainWrite(&scp->rw);
3098 lock_ObtainWrite(&buf_globalLock);
3099 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3100 buf_InsertToRedirQueue(scp, bufp);
3101 lock_ReleaseWrite(&buf_globalLock);
3102 lock_ReleaseWrite(&scp->rw);
3104 #ifdef VALIDATE_CHECK_SUM
3105 buf_ComputeCheckSum(bufp);
3107 /* we already have the buffer, return it now */
3108 pResultCB->FileExtents[count].Flags = 0;
3109 pResultCB->FileExtents[count].FileOffset = ByteOffset;
3110 pResultCB->FileExtents[count].CacheOffset.QuadPart = bufp->datap - RDR_extentBaseAddress;
3111 pResultCB->FileExtents[count].Length = cm_data.blockSize;
3114 bBufRelease = FALSE;
3116 #ifdef VALIDATE_CHECK_SUM
3118 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3119 snprintf( dbgstr, 1024,
3120 "RDR_RequestFileExtentsAsync md5 %s vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3122 scp->fid.volume, scp->fid.vnode, scp->fid.unique,
3123 pResultCB->FileExtents[count].FileOffset.HighPart,
3124 pResultCB->FileExtents[count].FileOffset.LowPart,
3125 pResultCB->FileExtents[count].CacheOffset.HighPart,
3126 pResultCB->FileExtents[count].CacheOffset.LowPart);
3127 OutputDebugStringA( dbgstr);
3130 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3131 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3133 lock_ReleaseWrite(&buf_globalLock);
3134 lock_ReleaseWrite(&scp->rw);
3139 * The service is not handing off the extent to the redirector in this pass.
3140 * However, we know the buffer is in recent use so move the buffer to the
3141 * front of the queue
3143 lock_ObtainWrite(&scp->rw);
3144 lock_ObtainWrite(&buf_globalLock);
3145 buf_MoveToHeadOfRedirQueue(scp, bufp);
3146 lock_ReleaseWrite(&buf_globalLock);
3147 lock_ReleaseWrite(&scp->rw);
3149 osi_Log4(afsd_logp, "RDR_RequestFileExtentsAsync Extent2FS Already held by Redirector bufp 0x%p foffset 0x%p coffset 0x%p len 0x%x",
3150 bufp, ByteOffset.QuadPart, bufp->datap - RDR_extentBaseAddress, cm_data.blockSize);
3154 lock_ReleaseMutex(&bufp->mx);
3159 cm_QueueBKGRequest(scp, RDR_BkgFetch, QueueOffset.LowPart, QueueOffset.HighPart,
3160 QueueLength, 0, userp, &req);
3161 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3162 QueueOffset.HighPart, QueueOffset.LowPart, QueueLength);
3165 /* No error from buf_Get() can be fatal */
3166 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync buf_Get FAILURE offset 0x%x:%x code 0x%x",
3167 BeginOffset.HighPart, BeginOffset.LowPart, code);
3171 if (BeginOffset.QuadPart != EndOffset.QuadPart) {
3172 afs_uint32 length = (afs_uint32)(EndOffset.QuadPart - BeginOffset.QuadPart);
3174 cm_QueueBKGRequest(scp, RDR_BkgFetch, BeginOffset.LowPart, BeginOffset.HighPart,
3175 length, 0, userp, &req);
3176 osi_Log3(afsd_logp, "RDR_RequestFileExtentsAsync Queued a Background Fetch offset 0x%x:%x length 0x%x",
3177 BeginOffset.HighPart, BeginOffset.LowPart, length);
3179 cm_ReleaseSCache(scp);
3181 (*ResultCB)->ExtentCount = count;
3182 osi_Log1(afsd_logp, "RDR_RequestFileExtentsAsync replying with 0x%x extent records", count);
3187 * When processing an extent release the extents must be accepted back by
3188 * the service even if there is an error condition returned to the redirector.
3189 * For example, there may no longer be a callback present or the file may
3190 * have been deleted on the file server. Regardless, the extents must be
3191 * put back into the pool.
3194 RDR_ReleaseFileExtents( IN cm_user_t *userp,
3195 IN AFSFileID FileId,
3196 IN AFSReleaseExtentsCB *ReleaseExtentsCB,
3198 IN DWORD ResultBufferLength,
3199 IN OUT AFSCommResult **ResultCB)
3202 cm_scache_t *scp = NULL;
3212 #ifdef VALIDATE_CHECK_SUM
3213 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3220 req.flags |= CM_REQ_WOW64;
3222 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
3223 FileId.Cell, FileId.Volume,
3224 FileId.Vnode, FileId.Unique);
3226 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
3232 sizeof( AFSCommResult));
3234 /* Process the release */
3235 Fid.cell = FileId.Cell;
3236 Fid.volume = FileId.Volume;
3237 Fid.vnode = FileId.Vnode;
3238 Fid.unique = FileId.Unique;
3239 Fid.hash = FileId.Hash;
3241 code = cm_GetSCache(&Fid, &scp, userp, &req);
3243 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3244 (*ResultCB)->ResultStatus = status;
3245 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents cm_GetSCache FID failure code=0x%x status=0x%x",
3250 * We do not stop processing as a result of being unable to find the cm_scache object.
3251 * If this occurs something really bad has happened since the cm_scache object must have
3252 * been recycled while extents were held by the redirector. However, we will be resilient
3253 * and carry on without it.
3255 if (scp && ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3258 memset(&setAttr, 0, sizeof(cm_attr_t));
3259 lock_ObtainWrite(&scp->rw);
3260 if (ReleaseExtentsCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3262 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents new length fid vol 0x%x vno 0x%x length 0x%x:%x",
3263 scp->fid.volume, scp->fid.vnode,
3264 ReleaseExtentsCB->AllocationSize.HighPart,
3265 ReleaseExtentsCB->AllocationSize.LowPart);
3267 setAttr.mask |= CM_ATTRMASK_LENGTH;
3268 setAttr.length.LowPart = ReleaseExtentsCB->AllocationSize.LowPart;
3269 setAttr.length.HighPart = ReleaseExtentsCB->AllocationSize.HighPart;
3271 lock_ReleaseWrite(&scp->rw);
3273 code = cm_SetAttr(scp, &setAttr, userp, &req);
3276 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3277 AFSFileExtentCB * pExtent = &ReleaseExtentsCB->FileExtents[count];
3279 thyper.QuadPart = pExtent->FileOffset.QuadPart;
3281 bufp = buf_Find(&Fid, &thyper);
3283 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
3284 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3285 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3286 Fid.volume, Fid.vnode,
3287 pExtent->FileOffset.HighPart,
3288 pExtent->FileOffset.LowPart);
3289 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
3290 pExtent->CacheOffset.HighPart,
3291 pExtent->CacheOffset.LowPart);
3293 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3294 Fid.volume, Fid.vnode,
3295 pExtent->FileOffset.HighPart,
3296 pExtent->FileOffset.LowPart);
3297 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
3298 pExtent->CacheOffset.HighPart,
3299 pExtent->CacheOffset.LowPart);
3305 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
3306 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3307 Fid.volume, Fid.vnode,
3308 pExtent->FileOffset.HighPart,
3309 pExtent->FileOffset.LowPart);
3310 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
3311 pExtent->CacheOffset.HighPart,
3312 pExtent->CacheOffset.LowPart);
3314 /* Move the buffer to the front of the queue */
3316 lock_ObtainWrite(&scp->rw);
3317 lock_ObtainWrite(&buf_globalLock);
3318 buf_MoveToHeadOfRedirQueue(scp, bufp);
3319 lock_ReleaseWrite(&buf_globalLock);
3321 lock_ReleaseWrite(&scp->rw);
3326 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
3327 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3328 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents extent vol 0x%x vno 0x%x foffset 0x%x:%x not held by file system",
3329 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
3330 pExtent->FileOffset.LowPart);
3331 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3332 pExtent->CacheOffset.HighPart,
3333 pExtent->CacheOffset.LowPart);
3335 osi_Log4(afsd_logp, "RDR_ReleaseFileExtents bufp 0x%p vno 0x%x foffset 0x%x:%x",
3336 bufp, bufp->fid.vnode, pExtent->FileOffset.HighPart,
3337 pExtent->FileOffset.LowPart);
3338 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3339 pExtent->CacheOffset.HighPart,
3340 pExtent->CacheOffset.LowPart);
3342 if (pExtent->Flags || ReleaseExtentsCB->Flags) {
3343 lock_ObtainMutex(&bufp->mx);
3344 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
3345 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
3347 if (bufp->qFlags & CM_BUF_QREDIR) {
3349 lock_ObtainWrite(&scp->rw);
3350 lock_ObtainWrite(&buf_globalLock);
3351 if (bufp->qFlags & CM_BUF_QREDIR) {
3352 buf_RemoveFromRedirQueue(scp, bufp);
3353 lock_ReleaseWrite(&scp->rw);
3354 buf_ReleaseLocked(bufp, TRUE);
3357 lock_ReleaseWrite(&scp->rw);
3360 lock_ReleaseWrite(&buf_globalLock);
3363 snprintf( dbgstr, 1024,
3364 "RDR_ReleaseFileExtents releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3365 Fid.volume, Fid.vnode, Fid.unique,
3366 pExtent->FileOffset.HighPart,
3367 pExtent->FileOffset.LowPart,
3368 pExtent->CacheOffset.HighPart,
3369 pExtent->CacheOffset.LowPart);
3370 OutputDebugStringA( dbgstr);
3375 snprintf( dbgstr, 1024,
3376 "RDR_ReleaseFileExtents not releasing: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3377 Fid.volume, Fid.vnode, Fid.unique,
3378 pExtent->FileOffset.HighPart,
3379 pExtent->FileOffset.LowPart,
3380 pExtent->CacheOffset.HighPart,
3381 pExtent->CacheOffset.LowPart);
3382 OutputDebugStringA( dbgstr);
3384 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
3385 Fid.volume, Fid.vnode,
3386 pExtent->FileOffset.HighPart,
3387 pExtent->FileOffset.LowPart);
3388 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3389 pExtent->CacheOffset.HighPart,
3390 pExtent->CacheOffset.LowPart);
3393 if ( (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
3394 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY) )
3396 #ifdef VALIDATE_CHECK_SUM
3398 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3402 * if the saved checksum matches the checksum of the current state of the buffer
3403 * then the buffer is the same as what was given to the kernel.
3405 if ( buf_ValidateCheckSum(bufp) ) {
3406 buf_ComputeCheckSum(bufp);
3408 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3411 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
3412 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3414 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3417 snprintf( dbgstr, 1024,
3418 "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",
3419 md5dbg, md5dbg2,md5dbg3,
3420 Fid.volume, Fid.vnode, Fid.unique,
3421 pExtent->FileOffset.HighPart,
3422 pExtent->FileOffset.LowPart,
3423 pExtent->CacheOffset.HighPart,
3424 pExtent->CacheOffset.LowPart);
3425 OutputDebugStringA( dbgstr);
3427 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
3428 Fid.volume, Fid.vnode,
3429 pExtent->FileOffset.HighPart,
3430 pExtent->FileOffset.LowPart);
3431 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3432 pExtent->CacheOffset.HighPart,
3433 pExtent->CacheOffset.LowPart);
3434 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3438 snprintf( dbgstr, 1024,
3439 "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",
3440 md5dbg, md5dbg2, md5dbg3,
3441 Fid.volume, Fid.vnode, Fid.unique,
3442 pExtent->FileOffset.HighPart,
3443 pExtent->FileOffset.LowPart,
3444 pExtent->CacheOffset.HighPart,
3445 pExtent->CacheOffset.LowPart);
3446 OutputDebugStringA( dbgstr);
3448 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3449 Fid.volume, Fid.vnode,
3450 pExtent->FileOffset.HighPart,
3451 pExtent->FileOffset.LowPart);
3452 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3453 pExtent->CacheOffset.HighPart,
3454 pExtent->CacheOffset.LowPart);
3458 snprintf( dbgstr, 1024,
3459 "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",
3460 Fid.volume, Fid.vnode, Fid.unique,
3461 pExtent->FileOffset.HighPart,
3462 pExtent->FileOffset.LowPart,
3463 pExtent->CacheOffset.HighPart,
3464 pExtent->CacheOffset.LowPart);
3465 OutputDebugStringA( dbgstr);
3467 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3468 Fid.volume, Fid.vnode,
3469 pExtent->FileOffset.HighPart,
3470 pExtent->FileOffset.LowPart);
3471 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3472 pExtent->CacheOffset.HighPart,
3473 pExtent->CacheOffset.LowPart);
3476 buf_ComputeCheckSum(bufp);
3478 if (pExtent->Flags & AFS_EXTENT_FLAG_MD5_SET)
3480 HexCheckSum(md5dbg3, sizeof(md5dbg3), bufp->md5cksum);
3481 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3483 snprintf( dbgstr, 1024,
3484 "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",
3485 md5dbg, md5dbg2,md5dbg3,
3486 Fid.volume, Fid.vnode, Fid.unique,
3487 pExtent->FileOffset.HighPart,
3488 pExtent->FileOffset.LowPart,
3489 pExtent->CacheOffset.HighPart,
3490 pExtent->CacheOffset.LowPart);
3491 OutputDebugStringA( dbgstr);
3493 snprintf( dbgstr, 1024,
3494 "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",
3495 md5dbg, md5dbg2,md5dbg3,
3496 Fid.volume, Fid.vnode, Fid.unique,
3497 pExtent->FileOffset.HighPart,
3498 pExtent->FileOffset.LowPart,
3499 pExtent->CacheOffset.HighPart,
3500 pExtent->CacheOffset.LowPart);
3501 OutputDebugStringA( dbgstr);
3504 snprintf( dbgstr, 1024,
3505 "RDR_ReleaseFileExtents dirty flag set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3506 Fid.volume, Fid.vnode, Fid.unique,
3507 pExtent->FileOffset.HighPart,
3508 pExtent->FileOffset.LowPart,
3509 pExtent->CacheOffset.HighPart,
3510 pExtent->CacheOffset.LowPart);
3511 OutputDebugStringA( dbgstr);
3514 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3517 #else /* !VALIDATE_CHECK_SUM */
3518 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3520 #endif /* VALIDATE_CHECK_SUM */
3522 #ifdef VALIDATE_CHECK_SUM
3525 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3527 if ( !buf_ValidateCheckSum(bufp) ) {
3528 buf_ComputeCheckSum(bufp);
3530 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3531 snprintf( dbgstr, 1024,
3532 "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",
3534 Fid.volume, Fid.vnode, Fid.unique,
3535 pExtent->FileOffset.HighPart,
3536 pExtent->FileOffset.LowPart,
3537 pExtent->CacheOffset.HighPart,
3538 pExtent->CacheOffset.LowPart);
3539 OutputDebugStringA( dbgstr);
3541 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set but extent has changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3542 Fid.volume, Fid.vnode,
3543 pExtent->FileOffset.HighPart,
3544 pExtent->FileOffset.LowPart);
3545 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3546 pExtent->CacheOffset.HighPart,
3547 pExtent->CacheOffset.LowPart);
3548 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3551 buf_ComputeCheckSum(bufp);
3553 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3554 snprintf( dbgstr, 1024,
3555 "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3556 Fid.volume, Fid.vnode, Fid.unique,
3557 pExtent->FileOffset.HighPart,
3558 pExtent->FileOffset.LowPart,
3559 pExtent->CacheOffset.HighPart,
3560 pExtent->CacheOffset.LowPart);
3561 OutputDebugStringA( dbgstr);
3563 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents dirty flag not set: vol 0x%x vno 0x%x foffset 0x%x:%x",
3564 Fid.volume, Fid.vnode,
3565 pExtent->FileOffset.HighPart,
3566 pExtent->FileOffset.LowPart);
3567 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3568 pExtent->CacheOffset.HighPart,
3569 pExtent->CacheOffset.LowPart);
3572 #endif /* VALIDATE_CHECK_SUM */
3573 lock_ReleaseMutex(&bufp->mx);
3578 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3581 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3582 if (wbp->datap == datap)
3587 snprintf( dbgstr, 1024,
3588 "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3589 Fid.volume, Fid.vnode, Fid.unique,
3590 pExtent->FileOffset.HighPart,
3591 pExtent->FileOffset.LowPart,
3592 pExtent->CacheOffset.HighPart,
3593 pExtent->CacheOffset.LowPart);
3594 OutputDebugStringA( dbgstr);
3596 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3597 Fid.volume, Fid.vnode,
3598 pExtent->FileOffset.HighPart,
3599 pExtent->FileOffset.LowPart);
3600 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3601 pExtent->CacheOffset.HighPart,
3602 pExtent->CacheOffset.LowPart);
3603 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3604 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3612 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
3615 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
3616 if (wbp->datap == datap)
3621 snprintf( dbgstr, 1024,
3622 "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3623 Fid.volume, Fid.vnode, Fid.unique,
3624 pExtent->FileOffset.HighPart,
3625 pExtent->FileOffset.LowPart,
3626 pExtent->CacheOffset.HighPart,
3627 pExtent->CacheOffset.LowPart);
3628 OutputDebugStringA( dbgstr);
3630 osi_Log4( afsd_logp, "RDR_ReleaseFileExtents unknown extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3631 Fid.volume, Fid.vnode,
3632 pExtent->FileOffset.HighPart,
3633 pExtent->FileOffset.LowPart);
3634 osi_Log2( afsd_logp, "... coffset 0x%x:%x",
3635 pExtent->CacheOffset.HighPart,
3636 pExtent->CacheOffset.LowPart);
3637 osi_Log5( afsd_logp, "... belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
3638 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
3643 if (ReleaseExtentsCB->Flags & AFS_EXTENT_FLAG_FLUSH) {
3644 code = buf_CleanVnode(scp, userp, &req);
3647 osi_hyper_t offset = {0,0};
3648 afs_uint32 length = 0;
3649 afs_uint32 rights = 0;
3651 lock_ObtainWrite(&scp->rw);
3652 code = cm_SyncOp(scp, NULL, userp, &req, PRSFS_WRITE,
3653 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
3654 lock_ReleaseWrite(&scp->rw);
3657 * there is at least one dirty extent on this file. queue up background store
3658 * requests for contiguous blocks
3660 for ( count = 0; count < ReleaseExtentsCB->ExtentCount; count++) {
3661 if (ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart == offset.QuadPart + length &&
3662 length + cm_data.buf_blockSize <= cm_chunkSize)
3664 length += cm_data.buf_blockSize;
3666 if (!(offset.QuadPart == 0 && length == 0))
3667 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3668 length, 0, userp, &req);
3669 offset.QuadPart = ReleaseExtentsCB->FileExtents[count].FileOffset.QuadPart;
3670 length = cm_data.buf_blockSize;
3673 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
3674 length, 0, userp, &req);
3677 cm_ReleaseSCache(scp);
3680 osi_Log5(afsd_logp, "RDR_ReleaseFileExtents File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
3681 FileId.Cell, FileId.Volume,
3682 FileId.Vnode, FileId.Unique, released);
3683 if (code && code != CM_ERROR_WOULDBLOCK) {
3684 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
3685 (*ResultCB)->ResultStatus = status;
3686 osi_Log2(afsd_logp, "RDR_ReleaseFileExtents FAILURE code=0x%x status=0x%x",
3689 (*ResultCB)->ResultStatus = 0;
3690 osi_Log0(afsd_logp, "RDR_ReleaseFileExtents SUCCESS");
3692 (*ResultCB)->ResultBufferLength = 0;
3698 RDR_ProcessReleaseFileExtentsResult( IN AFSReleaseFileExtentsResultCB *ReleaseFileExtentsResultCB,
3699 IN DWORD ResultBufferLength)
3701 afs_uint32 code = 0;
3705 unsigned int fileno, extentno, total_extents = 0;
3706 AFSReleaseFileExtentsResultFileCB *pNextFileCB;
3708 #ifdef VALIDATE_CHECK_SUM
3709 char md5dbg[33], md5dbg2[33], md5dbg3[33];
3715 for ( fileno = 0, pNextFileCB = &ReleaseFileExtentsResultCB->Files[0];
3716 fileno < ReleaseFileExtentsResultCB->FileCount;
3718 AFSReleaseFileExtentsResultFileCB *pFileCB = pNextFileCB;
3719 cm_user_t *userp = NULL;
3721 cm_scache_t * scp = NULL;
3726 userp = RDR_UserFromAuthGroup( &pFileCB->AuthGroup);
3728 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult %d.%d.%d.%d",
3729 pFileCB->FileId.Cell, pFileCB->FileId.Volume,
3730 pFileCB->FileId.Vnode, pFileCB->FileId.Unique);
3732 /* Process the release */
3733 Fid.cell = pFileCB->FileId.Cell;
3734 Fid.volume = pFileCB->FileId.Volume;
3735 Fid.vnode = pFileCB->FileId.Vnode;
3736 Fid.unique = pFileCB->FileId.Unique;
3737 Fid.hash = pFileCB->FileId.Hash;
3739 if (Fid.cell == 0) {
3740 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult Invalid FID %d.%d.%d.%d",
3741 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
3742 code = CM_ERROR_INVAL;
3746 code = cm_GetSCache(&Fid, &scp, userp, &req);
3748 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult cm_GetSCache FID failure code=0x%x",
3751 * A failure to find the cm_scache object cannot prevent the service
3752 * from accepting the extents back from the redirector.
3756 /* if the scp was not found, do not perform the length check */
3757 if (scp && (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart)) {
3760 memset(&setAttr, 0, sizeof(cm_attr_t));
3761 lock_ObtainWrite(&scp->rw);
3762 if (pFileCB->AllocationSize.QuadPart != scp->length.QuadPart) {
3763 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult length change vol 0x%x vno 0x%x length 0x%x:%x",
3764 scp->fid.volume, scp->fid.vnode,
3765 pFileCB->AllocationSize.HighPart,
3766 pFileCB->AllocationSize.LowPart);
3767 setAttr.mask |= CM_ATTRMASK_LENGTH;
3768 setAttr.length.LowPart = pFileCB->AllocationSize.LowPart;
3769 setAttr.length.HighPart = pFileCB->AllocationSize.HighPart;
3771 lock_ReleaseWrite(&scp->rw);
3773 code = cm_SetAttr(scp, &setAttr, userp, &req);
3776 for ( extentno = 0; extentno < pFileCB->ExtentCount; total_extents++, extentno++ ) {
3777 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
3779 thyper.QuadPart = pExtent->FileOffset.QuadPart;
3781 bufp = buf_Find(&Fid, &thyper);
3783 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
3784 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3785 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3786 Fid.volume, Fid.vnode,
3787 pExtent->FileOffset.HighPart,
3788 pExtent->FileOffset.LowPart);
3789 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; previously released",
3790 pExtent->CacheOffset.HighPart,
3791 pExtent->CacheOffset.LowPart);
3793 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3794 Fid.volume, Fid.vnode,
3795 pExtent->FileOffset.HighPart,
3796 pExtent->FileOffset.LowPart);
3797 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; owned by redirector",
3798 pExtent->CacheOffset.HighPart,
3799 pExtent->CacheOffset.LowPart);
3805 if (pExtent->Flags & AFS_EXTENT_FLAG_IN_USE) {
3806 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3807 Fid.volume, Fid.vnode,
3808 pExtent->FileOffset.HighPart,
3809 pExtent->FileOffset.LowPart);
3810 osi_Log2(afsd_logp, "... coffset 0x%x:%x IN_USE by file system",
3811 pExtent->CacheOffset.HighPart,
3812 pExtent->CacheOffset.LowPart);
3814 /* Move the buffer to the front of the queue */
3816 lock_ObtainWrite(&scp->rw);
3817 lock_ObtainWrite(&buf_globalLock);
3818 buf_MoveToHeadOfRedirQueue(scp, bufp);
3819 lock_ReleaseWrite(&buf_globalLock);
3821 lock_ReleaseWrite(&scp->rw);
3826 if (bufp->datap - RDR_extentBaseAddress == pExtent->CacheOffset.QuadPart) {
3827 if (!(bufp->qFlags & CM_BUF_QREDIR)) {
3828 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
3829 Fid.volume, Fid.vnode,
3830 pExtent->FileOffset.HighPart,
3831 pExtent->FileOffset.LowPart);
3832 osi_Log2(afsd_logp, "... coffset 0x%x:%x not held by file system",
3833 pExtent->CacheOffset.HighPart,
3834 pExtent->CacheOffset.LowPart);
3836 snprintf(dbgstr, 1024,
3837 "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",
3838 ReleaseFileExtentsResultCB->Flags, pExtent->Flags,
3839 Fid.volume, Fid.vnode, Fid.unique,
3840 pExtent->FileOffset.HighPart,
3841 pExtent->FileOffset.LowPart,
3842 pExtent->CacheOffset.HighPart,
3843 pExtent->CacheOffset.LowPart);
3844 OutputDebugStringA( dbgstr);
3847 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
3848 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
3849 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
3851 if (pExtent->Flags || ReleaseFileExtentsResultCB->Flags) {
3852 lock_ObtainMutex(&bufp->mx);
3853 if ( (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_RELEASE) ||
3854 (pExtent->Flags & AFS_EXTENT_FLAG_RELEASE) )
3856 if (bufp->qFlags & CM_BUF_QREDIR) {
3858 lock_ObtainWrite(&scp->rw);
3859 lock_ObtainWrite(&buf_globalLock);
3860 if (bufp->qFlags & CM_BUF_QREDIR) {
3861 buf_RemoveFromRedirQueue(scp, bufp);
3863 lock_ReleaseWrite(&scp->rw);
3864 buf_ReleaseLocked(bufp, TRUE);
3867 lock_ReleaseWrite(&scp->rw);
3869 lock_ReleaseWrite(&buf_globalLock);
3873 snprintf(dbgstr, 1024,
3874 "RDR_ProcessReleaseFileExtentsResult extent released: vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3875 Fid.volume, Fid.vnode, Fid.unique,
3876 pExtent->FileOffset.HighPart,
3877 pExtent->FileOffset.LowPart,
3878 pExtent->CacheOffset.HighPart,
3879 pExtent->CacheOffset.LowPart);
3880 OutputDebugStringA( dbgstr);
3885 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult not releasing vol 0x%x vno 0x%x foffset 0x%x:%x",
3886 Fid.volume, Fid.vnode,
3887 pExtent->FileOffset.HighPart,
3888 pExtent->FileOffset.LowPart);
3889 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
3890 pExtent->CacheOffset.HighPart,
3891 pExtent->CacheOffset.LowPart);
3893 snprintf(dbgstr, 1024,
3894 "RDR_ProcessReleaseFileExtentsResult not released! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3895 Fid.volume, Fid.vnode, Fid.unique,
3896 pExtent->FileOffset.HighPart,
3897 pExtent->FileOffset.LowPart,
3898 pExtent->CacheOffset.HighPart,
3899 pExtent->CacheOffset.LowPart);
3900 OutputDebugStringA( dbgstr);
3904 if ( (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_DIRTY) ||
3905 (pExtent->Flags & AFS_EXTENT_FLAG_DIRTY) )
3907 #ifdef VALIDATE_CHECK_SUM
3908 if ( buf_ValidateCheckSum(bufp) ) {
3910 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3911 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
3912 HexCheckSum(md5dbg2, sizeof(md5dbg2), pExtent->MD5);
3914 buf_ComputeCheckSum(bufp);
3916 HexCheckSum(md5dbg3, sizeof(md5dbg), bufp->md5cksum);
3918 if (ReleaseFileExtentsResultCB->Flags & AFS_EXTENT_FLAG_MD5_SET)
3920 if (memcmp(bufp->md5cksum, pExtent->MD5, 16))
3923 snprintf(dbgstr, 1024,
3924 "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",
3926 Fid.volume, Fid.vnode, Fid.unique,
3927 pExtent->FileOffset.HighPart,
3928 pExtent->FileOffset.LowPart,
3929 pExtent->CacheOffset.HighPart,
3930 pExtent->CacheOffset.LowPart);
3931 OutputDebugStringA( dbgstr);
3934 "RDR_ProcessReleaseFileExtentsResult dirty flag set and checksums do not match! vol 0x%x vno 0x%x foffset 0x%x:%x",
3935 Fid.volume, Fid.vnode,
3936 pExtent->FileOffset.HighPart,
3937 pExtent->FileOffset.LowPart);
3939 "... coffset 0x%x:%x",
3940 pExtent->CacheOffset.HighPart,
3941 pExtent->CacheOffset.LowPart);
3943 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3947 snprintf(dbgstr, 1024,
3948 "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",
3949 md5dbg, md5dbg2, md5dbg3,
3950 Fid.volume, Fid.vnode, Fid.unique,
3951 pExtent->FileOffset.HighPart,
3952 pExtent->FileOffset.LowPart,
3953 pExtent->CacheOffset.HighPart,
3954 pExtent->CacheOffset.LowPart);
3955 OutputDebugStringA( dbgstr);
3958 "RDR_ProcessReleaseFileExtentsResult dirty flag set but extent has not changed vol 0x%x vno 0x%x foffset 0x%x:%x",
3959 Fid.volume, Fid.vnode,
3960 pExtent->FileOffset.HighPart,
3961 pExtent->FileOffset.LowPart);
3963 "... coffset 0x%x:%x",
3964 pExtent->CacheOffset.HighPart,
3965 pExtent->CacheOffset.LowPart);
3969 #else /* !VALIDATE_CHECK_SUM */
3970 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
3973 snprintf(dbgstr, 1024,
3974 "RDR_ProcessReleaseFileExtentsResult dirty! vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
3975 Fid.volume, Fid.vnode, Fid.unique,
3976 pExtent->FileOffset.HighPart,
3977 pExtent->FileOffset.LowPart,
3978 pExtent->CacheOffset.HighPart,
3979 pExtent->CacheOffset.LowPart);
3980 OutputDebugStringA( dbgstr);
3982 #endif /* VALIDATE_CHECK_SUM */
3984 #ifdef VALIDATE_CHECK_SUM
3987 HexCheckSum(md5dbg, sizeof(md5dbg), bufp->md5cksum);
3989 if ( !buf_ValidateCheckSum(bufp) ) {
3990 buf_ComputeCheckSum(bufp);
3992 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
3993 snprintf(dbgstr, 1024,
3994 "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",
3996 Fid.volume, Fid.vnode, Fid.unique,
3997 pExtent->FileOffset.HighPart,
3998 pExtent->FileOffset.LowPart,
3999 pExtent->CacheOffset.HighPart,
4000 pExtent->CacheOffset.LowPart);
4001 OutputDebugStringA( dbgstr);
4003 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult dirty flag NOT set but extent has changed! vol 0x%x vno 0x%x foffset 0x%x:%x",
4004 Fid.volume, Fid.vnode,
4005 pExtent->FileOffset.HighPart,
4006 pExtent->FileOffset.LowPart);
4007 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4008 pExtent->CacheOffset.HighPart,
4009 pExtent->CacheOffset.LowPart);
4013 buf_SetDirty(bufp, &req, pExtent->DirtyOffset, pExtent->DirtyLength, userp);
4016 buf_ComputeCheckSum(bufp);
4018 HexCheckSum(md5dbg3, sizeof(md5dbg2), bufp->md5cksum);
4019 snprintf(dbgstr, 1024,
4020 "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",
4022 Fid.volume, Fid.vnode, Fid.unique,
4023 pExtent->FileOffset.HighPart,
4024 pExtent->FileOffset.LowPart,
4025 pExtent->CacheOffset.HighPart,
4026 pExtent->CacheOffset.LowPart);
4027 OutputDebugStringA( dbgstr);
4031 #endif /* VALIDATE_CHECK_SUM */
4032 lock_ReleaseMutex(&bufp->mx);
4036 /* CacheOffset doesn't match bufp->datap */
4037 char * datap = RDR_extentBaseAddress + pExtent->CacheOffset.QuadPart;
4040 for (wbp = cm_data.buf_allp; wbp; wbp = wbp->allp) {
4041 if (wbp->datap == datap)
4046 snprintf(dbgstr, 1024,
4047 "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",
4048 Fid.volume, Fid.vnode, Fid.unique,
4049 pExtent->FileOffset.HighPart,
4050 pExtent->FileOffset.LowPart,
4051 pExtent->CacheOffset.HighPart,
4052 pExtent->CacheOffset.LowPart,
4054 OutputDebugStringA( dbgstr);
4056 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult non-matching extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4057 Fid.volume, Fid.vnode,
4058 pExtent->FileOffset.HighPart,
4059 pExtent->FileOffset.LowPart);
4060 osi_Log3(afsd_logp, "... coffset 0x%x:%x flags 0x%x",
4061 pExtent->CacheOffset.HighPart,
4062 pExtent->CacheOffset.LowPart,
4065 osi_Log5(afsd_logp, "... coffset belongs to bp 0x%p vol 0x%x vno 0x%x foffset 0x%x:%x",
4066 wbp, wbp->fid.volume, wbp->fid.vnode, wbp->offset.HighPart, wbp->offset.LowPart);
4068 osi_Log0(afsd_logp, "... coffset cannot be found");
4075 if (pExtent->Flags & AFS_EXTENT_FLAG_UNKNOWN) {
4076 osi_Log4(afsd_logp, "RDR_ReleaseFileExtentsResult extent vol 0x%x vno 0x%x foffset 0x%x:%x",
4077 Fid.volume, Fid.vnode, pExtent->FileOffset.HighPart,
4078 pExtent->FileOffset.LowPart);
4079 osi_Log2(afsd_logp, "... coffset 0x%x:%x UNKNOWN to redirector; cm_buf not found -- recycled?",
4080 pExtent->CacheOffset.HighPart,
4081 pExtent->CacheOffset.LowPart);
4087 snprintf(dbgstr, 1024,
4088 "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x uniq 0x%x foffset 0x%x:%x coffset 0x%x:%x\n",
4089 Fid.volume, Fid.vnode, Fid.unique,
4090 pExtent->FileOffset.HighPart,
4091 pExtent->FileOffset.LowPart,
4092 pExtent->CacheOffset.HighPart,
4093 pExtent->CacheOffset.LowPart);
4094 OutputDebugStringA( dbgstr);
4096 osi_Log4(afsd_logp, "RDR_ProcessReleaseFileExtentsResult buf not found vol 0x%x vno 0x%x foffset 0x%x:%x",
4097 Fid.volume, Fid.vnode,
4098 pExtent->FileOffset.HighPart,
4099 pExtent->FileOffset.LowPart);
4100 osi_Log2(afsd_logp, "... coffset 0x%x:%x",
4101 pExtent->CacheOffset.HighPart,
4102 pExtent->CacheOffset.LowPart);
4107 osi_hyper_t offset = {0,0};
4108 afs_uint32 length = 0;
4111 * there is at least one dirty extent on this file. queue up background store
4112 * requests for contiguous blocks
4114 for ( extentno = 0; extentno < pFileCB->ExtentCount; extentno++ ) {
4115 AFSFileExtentCB *pExtent = &pFileCB->FileExtents[extentno];
4116 if (pExtent->FileOffset.QuadPart == offset.QuadPart + length &&
4117 length < cm_chunkSize) {
4118 length += cm_data.buf_blockSize;
4120 if (!(offset.QuadPart == 0 && length == 0))
4121 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4122 length, 0, userp, &req);
4123 offset.QuadPart = pExtent->FileOffset.QuadPart;
4124 length = cm_data.buf_blockSize;
4127 cm_QueueBKGRequest(scp, cm_BkgStore, offset.LowPart, offset.HighPart,
4128 length, 0, userp, &req);
4131 osi_Log5(afsd_logp, "RDR_ProcessReleaseFileExtentsResult File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x Released %d",
4132 Fid.cell, Fid.volume, Fid.vnode, Fid.unique, released);
4136 cm_ReleaseUser(userp);
4138 cm_ReleaseSCache(scp);
4140 p = (char *)pFileCB;
4141 p += sizeof(AFSReleaseFileExtentsResultFileCB);
4142 p += sizeof(AFSFileExtentCB) * (pFileCB->ExtentCount - 1);
4143 pNextFileCB = (AFSReleaseFileExtentsResultFileCB *)p;
4146 if (total_extents == 0) {
4147 osi_Log0(afsd_logp, "RDR_ProcessReleaseFileExtentsResult is empty");
4148 code = CM_ERROR_RETRY;
4152 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult FAILURE code=0x%x", code);
4154 osi_Log1(afsd_logp, "RDR_ProcessReleaseFileExtentsResult DONE code=0x%x", code);
4160 RDR_ReleaseFailedSetFileExtents( IN cm_user_t *userp,
4161 IN AFSSetFileExtentsCB *SetFileExtentsResultCB,
4162 IN DWORD ResultBufferLength)
4164 afs_uint32 code = 0;
4166 unsigned int extentno;
4168 cm_scache_t * scp = NULL;
4173 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFileExtents %d.%d.%d.%d",
4174 SetFileExtentsResultCB->FileId.Cell, SetFileExtentsResultCB->FileId.Volume,
4175 SetFileExtentsResultCB->FileId.Vnode, SetFileExtentsResultCB->FileId.Unique);
4177 /* Process the release */
4178 Fid.cell = SetFileExtentsResultCB->FileId.Cell;
4179 Fid.volume = SetFileExtentsResultCB->FileId.Volume;
4180 Fid.vnode = SetFileExtentsResultCB->FileId.Vnode;
4181 Fid.unique = SetFileExtentsResultCB->FileId.Unique;
4182 Fid.hash = SetFileExtentsResultCB->FileId.Hash;
4184 if (Fid.cell == 0) {
4185 osi_Log4(afsd_logp, "RDR_ReleaseFailedSetFile Invalid FID %d.%d.%d.%d",
4186 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
4187 code = CM_ERROR_INVAL;
4191 code = cm_GetSCache(&Fid, &scp, userp, &req);
4193 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents cm_GetSCache FID failure code=0x%x",
4195 /* Failure to find the cm_scache object cannot block return of the extents */
4198 for ( extentno = 0; extentno < SetFileExtentsResultCB->ExtentCount; extentno++ ) {
4201 AFSFileExtentCB *pExtent = &SetFileExtentsResultCB->FileExtents[extentno];
4203 thyper.QuadPart = pExtent->FileOffset.QuadPart;
4205 bufp = buf_Find(&Fid, &thyper);
4207 osi_Log5(afsd_logp, "RDR_ReleaseFailedSetFileExtents bufp 0x%p foffset 0x%x:%x coffset 0x%x:%x",
4208 bufp, pExtent->FileOffset.HighPart, pExtent->FileOffset.LowPart,
4209 pExtent->CacheOffset.HighPart, pExtent->CacheOffset.LowPart);
4211 lock_ObtainMutex(&bufp->mx);
4212 if (bufp->qFlags & CM_BUF_QREDIR) {
4214 lock_ObtainWrite(&scp->rw);
4215 lock_ObtainWrite(&buf_globalLock);
4216 if (bufp->qFlags & CM_BUF_QREDIR) {
4217 buf_RemoveFromRedirQueue(scp, bufp);
4219 lock_ReleaseWrite(&scp->rw);
4220 buf_ReleaseLocked(bufp, TRUE);
4223 lock_ReleaseWrite(&scp->rw);
4225 lock_ReleaseWrite(&buf_globalLock);
4227 lock_ReleaseMutex(&bufp->mx);
4234 cm_ReleaseUser(userp);
4236 cm_ReleaseSCache(scp);
4238 osi_Log1(afsd_logp, "RDR_ReleaseFailedSetFileExtents DONE code=0x%x", code);
4243 RDR_PioctlOpen( IN cm_user_t *userp,
4244 IN AFSFileID ParentId,
4245 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4247 IN DWORD ResultBufferLength,
4248 IN OUT AFSCommResult **ResultCB)
4253 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4259 sizeof( AFSCommResult));
4261 /* Get the active directory */
4262 ParentFid.cell = ParentId.Cell;
4263 ParentFid.volume = ParentId.Volume;
4264 ParentFid.vnode = ParentId.Vnode;
4265 ParentFid.unique = ParentId.Unique;
4266 ParentFid.hash = ParentId.Hash;
4268 /* Get the root directory */
4269 RootFid.cell = pPioctlCB->RootId.Cell;
4270 RootFid.volume = pPioctlCB->RootId.Volume;
4271 RootFid.vnode = pPioctlCB->RootId.Vnode;
4272 RootFid.unique = pPioctlCB->RootId.Unique;
4273 RootFid.hash = pPioctlCB->RootId.Hash;
4275 /* Create the pioctl index */
4276 RDR_SetupIoctl(pPioctlCB->RequestId, &ParentFid, &RootFid, userp);
4283 RDR_PioctlClose( IN cm_user_t *userp,
4284 IN AFSFileID ParentId,
4285 IN AFSPIOCtlOpenCloseRequestCB *pPioctlCB,
4287 IN DWORD ResultBufferLength,
4288 IN OUT AFSCommResult **ResultCB)
4290 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4296 sizeof( AFSCommResult));
4298 /* Cleanup the pioctl index */
4299 RDR_CleanupIoctl(pPioctlCB->RequestId);
4306 RDR_PioctlWrite( IN cm_user_t *userp,
4307 IN AFSFileID ParentId,
4308 IN AFSPIOCtlIORequestCB *pPioctlCB,
4310 IN DWORD ResultBufferLength,
4311 IN OUT AFSCommResult **ResultCB)
4313 AFSPIOCtlIOResultCB *pResultCB;
4314 cm_scache_t *dscp = NULL;
4321 req.flags |= CM_REQ_WOW64;
4323 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4329 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4331 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4333 code = RDR_IoctlWrite(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer, &req);
4335 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4336 (*ResultCB)->ResultStatus = status;
4340 pResultCB->BytesProcessed = pPioctlCB->BufferLength;
4341 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4345 RDR_PioctlRead( IN cm_user_t *userp,
4346 IN AFSFileID ParentId,
4347 IN AFSPIOCtlIORequestCB *pPioctlCB,
4349 IN BOOL bIsLocalSystem,
4350 IN DWORD ResultBufferLength,
4351 IN OUT AFSCommResult **ResultCB)
4353 AFSPIOCtlIOResultCB *pResultCB;
4354 cm_scache_t *dscp = NULL;
4358 afs_uint32 pflags = (bIsLocalSystem ? AFSCALL_FLAG_LOCAL_SYSTEM : 0);
4362 req.flags |= CM_REQ_WOW64;
4364 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4370 sizeof( AFSCommResult) + sizeof(AFSPIOCtlIOResultCB));
4372 pResultCB = (AFSPIOCtlIOResultCB *)(*ResultCB)->ResultData;
4374 code = RDR_IoctlRead(userp, pPioctlCB->RequestId, pPioctlCB->BufferLength, pPioctlCB->MappedBuffer,
4375 &pResultCB->BytesProcessed, &req, pflags);
4377 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4378 (*ResultCB)->ResultStatus = status;
4382 (*ResultCB)->ResultBufferLength = sizeof( AFSPIOCtlIOResultCB);
4386 RDR_ByteRangeLockSync( IN cm_user_t *userp,
4387 IN AFSFileID FileId,
4388 IN AFSByteRangeLockRequestCB *pBRLRequestCB,
4390 IN DWORD ResultBufferLength,
4391 IN OUT AFSCommResult **ResultCB)
4393 AFSByteRangeLockResultCB *pResultCB = NULL;
4394 LARGE_INTEGER ProcessId;
4396 cm_scache_t *scp = NULL;
4404 ProcessId.QuadPart = pBRLRequestCB->ProcessId;
4408 req.flags |= CM_REQ_WOW64;
4410 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4411 FileId.Cell, FileId.Volume,
4412 FileId.Vnode, FileId.Unique);
4413 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4414 ProcessId.HighPart, ProcessId.LowPart);
4416 Length = sizeof( AFSByteRangeLockResultCB) + ((pBRLRequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4417 if (Length > ResultBufferLength) {
4418 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4421 memset( *ResultCB, 0, sizeof(AFSCommResult));
4422 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4426 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4429 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4430 (*ResultCB)->ResultBufferLength = Length;
4432 pResultCB = (AFSByteRangeLockResultCB *)(*ResultCB)->ResultData;
4433 pResultCB->FileId = FileId;
4434 pResultCB->Count = pBRLRequestCB->Count;
4436 /* Allocate the extents from the buffer package */
4437 Fid.cell = FileId.Cell;
4438 Fid.volume = FileId.Volume;
4439 Fid.vnode = FileId.Vnode;
4440 Fid.unique = FileId.Unique;
4441 Fid.hash = FileId.Hash;
4443 code = cm_GetSCache(&Fid, &scp, userp, &req);
4445 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4446 (*ResultCB)->ResultStatus = status;
4447 (*ResultCB)->ResultBufferLength = 0;
4448 osi_Log2(afsd_logp, "RDR_ByteRangeLockSync cm_GetSCache FID failure code=0x%x status=0x%x",
4453 lock_ObtainWrite(&scp->rw);
4455 /* start by looking up the file's end */
4456 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4457 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4459 lock_ReleaseWrite(&scp->rw);
4460 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4461 (*ResultCB)->ResultStatus = status;
4462 (*ResultCB)->ResultBufferLength = 0;
4463 osi_Log3(afsd_logp, "RDR_ByteRangeLockSync cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4468 /* the scp is now locked and current */
4469 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4471 for ( i=0; i<pBRLRequestCB->Count; i++ ) {
4472 pResultCB->Result[i].LockType = pBRLRequestCB->Request[i].LockType;
4473 pResultCB->Result[i].Offset = pBRLRequestCB->Request[i].Offset;
4474 pResultCB->Result[i].Length = pBRLRequestCB->Request[i].Length;
4477 pBRLRequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4478 pBRLRequestCB->Request[i].Offset,
4479 pBRLRequestCB->Request[i].Length,
4480 key, 0, userp, &req, NULL);
4483 osi_Log4(afsd_logp, "RDR_ByteRangeLockSync FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4485 pBRLRequestCB->Request[i].LockType,
4486 pBRLRequestCB->Request[i].Offset.HighPart,
4487 pBRLRequestCB->Request[i].Offset.LowPart);
4488 osi_Log2(afsd_logp, "... length 0x%x:%x",
4489 pBRLRequestCB->Request[i].Length.HighPart,
4490 pBRLRequestCB->Request[i].Length.LowPart);
4495 pResultCB->Result[i].Status = 0;
4497 case CM_ERROR_WOULDBLOCK:
4498 pResultCB->Result[i].Status = STATUS_FILE_LOCK_CONFLICT;
4501 pResultCB->Result[i].Status = STATUS_LOCK_NOT_GRANTED;
4505 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4506 lock_ReleaseWrite(&scp->rw);
4507 cm_ReleaseSCache(scp);
4509 (*ResultCB)->ResultStatus = 0;
4510 osi_Log0(afsd_logp, "RDR_ByteRangeLockSync SUCCESS");
4515 RDR_ByteRangeUnlock( IN cm_user_t *userp,
4516 IN AFSFileID FileId,
4517 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4519 IN DWORD ResultBufferLength,
4520 IN OUT AFSCommResult **ResultCB)
4522 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4523 LARGE_INTEGER ProcessId;
4525 cm_scache_t *scp = NULL;
4533 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4537 req.flags |= CM_REQ_WOW64;
4539 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4540 FileId.Cell, FileId.Volume,
4541 FileId.Vnode, FileId.Unique);
4542 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4543 ProcessId.HighPart, ProcessId.LowPart);
4545 Length = sizeof( AFSByteRangeUnlockResultCB) + ((pBRURequestCB->Count - 1) * sizeof(AFSByteRangeLockResult));
4546 if (Length > ResultBufferLength) {
4547 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult));
4550 memset( *ResultCB, 0, sizeof(AFSCommResult));
4551 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4555 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4558 memset( *ResultCB, '\0', Length + sizeof( AFSCommResult) );
4559 (*ResultCB)->ResultBufferLength = Length;
4561 pResultCB = (AFSByteRangeUnlockResultCB *)(*ResultCB)->ResultData;
4562 pResultCB->Count = pBRURequestCB->Count;
4564 /* Allocate the extents from the buffer package */
4565 Fid.cell = FileId.Cell;
4566 Fid.volume = FileId.Volume;
4567 Fid.vnode = FileId.Vnode;
4568 Fid.unique = FileId.Unique;
4569 Fid.hash = FileId.Hash;
4571 code = cm_GetSCache(&Fid, &scp, userp, &req);
4573 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4574 (*ResultCB)->ResultStatus = status;
4575 (*ResultCB)->ResultBufferLength = 0;
4576 osi_Log2(afsd_logp, "RDR_ByteRangeUnlock cm_GetSCache FID failure code=0x%x status=0x%x",
4581 lock_ObtainWrite(&scp->rw);
4583 /* start by looking up the file's end */
4584 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4585 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4587 lock_ReleaseWrite(&scp->rw);
4588 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4589 (*ResultCB)->ResultStatus = status;
4590 (*ResultCB)->ResultBufferLength = 0;
4591 osi_Log3(afsd_logp, "RDR_ByteRangeUnlock cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4596 /* the scp is now locked and current */
4597 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4599 for ( i=0; i<pBRURequestCB->Count; i++ ) {
4600 pResultCB->Result[i].LockType = pBRURequestCB->Request[i].LockType;
4601 pResultCB->Result[i].Offset = pBRURequestCB->Request[i].Offset;
4602 pResultCB->Result[i].Length = pBRURequestCB->Request[i].Length;
4604 code = cm_Unlock(scp,
4605 pBRURequestCB->Request[i].LockType == AFS_BYTE_RANGE_LOCK_TYPE_SHARED,
4606 pBRURequestCB->Request[i].Offset,
4607 pBRURequestCB->Request[i].Length,
4608 key, CM_UNLOCK_FLAG_MATCH_RANGE, userp, &req);
4611 osi_Log4(afsd_logp, "RDR_ByteRangeUnlock FAILURE code 0x%x type 0x%u offset 0x%x:%x",
4612 code, pBRURequestCB->Request[i].LockType,
4613 pBRURequestCB->Request[i].Offset.HighPart,
4614 pBRURequestCB->Request[i].Offset.LowPart);
4615 osi_Log2(afsd_logp, "... length 0x%x:%x",
4616 pBRURequestCB->Request[i].Length.HighPart,
4617 pBRURequestCB->Request[i].Length.LowPart);
4619 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4620 pResultCB->Result[i].Status = status;
4623 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4624 lock_ReleaseWrite(&scp->rw);
4625 cm_ReleaseSCache(scp);
4627 (*ResultCB)->ResultStatus = 0;
4628 osi_Log0(afsd_logp, "RDR_ByteRangeUnlock SUCCESS");
4633 RDR_ByteRangeUnlockAll( IN cm_user_t *userp,
4634 IN AFSFileID FileId,
4635 IN AFSByteRangeUnlockRequestCB *pBRURequestCB,
4637 IN DWORD ResultBufferLength,
4638 IN OUT AFSCommResult **ResultCB)
4640 AFSByteRangeUnlockResultCB *pResultCB = NULL;
4641 LARGE_INTEGER ProcessId;
4642 cm_scache_t *scp = NULL;
4649 ProcessId.QuadPart = pBRURequestCB->ProcessId;
4653 req.flags |= CM_REQ_WOW64;
4655 osi_Log4(afsd_logp, "RDR_ByteRangeUnlockAll File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4656 FileId.Cell, FileId.Volume,
4657 FileId.Vnode, FileId.Unique);
4658 osi_Log2(afsd_logp, "... ProcessId 0x%x:%x",
4659 ProcessId.HighPart, ProcessId.LowPart);
4661 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
4664 memset( *ResultCB, '\0', sizeof( AFSCommResult));
4665 (*ResultCB)->ResultBufferLength = 0;
4667 /* Allocate the extents from the buffer package */
4668 Fid.cell = FileId.Cell;
4669 Fid.volume = FileId.Volume;
4670 Fid.vnode = FileId.Vnode;
4671 Fid.unique = FileId.Unique;
4672 Fid.hash = FileId.Hash;
4674 code = cm_GetSCache(&Fid, &scp, userp, &req);
4676 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4677 (*ResultCB)->ResultStatus = status;
4678 (*ResultCB)->ResultBufferLength = 0;
4679 osi_Log2(afsd_logp, "RDR_ByteRangeUnlockAll cm_GetSCache FID failure code=0x%x status=0x%x",
4684 lock_ObtainWrite(&scp->rw);
4686 /* start by looking up the file's end */
4687 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4688 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4690 lock_ReleaseWrite(&scp->rw);
4691 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4692 (*ResultCB)->ResultStatus = status;
4693 (*ResultCB)->ResultBufferLength = 0;
4694 osi_Log3(afsd_logp, "RDR_ByteRangeUnlockAll cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4699 /* the scp is now locked and current */
4700 key = cm_GenerateKey(CM_SESSION_IFS, ProcessId.QuadPart, 0);
4702 code = cm_UnlockByKey(scp, key, 0, userp, &req);
4704 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
4705 lock_ReleaseWrite(&scp->rw);
4706 cm_ReleaseSCache(scp);
4708 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4709 (*ResultCB)->ResultStatus = status;
4712 osi_Log1(afsd_logp, "RDR_ByteRangeUnlockAll FAILURE code 0x%x", code);
4714 osi_Log0(afsd_logp, "RDR_ByteRangeUnlockAll SUCCESS");
4720 RDR_GetVolumeInfo( IN cm_user_t *userp,
4721 IN AFSFileID FileId,
4723 IN DWORD ResultBufferLength,
4724 IN OUT AFSCommResult **ResultCB)
4726 AFSVolumeInfoCB *pResultCB = NULL;
4728 cm_scache_t *scp = NULL;
4729 cm_volume_t *volp = NULL;
4730 cm_vol_state_t *volstatep = NULL;
4732 cm_cell_t *cellp = NULL;
4737 FILETIME ft = {0x832cf000, 0x01abfcc4}; /* October 1, 1982 00:00:00 +0600 */
4739 char volName[32]="(unknown)";
4740 char offLineMsg[256]="server temporarily inaccessible";
4741 char motd[256]="server temporarily inaccessible";
4743 AFSFetchVolumeStatus volStat;
4747 struct rx_connection * rxconnp;
4751 req.flags |= CM_REQ_WOW64;
4753 osi_Log4(afsd_logp, "RDR_GetVolumeInfo File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4754 FileId.Cell, FileId.Volume,
4755 FileId.Vnode, FileId.Unique);
4757 Length = sizeof( AFSCommResult) + sizeof(AFSVolumeInfoCB);
4758 if (sizeof(AFSVolumeInfoCB) > ResultBufferLength) {
4759 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
4762 memset( *ResultCB, 0, sizeof(AFSCommResult));
4763 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4767 *ResultCB = (AFSCommResult *)malloc( Length );
4770 memset( *ResultCB, '\0', Length );
4771 (*ResultCB)->ResultBufferLength = sizeof(AFSVolumeInfoCB);
4772 pResultCB = (AFSVolumeInfoCB *)(*ResultCB)->ResultData;
4774 /* Allocate the extents from the buffer package */
4775 if (FileId.Cell != 0) {
4776 Fid.cell = FileId.Cell;
4777 Fid.volume = FileId.Volume;
4778 Fid.vnode = FileId.Vnode;
4779 Fid.unique = FileId.Unique;
4780 Fid.hash = FileId.Hash;
4782 code = cm_GetSCache(&Fid, &scp, userp, &req);
4784 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4785 (*ResultCB)->ResultStatus = status;
4786 (*ResultCB)->ResultBufferLength = 0;
4787 osi_Log2(afsd_logp, "RDR_GetVolumeInfo cm_GetSCache FID failure code=0x%x status=0x%x",
4792 (*ResultCB)->ResultStatus = STATUS_OBJECT_NAME_INVALID;
4793 osi_Log0(afsd_logp, "RDR_GetVolumeInfo Object Name Invalid - Cell = 0");
4796 lock_ObtainWrite(&scp->rw);
4798 /* start by looking up the file's end */
4799 code = cm_SyncOp(scp, NULL, userp, &req, 0,
4800 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
4802 lock_ReleaseWrite(&scp->rw);
4803 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4804 (*ResultCB)->ResultStatus = status;
4805 (*ResultCB)->ResultBufferLength = 0;
4806 osi_Log3(afsd_logp, "RDR_GetVolumeInfo cm_SyncOp failure scp=0x%p code=0x%x status=0x%x",
4812 pResultCB->SectorsPerAllocationUnit = 1;
4813 pResultCB->BytesPerSector = 1024;
4815 pResultCB->CellID = scp->fid.cell;
4816 pResultCB->VolumeID = scp->fid.volume;
4817 pResultCB->Characteristics = FILE_REMOTE_DEVICE;
4818 pResultCB->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_UNICODE_ON_DISK |
4819 FILE_SUPPORTS_REPARSE_POINTS;
4821 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
4822 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)
4824 pResultCB->TotalAllocationUnits.QuadPart = 100;
4825 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
4827 pResultCB->AvailableAllocationUnits.QuadPart = 0;
4828 pResultCB->Characteristics |= FILE_READ_ONLY_DEVICE;
4830 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( "Freelance.Local.Root", -1, pResultCB->VolumeLabel,
4831 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
4832 if ( pResultCB->VolumeLabelLength )
4833 pResultCB->VolumeLabelLength--;
4835 memcpy(&pResultCB->VolumeCreationTime, &ft, sizeof(ft));
4837 volp = cm_GetVolumeByFID(&scp->fid);
4839 code = CM_ERROR_NOSUCHVOLUME;
4842 volstatep = cm_VolumeStateByID(volp, scp->fid.volume);
4843 volType = cm_VolumeType(volp, scp->fid.volume);
4845 pResultCB->Characteristics |= ((volType == ROVOL || volType == BACKVOL) ? FILE_READ_ONLY_DEVICE : 0);
4848 OfflineMsg = offLineMsg;
4850 lock_ReleaseWrite(&scp->rw);
4852 code = cm_ConnFromFID(&scp->fid, userp, &req, &connp);
4855 rxconnp = cm_GetRxConn(connp);
4856 code = RXAFS_GetVolumeStatus(rxconnp, scp->fid.volume,
4857 &volStat, &Name, &OfflineMsg, &MOTD);
4858 rx_PutConnection(rxconnp);
4860 } while (cm_Analyze(connp, userp, &req, &scp->fid, NULL, NULL, NULL, code));
4861 code = cm_MapRPCError(code, &req);
4863 pResultCB->TotalAllocationUnits.QuadPart = volStat.PartMaxBlocks;
4864 pResultCB->AvailableAllocationUnits.QuadPart = volStat.PartBlocksAvail;
4866 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( Name, -1, pResultCB->VolumeLabel,
4867 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
4869 pResultCB->TotalAllocationUnits.QuadPart = 0x7FFFFFFF;
4870 pResultCB->AvailableAllocationUnits.QuadPart = (volType == ROVOL || volType == BACKVOL) ? 0 : 0x3F000000;
4872 pResultCB->VolumeLabelLength = cm_Utf8ToUtf16( volp->namep, -1, pResultCB->VolumeLabel,
4873 (sizeof(pResultCB->VolumeLabel) / sizeof(WCHAR)) + 1);
4876 if ( pResultCB->VolumeLabelLength )
4877 pResultCB->VolumeLabelLength--;
4879 lock_ObtainWrite(&scp->rw);
4881 pResultCB->VolumeLabelLength *= sizeof(WCHAR); /* convert to bytes from chars */
4883 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
4886 lock_ReleaseWrite(&scp->rw);
4889 cm_ReleaseSCache(scp);
4891 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
4892 (*ResultCB)->ResultStatus = status;
4893 osi_Log0(afsd_logp, "RDR_GetVolumeInfo SUCCESS");
4898 RDR_HoldFid( IN cm_user_t *userp,
4899 IN AFSHoldFidRequestCB * pHoldFidCB,
4901 IN DWORD ResultBufferLength,
4902 IN OUT AFSCommResult **ResultCB)
4904 AFSHoldFidResultCB *pResultCB = NULL;
4911 osi_Log1(afsd_logp, "RDR_HoldFid Count=%u", pHoldFidCB->Count);
4913 Length = sizeof(AFSHoldFidResultCB) + (pHoldFidCB->Count-1) * sizeof(AFSFidResult);
4914 if (Length > ResultBufferLength) {
4915 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
4918 memset( *ResultCB, 0, sizeof(AFSCommResult));
4919 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4922 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4925 memset( *ResultCB, '\0', Length );
4926 (*ResultCB)->ResultBufferLength = Length;
4927 pResultCB = (AFSHoldFidResultCB *)(*ResultCB)->ResultData;
4929 for ( index = 0; index < pHoldFidCB->Count; index++ )
4931 cm_scache_t *scp = NULL;
4934 Fid.cell = pResultCB->Result[index].FileID.Cell = pHoldFidCB->FileID[index].Cell;
4935 Fid.volume = pResultCB->Result[index].FileID.Volume = pHoldFidCB->FileID[index].Volume;
4936 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pHoldFidCB->FileID[index].Vnode;
4937 Fid.unique = pResultCB->Result[index].FileID.Unique = pHoldFidCB->FileID[index].Unique;
4938 Fid.hash = pResultCB->Result[index].FileID.Hash = pHoldFidCB->FileID[index].Hash;
4940 osi_Log4( afsd_logp,
4941 "RDR_HoldFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
4942 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
4944 scp = cm_FindSCache(&Fid);
4946 RDR_FlagScpInUse( scp, FALSE );
4947 cm_ReleaseSCache(scp);
4949 pResultCB->Result[index].Status = 0;
4952 (*ResultCB)->ResultStatus = 0;
4953 osi_Log0(afsd_logp, "RDR_HoldFid SUCCESS");
4958 RDR_ReleaseFid( IN cm_user_t *userp,
4959 IN AFSReleaseFidRequestCB * pReleaseFidCB,
4961 IN DWORD ResultBufferLength,
4962 IN OUT AFSCommResult **ResultCB)
4964 AFSReleaseFidResultCB *pResultCB = NULL;
4971 osi_Log1(afsd_logp, "RDR_ReleaseFid Count=%u", pReleaseFidCB->Count);
4973 Length = sizeof(AFSReleaseFidResultCB) + (pReleaseFidCB->Count ? pReleaseFidCB->Count-1 : 0) * sizeof(AFSFidResult);
4974 if (Length > ResultBufferLength) {
4975 *ResultCB = (AFSCommResult *)malloc(sizeof(AFSCommResult) );
4978 memset( *ResultCB, 0, sizeof(AFSCommResult));
4979 (*ResultCB)->ResultStatus = STATUS_BUFFER_OVERFLOW;
4982 *ResultCB = (AFSCommResult *)malloc( Length + sizeof( AFSCommResult) );
4985 memset( *ResultCB, '\0', Length );
4986 (*ResultCB)->ResultBufferLength = Length;
4987 pResultCB = (AFSReleaseFidResultCB *)(*ResultCB)->ResultData;
4989 for ( index = 0; index < pReleaseFidCB->Count; index++ )
4991 cm_scache_t *scp = NULL;
4994 Fid.cell = pResultCB->Result[index].FileID.Cell = pReleaseFidCB->FileID[index].Cell;
4995 Fid.volume = pResultCB->Result[index].FileID.Volume = pReleaseFidCB->FileID[index].Volume;
4996 Fid.vnode = pResultCB->Result[index].FileID.Vnode = pReleaseFidCB->FileID[index].Vnode;
4997 Fid.unique = pResultCB->Result[index].FileID.Unique = pReleaseFidCB->FileID[index].Unique;
4998 Fid.hash = pResultCB->Result[index].FileID.Hash = pReleaseFidCB->FileID[index].Hash;
5000 osi_Log4( afsd_logp,
5001 "RDR_ReleaseFid File FID cell=0x%x vol=0x%x vn=0x%x uniq=0x%x",
5002 Fid.cell, Fid.volume, Fid.vnode, Fid.unique);
5004 scp = cm_FindSCache(&Fid);
5006 lock_ObtainWrite(&scp->rw);
5007 scp->flags &= ~CM_SCACHEFLAG_RDR_IN_USE;
5008 lock_ReleaseWrite(&scp->rw);
5010 cm_ReleaseSCache(scp);
5012 pResultCB->Result[index].Status = 0;
5014 pResultCB->Count = pReleaseFidCB->Count;
5016 (*ResultCB)->ResultStatus = 0;
5017 osi_Log0(afsd_logp, "RDR_ReleaseFid SUCCESS");
5022 * The redirector makes several assumptions regarding the
5023 * SRVSVC and WKSSVC pipes transactions. First, the interface
5024 * versions are those indicated below. Secondly, the encoding
5025 * will be performed using NDR version 2. These assumptions
5026 * may not hold in the future and end-to-end MSRPC Bind
5027 * negotiations may need to be supported. Of course, these
5028 * are the only interface versions that are supported by the
5031 #define MSRPC_PIPE_PREFIX L".\\"
5033 static const UUID MSRPC_SRVSVC_UUID = {0x4B324FC8, 0x1670, 0x01D3,
5034 {0x12, 0x78, 0x5A, 0x47, 0xBF, 0x6E, 0xE1, 0x88}};
5035 #define MSRPC_SRVSVC_NAME L"PIPE\\SRVSVC"
5036 #define MSRPC_SRVSVC_VERS 3
5038 static const UUID MSRPC_WKSSVC_UUID = {0x6BFFD098, 0xA112, 0x3610,
5039 {0x98, 0x33, 0x46, 0xC3, 0xF8, 0x7E, 0x34, 0x5A}};
5040 #define MSRPC_WKSSVC_NAME L"PIPE\\WKSSVC"
5041 #define MSRPC_WKSSVC_VERS 1
5043 static const UUID MSRPC_NDR_UUID = {0x8A885D04, 0x1CEB, 0x11C9,
5044 {0x9F, 0xE8, 0x08, 0x00, 0x2B, 0x10, 0x48, 0x60}};
5045 #define MSRPC_NDR_NAME L"NDR"
5046 #define MSRPC_NDR_VERS 2
5048 extern RPC_IF_HANDLE srvsvc_v3_0_s_ifspec;
5049 extern RPC_IF_HANDLE wkssvc_v1_0_s_ifspec;
5052 RDR_PipeOpen( IN cm_user_t *userp,
5053 IN AFSFileID ParentId,
5055 IN DWORD NameLength,
5056 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5058 IN DWORD ResultBufferLength,
5059 IN OUT AFSCommResult **ResultCB)
5064 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5070 sizeof( AFSCommResult));
5072 /* Get the active directory */
5073 ParentFid.cell = ParentId.Cell;
5074 ParentFid.volume = ParentId.Volume;
5075 ParentFid.vnode = ParentId.Vnode;
5076 ParentFid.unique = ParentId.Unique;
5077 ParentFid.hash = ParentId.Hash;
5079 /* Get the root directory */
5080 RootFid.cell = pPipe_CB->RootId.Cell;
5081 RootFid.volume = pPipe_CB->RootId.Volume;
5082 RootFid.vnode = pPipe_CB->RootId.Vnode;
5083 RootFid.unique = pPipe_CB->RootId.Unique;
5084 RootFid.hash = pPipe_CB->RootId.Hash;
5086 /* Create the pipe index */
5087 (*ResultCB)->ResultStatus =
5088 RDR_SetupPipe( pPipe_CB->RequestId, &ParentFid, &RootFid,
5089 Name, NameLength, userp);
5095 RDR_PipeClose( IN cm_user_t *userp,
5096 IN AFSFileID ParentId,
5097 IN AFSPipeOpenCloseRequestCB *pPipe_CB,
5099 IN DWORD ResultBufferLength,
5100 IN OUT AFSCommResult **ResultCB)
5102 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5108 sizeof( AFSCommResult));
5110 /* Cleanup the pipe index */
5111 RDR_CleanupPipe(pPipe_CB->RequestId);
5118 RDR_PipeWrite( IN cm_user_t *userp,
5119 IN AFSFileID ParentId,
5120 IN AFSPipeIORequestCB *pPipe_CB,
5121 IN BYTE *pPipe_Data,
5123 IN DWORD ResultBufferLength,
5124 IN OUT AFSCommResult **ResultCB)
5126 AFSPipeIOResultCB *pResultCB;
5127 cm_scache_t *dscp = NULL;
5134 req.flags |= CM_REQ_WOW64;
5136 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5142 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5144 pResultCB = (AFSPipeIOResultCB *)(*ResultCB)->ResultData;
5146 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_Data, &req, userp);
5148 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5149 (*ResultCB)->ResultStatus = status;
5153 pResultCB->BytesProcessed = pPipe_CB->BufferLength;
5154 (*ResultCB)->ResultBufferLength = sizeof( AFSPipeIOResultCB);
5159 RDR_PipeRead( IN cm_user_t *userp,
5160 IN AFSFileID ParentId,
5161 IN AFSPipeIORequestCB *pPipe_CB,
5163 IN DWORD ResultBufferLength,
5164 IN OUT AFSCommResult **ResultCB)
5167 cm_scache_t *dscp = NULL;
5174 req.flags |= CM_REQ_WOW64;
5176 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5182 sizeof( AFSCommResult));
5184 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5186 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_Data,
5187 &(*ResultCB)->ResultBufferLength, &req, userp);
5189 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5190 (*ResultCB)->ResultStatus = status;
5197 RDR_PipeSetInfo( IN cm_user_t *userp,
5198 IN AFSFileID ParentId,
5199 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5200 IN BYTE *pPipe_Data,
5202 IN DWORD ResultBufferLength,
5203 IN OUT AFSCommResult **ResultCB)
5205 cm_scache_t *dscp = NULL;
5211 req.flags |= CM_REQ_WOW64;
5213 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult));
5219 sizeof( AFSCommResult));
5221 status = RDR_Pipe_SetInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5222 pPipeInfo_CB->BufferLength, pPipe_Data, &req, userp);
5224 (*ResultCB)->ResultStatus = status;
5229 RDR_PipeQueryInfo( IN cm_user_t *userp,
5230 IN AFSFileID ParentId,
5231 IN AFSPipeInfoRequestCB *pPipeInfo_CB,
5233 IN DWORD ResultBufferLength,
5234 IN OUT AFSCommResult **ResultCB)
5237 cm_scache_t *dscp = NULL;
5243 req.flags |= CM_REQ_WOW64;
5245 *ResultCB = (AFSCommResult *)malloc( sizeof( AFSCommResult) + ResultBufferLength);
5251 sizeof( AFSCommResult) + sizeof(AFSPipeIOResultCB));
5253 pPipe_Data = (BYTE *)(*ResultCB)->ResultData;
5255 status = RDR_Pipe_QueryInfo( pPipeInfo_CB->RequestId, pPipeInfo_CB->InformationClass,
5256 ResultBufferLength, pPipe_Data,
5257 &(*ResultCB)->ResultBufferLength, &req, userp);
5259 (*ResultCB)->ResultStatus = status;
5263 RDR_PipeTransceive( IN cm_user_t *userp,
5264 IN AFSFileID ParentId,
5265 IN AFSPipeIORequestCB *pPipe_CB,
5266 IN BYTE *pPipe_InData,
5268 IN DWORD ResultBufferLength,
5269 IN OUT AFSCommResult **ResultCB)
5272 * This function processes a Pipe Service request
5273 * that would normally be sent to a LAN Manager server
5274 * across an authenticated SMB-PIPE/MSRPC/SVC request
5275 * stack. The request is being sent here because the
5276 * application (e.g., Explorer Shell or Common Control File
5277 * dialog) believes that because the UNC path it is
5278 * processing has specified a server name that is not
5279 * "." and that the Server is remote and that the Share
5280 * list cannot be obtained using the Network Provider
5283 * The file system driver is faking the Bind-Ack response
5284 * to the MSRPC Bind request but cannot decode the NDR
5285 * encoded Pipe Service requests. For that we will use
5286 * the service's MSRPC module. However, unlike the SMB
5287 * server usage we must fake the MSRPC Bind exchange and
5288 * map the PipeName to an interface instead of using the
5289 * GUID specified in the MSRPC Bind request.
5291 * None of the requests that are being processed by the
5292 * service require authentication. As a result the userp
5293 * parameter will be ignored.
5295 * Although there are dozens of Pipe Services, the only
5296 * ones that we are implementing are WKSSVC and SRVSVC.
5297 * These support NetShareEnum, NetShareGetInfo,
5298 * NetServerGetInfo, and NetWorkstaGetInfo which are
5299 * commonly queried by NET VIEW, the Explorer Shell,
5300 * and the Common Control File dialog.
5302 BYTE *pPipe_OutData;
5303 cm_scache_t *dscp = NULL;
5307 DWORD Length = ResultBufferLength + sizeof( AFSCommResult);
5311 req.flags |= CM_REQ_WOW64;
5313 *ResultCB = (AFSCommResult *)malloc( Length);
5316 memset( *ResultCB, '\0', Length );
5318 code = RDR_Pipe_Write( pPipe_CB->RequestId, pPipe_CB->BufferLength, pPipe_InData, &req, userp);
5320 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5321 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Write FAILURE code=0x%x status=0x%x",
5323 (*ResultCB)->ResultStatus = status;
5327 pPipe_OutData = (BYTE *)(*ResultCB)->ResultData;
5328 code = RDR_Pipe_Read( pPipe_CB->RequestId, ResultBufferLength, pPipe_OutData,
5329 &(*ResultCB)->ResultBufferLength, &req, userp);
5331 smb_MapNTError(cm_MapRPCError(code, &req), &status, TRUE);
5332 osi_Log2( afsd_logp, "RDR_Pipe_Transceive Read FAILURE code=0x%x status=0x%x",
5334 (*ResultCB)->ResultStatus = status;
5338 (*ResultCB)->ResultStatus = 0;
5339 osi_Log0(afsd_logp, "RDR_Pipe_Transceive SUCCESS");