[PATCH] Set errno in is_loopdev on error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The function is_loopdev does not set errno if the supplied string does
not reference a valid loop device. Fix this to avoid an error message
like this one:

losetup: /: failed to use device: Success

I prefer this one:

losetup: /: failed to use device: No such device

Signed-off-by: Tobias Stoeckmann <tobias@xxxxxxxxxxxxxx>
---
 lib/loopdev.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/loopdev.c b/lib/loopdev.c
index b3941dd..a57e7a7 100644
--- a/lib/loopdev.c
+++ b/lib/loopdev.c
@@ -633,12 +633,13 @@ int is_loopdev(const char *device)
 {
 	struct stat st;
 
-	if (!device)
-		return 0;
-
-	return (stat(device, &st) == 0 &&
+	if (device && stat(device, &st) == 0 &&
 		S_ISBLK(st.st_mode) &&
-		major(st.st_rdev) == LOOPDEV_MAJOR);
+		major(st.st_rdev) == LOOPDEV_MAJOR)
+		return 1;
+
+	errno = ENODEV;
+	return 0;
 }
 
 /*
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux