mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-16 21:29:59 +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;
|
||||
struct tools_progress_params prog_parms = {
|
||||
.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))
|
||||
@@ -1206,7 +1207,7 @@ static int _wipe_data_device(struct crypt_device *cd)
|
||||
/* Wipe the device */
|
||||
set_int_handler(0);
|
||||
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))
|
||||
log_err(_("Cannot deactivate temporary device %s."), tmp_path);
|
||||
set_int_block(0);
|
||||
|
||||
@@ -96,10 +96,10 @@ struct tools_progress_params {
|
||||
struct timeval end_time;
|
||||
uint64_t start_offset;
|
||||
bool batch_mode;
|
||||
const char *interrupt_message;
|
||||
};
|
||||
|
||||
int tools_wipe_progress(uint64_t size, uint64_t offset, void *usrptr);
|
||||
int tools_reencrypt_progress(uint64_t size, uint64_t offset, void *usrptr);
|
||||
int tools_progress(uint64_t size, uint64_t offset, void *usrptr);
|
||||
|
||||
int tools_read_mk(const char *file, 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;
|
||||
struct tools_progress_params prog_parms = {
|
||||
.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))
|
||||
@@ -107,7 +108,7 @@ static int _wipe_data_device(struct crypt_device *cd, const char *integrity_key)
|
||||
/* Wipe the device */
|
||||
set_int_handler(0);
|
||||
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))
|
||||
log_err(_("Cannot deactivate temporary device %s."), tmp_path);
|
||||
set_int_block(0);
|
||||
|
||||
@@ -224,7 +224,7 @@ static void tools_time_progress(uint64_t device_size, uint64_t bytes, struct too
|
||||
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;
|
||||
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 (!parms || !parms->frequency)
|
||||
tools_clear_line();
|
||||
log_err(_("\nWipe interrupted."));
|
||||
}
|
||||
|
||||
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."));
|
||||
if (parms && parms->interrupt_message)
|
||||
log_err("%s", parms->interrupt_message);
|
||||
}
|
||||
|
||||
return r;
|
||||
|
||||
@@ -853,7 +853,8 @@ static int encrypt_luks2(int action_argc, const char **action_argv)
|
||||
struct crypt_device *cd = NULL;
|
||||
struct tools_progress_params prog_parms = {
|
||||
.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)) {
|
||||
@@ -881,7 +882,7 @@ static int encrypt_luks2(int action_argc, const char **action_argv)
|
||||
|
||||
if (r >= 0 && !ARG_SET(OPT_INIT_ONLY_ID)) {
|
||||
set_int_handler(0);
|
||||
r = crypt_reencrypt_run(cd, tools_reencrypt_progress, &prog_parms);
|
||||
r = crypt_reencrypt_run(cd, tools_progress, &prog_parms);
|
||||
}
|
||||
out:
|
||||
crypt_free(cd);
|
||||
@@ -894,7 +895,8 @@ static int decrypt_luks2(struct crypt_device *cd, int action_argc, const char **
|
||||
int r = 0;
|
||||
struct tools_progress_params prog_parms = {
|
||||
.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)) {
|
||||
@@ -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)) {
|
||||
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;
|
||||
@@ -933,7 +935,8 @@ static int reencrypt_luks2(struct crypt_device *cd, int action_argc, const char
|
||||
int r;
|
||||
struct tools_progress_params prog_parms = {
|
||||
.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);
|
||||
@@ -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)) {
|
||||
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;
|
||||
|
||||
@@ -719,7 +719,8 @@ static int copy_data_forward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
||||
ssize_t s1, s2;
|
||||
struct tools_progress_params prog_parms = {
|
||||
.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.");
|
||||
@@ -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;
|
||||
|
||||
tools_reencrypt_progress(rc->device_size, *bytes, &prog_parms);
|
||||
tools_progress(rc->device_size, *bytes, &prog_parms);
|
||||
|
||||
if (write_log(rc) < 0)
|
||||
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;
|
||||
|
||||
tools_reencrypt_progress(rc->device_size, *bytes, &prog_parms);
|
||||
tools_progress(rc->device_size, *bytes, &prog_parms);
|
||||
}
|
||||
|
||||
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;
|
||||
struct tools_progress_params prog_parms = {
|
||||
.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.");
|
||||
@@ -797,7 +799,7 @@ static int copy_data_backward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
||||
*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)
|
||||
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;
|
||||
|
||||
tools_reencrypt_progress(rc->device_size, *bytes, &prog_parms);
|
||||
tools_progress(rc->device_size, *bytes, &prog_parms);
|
||||
}
|
||||
|
||||
return quit ? -EAGAIN : 0;
|
||||
|
||||
Reference in New Issue
Block a user