lkml.org 
[lkml]   [2005]   [Sep]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH] open: O_DIRECTORY and O_CREAT together should fail
From
Date
Add a check for O_DIRECTORY in the O_CREAT path, and return -EINVAL.

Current behavior is inconsistent with documentation:
open(..., O_DIRECTORY|O_CREAT) succeeds if file didn't exist, and
returned descriptor does not refer to a directory.

No other error value quite fits this case:

ENOTDIR - the file doesn't exist, so this is slightly misleading
ENOENT - yes, but we asked for an O_CREAT so why wasn't it created

But EINVAL - invalid combination of flags, is quite good IMO.

Signed-off-by: Miklos Szeredi <miklos@szeredi.hu>

Index: linux/fs/namei.c
===================================================================
--- linux.orig/fs/namei.c 2005-09-23 16:35:32.000000000 +0200
+++ linux/fs/namei.c 2005-09-23 16:36:19.000000000 +0200
@@ -1441,6 +1441,9 @@ int open_namei(const char * pathname, in
return error;
goto ok;
}
+ /* O_CREAT | O_DIRECTORY should fail */
+ if (flag & O_DIRECTORY)
+ return -EINVAL;

/*
* Create - we need to know the parent.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-09-23 16:48    [W:0.330 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site