CfSetInSyncState does not behave as documented. (CfAPI) RRS feed

  • Question

  • I try to use CfSetInSyncState with an USN.

    The [documentation][1] says that you can provide an USN and the change will only performed when the USN still matches.

    However calling the Method on an NOT_IN_SYNC file with the current USN will not succeed. It returns `0x80070179` "The File is not in sync with the cloud" (translated from German, so maybe the text does not 100% match). The returned USN value did also not changed. 

    I have a minimal sample on [github][0] that will demonstrate this.

    I have tried different flags to obtain the handle and also using the CreateFile method instead. Opening the file also does not seems to change the USN. But until know I wasn't able to set SyncState if USN was provided nor I could retrieve the current USN from the function.

    Somehow my account is not verified, and I don't know what I can do to verify it. So I can't post links. Sorry for the inconvenience.

    [0]: https://github.com/LokiMidgard/CloudTest

    [1]: https://docs.microsoft.com/en-us/windows/win32/api/cfapi/nf-cfapi-cfsetinsyncstate?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev16.query%3FappId%3DDev16IDEF1%26l%3DEN-US%26k%3Dk(CFAPI%2FCfSetInSyncState)%3Bk(CfSetInSyncState)%3Bk(DevLang-C%2B%2B)%3Bk(TargetOS-Windows)%26rd%3Dtrue

    Monday, March 23, 2020 1:39 PM

All replies

  • Hello Patrick Kranz,

    When creating a new file/file-placeholder, the CfSetInSyncState set CF_IN_SYNC_STATE_NOT_IN_SYNC success with setting tmpUsn to zero.

    If the file is exiting, CfCreatePlaceholders will fails with 0x800700b7(Cannot create a file when the file already exists.) 

    In above test I stop OneDrive to sync, otherwise, if OneDrive is in syncing state, CfCreatePlaceholders will fails with 0x8007018b(Access to the cloud file is denied.).

    So I can't reproduce your issue. Could you try my tests or show some steps for how to reproduce your issue?

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 24, 2020 2:42 AM
  • Hello Rita,

    thanks for your answer and sorry for the late response. I haven't set up e-mail notification correctly. (hope this will work now)

    Can I assume your the same person I talked to on stackoverflow? Then I don't need to repost every thing.

    Unfortunately I'm still not not able to use the USN as a gatekeeper to allow or disallow changes.



    Thursday, June 18, 2020 5:24 AM
  • Hi Patrick

    I have a similar issue and I have found the same question posted by you on stackoverflow and daily checking it for any updates.But I have another question related to this cloud API file on demand feature and I suppose you will be able to answer my question.My question is after creating a placeholder file using the method 'CfCreatePlaceholders' how the hydration process(downloading data from actual file to placeholder file) can be initiated on clicking placeholder file.Which cloud filter API function can be used for that.



    Thursday, July 2, 2020 7:35 AM
  • Calling the function CfConnectSyncRoot you need to add CF_CALLBACK_TYPE_FETCH_DATA to the callbacks. This should get called when the system tries to dehydrate a file.

    In that you then need to send the data using CfExecute

    	CF_OPERATION_INFO opInfo = { 0 };
    	opInfo.StructSize = sizeof(opInfo);
    	opInfo.ConnectionKey = connectionKey;
    	opInfo.TransferKey = transferKey;
    	CF_OPERATION_PARAMETERS opParams = { 0 };
    	opParams.ParamSize = CF_SIZE_OF_OP_PARAM(TransferData);
    	opParams.TransferData.CompletionStatus = NTSTATUS_FROM_WIN32(result);
    	opParams.TransferData.Buffer = buffer;
    	opParams.TransferData.Offset.QuadPart = offset;
    	opParams.TransferData.Length.QuadPart = bufferLength;
    	auto hr = CfExecute(&opInfo, &opParams);
    You should be able to call this multiple times, using offset to define the position.

    Thursday, July 2, 2020 9:31 AM
  • Thank you for your great response.As you mentioned, I have already added CF_CALLBACK_TYPE_FETCH_DATA to the callbacks and send data using CfExecute.But when trying to open the placeholder file while running the application, its showing that 'Can't open this file.Make sure shell is running on your PC,then ry again'.I don't know why this happens.
    Friday, July 3, 2020 6:14 AM
  • I assume you have tried setting a break point int the callback. Does it get called and the CfExecute does not what it should or is the callback not called. I'm not sure if I find some time to create a minimal working sample. However if you have a minimum failing sample on some public git, I could compare my code with yours. Maybe I can find what is the difference to my code.
    Friday, July 3, 2020 8:47 AM
  • I have already tried to set the breakpoint. Unfortunately I am not able to run the program in debugging mode and hence no breakpoints hitting.So I had put console print statements.But print statements inside callback method is not working and hence I  think callback is not getting called .
    • Edited by divzmk Monday, July 6, 2020 8:18 AM
    Monday, July 6, 2020 5:12 AM

  • Hi Patrick,

    As you suggested, I have a minimal sample on github 'https://github.com/Divzmk/CloudSample' that demonstrate the problem.I have changed your CloudTest(https://github.com/LokiMidgard/CloudTest)  github sample for reproducing the issue.Please have a look and let me know whats wrong with the code



    Wednesday, July 22, 2020 7:15 AM