* names ("loop<N>") are converted to the path (/dev/loop<N> or to
* /dev/loop/<N>)
*
+ * This sets the device name, but does not check if the device exists!
+ *
* Returns: <0 on error, 0 on success
*/
int loopcxt_set_device(struct loopdev_cxt *lc, const char *device)
strncpy(lc->device, device, sizeof(lc->device));
lc->device[sizeof(lc->device) - 1] = '\0';
}
- DBG(lc, loopdev_debug("%s successfully assigned", device));
+ DBG(lc, loopdev_debug("%s name assigned", device));
}
sysfs_deinit(&lc->sysfs);
!(lc->iter.flags & LOOPITER_FL_FREE))
return 0; /* caller does not care about device status */
+ if (!is_loopdev(lc->device)) {
+ DBG(lc, loopdev_debug("iter: %s does not exist", lc->device));
+ return -errno;
+ }
+
+ DBG(lc, loopdev_debug("iter: %s exist", lc->device));
+
used = loopcxt_get_offset(lc, NULL) == 0;
if ((lc->iter.flags & LOOPITER_FL_USED) && used)
if ((lc->iter.flags & LOOPITER_FL_FREE) && !used)
return 0;
- DBG(lc, loopdev_debug("iter: unset device"));
+ DBG(lc, loopdev_debug("iter: failed to use %s device", lc->device));
ignore_result( loopcxt_set_device(lc, NULL) );
return 1;
}
{
int fd;
- if (!lc || lc->info_failed)
+ if (!lc || lc->info_failed) {
+ errno = EINVAL;
return NULL;
+ }
+ errno = 0;
if (lc->has_info)
return &lc->info;
lc->info_failed = 0;
DBG(lc, loopdev_debug("reading loop_info64 OK"));
return &lc->info;
- } else {
- lc->info_failed = 1;
- DBG(lc, loopdev_debug("reading loop_info64 FAILED"));
}
+ lc->info_failed = 1;
+ DBG(lc, loopdev_debug("reading loop_info64 FAILED"));
+
return NULL;
}
if (offset)
*offset = lo->lo_offset;
rc = 0;
- }
+ } else
+ rc = -errno;
}
DBG(lc, loopdev_debug("get_offset [rc=%d]", rc));
if (size)
*size = lo->lo_sizelimit;
rc = 0;
- }
+ } else
+ rc = -errno;
}
DBG(lc, loopdev_debug("get_sizelimit [rc=%d]", rc));
int loopcxt_get_encrypt_type(struct loopdev_cxt *lc, uint32_t *type)
{
struct loop_info64 *lo = loopcxt_get_info(lc);
- int rc = -EINVAL;
+ int rc;
+ /* not provided by sysfs */
if (lo) {
if (type)
*type = lo->lo_encrypt_type;
rc = 0;
- }
+ } else
+ rc = -errno;
+
DBG(lc, loopdev_debug("get_encrypt_type [rc=%d]", rc));
return rc;
}
int loopcxt_get_backing_devno(struct loopdev_cxt *lc, dev_t *devno)
{
struct loop_info64 *lo = loopcxt_get_info(lc);
- int rc = -EINVAL;
+ int rc;
if (lo) {
if (devno)
*devno = lo->lo_device;
rc = 0;
- }
+ } else
+ rc = -errno;
+
DBG(lc, loopdev_debug("get_backing_devno [rc=%d]", rc));
return rc;
}
int loopcxt_get_backing_inode(struct loopdev_cxt *lc, ino_t *ino)
{
struct loop_info64 *lo = loopcxt_get_info(lc);
- int rc = -EINVAL;
+ int rc;
if (lo) {
if (ino)
*ino = lo->lo_inode;
rc = 0;
- }
+ } else
+ rc = -errno;
+
DBG(lc, loopdev_debug("get_backing_inode [rc=%d]", rc));
return rc;
}