I have a user app that opens a file and then calls CreateFileMapping. I have a driver that creates/opens the file which I have traced and successfully executes. The problem is that CreateFileMapping always returns error 193. I have successfully mapped against other files so I'm thinking must be an issue on the driver side. Windows 8.1 x64 (driver obviously 64bit) and the application as well. I have used dependency walker to check any dll issues and all seem to be fine.
Driver snippet:
InitializeObjectAttributes(&fileAttributes,
&fileName,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL, // RootDirectory
NULL // SecurityDescriptor
);
if (KeGetCurrentIrql() != PASSIVE_LEVEL)
return STATUS_INVALID_DEVICE_STATE;
status = ZwCreateFile(
&context->FileHandle,
SYNCHRONIZE | FILE_GENERIC_WRITE | FILE_GENERIC_READ | DELETE,
&fileAttributes,
&ioStatus,
NULL, // alloc size = none
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_OPEN_IF,
FILE_RANDOM_ACCESS |
FILE_NON_DIRECTORY_FILE | FILE_DELETE_ON_CLOSE |
FILE_SYNCHRONOUS_IO_NONALERT | FILE_DEVICE_SECURE_OPEN,
NULL, // eabuffer
0 // ealength
);
User app snippet:
LPCWSTR dev_path = L"\\\\.\\testdisk.txt";
fd = CreateFile(dev_path, FILE_GENERIC_READ | FILE_GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, // FILE_SHARE_DELETE
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (fd == INVALID_HANDLE_VALUE)
{
error("open device %ls failed, %s (%u)\n", dev_path, strerror(errno), GetLastError());
exit(EXIT_FAILURE);
}
mapFile = CreateFileMapping(
fd,
NULL,
PAGE_READWRITE,
0, // maximum object size (high-order DWORD)
1, // maximum object size (low-order DWORD)
NULL);
Edit 1:
The filename in the driver is #define DEV_PATH L"\\DosDevices\\C:\\testdisk.txt"
The symbolic link is #define DEV_SYMBOLIC_LINK L"\\DosDevices\\testdrive.txt"
using the function WdfDeviceCreateSymbolicLink
and I set the device name to #define DEV_NAME L"\\Device\\testdrive.txt"
using the function WdfDeviceInitAssignName
Edit 2:
I have updated the device and file paths. I still get 193 error when accessing the file from user space \\.\qqdevice\test.txt
and if I use C:\qqdevice\test.txt
then the file gets created but the driver never gets notified.
#define DEV_NAME L"\\Device\\qqdevice"
#define DEV_SYMBOLIC_LINK L"\\DosDevices\\qqdevice"
#define DEV_FILE_PATH L"\\DosDevices\\C:\\qqdevice\\test.txt"