How to get "\Device\HarddiskVolume1" Device Object ?

How to get “\Device\HarddiskVolume1” Device Object ?

I use IoGetDeviceObjectPointer() get “\Device\HarddiskVolume1” Device object , my code:

NTSTATUS func_Status = STATUS_SUCCESS ;

UNICODE_STRING ustring_DHV1 ;

PFILE_OBJECT pfileobject_DHV1 = NULL ;
PDEVICE_OBJECT pdeviceobject_DHV1 = NULL ;

WCHAR wchar_DHV1 = L"\Device\HarddiskVolume1" ;

RtlInitUnicodeString(&ustring_DHV1,
wchar_DHV1) ;

func_Status = IoGetDeviceObjectPointer(&ustring_DHV1,
FILE_ALL_ACCESS,
&pfileobject_DHV1,
&pdeviceobject_DHV1) ;

but pdeviceobject_DHV1->DriverObject->DriverName is “\FileSystem\RAW” , not is “\Driver\Ftdisk” , Why ?

I use DeviceTree , this show \Driver\Ftdisk -> \Device\HarddiksVolume1

IoGetDeviceObjectPointer() is used to get a pointer to the *TOP* object in
the named device object’s stack.

On Wed, Jul 9, 2008 at 8:51 AM, wrote:

> How to get “\Device\HarddiskVolume1” Device Object ?
>
> I use IoGetDeviceObjectPointer() get “\Device\HarddiskVolume1” Device
> object , my code:
>
> NTSTATUS func_Status = STATUS_SUCCESS ;
>
> UNICODE_STRING ustring_DHV1 ;
>
> PFILE_OBJECT pfileobject_DHV1 = NULL ;
> PDEVICE_OBJECT pdeviceobject_DHV1 = NULL ;
>
> WCHAR wchar_DHV1 = L"\Device\HarddiskVolume1" ;
>
> RtlInitUnicodeString(&ustring_DHV1,
> wchar_DHV1) ;
>
> func_Status = IoGetDeviceObjectPointer(&ustring_DHV1,
> FILE_ALL_ACCESS,
>
> &pfileobject_DHV1,
>
> &pdeviceobject_DHV1) ;
>
>
> but pdeviceobject_DHV1->DriverObject->DriverName is “\FileSystem\RAW” ,
> not is “\Driver\Ftdisk” , Why ?
>
> I use DeviceTree , this show \Driver\Ftdisk -> \Device\HarddiksVolume1
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Why do you need this? for filtering? then register as PnP volume filter.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntdev…
> How to get “\Device\HarddiskVolume1” Device Object ?
>
> I use IoGetDeviceObjectPointer() get “\Device\HarddiskVolume1” Device object
, my code:
>
> NTSTATUS func_Status = STATUS_SUCCESS ;
>
> UNICODE_STRING ustring_DHV1 ;
>
> PFILE_OBJECT pfileobject_DHV1 = NULL ;
> PDEVICE_OBJECT pdeviceobject_DHV1 = NULL ;
>
> WCHAR wchar_DHV1 = L"\Device\HarddiskVolume1" ;
>
> RtlInitUnicodeString(&ustring_DHV1,
> wchar_DHV1) ;
>
> func_Status = IoGetDeviceObjectPointer(&ustring_DHV1,
> FILE_ALL_ACCESS,
> &pfileobject_DHV1,
> &pdeviceobject_DHV1) ;
>
>
> but pdeviceobject_DHV1->DriverObject->DriverName is “\FileSystem\RAW” , not
is “\Driver\Ftdisk” , Why ?
>
> I use DeviceTree , this show \Driver\Ftdisk -> \Device\HarddiksVolume1
>

Thank Michael Zhu and Maxim S. Shatskih

To Maxim S. Shatskih

Because i want to use diskperf driver filter two types IRP[1: Disk offset’s IRP 2: Partition offset’s IRP], So, I install diskperf driver use register as PnP disk filter,and then my diskperf driver start, this driver will Attach to volume .But I use this code attach to volume device is failed .

NTSTATUS func_Status = STATUS_SUCCESS ;

WCHAR wchar_DHV1 = L"\Device\HarddiskVolume1" ;

RtlInitUnicodeString(&ustring_DHV1,
wchar_DHV1) ;

func_Status = IoGetDeviceObjectPointer(&ustring_DHV1,
FILE_ALL_ACCESS,
&pfileobject_DHV1,
&pdeviceobject_DHV1) ;
if (!NT_SUCCESS(func_Status))
{
return FALSE ;
}
else
{
func_Status = IoCreateDevice(pdeviceobject_DHV1->DriverObject,
DEVICE_EXTENSION_SIZE,
NULL,
FILE_DEVICE_DISK,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&pdevobj_FilterDeviceObject) ;
if (!NT_SUCCESS(func_Status))
{
DISK_KDPRINT((“Cannot create Par filterDeviceObject\n”)) ;
return FALSE ;
}
else
{
g_pdevobj_PartitionDeviceObject = pdevobj_FilterDeviceObject ;
DISK_KDPRINT((“pdevobj_PartitionDeviceObject %p\n”, pstruct_DeviceExtension->pdevobj_PartitionDeviceObject)) ;
}

pdevobj_FilterDeviceObject->Flags |= DO_DIRECT_IO ;

pstruct_DeviceExtension->pdevobj_TargetPartitionDeviceObject = IoAttachDeviceToDeviceStack(pdevobj_FilterDeviceObject,
pdeviceobject_DHV1) ;

// default to DO_POWER_PAGABLE
pdevobj_FilterDeviceObject->Flags |= DO_POWER_PAGABLE ;

// Clear the DO_DEVICE_INITIALIZING flag
pdevobj_FilterDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING ;
}

Be very precise in the terminology you use, what you wrote is mixing
terminology between a disk filter and a volume filter.

As far as I read what you wrote, you have installed a disk filter and
from within the PnP StartDevice you try to attach to a volume ? This
is bound to fail, volumes don’t exist until after the disk is started.

By the sound of it you seem to have some architecture in mind whereby
you think you need to filter both disks and volumes. If this is the
case, then write both a disk filter and a volume filter, don’t try to
do both in the same driver.

Tell us what you’re trying to achieve and we may be able to help more.

Mark.

At 04:12 14/07/2008, xxxxx@gmail.com wrote:

Thank Michael Zhu and Maxim S. Shatskih

To Maxim S. Shatskih

Because i want to use diskperf driver filter two types IRP[1: Disk
offset’s IRP 2: Partition offset’s IRP], So, I install diskperf
driver use register as PnP disk filter,and then my diskperf driver
start, this driver will Attach to volume .But I use this code attach
to volume device is failed .

NTSTATUS func_Status = STATUS_SUCCESS ;

WCHAR wchar_DHV1 = L"\Device\HarddiskVolume1" ;

RtlInitUnicodeString(&ustring_DHV1,
wchar_DHV1) ;

func_Status = IoGetDeviceObjectPointer(&ustring_DHV1,
FILE_ALL_ACCESS,

&pfileobject_DHV1,

&pdeviceobject_DHV1) ;
if (!NT_SUCCESS(func_Status))
{
return FALSE ;
}
else
{
func_Status = IoCreateDevice(pdeviceobject_DHV1->DriverObject,
DEVICE_EXTENSION_SIZE,
NULL,

FILE_DEVICE_DISK,

FILE_DEVICE_SECURE_OPEN,
FALSE,

&pdevobj_FilterDeviceObject) ;
if (!NT_SUCCESS(func_Status))
{
DISK_KDPRINT((“Cannot create Par filterDeviceObject\n”)) ;
return FALSE ;
}
else
{
g_pdevobj_PartitionDeviceObject =
pdevobj_FilterDeviceObject ;
DISK_KDPRINT((“pdevobj_PartitionDeviceObject %p\n”,
pstruct_DeviceExtension->pdevobj_PartitionDeviceObject)) ;
}

pdevobj_FilterDeviceObject->Flags |= DO_DIRECT_IO ;

pstruct_DeviceExtension->pdevobj_TargetPartitionDeviceObject =
IoAttachDeviceToDeviceStack(pdevobj_FilterDeviceObject,

pdeviceobject_DHV1) ;

// default to DO_POWER_PAGABLE
pdevobj_FilterDeviceObject->Flags |= DO_POWER_PAGABLE ;

// Clear the DO_DEVICE_INITIALIZING flag
pdevobj_FilterDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING ;
}


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

To Mark S. Edwards
I want to write a disk driver, this disk driver can protect disk data and partition date.
but if you use volume filter, this can not protect disk’s boot sector.
but if you use disk filter, this IRP’s offset is disk offset, then this disk driver receive IRP, you must change to partititon’s offset, or change to paritition cluster, this way is very trouble.

so i want to wrote is mixing terminology between a disk filter and a volume filter , manage two two types IRP[1: Disk offset’s IRP 2: Partition offset’s IRP] in the same driver.

You need to write two drivers.

You seem to be making a bad assumption that a volume is always a
single entity smaller than a disk. Volumes can span multiple disk extents.

Do disk related functionality in a disk filter and do volume related
functionality in a volume filter. Trying to stick them all together
in to one driver is an inversion of the storage model that will get
you deeper and deeper in to the hole you seem to be digging.

Cleanly separate the functionality and things will go a whole lot smoother.

Mark.

At 08:31 14/07/2008, xxxxx@gmail.com wrote:

To Mark S. Edwards
I want to write a disk driver, this disk driver can protect disk
data and partition date.
but if you use volume filter, this can not protect disk’s boot sector.
but if you use disk filter, this IRP’s offset is disk offset, then
this disk driver receive IRP, you must change to partititon’s
offset, or change to paritition cluster, this way is very trouble.

so i want to wrote is mixing terminology between a disk filter and a
volume filter , manage two two types IRP[1: Disk offset’s IRP 2:
Partition offset’s IRP] in the same driver.

What is your meaning about protecting partition data? What kind of partition
data you want to protect? I have experience about disk encryption
implemented by a disk class filter. We also need to do some volume related
work. But we have separate mini-filter doing this kind of work.

On Mon, Jul 14, 2008 at 3:31 AM, wrote:

> To Mark S. Edwards
> I want to write a disk driver, this disk driver can protect disk data and
> partition date.
> but if you use volume filter, this can not protect disk’s boot sector.
> but if you use disk filter, this IRP’s offset is disk offset, then this
> disk driver receive IRP, you must change to partititon’s offset, or change
> to paritition cluster, this way is very trouble.
>
> so i want to wrote is mixing terminology between a disk filter and a volume
> filter , manage two two types IRP[1: Disk offset’s IRP 2: Partition offset’s
> IRP] in the same driver.
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Thank you for your help, Mr. Mark S. Edwards. Now I truly understand the concept of VOLUME. I have been thinking for days and really consider that it is not suitable to use VOLUME filter.

Thank you for your help, Michael Zhu. The Partition data protection mechanism I mentioned before is similar to the way Deep Freesz works, which is a famous data protection software. I think the principle Deep Freesz applies is DISK filter rather than VOLUME filter.

In my opinion, Deep Freesz has the data backup mechanism by backing up the specific data firstly; for example, if RING3 rewrites the data within section A (rewrites data sectin A in RING3 mode), Deep Freesz will firstly back up the data within the section A and then rewrites the data in the section A.

should we go on discassing those technical problems ?