On Sun, 12 Nov 2017, Otto Moerbeek wrote:
> On Sun, Nov 12, 2017 at 08:12:26PM +0100, Mark Kettenis wrote:
...
> > It certainly doesn't make sense to have touch(1) do the checks.
> > 
> > Note that POSIX says that futimens(2) shall faill if:
> > 
> > [EINVAL]
> >     A new file timestamp would be a value whose tv_sec component is
> >     not a value supported by the file system.
> > 
> > which is something we don't implement for the filesystems where it
> > matters.  Also note that NFSv3 still uses 32 bits for storing the
> > timestamp so there wil;l be issues regardless of the underlying
> > filesystem.

Yeah, for NFS the best we can do is reflect the protocol limitation; NFS 
export of FFSv1 will still see the misbehavior, but that can't be fixed 
without an NFS protocol addition.


> One thing to consider: touch first creates a file using 
> open(...O_CREAT...)  and then sets it's timestamp using futimens(2). 
> That means that we can only determine something went wrong after the 
> fact and if there's would be an error we end up with a file with the 
> wrong filestamp.

The "Right" way to solve that would be to add a new pathconf(2) item(s) 
that would provide info on the timestamp range, or maybe direct max+min 
queries.  The API design would be a bit tricky as pathconf(2) returns 
long, not long long, so either some sort of scaling (log scale by 
returning the # of bits supported?) or an alternate entry point to return 
the full value would be necessary.  Returning log-scale, say, 
_PC_FILETIMEBITS, would be rather annoying to actually *use*, but adding 
pathconfll() just to fix this situation in touch(1) feels like squashing a 
bug with a pile-driver.


Hmm, here's an idea: add a new AT_UTIME_TEST flag for use with utimensat() 
that, when used, makes utimensat() do no actual filesystem change but 
rather simply succeed if and only if the supplied timestamps are within 
the range of the filesystem of the named path, ignoring permission checks.  
touch(1) could then, when the named file doesn't already exist, use 
utimensat(AT_UTIME_TEST) on the directory holding the target.


Philip

Reply via email to