Re: [PATCH v3 09/14] vfs: add O_CREAT|O_DIRECTORY to open*(2)
From: Christian Brauner
Date: Tue Jul 07 2026 - 09:37:21 EST
> > It's been years since O_DIRECTORY | O_CREAT has been made consistent
> > which means all LTS kernels have consistent behavior. We often make flag
>
> This is not actually (as far as I can tell) correct. Your commit dates back
> to 6.4-rc1. Since then we've had 6.6, 6.12 and 6.18. However, we have 5.10,
> 5.15 and 6.1 which all should still have the old behavior
> (per https://kernel.dance/#43b450632676, that was only backported to 6.1).
We can backport the old fix fwiw because the behavior as is is just a bug.
> > I appreciate the concern but even if this were to fall flat then
> > worst-case we'd add a new flag and we'd still make that work. But I see
> > no reason to not try the semantically obvious thing and make
> > O_DIRECTORY | O_CREAT work.
>
> For what it's worth, if the fugly test function moved you, I do see an easy way
> forward here with openat2(). Namely, openat2(O_CREAT | O_DIRECTORY) with
> mode S_IFDIR | 0777 could Just Work (and will unambiguously be rejected
> in old kernels with EINVAL). Of course it doesn't work with open() :=)
>
> Hmm, if you could use openat2() as a way to simply feature-test for this,
> then suddenly open(O_CREAT | O_DIRECTORY) can also Just Work...
Feature testing has always been a pain that we forced onto userspace. I
think we should continue with that proud tradition.