]> bbs.cooldavid.org Git - net-next-2.6.git/commit - fs/open.c
[PATCH] open returns ENFILE but creates file anyway
authorPeter Staubach <staubach@redhat.com>
Tue, 13 Sep 2005 08:25:12 +0000 (01:25 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Tue, 13 Sep 2005 15:22:28 +0000 (08:22 -0700)
commita1a5b3d93ca45613ec1d920fdb131b69b6553882
tree19b5a05aca27f3f2ef1dc2169ce6c521ddfa8468
parent873d3469db66ea08e94b0d04a96b1a4507684824
[PATCH] open returns ENFILE but creates file anyway

When open(O_CREAT) is called and the error, ENFILE, is returned, the file
may be created anyway.  This is counter intuitive, against the SUS V3
specification, and may cause applications to misbehave if they are not
coded correctly to handle this semantic.  The SUS V3 specification
explicitly states "No files shall be created or modified if the function
returns -1.".

The error, ENFILE, is used to indicate the system wide open file table is
full and no more file structs can be allocated.

This is due to an ordering problem.  The entry in the directory is created
before the file struct is allocated.  If the allocation for the file struct
fails, then the system call must return an error, but the directory entry
was already created and can not be safely removed.

The solution to this situation is relatively easy.  The file struct should
be allocated before the directory entry is created.  If the allocation
fails, then the error can be returned directly.  If the creation of the
directory entry fails, then the file struct can be easily freed.

Signed-off-by: Peter Staubach <staubach@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
fs/open.c