runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Supply the Extended Attributes via CreateFile/CreateFile2 instead of NTCreateFile

Open keeratsingh opened this issue 8 years ago • 1 comments

For SqlFileStream to work we need acquire and supply two pieces of information:

  • Path to the destination file: This can be acquired using PathName method, bear in mind this is not a UNC path to the physical file system on the server. The path is just a bogus path that has meaning only in the context of this transaction which SQL Server can use to map to the real file in the file system.
  • Transaction Context Token: Secondly, we need a token that identifies the NTFS file system transaction that SQL Server initiated behind the scenes, which we obtain with the GET_FILESTREAM_TRANSACTION_CONTEXT function.

This transaction context can be supplied via the Extended Attribute Buffer (eaBuffer) argument in case of NTCreateFile. I couldn't find a way to do the same with CreateFile/CreateFile2, hence why I used NTCreateFile. If there is way to do the same with CreateFile/CreateFile2 it would be more preferable.

For more information refer to : dotnet/runtime#25921 dotnet/SqlClient#15

cc @JeremyKuhne

keeratsingh avatar Apr 27 '18 21:04 keeratsingh

Afaik, there is no way to do this without hitting Nt/Zw APIs (such as ZwSetEaFile). In theory it could be added to SetFileInformationByHandle in the future by Windows to allow access.

Ideally we'd get SQL to use another (or additional) mechanism to store the transaction context, such as alternate data streams, which can be used without hitting NT APIs.

JeremyKuhne avatar Sep 28 '18 20:09 JeremyKuhne