Hi (again…),
Even though the official suggestion is to open DosDevices objects with CreateFile(), it will be a significant benefit if it could be done with the POSIX-compliant functions fopen() and open().
I do recall the remarks about Windows not being Linux when I asked a similar question on accessing these objects (symlinks, actually) in a DOS command window. I also know that the common way to expose hardware is with a supporting API. But one of the great benefits of this specific project is to make the hardware available to less professional programmers. It’s a development kit more than a finalized product.
There are no problems at all when using Cygwin. It looks like cygwin1.dll does the translation from fopen() and open() to CreateFile() without making any fuss about what kind of object it’s opening, so both command line utilities and my own test programs work great.
But when compiling the test programs with Visual Studio (or with gcc, with the -mno-cygwin flag), open(…, O_RDONLY), _open(…, O_RDONLY) and fopen(…, “rb”) fail on the DosDevice with an “Invalid argument” error. Needless to say, there is no problem when I try exactly the same programs on a regular disk file.
This is something I’m ready to go a long way to fix.
IrpTracker (as well as other debug dumps) tell me that the device driver itself returned success on the CreateFile IRP. The IRP sequence goes simply CREATE, CLEANUP and CLOSE, all returning with success.
A dump of API calls to kerner32.dll reveals a CreateFileA() call returning successfully, followed by a GetFileType() returning zero (FILE_TYPE_UNKNOWN), after which CloseHandle() is called. When I ran the same thing on a regular file, GetFileType() returned 0x0001 (FILE_TYPE_DISK). It does look like the problem, in particular in light of a question asked some ten years ago:
http://www.osronline.com/showThread.cfm?link=31320
Unfortunately, setting IoCreateDevice()'s DeviceType to FILE_DEVICE_DISK_FILE_SYSTEM didn’t help (neither did FILE_DEVICE_NAMED_PIPE or FILE_DEVICE_STREAMS which make more sense in my context). GetFileType() keeps returning FILE_TYPE_UNKNOWN.
Maybe it’s the difference in Windows version (Windows 7, build 7600 in my case). I couldn’t know.
Any ideas?
Thanks in advance,
Eli