[PATCH] open: O_DIRECTORY and O_CREAT together should fail

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <[email protected]>

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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux