[LTP] [PATCH 2/2] fill_fs: Ensure written data is not easily compressed
Richard Palethorpe
rpalethorpe@suse.com
Tue Dec 6 12:53:29 CET 2022
If the stack is auto initialized to zero, then we will write all
zeros. Some FS may treat this as a special case and just record the
number of zero bytes or sectors.
This could alter the test behaviour in unpredictable ways. For example
a large number of (slow) syscalls may be required to fill up the
drive, extending the required test time. Or we could overflow the file
size/offset causing EFBIG.
So this writes random data to the buffer if it is zero.
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
Cc: Cyril Hrubis <chrubis@suse.cz>
---
lib/tst_fill_fs.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/lib/tst_fill_fs.c b/lib/tst_fill_fs.c
index 121dd2f20..ade0a52ba 100644
--- a/lib/tst_fill_fs.c
+++ b/lib/tst_fill_fs.c
@@ -16,13 +16,20 @@ void tst_fill_fs(const char *path, int verbose)
{
int i = 0;
char file[PATH_MAX];
- char buf[4096];
+ static char buf[4096];
size_t len;
ssize_t ret;
int fd;
struct statvfs fi;
+
statvfs(path, &fi);
+ if (!(buf[0] || buf[4095])) {
+ fd = SAFE_OPEN("/dev/urandom", O_RDONLY);
+ SAFE_READ(0, fd, buf, 4096);
+ SAFE_CLOSE(fd);
+ }
+
for (;;) {
len = random() % (1024 * 102400);
--
2.38.1
More information about the ltp
mailing list