Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results


More Info on Driver Writing and Debugging

The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.

Check out The OSR Learning Library at:

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

sending IRP_MJ_PNP to \device\harddisk0\partition0 with minor function IRP_MN_QUERY_DEVICE_RELATIONS

Liam__hkLiam__hk Member Posts: 1
edited November 2020 in NTDEV

I was reading about file system stack and found a source code and i am trying to understand what it is actually doing

it is finding the device object of \device\harddisk0\partition0 and then it sends a IRP_MJ_PNP request to it and builds the IRP using IoBuildSynchronousFsdRequest, sets the minorfunc to IRP_MN_QUERY_DEVICE_RELATIONS and QueryDeviceRelations.Type to TargetDeviceRelation

now can someone explain what does this actually do? whats the purpose of IRP_MN_QUERY_DEVICE_RELATIONS regarding the partition0 device object and whats the deal with this TargetDeviceRelation? where can i read more about this?

    KeInitializeEvent( &event, NotificationEvent, FALSE );

    irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP,
                                        &ioStatusBlock );

    if (irp == NULL) {
        goto End;

    irpStack = IoGetNextIrpStackLocation( irp );
    irpStack->MinorFunction = IRP_MN_QUERY_DEVICE_RELATIONS;
    irpStack->Parameters.QueryDeviceRelations.Type = TargetDeviceRelation;

    irp->IoStatus.Status = STATUS_NOT_SUPPORTED ;

    status = IoCallDriver( DeviceObject, irp );

    if (status == STATUS_PENDING) {

        KeWaitForSingleObject( &event, Executive, KernelMode, FALSE, NULL );
        status = ioStatusBlock.Status;}


  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,972
    edited November 2020

    where can i read more about this?

    How can you ask that question with a straight face? I Googled for IRP_MN_QUERY_DEVICE_RELATIONS, and the top hit was the MSDN page that describes these option. TargetDeviceRelations returns the device object associated with a particular file object.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Developing Minifilters 24 May 2021 Live, Online
Writing WDF Drivers 14 June 2021 Live, Online
Internals & Software Drivers 27 September 2021 Live, Online
Kernel Debugging 15 November 2021 Live, Online