linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* futimens use of utimensat does not support O_PATH fds
@ 2025-08-07 21:01 Josh Triplett
  2025-08-07 21:51 ` Aleksa Sarai
  2025-08-08 13:22 ` Christian Brauner
  0 siblings, 2 replies; 6+ messages in thread
From: Josh Triplett @ 2025-08-07 21:01 UTC (permalink / raw)
  To: linux-fsdevel

I just discovered that opening a file with O_PATH gives an fd that works
with

utimensat(fd, "", times, O_EMPTY_PATH)

but does *not* work with what futimens calls, which is:

utimensat(fd, NULL, times, 0)

The former will go through do_utimes_fd, while the latter goes through
do_utimes_path. I would have expected these two cases to end up in the
same codepath once they'd discovered they were operating on a file
descriptor, and I would have expected both to support O_PATH file
descriptors if either does.

This is true for both symlinks (with O_NOFOLLOW | O_PATH) and regular
files (with just O_PATH). This is on 6.12, in case it matters.

Quick and dirty test program (in Rust, using rustix to make syscalls):

```
use rustix::fs::{AtFlags, OFlags, Timespec, Timestamps, UTIME_OMIT};

fn main() -> std::io::Result<()> {
    let f = rustix::fs::open("oldfile", OFlags::PATH | OFlags::CLOEXEC, 0o666.into())?;
    let times = Timestamps {
        last_access: Timespec { tv_sec: 0, tv_nsec: UTIME_OMIT },
        last_modification: Timespec { tv_sec: 0, tv_nsec: 0 },
    };
    let ret = rustix::fs::utimensat(&f, "", &times, AtFlags::EMPTY_PATH);
    println!("utimensat: {ret:?}");
    let ret = rustix::fs::futimens(&f, &times);
    println!("futimens: {ret:?}");
    Ok(())
}
```

Is this something that would be reasonable to fix? Would a patch be
welcome that makes both cases work identically and support O_PATH file
descriptors?

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-08-10  4:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07 21:01 futimens use of utimensat does not support O_PATH fds Josh Triplett
2025-08-07 21:51 ` Aleksa Sarai
2025-08-08  2:16   ` Josh Triplett
2025-08-08 13:22 ` Christian Brauner
2025-08-08 19:01   ` Josh Triplett
2025-08-10  4:44     ` Aleksa Sarai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).