winapiwindows-10onedriventfswindows-10-desktop

How can I automate no, partial and full hydration of "cloud" files (OneDrive) for testing?


I would like to test some software and would like to make it well-behaved regarding cloud files. For reference functions like RtlIsPartialPlaceholder and RtlIsCloudFilesPlaceholder have been introduced in order to look at the information returned when traversing the folder hierarchy. The above links point to kernel mode documentation, but these functions also exist in user mode (ntdll.dll) and they are really implemented very trivially.

However, in order to test said software I would have to be able to somehow create the states a placeholder for a file on OneDrive can be in.

What functions (registered COM classes would also be fine) can I use to automate creation of a reproducible test set up which I can use to:

  1. create placeholders
  2. only partially hydrate a placeholder
  3. achieve the same for both directories and files

PS: this question was the only one remotely connected to the topic, which I was able to find here on SO.


Solution

  • Standard file/directory operations (create/read/write, etc.) can be achieved transparently using the Win32 API. That's the whole point of this technology.

    So, you can create a placeholder using the standard Win32 APIs.

    If you create a file or directory in a "sync root" (like in the OneDrive folder hierarchy in the OneDrive case), the associated sync engine process (like OneDrive.exe) will ensure the file or directory is a placeholder. And you can't create a placeholder outside of a sync root hierarchy, AFAIK.

    For a file (you can't hydrate or dehydrate a directory), reading/writing correspond to hydration. Note that some sync engines (and/or depending on their configuration) can decide to always fully hydrate a file even if only some bytes were asked by the end-user API (applications).

    There are some specific Win32 APIs though for special operations.

    You can dehydrate a file using CfDehydratePlaceholder. You can hydrate a file CfHydratePlaceholder. For all the Cloud Filter API, when creating directory handles, don't forget to use the FILE_FLAG_BACKUP_SEMANTICS flags.