filename);
}
+static int find_unused(struct loopdev_cxt *lc)
+{
+ int rc;
+
+ rc = loopcxt_find_unused(lc);
+ if (!rc)
+ return 0;
+
+ if (access(_PATH_DEV_LOOPCTL, F_OK) == 0 &&
+ access(_PATH_DEV_LOOPCTL, W_OK) != 0)
+ ;
+ else
+ errno = -rc;
+
+ warn(_("cannot find an unused loop device"));
+
+ return rc;
+}
+
static int create_loop(struct loopdev_cxt *lc,
int nooverlap, int lo_flags, int flags,
const char *file, uint64_t offset, uint64_t sizelimit,
/* Note that loopcxt_{find_unused,set_device}() resets
* loopcxt struct.
*/
- if (!hasdev && (rc = loopcxt_find_unused(lc))) {
- warnx(_("cannot find an unused loop device"));
+ if (!hasdev && (rc = find_unused(lc)))
break;
- }
if (flags & LOOPDEV_FL_OFFSET)
loopcxt_set_offset(lc, offset);
if (flags & LOOPDEV_FL_SIZELIMIT)
res = delete_all_loops(&lc);
break;
case A_FIND_FREE:
- res = loopcxt_find_unused(&lc);
- if (res) {
- int errsv = errno;
-
- if (access(_PATH_DEV_LOOPCTL, F_OK) == 0 &&
- access(_PATH_DEV_LOOPCTL, W_OK) != 0)
- ;
- else
- errno = errsv;
-
- warn(_("cannot find an unused loop device"));
- } else
+ res = find_unused(&lc);
+ if (!res)
printf("%s\n", loopcxt_get_device(&lc));
break;
case A_SHOW: