From 774d1de56eff7f295122d59755b3b41e7d7c9f0c Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Tue, 8 Nov 2011 21:29:44 +0000 Subject: [PATCH] Fix cryptsetup status output if parameter is device path. git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@682 36d66b0a-2a48-0410-832c-cd162a569da5 --- ChangeLog | 1 + src/cryptsetup.c | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3796d732..541437a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2011-11-05 Milan Broz * Merge pycryptsetup (Python libcryptsetup bindings). * Fix stupid typo in set_iteration_time API call. + * Fix cryptsetup status output if parameter is device path. 2011-10-27 Milan Broz * Fix crypt_get_volume_key_size() for plain device. diff --git a/src/cryptsetup.c b/src/cryptsetup.c index b4758411..1bf43eb8 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -378,9 +379,14 @@ static int action_status(int arg __attribute__((unused))) crypt_status_info ci; struct crypt_active_device cad; struct crypt_device *cd = NULL; + struct stat st; char *backing_file; const char *device; - int r = 0; + int path = 0, r = 0; + + /* perhaps a path, not a dm device name */ + if (strchr(action_argv[0], '/') && !stat(action_argv[0], &st)) + path = 1; ci = crypt_status(NULL, action_argv[0]); switch (ci) { @@ -388,13 +394,20 @@ static int action_status(int arg __attribute__((unused))) r = -EINVAL; break; case CRYPT_INACTIVE: - log_std("%s/%s is inactive.\n", crypt_get_dir(), action_argv[0]); + if (path) + log_std("%s is inactive.\n", action_argv[0]); + else + log_std("%s/%s is inactive.\n", crypt_get_dir(), action_argv[0]); r = -ENODEV; break; case CRYPT_ACTIVE: case CRYPT_BUSY: - log_std("%s/%s is active%s.\n", crypt_get_dir(), action_argv[0], - ci == CRYPT_BUSY ? " and is in use" : ""); + if (path) + log_std("%s is active%s.\n", action_argv[0], + ci == CRYPT_BUSY ? " and is in use" : ""); + else + log_std("%s/%s is active%s.\n", crypt_get_dir(), action_argv[0], + ci == CRYPT_BUSY ? " and is in use" : ""); r = crypt_init_by_name(&cd, action_argv[0]); if (r < 0 || !crypt_get_type(cd)) goto out;