fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / scsi / osst.c
index d9946bd..7d23110 100644 (file)
@@ -13,7 +13,7 @@
   order) Klaus Ehrenfried, Wolfgang Denk, Steve Hirsch, Andreas Koppenh"ofer,
   Michael Leodolter, Eyal Lebedinsky, J"org Weule, and Eric Youngdale.
 
   order) Klaus Ehrenfried, Wolfgang Denk, Steve Hirsch, Andreas Koppenh"ofer,
   Michael Leodolter, Eyal Lebedinsky, J"org Weule, and Eric Youngdale.
 
-  Copyright 1992 - 2002 Kai Makisara / 2000 - 2004 Willem Riede
+  Copyright 1992 - 2002 Kai Makisara / 2000 - 2006 Willem Riede
         email osst@riede.org
 
   $Header: /cvsroot/osst/Driver/osst.c,v 1.73 2005/01/01 21:13:34 wriede Exp $
         email osst@riede.org
 
   $Header: /cvsroot/osst/Driver/osst.c,v 1.73 2005/01/01 21:13:34 wriede Exp $
@@ -24,7 +24,7 @@
 */
 
 static const char * cvsid = "$Id: osst.c,v 1.73 2005/01/01 21:13:34 wriede Exp $";
 */
 
 static const char * cvsid = "$Id: osst.c,v 1.73 2005/01/01 21:13:34 wriede Exp $";
-static const char * osst_version = "0.99.3";
+static const char * osst_version = "0.99.4";
 
 /* The "failure to reconnect" firmware bug */
 #define OSST_FW_NEED_POLL_MIN 10601 /*(107A)*/
 
 /* The "failure to reconnect" firmware bug */
 #define OSST_FW_NEED_POLL_MIN 10601 /*(107A)*/
@@ -48,8 +48,8 @@ static const char * osst_version = "0.99.3";
 #include <linux/vmalloc.h>
 #include <linux/blkdev.h>
 #include <linux/moduleparam.h>
 #include <linux/vmalloc.h>
 #include <linux/blkdev.h>
 #include <linux/moduleparam.h>
-#include <linux/devfs_fs_kernel.h>
 #include <linux/delay.h>
 #include <linux/delay.h>
+#include <linux/jiffies.h>
 #include <asm/uaccess.h>
 #include <asm/dma.h>
 #include <asm/system.h>
 #include <asm/uaccess.h>
 #include <asm/dma.h>
 #include <asm/system.h>
@@ -70,7 +70,6 @@ static const char * osst_version = "0.99.3";
 #include <scsi/scsi_eh.h>
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_ioctl.h>
 #include <scsi/scsi_eh.h>
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_ioctl.h>
-#include <scsi/scsi_request.h>
 
 #define ST_KILOBYTE 1024
 
 
 #define ST_KILOBYTE 1024
 
@@ -87,6 +86,7 @@ static int max_sg_segs = 0;
 MODULE_AUTHOR("Willem Riede");
 MODULE_DESCRIPTION("OnStream {DI-|FW-|SC-|USB}{30|50} Tape Driver");
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Willem Riede");
 MODULE_DESCRIPTION("OnStream {DI-|FW-|SC-|USB}{30|50} Tape Driver");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS_CHARDEV_MAJOR(OSST_MAJOR);
 
 module_param(max_dev, int, 0444);
 MODULE_PARM_DESC(max_dev, "Maximum number of OnStream Tape Drives to attach (4)");
 
 module_param(max_dev, int, 0444);
 MODULE_PARM_DESC(max_dev, "Maximum number of OnStream Tape Drives to attach (4)");
@@ -107,8 +107,6 @@ static struct osst_dev_parm {
 };
 #endif
 
 };
 #endif
 
-static char *osst_formats[ST_NBR_MODES] ={"", "l", "m", "a"};
-
 /* Some default definitions have been moved to osst_options.h */
 #define OSST_BUFFER_SIZE (OSST_BUFFER_BLOCKS * ST_KILOBYTE)
 #define OSST_WRITE_THRESHOLD (OSST_WRITE_THRESHOLD_BLOCKS * ST_KILOBYTE)
 /* Some default definitions have been moved to osst_options.h */
 #define OSST_BUFFER_SIZE (OSST_BUFFER_BLOCKS * ST_KILOBYTE)
 #define OSST_WRITE_THRESHOLD (OSST_WRITE_THRESHOLD_BLOCKS * ST_KILOBYTE)
@@ -179,16 +177,16 @@ static struct scsi_driver osst_template = {
        }
 };
 
        }
 };
 
-static int osst_int_ioctl(struct osst_tape *STp, struct scsi_request ** aSRpnt,
+static int osst_int_ioctl(struct osst_tape *STp, struct osst_request ** aSRpnt,
                            unsigned int cmd_in, unsigned long arg);
 
                            unsigned int cmd_in, unsigned long arg);
 
-static int osst_set_frame_position(struct osst_tape *STp, struct scsi_request ** aSRpnt, int frame, int skip);
+static int osst_set_frame_position(struct osst_tape *STp, struct osst_request ** aSRpnt, int frame, int skip);
 
 
-static int osst_get_frame_position(struct osst_tape *STp, struct scsi_request ** aSRpnt);
+static int osst_get_frame_position(struct osst_tape *STp, struct osst_request ** aSRpnt);
 
 
-static int osst_flush_write_buffer(struct osst_tape *STp, struct scsi_request ** aSRpnt);
+static int osst_flush_write_buffer(struct osst_tape *STp, struct osst_request ** aSRpnt);
 
 
-static int osst_write_error_recovery(struct osst_tape * STp, struct scsi_request ** aSRpnt, int pending);
+static int osst_write_error_recovery(struct osst_tape * STp, struct osst_request ** aSRpnt, int pending);
 
 static inline char *tape_name(struct osst_tape *tape)
 {
 
 static inline char *tape_name(struct osst_tape *tape)
 {
@@ -197,52 +195,84 @@ static inline char *tape_name(struct osst_tape *tape)
 \f
 /* Routines that handle the interaction with mid-layer SCSI routines */
 
 \f
 /* Routines that handle the interaction with mid-layer SCSI routines */
 
+
+/* Normalize Sense */
+static void osst_analyze_sense(struct osst_request *SRpnt, struct st_cmdstatus *s)
+{
+       const u8 *ucp;
+       const u8 *sense = SRpnt->sense;
+
+       s->have_sense = scsi_normalize_sense(SRpnt->sense,
+                               SCSI_SENSE_BUFFERSIZE, &s->sense_hdr);
+       s->flags = 0;
+
+       if (s->have_sense) {
+               s->deferred = 0;
+               s->remainder_valid =
+                       scsi_get_sense_info_fld(sense, SCSI_SENSE_BUFFERSIZE, &s->uremainder64);
+               switch (sense[0] & 0x7f) {
+               case 0x71:
+                       s->deferred = 1;
+               case 0x70:
+                       s->fixed_format = 1;
+                       s->flags = sense[2] & 0xe0;
+                       break;
+               case 0x73:
+                       s->deferred = 1;
+               case 0x72:
+                       s->fixed_format = 0;
+                       ucp = scsi_sense_desc_find(sense, SCSI_SENSE_BUFFERSIZE, 4);
+                       s->flags = ucp ? (ucp[3] & 0xe0) : 0;
+                       break;
+               }
+       }
+}
+
 /* Convert the result to success code */
 /* Convert the result to success code */
-static int osst_chk_result(struct osst_tape * STp, struct scsi_request * SRpnt)
+static int osst_chk_result(struct osst_tape * STp, struct osst_request * SRpnt)
 {
        char *name = tape_name(STp);
 {
        char *name = tape_name(STp);
-       int result = SRpnt->sr_result;
-       unsigned char * sense = SRpnt->sr_sense_buffer, scode;
+       int result = SRpnt->result;
+       u8 * sense = SRpnt->sense, scode;
 #if DEBUG
        const char *stp;
 #endif
 #if DEBUG
        const char *stp;
 #endif
+       struct st_cmdstatus *cmdstatp;
 
 
-       if (!result) {
-               sense[0] = 0;    /* We don't have sense data if this byte is zero */
+       if (!result)
                return 0;
                return 0;
-       }
-       if ((driver_byte(result) & DRIVER_MASK) == DRIVER_SENSE)
-               scode = sense[2] & 0x0f;
-       else {
-               sense[0] = 0;    /* We don't have sense data if this byte is zero */
+
+       cmdstatp = &STp->buffer->cmdstat;
+       osst_analyze_sense(SRpnt, cmdstatp);
+
+       if (cmdstatp->have_sense)
+               scode = STp->buffer->cmdstat.sense_hdr.sense_key;
+       else
                scode = 0;
                scode = 0;
-       }
 #if DEBUG
        if (debugging) {
 #if DEBUG
        if (debugging) {
-               printk(OSST_DEB_MSG "%s:D: Error: %x, cmd: %x %x %x %x %x %x Len: %d\n",
+               printk(OSST_DEB_MSG "%s:D: Error: %x, cmd: %x %x %x %x %x %x\n",
                   name, result,
                   name, result,
-                  SRpnt->sr_cmnd[0], SRpnt->sr_cmnd[1], SRpnt->sr_cmnd[2],
-                  SRpnt->sr_cmnd[3], SRpnt->sr_cmnd[4], SRpnt->sr_cmnd[5],
-                  SRpnt->sr_bufflen);
+                  SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2],
+                  SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]);
                if (scode) printk(OSST_DEB_MSG "%s:D: Sense: %02x, ASC: %02x, ASCQ: %02x\n",
                                name, scode, sense[12], sense[13]);
                if (scode) printk(OSST_DEB_MSG "%s:D: Sense: %02x, ASC: %02x, ASCQ: %02x\n",
                                name, scode, sense[12], sense[13]);
-               if (driver_byte(result) & DRIVER_SENSE)
-                       scsi_print_req_sense("osst ", SRpnt);
+               if (cmdstatp->have_sense)
+                       __scsi_print_sense("osst ", SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
        }
        else
 #endif
        }
        else
 #endif
-       if (!(driver_byte(result) & DRIVER_SENSE) ||
-               ((sense[0] & 0x70) == 0x70 &&
+       if (cmdstatp->have_sense && (
                 scode != NO_SENSE &&
                 scode != RECOVERED_ERROR &&
 /*              scode != UNIT_ATTENTION && */
                 scode != BLANK_CHECK &&
                 scode != VOLUME_OVERFLOW &&
                 scode != NO_SENSE &&
                 scode != RECOVERED_ERROR &&
 /*              scode != UNIT_ATTENTION && */
                 scode != BLANK_CHECK &&
                 scode != VOLUME_OVERFLOW &&
-                SRpnt->sr_cmnd[0] != MODE_SENSE &&
-                SRpnt->sr_cmnd[0] != TEST_UNIT_READY)) { /* Abnormal conditions for tape */
-               if (driver_byte(result) & DRIVER_SENSE) {
+                SRpnt->cmd[0] != MODE_SENSE &&
+                SRpnt->cmd[0] != TEST_UNIT_READY)) { /* Abnormal conditions for tape */
+               if (cmdstatp->have_sense) {
                        printk(KERN_WARNING "%s:W: Command with sense data:\n", name);
                        printk(KERN_WARNING "%s:W: Command with sense data:\n", name);
-                       scsi_print_req_sense("osst:", SRpnt);
+                       __scsi_print_sense("osst ", SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
                }
                else {
                        static  int     notyetprinted = 1;
                }
                else {
                        static  int     notyetprinted = 1;
@@ -262,15 +292,14 @@ static int osst_chk_result(struct osst_tape * STp, struct scsi_request * SRpnt)
        }
        STp->pos_unknown |= STp->device->was_reset;
 
        }
        STp->pos_unknown |= STp->device->was_reset;
 
-       if ((sense[0] & 0x70) == 0x70 &&
-            scode == RECOVERED_ERROR) {
+       if (cmdstatp->have_sense && scode == RECOVERED_ERROR) {
                STp->recover_count++;
                STp->recover_erreg++;
 #if DEBUG
                if (debugging) {
                STp->recover_count++;
                STp->recover_erreg++;
 #if DEBUG
                if (debugging) {
-                       if (SRpnt->sr_cmnd[0] == READ_6)
+                       if (SRpnt->cmd[0] == READ_6)
                                stp = "read";
                                stp = "read";
-                       else if (SRpnt->sr_cmnd[0] == WRITE_6)
+                       else if (SRpnt->cmd[0] == WRITE_6)
                                stp = "write";
                        else
                                stp = "ioctl";
                                stp = "write";
                        else
                                stp = "ioctl";
@@ -286,74 +315,99 @@ static int osst_chk_result(struct osst_tape * STp, struct scsi_request * SRpnt)
 
 
 /* Wakeup from interrupt */
 
 
 /* Wakeup from interrupt */
-static void osst_sleep_done (struct scsi_cmnd * SCpnt)
+static void osst_sleep_done(void *data, char *sense, int result, int resid)
 {
 {
-       struct osst_tape * STp = container_of(SCpnt->request->rq_disk->private_data, struct osst_tape, driver);
-
-       if ((STp->buffer)->writing &&
-           (SCpnt->sense_buffer[0] & 0x70) == 0x70 &&
-           (SCpnt->sense_buffer[2] & 0x40)) {
-               /* EOM at write-behind, has all been written? */
-               if ((SCpnt->sense_buffer[2] & 0x0f) == VOLUME_OVERFLOW)
-                       STp->buffer->midlevel_result = SCpnt->result; /* Error */
-               else
-                       STp->buffer->midlevel_result = INT_MAX;       /* OK */
-       }
-       else
-               STp->buffer->midlevel_result = SCpnt->result;
-       SCpnt->request->rq_status = RQ_SCSI_DONE;
-       STp->buffer->last_SRpnt = SCpnt->sc_request;
+       struct osst_request *SRpnt = data;
+       struct osst_tape *STp = SRpnt->stp;
 
 
+       memcpy(SRpnt->sense, sense, SCSI_SENSE_BUFFERSIZE);
+       STp->buffer->cmdstat.midlevel_result = SRpnt->result = result;
 #if DEBUG
        STp->write_pending = 0;
 #endif
 #if DEBUG
        STp->write_pending = 0;
 #endif
-       complete(SCpnt->request->waiting);
+       if (SRpnt->waiting)
+               complete(SRpnt->waiting);
 }
 
 }
 
+/* osst_request memory management */
+static struct osst_request *osst_allocate_request(void)
+{
+       return kzalloc(sizeof(struct osst_request), GFP_KERNEL);
+}
+
+static void osst_release_request(struct osst_request *streq)
+{
+       kfree(streq);
+}
 
 /* Do the scsi command. Waits until command performed if do_wait is true.
    Otherwise osst_write_behind_check() is used to check that the command
    has finished. */
 
 /* Do the scsi command. Waits until command performed if do_wait is true.
    Otherwise osst_write_behind_check() is used to check that the command
    has finished. */
-static struct scsi_request * osst_do_scsi(struct scsi_request *SRpnt, struct osst_tape *STp, 
+static struct osst_request * osst_do_scsi(struct osst_request *SRpnt, struct osst_tape *STp, 
        unsigned char *cmd, int bytes, int direction, int timeout, int retries, int do_wait)
 {
        unsigned char *bp;
        unsigned char *cmd, int bytes, int direction, int timeout, int retries, int do_wait)
 {
        unsigned char *bp;
+       unsigned short use_sg;
 #ifdef OSST_INJECT_ERRORS
        static   int   inject = 0;
        static   int   repeat = 0;
 #endif
 #ifdef OSST_INJECT_ERRORS
        static   int   inject = 0;
        static   int   repeat = 0;
 #endif
+       struct completion *waiting;
+
+       /* if async, make sure there's no command outstanding */
+       if (!do_wait && ((STp->buffer)->last_SRpnt)) {
+               printk(KERN_ERR "%s: Async command already active.\n",
+                      tape_name(STp));
+               if (signal_pending(current))
+                       (STp->buffer)->syscall_result = (-EINTR);
+               else
+                       (STp->buffer)->syscall_result = (-EBUSY);
+               return NULL;
+       }
+
        if (SRpnt == NULL) {
        if (SRpnt == NULL) {
-               if ((SRpnt = scsi_allocate_request(STp->device, GFP_ATOMIC)) == NULL) {
-                       printk(KERN_ERR "%s:E: Can't get SCSI request.\n", tape_name(STp));
+               SRpnt = osst_allocate_request();
+               if (SRpnt == NULL) {
+                       printk(KERN_ERR "%s: Can't allocate SCSI request.\n",
+                                    tape_name(STp));
                        if (signal_pending(current))
                                (STp->buffer)->syscall_result = (-EINTR);
                        else
                                (STp->buffer)->syscall_result = (-EBUSY);
                        return NULL;
                }
                        if (signal_pending(current))
                                (STp->buffer)->syscall_result = (-EINTR);
                        else
                                (STp->buffer)->syscall_result = (-EBUSY);
                        return NULL;
                }
+               SRpnt->stp = STp;
        }
 
        }
 
-        init_completion(&STp->wait);
-       SRpnt->sr_use_sg = (bytes > (STp->buffer)->sg[0].length) ?
-                                   (STp->buffer)->use_sg : 0;
-       if (SRpnt->sr_use_sg) {
+       /* If async IO, set last_SRpnt. This ptr tells write_behind_check
+          which IO is outstanding. It's nulled out when the IO completes. */
+       if (!do_wait)
+               (STp->buffer)->last_SRpnt = SRpnt;
+
+       waiting = &STp->wait;
+       init_completion(waiting);
+       SRpnt->waiting = waiting;
+
+       use_sg = (bytes > STp->buffer->sg[0].length) ? STp->buffer->use_sg : 0;
+       if (use_sg) {
                bp = (char *)&(STp->buffer->sg[0]);
                bp = (char *)&(STp->buffer->sg[0]);
-               if (STp->buffer->sg_segs < SRpnt->sr_use_sg)
-                       SRpnt->sr_use_sg = STp->buffer->sg_segs;
+               if (STp->buffer->sg_segs < use_sg)
+                       use_sg = STp->buffer->sg_segs;
        }
        else
                bp = (STp->buffer)->b_data;
        }
        else
                bp = (STp->buffer)->b_data;
-       SRpnt->sr_data_direction = direction;
-       SRpnt->sr_cmd_len = 0;
-       SRpnt->sr_request->waiting = &(STp->wait);
-       SRpnt->sr_request->rq_status = RQ_SCSI_BUSY;
-       SRpnt->sr_request->rq_disk = STp->drive;
 
 
-       scsi_do_req(SRpnt, (void *)cmd, bp, bytes, osst_sleep_done, timeout, retries);
+       memcpy(SRpnt->cmd, cmd, sizeof(SRpnt->cmd));
+       STp->buffer->cmdstat.have_sense = 0;
+       STp->buffer->syscall_result = 0;
 
 
-       if (do_wait) {
-               wait_for_completion(SRpnt->sr_request->waiting);
-               SRpnt->sr_request->waiting = NULL;
+       if (scsi_execute_async(STp->device, cmd, COMMAND_SIZE(cmd[0]), direction, bp, bytes,
+                       use_sg, timeout, retries, SRpnt, osst_sleep_done, GFP_KERNEL))
+               /* could not allocate the buffer or request was too large */
+               (STp->buffer)->syscall_result = (-EBUSY);
+       else if (do_wait) {
+               wait_for_completion(waiting);
+               SRpnt->waiting = NULL;
                STp->buffer->syscall_result = osst_chk_result(STp, SRpnt);
 #ifdef OSST_INJECT_ERRORS
                if (STp->buffer->syscall_result == 0 &&
                STp->buffer->syscall_result = osst_chk_result(STp, SRpnt);
 #ifdef OSST_INJECT_ERRORS
                if (STp->buffer->syscall_result == 0 &&
@@ -386,21 +440,22 @@ static void osst_write_behind_check(struct osst_tape *STp)
                STp->nbr_finished++;
 #endif
        wait_for_completion(&(STp->wait));
                STp->nbr_finished++;
 #endif
        wait_for_completion(&(STp->wait));
-       (STp->buffer)->last_SRpnt->sr_request->waiting = NULL;
+       STp->buffer->last_SRpnt->waiting = NULL;
 
        STp->buffer->syscall_result = osst_chk_result(STp, STp->buffer->last_SRpnt);
 
 
        STp->buffer->syscall_result = osst_chk_result(STp, STp->buffer->last_SRpnt);
 
-       if ((STp->buffer)->syscall_result)
-               (STp->buffer)->syscall_result =
-                       osst_write_error_recovery(STp, &((STp->buffer)->last_SRpnt), 1);
+       if (STp->buffer->syscall_result)
+               STp->buffer->syscall_result =
+                       osst_write_error_recovery(STp, &(STp->buffer->last_SRpnt), 1);
        else
                STp->first_frame_position++;
 
        else
                STp->first_frame_position++;
 
-       scsi_release_request((STp->buffer)->last_SRpnt);
+       osst_release_request(STp->buffer->last_SRpnt);
 
        if (STbuffer->writing < STbuffer->buffer_bytes)
                printk(KERN_WARNING "osst :A: write_behind_check: something left in buffer!\n");
 
 
        if (STbuffer->writing < STbuffer->buffer_bytes)
                printk(KERN_WARNING "osst :A: write_behind_check: something left in buffer!\n");
 
+       STbuffer->last_SRpnt = NULL;
        STbuffer->buffer_bytes -= STbuffer->writing;
        STbuffer->writing = 0;
 
        STbuffer->buffer_bytes -= STbuffer->writing;
        STbuffer->writing = 0;
 
@@ -609,11 +664,11 @@ err_out:
 /*
  * Wait for the unit to become Ready
  */
 /*
  * Wait for the unit to become Ready
  */
-static int osst_wait_ready(struct osst_tape * STp, struct scsi_request ** aSRpnt,
+static int osst_wait_ready(struct osst_tape * STp, struct osst_request ** aSRpnt,
                                 unsigned timeout, int initial_delay)
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
                                 unsigned timeout, int initial_delay)
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
-       struct scsi_request   * SRpnt;
+       struct osst_request   * SRpnt;
        unsigned long           startwait = jiffies;
 #if DEBUG
        int                     dbg  = debugging;
        unsigned long           startwait = jiffies;
 #if DEBUG
        int                     dbg  = debugging;
@@ -633,10 +688,10 @@ static int osst_wait_ready(struct osst_tape * STp, struct scsi_request ** aSRpnt
        if (!SRpnt) return (-EBUSY);
 
        while ( STp->buffer->syscall_result && time_before(jiffies, startwait + timeout*HZ) &&
        if (!SRpnt) return (-EBUSY);
 
        while ( STp->buffer->syscall_result && time_before(jiffies, startwait + timeout*HZ) &&
-              (( SRpnt->sr_sense_buffer[2]  == 2 && SRpnt->sr_sense_buffer[12] == 4    &&
-                (SRpnt->sr_sense_buffer[13] == 1 || SRpnt->sr_sense_buffer[13] == 8)    ) ||
-               ( SRpnt->sr_sense_buffer[2]  == 6 && SRpnt->sr_sense_buffer[12] == 0x28 &&
-                 SRpnt->sr_sense_buffer[13] == 0                                        )  )) {
+              (( SRpnt->sense[2]  == 2 && SRpnt->sense[12] == 4    &&
+                (SRpnt->sense[13] == 1 || SRpnt->sense[13] == 8)    ) ||
+               ( SRpnt->sense[2]  == 6 && SRpnt->sense[12] == 0x28 &&
+                 SRpnt->sense[13] == 0                                        )  )) {
 #if DEBUG
            if (debugging) {
                printk(OSST_DEB_MSG "%s:D: Sleeping in onstream wait ready\n", name);
 #if DEBUG
            if (debugging) {
                printk(OSST_DEB_MSG "%s:D: Sleeping in onstream wait ready\n", name);
@@ -660,8 +715,8 @@ static int osst_wait_ready(struct osst_tape * STp, struct scsi_request ** aSRpnt
 #if DEBUG
            printk(OSST_DEB_MSG "%s:D: Abnormal exit from onstream wait ready\n", name);
            printk(OSST_DEB_MSG "%s:D: Result = %d, Sense: 0=%02x, 2=%02x, 12=%02x, 13=%02x\n", name,
 #if DEBUG
            printk(OSST_DEB_MSG "%s:D: Abnormal exit from onstream wait ready\n", name);
            printk(OSST_DEB_MSG "%s:D: Result = %d, Sense: 0=%02x, 2=%02x, 12=%02x, 13=%02x\n", name,
-                       STp->buffer->syscall_result, SRpnt->sr_sense_buffer[0], SRpnt->sr_sense_buffer[2],
-                       SRpnt->sr_sense_buffer[12], SRpnt->sr_sense_buffer[13]);
+                       STp->buffer->syscall_result, SRpnt->sense[0], SRpnt->sense[2],
+                       SRpnt->sense[12], SRpnt->sense[13]);
 #endif
            return (-EIO);
        }
 #endif
            return (-EIO);
        }
@@ -674,10 +729,10 @@ static int osst_wait_ready(struct osst_tape * STp, struct scsi_request ** aSRpnt
 /*
  * Wait for a tape to be inserted in the unit
  */
 /*
  * Wait for a tape to be inserted in the unit
  */
-static int osst_wait_for_medium(struct osst_tape * STp, struct scsi_request ** aSRpnt, unsigned timeout)
+static int osst_wait_for_medium(struct osst_tape * STp, struct osst_request ** aSRpnt, unsigned timeout)
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
-       struct scsi_request   * SRpnt;
+       struct osst_request   * SRpnt;
        unsigned long           startwait = jiffies;
 #if DEBUG
        int                     dbg = debugging;
        unsigned long           startwait = jiffies;
 #if DEBUG
        int                     dbg = debugging;
@@ -694,8 +749,7 @@ static int osst_wait_for_medium(struct osst_tape * STp, struct scsi_request ** a
        if (!SRpnt) return (-EBUSY);
 
        while ( STp->buffer->syscall_result && time_before(jiffies, startwait + timeout*HZ) &&
        if (!SRpnt) return (-EBUSY);
 
        while ( STp->buffer->syscall_result && time_before(jiffies, startwait + timeout*HZ) &&
-               SRpnt->sr_sense_buffer[2]  == 2 && SRpnt->sr_sense_buffer[12] == 0x3a       &&
-               SRpnt->sr_sense_buffer[13] == 0                                             ) {
+               SRpnt->sense[2] == 2 && SRpnt->sense[12] == 0x3a && SRpnt->sense[13] == 0  ) {
 #if DEBUG
            if (debugging) {
                printk(OSST_DEB_MSG "%s:D: Sleeping in onstream wait medium\n", name);
 #if DEBUG
            if (debugging) {
                printk(OSST_DEB_MSG "%s:D: Sleeping in onstream wait medium\n", name);
@@ -714,13 +768,13 @@ static int osst_wait_for_medium(struct osst_tape * STp, struct scsi_request ** a
 #if DEBUG
        debugging = dbg;
 #endif
 #if DEBUG
        debugging = dbg;
 #endif
-       if ( STp->buffer->syscall_result     && SRpnt->sr_sense_buffer[2]  != 2 &&
-            SRpnt->sr_sense_buffer[12] != 4 && SRpnt->sr_sense_buffer[13] == 1) {
+       if ( STp->buffer->syscall_result     && SRpnt->sense[2]  != 2 &&
+            SRpnt->sense[12] != 4 && SRpnt->sense[13] == 1) {
 #if DEBUG
            printk(OSST_DEB_MSG "%s:D: Abnormal exit from onstream wait medium\n", name);
            printk(OSST_DEB_MSG "%s:D: Result = %d, Sense: 0=%02x, 2=%02x, 12=%02x, 13=%02x\n", name,
 #if DEBUG
            printk(OSST_DEB_MSG "%s:D: Abnormal exit from onstream wait medium\n", name);
            printk(OSST_DEB_MSG "%s:D: Result = %d, Sense: 0=%02x, 2=%02x, 12=%02x, 13=%02x\n", name,
-                       STp->buffer->syscall_result, SRpnt->sr_sense_buffer[0], SRpnt->sr_sense_buffer[2],
-                       SRpnt->sr_sense_buffer[12], SRpnt->sr_sense_buffer[13]);
+                       STp->buffer->syscall_result, SRpnt->sense[0], SRpnt->sense[2],
+                       SRpnt->sense[12], SRpnt->sense[13]);
 #endif
            return 0;
        }
 #endif
            return 0;
        }
@@ -730,7 +784,7 @@ static int osst_wait_for_medium(struct osst_tape * STp, struct scsi_request ** a
        return 1;
 }
 
        return 1;
 }
 
-static int osst_position_tape_and_confirm(struct osst_tape * STp, struct scsi_request ** aSRpnt, int frame)
+static int osst_position_tape_and_confirm(struct osst_tape * STp, struct osst_request ** aSRpnt, int frame)
 {
        int     retval;
 
 {
        int     retval;
 
@@ -744,10 +798,10 @@ static int osst_position_tape_and_confirm(struct osst_tape * STp, struct scsi_re
 /*
  * Wait for write(s) to complete
  */
 /*
  * Wait for write(s) to complete
  */
-static int osst_flush_drive_buffer(struct osst_tape * STp, struct scsi_request ** aSRpnt)
+static int osst_flush_drive_buffer(struct osst_tape * STp, struct osst_request ** aSRpnt)
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
-       struct scsi_request   * SRpnt;
+       struct osst_request   * SRpnt;
        int                     result = 0;
        int                     delay  = OSST_WAIT_WRITE_COMPLETE;
 #if DEBUG
        int                     result = 0;
        int                     delay  = OSST_WAIT_WRITE_COMPLETE;
 #if DEBUG
@@ -764,8 +818,8 @@ static int osst_flush_drive_buffer(struct osst_tape * STp, struct scsi_request *
        *aSRpnt = SRpnt;
        if (!SRpnt) return (-EBUSY);
        if (STp->buffer->syscall_result) {
        *aSRpnt = SRpnt;
        if (!SRpnt) return (-EBUSY);
        if (STp->buffer->syscall_result) {
-               if ((SRpnt->sr_sense_buffer[2] & 0x0f) == 2 && SRpnt->sr_sense_buffer[12] == 4) {
-                       if (SRpnt->sr_sense_buffer[13] == 8) {
+               if ((SRpnt->sense[2] & 0x0f) == 2 && SRpnt->sense[12] == 4) {
+                       if (SRpnt->sense[13] == 8) {
                                delay = OSST_WAIT_LONG_WRITE_COMPLETE;
                        }
                } else
                                delay = OSST_WAIT_LONG_WRITE_COMPLETE;
                        }
                } else
@@ -778,7 +832,7 @@ static int osst_flush_drive_buffer(struct osst_tape * STp, struct scsi_request *
 }
 
 #define OSST_POLL_PER_SEC 10
 }
 
 #define OSST_POLL_PER_SEC 10
-static int osst_wait_frame(struct osst_tape * STp, struct scsi_request ** aSRpnt, int curr, int minlast, int to)
+static int osst_wait_frame(struct osst_tape * STp, struct osst_request ** aSRpnt, int curr, int minlast, int to)
 {
        unsigned long   startwait = jiffies;
        char          * name      = tape_name(STp);
 {
        unsigned long   startwait = jiffies;
        char          * name      = tape_name(STp);
@@ -803,7 +857,7 @@ static int osst_wait_frame(struct osst_tape * STp, struct scsi_request ** aSRpnt
                    ) && result >= 0)
                {
 #if DEBUG                      
                    ) && result >= 0)
                {
 #if DEBUG                      
-                       if (debugging || jiffies - startwait >= 2*HZ/OSST_POLL_PER_SEC)
+                       if (debugging || time_after_eq(jiffies, startwait + 2*HZ/OSST_POLL_PER_SEC))
                                printk (OSST_DEB_MSG
                                        "%s:D: Succ wait f fr %i (>%i): %i-%i %i (%i): %3li.%li s\n",
                                        name, curr, curr+minlast, STp->first_frame_position,
                                printk (OSST_DEB_MSG
                                        "%s:D: Succ wait f fr %i (>%i): %i-%i %i (%i): %3li.%li s\n",
                                        name, curr, curr+minlast, STp->first_frame_position,
@@ -814,7 +868,7 @@ static int osst_wait_frame(struct osst_tape * STp, struct scsi_request ** aSRpnt
                        return 0;
                }
 #if DEBUG
                        return 0;
                }
 #if DEBUG
-               if (jiffies - startwait >= 2*HZ/OSST_POLL_PER_SEC && notyetprinted)
+               if (time_after_eq(jiffies, startwait + 2*HZ/OSST_POLL_PER_SEC) && notyetprinted)
                {
                        printk (OSST_DEB_MSG "%s:D: Wait for frame %i (>%i): %i-%i %i (%i)\n",
                                name, curr, curr+minlast, STp->first_frame_position,
                {
                        printk (OSST_DEB_MSG "%s:D: Wait for frame %i (>%i): %i-%i %i (%i)\n",
                                name, curr, curr+minlast, STp->first_frame_position,
@@ -833,9 +887,9 @@ static int osst_wait_frame(struct osst_tape * STp, struct scsi_request ** aSRpnt
        return -EBUSY;
 }
 
        return -EBUSY;
 }
 
-static int osst_recover_wait_frame(struct osst_tape * STp, struct scsi_request ** aSRpnt, int writing)
+static int osst_recover_wait_frame(struct osst_tape * STp, struct osst_request ** aSRpnt, int writing)
 {
 {
-       struct scsi_request   * SRpnt;
+       struct osst_request   * SRpnt;
        unsigned char           cmd[MAX_COMMAND_SIZE];
        unsigned long           startwait = jiffies;
        int                     retval    = 1;
        unsigned char           cmd[MAX_COMMAND_SIZE];
        unsigned long           startwait = jiffies;
        int                     retval    = 1;
@@ -856,7 +910,7 @@ static int osst_recover_wait_frame(struct osst_tape * STp, struct scsi_request *
 
                while (retval && time_before (jiffies, startwait + 5*60*HZ)) {
 
 
                while (retval && time_before (jiffies, startwait + 5*60*HZ)) {
 
-                       if (STp->buffer->syscall_result && (SRpnt->sr_sense_buffer[2] & 0x0f) != 2) {
+                       if (STp->buffer->syscall_result && (SRpnt->sense[2] & 0x0f) != 2) {
 
                                /* some failure - not just not-ready */
                                retval = osst_write_error_recovery(STp, aSRpnt, 0);
 
                                /* some failure - not just not-ready */
                                retval = osst_write_error_recovery(STp, aSRpnt, 0);
@@ -881,9 +935,9 @@ static int osst_recover_wait_frame(struct osst_tape * STp, struct scsi_request *
                if (STp->buffer->syscall_result)
                        printk(KERN_WARNING
                                "%s:W: Recover_wait_frame(read) cannot handle %02x:%02x:%02x\n", name,
                if (STp->buffer->syscall_result)
                        printk(KERN_WARNING
                                "%s:W: Recover_wait_frame(read) cannot handle %02x:%02x:%02x\n", name,
-                                       (*aSRpnt)->sr_sense_buffer[ 2] & 0x0f,
-                                       (*aSRpnt)->sr_sense_buffer[12],
-                                       (*aSRpnt)->sr_sense_buffer[13]);
+                                       (*aSRpnt)->sense[ 2] & 0x0f,
+                                       (*aSRpnt)->sense[12],
+                                       (*aSRpnt)->sense[13]);
 
        return retval;
 }
 
        return retval;
 }
@@ -891,10 +945,10 @@ static int osst_recover_wait_frame(struct osst_tape * STp, struct scsi_request *
 /*
  * Read the next OnStream tape frame at the current location
  */
 /*
  * Read the next OnStream tape frame at the current location
  */
-static int osst_read_frame(struct osst_tape * STp, struct scsi_request ** aSRpnt, int timeout)
+static int osst_read_frame(struct osst_tape * STp, struct osst_request ** aSRpnt, int timeout)
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
-       struct scsi_request   * SRpnt;
+       struct osst_request   * SRpnt;
        int                     retval = 0;
 #if DEBUG
        os_aux_t              * aux    = STp->buffer->aux;
        int                     retval = 0;
 #if DEBUG
        os_aux_t              * aux    = STp->buffer->aux;
@@ -932,10 +986,10 @@ static int osst_read_frame(struct osst_tape * STp, struct scsi_request ** aSRpnt
            if (debugging)
                printk(OSST_DEB_MSG "%s:D: Sense: %2x %2x %2x %2x %2x %2x %2x %2x\n",
                   name,
            if (debugging)
                printk(OSST_DEB_MSG "%s:D: Sense: %2x %2x %2x %2x %2x %2x %2x %2x\n",
                   name,
-                  SRpnt->sr_sense_buffer[0], SRpnt->sr_sense_buffer[1],
-                  SRpnt->sr_sense_buffer[2], SRpnt->sr_sense_buffer[3],
-                  SRpnt->sr_sense_buffer[4], SRpnt->sr_sense_buffer[5],
-                  SRpnt->sr_sense_buffer[6], SRpnt->sr_sense_buffer[7]);
+                  SRpnt->sense[0], SRpnt->sense[1],
+                  SRpnt->sense[2], SRpnt->sense[3],
+                  SRpnt->sense[4], SRpnt->sense[5],
+                  SRpnt->sense[6], SRpnt->sense[7]);
 #endif
        }
        else
 #endif
        }
        else
@@ -962,10 +1016,10 @@ static int osst_read_frame(struct osst_tape * STp, struct scsi_request ** aSRpnt
        return (retval);
 }
 
        return (retval);
 }
 
-static int osst_initiate_read(struct osst_tape * STp, struct scsi_request ** aSRpnt)
+static int osst_initiate_read(struct osst_tape * STp, struct osst_request ** aSRpnt)
 {
        struct st_partstat    * STps   = &(STp->ps[STp->partition]);
 {
        struct st_partstat    * STps   = &(STp->ps[STp->partition]);
-       struct scsi_request   * SRpnt  ;
+       struct osst_request   * SRpnt  ;
        unsigned char           cmd[MAX_COMMAND_SIZE];
        int                     retval = 0;
        char                  * name   = tape_name(STp);
        unsigned char           cmd[MAX_COMMAND_SIZE];
        int                     retval = 0;
        char                  * name   = tape_name(STp);
@@ -999,7 +1053,7 @@ static int osst_initiate_read(struct osst_tape * STp, struct scsi_request ** aSR
        return retval;
 }
 
        return retval;
 }
 
-static int osst_get_logical_frame(struct osst_tape * STp, struct scsi_request ** aSRpnt,
+static int osst_get_logical_frame(struct osst_tape * STp, struct osst_request ** aSRpnt,
                                                int frame_seq_number, int quiet)
 {
        struct st_partstat * STps  = &(STp->ps[STp->partition]);
                                                int frame_seq_number, int quiet)
 {
        struct st_partstat * STps  = &(STp->ps[STp->partition]);
@@ -1128,7 +1182,7 @@ static int osst_get_logical_frame(struct osst_tape * STp, struct scsi_request **
        return (STps->eof);
 }
 
        return (STps->eof);
 }
 
-static int osst_seek_logical_blk(struct osst_tape * STp, struct scsi_request ** aSRpnt, int logical_blk_num)
+static int osst_seek_logical_blk(struct osst_tape * STp, struct osst_request ** aSRpnt, int logical_blk_num)
 {
         struct st_partstat * STps = &(STp->ps[STp->partition]);
        char               * name = tape_name(STp);
 {
         struct st_partstat * STps = &(STp->ps[STp->partition]);
        char               * name = tape_name(STp);
@@ -1237,7 +1291,7 @@ error:
 #define OSST_SECTOR_SHIFT 9
 #define OSST_SECTOR_MASK  0x03F
 
 #define OSST_SECTOR_SHIFT 9
 #define OSST_SECTOR_MASK  0x03F
 
-static int osst_get_sector(struct osst_tape * STp, struct scsi_request ** aSRpnt)
+static int osst_get_sector(struct osst_tape * STp, struct osst_request ** aSRpnt)
 {
        int     sector;
 #if DEBUG
 {
        int     sector;
 #if DEBUG
@@ -1267,7 +1321,7 @@ static int osst_get_sector(struct osst_tape * STp, struct scsi_request ** aSRpnt
        return sector;
 }
 
        return sector;
 }
 
-static int osst_seek_sector(struct osst_tape * STp, struct scsi_request ** aSRpnt, int sector)
+static int osst_seek_sector(struct osst_tape * STp, struct osst_request ** aSRpnt, int sector)
 {
         struct st_partstat * STps   = &(STp->ps[STp->partition]);
        int                  frame  = sector >> OSST_FRAME_SHIFT,
 {
         struct st_partstat * STps   = &(STp->ps[STp->partition]);
        int                  frame  = sector >> OSST_FRAME_SHIFT,
@@ -1330,10 +1384,10 @@ static int osst_seek_sector(struct osst_tape * STp, struct scsi_request ** aSRpn
  * Precondition for this function to work: all frames in the
  * drive's buffer must be of one type (DATA, MARK or EOD)!
  */
  * Precondition for this function to work: all frames in the
  * drive's buffer must be of one type (DATA, MARK or EOD)!
  */
-static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct scsi_request ** aSRpnt,
+static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct osst_request ** aSRpnt,
                                                unsigned int frame, unsigned int skip, int pending)
 {
                                                unsigned int frame, unsigned int skip, int pending)
 {
-       struct scsi_request   * SRpnt = * aSRpnt;
+       struct osst_request   * SRpnt = * aSRpnt;
        unsigned char         * buffer, * p;
        unsigned char           cmd[MAX_COMMAND_SIZE];
        int                     flag, new_frame, i;
        unsigned char         * buffer, * p;
        unsigned char           cmd[MAX_COMMAND_SIZE];
        int                     flag, new_frame, i;
@@ -1477,8 +1531,8 @@ static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct scsi
                                        SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE, STp->timeout,
                                                                                                MAX_RETRIES, 1);
 
                                        SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE, STp->timeout,
                                                                                                MAX_RETRIES, 1);
 
-                                       if (SRpnt->sr_sense_buffer[2] == 2 && SRpnt->sr_sense_buffer[12] == 4 &&
-                                           (SRpnt->sr_sense_buffer[13] == 1 || SRpnt->sr_sense_buffer[13] == 8)) {
+                                       if (SRpnt->sense[2] == 2 && SRpnt->sense[12] == 4 &&
+                                           (SRpnt->sense[13] == 1 || SRpnt->sense[13] == 8)) {
                                                /* in the process of becoming ready */
                                                msleep(100);
                                                continue;
                                                /* in the process of becoming ready */
                                                msleep(100);
                                                continue;
@@ -1495,17 +1549,17 @@ static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct scsi
                }
                *aSRpnt = SRpnt;
                if (flag) {
                }
                *aSRpnt = SRpnt;
                if (flag) {
-                       if ((SRpnt->sr_sense_buffer[ 2] & 0x0f) == 13 &&
-                            SRpnt->sr_sense_buffer[12]         ==  0 &&
-                            SRpnt->sr_sense_buffer[13]         ==  2) {
+                       if ((SRpnt->sense[ 2] & 0x0f) == 13 &&
+                            SRpnt->sense[12]         ==  0 &&
+                            SRpnt->sense[13]         ==  2) {
                                printk(KERN_ERR "%s:E: Volume overflow in write error recovery\n", name);
                                vfree(buffer);
                                return (-EIO);                  /* hit end of tape = fail */
                        }
                                printk(KERN_ERR "%s:E: Volume overflow in write error recovery\n", name);
                                vfree(buffer);
                                return (-EIO);                  /* hit end of tape = fail */
                        }
-                       i = ((SRpnt->sr_sense_buffer[3] << 24) |
-                            (SRpnt->sr_sense_buffer[4] << 16) |
-                            (SRpnt->sr_sense_buffer[5] <<  8) |
-                             SRpnt->sr_sense_buffer[6]        ) - new_frame;
+                       i = ((SRpnt->sense[3] << 24) |
+                            (SRpnt->sense[4] << 16) |
+                            (SRpnt->sense[5] <<  8) |
+                             SRpnt->sense[6]        ) - new_frame;
                        p = &buffer[i * OS_DATA_SIZE];
 #if DEBUG
                        printk(OSST_DEB_MSG "%s:D: Additional write error at %d\n", name, new_frame+i);
                        p = &buffer[i * OS_DATA_SIZE];
 #if DEBUG
                        printk(OSST_DEB_MSG "%s:D: Additional write error at %d\n", name, new_frame+i);
@@ -1528,11 +1582,11 @@ static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct scsi
        return 0;
 }
 
        return 0;
 }
 
-static int osst_reposition_and_retry(struct osst_tape * STp, struct scsi_request ** aSRpnt,
+static int osst_reposition_and_retry(struct osst_tape * STp, struct osst_request ** aSRpnt,
                                        unsigned int frame, unsigned int skip, int pending)
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
                                        unsigned int frame, unsigned int skip, int pending)
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
-       struct scsi_request   * SRpnt;
+       struct osst_request   * SRpnt;
        char                  * name      = tape_name(STp);
        int                     expected  = 0;
        int                     attempts  = 1000 / skip;
        char                  * name      = tape_name(STp);
        int                     expected  = 0;
        int                     attempts  = 1000 / skip;
@@ -1584,9 +1638,9 @@ static int osst_reposition_and_retry(struct osst_tape * STp, struct scsi_request
                        *aSRpnt = SRpnt;
 
                        if (STp->buffer->syscall_result) {              /* additional write error */
                        *aSRpnt = SRpnt;
 
                        if (STp->buffer->syscall_result) {              /* additional write error */
-                               if ((SRpnt->sr_sense_buffer[ 2] & 0x0f) == 13 &&
-                                    SRpnt->sr_sense_buffer[12]         ==  0 &&
-                                    SRpnt->sr_sense_buffer[13]         ==  2) {
+                               if ((SRpnt->sense[ 2] & 0x0f) == 13 &&
+                                    SRpnt->sense[12]         ==  0 &&
+                                    SRpnt->sense[13]         ==  2) {
                                        printk(KERN_ERR
                                               "%s:E: Volume overflow in write error recovery\n",
                                               name);
                                        printk(KERN_ERR
                                               "%s:E: Volume overflow in write error recovery\n",
                                               name);
@@ -1631,9 +1685,9 @@ static int osst_reposition_and_retry(struct osst_tape * STp, struct scsi_request
  * Error recovery algorithm for the OnStream tape.
  */
 
  * Error recovery algorithm for the OnStream tape.
  */
 
-static int osst_write_error_recovery(struct osst_tape * STp, struct scsi_request ** aSRpnt, int pending)
+static int osst_write_error_recovery(struct osst_tape * STp, struct osst_request ** aSRpnt, int pending)
 {
 {
-       struct scsi_request * SRpnt  = * aSRpnt;
+       struct osst_request * SRpnt  = * aSRpnt;
        struct st_partstat  * STps   = & STp->ps[STp->partition];
        char                * name   = tape_name(STp);
        int                   retval = 0;
        struct st_partstat  * STps   = & STp->ps[STp->partition];
        char                * name   = tape_name(STp);
        int                   retval = 0;
@@ -1642,20 +1696,20 @@ static int osst_write_error_recovery(struct osst_tape * STp, struct scsi_request
 
        rw_state = STps->rw;
 
 
        rw_state = STps->rw;
 
-       if ((SRpnt->sr_sense_buffer[ 2] & 0x0f) != 3
-         || SRpnt->sr_sense_buffer[12]         != 12
-         || SRpnt->sr_sense_buffer[13]         != 0) {
+       if ((SRpnt->sense[ 2] & 0x0f) != 3
+         || SRpnt->sense[12]         != 12
+         || SRpnt->sense[13]         != 0) {
 #if DEBUG
                printk(OSST_DEB_MSG "%s:D: Write error recovery cannot handle %02x:%02x:%02x\n", name,
 #if DEBUG
                printk(OSST_DEB_MSG "%s:D: Write error recovery cannot handle %02x:%02x:%02x\n", name,
-                       SRpnt->sr_sense_buffer[2], SRpnt->sr_sense_buffer[12], SRpnt->sr_sense_buffer[13]);
+                       SRpnt->sense[2], SRpnt->sense[12], SRpnt->sense[13]);
 #endif
                return (-EIO);
        }
 #endif
                return (-EIO);
        }
-       frame = (SRpnt->sr_sense_buffer[3] << 24) |
-               (SRpnt->sr_sense_buffer[4] << 16) |
-               (SRpnt->sr_sense_buffer[5] <<  8) |
-                SRpnt->sr_sense_buffer[6];
-       skip  =  SRpnt->sr_sense_buffer[9];
+       frame = (SRpnt->sense[3] << 24) |
+               (SRpnt->sense[4] << 16) |
+               (SRpnt->sense[5] <<  8) |
+                SRpnt->sense[6];
+       skip  =  SRpnt->sense[9];
  
 #if DEBUG
        printk(OSST_DEB_MSG "%s:D: Detected physical bad frame at %u, advised to skip %d\n", name, frame, skip);
  
 #if DEBUG
        printk(OSST_DEB_MSG "%s:D: Detected physical bad frame at %u, advised to skip %d\n", name, frame, skip);
@@ -1710,7 +1764,7 @@ static int osst_write_error_recovery(struct osst_tape * STp, struct scsi_request
        return retval;
 }
 
        return retval;
 }
 
-static int osst_space_over_filemarks_backward(struct osst_tape * STp, struct scsi_request ** aSRpnt,
+static int osst_space_over_filemarks_backward(struct osst_tape * STp, struct osst_request ** aSRpnt,
                                                                 int mt_op, int mt_count)
 {
        char  * name = tape_name(STp);
                                                                 int mt_op, int mt_count)
 {
        char  * name = tape_name(STp);
@@ -1809,7 +1863,7 @@ found:
  *
  * Just scans for the filemark sequentially.
  */
  *
  * Just scans for the filemark sequentially.
  */
-static int osst_space_over_filemarks_forward_slow(struct osst_tape * STp, struct scsi_request ** aSRpnt,
+static int osst_space_over_filemarks_forward_slow(struct osst_tape * STp, struct osst_request ** aSRpnt,
                                                                     int mt_op, int mt_count)
 {
        int     cnt = 0;
                                                                     int mt_op, int mt_count)
 {
        int     cnt = 0;
@@ -1863,7 +1917,7 @@ static int osst_space_over_filemarks_forward_slow(struct osst_tape * STp, struct
 /*
  * Fast linux specific version of OnStream FSF
  */
 /*
  * Fast linux specific version of OnStream FSF
  */
-static int osst_space_over_filemarks_forward_fast(struct osst_tape * STp, struct scsi_request ** aSRpnt,
+static int osst_space_over_filemarks_forward_fast(struct osst_tape * STp, struct osst_request ** aSRpnt,
                                                                     int mt_op, int mt_count)
 {
        char  * name = tape_name(STp);
                                                                     int mt_op, int mt_count)
 {
        char  * name = tape_name(STp);
@@ -2014,10 +2068,10 @@ static int osst_space_over_filemarks_forward_fast(struct osst_tape * STp, struct
  * to test the error recovery mechanism.
  */
 #if DEBUG
  * to test the error recovery mechanism.
  */
 #if DEBUG
-static void osst_set_retries(struct osst_tape * STp, struct scsi_request ** aSRpnt, int retries)
+static void osst_set_retries(struct osst_tape * STp, struct osst_request ** aSRpnt, int retries)
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
-       struct scsi_request   * SRpnt  = * aSRpnt;
+       struct osst_request   * SRpnt  = * aSRpnt;
        char                  * name   = tape_name(STp);
 
        memset(cmd, 0, MAX_COMMAND_SIZE);
        char                  * name   = tape_name(STp);
 
        memset(cmd, 0, MAX_COMMAND_SIZE);
@@ -2046,7 +2100,7 @@ static void osst_set_retries(struct osst_tape * STp, struct scsi_request ** aSRp
 #endif
 
 
 #endif
 
 
-static int osst_write_filemark(struct osst_tape * STp, struct scsi_request ** aSRpnt)
+static int osst_write_filemark(struct osst_tape * STp, struct osst_request ** aSRpnt)
 {
        int     result;
        int     this_mark_ppos = STp->first_frame_position;
 {
        int     result;
        int     this_mark_ppos = STp->first_frame_position;
@@ -2074,7 +2128,7 @@ static int osst_write_filemark(struct osst_tape * STp, struct scsi_request ** aS
        return result;
 }
 
        return result;
 }
 
-static int osst_write_eod(struct osst_tape * STp, struct scsi_request ** aSRpnt)
+static int osst_write_eod(struct osst_tape * STp, struct osst_request ** aSRpnt)
 {
        int     result;
 #if DEBUG
 {
        int     result;
 #if DEBUG
@@ -2097,7 +2151,7 @@ static int osst_write_eod(struct osst_tape * STp, struct scsi_request ** aSRpnt)
        return result;
 }
 
        return result;
 }
 
-static int osst_write_filler(struct osst_tape * STp, struct scsi_request ** aSRpnt, int where, int count)
+static int osst_write_filler(struct osst_tape * STp, struct osst_request ** aSRpnt, int where, int count)
 {
        char * name = tape_name(STp);
 
 {
        char * name = tape_name(STp);
 
@@ -2122,7 +2176,7 @@ static int osst_write_filler(struct osst_tape * STp, struct scsi_request ** aSRp
        return osst_flush_drive_buffer(STp, aSRpnt);
 }
 
        return osst_flush_drive_buffer(STp, aSRpnt);
 }
 
-static int __osst_write_header(struct osst_tape * STp, struct scsi_request ** aSRpnt, int where, int count)
+static int __osst_write_header(struct osst_tape * STp, struct osst_request ** aSRpnt, int where, int count)
 {
        char * name = tape_name(STp);
        int     result;
 {
        char * name = tape_name(STp);
        int     result;
@@ -2149,7 +2203,7 @@ static int __osst_write_header(struct osst_tape * STp, struct scsi_request ** aS
        return result;
 }
 
        return result;
 }
 
-static int osst_write_header(struct osst_tape * STp, struct scsi_request ** aSRpnt, int locate_eod)
+static int osst_write_header(struct osst_tape * STp, struct osst_request ** aSRpnt, int locate_eod)
 {
        os_header_t * header;
        int           result;
 {
        os_header_t * header;
        int           result;
@@ -2223,7 +2277,7 @@ static int osst_write_header(struct osst_tape * STp, struct scsi_request ** aSRp
        return result;
 }
 
        return result;
 }
 
-static int osst_reset_header(struct osst_tape * STp, struct scsi_request ** aSRpnt)
+static int osst_reset_header(struct osst_tape * STp, struct osst_request ** aSRpnt)
 {
        if (STp->header_cache != NULL)
                memset(STp->header_cache, 0, sizeof(os_header_t));
 {
        if (STp->header_cache != NULL)
                memset(STp->header_cache, 0, sizeof(os_header_t));
@@ -2236,7 +2290,7 @@ static int osst_reset_header(struct osst_tape * STp, struct scsi_request ** aSRp
        return osst_write_header(STp, aSRpnt, 1);
 }
 
        return osst_write_header(STp, aSRpnt, 1);
 }
 
-static int __osst_analyze_headers(struct osst_tape * STp, struct scsi_request ** aSRpnt, int ppos)
+static int __osst_analyze_headers(struct osst_tape * STp, struct osst_request ** aSRpnt, int ppos)
 {
        char        * name = tape_name(STp);
        os_header_t * header;
 {
        char        * name = tape_name(STp);
        os_header_t * header;
@@ -2413,7 +2467,7 @@ static int __osst_analyze_headers(struct osst_tape * STp, struct scsi_request **
        return 1;
 }
 
        return 1;
 }
 
-static int osst_analyze_headers(struct osst_tape * STp, struct scsi_request ** aSRpnt)
+static int osst_analyze_headers(struct osst_tape * STp, struct osst_request ** aSRpnt)
 {
        int     position, ppos;
        int     first, last;
 {
        int     position, ppos;
        int     first, last;
@@ -2468,7 +2522,7 @@ static int osst_analyze_headers(struct osst_tape * STp, struct scsi_request ** a
        return 1;
 }
 
        return 1;
 }
 
-static int osst_verify_position(struct osst_tape * STp, struct scsi_request ** aSRpnt)
+static int osst_verify_position(struct osst_tape * STp, struct osst_request ** aSRpnt)
 {
        int     frame_position  = STp->first_frame_position;
        int     frame_seq_numbr = STp->frame_seq_number;
 {
        int     frame_position  = STp->first_frame_position;
        int     frame_seq_numbr = STp->frame_seq_number;
@@ -2544,11 +2598,11 @@ static unsigned int osst_parse_firmware_rev (const char * str)
 /*
  * Configure the OnStream SCII tape drive for default operation
  */
 /*
  * Configure the OnStream SCII tape drive for default operation
  */
-static int osst_configure_onstream(struct osst_tape *STp, struct scsi_request ** aSRpnt)
+static int osst_configure_onstream(struct osst_tape *STp, struct osst_request ** aSRpnt)
 {
        unsigned char                  cmd[MAX_COMMAND_SIZE];
        char                         * name = tape_name(STp);
 {
        unsigned char                  cmd[MAX_COMMAND_SIZE];
        char                         * name = tape_name(STp);
-       struct scsi_request                 * SRpnt = * aSRpnt;
+       struct osst_request          * SRpnt = * aSRpnt;
        osst_mode_parameter_header_t * header;
        osst_block_size_page_t       * bs;
        osst_capabilities_page_t     * cp;
        osst_mode_parameter_header_t * header;
        osst_block_size_page_t       * bs;
        osst_capabilities_page_t     * cp;
@@ -2715,7 +2769,7 @@ static int osst_configure_onstream(struct osst_tape *STp, struct scsi_request **
 
 /* Step over EOF if it has been inadvertently crossed (ioctl not used because
    it messes up the block number). */
 
 /* Step over EOF if it has been inadvertently crossed (ioctl not used because
    it messes up the block number). */
-static int cross_eof(struct osst_tape *STp, struct scsi_request ** aSRpnt, int forward)
+static int cross_eof(struct osst_tape *STp, struct osst_request ** aSRpnt, int forward)
 {
        int     result;
        char  * name = tape_name(STp);
 {
        int     result;
        char  * name = tape_name(STp);
@@ -2744,10 +2798,10 @@ static int cross_eof(struct osst_tape *STp, struct scsi_request ** aSRpnt, int f
 
 /* Get the tape position. */
 
 
 /* Get the tape position. */
 
-static int osst_get_frame_position(struct osst_tape *STp, struct scsi_request ** aSRpnt)
+static int osst_get_frame_position(struct osst_tape *STp, struct osst_request ** aSRpnt)
 {
        unsigned char           scmd[MAX_COMMAND_SIZE];
 {
        unsigned char           scmd[MAX_COMMAND_SIZE];
-       struct scsi_request   * SRpnt;
+       struct osst_request   * SRpnt;
        int                     result = 0;
        char                  * name   = tape_name(STp);
 
        int                     result = 0;
        char                  * name   = tape_name(STp);
 
@@ -2772,14 +2826,14 @@ static int osst_get_frame_position(struct osst_tape *STp, struct scsi_request **
        *aSRpnt = SRpnt;
 
        if (STp->buffer->syscall_result)
        *aSRpnt = SRpnt;
 
        if (STp->buffer->syscall_result)
-               result = ((SRpnt->sr_sense_buffer[2] & 0x0f) == 3) ? -EIO : -EINVAL;    /* 3: Write Error */
+               result = ((SRpnt->sense[2] & 0x0f) == 3) ? -EIO : -EINVAL;      /* 3: Write Error */
 
        if (result == -EINVAL)
                printk(KERN_ERR "%s:E: Can't read tape position.\n", name);
        else {
                if (result == -EIO) {   /* re-read position - this needs to preserve media errors */
                        unsigned char mysense[16];
 
        if (result == -EINVAL)
                printk(KERN_ERR "%s:E: Can't read tape position.\n", name);
        else {
                if (result == -EIO) {   /* re-read position - this needs to preserve media errors */
                        unsigned char mysense[16];
-                       memcpy (mysense, SRpnt->sr_sense_buffer, 16);
+                       memcpy (mysense, SRpnt->sense, 16);
                        memset (scmd, 0, MAX_COMMAND_SIZE);
                        scmd[0] = READ_POSITION;
                        STp->buffer->b_data = mybuf; STp->buffer->buffer_size = 24;
                        memset (scmd, 0, MAX_COMMAND_SIZE);
                        scmd[0] = READ_POSITION;
                        STp->buffer->b_data = mybuf; STp->buffer->buffer_size = 24;
@@ -2788,10 +2842,10 @@ static int osst_get_frame_position(struct osst_tape *STp, struct scsi_request **
 #if DEBUG
                        printk(OSST_DEB_MSG "%s:D: Reread position, reason=[%02x:%02x:%02x], result=[%s%02x:%02x:%02x]\n",
                                        name, mysense[2], mysense[12], mysense[13], STp->buffer->syscall_result?"":"ok:",
 #if DEBUG
                        printk(OSST_DEB_MSG "%s:D: Reread position, reason=[%02x:%02x:%02x], result=[%s%02x:%02x:%02x]\n",
                                        name, mysense[2], mysense[12], mysense[13], STp->buffer->syscall_result?"":"ok:",
-                                       SRpnt->sr_sense_buffer[2],SRpnt->sr_sense_buffer[12],SRpnt->sr_sense_buffer[13]);
+                                       SRpnt->sense[2],SRpnt->sense[12],SRpnt->sense[13]);
 #endif
                        if (!STp->buffer->syscall_result)
 #endif
                        if (!STp->buffer->syscall_result)
-                               memcpy (SRpnt->sr_sense_buffer, mysense, 16);
+                               memcpy (SRpnt->sense, mysense, 16);
                        else
                                printk(KERN_WARNING "%s:W: Double error in get position\n", name);
                }
                        else
                                printk(KERN_WARNING "%s:W: Double error in get position\n", name);
                }
@@ -2828,10 +2882,10 @@ static int osst_get_frame_position(struct osst_tape *STp, struct scsi_request **
 
 
 /* Set the tape block */
 
 
 /* Set the tape block */
-static int osst_set_frame_position(struct osst_tape *STp, struct scsi_request ** aSRpnt, int ppos, int skip)
+static int osst_set_frame_position(struct osst_tape *STp, struct osst_request ** aSRpnt, int ppos, int skip)
 {
        unsigned char           scmd[MAX_COMMAND_SIZE];
 {
        unsigned char           scmd[MAX_COMMAND_SIZE];
-       struct scsi_request   * SRpnt;
+       struct osst_request   * SRpnt;
        struct st_partstat    * STps;
        int                     result = 0;
        int                     pp     = (ppos == 3000 && !skip)? 0 : ppos;
        struct st_partstat    * STps;
        int                     result = 0;
        int                     pp     = (ppos == 3000 && !skip)? 0 : ppos;
@@ -2886,7 +2940,7 @@ static int osst_set_frame_position(struct osst_tape *STp, struct scsi_request **
        return result;
 }
 
        return result;
 }
 
-static int osst_write_trailer(struct osst_tape *STp, struct scsi_request ** aSRpnt, int leave_at_EOT)
+static int osst_write_trailer(struct osst_tape *STp, struct osst_request ** aSRpnt, int leave_at_EOT)
 {
        struct st_partstat * STps = &(STp->ps[STp->partition]);
        int result = 0;
 {
        struct st_partstat * STps = &(STp->ps[STp->partition]);
        int result = 0;
@@ -2913,12 +2967,12 @@ out:
 /* osst versions of st functions - augmented and stripped to suit OnStream only */
 
 /* Flush the write buffer (never need to write if variable blocksize). */
 /* osst versions of st functions - augmented and stripped to suit OnStream only */
 
 /* Flush the write buffer (never need to write if variable blocksize). */
-static int osst_flush_write_buffer(struct osst_tape *STp, struct scsi_request ** aSRpnt)
+static int osst_flush_write_buffer(struct osst_tape *STp, struct osst_request ** aSRpnt)
 {
        int                     offset, transfer, blks = 0;
        int                     result = 0;
        unsigned char           cmd[MAX_COMMAND_SIZE];
 {
        int                     offset, transfer, blks = 0;
        int                     result = 0;
        unsigned char           cmd[MAX_COMMAND_SIZE];
-       struct scsi_request   * SRpnt = *aSRpnt;
+       struct osst_request   * SRpnt = *aSRpnt;
        struct st_partstat    * STps;
        char                  * name = tape_name(STp);
 
        struct st_partstat    * STps;
        char                  * name = tape_name(STp);
 
@@ -2926,13 +2980,13 @@ static int osst_flush_write_buffer(struct osst_tape *STp, struct scsi_request **
                if (SRpnt == (STp->buffer)->last_SRpnt)
 #if DEBUG
                        { printk(OSST_DEB_MSG
                if (SRpnt == (STp->buffer)->last_SRpnt)
 #if DEBUG
                        { printk(OSST_DEB_MSG
-        "%s:D: aSRpnt points to scsi_request that write_behind_check will release -- cleared\n", name);
+        "%s:D: aSRpnt points to osst_request that write_behind_check will release -- cleared\n", name);
 #endif
                        *aSRpnt = SRpnt = NULL;
 #if DEBUG
                        } else if (SRpnt)
                                printk(OSST_DEB_MSG
 #endif
                        *aSRpnt = SRpnt = NULL;
 #if DEBUG
                        } else if (SRpnt)
                                printk(OSST_DEB_MSG
-        "%s:D: aSRpnt does not point to scsi_request that write_behind_check will release -- strange\n", name);
+        "%s:D: aSRpnt does not point to osst_request that write_behind_check will release -- strange\n", name);
 #endif 
                osst_write_behind_check(STp);
                if ((STp->buffer)->syscall_result) {
 #endif 
                osst_write_behind_check(STp);
                if ((STp->buffer)->syscall_result) {
@@ -3010,12 +3064,12 @@ static int osst_flush_write_buffer(struct osst_tape *STp, struct scsi_request **
 #if DEBUG
                        printk(OSST_DEB_MSG
                                "%s:D: write sense [0]=0x%02x [2]=%02x [12]=%02x [13]=%02x\n",
 #if DEBUG
                        printk(OSST_DEB_MSG
                                "%s:D: write sense [0]=0x%02x [2]=%02x [12]=%02x [13]=%02x\n",
-                               name, SRpnt->sr_sense_buffer[0], SRpnt->sr_sense_buffer[2],
-                               SRpnt->sr_sense_buffer[12], SRpnt->sr_sense_buffer[13]);
+                               name, SRpnt->sense[0], SRpnt->sense[2],
+                               SRpnt->sense[12], SRpnt->sense[13]);
 #endif
 #endif
-                       if ((SRpnt->sr_sense_buffer[0] & 0x70) == 0x70 &&
-                           (SRpnt->sr_sense_buffer[2] & 0x40) && /* FIXME - SC-30 drive doesn't assert EOM bit */
-                           (SRpnt->sr_sense_buffer[2] & 0x0f) == NO_SENSE) {
+                       if ((SRpnt->sense[0] & 0x70) == 0x70 &&
+                           (SRpnt->sense[2] & 0x40) && /* FIXME - SC-30 drive doesn't assert EOM bit */
+                           (SRpnt->sense[2] & 0x0f) == NO_SENSE) {
                                STp->dirty = 0;
                                (STp->buffer)->buffer_bytes = 0;
                                result = (-ENOSPC);
                                STp->dirty = 0;
                                (STp->buffer)->buffer_bytes = 0;
                                result = (-ENOSPC);
@@ -3043,7 +3097,7 @@ static int osst_flush_write_buffer(struct osst_tape *STp, struct scsi_request **
 
 /* Flush the tape buffer. The tape will be positioned correctly unless
    seek_next is true. */
 
 /* Flush the tape buffer. The tape will be positioned correctly unless
    seek_next is true. */
-static int osst_flush_buffer(struct osst_tape * STp, struct scsi_request ** aSRpnt, int seek_next)
+static int osst_flush_buffer(struct osst_tape * STp, struct osst_request ** aSRpnt, int seek_next)
 {
        struct st_partstat * STps;
        int    backspace = 0, result = 0;
 {
        struct st_partstat * STps;
        int    backspace = 0, result = 0;
@@ -3105,10 +3159,10 @@ static int osst_flush_buffer(struct osst_tape * STp, struct scsi_request ** aSRp
        return result;
 }
 
        return result;
 }
 
-static int osst_write_frame(struct osst_tape * STp, struct scsi_request ** aSRpnt, int synchronous)
+static int osst_write_frame(struct osst_tape * STp, struct osst_request ** aSRpnt, int synchronous)
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
 {
        unsigned char           cmd[MAX_COMMAND_SIZE];
-       struct scsi_request   * SRpnt;
+       struct osst_request   * SRpnt;
        int                     blks;
 #if DEBUG
        char                  * name = tape_name(STp);
        int                     blks;
 #if DEBUG
        char                  * name = tape_name(STp);
@@ -3169,9 +3223,9 @@ static int osst_write_frame(struct osst_tape * STp, struct scsi_request ** aSRpn
                        if (debugging)
                                printk(OSST_DEB_MSG "%s:D: Error on write:\n", name);
 #endif
                        if (debugging)
                                printk(OSST_DEB_MSG "%s:D: Error on write:\n", name);
 #endif
-                       if ((SRpnt->sr_sense_buffer[0] & 0x70) == 0x70 &&
-                           (SRpnt->sr_sense_buffer[2] & 0x40)) {
-                               if ((SRpnt->sr_sense_buffer[2] & 0x0f) == VOLUME_OVERFLOW)
+                       if ((SRpnt->sense[0] & 0x70) == 0x70 &&
+                           (SRpnt->sense[2] & 0x40)) {
+                               if ((SRpnt->sense[2] & 0x0f) == VOLUME_OVERFLOW)
                                        return (-ENOSPC);
                        }
                        else {
                                        return (-ENOSPC);
                        }
                        else {
@@ -3188,7 +3242,7 @@ static int osst_write_frame(struct osst_tape * STp, struct scsi_request ** aSRpn
        return 0;
 }
 
        return 0;
 }
 
-/* Lock or unlock the drive door. Don't use when struct scsi_request allocated. */
+/* Lock or unlock the drive door. Don't use when struct osst_request allocated. */
 static int do_door_lock(struct osst_tape * STp, int do_lock)
 {
        int retval, cmd;
 static int do_door_lock(struct osst_tape * STp, int do_lock)
 {
        int retval, cmd;
@@ -3236,7 +3290,7 @@ static ssize_t osst_write(struct file * filp, const char __user * buf, size_t co
        int                   write_threshold;
        int                   doing_write = 0;
        const char   __user * b_point;
        int                   write_threshold;
        int                   doing_write = 0;
        const char   __user * b_point;
-       struct scsi_request * SRpnt = NULL;
+       struct osst_request * SRpnt = NULL;
        struct st_modedef   * STm;
        struct st_partstat  * STps;
        struct osst_tape    * STp  = filp->private_data;
        struct st_modedef   * STm;
        struct st_partstat  * STps;
        struct osst_tape    * STp  = filp->private_data;
@@ -3427,7 +3481,7 @@ if (SRpnt) printk(KERN_ERR "%s:A: Not supposed to have SRpnt at line %d\n", name
 #if DEBUG
        if (debugging)
                printk(OSST_DEB_MSG "%s:D: Writing %d bytes to file %d block %d lblk %d fseq %d fppos %d\n",
 #if DEBUG
        if (debugging)
                printk(OSST_DEB_MSG "%s:D: Writing %d bytes to file %d block %d lblk %d fseq %d fppos %d\n",
-                               name, count, STps->drv_file, STps->drv_block,
+                               name, (int) count, STps->drv_file, STps->drv_block,
                                STp->logical_blk_num, STp->frame_seq_number, STp->first_frame_position);
 #endif
        b_point = buf;
                                STp->logical_blk_num, STp->frame_seq_number, STp->first_frame_position);
 #endif
        b_point = buf;
@@ -3463,7 +3517,7 @@ if (SRpnt) printk(KERN_ERR "%s:A: Not supposed to have SRpnt at line %d\n", name
 #if DEBUG
                                if (debugging)
                                      printk(OSST_DEB_MSG "%s:D: EOM with %d bytes unwritten.\n",
 #if DEBUG
                                if (debugging)
                                      printk(OSST_DEB_MSG "%s:D: EOM with %d bytes unwritten.\n",
-                                                            name, transfer);
+                                                            name, (int) transfer);
 #endif
                        }
                        else {
 #endif
                        }
                        else {
@@ -3481,7 +3535,7 @@ if (SRpnt) printk(KERN_ERR "%s:A: Not supposed to have SRpnt at line %d\n", name
                        
                if (retval < 0) {
                        if (SRpnt != NULL) {
                        
                if (retval < 0) {
                        if (SRpnt != NULL) {
-                               scsi_release_request(SRpnt);
+                               osst_release_request(SRpnt);
                                SRpnt = NULL;
                        }
                        STp->buffer->buffer_bytes = 0;
                                SRpnt = NULL;
                        }
                        STp->buffer->buffer_bytes = 0;
@@ -3543,7 +3597,7 @@ if (SRpnt) printk(KERN_ERR "%s:A: Not supposed to have SRpnt at line %d\n", name
        retval = total;
 
 out:
        retval = total;
 
 out:
-       if (SRpnt != NULL) scsi_release_request(SRpnt);
+       if (SRpnt != NULL) osst_release_request(SRpnt);
 
        up(&STp->lock);
 
 
        up(&STp->lock);
 
@@ -3559,7 +3613,7 @@ static ssize_t osst_read(struct file * filp, char __user * buf, size_t count, lo
        int                   special;
        struct st_modedef   * STm;
        struct st_partstat  * STps;
        int                   special;
        struct st_modedef   * STm;
        struct st_partstat  * STps;
-       struct scsi_request * SRpnt = NULL;
+       struct osst_request * SRpnt = NULL;
        struct osst_tape    * STp   = filp->private_data;
        char                * name  = tape_name(STp);
 
        struct osst_tape    * STp   = filp->private_data;
        char                * name  = tape_name(STp);
 
@@ -3667,7 +3721,7 @@ static ssize_t osst_read(struct file * filp, char __user * buf, size_t count, lo
 #if DEBUG
                        if (debugging && STps->eof != ST_NOEOF)
                            printk(OSST_DEB_MSG "%s:D: EOF up (%d). Left %d, needed %d.\n", name,
 #if DEBUG
                        if (debugging && STps->eof != ST_NOEOF)
                            printk(OSST_DEB_MSG "%s:D: EOF up (%d). Left %d, needed %d.\n", name,
-                                                STps->eof, (STp->buffer)->buffer_bytes, count - total);
+                                                STps->eof, (STp->buffer)->buffer_bytes, (int) (count - total));
 #endif
                        /* force multiple of block size, note block_size may have been adjusted */
                        transfer = (((STp->buffer)->buffer_bytes < count - total ?
 #endif
                        /* force multiple of block size, note block_size may have been adjusted */
                        transfer = (((STp->buffer)->buffer_bytes < count - total ?
@@ -3728,7 +3782,7 @@ static ssize_t osst_read(struct file * filp, char __user * buf, size_t count, lo
        retval = total;
 
 out:
        retval = total;
 
 out:
-       if (SRpnt != NULL) scsi_release_request(SRpnt);
+       if (SRpnt != NULL) osst_release_request(SRpnt);
 
        up(&STp->lock);
 
 
        up(&STp->lock);
 
@@ -3916,7 +3970,7 @@ static int osst_set_options(struct osst_tape *STp, long options)
 
 
 /* Internal ioctl function */
 
 
 /* Internal ioctl function */
-static int osst_int_ioctl(struct osst_tape * STp, struct scsi_request ** aSRpnt,
+static int osst_int_ioctl(struct osst_tape * STp, struct osst_request ** aSRpnt,
                             unsigned int cmd_in, unsigned long arg)
 {
        int                     timeout;
                             unsigned int cmd_in, unsigned long arg)
 {
        int                     timeout;
@@ -3924,7 +3978,7 @@ static int osst_int_ioctl(struct osst_tape * STp, struct scsi_request ** aSRpnt,
        int                     i, ioctl_result;
        int                     chg_eof = 1;
        unsigned char           cmd[MAX_COMMAND_SIZE];
        int                     i, ioctl_result;
        int                     chg_eof = 1;
        unsigned char           cmd[MAX_COMMAND_SIZE];
-       struct scsi_request   * SRpnt = * aSRpnt;
+       struct osst_request   * SRpnt = * aSRpnt;
        struct st_partstat    * STps;
        int                     fileno, blkno, at_sm, frame_seq_numbr, logical_blk_num;
        int                     datalen = 0, direction = DMA_NONE;
        struct st_partstat    * STps;
        int                     fileno, blkno, at_sm, frame_seq_numbr, logical_blk_num;
        int                     datalen = 0, direction = DMA_NONE;
@@ -4282,14 +4336,14 @@ os_bypass:
        } else if (cmd_in == MTERASE) {
                STp->header_ok = 0;
        } else if (SRpnt) {  /* SCSI command was not completely successful. */
        } else if (cmd_in == MTERASE) {
                STp->header_ok = 0;
        } else if (SRpnt) {  /* SCSI command was not completely successful. */
-               if (SRpnt->sr_sense_buffer[2] & 0x40) {
+               if (SRpnt->sense[2] & 0x40) {
                        STps->eof = ST_EOM_OK;
                        STps->drv_block = 0;
                }
                if (chg_eof)
                        STps->eof = ST_NOEOF;
 
                        STps->eof = ST_EOM_OK;
                        STps->drv_block = 0;
                }
                if (chg_eof)
                        STps->eof = ST_NOEOF;
 
-               if ((SRpnt->sr_sense_buffer[2] & 0x0f) == BLANK_CHECK)
+               if ((SRpnt->sense[2] & 0x0f) == BLANK_CHECK)
                        STps->eof = ST_EOD;
 
                if (cmd_in == MTLOAD && osst_wait_for_medium(STp, &SRpnt, 60))
                        STps->eof = ST_EOD;
 
                if (cmd_in == MTLOAD && osst_wait_for_medium(STp, &SRpnt, 60))
@@ -4307,7 +4361,7 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
        unsigned short        flags;
        int                   i, b_size, new_session = 0, retval = 0;
        unsigned char         cmd[MAX_COMMAND_SIZE];
        unsigned short        flags;
        int                   i, b_size, new_session = 0, retval = 0;
        unsigned char         cmd[MAX_COMMAND_SIZE];
-       struct scsi_request * SRpnt = NULL;
+       struct osst_request * SRpnt = NULL;
        struct osst_tape    * STp;
        struct st_modedef   * STm;
        struct st_partstat  * STps;
        struct osst_tape    * STp;
        struct st_modedef   * STm;
        struct st_partstat  * STps;
@@ -4415,17 +4469,17 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
                retval = (STp->buffer)->syscall_result;         /* FIXME - valid? */
                goto err_out;
        }
                retval = (STp->buffer)->syscall_result;         /* FIXME - valid? */
                goto err_out;
        }
-       if ((SRpnt->sr_sense_buffer[0] & 0x70) == 0x70      &&
-           (SRpnt->sr_sense_buffer[2] & 0x0f) == NOT_READY &&
-            SRpnt->sr_sense_buffer[12]        == 4         ) {
+       if ((SRpnt->sense[0] & 0x70) == 0x70      &&
+           (SRpnt->sense[2] & 0x0f) == NOT_READY &&
+            SRpnt->sense[12]        == 4         ) {
 #if DEBUG
 #if DEBUG
-               printk(OSST_DEB_MSG "%s:D: Unit not ready, cause %x\n", name, SRpnt->sr_sense_buffer[13]);
+               printk(OSST_DEB_MSG "%s:D: Unit not ready, cause %x\n", name, SRpnt->sense[13]);
 #endif
                if (filp->f_flags & O_NONBLOCK) {
                        retval = -EAGAIN;
                        goto err_out;
                }
 #endif
                if (filp->f_flags & O_NONBLOCK) {
                        retval = -EAGAIN;
                        goto err_out;
                }
-               if (SRpnt->sr_sense_buffer[13] == 2) {  /* initialize command required (LOAD) */
+               if (SRpnt->sense[13] == 2) {    /* initialize command required (LOAD) */
                        memset (cmd, 0, MAX_COMMAND_SIZE);
                        cmd[0] = START_STOP;
                        cmd[1] = 1;
                        memset (cmd, 0, MAX_COMMAND_SIZE);
                        cmd[0] = START_STOP;
                        cmd[1] = 1;
@@ -4433,10 +4487,10 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
                        SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
                                             STp->timeout, MAX_RETRIES, 1);
                }
                        SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
                                             STp->timeout, MAX_RETRIES, 1);
                }
-               osst_wait_ready(STp, &SRpnt, (SRpnt->sr_sense_buffer[13]==1?15:3) * 60, 0);
+               osst_wait_ready(STp, &SRpnt, (SRpnt->sense[13]==1?15:3) * 60, 0);
        }
        }
-       if ((SRpnt->sr_sense_buffer[0] & 0x70) == 0x70 &&
-           (SRpnt->sr_sense_buffer[2] & 0x0f) == UNIT_ATTENTION) { /* New media? */
+       if ((SRpnt->sense[0] & 0x70) == 0x70 &&
+           (SRpnt->sense[2] & 0x0f) == UNIT_ATTENTION) { /* New media? */
 #if DEBUG
                printk(OSST_DEB_MSG "%s:D: Unit wants attention\n", name);
 #endif
 #if DEBUG
                printk(OSST_DEB_MSG "%s:D: Unit wants attention\n", name);
 #endif
@@ -4449,8 +4503,8 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
 
                        SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
                                             STp->timeout, MAX_RETRIES, 1);
 
                        SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
                                             STp->timeout, MAX_RETRIES, 1);
-                       if ((SRpnt->sr_sense_buffer[0] & 0x70) != 0x70 ||
-                           (SRpnt->sr_sense_buffer[2] & 0x0f) != UNIT_ATTENTION)
+                       if ((SRpnt->sense[0] & 0x70) != 0x70 ||
+                           (SRpnt->sense[2] & 0x0f) != UNIT_ATTENTION)
                                break;
                }
 
                                break;
                }
 
@@ -4476,7 +4530,7 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
         * open without reconfiguring and re-reading the headers
         */
        if (!STp->buffer->syscall_result && STp->header_ok &&
         * open without reconfiguring and re-reading the headers
         */
        if (!STp->buffer->syscall_result && STp->header_ok &&
-           !SRpnt->sr_result && SRpnt->sr_sense_buffer[0] == 0) {
+           !SRpnt->result && SRpnt->sense[0] == 0) {
 
                memset(cmd, 0, MAX_COMMAND_SIZE);
                cmd[0] = MODE_SENSE;
 
                memset(cmd, 0, MAX_COMMAND_SIZE);
                cmd[0] = MODE_SENSE;
@@ -4515,7 +4569,7 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
                        }
                        STp->buffer->buffer_blocks = OS_DATA_SIZE / STp->block_size;
                        STp->fast_open = 1;
                        }
                        STp->buffer->buffer_blocks = OS_DATA_SIZE / STp->block_size;
                        STp->fast_open = 1;
-                       scsi_release_request(SRpnt);
+                       osst_release_request(SRpnt);
                        return 0;
                }
 #if DEBUG
                        return 0;
                }
 #if DEBUG
@@ -4528,7 +4582,7 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
        STp->fast_open = 0;
 
        if ((STp->buffer)->syscall_result != 0 &&   /* in all error conditions except no medium */ 
        STp->fast_open = 0;
 
        if ((STp->buffer)->syscall_result != 0 &&   /* in all error conditions except no medium */ 
-           (SRpnt->sr_sense_buffer[2] != 2 || SRpnt->sr_sense_buffer[12] != 0x3A) ) {
+           (SRpnt->sense[2] != 2 || SRpnt->sense[12] != 0x3A) ) {
 
                memset(cmd, 0, MAX_COMMAND_SIZE);
                cmd[0] = MODE_SELECT;
 
                memset(cmd, 0, MAX_COMMAND_SIZE);
                cmd[0] = MODE_SELECT;
@@ -4558,11 +4612,11 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
 
                        SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
                                                    STp->timeout, MAX_RETRIES, 1);
 
                        SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
                                                    STp->timeout, MAX_RETRIES, 1);
-                       if ((SRpnt->sr_sense_buffer[0] & 0x70) != 0x70 ||
-                           (SRpnt->sr_sense_buffer[2] & 0x0f) == NOT_READY)
+                       if ((SRpnt->sense[0] & 0x70) != 0x70 ||
+                           (SRpnt->sense[2] & 0x0f) == NOT_READY)
                        break;
 
                        break;
 
-                       if ((SRpnt->sr_sense_buffer[2] & 0x0f) == UNIT_ATTENTION) {
+                       if ((SRpnt->sense[2] & 0x0f) == UNIT_ATTENTION) {
                                STp->pos_unknown = 0;
                                STp->partition = STp->new_partition = 0;
                                if (STp->can_partitions)
                                STp->pos_unknown = 0;
                                STp->partition = STp->new_partition = 0;
                                if (STp->can_partitions)
@@ -4586,13 +4640,13 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
 
        if ((STp->buffer)->syscall_result != 0) {
                if ((STp->device)->scsi_level >= SCSI_2 &&
 
        if ((STp->buffer)->syscall_result != 0) {
                if ((STp->device)->scsi_level >= SCSI_2 &&
-                   (SRpnt->sr_sense_buffer[0] & 0x70) == 0x70 &&
-                   (SRpnt->sr_sense_buffer[2] & 0x0f) == NOT_READY &&
-                    SRpnt->sr_sense_buffer[12] == 0x3a) { /* Check ASC */
+                   (SRpnt->sense[0] & 0x70) == 0x70 &&
+                   (SRpnt->sense[2] & 0x0f) == NOT_READY &&
+                    SRpnt->sense[12] == 0x3a) { /* Check ASC */
                        STp->ready = ST_NO_TAPE;
                } else
                        STp->ready = ST_NOT_READY;
                        STp->ready = ST_NO_TAPE;
                } else
                        STp->ready = ST_NOT_READY;
-               scsi_release_request(SRpnt);
+               osst_release_request(SRpnt);
                SRpnt = NULL;
                STp->density = 0;       /* Clear the erroneous "residue" */
                STp->write_prot = 0;
                SRpnt = NULL;
                STp->density = 0;       /* Clear the erroneous "residue" */
                STp->write_prot = 0;
@@ -4652,14 +4706,14 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
 
        osst_analyze_headers(STp, &SRpnt);
 
 
        osst_analyze_headers(STp, &SRpnt);
 
-       scsi_release_request(SRpnt);
+       osst_release_request(SRpnt);
        SRpnt = NULL;
 
        return 0;
 
 err_out:
        if (SRpnt != NULL)
        SRpnt = NULL;
 
        return 0;
 
 err_out:
        if (SRpnt != NULL)
-               scsi_release_request(SRpnt);
+               osst_release_request(SRpnt);
        normalize_buffer(STp->buffer);
        STp->header_ok = 0;
        STp->in_use = 0;
        normalize_buffer(STp->buffer);
        STp->header_ok = 0;
        STp->in_use = 0;
@@ -4670,13 +4724,13 @@ err_out:
 
 
 /* Flush the tape buffer before close */
 
 
 /* Flush the tape buffer before close */
-static int os_scsi_tape_flush(struct file * filp)
+static int os_scsi_tape_flush(struct file * filp, fl_owner_t id)
 {
        int                   result = 0, result2;
        struct osst_tape    * STp    = filp->private_data;
        struct st_modedef   * STm    = &(STp->modes[STp->current_mode]);
        struct st_partstat  * STps   = &(STp->ps[STp->partition]);
 {
        int                   result = 0, result2;
        struct osst_tape    * STp    = filp->private_data;
        struct st_modedef   * STm    = &(STp->modes[STp->current_mode]);
        struct st_partstat  * STps   = &(STp->ps[STp->partition]);
-       struct scsi_request * SRpnt  = NULL;
+       struct osst_request * SRpnt  = NULL;
        char                * name   = tape_name(STp);
 
        if (file_count(filp) > 1)
        char                * name   = tape_name(STp);
 
        if (file_count(filp) > 1)
@@ -4739,7 +4793,7 @@ out:
                if (result == 0 && result2 < 0)
                        result = result2;
        }
                if (result == 0 && result2 < 0)
                        result = result2;
        }
-       if (SRpnt) scsi_release_request(SRpnt);
+       if (SRpnt) osst_release_request(SRpnt);
 
        if (STp->abort_count || STp->recover_count) {
                printk(KERN_INFO "%s:I:", name);
 
        if (STp->abort_count || STp->recover_count) {
                printk(KERN_INFO "%s:I:", name);
@@ -4789,11 +4843,10 @@ static int os_scsi_tape_close(struct inode * inode, struct file * filp)
 static int osst_ioctl(struct inode * inode,struct file * file,
         unsigned int cmd_in, unsigned long arg)
 {
 static int osst_ioctl(struct inode * inode,struct file * file,
         unsigned int cmd_in, unsigned long arg)
 {
-       int                   i, cmd_nr, cmd_type, retval = 0;
-       unsigned int          blk;
+       int                   i, cmd_nr, cmd_type, blk, retval = 0;
        struct st_modedef   * STm;
        struct st_partstat  * STps;
        struct st_modedef   * STm;
        struct st_partstat  * STps;
-       struct scsi_request * SRpnt = NULL;
+       struct osst_request * SRpnt = NULL;
        struct osst_tape    * STp   = file->private_data;
        char                * name  = tape_name(STp);
        void        __user  * p     = (void __user *)arg;
        struct osst_tape    * STp   = file->private_data;
        char                * name  = tape_name(STp);
        void        __user  * p     = (void __user *)arg;
@@ -5107,14 +5160,14 @@ static int osst_ioctl(struct inode * inode,struct file * file,
                        retval = -EFAULT;
                goto out;
        }
                        retval = -EFAULT;
                goto out;
        }
-       if (SRpnt) scsi_release_request(SRpnt);
+       if (SRpnt) osst_release_request(SRpnt);
 
        up(&STp->lock);
 
        return scsi_ioctl(STp->device, cmd_in, p);
 
 out:
 
        up(&STp->lock);
 
        return scsi_ioctl(STp->device, cmd_in, p);
 
 out:
-       if (SRpnt) scsi_release_request(SRpnt);
+       if (SRpnt) osst_release_request(SRpnt);
 
        up(&STp->lock);
 
 
        up(&STp->lock);
 
@@ -5153,12 +5206,12 @@ static struct osst_buffer * new_tape_buffer( int from_initialization, int need_d
                priority = GFP_KERNEL;
 
        i = sizeof(struct osst_buffer) + (osst_max_sg_segs - 1) * sizeof(struct scatterlist);
                priority = GFP_KERNEL;
 
        i = sizeof(struct osst_buffer) + (osst_max_sg_segs - 1) * sizeof(struct scatterlist);
-       tb = (struct osst_buffer *)kmalloc(i, priority);
+       tb = kzalloc(i, priority);
        if (!tb) {
                printk(KERN_NOTICE "osst :I: Can't allocate new tape buffer.\n");
                return NULL;
        }
        if (!tb) {
                printk(KERN_NOTICE "osst :I: Can't allocate new tape buffer.\n");
                return NULL;
        }
-       memset(tb, 0, i);
+
        tb->sg_segs = tb->orig_sg_segs = 0;
        tb->use_sg = max_sg;
        tb->in_use = 1;
        tb->sg_segs = tb->orig_sg_segs = 0;
        tb->use_sg = max_sg;
        tb->in_use = 1;
@@ -5438,7 +5491,7 @@ static int __init osst_setup (char *str)
   char *stp;
 
   stp = get_options(str, ARRAY_SIZE(ints), ints);
   char *stp;
 
   stp = get_options(str, ARRAY_SIZE(ints), ints);
-       
+
   if (ints[0] > 0) {
        for (i = 0; i < ints[0] && i < ARRAY_SIZE(parms); i++)
                  *parms[i].val = ints[i + 1];
   if (ints[0] > 0) {
        for (i = 0; i < ints[0] && i < ARRAY_SIZE(parms); i++)
                  *parms[i].val = ints[i + 1];
@@ -5453,7 +5506,7 @@ static int __init osst_setup (char *str)
                                break;
                        }
                }
                                break;
                        }
                }
-               if (i >= sizeof(parms) / sizeof(struct osst_dev_parm))
+               if (i >= ARRAY_SIZE(parms))
                        printk(KERN_INFO "osst :I: Illegal parameter in '%s'\n",
                               stp);
                stp = strchr(stp, ',');
                        printk(KERN_INFO "osst :I: Illegal parameter in '%s'\n",
                               stp);
                stp = strchr(stp, ',');
@@ -5521,9 +5574,9 @@ static ssize_t osst_version_show(struct device_driver *ddd, char *buf)
 
 static DRIVER_ATTR(version, S_IRUGO, osst_version_show, NULL);
 
 
 static DRIVER_ATTR(version, S_IRUGO, osst_version_show, NULL);
 
-static void osst_create_driverfs_files(struct device_driver *driverfs)
+static int osst_create_driverfs_files(struct device_driver *driverfs)
 {
 {
-       driver_create_file(driverfs, &driver_attr_version);
+       return driver_create_file(driverfs, &driver_attr_version);
 }
 
 static void osst_remove_driverfs_files(struct device_driver *driverfs)
 }
 
 static void osst_remove_driverfs_files(struct device_driver *driverfs)
@@ -5609,50 +5662,70 @@ CLASS_DEVICE_ATTR(file_count, S_IRUGO, osst_filemark_cnt_show, NULL);
 
 static struct class *osst_sysfs_class;
 
 
 static struct class *osst_sysfs_class;
 
-static int osst_sysfs_valid = 0;
-
-static void osst_sysfs_init(void)
+static int osst_sysfs_init(void)
 {
        osst_sysfs_class = class_create(THIS_MODULE, "onstream_tape");
 {
        osst_sysfs_class = class_create(THIS_MODULE, "onstream_tape");
-       if ( IS_ERR(osst_sysfs_class) )
-               printk(KERN_WARNING "osst :W: Unable to register sysfs class\n");
-       else
-               osst_sysfs_valid = 1;
+       if (IS_ERR(osst_sysfs_class)) {
+               printk(KERN_ERR "osst :W: Unable to register sysfs class\n");
+               return PTR_ERR(osst_sysfs_class);
+       }
+
+       return 0;
 }
 
 }
 
-static void osst_sysfs_add(dev_t dev, struct device *device, struct osst_tape * STp, char * name)
+static void osst_sysfs_destroy(dev_t dev)
 {
 {
-       struct class_device *osst_class_member;
+       class_device_destroy(osst_sysfs_class, dev);
+}
 
 
-       if (!osst_sysfs_valid) return;
+static int osst_sysfs_add(dev_t dev, struct device *device, struct osst_tape * STp, char * name)
+{
+       struct class_device *osst_class_member;
+       int err;
 
 
-       osst_class_member = class_device_create(osst_sysfs_class, NULL, dev, device, "%s", name);
+       osst_class_member = class_device_create(osst_sysfs_class, NULL, dev,
+                                               device, "%s", name);
        if (IS_ERR(osst_class_member)) {
                printk(KERN_WARNING "osst :W: Unable to add sysfs class member %s\n", name);
        if (IS_ERR(osst_class_member)) {
                printk(KERN_WARNING "osst :W: Unable to add sysfs class member %s\n", name);
-               return;
+               return PTR_ERR(osst_class_member);
        }
        }
+
        class_set_devdata(osst_class_member, STp);
        class_set_devdata(osst_class_member, STp);
-       class_device_create_file(osst_class_member, &class_device_attr_ADR_rev);
-       class_device_create_file(osst_class_member, &class_device_attr_media_version);
-       class_device_create_file(osst_class_member, &class_device_attr_capacity);
-       class_device_create_file(osst_class_member, &class_device_attr_BOT_frame);
-       class_device_create_file(osst_class_member, &class_device_attr_EOD_frame);
-       class_device_create_file(osst_class_member, &class_device_attr_file_count);
-}
+       err = class_device_create_file(osst_class_member,
+                                      &class_device_attr_ADR_rev);
+       if (err)
+               goto err_out;
+       err = class_device_create_file(osst_class_member,
+                                      &class_device_attr_media_version);
+       if (err)
+               goto err_out;
+       err = class_device_create_file(osst_class_member,
+                                      &class_device_attr_capacity);
+       if (err)
+               goto err_out;
+       err = class_device_create_file(osst_class_member,
+                                      &class_device_attr_BOT_frame);
+       if (err)
+               goto err_out;
+       err = class_device_create_file(osst_class_member,
+                                      &class_device_attr_EOD_frame);
+       if (err)
+               goto err_out;
+       err = class_device_create_file(osst_class_member,
+                                      &class_device_attr_file_count);
+       if (err)
+               goto err_out;
 
 
-static void osst_sysfs_destroy(dev_t dev)
-{
-       if (!osst_sysfs_valid) return; 
+       return 0;
 
 
-       class_device_destroy(osst_sysfs_class, dev);
+err_out:
+       osst_sysfs_destroy(dev);
+       return err;
 }
 
 static void osst_sysfs_cleanup(void)
 {
 }
 
 static void osst_sysfs_cleanup(void)
 {
-       if (osst_sysfs_valid) {
-               class_destroy(osst_sysfs_class);
-               osst_sysfs_valid = 0;
-       }
+       class_destroy(osst_sysfs_class);
 }
 
 /*
 }
 
 /*
@@ -5667,7 +5740,7 @@ static int osst_probe(struct device *dev)
        struct st_partstat * STps;
        struct osst_buffer * buffer;
        struct gendisk     * drive;
        struct st_partstat * STps;
        struct osst_buffer * buffer;
        struct gendisk     * drive;
-       int                  i, mode, dev_num;
+       int                  i, dev_num, err = -ENODEV;
 
        if (SDp->type != TYPE_TAPE || !osst_supports(SDp))
                return -ENODEV;
 
        if (SDp->type != TYPE_TAPE || !osst_supports(SDp))
                return -ENODEV;
@@ -5704,7 +5777,7 @@ static int osst_probe(struct device *dev)
        dev_num = i;
 
        /* allocate a struct osst_tape for this device */
        dev_num = i;
 
        /* allocate a struct osst_tape for this device */
-       tpnt = (struct osst_tape *)kmalloc(sizeof(struct osst_tape), GFP_ATOMIC);
+       tpnt = kmalloc(sizeof(struct osst_tape), GFP_ATOMIC);
        if (tpnt == NULL) {
                write_unlock(&os_scsi_tapes_lock);
                printk(KERN_ERR "osst :E: Can't allocate device descriptor, device not attached.\n");
        if (tpnt == NULL) {
                write_unlock(&os_scsi_tapes_lock);
                printk(KERN_ERR "osst :E: Can't allocate device descriptor, device not attached.\n");
@@ -5795,26 +5868,21 @@ static int osst_probe(struct device *dev)
        init_MUTEX(&tpnt->lock);
        osst_nr_dev++;
        write_unlock(&os_scsi_tapes_lock);
        init_MUTEX(&tpnt->lock);
        osst_nr_dev++;
        write_unlock(&os_scsi_tapes_lock);
+
        {
                char name[8];
        {
                char name[8];
+
                /*  Rewind entry  */
                /*  Rewind entry  */
-               osst_sysfs_add(MKDEV(OSST_MAJOR, dev_num), dev, tpnt, tape_name(tpnt));
-               /*  No-rewind entry  */
-               snprintf(name, 8, "%s%s", "n", tape_name(tpnt));
-               osst_sysfs_add(MKDEV(OSST_MAJOR, dev_num + 128), dev, tpnt, name);
-       }
-       for (mode = 0; mode < ST_NBR_MODES; ++mode) {
-               /*  Rewind entry  */
-               devfs_mk_cdev(MKDEV(OSST_MAJOR, dev_num + (mode << 5)),
-                               S_IFCHR | S_IRUGO | S_IWUGO,
-                               "%s/ot%s", SDp->devfs_name, osst_formats[mode]);
+               err = osst_sysfs_add(MKDEV(OSST_MAJOR, dev_num), dev, tpnt, tape_name(tpnt));
+               if (err)
+                       goto out_free_buffer;
 
                /*  No-rewind entry  */
 
                /*  No-rewind entry  */
-               devfs_mk_cdev(MKDEV(OSST_MAJOR, dev_num + (mode << 5) + 128),
-                               S_IFCHR | S_IRUGO | S_IWUGO,
-                               "%s/ot%sn", SDp->devfs_name, osst_formats[mode]);
+               snprintf(name, 8, "%s%s", "n", tape_name(tpnt));
+               err = osst_sysfs_add(MKDEV(OSST_MAJOR, dev_num + 128), dev, tpnt, name);
+               if (err)
+                       goto out_free_sysfs1;
        }
        }
-       drive->number = devfs_register_tape(SDp->devfs_name);
 
        sdev_printk(KERN_INFO, SDp,
                "osst :I: Attached OnStream %.5s tape as %s\n",
 
        sdev_printk(KERN_INFO, SDp,
                "osst :I: Attached OnStream %.5s tape as %s\n",
@@ -5822,16 +5890,20 @@ static int osst_probe(struct device *dev)
 
        return 0;
 
 
        return 0;
 
+out_free_sysfs1:
+       osst_sysfs_destroy(MKDEV(OSST_MAJOR, dev_num));
+out_free_buffer:
+       kfree(buffer);
 out_put_disk:
         put_disk(drive);
 out_put_disk:
         put_disk(drive);
-        return -ENODEV;
+        return err;
 };
 
 static int osst_remove(struct device *dev)
 {
        struct scsi_device * SDp = to_scsi_device(dev);
        struct osst_tape * tpnt;
 };
 
 static int osst_remove(struct device *dev)
 {
        struct scsi_device * SDp = to_scsi_device(dev);
        struct osst_tape * tpnt;
-       int i, mode;
+       int i;
 
        if ((SDp->type != TYPE_TAPE) || (osst_nr_dev <= 0))
                return 0;
 
        if ((SDp->type != TYPE_TAPE) || (osst_nr_dev <= 0))
                return 0;
@@ -5842,11 +5914,6 @@ static int osst_remove(struct device *dev)
                        osst_sysfs_destroy(MKDEV(OSST_MAJOR, i));
                        osst_sysfs_destroy(MKDEV(OSST_MAJOR, i+128));
                        tpnt->device = NULL;
                        osst_sysfs_destroy(MKDEV(OSST_MAJOR, i));
                        osst_sysfs_destroy(MKDEV(OSST_MAJOR, i+128));
                        tpnt->device = NULL;
-                       for (mode = 0; mode < ST_NBR_MODES; ++mode) {
-                               devfs_remove("%s/ot%s", SDp->devfs_name, osst_formats[mode]);
-                               devfs_remove("%s/ot%sn", SDp->devfs_name, osst_formats[mode]);
-                       }
-                       devfs_unregister_tape(tpnt->drive->number);
                        put_disk(tpnt->drive);
                        os_scsi_tapes[i] = NULL;
                        osst_nr_dev--;
                        put_disk(tpnt->drive);
                        os_scsi_tapes[i] = NULL;
                        osst_nr_dev--;
@@ -5866,19 +5933,39 @@ static int osst_remove(struct device *dev)
 
 static int __init init_osst(void) 
 {
 
 static int __init init_osst(void) 
 {
+       int err;
+
        printk(KERN_INFO "osst :I: Tape driver with OnStream support version %s\nosst :I: %s\n", osst_version, cvsid);
 
        validate_options();
        printk(KERN_INFO "osst :I: Tape driver with OnStream support version %s\nosst :I: %s\n", osst_version, cvsid);
 
        validate_options();
-       osst_sysfs_init();
 
 
-       if ((register_chrdev(OSST_MAJOR,"osst", &osst_fops) < 0) || scsi_register_driver(&osst_template.gendrv)) {
+       err = osst_sysfs_init();
+       if (err)
+               return err;
+
+       err = register_chrdev(OSST_MAJOR, "osst", &osst_fops);
+       if (err < 0) {
                printk(KERN_ERR "osst :E: Unable to register major %d for OnStream tapes\n", OSST_MAJOR);
                printk(KERN_ERR "osst :E: Unable to register major %d for OnStream tapes\n", OSST_MAJOR);
-               osst_sysfs_cleanup();
-               return 1;
+               goto err_out;
        }
        }
-       osst_create_driverfs_files(&osst_template.gendrv);
+
+       err = scsi_register_driver(&osst_template.gendrv);
+       if (err)
+               goto err_out_chrdev;
+
+       err = osst_create_driverfs_files(&osst_template.gendrv);
+       if (err)
+               goto err_out_scsidrv;
 
        return 0;
 
        return 0;
+
+err_out_scsidrv:
+       scsi_unregister_driver(&osst_template.gendrv);
+err_out_chrdev:
+       unregister_chrdev(OSST_MAJOR, "osst");
+err_out:
+       osst_sysfs_cleanup();
+       return err;
 }
 
 static void __exit exit_osst (void)
 }
 
 static void __exit exit_osst (void)