Everhart, Glenn From: Rob Green [robg@cdp.com] Sent: Wednesday, January 13, 1999 2:55 PM To: John Losche Cc: ntfsd; ntdev Subject: [ntdev] Re: [ntfsd] deleting dir objects created with ZwCreateDirectoryObject not working? The handle needs to be closed in the same process as the create (handles are process specific). You can use ObReferenceObjectByHandle to get a object pointer that is valid, followed by a ZwClose on the handle. But then you can not do the ZwMakeTemp* as it deletes the directory on the last HANDLE not the last object. To delete the directory you would then do the ObDeref* on the existing handle (to get ref count to 0) then ZwCreateDir*, ZwMakeTemp*, ZwClose. Rob At 01:23 PM 1/13/99 , you wrote: >This may be my week for obvious questions but.... I am creating a dir >object to put some >device names in, which should be deleted in my unload function, but is not. > >So I am creating a dir object using: > > // Create an object attributes structure. > InitializeObjectAttributes(&DirectoryAttributes, > &DirectoryName, OBJ_PERMANENT, > NULL, NULL); > > // The following call will fail if we do not have appropriate privileges. > if (!NT_SUCCESS(RC = ZwCreateDirectoryObject(PtrReturnedHandle, > DIRECTORY_ALL_ACCESS, > &DirectoryAttributes)) ) { > return RC; > } > >ZwMakeTemporaryObject(PtrReturnedHandle); > >DosDirectoryHandle = *PtrReturnedHandle; > >I create a device name in that directory, all of this works. > >In my unload: > >IoDeleteSymbolicLink(&ctlp->UserVisibleName); // of the device > >IoDeleteDevice(ctlp->myDeviceObject); > >if (ctlp->DosDirectoryHandle) { > ZwClose(ctlp->DosDirectoryHandle); > ctlp->DosDirectoryHandle = NULL; > } > >From the DDK docs, this should decrement to reference count to 0 and delete >the dir object, it does'nt. >So the next time I start the driver the ZwCreateDirectoryObject call fails, >because the dir object already exists. > >Any ideas???? > >Thanks, >John Losche > > > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >[ To unsubscribe, send email to ntfsd-request@atria.com with body >UNSUBSCRIBE (the subject is ignored). ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ To unsubscribe, send email to ntdev-request@atria.com with body UNSUBSCRIBE (the subject is ignored). ]