From 26d513086990d8ead515c676d1f5b984fc304548 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 30 Jun 2009 00:48:15 +0200 Subject: [PATCH] losetup: fix return codes of functions arounf is_associated() Signed-off-by: Karel Zak --- mount/lomount.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/mount/lomount.c b/mount/lomount.c index 1b191ab7..f0f81ed6 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -500,8 +500,7 @@ show_associated_loop_devices(char *filename, unsigned long long offset, int isof /* check if the loopfile is already associated with the same given * parameters. * - * returns: -1 error - * 0 unused + * returns: 0 unused / error * 1 loop device already used */ static int @@ -516,17 +515,15 @@ is_associated(int dev, struct stat *file, unsigned long long offset, int isoff) file->st_ino == linfo64.lo_inode && (isoff == 0 || offset == linfo64.lo_offset)) ret = 1; - return ret; - } - if (ioctl(dev, LOOP_GET_STATUS, &linfo) == 0) { + + } else if (ioctl(dev, LOOP_GET_STATUS, &linfo) == 0) { if (file->st_dev == linfo.lo_device && file->st_ino == linfo.lo_inode && (isoff == 0 || offset == linfo.lo_offset)) ret = 1; - return ret; } - return errno == ENXIO ? 0 : -1; + return ret; } /* check if the loop file is already used with the same given @@ -572,18 +569,14 @@ loopfile_used_with(char *devname, const char *filename, unsigned long long offse if (!is_loop_device(devname)) return 0; - if (stat(filename, &statbuf) == -1) { - perror(filename); - return -1; - } + if (stat(filename, &statbuf) == -1) + return 0; fd = open(devname, O_RDONLY); - if (fd == -1) { - perror(devname); - return -1; - } - ret = is_associated(fd, &statbuf, offset, 1); + if (fd == -1) + return 0; + ret = is_associated(fd, &statbuf, offset, 1); close(fd); return ret; } -- 2.39.5