Verify whether input device path is actually a block device

This applies to add/momove core, start/stop cache, zero superblock
commands.

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski 2021-01-20 16:53:30 +01:00
parent 5f5c150c30
commit 1fb5fd9662
2 changed files with 17 additions and 6 deletions

View File

@ -159,10 +159,24 @@ cas_printf_t cas_printf = std_printf;
int validate_dev(const char *dev_path)
{
struct fstab *fstab_entry;
struct stat status;
fstab_entry = getfsspec(dev_path);
if (fstab_entry != NULL) {
printf("Device entry present in fstab, please remove it.\n");
return FAILURE;
}
if (stat(dev_path, &status) == -1) {
printf("Failed to query device status.\n");
return FAILURE;
}
if (!S_ISBLK(status.st_mode)) {
printf("Path does not describe a block device\n");
return FAILURE;
}
return SUCCESS;
}

View File

@ -92,16 +92,13 @@ static struct command_args command_args_values = {
};
int validate_device_name(const char *dev_name) {
if (validate_dev(dev_name)) {
cas_printf(LOG_ERR, "Cache creation aborted, %s entry exists in /etc/fstab. Please remove it!\n",
dev_name);
if (strnlen(dev_name, MAX_STR_LEN) >= MAX_STR_LEN) {
cas_printf(LOG_ERR, "Illegal device name\n");
return FAILURE;
}
if (strnlen(dev_name, MAX_STR_LEN) >= MAX_STR_LEN) {
cas_printf(LOG_ERR, "Illegal device %s\n", dev_name);
if (validate_dev(dev_name))
return FAILURE;
}
return SUCCESS;
}