Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750719AbVIWT3g (ORCPT ); Fri, 23 Sep 2005 15:29:36 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751086AbVIWT3g (ORCPT ); Fri, 23 Sep 2005 15:29:36 -0400 Received: from smtp.osdl.org ([65.172.181.4]:65213 "EHLO smtp.osdl.org") by vger.kernel.org with ESMTP id S1750719AbVIWT3f (ORCPT ); Fri, 23 Sep 2005 15:29:35 -0400 Date: Fri, 23 Sep 2005 12:28:34 -0700 From: Andrew Morton To: Miklos Szeredi Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] open: O_DIRECTORY and O_CREAT together should fail Message-Id: <20050923122834.659966c4.akpm@osdl.org> In-Reply-To: References: X-Mailer: Sylpheed version 1.0.4 (GTK+ 1.2.10; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1533 Lines: 42 Miklos Szeredi wrote: > > 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. > We could be a bit screwed here. If there are any apps out there which are using this combination, we just broke them. Essentially the patch is assuming that nobody is currently using O_CREAT|O_DIRECTORY, but one day in the future someone will do that. > > 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/