return 0;
}
+static sector_t get_sdebug_capacity(void)
+{
+ if (scsi_debug_virtual_gb > 0)
+ return 2048 * 1024 * scsi_debug_virtual_gb;
+ else
+ return sdebug_store_sectors;
+}
+
#define SDEBUG_READCAP_ARR_SZ 8
static int resp_readcap(struct scsi_cmnd * scp,
struct sdebug_dev_info * devip)
if ((errsts = check_readiness(scp, 1, devip)))
return errsts;
/* following just in case virtual_gb changed */
- if (scsi_debug_virtual_gb > 0) {
- sdebug_capacity = 2048 * 1024;
- sdebug_capacity *= scsi_debug_virtual_gb;
- } else
- sdebug_capacity = sdebug_store_sectors;
+ sdebug_capacity = get_sdebug_capacity();
memset(arr, 0, SDEBUG_READCAP_ARR_SZ);
if (sdebug_capacity < 0xffffffff) {
capac = (unsigned int)sdebug_capacity - 1;
alloc_len = ((cmd[10] << 24) + (cmd[11] << 16) + (cmd[12] << 8)
+ cmd[13]);
/* following just in case virtual_gb changed */
- if (scsi_debug_virtual_gb > 0) {
- sdebug_capacity = 2048 * 1024;
- sdebug_capacity *= scsi_debug_virtual_gb;
- } else
- sdebug_capacity = sdebug_store_sectors;
+ sdebug_capacity = get_sdebug_capacity();
memset(arr, 0, SDEBUG_READCAP16_ARR_SZ);
capac = sdebug_capacity - 1;
for (k = 0; k < 8; ++k, capac >>= 8)
offset = 8;
}
ap = arr + offset;
- if ((bd_len > 0) && (0 == sdebug_capacity)) {
- if (scsi_debug_virtual_gb > 0) {
- sdebug_capacity = 2048 * 1024;
- sdebug_capacity *= scsi_debug_virtual_gb;
- } else
- sdebug_capacity = sdebug_store_sectors;
- }
+ if ((bd_len > 0) && (!sdebug_capacity))
+ sdebug_capacity = get_sdebug_capacity();
+
if (8 == bd_len) {
if (sdebug_capacity > 0xfffffffe) {
ap[0] = 0xff;
if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
scsi_debug_virtual_gb = n;
- if (scsi_debug_virtual_gb > 0) {
- sdebug_capacity = 2048 * 1024;
- sdebug_capacity *= scsi_debug_virtual_gb;
- } else
- sdebug_capacity = sdebug_store_sectors;
+
+ sdebug_capacity = get_sdebug_capacity();
+
return count;
}
return -EINVAL;
scsi_debug_dev_size_mb = 1; /* force minimum 1 MB ramdisk */
sz = (unsigned int)scsi_debug_dev_size_mb * 1048576;
sdebug_store_sectors = sz / SECT_SIZE;
- if (scsi_debug_virtual_gb > 0) {
- sdebug_capacity = 2048 * 1024;
- sdebug_capacity *= scsi_debug_virtual_gb;
- } else
- sdebug_capacity = sdebug_store_sectors;
+ sdebug_capacity = get_sdebug_capacity();
/* play around with geometry, don't waste too much on track 0 */
sdebug_heads = 8;