On Fri, Oct 31, 2025 at 09:33:30AM -0600, Paul Eggert wrote: > On 10/31/25 09:14, Pavel Cahyna wrote: > Yes, for GNU Tar the FreeBSD API is better. I don't know why the Linux > kernel went a different way.
Perhaps, since gnulib already provides openat(), the O_RESOLVE_BENEATH flag (from FreeBSD) could be added to it? Not sure if it is better or worse than the alternatives of introducing a new API or an openat2() reimplementation. > > wouldn't it be enough for tar to use > > openat2 (or open_beneath or whatever wrapper) and fstat / fchmod / mkdirat > > on the fd returned > > No, because you can't use openat to make directories, etc. It's good only > for opening existing files, for creating regular files and (perhaps; I > haven't checked) for statting them. I was thinking of something like, if the task is to create "a/b/c/childdir" : parentdir = open_beneath(AT_FDCWD, "a/b/c", O_DIRECTORY | O_PATH); /* safe as mkdir fails in case "childdir" is a symlink */ mkdirat(parentdir, "childdir", 0700); and, if the task is to create "a/b/c/dev": ... mknodat(parentdir, "dev", S_IFCHR | 0600, dev); and, if the task is to change its permissions: node = open_beneath(AT_FDCWD, "a/b/c/dev", O_RDONLY); fchmod(node, S_IRUSR | S_IWUSR | S_IRGRP); so the openat2 or open_beneath (or openat with O_RESOLVE_BENEATH) API should be enough (one could introduce wrappers to perform the above, let's say mkdir_beneath() and so on, but it is not required for the task). Regards, Pavel
