summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-08-19 17:22:18 +0200
committerLennart Poettering <lennart@poettering.net>2021-08-20 21:56:59 +0200
commitbf284aee235247b71fbd62b331d35ff9f7907775 (patch)
tree47d637d3f3888a865211734913f2ddc1857c40d0
parent53e03c9692505384ed4ec743791ddf2ba18a455f (diff)
downloadsystemd-bf284aee235247b71fbd62b331d35ff9f7907775.tar.gz
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)
-rw-r--r--src/import/import-raw.c2
-rw-r--r--src/import/pull-job.c2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/import/import-raw.c b/src/import/import-raw.c
index 9c2c74527f..fcb07751d2 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 fb869e7095..4e37dce33f 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);