Move check for loop device inside crypt_loop_backing_file.

It also fixes minor regression where we return backing file
for partition on top of loop device when prompting for passphrase.
Partition on loop has different major number so it should not be
considered loop device at all.
This commit is contained in:
Ondrej Kozina
2019-10-03 15:58:47 +02:00
parent c4c4f9d159
commit 62b580904b
4 changed files with 12 additions and 13 deletions

View File

@@ -252,7 +252,12 @@ static char *_sysfs_backing_file(const char *loop)
char *crypt_loop_backing_file(const char *loop) char *crypt_loop_backing_file(const char *loop)
{ {
char *bf = _sysfs_backing_file(loop); char *bf;
if (!crypt_loop_device(loop))
return NULL;
bf = _sysfs_backing_file(loop);
return bf ?: _ioctl_backing_file(loop); return bf ?: _ioctl_backing_file(loop);
} }

View File

@@ -736,8 +736,7 @@ static int action_status(void)
log_std(" integrity keysize: %d bits\n", ip.integrity_key_size * 8); log_std(" integrity keysize: %d bits\n", ip.integrity_key_size * 8);
device = crypt_get_device_name(cd); device = crypt_get_device_name(cd);
log_std(" device: %s\n", device); log_std(" device: %s\n", device);
if (crypt_loop_device(device)) { if ((backing_file = crypt_loop_backing_file(device))) {
backing_file = crypt_loop_backing_file(device);
log_std(" loop: %s\n", backing_file); log_std(" loop: %s\n", backing_file);
free(backing_file); free(backing_file);
} }

View File

@@ -402,15 +402,13 @@ static int action_status(int arg)
device = crypt_get_device_name(cd); device = crypt_get_device_name(cd);
metadata_device = crypt_get_metadata_device_name(cd); metadata_device = crypt_get_metadata_device_name(cd);
log_std(" device: %s%s\n", device, metadata_device ? " (detached)" : ""); log_std(" device: %s%s\n", device, metadata_device ? " (detached)" : "");
if (crypt_loop_device(device)) { if ((backing_file = crypt_loop_backing_file(device))) {
backing_file = crypt_loop_backing_file(device);
log_std(" loop: %s\n", backing_file); log_std(" loop: %s\n", backing_file);
free(backing_file); free(backing_file);
} }
if (metadata_device) { if (metadata_device) {
log_std(" metadata device: %s\n", metadata_device); log_std(" metadata device: %s\n", metadata_device);
if (crypt_loop_device(metadata_device)) { if ((backing_file = crypt_loop_backing_file(metadata_device))) {
backing_file = crypt_loop_backing_file(metadata_device);
log_std(" loop: %s\n", backing_file); log_std(" loop: %s\n", backing_file);
free(backing_file); free(backing_file);
} }

View File

@@ -287,8 +287,7 @@ static int action_status(int arg)
log_std("\n"); log_std("\n");
log_std(" data device: %s\n", vp.data_device); log_std(" data device: %s\n", vp.data_device);
if (crypt_loop_device(vp.data_device)) { if ((backing_file = crypt_loop_backing_file(vp.data_device))) {
backing_file = crypt_loop_backing_file(vp.data_device);
log_std(" data loop: %s\n", backing_file); log_std(" data loop: %s\n", backing_file);
free(backing_file); free(backing_file);
} }
@@ -297,8 +296,7 @@ static int action_status(int arg)
"readonly" : "read/write"); "readonly" : "read/write");
log_std(" hash device: %s\n", vp.hash_device); log_std(" hash device: %s\n", vp.hash_device);
if (crypt_loop_device(vp.hash_device)) { if ((backing_file = crypt_loop_backing_file(vp.hash_device))) {
backing_file = crypt_loop_backing_file(vp.hash_device);
log_std(" hash loop: %s\n", backing_file); log_std(" hash loop: %s\n", backing_file);
free(backing_file); free(backing_file);
} }
@@ -307,8 +305,7 @@ static int action_status(int arg)
if (vp.fec_device) { if (vp.fec_device) {
log_std(" FEC device: %s\n", vp.fec_device); log_std(" FEC device: %s\n", vp.fec_device);
if (crypt_loop_device(vp.fec_device)) { if ((backing_file = crypt_loop_backing_file(vp.fec_device))) {
backing_file = crypt_loop_backing_file(vp.fec_device);
log_std(" FEC loop: %s\n", backing_file); log_std(" FEC loop: %s\n", backing_file);
free(backing_file); free(backing_file);
} }