]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
import: enable sparse file writing logic only for files we create
authorLennart Poettering <lennart@poettering.net>
Thu, 19 Aug 2021 15:22:18 +0000 (17:22 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 20 Aug 2021 19:56:59 +0000 (21:56 +0200)
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
src/import/pull-job.c

index 9c2c74527fef57d44792e31f26dfe11e50d8291f..fcb07751d20d30fa43054106b85555c70a355a26 100644 (file)
@@ -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);
index fb869e7095f5408e2f4146a7c0101f2a00155c5d..4e37dce33f5b764e9fab6ba0f6ea024d66109d63 100644 (file)
@@ -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);