From bf284aee235247b71fbd62b331d35ff9f7907775 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 19 Aug 2021 17:22:18 +0200 Subject: [PATCH] import: enable sparse file writing logic only for files we create Only if we create a file we know for sure that it is empty and hence our sparse file logic of skipping over NUL bytes can can work. If we hwoever are called to write data to some existing file/block device, we must do regular writes to override everything that might be in place before. Hence, conditionalize sparse file writing on the write offset not being configured (which is how we internally distinguish write to existing file and write to new file) --- src/import/import-raw.c | 2 +- src/import/pull-job.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/import/import-raw.c b/src/import/import-raw.c index 9c2c74527fe..fcb07751d20 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -368,7 +368,7 @@ static int raw_import_write(const void *p, size_t sz, void *userdata) { } /* Generate sparse file if we created/truncated the file */ - if (S_ISREG(i->output_stat.st_mode)) { + if (S_ISREG(i->output_stat.st_mode) && i->offset == UINT64_MAX) { ssize_t n; n = sparse_write(i->output_fd, p, sz, 64); diff --git a/src/import/pull-job.c b/src/import/pull-job.c index fb869e7095f..4e37dce33f5 100644 --- a/src/import/pull-job.c +++ b/src/import/pull-job.c @@ -306,7 +306,7 @@ static int pull_job_write_uncompressed(const void *p, size_t sz, void *userdata) if (j->disk_fd >= 0) { - if (S_ISREG(j->disk_stat.st_mode)) { + if (S_ISREG(j->disk_stat.st_mode) && j->offset == UINT64_MAX) { ssize_t n; n = sparse_write(j->disk_fd, p, sz, 64); -- 2.47.3