diff --git a/lib/integrity/integrity.c b/lib/integrity/integrity.c index 04000219..a17ebbf8 100644 --- a/lib/integrity/integrity.c +++ b/lib/integrity/integrity.c @@ -34,12 +34,12 @@ static int INTEGRITY_read_superblock(struct crypt_device *cd, { int devfd, r; - devfd = device_open(device, O_RDONLY); + devfd = device_open(cd, device, O_RDONLY); if(devfd < 0) { return -EINVAL; } - if (read_lseek_blockwise(devfd, device_block_size(device), + if (read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), sb, sizeof(*sb), offset) != sizeof(*sb) || memcmp(sb->magic, SB_MAGIC, sizeof(sb->magic)) || (sb->version != SB_VERSION_1 && sb->version != SB_VERSION_2)) { diff --git a/lib/internal.h b/lib/internal.h index d13ae04e..1847f6f8 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -90,33 +90,34 @@ int crypt_benchmark_pbkdf_internal(struct crypt_device *cd, /* Device backend */ struct device; -int device_alloc(struct device **device, const char *path); +int device_alloc(struct crypt_device *cd, struct device **device, const char *path); int device_alloc_no_check(struct device **device, const char *path); -void device_free(struct device *device); +void device_free(struct crypt_device *cd, struct device *device); const char *device_path(const struct device *device); const char *device_dm_name(const struct device *device); const char *device_block_path(const struct device *device); -void device_topology_alignment(struct device *device, - unsigned long *required_alignment, /* bytes */ - unsigned long *alignment_offset, /* bytes */ - unsigned long default_alignment); -size_t device_block_size(struct device *device); +void device_topology_alignment(struct crypt_device *cd, + struct device *device, + unsigned long *required_alignment, /* bytes */ + unsigned long *alignment_offset, /* bytes */ + unsigned long default_alignment); +size_t device_block_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_open(struct device *device, int flags); +int device_open(struct crypt_device *cd, struct device *device, int flags); void device_disable_direct_io(struct device *device); int device_is_identical(struct device *device1, struct device *device2); int device_is_rotational(struct device *device); size_t device_alignment(struct device *device); int device_direct_io(const struct device *device); int device_fallocate(struct device *device, uint64_t size); -void device_sync(struct device *device, int devfd); +void device_sync(struct crypt_device *cd, struct device *device, int devfd); -int device_open_locked(struct device *device, int flags); +int device_open_locked(struct crypt_device *cd, struct device *device, int flags); 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 device *device); -void device_write_unlock(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); enum devcheck { DEV_OK = 0, DEV_EXCL = 1, DEV_SHARED = 2 }; int device_check_access(struct crypt_device *cd, diff --git a/lib/libdevmapper.c b/lib/libdevmapper.c index c4cad57c..c2cdb86d 100644 --- a/lib/libdevmapper.c +++ b/lib/libdevmapper.c @@ -1423,7 +1423,7 @@ static int _dm_query_crypt(uint32_t get_flags, rdevice = strsep(¶ms, " "); if (get_flags & DM_ACTIVE_DEVICE) { arg = crypt_lookup_dev(rdevice); - r = device_alloc(&data_device, arg); + r = device_alloc(NULL, &data_device, arg); free(arg); if (r < 0 && r != -ENOTBLK) goto err; @@ -1552,7 +1552,7 @@ static int _dm_query_crypt(uint32_t get_flags, err: free(cipher); free(integrity); - device_free(data_device); + device_free(NULL, data_device); crypt_free_volume_key(vk); return r; } @@ -1594,7 +1594,7 @@ static int _dm_query_verity(uint32_t get_flags, return -EINVAL; if (get_flags & DM_ACTIVE_DEVICE) { str2 = crypt_lookup_dev(str); - r = device_alloc(&data_device, str2); + r = device_alloc(NULL, &data_device, str2); free(str2); if (r < 0 && r != -ENOTBLK) return r; @@ -1608,7 +1608,7 @@ static int _dm_query_verity(uint32_t get_flags, goto err; if (get_flags & DM_ACTIVE_VERITY_HASH_DEVICE) { str2 = crypt_lookup_dev(str); - r = device_alloc(&hash_device, str2); + r = device_alloc(NULL, &hash_device, str2); free(str2); if (r < 0 && r != -ENOTBLK) goto err; @@ -1719,7 +1719,7 @@ static int _dm_query_verity(uint32_t get_flags, str = strsep(¶ms, " "); str2 = crypt_lookup_dev(str); if (get_flags & DM_ACTIVE_VERITY_HASH_DEVICE) { - r = device_alloc(&fec_device, str2); + r = device_alloc(NULL, &fec_device, str2); if (r < 0 && r != -ENOTBLK) { free(str2); goto err; @@ -1779,9 +1779,9 @@ static int _dm_query_verity(uint32_t get_flags, vp->fec_device = fec_dev_str; return 0; err: - device_free(data_device); - device_free(hash_device); - device_free(fec_device); + device_free(NULL, data_device); + device_free(NULL, hash_device); + device_free(NULL, fec_device); free(root_hash); free(hash_name); free(salt); @@ -1812,7 +1812,7 @@ static int _dm_query_integrity(uint32_t get_flags, str = strsep(¶ms, " "); if (get_flags & DM_ACTIVE_DEVICE) { str2 = crypt_lookup_dev(str); - r = device_alloc(&data_device, str2); + r = device_alloc(NULL, &data_device, str2); free(str2); if (r < 0 && r != -ENOTBLK) return r; @@ -1946,7 +1946,7 @@ static int _dm_query_integrity(uint32_t get_flags, dmd->u.integrity.vk = vk; return 0; err: - device_free(data_device); + device_free(NULL, data_device); free(integrity); free(journal_crypt); free(journal_integrity); diff --git a/lib/luks1/keyencryption.c b/lib/luks1/keyencryption.c index 10134cac..559bad17 100644 --- a/lib/luks1/keyencryption.c +++ b/lib/luks1/keyencryption.c @@ -75,7 +75,7 @@ static int LUKS_endec_template(char *src, size_t srcLength, log_dbg(ctx, "Using dmcrypt to access keyslot area."); - bsize = device_block_size(dmd.data_device); + bsize = device_block_size(ctx, dmd.data_device); alignment = device_alignment(dmd.data_device); if (!bsize || !alignment) return -EINVAL; @@ -183,11 +183,11 @@ int LUKS_encrypt_to_storage(char *src, size_t srcLength, r = -EIO; /* Write buffer to device */ - devfd = device_open(device, O_RDWR); + devfd = device_open(ctx, device, O_RDWR); if (devfd < 0) goto out; - if (write_lseek_blockwise(devfd, device_block_size(device), + if (write_lseek_blockwise(devfd, device_block_size(ctx, device), device_alignment(device), src, srcLength, sector * SECTOR_SIZE) < 0) goto out; @@ -195,7 +195,7 @@ int LUKS_encrypt_to_storage(char *src, size_t srcLength, r = 0; out: if (devfd >= 0) { - device_sync(device, devfd); + device_sync(ctx, device, devfd); close(devfd); } if (r) @@ -240,14 +240,14 @@ int LUKS_decrypt_from_storage(char *dst, size_t dstLength, log_dbg(ctx, "Using userspace crypto wrapper to access keyslot area."); /* Read buffer from device */ - devfd = device_open(device, O_RDONLY); + devfd = device_open(ctx, device, O_RDONLY); if (devfd < 0) { log_err(ctx, _("Cannot open device %s."), device_path(device)); crypt_storage_destroy(s); return -EIO; } - if (read_lseek_blockwise(devfd, device_block_size(device), + if (read_lseek_blockwise(devfd, device_block_size(ctx, device), device_alignment(device), dst, dstLength, sector * SECTOR_SIZE) < 0) { if (!fstat(devfd, &st) && (st.st_size < (off_t)dstLength)) diff --git a/lib/luks1/keymanage.c b/lib/luks1/keymanage.c index 2c4d0854..c2d87320 100644 --- a/lib/luks1/keymanage.c +++ b/lib/luks1/keymanage.c @@ -240,14 +240,14 @@ int LUKS_hdr_backup(const char *backup_file, struct crypt_device *ctx) log_dbg(ctx, "Output backup file size: %zu bytes.", buffer_size); - devfd = device_open(device, O_RDONLY); + devfd = device_open(ctx, device, O_RDONLY); if (devfd < 0) { log_err(ctx, _("Device %s is not a valid LUKS device."), device_path(device)); r = -EINVAL; goto out; } - if (read_blockwise(devfd, device_block_size(device), device_alignment(device), + if (read_blockwise(devfd, device_block_size(ctx, device), device_alignment(device), buffer, hdr_size) < (ssize_t)hdr_size) { r = -EIO; goto out; @@ -356,7 +356,7 @@ int LUKS_hdr_restore( log_dbg(ctx, "Storing backup of header (%zu bytes) and keyslot area (%zu bytes) to device %s.", sizeof(*hdr), buffer_size - LUKS_ALIGN_KEYSLOTS, device_path(device)); - devfd = device_open(device, O_RDWR); + devfd = device_open(ctx, device, O_RDWR); if (devfd < 0) { if (errno == EACCES) log_err(ctx, _("Cannot write to device %s, permission denied."), @@ -367,7 +367,7 @@ int LUKS_hdr_restore( goto out; } - if (write_blockwise(devfd, device_block_size(device), device_alignment(device), + if (write_blockwise(devfd, device_block_size(ctx, device), device_alignment(device), buffer, buffer_size) < buffer_size) { r = -EIO; goto out; @@ -379,7 +379,7 @@ int LUKS_hdr_restore( r = LUKS_read_phdr(hdr, 1, 0, ctx); out: if (devfd >= 0) { - device_sync(device, devfd); + device_sync(ctx, device, devfd); close(devfd); } crypt_safe_free(buffer); @@ -607,13 +607,13 @@ int LUKS_read_phdr(struct luks_phdr *hdr, log_dbg(ctx, "Reading LUKS header of size %zu from device %s", hdr_size, device_path(device)); - devfd = device_open(device, O_RDONLY); + devfd = device_open(ctx, device, O_RDONLY); if (devfd < 0) { log_err(ctx, _("Cannot open device %s."), device_path(device)); return -EINVAL; } - if (read_blockwise(devfd, device_block_size(device), device_alignment(device), + if (read_blockwise(devfd, device_block_size(ctx, device), device_alignment(device), hdr, hdr_size) < hdr_size) r = -EIO; else @@ -654,7 +654,7 @@ int LUKS_write_phdr(struct luks_phdr *hdr, if (r) return r; - devfd = device_open(device, O_RDWR); + devfd = device_open(ctx, device, O_RDWR); if (devfd < 0) { if (errno == EACCES) log_err(ctx, _("Cannot write to device %s, permission denied."), @@ -679,12 +679,12 @@ int LUKS_write_phdr(struct luks_phdr *hdr, convHdr.keyblock[i].stripes = htonl(hdr->keyblock[i].stripes); } - r = write_blockwise(devfd, device_block_size(device), device_alignment(device), + r = write_blockwise(devfd, device_block_size(ctx, device), device_alignment(device), &convHdr, hdr_size) < hdr_size ? -EIO : 0; if (r) log_err(ctx, _("Error during update of LUKS header on device %s."), device_path(device)); - device_sync(device, devfd); + device_sync(ctx, device, devfd); close(devfd); /* Re-read header from disk to be sure that in-memory and on-disk data are the same. */ diff --git a/lib/luks2/luks2_disk_metadata.c b/lib/luks2/luks2_disk_metadata.c index 46fe5770..dae6dd8c 100644 --- a/lib/luks2/luks2_disk_metadata.c +++ b/lib/luks2/luks2_disk_metadata.c @@ -238,7 +238,7 @@ static int hdr_read_disk(struct crypt_device *cd, log_dbg(cd, "Trying to read %s LUKS2 header at offset 0x%" PRIx64 ".", secondary ? "secondary" : "primary", offset); - devfd = device_open_locked(device, O_RDONLY); + devfd = device_open_locked(cd, device, O_RDONLY); if (devfd < 0) return devfd == -1 ? -EIO : devfd; @@ -246,7 +246,7 @@ static int hdr_read_disk(struct crypt_device *cd, * Read binary header and run sanity check before reading * JSON area and validating checksum. */ - if (read_lseek_blockwise(devfd, device_block_size(device), + if (read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), hdr_disk, LUKS2_HDR_BIN_LEN, offset) != LUKS2_HDR_BIN_LEN) { close(devfd); @@ -268,7 +268,7 @@ static int hdr_read_disk(struct crypt_device *cd, return -ENOMEM; } - if (read_lseek_blockwise(devfd, device_block_size(device), + if (read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), *json_area, hdr_json_size, offset + LUKS2_HDR_BIN_LEN) != (ssize_t)hdr_json_size) { close(devfd); @@ -309,7 +309,7 @@ static int hdr_write_disk(struct crypt_device *cd, /* FIXME: read-only device silent fail? */ - devfd = device_open_locked(device, O_RDWR); + devfd = device_open_locked(cd, device, O_RDWR); if (devfd < 0) return devfd == -1 ? -EINVAL : devfd; @@ -320,7 +320,7 @@ static int hdr_write_disk(struct crypt_device *cd, /* * Write header without checksum but with proper seqid. */ - if (write_lseek_blockwise(devfd, device_block_size(device), + if (write_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), (char *)&hdr_disk, LUKS2_HDR_BIN_LEN, offset) < (ssize_t)LUKS2_HDR_BIN_LEN) { close(devfd); @@ -330,7 +330,7 @@ static int hdr_write_disk(struct crypt_device *cd, /* * Write json area. */ - if (write_lseek_blockwise(devfd, device_block_size(device), + if (write_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), CONST_CAST(char*)json_area, hdr_json_len, LUKS2_HDR_BIN_LEN + offset) < (ssize_t)hdr_json_len) { @@ -349,12 +349,12 @@ static int hdr_write_disk(struct crypt_device *cd, } log_dbg_checksum(cd, hdr_disk.csum, hdr_disk.checksum_alg, "in-memory"); - if (write_lseek_blockwise(devfd, device_block_size(device), + if (write_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), (char *)&hdr_disk, LUKS2_HDR_BIN_LEN, offset) < (ssize_t)LUKS2_HDR_BIN_LEN) r = -EIO; - device_sync(device, devfd); + device_sync(cd, device, devfd); close(devfd); return r; } @@ -448,7 +448,7 @@ int LUKS2_disk_hdr_write(struct crypt_device *cd, struct luks2_hdr *hdr, struct if (r) log_dbg(cd, "LUKS2 header write failed (%d).", r); - device_write_unlock(device); + device_write_unlock(cd, device); /* FIXME: try recovery here? */ @@ -765,7 +765,7 @@ int LUKS2_hdr_version_unlocked(struct crypt_device *cd, const char *backup_file) if (!backup_file) device = crypt_metadata_device(cd); - else if (device_alloc(&device, backup_file) < 0) + else if (device_alloc(cd, &device, backup_file) < 0) return 0; if (!device) @@ -779,7 +779,7 @@ int LUKS2_hdr_version_unlocked(struct crypt_device *cd, const char *backup_file) if (devfd < 0) goto err; - if ((read_lseek_blockwise(devfd, device_block_size(device), + if ((read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), &hdr, sizeof(hdr), 0) == sizeof(hdr)) && !memcmp(hdr.magic, LUKS2_MAGIC_1ST, LUKS2_MAGIC_L)) r = (int)be16_to_cpu(hdr.version); @@ -788,7 +788,7 @@ err: close(devfd); if (backup_file) - device_free(device); + device_free(cd, device); return r; } diff --git a/lib/luks2/luks2_json_metadata.c b/lib/luks2/luks2_json_metadata.c index 85944bf0..347d89d6 100644 --- a/lib/luks2/luks2_json_metadata.c +++ b/lib/luks2/luks2_json_metadata.c @@ -883,7 +883,7 @@ int LUKS2_hdr_read(struct crypt_device *cd, struct luks2_hdr *hdr, int repair) r = LUKS2_disk_hdr_read(cd, hdr, crypt_metadata_device(cd), 1, !repair); if (r == -EAGAIN) { /* unlikely: auto-recovery is required and failed due to read lock being held */ - device_read_unlock(crypt_metadata_device(cd)); + device_read_unlock(cd, crypt_metadata_device(cd)); r = device_write_lock(cd, crypt_metadata_device(cd)); if (r) { @@ -894,9 +894,9 @@ int LUKS2_hdr_read(struct crypt_device *cd, struct luks2_hdr *hdr, int repair) r = LUKS2_disk_hdr_read(cd, hdr, crypt_metadata_device(cd), 1, !repair); - device_write_unlock(crypt_metadata_device(cd)); + device_write_unlock(cd, crypt_metadata_device(cd)); } else - device_read_unlock(crypt_metadata_device(cd)); + device_read_unlock(cd, crypt_metadata_device(cd)); return r; } @@ -1004,24 +1004,24 @@ int LUKS2_hdr_backup(struct crypt_device *cd, struct luks2_hdr *hdr, return r; } - devfd = device_open_locked(device, O_RDONLY); + devfd = device_open_locked(cd, device, O_RDONLY); if (devfd < 0) { - device_read_unlock(device); + device_read_unlock(cd, device); log_err(cd, _("Device %s is not a valid LUKS device."), device_path(device)); crypt_safe_free(buffer); return devfd == -1 ? -EINVAL : devfd; } - if (read_blockwise(devfd, device_block_size(device), + if (read_blockwise(devfd, device_block_size(cd, device), device_alignment(device), buffer, hdr_size) < hdr_size) { close(devfd); - device_read_unlock(device); + device_read_unlock(cd, device); crypt_safe_free(buffer); return -EIO; } close(devfd); - device_read_unlock(device); + device_read_unlock(cd, device); devfd = open(backup_file, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR); if (devfd == -1) { @@ -1064,7 +1064,7 @@ int LUKS2_hdr_restore(struct crypt_device *cd, struct luks2_hdr *hdr, struct luks2_hdr tmp_hdr = {}; uint32_t reqs = 0; - r = device_alloc(&backup_device, backup_file); + r = device_alloc(cd, &backup_device, backup_file); if (r < 0) return r; @@ -1073,13 +1073,13 @@ int LUKS2_hdr_restore(struct crypt_device *cd, struct luks2_hdr *hdr, if (r) { log_err(cd, _("Failed to acquire read lock on device %s."), device_path(backup_device)); - device_free(backup_device); + device_free(cd, backup_device); return r; } r = LUKS2_disk_hdr_read(cd, &hdr_file, backup_device, 0, 0); - device_read_unlock(backup_device); - device_free(backup_device); + device_read_unlock(cd, backup_device); + device_free(cd, backup_device); if (r < 0) { log_err(cd, _("Backup file doesn't contain valid LUKS header.")); @@ -1170,25 +1170,25 @@ int LUKS2_hdr_restore(struct crypt_device *cd, struct luks2_hdr *hdr, goto out; } - devfd = device_open_locked(device, O_RDWR); + devfd = device_open_locked(cd, device, O_RDWR); if (devfd < 0) { if (errno == EACCES) log_err(cd, _("Cannot write to device %s, permission denied."), device_path(device)); else log_err(cd, _("Cannot open device %s."), device_path(device)); - device_write_unlock(device); + device_write_unlock(cd, device); r = -EINVAL; goto out; } - if (write_blockwise(devfd, device_block_size(device), + if (write_blockwise(devfd, device_block_size(cd, device), device_alignment(device), buffer, buffer_size) < buffer_size) r = -EIO; else r = 0; - device_write_unlock(device); + device_write_unlock(cd, device); /* end of TODO */ out: @@ -1200,7 +1200,7 @@ out: crypt_safe_free(buffer); if (devfd >= 0) { - device_sync(device, devfd); + device_sync(cd, device, devfd); close(devfd); } @@ -1923,7 +1923,7 @@ int LUKS2_activate(struct crypt_device *cd, return r; snprintf(dm_int_dev_name, sizeof(dm_int_dev_name), "%s/%s", dm_get_dir(), dm_int_name); - r = device_alloc(&device, dm_int_dev_name); + r = device_alloc(cd, &device, dm_int_dev_name); if (r) { dm_remove_device(cd, dm_int_name, 0); return r; @@ -1941,7 +1941,7 @@ int LUKS2_activate(struct crypt_device *cd, &dmd.size); if (r < 0) { log_err(cd, "Cannot detect integrity device size."); - device_free(device); + device_free(cd, device); dm_remove_device(cd, dm_int_name, 0); return r; } @@ -1955,7 +1955,7 @@ int LUKS2_activate(struct crypt_device *cd, if (r < 0 && dmd.u.crypt.integrity) dm_remove_device(cd, dm_int_name, 0); - device_free(device); + device_free(cd, device); return r; } diff --git a/lib/luks2/luks2_keyslot.c b/lib/luks2/luks2_keyslot.c index 24070aa9..84238839 100644 --- a/lib/luks2/luks2_keyslot.c +++ b/lib/luks2/luks2_keyslot.c @@ -435,7 +435,7 @@ int LUKS2_keyslot_wipe(struct crypt_device *cd, device_path(device)); return r; } - device_write_unlock(device); + device_write_unlock(cd, device); /* secure deletion of possible key material in keyslot area */ r = crypt_keyslot_area(cd, keyslot, &area_offset, &area_length); diff --git a/lib/luks2/luks2_keyslot_luks2.c b/lib/luks2/luks2_keyslot_luks2.c index 0773cd12..ea0a77cf 100644 --- a/lib/luks2/luks2_keyslot_luks2.c +++ b/lib/luks2/luks2_keyslot_luks2.c @@ -41,7 +41,7 @@ static int luks2_encrypt_to_storage(char *src, size_t srcLength, return r; } r = LUKS_encrypt_to_storage(src, srcLength, cipher, cipher_mode, vk, sector, cd); - device_write_unlock(crypt_metadata_device(cd)); + device_write_unlock(cd, crypt_metadata_device(cd)); return r; #else struct crypt_storage *s; @@ -71,21 +71,21 @@ static int luks2_encrypt_to_storage(char *src, size_t srcLength, return r; } - devfd = device_open_locked(device, O_RDWR); + devfd = device_open_locked(cd, device, O_RDWR); if (devfd >= 0) { - if (write_lseek_blockwise(devfd, device_block_size(device), + if (write_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), src, srcLength, sector * SECTOR_SIZE) < 0) r = -EIO; else r = 0; - device_sync(device, devfd); + device_sync(cd, device, devfd); close(devfd); } else r = -EIO; - device_write_unlock(device); + device_write_unlock(cd, device); if (r) log_err(cd, _("IO error while encrypting keyslot.")); @@ -106,7 +106,7 @@ static int luks2_decrypt_from_storage(char *dst, size_t dstLength, return r; } r = LUKS_decrypt_from_storage(dst, dstLength, cipher, cipher_mode, vk, sector, cd); - device_read_unlock(crypt_metadata_device(cd)); + device_read_unlock(cd, crypt_metadata_device(cd)); return r; #else struct crypt_storage *s; @@ -131,9 +131,9 @@ static int luks2_decrypt_from_storage(char *dst, size_t dstLength, return r; } - devfd = device_open_locked(device, O_RDONLY); + devfd = device_open_locked(cd, device, O_RDONLY); if (devfd >= 0) { - if (read_lseek_blockwise(devfd, device_block_size(device), + if (read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), dst, dstLength, sector * SECTOR_SIZE) < 0) r = -EIO; @@ -143,7 +143,7 @@ static int luks2_decrypt_from_storage(char *dst, size_t dstLength, } else r = -EIO; - device_read_unlock(device); + device_read_unlock(cd, device); /* Decrypt buffer */ if (!r) diff --git a/lib/luks2/luks2_luks1_convert.c b/lib/luks2/luks2_luks1_convert.c index ead16949..46451c72 100644 --- a/lib/luks2/luks2_luks1_convert.c +++ b/lib/luks2/luks2_luks1_convert.c @@ -433,7 +433,7 @@ static int move_keyslot_areas(struct crypt_device *cd, off_t offset_from, if (posix_memalign(&buf, crypt_getpagesize(), buf_size)) return -ENOMEM; - devfd = device_open(device, O_RDWR); + devfd = device_open(cd, device, O_RDWR); if (devfd == -1) { free(buf); return -EIO; @@ -444,24 +444,24 @@ static int move_keyslot_areas(struct crypt_device *cd, off_t offset_from, log_dbg(cd, "Preallocation (fallocate) of new keyslot area not available."); /* Try to read *new* area to check that area is there (trimmed backup). */ - if (read_lseek_blockwise(devfd, device_block_size(device), + if (read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), buf, buf_size, offset_to)!= (ssize_t)buf_size) goto out; - if (read_lseek_blockwise(devfd, device_block_size(device), + if (read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), buf, buf_size, offset_from)!= (ssize_t)buf_size) goto out; - if (write_lseek_blockwise(devfd, device_block_size(device), + if (write_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), buf, buf_size, offset_to) != (ssize_t)buf_size) goto out; r = 0; out: - device_sync(device, devfd); + device_sync(cd, device, devfd); close(devfd); crypt_memzero(buf, buf_size); free(buf); @@ -491,14 +491,14 @@ static int luksmeta_header_present(struct crypt_device *cd, off_t luks1_size) if (posix_memalign(&buf, crypt_getpagesize(), sizeof(LM_MAGIC))) return -ENOMEM; - devfd = device_open(device, O_RDONLY); + devfd = device_open(cd, device, O_RDONLY); if (devfd == -1) { free(buf); return -EIO; } /* Note: we must not detect failure as problem here, header can be trimmed. */ - if (read_lseek_blockwise(devfd, device_block_size(device), device_alignment(device), + if (read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), buf, sizeof(LM_MAGIC), luks1_size) == (ssize_t)sizeof(LM_MAGIC) && !memcmp(LM_MAGIC, buf, sizeof(LM_MAGIC))) { log_err(cd, _("Unable to convert header with LUKSMETA additional metadata.")); diff --git a/lib/luks2/luks2_token.c b/lib/luks2/luks2_token.c index ce93093a..52a87c6a 100644 --- a/lib/luks2/luks2_token.c +++ b/lib/luks2/luks2_token.c @@ -56,10 +56,8 @@ int crypt_token_register(const crypt_token_handler *handler) } } - if (i == LUKS2_TOKENS_MAX) { - log_dbg(NULL, "No more space for another token handler."); + if (i == LUKS2_TOKENS_MAX) return -EINVAL; - } token_handlers[i].h = handler; return 0; diff --git a/lib/setup.c b/lib/setup.c index f504cf94..228f3e53 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -567,7 +567,7 @@ int crypt_init(struct crypt_device **cd, const char *device) memset(h, 0, sizeof(*h)); - r = device_alloc(&h->device, device); + r = device_alloc(NULL, &h->device, device); if (r < 0) goto bad; @@ -578,7 +578,7 @@ int crypt_init(struct crypt_device **cd, const char *device) *cd = h; return 0; bad: - device_free(h->device); + device_free(NULL, h->device); free(h); return r; } @@ -623,14 +623,14 @@ int crypt_set_data_device(struct crypt_device *cd, const char *device) if (!cd->device || !device) return -EINVAL; - r = device_alloc(&dev, device); + r = device_alloc(cd, &dev, device); if (r < 0) return r; if (!cd->metadata_device) { cd->metadata_device = cd->device; } else - device_free(cd->device); + device_free(cd, cd->device); cd->device = dev; @@ -839,7 +839,7 @@ static int _crypt_load_verity(struct crypt_device *cd, struct crypt_params_verit return r; if (params && params->fec_device) { - r = device_alloc(&cd->u.verity.fec_device, params->fec_device); + r = device_alloc(cd, &cd->u.verity.fec_device, params->fec_device); if (r < 0) return r; cd->u.verity.hdr.fec_area_offset = params->fec_area_offset; @@ -1008,7 +1008,7 @@ static void crypt_free_type(struct crypt_device *cd) free(CONST_CAST(void*)cd->u.verity.hdr.salt); free(cd->u.verity.root_hash); free(cd->u.verity.uuid); - device_free(cd->u.verity.fec_device); + device_free(cd, cd->u.verity.fec_device); } else if (isINTEGRITY(cd->type)) { free(CONST_CAST(void*)cd->u.integrity.params.integrity); free(CONST_CAST(void*)cd->u.integrity.params.journal_integrity); @@ -1050,10 +1050,10 @@ static int _init_by_name_crypt(struct crypt_device *cd, const char *name) if (r < 0) goto out; if (dmdi.target == DM_INTEGRITY && !cd->metadata_device) { - device_free(cd->device); + device_free(cd, cd->device); cd->device = dmdi.data_device; } else - device_free(dmdi.data_device); + device_free(cd, dmdi.data_device); } if (isPLAIN(cd->type)) { @@ -1101,7 +1101,7 @@ static int _init_by_name_crypt(struct crypt_device *cd, const char *name) } out: crypt_free_volume_key(dmd.u.crypt.vk); - device_free(dmd.data_device); + device_free(cd, dmd.data_device); free(CONST_CAST(void*)dmd.u.crypt.cipher); free(CONST_CAST(void*)dmd.u.crypt.integrity); free(CONST_CAST(void*)dmd.uuid); @@ -1155,7 +1155,7 @@ out: free(CONST_CAST(void*)params.salt); free(CONST_CAST(void*)params.fec_device); } - device_free(dmd.data_device); + device_free(cd, dmd.data_device); return r; } @@ -1204,7 +1204,7 @@ out: crypt_free_volume_key(dmd.u.integrity.vk); crypt_free_volume_key(dmd.u.integrity.journal_integrity_key); crypt_free_volume_key(dmd.u.integrity.journal_crypt_key); - device_free(dmd.data_device); + device_free(cd, dmd.data_device); return r; } @@ -1248,7 +1248,7 @@ int crypt_init_by_name_and_header(struct crypt_device **cd, /* Underlying device is not readable but crypt mapping exists */ if (r == -ENOTBLK) { - device_free(dmd.data_device); + device_free(NULL, dmd.data_device); dmd.data_device = NULL; r = crypt_init(cd, NULL); } @@ -1300,7 +1300,7 @@ out: (*cd)->u.none.active_name = strdup(name); } - device_free(dmd.data_device); + device_free(NULL, dmd.data_device); free(CONST_CAST(void*)dmd.uuid); return r; } @@ -1431,13 +1431,13 @@ static int _crypt_format_luks1(struct crypt_device *cd, if (params && params->data_device) { cd->metadata_device = cd->device; cd->device = NULL; - if (device_alloc(&cd->device, params->data_device) < 0) + if (device_alloc(cd, &cd->device, params->data_device) < 0) return -ENOMEM; required_alignment = params->data_alignment * SECTOR_SIZE; } else if (params && params->data_alignment) { required_alignment = params->data_alignment * SECTOR_SIZE; } else - device_topology_alignment(cd->device, + device_topology_alignment(cd, cd->device, &required_alignment, &alignment_offset, DEFAULT_DISK_ALIGNMENT); @@ -1551,13 +1551,13 @@ static int _crypt_format_luks2(struct crypt_device *cd, if (params && params->data_device) { cd->metadata_device = cd->device; cd->device = NULL; - if (device_alloc(&cd->device, params->data_device) < 0) + if (device_alloc(cd, &cd->device, params->data_device) < 0) return -ENOMEM; required_alignment = params->data_alignment * SECTOR_SIZE; } else if (params && params->data_alignment) { required_alignment = params->data_alignment * SECTOR_SIZE; } else - device_topology_alignment(cd->device, + device_topology_alignment(cd, cd->device, &required_alignment, &alignment_offset, DEFAULT_DISK_ALIGNMENT); @@ -1770,7 +1770,7 @@ static int _crypt_format_verity(struct crypt_device *cd, fec_device_path = strdup(params->fec_device); if (!fec_device_path) return -ENOMEM; - r = device_alloc(&fec_device, params->fec_device); + r = device_alloc(cd, &fec_device, params->fec_device); if (r < 0) { r = -ENOMEM; goto err; @@ -1848,7 +1848,7 @@ static int _crypt_format_verity(struct crypt_device *cd, err: if (r) { - device_free(fec_device); + device_free(cd, fec_device); free(root_hash); free(hash_name); free(fec_device_path); @@ -2125,7 +2125,7 @@ out: free(CONST_CAST(void*)dmd.u.crypt.cipher); free(CONST_CAST(void*)dmd.u.crypt.integrity); } - device_free(dmd.data_device); + device_free(cd, dmd.data_device); free(CONST_CAST(void*)dmd.uuid); return r; @@ -2269,8 +2269,8 @@ void crypt_free(struct crypt_device *cd) dm_backend_exit(); crypt_free_volume_key(cd->volume_key); - device_free(cd->device); - device_free(cd->metadata_device); + device_free(cd, cd->device); + device_free(cd, cd->metadata_device); free(CONST_CAST(void*)cd->pbkdf.type); free(CONST_CAST(void*)cd->pbkdf.hash); @@ -3323,7 +3323,7 @@ int crypt_deactivate_by_name(struct crypt_device *cd, const char *name, uint32_t r = -EINVAL; } - device_free(dmd.data_device); + device_free(cd, dmd.data_device); crypt_free(fake_cd); return r; @@ -3359,7 +3359,7 @@ int crypt_get_active_device(struct crypt_device *cd, const char *name, if (namei && dm_query_device(cd, namei, 0, &dmdi) >= 0) dmd.flags |= dmdi.flags; } - device_free(dmd.data_device); + device_free(cd, dmd.data_device); if (cd && isTCRYPT(cd->type)) { cad->offset = TCRYPT_get_data_offset(cd, &cd->u.tcrypt.hdr, &cd->u.tcrypt.params); diff --git a/lib/tcrypt/tcrypt.c b/lib/tcrypt/tcrypt.c index 7c254b2b..c3fbd1bf 100644 --- a/lib/tcrypt/tcrypt.c +++ b/lib/tcrypt/tcrypt.c @@ -650,14 +650,14 @@ int TCRYPT_read_phdr(struct crypt_device *cd, if (!base_device_path) return -EINVAL; - r = device_alloc(&base_device, base_device_path); + r = device_alloc(cd, &base_device, base_device_path); free(base_device_path); if (r < 0) return r; - devfd = device_open(base_device, O_RDONLY); - device_free(base_device); + devfd = device_open(cd, base_device, O_RDONLY); + device_free(cd, base_device); } else - devfd = device_open(device, O_RDONLY); + devfd = device_open(cd, device, O_RDONLY); if (devfd < 0) { log_err(cd, _("Cannot open device %s."), device_path(device)); @@ -666,33 +666,33 @@ int TCRYPT_read_phdr(struct crypt_device *cd, r = -EIO; if (params->flags & CRYPT_TCRYPT_SYSTEM_HEADER) { - if (read_lseek_blockwise(devfd, device_block_size(device), + if (read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), hdr, hdr_size, TCRYPT_HDR_SYSTEM_OFFSET) == hdr_size) { r = TCRYPT_init_hdr(cd, hdr, params); } } else if (params->flags & CRYPT_TCRYPT_HIDDEN_HEADER) { if (params->flags & CRYPT_TCRYPT_BACKUP_HEADER) { - if (read_lseek_blockwise(devfd, device_block_size(device), + if (read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), hdr, hdr_size, TCRYPT_HDR_HIDDEN_OFFSET_BCK) == hdr_size) r = TCRYPT_init_hdr(cd, hdr, params); } else { - if (read_lseek_blockwise(devfd, device_block_size(device), + if (read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), hdr, hdr_size, TCRYPT_HDR_HIDDEN_OFFSET) == hdr_size) r = TCRYPT_init_hdr(cd, hdr, params); - if (r && read_lseek_blockwise(devfd, device_block_size(device), + if (r && read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), hdr, hdr_size, TCRYPT_HDR_HIDDEN_OFFSET_OLD) == hdr_size) r = TCRYPT_init_hdr(cd, hdr, params); } } else if (params->flags & CRYPT_TCRYPT_BACKUP_HEADER) { - if (read_lseek_blockwise(devfd, device_block_size(device), + if (read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), hdr, hdr_size, TCRYPT_HDR_OFFSET_BCK) == hdr_size) r = TCRYPT_init_hdr(cd, hdr, params); - } else if (read_blockwise(devfd, device_block_size(device), + } else if (read_blockwise(devfd, device_block_size(cd, device), device_alignment(device), hdr, hdr_size) == hdr_size) r = TCRYPT_init_hdr(cd, hdr, params); @@ -788,7 +788,7 @@ int TCRYPT_activate(struct crypt_device *cd, part_path = crypt_get_partition_device(device_path(dmd.data_device), dmd.u.crypt.offset, dmd.size); if (part_path) { - if (!device_alloc(&part_device, part_path)) { + if (!device_alloc(cd, &part_device, part_path)) { log_verbose(cd, _("Activating TCRYPT system encryption for partition %s."), part_path); dmd.data_device = part_device; @@ -806,7 +806,7 @@ int TCRYPT_activate(struct crypt_device *cd, r = device_block_adjust(cd, dmd.data_device, device_check, dmd.u.crypt.offset, &dmd.size, &dmd.flags); if (r) { - device_free(part_device); + device_free(cd, part_device); return r; } @@ -814,7 +814,7 @@ int TCRYPT_activate(struct crypt_device *cd, dmd.u.crypt.vk = crypt_alloc_volume_key(algs->cipher[0].key_size + algs->cipher[0].key_extra_size, NULL); if (!dmd.u.crypt.vk) { - device_free(part_device); + device_free(cd, part_device); return -ENOMEM; } @@ -837,7 +837,7 @@ int TCRYPT_activate(struct crypt_device *cd, if (algs->chain_count != i) { snprintf(dm_dev_name, sizeof(dm_dev_name), "%s/%s_%d", dm_get_dir(), name, i); - r = device_alloc(&device, dm_dev_name); + r = device_alloc(cd, &device, dm_dev_name); if (r) break; dmd.data_device = device; @@ -848,7 +848,7 @@ int TCRYPT_activate(struct crypt_device *cd, dm_name, dmd.u.crypt.cipher); r = dm_create_device(cd, dm_name, CRYPT_TCRYPT, &dmd, 0); - device_free(device); + device_free(cd, device); device = NULL; if (r) @@ -861,7 +861,7 @@ int TCRYPT_activate(struct crypt_device *cd, r = -ENOTSUP; } - device_free(part_device); + device_free(cd, part_device); crypt_free_volume_key(dmd.u.crypt.vk); return r; } @@ -944,10 +944,10 @@ static int TCRYPT_status_one(struct crypt_device *cd, const char *name, strncat(cipher, dmd.u.crypt.cipher, MAX_CIPHER_LEN); *key_size += dmd.u.crypt.vk->keylength; *data_offset = dmd.u.crypt.offset * SECTOR_SIZE; - device_free(*device); + device_free(cd, *device); *device = dmd.data_device; } else { - device_free(dmd.data_device); + device_free(cd, dmd.data_device); r = -ENODEV; } diff --git a/lib/utils_device.c b/lib/utils_device.c index 16039a6f..884ee5f2 100644 --- a/lib/utils_device.c +++ b/lib/utils_device.c @@ -153,14 +153,14 @@ static int device_read_test(int devfd) * The read test is needed to detect broken configurations (seen with remote * block devices) that allow open with direct-io but then fails on read. */ -static int device_ready(struct device *device) +static int device_ready(struct crypt_device *cd, struct device *device) { int devfd = -1, r = 0; struct stat st; size_t tmp_size; if (device->o_direct) { - log_dbg(NULL, "Trying to open and read device %s with direct-io.", + log_dbg(cd, "Trying to open and read device %s with direct-io.", device_path(device)); device->o_direct = 0; devfd = open(device_path(device), O_RDONLY | O_DIRECT); @@ -175,13 +175,13 @@ static int device_ready(struct device *device) } if (devfd < 0) { - log_dbg(NULL, "Trying to open device %s without direct-io.", + log_dbg(cd, "Trying to open device %s without direct-io.", device_path(device)); devfd = open(device_path(device), O_RDONLY); } if (devfd < 0) { - log_err(NULL, _("Device %s doesn't exist or access denied."), + log_err(cd, _("Device %s doesn't exist or access denied."), device_path(device)); return -EINVAL; } @@ -191,7 +191,7 @@ static int device_ready(struct device *device) else if (!S_ISBLK(st.st_mode)) r = S_ISREG(st.st_mode) ? -ENOTBLK : -EINVAL; if (r == -EINVAL) { - log_err(NULL, _("Device %s is not compatible."), + log_err(cd, _("Device %s is not compatible."), device_path(device)); close(devfd); return r; @@ -210,14 +210,14 @@ static int device_ready(struct device *device) return r; } -static int _open_locked(struct device *device, int flags) +static int _open_locked(struct crypt_device *cd, struct device *device, int flags) { int fd; - log_dbg(NULL, "Opening locked device %s", device_path(device)); + log_dbg(cd, "Opening locked device %s", device_path(device)); if ((flags & O_ACCMODE) != O_RDONLY && device_locked_readonly(device->lh)) { - log_dbg(NULL, "Can not open locked device %s in write mode. Read lock held.", device_path(device)); + log_dbg(cd, "Can not open locked device %s in write mode. Read lock held.", device_path(device)); return -EAGAIN; } @@ -228,7 +228,7 @@ static int _open_locked(struct device *device, int flags) if (device_locked_verify(NULL, fd, device->lh)) { /* fd doesn't correspond to a locked resource */ close(fd); - log_dbg(NULL, "Failed to verify lock resource for device %s.", device_path(device)); + log_dbg(cd, "Failed to verify lock resource for device %s.", device_path(device)); return -EINVAL; } @@ -239,10 +239,10 @@ static int _open_locked(struct device *device, int flags) * Common wrapper for device sync. * FIXME: file descriptor will be in struct later. */ -void device_sync(struct device *device, int devfd) +void device_sync(struct crypt_device *cd, struct device *device, int devfd) { if (fsync(devfd) == -1) - log_dbg(NULL, "Cannot sync device %s.", device_path(device)); + log_dbg(cd, "Cannot sync device %s.", device_path(device)); } /* @@ -254,7 +254,7 @@ void device_sync(struct device *device, int devfd) * -EINVAL : invalid lock fd state * -1 : all other errors */ -static int device_open_internal(struct device *device, int flags) +static int device_open_internal(struct crypt_device *cd, struct device *device, int flags) { int devfd; @@ -262,28 +262,28 @@ static int device_open_internal(struct device *device, int flags) flags |= O_DIRECT; if (device_locked(device->lh)) - devfd = _open_locked(device, flags); + devfd = _open_locked(cd, device, flags); else devfd = open(device_path(device), flags); if (devfd < 0) - log_dbg(NULL, "Cannot open device %s%s.", + log_dbg(cd, "Cannot open device %s%s.", device_path(device), (flags & O_ACCMODE) != O_RDONLY ? " for write" : ""); return devfd; } -int device_open(struct device *device, int flags) +int device_open(struct crypt_device *cd, struct device *device, int flags) { assert(!device_locked(device->lh)); - return device_open_internal(device, flags); + return device_open_internal(cd, device, flags); } -int device_open_locked(struct device *device, int flags) +int device_open_locked(struct crypt_device *cd, struct device *device, int flags) { assert(!crypt_metadata_locking_enabled() || device_locked(device->lh)); - return device_open_internal(device, flags); + return device_open_internal(cd, device, flags); } /* Avoid any read from device, expects direct-io to work. */ @@ -313,7 +313,7 @@ int device_alloc_no_check(struct device **device, const char *path) return 0; } -int device_alloc(struct device **device, const char *path) +int device_alloc(struct crypt_device *cd, struct device **device, const char *path) { struct device *dev; int r; @@ -323,7 +323,7 @@ int device_alloc(struct device **device, const char *path) return r; if (dev) { - r = device_ready(dev); + r = device_ready(cd, dev); if (!r) { dev->init_done = 1; } else if (r == -ENOTBLK) { @@ -339,13 +339,13 @@ int device_alloc(struct device **device, const char *path) return 0; } -void device_free(struct device *device) +void device_free(struct crypt_device *cd, struct device *device) { if (!device) return; if (device->loop_fd != -1) { - log_dbg(NULL, "Closed loop %s (%s).", device->path, device->file_path); + log_dbg(cd, "Closed loop %s (%s).", device->path, device->file_path); close(device->loop_fd); } @@ -399,10 +399,11 @@ const char *device_path(const struct device *device) #define BLKALIGNOFF _IO(0x12,122) #endif -void device_topology_alignment(struct device *device, - unsigned long *required_alignment, /* bytes */ - unsigned long *alignment_offset, /* bytes */ - unsigned long default_alignment) +void device_topology_alignment(struct crypt_device *cd, + struct device *device, + unsigned long *required_alignment, /* bytes */ + unsigned long *alignment_offset, /* bytes */ + unsigned long default_alignment) { int dev_alignment_offset = 0; unsigned int min_io_size = 0, opt_io_size = 0; @@ -421,7 +422,7 @@ void device_topology_alignment(struct device *device, /* minimum io size */ if (ioctl(fd, BLKIOMIN, &min_io_size) == -1) { - log_dbg(NULL, "Topology info for %s not supported, using default offset %lu bytes.", + log_dbg(cd, "Topology info for %s not supported, using default offset %lu bytes.", device->path, default_alignment); goto out; } @@ -446,13 +447,13 @@ void device_topology_alignment(struct device *device, if (temp_alignment && (default_alignment % temp_alignment)) *required_alignment = temp_alignment; - log_dbg(NULL, "Topology: IO (%u/%u), offset = %lu; Required alignment is %lu bytes.", + log_dbg(cd, "Topology: IO (%u/%u), offset = %lu; Required alignment is %lu bytes.", min_io_size, opt_io_size, *alignment_offset, *required_alignment); out: (void)close(fd); } -size_t device_block_size(struct device *device) +size_t device_block_size(struct crypt_device *cd, struct device *device) { int fd; @@ -469,7 +470,7 @@ size_t device_block_size(struct device *device) } if (!device->block_size) - log_dbg(NULL, "Cannot get block size for device %s.", device_path(device)); + log_dbg(cd, "Cannot get block size for device %s.", device_path(device)); return device->block_size; } @@ -660,7 +661,7 @@ static int device_internal_prepare(struct crypt_device *cd, struct device *devic file_path = device->path; device->path = loop_device; - r = device_ready(device); + r = device_ready(cd, device); if (r < 0) { device->path = file_path; crypt_loop_detach(loop_device); @@ -822,30 +823,30 @@ int device_write_lock(struct crypt_device *cd, struct device *device) return -EBUSY; } -void device_read_unlock(struct device *device) +void device_read_unlock(struct crypt_device *cd, struct device *device) { if (!crypt_metadata_locking_enabled()) return; assert(device_locked(device->lh) && device_locked_readonly(device->lh)); - device_unlock_handle(NULL, device->lh); + device_unlock_handle(cd, device->lh); - log_dbg(NULL, "Device %s READ lock released.", device_path(device)); + log_dbg(cd, "Device %s READ lock released.", device_path(device)); device->lh = NULL; } -void device_write_unlock(struct device *device) +void device_write_unlock(struct crypt_device *cd, struct device *device) { if (!crypt_metadata_locking_enabled()) return; assert(device_locked(device->lh) && !device_locked_readonly(device->lh)); - device_unlock_handle(NULL, device->lh); + device_unlock_handle(cd, device->lh); - log_dbg(NULL, "Device %s WRITE lock released.", device_path(device)); + log_dbg(cd, "Device %s WRITE lock released.", device_path(device)); device->lh = NULL; } diff --git a/lib/utils_wipe.c b/lib/utils_wipe.c index e0e31e6c..f375c3c6 100644 --- a/lib/utils_wipe.c +++ b/lib/utils_wipe.c @@ -145,7 +145,7 @@ int crypt_wipe_device(struct crypt_device *cd, bool need_block_init = true; /* Note: LUKS1 calls it with wipe_block not aligned to multiple of bsize */ - bsize = device_block_size(device); + bsize = device_block_size(cd, device); alignment = device_alignment(device); if (!bsize || !alignment || !wipe_block_size) return -EINVAL; @@ -156,7 +156,7 @@ int crypt_wipe_device(struct crypt_device *cd, if (MISALIGNED_512(offset) || MISALIGNED_512(length) || MISALIGNED_512(wipe_block_size)) return -EINVAL; - devfd = device_open(device, O_RDWR); + devfd = device_open(cd, device, O_RDWR); if (devfd < 0) return errno ? -errno : -EINVAL; @@ -216,7 +216,7 @@ int crypt_wipe_device(struct crypt_device *cd, } } - device_sync(device, devfd); + device_sync(cd, device, devfd); out: close(devfd); free(sf); @@ -260,7 +260,7 @@ int crypt_wipe(struct crypt_device *cd, wipe_block_size, progress, usrptr); if (dev_path) - device_free(device); + device_free(cd, device); return r; } diff --git a/lib/verity/verity.c b/lib/verity/verity.c index ae718984..e1aa3019 100644 --- a/lib/verity/verity.c +++ b/lib/verity/verity.c @@ -76,13 +76,13 @@ int VERITY_read_sb(struct crypt_device *cd, return -EINVAL; } - devfd = device_open(device, O_RDONLY); + devfd = device_open(cd, device, O_RDONLY); if (devfd < 0) { log_err(cd, _("Cannot open device %s."), device_path(device)); return -EINVAL; } - if (read_lseek_blockwise(devfd, device_block_size(device), + if (read_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), &sb, hdr_size, sb_offset) < hdr_size) { close(devfd); @@ -177,7 +177,7 @@ int VERITY_write_sb(struct crypt_device *cd, return -EINVAL; } - devfd = device_open(device, O_RDWR); + devfd = device_open(cd, device, O_RDWR); if (devfd < 0) { log_err(cd, _("Cannot open device %s."), device_path(device)); return -EINVAL; @@ -196,13 +196,13 @@ int VERITY_write_sb(struct crypt_device *cd, memcpy(sb.salt, params->salt, params->salt_size); memcpy(sb.uuid, uuid, sizeof(sb.uuid)); - r = write_lseek_blockwise(devfd, device_block_size(device), device_alignment(device), + r = write_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), (char*)&sb, hdr_size, sb_offset) < hdr_size ? -EIO : 0; if (r) log_err(cd, _("Error during update of verity header on device %s."), device_path(device)); - device_sync(device, devfd); + device_sync(cd, device, devfd); close(devfd); return r;