mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-22 16:20:01 +01:00
Create smaller header device.
This commit is contained in:
@@ -95,6 +95,7 @@ struct {
|
|||||||
int keyslot;
|
int keyslot;
|
||||||
|
|
||||||
struct timeval start_time, end_time;
|
struct timeval start_time, end_time;
|
||||||
|
uint64_t restart_bytest;
|
||||||
} rnc;
|
} rnc;
|
||||||
|
|
||||||
char MAGIC[] = {'L','U','K','S', 0xba, 0xbe};
|
char MAGIC[] = {'L','U','K','S', 0xba, 0xbe};
|
||||||
@@ -259,11 +260,17 @@ out:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int create_empty_header(const char *new_file, uint64_t size)
|
static int create_empty_header(const char *new_file, const char *old_file)
|
||||||
{
|
{
|
||||||
|
struct stat st;
|
||||||
|
size_t size;
|
||||||
int fd, r = 0;
|
int fd, r = 0;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
|
if (stat(old_file, &st) == -1 || (st.st_mode & S_IFMT) != S_IFREG)
|
||||||
|
return -EINVAL;
|
||||||
|
size = st.st_size;
|
||||||
|
|
||||||
log_dbg("Creating empty file %s of size %lu.", new_file, (unsigned long)size);
|
log_dbg("Creating empty file %s of size %lu.", new_file, (unsigned long)size);
|
||||||
|
|
||||||
if (!(buf = malloc(size)))
|
if (!(buf = malloc(size)))
|
||||||
@@ -453,8 +460,7 @@ static int backup_luks_headers(void)
|
|||||||
if ((r = crypt_header_backup(cd, CRYPT_LUKS1, rnc.header_file_org)))
|
if ((r = crypt_header_backup(cd, CRYPT_LUKS1, rnc.header_file_org)))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if ((r = create_empty_header(rnc.header_file_new,
|
if ((r = create_empty_header(rnc.header_file_new, rnc.header_file_org)))
|
||||||
crypt_get_data_offset(cd) * 512)))
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
params.hash = opt_hash ?: DEFAULT_LUKS1_HASH;
|
params.hash = opt_hash ?: DEFAULT_LUKS1_HASH;
|
||||||
@@ -527,7 +533,7 @@ static int restore_luks_header(const char *backup)
|
|||||||
|
|
||||||
void print_progress(uint64_t bytes, int final)
|
void print_progress(uint64_t bytes, int final)
|
||||||
{
|
{
|
||||||
uint64_t mbytes = bytes / 1024 / 1024;
|
uint64_t mbytes = (bytes - rnc.restart_bytest) / 1024 / 1024;
|
||||||
struct timeval now_time;
|
struct timeval now_time;
|
||||||
double tdiff;
|
double tdiff;
|
||||||
|
|
||||||
@@ -556,7 +562,7 @@ static int copy_data_forward(int fd_old, int fd_new, size_t block_size, void *bu
|
|||||||
{
|
{
|
||||||
ssize_t s1, s2;
|
ssize_t s1, s2;
|
||||||
|
|
||||||
*bytes = rnc.device_offset;
|
rnc.restart_bytest = *bytes = rnc.device_offset;
|
||||||
while (!quit && rnc.device_offset < rnc.device_size) {
|
while (!quit && rnc.device_offset < rnc.device_size) {
|
||||||
s1 = read(fd_old, buf, block_size);
|
s1 = read(fd_old, buf, block_size);
|
||||||
if (s1 < 0 || (s1 != block_size && (rnc.device_offset + s1) != rnc.device_size)) {
|
if (s1 < 0 || (s1 != block_size && (rnc.device_offset + s1) != rnc.device_size)) {
|
||||||
@@ -586,7 +592,7 @@ static int copy_data_backward(int fd_old, int fd_new, size_t block_size, void *b
|
|||||||
ssize_t s1, s2, working_block;
|
ssize_t s1, s2, working_block;
|
||||||
off64_t working_offset;
|
off64_t working_offset;
|
||||||
|
|
||||||
*bytes = rnc.device_size - rnc.device_offset;
|
rnc.restart_bytest = *bytes = rnc.device_size - rnc.device_offset;
|
||||||
while (!quit && rnc.device_offset) {
|
while (!quit && rnc.device_offset) {
|
||||||
if (rnc.device_offset < block_size) {
|
if (rnc.device_offset < block_size) {
|
||||||
working_offset = 0;
|
working_offset = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user