diff mbox

libext2fs: return errno on failure in ext2fs_sync_device()

Message ID 1452443341-1851-1-git-send-email-guaneryu@gmail.com
State Superseded
Headers show

Commit Message

Eryu Guan Jan. 10, 2016, 4:29 p.m. UTC
ext2fs_sync_device() returns -1 on ioctl error, which is the return
value from ioctl, but the callers expect the return value to be an errno
on failure.

Seen this while flushing in e2fsck on a file:

[root@localhost e2fsprogs]# e2fsck -Ff ~/ext4.img
ext2fs_sync_device: Unknown code ____ 255 while trying to flush /root/ext4.img

After fixing, correct error message is printed:

[root@localhost e2fsprogs]# e2fsck -Ff ~/ext4.img
ext2fs_sync_device: Inappropriate ioctl for device while trying to flush /root/ext4.img

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
---
 lib/ext2fs/flushb.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Eryu Guan March 7, 2016, 3:31 a.m. UTC | #1
On Mon, Jan 11, 2016 at 12:29:01AM +0800, Eryu Guan wrote:
> ext2fs_sync_device() returns -1 on ioctl error, which is the return
> value from ioctl, but the callers expect the return value to be an errno
> on failure.
> 
> Seen this while flushing in e2fsck on a file:
> 
> [root@localhost e2fsprogs]# e2fsck -Ff ~/ext4.img
> ext2fs_sync_device: Unknown code ____ 255 while trying to flush /root/ext4.img
> 
> After fixing, correct error message is printed:
> 
> [root@localhost e2fsprogs]# e2fsck -Ff ~/ext4.img
> ext2fs_sync_device: Inappropriate ioctl for device while trying to flush /root/ext4.img
> 
> Signed-off-by: Eryu Guan <guaneryu@gmail.com>

ping on this one :)

Eryu

> ---
>  lib/ext2fs/flushb.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/ext2fs/flushb.c b/lib/ext2fs/flushb.c
> index 98821fc..c62b659 100644
> --- a/lib/ext2fs/flushb.c
> +++ b/lib/ext2fs/flushb.c
> @@ -52,6 +52,7 @@
>   */
>  errcode_t ext2fs_sync_device(int fd, int flushb)
>  {
> +	int ret = 0;
>  	/*
>  	 * We always sync the device in case we're running on old
>  	 * kernels for which we can lose data if we don't.  (There
> @@ -66,14 +67,18 @@ errcode_t ext2fs_sync_device(int fd, int flushb)
>  #ifdef BLKFLSBUF
>  		if (ioctl (fd, BLKFLSBUF, 0) == 0)
>  			return 0;
> +		ret = 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;
> +		ret = errno;
>  #elif defined(__linux__)
>  #warning FDFLUSH not defined
>  #endif
>  	}
> -	return 0;
> +	return ret;
>  }
> -- 
> 1.8.3.1
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/lib/ext2fs/flushb.c b/lib/ext2fs/flushb.c
index 98821fc..c62b659 100644
--- a/lib/ext2fs/flushb.c
+++ b/lib/ext2fs/flushb.c
@@ -52,6 +52,7 @@ 
  */
 errcode_t ext2fs_sync_device(int fd, int flushb)
 {
+	int ret = 0;
 	/*
 	 * We always sync the device in case we're running on old
 	 * kernels for which we can lose data if we don't.  (There
@@ -66,14 +67,18 @@  errcode_t ext2fs_sync_device(int fd, int flushb)
 #ifdef BLKFLSBUF
 		if (ioctl (fd, BLKFLSBUF, 0) == 0)
 			return 0;
+		ret = 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;
+		ret = errno;
 #elif defined(__linux__)
 #warning FDFLUSH not defined
 #endif
 	}
-	return 0;
+	return ret;
 }