All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Pavel V. Panteleev" <panteleev_p@mcst.ru>
To: linux-fsdevel@vger.kernel.org,
	"viro@zeniv.linux.org.uk >> Al Viro" <viro@zeniv.linux.org.uk>
Subject: timestamp_truncate() incorrect truncate
Date: Fri, 7 Aug 2020 12:15:29 +0300	[thread overview]
Message-ID: <5F2D1BB1.6000202@mcst.ru> (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?

                 reply	other threads:[~2020-08-07  9:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=5F2D1BB1.6000202@mcst.ru \
    --to=panteleev_p@mcst.ru \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.