Failing IRP_MJ_CLOSE/CLEANUP...

I seem to recall from vague memories of driver
classes that IRP_MJ_CLOSE can’t be failed?

Is this true, or am I out to lunch?

If it is true, can MRxCloseSrvOpen()
be failed?

I guess I’m wondering if I should wait
for a status from the server when I
close a file, or if it is just a
waste of time to do so.

Thanks,

Joseph

Failing IRP_MJ_CLOSE has no meaning. IRP_MJ_CLOSE is just a notification
that nobody uses the file object any more and it is going to be destroyed.
You need to cleanup your resources associated with the file object. If you
can’t cleanup everything at this moment you can delay your cleanup - just
make sure that you saved everything you need from the file object.

Alexei.

“Joseph Galbraith” wrote in message news:xxxxx@ntfsd…
> I seem to recall from vague memories of driver
> classes that IRP_MJ_CLOSE can’t be failed?
>
> Is this true, or am I out to lunch?
>
> If it is true, can MRxCloseSrvOpen()
> be failed?
>
> I guess I’m wondering if I should wait
> for a status from the server when I
> close a file, or if it is just a
> waste of time to do so.
>
> Thanks,
>
> Joseph
>

Joseph,

The return value from IRP_MJ_CLEANUP will be reflected in the
CloseHandle call (for example) but in my experience applications do not
generally look for this error - nor is it clear what the correct
behavior is if this call fails.

The return value for IRP_MJ_CLOSE is not used by anything I have ever
seen - in this case it is generally some call to ObDereferenceObject
that causes the IRP_MJ_CLOSE. Again, there’s no clear recovery
mechanism from a failed call to IRP_MJ_CLOSE.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Joseph Galbraith
Sent: Monday, November 22, 2004 5:18 PM
To: ntfsd redirect
Subject: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

I seem to recall from vague memories of driver
classes that IRP_MJ_CLOSE can’t be failed?

Is this true, or am I out to lunch?

If it is true, can MRxCloseSrvOpen()
be failed?

I guess I’m wondering if I should wait
for a status from the server when I
close a file, or if it is just a
waste of time to do so.

Thanks,

Joseph


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@osr.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

> ----------

From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Tony Mason[SMTP:xxxxx@osr.com]
Reply To: Windows File Systems Devs Interest List
Sent: Tuesday, November 23, 2004 8:47 AM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

The return value from IRP_MJ_CLEANUP will be reflected in the
CloseHandle call (for example) but in my experience applications do not
generally look for this error - nor is it clear what the correct
behavior is if this call fails.

Paranoid developers (kernel mode forced to write an app :slight_smile: usually write something like VERIFY(CloseHandle(Handle)) to be notified about possible error. An error there means something is wrong with app; Handle value is wrong for some reason. Overwritten or closed before. In any case the error means code should be checked. If kernel returns failure for correct handle, it could lead to real headache. So please, don’t do it :slight_smile:

Best regards,

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

Michal Vodicka wrote:

>----------
>From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Tony Mason[SMTP:xxxxx@osr.com]
>Reply To: Windows File Systems Devs Interest List
>Sent: Tuesday, November 23, 2004 8:47 AM
>To: Windows File Systems Devs Interest List
>Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…
>
>The return value from IRP_MJ_CLEANUP will be reflected in the
>CloseHandle call (for example) but in my experience applications do not
>generally look for this error - nor is it clear what the correct
>behavior is if this call fails.
>

Paranoid developers (kernel mode forced to write an app :slight_smile: usually write something like VERIFY(CloseHandle(Handle)) to be notified about possible error. An error there means something is wrong with app; Handle value is wrong for some reason. Overwritten or closed before. In any case the error means code should be checked. If kernel returns failure for correct handle, it could lead to real headache. So please, don’t do it :slight_smile:

Right.

Which means there is no point in me blocking
MRxCloseSrvOpen() (which I think is coming
as a result of one of these) while waiting
for the response from the server… since
even if the server told me something was
hosed, I don’t want to propagate it anyhow.

So, I get an optimization :slight_smile: Which I sorely
need since the thing is slower than snot
at the moment.

Thanks everyone for your answers.

Joseph

Oh, I certainly agree - and I write code that checks the value of
CloseHandle. However, I stand by my original observation that “in my
experience applications do not generally look for this error…”

The first time I saw this was 15 years ago when debugging the “compact”
UNIX utility and how it worked on top of AFS with respect to
out-of-quota errors (which are reported at close time). Since then I’ve
found very few developers who check for errors on close.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 23, 2004 5:38 PM
To: ntfsd redirect
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…


From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com
] on behalf of Tony Mason[SMTP:xxxxx@osr.com]
Reply To: Windows File Systems Devs Interest List
Sent: Tuesday, November 23, 2004 8:47 AM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

The return value from IRP_MJ_CLEANUP will be reflected in the
CloseHandle call (for example) but in my experience applications do
not
generally look for this error - nor is it clear what the correct
behavior is if this call fails.

Paranoid developers (kernel mode forced to write an app :slight_smile: usually write
something like VERIFY(CloseHandle(Handle)) to be notified about possible
error. An error there means something is wrong with app; Handle value is
wrong for some reason. Overwritten or closed before. In any case the
error means code should be checked. If kernel returns failure for
correct handle, it could lead to real headache. So please, don’t do it
:slight_smile:

Best regards,

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


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

You’re of course right and I have similar experience: most developers ignore CloseHandle() result. I just hope it doesn’t apply to members of this list :wink: I only wanted to point out that failing IRP_MJ_CLOSE can cause unexpected problems to others.

BTW, checking “unimportant” error codes is one of side effect of using lint which complaints about any function which return code is unused. Good effect.

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 Tony Mason[SMTP:xxxxx@osr.com]
Reply To: Windows File Systems Devs Interest List
Sent: Wednesday, November 24, 2004 2:28 AM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

Oh, I certainly agree - and I write code that checks the value of
CloseHandle. However, I stand by my original observation that “in my
experience applications do not generally look for this error…”

The first time I saw this was 15 years ago when debugging the “compact”
UNIX utility and how it worked on top of AFS with respect to
out-of-quota errors (which are reported at close time). Since then I’ve
found very few developers who check for errors on close.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 23, 2004 5:38 PM
To: ntfsd redirect
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

> ----------
> From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com
] on behalf of Tony Mason[SMTP:xxxxx@osr.com]
> Reply To: Windows File Systems Devs Interest List
> Sent: Tuesday, November 23, 2004 8:47 AM
> To: Windows File Systems Devs Interest List
> Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…
>
> The return value from IRP_MJ_CLEANUP will be reflected in the
> CloseHandle call (for example) but in my experience applications do
not
> generally look for this error - nor is it clear what the correct
> behavior is if this call fails.
>
Paranoid developers (kernel mode forced to write an app :slight_smile: usually write
something like VERIFY(CloseHandle(Handle)) to be notified about possible
error. An error there means something is wrong with app; Handle value is
wrong for some reason. Overwritten or closed before. In any case the
error means code should be checked. If kernel returns failure for
correct handle, it could lead to real headache. So please, don’t do it
:slight_smile:

Best regards,

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


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Some of us have never ventured out of kernel-mode. What is CloseHandle()
anyway?

:slight_smile:

Jamey

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 23, 2004 8:00 PM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

You’re of course right and I have similar experience: most developers ignore
CloseHandle() result. I just hope it doesn’t apply to members of this list
:wink: I only wanted to point out that failing IRP_MJ_CLOSE can cause
unexpected problems to others.

BTW, checking “unimportant” error codes is one of side effect of using lint
which complaints about any function which return code is unused. Good
effect.

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 Tony Mason[SMTP:xxxxx@osr.com]
Reply To: Windows File Systems Devs Interest List
Sent: Wednesday, November 24, 2004 2:28 AM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

Oh, I certainly agree - and I write code that checks the value of
CloseHandle. However, I stand by my original observation that “in my
experience applications do not generally look for this error…”

The first time I saw this was 15 years ago when debugging the “compact”
UNIX utility and how it worked on top of AFS with respect to
out-of-quota errors (which are reported at close time). Since then I’ve
found very few developers who check for errors on close.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 23, 2004 5:38 PM
To: ntfsd redirect
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

> ----------
> From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com
] on behalf of Tony Mason[SMTP:xxxxx@osr.com]
> Reply To: Windows File Systems Devs Interest List
> Sent: Tuesday, November 23, 2004 8:47 AM
> To: Windows File Systems Devs Interest List
> Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…
>
> The return value from IRP_MJ_CLEANUP will be reflected in the
> CloseHandle call (for example) but in my experience applications do
not
> generally look for this error - nor is it clear what the correct
> behavior is if this call fails.
>
Paranoid developers (kernel mode forced to write an app :slight_smile: usually write
something like VERIFY(CloseHandle(Handle)) to be notified about possible
error. An error there means something is wrong with app; Handle value is
wrong for some reason. Overwritten or closed before. In any case the
error means code should be checked. If kernel returns failure for
correct handle, it could lead to real headache. So please, don’t do it
:slight_smile:

Best regards,

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


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

I’ve only heard about this thing because periodically I go slumming
amongst user mode developers. I THINK it is the Win32 (yech) equivalent
of NtClose or ZwClose. :wink:

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jamey Kirby
Sent: Wednesday, November 24, 2004 1:01 AM
To: ntfsd redirect
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

Some of us have never ventured out of kernel-mode. What is CloseHandle()
anyway?

:slight_smile:

Jamey

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 23, 2004 8:00 PM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

You’re of course right and I have similar experience: most developers
ignore
CloseHandle() result. I just hope it doesn’t apply to members of this
list
:wink: I only wanted to point out that failing IRP_MJ_CLOSE can cause
unexpected problems to others.

BTW, checking “unimportant” error codes is one of side effect of using
lint
which complaints about any function which return code is unused. Good
effect.

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 Tony Mason[SMTP:xxxxx@osr.com]
Reply To: Windows File Systems Devs Interest List
Sent: Wednesday, November 24, 2004 2:28 AM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

Oh, I certainly agree - and I write code that checks the value of
CloseHandle. However, I stand by my original observation that “in my
experience applications do not generally look for this error…”

The first time I saw this was 15 years ago when debugging the
“compact”
UNIX utility and how it worked on top of AFS with respect to
out-of-quota errors (which are reported at close time). Since then
I’ve
found very few developers who check for errors on close.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 23, 2004 5:38 PM
To: ntfsd redirect
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

> ----------
> From:

xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com

] on behalf of Tony Mason[SMTP:xxxxx@osr.com]
> Reply To: Windows File Systems Devs Interest List
> Sent: Tuesday, November 23, 2004 8:47 AM
> To: Windows File Systems Devs Interest List
> Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…
>
> The return value from IRP_MJ_CLEANUP will be reflected in the
> CloseHandle call (for example) but in my experience applications do
not
> generally look for this error - nor is it clear what the correct
> behavior is if this call fails.
>
Paranoid developers (kernel mode forced to write an app :slight_smile: usually
write
something like VERIFY(CloseHandle(Handle)) to be notified about
possible
error. An error there means something is wrong with app; Handle value
is
wrong for some reason. Overwritten or closed before. In any case the
error means code should be checked. If kernel returns failure for
correct handle, it could lead to real headache. So please, don’t do it
:slight_smile:

Best regards,

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


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag
argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag
argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@osr.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

> You’re of course right and I have similar experience:

most developers ignore CloseHandle() result.
I just hope it doesn’t apply to members of this list :wink:

Eh, well, I do it too. As Tony pointed out,
there is no good action to do in the case of failure.

BTW, checking “unimportant” error codes is one of side effect
of using lint which complaints about any function which return
code is unused.

What if you write (VOID)CloseHandle(hFile) ?

L.

CloseHandle() cannot fail unless the handle is invalid i.e. the only
time CloseHandle() will return a failure status is if the handle that is
supplied is not an open handle for the process. As for drivers - they
are expected to succeed CLEANUP & CLOSE always.
Ob will destroy the handle table entry regardless of how the driver
handles cleanup - think of CloseHandle() as a destructor, or a memory
free operation. It doesn’t fail. Note that CloseHandle() does not call
CLEANUP and return the status of that: it simply decrements the handle
count. If the handle count goes to zero (there could be duplicates of
this handle, each of which bumps up the handle count), an IRP_MJ_CLEANUP
is generated - this is a side effect of the decrement handle count
operation.

Finally when the pointer count goes to zero, an IRP_MJ_CLOSE is
generated, but Ob destroys the object. So regardless of how the client
of Ob (I/O in this case) deals with their object close (i.e. handle
count goes to zero) or object destroy (pointer count goes to zero), Ob
will always destroy handles when the handle count is zero, and delete
objects when pointer count is zero.

Ravi

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jamey Kirby
Sent: Tuesday, November 23, 2004 10:01 PM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

Some of us have never ventured out of kernel-mode. What is CloseHandle()
anyway?

:slight_smile:

Jamey

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 23, 2004 8:00 PM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

You’re of course right and I have similar experience: most developers
ignore
CloseHandle() result. I just hope it doesn’t apply to members of this
list
:wink: I only wanted to point out that failing IRP_MJ_CLOSE can cause
unexpected problems to others.

BTW, checking “unimportant” error codes is one of side effect of using
lint which complaints about any function which return code is unused.
Good effect.

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 Tony Mason[SMTP:xxxxx@osr.com]
Reply To: Windows File Systems Devs Interest List
Sent: Wednesday, November 24, 2004 2:28 AM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

Oh, I certainly agree - and I write code that checks the value of
CloseHandle. However, I stand by my original observation that “in my
experience applications do not generally look for this error…”

The first time I saw this was 15 years ago when debugging the
“compact”
UNIX utility and how it worked on top of AFS with respect to
out-of-quota errors (which are reported at close time). Since then
I’ve found very few developers who check for errors on close.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 23, 2004 5:38 PM
To: ntfsd redirect
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

> ----------
> From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.c
om ] on behalf of Tony Mason[SMTP:xxxxx@osr.com]
> Reply To: Windows File Systems Devs Interest List
> Sent: Tuesday, November 23, 2004 8:47 AM
> To: Windows File Systems Devs Interest List
> Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…
>
> The return value from IRP_MJ_CLEANUP will be reflected in the
> CloseHandle call (for example) but in my experience applications do
not
> generally look for this error - nor is it clear what the correct
> behavior is if this call fails.
>
Paranoid developers (kernel mode forced to write an app :slight_smile: usually
write something like VERIFY(CloseHandle(Handle)) to be notified about
possible error. An error there means something is wrong with app;
Handle value is wrong for some reason. Overwritten or closed before.
In any case the error means code should be checked. If kernel returns
failure for correct handle, it could lead to real headache. So please,

don’t do it
:slight_smile:

Best regards,

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


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag
argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag
argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

To finish the monologue:
It’s perfectly valid to do (VOID) CloseHandle()unless you were
attempting to close an invalid handle and attempting to catch bugs in
your own code.
Ravi

-----Original Message-----
From: Ravisankar Pudipeddi
Sent: Tuesday, November 23, 2004 10:53 PM
To: ‘Windows File Systems Devs Interest List’
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

CloseHandle() cannot fail unless the handle is invalid i.e. the only
time CloseHandle() will return a failure status is if the handle that is
supplied is not an open handle for the process. As for drivers - they
are expected to succeed CLEANUP & CLOSE always.
Ob will destroy the handle table entry regardless of how the driver
handles cleanup - think of CloseHandle() as a destructor, or a memory
free operation. It doesn’t fail. Note that CloseHandle() does not call
CLEANUP and return the status of that: it simply decrements the handle
count. If the handle count goes to zero (there could be duplicates of
this handle, each of which bumps up the handle count), an IRP_MJ_CLEANUP
is generated - this is a side effect of the decrement handle count
operation.

Finally when the pointer count goes to zero, an IRP_MJ_CLOSE is
generated, but Ob destroys the object. So regardless of how the client
of Ob (I/O in this case) deals with their object close (i.e. handle
count goes to zero) or object destroy (pointer count goes to zero), Ob
will always destroy handles when the handle count is zero, and delete
objects when pointer count is zero.

Ravi

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jamey Kirby
Sent: Tuesday, November 23, 2004 10:01 PM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

Some of us have never ventured out of kernel-mode. What is CloseHandle()
anyway?

:slight_smile:

Jamey

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 23, 2004 8:00 PM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

You’re of course right and I have similar experience: most developers
ignore
CloseHandle() result. I just hope it doesn’t apply to members of this
list
:wink: I only wanted to point out that failing IRP_MJ_CLOSE can cause
unexpected problems to others.

BTW, checking “unimportant” error codes is one of side effect of using
lint which complaints about any function which return code is unused.
Good effect.

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 Tony Mason[SMTP:xxxxx@osr.com]
Reply To: Windows File Systems Devs Interest List
Sent: Wednesday, November 24, 2004 2:28 AM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

Oh, I certainly agree - and I write code that checks the value of
CloseHandle. However, I stand by my original observation that “in my
experience applications do not generally look for this error…”

The first time I saw this was 15 years ago when debugging the
“compact”
UNIX utility and how it worked on top of AFS with respect to
out-of-quota errors (which are reported at close time). Since then
I’ve found very few developers who check for errors on close.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 23, 2004 5:38 PM
To: ntfsd redirect
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

> ----------
> From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.c
om ] on behalf of Tony Mason[SMTP:xxxxx@osr.com]
> Reply To: Windows File Systems Devs Interest List
> Sent: Tuesday, November 23, 2004 8:47 AM
> To: Windows File Systems Devs Interest List
> Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…
>
> The return value from IRP_MJ_CLEANUP will be reflected in the
> CloseHandle call (for example) but in my experience applications do
not
> generally look for this error - nor is it clear what the correct
> behavior is if this call fails.
>
Paranoid developers (kernel mode forced to write an app :slight_smile: usually
write something like VERIFY(CloseHandle(Handle)) to be notified about
possible error. An error there means something is wrong with app;
Handle value is wrong for some reason. Overwritten or closed before.
In any case the error means code should be checked. If kernel returns
failure for correct handle, it could lead to real headache. So please,

don’t do it
:slight_smile:

Best regards,

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


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag
argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag
argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

At least in some cases CloseHandle throws an exception if called on invalid
handle.

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

----- Original Message -----
From: “Tony Mason”
To: “Windows File Systems Devs Interest List”
Sent: Wednesday, November 24, 2004 4:28 AM
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

Oh, I certainly agree - and I write code that checks the value of
CloseHandle. However, I stand by my original observation that “in my
experience applications do not generally look for this error…”

The first time I saw this was 15 years ago when debugging the “compact”
UNIX utility and how it worked on top of AFS with respect to
out-of-quota errors (which are reported at close time). Since then I’ve
found very few developers who check for errors on close.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 23, 2004 5:38 PM
To: ntfsd redirect
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

> ----------
> From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com
] on behalf of Tony Mason[SMTP:xxxxx@osr.com]
> Reply To: Windows File Systems Devs Interest List
> Sent: Tuesday, November 23, 2004 8:47 AM
> To: Windows File Systems Devs Interest List
> Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…
>
> The return value from IRP_MJ_CLEANUP will be reflected in the
> CloseHandle call (for example) but in my experience applications do
not
> generally look for this error - nor is it clear what the correct
> behavior is if this call fails.
>
Paranoid developers (kernel mode forced to write an app :slight_smile: usually write
something like VERIFY(CloseHandle(Handle)) to be notified about possible
error. An error there means something is wrong with app; Handle value is
wrong for some reason. Overwritten or closed before. In any case the
error means code should be checked. If kernel returns failure for
correct handle, it could lead to real headache. So please, don’t do it
:slight_smile:

Best regards,

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


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

CloseHandle() will not throw exceptions - unless you are running under a
debugger and an invalid handle was supplied. The latter is so that you
can catch bugs in your own code - when you are double closing and so on.
Ravi

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Wednesday, November 24, 2004 3:16 AM
To: Windows File Systems Devs Interest List
Subject: Re: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

At least in some cases CloseHandle throws an exception if called on
invalid handle.

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

----- Original Message -----
From: “Tony Mason”
To: “Windows File Systems Devs Interest List”
Sent: Wednesday, November 24, 2004 4:28 AM
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

Oh, I certainly agree - and I write code that checks the value of
CloseHandle. However, I stand by my original observation that “in my
experience applications do not generally look for this error…”

The first time I saw this was 15 years ago when debugging the “compact”
UNIX utility and how it worked on top of AFS with respect to
out-of-quota errors (which are reported at close time). Since then I’ve
found very few developers who check for errors on close.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Michal Vodicka
Sent: Tuesday, November 23, 2004 5:38 PM
To: ntfsd redirect
Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

> ----------
> From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com
] on behalf of Tony Mason[SMTP:xxxxx@osr.com]
> Reply To: Windows File Systems Devs Interest List
> Sent: Tuesday, November 23, 2004 8:47 AM
> To: Windows File Systems Devs Interest List
> Subject: RE: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…
>
> The return value from IRP_MJ_CLEANUP will be reflected in the
> CloseHandle call (for example) but in my experience applications do
not
> generally look for this error - nor is it clear what the correct
> behavior is if this call fails.
>
Paranoid developers (kernel mode forced to write an app :slight_smile: usually write
something like VERIFY(CloseHandle(Handle)) to be notified about possible
error. An error there means something is wrong with app; Handle value is
wrong for some reason. Overwritten or closed before. In any case the
error means code should be checked. If kernel returns failure for
correct handle, it could lead to real headache. So please, don’t do it
:slight_smile:

Best regards,

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


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

> ----------

From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Ladislav Zezula[SMTP:xxxxx@volny.cz]
Reply To: Windows File Systems Devs Interest List
Sent: Wednesday, November 24, 2004 7:35 AM
To: Windows File Systems Devs Interest List
Subject: Re: [ntfsd] Failing IRP_MJ_CLOSE/CLEANUP…

> You’re of course right and I have similar experience:
> most developers ignore CloseHandle() result.
> I just hope it doesn’t apply to members of this list :wink:

Eh, well, I do it too. As Tony pointed out,
there is no good action to do in the case of failure.

The good action is to invoke assertion failure to inform developer about possible application bug.

> BTW, checking “unimportant” error codes is one of side effect
> of using lint which complaints about any function which return
> code is unused.

What if you write (VOID)CloseHandle(hFile) ?

Sure, it is possible to avoid lint warnings several ways. PC-lint allows to disable it globally (-esym(534, CloseHandle)) but it isn’t a good idea. Why don’t catch possible bug if there is a chance? I always use VERIFY(exp) macro which is ASSERT(exp) in debug version and (exp) in release. It already paid off several times for me.

Best regards,

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