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

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

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: https://www.osr.com/osr-learning-library/


How to get the Device Number in File System Driver

Nikhil_V_SNikhil_V_S Member - All Emails Posts: 58

I have created a sample MFC application to find the device number
using IOCTL_STORAGE_GET_DEVICE_NUMBER
following code block used
hDeviceHandle = CreateFile(strDrivePath,0,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,0);
if (hDeviceHandle != (HANDLE)-1)
{
STORAGE_DEVICE_NUMBER sdn;
DWORD returned;
if (DeviceIoControl( hDeviceHandle,IOCTL_STORAGE_GET_DEVICE_NUMBER,NULL,0,&sdn,sizeof(sdn),&returned,NULL));
{
printf("\tDevice type: %d number: %d partition: %d\n",sdn.DeviceType, sdn.DeviceNumber, sdn.PartitionNumber);
}
}

I Need to find out the Device number in file system driver.Is it Possible find the device number in kernel mode .

Comments

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 8,036

    (Moved to appropriate category)

    Peter Viscarola
    OSR
    @OSRDrivers

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,596
    Nikhil_V_S wrote:
    > I Need to find out the Device number in file system driver.Is it Possible find the device number in kernel mode .

    Are you talking about finding the number for the device where your file
    system resides, or for a different device?

    The driver layers are abstracted, for good reasons.  You shouldn't be
    making any assumptions about what drivers lie underneath you.  If it
    were a network share or some nested file system, then you wouldn't even
    have a device number.

    Why do you think you need this?  What are you really trying to do here?

    Note: The email was trying to reply to an invalid Discussion (290933).

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

  • Mark_RoddyMark_Roddy Member - All Emails Posts: 4,366
    This IOCTL should be usable in kernel mode.
    Mark Roddy

    Note: The email was trying to reply to an invalid Discussion (290933).
  • Nikhil_V_SNikhil_V_S Member - All Emails Posts: 58

    @Tim_Roberts said:

    Are you talking about finding the number for the device where your file
    system resides, or for a different device?

    same device number.when i connect multiple usb device i need to find out which one is it .

  • Nikhil_V_SNikhil_V_S Member - All Emails Posts: 58

    @Mark_Roddy said:

    This IOCTL should be usable in kernel mode.
    Mark Roddy

    thank you @Mark Roddy

    Can you please share any sample code .

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!
Internals & Software Drivers 30 Nov 2020 LIVE ONLINE
Writing WDF Drivers 7 Dec 2020 LIVE ONLINE
Developing Minifilters Early 2021 LIVE ONLINE