Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PrjGetOnDiskFileState not available? #49

Closed
FeralSquid opened this issue Jul 22, 2020 · 4 comments
Closed

PrjGetOnDiskFileState not available? #49

FeralSquid opened this issue Jul 22, 2020 · 4 comments

Comments

@FeralSquid
Copy link

Hello,

I need a way to tell if a given random file path string from a user/client application is as "real"/local file or if it is virtual (whether hydrated or not) quickly.

From the MSDN docs, it sounds like PrjGetOnDiskFileState() is exactly what I want here, but it doesn't appear to be exposed through the managed layer ... am I overlooking it, or is there a reason it was omitted?

I can just call File.Exists(), I suppose, but that seems pretty wasteful when I'm going to be in the code that owns the VirtualizationInstance anyway.

I could also track all locally created files via callbacks, I suppose, but then I'd have to persist that and keep it in memory, and it could be millions in degenerate cases, so definitely isn't ideal.

Thanks,
Brandon

P.S. - I'm just starting on a project using this and so far it is pretty sweet and easy to work with! ;)

@Debee416
Copy link

Hi,
the method you are looking for is Microsoft.Windows.ProjFS.Utils.TryGetOnDiskFileState().

D.

@FeralSquid
Copy link
Author

Ah, there it is!

Thanks

@cgallred
Copy link
Contributor

@FeralSquid note that TryGetOnDiskFileState() will never return a state indicating "virtual"; if you look in Microsoft.Windows.ProjFS.OnDiskFileState you'll see that there is no "virtual" state. That's because a virtual file has no on-disk state. Calling TryGetOnDiskFileState() on a path for a virtual item will cause a request to the provider to hydrate a placeholder (which is why there's a warning that a running provider needs to be cautious calling it; the idea is that it is mainly intended for utility apps).

If you just want to tell the difference between virtual and local (in any state), you can enumerate the item's parent directory. If the FILE_ATTRIBUTE_RECALL_ON_OPEN bit is set for that item in the enumeration then it is virtual. Again, you may need to be careful if the provider is performing the enumeration since it will receive callbacks to supply the contents of the enumeration it is itself requesting.

Note that a provider that supports view changes would be expected to keep track of which items it has hydrated, otherwise it would be difficult and/or expensive for the provider to determine which local items needed to be updated or deleted in the view change.

@FeralSquid
Copy link
Author

FeralSquid commented Jul 22, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants