Can't delete symbolic link

I’m having some trouble with the deletion of a symbolic link, but only sometimes. The problem is reproducible, but I can’t figure it out.

The driver I am writing is for a virtual device, thus I can add and remove devices on demand from the command line. A symbolic link is created during the AddDevice routine. The link is generated using a format string like L"\DosDevices\SymName%d". The UNICODE_STRING that is used for the creation of the symlink (including the buffer) is stored in the device extension. The RemoveDevice routine then uses the same UNICODE_STRING value to delete the symbolic link prior to deleting the device itself.

There are two circumstances under which the RemoveDevice routine is called.
The first is when a request from the command line asks for the device to be destroyed. This works fine quite nicely. The second case is when the user requests the unloading of the driver, i.e. net stop driver. In this case the DriverUnload routine enumerates each virtual device currently remaining, and calls RemoveDevice for each device in turn. This works fine as well, except for the deletion of the symbolic link.

Initially I was somewhat surprised at this, and still am. At little exploration has revealed some potentially interesting information though. One possibility that I thought of is that the problem is occurring because of a combination of the way “\DosDevices” is treated and the fact that the two circumstances may involve different user contexts. Here I’m assuming that “net stop driver” will result in being called from a system context as compared to the user context that the application using DeviceIoControl will yield. In support of this, even when I know the link has been created I don’t see it in the Global?? object directory.

Would this explain what I am seeing. Does anyone have any other ideas? If this is the problem how do I solve it? Do I simply change the link name to L"\Global??\SymName%d"? I seem to recall that has some portability issues to older systems.

Thanks in advance for any assistance

Richard

On Thu, 31 Mar 2005 16:48:34 +0930, McNally, Richard
wrote:

> I’m having some trouble with the deletion of a symbolic link, but only
> sometimes. The problem is reproducible, but I can’t figure it out.

I’ve seen such problem in XP SP1. In NT 4.0 and 2k SP2…4, it wasn’t
occured. But I haven’t tested it under XP SP2.

Eugene


Using Opera’s revolutionary e-mail client: http://www.opera.com/mail/