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:
parent
5f5c150c30
commit
1fb5fd9662
@ -159,10 +159,24 @@ cas_printf_t cas_printf = std_printf;
|
|||||||
int validate_dev(const char *dev_path)
|
int validate_dev(const char *dev_path)
|
||||||
{
|
{
|
||||||
struct fstab *fstab_entry;
|
struct fstab *fstab_entry;
|
||||||
|
struct stat status;
|
||||||
|
|
||||||
fstab_entry = getfsspec(dev_path);
|
fstab_entry = getfsspec(dev_path);
|
||||||
if (fstab_entry != NULL) {
|
if (fstab_entry != NULL) {
|
||||||
|
printf("Device entry present in fstab, please remove it.\n");
|
||||||
return FAILURE;
|
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;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,16 +92,13 @@ static struct command_args command_args_values = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int validate_device_name(const char *dev_name) {
|
int validate_device_name(const char *dev_name) {
|
||||||
if (validate_dev(dev_name)) {
|
if (strnlen(dev_name, MAX_STR_LEN) >= MAX_STR_LEN) {
|
||||||
cas_printf(LOG_ERR, "Cache creation aborted, %s entry exists in /etc/fstab. Please remove it!\n",
|
cas_printf(LOG_ERR, "Illegal device name\n");
|
||||||
dev_name);
|
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strnlen(dev_name, MAX_STR_LEN) >= MAX_STR_LEN) {
|
if (validate_dev(dev_name))
|
||||||
cas_printf(LOG_ERR, "Illegal device %s\n", dev_name);
|
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user