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.
  Fossies Dox: cryptsetup-2.4.3.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

utils_device.c File Reference
#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"
Include dependency graph for utils_device.c:

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_handledevice_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)
 

Macro Definition Documentation

◆ BLKALIGNOFF

#define BLKALIGNOFF   _IO(0x12,122)

Definition at line 511 of file utils_device.c.

◆ BLKIOMIN

#define BLKIOMIN   _IO(0x12,120)

Definition at line 509 of file utils_device.c.

◆ BLKIOOPT

#define BLKIOOPT   _IO(0x12,121)

Definition at line 510 of file utils_device.c.

Function Documentation

◆ _open_locked()

static int _open_locked ( struct crypt_device cd,
struct device device,
int  flags 
)
static

◆ device_alignment()

◆ device_alignment_fd()

static size_t device_alignment_fd ( int  devfd)
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().

◆ device_alloc()

◆ device_alloc_no_check()

int device_alloc_no_check ( struct device **  device,
const char *  path 
)

◆ device_block_adjust()

◆ device_block_path()

const char * device_block_path ( const struct device device)

◆ device_block_phys_size_fd()

static size_t device_block_phys_size_fd ( int  fd)
static

Definition at line 115 of file utils_device.c.

References MAX_SECTOR_SIZE, and SECTOR_SIZE.

Referenced by device_optimal_encryption_sector_size().

◆ device_block_size()

◆ device_block_size_fd()

static size_t device_block_size_fd ( int  fd,
size_t *  min_size 
)
static

◆ device_check_access()

int device_check_access ( struct crypt_device cd,
struct device device,
enum devcheck  device_check 
)

◆ device_check_size()

int device_check_size ( struct crypt_device cd,
struct device device,
uint64_t  req_offset,
int  falloc 
)

◆ device_close()

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().

◆ device_compare_path()

static int device_compare_path ( const char *  path1,
const char *  path2 
)
static

Definition at line 939 of file utils_device.c.

Referenced by device_is_identical().

◆ device_direct_io()

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().

◆ device_disable_direct_io()

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().

◆ device_dm_name()

const char * device_dm_name ( const struct device device)

◆ device_fallocate()

int device_fallocate ( struct device device,
uint64_t  size 
)

◆ device_free()

◆ device_fs_block_size_fd()

static size_t device_fs_block_size_fd ( int  fd)
static

Definition at line 63 of file utils_device.c.

References crypt_getpagesize().

Referenced by device_block_size_fd().

◆ device_get_lock_handle()

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().

◆ device_info()

static int device_info ( struct crypt_device cd,
struct device device,
enum devcheck  device_check,
int *  readonly,
uint64_t *  size 
)
static

◆ device_internal_prepare()

static int device_internal_prepare ( struct crypt_device cd,
struct device device 
)
static

◆ device_is_identical()

int device_is_identical ( struct device device1,
struct device device2 
)

◆ device_is_locked()

bool device_is_locked ( struct device device)

◆ device_is_rotational()

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().

◆ device_open()

◆ device_open_excl()

int device_open_excl ( struct crypt_device cd,
struct device device,
int  flags 
)

◆ device_open_internal()

static int device_open_internal ( struct crypt_device cd,
struct device device,
int  flags 
)
static

◆ device_open_locked()

◆ device_optimal_encryption_sector_size()

size_t device_optimal_encryption_sector_size ( struct crypt_device cd,
struct device device 
)

◆ device_path()

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().

◆ device_read_ahead()

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().

◆ device_read_lock()

int device_read_lock ( struct crypt_device cd,
struct device device 
)

◆ device_read_test()

static int device_read_test ( int  devfd)
static

◆ device_read_unlock()

void device_read_unlock ( struct crypt_device cd,
struct device device 
)

◆ device_ready()

static int device_ready ( struct crypt_device cd,
struct device device 
)
static

◆ device_release_excl()

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().

◆ device_set_block_size()

void device_set_block_size ( struct device device,
size_t  size 
)

◆ device_set_lock_handle()

void device_set_lock_handle ( struct device device,
struct crypt_lock_handle h 
)

◆ device_size()

◆ device_sync()

◆ device_topology_alignment()

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().

◆ device_write_lock()

◆ device_write_unlock()

◆ size_round_up()