[PATCH] SBC add support for removable SBC devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tomo, List

Please find attached a patch to SBC to support "removable media for sb devices"
Patch contains a pointer to SBC where removable media is discussed.

The patch does not modify any existing behaviour, but IF a SBC device
is flagged as removable and IF it is also made offline
then all media accessing opcodes now return check condition/medium not present



regards
ronnie sahlberg

Attachment: 0001-SBC-Support-removable-devices-for-SBC.patch.gz
Description: GNU Zip compressed data

From 9875346857c9d1c383c5da91b0f9cb097fe068cf Mon Sep 17 00:00:00 2001
From: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx>
Date: Thu, 26 Jan 2012 11:05:09 +1100
Subject: [PATCH] SBC: Support removable devices for SBC

SBC supports removable devices.
See   SBC   4.3.1 REMOVABLE MEDIUM OVERVIEW

TEST UNIT READY, START STOP UNIT and PREVENT ALLOW MEDIUM REMOVAL
already provide the required behaviour described in 4.3.1

This patch adds support for the SBC medium access opcodes to return
check condition/not ready/medium not present
for any calls when the devie is set in offline mode.

regards
ronnie sahlberg

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx>
---
 usr/sbc.c |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/usr/sbc.c b/usr/sbc.c
index 8330291..b96cc7a 100644
--- a/usr/sbc.c
+++ b/usr/sbc.c
@@ -154,6 +154,12 @@ static int sbc_rw(int host_no, struct scsi_cmd *cmd)
 	if (ret)
 		return SAM_STAT_RESERVATION_CONFLICT;
 
+	if (cmd->dev->attrs.removable && !cmd->dev->attrs.online) {
+		key = NOT_READY;
+		asc = ASC_MEDIUM_NOT_PRESENT;
+		goto sense;
+	}
+
 	switch (cmd->scb[0]) {
 	case READ_10:
 	case READ_12:
@@ -238,6 +244,12 @@ static int sbc_read_capacity(int host_no, struct scsi_cmd *cmd)
 	unsigned char key = ILLEGAL_REQUEST;
 	uint16_t asc = ASC_LUN_NOT_SUPPORTED;
 
+	if (cmd->dev->attrs.removable && !cmd->dev->attrs.online) {
+		key = NOT_READY;
+		asc = ASC_MEDIUM_NOT_PRESENT;
+		goto sense;
+	}
+
 	if (!(scb[8] & 0x1) && (scb[2] | scb[3] | scb[4] | scb[5])) {
 		asc = ASC_INVALID_FIELD_IN_CDB;
 		goto sense;
@@ -272,6 +284,12 @@ static int sbc_verify(int host_no, struct scsi_cmd *cmd)
 	uint64_t lba;
 	uint32_t tl;
 
+	if (cmd->dev->attrs.removable && !cmd->dev->attrs.online) {
+		key = NOT_READY;
+		asc = ASC_MEDIUM_NOT_PRESENT;
+		goto sense;
+	}
+
 	vprotect = cmd->scb[1] & 0xe0;
 	if (vprotect) {
 		/* we dont support formatting with protection information,
@@ -323,6 +341,14 @@ static int sbc_service_action(int host_no, struct scsi_cmd *cmd)
 	uint64_t size;
 	int len = 32;
 	int val;
+	unsigned char key = ILLEGAL_REQUEST;
+	uint16_t asc = ASC_INVALID_OP_CODE;
+
+	if (cmd->dev->attrs.removable && !cmd->dev->attrs.online) {
+		key = NOT_READY;
+		asc = ASC_MEDIUM_NOT_PRESENT;
+		goto sense;
+	}
 
 	if (cmd->scb[1] != SAI_READ_CAPACITY_16)
 		goto sense;
@@ -347,8 +373,9 @@ static int sbc_service_action(int host_no, struct scsi_cmd *cmd)
 overflow:
 	scsi_set_in_resid_by_actual(cmd, len);
 	return SAM_STAT_GOOD;
+
 sense:
-	sense_data_build(cmd, ILLEGAL_REQUEST, ASC_INVALID_OP_CODE);
+	sense_data_build(cmd, key, asc);
 	return SAM_STAT_CHECK_CONDITION;
 }
 
@@ -361,6 +388,12 @@ static int sbc_sync_cache(int host_no, struct scsi_cmd *cmd)
 	if (device_reserved(cmd))
 		return SAM_STAT_RESERVATION_CONFLICT;
 
+	if (cmd->dev->attrs.removable && !cmd->dev->attrs.online) {
+		key = NOT_READY;
+		asc = ASC_MEDIUM_NOT_PRESENT;
+		goto sense;
+	}
+
 	ret = cmd->dev->bst->bs_cmd_submit(cmd);
 	switch (ret) {
 	case EROFS:
-- 
1.7.3.1


[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux