Whamcloud - gitweb
libext2fs: fix error handling for ext2fs_sync_device()
authorTheodore Ts'o <tytso@mit.edu>
Thu, 27 Jul 2017 23:41:22 +0000 (19:41 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 27 Jul 2017 23:41:22 +0000 (19:41 -0400)
Return the proper error code instead of -1.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/flushb.c

index 98821fc..1b9c671 100644 (file)
@@ -62,18 +62,25 @@ errcode_t ext2fs_sync_device(int fd, int flushb)
                return errno;
 
        if (flushb) {
+               errcode_t       retval = 0;
 
 #ifdef BLKFLSBUF
                if (ioctl (fd, BLKFLSBUF, 0) == 0)
                        return 0;
+               retval = errno;
 #elif defined(__linux__)
 #warning BLKFLSBUF not defined
 #endif
 #ifdef FDFLUSH
-               return ioctl(fd, FDFLUSH, 0);   /* In case this is a floppy */
+               /* In case this is a floppy */
+               if (ioctl(fd, FDFLUSH, 0) == 0)
+                       return 0;
+               if (retval == 0)
+                       retval = errno;
 #elif defined(__linux__)
 #warning FDFLUSH not defined
 #endif
+               return retval;
        }
        return 0;
 }