notes

File times: modified and set_times

Name: ratified 2026-10-18 (calef, convention-rulings Rule 3).

An appendix to notes/std.md, which is the page to read. This file holds milestone 64's last pass: the mapping for each time call, why the handle shapes refuse, its EXAMPLES and its BUGS.

The records this file cites by number:

File times: modified and set_times (milestone 64's last pass)

Both bind to the contract's GETMTIME, SETMTIME and SETMTIME_AT verbs (DECISIONS §112).

The mapping, verb by verb:

std call what it does here
std::fs::metadata(p).modified(), DirEntry::metadata().modified() Bound. stat walks to the directory holding the name (asking dir::READ, as it always did), runs OPEN/FSTAT/CLOSE for the size and kind, then GETMTIME for the time. Works for a directory as for a file.
std::fs::set_times(p, t), set_times_nofollow, FileTimes::set_modified Bound, always to SETMTIME_AT with the caller's seconds, walking with dir::WRITE | dir::SET_MODIFICATION_TIME_AT. Sub-second part truncated.
File::metadata().modified(), Dir::metadata().modified() Refused, Unsupported: the contract asks by name and a handle has none.
File::set_times, File::set_modified Refused, Unsupported, same reason.
FileTimes::set_accessed passed to set_times Refused whole, Unsupported, and nothing is changed: no verb sets an access time.
metadata(".") / metadata("/"), set_times(".") The granted directory itself has no name; modified() and set_times refuse.
accessed(), created() Refused: no verb carries either.
SETMTIME (set to the server's own "now") Not used by std, deliberately (below).

Why the handle shapes refuse rather than remember the name. The PAL could record the name a File was opened by and ask GETMTIME with it. The answer would be about whatever holds that name now. After a rename it would report another file's time, after an unlink a NotFound for a file the caller is holding open, and set_times the same way would stamp the wrong file and return Ok. POSIX's fstat and futimens act on the inode, and a binding that silently acted on a name instead is the answer-instead-of-refusing failure this note keeps recording. A handle-taking form is a wire change and is proposed in design/roadmap/0504-an-mtime-for-an-open-file.md.

Why set_times never falls back to SETMTIME. A SystemTime from the caller is an assertion about history even when it came from SystemTime::now(), and §112 put that authority behind dir::SET_MODIFICATION_TIME_AT, separate from dir::WRITE. So a grant without SET_MODIFICATION_TIME_AT answers ReadOnlyFilesystem. Falling back to SETMTIME would write the server's own "now" instead of the time asked for and report success, and that "now" is not a time at all (next paragraph).

A refused GETMTIME does not fail metadata(). The size and the kind are still true, and a metadata() that failed because one field could not be read would break every caller that only wanted is_dir(). The reply word is kept and modified() reports it. Through a per-file grant the caretaker refuses all three mtime verbs with ENOTDIR (it has no directory to resolve a name under). modified() says that in its message rather than reporting NotADirectory, which would read as a fact about the file.

EXAMPLES, as std_exerciser runs them on all three architectures:

let t = std::fs::metadata("motd")?.modified()?;          // the host tool's stamp: a real second
std::fs::write("f", b"x")?;
std::fs::set_times("f", FileTimes::new().set_modified(t))?; // SETMTIME_AT, needs WRITE | SET_MODIFICATION_TIME_AT
assert_eq!(std::fs::metadata("f")?.modified()?, t);       // whole seconds round-trip
let f = File::open("f")?;
assert_eq!(f.metadata()?.modified().unwrap_err().kind(), ErrorKind::Unsupported);

BUGS: