On Wed, 14 Oct 2009 06:44:02 +1100 Mark Harvey <markh794@xxxxxxxxx> wrote: > >From 8838e603da133001d3284f0ee1f0a6c71f906d09 Mon Sep 17 00:00:00 2001 > From: Mark Harvey <markh794@xxxxxxxxx> > Date: Tue, 13 Oct 2009 18:36:15 +1100 > Subject: Honour media capacity. > > Return NO_SENSE with 'EOM' set once 'media capacity' number of bytes > written to backing store file. > > Signed-off-by: Mark Harvey <markh794@xxxxxxxxx> > --- > usr/bs_ssc.c | 23 +++++++++++++++++++++-- > 1 files changed, 21 insertions(+), 2 deletions(-) > > diff --git a/usr/bs_ssc.c b/usr/bs_ssc.c > index ce5c3bf..b2ad7c7 100644 > --- a/usr/bs_ssc.c > +++ b/usr/bs_ssc.c > @@ -40,6 +40,12 @@ > #include "ssc.h" > #include "libssc.h" > > +#define SENSE_FILEMARK 0x80 > +#define SENSE_EOM 0x40 > +#define SENSE_ILI 0X20 > + > +static uint64_t media_capacity; Hmm, the global media_capacity value doesn't look correct? If you have multiple virtual tape devices, what happens? Why can't we do something like this? diff --git a/usr/bs_ssc.c b/usr/bs_ssc.c index c0d5b59..8e57c1c 100644 --- a/usr/bs_ssc.c +++ b/usr/bs_ssc.c @@ -40,6 +40,10 @@ #include "ssc.h" #include "libssc.h" +#define SENSE_FILEMARK 0x80 +#define SENSE_EOM 0x40 +#define SENSE_ILI 0X20 + static void ssc_sense_data_build(struct scsi_cmd *cmd, uint8_t key, uint16_t asc, uint8_t *info, int info_len) { @@ -109,6 +113,12 @@ static int resp_rewind(struct scsi_lu *lu) return skip_next_header(lu); } +static unsigned long current_size(struct scsi_cmd *cmd) +{ + struct ssc_info *ssc = dtype_priv(cmd->dev); + return ssc->c_blk.curr; +} + static int append_blk(struct scsi_cmd *cmd, uint8_t *data, int size, int orig_sz, int type) { @@ -184,8 +194,6 @@ static int append_blk(struct scsi_cmd *cmd, uint8_t *data, return SAM_STAT_GOOD; } -#define SENSE_FILEMARK 0x80 - static int space_filemark_reverse(struct scsi_cmd *cmd, int32_t count) { struct ssc_info *ssc = dtype_priv(cmd->dev); @@ -515,6 +523,14 @@ static void tape_rdwr_request(struct scsi_cmd *cmd) count, length, ret, (fixed) ? "Yes" : "No", block_length); + /* Check for end of media */ + if (current_size(cmd) > ssc->mam.max_capacity) { + sense_data_build(cmd, NO_SENSE|SENSE_EOM, + NO_ADDITIONAL_SENSE); + result = SAM_STAT_CHECK_CONDITION; + break; + } + if (ret != length) { sense_data_build(cmd, MEDIUM_ERROR, ASC_WRITE_ERROR); result = SAM_STAT_CHECK_CONDITION; -- To unsubscribe from this list: send the line "unsubscribe stgt" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html