Everhart, Glenn (FUSA) From: Chtchetkine, Vladimir [VChtchetkine@Starbase.com] Sent: Wednesday, April 28, 1999 11:51 AM To: 'Hernan Ochoa'; ntdev@atria.com Subject: RE: [ntdev] writing to a file from a filter driver Hernan: In this model you don't have to use FileObject to make reads/writes to your log file. You can simply use file handle because you _are_ in the same context. Note, though, that this code snip differs from the previous one. From what you described in your first posting, the obvious guess would be that you open a file, make first write and _keep_ the file handle somewhere in the driver. Then, when you need to write your log second time you simply reuse this handle, which is _wrong_ because this time your code may be (and, most likely, is) running in another [process] context. About ZwClose. The file (not the handle!) will get closed when its FileObject's reference count drops to zero. It's a simple math. When you open a file via ZwCreateFile its ref. count is increasing by 1. When you use ObReference its ref. count is increasing by 1 again. When you call ObDereference its ref. count is decreasing by 1. If you fail to call ZwClose there will be an outstanding reference that will last forever. When you build your own read/write IRPs that you're going to send to an FSD, you don't have to deal with MDLs. Simply use IoBuild(A)SynchronousFsdRequest. Hope this helps, Vladimir Chtchetkine, StarBase Corporation [http://www.starbase.com] mailto:vchtchetkine@starbase.com > -----Original Message----- > From: Hernan Ochoa [SMTP:soporte@sentinel.com.ar] > Sent: Wednesday, April 28, 1999 4:50 AM > To: ntdev@atria.com > Subject: [ntdev] writing to a file from a filter driver > > Hello, > > well, i think i've done it. thanks you for all your help. > i'm able to write to a file from my filter driver, i have to test it more > because sometimes i think it crashes, but well, anyway, i still don't quit > understand why it works :) because i'm doing some strange things, i'm > doint this: > > WriteLog() > { > filehandle = zwcreatefile(..); > fileobject = obReferenceObjectByHandle(filehandle,...); > > > > ObDereferenceObject(fileobject); > zwclose(filehandle); > } > > well, this works just fine. the thing is, if i don't issue the last > zwclose the file remains open > even when my drivers gets unlodaded. if i added, everything works just > fine. > that's seem reasonably, BUT, i'm going to all the trouble of building my > own IRPs because i > can't trust the filehandle, so why does the last close on the file handler > works? :) > > another question, do i need to lock the mdl buffer i allocate to build my > IRPs? > > thanks in adavance. > > > > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > [ To unsubscribe, send email to ntdev-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). ]