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: 55

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: 7,251

    (Moved to appropriate category)

    Peter Viscarola
    OSR
    @OSRDrivers

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,002
    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,306
    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: 55

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

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