mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-17 05:40:13 +01:00
Merge progress functions into single routine.
This commit is contained in:
@@ -1182,7 +1182,8 @@ static int _wipe_data_device(struct crypt_device *cd)
|
|||||||
int r;
|
int r;
|
||||||
struct tools_progress_params prog_parms = {
|
struct tools_progress_params prog_parms = {
|
||||||
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
||||||
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID)
|
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID),
|
||||||
|
.interrupt_message = _("\nWipe interrupted.")
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!ARG_SET(OPT_BATCH_MODE_ID))
|
if (!ARG_SET(OPT_BATCH_MODE_ID))
|
||||||
@@ -1206,7 +1207,7 @@ static int _wipe_data_device(struct crypt_device *cd)
|
|||||||
/* Wipe the device */
|
/* Wipe the device */
|
||||||
set_int_handler(0);
|
set_int_handler(0);
|
||||||
r = crypt_wipe(cd, tmp_path, CRYPT_WIPE_ZERO, 0, 0, DEFAULT_WIPE_BLOCK,
|
r = crypt_wipe(cd, tmp_path, CRYPT_WIPE_ZERO, 0, 0, DEFAULT_WIPE_BLOCK,
|
||||||
0, &tools_wipe_progress, &prog_parms);
|
0, &tools_progress, &prog_parms);
|
||||||
if (crypt_deactivate(cd, tmp_name))
|
if (crypt_deactivate(cd, tmp_name))
|
||||||
log_err(_("Cannot deactivate temporary device %s."), tmp_path);
|
log_err(_("Cannot deactivate temporary device %s."), tmp_path);
|
||||||
set_int_block(0);
|
set_int_block(0);
|
||||||
|
|||||||
@@ -96,10 +96,10 @@ struct tools_progress_params {
|
|||||||
struct timeval end_time;
|
struct timeval end_time;
|
||||||
uint64_t start_offset;
|
uint64_t start_offset;
|
||||||
bool batch_mode;
|
bool batch_mode;
|
||||||
|
const char *interrupt_message;
|
||||||
};
|
};
|
||||||
|
|
||||||
int tools_wipe_progress(uint64_t size, uint64_t offset, void *usrptr);
|
int tools_progress(uint64_t size, uint64_t offset, void *usrptr);
|
||||||
int tools_reencrypt_progress(uint64_t size, uint64_t offset, void *usrptr);
|
|
||||||
|
|
||||||
int tools_read_mk(const char *file, char **key, int keysize);
|
int tools_read_mk(const char *file, char **key, int keysize);
|
||||||
int tools_write_mk(const char *file, const char *key, int keysize);
|
int tools_write_mk(const char *file, const char *key, int keysize);
|
||||||
|
|||||||
@@ -83,7 +83,8 @@ static int _wipe_data_device(struct crypt_device *cd, const char *integrity_key)
|
|||||||
int r;
|
int r;
|
||||||
struct tools_progress_params prog_parms = {
|
struct tools_progress_params prog_parms = {
|
||||||
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
||||||
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID)
|
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID),
|
||||||
|
.interrupt_message = _("\nWipe interrupted.")
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!ARG_SET(OPT_BATCH_MODE_ID))
|
if (!ARG_SET(OPT_BATCH_MODE_ID))
|
||||||
@@ -107,7 +108,7 @@ static int _wipe_data_device(struct crypt_device *cd, const char *integrity_key)
|
|||||||
/* Wipe the device */
|
/* Wipe the device */
|
||||||
set_int_handler(0);
|
set_int_handler(0);
|
||||||
r = crypt_wipe(cd, tmp_path, CRYPT_WIPE_ZERO, 0, 0, DEFAULT_WIPE_BLOCK,
|
r = crypt_wipe(cd, tmp_path, CRYPT_WIPE_ZERO, 0, 0, DEFAULT_WIPE_BLOCK,
|
||||||
0, &tools_wipe_progress, &prog_parms);
|
0, &tools_progress, &prog_parms);
|
||||||
if (crypt_deactivate(cd, tmp_name))
|
if (crypt_deactivate(cd, tmp_name))
|
||||||
log_err(_("Cannot deactivate temporary device %s."), tmp_path);
|
log_err(_("Cannot deactivate temporary device %s."), tmp_path);
|
||||||
set_int_block(0);
|
set_int_block(0);
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ static void tools_time_progress(uint64_t device_size, uint64_t bytes, struct too
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tools_wipe_progress(uint64_t size, uint64_t offset, void *usrptr)
|
int tools_progress(uint64_t size, uint64_t offset, void *usrptr)
|
||||||
{
|
{
|
||||||
int r = 0;
|
int r = 0;
|
||||||
struct tools_progress_params *parms = (struct tools_progress_params *)usrptr;
|
struct tools_progress_params *parms = (struct tools_progress_params *)usrptr;
|
||||||
@@ -236,25 +236,8 @@ int tools_wipe_progress(uint64_t size, uint64_t offset, void *usrptr)
|
|||||||
if (r) {
|
if (r) {
|
||||||
if (!parms || !parms->frequency)
|
if (!parms || !parms->frequency)
|
||||||
tools_clear_line();
|
tools_clear_line();
|
||||||
log_err(_("\nWipe interrupted."));
|
if (parms && parms->interrupt_message)
|
||||||
}
|
log_err("%s", parms->interrupt_message);
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
int tools_reencrypt_progress(uint64_t size, uint64_t offset, void *usrptr)
|
|
||||||
{
|
|
||||||
int r = 0;
|
|
||||||
struct tools_progress_params *parms = (struct tools_progress_params *)usrptr;
|
|
||||||
|
|
||||||
if (parms && !parms->batch_mode)
|
|
||||||
tools_time_progress(size, offset, parms);
|
|
||||||
|
|
||||||
check_signal(&r);
|
|
||||||
if (r) {
|
|
||||||
if (!parms || !parms->frequency)
|
|
||||||
tools_clear_line();
|
|
||||||
log_err(_("\nReencryption interrupted."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
@@ -853,7 +853,8 @@ static int encrypt_luks2(int action_argc, const char **action_argv)
|
|||||||
struct crypt_device *cd = NULL;
|
struct crypt_device *cd = NULL;
|
||||||
struct tools_progress_params prog_parms = {
|
struct tools_progress_params prog_parms = {
|
||||||
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
||||||
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID)
|
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID),
|
||||||
|
.interrupt_message = _("\nReencryption interrupted.")
|
||||||
};
|
};
|
||||||
|
|
||||||
if (ARG_SET(OPT_RESUME_ONLY_ID)) {
|
if (ARG_SET(OPT_RESUME_ONLY_ID)) {
|
||||||
@@ -881,7 +882,7 @@ static int encrypt_luks2(int action_argc, const char **action_argv)
|
|||||||
|
|
||||||
if (r >= 0 && !ARG_SET(OPT_INIT_ONLY_ID)) {
|
if (r >= 0 && !ARG_SET(OPT_INIT_ONLY_ID)) {
|
||||||
set_int_handler(0);
|
set_int_handler(0);
|
||||||
r = crypt_reencrypt_run(cd, tools_reencrypt_progress, &prog_parms);
|
r = crypt_reencrypt_run(cd, tools_progress, &prog_parms);
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
crypt_free(cd);
|
crypt_free(cd);
|
||||||
@@ -894,7 +895,8 @@ static int decrypt_luks2(struct crypt_device *cd, int action_argc, const char **
|
|||||||
int r = 0;
|
int r = 0;
|
||||||
struct tools_progress_params prog_parms = {
|
struct tools_progress_params prog_parms = {
|
||||||
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
||||||
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID)
|
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID),
|
||||||
|
.interrupt_message = _("\nReencryption interrupted.")
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!ARG_SET(OPT_HEADER_ID)) {
|
if (!ARG_SET(OPT_HEADER_ID)) {
|
||||||
@@ -922,7 +924,7 @@ static int decrypt_luks2(struct crypt_device *cd, int action_argc, const char **
|
|||||||
|
|
||||||
if (r >= 0 && !ARG_SET(OPT_INIT_ONLY_ID)) {
|
if (r >= 0 && !ARG_SET(OPT_INIT_ONLY_ID)) {
|
||||||
set_int_handler(0);
|
set_int_handler(0);
|
||||||
r = crypt_reencrypt_run(cd, tools_reencrypt_progress, &prog_parms);
|
r = crypt_reencrypt_run(cd, tools_progress, &prog_parms);
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
@@ -933,7 +935,8 @@ static int reencrypt_luks2(struct crypt_device *cd, int action_argc, const char
|
|||||||
int r;
|
int r;
|
||||||
struct tools_progress_params prog_parms = {
|
struct tools_progress_params prog_parms = {
|
||||||
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
||||||
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID)
|
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID),
|
||||||
|
.interrupt_message = _("\nReencryption interrupted.")
|
||||||
};
|
};
|
||||||
|
|
||||||
r = luks2_reencrypt_in_progress(cd);
|
r = luks2_reencrypt_in_progress(cd);
|
||||||
@@ -956,7 +959,7 @@ static int reencrypt_luks2(struct crypt_device *cd, int action_argc, const char
|
|||||||
|
|
||||||
if (r >= 0 && !ARG_SET(OPT_INIT_ONLY_ID)) {
|
if (r >= 0 && !ARG_SET(OPT_INIT_ONLY_ID)) {
|
||||||
set_int_handler(0);
|
set_int_handler(0);
|
||||||
r = crypt_reencrypt_run(cd, tools_reencrypt_progress, &prog_parms);
|
r = crypt_reencrypt_run(cd, tools_progress, &prog_parms);
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
@@ -719,7 +719,8 @@ static int copy_data_forward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
|||||||
ssize_t s1, s2;
|
ssize_t s1, s2;
|
||||||
struct tools_progress_params prog_parms = {
|
struct tools_progress_params prog_parms = {
|
||||||
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
||||||
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID)
|
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID),
|
||||||
|
.interrupt_message = _("\nReencryption interrupted.")
|
||||||
};
|
};
|
||||||
|
|
||||||
log_dbg("Reencrypting in forward direction.");
|
log_dbg("Reencrypting in forward direction.");
|
||||||
@@ -732,7 +733,7 @@ static int copy_data_forward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
|||||||
|
|
||||||
rc->resume_bytes = *bytes = rc->device_offset;
|
rc->resume_bytes = *bytes = rc->device_offset;
|
||||||
|
|
||||||
tools_reencrypt_progress(rc->device_size, *bytes, &prog_parms);
|
tools_progress(rc->device_size, *bytes, &prog_parms);
|
||||||
|
|
||||||
if (write_log(rc) < 0)
|
if (write_log(rc) < 0)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
@@ -770,7 +771,7 @@ static int copy_data_forward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
|||||||
|
|
||||||
*bytes += (uint64_t)s2;
|
*bytes += (uint64_t)s2;
|
||||||
|
|
||||||
tools_reencrypt_progress(rc->device_size, *bytes, &prog_parms);
|
tools_progress(rc->device_size, *bytes, &prog_parms);
|
||||||
}
|
}
|
||||||
|
|
||||||
return quit ? -EAGAIN : 0;
|
return quit ? -EAGAIN : 0;
|
||||||
@@ -783,7 +784,8 @@ static int copy_data_backward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
|||||||
off64_t working_offset;
|
off64_t working_offset;
|
||||||
struct tools_progress_params prog_parms = {
|
struct tools_progress_params prog_parms = {
|
||||||
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
||||||
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID)
|
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID),
|
||||||
|
.interrupt_message = _("\nReencryption interrupted.")
|
||||||
};
|
};
|
||||||
|
|
||||||
log_dbg("Reencrypting in backward direction.");
|
log_dbg("Reencrypting in backward direction.");
|
||||||
@@ -797,7 +799,7 @@ static int copy_data_backward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
|||||||
*bytes = rc->resume_bytes;
|
*bytes = rc->resume_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
tools_reencrypt_progress(rc->device_size, *bytes, &prog_parms);
|
tools_progress(rc->device_size, *bytes, &prog_parms);
|
||||||
|
|
||||||
if (write_log(rc) < 0)
|
if (write_log(rc) < 0)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
@@ -845,7 +847,7 @@ static int copy_data_backward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
|||||||
|
|
||||||
*bytes += (uint64_t)s2;
|
*bytes += (uint64_t)s2;
|
||||||
|
|
||||||
tools_reencrypt_progress(rc->device_size, *bytes, &prog_parms);
|
tools_progress(rc->device_size, *bytes, &prog_parms);
|
||||||
}
|
}
|
||||||
|
|
||||||
return quit ? -EAGAIN : 0;
|
return quit ? -EAGAIN : 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user