From: Josh Triplett <josh@joshtriplett.org>
To: linux-fsdevel@vger.kernel.org
Subject: futimens use of utimensat does not support O_PATH fds
Date: Thu, 7 Aug 2025 14:01:15 -0700 [thread overview]
Message-ID: <aJUUGyJJrWLgL8xv@localhost> (raw)
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, "", ×, AtFlags::EMPTY_PATH);
println!("utimensat: {ret:?}");
let ret = rustix::fs::futimens(&f, ×);
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?
next reply other threads:[~2025-08-07 21:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-07 21:01 Josh Triplett [this message]
2025-08-07 21:51 ` futimens use of utimensat does not support O_PATH fds 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aJUUGyJJrWLgL8xv@localhost \
--to=josh@joshtriplett.org \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).