VS 2015 migration problem

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

VS 2015 migration problem

Karsten Winter
Currently I migrate the FDO common part to VS 2015.
Here I came to a problem with a deprecated functionality. It's in the class fdo\unmanaged\src\common\io\FileStream.cpp on the method "InitFileStream". The file stream will be opened and the read/write status will be evaluated by a property of the FILE type (_flag).
But this property is now not available anymore. See comment about VC++ 14 FILE encapsulation:

In previous versions, the FILE type was completely defined in <stdio.h>, so it was possible for user code to reach into a FILE and muck with its internals.
We have refactored the stdio library to improve encapsulation of the library implementation details.
As part of this, FILE as defined in <stdio.h> is now an opaque type and its members are inaccessible from outside of the CRT itself.

There are other options to read the file status. But none of them are working like FDO expects. The read-only permission how the file was opened, can not be requested later with the file handler. I have attached a patch with the options I used.
One option is the "fstat" method. But the "st_mode" field of the output does not reflect how the file was opened before. It's always 33206, not matter whether the file was opened with e.g. "rt" or "wt".
I couldn't also find out which bit mask combination this is.
The other option I tried is the method "GetFileInformationByHandle". But here again, the file permission defined on open the file will not be considered. When the file will be opened with read-only, the dwAttributes value is 8224,

It looks that the file permissions are used from the file on the disc and not how the file handle itself was created. There is no way to request the read-only attribute correctly.
Only when I open the file with the "CREATE_ALWAYS" (dwCreationDisposition) flag I get the read-only attribute. But then an existing file will be erased and overwritten(not what we want).

Some unit tests (fdo\unittest\iotests.cpp) are set-up that the file stream has the properties of how the file was opened. Open the file with "rt" flags expect that the file is read-only. But when the file is not read-only on the disc,
the file stream is writeable with the current information we get from the system!

Do you have any ideas how do we get the status of the file from the permission we gave to the "CreateFile" or "_wfopen" method?
Otherwise we will have to change it that way that we say, we can only get the status of the file how it is on disc, so lets work with it. Then we have to adapt the related unit tests in "iotest.cpp"

Best regards