[PATCH 7/7] change how we handle dvdrecorder close track

Ronnie Sahlberg ronniesahlberg
Fri May 2 14:41:50 CEST 2008


dvdrecorder uses the reserve_track command before starting to write data.
pull the size of the full track from the cdb and store it in the mmc
structure.
once we see a write command where offset+length is equal to this track size
we consider the burning complete and morph the device into DVD-ROM

Signed-off-by: Ronnie Sahlberg <ronniesahlberg at gmail.com>
---
 usr/mmc.c |   33 +++++++++++++++++++++++++--------
 1 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/usr/mmc.c b/usr/mmc.c
index d075b23..9e52845 100644
--- a/usr/mmc.c
+++ b/usr/mmc.c
@@ -54,6 +54,7 @@

 struct mmc_info {
 	int current_profile;
+	uint64_t reserve_track_len;
 };

 static int mmc_rw(int host_no, struct scsi_cmd *cmd)
@@ -61,6 +62,7 @@ static int mmc_rw(int host_no, struct scsi_cmd *cmd)
 	struct mmc_info *mmc = (struct mmc_info *)cmd->dev->mmc_p;
 	int ret;
 	uint64_t end_offset;
+	uint64_t offset, length;

 	if (mmc->current_profile == PROFILE_NO_PROFILE) {
 		scsi_set_in_resid_by_actual(cmd, 0);
@@ -97,11 +99,13 @@ static int mmc_rw(int host_no, struct scsi_cmd *cmd)

 	cmd->scsi_cmd_done = target_cmd_io_done;

-	cmd->offset = (scsi_rw_offset(cmd->scb) << MMC_BLK_SHIFT);
+	offset = scsi_rw_offset(cmd->scb);
+	cmd->offset = (offset << MMC_BLK_SHIFT);

 	/* update the size of the device */
-	end_offset = cmd->offset +
-		(((uint64_t)scsi_rw_count(cmd->scb)) << MMC_BLK_SHIFT);
+	length = scsi_rw_count(cmd->scb);
+	end_offset = cmd->offset + (length << MMC_BLK_SHIFT);
+
 	if (end_offset > cmd->dev->size)
 		cmd->dev->size = end_offset;

@@ -116,10 +120,17 @@ static int mmc_rw(int host_no, struct scsi_cmd *cmd)
 		sense_data_build(cmd, ILLEGAL_REQUEST, ASC_LUN_NOT_SUPPORTED);
 		return SAM_STAT_CHECK_CONDITION;
 	} else {
+		if ((mmc->current_profile == PROFILE_DVD_PLUS_R) &&
+			(mmc->reserve_track_len == (offset + length))) {
+			/* once we close the track it becomes a DVD_ROM */
+			mmc->current_profile = PROFILE_DVD_ROM;
+		}
+
 		set_cmd_mmapio(cmd);
 		return SAM_STAT_GOOD;
 	}

+
 	return 0;
 }

@@ -1455,11 +1466,6 @@ static int mmc_synchronize_cache(int host_no,
struct scsi_cmd *cmd)
 		return SAM_STAT_CHECK_CONDITION;
 	}

-	if (mmc->current_profile == PROFILE_DVD_PLUS_R) {
-		/* once we close the track it becomes a DVD_ROM */
-		mmc->current_profile = PROFILE_DVD_ROM;
-	}
-
 	return SAM_STAT_GOOD;
 }

@@ -2154,6 +2160,16 @@ static int mmc_read_dvd_structure(int host_no,
struct scsi_cmd *cmd)

 static int mmc_reserve_track(int host_no, struct scsi_cmd *cmd)
 {
+	struct mmc_info *mmc = (struct mmc_info *)cmd->dev->mmc_p;
+	uint64_t tmp;
+
+	tmp = cmd->scb[5];
+	tmp = (tmp << 8) | cmd->scb[6];
+	tmp = (tmp << 8) | cmd->scb[7];
+	tmp = (tmp << 8) | cmd->scb[8];
+
+	mmc->reserve_track_len = tmp;
+
 	return SAM_STAT_GOOD;
 }

@@ -2247,6 +2263,7 @@ static int mmc_lu_online(struct scsi_lu *lu)
 	struct stat st;

 	mmc->current_profile = PROFILE_NO_PROFILE;
+	mmc->reserve_track_len = 0;

 	if (lu->fd == -1)
 		return TGTADM_INVALID_REQUEST;
-- 
1.5.5



More information about the stgt mailing list