- h->loop_fd = -1;
-
- if (device) {
- r = device_ready(NULL, device, O_RDONLY);
- if (r == -ENOTBLK) {
- h->device = crypt_loop_get_device();
- log_dbg("Not a block device, %s%s.",
- h->device ? "using free loop device " :
- "no free loop device found",
- h->device ?: "");
- if (!h->device) {
- log_err(NULL, _("Cannot find a free loopback device.\n"));
- r = -ENOSYS;
- goto bad;
- }
-
- /* Keep the loop open, dettached on last close. */
- h->loop_fd = crypt_loop_attach(h->device, device, 0, 1, &readonly);
- if (h->loop_fd == -1) {
- log_err(NULL, _("Attaching loopback device failed "
- "(loop device with autoclear flag is required).\n"));
- r = -EINVAL;
- goto bad;
- }