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

Re: [PATCH 4/4] cygwin: Use native Win32 API for stat

From
Alex Riesen <raa.lkml@gmail.com>
Date
Sep 28, 2008, 09:50 UTC
Message-ID
<20080928095045.GA3746@blimp.localhost>
In-Reply-To
<20080927084349.GC21650@dpotapov.dyndns.org>
Dmitry Potapov, Sat, Sep 27, 2008 10:43:49 +0200:
Show 5 quoted lines
> Despite all efforts to make the fast implementation as robust as possible,
> it may not work well for some very rare situations. I am aware only one
> situation: use Cygwin mount to bind unrelated paths inside repository
> together.  Therefore, the core.cygwinnativestat configuration option is
> provided, which controls whether native or Cygwin version of stat is used.
cygwin.tryWindowsState? (I think cygwin has to get its own section)
Show 18 quoted lines
> +static int do_stat(const char *file_name, struct stat *buf, stat_fn_t cygstat)
> +{
> +	WIN32_FILE_ATTRIBUTE_DATA fdata;
> +
> +	if (file_name[0] == '/')
> +		return cygstat (file_name, buf);
> +
> +	if (!(errno = get_file_attr(file_name, &fdata))) {
> +		/*
> +		 * If the system attribute is set and it is not a directory then
> +		 * it could be a symbol link created in the nowinsymlinks mode.
> +		 * Normally, Cygwin works in the winsymlinks mode, so this situation
> +		 * is very unlikely. For the sake of simplicity of our code, let's
> +		 * Cygwin to handle it.
> +		 */
> +		if ((fdata.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) &&
> +		    !(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
> +			return cygstat (file_name, buf);
formatting: space after function name.
Show 30 quoted lines
> +
> +		/* fill out the stat structure */
> +		buf->st_dev = buf->st_rdev = 0; /* not used by Git */
> +		buf->st_ino = 0;
> +		buf->st_mode = file_attr_to_st_mode (fdata.dwFileAttributes);
> +		buf->st_nlink = 1;
> +		buf->st_uid = buf->st_gid = 0;
> +#ifdef __CYGWIN_USE_BIG_TYPES__
> +		buf->st_size = ((_off64_t)fdata.nFileSizeHigh << 32) +
> +			fdata.nFileSizeLow;
> +#else
> +		buf->st_size = (off_t)fdata.nFileSizeLow;
> +#endif
> +		buf->st_blocks = size_to_blocks(buf->st_size);
> +		filetime_to_timespec(&fdata.ftLastAccessTime, &buf->st_atim);
> +		filetime_to_timespec(&fdata.ftLastWriteTime, &buf->st_mtim);
> +		filetime_to_timespec(&fdata.ftCreationTime, &buf->st_ctim);
> +		return 0;
> +	} else if (errno == ENOENT) {
> +		/*
> +		 * In the winsymlinks mode (which is the default), Cygwin
> +		 * emulates symbol links using Windows shortcut files. These
> +		 * files are formed by adding .lnk extension. So, if we have
> +		 * not found the specified file name, it could be that it is
> +		 * a symbol link. Let's Cygwin to deal with that.
> +		 */
> +		return cygstat (file_name, buf);
> +	}
> +	return -1;
> +}
I like it and will be keeping in my tree. Thanks!
Previous: Shawn O. PearceNext: Dmitry Potapov
Message 10 of 11 in “cygwin: Use native Win32 API for stat”
  1. 4/4 cygwin: Use native Win32 API for statDmitry Potapov, Sep 27, 2008
  2. Johannes SixtSep 27, 2008
  3. Dmitry PotapovSep 27, 2008
  4. Johannes SixtSep 28, 2008
  5. Shawn O. PearceSep 29, 2008
  6. Dmitry PotapovSep 29, 2008
  7. 4/4 cygwin: Use native Win32 API for statDmitry Potapov, Sep 30, 2008
  8. Marcus GriepSep 30, 2008
  9. Shawn O. PearceSep 30, 2008
  10. Alex RiesenSep 28, 2008
  11. Dmitry PotapovSep 27, 2008

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.