rpodgorny / unionfs-fuse

union filesystem using fuse
Other
300 stars 76 forks source link

File timestamps lose precision on cow copy #99

Closed Tuupertunut closed 3 years ago

Tuupertunut commented 3 years ago

Version: 2.1

How to reproduce:

  1. Create directories rodir, rwdir and mountpoint.
  2. Create an empty file foo inside rodir.
  3. Create a unionfs instance with -o cow rwdir=rw:rodir=ro and mount it to mountpoint.
  4. Run stat mountpoint/foo and notice the access and modify timestamps.
  5. Run echo -n > mountpoint/foo, now foo gets copied to rwdir but is not actually written to or accessed.
  6. Run stat mountpoint/foo again.

Expected behavior: The file was not actually written to or accessed, so modify and access timestamps should remain the same.

Actual behavior: The modify and access timestamps are truncated to second precision, the nanosecond part has been lost.

Cause: https://github.com/rpodgorny/unionfs-fuse/blob/30c745ca6614d82b74742f025755982b91b2c41f/src/cow_utils.c#L68-L73 Here the st_atime and st_mtime fields only contain timestamps with second precision. Also the utime() system call only modifies timestamps with second precision.