Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
do better at Notification, by converting to UTF so we
handle locale better, work out where slash it based on that.

cleanup the QueryProperty and GetStandard to be cleaner and
return size needed the new way.

volume label size was wrong, included null.

Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Jul 31, 2024
1 parent d7a135b commit bfdec0a
Show file tree
Hide file tree
Showing 4 changed files with 295 additions and 250 deletions.
127 changes: 56 additions & 71 deletions module/os/windows/zfs/zfs_ioctl_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,28 +1127,14 @@ OpenZFS_AddDevice(
RtlInitUnicodeString(&zmo_bus->device_name, L"\\Device\\OpenZFS");
zmo_bus->FunctionalDeviceObject = DriverExtension->FunctionalDeviceObject;
zmo_bus->PhysicalDeviceObject = PhysicalDeviceObject;


// status = IoReportDetectedDevice(WIN_DriverObject, InterfaceTypeUndefined, 0xFFFFFFFF, 0xFFFFFFFF,
// NULL, NULL, 0, &zmo_bus->PhysicalDeviceObject);
// NULL, NULL, 0, &zmo_bus->PNPDeviceObject);

// xprintf("%s called: PhysicalDeviceObject %p\n", __func__, zmo_bus->PhysicalDeviceObject);
// status = IoRegisterDeviceInterface(zmo_bus->PhysicalDeviceObject, &BtrfsBusInterface, NULL,
// &zmo_bus->deviceInterfaceName);
DECLARE_UNICODE_STRING_SIZE(hardwareId, 100);

// RtlInitUnicodeString(&hardwareId, L"ROOT\\OPENZFS");
RtlUnicodeStringPrintf(&hardwareId,
L"ROOT\\OpenZFS%lc%lc", 0, 0);


status = IoSetDevicePropertyData(
PhysicalDeviceObject,
&DEVPKEY_Device_HardwareIds,
0,
0,
DEVPROP_TYPE_STRING_LIST,
(ULONG)(hardwareId.Length),
hardwareId.Buffer
);


zmo_bus->AttachedDevice = IoAttachDeviceToDeviceStack(DriverExtension->FunctionalDeviceObject,
zmo_bus->PhysicalDeviceObject);
Expand All @@ -1161,68 +1147,67 @@ OpenZFS_AddDevice(
// IoInvalidateDeviceRelations(zmo_bus->PhysicalDeviceObject, BusRelations);

#if 1
NTSTATUS ntStatus;
UNICODE_STRING ntUnicodeString; // NT Device Name
UNICODE_STRING ntWin32NameString; // Win32 Name
int err;

static UNICODE_STRING sddl = RTL_CONSTANT_STRING(
L"D:P(A;;GA;;;SY)(A;;GRGWGX;;;BA)"
"(A;;GRGWGX;;;WD)(A;;GRGX;;;RC)");
// Or use &SDDL_DEVOBJ_SYS_ALL_ADM_RWX_WORLD_RW_RES_R

RtlInitUnicodeString(&ntUnicodeString, ZFS_DEV_KERNEL);
ntStatus = IoCreateDeviceSecure(
WIN_DriverObject,
sizeof (mount_t),
&ntUnicodeString, // Device name "\Device\SIOCTL"
FILE_DEVICE_UNKNOWN, // Device type
FILE_DEVICE_SECURE_OPEN, // Device characteristics
FALSE, // Not an exclusive device
&sddl,
NULL,
&DriverExtension->ioctlDeviceObject); // Returned ptr to Device Object

if (!NT_SUCCESS(ntStatus)) {
dprintf("ZFS: Couldn't create the device object "
"/dev/zfs (%S)\n", ZFS_DEV_KERNEL);
return (ntStatus);
}
// dprintf("ZFS: created kernel device node: %p: name %S\n",
// DriverExtension->ioctlDeviceObject, ZFS_DEV_KERNEL);
NTSTATUS ntStatus;
UNICODE_STRING ntUnicodeString; // NT Device Name
UNICODE_STRING ntWin32NameString; // Win32 Name
int err;

static UNICODE_STRING sddl = RTL_CONSTANT_STRING(
L"D:P(A;;GA;;;SY)(A;;GRGWGX;;;BA)"
"(A;;GRGWGX;;;WD)(A;;GRGX;;;RC)");
// Or use &SDDL_DEVOBJ_SYS_ALL_ADM_RWX_WORLD_RW_RES_R

RtlInitUnicodeString(&ntUnicodeString, ZFS_DEV_KERNEL);
ntStatus = IoCreateDeviceSecure(
WIN_DriverObject,
sizeof (mount_t),
&ntUnicodeString, // Device name "\Device\SIOCTL"
FILE_DEVICE_UNKNOWN, // Device type
FILE_DEVICE_SECURE_OPEN, // Device characteristics
FALSE, // Not an exclusive device
&sddl,
NULL,
&DriverExtension->ioctlDeviceObject); // Returned ptr to Device Object

if (!NT_SUCCESS(ntStatus)) {
dprintf("ZFS: Couldn't create the device object "
"/dev/zfs (%S)\n", ZFS_DEV_KERNEL);
return (ntStatus);
}
// dprintf("ZFS: created kernel device node: %p: name %S\n",
// DriverExtension->ioctlDeviceObject, ZFS_DEV_KERNEL);

// ObReferenceObject(ioctlDeviceObject);
// ObReferenceObject(ioctlDeviceObject);

mount_t *dgl;
dgl = DriverExtension->ioctlDeviceObject->DeviceExtension;
dgl->type = MOUNT_TYPE_DGL;
dgl->size = sizeof (mount_t);
mount_t *dgl;
dgl = DriverExtension->ioctlDeviceObject->DeviceExtension;
dgl->type = MOUNT_TYPE_DGL;
dgl->size = sizeof (mount_t);

// Initialize a Unicode String containing the Win32 name
// for our device.
// Initialize a Unicode String containing the Win32 name
// for our device.
#if 1
RtlInitUnicodeString(&ntWin32NameString, ZFS_DEV_DOS);
// RtlInitUnicodeString(&ntWin32NameString, L"\\DosDevices\\Global\\OpenZFS");

// Create a symbolic link between our device name and the Win32 name
ntStatus = IoCreateSymbolicLink(
&ntWin32NameString, &ntUnicodeString);

if (!NT_SUCCESS(ntStatus)) {
dprintf("ZFS: Couldn't create userland symbolic link to "
"/dev/zfs (%wZ)\n", ZFS_DEV);
// ObDereferenceObject(ioctlDeviceObject);
IoDeleteDevice(DriverExtension->ioctlDeviceObject);
return (-1);
}
RtlInitUnicodeString(&ntWin32NameString, ZFS_DEV_DOS);
// RtlInitUnicodeString(&ntWin32NameString, L"\\DosDevices\\Global\\OpenZFS");

// Create a symbolic link between our device name and the Win32 name
ntStatus = IoCreateSymbolicLink(
&ntWin32NameString, &ntUnicodeString);

if (!NT_SUCCESS(ntStatus)) {
dprintf("ZFS: Couldn't create userland symbolic link to "
"/dev/zfs (%wZ)\n", ZFS_DEV);
// ObDereferenceObject(ioctlDeviceObject);
IoDeleteDevice(DriverExtension->ioctlDeviceObject);
return (-1);
}
#endif
// dprintf("ZFS: created userland device symlink\n");
// dprintf("ZFS: created userland device symlink\n");

DriverExtension->ioctlDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
DriverExtension->ioctlDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
#endif



xprintf("bus is up and running\n");
return (STATUS_SUCCESS);
}
Expand Down
69 changes: 20 additions & 49 deletions module/os/windows/zfs/zfs_vnops_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,10 @@ zfs_vnop_lookup_impl(PIRP Irp, PIO_STACK_LOCATION IrpSp, mount_t *zmo,
(CreateDisposition == FILE_OVERWRITE_IF)));

// If it is a volumeopen, we just grab rootvp so that directory
// listings work
// listings work - most Options are ignored with VolumeOpens
if (FileObject->FileName.Length == 0 &&
FileObject->RelatedFileObject == NULL) {
// If DirectoryFile return STATUS_NOT_A_DIRECTORY
// If OpenTargetDirectory return STATUS_INVALID_PARAMETER

dprintf("Started NULL open, returning root of mount\n");
error = zfs_zget(zfsvfs, zfsvfs->z_root, &zp);
if (error != 0)
Expand Down Expand Up @@ -1001,6 +1000,9 @@ zfs_vnop_lookup_impl(PIRP Irp, PIO_STACK_LOCATION IrpSp, mount_t *zmo,

if (OpenRoot) {

if (NonDirectoryFile)
return (STATUS_FILE_IS_A_DIRECTORY);

error = zfs_zget(zfsvfs, zfsvfs->z_root, &zp);

if (error == 0) {
Expand Down Expand Up @@ -2228,12 +2230,12 @@ pnp_query_id(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
idLen = mpt.Length;
break;
case BusQueryHardwareIDs: // IDs, plural
// if (zmo->type == MOUNT_TYPE_BUS)
//if (zmo->type == MOUNT_TYPE_BUS)

Check failure on line 2233 in module/os/windows/zfs/zfs_vnops_windows.c

View workflow job for this annotation

GitHub Actions / checkstyle

missing blank after start comment
RtlUnicodeStringPrintf(&mpt,
L"ROOT\\OpenZFS%lc%lc", 0, 0); // double nulls
// else
// RtlUnicodeStringPrintf(&mpt,
// L"OpenZFSVolume%lcGenDisk%lc%lc", 0, 0, 0);
//else

Check failure on line 2236 in module/os/windows/zfs/zfs_vnops_windows.c

View workflow job for this annotation

GitHub Actions / checkstyle

missing blank after start comment
// RtlUnicodeStringPrintf(&mpt,
// L"OpenZFSVolume%lcGenDisk%lc%lc", 0, 0, 0);
idString = mpt.Buffer;
idLen = mpt.Length;
break;
Expand All @@ -2244,6 +2246,7 @@ pnp_query_id(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
idLen = mpt.Length;
break;
#if 0
// If these are included, AddDevice() does not get called.
case BusQueryCompatibleIDs:
RtlUnicodeStringPrintf(&mpt,
L"OpenZFS\\Generic%lc%lc", 0, 0);
Expand All @@ -2254,10 +2257,6 @@ pnp_query_id(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
idString = zmo->uuid.Buffer;
idLen = zmo->uuid.Length;
break;
case BusQueryContainerID:
idString = zmo->device_name.Buffer;
idLen = zmo->device_name.Length;
break;
#endif
default:
// Status = Irp->IoStatus.Status;
Expand Down Expand Up @@ -2505,17 +2504,10 @@ query_volume_information(PDEVICE_OBJECT DeviceObject, PIRP Irp,
PVPB Vpb = zmo->vpb;
WCHAR *wstr;

if (Vpb) {
ffvi->VolumeSerialNumber = Vpb->SerialNumber;
ffvi->VolumeLabelLength =
Vpb->VolumeLabelLength;
wstr = Vpb->VolumeLabel;
} else {
ffvi->VolumeSerialNumber = 0x19831116;
ffvi->VolumeLabelLength =
zmo->name.Length;
wstr = zmo->name.Buffer;
}
ffvi->VolumeSerialNumber = 0x19831116;
ffvi->VolumeLabelLength =
sizeof(VOLUME_LABEL) - sizeof(WCHAR);

Check failure on line 2509 in module/os/windows/zfs/zfs_vnops_windows.c

View workflow job for this annotation

GitHub Actions / checkstyle

missing space between keyword and paren
wstr = VOLUME_LABEL;

int space =
IrpSp->Parameters.QueryFile.Length -
Expand Down Expand Up @@ -6624,6 +6616,7 @@ _Function_class_(DRIVER_DISPATCH)
case IRP_MN_START_DEVICE:
dprintf("IRP_MN_START_DEVICE\n");
Status = STATUS_SUCCESS;

break;
case IRP_MN_CANCEL_REMOVE_DEVICE:
dprintf("IRP_MN_CANCEL_REMOVE_DEVICE\n");
Expand Down Expand Up @@ -6662,6 +6655,7 @@ _Function_class_(DRIVER_DISPATCH)
// these are not handled in btrfs, pass down
case IRP_MN_DEVICE_ENUMERATED:
dprintf("IRP_MN_DEVICE_ENUMERATED\n");
Status = STATUS_SUCCESS;
break;
case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
dprintf("IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
Expand Down Expand Up @@ -6944,6 +6938,7 @@ _Function_class_(DRIVER_DISPATCH)
case IRP_MN_START_DEVICE:
dprintf("IRP_MN_START_DEVICE\n");
Status = STATUS_SUCCESS;
DbgBreakPoint();
break;
case IRP_MN_CANCEL_REMOVE_DEVICE:
dprintf("IRP_MN_CANCEL_REMOVE_DEVICE\n");
Expand Down Expand Up @@ -7275,6 +7270,7 @@ _Function_class_(DRIVER_DISPATCH)
break;
case IRP_MN_DEVICE_ENUMERATED:
dprintf("IRP_MN_DEVICE_ENUMERATED\n");
Status = STATUS_SUCCESS;
break;
default:
dprintf("Unknown IRP_MJ_PNP(disk): 0x%x\n",
Expand Down Expand Up @@ -7484,26 +7480,11 @@ _Function_class_(DRIVER_DISPATCH)
dprintf("IOCTL_VOLUME_GET_GPT_ATTRIBUTES\n");
Status = 0;
break;
case IOCTL_MOUNTDEV_QUERY_DEVICE_NAME:
dprintf("IOCTL_MOUNTDEV_QUERY_DEVICE_NAME\n");
Status = ioctl_query_device_name(DeviceObject, Irp,
IrpSp);
break;
case IOCTL_MOUNTDEV_QUERY_UNIQUE_ID:
dprintf("IOCTL_MOUNTDEV_QUERY_UNIQUE_ID\n");
Status = ioctl_query_unique_id(DeviceObject, Irp,
IrpSp);
break;
case IOCTL_MOUNTDEV_QUERY_STABLE_GUID:
dprintf("IOCTL_MOUNTDEV_QUERY_STABLE_GUID\n");
Status = ioctl_query_stable_guid(DeviceObject, Irp,
IrpSp);
break;
case IOCTL_MOUNTDEV_QUERY_SUGGESTED_LINK_NAME:
dprintf("IOCTL_MOUNTDEV_QUERY_SUGGESTED_LINK_NAME\n");
Status = ioctl_mountdev_query_suggested_link_name(
DeviceObject, Irp, IrpSp);
break;
case IOCTL_VOLUME_ONLINE:
dprintf("IOCTL_VOLUME_ONLINE\n");
Status = STATUS_SUCCESS;
Expand All @@ -7513,10 +7494,6 @@ _Function_class_(DRIVER_DISPATCH)
dprintf("IOCTL_VOLUME_OFFLINE\n");
Status = STATUS_SUCCESS;
break;
case IOCTL_DISK_IS_WRITABLE:
dprintf("IOCTL_DISK_IS_WRITABLE\n");
Status = STATUS_SUCCESS;
break;
case IOCTL_DISK_MEDIA_REMOVAL:
dprintf("IOCTL_DISK_MEDIA_REMOVAL\n");
Status = STATUS_SUCCESS;
Expand Down Expand Up @@ -7665,11 +7642,9 @@ _Function_class_(DRIVER_DISPATCH)
break;
case IRP_MN_DEVICE_ENUMERATED:
dprintf("IRP_MN_DEVICE_ENUMERATED\n");
Status = STATUS_SUCCESS;
break;
#if 0
case IRP_MN_QUERY_CAPABILITIES: // x INTERFACE TEXT IRP_MN_QUERY_BUS_INFORMATION IRP_MN_QUERY_RESOURCE_REQUIREMENTS IRP_MN_QUERY_RESOURCES
Status = QueryCapabilities(DeviceObject, Irp, IrpSp);
break;
case IRP_MN_QUERY_PNP_DEVICE_STATE:
Status = pnp_device_state(DeviceObject, Irp, IrpSp);
break;
Expand All @@ -7681,10 +7656,6 @@ _Function_class_(DRIVER_DISPATCH)
dprintf("IRP_MN_SURPRISE_REMOVAL\n");
Status = STATUS_SUCCESS;
break;
case IRP_MN_REMOVE_DEVICE:
dprintf("IRP_MN_REMOVE_DEVICE\n");
Status = STATUS_SUCCESS;
break;
case IRP_MN_CANCEL_REMOVE_DEVICE:
dprintf("IRP_MN_CANCEL_REMOVE_DEVICE\n");
Status = STATUS_SUCCESS;
Expand All @@ -7702,7 +7673,7 @@ _Function_class_(DRIVER_DISPATCH)
break;
}
break;
#if 0
#if 1
case IRP_MJ_QUERY_VOLUME_INFORMATION:
Status = query_volume_information(DeviceObject, Irp, IrpSp);
break;
Expand Down
Loading

0 comments on commit bfdec0a

Please sign in to comment.