All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miklos Szeredi <miklos@szeredi.hu>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] open: O_DIRECTORY and O_CREAT together should fail
Date: Fri, 23 Sep 2005 16:45:04 +0200	[thread overview]
Message-ID: <E1EIonQ-0006Ts-00@dorka.pomaz.szeredi.hu> (raw)

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.

             reply	other threads:[~2005-09-23 14:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-23 14:45 Miklos Szeredi [this message]
2005-09-23 19:28 ` [PATCH] open: O_DIRECTORY and O_CREAT together should fail 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1EIonQ-0006Ts-00@dorka.pomaz.szeredi.hu \
    --to=miklos@szeredi.hu \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.