dev_handlers: Report invalid block sizes

If while attaching a pass-through device the READ CAPACITY command
reports an invalid sector size, log an error message.


git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6355 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Bart Van Assche
2015-06-16 23:59:38 +00:00
parent 612fac9874
commit e31d1999f3
4 changed files with 26 additions and 1 deletions

View File

@@ -129,6 +129,12 @@ static int cdrom_attach(struct scst_device *dev)
dev->block_shift = scst_calc_block_shift(sector_size);
TRACE_DBG("Sector size is %i scsi_level %d(SCSI_2 %d)",
sector_size, dev->scsi_dev->scsi_level, SCSI_2);
if (dev->block_shift < 9) {
PRINT_ERROR("READ CAPACITY reported an invalid sector size: %d",
sector_size);
res = -EINVAL;
goto out_free_buf;
}
} else {
dev->block_shift = CDROM_DEF_BLOCK_SHIFT;
TRACE(TRACE_MINOR, "Read capacity failed: %x, using default "

View File

@@ -221,6 +221,12 @@ static int disk_attach(struct scst_device *dev)
dev->block_shift = DISK_DEF_BLOCK_SHIFT;
else
dev->block_shift = scst_calc_block_shift(sector_size);
if (dev->block_shift < 9) {
PRINT_ERROR("READ CAPACITY reported an invalid sector size: %d",
sector_size);
res = -EINVAL;
goto out_free_buf;
}
} else {
dev->block_shift = DISK_DEF_BLOCK_SHIFT;
TRACE(TRACE_MINOR, "Read capacity failed: %x, using default "

View File

@@ -228,6 +228,12 @@ static int modisk_attach(struct scst_device *dev)
dev->block_shift = scst_calc_block_shift(sector_size);
TRACE_DBG("Sector size is %i scsi_level %d(SCSI_2 %d)",
sector_size, dev->scsi_dev->scsi_level, SCSI_2);
if (dev->block_shift < 9) {
PRINT_ERROR("READ CAPACITY reported an invalid sector size: %d",
sector_size);
res = -EINVAL;
goto out_free_buf;
}
} else {
dev->block_shift = MODISK_DEF_BLOCK_SHIFT;
TRACE(TRACE_MINOR, "Read capacity failed: %x, using default "

View File

@@ -1030,7 +1030,9 @@ static void dev_user_set_block_shift(struct scst_cmd *cmd, int block_shift)
*/
new_block_shift = block_shift ? :
scst_calc_block_shift(udev->def_block_size);
if (dev->block_shift != new_block_shift) {
if (new_block_shift < 9) {
PRINT_ERROR("Invalid block shift %d", new_block_shift);
} else if (dev->block_shift != new_block_shift) {
PRINT_INFO("%s: Changed block shift from %d into %d / %d",
dev->virt_name, dev->block_shift, block_shift,
new_block_shift);
@@ -2582,6 +2584,11 @@ static int dev_user_attach(struct scst_device *sdev)
case TYPE_ROM:
case TYPE_MOD:
sdev->block_shift = scst_calc_block_shift(sdev->block_size);
if (sdev->block_shift < 9) {
PRINT_ERROR("Invalid block size %d", sdev->block_size);
res = -EINVAL;
goto out;
}
break;
default:
sdev->block_shift = -1; /* not used */