* kernels we have to check all loop devices to found unused one.
*
* See kernel commit 770fe30a46a12b6fb6b63fbe1737654d28e8484.
+ *
+ * Returns: 0 = success, < 0 error
*/
int loopcxt_find_unused(struct loopdev_cxt *lc)
{
ctl = open(_PATH_DEV_LOOPCTL, O_RDWR|O_CLOEXEC);
if (ctl >= 0)
rc = ioctl(ctl, LOOP_CTL_GET_FREE);
+ else
+ rc = -errno;
if (rc >= 0) {
char name[16];
snprintf(name, sizeof(name), "loop%d", rc);
rc = loopcxt_next(lc);
loopcxt_deinit_iterator(lc);
DBG(CXT, ul_debugobj(lc, "find_unused by scan [rc=%d]", rc));
+ if (rc)
+ return -ENOENT;
}
return rc;
}