-static int _crypt_init(struct crypt_device **cd,
- const char *type,
- struct crypt_options *options,
- int load, int need_dm)
-{
- int init_by_name, r;
-
- /* if it is plain device and mapping table is being reloaded
- initialize it by name*/
- init_by_name = (type && !strcmp(type, CRYPT_PLAIN) && load);
-
- /* Some of old API calls do not require DM in kernel,
- fake initialisation by initialise it with kernel_check disabled */
- if (!need_dm)
- (void)dm_init(NULL, 0);
- if (init_by_name)
- r = crypt_init_by_name(cd, options->name);
- else
- r = crypt_init(cd, options->device);
- if (!need_dm)
- dm_exit();
-
- if (r)
- return -EINVAL;
-
- crypt_set_log_callback(*cd, log_wrapper, options->icb->log);
- crypt_set_confirm_callback(*cd, yesDialog_wrapper, options->icb->yesDialog);
-
- crypt_set_timeout(*cd, options->timeout);
- crypt_set_password_retry(*cd, options->tries);
- crypt_set_iterarion_time(*cd, options->iteration_time ?: 1000);
- crypt_set_password_verify(*cd, options->flags & CRYPT_FLAG_VERIFY);
-
- if (load && !init_by_name)
- r = crypt_load(*cd, type, NULL);
-
- if (!r && type && !(*cd)->type) {
- (*cd)->type = strdup(type);
- if (!(*cd)->type)
- r = -ENOMEM;
- }
-
- if (r)
- crypt_free(*cd);
-
- return r;
-}
-