All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] open: O_DIRECTORY and O_CREAT together should fail
@ 2005-09-23 14:45 Miklos Szeredi
  2005-09-23 19:28 ` Andrew Morton
  0 siblings, 1 reply; 8+ messages in thread
From: Miklos Szeredi @ 2005-09-23 14:45 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-09-24 19:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-23 14:45 [PATCH] open: O_DIRECTORY and O_CREAT together should fail Miklos Szeredi
2005-09-23 19:28 ` Andrew Morton
2005-09-24  5:52   ` Miklos Szeredi
2005-09-24  6:09     ` Al Viro
2005-09-24  6:41       ` Miklos Szeredi
2005-09-24  7:01         ` Al Viro
2005-09-24  7:43           ` Miklos Szeredi
2005-09-24 19:53           ` Kyle Moffett

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.