From de26ef4f87c55b291e284c3a644e0cb2cca62352 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 27 Jul 2017 19:41:22 -0400 Subject: [PATCH] libext2fs: fix error handling for ext2fs_sync_device() Return the proper error code instead of -1. Signed-off-by: Theodore Ts'o --- lib/ext2fs/flushb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ext2fs/flushb.c b/lib/ext2fs/flushb.c index 98821fc..1b9c671 100644 --- a/lib/ext2fs/flushb.c +++ b/lib/ext2fs/flushb.c @@ -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; } -- 1.8.3.1