]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/import/import-raw.c
tree-wide: check if return value of lseek() and friends is negative
[thirdparty/systemd.git] / src / import / import-raw.c
index 30f5b9050ba5803eb24b30a490d0747c0049a714..2db3198ba6123fa32c7580ba3e3a9ffe6a15ae9f 100644 (file)
@@ -25,7 +25,6 @@
 #include "rm-rf.h"
 #include "string-util.h"
 #include "tmpfile-util.h"
-#include "util.h"
 
 struct RawImport {
         sd_event *event;
@@ -106,8 +105,8 @@ int raw_import_new(
                 return -ENOMEM;
 
         *i = (RawImport) {
-                .input_fd = -1,
-                .output_fd = -1,
+                .input_fd = -EBADF,
+                .output_fd = -EBADF,
                 .on_finished = on_finished,
                 .userdata = userdata,
                 .last_percent = UINT_MAX,
@@ -155,7 +154,7 @@ static void raw_import_report_progress(RawImport *i) {
 }
 
 static int raw_import_maybe_convert_qcow2(RawImport *i) {
-        _cleanup_close_ int converted_fd = -1;
+        _cleanup_close_ int converted_fd = -EBADF;
         _cleanup_(unlink_and_freep) char *t = NULL;
         _cleanup_free_ char *f = NULL;
         int r;
@@ -235,7 +234,7 @@ static int raw_import_finish(RawImport *i) {
 
                 if (S_ISREG(i->input_stat.st_mode)) {
                         (void) copy_times(i->input_fd, i->output_fd, COPY_CRTIME);
-                        (void) copy_xattr(i->input_fd, i->output_fd, 0);
+                        (void) copy_xattr(i->input_fd, NULL, i->output_fd, NULL, 0);
                 }
         }
 
@@ -304,7 +303,7 @@ static int raw_import_open_disk(RawImport *i) {
                                        "Target file is not a regular file or block device");
 
         if (i->offset != UINT64_MAX) {
-                if (lseek(i->output_fd, i->offset, SEEK_SET) == (off_t) -1)
+                if (lseek(i->output_fd, i->offset, SEEK_SET) < 0)
                         return log_error_errno(errno, "Failed to seek to offset: %m");
         }
 
@@ -329,14 +328,14 @@ static int raw_import_try_reflink(RawImport *i) {
                 return 0;
 
         p = lseek(i->input_fd, 0, SEEK_CUR);
-        if (p == (off_t) -1)
+        if (p < 0)
                 return log_error_errno(errno, "Failed to read file offset of input file: %m");
 
         /* Let's only try a btrfs reflink, if we are reading from the beginning of the file */
         if ((uint64_t) p != (uint64_t) i->buffer_size)
                 return 0;
 
-        r = btrfs_reflink(i->input_fd, i->output_fd);
+        r = reflink(i->input_fd, i->output_fd);
         if (r >= 0)
                 return 1;
 
@@ -379,7 +378,7 @@ static int raw_import_write(const void *p, size_t sz, void *userdata) {
                 if ((size_t) n < sz)
                         return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short write");
         } else {
-                r = loop_write(i->output_fd, p, sz, false);
+                r = loop_write(i->output_fd, p, sz);
                 if (r < 0)
                         return log_error_errno(r, "Failed to write file: %m");
         }