]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_fsr: test for more potential failures in packfile()
authorEric Sandeen <sandeen@sandeen.net>
Thu, 19 Jun 2014 02:13:23 +0000 (12:13 +1000)
committerDave Chinner <david@fromorbit.com>
Thu, 19 Jun 2014 02:13:23 +0000 (12:13 +1000)
Test for lseek, ftruncate, and fsync failures in packfile()

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fsr/xfs_fsr.c

index 8b191e65f242ed541424662e20d4c58992c8871d..48629fde101e35e48ed385037aca1b650bdfc775 100644 (file)
@@ -1325,7 +1325,11 @@ packfile(char *fname, char *tname, int fd,
                                fsrprintf(_("could not trunc tmp %s\n"),
                                           tname);
                        }
-                       lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR);
+                       if (lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR) < 0) {
+                               fsrprintf(_("could not lseek in tmpfile: %s : %s\n"),
+                                  tname, strerror(errno));
+                               goto out;
+                       }
                        continue;
                } else if (outmap[extent].bmv_length == 0) {
                        /* to catch holes at the beginning of the file */
@@ -1341,7 +1345,11 @@ packfile(char *fname, char *tname, int fd,
                                        " %s\n"), tname);
                                goto out;
                        }
-                       lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR);
+                       if (lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR) < 0) {
+                               fsrprintf(_("could not lseek in tmpfile: %s : %s\n"),
+                                  tname, strerror(errno));
+                               goto out;
+                       }
                }
        } /* end of space allocation loop */
 
@@ -1365,8 +1373,16 @@ packfile(char *fname, char *tname, int fd,
        for (extent = 0; extent < nextents; extent++) {
                pos = outmap[extent].bmv_offset;
                if (outmap[extent].bmv_block == -1) {
-                       lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR);
-                       lseek64(fd, outmap[extent].bmv_length, SEEK_CUR);
+                       if (lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR) < 0) {
+                               fsrprintf(_("could not lseek in tmpfile: %s : %s\n"),
+                                  tname, strerror(errno));
+                               goto out;
+                       }
+                       if (lseek64(fd, outmap[extent].bmv_length, SEEK_CUR) < 0) {
+                               fsrprintf(_("could not lseek in file: %s : %s\n"),
+                                  fname, strerror(errno));
+                               goto out;
+                       }
                        continue;
                } else if (outmap[extent].bmv_length == 0) {
                        /* to catch holes at the beginning of the file */
@@ -1442,8 +1458,16 @@ packfile(char *fname, char *tname, int fd,
                        }
                }
        }
-       ftruncate64(tfd, statp->bs_size);
-       fsync(tfd);
+       if (ftruncate64(tfd, statp->bs_size) < 0) {
+               fsrprintf(_("could not truncate tmpfile: %s : %s\n"),
+                               fname, strerror(errno));
+               goto out;
+       }
+       if (fsync(tfd) < 0) {
+               fsrprintf(_("could not fsync tmpfile: %s : %s\n"),
+                               fname, strerror(errno));
+               goto out;
+       }
 
        sx.sx_stat     = *statp; /* struct copy */
        sx.sx_version  = XFS_SX_VERSION;