Re: [RFC PATCH v5 1/2] vfs: add O_CREAT|O_DIRECTORY to open*(2)

From: Christian Brauner

Date: Tue Jun 02 2026 - 09:47:24 EST


On Mon, Jun 01, 2026 at 10:52:24PM +0200, Jori Koolstra wrote:
>
> > Op 27-05-2026 13:43 CEST schreef Christian Brauner <brauner@xxxxxxxxxx>:
> >
> > I agree, let's not do booleans if we can avoid them. But fwiw, some
> > userspace projects require naked booleans to come with a comment like:
> >
> > may_o_create(..., /* create_dir */ true)
> >
> > Which makes this easier to handle. But conventions like this are
> > difficult to enforce - especially in the kernel.
> >
> > Years ago I added vfs_prepare_mode() which should handle all that
> > uniformly. Back then I didn't pass S_IFDIR and wrote:
> >
> > * Note that it's currently valid for @type to be 0 if a directory is created.
> > * Filesystems raise that flag individually and we need to check whether each
> > * filesystem can deal with receiving S_IFDIR from the vfs before we enforce a
> > * non-zero type.
>
> Yeah, I think this confused me. Now that I look at it again we can just get
> rid of that bool flag in may_o_create() since we just prepared the mode with
> vfs_prepare_mode(). It would be nice to also remove it from o_create_mode(),
> but off the top of my head, nothing is stopping you from passing a mode type
> to open(2) that has more than one bit set (e.g. both S_IFDIR and S_IFREG), and
> this is precisely what vfs_prepare_mode() is for to fix.
>
> I was planning to get rid off this comment and enforce S_IFDIR, but I think
> that should be separate from this patchset. Agree?

Sure.