mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 11:50:10 +01:00
Replace round_up macro with function.
This commit is contained in:
@@ -84,6 +84,7 @@ int device_block_adjust(struct crypt_device *cd,
|
|||||||
uint64_t device_offset,
|
uint64_t device_offset,
|
||||||
uint64_t *size,
|
uint64_t *size,
|
||||||
uint32_t *flags);
|
uint32_t *flags);
|
||||||
|
size_t size_round_up(size_t size, unsigned int block);
|
||||||
|
|
||||||
/* Receive backend devices from context helpers */
|
/* Receive backend devices from context helpers */
|
||||||
struct device *crypt_metadata_device(struct crypt_device *cd);
|
struct device *crypt_metadata_device(struct crypt_device *cd);
|
||||||
|
|||||||
@@ -36,22 +36,12 @@
|
|||||||
#include "luks.h"
|
#include "luks.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
#define div_round_up(a,b) ({ \
|
|
||||||
typeof(a) __a = (a); \
|
|
||||||
typeof(b) __b = (b); \
|
|
||||||
(__a - 1) / __b + 1; \
|
|
||||||
})
|
|
||||||
|
|
||||||
static inline int round_up_modulo(int x, int m) {
|
|
||||||
return div_round_up(x, m) * m;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *cleaner_name=NULL;
|
static const char *cleaner_name=NULL;
|
||||||
static uint64_t cleaner_size = 0;
|
static uint64_t cleaner_size = 0;
|
||||||
static int devfd=-1;
|
static int devfd=-1;
|
||||||
|
|
||||||
static int setup_mapping(const char *cipher, const char *name,
|
static int setup_mapping(const char *cipher, const char *name,
|
||||||
int bsize, struct volume_key *vk,
|
unsigned int bsize, struct volume_key *vk,
|
||||||
unsigned int sector, size_t srcLength,
|
unsigned int sector, size_t srcLength,
|
||||||
int mode, struct crypt_device *ctx)
|
int mode, struct crypt_device *ctx)
|
||||||
{
|
{
|
||||||
@@ -59,7 +49,7 @@ static int setup_mapping(const char *cipher, const char *name,
|
|||||||
struct crypt_dm_active_device dmd = {
|
struct crypt_dm_active_device dmd = {
|
||||||
.target = DM_CRYPT,
|
.target = DM_CRYPT,
|
||||||
.uuid = NULL,
|
.uuid = NULL,
|
||||||
.size = round_up_modulo(srcLength, bsize) / SECTOR_SIZE,
|
.size = size_round_up(srcLength, bsize) / SECTOR_SIZE,
|
||||||
.flags = CRYPT_ACTIVATE_PRIVATE,
|
.flags = CRYPT_ACTIVATE_PRIVATE,
|
||||||
.data_device = device,
|
.data_device = device,
|
||||||
.u.crypt = {
|
.u.crypt = {
|
||||||
|
|||||||
@@ -36,27 +36,17 @@
|
|||||||
#include "pbkdf.h"
|
#include "pbkdf.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
#define div_round_up(a,b) ({ \
|
/* Get size of struct luks_phdr with all keyslots material space */
|
||||||
typeof(a) __a = (a); \
|
static size_t LUKS_device_sectors(size_t keyLen)
|
||||||
typeof(b) __b = (b); \
|
|
||||||
(__a - 1) / __b + 1; \
|
|
||||||
})
|
|
||||||
|
|
||||||
static inline int round_up_modulo(int x, int m) {
|
|
||||||
return div_round_up(x, m) * m;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get size of struct luks_phrd with all keyslots material space */
|
|
||||||
static uint64_t LUKS_device_sectors(size_t keyLen)
|
|
||||||
{
|
{
|
||||||
uint64_t keyslot_sectors, sector;
|
size_t keyslot_sectors, sector;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
keyslot_sectors = AF_split_sectors(keyLen, LUKS_STRIPES);
|
keyslot_sectors = AF_split_sectors(keyLen, LUKS_STRIPES);
|
||||||
sector = LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE;
|
sector = LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE;
|
||||||
|
|
||||||
for (i = 0; i < LUKS_NUMKEYS; i++) {
|
for (i = 0; i < LUKS_NUMKEYS; i++) {
|
||||||
sector = round_up_modulo(sector, LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE);
|
sector = size_round_up(sector, LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE);
|
||||||
sector += keyslot_sectors;
|
sector += keyslot_sectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -621,10 +611,9 @@ int LUKS_generate_phdr(struct luks_phdr *header,
|
|||||||
struct crypt_device *ctx)
|
struct crypt_device *ctx)
|
||||||
{
|
{
|
||||||
unsigned int i=0;
|
unsigned int i=0;
|
||||||
unsigned int blocksPerStripeSet = AF_split_sectors(vk->keylength, stripes);
|
size_t blocksPerStripeSet, currentSector;
|
||||||
int r;
|
int r;
|
||||||
uuid_t partitionUuid;
|
uuid_t partitionUuid;
|
||||||
int currentSector;
|
|
||||||
char luksMagic[] = LUKS_MAGIC;
|
char luksMagic[] = LUKS_MAGIC;
|
||||||
|
|
||||||
/* For separate metadata device allow zero alignment */
|
/* For separate metadata device allow zero alignment */
|
||||||
@@ -685,11 +674,12 @@ int LUKS_generate_phdr(struct luks_phdr *header,
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentSector = LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE;
|
currentSector = LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE;
|
||||||
|
blocksPerStripeSet = AF_split_sectors(vk->keylength, stripes);
|
||||||
for(i = 0; i < LUKS_NUMKEYS; ++i) {
|
for(i = 0; i < LUKS_NUMKEYS; ++i) {
|
||||||
header->keyblock[i].active = LUKS_KEY_DISABLED;
|
header->keyblock[i].active = LUKS_KEY_DISABLED;
|
||||||
header->keyblock[i].keyMaterialOffset = currentSector;
|
header->keyblock[i].keyMaterialOffset = currentSector;
|
||||||
header->keyblock[i].stripes = stripes;
|
header->keyblock[i].stripes = stripes;
|
||||||
currentSector = round_up_modulo(currentSector + blocksPerStripeSet,
|
currentSector = size_round_up(currentSector + blocksPerStripeSet,
|
||||||
LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE);
|
LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -698,7 +688,7 @@ int LUKS_generate_phdr(struct luks_phdr *header,
|
|||||||
header->payloadOffset = alignPayload;
|
header->payloadOffset = alignPayload;
|
||||||
} else {
|
} else {
|
||||||
/* alignOffset - offset from natural device alignment provided by topology info */
|
/* alignOffset - offset from natural device alignment provided by topology info */
|
||||||
currentSector = round_up_modulo(currentSector, alignPayload);
|
currentSector = size_round_up(currentSector, alignPayload);
|
||||||
header->payloadOffset = currentSector + alignOffset;
|
header->payloadOffset = currentSector + alignOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -421,3 +421,9 @@ int device_block_adjust(struct crypt_device *cd,
|
|||||||
*size, real_readonly ? "RO" : "RW", device_offset);
|
*size, real_readonly ? "RO" : "RW", device_offset);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t size_round_up(size_t size, unsigned int block)
|
||||||
|
{
|
||||||
|
size_t s = (size + (block - 1)) / block;
|
||||||
|
return s * block;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user