-
Notifications
You must be signed in to change notification settings - Fork 162
Open
Description
The method used to avoid that f3read reads previously cached data does not work on Cygwin. This may result in false positive tests. Here is the local patch used for the new Cygwin package f3-8.0-2:
From c85e6f20d1de2c5cab358929e490d760e50e41d1 Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Mon, 27 Jan 2025 12:04:17 +0100
Subject: [PATCH] f3read: ensure unbuffered reads also on Cygwin
Use O_DIRECT because POSIX_FADV_DONTNEED etc. have not the desired
effect.
---
f3read.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/f3read.c b/f3read.c
index 7537b2e..fd670c5 100644
--- a/f3read.c
+++ b/f3read.c
@@ -1,5 +1,8 @@
#define _POSIX_C_SOURCE 200112L
#define _XOPEN_SOURCE 600
+#ifdef __CYGWIN__
+#define _BSD_SOURCE /* required for O_DIRECT */
+#endif
#include <assert.h>
#include <stdint.h>
@@ -243,16 +246,18 @@ static void validate_file(const char *path, int number, struct flow *fw,
printf("Validating file %s ... ", filename);
fflush(stdout);
#ifdef __CYGWIN__
- /* We don't need write access, but some kernels require that
- * the file descriptor passed to fdatasync(2) to be writable.
+ /* On Cygwin, the fdatasync() and posix_fadvise() calls below do
+ * not have the desired effect. Use O_DIRECT instead to avoid
+ * read caching.
*/
- fd = open(full_fn, O_RDWR);
+ fd = open(full_fn, O_RDONLY | O_DIRECT);
#else
fd = open(full_fn, O_RDONLY);
#endif
if (fd < 0)
err(errno, "Can't open file %s", full_fn);
+#ifndef __CYGWIN__
/* If the kernel follows our advice, f3read won't ever read from cache
* even when testing small memory cards without a remount, and
* we should have a better reading-speed measurement.
@@ -262,6 +267,7 @@ static void validate_file(const char *path, int number, struct flow *fw,
/* Help the kernel to help us. */
assert(!posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL));
+#endif
saved_errno = 0;
expected_offset = (uint64_t)number * GIGABYTES;
--
2.45.1BTW: It may make sense to use the (non-POSIX) flag O_DIRECT on all platforms supporting it (Linux, *BSD, ...).
POSIX 2024 says about posix_fadvise(): The implementation may use this information to optimize handling of the specified data.
Metadata
Metadata
Assignees
Labels
No labels