首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >cfapi:云操作无效

cfapi:云操作无效
EN

Stack Overflow用户
提问于 2020-03-18 03:15:54
回答 2查看 686关注 0票数 3

我正在做一个基于云同步引擎支持占位符CloudMirror。在数据上遇到了问题

当我双击窗口资源管理器中的文件(占位符)时,app触发FILE_ATTRIBUTE_PINNED和水化文件。然后cfapi调用FETCH_DATA并读取异步文件(我的应用程序工作与CloudMirror看起来一样)。

但我从CfExecute is 0x8007017c the cloud operation is invalid得到了HRESULT的回报。调试外观所有值均为真

那该怎么解决呢,谢谢。

代码语言:javascript
运行
复制
#define CHUNKSIZE 4096
#define FIELD_SIZE( type, field ) ( sizeof( ( (type*)0 )->field ) )
#define CF_SIZE_OF_OP_PARAM( field )( FIELD_OFFSET( CF_OPERATION_PARAMETERS, field ) + FIELD_SIZE( CF_OPERATION_PARAMETERS, field ) )
    struct READ_COMPLETION_CONTEXT
    {
        OVERLAPPED Overlapped;
        LARGE_INTEGER CallbackInfo_FileSize;
        CF_CONNECTION_KEY CallbackInfo_ConnectionKey;
        CF_TRANSFER_KEY CallbackInfo_TransferKey;
        HANDLE PipeHandle{ 0 };
        LARGE_INTEGER StartOffset;
        LARGE_INTEGER RemainingLength;
        ULONG BufferSize;

        WCHAR* FullPath{ nullptr };
        BYTE* Buffer{ nullptr };
        ~READ_COMPLETION_CONTEXT()
        {
            if (FullPath) delete FullPath;
            if (Buffer) delete Buffer;
            if (PipeHandle) CloseHandle(PipeHandle);
        }
        void Cancel()
        {
            TransferData(
                CallbackInfo_ConnectionKey, 
                CallbackInfo_TransferKey,
                NULL,
                StartOffset,
                RemainingLength,
                STATUS_UNSUCCESSFUL);
        }
    };
    void CALLBACK FETCH_DATA(_In_ CONST CF_CALLBACK_INFO* callbackInfo, _In_ CONST CF_CALLBACK_PARAMETERS* callbackParameters)
    {
        try
        {
            //...
                if (DownloadItem(/*call to c++\cli for stream download and copy async to pipe server*/))
                {
                    std::wstring pipename(L"\\\\.\\pipe\\");
                    pipename.append(ci->Id);
                    HANDLE hpipe = CreateFile(pipename.c_str(),
                        GENERIC_READ,
                        0,                  // no sharing 
                        NULL,               // default security attributes
                        OPEN_EXISTING,
                        FILE_FLAG_OVERLAPPED,
                        NULL);              // no template file 
                    if (hpipe != INVALID_HANDLE_VALUE)
                    {
                        if (GetLastError() != ERROR_PIPE_BUSY)
                        {
                            READ_COMPLETION_CONTEXT* readContext = new READ_COMPLETION_CONTEXT();
                            DWORD chunkBufferSize = (ULONG)min(callbackParameters->FetchData.RequiredLength.QuadPart, CHUNKSIZE);

                            std::wstring fullClientPath(callbackInfo->VolumeDosName);
                            fullClientPath.append(callbackInfo->NormalizedPath);
                            readContext->Overlapped.Offset = callbackParameters->FetchData.RequiredFileOffset.LowPart;
                            readContext->Overlapped.OffsetHigh = callbackParameters->FetchData.RequiredFileOffset.HighPart;
                            readContext->CallbackInfo_FileSize = callbackInfo->FileSize;
                            readContext->CallbackInfo_ConnectionKey = callbackInfo->ConnectionKey;
                            readContext->CallbackInfo_TransferKey = callbackInfo->TransferKey;
                            readContext->PipeHandle = hpipe;
                            readContext->StartOffset = callbackParameters->FetchData.RequiredFileOffset;
                            readContext->RemainingLength = callbackParameters->FetchData.RequiredLength;
                            readContext->BufferSize = chunkBufferSize;
                            readContext->FullPath = Utilities::WStringToWCHARP(fullClientPath);
                            readContext->Buffer = new BYTE[chunkBufferSize];

                            if (ReadFileEx(hpipe, readContext->Buffer, chunkBufferSize, &readContext->Overlapped, OverlappedCompletionRoutine)) 
                                if (GetLastError() == S_OK) return;
                            delete readContext;
                        }
                        else CloseHandle(hpipe);
                    }
                }               
            }
        
        catch (...)
        {        
        }
        TransferData(
            callbackInfo->ConnectionKey,
            callbackInfo->TransferKey,
            NULL,
            callbackParameters->FetchData.RequiredFileOffset,
            callbackParameters->FetchData.RequiredLength,
            STATUS_UNSUCCESSFUL);
    }
    void CALLBACK CANCEL_FETCH_DATA(_In_ CONST CF_CALLBACK_INFO* callbackInfo,_In_ CONST CF_CALLBACK_PARAMETERS* callbackParameters)
    {

    }

    HRESULT TransferData(
        _In_ CF_CONNECTION_KEY connectionKey,
        _In_ LARGE_INTEGER transferKey,
        _In_reads_bytes_opt_(length.QuadPart) LPCVOID transferData,
        _In_ LARGE_INTEGER startingOffset,
        _In_ LARGE_INTEGER length,
        _In_ NTSTATUS completionStatus)
    {
        CF_OPERATION_INFO opInfo = { 0 };
        CF_OPERATION_PARAMETERS opParams = { 0 };

        opInfo.StructSize = sizeof(opInfo);
        opInfo.Type = CF_OPERATION_TYPE_TRANSFER_DATA;
        opInfo.ConnectionKey = connectionKey;
        opInfo.TransferKey = transferKey;
        opParams.ParamSize = CF_SIZE_OF_OP_PARAM(TransferData);
        opParams.TransferData.CompletionStatus = completionStatus;
        opParams.TransferData.Buffer = transferData;
        opParams.TransferData.Offset = startingOffset;
        opParams.TransferData.Length = length;
        HRESULT hresult = CfExecute(&opInfo, &opParams);
        return hresult;
    }

    void WINAPI OverlappedCompletionRoutine(
        _In_ DWORD errorCode,
        _In_ DWORD numberOfBytesTransfered,
        _Inout_ LPOVERLAPPED overlapped)
    {
        READ_COMPLETION_CONTEXT* readContext = (READ_COMPLETION_CONTEXT*)overlapped;
        if (errorCode == 0 && !GetOverlappedResult(readContext->PipeHandle, overlapped, &numberOfBytesTransfered, TRUE)) errorCode = GetLastError();

        if (errorCode != 0)
        {
            readContext->Cancel();
            delete readContext;
            return;
        }

        assert(numberOfBytesTransfered != 0);

        LONGLONG total = readContext->CallbackInfo_FileSize.QuadPart;
        LONGLONG completed = readContext->StartOffset.QuadPart + numberOfBytesTransfered;

        Utilities::ApplyTransferStateToFile(readContext->FullPath,
            readContext->CallbackInfo_ConnectionKey,
            readContext->CallbackInfo_TransferKey,
            total,
            completed);

        HRESULT hresult = TransferData(
            readContext->CallbackInfo_ConnectionKey,
            readContext->CallbackInfo_TransferKey,
            errorCode == 0 ? readContext->Buffer : NULL,
            readContext->StartOffset,
            Utilities::LongLongToLargeInteger(numberOfBytesTransfered),
            errorCode);
        if (hresult != S_OK)
        {
            readContext->Cancel();
            delete readContext;
            winrt::check_hresult(hresult);
            return;
        }

        readContext->StartOffset.QuadPart += numberOfBytesTransfered;
        readContext->RemainingLength.QuadPart -= numberOfBytesTransfered;

        if (readContext->RemainingLength.QuadPart > 0)
        {
            DWORD bytesToRead = (DWORD)(min(readContext->RemainingLength.QuadPart, readContext->BufferSize));
            readContext->Overlapped.Offset = readContext->StartOffset.LowPart;
            readContext->Overlapped.OffsetHigh = readContext->StartOffset.HighPart;

            if (!ReadFileEx(readContext->PipeHandle, readContext->Buffer, bytesToRead, &readContext->Overlapped, OverlappedCompletionRoutine))
            {
                readContext->Cancel();
                delete readContext;
            }
        }
        else delete readContext;//done
    }

编辑:经过测试,假字节= 4096它运行成功。那么,数据传输的最小限度是多少?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-07-05 02:23:03

我在另一个论坛上的问题

卡盘大小似乎需要4096倍。将此大小定义为(4096*N)将解决0x8007017c错误。

票数 0
EN

Stack Overflow用户

发布于 2020-08-25 00:55:53

这被怀疑是在传输数据操作期间发生偏移/长度对齐的问题。这就是API规范对这些参数的描述。

OpParams.TransferData.Offset和OpParams.TransferData.Length描述了同步提供程序向其传输数据的占位符中的范围。不需要同步提供程序按一次请求返回所有数据。同步提供程序也可以返回比请求更多的数据。例如,由于性能或其他原因,同步提供程序可以决定过读.同步提供程序还可以重复执行多个TRANSFER_DATA操作,作为对同一个FETCH_DATA回调的响应。唯一的要求是偏移量和长度都对齐,除非所描述的范围以逻辑文件大小(EoF)结束,在这种情况下,只要结果范围结束于或超过逻辑文件大小,就不需要对长度为4KB。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60733034

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档