summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/fhandler_disk_file.cc
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/fhandler_disk_file.cc')
-rw-r--r--winsup/cygwin/fhandler_disk_file.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index 8deb7fb16..27e621708 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -26,6 +26,7 @@ details. */
#include "pinfo.h"
#include <assert.h>
#include <ctype.h>
+#include <winioctl.h>
#define _COMPILING_NEWLIB
#include <dirent.h>
@@ -386,6 +387,19 @@ fhandler_disk_file::open (path_conv *real_path, int flags, mode_t mode)
return 0;
}
+ /* Set newly created and truncated files as sparse files. */
+ if ((real_path->fs_flags () & FILE_SUPPORTS_SPARSE_FILES)
+ && (get_access () & GENERIC_WRITE) == GENERIC_WRITE
+ && (get_flags () & (O_CREAT | O_TRUNC)))
+ {
+ DWORD dw;
+ HANDLE h = get_handle ();
+ BOOL r = DeviceIoControl (h , FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &dw,
+ NULL);
+ syscall_printf ("%d = DeviceIoControl(0x%x, FSCTL_SET_SPARSE, NULL, 0, "
+ "NULL, 0, &dw, NULL)", r, h);
+ }
+
set_symlink_p (real_path->issymlink ());
set_execable_p (real_path->exec_state ());
set_socket_p (real_path->issocket ());