This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Create new files as sparse on NT. (fwd)


Hi,
this little patch makes Cygwin create new files as sparse on NT systems.
There is no error checking for DeviceIoCotrol() result because there should be
no harm if it should fail only that the file will not be sparse.

This patch has only been tested on my WinXP box by running P2P sharing
program BitTorrent.

Vaclav Haisman


2003-02-01  Vaclav Haisman  <V.Haisman@sh.cvut.cz>
        * fhandler.cc (fhandler_base::open): Try to create new files as
        sparse on NT systems.

Index: cygwin/fhandler.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler.cc,v
retrieving revision 1.143
diff -c -r1.143 fhandler.cc
*** cygwin/fhandler.cc	20 Dec 2002 01:48:22 -0000	1.143
--- cygwin/fhandler.cc	1 Feb 2003 20:30:09 -0000
***************
*** 27,32 ****
--- 27,37 ----
  #include "pinfo.h"
  #include <assert.h>
  #include <limits.h>
+ #include <winioctl.h>
+
+ #define METHOD_BUFFERED 0
+ #define FSCTL_SET_SPARSE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 49, \
+   METHOD_BUFFERED, FILE_SPECIAL_ACCESS)

  static NO_COPY const int CHUNK_SIZE = 1024; /* Used for crlf conversions */

***************
*** 371,376 ****
--- 376,383 ----
    int shared;
    int creation_distribution;
    SECURITY_ATTRIBUTES sa = sec_none;
+   DWORD dw;
+   BOOL r;

    syscall_printf ("(%s, %p) query_open %d", get_win32_name (), flags, get_query_open ());

***************
*** 486,491 ****
--- 493,507 ----
        && !allow_ntsec && allow_ntea)
      set_file_attribute (has_acls (), get_win32_name (), mode);

+   /* Try to set newly created files as sparse on NT system. */
+   if (wincap.is_winnt () && (access & GENERIC_WRITE) == GENERIC_WRITE
+       && (flags & (O_CREAT | O_TRUNC)) && get_device () == FH_DISK)
+     {
+       r = DeviceIoControl(x, 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, x);
+     }
+
    set_io_handle (x);
    set_flags (flags, pc ? pc->binmode () : 0);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]