Learning from Ramdrive

Hello

I am reading RamDrive’s source code and learning from it.

There are some questions and concepts that I don’t understand yet:

  1. Please correct me: The PNP manager will call ramdrive’s AddDevice and
    then Ramdrive driver will createdevice with device type
    FILE_DEVICE_VIRTUAL_DISK

  2. How can I add more drives? who can cause the AddDevice to be called again
    so that a new driver will be called?

  3. In the case of a real hardware the PNP manager will detect insertion of a
    new device and call appropriate AddDevice, but in the case of a software PNP
    driver, who can call the AddDevice?

  4. I want to be able to send an IOCTL that will initiate a new AddDevice()
    which will do its job, how can I do that?


Elias

And he said: “It is in teaching others that you learn the secrets” (M. J)

> 3. In the case of a real hardware the PNP manager will detect insertion of a

new device and call appropriate AddDevice, but in the case of a software PNP
driver, who can call the AddDevice?

AddDevice is called when the devnode in which this driver is participating is
being set up.

For the first time, the list of the drivers participating in devnode is built
by matching the PnP IDs of the devnode with the INF files in %SystemRoot%\INF.
This is done by user-mode PnP service.

The PnP IDs of the devnode are asked from the bus driver which originated it
using IRP_MN_QUERY_ID.

For the next times, the list of the drivers participating in devnode is already
in the devnode’s registry key.

The devnode registry key for a real hardware is created by the kernel based on
the results of IRP_MN_QUERY_RELATIONS/BusRelations returned by some bus driver.
For each newly arrived PDO in these results, the kernel sends IRP_MN_QUERY_ID,
assembles the devnode registry key name from these IDs and creates it. After
this, usually the processing by user-mode PnP is done to determine the list of
the participating drivers.

The devnode registry key for a virtual hardware-less driver is usually created
by the user mode apps - installer or such, using the calls like
SetupDiCreateDeviceInfo. Such a devnode is only consists of its registry key,
and is enumerated by the root enumerator, whose job is to enumerate some
registry keys (and not the real hardware).

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

You can add more drivers by installing more instances of the ram disk
driver in user mode, or instead, create 2 drivers. The first is a bus
driver which is installed once. Whenever you want to create a ram disk,
it creates a child PDO which will load the ramdisk function driver.
Since you own the enumerator, you can create/destroy disks at will.
This would be a software bus driver.

I strongly suggest you use KMDF for the bus driver part and ramdisk
function driver part. Writing a bus driver is not trivial and KMDF
makes it much much easier to do. There is a KMDF ramdisk sample as well
to get you started.

d

– I can spell, I just can’t type.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of lallous
Sent: Monday, April 17, 2006 5:24 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Learning from Ramdrive

Hello

I am reading RamDrive’s source code and learning from it.

There are some questions and concepts that I don’t understand yet:

  1. Please correct me: The PNP manager will call ramdrive’s AddDevice and

then Ramdrive driver will createdevice with device type
FILE_DEVICE_VIRTUAL_DISK

  1. How can I add more drives? who can cause the AddDevice to be called
    again
    so that a new driver will be called?
  2. In the case of a real hardware the PNP manager will detect insertion
    of a
    new device and call appropriate AddDevice, but in the case of a software
    PNP
    driver, who can call the AddDevice?
  3. I want to be able to send an IOCTL that will initiate a new
    AddDevice()
    which will do its job, how can I do that?


Elias

And he said: “It is in teaching others that you learn the secrets” (M.
J)


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

The question and previous answers show why “improving” RamDisk to be PnP compatible was a bad idea. Instead, take original version from NT4 DDK and add IOCTLs which allow create and delete drives on-the-fly. We have such a driver (uses encrypted files as a storage) which is binary compatible from NT4 to w2k3 and seems to work at Vista, too.

There is no need for PnP for software only drivers.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]


From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of lallous[SMTP:xxxxx@lgwm.org]
Reply To: Windows System Software Devs Interest List
Sent: Monday, April 17, 2006 2:23 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Learning from Ramdrive

Hello

I am reading RamDrive’s source code and learning from it.

There are some questions and concepts that I don’t understand yet:

  1. Please correct me: The PNP manager will call ramdrive’s AddDevice and
    then Ramdrive driver will createdevice with device type
    FILE_DEVICE_VIRTUAL_DISK

  2. How can I add more drives? who can cause the AddDevice to be called again
    so that a new driver will be called?

  3. In the case of a real hardware the PNP manager will detect insertion of a
    new device and call appropriate AddDevice, but in the case of a software PNP
    driver, who can call the AddDevice?

  4. I want to be able to send an IOCTL that will initiate a new AddDevice()
    which will do its job, how can I do that?


Elias

And he said: “It is in teaching others that you learn the secrets” (M. J)


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

> There is no need for PnP for software only drivers.

That is a bit of a broad stroke. Of course there is a general need for
pnp for software only drivers. There are many components in the system
which require pnp interfaces/notifications so you must be pnp.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, April 18, 2006 4:50 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Learning from Ramdrive

The question and previous answers show why “improving” RamDisk to be PnP
compatible was a bad idea. Instead, take original version from NT4 DDK
and add IOCTLs which allow create and delete drives on-the-fly. We have
such a driver (uses encrypted files as a storage) which is binary
compatible from NT4 to w2k3 and seems to work at Vista, too.

There is no need for PnP for software only drivers.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]


From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com
] on behalf of lallous[SMTP:xxxxx@lgwm.org]
Reply To: Windows System Software Devs Interest List
Sent: Monday, April 17, 2006 2:23 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Learning from Ramdrive

Hello

I am reading RamDrive’s source code and learning from it.

There are some questions and concepts that I don’t understand yet:

  1. Please correct me: The PNP manager will call ramdrive’s AddDevice
    and
    then Ramdrive driver will createdevice with device type
    FILE_DEVICE_VIRTUAL_DISK

  2. How can I add more drives? who can cause the AddDevice to be called
    again
    so that a new driver will be called?

  3. In the case of a real hardware the PNP manager will detect
    insertion of a
    new device and call appropriate AddDevice, but in the case of a
    software PNP
    driver, who can call the AddDevice?

  4. I want to be able to send an IOCTL that will initiate a new
    AddDevice()
    which will do its job, how can I do that?


Elias

And he said: “It is in teaching others that you learn the secrets” (M.
J)


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

OK, let’s stay with virtual disk drivers. There is a need to create a new drive on user request. Simple IOCTL with “classic” driver works with no problem and PnP way is just ridiculously complicated. I never noticed any problem with this driver not beeing PnP as it is fully controlled by our user mode software. It is able to react to necessary PnP events as when a flashdrive with host file is unplugged. Do you see any real problem with this approach?

What advantage gained RamDisk when became PnP?

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]


From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Doron Holan[SMTP:xxxxx@microsoft.com]
Reply To: Windows System Software Devs Interest List
Sent: Wednesday, April 19, 2006 4:39 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Learning from Ramdrive

> There is no need for PnP for software only drivers.

That is a bit of a broad stroke. Of course there is a general need for
pnp for software only drivers. There are many components in the system
which require pnp interfaces/notifications so you must be pnp.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, April 18, 2006 4:50 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Learning from Ramdrive

The question and previous answers show why “improving” RamDisk to be PnP
compatible was a bad idea. Instead, take original version from NT4 DDK
and add IOCTLs which allow create and delete drives on-the-fly. We have
such a driver (uses encrypted files as a storage) which is binary
compatible from NT4 to w2k3 and seems to work at Vista, too.

There is no need for PnP for software only drivers.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]

> ----------
> From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com
] on behalf of lallous[SMTP:xxxxx@lgwm.org]
> Reply To: Windows System Software Devs Interest List
> Sent: Monday, April 17, 2006 2:23 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] Learning from Ramdrive
>
> Hello
>
> I am reading RamDrive’s source code and learning from it.
>
> There are some questions and concepts that I don’t understand yet:
>
> 1. Please correct me: The PNP manager will call ramdrive’s AddDevice
and
> then Ramdrive driver will createdevice with device type
> FILE_DEVICE_VIRTUAL_DISK
>
> 2. How can I add more drives? who can cause the AddDevice to be called
again
> so that a new driver will be called?
> 3. In the case of a real hardware the PNP manager will detect
insertion of a
> new device and call appropriate AddDevice, but in the case of a
software PNP
> driver, who can call the AddDevice?
> 4. I want to be able to send an IOCTL that will initiate a new
AddDevice()
> which will do its job, how can I do that?
>
>
> –
> Elias
>
> And he said: “It is in teaching others that you learn the secrets” (M.
J)
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at > http://www.osronline.com/page.cfm?name=ListServer

BTW, Doron, doesn’t MS virtual CD driver work exactly this way? I know, it is unsupported :slight_smile:

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]


From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Michal Vodicka[SMTP:xxxxx@upek.com]
Reply To: Windows System Software Devs Interest List
Sent: Wednesday, April 19, 2006 5:32 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Learning from Ramdrive

OK, let’s stay with virtual disk drivers. There is a need to create a new drive on user request. Simple IOCTL with “classic” driver works with no problem and PnP way is just ridiculously complicated. I never noticed any problem with this driver not beeing PnP as it is fully controlled by our user mode software. It is able to react to necessary PnP events as when a flashdrive with host file is unplugged. Do you see any real problem with this approach?

What advantage gained RamDisk when became PnP?

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]

> ----------
> From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Doron Holan[SMTP:xxxxx@microsoft.com]
> Reply To: Windows System Software Devs Interest List
> Sent: Wednesday, April 19, 2006 4:39 AM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] Learning from Ramdrive
>
> > There is no need for PnP for software only drivers.
>
> That is a bit of a broad stroke. Of course there is a general need for
> pnp for software only drivers. There are many components in the system
> which require pnp interfaces/notifications so you must be pnp.
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
> Sent: Tuesday, April 18, 2006 4:50 PM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] Learning from Ramdrive
>
> The question and previous answers show why “improving” RamDisk to be PnP
> compatible was a bad idea. Instead, take original version from NT4 DDK
> and add IOCTLs which allow create and delete drives on-the-fly. We have
> such a driver (uses encrypted files as a storage) which is binary
> compatible from NT4 to w2k3 and seems to work at Vista, too.
>
> There is no need for PnP for software only drivers.
>
> Best regards,
>
> Michal Vodicka
> UPEK, Inc.
> [xxxxx@upek.com, http://www.upek.com]
>
>
> > ----------
> > From:
> xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com
> ] on behalf of lallous[SMTP:xxxxx@lgwm.org]
> > Reply To: Windows System Software Devs Interest List
> > Sent: Monday, April 17, 2006 2:23 PM
> > To: Windows System Software Devs Interest List
> > Subject: [ntdev] Learning from Ramdrive
> >
> > Hello
> >
> > I am reading RamDrive’s source code and learning from it.
> >
> > There are some questions and concepts that I don’t understand yet:
> >
> > 1. Please correct me: The PNP manager will call ramdrive’s AddDevice
> and
> > then Ramdrive driver will createdevice with device type
> > FILE_DEVICE_VIRTUAL_DISK
> >
> > 2. How can I add more drives? who can cause the AddDevice to be called
> again
> > so that a new driver will be called?
> > 3. In the case of a real hardware the PNP manager will detect
> insertion of a
> > new device and call appropriate AddDevice, but in the case of a
> software PNP
> > driver, who can call the AddDevice?
> > 4. I want to be able to send an IOCTL that will initiate a new
> AddDevice()
> > which will do its job, how can I do that?
> >
> >
> > –
> > Elias
> >
> > And he said: “It is in teaching others that you learn the secrets” (M.>
> J)
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
> >
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at > http://www.osronline.com/page.cfm?name=ListServer
>


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

I have no idea how it works. My point is not that using pnp in a
software only driver is an absolute, just that the statement “there is
no need for pnp in a software only driver” is not an absolute either.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, April 18, 2006 8:39 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Learning from Ramdrive

BTW, Doron, doesn’t MS virtual CD driver work exactly this way? I know,
it is unsupported :slight_smile:

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]


From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com
] on behalf of Michal Vodicka[SMTP:xxxxx@upek.com]
Reply To: Windows System Software Devs Interest List
Sent: Wednesday, April 19, 2006 5:32 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Learning from Ramdrive

OK, let’s stay with virtual disk drivers. There is a need to create a
new drive on user request. Simple IOCTL with “classic” driver works with
no problem and PnP way is just ridiculously complicated. I never noticed
any problem with this driver not beeing PnP as it is fully controlled by
our user mode software. It is able to react to necessary PnP events as
when a flashdrive with host file is unplugged. Do you see any real
problem with this approach?

What advantage gained RamDisk when became PnP?

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]

> ----------
> From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com
] on behalf of Doron Holan[SMTP:xxxxx@microsoft.com]
> Reply To: Windows System Software Devs Interest List
> Sent: Wednesday, April 19, 2006 4:39 AM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] Learning from Ramdrive
>
> > There is no need for PnP for software only drivers.
>
> That is a bit of a broad stroke. Of course there is a general need
for
> pnp for software only drivers. There are many components in the
system
> which require pnp interfaces/notifications so you must be pnp.
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Michal
Vodicka
> Sent: Tuesday, April 18, 2006 4:50 PM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] Learning from Ramdrive
>
> The question and previous answers show why “improving” RamDisk to be
PnP
> compatible was a bad idea. Instead, take original version from NT4
DDK
> and add IOCTLs which allow create and delete drives on-the-fly. We
have
> such a driver (uses encrypted files as a storage) which is binary
> compatible from NT4 to w2k3 and seems to work at Vista, too.
>
> There is no need for PnP for software only drivers.
>
> Best regards,
>
> Michal Vodicka
> UPEK, Inc.
> [xxxxx@upek.com, http://www.upek.com]
>
>
> > ----------
> > From:
>
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com
> ] on behalf of lallous[SMTP:xxxxx@lgwm.org]
> > Reply To: Windows System Software Devs Interest List
> > Sent: Monday, April 17, 2006 2:23 PM
> > To: Windows System Software Devs Interest List
> > Subject: [ntdev] Learning from Ramdrive
> >
> > Hello
> >
> > I am reading RamDrive’s source code and learning from it.
> >
> > There are some questions and concepts that I don’t understand yet:
> >
> > 1. Please correct me: The PNP manager will call ramdrive’s
AddDevice
> and
> > then Ramdrive driver will createdevice with device type
> > FILE_DEVICE_VIRTUAL_DISK
> >
> > 2. How can I add more drives? who can cause the AddDevice to be
called
> again
> > so that a new driver will be called?
> > 3. In the case of a real hardware the PNP manager will detect
> insertion of a
> > new device and call appropriate AddDevice, but in the case of a
> software PNP
> > driver, who can call the AddDevice?
> > 4. I want to be able to send an IOCTL that will initiate a new
> AddDevice()
> > which will do its job, how can I do that?
> >
> >
> > –
> > Elias
> >
> > And he said: “It is in teaching others that you learn the secrets”
(M.>
> J)
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
> >
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at >
http://www.osronline.com/page.cfm?name=ListServer
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

>software only driver is an absolute, just that the statement "there is

no need for pnp in a software only driver" is not an absolute either

PnP is good for:

  • MountMgr interaction
  • managing device instances in Device Manager
  • many other things

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

>PnP is good for:

  • MountMgr interaction
  • many other things

I understand there are two ways of notifying, one is to register
MOUNTDEV_MOUNTED_DEVICE_GUID and the second being sending IOCTL to the mount
manager. Is one preferred over other?

  • managing device instances in Device Manager
    Since we are talking about “Software only” device. How important is this?
    There is no resource conflicts/resolution etc. These devices are going to be
    managed by custom app, no requirement for enumeration based on interfaces,
    no filter driver requirement etc.
  • many other things

Can you point to some of these advantages? How about Power Management?
Actually, I am also trying to evaluate a bus vs non-bus approach.

TIA
Pash

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Wednesday, April 19, 2006 5:56 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Learning from Ramdrive

software only driver is an absolute, just that the statement “there is
no need for pnp in a software only driver” is not an absolute either

PnP is good for:

  • MountMgr interaction
  • managing device instances in Device Manager
  • many other things

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> Can you point to some of these advantages? How about Power Management?

No need in PM for software modules, only in some weird cases like the TCP/IP
clients, where TdiRegisterPnPHandlers work.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com