summaryrefslogtreecommitdiffstats
path: root/lib/loopdev.c
diff options
context:
space:
mode:
authorTobias Stoeckmann2016-08-30 21:00:38 +0200
committerKarel Zak2016-08-31 09:49:01 +0200
commitcb129d9cc4a2ae39ba2b678bc511ff81d5023850 (patch)
tree9bd2787a9223de82f705fd384b48ee2b792f96ff /lib/loopdev.c
parentmount: add note about paths verification to mount.8 (diff)
downloadkernel-qcow2-util-linux-cb129d9cc4a2ae39ba2b678bc511ff81d5023850.tar.gz
kernel-qcow2-util-linux-cb129d9cc4a2ae39ba2b678bc511ff81d5023850.tar.xz
kernel-qcow2-util-linux-cb129d9cc4a2ae39ba2b678bc511ff81d5023850.zip
lib/loopdev: Set errno in is_loopdev on error
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@stoeckmann.org>
Diffstat (limited to 'lib/loopdev.c')
-rw-r--r--lib/loopdev.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/loopdev.c b/lib/loopdev.c
index b3941dd14..a57e7a73b 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;
}
/*