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

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

: how to get USB busid from minifilter driver

Don_Burn_1Don_Burn_1 Member Posts: 4,311
That should do it, you may get back more than one ID. You will have to
resolve that.


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



From: Dennis Scott [mailto:xxxxx@allaboutif.com]
Posted At: Thursday, March 18, 2010 8:34 AM
Posted To: ntfsd
Conversation: how to get USB busid from minifilter driver
Subject: Re: how to get USB busid from minifilter driver

Thanks Don,

should i use IoGetDeviceProperty with DeviceProperty as
DevicePropertyHardwareID?

is this the correct way to get busid.
On Thu, Mar 18, 2010 at 5:51 PM, Don Burn <xxxxx@acm.org> wrote:
In the InstanceSetupCallback use FltGetDiskDeviceObject to get the
device, then use that to get the bus-id and store it in the context for
the instance.  You do not want to get it for every create, it will stay
the same for a volume.





Don Burn (MVP, Windows DKD)

Windows Filesystem and Driver Consulting

Website: http://www.windrvr.com

Blog: http://msmvps.com/blogs/WinDrvr







From: Dennis Scott [mailto:xxxxx@allaboutif.com]
Posted At: Thursday, March 18, 2010 8:12 AM
Posted To: ntfsd
Conversation: how to get USB busid from minifilter driver
Subject: how to get USB busid from minifilter driver



Hi all,

How can i get the usb drive bus-id in an minifilter driver during
IRP_MJ_CREATE.

Thanks and Regards
dennis scott


__________ Information from ESET Smart Security, version of virus
signature database 4954 (20100318) __________



The message was checked by ESET Smart Security.



http://www.eset.com



---
NTFSD is sponsored by OSR

For our schedule of debugging and file system seminars
(including our new fs mini-filter seminar) 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


__________ Information from ESET Smart Security, version of virus
signature database 4954 (20100318) __________

The message was checked by ESET Smart Security.

http://www.eset.com

Comments

  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    Don,

    this is returning "STORAGE\Volume"

    the code follows

    case FILE_DEVICE_DISK_FILE_SYSTEM: if (NT_SUCCESS(FltGetDiskDeviceObject(FltObjects->Volume, &DiskDeviceObject))) { DbgPrint("FltGetDiskDeviceObject succeded\n"); status = IoGetDeviceProperty(DiskDeviceObject,DevicePropertyHardwareID,sizeof(name), name, &junk); if (NT_SUCCESS(status)) DbgPrint("succeeded for '%ws' device\n", name); else DbgPrint("IoGetDeviceProperty failed - %X\n", status); }

    thanks
    dennis scott

    On Thu, Mar 18, 2010 at 6:19 PM, Don Burn wrote:

    > That should do it, you may get back more than one ID. You will have to
    > resolve that.
    >
    >
    > Don Burn (MVP, Windows DKD)
    > Windows Filesystem and Driver Consulting
    > Website: http://www.windrvr.com
    > Blog: http://msmvps.com/blogs/WinDrvr
    >
    >
    >
    > From: Dennis Scott [mailto:xxxxx@allaboutif.com]
    > Posted At: Thursday, March 18, 2010 8:34 AM
    > Posted To: ntfsd
    > Conversation: how to get USB busid from minifilter driver
    > Subject: Re: how to get USB busid from minifilter driver
    >
    > Thanks Don,
    >
    > should i use IoGetDeviceProperty with DeviceProperty as
    > DevicePropertyHardwareID?
    >
    > is this the correct way to get busid.
    > On Thu, Mar 18, 2010 at 5:51 PM, Don Burn wrote:
    > In the InstanceSetupCallback use FltGetDiskDeviceObject to get the
    > device, then use that to get the bus-id and store it in the context for
    > the instance. You do not want to get it for every create, it will stay
    > the same for a volume.
    >
    >
    >
    >
    >
    > Don Burn (MVP, Windows DKD)
    >
    > Windows Filesystem and Driver Consulting
    >
    > Website: http://www.windrvr.com
    >
    > Blog: http://msmvps.com/blogs/WinDrvr
    >
    >
    >
    >
    >
    >
    >
    > From: Dennis Scott [mailto:xxxxx@allaboutif.com]
    > Posted At: Thursday, March 18, 2010 8:12 AM
    > Posted To: ntfsd
    > Conversation: how to get USB busid from minifilter driver
    > Subject: how to get USB busid from minifilter driver
    >
    >
    >
    > Hi all,
    >
    > How can i get the usb drive bus-id in an minifilter driver during
    > IRP_MJ_CREATE.
    >
    > Thanks and Regards
    > dennis scott
    >
    >
    > __________ Information from ESET Smart Security, version of virus
    > signature database 4954 (20100318) __________
    >
    >
    >
    > The message was checked by ESET Smart Security.
    >
    >
    >
    > http://www.eset.com
    >
    >
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
    >
    > __________ Information from ESET Smart Security, version of virus
    > signature database 4954 (20100318) __________
    >
    > The message was checked by ESET Smart Security.
    >
    > http://www.eset.com
    >
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,135
    Is this XP or Vista? Prior to Vista you used to be able to do this for disks
    that reported themselves as removable since the volume manager didn't get in
    the way of those. For disks that don't report themselves as removable or on
    Vista and later you're going to have to work harder to map the volume to the
    disk. The issue that you have is that in this case disks and storage volumes
    exist in different branches of the device tree, so you need some way to
    bridge the two starting at the volume.

    I haven't actually tried to do exactly this yet. If you can get away with it
    in user mode then you might be better off or maybe there's a new API that's
    been added to help with this and someone else can chime in. If not, a
    starting point might be IoGetDeviceInterfaces and IOCTL_SCSI_GET_ADDRESS,
    you'd be looking for the same address to come back from the disk path as you
    would the volume. I've used this trick in the past from user mode to do
    something similar. It's a bit overkill, but a starting point to get the
    creative juices flowing in case no one has a better idea...

    Good luck,

    -scott

    --
    Scott Noone
    Consulting Associate
    OSR Open Systems Resources, Inc.
    http://www.osronline.com


    "Dennis Scott" <xxxxx@allaboutif.com> wrote in message
    news:xxxxx@ntfsd...
    Don,

    this is returning "STORAGE\Volume"

    the code follows

    <code>

    case FILE_DEVICE_DISK_FILE_SYSTEM:

    if (NT_SUCCESS(FltGetDiskDeviceObject(FltObjects->Volume,
    &DiskDeviceObject)))
    {

    DbgPrint("FltGetDiskDeviceObject succeded\n");

    status =
    IoGetDeviceProperty(DiskDeviceObject,DevicePropertyHardwareID,sizeof(name),
    name, &junk);

    if (NT_SUCCESS(status))
    DbgPrint("succeeded for '%ws' device\n", name);
    else
    DbgPrint("IoGetDeviceProperty failed - %X\n", status);
    }

    </code>

    thanks
    dennis scott


    On Thu, Mar 18, 2010 at 6:19 PM, Don Burn <xxxxx@acm.org> wrote:

    That should do it, you may get back more than one ID. You will have to
    resolve that.


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



    From: Dennis Scott [mailto:xxxxx@allaboutif.com]
    Posted At: Thursday, March 18, 2010 8:34 AM
    Posted To: ntfsd
    Conversation: how to get USB busid from minifilter driver
    Subject: Re: how to get USB busid from minifilter driver

    Thanks Don,

    should i use IoGetDeviceProperty with DeviceProperty as
    DevicePropertyHardwareID?

    is this the correct way to get busid.
    On Thu, Mar 18, 2010 at 5:51 PM, Don Burn <xxxxx@acm.org> wrote:
    In the InstanceSetupCallback use FltGetDiskDeviceObject to get the
    device, then use that to get the bus-id and store it in the context for
    the instance. You do not want to get it for every create, it will stay
    the same for a volume.





    Don Burn (MVP, Windows DKD)

    Windows Filesystem and Driver Consulting

    Website: http://www.windrvr.com

    Blog: http://msmvps.com/blogs/WinDrvr







    From: Dennis Scott [mailto:xxxxx@allaboutif.com]
    Posted At: Thursday, March 18, 2010 8:12 AM
    Posted To: ntfsd
    Conversation: how to get USB busid from minifilter driver
    Subject: how to get USB busid from minifilter driver



    Hi all,

    How can i get the usb drive bus-id in an minifilter driver during
    IRP_MJ_CREATE.

    Thanks and Regards
    dennis scott


    __________ Information from ESET Smart Security, version of virus
    signature database 4954 (20100318) __________



    The message was checked by ESET Smart Security.



    http://www.eset.com



    ---
    NTFSD is sponsored by OSR

    For our schedule of debugging and file system seminars
    (including our new fs mini-filter seminar) 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


    __________ Information from ESET Smart Security, version of virus
    signature database 4954 (20100318) __________

    The message was checked by ESET Smart Security.

    http://www.eset.com


    ---
    NTFSD is sponsored by OSR

    For our schedule of debugging and file system seminars
    (including our new fs mini-filter seminar) 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

    -scott
    OSR

  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    > starting point might be IoGetDeviceInterfaces and IOCTL_SCSI_GET_ADDRESS,

    IOCTL_STORAGE_GET_DEVICE_NUMBER also helps.

    --
    Maxim S. Shatskih
    Windows DDK MVP
    xxxxx@storagecraft.com
    http://www.storagecraft.com
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    Hello scott,

    Thanks,

    This has to be done in both Xp, and Vista, the code returned
    "STORAGE\Volume" in Xp and i have to test in vista,

    Maxim,

    I ll test with IoGetDeviceInterfaces with IOCTL_SCSI_GET_ADDRESS or
    IOCTL_STORAGE_GET_DEVICE_
    NUMBER and let you know.


    On Fri, Mar 19, 2010 at 5:27 AM, Maxim S. Shatskih
    wrote:

    > > starting point might be IoGetDeviceInterfaces and IOCTL_SCSI_GET_ADDRESS,
    >
    > IOCTL_STORAGE_GET_DEVICE_NUMBER also helps.
    >
    > --
    > Maxim S. Shatskih
    > Windows DDK MVP
    > xxxxx@storagecraft.com
    > http://www.storagecraft.com
    >
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    Guys,

    IOCTL_SCSI_GET_ADDRESS discription says "This request is not relevant to
    storage class drivers that support Plug and Play because the port driver
    supplies the address information on behalf of the class driver" Then how can
    i use this to get USB busid?

    On Fri, Mar 19, 2010 at 9:06 AM, Dennis Scott
    wrote:

    > Hello scott,
    >
    > Thanks,
    >
    > This has to be done in both Xp, and Vista, the code returned
    > "STORAGE\Volume" in Xp and i have to test in vista,
    >
    > Maxim,
    >
    > I ll test with IoGetDeviceInterfaces with IOCTL_SCSI_GET_ADDRESS or
    > IOCTL_STORAGE_GET_DEVICE_
    > NUMBER and let you know.
    >
    >
    > On Fri, Mar 19, 2010 at 5:27 AM, Maxim S. Shatskih > wrote:
    >
    >> > starting point might be IoGetDeviceInterfaces and
    >> IOCTL_SCSI_GET_ADDRESS,
    >>
    >> IOCTL_STORAGE_GET_DEVICE_NUMBER also helps.
    >>
    >> --
    >> Maxim S. Shatskih
    >> Windows DDK MVP
    >> xxxxx@storagecraft.com
    >> http://www.storagecraft.com
    >>
    >>
    >> ---
    >> NTFSD is sponsored by OSR
    >>
    >> For our schedule of debugging and file system seminars
    >> (including our new fs mini-filter seminar) 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
    >>
    >
    >
  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,135
    That note is for implementers of storage class drivers, so it's not really
    relevant.

    >Then how can i use this to get USB busid?

    You have to figure out which disk maps to the volume that you have. One way
    to do this is to send a request to the volume that the volume will pass
    through to the disk and save the results. Then grab all of the disk devices
    in the system and send the same request to each disk until you get a match.
    Then you have a device object in the disk stack that you can get the
    hardware ID from.

    There's also IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS which will give you the
    disk number (forgot about this one yesterday). You can then open
    \Global??\PhysicalDriveN (I think, you need to verify) and do the same sort
    of thing.

    -scott

    --
    Scott Noone
    Consulting Associate
    OSR Open Systems Resources, Inc.
    http://www.osronline.com



    "Dennis Scott" <xxxxx@allaboutif.com> wrote in message
    news:xxxxx@ntfsd...
    Guys,

    IOCTL_SCSI_GET_ADDRESS discription says "This request is not relevant to
    storage class drivers that support Plug and Play because the port driver
    supplies the address information on behalf of the class driver" Then how can
    i use this to get USB busid?


    On Fri, Mar 19, 2010 at 9:06 AM, Dennis Scott <xxxxx@allaboutif.com>
    wrote:

    Hello scott,

    Thanks,

    This has to be done in both Xp, and Vista, the code returned
    "STORAGE\Volume" in Xp and i have to test in vista,

    Maxim,

    I ll test with IoGetDeviceInterfaces with IOCTL_SCSI_GET_ADDRESS or
    IOCTL_STORAGE_GET_DEVICE_
    NUMBER and let you know.




    On Fri, Mar 19, 2010 at 5:27 AM, Maxim S. Shatskih <xxxxx@storagecraft.com>
    wrote:

    > starting point might be IoGetDeviceInterfaces and IOCTL_SCSI_GET_ADDRESS,


    IOCTL_STORAGE_GET_DEVICE_NUMBER also helps.

    --
    Maxim S. Shatskih
    Windows DDK MVP
    xxxxx@storagecraft.com
    http://www.storagecraft.com



    ---
    NTFSD is sponsored by OSR

    For our schedule of debugging and file system seminars
    (including our new fs mini-filter seminar) 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

    -scott
    OSR

  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    Thanks Scott,

    I ll try this one.

    On Fri, Mar 19, 2010 at 6:05 PM, Scott Noone wrote:

    > That note is for implementers of storage class drivers, so it's not really
    > relevant.
    >
    >
    > Then how can i use this to get USB busid?
    >>
    >
    > You have to figure out which disk maps to the volume that you have. One way
    > to do this is to send a request to the volume that the volume will pass
    > through to the disk and save the results. Then grab all of the disk devices
    > in the system and send the same request to each disk until you get a match.
    > Then you have a device object in the disk stack that you can get the
    > hardware ID from.
    >
    > There's also IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS which will give you the
    > disk number (forgot about this one yesterday). You can then open
    > \Global??\PhysicalDriveN (I think, you need to verify) and do the same sort
    > of thing.
    >
    >
    > -scott
    >
    > --
    > Scott Noone
    > Consulting Associate
    > OSR Open Systems Resources, Inc.
    > http://www.osronline.com
    >
    >
    >
    > "Dennis Scott" wrote in message
    > news:xxxxx@ntfsd...
    >
    > Guys,
    >
    > IOCTL_SCSI_GET_ADDRESS discription says "This request is not relevant to
    > storage class drivers that support Plug and Play because the port driver
    > supplies the address information on behalf of the class driver" Then how can
    > i use this to get USB busid?
    >
    >
    > On Fri, Mar 19, 2010 at 9:06 AM, Dennis Scott
    > wrote:
    >
    > Hello scott,
    >
    > Thanks,
    >
    > This has to be done in both Xp, and Vista, the code returned
    > "STORAGE\Volume" in Xp and i have to test in vista,
    >
    > Maxim,
    >
    > I ll test with IoGetDeviceInterfaces with IOCTL_SCSI_GET_ADDRESS or
    > IOCTL_STORAGE_GET_DEVICE_
    > NUMBER and let you know.
    >
    >
    >
    >
    > On Fri, Mar 19, 2010 at 5:27 AM, Maxim S. Shatskih
    > wrote:
    >
    > starting point might be IoGetDeviceInterfaces and IOCTL_SCSI_GET_ADDRESS,
    >>
    >
    >
    > IOCTL_STORAGE_GET_DEVICE_NUMBER also helps.
    >
    > --
    > Maxim S. Shatskih
    > Windows DDK MVP
    > xxxxx@storagecraft.com
    > http://www.storagecraft.com
    >
    >
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    scott,

    I am not able to get the busid with the steps you mentioned in previous
    mail,

    can you just confirm me with these queries.

    "send a request to the volume that the volume will pass through to the disk
    and save the results"
    which request you are mentioning here? IOCTL_SCSI_GET_ADDRESS? this ioclt
    returns not supported.

    "Then grab all of the disk devices in the system and send the same request
    to each disk until you get a match"
    Done, No problems, but some disks says IOCTL_SCSI_GET_ADDRESS not supported.

    and hence i am not able to get PDO.

    On Fri, Mar 19, 2010 at 6:12 PM, Dennis Scott
    wrote:

    > Thanks Scott,
    >
    > I ll try this one.
    >
    >
    > On Fri, Mar 19, 2010 at 6:05 PM, Scott Noone wrote:
    >
    >> That note is for implementers of storage class drivers, so it's not really
    >> relevant.
    >>
    >>
    >> Then how can i use this to get USB busid?
    >>>
    >>
    >> You have to figure out which disk maps to the volume that you have. One
    >> way to do this is to send a request to the volume that the volume will pass
    >> through to the disk and save the results. Then grab all of the disk devices
    >> in the system and send the same request to each disk until you get a match.
    >> Then you have a device object in the disk stack that you can get the
    >> hardware ID from.
    >>
    >> There's also IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS which will give you the
    >> disk number (forgot about this one yesterday). You can then open
    >> \Global??\PhysicalDriveN (I think, you need to verify) and do the same sort
    >> of thing.
    >>
    >>
    >> -scott
    >>
    >> --
    >> Scott Noone
    >> Consulting Associate
    >> OSR Open Systems Resources, Inc.
    >> http://www.osronline.com
    >>
    >>
    >>
    >> "Dennis Scott" wrote in message
    >> news:xxxxx@ntfsd...
    >>
    >> Guys,
    >>
    >> IOCTL_SCSI_GET_ADDRESS discription says "This request is not relevant to
    >> storage class drivers that support Plug and Play because the port driver
    >> supplies the address information on behalf of the class driver" Then how can
    >> i use this to get USB busid?
    >>
    >>
    >> On Fri, Mar 19, 2010 at 9:06 AM, Dennis Scott <
    >> xxxxx@allaboutif.com> wrote:
    >>
    >> Hello scott,
    >>
    >> Thanks,
    >>
    >> This has to be done in both Xp, and Vista, the code returned
    >> "STORAGE\Volume" in Xp and i have to test in vista,
    >>
    >> Maxim,
    >>
    >> I ll test with IoGetDeviceInterfaces with IOCTL_SCSI_GET_ADDRESS or
    >> IOCTL_STORAGE_GET_DEVICE_
    >> NUMBER and let you know.
    >>
    >>
    >>
    >>
    >> On Fri, Mar 19, 2010 at 5:27 AM, Maxim S. Shatskih <
    >> xxxxx@storagecraft.com> wrote:
    >>
    >> starting point might be IoGetDeviceInterfaces and IOCTL_SCSI_GET_ADDRESS,
    >>>
    >>
    >>
    >> IOCTL_STORAGE_GET_DEVICE_NUMBER also helps.
    >>
    >> --
    >> Maxim S. Shatskih
    >> Windows DDK MVP
    >> xxxxx@storagecraft.com
    >> http://www.storagecraft.com
    >>
    >>
    >>
    >> ---
    >> NTFSD is sponsored by OSR
    >>
    >> For our schedule of debugging and file system seminars
    >> (including our new fs mini-filter seminar) 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
    >>
    >> ---
    >> NTFSD is sponsored by OSR
    >>
    >> For our schedule of debugging and file system seminars
    >> (including our new fs mini-filter seminar) 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
    >>
    >
    >
  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,135
    Well look at that, USBSTOR doesn't support this request. That's a real pain,
    I guess we've only ever needed to do this for fixed disks. Sorry about that.

    I believe that the other method should still work, in that case you don't
    need IOCTL_SCSI_GET_ADDRESS since the IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
    request uniquely identifies the underlying disk (I'm making an assumption
    here that no one would somehow stripe a set of USB disks, though you could
    handle that). Just build the \Global??\PhysicalDriveN name then use
    IoGetDeviceObjectPointer and IoGetDeviceAttachmentBaseRef to get the USBSTOR
    enumerated PDO. From there IoGetDeviceProperty should give you some
    identifying information that you can use to determine it's a USB disk (e.g.
    "USBSTOR" as the enumerator).

    -scott

    --
    Scott Noone
    Consulting Associate
    OSR Open Systems Resources, Inc.
    http://www.osronline.com


    "Dennis Scott" <xxxxx@allaboutif.com> wrote in message
    news:xxxxx@ntfsd...
    scott,

    I am not able to get the busid with the steps you mentioned in previous
    mail,

    can you just confirm me with these queries.

    "send a request to the volume that the volume will pass through to the disk
    and save the results"
    which request you are mentioning here? IOCTL_SCSI_GET_ADDRESS? this ioclt
    returns not supported.

    "Then grab all of the disk devices in the system and send the same request
    to each disk until you get a match"
    Done, No problems, but some disks says IOCTL_SCSI_GET_ADDRESS not supported.

    and hence i am not able to get PDO.


    On Fri, Mar 19, 2010 at 6:12 PM, Dennis Scott <xxxxx@allaboutif.com>
    wrote:

    Thanks Scott,

    I ll try this one.



    On Fri, Mar 19, 2010 at 6:05 PM, Scott Noone <xxxxx@osr.com> wrote:

    That note is for implementers of storage class drivers, so it's not really
    relevant.



    Then how can i use this to get USB busid?



    You have to figure out which disk maps to the volume that you have. One way
    to do this is to send a request to the volume that the volume will pass
    through to the disk and save the results. Then grab all of the disk devices
    in the system and send the same request to each disk until you get a match.
    Then you have a device object in the disk stack that you can get the
    hardware ID from.

    There's also IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS which will give you the
    disk number (forgot about this one yesterday). You can then open
    \Global??\PhysicalDriveN (I think, you need to verify) and do the same sort
    of thing.


    -scott

    --
    Scott Noone
    Consulting Associate
    OSR Open Systems Resources, Inc.
    http://www.osronline.com




    "Dennis Scott" <xxxxx@allaboutif.com> wrote in message
    news:xxxxx@ntfsd...

    Guys,

    IOCTL_SCSI_GET_ADDRESS discription says "This request is not relevant to
    storage class drivers that support Plug and Play because the port driver
    supplies the address information on behalf of the class driver" Then how can
    i use this to get USB busid?


    On Fri, Mar 19, 2010 at 9:06 AM, Dennis Scott <xxxxx@allaboutif.com>
    wrote:


    Hello scott,

    Thanks,

    This has to be done in both Xp, and Vista, the code returned
    "STORAGE\Volume" in Xp and i have to test in vista,

    Maxim,

    I ll test with IoGetDeviceInterfaces with IOCTL_SCSI_GET_ADDRESS or
    IOCTL_STORAGE_GET_DEVICE_
    NUMBER and let you know.




    On Fri, Mar 19, 2010 at 5:27 AM, Maxim S. Shatskih <xxxxx@storagecraft.com>
    wrote:


    starting point might be IoGetDeviceInterfaces and IOCTL_SCSI_GET_ADDRESS,



    IOCTL_STORAGE_GET_DEVICE_NUMBER also helps.

    --
    Maxim S. Shatskih
    Windows DDK MVP
    xxxxx@storagecraft.com
    http://www.storagecraft.com



    ---
    NTFSD is sponsored by OSR

    For our schedule of debugging and file system seminars
    (including our new fs mini-filter seminar) 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

    ---
    NTFSD is sponsored by OSR

    For our schedule of debugging and file system seminars
    (including our new fs mini-filter seminar) 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

    -scott
    OSR

  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    Scott,

    Thanks a lot i Finally got the USBSTOR Device Object from that method, And
    now i can get Hardware Id (USBSTOR\DiskJetFlashTranscend_2GB___8.07 etc.),
    and other info from IoGetDeviceProperty,

    Is their any way to get actual location of the device on bus? i tried
    *DevicePropertyLocationInformation
    *but it is failing with STATUS_OBJECT_NAME_NOT_FOUND.

    On Wed, Mar 24, 2010 at 12:48 AM, Scott Noone wrote:

    > Well look at that, USBSTOR doesn't support this request. That's a real
    > pain, I guess we've only ever needed to do this for fixed disks. Sorry about
    > that.
    >
    > I believe that the other method should still work, in that case you don't
    > need IOCTL_SCSI_GET_ADDRESS since the IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
    > request uniquely identifies the underlying disk (I'm making an assumption
    > here that no one would somehow stripe a set of USB disks, though you could
    > handle that). Just build the \Global??\PhysicalDriveN name then use
    > IoGetDeviceObjectPointer and IoGetDeviceAttachmentBaseRef to get the USBSTOR
    > enumerated PDO. From there IoGetDeviceProperty should give you some
    > identifying information that you can use to determine it's a USB disk (e.g.
    > "USBSTOR" as the enumerator).
    >
    >
    > -scott
    >
    > --
    > Scott Noone
    > Consulting Associate
    > OSR Open Systems Resources, Inc.
    > http://www.osronline.com
    >
    >
    > "Dennis Scott" wrote in message
    > news:xxxxx@ntfsd...
    >
    > scott,
    >
    > I am not able to get the busid with the steps you mentioned in previous
    > mail,
    >
    > can you just confirm me with these queries.
    >
    > "send a request to the volume that the volume will pass through to the disk
    > and save the results"
    > which request you are mentioning here? IOCTL_SCSI_GET_ADDRESS? this ioclt
    > returns not supported.
    >
    > "Then grab all of the disk devices in the system and send the same request
    > to each disk until you get a match"
    > Done, No problems, but some disks says IOCTL_SCSI_GET_ADDRESS not
    > supported.
    >
    > and hence i am not able to get PDO.
    >
    >
    > On Fri, Mar 19, 2010 at 6:12 PM, Dennis Scott
    > wrote:
    >
    > Thanks Scott,
    >
    > I ll try this one.
    >
    >
    >
    > On Fri, Mar 19, 2010 at 6:05 PM, Scott Noone wrote:
    >
    > That note is for implementers of storage class drivers, so it's not really
    > relevant.
    >
    >
    >
    > Then how can i use this to get USB busid?
    >
    >
    >
    > You have to figure out which disk maps to the volume that you have. One way
    > to do this is to send a request to the volume that the volume will pass
    > through to the disk and save the results. Then grab all of the disk devices
    > in the system and send the same request to each disk until you get a match.
    > Then you have a device object in the disk stack that you can get the
    > hardware ID from.
    >
    > There's also IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS which will give you the
    > disk number (forgot about this one yesterday). You can then open
    > \Global??\PhysicalDriveN (I think, you need to verify) and do the same sort
    > of thing.
    >
    >
    > -scott
    >
    > --
    > Scott Noone
    > Consulting Associate
    > OSR Open Systems Resources, Inc.
    > http://www.osronline.com
    >
    >
    >
    >
    > "Dennis Scott" wrote in message
    > news:xxxxx@ntfsd...
    >
    > Guys,
    >
    > IOCTL_SCSI_GET_ADDRESS discription says "This request is not relevant to
    > storage class drivers that support Plug and Play because the port driver
    > supplies the address information on behalf of the class driver" Then how can
    > i use this to get USB busid?
    >
    >
    > On Fri, Mar 19, 2010 at 9:06 AM, Dennis Scott
    > wrote:
    >
    >
    > Hello scott,
    >
    > Thanks,
    >
    > This has to be done in both Xp, and Vista, the code returned
    > "STORAGE\Volume" in Xp and i have to test in vista,
    >
    > Maxim,
    >
    > I ll test with IoGetDeviceInterfaces with IOCTL_SCSI_GET_ADDRESS or
    > IOCTL_STORAGE_GET_DEVICE_
    > NUMBER and let you know.
    >
    >
    >
    >
    > On Fri, Mar 19, 2010 at 5:27 AM, Maxim S. Shatskih
    > wrote:
    >
    >
    > starting point might be IoGetDeviceInterfaces and IOCTL_SCSI_GET_ADDRESS,
    >
    >
    >
    > IOCTL_STORAGE_GET_DEVICE_NUMBER also helps.
    >
    > --
    > Maxim S. Shatskih
    > Windows DDK MVP
    > xxxxx@storagecraft.com
    > http://www.storagecraft.com
    >
    >
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,135
    >Is their any way to get actual location of the device on bus?

    Like, which port it's plugged in to? It's generally not very useful, but
    ignoring that...Not really, you can't get that information from this PDO.
    For that, you need the USB hub's PDO or the USBSTOR FDO so that you can send
    some USB specific IOCTL to it.

    You should play with DeviceTree a bit so that you can visualize what pieces
    you're talking to, that should give you an idea about the boundaries that
    you're running in to. I'd also really recommend trying to do this work in
    user mode and sending the results back to the driver, if you look at the
    USBView sample in the WDK you can see how much easier it is to get this sort
    of information using the UM APIs.

    -scott

    --
    Scott Noone
    Consulting Associate
    OSR Open Systems Resources, Inc.
    http://www.osronline.com


    "Dennis Scott" <xxxxx@allaboutif.com> wrote in message
    news:xxxxx@ntfsd...
    Scott,

    Thanks a lot i Finally got the USBSTOR Device Object from that method, And
    now i can get Hardware Id (USBSTOR\DiskJetFlashTranscend_2GB___8.07 etc.),
    and other info from IoGetDeviceProperty,

    Is their any way to get actual location of the device on bus? i tried
    DevicePropertyLocationInformation but it is failing with
    STATUS_OBJECT_NAME_NOT_FOUND.


    On Wed, Mar 24, 2010 at 12:48 AM, Scott Noone <xxxxx@osr.com> wrote:

    Well look at that, USBSTOR doesn't support this request. That's a real pain,
    I guess we've only ever needed to do this for fixed disks. Sorry about that.

    I believe that the other method should still work, in that case you don't
    need IOCTL_SCSI_GET_ADDRESS since the IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
    request uniquely identifies the underlying disk (I'm making an assumption
    here that no one would somehow stripe a set of USB disks, though you could
    handle that). Just build the \Global??\PhysicalDriveN name then use
    IoGetDeviceObjectPointer and IoGetDeviceAttachmentBaseRef to get the USBSTOR
    enumerated PDO. From there IoGetDeviceProperty should give you some
    identifying information that you can use to determine it's a USB disk (e.g.
    "USBSTOR" as the enumerator).


    -scott

    --
    Scott Noone
    Consulting Associate
    OSR Open Systems Resources, Inc.
    http://www.osronline.com



    "Dennis Scott" <xxxxx@allaboutif.com> wrote in message
    news:xxxxx@ntfsd...

    scott,

    I am not able to get the busid with the steps you mentioned in previous
    mail,

    can you just confirm me with these queries.


    "send a request to the volume that the volume will pass through to the disk
    and save the results"

    which request you are mentioning here? IOCTL_SCSI_GET_ADDRESS? this ioclt
    returns not supported.


    "Then grab all of the disk devices in the system and send the same request
    to each disk until you get a match"

    Done, No problems, but some disks says IOCTL_SCSI_GET_ADDRESS not supported.

    and hence i am not able to get PDO.



    On Fri, Mar 19, 2010 at 6:12 PM, Dennis Scott <xxxxx@allaboutif.com>
    wrote:

    Thanks Scott,

    I ll try this one.



    On Fri, Mar 19, 2010 at 6:05 PM, Scott Noone <xxxxx@osr.com> wrote:

    That note is for implementers of storage class drivers, so it's not really
    relevant.



    Then how can i use this to get USB busid?



    You have to figure out which disk maps to the volume that you have. One way
    to do this is to send a request to the volume that the volume will pass
    through to the disk and save the results. Then grab all of the disk devices
    in the system and send the same request to each disk until you get a match.
    Then you have a device object in the disk stack that you can get the
    hardware ID from.

    There's also IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS which will give you the
    disk number (forgot about this one yesterday). You can then open
    \Global??\PhysicalDriveN (I think, you need to verify) and do the same sort
    of thing.


    -scott

    --
    Scott Noone
    Consulting Associate
    OSR Open Systems Resources, Inc.
    http://www.osronline.com




    "Dennis Scott" <xxxxx@allaboutif.com> wrote in message
    news:xxxxx@ntfsd...

    Guys,

    IOCTL_SCSI_GET_ADDRESS discription says "This request is not relevant to
    storage class drivers that support Plug and Play because the port driver
    supplies the address information on behalf of the class driver" Then how can
    i use this to get USB busid?


    On Fri, Mar 19, 2010 at 9:06 AM, Dennis Scott <xxxxx@allaboutif.com>
    wrote:


    Hello scott,

    Thanks,

    This has to be done in both Xp, and Vista, the code returned
    "STORAGE\Volume" in Xp and i have to test in vista,

    Maxim,

    I ll test with IoGetDeviceInterfaces with IOCTL_SCSI_GET_ADDRESS or
    IOCTL_STORAGE_GET_DEVICE_
    NUMBER and let you know.




    On Fri, Mar 19, 2010 at 5:27 AM, Maxim S. Shatskih <xxxxx@storagecraft.com>
    wrote:


    starting point might be IoGetDeviceInterfaces and IOCTL_SCSI_GET_ADDRESS,



    IOCTL_STORAGE_GET_DEVICE_NUMBER also helps.

    --
    Maxim S. Shatskih
    Windows DDK MVP
    xxxxx@storagecraft.com
    http://www.storagecraft.com



    ---
    NTFSD is sponsored by OSR

    For our schedule of debugging and file system seminars
    (including our new fs mini-filter seminar) 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

    ---
    NTFSD is sponsored by OSR

    For our schedule of debugging and file system seminars
    (including our new fs mini-filter seminar) 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

    ---
    NTFSD is sponsored by OSR

    For our schedule of debugging and file system seminars
    (including our new fs mini-filter seminar) 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

    -scott
    OSR

  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    >
    > Like, which port it's plugged in to?


    Yes,

    Thanks for your help,

    I am using Device tree for comparing the PDO and device address i am getting
    in my driver, yes it is very use full, example my USBSTOR device object is
    0X829DDA80 and is same as PDO address i got from
    IoGetDeviceAttachmentBaseRef.




    > It's generally not very useful, but ignoring that...Not really, you can't
    > get that information from this PDO. For that, you need the USB hub's PDO or
    > the USBSTOR FDO so that you can send some USB specific IOCTL to it.
    >
    > You should play with DeviceTree a bit so that you can visualize what pieces
    > you're talking to, that should give you an idea about the boundaries that
    > you're running in to. I'd also really recommend trying to do this work in
    > user mode and sending the results back to the driver, if you look at the
    > USBView sample in the WDK you can see how much easier it is to get this sort
    > of information using the UM APIs.
    >
    >
    > -scott
    >
    > --
    > Scott Noone
    > Consulting Associate
    > OSR Open Systems Resources, Inc.
    > http://www.osronline.com
    >
    >
    > "Dennis Scott" wrote in message
    > news:xxxxx@ntfsd...
    >
    > Scott,
    >
    > Thanks a lot i Finally got the USBSTOR Device Object from that method, And
    > now i can get Hardware Id (USBSTOR\DiskJetFlashTranscend_2GB___8.07 etc.),
    > and other info from IoGetDeviceProperty,
    >
    > Is their any way to get actual location of the device on bus? i tried
    > DevicePropertyLocationInformation but it is failing with
    > STATUS_OBJECT_NAME_NOT_FOUND.
    >
    >
    > On Wed, Mar 24, 2010 at 12:48 AM, Scott Noone wrote:
    >
    > Well look at that, USBSTOR doesn't support this request. That's a real
    > pain, I guess we've only ever needed to do this for fixed disks. Sorry about
    > that.
    >
    > I believe that the other method should still work, in that case you don't
    > need IOCTL_SCSI_GET_ADDRESS since the IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
    > request uniquely identifies the underlying disk (I'm making an assumption
    > here that no one would somehow stripe a set of USB disks, though you could
    > handle that). Just build the \Global??\PhysicalDriveN name then use
    > IoGetDeviceObjectPointer and IoGetDeviceAttachmentBaseRef to get the USBSTOR
    > enumerated PDO. From there IoGetDeviceProperty should give you some
    > identifying information that you can use to determine it's a USB disk (e.g.
    > "USBSTOR" as the enumerator).
    >
    >
    > -scott
    >
    > --
    > Scott Noone
    > Consulting Associate
    > OSR Open Systems Resources, Inc.
    > http://www.osronline.com
    >
    >
    >
    > "Dennis Scott" wrote in message
    > news:xxxxx@ntfsd...
    >
    > scott,
    >
    > I am not able to get the busid with the steps you mentioned in previous
    > mail,
    >
    > can you just confirm me with these queries.
    >
    >
    > "send a request to the volume that the volume will pass through to the disk
    > and save the results"
    >
    > which request you are mentioning here? IOCTL_SCSI_GET_ADDRESS? this ioclt
    > returns not supported.
    >
    >
    > "Then grab all of the disk devices in the system and send the same request
    > to each disk until you get a match"
    >
    > Done, No problems, but some disks says IOCTL_SCSI_GET_ADDRESS not
    > supported.
    >
    > and hence i am not able to get PDO.
    >
    >
    >
    > On Fri, Mar 19, 2010 at 6:12 PM, Dennis Scott
    > wrote:
    >
    > Thanks Scott,
    >
    > I ll try this one.
    >
    >
    >
    > On Fri, Mar 19, 2010 at 6:05 PM, Scott Noone wrote:
    >
    > That note is for implementers of storage class drivers, so it's not really
    > relevant.
    >
    >
    >
    > Then how can i use this to get USB busid?
    >
    >
    >
    > You have to figure out which disk maps to the volume that you have. One way
    > to do this is to send a request to the volume that the volume will pass
    > through to the disk and save the results. Then grab all of the disk devices
    > in the system and send the same request to each disk until you get a match.
    > Then you have a device object in the disk stack that you can get the
    > hardware ID from.
    >
    > There's also IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS which will give you the
    > disk number (forgot about this one yesterday). You can then open
    > \Global??\PhysicalDriveN (I think, you need to verify) and do the same sort
    > of thing.
    >
    >
    > -scott
    >
    > --
    > Scott Noone
    > Consulting Associate
    > OSR Open Systems Resources, Inc.
    > http://www.osronline.com
    >
    >
    >
    >
    > "Dennis Scott" wrote in message
    > news:xxxxx@ntfsd...
    >
    > Guys,
    >
    > IOCTL_SCSI_GET_ADDRESS discription says "This request is not relevant to
    > storage class drivers that support Plug and Play because the port driver
    > supplies the address information on behalf of the class driver" Then how can
    > i use this to get USB busid?
    >
    >
    > On Fri, Mar 19, 2010 at 9:06 AM, Dennis Scott
    > wrote:
    >
    >
    > Hello scott,
    >
    > Thanks,
    >
    > This has to be done in both Xp, and Vista, the code returned
    > "STORAGE\Volume" in Xp and i have to test in vista,
    >
    > Maxim,
    >
    > I ll test with IoGetDeviceInterfaces with IOCTL_SCSI_GET_ADDRESS or
    > IOCTL_STORAGE_GET_DEVICE_
    > NUMBER and let you know.
    >
    >
    >
    >
    > On Fri, Mar 19, 2010 at 5:27 AM, Maxim S. Shatskih
    > wrote:
    >
    >
    > starting point might be IoGetDeviceInterfaces and IOCTL_SCSI_GET_ADDRESS,
    >
    >
    >
    > IOCTL_STORAGE_GET_DEVICE_NUMBER also helps.
    >
    > --
    > Maxim S. Shatskih
    > Windows DDK MVP
    > xxxxx@storagecraft.com
    > http://www.storagecraft.com
    >
    >
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    How you got the USBSTOR device object.
    I tried FltGetVolumeName then IoGetDeviceObjectPointer,IoGetDeviceAttachmentBaseRef.
    IoGetDeviceAttachmentBaseRef give me a pointer to fastfat back.
    What have i made wrong?
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    send IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS for device object obtained from
    FltGetDiskDeviceObject,

    once you get the volume extent *N* append this number to "*
    \\GLOBAL??\\PhysicalDrive*"

    Create unicode string and call IoGetDeviceObjectPointer,

    once you get the deviceobject then call IoGetDeviceAttachmentBaseRef

    this will return you USBSTOR device object, now on this you can call
    IoGetDeviceProperty.

    On Wed, Mar 31, 2010 at 12:44 AM, wrote:

    > How you got the USBSTOR device object.
    > I tried FltGetVolumeName then
    > IoGetDeviceObjectPointer,IoGetDeviceAttachmentBaseRef.
    > IoGetDeviceAttachmentBaseRef give me a pointer to fastfat back.
    > What have i made wrong?
    >
    >
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    Thanks for the fast reply.
    Now i have a simple question how will i get the unicodestring?
    I tried it so, but it's not right.
    UNICODE_STRING devicename;
    devicename.Buffer = "\Global??\PhysicalDrive" + volumeextents->Extents->DiskNumber;
    Please help me!
    Best Regards
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    This works for me.

    UNICODE_STRING devicename;
    wchar_t globalpath[30];
    .
    .
    .
    .
    .
    wcscpy(globalpath,L"\\GLOBAL??\\PhysicalDrive");

    globalpath[23]=(WORD)pvdExtents->Extents[0].DiskNumber+0x30; // Some bad
    "hardcoding"

    globalpath[24]=0;

    RtlInitUnicodeString(&devicename,globalpath);

    Now use

    IoGetDeviceObjectPointer(&devicename,FILE_READ_ATTRIBUTES,&FileObject,&DeviceObject)

    On Wed, Mar 31, 2010 at 8:07 PM, wrote:

    > Thanks for the fast reply.
    > Now i have a simple question how will i get the unicodestring?
    > I tried it so, but it's not right.
    > UNICODE_STRING devicename;
    > devicename.Buffer = "\Global??\PhysicalDrive" +
    > volumeextents->Extents->DiskNumber;
    > Please help me!
    > Best Regards
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    So now i tried:
    \GLOBAL??\PhysicalDrive1
    - IoGetDeviceObjectPointer i get a pointer to FILE_DEVICE_DISK_FILE_SYSTEM at \Filesystem\FltMgr
    - IoGetDeviceAttachmentBaseRef i get a pointer to FILE_DEVICE_DISK_FILE_SYSTEM at \Filesystem\RAW
    - IoGetDeviceProperty failed with STATUS_INVALID_DEVICE_REQUEST

    Have you any idea how i can work?
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    IoGetDeviceAttachmentBaseRef should give you the USBSTOR object, If you can
    put the code out, some one on the list can figure out the problem.

    On Thu, Apr 1, 2010 at 4:07 PM, wrote:

    > So now i tried:
    > \GLOBAL??\PhysicalDrive1
    > - IoGetDeviceObjectPointer i get a pointer to FILE_DEVICE_DISK_FILE_SYSTEM
    > at \Filesystem\FltMgr
    > - IoGetDeviceAttachmentBaseRef i get a pointer to
    > FILE_DEVICE_DISK_FILE_SYSTEM at \Filesystem\RAW
    > - IoGetDeviceProperty failed with STATUS_INVALID_DEVICE_REQUEST
    >
    > Have you any idea how i can work?
    >
    >
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    I would be glad, if someone can say me how to get the USBSTOR object.

    KEVENT WaitEvent;
    PIRP NewIrp;
    NTSTATUS status1;
    PDEVICE_OBJECT ndevice;
    PDEVICE_OBJECT device;
    PFILE_OBJECT file;
    ULONG lenght;
    WCHAR hwId[256];
    PVOLUME_DISK_EXTENTS volumeextents;
    PUNICODE_STRING devicename;
    wchar_t data[25];

    KeInitializeEvent(&WaitEvent, NotificationEvent, FALSE);
    volumeextents = ExAllocatePoolWithTag(NonPagedPool,sizeof(VOLUME_DISK_EXTENTS), 500);
    NewIrp = IoBuildDeviceIoControlRequest(IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
    DeviceObject,
    NULL, 0,
    (PVOID)volumeextents, sizeof(VOLUME_DISK_EXTENTS),
    FALSE, &WaitEvent, &IoStatus);

    if (!NewIrp) {
    DbgPrint("Failed to create new IRP,IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS");
    ExFreePoolWithTag(volumeextents, 500);
    return;
    }

    // send this irp to the storage device
    irpnext = IoGetNextIrpStackLocation(NewIrp);
    DbgPrint("Setze jetz IoCall ab!\n");
    Status = IoCallDriver(DeviceObject, NewIrp);

    if (Status == STATUS_PENDING) {
    Status = KeWaitForSingleObject(&WaitEvent, Executive, KernelMode, FALSE,
    NULL);
    Status = IoStatus.Status;
    }

    if (!NT_SUCCESS(Status)) {
    DbgPrint("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS failed, status =0x%x", Status);
    ExFreePoolWithTag(volumeextents, 500);
    return;
    }

    wcscpy(data,L"\\GLOBAL??\\PhysicalDrive");
    data[23]= volumeextents->Extents[0].DiskNumber+0x30;
    data[24]=0;
    RtlInitUnicodeString(&devicename,data);
    ExFreePoolWithTag(volumeextents, 500);
    IoGetDeviceObjectPointer(&devicename,FILE_WRITE_DATA,&file,&device);
    ndevice = IoGetDeviceAttachmentBaseRef(device);
    status1 = IoGetDeviceProperty(ndevice,DevicePropertyHardwareID,sizeof (hwId),hwId,&lenght);
    if (!NT_SUCCESS(status1)) {
    DbgPrint(" failed, status =0x%x", status1);
    return;
    }
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    i dont see much difference but surely, make these changes

    data[23]= *(DWORD)*volumeextents->Extents[0].DiskNumber+0x30;

    and

    IoGetDeviceObjectPointer(&devicename,*FILE_READ_ATTRIBUTES*,&file,&device);

    On Thu, Apr 1, 2010 at 5:01 PM, wrote:

    > I would be glad, if someone can say me how to get the USBSTOR object.
    >
    > KEVENT WaitEvent;
    > PIRP NewIrp;
    > NTSTATUS status1;
    > PDEVICE_OBJECT ndevice;
    > PDEVICE_OBJECT device;
    > PFILE_OBJECT file;
    > ULONG lenght;
    > WCHAR hwId[256];
    > PVOLUME_DISK_EXTENTS volumeextents;
    > PUNICODE_STRING devicename;
    > wchar_t data[25];
    >
    > KeInitializeEvent(&WaitEvent, NotificationEvent, FALSE);
    > volumeextents =
    > ExAllocatePoolWithTag(NonPagedPool,sizeof(VOLUME_DISK_EXTENTS), 500);
    > NewIrp =
    > IoBuildDeviceIoControlRequest(IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
    > DeviceObject,
    > NULL, 0,
    > (PVOID)volumeextents, sizeof(VOLUME_DISK_EXTENTS),
    > FALSE, &WaitEvent, &IoStatus);
    >
    > if (!NewIrp) {
    > DbgPrint("Failed to create new
    > IRP,IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS");
    > ExFreePoolWithTag(volumeextents, 500);
    > return;
    > }
    >
    > // send this irp to the storage device
    > irpnext = IoGetNextIrpStackLocation(NewIrp);
    > DbgPrint("Setze jetz IoCall ab!\n");
    > Status = IoCallDriver(DeviceObject, NewIrp);
    >
    > if (Status == STATUS_PENDING) {
    > Status = KeWaitForSingleObject(&WaitEvent, Executive,
    > KernelMode, FALSE,
    > NULL);
    > Status = IoStatus.Status;
    > }
    >
    > if (!NT_SUCCESS(Status)) {
    > DbgPrint("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS failed,
    > status =0x%x", Status);
    > ExFreePoolWithTag(volumeextents, 500);
    > return;
    > }
    >
    > wcscpy(data,L"\\GLOBAL??\\PhysicalDrive");
    > data[23]= volumeextents->Extents[0].DiskNumber+0x30;
    > data[24]=0;
    > RtlInitUnicodeString(&devicename,data);
    > ExFreePoolWithTag(volumeextents, 500);
    > IoGetDeviceObjectPointer(&devicename,FILE_WRITE_DATA,&file,&device);
    > ndevice = IoGetDeviceAttachmentBaseRef(device);
    > status1 = IoGetDeviceProperty(ndevice,DevicePropertyHardwareID,sizeof
    > (hwId),hwId,&lenght);
    > if (!NT_SUCCESS(status1)) {
    > DbgPrint(" failed, status =0x%x", status1);
    > return;
    > }
    >
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    great!!! thanks, that was it - now i got the USBSTOR object :-))))
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    Good to hear.

    any how what made the difference?


    On Thu, Apr 1, 2010 at 5:42 PM, wrote:

    > great!!! thanks, that was it - now i got the USBSTOR object :-))))
    >
    > ---
    > NTFSD is sponsored by OSR
    >
    > For our schedule of debugging and file system seminars
    > (including our new fs mini-filter seminar) 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
    >
  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,135
    I suspect that not asking for data access in the open was the difference.

    -scott

    --
    Scott Noone
    Consulting Associate
    OSR Open Systems Resources, Inc.
    http://www.osronline.com

    "Dennis Scott" <xxxxx@allaboutif.com> wrote in message
    news:xxxxx@ntfsd...
    Good to hear.

    any how what made the difference?



    On Thu, Apr 1, 2010 at 5:42 PM, <xxxxx@gmx.at> wrote:

    great!!! thanks, that was it - now i got the USBSTOR object :-))))


    ---
    NTFSD is sponsored by OSR

    For our schedule of debugging and file system seminars
    (including our new fs mini-filter seminar) 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

    -scott
    OSR

  • __Present__Present Member Posts: 7
    to mike meyers:

    are these code wrote in minifilter??

    RE: : how to get USB busid from minifilter driver

    --------------------------------------------------------------------------------

    I would be glad, if someone can say me how to get the USBSTOR object.

    KEVENT WaitEvent;
    PIRP NewIrp;
    NTSTATUS status1;
    PDEVICE_OBJECT ndevice;
    PDEVICE_OBJECT device;
    PFILE_OBJECT file;
    ULONG lenght;
    WCHAR hwId[256];
    PVOLUME_DISK_EXTENTS volumeextents;
    PUNICODE_STRING devicename;
    wchar_t data[25];

    KeInitializeEvent(&WaitEvent, NotificationEvent, FALSE);
    volumeextents = ExAllocatePoolWithTag(NonPagedPool,sizeof(VOLUME_DISK_EXTENTS),
    500);
    NewIrp = IoBuildDeviceIoControlRequest(IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
    DeviceObject,
    NULL, 0,
    (PVOID)volumeextents, sizeof(VOLUME_DISK_EXTENTS),
    FALSE, &WaitEvent, &IoStatus);

    if (!NewIrp) {
    DbgPrint("Failed to create new IRP,IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS");
    ExFreePoolWithTag(volumeextents, 500);
    return;
    }

    // send this irp to the storage device
    irpnext = IoGetNextIrpStackLocation(NewIrp);
    DbgPrint("Setze jetz IoCall ab!\n");
    Status = IoCallDriver(DeviceObject, NewIrp);

    if (Status == STATUS_PENDING) {
    Status = KeWaitForSingleObject(&WaitEvent, Executive, KernelMode, FALSE,
    NULL);
    Status = IoStatus.Status;
    }

    if (!NT_SUCCESS(Status)) {
    DbgPrint("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS failed, status =0x%x", Status);
    ExFreePoolWithTag(volumeextents, 500);
    return;
    }

    wcscpy(data,L"\\GLOBAL??\\PhysicalDrive");
    data[23]= volumeextents->Extents[0].DiskNumber+0x30;
    data[24]=0;
    RtlInitUnicodeString(&devicename,data);
    ExFreePoolWithTag(volumeextents, 500);
    IoGetDeviceObjectPointer(&devicename,FILE_WRITE_DATA,&file,&device);
    ndevice = IoGetDeviceAttachmentBaseRef(device);
    status1 = IoGetDeviceProperty(ndevice,DevicePropertyHardwareID,sizeof
    (hwId),hwId,&lenght);
    if (!NT_SUCCESS(status1)) {
    DbgPrint(" failed, status =0x%x", status1);
    return;
    }
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    yes this code is wrote in a minifilter
  • __Present__Present Member Posts: 7
    so these code were worte in PRECREATE or other dispatcher?i'am trying to block operations about usb mass storage,but device type i got always be FILE_DEVICE_DISK_FILE_SYSTEM,can you suggest me somthing usefull ,thx a million!!
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
Developing Minifilters 29 July 2019 OSR Seminar Space
Writing WDF Drivers 23 Sept 2019 OSR Seminar Space
Kernel Debugging 21 Oct 2019 OSR Seminar Space
Internals & Software Drivers 18 Nov 2019 Dulles, VA