public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* FILE_ATTRIBUTE_TEMPORARY ?
@ 2021-01-06  9:02 Noel Grandin
  2021-01-06  9:44 ` Mark Geisert
  0 siblings, 1 reply; 4+ messages in thread
From: Noel Grandin @ 2021-01-06  9:02 UTC (permalink / raw)
  To: cygwin

Hi

Does the cygwin
     tempfile()
API use the Win32
     FILE_ATTRIBUTE_TEMPORARY
flag on the files it creates?

Asking because that makes a fairly significant performance difference when creating very short lived temp files.

Thanks, Noel Grandin


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: FILE_ATTRIBUTE_TEMPORARY ?
  2021-01-06  9:02 FILE_ATTRIBUTE_TEMPORARY ? Noel Grandin
@ 2021-01-06  9:44 ` Mark Geisert
  2021-01-06 13:26   ` Noel Grandin
  2021-01-06 17:16   ` Brian Inglis
  0 siblings, 2 replies; 4+ messages in thread
From: Mark Geisert @ 2021-01-06  9:44 UTC (permalink / raw)
  To: cygwin

Hi Noel,

Noel Grandin via Cygwin wrote:
> Hi
> 
> Does the cygwin
>      tempfile()
> API use the Win32
>      FILE_ATTRIBUTE_TEMPORARY
> flag on the files it creates?
> 
> Asking because that makes a fairly significant performance difference when 
> creating very short lived temp files.

Good question!  If one specifies O_TMPFILE as one of the flags on an open() call, 
Cygwin does set that Win32 attribute as desired.  Unfortunately, Cygwin's 
tmpfile() is supplied by newlib and it does not specify O_TMPFILE on its 
underlying open() call.

That looks like a bug to me, unless I'm missing something subtle there; I'll 
submit a patch and find out.
Thanks!

..mark

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: FILE_ATTRIBUTE_TEMPORARY ?
  2021-01-06  9:44 ` Mark Geisert
@ 2021-01-06 13:26   ` Noel Grandin
  2021-01-06 17:16   ` Brian Inglis
  1 sibling, 0 replies; 4+ messages in thread
From: Noel Grandin @ 2021-01-06 13:26 UTC (permalink / raw)
  To: Mark Geisert, cygwin

On 2021/01/06 11:44 am, Mark Geisert wrote:
> Hi Noel,
> That looks like a bug to me, unless I'm missing something subtle there; I'll submit a patch and find out.
> Thanks!
> 

Cool thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: FILE_ATTRIBUTE_TEMPORARY ?
  2021-01-06  9:44 ` Mark Geisert
  2021-01-06 13:26   ` Noel Grandin
@ 2021-01-06 17:16   ` Brian Inglis
  1 sibling, 0 replies; 4+ messages in thread
From: Brian Inglis @ 2021-01-06 17:16 UTC (permalink / raw)
  To: cygwin

On 2021-01-06 02:44, Mark Geisert wrote:
> Hi Noel,
> 
> Noel Grandin via Cygwin wrote:
>> Hi
>>
>> Does the cygwin
>>      tempfile()
>> API use the Win32
>>      FILE_ATTRIBUTE_TEMPORARY
>> flag on the files it creates?
>>
>> Asking because that makes a fairly significant performance difference when 
>> creating very short lived temp files.
> 
> Good question!  If one specifies O_TMPFILE as one of the flags on an open() 
> call, Cygwin does set that Win32 attribute as desired.  Unfortunately, Cygwin's 
> tmpfile() is supplied by newlib and it does not specify O_TMPFILE on its 
> underlying open() call.
> 
> That looks like a bug to me, unless I'm missing something subtle there; I'll 
> submit a patch and find out.

O_TMPFILE is only implemented under winsup/cygwin, and only defined for newlib 
under Cygwin:

https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=newlib/libc/include/sys/_default_fcntl.h

see:

https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=0aa99373c1d01b19a7f8ba53e8c7749358480f3e

	https://cygwin.com/pipermail/cygwin/2018-February/236018.html

and:

	https://cygwin.com/pipermail/cygwin/2018-February/235869.html

https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=7ae73be14194ccadc9a7557be33c3940ca4667cb

You should allow linkat to reverse the applied attributes to make the file 
permanent, which may be taken care of in the patch above to 
fhandler_disk_file::link;
from Linux open(2) see

	https://man7.org/linux/man-pages/man2/open.2.html:

"O_TMPFILE must be specified with one of O_RDWR or O_WRONLY and,
optionally, O_EXCL. If O_EXCL is not specified, then linkat(2) can be
used to link the temporary file into the filesystem, making it
permanent, using code like the following:

	char path[PATH_MAX];
	fd = open("/path/to/dir", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR);

	/* File I/O on 'fd'... */

	snprintf(path, PATH_MAX, "/proc/self/fd/%d", fd);
	linkat(AT_FDCWD, path, AT_FDCWD, "/path/for/file",
					AT_SYMLINK_FOLLOW);
"

although the implementation may not currently handle O_EXCL.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-06 17:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-06  9:02 FILE_ATTRIBUTE_TEMPORARY ? Noel Grandin
2021-01-06  9:44 ` Mark Geisert
2021-01-06 13:26   ` Noel Grandin
2021-01-06 17:16   ` Brian Inglis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).