Skip to contentSkip to conversation

timestamp_truncate() incorrect truncate

DISCUSSION Pavel V. Panteleev 1 participant 1 message Aug 7, 2020 VFS

lore
Share & tools
lore
#0 lore raw

Hello,

timestamp_truncate() truncates nsec to 0, if sec is 0 for nfs v3. There is a test:

$ cat ./t.c

#define _GNU_SOURCE

#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int
main (void)
{
const char *fname = "./delme.log";
int fd;
struct stat sb;
const struct timespec ts[2] = {{0, 199}, {0, 999}};

  unlink (fname);
  fd = open (fname, O_CREAT | O_TRUNC, 0660);

  if (futimens(fd, ts) != 0)
    {
      perror ("futimens()");
      return 1;
    }

  close (fd);

  stat (fname, &sb);

printf ("atim: sec == %ld, nsec == %ld\n",

          (long) sb.st_atim.tv_sec,
          (long) sb.st_atim.tv_nsec);

printf ("mtim: sec == %ld, nsec == %ld\n",

          (long) sb.st_mtim.tv_sec,
          (long) sb.st_mtim.tv_nsec);

if (sb.st_atim.tv_sec != ts[0].tv_sec

      || sb.st_atim.tv_nsec != ts[0].tv_nsec
      || sb.st_mtim.tv_sec != ts[1].tv_sec
      || sb.st_mtim.tv_nsec != ts[1].tv_nsec)
    return 1;

return 0;
}

(sec + nsec = nsec) is inside of interval, supported by nfs v3. Why nsec is truncated to 0?