Hi, the attached patch sets FILE_ATTRIBUTE_TEMPORARY on files opened by mkstemp() on WinNT class systems. Theoretically the OS should then be less eager to write such files onto the physical storage and use cache instead.
VH 2005-07-22 Vaclav Haisman <[EMAIL PROTECTED]> * syscalls.cc (open_with_attributes): Rename open() to open_with_attributes(). Add fileattr parameter and use it. Add explicit mode_t parameter for mode. Tweak debugging syscall_printf() calls to reflect the new parameter. (open): Reimplement using open_with_attributes(). * fhandler.cc (fhandler_base::open): Use pc.file_attributes() when opening disk file. * mktemp.cc (_gettemp): Set FILE_ATTRIBUTE_TEMPORARY on WinNT using open_with_attributes().
Index: fhandler.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/fhandler.cc,v retrieving revision 1.239 diff -u -p -d -r1.239 fhandler.cc --- fhandler.cc 6 Jul 2005 20:05:00 -0000 1.239 +++ fhandler.cc 21 Jul 2005 23:27:57 -0000 @@ -639,7 +639,10 @@ fhandler_base::open (int flags, mode_t m if (flags & O_CREAT && get_device () == FH_FS) { - file_attributes = FILE_ATTRIBUTE_NORMAL; + if (pc.file_attributes () == INVALID_FILE_ATTRIBUTES) + file_attributes = FILE_ATTRIBUTE_NORMAL; + else + file_attributes = pc.file_attributes (); /* If mode has no write bits set, we set the R/O attribute. */ if (!(mode & (S_IWUSR | S_IWGRP | S_IWOTH))) file_attributes |= FILE_ATTRIBUTE_READONLY; Index: mktemp.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/mktemp.cc,v retrieving revision 1.2 diff -u -p -d -r1.2 mktemp.cc --- mktemp.cc 25 May 2005 03:43:58 -0000 1.2 +++ mktemp.cc 21 Jul 2005 23:27:57 -0000 @@ -101,11 +101,15 @@ _gettemp(char *path, int *doopen, int do } } + DWORD const fileattr = wincap.is_winnt () ? + FILE_ATTRIBUTE_TEMPORARY : FILE_ATTRIBUTE_NORMAL; for (;;) { if (doopen) { - if ((*doopen = open (path, O_CREAT | O_EXCL | O_RDWR, 0600)) >= 0) + extern int open_with_attributes (const char *, int, mode_t, DWORD); + if ((*doopen = open_with_attributes (path, O_CREAT | O_EXCL | O_RDWR, + 0600, fileattr)) >= 0) return 1; if (errno != EEXIST) return 0; Index: syscalls.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/syscalls.cc,v retrieving revision 1.386 diff -u -p -d -r1.386 syscalls.cc --- syscalls.cc 6 Jul 2005 20:05:03 -0000 1.386 +++ syscalls.cc 21 Jul 2005 23:27:59 -0000 @@ -539,18 +539,15 @@ done: return res; } -/* _open */ -/* newlib's fcntl.h defines _open as taking variable args so we must - correspond. The third arg if it exists is: mode_t mode. */ -extern "C" int -open (const char *unix_path, int flags, ...) + +extern int +open_with_attributes (const char *unix_path, int flags, mode_t mode, + DWORD fileattr) { int res = -1; - va_list ap; - mode_t mode = 0; sig_dispatch_pending (); - syscall_printf ("open (%s, %p)", unix_path, flags); + syscall_printf ("open (%s, %p, %p, %p)", unix_path, flags, mode, fileattr); myfault efault; if (efault.faulted (EFAULT)) /* errno already set */; @@ -558,30 +555,36 @@ open (const char *unix_path, int flags, set_errno (ENOENT); else { - /* check for optional mode argument */ - va_start (ap, flags); - mode = va_arg (ap, mode_t); - va_end (ap); - fhandler_base *fh; cygheap_fdnew fd; if (fd >= 0) { if (!(fh = build_fh_name (unix_path, NULL, PC_SYM_FOLLOW))) - res = -1; // errno already set - else if (((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) && fh->exists ()) + { + res = -1; // errno already set + goto out; + } + else if (((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) + && fh->exists ()) { delete fh; res = -1; set_errno (EEXIST); + goto out; } else if (fh->is_fs_special () && fh->device_access_denied (flags)) { delete fh; res = -1; + goto out; } - else if (!fh->open (flags, (mode & 07777) & ~cygheap->umask)) + + if (static_cast<DWORD &>(*fh) == INVALID_FILE_ATTRIBUTES) + static_cast<DWORD &>(*fh) = fileattr; + else + static_cast<DWORD &>(*fh) = static_cast<DWORD &>(*fh) | fileattr; + if (!fh->open (flags, (mode & 07777) & ~cygheap->umask)) { delete fh; res = -1; @@ -595,10 +598,31 @@ open (const char *unix_path, int flags, } } - syscall_printf ("%d = open (%s, %p)", res, unix_path, flags); + out: + syscall_printf ("%d = open (%s, %p, %p, %p)", res, unix_path, flags, mode, + fileattr); return res; } + +/* _open */ +/* newlib's fcntl.h defines _open as taking variable args so we must + correspond. The third arg if it exists is: mode_t mode. */ +extern "C" int +open (const char *unix_path, int flags, ...) +{ + va_list ap; + int ret; + mode_t mode; + + va_start (ap, flags); + mode = flags & O_CREAT ? va_arg (ap, mode_t) : 0; + ret = open_with_attributes (unix_path, flags, mode, FILE_ATTRIBUTE_NORMAL); + va_end (ap); + + return ret; +} + EXPORT_ALIAS (open, _open ) EXPORT_ALIAS (open, _open64 )
2005-07-22 Vaclav Haisman <[EMAIL PROTECTED]> * syscalls.cc (open_with_attributes): Rename open() to open_with_attributes(). Add fileattr parameter and use it. Add explicit mode_t parameter for mode. Tweak debugging syscall_printf() calls to reflect the new parameter. (open): Reimplement using open_with_attributes(). * fhandler.cc (fhandler_base::open): Use pc.file_attributes() when opening disk file. * mktemp.cc (_gettemp): Set FILE_ATTRIBUTE_TEMPORARY on WinNT using open_with_attributes().