mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Add context to DM helpers.
(To be used later.)
This commit is contained in:
@@ -425,7 +425,8 @@ error:
|
||||
return r;
|
||||
}
|
||||
|
||||
int dm_remove_device(const char *name, int force, uint64_t size)
|
||||
int dm_remove_device(struct crypt_device *cd, const char *name,
|
||||
int force, uint64_t size)
|
||||
{
|
||||
int r = -EINVAL;
|
||||
int retries = force ? RETRY_COUNT : 1;
|
||||
@@ -574,7 +575,7 @@ out:
|
||||
}
|
||||
|
||||
if (r < 0 && !reload)
|
||||
dm_remove_device(name, 0, 0);
|
||||
_dm_simple(DM_DEVICE_REMOVE, name, 1);
|
||||
|
||||
out_no_removal:
|
||||
if (cookie && _dm_use_udev())
|
||||
@@ -589,7 +590,7 @@ out_no_removal:
|
||||
return r;
|
||||
}
|
||||
|
||||
int dm_create_device(const char *name,
|
||||
int dm_create_device(struct crypt_device *cd, const char *name,
|
||||
const char *type,
|
||||
struct crypt_dm_active_device *dmd,
|
||||
int reload)
|
||||
@@ -658,7 +659,7 @@ out:
|
||||
return r;
|
||||
}
|
||||
|
||||
int dm_status_device(const char *name)
|
||||
int dm_status_device(struct crypt_device *cd, const char *name)
|
||||
{
|
||||
int r;
|
||||
struct dm_info dmi;
|
||||
@@ -670,7 +671,7 @@ int dm_status_device(const char *name)
|
||||
return (dmi.open_count > 0);
|
||||
}
|
||||
|
||||
int dm_status_suspended(const char *name)
|
||||
int dm_status_suspended(struct crypt_device *cd, const char *name)
|
||||
{
|
||||
int r;
|
||||
struct dm_info dmi;
|
||||
@@ -682,7 +683,7 @@ int dm_status_suspended(const char *name)
|
||||
return dmi.suspended ? 1 : 0;
|
||||
}
|
||||
|
||||
int dm_status_verity_ok(const char *name)
|
||||
static int _dm_status_verity_ok(const char *name)
|
||||
{
|
||||
int r;
|
||||
struct dm_info dmi;
|
||||
@@ -701,6 +702,11 @@ int dm_status_verity_ok(const char *name)
|
||||
return r;
|
||||
}
|
||||
|
||||
int dm_status_verity_ok(struct crypt_device *cd, const char *name)
|
||||
{
|
||||
return _dm_status_verity_ok(name);
|
||||
}
|
||||
|
||||
/* FIXME use hex wrapper, user val wrappers for line parsing */
|
||||
static int _dm_query_crypt(uint32_t get_flags,
|
||||
struct dm_info *dmi,
|
||||
@@ -926,8 +932,8 @@ static int _dm_query_verity(uint32_t get_flags,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dm_query_device(const char *name, uint32_t get_flags,
|
||||
struct crypt_dm_active_device *dmd)
|
||||
int dm_query_device(struct crypt_device *cd, const char *name,
|
||||
uint32_t get_flags, struct crypt_dm_active_device *dmd)
|
||||
{
|
||||
struct dm_task *dmt;
|
||||
struct dm_info dmi;
|
||||
@@ -968,7 +974,7 @@ int dm_query_device(const char *name, uint32_t get_flags,
|
||||
r = _dm_query_verity(get_flags, &dmi, params, dmd);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
r = dm_status_verity_ok(name);
|
||||
r = _dm_status_verity_ok(name);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
if (r == 0)
|
||||
@@ -1028,7 +1034,7 @@ static int _dm_message(const char *name, const char *msg)
|
||||
return r;
|
||||
}
|
||||
|
||||
int dm_suspend_and_wipe_key(const char *name)
|
||||
int dm_suspend_and_wipe_key(struct crypt_device *cd, const char *name)
|
||||
{
|
||||
if (!_dm_check_versions())
|
||||
return -ENOTSUP;
|
||||
@@ -1047,9 +1053,8 @@ int dm_suspend_and_wipe_key(const char *name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dm_resume_and_reinstate_key(const char *name,
|
||||
size_t key_size,
|
||||
const char *key)
|
||||
int dm_resume_and_reinstate_key(struct crypt_device *cd, const char *name,
|
||||
size_t key_size, const char *key)
|
||||
{
|
||||
int msg_size = key_size * 2 + 10; // key set <key>
|
||||
char *msg;
|
||||
|
||||
@@ -224,7 +224,7 @@ int LOOPAES_activate(struct crypt_device *cd,
|
||||
log_dbg("Trying to activate loop-AES device %s using cipher %s.",
|
||||
name, dmd.u.crypt.cipher);
|
||||
|
||||
r = dm_create_device(name, CRYPT_LOOPAES, &dmd, 0);
|
||||
r = dm_create_device(cd, name, CRYPT_LOOPAES, &dmd, 0);
|
||||
|
||||
if (!r && !(dm_flags() & req_flags)) {
|
||||
log_err(cd, _("Kernel doesn't support loop-AES compatible mapping.\n"));
|
||||
|
||||
@@ -85,7 +85,7 @@ static int setup_mapping(const char *cipher, const char *name,
|
||||
return -EACCES;
|
||||
}
|
||||
cleaner_size = dmd.size;
|
||||
return dm_create_device(name, "TEMP", &dmd, 0);
|
||||
return dm_create_device(ctx, name, "TEMP", &dmd, 0);
|
||||
}
|
||||
|
||||
static void sigint_handler(int sig __attribute__((unused)))
|
||||
@@ -94,7 +94,7 @@ static void sigint_handler(int sig __attribute__((unused)))
|
||||
close(devfd);
|
||||
devfd = -1;
|
||||
if(cleaner_name)
|
||||
dm_remove_device(cleaner_name, 1, cleaner_size);
|
||||
dm_remove_device(NULL, cleaner_name, 1, cleaner_size);
|
||||
|
||||
signal(SIGINT, SIG_DFL);
|
||||
kill(getpid(), SIGINT);
|
||||
@@ -171,7 +171,7 @@ static int LUKS_endec_template(char *src, size_t srcLength,
|
||||
close(devfd);
|
||||
devfd = -1;
|
||||
out2:
|
||||
dm_remove_device(cleaner_name, 1, cleaner_size);
|
||||
dm_remove_device(ctx, cleaner_name, 1, cleaner_size);
|
||||
out1:
|
||||
signal(SIGINT, SIG_DFL);
|
||||
cleaner_name = NULL;
|
||||
|
||||
@@ -1077,7 +1077,7 @@ int LUKS1_activate(struct crypt_device *cd,
|
||||
return -ENOMEM;
|
||||
|
||||
dmd.u.crypt.cipher = dm_cipher;
|
||||
r = dm_create_device(name, CRYPT_LUKS1, &dmd, 0);
|
||||
r = dm_create_device(cd, name, CRYPT_LUKS1, &dmd, 0);
|
||||
|
||||
free(dm_cipher);
|
||||
return r;
|
||||
|
||||
34
lib/setup.c
34
lib/setup.c
@@ -344,10 +344,10 @@ int PLAIN_activate(struct crypt_device *cd,
|
||||
log_dbg("Trying to activate PLAIN device %s using cipher %s.",
|
||||
name, dmd.u.crypt.cipher);
|
||||
|
||||
r = dm_create_device(name, CRYPT_PLAIN, &dmd, 0);
|
||||
r = dm_create_device(cd, name, CRYPT_PLAIN, &dmd, 0);
|
||||
|
||||
// FIXME
|
||||
if (!cd->plain_uuid && dm_query_device(name, DM_ACTIVE_UUID, &dmd) >= 0)
|
||||
if (!cd->plain_uuid && dm_query_device(cd, name, DM_ACTIVE_UUID, &dmd) >= 0)
|
||||
cd->plain_uuid = CONST_CAST(char*)dmd.uuid;
|
||||
|
||||
free(dm_cipher);
|
||||
@@ -662,7 +662,8 @@ static int _init_by_name_crypt(struct crypt_device *cd, const char *name)
|
||||
char cipher[MAX_CIPHER_LEN], cipher_mode[MAX_CIPHER_LEN];
|
||||
int key_nums, r;
|
||||
|
||||
r = dm_query_device(name, DM_ACTIVE_DEVICE |
|
||||
r = dm_query_device(cd, name,
|
||||
DM_ACTIVE_DEVICE |
|
||||
DM_ACTIVE_UUID |
|
||||
DM_ACTIVE_CRYPT_CIPHER |
|
||||
DM_ACTIVE_CRYPT_KEYSIZE, &dmd);
|
||||
@@ -734,7 +735,8 @@ static int _init_by_name_verity(struct crypt_device *cd, const char *name)
|
||||
};
|
||||
int r;
|
||||
|
||||
r = dm_query_device(name, DM_ACTIVE_DEVICE |
|
||||
r = dm_query_device(cd, name,
|
||||
DM_ACTIVE_DEVICE |
|
||||
DM_ACTIVE_UUID |
|
||||
DM_ACTIVE_VERITY_HASH_DEVICE |
|
||||
DM_ACTIVE_VERITY_PARAMS, &dmd);
|
||||
@@ -784,7 +786,7 @@ int crypt_init_by_name_and_header(struct crypt_device **cd,
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
r = dm_query_device(name, DM_ACTIVE_DEVICE | DM_ACTIVE_UUID, &dmd);
|
||||
r = dm_query_device(NULL, name, DM_ACTIVE_DEVICE | DM_ACTIVE_UUID, &dmd);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
|
||||
@@ -1228,7 +1230,7 @@ int crypt_resize(struct crypt_device *cd, const char *name, uint64_t new_size)
|
||||
|
||||
log_dbg("Resizing device %s to %" PRIu64 " sectors.", name, new_size);
|
||||
|
||||
r = dm_query_device(name, DM_ACTIVE_DEVICE | DM_ACTIVE_CRYPT_CIPHER |
|
||||
r = dm_query_device(cd, name, DM_ACTIVE_DEVICE | DM_ACTIVE_CRYPT_CIPHER |
|
||||
DM_ACTIVE_UUID | DM_ACTIVE_CRYPT_KEYSIZE |
|
||||
DM_ACTIVE_CRYPT_KEY, &dmd);
|
||||
if (r < 0) {
|
||||
@@ -1252,7 +1254,7 @@ int crypt_resize(struct crypt_device *cd, const char *name, uint64_t new_size)
|
||||
r = 0;
|
||||
} else {
|
||||
dmd.size = new_size;
|
||||
r = dm_create_device(name, cd->type, &dmd, 1);
|
||||
r = dm_create_device(cd, name, cd->type, &dmd, 1);
|
||||
}
|
||||
out:
|
||||
if (dmd.target == DM_CRYPT) {
|
||||
@@ -1383,7 +1385,7 @@ int crypt_suspend(struct crypt_device *cd,
|
||||
if (!cd && dm_init(NULL, 1) < 0)
|
||||
return -ENOSYS;
|
||||
|
||||
r = dm_status_suspended(name);
|
||||
r = dm_status_suspended(cd, name);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
|
||||
@@ -1393,7 +1395,7 @@ int crypt_suspend(struct crypt_device *cd,
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = dm_suspend_and_wipe_key(name);
|
||||
r = dm_suspend_and_wipe_key(cd, name);
|
||||
if (r == -ENOTSUP)
|
||||
log_err(cd, "Suspend is not supported for device %s.\n", name);
|
||||
else if (r)
|
||||
@@ -1421,7 +1423,7 @@ int crypt_resume_by_passphrase(struct crypt_device *cd,
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = dm_status_suspended(name);
|
||||
r = dm_status_suspended(cd, name);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1438,7 +1440,7 @@ int crypt_resume_by_passphrase(struct crypt_device *cd,
|
||||
|
||||
if (r >= 0) {
|
||||
keyslot = r;
|
||||
r = dm_resume_and_reinstate_key(name, vk->keylength, vk->key);
|
||||
r = dm_resume_and_reinstate_key(cd, name, vk->keylength, vk->key);
|
||||
if (r == -ENOTSUP)
|
||||
log_err(cd, "Resume is not supported for device %s.\n", name);
|
||||
else if (r)
|
||||
@@ -1470,7 +1472,7 @@ int crypt_resume_by_keyfile_offset(struct crypt_device *cd,
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = dm_status_suspended(name);
|
||||
r = dm_status_suspended(cd, name);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1494,7 +1496,7 @@ int crypt_resume_by_keyfile_offset(struct crypt_device *cd,
|
||||
goto out;
|
||||
|
||||
keyslot = r;
|
||||
r = dm_resume_and_reinstate_key(name, vk->keylength, vk->key);
|
||||
r = dm_resume_and_reinstate_key(cd, name, vk->keylength, vk->key);
|
||||
if (r)
|
||||
log_err(cd, "Error during resuming device %s.\n", name);
|
||||
out:
|
||||
@@ -2023,7 +2025,7 @@ int crypt_deactivate(struct crypt_device *cd, const char *name)
|
||||
switch (crypt_status(cd, name)) {
|
||||
case CRYPT_ACTIVE:
|
||||
case CRYPT_BUSY:
|
||||
r = dm_remove_device(name, 0, 0);
|
||||
r = dm_remove_device(cd, name, 0, 0);
|
||||
break;
|
||||
case CRYPT_INACTIVE:
|
||||
log_err(cd, _("Device %s is not active.\n"), name);
|
||||
@@ -2168,7 +2170,7 @@ crypt_status_info crypt_status(struct crypt_device *cd, const char *name)
|
||||
if (!cd && dm_init(NULL, 1) < 0)
|
||||
return CRYPT_INVALID;
|
||||
|
||||
r = dm_status_device(name);
|
||||
r = dm_status_device(cd, name);
|
||||
|
||||
if (!cd)
|
||||
dm_exit();
|
||||
@@ -2421,7 +2423,7 @@ int crypt_get_active_device(struct crypt_device *cd __attribute__((unused)),
|
||||
struct crypt_dm_active_device dmd;
|
||||
int r;
|
||||
|
||||
r = dm_query_device(name, 0, &dmd);
|
||||
r = dm_query_device(cd, name, 0, &dmd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
#include <sys/types.h>
|
||||
#include "utils_dm.h"
|
||||
|
||||
/* These are DM helpers used only by this file */
|
||||
int dm_is_dm_device(int major, int minor);
|
||||
int dm_is_dm_kernel_name(const char *name);
|
||||
char *dm_device_path(const char *prefix, int major, int minor);
|
||||
|
||||
char *crypt_lookup_dev(const char *dev_id);
|
||||
int crypt_sysfs_get_rotational(int major, int minor, int *rotational);
|
||||
|
||||
|
||||
@@ -79,25 +79,23 @@ struct crypt_dm_active_device {
|
||||
} u;
|
||||
};
|
||||
|
||||
const char *dm_get_dir(void);
|
||||
int dm_init(struct crypt_device *context, int check_kernel);
|
||||
void dm_exit(void);
|
||||
int dm_remove_device(const char *name, int force, uint64_t size);
|
||||
int dm_status_device(const char *name);
|
||||
int dm_status_suspended(const char *name);
|
||||
int dm_status_verity_ok(const char *name);
|
||||
int dm_query_device(const char *name, uint32_t get_flags,
|
||||
struct crypt_dm_active_device *dmd);
|
||||
int dm_create_device(const char *name,
|
||||
const char *type,
|
||||
struct crypt_dm_active_device *dmd,
|
||||
|
||||
int dm_remove_device(struct crypt_device *cd, const char *name,
|
||||
int force, uint64_t size);
|
||||
int dm_status_device(struct crypt_device *cd, const char *name);
|
||||
int dm_status_suspended(struct crypt_device *cd, const char *name);
|
||||
int dm_status_verity_ok(struct crypt_device *cd, const char *name);
|
||||
int dm_query_device(struct crypt_device *cd, const char *name,
|
||||
uint32_t get_flags, struct crypt_dm_active_device *dmd);
|
||||
int dm_create_device(struct crypt_device *cd, const char *name,
|
||||
const char *type, struct crypt_dm_active_device *dmd,
|
||||
int reload);
|
||||
int dm_suspend_and_wipe_key(const char *name);
|
||||
int dm_resume_and_reinstate_key(const char *name,
|
||||
size_t key_size,
|
||||
const char *key);
|
||||
char *dm_device_path(const char *prefix, int major, int minor);
|
||||
int dm_is_dm_device(int major, int minor);
|
||||
int dm_is_dm_kernel_name(const char *name);
|
||||
int dm_suspend_and_wipe_key(struct crypt_device *cd, const char *name);
|
||||
int dm_resume_and_reinstate_key(struct crypt_device *cd, const char *name,
|
||||
size_t key_size, const char *key);
|
||||
|
||||
const char *dm_get_dir(void);
|
||||
|
||||
#endif /* _UTILS_DM_H */
|
||||
|
||||
@@ -265,7 +265,7 @@ int VERITY_activate(struct crypt_device *cd,
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
r = dm_create_device(name, CRYPT_VERITY, &dmd, 0);
|
||||
r = dm_create_device(cd, name, CRYPT_VERITY, &dmd, 0);
|
||||
if (!r && !(dm_flags() & DM_VERITY_SUPPORTED)) {
|
||||
log_err(cd, _("Kernel doesn't support dm-verity mapping.\n"));
|
||||
return -ENOTSUP;
|
||||
@@ -273,7 +273,7 @@ int VERITY_activate(struct crypt_device *cd,
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = dm_status_verity_ok(name);
|
||||
r = dm_status_verity_ok(cd, name);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user