mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-17 13:50:06 +01:00
Move duplicated failed message to verbose level, add some debug messages, fix resize call.
git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@126 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
* Add crypt_log to library.
|
||||
* Fix crypt_remove_device (remove, luksClose) implementation.
|
||||
* Move dm backend initialisation to library calls.
|
||||
* Move duplicate Command failed message to verbose level (error is printed always).
|
||||
|
||||
2009-09-28 Milan Broz <mbroz@redhat.com>
|
||||
* Add luksHeaderBackup and luksHeaderRestore commands.
|
||||
|
||||
35
lib/setup.c
35
lib/setup.c
@@ -269,6 +269,8 @@ static int device_check_and_adjust(struct crypt_device *cd,
|
||||
if (infos.readonly)
|
||||
*read_only = 1;
|
||||
|
||||
log_dbg("Calculated device size is %" PRIu64 " sectors (%s), offset %" PRIu64 ".",
|
||||
*size, *read_only ? "RO" : "RW", *offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -643,15 +645,20 @@ int crypt_resize_device(struct crypt_options *options)
|
||||
uint64_t size, skip, offset;
|
||||
int key_size, read_only, r;
|
||||
|
||||
log_dbg("Resizing device %s to %" PRIu64 " sectors.", options->name, options->size);
|
||||
|
||||
if (dm_init(NULL, 1) < 0)
|
||||
return -ENOSYS;
|
||||
|
||||
r = dm_query_device(options->name, &device, &size, &skip, &offset,
|
||||
&cipher, &key_size, &key, &read_only, NULL, &uuid);
|
||||
if (r < 0)
|
||||
if (r < 0) {
|
||||
log_err(NULL, _("Device %s is not active.\n"), options->name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Try to determine type of device from UUID */
|
||||
type = CRYPT_PLAIN;
|
||||
if (uuid) {
|
||||
if (!strncmp(uuid, CRYPT_PLAIN, strlen(CRYPT_PLAIN))) {
|
||||
type = CRYPT_PLAIN;
|
||||
@@ -661,6 +668,9 @@ int crypt_resize_device(struct crypt_options *options)
|
||||
type = CRYPT_LUKS1;
|
||||
}
|
||||
|
||||
if (!options->device)
|
||||
options->device = device;
|
||||
|
||||
r = _crypt_init(&cd, type, options, 1, 1);
|
||||
if (r)
|
||||
goto out;
|
||||
@@ -676,6 +686,8 @@ int crypt_resize_device(struct crypt_options *options)
|
||||
out:
|
||||
safe_free(key);
|
||||
free(cipher);
|
||||
if (options->device == device)
|
||||
options->device = NULL;
|
||||
free(device);
|
||||
free(uuid);
|
||||
crypt_free(cd);
|
||||
@@ -688,6 +700,8 @@ int crypt_query_device(struct crypt_options *options)
|
||||
{
|
||||
int read_only, r;
|
||||
|
||||
log_dbg("Query device %s.", options->name);
|
||||
|
||||
if (dm_init(NULL, 1) < 0)
|
||||
return -ENOSYS;
|
||||
|
||||
@@ -900,9 +914,16 @@ int crypt_isLuks(struct crypt_options *options)
|
||||
struct crypt_device *cd = NULL;
|
||||
int r;
|
||||
|
||||
r = _crypt_init(&cd, CRYPT_LUKS1, options, 1, 0);
|
||||
if (!r)
|
||||
crypt_free(cd);
|
||||
log_dbg("Check device %s for LUKS header.", options->device);
|
||||
|
||||
r = crypt_init(&cd, options->device);
|
||||
if (r < 0)
|
||||
return -EINVAL;
|
||||
|
||||
/* Do print fail here, no need to crypt_load() */
|
||||
r = LUKS_read_phdr(cd->device, &cd->hdr, 0, cd) ? -EINVAL : 0;
|
||||
|
||||
crypt_free(cd);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -1756,13 +1777,13 @@ int crypt_deactivate(struct crypt_device *cd, const char *name)
|
||||
switch (crypt_status(cd, name)) {
|
||||
case ACTIVE: r = dm_remove_device(name, 0, 0);
|
||||
break;
|
||||
case BUSY: log_err(cd, _("Device %s is busy."), name);
|
||||
case BUSY: log_err(cd, _("Device %s is busy.\n"), name);
|
||||
r = -EBUSY;
|
||||
break;
|
||||
case INACTIVE: log_err(cd, _("Device %s is not active."), name);
|
||||
case INACTIVE: log_err(cd, _("Device %s is not active.\n"), name);
|
||||
r = -ENODEV;
|
||||
break;
|
||||
default: log_err(cd, _("Invalid device %s."), name);
|
||||
default: log_err(cd, _("Invalid device %s.\n"), name);
|
||||
r = -EINVAL;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,30 +65,29 @@ static struct action_type {
|
||||
int arg;
|
||||
int required_action_argc;
|
||||
int required_memlock;
|
||||
int show_status;
|
||||
const char *arg_desc;
|
||||
const char *desc;
|
||||
} action_types[] = {
|
||||
{ "create", action_create, 0, 2, 1, 1, N_("<name> <device>"),N_("create device") },
|
||||
{ "remove", action_remove, 0, 1, 1, 1, N_("<name>"), N_("remove device") },
|
||||
{ "resize", action_resize, 0, 1, 1, 1, N_("<name>"), N_("resize active device") },
|
||||
{ "status", action_status, 0, 1, 0, 1, N_("<name>"), N_("show device status") },
|
||||
{ "luksFormat", action_luksFormat, 0, 1, 1, 1, N_("<device> [<new key file>]"), N_("formats a LUKS device") },
|
||||
{ "luksOpen", action_luksOpen, 0, 2, 1, 1, N_("<device> <name> "), N_("open LUKS device as mapping <name>") },
|
||||
{ "luksAddKey", action_luksAddKey, 0, 1, 1, 1, N_("<device> [<new key file>]"), N_("add key to LUKS device") },
|
||||
{ "luksRemoveKey",action_luksRemoveKey, 0, 1, 1, 1, N_("<device> [<key file>]"), N_("removes supplied key or key file from LUKS device") },
|
||||
{ "luksKillSlot", action_luksKillSlot, 0, 2, 1, 1, N_("<device> <key slot>"), N_("wipes key with number <key slot> from LUKS device") },
|
||||
{ "luksUUID", action_luksUUID, 0, 1, 0, 1, N_("<device>"), N_("print UUID of LUKS device") },
|
||||
{ "isLuks", action_isLuks, 0, 1, 0, 0, N_("<device>"), N_("tests <device> for LUKS partition header") },
|
||||
{ "luksClose", action_remove, 0, 1, 1, 1, N_("<name>"), N_("remove LUKS mapping") },
|
||||
{ "luksDump", action_luksDump, 0, 1, 0, 1, N_("<device>"), N_("dump LUKS partition information") },
|
||||
{ "luksSuspend",action_luksSuspend, 0, 1, 1, 1, N_("<device>"), N_("Suspend LUKS device and wipe key (all IOs are frozen).") },
|
||||
{ "luksResume", action_luksResume, 0, 1, 1, 1, N_("<device>"), N_("Resume suspended LUKS device.") },
|
||||
{ "luksHeaderBackup",action_luksBackup, 0, 1, 1, 1, N_("<device>"), N_("Backup LUKS device header and keyslots") },
|
||||
{ "luksHeaderRestore",action_luksRestore,0,1, 1, 1, N_("<device>"), N_("Restore LUKS device header and keyslots") },
|
||||
{ "luksDelKey", action_luksDelKey, 0, 2, 1, 1, N_("<device> <key slot>"), N_("identical to luksKillSlot - DEPRECATED - see man page") },
|
||||
{ "reload", action_create, 1, 2, 1, 1, N_("<name> <device>"), N_("modify active device - DEPRECATED - see man page") },
|
||||
{ NULL, NULL, 0, 0, 0, 0, NULL, NULL }
|
||||
{ "create", action_create, 0, 2, 1, N_("<name> <device>"),N_("create device") },
|
||||
{ "remove", action_remove, 0, 1, 1, N_("<name>"), N_("remove device") },
|
||||
{ "resize", action_resize, 0, 1, 1, N_("<name>"), N_("resize active device") },
|
||||
{ "status", action_status, 0, 1, 0, N_("<name>"), N_("show device status") },
|
||||
{ "luksFormat", action_luksFormat, 0, 1, 1, N_("<device> [<new key file>]"), N_("formats a LUKS device") },
|
||||
{ "luksOpen", action_luksOpen, 0, 2, 1, N_("<device> <name> "), N_("open LUKS device as mapping <name>") },
|
||||
{ "luksAddKey", action_luksAddKey, 0, 1, 1, N_("<device> [<new key file>]"), N_("add key to LUKS device") },
|
||||
{ "luksRemoveKey",action_luksRemoveKey, 0, 1, 1, N_("<device> [<key file>]"), N_("removes supplied key or key file from LUKS device") },
|
||||
{ "luksKillSlot", action_luksKillSlot, 0, 2, 1, N_("<device> <key slot>"), N_("wipes key with number <key slot> from LUKS device") },
|
||||
{ "luksUUID", action_luksUUID, 0, 1, 0, N_("<device>"), N_("print UUID of LUKS device") },
|
||||
{ "isLuks", action_isLuks, 0, 1, 0, N_("<device>"), N_("tests <device> for LUKS partition header") },
|
||||
{ "luksClose", action_remove, 0, 1, 1, N_("<name>"), N_("remove LUKS mapping") },
|
||||
{ "luksDump", action_luksDump, 0, 1, 0, N_("<device>"), N_("dump LUKS partition information") },
|
||||
{ "luksSuspend",action_luksSuspend, 0, 1, 1, N_("<device>"), N_("Suspend LUKS device and wipe key (all IOs are frozen).") },
|
||||
{ "luksResume", action_luksResume, 0, 1, 1, N_("<device>"), N_("Resume suspended LUKS device.") },
|
||||
{ "luksHeaderBackup",action_luksBackup, 0, 1, 1, N_("<device>"), N_("Backup LUKS device header and keyslots") },
|
||||
{ "luksHeaderRestore",action_luksRestore,0,1, 1, N_("<device>"), N_("Restore LUKS device header and keyslots") },
|
||||
{ "luksDelKey", action_luksDelKey, 0, 2, 1, N_("<device> <key slot>"), N_("identical to luksKillSlot - DEPRECATED - see man page") },
|
||||
{ "reload", action_create, 1, 2, 1, N_("<name> <device>"), N_("modify active device - DEPRECATED - see man page") },
|
||||
{ NULL, NULL, 0, 0, 0, NULL, NULL }
|
||||
};
|
||||
|
||||
static void clogger(struct crypt_device *cd, int class, const char *file,
|
||||
@@ -174,7 +173,10 @@ static void show_status(int errcode)
|
||||
{
|
||||
char error[256], *error_;
|
||||
|
||||
if(!errcode && opt_verbose) {
|
||||
if(!opt_verbose)
|
||||
return;
|
||||
|
||||
if(!errcode) {
|
||||
log_std(_("Command successful.\n"));
|
||||
return;
|
||||
}
|
||||
@@ -182,19 +184,18 @@ static void show_status(int errcode)
|
||||
crypt_get_error(error, sizeof(error));
|
||||
|
||||
if (!error[0]) {
|
||||
error_ = strerror_r(errcode, error, sizeof(error));
|
||||
error_ = strerror_r(-errcode, error, sizeof(error));
|
||||
if (error_ != error) {
|
||||
strncpy(error, error_, sizeof(error));
|
||||
error[sizeof(error) - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
log_err(_("Command failed"));
|
||||
log_err(_("Command failed with code %i"), -errcode);
|
||||
if (*error)
|
||||
log_err(": %s\n", error);
|
||||
else
|
||||
log_err(".\n");
|
||||
return;
|
||||
}
|
||||
|
||||
static int action_create(int reload)
|
||||
@@ -677,8 +678,7 @@ static int run_action(struct action_type *action)
|
||||
if (action->required_memlock)
|
||||
crypt_memory_lock(NULL, 0);
|
||||
|
||||
if (r < 0 && (opt_verbose || action->show_status))
|
||||
show_status(-r);
|
||||
show_status(r);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user