cryptsetup
2.4.3
About: cryptsetup is a utility used to conveniently setup disk encryption based on the dm-crypt kernel module. These include plain dm-crypt volumes, LUKS volumes, loop-AES and TrueCrypt compatible format.
![]() ![]() |
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
#include <unistd.h>
#include "internal.h"
#include "utils_device_locking.h"
Go to the source code of this file.
Data Structures | |
struct | device |
Macros | |
#define | BLKIOMIN _IO(0x12,120) |
#define | BLKIOOPT _IO(0x12,121) |
#define | BLKALIGNOFF _IO(0x12,122) |
Functions | |
static size_t | device_fs_block_size_fd (int fd) |
static size_t | device_block_size_fd (int fd, size_t *min_size) |
static size_t | device_block_phys_size_fd (int fd) |
static size_t | device_alignment_fd (int devfd) |
static int | device_read_test (int devfd) |
static int | device_ready (struct crypt_device *cd, struct device *device) |
static int | _open_locked (struct crypt_device *cd, struct device *device, int flags) |
void | device_sync (struct crypt_device *cd, struct device *device) |
static int | device_open_internal (struct crypt_device *cd, struct device *device, int flags) |
int | device_open (struct crypt_device *cd, struct device *device, int flags) |
int | device_open_excl (struct crypt_device *cd, struct device *device, int flags) |
void | device_release_excl (struct crypt_device *cd, struct device *device) |
int | device_open_locked (struct crypt_device *cd, struct device *device, int flags) |
int | device_alloc_no_check (struct device **device, const char *path) |
int | device_alloc (struct crypt_device *cd, struct device **device, const char *path) |
void | device_free (struct crypt_device *cd, struct device *device) |
const char * | device_block_path (const struct device *device) |
const char * | device_dm_name (const struct device *device) |
const char * | device_path (const struct device *device) |
void | device_topology_alignment (struct crypt_device *cd, struct device *device, unsigned long *required_alignment, unsigned long *alignment_offset, unsigned long default_alignment) |
size_t | device_block_size (struct crypt_device *cd, struct device *device) |
size_t | device_optimal_encryption_sector_size (struct crypt_device *cd, struct device *device) |
int | device_read_ahead (struct device *device, uint32_t *read_ahead) |
int | device_size (struct device *device, uint64_t *size) |
int | device_fallocate (struct device *device, uint64_t size) |
int | device_check_size (struct crypt_device *cd, struct device *device, uint64_t req_offset, int falloc) |
static int | device_info (struct crypt_device *cd, struct device *device, enum devcheck device_check, int *readonly, uint64_t *size) |
int | device_check_access (struct crypt_device *cd, struct device *device, enum devcheck device_check) |
static int | device_internal_prepare (struct crypt_device *cd, struct device *device) |
int | device_block_adjust (struct crypt_device *cd, struct device *device, enum devcheck device_check, uint64_t device_offset, uint64_t *size, uint32_t *flags) |
size_t | size_round_up (size_t size, size_t block) |
void | device_disable_direct_io (struct device *device) |
int | device_direct_io (const struct device *device) |
static int | device_compare_path (const char *path1, const char *path2) |
int | device_is_identical (struct device *device1, struct device *device2) |
int | device_is_rotational (struct device *device) |
size_t | device_alignment (struct device *device) |
void | device_set_lock_handle (struct device *device, struct crypt_lock_handle *h) |
struct crypt_lock_handle * | device_get_lock_handle (struct device *device) |
int | device_read_lock (struct crypt_device *cd, struct device *device) |
int | device_write_lock (struct crypt_device *cd, struct device *device) |
void | device_read_unlock (struct crypt_device *cd, struct device *device) |
void | device_write_unlock (struct crypt_device *cd, struct device *device) |
bool | device_is_locked (struct device *device) |
void | device_close (struct crypt_device *cd, struct device *device) |
void | device_set_block_size (struct device *device, size_t size) |
#define BLKALIGNOFF _IO(0x12,122) |
Definition at line 511 of file utils_device.c.
#define BLKIOMIN _IO(0x12,120) |
Definition at line 509 of file utils_device.c.
#define BLKIOOPT _IO(0x12,121) |
Definition at line 510 of file utils_device.c.
|
static |
Definition at line 237 of file utils_device.c.
References device_locked_readonly(), device_locked_verify(), device_path(), device::lh, and log_dbg.
Referenced by device_open_internal().
size_t device_alignment | ( | struct device * | device | ) |
Definition at line 986 of file utils_device.c.
References device::alignment, device_alignment_fd(), and device_path().
Referenced by BITLK_read_sb(), crypt_storage_wrapper_init(), crypt_wipe_device(), hdr_read_disk(), hdr_write_disk(), INTEGRITY_read_superblock(), LUKS2_check_sequence_id(), luks2_decrypt_from_storage(), luks2_encrypt_to_storage(), LUKS2_hdr_backup(), LUKS2_hdr_restore(), LUKS2_hdr_version_unlocked(), LUKS_decrypt_from_storage(), LUKS_encrypt_to_storage(), LUKS_endec_template(), LUKS_hdr_backup(), LUKS_hdr_restore(), LUKS_read_phdr(), LUKS_write_phdr(), luksmeta_header_present(), move_keyslot_areas(), reenc_keyslot_store_data(), TCRYPT_read_phdr(), VERITY_read_sb(), and VERITY_write_sb().
|
static |
Definition at line 132 of file utils_device.c.
References alignment(), and DEFAULT_MEM_ALIGNMENT.
Referenced by device_alignment(), device_read_test(), and device_ready().
int device_alloc | ( | struct crypt_device * | cd, |
struct device ** | device, | ||
const char * | path | ||
) |
Definition at line 421 of file utils_device.c.
References device_alloc_no_check(), device_ready(), device::init_done, and device::path.
Referenced by _create_device_with_integrity(), _crypt_format_luks1(), _crypt_format_luks2(), _crypt_format_verity(), _crypt_load_verity(), _crypt_set_data_device(), _dm_target_query_crypt(), _dm_target_query_integrity(), _dm_target_query_linear(), _dm_target_query_verity(), _reload_device_with_integrity(), crypt_init(), LUKS2_hdr_restore(), LUKS2_hdr_version_unlocked(), TCRYPT_activate(), and TCRYPT_read_phdr().
int device_alloc_no_check | ( | struct device ** | device, |
const char * | path | ||
) |
Definition at line 392 of file utils_device.c.
References device::dev_fd, device::dev_fd_excl, device::loop_fd, NULL, device::o_direct, device::path, and device::ro_dev_fd.
Referenced by crypt_wipe(), and device_alloc().
int device_block_adjust | ( | struct crypt_device * | cd, |
struct device * | device, | ||
enum devcheck | device_check, | ||
uint64_t | device_offset, | ||
uint64_t * | size, | ||
uint32_t * | flags | ||
) |
Definition at line 868 of file utils_device.c.
References _, CRYPT_ACTIVATE_READONLY, device_check(), device_info(), device_internal_prepare(), device_path(), log_dbg, log_err, and device::path.
Referenced by _activate(), _create_device_with_integrity(), _reload_device(), _reload_device_with_integrity(), create_or_reload_device(), crypt_resize(), crypt_storage_dmcrypt_init(), INTEGRITY_activate_dmd_device(), INTEGRITY_format(), LOOPAES_activate(), LUKS2_assembly_multisegment_dmd(), LUKS_endec_template(), TCRYPT_activate(), and VERITY_activate().
const char * device_block_path | ( | const struct device * | device | ) |
Definition at line 472 of file utils_device.c.
References device::init_done, NULL, and device::path.
Referenced by crypt_get_device_name(), crypt_get_metadata_device_name(), get_dm_crypt_params(), get_dm_integrity_params(), get_dm_linear_params(), and get_dm_verity_params().
|
static |
Definition at line 115 of file utils_device.c.
References MAX_SECTOR_SIZE, and SECTOR_SIZE.
Referenced by device_optimal_encryption_sector_size().
size_t device_block_size | ( | struct crypt_device * | cd, |
struct device * | device | ||
) |
Definition at line 574 of file utils_device.c.
References device::block_size, device_block_size_fd(), device_path(), device::file_path, log_dbg, NULL, and device::path.
Referenced by BITLK_read_sb(), crypt_resize(), crypt_storage_wrapper_init(), crypt_wipe_device(), hdr_read_disk(), hdr_write_disk(), INTEGRITY_read_superblock(), LUKS2_check_sequence_id(), luks2_decrypt_from_storage(), luks2_encrypt_to_storage(), LUKS2_hdr_backup(), LUKS2_hdr_restore(), LUKS2_hdr_version_unlocked(), LUKS_decrypt_from_storage(), LUKS_encrypt_to_storage(), LUKS_endec_template(), LUKS_hdr_backup(), LUKS_hdr_restore(), LUKS_read_phdr(), LUKS_write_phdr(), luksmeta_header_present(), move_keyslot_areas(), PLAIN_activate(), reenc_keyslot_store_data(), TCRYPT_read_phdr(), VERITY_read_sb(), VERITY_write_sb(), and wipe_block().
|
static |
Definition at line 80 of file utils_device.c.
References crypt_getpagesize(), and device_fs_block_size_fd().
Referenced by device_block_size(), device_internal_prepare(), device_optimal_encryption_sector_size(), device_read_test(), and device_ready().
int device_check_access | ( | struct crypt_device * | cd, |
struct device * | device, | ||
enum devcheck | device_check | ||
) |
Definition at line 815 of file utils_device.c.
References device_check(), device_info(), and NULL.
Referenced by _crypt_format_integrity(), _crypt_format_luks1(), _crypt_format_luks2(), and LUKS2_reencrypt_check_device_size().
int device_check_size | ( | struct crypt_device * | cd, |
struct device * | device, | ||
uint64_t | req_offset, | ||
int | falloc | ||
) |
Definition at line 702 of file utils_device.c.
References _, device_fallocate(), device_path(), device_size(), log_dbg, and log_err.
Referenced by LUKS2_disk_hdr_read(), LUKS2_disk_hdr_write(), and LUKS2_reencrypt_check_device_size().
void device_close | ( | struct crypt_device * | cd, |
struct device * | device | ||
) |
Definition at line 1061 of file utils_device.c.
References device::dev_fd, device_path(), log_dbg, and device::ro_dev_fd.
Referenced by _init_by_name_crypt(), and device_free().
|
static |
Definition at line 939 of file utils_device.c.
Referenced by device_is_identical().
int device_direct_io | ( | const struct device * | device | ) |
Definition at line 934 of file utils_device.c.
References device::o_direct.
Referenced by LUKS2_hdr_version_unlocked().
void device_disable_direct_io | ( | struct device * | device | ) |
Definition at line 928 of file utils_device.c.
References device::o_direct.
Referenced by crypt_wipe(), LUKS_read_phdr(), and VERITY_write_sb().
const char * device_dm_name | ( | const struct device * | device | ) |
Definition at line 481 of file utils_device.c.
References dm_get_dir(), device::init_done, NULL, and device::path.
Referenced by _init_by_name_crypt(), crypt_get_active_device(), and LUKS2_deactivate().
int device_fallocate | ( | struct device * | device, |
uint64_t | size | ||
) |
Definition at line 679 of file utils_device.c.
References crypt_loop_resize(), device_path(), device::file_path, and device::path.
Referenced by device_check_size(), LUKS2_generate_hdr(), LUKS2_luks1_to_luks2(), and LUKS_check_device_size().
void device_free | ( | struct crypt_device * | cd, |
struct device * | device | ||
) |
Definition at line 447 of file utils_device.c.
References device::dev_fd_excl, device_close(), device_locked(), device_path(), device::file_path, device::lh, log_dbg, device::loop_fd, and device::path.
Referenced by _create_device_with_integrity(), _crypt_format_luks1(), _crypt_format_luks2(), _crypt_format_verity(), _crypt_set_data_device(), _dm_target_free_query_path(), _dm_target_query_crypt(), _dm_target_query_integrity(), _dm_target_query_linear(), _dm_target_query_verity(), _init_by_name_crypt(), _reload_device_with_integrity(), crypt_free(), crypt_free_type(), crypt_wipe(), LUKS2_hdr_restore(), LUKS2_hdr_version_unlocked(), TCRYPT_activate(), TCRYPT_read_phdr(), and TCRYPT_status_one().
|
static |
Definition at line 63 of file utils_device.c.
References crypt_getpagesize().
Referenced by device_block_size_fd().
struct crypt_lock_handle * device_get_lock_handle | ( | struct device * | device | ) |
Definition at line 1010 of file utils_device.c.
References device::lh, and NULL.
Referenced by device_read_lock_internal(), device_unlock_internal(), and device_write_lock_internal().
|
static |
Definition at line 728 of file utils_device.c.
References _, DEV_EXCL, device_check(), device_path(), log_err, device::path, and SECTOR_SHIFT.
Referenced by device_block_adjust(), and device_check_access().
|
static |
Definition at line 822 of file utils_device.c.
References _, crypt_loop_attach(), crypt_loop_detach(), device_block_size_fd(), device_ready(), device::file_path, device::init_done, log_dbg, log_err, device::loop_block_size, device::loop_fd, NULL, device::path, and SECTOR_SIZE.
Referenced by device_block_adjust().
Definition at line 956 of file utils_device.c.
References device_compare_path(), and device_path().
Referenced by _check_header_data_overlap(), _compare_crypt_devices(), _compare_integrity_devices(), _crypt_format_verity(), crypt_header_is_detached(), and VERITY_FEC_blocks().
bool device_is_locked | ( | struct device * | device | ) |
Definition at line 1056 of file utils_device.c.
References device_locked(), and device::lh.
Referenced by crypt_wipe_device(), LUKS_decrypt_from_storage(), and LUKS_encrypt_to_storage().
int device_is_rotational | ( | struct device * | device | ) |
Definition at line 970 of file utils_device.c.
References crypt_dev_is_rotational(), and device_path().
Referenced by crypt_wipe_device().
int device_open | ( | struct crypt_device * | cd, |
struct device * | device, | ||
int | flags | ||
) |
Definition at line 325 of file utils_device.c.
References device_locked(), device_open_internal(), and device::lh.
Referenced by BITLK_read_sb(), crypt_storage_wrapper_init(), crypt_wipe_device(), INTEGRITY_read_superblock(), LUKS_decrypt_from_storage(), LUKS_encrypt_to_storage(), LUKS_hdr_backup(), LUKS_hdr_restore(), LUKS_read_phdr(), LUKS_write_phdr(), luksmeta_header_present(), move_keyslot_areas(), TCRYPT_read_phdr(), VERITY_read_sb(), and VERITY_write_sb().
int device_open_excl | ( | struct crypt_device * | cd, |
struct device * | device, | ||
int | flags | ||
) |
Definition at line 334 of file utils_device.c.
References device::dev_fd_excl, device_locked(), device_open_internal(), device_path(), device::lh, and log_dbg.
|
static |
Definition at line 286 of file utils_device.c.
References _open_locked(), device::dev_fd, device_locked(), device_path(), device::lh, log_dbg, device::o_direct, and device::ro_dev_fd.
Referenced by device_open(), device_open_excl(), and device_open_locked().
int device_open_locked | ( | struct crypt_device * | cd, |
struct device * | device, | ||
int | flags | ||
) |
Definition at line 382 of file utils_device.c.
References crypt_metadata_locking_enabled(), device_locked(), device_open_internal(), and device::lh.
Referenced by crypt_wipe_device(), hdr_read_disk(), hdr_write_disk(), LUKS2_check_sequence_id(), luks2_decrypt_from_storage(), luks2_encrypt_to_storage(), LUKS2_hdr_backup(), LUKS2_hdr_restore(), LUKS_decrypt_from_storage(), LUKS_encrypt_to_storage(), and reenc_keyslot_store_data().
size_t device_optimal_encryption_sector_size | ( | struct crypt_device * | cd, |
struct device * | device | ||
) |
Definition at line 596 of file utils_device.c.
References device::block_size, device_block_phys_size_fd(), device_block_size_fd(), device_path(), device::file_path, log_dbg, MAX_SECTOR_SIZE, MISALIGNED, NULL, device::path, and SECTOR_SIZE.
Referenced by _crypt_format_luks2().
const char * device_path | ( | const struct device * | device | ) |
Definition at line 496 of file utils_device.c.
References device::file_path, NULL, and device::path.
Referenced by _activate(), _crypt_format_luks2(), _init_by_name_crypt(), _open_locked(), acquire_and_verify(), acquire_lock_handle(), BITLK_dump(), BITLK_read_sb(), crypt_check_data_device_size(), crypt_get_device_name(), crypt_get_metadata_device_name(), crypt_get_verity_info(), crypt_init_by_name_and_header(), crypt_storage_dmcrypt_init(), crypt_wipe(), data_device_path(), device_alignment(), device_block_adjust(), device_block_size(), device_check_size(), device_close(), device_fallocate(), device_free(), device_info(), device_is_identical(), device_is_rotational(), device_open_excl(), device_open_internal(), device_optimal_encryption_sector_size(), device_read_lock_internal(), device_ready(), device_release_excl(), device_sync(), device_unlock_internal(), device_write_lock_internal(), FEC_process_inputs(), INTEGRITY_activate_dmd_device(), INTEGRITY_dump(), INTEGRITY_format(), INTEGRITY_read_superblock(), luks2_decrypt_from_storage(), LUKS2_device_write_lock(), LUKS2_disk_hdr_read(), LUKS2_hdr_backup(), LUKS2_hdr_read(), LUKS2_hdr_restore(), LUKS2_hdr_version_unlocked(), LUKS2_keyslot_wipe(), LUKS2_reencrypt_check_device_size(), LUKS_check_device_size(), LUKS_decrypt_from_storage(), LUKS_del_key(), LUKS_encrypt_to_storage(), LUKS_endec_template(), LUKS_hdr_backup(), LUKS_hdr_restore(), LUKS_read_phdr(), LUKS_write_phdr(), mdata_device_path(), TCRYPT_activate(), TCRYPT_dump(), TCRYPT_get_data_offset(), TCRYPT_get_iv_offset(), TCRYPT_read_phdr(), VERITY_create_or_verify_hash(), VERITY_FEC_blocks(), VERITY_FEC_process(), VERITY_read_sb(), and VERITY_write_sb().
int device_read_ahead | ( | struct device * | device, |
uint32_t * | read_ahead | ||
) |
Definition at line 632 of file utils_device.c.
References device::path.
Referenced by _dm_create_device(), and _dm_reload_device().
int device_read_lock | ( | struct crypt_device * | cd, |
struct device * | device | ||
) |
Definition at line 1015 of file utils_device.c.
References crypt_metadata_locking_enabled(), and device_read_lock_internal().
Referenced by luks2_decrypt_from_storage(), LUKS2_hdr_backup(), LUKS2_hdr_read(), and LUKS2_hdr_restore().
|
static |
Definition at line 144 of file utils_device.c.
References alignment(), crypt_safe_memzero(), device_alignment_fd(), device_block_size_fd(), and read_blockwise().
Referenced by device_ready().
void device_read_unlock | ( | struct crypt_device * | cd, |
struct device * | device | ||
) |
Definition at line 1036 of file utils_device.c.
References crypt_metadata_locking_enabled(), device_locked(), device_unlock_internal(), and device::lh.
Referenced by luks2_decrypt_from_storage(), LUKS2_hdr_backup(), LUKS2_hdr_read(), and LUKS2_hdr_restore().
|
static |
Definition at line 177 of file utils_device.c.
References _, device::alignment, device::block_size, device_alignment_fd(), device_block_size_fd(), device_path(), device_read_test(), log_dbg, log_err, NULL, and device::o_direct.
Referenced by device_alloc(), and device_internal_prepare().
void device_release_excl | ( | struct crypt_device * | cd, |
struct device * | device | ||
) |
Definition at line 370 of file utils_device.c.
References device::dev_fd_excl, device_path(), and log_dbg.
Referenced by LUKS2_reencrypt_free().
void device_set_block_size | ( | struct device * | device, |
size_t | size | ||
) |
Definition at line 1081 of file utils_device.c.
References device::loop_block_size.
Referenced by _crypt_format_luks2(), _crypt_format_plain(), _crypt_load_bitlk(), _crypt_load_luks(), and _crypt_set_data_device().
void device_set_lock_handle | ( | struct device * | device, |
struct crypt_lock_handle * | h | ||
) |
Definition at line 1004 of file utils_device.c.
References device::lh.
Referenced by device_read_lock_internal(), device_unlock_internal(), and device_write_lock_internal().
int device_size | ( | struct device * | device, |
uint64_t * | size | ||
) |
Definition at line 653 of file utils_device.c.
References device::path.
Referenced by _crypt_format_luks1(), _crypt_format_luks2(), _crypt_format_plain(), _crypt_format_verity(), _reload_custom_multi(), crypt_check_data_device_size(), crypt_wipe_device(), device_check_size(), LUKS2_activate_multi(), LUKS2_generate_hdr(), LUKS2_luks1_to_luks2(), LUKS2_reencrypt_check_device_size(), LUKS2_reload(), LUKS_check_device_size(), TCRYPT_get_data_offset(), tools_time_progress(), VERITY_create_or_verify_hash(), and VERITY_FEC_blocks().
void device_sync | ( | struct crypt_device * | cd, |
struct device * | device | ||
) |
Definition at line 268 of file utils_device.c.
References device::dev_fd, device_path(), and log_dbg.
Referenced by crypt_wipe_device(), hdr_write_disk(), luks2_encrypt_to_storage(), LUKS2_hdr_restore(), LUKS_encrypt_to_storage(), LUKS_hdr_restore(), LUKS_write_phdr(), move_keyslot_areas(), and VERITY_write_sb().
void device_topology_alignment | ( | struct crypt_device * | cd, |
struct device * | device, | ||
unsigned long * | required_alignment, | ||
unsigned long * | alignment_offset, | ||
unsigned long | default_alignment | ||
) |
Definition at line 514 of file utils_device.c.
References _, BLKALIGNOFF, BLKIOMIN, BLKIOOPT, log_dbg, log_err, MISALIGNED_4K, and device::path.
Referenced by _crypt_format_luks1(), and _crypt_format_luks2().
int device_write_lock | ( | struct crypt_device * | cd, |
struct device * | device | ||
) |
Definition at line 1026 of file utils_device.c.
References crypt_metadata_locking_enabled(), device_locked(), device_locked_readonly(), device_write_lock_internal(), and device::lh.
Referenced by LUKS2_device_write_lock(), LUKS2_disk_hdr_write(), LUKS2_hdr_read(), and LUKS2_hdr_restore().
void device_write_unlock | ( | struct crypt_device * | cd, |
struct device * | device | ||
) |
Definition at line 1046 of file utils_device.c.
References crypt_metadata_locking_enabled(), device_locked(), device_locked_readonly(), device_unlock_internal(), and device::lh.
Referenced by LUKS2_device_write_lock(), LUKS2_disk_hdr_write(), LUKS2_hdr_read(), LUKS2_hdr_restore(), luks2_keyslot_store(), LUKS2_keyslot_wipe(), reenc_keyslot_store(), and reencrypt_init_by_passphrase().
size_t size_round_up | ( | size_t | size, |
size_t | block | ||
) |
Definition at line 922 of file utils_device.c.
Referenced by get_area_size(), keyslot_LUKS1_compatible(), LUKS2_find_area_max_gap(), LUKS2_generate_hdr(), LUKS2_hdr_backup(), LUKS2_luks1_to_luks2(), LUKS_endec_template(), LUKS_generate_phdr(), and LUKS_hdr_backup().