From: Theodore Ts'o Date: Thu, 27 Jul 2017 23:41:22 +0000 (-0400) Subject: libext2fs: fix error handling for ext2fs_sync_device() X-Git-Tag: v1.43.5~18 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=de26ef4f87c55b291e284c3a644e0cb2cca62352;p=tools%2Fe2fsprogs.git libext2fs: fix error handling for ext2fs_sync_device() Return the proper error code instead of -1. Signed-off-by: Theodore Ts'o --- 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; }