git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] Windows: Skip fstat/lstat optimization in write_entry()

From
Dmitry Potapov <dpotapov@gmail.com>
Date
Apr 20, 2009, 13:33 UTC
Message-ID
<20090420133305.GE25059@dpotapov.dyndns.org>
In-Reply-To
<81b0412b0904200558w2d506f18i675d5dfb990005ce@mail.gmail.com>
On Mon, Apr 20, 2009 at 02:58:49PM +0200, Alex Riesen wrote:
Show 12 quoted lines
> 2009/4/20 Dmitry Potapov <dpotapov@gmail.com>:
> > The cygwin version has the same problem. (In fact, it is even worse,
> > because we have an optimized version for lstat/stat but not for fstat,
> > and they return different values for some fields like i_no). But even
> > if we used the only Cygwin functions, we would still face the problem,
> > because Windows returns the wrong values for timestamps (and maybe
> > even size on FAT?). So I think the following patch should be squashed
> > on top.
> 
> I just sent a patch with an "optimized" fstat. I see no problems (at least none
> like these) with that patch. Timestamps match. Windows XP, yes. But since
> that MSDN article mentions that it is not guaranteed, I guess I just been lucky.

If the time passed between the creating file and end of writing to it is small (less than timestamp resolution), you may not notice the problem. The following program demonstrates the problem with fstat on Windows. (I compiled it using Cygwin). If you remove 'sleep' then you may not notice the problem for a long time.

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

#define FILENAME "stat-test.tmp"
int main()
{
	struct stat st1, st2;
	memset(&st1, 0, sizeof(st1));
	memset(&st2, 0, sizeof(st2));
	unlink(FILENAME);
	int fd = open(FILENAME, O_CREAT|O_RDWR|O_TRUNC, S_IRWXU);
	if (fd == -1)
	{
		perror("Cannot open " FILENAME);
		return -1;
	}
	sleep(1); /* It is IMPORTANT! */
	write(fd, "test\n", 5);
	fstat(fd, &st1);
	close(fd);
	lstat(FILENAME, &st2);
	if (memcmp(&st1, &st2, sizeof(st1))==0)
		printf("fstat is OK\n");
	else
		printf("fstat is broken\n");
	return 0;
}
-- >8 --
Dmitry
Previous: Alex RiesenNext: Alex Riesen
Message 6 of 12 in “Windows: Skip fstat/lstat optimization in write_entry()”
  1. 2/2 Windows: Skip fstat/lstat optimization in write_entry()Johannes Sixt, Apr 20, 2009
  2. Johannes SchindelinApr 20, 2009
  3. Dmitry PotapovApr 20, 2009
  4. Hannu KoivistoApr 20, 2009
  5. Alex RiesenApr 20, 2009
  6. Dmitry PotapovApr 20, 2009
  7. Alex RiesenApr 20, 2009
  8. Johannes SixtApr 20, 2009
  9. Alex RiesenApr 20, 2009
  10. Alex RiesenApr 20, 2009
  11. Junio C HamanoApr 20, 2009
  12. Alex RiesenApr 20, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.