Skip to content

Commit

Permalink
latest hackslash.
Browse files Browse the repository at this point in the history
register driver seems correct, and first mount is working, although
hardcoded.

Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Jul 26, 2024
1 parent bde195d commit d7a135b
Show file tree
Hide file tree
Showing 9 changed files with 591 additions and 337 deletions.
6 changes: 3 additions & 3 deletions cmd/os/windows/zfsinstaller/zfsinstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ DWORD
executeInfSection(const char *cmd, char *inf_path) {

#ifdef _DEBUG
system("sc query ZFSin");
system("sc query OpenZFS");
fprintf(stderr, "\n\n");
#endif

Expand All @@ -528,7 +528,7 @@ executeInfSection(const char *cmd, char *inf_path) {


#ifdef _DEBUG
system("sc query ZFSin");
system("sc query OpenZFS");
#endif

return (error);
Expand Down Expand Up @@ -665,7 +665,7 @@ send_zfs_ioc_unregister_fs(void)
#include <cfgmgr32.h>
#include <newdev.h>

#define ZFS_ROOTDEV "Root\\OpenZFS"
#define ZFS_ROOTDEV "ROOT\\OpenZFS"
// DevCon uses LoadLib() - but lets just static link
#pragma comment(lib, "Newdev.lib")

Expand Down
2 changes: 1 addition & 1 deletion include/os/windows/zfs/sys/zfs_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern PDEVICE_OBJECT ioctlDeviceObject;
extern PDEVICE_OBJECT fsDiskDeviceObject;

#define ZFS_SERIAL (ULONG)'wZFS'
#define VOLUME_LABEL L"ZFS"
#define VOLUME_LABEL L"OpenZFSVolume"

#define ZFS_HAVE_FASTIO

Expand Down
2 changes: 1 addition & 1 deletion include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ typedef struct ddt_histogram {
#define ZFS_DEV "\\\\.\\ZFS"
#define ZFS_DEV_DOS L"\\DosDevices\\Global\\ZFS"
#define ZFS_DEV_KERNEL L"\\Device\\ZFSCTL"
#define ZFS_GLOBAL_FS_DISK_DEVICE_NAME L"\\ZFS"
#define ZFS_GLOBAL_FS_DISK_DEVICE_NAME L"\\OpenZFS"
#else
#define ZFS_DEV "/dev/zfs"
#endif
Expand Down
23 changes: 13 additions & 10 deletions module/os/windows/OpenZFS.inf
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,25 @@ OpenZFS.DllFiles = 11 ;%windir%\system32
%Me%=Standard,NTamd64,NTx86

[Standard.NTamd64]
%VolumeName% = OpenZFS_Install, OpenZFSVolume
;%DriverName% = OpenZFS_Install, ROOT\OpenZFS
%ControllerName% = OpenZFS_Install, ROOT\OpenZFS
;%VolumeName% = OpenZFS_Install, OpenZFSVolume
%DriverName% = OpenZFS_Install, ROOT\OpenZFS
;%ControllerName% = OpenZFS_Install, ROOT\OpenZFS

[Standard.NTx86]
%VolumeName% = OpenZFS_Install, OpenZFSVolume
;%DriverName% = OpenZFS_Install, ROOT\OpenZFS
%ControllerName% = OpenZFS_Install, ROOT\OpenZFS
;%VolumeName% = OpenZFS_Install, OpenZFSVolume
%DriverName% = OpenZFS_Install, ROOT\OpenZFS
;%ControllerName% = OpenZFS_Install, ROOT\OpenZFS

[OpenZFS_Install]
OptionDesc = %ServiceDescription%
CopyFiles = OpenZFS.DriverFiles
AddReg=Device_AddReg
AddReg = OpenZFS_AddReg

[Device_AddReg]
HKR,,DeviceType,0x00010001,1
[OpenZFS_AddReg]
;HKR,,DeviceType,0x00010001,0x00000002
;HKR,,Type,0x00010001,0x00000002 ; FILE_SYSTEM_DRIVER
;HKR,,System.Devices.ContainerID,, "{00000001-0002-0003-0004-000000000001}"
;HKR,,Group,0x00000000,"File System"

;;,OpenZFS.DllFiles
;;RegisterDlls = shellopenzfs
Expand Down Expand Up @@ -79,7 +82,7 @@ DelService = %ServiceName%,0x200 ;Ensure service is stopped before deleting
DisplayName = %ServiceName%
Description = %ServiceDescription%
ServiceBinary = %12%\%DriverName%.sys ;%windir%\system32\drivers\
ServiceType = 1
ServiceType = 2
StartType = 1 ;SERVICE_SYSTEM_START
ErrorControl = 1
LoadOrderGroup = "File System"
Expand Down
104 changes: 3 additions & 101 deletions module/os/windows/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,103 +74,12 @@ extern _Function_class_(IO_WORKITEM_ROUTINE)
void __stdcall
sysctl_os_registry_change(DEVICE_OBJECT *DeviceObject,
PVOID Parameter);
void
mount_add_device(PDEVICE_OBJECT DriverObject,
PDEVICE_OBJECT PhysicalDeviceObject, PDEVICE_OBJECT AddDeviceObject);

NTSTATUS
OpenZFS_AddDevice(
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT PhysicalDeviceObject
)
{
NTSTATUS status;

if (PhysicalDeviceObject == NULL) {
DbgBreakPoint();
return (STATUS_NO_MORE_ENTRIES);
}

OpenZFS_Driver_Extension *DriverExtension =
(OpenZFS_Driver_Extension *)IoGetDriverObjectExtension(DriverObject, DriverObject);

xprintf("%s called: PhysicalDeviceObject %p\n", __func__, PhysicalDeviceObject);
DbgBreakPoint();

if (DriverExtension == NULL) {
dprintf("No DriverExtension? Help!\n");
return (STATUS_INVALID_PARAMETER);
}

if (PhysicalDeviceObject->DeviceType == FILE_DEVICE_CONTROLLER) {
DriverExtension->PhysicalDeviceObject = PhysicalDeviceObject;
return (STATUS_SUCCESS);
}

// This isnt needed, we set it in DriverLoad
if (DriverExtension->PhysicalDeviceObject == NULL) {
// Called when driver installs at load time.
DriverExtension->PhysicalDeviceObject = PhysicalDeviceObject;
#if 0 // chatgpt version
// I feel we don't really need this one?
status = IoCreateDevice(
DriverObject,
sizeof(mount_t),
NULL,
FILE_DEVICE_BUS_EXTENDER,
FILE_AUTOGENERATED_DEVICE_NAME | FILE_DEVICE_SECURE_OPEN,
FALSE,
&DriverExtension->FunctionalDeviceObject // busfdo
);

if (NT_SUCCESS(status)) {
mount_t *zmo = DriverExtension->FunctionalDeviceObject->DeviceExtension;
zmo->size = sizeof(mount_t);
zmo->type = MOUNT_TYPE_BUS;
DriverExtension->FunctionalDeviceObject->Flags |= DO_POWER_PAGABLE;
DriverExtension->FunctionalDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
// DriverExtension->ChildDeviceObject = DriverExtension->FunctionalDeviceObject;
zmo->PhysicalDeviceObject = PhysicalDeviceObject;

DriverExtension->LowerDeviceObject =
IoAttachDeviceToDeviceStack(DriverExtension->FunctionalDeviceObject,
PhysicalDeviceObject);

zmo->LowerDeviceObject = DriverExtension->LowerDeviceObject;
RtlInitUnicodeString(&zmo->bus_name, L"OpenZFS");

status = IoRegisterDeviceInterface(DriverExtension->FunctionalDeviceObject,
&BtrfsBusInterface, NULL, &zmo->bus_name);

status = IoSetDeviceInterfaceState(&zmo->bus_name, TRUE);

}
#else // btrfs


#endif
return (STATUS_SUCCESS);
}

// DbgBreakPoint();

// OK, we created a new mount
if (DriverExtension->AddDeviceObject) {
PDEVICE_OBJECT AddDeviceObject = DriverExtension->AddDeviceObject;
DriverExtension->AddDeviceObject = NULL; // Yeah, we need better sync here

mount_add_device(DriverObject, PhysicalDeviceObject, AddDeviceObject);

}

return (STATUS_SUCCESS);
}

void
OpenZFS_Fini(PDRIVER_OBJECT DriverObject)
{
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "OpenZFS_Fini\n"));

DbgBreakPoint();
zfs_vfsops_fini();

if (STOR_DriverUnload != NULL) {
Expand Down Expand Up @@ -217,14 +126,8 @@ DriverEntry(_In_ PDRIVER_OBJECT DriverObject,
frequency = KeQueryPerformanceCounter(NULL);
start = KeQueryPerformanceCounter(NULL);


status = IoAllocateDriverObjectExtension(
DriverObject,
DriverObject, // Identifying the extension
sizeof(OpenZFS_Driver_Extension), // Size of your custom structure
(PVOID*)&DriverExtension
);

if (zfs_init_driver_extension(DriverObject))
return (STATUS_INSUFFICIENT_RESOURCES);

ZFSWppInit(DriverObject, pRegistryPath);

Expand Down Expand Up @@ -269,7 +172,6 @@ DriverEntry(_In_ PDRIVER_OBJECT DriverObject,

/* Now set the Driver Callbacks to dispatcher and start ZFS */
WIN_DriverObject->DriverUnload = OpenZFS_Fini;
WIN_DriverObject->DriverExtension->AddDevice = OpenZFS_AddDevice;

/* Start ZFS itself */
zfs_kmod_init();
Expand Down
Loading

0 comments on commit d7a135b

Please sign in to comment.