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 the Device Number in File System Driver

Nikhil_V_SNikhil_V_S Member - All Emails Posts: 25

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: 6,907

    (Moved to appropriate category)

    Peter Viscarola
    OSR
    @OSRDrivers

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 12,769
    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,290
    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: 25

    @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: 25

    @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
Developing Minifilters 4 Feb 2019 OSR Seminar Space
Writing WDF Drivers 25 Feb 2019 OSR Seminar Space
Kernel Debugging and Crash Analysis 25 Mar 2019 OSR Seminar Space