Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Drivers > returning STATUS_FAILED from AddDevice...doesnt make a difference

Reply
Thread Tools Display Modes

returning STATUS_FAILED from AddDevice...doesnt make a difference

 
 
unclepauly
Guest
Posts: n/a

 
      05-25-2010
hello,

you may or may not have read my other post about needing to enable/disable
usb sticks. one suggestion was to write a filter for the DiskDrive class that
detects usb sticks in the AddDevice function, and when it is usb, change the
device type to something other than storage. can i just say at this point
that disabling usbstor reg key does not always work, hence my need for a
different approach.

i have used the diskperf sample from the WDK, and modified the AddDevice
function as follows:

first i do IoGetDeviceProperty on DevicePropertyHardwareID, and if this is
usb the return value will be "USBSTOR\xxxxxx", so i do a check on this. if it
is usb, i do:

PhysicalDeviceObject->DeviceType = 0;
PhysicalDeviceObject->Characteristics = 0;
PhysicalDeviceObject->Flags = 0;

where PhysicalDeviceObject is the DEVICE_OBJECT passed to AddDevice. then i
just return STATUS_NO_SUCH_DEVICE. i have tried other error codes too, and I
have also tried calling IoCreateDevice, passing in null/wrong values for the
device type and other arguments.

i installed the filter by setting the UpperFilters reg key of the disk drive
class to be diskperf/PartMgr.

with this code, when i insert a usb stick, i can see my filter being hit in
debugview. the usb stick is detected and AddDevice is forced to 'fail'. the
problem is that it does not have any effect ! in windows explorer i can still
see the device and i can still read/write to it. with my code removed,
debugview shows many more functions being hit after AddDevice, such as
SendToNextDriver, StartDevice, RegisterDevice, etc. With my code, nothing
gets called after AddDevice, which is what i would expect, but like i say
this doesnt actually make any difference to anything....

can anyone offer an explaination ?
any help appreciated.
 
Reply With Quote
 
 
 
 
unclepauly
Guest
Posts: n/a

 
      05-25-2010
Doran,

Can you hold my hand just for 2 more minutes please...im sure im almost
there...i think what you are saying is what i tried to do initially, i must
be doing it wrong.

the AddDevice code in the diskperf sample is as such:

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

status = IoCreateDevice(DriverObject, DEVICE_EXTENSION_SIZE, NULL,
FILE_DEVICE_DISK, FILE_DEVICE_SECURE_OPEN, FALSE, &filterDeviceObject);

filterDeviceObject->Flags |= DO_DIRECT_IO;

deviceExtension = (PDEVICE_EXTENSION)
filterDeviceObject->DeviceExtension;
deviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
deviceExtension->TargetDeviceObject =
IoAttachDeviceToDeviceStack(filterDeviceObject, PhysicalDeviceObject);
deviceExtension->DeviceObject = filterDeviceObject;
deviceExtension->PhysicalDeviceName.Buffer =
deviceExtension->PhysicalDeviceNameBuffer;

filterDeviceObject->Flags |= DO_POWER_PAGABLE;
filterDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;

return STATUS_SUCCESS;
}


when you say i should attach the filer device object (FDO) with a unique
type, i changed the code to be:

if(isUsb)
{
status = IoCreateDevice(DriverObject, DEVICE_EXTENSION_SIZE, NULL,
FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &filterDeviceObject);
//just to make sure
filterDeviceObject->DeviceType = FILE_DEVICE_UNKNOWN;
}
else
{
status = IoCreateDevice(DriverObject, DEVICE_EXTENSION_SIZE, NULL,
FILE_DEVICE_DISK, FILE_DEVICE_SECURE_OPEN, FALSE, &filterDeviceObject);
}

so as you can see i created the device using FILE_DEVICE_UNKNOWN instead of
FILE_DEVICE_DISK. i tried tried other values too. this doesnt work though.
what have i misunderstood ?

thanks again for your help, sorry if my knowledge is very poor on this matter.
 
Reply With Quote
 
Doron Holan [MSFT]
Guest
Posts: n/a

 
      05-25-2010
to clarify, failure codes from filter drivers do not fail the start of the
stack because filters are deemed non essential to get the device up and
running.

d

"Don Burn" wrote in message
news:7AFF476955BE485F8CD5DC031F041B75@Destiny...

YOU DO NOT FAIL THE AddDevice. In AddDevice you attach you FDO with a
unique type and return success if it is a USB device, if it is not a usb
device you do not attach a FDO and return success.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr



> -----Original Message-----
> From: unclepauly [private.php?do=newpm&u=]
> Posted At: Tuesday, May 25, 2010 8:15 AM
> Posted To: microsoft.public.development.device.drivers
> Conversation: returning STATUS_FAILED from AddDevice...doesnt make a
> difference
> Subject: returning STATUS_FAILED from AddDevice...doesnt make a
> difference
>
> hello,
>
> you may or may not have read my other post about needing to
> enable/disable usb
> sticks. one suggestion was to write a filter for the DiskDrive class
> that
> detects usb sticks in the AddDevice function, and when it is usb, change
> the
> device type to something other than storage. can i just say at this
> point that
> disabling usbstor reg key does not always work, hence my need for a
> different
> approach.
>
> i have used the diskperf sample from the WDK, and modified the AddDevice
> function as follows:
>
> first i do IoGetDeviceProperty on DevicePropertyHardwareID, and if this
> is usb
> the return value will be "USBSTOR\xxxxxx", so i do a check on this. if
> it is
> usb, i do:
>
> PhysicalDeviceObject->DeviceType = 0;
> PhysicalDeviceObject->Characteristics = 0; Flags = 0;
>
> where PhysicalDeviceObject is the DEVICE_OBJECT passed to AddDevice.
> then i
> just return STATUS_NO_SUCH_DEVICE. i have tried other error codes too,
> and I
> have also tried calling IoCreateDevice, passing in null/wrong values for
> the
> device type and other arguments.
>
> i installed the filter by setting the UpperFilters reg key of the disk
> drive
> class to be diskperf/PartMgr.
>
> with this code, when i insert a usb stick, i can see my filter being hit
> in
> debugview. the usb stick is detected and AddDevice is forced to 'fail'.
> the
> problem is that it does not have any effect ! in windows explorer i can
> still
> see the device and i can still read/write to it. with my code removed,
> debugview shows many more functions being hit after AddDevice, such as
> SendToNextDriver, StartDevice, RegisterDevice, etc. With my code,
> nothing gets
> called after AddDevice, which is what i would expect, but like i say
> this
> doesnt actually make any difference to anything....
>
> can anyone offer an explaination ?
> any help appreciated.
>
>
> __________ Information from ESET Smart Security, version of virus
> signature
> database 5143 (20100525) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>


 
Reply With Quote
 
unclepauly
Guest
Posts: n/a

 
      05-27-2010
i see - so looking at my code above can you tell me where i have gone wrong ?
ie, i detect usb and then create the filterDeviceObject via IoCreateDevice,
by passing in FILE_DEVICE_UNKNOWN instead of FILE_DEVICE_DISK.

thanks for your help.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make Thumbnails for video? ddn85602 Windows Vista Music, Pictures and Video 0 04-16-2010 07:46 AM
Error: Agent failed detecting with reason: 0x80248008 (WSUS client AAM Windows Server 0 12-30-2009 03:26 AM
Re: Spell Corrected: MSFT Connect Officially Rejects Public Access to Bugs/Sam-R Chad Harris Windows Vista Installation 1 09-09-2006 11:21 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59