Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2023-11-28 12:42:52 +0300
committerCorinna Vinschen <corinna@vinschen.de>2023-11-28 12:55:38 +0300
commit65831f88d6c4cd943969b5ee531bc6162c7b0f60 (patch)
tree11b0b37fb95d53171d0f10df0d6a6d9812ad6b67 /winsup/cygwin/local_includes/fhandler.h
parentf64f3eced8e0f51753bc199f3ba96fab06a54848 (diff)
Cygwin: fallocate(2): handle FALLOC_FL_PUNCH_HOLE and FALLOC_FL_ZERO_RANGE
Split fhandler_disk_file::fallocate into multiple methods, each implementing a different aspect of fallocate(2), thus adding FALLOC_FL_PUNCH_HOLE and FALLOC_FL_ZERO_RANGE handling. For more correctly implementing posix_fallocate(3) semantics, make sure to re-allocate holes in the given range if the file is sparse. While at it, change the way checking when to make a file sparse. The rule is now, make file sparse if the hole created by the action spans at least one sparse block, taking the allocation granularity of sparse files into account. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin/local_includes/fhandler.h')
-rw-r--r--winsup/cygwin/local_includes/fhandler.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h
index 54e0c6e80..1dc02608b 100644
--- a/winsup/cygwin/local_includes/fhandler.h
+++ b/winsup/cygwin/local_includes/fhandler.h
@@ -14,6 +14,7 @@ details. */
#include <cygwin/_socketflags.h>
#include <cygwin/_ucred.h>
#include <sys/un.h>
+#include <sys/param.h>
/* It appears that 64K is the block size used for buffered I/O on NT.
Using this blocksize in read/write calls in the application results
@@ -37,6 +38,15 @@ details. */
ERROR_NOT_ENOUGH_MEMORY occurs in win7 if this value is used. */
#define INREC_SIZE 2048
+/* Helper function to allow checking if some offset in a file is so far
+ beyond EOF, that at least one sparse chunk fits into the span. */
+inline bool
+span_sparse_chunk (off_t new_pos, off_t old_eof)
+{
+ return roundup2 (old_eof, FILE_SPARSE_GRANULARITY) + FILE_SPARSE_GRANULARITY
+ <= rounddown (new_pos, FILE_SPARSE_GRANULARITY);
+}
+
extern const char *windows_device_names[];
extern struct __cygwin_perfile *perfile_table;
#define __fmode (*(user_data->fmode_ptr))
@@ -1708,6 +1718,10 @@ class fhandler_disk_file: public fhandler_base
uint64_t fs_ioc_getflags ();
int fs_ioc_setflags (uint64_t);
+ falloc_allocate (int, off_t, off_t);
+ falloc_punch_hole (off_t, off_t);
+ falloc_zero_range (int, off_t, off_t);
+
public:
fhandler_disk_file ();
fhandler_disk_file (path_conv &pc);