Hello list!
My apologies for the crappy looking question, hopefully someone will have
patience to read it and reply…
I was hoping someone could provide some insight into using DeviceExtension
with IoCreateDeviceSecure.
In this case I want to simulate (as much as I can) the way mounting works
on Unix, so there are not many examples to look at out there. I have been
looking at win-btrfs sources, and when I can, fastfat.
So, I call:
status = IoCreateDeviceSecure(WIN_DriverObject,
sizeof(mount_t),
&diskDeviceName,
FILE_DEVICE_DISK,
deviceCharacteristics,
FALSE,
&SDDL_DEVOBJ_SYS_ALL_ADM_RWX_WORLD_RW_RES_R,
NULL,
&diskDeviceObject);
mount_t *zmo_dcb = diskDeviceObject->DeviceExtension;
and fill in my struct ‘zmo_dcb’ with all the goodies I need later.
Some extra bits that follows that, calling IoCreateSymbolicLink(),
unsetting DO_DEVICE_INITIALIZING and finally calling IoVerifyVolume().
Then we wait for the mount request to come in:
case IRP_MJ_FILE_SYSTEM_CONTROL:
switch (IrpSp->MinorFunction) {
case IRP_MN_MOUNT_VOLUME:
DeviceToMount = IrpSp->Parameters.MountVolume.DeviceObject;
mount_t *dcb = DeviceToMount->DeviceExtension; [**1]
which then goes on to call IoCreateDevice(FILE_DEVICE_DISK) and carry on
with other code.
and this works great! No really, it works all is well!
… for me, and for a few other people who have tested it, and I thought I
was done with the mounting part.
Then another user comes along to test it, (on Win10 Pro, like myself, but
hardware vs VMs), and it does not work!
Debugging starts:
The DeviceExtension in [**1] is not mine suddenly - I have no idea what it
points to, but it isn’t the structure I filled in.
When I verify the dcb I get:
if ((dcb->type != MOUNT_TYPE_DCB) ||
(dcb->size != sizeof(mount_t))) {
dprintf(“%s: Not a ZFS dataset – dcb %p ignoring: type 0x%x != 0x%x,
size %d != %d\n”,
func, dcb,
dcb->type, MOUNT_TYPE_DCB, dcb->size,
sizeof(mount_t));
zfs_vnop_mount: Not a ZFS dataset – ignoring: type 0x9fb41040 !=
0x3a444342, size -7423 != 192
Why would this be? Isn’t this what the DeviceExtension ptr is for? Also,
why does it only happen on his install of Win10 ?
I had noticed that win-btrfs also call:
case IRP_MN_MOUNT_VOLUME:
pdo = DeviceToMount;
while (IoGetLowerDeviceObject(pdo)) {
pdo = IoGetLowerDeviceObject(pdo);
dprintf(“going deeper %p\n”, pdo);
}
Which was not needed on my machines (so far), but I thought I would try it
on the trouble machine, in case the device gets encapsulated for some reason:
*** mount request for FFFFD38FE0472040
… going deeper FFFFD38FE03C3C50
… going deeper FFFFD38FE03C4B40
… going deeper FFFFD38FE061F030
… going deeper FFFFD38FE03A9880
zfs_vnop_mount: Not a ZFS dataset – dcb FFFFD38FE03A99D0 ignoring: type
0xe03a9880 != 0x3a444342, size -11377 != 192
which surprised me, and yet, none of those ‘lower device objects’ has a
DeviceExtension that “is mine”.
What gives? Can I not rely on DeviceExtension to stay untouched? Should I
match the new device some other way?
Perhaps by IOCTL_MOUNTDEV_QUERY_DEVICE_NAME ?
Why can his system call IoGetLowerDeviceObject() and get 3 additional
“devices”? How do I know which is mine?
Can I somehow replicate what happens on his system, so I can more easily
debug it myself?
Be patient with me, I’m just a Unix dev…
Lund
–
Jorgen Lundman |
Unix Administrator | +81 (0)90-5578-8500
Shibuya-ku, Tokyo | Japan