osst.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:172k
- /*
- SCSI Tape Driver for Linux version 1.1 and newer. See the accompanying
- file README.st for more information.
- History:
- OnStream SCSI Tape support (osst) cloned from st.c by
- Willem Riede (osst@riede.org) Feb 2000
- Fixes ... Kurt Garloff <garloff@suse.de> Mar 2000
- Rewritten from Dwayne Forsyth's SCSI tape driver by Kai Makisara.
- Contribution and ideas from several people including (in alphabetical
- order) Klaus Ehrenfried, Wolfgang Denk, Steve Hirsch, Andreas Koppenh"ofer,
- Michael Leodolter, Eyal Lebedinsky, J"org Weule, and Eric Youngdale.
- Copyright 1992 - 2000 Kai Makisara
- email Kai.Makisara@metla.fi
- $Header: /home/cvsroot/Driver/osst.c,v 1.65 2001/11/11 20:38:56 riede Exp $
- Microscopic alterations - Rik Ling, 2000/12/21
- Last modified: Wed Feb 2 22:04:05 2000 by makisara@kai.makisara.local
- Some small formal changes - aeb, 950809
- */
- static const char * cvsid = "$Id: osst.c,v 1.65 2001/11/11 20:38:56 riede Exp $";
- const char * osst_version = "0.9.10";
- /* The "failure to reconnect" firmware bug */
- #define OSST_FW_NEED_POLL_MIN 10601 /*(107A)*/
- #define OSST_FW_NEED_POLL_MAX 10704 /*(108D)*/
- #define OSST_FW_NEED_POLL(x,d) ((x) >= OSST_FW_NEED_POLL_MIN && (x) <= OSST_FW_NEED_POLL_MAX && d->host->this_id != 7)
- #include <linux/module.h>
- #include <linux/fs.h>
- #include <linux/kernel.h>
- #include <linux/sched.h>
- #include <linux/mm.h>
- #include <linux/init.h>
- #include <linux/string.h>
- #include <linux/errno.h>
- #include <linux/mtio.h>
- #include <linux/ioctl.h>
- #include <linux/fcntl.h>
- #include <linux/spinlock.h>
- #include <linux/vmalloc.h>
- #include <linux/version.h>
- #include <asm/uaccess.h>
- #include <asm/dma.h>
- #include <asm/system.h>
- /* The driver prints some debugging information on the console if DEBUG
- is defined and non-zero. */
- #define DEBUG 0
- /* The message level for the debug messages is currently set to KERN_NOTICE
- so that people can easily see the messages. Later when the debugging messages
- in the drivers are more widely classified, this may be changed to KERN_DEBUG. */
- #define OSST_DEB_MSG KERN_NOTICE
- #define MAJOR_NR OSST_MAJOR
- #include <linux/blk.h>
- #include "scsi.h"
- #include "hosts.h"
- #include <scsi/scsi_ioctl.h>
- #define ST_KILOBYTE 1024
- #include "st.h"
- #include "osst.h"
- #include "osst_options.h"
- #include "osst_detect.h"
- #include "constants.h"
- static int buffer_kbs = 0;
- static int write_threshold_kbs = 0;
- static int max_buffers = 0;
- static int max_sg_segs = 0;
- #ifdef MODULE
- MODULE_AUTHOR("Willem Riede");
- MODULE_DESCRIPTION("OnStream SCSI Tape Driver");
- MODULE_LICENSE("GPL");
- MODULE_PARM(buffer_kbs, "i");
- MODULE_PARM(write_threshold_kbs, "i");
- MODULE_PARM(max_buffers, "i");
- MODULE_PARM(max_sg_segs, "i");
- #else
- static struct osst_dev_parm {
- char *name;
- int *val;
- } parms[] __initdata = {
- { "buffer_kbs", &buffer_kbs },
- { "write_threshold_kbs", &write_threshold_kbs },
- { "max_buffers", &max_buffers },
- { "max_sg_segs", &max_sg_segs }
- };
- #endif
- /* 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)
- /* The buffer size should fit into the 24 bits for length in the
- 6-byte SCSI read and write commands. */
- #if OSST_BUFFER_SIZE >= (2 << 24 - 1)
- #error "Buffer size should not exceed (2 << 24 - 1) bytes!"
- #endif
- #if DEBUG
- static int debugging = 1;
- /* uncomment define below to test error recovery */
- // #define OSST_INJECT_ERRORS 1
- #endif
- #define MAX_RETRIES 0
- #define MAX_WRITE_RETRIES 0
- #define MAX_READY_RETRIES 5
- #define NO_TAPE NOT_READY
- #define OSST_TIMEOUT (200 * HZ)
- #define OSST_LONG_TIMEOUT (1800 * HZ)
- #define TAPE_NR(x) (MINOR(x) & ~(128 | ST_MODE_MASK))
- #define TAPE_MODE(x) ((MINOR(x) & ST_MODE_MASK) >> ST_MODE_SHIFT)
- /* Internal ioctl to set both density (uppermost 8 bits) and blocksize (lower
- 24 bits) */
- #define SET_DENS_AND_BLK 0x10001
- static int osst_nbr_buffers;
- static int osst_buffer_size = OSST_BUFFER_SIZE;
- static int osst_write_threshold = OSST_WRITE_THRESHOLD;
- static int osst_max_buffers = OSST_MAX_BUFFERS;
- static int osst_max_sg_segs = OSST_MAX_SG;
- static OS_Scsi_Tape **os_scsi_tapes = NULL;
- static OSST_buffer **osst_buffers = NULL;
- static int modes_defined = FALSE;
- static OSST_buffer *new_tape_buffer(int, int);
- static int enlarge_buffer(OSST_buffer *, int, int);
- static void normalize_buffer(OSST_buffer *);
- static int append_to_buffer(const char *, OSST_buffer *, int);
- static int from_buffer(OSST_buffer *, char *, int);
- static int osst_zero_buffer_tail(OSST_buffer *);
- static int osst_copy_to_buffer(OSST_buffer *, unsigned char *);
- static int osst_copy_from_buffer(OSST_buffer *, unsigned char *);
- static int osst_init(void);
- static int osst_attach(Scsi_Device *);
- static int osst_detect(Scsi_Device *);
- static void osst_detach(Scsi_Device *);
- struct Scsi_Device_Template osst_template =
- {
- name: "OnStream tape",
- tag: "osst",
- scsi_type: TYPE_TAPE,
- major: OSST_MAJOR,
- detect: osst_detect,
- init: osst_init,
- attach: osst_attach,
- detach: osst_detach
- };
- static int osst_int_ioctl(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt, unsigned int cmd_in,unsigned long arg);
- static int osst_set_frame_position(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt, int frame, int skip);
- static int osst_get_frame_position(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt);
- static int osst_flush_write_buffer(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt);
- static int osst_write_error_recovery(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int pending);
- /* Routines that handle the interaction with mid-layer SCSI routines */
- /* Convert the result to success code */
- static int osst_chk_result(OS_Scsi_Tape * STp, Scsi_Request * SRpnt)
- {
- int dev = TAPE_NR(STp->devt);
- int result = SRpnt->sr_result;
- unsigned char * sense = SRpnt->sr_sense_buffer, scode;
- #if DEBUG
- const char *stp;
- #endif
- if (!result) {
- sense[0] = 0; /* We don't have sense data if this byte is zero */
- return 0;
- }
- if (driver_byte(result) & DRIVER_SENSE)
- scode = sense[2] & 0x0f;
- else {
- sense[0] = 0; /* We don't have sense data if this byte is zero */
- scode = 0;
- }
- #if DEBUG
- if (debugging) {
- printk(OSST_DEB_MSG "osst%d:D: Error: %x, cmd: %x %x %x %x %x %x Len: %dn",
- dev, 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);
- if (driver_byte(result) & DRIVER_SENSE)
- print_req_sense("osst", SRpnt);
- }
- else
- #endif
- if (!(driver_byte(result) & DRIVER_SENSE) ||
- ((sense[0] & 0x70) == 0x70 &&
- 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) {
- printk(KERN_WARNING "osst%d:W: Command with sense data: ", dev);
- print_req_sense("osst:", SRpnt);
- }
- else {
- static int notyetprinted = 1;
- printk(KERN_WARNING
- "osst%d:W: Warning %x (sugg. bt 0x%x, driver bt 0x%x, host bt 0x%x).n",
- dev, result, suggestion(result), driver_byte(result) & DRIVER_MASK,
- host_byte(result));
- if (notyetprinted) {
- notyetprinted = 0;
- printk(KERN_INFO
- "osst%d:I: This warning may be caused by your scsi controller,n", dev);
- printk(KERN_INFO
- "osst%d:I: it has been reported with some Buslogic cards.n", dev);
- }
- }
- }
- if ((sense[0] & 0x70) == 0x70 &&
- scode == RECOVERED_ERROR) {
- STp->recover_count++;
- STp->recover_erreg++;
- #if DEBUG
- if (debugging) {
- if (SRpnt->sr_cmnd[0] == READ_6)
- stp = "read";
- else if (SRpnt->sr_cmnd[0] == WRITE_6)
- stp = "write";
- else
- stp = "ioctl";
- printk(OSST_DEB_MSG "osst%d:D: Recovered %s error (%d).n", dev, stp,
- os_scsi_tapes[dev]->recover_count);
- }
- #endif
- if ((sense[2] & 0xe0) == 0)
- return 0;
- }
- return (-EIO);
- }
- /* Wakeup from interrupt */
- static void osst_sleep_done (Scsi_Cmnd * SCpnt)
- {
- unsigned int dev = TAPE_NR(SCpnt->request.rq_dev);
- OS_Scsi_Tape * STp;
- if (os_scsi_tapes && (STp = os_scsi_tapes[dev])) {
- 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;
- #if DEBUG
- STp->write_pending = 0;
- #endif
- complete(SCpnt->request.waiting);
- }
- #if DEBUG
- else if (debugging)
- printk(OSST_DEB_MSG "osst?:D: Illegal interrupt device %xn", dev);
- #endif
- }
- /* 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 Scsi_Request * osst_do_scsi(Scsi_Request *SRpnt, OS_Scsi_Tape *STp,
- unsigned char *cmd, int bytes, int direction, int timeout, int retries, int do_wait)
- {
- unsigned char *bp;
- #ifdef OSST_INJECT_ERRORS
- static int inject = 0;
- static int repeat = 0;
- #endif
- if (SRpnt == NULL) {
- if ((SRpnt = scsi_allocate_request(STp->device)) == NULL) {
- printk(KERN_ERR "osst%d:E: Can't get SCSI request.n", TAPE_NR(STp->devt));
- if (signal_pending(current))
- (STp->buffer)->syscall_result = (-EINTR);
- else
- (STp->buffer)->syscall_result = (-EBUSY);
- return NULL;
- }
- }
- if (SRpnt->sr_device->scsi_level <= SCSI_2)
- cmd[1] |= (SRpnt->sr_device->lun << 5) & 0xe0;
- init_completion(&STp->wait);
- SRpnt->sr_use_sg = (bytes > (STp->buffer)->sg[0].length) ?
- (STp->buffer)->use_sg : 0;
- if (SRpnt->sr_use_sg) {
- bp = (char *)&(STp->buffer->sg[0]);
- if (STp->buffer->sg_segs < SRpnt->sr_use_sg)
- SRpnt->sr_use_sg = STp->buffer->sg_segs;
- }
- 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_dev = STp->devt;
- scsi_do_req(SRpnt, (void *)cmd, bp, bytes, osst_sleep_done, timeout, retries);
- if (do_wait) {
- wait_for_completion(SRpnt->sr_request.waiting);
- SRpnt->sr_request.waiting = NULL;
- STp->buffer->syscall_result = osst_chk_result(STp, SRpnt);
- #ifdef OSST_INJECT_ERRORS
- if (STp->buffer->syscall_result == 0 &&
- cmd[0] == READ_6 &&
- cmd[4] &&
- ( (++ inject % 83) == 29 ||
- (STp->first_frame_position == 240
- /* or STp->read_error_frame to fail again on the block calculated above */ &&
- ++repeat < 3))) {
- printk(OSST_DEB_MSG "osst%d:D: Injecting read errorn", TAPE_NR(STp->devt));
- STp->buffer->last_result_fatal = 1;
- }
- #endif
- }
- return SRpnt;
- }
- /* Handle the write-behind checking (downs the semaphore) */
- static void osst_write_behind_check(OS_Scsi_Tape *STp)
- {
- OSST_buffer * STbuffer;
- STbuffer = STp->buffer;
- #if DEBUG
- if (STp->write_pending)
- STp->nbr_waits++;
- else
- STp->nbr_finished++;
- #endif
- wait_for_completion(&(STp->wait));
- (STp->buffer)->last_SRpnt->sr_request.waiting = NULL;
- 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);
- else
- STp->first_frame_position++;
- scsi_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");
- STbuffer->buffer_bytes -= STbuffer->writing;
- STbuffer->writing = 0;
- return;
- }
- /* Onstream specific Routines */
- /*
- * Initialize the OnStream AUX
- */
- static void osst_init_aux(OS_Scsi_Tape * STp, int frame_type, int frame_seq_number,
- int logical_blk_num, int blk_sz, int blk_cnt)
- {
- os_aux_t *aux = STp->buffer->aux;
- os_partition_t *par = &aux->partition;
- os_dat_t *dat = &aux->dat;
- if (STp->raw) return;
- memset(aux, 0, sizeof(*aux));
- aux->format_id = htonl(0);
- memcpy(aux->application_sig, "LIN4", 4);
- aux->hdwr = htonl(0);
- aux->frame_type = frame_type;
- switch (frame_type) {
- case OS_FRAME_TYPE_HEADER:
- aux->update_frame_cntr = htonl(STp->update_frame_cntr);
- par->partition_num = OS_CONFIG_PARTITION;
- par->par_desc_ver = OS_PARTITION_VERSION;
- par->wrt_pass_cntr = htons(0xffff);
- /* 0-4 = reserved, 5-9 = header, 2990-2994 = header, 2995-2999 = reserved */
- par->first_frame_ppos = htonl(0);
- par->last_frame_ppos = htonl(0xbb7);
- aux->frame_seq_num = htonl(0);
- aux->logical_blk_num_high = htonl(0);
- aux->logical_blk_num = htonl(0);
- aux->next_mark_ppos = htonl(STp->first_mark_ppos);
- break;
- case OS_FRAME_TYPE_DATA:
- case OS_FRAME_TYPE_MARKER:
- dat->dat_sz = 8;
- dat->reserved1 = 0;
- dat->entry_cnt = 1;
- dat->reserved3 = 0;
- dat->dat_list[0].blk_sz = htonl(blk_sz);
- dat->dat_list[0].blk_cnt = htons(blk_cnt);
- dat->dat_list[0].flags = frame_type==OS_FRAME_TYPE_MARKER?
- OS_DAT_FLAGS_MARK:OS_DAT_FLAGS_DATA;
- dat->dat_list[0].reserved = 0;
- case OS_FRAME_TYPE_EOD:
- aux->update_frame_cntr = htonl(0);
- par->partition_num = OS_DATA_PARTITION;
- par->par_desc_ver = OS_PARTITION_VERSION;
- par->wrt_pass_cntr = htons(STp->wrt_pass_cntr);
- par->first_frame_ppos = htonl(STp->first_data_ppos);
- par->last_frame_ppos = htonl(STp->capacity);
- aux->frame_seq_num = htonl(frame_seq_number);
- aux->logical_blk_num_high = htonl(0);
- aux->logical_blk_num = htonl(logical_blk_num);
- break;
- default: ; /* probably FILL */
- }
- aux->filemark_cnt = ntohl(STp->filemark_cnt);
- aux->phys_fm = ntohl(0xffffffff);
- aux->last_mark_ppos = ntohl(STp->last_mark_ppos);
- aux->last_mark_lbn = ntohl(STp->last_mark_lbn);
- }
- /*
- * Verify that we have the correct tape frame
- */
- static int osst_verify_frame(OS_Scsi_Tape * STp, int frame_seq_number, int quiet)
- {
- os_aux_t * aux = STp->buffer->aux;
- os_partition_t * par = &(aux->partition);
- ST_partstat * STps = &(STp->ps[STp->partition]);
- int dev = TAPE_NR(STp->devt);
- int blk_cnt, blk_sz, i;
- if (STp->raw) {
- if (STp->buffer->syscall_result) {
- for (i=0; i < STp->buffer->sg_segs; i++)
- memset(STp->buffer->sg[i].address, 0, STp->buffer->sg[i].length);
- strcpy(STp->buffer->b_data, "READ ERROR ON FRAME");
- } else
- STp->buffer->buffer_bytes = OS_FRAME_SIZE;
- return 1;
- }
- if (STp->buffer->syscall_result) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Skipping frame, read errorn", dev);
- #endif
- return 0;
- }
- if (ntohl(aux->format_id) != 0) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Skipping frame, format_id %un", dev, ntohl(aux->format_id));
- #endif
- goto err_out;
- }
- if (memcmp(aux->application_sig, STp->application_sig, 4) != 0 &&
- (memcmp(aux->application_sig, "LIN3", 4) != 0 || STp->linux_media_version != 4)) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Skipping frame, incorrect application signaturen", dev);
- #endif
- goto err_out;
- }
- if (par->partition_num != OS_DATA_PARTITION) {
- if (!STp->linux_media || STp->linux_media_version != 2) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Skipping frame, partition num %dn",
- dev, par->partition_num);
- #endif
- goto err_out;
- }
- }
- if (par->par_desc_ver != OS_PARTITION_VERSION) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Skipping frame, partition version %dn", dev, par->par_desc_ver);
- #endif
- goto err_out;
- }
- if (ntohs(par->wrt_pass_cntr) != STp->wrt_pass_cntr) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Skipping frame, wrt_pass_cntr %d (expected %d)n",
- dev, ntohs(par->wrt_pass_cntr), STp->wrt_pass_cntr);
- #endif
- goto err_out;
- }
- if (aux->frame_type != OS_FRAME_TYPE_DATA &&
- aux->frame_type != OS_FRAME_TYPE_EOD &&
- aux->frame_type != OS_FRAME_TYPE_MARKER) {
- if (!quiet)
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Skipping frame, frame type %xn", dev, aux->frame_type);
- #endif
- goto err_out;
- }
- if (aux->frame_type == OS_FRAME_TYPE_EOD &&
- STp->first_frame_position < STp->eod_frame_ppos) {
- printk(KERN_INFO "osst%d:I: Skipping premature EOD frame %dn", dev,
- STp->first_frame_position);
- goto err_out;
- }
- STp->frame_in_buffer = 1;
- if (frame_seq_number != -1 && ntohl(aux->frame_seq_num) != frame_seq_number) {
- if (!quiet)
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Skipping frame, sequence number %u (expected %d)n",
- dev, ntohl(aux->frame_seq_num), frame_seq_number);
- #endif
- goto err_out;
- }
- if (aux->frame_type == OS_FRAME_TYPE_MARKER) {
- STps->eof = ST_FM_HIT;
- i = ntohl(aux->filemark_cnt);
- if (STp->header_cache != NULL && i < OS_FM_TAB_MAX && (i > STp->filemark_cnt ||
- STp->first_frame_position - 1 != ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[i]))) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: %s filemark %d at frame pos %dn", dev,
- STp->header_cache->dat_fm_tab.fm_tab_ent[i] == 0?"Learned":"Corrected",
- i, STp->first_frame_position - 1);
- #endif
- STp->header_cache->dat_fm_tab.fm_tab_ent[i] = htonl(STp->first_frame_position - 1);
- if (i >= STp->filemark_cnt)
- STp->filemark_cnt = i+1;
- }
- }
- if (aux->frame_type == OS_FRAME_TYPE_EOD) {
- STps->eof = ST_EOD_1;
- }
- if (aux->frame_type == OS_FRAME_TYPE_DATA) {
- blk_cnt = ntohs(aux->dat.dat_list[0].blk_cnt);
- blk_sz = ntohl(aux->dat.dat_list[0].blk_sz);
- STp->buffer->buffer_bytes = blk_cnt * blk_sz;
- STp->buffer->read_pointer = 0;
- /* See what block size was used to write file */
- if (STp->block_size != blk_sz && blk_sz > 0) {
- printk(KERN_INFO
- "osst%d:I: File was written with block size %d%c, currently %d%c, adjusted to match.n",
- dev, blk_sz<1024?blk_sz:blk_sz/1024,blk_sz<1024?'b':'k',
- STp->block_size<1024?STp->block_size:STp->block_size/1024,
- STp->block_size<1024?'b':'k');
- STp->block_size = blk_sz;
- STp->buffer->buffer_blocks = OS_DATA_SIZE / blk_sz;
- }
- STps->eof = ST_NOEOF;
- }
- STp->frame_seq_number = ntohl(aux->frame_seq_num);
- STp->logical_blk_num = ntohl(aux->logical_blk_num);
- return 1;
- err_out:
- if (STp->read_error_frame == 0)
- STp->read_error_frame = STp->first_frame_position - 1;
- return 0;
- }
- /*
- * Wait for the unit to become Ready
- */
- static int osst_wait_ready(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, unsigned timeout)
- {
- unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request * SRpnt;
- long startwait = jiffies;
- #if DEBUG
- int dbg = debugging;
- int dev = TAPE_NR(STp->devt);
- printk(OSST_DEB_MSG "osst%d:D: Reached onstream wait readyn", dev);
- #endif
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = TEST_UNIT_READY;
- SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_READY_RETRIES, TRUE);
- *aSRpnt = SRpnt;
- 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 ) )) {
- #if DEBUG
- if (debugging) {
- printk(OSST_DEB_MSG "osst%d:D: Sleeping in onstream wait readyn", dev);
- printk(OSST_DEB_MSG "osst%d:D: Turning off debugging for a whilen", dev);
- debugging = 0;
- }
- #endif
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(HZ / 10);
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = TEST_UNIT_READY;
- SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_READY_RETRIES, TRUE);
- }
- *aSRpnt = SRpnt;
- #if DEBUG
- debugging = dbg;
- #endif
- if ( STp->buffer->syscall_result &&
- osst_write_error_recovery(STp, aSRpnt, 0) ) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Abnormal exit from onstream wait readyn", dev);
- printk(OSST_DEB_MSG "osst%d:D: Result = %d, Sense: 0=%02x, 2=%02x, 12=%02x, 13=%02xn", dev,
- STp->buffer->syscall_result, SRpnt->sr_sense_buffer[0], SRpnt->sr_sense_buffer[2],
- SRpnt->sr_sense_buffer[12], SRpnt->sr_sense_buffer[13]);
- #endif
- return (-EIO);
- }
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Normal exit from onstream wait readyn", dev);
- #endif
- return 0;
- }
- /*
- * Wait for a tape to be inserted in the unit
- */
- static int osst_wait_for_medium(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, unsigned timeout)
- {
- unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request * SRpnt;
- long startwait = jiffies;
- #if DEBUG
- int dbg = debugging;
- int dev = TAPE_NR(STp->devt);
- printk(OSST_DEB_MSG "osst%d:D: Reached onstream wait for mediumn", dev);
- #endif
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = TEST_UNIT_READY;
- SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_READY_RETRIES, TRUE);
- *aSRpnt = SRpnt;
- 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 ) {
- #if DEBUG
- if (debugging) {
- printk(OSST_DEB_MSG "osst%d:D: Sleeping in onstream wait mediumn", dev);
- printk(OSST_DEB_MSG "osst%d:D: Turning off debugging for a whilen", dev);
- debugging = 0;
- }
- #endif
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(HZ / 10);
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = TEST_UNIT_READY;
- SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_READY_RETRIES, TRUE);
- }
- *aSRpnt = SRpnt;
- #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 DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Abnormal exit from onstream wait mediumn", dev);
- printk(OSST_DEB_MSG "osst%d:D: Result = %d, Sense: 0=%02x, 2=%02x, 12=%02x, 13=%02xn", dev,
- STp->buffer->syscall_result, SRpnt->sr_sense_buffer[0], SRpnt->sr_sense_buffer[2],
- SRpnt->sr_sense_buffer[12], SRpnt->sr_sense_buffer[13]);
- #endif
- return 0;
- }
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Normal exit from onstream wait mediumn", dev);
- #endif
- return 1;
- }
- static int osst_position_tape_and_confirm(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int frame)
- {
- int retval;
- osst_wait_ready(STp, aSRpnt, 15 * 60); /* TODO - can this catch a write error? */
- retval = osst_set_frame_position(STp, aSRpnt, frame, 0);
- if (retval) return (retval);
- osst_wait_ready(STp, aSRpnt, 15 * 60);
- return (osst_get_frame_position(STp, aSRpnt));
- }
- /*
- * Wait for write(s) to complete
- */
- static int osst_flush_drive_buffer(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt)
- {
- unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request * SRpnt;
- int result = 0;
- #if DEBUG
- int dev = TAPE_NR(STp->devt);
- printk(OSST_DEB_MSG "osst%d:D: Reached onstream flush drive buffer (write filemark)n", dev);
- #endif
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = WRITE_FILEMARKS;
- cmd[1] = 1;
- SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_WRITE_RETRIES, TRUE);
- *aSRpnt = SRpnt;
- if (!SRpnt) return (-EBUSY);
- if ((STp->buffer)->syscall_result)
- result = osst_write_error_recovery(STp, aSRpnt, 0);
- result |= osst_wait_ready(STp, aSRpnt, 5 * 60);
- STp->ps[STp->partition].rw = OS_WRITING_COMPLETE;
- return (result);
- }
- #define OSST_POLL_PER_SEC 10
- static int osst_wait_frame(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int curr, int minlast, int to)
- {
- long startwait = jiffies;
- int dev = TAPE_NR(STp->devt);
- #if DEBUG
- char notyetprinted = 1;
- #endif
- if (minlast >= 0 && STp->ps[STp->partition].rw != ST_READING)
- printk(KERN_ERR "osst%i:A: Waiting for frame without having initialized read!n", dev);
- while (time_before (jiffies, startwait + to*HZ))
- {
- int result;
- result = osst_get_frame_position (STp, aSRpnt);
- if (result == -EIO)
- if ((result = osst_write_error_recovery(STp, aSRpnt, 0)) == 0)
- return 0; /* successful recovery leaves drive ready for frame */
- if (result < 0) break;
- if (STp->first_frame_position == curr &&
- ((minlast < 0 &&
- (signed)STp->last_frame_position > (signed)curr + minlast) ||
- (minlast >= 0 && STp->cur_frames > minlast)
- ) && result >= 0)
- {
- #if DEBUG
- if (debugging || jiffies - startwait >= 2*HZ/OSST_POLL_PER_SEC)
- printk (OSST_DEB_MSG
- "osst%d:D: Succ wait f fr %i (>%i): %i-%i %i (%i): %3li.%li sn",
- dev, curr, curr+minlast, STp->first_frame_position,
- STp->last_frame_position, STp->cur_frames,
- result, (jiffies-startwait)/HZ,
- (((jiffies-startwait)%HZ)*10)/HZ);
- #endif
- return 0;
- }
- #if DEBUG
- if (jiffies - startwait >= 2*HZ/OSST_POLL_PER_SEC && notyetprinted)
- {
- printk (OSST_DEB_MSG "osst%d:D: Wait for frame %i (>%i): %i-%i %i (%i)n",
- dev, curr, curr+minlast, STp->first_frame_position,
- STp->last_frame_position, STp->cur_frames, result);
- notyetprinted--;
- }
- #endif
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout (HZ / OSST_POLL_PER_SEC);
- }
- #if DEBUG
- printk (OSST_DEB_MSG "osst%d:D: Fail wait f fr %i (>%i): %i-%i %i: %3li.%li sn",
- dev, curr, curr+minlast, STp->first_frame_position,
- STp->last_frame_position, STp->cur_frames,
- (jiffies-startwait)/HZ, (((jiffies-startwait)%HZ)*10)/HZ);
- #endif
- return -EBUSY;
- }
- /*
- * Read the next OnStream tape frame at the current location
- */
- static int osst_read_frame(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int timeout)
- {
- unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request * SRpnt;
- int retval = 0;
- #if DEBUG
- os_aux_t * aux = STp->buffer->aux;
- int dev = TAPE_NR(STp->devt);
- #endif
- /* TODO: Error handling */
- if (STp->poll)
- retval = osst_wait_frame (STp, aSRpnt, STp->first_frame_position, 0, timeout);
- #if 0// DEBUG
- printk ("osst_read: wait for frame returned %in", retval);
- #endif
-
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = READ_6;
- cmd[1] = 1;
- cmd[4] = 1;
- #if DEBUG
- if (debugging)
- printk(OSST_DEB_MSG "osst%d:D: Reading frame from OnStream tapen", dev);
- #endif
- SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, OS_FRAME_SIZE, SCSI_DATA_READ,
- STp->timeout, MAX_RETRIES, TRUE);
- *aSRpnt = SRpnt;
- if (!SRpnt)
- return (-EBUSY);
- if ((STp->buffer)->syscall_result) {
- retval = 1;
- if (STp->read_error_frame == 0) {
- STp->read_error_frame = STp->first_frame_position;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Recording read error at %dn", dev, STp->read_error_frame);
- #endif
- }
- #if DEBUG
- if (debugging)
- printk(OSST_DEB_MSG "osst%d:D: Sense: %2x %2x %2x %2x %2x %2x %2x %2xn",
- dev,
- 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]);
- #endif
- }
- else
- STp->first_frame_position++;
- #if DEBUG
- if (debugging) {
- printk(OSST_DEB_MSG
- "osst%d:D: AUX: %c%c%c%c UpdFrCt#%d Wpass#%d %s FrSeq#%d LogBlk#%d Qty=%d Sz=%dn", dev,
- aux->application_sig[0], aux->application_sig[1],
- aux->application_sig[2], aux->application_sig[3],
- ntohl(aux->update_frame_cntr), ntohs(aux->partition.wrt_pass_cntr),
- aux->frame_type==1?"EOD":aux->frame_type==2?"MARK":
- aux->frame_type==8?"HEADR":aux->frame_type==0x80?"DATA":"FILL",
- ntohl(aux->frame_seq_num), ntohl(aux->logical_blk_num),
- ntohs(aux->dat.dat_list[0].blk_cnt), ntohl(aux->dat.dat_list[0].blk_sz) );
- if (aux->frame_type==2)
- printk(OSST_DEB_MSG "osst%d:D: mark_cnt=%d, last_mark_ppos=%d, last_mark_lbn=%dn", dev,
- ntohl(aux->filemark_cnt), ntohl(aux->last_mark_ppos), ntohl(aux->last_mark_lbn));
- printk(OSST_DEB_MSG "osst%d:D: Exit read frame from OnStream tape with code %dn", dev, retval);
- }
- #endif
- return (retval);
- }
- static int osst_initiate_read(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt)
- {
- ST_partstat * STps = &(STp->ps[STp->partition]);
- Scsi_Request * SRpnt ;
- unsigned char cmd[MAX_COMMAND_SIZE];
- int retval = 0;
- #if DEBUG
- int dev = TAPE_NR(STp->devt);
- #endif
- if (STps->rw != ST_READING) { /* Initialize read operation */
- if (STps->rw == ST_WRITING) {
- osst_flush_write_buffer(STp, aSRpnt);
- osst_flush_drive_buffer(STp, aSRpnt);
- }
- STps->rw = ST_READING;
- STp->frame_in_buffer = 0;
- /*
- * Issue a read 0 command to get the OnStream drive
- * read frames into its buffer.
- */
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = READ_6;
- cmd[1] = 1;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Start Read Ahead on OnStream tapen", dev);
- #endif
- SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_RETRIES, TRUE);
- *aSRpnt = SRpnt;
- retval = STp->buffer->syscall_result;
- }
- return retval;
- }
- static int osst_get_logical_frame(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int frame_seq_number, int quiet)
- {
- ST_partstat * STps = &(STp->ps[STp->partition]);
- int dev = TAPE_NR(STp->devt);
- int cnt = 0,
- bad = 0,
- past = 0,
- x,
- position;
- /*
- * Search and wait for the next logical tape frame
- */
- while (1) {
- if (cnt++ > 400) {
- printk(KERN_ERR "osst%d:E: Couldn't find logical frame %d, abortingn",
- dev, frame_seq_number);
- if (STp->read_error_frame) {
- osst_set_frame_position(STp, aSRpnt, STp->read_error_frame, 0);
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Repositioning tape to bad frame %dn",
- dev, STp->read_error_frame);
- #endif
- STp->read_error_frame = 0;
- }
- return (-EIO);
- }
- #if DEBUG
- if (debugging)
- printk(OSST_DEB_MSG "osst%d:D: Looking for frame %d, attempt %dn",
- dev, frame_seq_number, cnt);
- #endif
- if ( osst_initiate_read(STp, aSRpnt)
- || ( (!STp->frame_in_buffer) && osst_read_frame(STp, aSRpnt, 30) ) ) {
- if (STp->raw)
- return (-EIO);
- position = osst_get_frame_position(STp, aSRpnt);
- if (position >= 0xbae && position < 0xbb8)
- position = 0xbb8;
- else if (position > STp->eod_frame_ppos || ++bad == 10) {
- position = STp->read_error_frame - 1;
- }
- else {
- position += 39;
- cnt += 20;
- }
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Bad frame detected, positioning tape to block %dn",
- dev, position);
- #endif
- osst_set_frame_position(STp, aSRpnt, position, 0);
- continue;
- }
- if (osst_verify_frame(STp, frame_seq_number, quiet))
- break;
- if (osst_verify_frame(STp, -1, quiet)) {
- x = ntohl(STp->buffer->aux->frame_seq_num);
- if (STp->fast_open) {
- printk(KERN_WARNING
- "osst%d:W: Found logical frame %d instead of %d after fast openn",
- dev, x, frame_seq_number);
- STp->header_ok = 0;
- STp->read_error_frame = 0;
- return (-EIO);
- }
- if (x > frame_seq_number) {
- if (++past > 3) {
- /* positioning backwards did not bring us to the desired frame */
- position = STp->read_error_frame - 1;
- }
- else {
- position = osst_get_frame_position(STp, aSRpnt)
- + frame_seq_number - x - 1;
- if (STp->first_frame_position >= 3000 && position < 3000)
- position -= 10;
- }
- #if DEBUG
- printk(OSST_DEB_MSG
- "osst%d:D: Found logical frame %d while looking for %d: back up %dn",
- dev, x, frame_seq_number,
- STp->first_frame_position - position);
- #endif
- osst_set_frame_position(STp, aSRpnt, position, 0);
- cnt += 10;
- }
- else
- past = 0;
- }
- if (osst_get_frame_position(STp, aSRpnt) == 0xbaf) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Skipping config partitionn", dev);
- #endif
- osst_set_frame_position(STp, aSRpnt, 0xbb8, 0);
- cnt--;
- }
- STp->frame_in_buffer = 0;
- }
- if (cnt > 1) {
- STp->recover_count++;
- STp->recover_erreg++;
- printk(KERN_WARNING "osst%d:I: Don't worry, Read error at position %d recoveredn",
- dev, STp->read_error_frame);
- }
- STp->read_count++;
- #if DEBUG
- if (debugging || STps->eof)
- printk(OSST_DEB_MSG
- "osst%d:D: Exit get logical frame (%d=>%d) from OnStream tape with code %dn",
- dev, frame_seq_number, STp->frame_seq_number, STps->eof);
- #endif
- STp->fast_open = FALSE;
- STp->read_error_frame = 0;
- return (STps->eof);
- }
- static int osst_seek_logical_blk(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int logical_blk_num)
- {
- ST_partstat * STps = &(STp->ps[STp->partition]);
- int dev = TAPE_NR(STp->devt);
- int retries = 0;
- int frame_seq_estimate, ppos_estimate, move;
-
- if (logical_blk_num < 0) logical_blk_num = 0;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Seeking logical block %d (now at %d, size %d%c)n",
- dev, logical_blk_num, STp->logical_blk_num,
- STp->block_size<1024?STp->block_size:STp->block_size/1024,
- STp->block_size<1024?'b':'k');
- #endif
- /* Do we know where we are? */
- if (STps->drv_block >= 0) {
- move = logical_blk_num - STp->logical_blk_num;
- if (move < 0) move -= (OS_DATA_SIZE / STp->block_size) - 1;
- move /= (OS_DATA_SIZE / STp->block_size);
- frame_seq_estimate = STp->frame_seq_number + move;
- } else
- frame_seq_estimate = logical_blk_num * STp->block_size / OS_DATA_SIZE;
- if (frame_seq_estimate < 2980) ppos_estimate = frame_seq_estimate + 10;
- else ppos_estimate = frame_seq_estimate + 20;
- while (++retries < 10) {
- if (ppos_estimate > STp->eod_frame_ppos-2) {
- frame_seq_estimate += STp->eod_frame_ppos - 2 - ppos_estimate;
- ppos_estimate = STp->eod_frame_ppos - 2;
- }
- if (frame_seq_estimate < 0) {
- frame_seq_estimate = 0;
- ppos_estimate = 10;
- }
- osst_set_frame_position(STp, aSRpnt, ppos_estimate, 0);
- if (osst_get_logical_frame(STp, aSRpnt, frame_seq_estimate, 1) >= 0) {
- /* we've located the estimated frame, now does it have our block? */
- if (logical_blk_num < STp->logical_blk_num ||
- logical_blk_num >= STp->logical_blk_num + ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt)) {
- if (STps->eof == ST_FM_HIT)
- move = logical_blk_num < STp->logical_blk_num? -2 : 1;
- else {
- move = logical_blk_num - STp->logical_blk_num;
- if (move < 0) move -= (OS_DATA_SIZE / STp->block_size) - 1;
- move /= (OS_DATA_SIZE / STp->block_size);
- }
- #if DEBUG
- printk(OSST_DEB_MSG
- "osst%d:D: Seek retry %d at ppos %d fsq %d (est %d) lbn %d (need %d) move %dn",
- dev, retries, ppos_estimate, STp->frame_seq_number, frame_seq_estimate,
- STp->logical_blk_num, logical_blk_num, move);
- #endif
- frame_seq_estimate += move;
- ppos_estimate += move;
- continue;
- } else {
- STp->buffer->read_pointer = (logical_blk_num - STp->logical_blk_num) * STp->block_size;
- STp->buffer->buffer_bytes -= STp->buffer->read_pointer;
- STp->logical_blk_num = logical_blk_num;
- #if DEBUG
- printk(OSST_DEB_MSG
- "osst%d:D: Seek success at ppos %d fsq %d in_buf %d, bytes %d, ptr %d*%dn",
- dev, ppos_estimate, STp->frame_seq_number, STp->frame_in_buffer,
- STp->buffer->buffer_bytes, STp->buffer->read_pointer / STp->block_size,
- STp->block_size);
- #endif
- STps->drv_file = ntohl(STp->buffer->aux->filemark_cnt);
- if (STps->eof == ST_FM_HIT) {
- STps->drv_file++;
- STps->drv_block = 0;
- } else {
- STps->drv_block = ntohl(STp->buffer->aux->last_mark_lbn)?
- STp->logical_blk_num -
- (STps->drv_file ? ntohl(STp->buffer->aux->last_mark_lbn) + 1 : 0):
- -1;
- }
- STps->eof = (STp->first_frame_position >= STp->eod_frame_ppos)?ST_EOD:ST_NOEOF;
- return 0;
- }
- }
- if (osst_get_logical_frame(STp, aSRpnt, -1, 1) < 0)
- goto error;
- /* we are not yet at the estimated frame, adjust our estimate of its physical position */
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Seek retry %d at ppos %d fsq %d (est %d) lbn %d (need %d)n",
- dev, retries, ppos_estimate, STp->frame_seq_number, frame_seq_estimate,
- STp->logical_blk_num, logical_blk_num);
- #endif
- if (frame_seq_estimate != STp->frame_seq_number)
- ppos_estimate += frame_seq_estimate - STp->frame_seq_number;
- else
- break;
- }
- error:
- printk(KERN_ERR "osst%d:E: Couldn't seek to logical block %d (at %d), %d retriesn",
- dev, logical_blk_num, STp->logical_blk_num, retries);
- return (-EIO);
- }
- /* The values below are based on the OnStream frame payload size of 32K == 2**15,
- * that is, OSST_FRAME_SHIFT + OSST_SECTOR_SHIFT must be 15. With a minimum block
- * size of 512 bytes, we need to be able to resolve 32K/512 == 64 == 2**6 positions
- * inside each frame. Finaly, OSST_SECTOR_MASK == 2**OSST_FRAME_SHIFT - 1.
- */
- #define OSST_FRAME_SHIFT 6
- #define OSST_SECTOR_SHIFT 9
- #define OSST_SECTOR_MASK 0x03F
- static int osst_get_sector(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt)
- {
- int sector;
- #if DEBUG
- int dev = TAPE_NR(STp->devt);
-
- printk(OSST_DEB_MSG
- "osst%d:D: Positioned at ppos %d, frame %d, lbn %d, file %d, blk %d, %cptr %d, eof %dn",
- dev, STp->first_frame_position, STp->frame_seq_number, STp->logical_blk_num,
- STp->ps[STp->partition].drv_file, STp->ps[STp->partition].drv_block,
- STp->ps[STp->partition].rw == ST_WRITING?'w':'r',
- STp->ps[STp->partition].rw == ST_WRITING?STp->buffer->buffer_bytes:
- STp->buffer->read_pointer, STp->ps[STp->partition].eof);
- #endif
- /* do we know where we are inside a file? */
- if (STp->ps[STp->partition].drv_block >= 0) {
- sector = (STp->frame_in_buffer ? STp->first_frame_position-1 :
- STp->first_frame_position) << OSST_FRAME_SHIFT;
- if (STp->ps[STp->partition].rw == ST_WRITING)
- sector |= (STp->buffer->buffer_bytes >> OSST_SECTOR_SHIFT) & OSST_SECTOR_MASK;
- else
- sector |= (STp->buffer->read_pointer >> OSST_SECTOR_SHIFT) & OSST_SECTOR_MASK;
- } else {
- sector = osst_get_frame_position(STp, aSRpnt);
- if (sector > 0)
- sector <<= OSST_FRAME_SHIFT;
- }
- return sector;
- }
- static int osst_seek_sector(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int sector)
- {
- ST_partstat * STps = &(STp->ps[STp->partition]);
- int frame = sector >> OSST_FRAME_SHIFT,
- offset = (sector & OSST_SECTOR_MASK) << OSST_SECTOR_SHIFT,
- r;
- #if DEBUG
- int dev = TAPE_NR(STp->devt);
- printk(OSST_DEB_MSG "osst%d:D: Seeking sector %d in frame %d at offset %dn",
- dev, sector, frame, offset);
- #endif
- if (frame < 0 || frame >= STp->capacity) return (-ENXIO);
- if (frame <= STp->first_data_ppos) {
- STp->frame_seq_number = STp->logical_blk_num = STps->drv_file = STps->drv_block = 0;
- return (osst_set_frame_position(STp, aSRpnt, frame, 0));
- }
- r = osst_set_frame_position(STp, aSRpnt, offset?frame:frame-1, 0);
- if (r < 0) return r;
- r = osst_get_logical_frame(STp, aSRpnt, -1, 1);
- if (r < 0) return r;
- if (osst_get_frame_position(STp, aSRpnt) != (offset?frame+1:frame)) return (-EIO);
- if (offset) {
- STp->logical_blk_num += offset / STp->block_size;
- STp->buffer->read_pointer = offset;
- STp->buffer->buffer_bytes -= offset;
- } else {
- STp->frame_seq_number++;
- STp->frame_in_buffer = 0;
- STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
- STp->buffer->buffer_bytes = STp->buffer->read_pointer = 0;
- }
- STps->drv_file = ntohl(STp->buffer->aux->filemark_cnt);
- if (STps->eof == ST_FM_HIT) {
- STps->drv_file++;
- STps->drv_block = 0;
- } else {
- STps->drv_block = ntohl(STp->buffer->aux->last_mark_lbn)?
- STp->logical_blk_num -
- (STps->drv_file ? ntohl(STp->buffer->aux->last_mark_lbn) + 1 : 0):
- -1;
- }
- STps->eof = (STp->first_frame_position >= STp->eod_frame_ppos)?ST_EOD:ST_NOEOF;
- #if DEBUG
- printk(OSST_DEB_MSG
- "osst%d:D: Now positioned at ppos %d, frame %d, lbn %d, file %d, blk %d, rptr %d, eof %dn",
- dev, STp->first_frame_position, STp->frame_seq_number, STp->logical_blk_num,
- STps->drv_file, STps->drv_block, STp->buffer->read_pointer, STps->eof);
- #endif
- return 0;
- }
- /*
- * Read back the drive's internal buffer contents, as a part
- * of the write error recovery mechanism for old OnStream
- * firmware revisions.
- * 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(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt,
- unsigned int frame, unsigned int skip, int pending)
- {
- Scsi_Request * SRpnt = * aSRpnt;
- unsigned char * buffer, * p;
- unsigned char cmd[MAX_COMMAND_SIZE];
- int flag, new_frame, i;
- int nframes = STp->cur_frames;
- int blks_per_frame = ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
- int frame_seq_number = ntohl(STp->buffer->aux->frame_seq_num)
- - (nframes + pending - 1);
- int logical_blk_num = ntohl(STp->buffer->aux->logical_blk_num)
- - (nframes + pending - 1) * blks_per_frame;
- int dev = TAPE_NR(STp->devt);
- long startwait = jiffies;
- #if DEBUG
- int dbg = debugging;
- #endif
- if ((buffer = (unsigned char *)vmalloc((nframes + 1) * OS_DATA_SIZE)) == NULL)
- return (-EIO);
- printk(KERN_INFO "osst%d:I: Reading back %d frames from drive buffer%sn",
- dev, nframes, pending?" and one that was pending":"");
- osst_copy_from_buffer(STp->buffer, (p = &buffer[nframes * OS_DATA_SIZE]));
- #if DEBUG
- if (pending && debugging)
- printk(OSST_DEB_MSG "osst%d:D: Pending frame %d (lblk %d), data %02x %02x %02x %02xn",
- dev, frame_seq_number + nframes,
- logical_blk_num + nframes * blks_per_frame,
- p[0], p[1], p[2], p[3]);
- #endif
- for (i = 0, p = buffer; i < nframes; i++, p += OS_DATA_SIZE) {
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = 0x3C; /* Buffer Read */
- cmd[1] = 6; /* Retrieve Faulty Block */
- cmd[7] = 32768 >> 8;
- cmd[8] = 32768 & 0xff;
- SRpnt = osst_do_scsi(SRpnt, STp, cmd, OS_FRAME_SIZE, SCSI_DATA_READ,
- STp->timeout, MAX_RETRIES, TRUE);
-
- if ((STp->buffer)->syscall_result || !SRpnt) {
- printk(KERN_ERR "osst%d:E: Failed to read frame back from OnStream buffern", dev);
- vfree((void *)buffer);
- *aSRpnt = SRpnt;
- return (-EIO);
- }
- osst_copy_from_buffer(STp->buffer, p);
- #if DEBUG
- if (debugging)
- printk(OSST_DEB_MSG "osst%d:D: Read back logical frame %d, data %02x %02x %02x %02xn",
- dev, frame_seq_number + i, p[0], p[1], p[2], p[3]);
- #endif
- }
- *aSRpnt = SRpnt;
- osst_get_frame_position(STp, aSRpnt);
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Frames left in buffer: %dn", dev, STp->cur_frames);
- #endif
- /* Write synchronously so we can be sure we're OK again and don't have to recover recursively */
- /* In the header we don't actually re-write the frames that fail, just the ones after them */
- for (flag=1, new_frame=frame, p=buffer, i=0; i < nframes + pending; ) {
- if (flag) {
- if (STp->write_type == OS_WRITE_HEADER) {
- i += skip;
- p += skip * OS_DATA_SIZE;
- }
- else if (new_frame < 2990 && new_frame+skip+nframes+pending >= 2990)
- new_frame = 3000-i;
- else
- new_frame += skip;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Position to frame %d, write fseq %dn",
- dev, new_frame+i, frame_seq_number+i);
- #endif
- osst_set_frame_position(STp, aSRpnt, new_frame + i, 0);
- osst_wait_ready(STp, aSRpnt, 60);
- osst_get_frame_position(STp, aSRpnt);
- SRpnt = * aSRpnt;
- if (new_frame > frame + 1000) {
- printk(KERN_ERR "osst%d:E: Failed to find writable tape median", dev);
- vfree((void *)buffer);
- return (-EIO);
- }
- flag = 0;
- if ( i >= nframes + pending ) break;
- }
- osst_copy_to_buffer(STp->buffer, p);
- /*
- * IMPORTANT: for error recovery to work, _never_ queue frames with mixed frame type!
- */
- osst_init_aux(STp, STp->buffer->aux->frame_type, frame_seq_number+i,
- logical_blk_num + i*blks_per_frame,
- ntohl(STp->buffer->aux->dat.dat_list[0].blk_sz), blks_per_frame);
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = WRITE_6;
- cmd[1] = 1;
- cmd[4] = 1;
- #if DEBUG
- if (debugging)
- printk(OSST_DEB_MSG
- "osst%d:D: About to write frame %d, seq %d, lbn %d, data %02x %02x %02x %02xn",
- dev, new_frame+i, frame_seq_number+i, logical_blk_num + i*blks_per_frame,
- p[0], p[1], p[2], p[3]);
- #endif
- SRpnt = osst_do_scsi(SRpnt, STp, cmd, OS_FRAME_SIZE, SCSI_DATA_WRITE,
- STp->timeout, MAX_WRITE_RETRIES, TRUE);
- if (STp->buffer->syscall_result)
- flag = 1;
- else {
- p += OS_DATA_SIZE; i++;
- /* if we just sent the last frame, wait till all successfully written */
- if ( i == nframes + pending ) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Check re-write successfuln", dev);
- #endif
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = WRITE_FILEMARKS;
- cmd[1] = 1;
- SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, SCSI_DATA_NONE,
- STp->timeout, MAX_WRITE_RETRIES, TRUE);
- #if DEBUG
- if (debugging) {
- printk(OSST_DEB_MSG "osst%d:D: Sleeping in re-write wait readyn", dev);
- printk(OSST_DEB_MSG "osst%d:D: Turning off debugging for a whilen", dev);
- debugging = 0;
- }
- #endif
- flag = STp->buffer->syscall_result;
- while ( !flag && time_before(jiffies, startwait + 60*HZ) ) {
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = TEST_UNIT_READY;
- SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout,
- MAX_READY_RETRIES, TRUE);
- 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)) {
- /* in the process of becoming ready */
- schedule_timeout(HZ / 10);
- continue;
- }
- if (STp->buffer->syscall_result)
- flag = 1;
- break;
- }
- #if DEBUG
- debugging = dbg;
- printk(OSST_DEB_MSG "osst%d:D: Wait re-write finishedn", dev);
- #endif
- }
- }
- *aSRpnt = SRpnt;
- if (flag) {
- if ((SRpnt->sr_sense_buffer[ 2] & 0x0f) == 13 &&
- SRpnt->sr_sense_buffer[12] == 0 &&
- SRpnt->sr_sense_buffer[13] == 2) {
- printk(KERN_ERR "osst%d:E: Volume overflow in write error recoveryn", dev);
- vfree((void *)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;
- p = &buffer[i * OS_DATA_SIZE];
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Additional write error at %dn", dev, new_frame+i);
- #endif
- osst_get_frame_position(STp, aSRpnt);
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: reported frame positions: host = %d, tape = %dn",
- dev, STp->first_frame_position, STp->last_frame_position);
- #endif
- }
- }
- if (!pending)
- osst_copy_to_buffer(STp->buffer, p); /* so buffer content == at entry in all cases */
- vfree((void *)buffer);
- return 0;
- }
- static int osst_reposition_and_retry(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt,
- unsigned int frame, unsigned int skip, int pending)
- {
- unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request * SRpnt;
- int dev = TAPE_NR(STp->devt);
- int expected = 0;
- int attempts = 1000 / skip;
- int flag = 1;
- long startwait = jiffies;
- #if DEBUG
- int dbg = debugging;
- #endif
- while (attempts && time_before(jiffies, startwait + 60*HZ)) {
- if (flag) {
- #if DEBUG
- debugging = dbg;
- #endif
- if (frame < 2990 && frame+skip+STp->cur_frames+pending >= 2990)
- frame = 3000-skip;
- expected = frame+skip+STp->cur_frames+pending;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Position to fppos %d, re-write from fseq %dn",
- dev, frame+skip, STp->frame_seq_number-STp->cur_frames-pending);
- #endif
- osst_set_frame_position(STp, aSRpnt, frame + skip, 1);
- flag = 0;
- attempts--;
- }
- if (osst_get_frame_position(STp, aSRpnt) < 0) { /* additional write error */
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Addl error, host %d, tape %d, buffer %dn",
- dev, STp->first_frame_position,
- STp->last_frame_position, STp->cur_frames);
- #endif
- frame = STp->last_frame_position;
- flag = 1;
- continue;
- }
- if (pending && STp->cur_frames < 50) {
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = WRITE_6;
- cmd[1] = 1;
- cmd[4] = 1;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: About to write pending fseq %d at fppos %dn",
- dev, STp->frame_seq_number-1, STp->first_frame_position);
- #endif
- SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, OS_FRAME_SIZE, SCSI_DATA_WRITE,
- STp->timeout, MAX_WRITE_RETRIES, TRUE);
- *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) {
- printk(KERN_ERR
- "osst%d:E: Volume overflow in write error recoveryn",
- dev);
- break; /* hit end of tape = fail */
- }
- flag = 1;
- }
- else
- pending = 0;
- continue;
- }
- if (STp->cur_frames == 0) {
- #if DEBUG
- debugging = dbg;
- printk(OSST_DEB_MSG "osst%d:D: Wait re-write finishedn", dev);
- #endif
- if (STp->first_frame_position != expected) {
- printk(KERN_ERR "osst%d:A: Actual position %d - expected %dn",
- dev, STp->first_frame_position, expected);
- return (-EIO);
- }
- return 0;
- }
- #if DEBUG
- if (debugging) {
- printk(OSST_DEB_MSG "osst%d:D: Sleeping in re-write wait readyn", dev);
- printk(OSST_DEB_MSG "osst%d:D: Turning off debugging for a whilen", dev);
- debugging = 0;
- }
- #endif
- schedule_timeout(HZ / 10);
- }
- printk(KERN_ERR "osst%d:E: Failed to find valid tape median", dev);
- #if DEBUG
- debugging = dbg;
- #endif
- return (-EIO);
- }
- /*
- * Error recovery algorithm for the OnStream tape.
- */
- static int osst_write_error_recovery(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int pending)
- {
- Scsi_Request * SRpnt = * aSRpnt;
- ST_partstat * STps = & STp->ps[STp->partition];
- int dev = TAPE_NR(STp->devt);
- int retval = 0;
- int rw_state;
- unsigned int frame, skip;
- 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 DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Write error recovery cannot handle %02x:%02x:%02xn", dev,
- SRpnt->sr_sense_buffer[2], SRpnt->sr_sense_buffer[12], SRpnt->sr_sense_buffer[13]);
- #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];
-
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Detected physical bad frame at %u, advised to skip %dn", dev, frame, skip);
- #endif
- osst_get_frame_position(STp, aSRpnt);
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: reported frame positions: host = %d, tape = %dn",
- dev, STp->first_frame_position, STp->last_frame_position);
- #endif
- switch (STp->write_type) {
- case OS_WRITE_DATA:
- case OS_WRITE_EOD:
- case OS_WRITE_NEW_MARK:
- printk(KERN_WARNING
- "osst%d:I: Relocating %d buffered logical frames from position %u to %un",
- dev, STp->cur_frames, frame, (frame + skip > 3000 && frame < 3000)?3000:frame + skip);
- if (STp->os_fw_rev >= 10600)
- retval = osst_reposition_and_retry(STp, aSRpnt, frame, skip, pending);
- else
- retval = osst_read_back_buffer_and_rewrite(STp, aSRpnt, frame, skip, pending);
- printk(KERN_WARNING "osst%d:%s: %sWrite error%srecoveredn", dev,
- retval?"E" :"I",
- retval?"" :"Don't worry, ",
- retval?" not ":" ");
- break;
- case OS_WRITE_LAST_MARK:
- printk(KERN_ERR "osst%d:E: Bad frame in update last marker, fataln", dev);
- osst_set_frame_position(STp, aSRpnt, frame + STp->cur_frames + pending, 0);
- retval = -EIO;
- break;
- case OS_WRITE_HEADER:
- printk(KERN_WARNING "osst%d:I: Bad frame in header partition, skippedn", dev);
- retval = osst_read_back_buffer_and_rewrite(STp, aSRpnt, frame, 1, pending);
- break;
- default:
- printk(KERN_INFO "osst%d:I: Bad frame in filler, ignoredn", dev);
- osst_set_frame_position(STp, aSRpnt, frame + STp->cur_frames + pending, 0);
- }
- osst_get_frame_position(STp, aSRpnt);
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Positioning complete, cur_frames %d, pos %d, tape pos %dn",
- dev, STp->cur_frames, STp->first_frame_position, STp->last_frame_position);
- printk(OSST_DEB_MSG "osst%d:D: next logical frame to write: %dn", dev, STp->logical_blk_num);
- #endif
- if (retval == 0) {
- STp->recover_count++;
- STp->recover_erreg++;
- }
- STps->rw = rw_state;
- return retval;
- }
- static int osst_space_over_filemarks_backward(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt,
- int mt_op, int mt_count)
- {
- int dev = TAPE_NR(STp->devt);
- int cnt;
- int last_mark_ppos = -1;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Reached space_over_filemarks_backwards %d %dn", dev, mt_op, mt_count);
- #endif
- if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Couldn't get logical blk num in space_filemarks_bwdn", dev);
- #endif
- return -EIO;
- }
- if (STp->linux_media_version >= 4) {
- /*
- * direct lookup in header filemark list
- */
- cnt = ntohl(STp->buffer->aux->filemark_cnt);
- if (STp->header_ok &&
- STp->header_cache != NULL &&
- (cnt - mt_count) >= 0 &&
- (cnt - mt_count) < OS_FM_TAB_MAX &&
- (cnt - mt_count) < STp->filemark_cnt &&
- STp->header_cache->dat_fm_tab.fm_tab_ent[cnt-1] == STp->buffer->aux->last_mark_ppos)
- last_mark_ppos = ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[cnt - mt_count]);
- #if DEBUG
- if (STp->header_cache == NULL || (cnt - mt_count) < 0 || (cnt - mt_count) >= OS_FM_TAB_MAX)
- printk(OSST_DEB_MSG "osst%d:D: Filemark lookup fail due to %sn", dev,
- STp->header_cache == NULL?"lack of header cache":"count out of range");
- else
- printk(OSST_DEB_MSG "osst%d:D: Filemark lookup: prev mark %d (%s), skip %d to %dn",
- dev, cnt,
- ((cnt == -1 && ntohl(STp->buffer->aux->last_mark_ppos) == -1) ||
- (STp->header_cache->dat_fm_tab.fm_tab_ent[cnt-1] ==
- STp->buffer->aux->last_mark_ppos))?"match":"error",
- mt_count, last_mark_ppos);
- #endif
- if (last_mark_ppos > 10 && last_mark_ppos < STp->eod_frame_ppos) {
- osst_position_tape_and_confirm(STp, aSRpnt, last_mark_ppos);
- if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
- #if DEBUG
- printk(OSST_DEB_MSG
- "osst%d:D: Couldn't get logical blk num in space_filemarksn", dev);
- #endif
- return (-EIO);
- }
- if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) {
- printk(KERN_WARNING "osst%d:W: Expected to find marker at ppos %d, not foundn",
- dev, last_mark_ppos);
- return (-EIO);
- }
- if (mt_op == MTBSFM) {
- STp->frame_seq_number++;
- STp->frame_in_buffer = 0;
- STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
- }
- return 0;
- }
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Reverting to scan filemark backwardsn", dev);
- #endif
- }
- cnt = 0;
- while (cnt != mt_count) {
- last_mark_ppos = ntohl(STp->buffer->aux->last_mark_ppos);
- if (last_mark_ppos == -1)
- return (-EIO);
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Positioning to last mark at %dn", dev, last_mark_ppos);
- #endif
- osst_position_tape_and_confirm(STp, aSRpnt, last_mark_ppos);
- cnt++;
- if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Couldn't get logical blk num in space_filemarksn", dev);
- #endif
- return (-EIO);
- }
- if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) {
- printk(KERN_WARNING "osst%d:W: Expected to find marker at ppos %d, not foundn",
- dev, last_mark_ppos);
- return (-EIO);
- }
- }
- if (mt_op == MTBSFM) {
- STp->frame_seq_number++;
- STp->frame_in_buffer = 0;
- STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
- }
- return 0;
- }
- /*
- * ADRL 1.1 compatible "slow" space filemarks fwd version
- *
- * Just scans for the filemark sequentially.
- */
- static int osst_space_over_filemarks_forward_slow(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt,
- int mt_op, int mt_count)
- {
- int cnt = 0;
- #if DEBUG
- int dev = TAPE_NR(STp->devt);
- printk(OSST_DEB_MSG "osst%d:D: Reached space_over_filemarks_forward_slow %d %dn", dev, mt_op, mt_count);
- #endif
- if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Couldn't get logical blk num in space_filemarks_fwdn", dev);
- #endif
- return (-EIO);
- }
- while (1) {
- if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Couldn't get logical blk num in space_filemarksn", dev);
- #endif
- return (-EIO);
- }
- if (STp->buffer->aux->frame_type == OS_FRAME_TYPE_MARKER)
- cnt++;
- if (STp->buffer->aux->frame_type == OS_FRAME_TYPE_EOD) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: space_fwd: EOD reachedn", dev);
- #endif
- if (STp->first_frame_position > STp->eod_frame_ppos+1) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: EOD position corrected (%d=>%d)n",
- dev, STp->eod_frame_ppos, STp->first_frame_position-1);
- #endif
- STp->eod_frame_ppos = STp->first_frame_position-1;
- }
- return (-EIO);
- }
- if (cnt == mt_count)
- break;
- STp->frame_in_buffer = 0;
- }
- if (mt_op == MTFSF) {
- STp->frame_seq_number++;
- STp->frame_in_buffer = 0;
- STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
- }
- return 0;
- }
- /*
- * Fast linux specific version of OnStream FSF
- */
- static int osst_space_over_filemarks_forward_fast(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt,
- int mt_op, int mt_count)
- {
- int dev = TAPE_NR(STp->devt);
- int cnt = 0,
- next_mark_ppos = -1;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Reached space_over_filemarks_forward_fast %d %dn", dev, mt_op, mt_count);
- #endif
- if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Couldn't get logical blk num in space_filemarks_fwdn", dev);
- #endif
- return (-EIO);
- }
- if (STp->linux_media_version >= 4) {
- /*
- * direct lookup in header filemark list
- */
- cnt = ntohl(STp->buffer->aux->filemark_cnt) - 1;
- if (STp->header_ok &&
- STp->header_cache != NULL &&
- (cnt + mt_count) < OS_FM_TAB_MAX &&
- (cnt + mt_count) < STp->filemark_cnt &&
- ((cnt == -1 && ntohl(STp->buffer->aux->last_mark_ppos) == -1) ||
- (STp->header_cache->dat_fm_tab.fm_tab_ent[cnt] == STp->buffer->aux->last_mark_ppos)))
- next_mark_ppos = ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[cnt + mt_count]);
- #if DEBUG
- if (STp->header_cache == NULL || (cnt + mt_count) >= OS_FM_TAB_MAX)
- printk(OSST_DEB_MSG "osst%d:D: Filemark lookup fail due to %sn", dev,
- STp->header_cache == NULL?"lack of header cache":"count out of range");
- else
- printk(OSST_DEB_MSG "osst%d:D: Filemark lookup: prev mark %d (%s), skip %d to %dn",
- dev, cnt,
- ((cnt == -1 && ntohl(STp->buffer->aux->last_mark_ppos) == -1) ||
- (STp->header_cache->dat_fm_tab.fm_tab_ent[cnt] ==
- STp->buffer->aux->last_mark_ppos))?"match":"error",
- mt_count, next_mark_ppos);
- #endif
- if (next_mark_ppos <= 10 || next_mark_ppos > STp->eod_frame_ppos) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Reverting to slow filemark spacen", dev);
- #endif
- return osst_space_over_filemarks_forward_slow(STp, aSRpnt, mt_op, mt_count);
- } else {
- osst_position_tape_and_confirm(STp, aSRpnt, next_mark_ppos);
- if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Couldn't get logical blk num in space_filemarksn",
- dev);
- #endif
- return (-EIO);
- }
- if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) {
- printk(KERN_WARNING "osst%d:W: Expected to find marker at ppos %d, not foundn",
- dev, next_mark_ppos);
- return (-EIO);
- }
- if (ntohl(STp->buffer->aux->filemark_cnt) != cnt + mt_count) {
- printk(KERN_WARNING "osst%d:W: Expected to find marker %d at ppos %d, not %dn",
- dev, cnt+mt_count, next_mark_ppos,
- ntohl(STp->buffer->aux->filemark_cnt));
- return (-EIO);
- }
- }
- } else {
- /*
- * Find nearest (usually previous) marker, then jump from marker to marker
- */
- while (1) {
- if (STp->buffer->aux->frame_type == OS_FRAME_TYPE_MARKER)
- break;
- if (STp->buffer->aux->frame_type == OS_FRAME_TYPE_EOD) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: space_fwd: EOD reachedn", dev);
- #endif
- return (-EIO);
- }
- if (ntohl(STp->buffer->aux->filemark_cnt) == 0) {
- if (STp->first_mark_ppos == -1) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Reverting to slow filemark spacen", dev);
- #endif
- return osst_space_over_filemarks_forward_slow(STp, aSRpnt, mt_op, mt_count);
- }
- osst_position_tape_and_confirm(STp, aSRpnt, STp->first_mark_ppos);
- if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
- #if DEBUG
- printk(OSST_DEB_MSG
- "osst%d:D: Couldn't get logical blk num in space_filemarks_fwd_fastn",
- dev);
- #endif
- return (-EIO);
- }
- if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) {
- printk(KERN_WARNING "osst%d:W: Expected to find filemark at %dn",
- dev, STp->first_mark_ppos);
- return (-EIO);
- }
- } else {
- if (osst_space_over_filemarks_backward(STp, aSRpnt, MTBSF, 1) < 0)
- return (-EIO);
- mt_count++;
- }
- }
- cnt++;
- while (cnt != mt_count) {
- next_mark_ppos = ntohl(STp->buffer->aux->next_mark_ppos);
- if (!next_mark_ppos || next_mark_ppos > STp->eod_frame_ppos) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Reverting to slow filemark spacen", dev);
- #endif
- return osst_space_over_filemarks_forward_slow(STp, aSRpnt, mt_op, mt_count - cnt);
- }
- #if DEBUG
- else printk(OSST_DEB_MSG "osst%d:D: Positioning to next mark at %dn", dev, next_mark_ppos);
- #endif
- osst_position_tape_and_confirm(STp, aSRpnt, next_mark_ppos);
- cnt++;
- if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Couldn't get logical blk num in space_filemarksn",
- dev);
- #endif
- return (-EIO);
- }
- if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) {
- printk(KERN_WARNING "osst%d:W: Expected to find marker at ppos %d, not foundn",
- dev, next_mark_ppos);
- return (-EIO);
- }
- }
- }
- if (mt_op == MTFSF) {
- STp->frame_seq_number++;
- STp->frame_in_buffer = 0;
- STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
- }
- return 0;
- }
- /*
- * In debug mode, we want to see as many errors as possible
- * to test the error recovery mechanism.
- */
- #if DEBUG
- static void osst_set_retries(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int retries)
- {
- unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request * SRpnt = * aSRpnt;
- int dev = TAPE_NR(STp->devt);
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = MODE_SELECT;
- cmd[1] = 0x10;
- cmd[4] = NUMBER_RETRIES_PAGE_LENGTH + MODE_HEADER_LENGTH;
- (STp->buffer)->b_data[0] = cmd[4] - 1;
- (STp->buffer)->b_data[1] = 0; /* Medium Type - ignoring */
- (STp->buffer)->b_data[2] = 0; /* Reserved */
- (STp->buffer)->b_data[3] = 0; /* Block Descriptor Length */
- (STp->buffer)->b_data[MODE_HEADER_LENGTH + 0] = NUMBER_RETRIES_PAGE | (1 << 7);
- (STp->buffer)->b_data[MODE_HEADER_LENGTH + 1] = 2;
- (STp->buffer)->b_data[MODE_HEADER_LENGTH + 2] = 4;
- (STp->buffer)->b_data[MODE_HEADER_LENGTH + 3] = retries;
- if (debugging)
- printk(OSST_DEB_MSG "osst%d:D: Setting number of retries on OnStream tape to %dn", dev, retries);
- SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_WRITE, STp->timeout, 0, TRUE);
- *aSRpnt = SRpnt;
- if ((STp->buffer)->syscall_result)
- printk (KERN_ERR "osst%d:D: Couldn't set retries to %dn", dev, retries);
- }
- #endif
- static int osst_write_filemark(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt)
- {
- int result;
- int this_mark_ppos = STp->first_frame_position;
- int this_mark_lbn = STp->logical_blk_num;
- #if DEBUG
- int dev = TAPE_NR(STp->devt);
- #endif
- if (STp->raw) return 0;
- STp->write_type = OS_WRITE_NEW_MARK;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Writing Filemark %i at fppos %d (fseq %d, lblk %d)n",
- dev, STp->filemark_cnt, this_mark_ppos, STp->frame_seq_number, this_mark_lbn);
- #endif
- STp->dirty = 1;
- result = osst_flush_write_buffer(STp, aSRpnt);
- result |= osst_flush_drive_buffer(STp, aSRpnt);
- STp->last_mark_ppos = this_mark_ppos;
- STp->last_mark_lbn = this_mark_lbn;
- if (STp->header_cache != NULL && STp->filemark_cnt < OS_FM_TAB_MAX)
- STp->header_cache->dat_fm_tab.fm_tab_ent[STp->filemark_cnt] = htonl(this_mark_ppos);
- if (STp->filemark_cnt++ == 0)
- STp->first_mark_ppos = this_mark_ppos;
- return result;
- }
- static int osst_write_eod(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt)
- {
- int result;
- #if DEBUG
- int dev = TAPE_NR(STp->devt);
- #endif
- if (STp->raw) return 0;
- STp->write_type = OS_WRITE_EOD;
- STp->eod_frame_ppos = STp->first_frame_position;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Writing EOD at fppos %d (fseq %d, lblk %d)n", dev,
- STp->eod_frame_ppos, STp->frame_seq_number, STp->logical_blk_num);
- #endif
- STp->dirty = 1;
- result = osst_flush_write_buffer(STp, aSRpnt);
- result |= osst_flush_drive_buffer(STp, aSRpnt);
- STp->eod_frame_lfa = --(STp->frame_seq_number);
- return result;
- }
- static int osst_write_filler(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int where, int count)
- {
- int dev = TAPE_NR(STp->devt);
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Reached onstream write filler group %dn", dev, where);
- #endif
- osst_wait_ready(STp, aSRpnt, 60 * 5);
- osst_set_frame_position(STp, aSRpnt, where, 0);
- STp->write_type = OS_WRITE_FILLER;
- while (count--) {
- memcpy(STp->buffer->b_data, "Filler", 6);
- STp->buffer->buffer_bytes = 6;
- STp->dirty = 1;
- if (osst_flush_write_buffer(STp, aSRpnt)) {
- printk(KERN_INFO "osst%i:I: Couldn't write filler framen", dev);
- return (-EIO);
- }
- }
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Exiting onstream write filler groupn", dev);
- #endif
- return osst_flush_drive_buffer(STp, aSRpnt);
- }
- static int __osst_write_header(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int where, int count)
- {
- int dev = TAPE_NR(STp->devt);
- int result;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Reached onstream write header group %dn", dev, where);
- #endif
- osst_wait_ready(STp, aSRpnt, 60 * 5);
- osst_set_frame_position(STp, aSRpnt, where, 0);
- STp->write_type = OS_WRITE_HEADER;
- while (count--) {
- osst_copy_to_buffer(STp->buffer, (unsigned char *)STp->header_cache);
- STp->buffer->buffer_bytes = sizeof(os_header_t);
- STp->dirty = 1;
- if (osst_flush_write_buffer(STp, aSRpnt)) {
- printk(KERN_INFO "osst%i:I: Couldn't write header framen", dev);
- return (-EIO);
- }
- }
- result = osst_flush_drive_buffer(STp, aSRpnt);
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Write onstream header group %sn", dev, result?"failed":"done");
- #endif
- return result;
- }
- static int osst_write_header(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int locate_eod)
- {
- os_header_t * header;
- int result;
- int dev = TAPE_NR(STp->devt);
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Writing tape headern", dev);
- #endif
- if (STp->raw) return 0;
- if (STp->header_cache == NULL) {
- if ((STp->header_cache = (os_header_t *)vmalloc(sizeof(os_header_t))) == NULL) {
- printk(KERN_ERR "osst%i:E: Failed to allocate header cachen", dev);
- return (-ENOMEM);
- }
- memset(STp->header_cache, 0, sizeof(os_header_t));
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Allocated and cleared memory for header cachen", dev);
- #endif
- }
- if (STp->header_ok) STp->update_frame_cntr++;
- else STp->update_frame_cntr = 0;
- header = STp->header_cache;
- strcpy(header->ident_str, "ADR_SEQ");
- header->major_rev = 1;
- header->minor_rev = 4;
- header->ext_trk_tb_off = htons(17192);
- header->pt_par_num = 1;
- header->partition[0].partition_num = OS_DATA_PARTITION;
- header->partition[0].par_desc_ver = OS_PARTITION_VERSION;
- header->partition[0].wrt_pass_cntr = htons(STp->wrt_pass_cntr);
- header->partition[0].first_frame_ppos = htonl(STp->first_data_ppos);
- header->partition[0].last_frame_ppos = htonl(STp->capacity);
- header->partition[0].eod_frame_ppos = htonl(STp->eod_frame_ppos);
- header->cfg_col_width = htonl(20);
- header->dat_col_width = htonl(1500);
- header->qfa_col_width = htonl(0);
- header->ext_track_tb.nr_stream_part = 1;
- header->ext_track_tb.et_ent_sz = 32;
- header->ext_track_tb.dat_ext_trk_ey.et_part_num = 0;
- header->ext_track_tb.dat_ext_trk_ey.fmt = 1;
- header->ext_track_tb.dat_ext_trk_ey.fm_tab_off = htons(17736);
- header->ext_track_tb.dat_ext_trk_ey.last_hlb_hi = 0;
- header->ext_track_tb.dat_ext_trk_ey.last_hlb = htonl(STp->eod_frame_lfa);
- header->ext_track_tb.dat_ext_trk_ey.last_pp = htonl(STp->eod_frame_ppos);
- header->dat_fm_tab.fm_part_num = 0;
- header->dat_fm_tab.fm_tab_ent_sz = 4;
- header->dat_fm_tab.fm_tab_ent_cnt = htons(STp->filemark_cnt<OS_FM_TAB_MAX?
- STp->filemark_cnt:OS_FM_TAB_MAX);
- result = __osst_write_header(STp, aSRpnt, 0xbae, 5);
- if (STp->update_frame_cntr == 0)
- osst_write_filler(STp, aSRpnt, 0xbb3, 5);
- result &= __osst_write_header(STp, aSRpnt, 5, 5);
- if (locate_eod) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Locating back to eod frame addr %dn", dev, STp->eod_frame_ppos);
- #endif
- osst_set_frame_position(STp, aSRpnt, STp->eod_frame_ppos, 0);
- }
- if (result)
- printk(KERN_ERR "osst%i:E: Write header failedn", dev);
- else {
- memcpy(STp->application_sig, "LIN4", 4);
- STp->linux_media = 1;
- STp->linux_media_version = 4;
- STp->header_ok = 1;
- }
- return result;
- }
- static int osst_reset_header(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt)
- {
- if (STp->header_cache != NULL)
- memset(STp->header_cache, 0, sizeof(os_header_t));
- STp->logical_blk_num = STp->frame_seq_number = 0;
- STp->frame_in_buffer = 0;
- STp->eod_frame_ppos = STp->first_data_ppos = 0x0000000A;
- STp->filemark_cnt = 0;
- STp->first_mark_ppos = STp->last_mark_ppos = STp->last_mark_lbn = -1;
- return osst_write_header(STp, aSRpnt, 1);
- }
- static int __osst_analyze_headers(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int ppos)
- {
- int dev = TAPE_NR(STp->devt);
- os_header_t * header;
- os_aux_t * aux;
- char id_string[8];
- int linux_media_version,
- update_frame_cntr;
- if (STp->raw)
- return 1;
- if (ppos == 5 || ppos == 0xbae || STp->buffer->syscall_result) {
- if (osst_set_frame_position(STp, aSRpnt, ppos, 0))
- printk(KERN_WARNING "osst%i:W: Couldn't position tapen", dev);
- if (osst_initiate_read (STp, aSRpnt)) {
- printk(KERN_WARNING "osst%i:W: Couldn't initiate readn", dev);
- return 0;
- }
- }
- if (osst_read_frame(STp, aSRpnt, 180)) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Couldn't read header framen", dev);
- #endif
- return 0;
- }
- header = (os_header_t *) STp->buffer->b_data; /* warning: only first segment addressable */
- aux = STp->buffer->aux;
- if (aux->frame_type != OS_FRAME_TYPE_HEADER) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Skipping non-header frame (%d)n", dev, ppos);
- #endif
- return 0;
- }
- if (ntohl(aux->frame_seq_num) != 0 ||
- ntohl(aux->logical_blk_num) != 0 ||
- aux->partition.partition_num != OS_CONFIG_PARTITION ||
- ntohl(aux->partition.first_frame_ppos) != 0 ||
- ntohl(aux->partition.last_frame_ppos) != 0xbb7 ) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Invalid header frame (%d,%d,%d,%d,%d)n", dev,
- ntohl(aux->frame_seq_num), ntohl(aux->logical_blk_num),
- aux->partition.partition_num, ntohl(aux->partition.first_frame_ppos),
- ntohl(aux->partition.last_frame_ppos));
- #endif
- return 0;
- }
- if (strncmp(header->ident_str, "ADR_SEQ", 7) != 0 &&
- strncmp(header->ident_str, "ADR-SEQ", 7) != 0) {
- strncpy(id_string, header->ident_str, 7);
- id_string[7] = 0;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Invalid header identification string %sn", dev, id_string);
- #endif
- return 0;
- }
- update_frame_cntr = ntohl(aux->update_frame_cntr);
- if (update_frame_cntr < STp->update_frame_cntr) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Skipping frame %d with update_frame_counter %d<%dn",
- dev, ppos, update_frame_cntr, STp->update_frame_cntr);
- #endif
- return 0;
- }
- if (header->major_rev != 1 || header->minor_rev != 4 ) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: %s revision %d.%d detected (1.4 supported)n",
- dev, (header->major_rev != 1 || header->minor_rev < 2 ||
- header->minor_rev > 4 )? "Invalid" : "Warning:",
- header->major_rev, header->minor_rev);
- #endif
- if (header->major_rev != 1 || header->minor_rev < 2 || header->minor_rev > 4)
- return 0;
- }
- #if DEBUG
- if (header->pt_par_num != 1)
- printk(KERN_INFO "osst%i:W: %d partitions defined, only one supportedn",
- dev, header->pt_par_num);
- #endif
- memcpy(id_string, aux->application_sig, 4);
- id_string[4] = 0;
- if (memcmp(id_string, "LIN", 3) == 0) {
- STp->linux_media = 1;
- linux_media_version = id_string[3] - '0';
- if (linux_media_version != 4)
- printk(KERN_INFO "osst%i:I: Linux media version %d detected (current 4)n",
- dev, linux_media_version);
- } else {
- printk(KERN_WARNING "osst%i:W: Non Linux media detected (%s)n", dev, id_string);
- return 0;
- }
- if (linux_media_version < STp->linux_media_version) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Skipping frame %d with linux_media_version %dn",
- dev, ppos, linux_media_version);
- #endif
- return 0;
- }
- if (linux_media_version > STp->linux_media_version) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Frame %d sets linux_media_version to %dn",
- dev, ppos, linux_media_version);
- #endif
- memcpy(STp->application_sig, id_string, 5);
- STp->linux_media_version = linux_media_version;
- STp->update_frame_cntr = -1;
- }
- if (update_frame_cntr > STp->update_frame_cntr) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Frame %d sets update_frame_counter to %dn",
- dev, ppos, update_frame_cntr);
- #endif
- if (STp->header_cache == NULL) {
- if ((STp->header_cache = (os_header_t *)vmalloc(sizeof(os_header_t))) == NULL) {
- printk(KERN_ERR "osst%i:E: Failed to allocate header cachen", dev);
- return 0;
- }
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Allocated memory for header cachen", dev);
- #endif
- }
- osst_copy_from_buffer(STp->buffer, (unsigned char *)STp->header_cache);
- header = STp->header_cache; /* further accesses from cached (full) copy */
- STp->wrt_pass_cntr = ntohs(header->partition[0].wrt_pass_cntr);
- STp->first_data_ppos = ntohl(header->partition[0].first_frame_ppos);
- STp->eod_frame_ppos = ntohl(header->partition[0].eod_frame_ppos);
- STp->eod_frame_lfa = ntohl(header->ext_track_tb.dat_ext_trk_ey.last_hlb);
- STp->filemark_cnt = ntohl(aux->filemark_cnt);
- STp->first_mark_ppos = ntohl(aux->next_mark_ppos);
- STp->last_mark_ppos = ntohl(aux->last_mark_ppos);
- STp->last_mark_lbn = ntohl(aux->last_mark_lbn);
- STp->update_frame_cntr = update_frame_cntr;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Detected write pass %d, update frame counter %d, filemark counter %dn",
- dev, STp->wrt_pass_cntr, STp->update_frame_cntr, STp->filemark_cnt);
- printk(OSST_DEB_MSG "osst%d:D: first data frame on tape = %d, last = %d, eod frame = %dn", dev,
- STp->first_data_ppos,
- ntohl(header->partition[0].last_frame_ppos),
- ntohl(header->partition[0].eod_frame_ppos));
- printk(OSST_DEB_MSG "osst%d:D: first mark on tape = %d, last = %d, eod frame = %dn",
- dev, STp->first_mark_ppos, STp->last_mark_ppos, STp->eod_frame_ppos);
- #endif
- if (header->minor_rev < 4 && STp->linux_media_version == 4) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%i:D: Moving filemark list to ADR 1.4 locationn", dev);
- #endif
- memcpy((void *)header->dat_fm_tab.fm_tab_ent,
- (void *)header->old_filemark_list, sizeof(header->dat_fm_tab.fm_tab_ent));
- memset((void *)header->old_filemark_list, 0, sizeof(header->old_filemark_list));
- }
- if (header->minor_rev == 4 &&
- (header->ext_trk_tb_off != htons(17192) ||
- header->partition[0].partition_num != OS_DATA_PARTITION ||
- header->partition[0].par_desc_ver != OS_PARTITION_VERSION ||
- header->partition[0].last_frame_ppos != htonl(STp->capacity) ||
- header->cfg_col_width != htonl(20) ||
- header->dat_col_width != htonl(1500) ||
- header->qfa_col_width != htonl(0) ||
- header->ext_track_tb.nr_stream_part != 1 ||
- header->ext_track_tb.et_ent_sz != 32 ||
- header->ext_track_tb.dat_ext_trk_ey.et_part_num != OS_DATA_PARTITION ||
- header->ext_track_tb.dat_ext_trk_ey.fmt != 1 ||
- header->ext_track_tb.dat_ext_trk_ey.fm_tab_off != htons(17736) ||
- header->ext_track_tb.dat_ext_trk_ey.last_hlb_hi != 0 ||
- header->ext_track_tb.dat_ext_trk_ey.last_pp != htonl(STp->eod_frame_ppos) ||
- header->dat_fm_tab.fm_part_num != OS_DATA_PARTITION ||
- header->dat_fm_tab.fm_tab_ent_sz != 4 ||
- header->dat_fm_tab.fm_tab_ent_cnt !=
- htons(STp->filemark_cnt<OS_FM_TAB_MAX?STp->filemark_cnt:OS_FM_TAB_MAX)))
- printk(KERN_WARNING "osst%i:W: Failed consistency check ADR 1.4 formatn", dev);
- }
- return 1;
- }
- static int osst_analyze_headers(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt)
- {
- int position, ppos;
- int first, last;
- int valid = 0;
- int dev = TAPE_NR(STp->devt);
- position = osst_get_frame_position(STp, aSRpnt);
- if (STp->raw) {
- STp->header_ok = STp->linux_media = 1;
- STp->linux_media_version = 0;
- return 1;
- }
- STp->header_ok = STp->linux_media = STp->linux_media_version = 0;
- STp->wrt_pass_cntr = STp->update_frame_cntr = -1;
- STp->eod_frame_ppos = STp->first_data_ppos = -1;
- STp->first_mark_ppos = STp->last_mark_ppos = STp->last_mark_lbn = -1;
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Reading headern", dev);
- #endif
- /* optimization for speed - if we are positioned at ppos 10, read second group first */
- /* TODO try the ADR 1.1 locations for the second group if we have no valid one yet... */
- first = position==10?0xbae: 5;
- last = position==10?0xbb3:10;
- for (ppos = first; ppos < last; ppos++)
- if (__osst_analyze_headers(STp, aSRpnt, ppos))
- valid = 1;
- first = position==10? 5:0xbae;
- last = position==10?10:0xbb3;
- for (ppos = first; ppos < last; ppos++)
- if (__osst_analyze_headers(STp, aSRpnt, ppos))
- valid = 1;
- if (!valid) {
- printk(KERN_ERR "osst%i:E: Failed to find valid ADRL header, new media?n", dev);
- STp->eod_frame_ppos = STp->first_data_ppos = 0;
- osst_set_frame_position(STp, aSRpnt, 10, 0);
- return 0;
- }
- if (position <= STp->first_data_ppos) {
- position = STp->first_data_ppos;
- STp->ps[0].drv_file = STp->ps[0].drv_block = STp->frame_seq_number = STp->logical_blk_num = 0;
- }
- osst_set_frame_position(STp, aSRpnt, position, 0);
- STp->header_ok = 1;
- return 1;
- }
- static int osst_verify_position(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt)
- {
- int frame_position = STp->first_frame_position;
- int frame_seq_numbr = STp->frame_seq_number;
- int logical_blk_num = STp->logical_blk_num;
- int halfway_frame = STp->frame_in_buffer;
- int read_pointer = STp->buffer->read_pointer;
- int prev_mark_ppos = -1;
- int actual_mark_ppos, i, n;
- #if DEBUG
- int dev = TAPE_NR(STp->devt);
- printk(OSST_DEB_MSG "osst%d:D: Verify that the tape is really the one we think before writingn", dev);
- #endif
- osst_set_frame_position(STp, aSRpnt, frame_position - 1, 0);
- if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Couldn't get logical blk num in verify_positionn", dev);
- #endif
- return (-EIO);
- }
- if (STp->linux_media_version >= 4) {
- for (i=0; i<STp->filemark_cnt; i++)
- if ((n=ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[i])) < frame_position)
- prev_mark_ppos = n;
- } else
- prev_mark_ppos = frame_position - 1; /* usually - we don't really know */
- actual_mark_ppos = STp->buffer->aux->frame_type == OS_FRAME_TYPE_MARKER ?
- frame_position - 1 : ntohl(STp->buffer->aux->last_mark_ppos);
- if (frame_position != STp->first_frame_position ||
- frame_seq_numbr != STp->frame_seq_number + (halfway_frame?0:1) ||
- prev_mark_ppos != actual_mark_ppos ) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Block mismatch: fppos %d-%d, fseq %d-%d, mark %d-%dn", dev,
- STp->first_frame_position, frame_position,
- STp->frame_seq_number + (halfway_frame?0:1),
- frame_seq_numbr, actual_mark_ppos, prev_mark_ppos);
- #endif
- return (-EIO);
- }
- if (halfway_frame) {
- /* prepare buffer for append and rewrite on top of original */
- osst_set_frame_position(STp, aSRpnt, frame_position - 1, 0);
- STp->buffer->buffer_bytes = read_pointer;
- STp->ps[STp->partition].rw = ST_WRITING;
- STp->dirty = 1;
- }
- STp->frame_in_buffer = halfway_frame;
- STp->frame_seq_number = frame_seq_numbr;
- STp->logical_blk_num = logical_blk_num;
- return 0;
- }
- /* Acc. to OnStream, the vers. numbering is the following:
- * X.XX for released versions (X=digit),
- * XXXY for unreleased versions (Y=letter)
- * Ordering 1.05 < 106A < 106B < ... < 106a < ... < 1.06
- * This fn makes monoton numbers out of this scheme ...
- */
- static unsigned int osst_parse_firmware_rev (const char * str)
- {
- if (str[1] == '.') {
- return (str[0]-'0')*10000
- +(str[2]-'0')*1000
- +(str[3]-'0')*100;
- } else {
- return (str[0]-'0')*10000
- +(str[1]-'0')*1000
- +(str[2]-'0')*100 - 100
- +(str[3]-'@');
- }
- }
- /*
- * Configure the OnStream SCII tape drive for default operation
- */
- static int osst_configure_onstream(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt)
- {
- unsigned char cmd[MAX_COMMAND_SIZE];
- int dev = TAPE_NR(STp->devt);
- Scsi_Request * SRpnt = * aSRpnt;
- osst_mode_parameter_header_t * header;
- osst_block_size_page_t * bs;
- osst_capabilities_page_t * cp;
- osst_tape_paramtr_page_t * prm;
- int drive_buffer_size;
- if (STp->ready != ST_READY) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Not Readyn", dev);
- #endif
- return (-EIO);
- }
-
- if (STp->os_fw_rev < 10600) {
- printk(KERN_INFO "osst%i:I: Old OnStream firmware revision detected (%s),n", dev, STp->device->rev);
- printk(KERN_INFO "osst%d:I: an upgrade to version 1.06 or above is recommendedn", dev);
- }
- /*
- * Configure 32.5KB (data+aux) frame size.
- * Get the current frame size from the block size mode page
- */
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = MODE_SENSE;
- cmd[1] = 8;
- cmd[2] = BLOCK_SIZE_PAGE;
- cmd[4] = BLOCK_SIZE_PAGE_LENGTH + MODE_HEADER_LENGTH;
- SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_READ, STp->timeout, 0, TRUE);
- if (SRpnt == NULL) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst :D: Busyn");
- #endif
- return (-EBUSY);
- }
- *aSRpnt = SRpnt;
- if ((STp->buffer)->syscall_result != 0) {
- printk (KERN_ERR "osst%i:E: Can't get tape block size mode pagen", dev);
- return (-EIO);
- }
- header = (osst_mode_parameter_header_t *) (STp->buffer)->b_data;
- bs = (osst_block_size_page_t *) ((STp->buffer)->b_data + sizeof(osst_mode_parameter_header_t) + header->bdl);
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: 32KB play back: %sn", dev, bs->play32 ? "Yes" : "No");
- printk(OSST_DEB_MSG "osst%d:D: 32.5KB play back: %sn", dev, bs->play32_5 ? "Yes" : "No");
- printk(OSST_DEB_MSG "osst%d:D: 32KB record: %sn", dev, bs->record32 ? "Yes" : "No");
- printk(OSST_DEB_MSG "osst%d:D: 32.5KB record: %sn", dev, bs->record32_5 ? "Yes" : "No");
- #endif
- /*
- * Configure default auto columns mode, 32.5KB transfer mode
- */
- bs->one = 1;
- bs->play32 = 0;
- bs->play32_5 = 1;
- bs->record32 = 0;
- bs->record32_5 = 1;
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = MODE_SELECT;
- cmd[1] = 0x10;
- cmd[4] = BLOCK_SIZE_PAGE_LENGTH + MODE_HEADER_LENGTH;
- SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_WRITE, STp->timeout, 0, TRUE);
- *aSRpnt = SRpnt;
- if ((STp->buffer)->syscall_result != 0) {
- printk (KERN_ERR "osst%i:E: Couldn't set tape block size mode pagen", dev);
- return (-EIO);
- }
- #if DEBUG
- printk(KERN_INFO "osst%d:D: Drive Block Size changed to 32.5Kn", dev);
- /*
- * In debug mode, we want to see as many errors as possible
- * to test the error recovery mechanism.
- */
- osst_set_retries(STp, aSRpnt, 0);
- SRpnt = * aSRpnt;
- #endif
- /*
- * Set vendor name to 'LIN4' for "Linux support version 4".
- */
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = MODE_SELECT;
- cmd[1] = 0x10;
- cmd[4] = VENDOR_IDENT_PAGE_LENGTH + MODE_HEADER_LENGTH;
- header->mode_data_length = VENDOR_IDENT_PAGE_LENGTH + MODE_HEADER_LENGTH - 1;
- header->medium_type = 0; /* Medium Type - ignoring */
- header->dsp = 0; /* Reserved */
- header->bdl = 0; /* Block Descriptor Length */
-
- (STp->buffer)->b_data[MODE_HEADER_LENGTH + 0] = VENDOR_IDENT_PAGE | (1 << 7);
- (STp->buffer)->b_data[MODE_HEADER_LENGTH + 1] = 6;
- (STp->buffer)->b_data[MODE_HEADER_LENGTH + 2] = 'L';
- (STp->buffer)->b_data[MODE_HEADER_LENGTH + 3] = 'I';
- (STp->buffer)->b_data[MODE_HEADER_LENGTH + 4] = 'N';
- (STp->buffer)->b_data[MODE_HEADER_LENGTH + 5] = '4';
- (STp->buffer)->b_data[MODE_HEADER_LENGTH + 6] = 0;
- (STp->buffer)->b_data[MODE_HEADER_LENGTH + 7] = 0;
- SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_WRITE, STp->timeout, 0, TRUE);
- *aSRpnt = SRpnt;
- if ((STp->buffer)->syscall_result != 0) {
- printk (KERN_ERR "osst%i:E: Couldn't set vendor name to %sn", dev,
- (char *) ((STp->buffer)->b_data + MODE_HEADER_LENGTH + 2));
- return (-EIO);
- }
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = MODE_SENSE;
- cmd[1] = 8;
- cmd[2] = CAPABILITIES_PAGE;
- cmd[4] = CAPABILITIES_PAGE_LENGTH + MODE_HEADER_LENGTH;
- SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_READ, STp->timeout, 0, TRUE);
- *aSRpnt = SRpnt;
- if ((STp->buffer)->syscall_result != 0) {
- printk (KERN_ERR "osst%i:E: Can't get capabilities pagen", dev);
- return (-EIO);
- }
- header = (osst_mode_parameter_header_t *) (STp->buffer)->b_data;
- cp = (osst_capabilities_page_t *) ((STp->buffer)->b_data +
- sizeof(osst_mode_parameter_header_t) + header->bdl);
- drive_buffer_size = ntohs(cp->buffer_size) / 2;
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = MODE_SENSE;
- cmd[1] = 8;
- cmd[2] = TAPE_PARAMTR_PAGE;
- cmd[4] = TAPE_PARAMTR_PAGE_LENGTH + MODE_HEADER_LENGTH;
- SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_READ, STp->timeout, 0, TRUE);
- *aSRpnt = SRpnt;
- if ((STp->buffer)->syscall_result != 0) {
- printk (KERN_ERR "osst%i:E: Can't get tape parameter pagen", dev);
- return (-EIO);
- }
- header = (osst_mode_parameter_header_t *) (STp->buffer)->b_data;
- prm = (osst_tape_paramtr_page_t *) ((STp->buffer)->b_data +
- sizeof(osst_mode_parameter_header_t) + header->bdl);
- STp->density = prm->density;
- STp->capacity = ntohs(prm->segtrk) * ntohs(prm->trks);
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: Density %d, tape length: %dMB, drive buffer size: %dKBn",
- dev, STp->density, STp->capacity / 32, drive_buffer_size);
- #endif
- return 0;
-
- }
- /* Step over EOF if it has been inadvertently crossed (ioctl not used because
- it messes up the block number). */
- static int cross_eof(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt, int forward)
- {
- int result;
- int dev = TAPE_NR(STp->devt);
- #if DEBUG
- if (debugging)
- printk(OSST_DEB_MSG "osst%d:D: Stepping over filemark %s.n",
- dev, forward ? "forward" : "backward");
- #endif
- if (forward) {
- /* assumes that the filemark is already read by the drive, so this is low cost */
- result = osst_space_over_filemarks_forward_slow(STp, aSRpnt, MTFSF, 1);
- }
- else
- /* assumes this is only called if we just read the filemark! */
- result = osst_seek_logical_blk(STp, aSRpnt, STp->logical_blk_num - 1);
- if (result < 0)
- printk(KERN_WARNING "osst%d:W: Stepping over filemark %s failed.n",
- dev, forward ? "forward" : "backward");
- return result;
- }
- /* Get the tape position. */
- static int osst_get_frame_position(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt)
- {
- unsigned char scmd[MAX_COMMAND_SIZE];
- Scsi_Request * SRpnt;
- int result = 0;
- /* KG: We want to be able to use it for checking Write Buffer availability
- * and thus don't want to risk to overwrite anything. Exchange buffers ... */
- char mybuf[24];
- char * olddata = STp->buffer->b_data;
- int oldsize = STp->buffer->buffer_size;
- int dev = TAPE_NR(STp->devt);
- if (STp->ready != ST_READY) return (-EIO);
- memset (scmd, 0, MAX_COMMAND_SIZE);
- scmd[0] = READ_POSITION;
- STp->buffer->b_data = mybuf; STp->buffer->buffer_size = 24;
- SRpnt = osst_do_scsi(*aSRpnt, STp, scmd, 20, SCSI_DATA_READ,
- STp->timeout, MAX_READY_RETRIES, TRUE);
- if (!SRpnt) {
- STp->buffer->b_data = olddata; STp->buffer->buffer_size = oldsize;
- return (-EBUSY);
- }
- *aSRpnt = SRpnt;
- if (STp->buffer->syscall_result)
- result = ((SRpnt->sr_sense_buffer[2] & 0x0f) == 3) ? -EIO : -EINVAL;
- if (result == -EINVAL)
- printk(KERN_ERR "osst%d:E: Can't read tape position.n", dev);
- else {
- if (result == -EIO) { /* re-read position */
- unsigned char mysense[16];
- memcpy (mysense, SRpnt->sr_sense_buffer, 16);
- memset (scmd, 0, MAX_COMMAND_SIZE);
- scmd[0] = READ_POSITION;
- STp->buffer->b_data = mybuf; STp->buffer->buffer_size = 24;
- SRpnt = osst_do_scsi(SRpnt, STp, scmd, 20, SCSI_DATA_READ,
- STp->timeout, MAX_READY_RETRIES, TRUE);
- if (!STp->buffer->syscall_result)
- memcpy (SRpnt->sr_sense_buffer, mysense, 16);
- }
- STp->first_frame_position = ((STp->buffer)->b_data[4] << 24)
- + ((STp->buffer)->b_data[5] << 16)
- + ((STp->buffer)->b_data[6] << 8)
- + (STp->buffer)->b_data[7];
- STp->last_frame_position = ((STp->buffer)->b_data[ 8] << 24)
- + ((STp->buffer)->b_data[ 9] << 16)
- + ((STp->buffer)->b_data[10] << 8)
- + (STp->buffer)->b_data[11];
- STp->cur_frames = (STp->buffer)->b_data[15];
- #if DEBUG
- if (debugging) {
- printk(OSST_DEB_MSG "osst%d:D: Drive Positions: host %d, tape %d%s, buffer %dn", dev,
- STp->first_frame_position, STp->last_frame_position,
- ((STp->buffer)->b_data[0]&0x80)?" (BOP)":
- ((STp->buffer)->b_data[0]&0x40)?" (EOP)":"",
- STp->cur_frames);
- }
- #endif
- if (STp->cur_frames == 0 && STp->first_frame_position != STp->last_frame_position) {
- #if DEBUG
- printk(KERN_WARNING "osst%d:D: Correcting read position %d, %d, %dn", dev,
- STp->first_frame_position, STp->last_frame_position, STp->cur_frames);
- #endif
- STp->first_frame_position = STp->last_frame_position;
- }
- }
- STp->buffer->b_data = olddata; STp->buffer->buffer_size = oldsize;
- return (result == 0 ? STp->first_frame_position : result);
- }
- /* Set the tape block */
- static int osst_set_frame_position(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt, int ppos, int skip)
- {
- unsigned char scmd[MAX_COMMAND_SIZE];
- Scsi_Request * SRpnt;
- ST_partstat * STps;
- int result = 0;
- int pp = (ppos == 3000 && !skip)? 0 : ppos;
- int dev = TAPE_NR(STp->devt);
- if (STp->ready != ST_READY) return (-EIO);
- STps = &(STp->ps[STp->partition]);
- if (ppos < 0 || ppos > STp->capacity) {
- printk(KERN_WARNING "osst%d:W: Reposition request %d out of rangen", dev, ppos);
- pp = ppos = ppos < 0 ? 0 : (STp->capacity - 1);
- result = (-EINVAL);
- }
- do {
- #if DEBUG
- if (debugging)
- printk(OSST_DEB_MSG "osst%d:D: Setting ppos to %d.n", dev, pp);
- #endif
- memset (scmd, 0, MAX_COMMAND_SIZE);
- scmd[0] = SEEK_10;
- scmd[1] = 1;
- scmd[3] = (pp >> 24);
- scmd[4] = (pp >> 16);
- scmd[5] = (pp >> 8);
- scmd[6] = pp;
- if (skip)
- scmd[9] = 0x80;
- SRpnt = osst_do_scsi(*aSRpnt, STp, scmd, 0, SCSI_DATA_NONE, STp->long_timeout,
- MAX_READY_RETRIES, TRUE);
- if (!SRpnt)
- return (-EBUSY);
- *aSRpnt = SRpnt;
- if ((STp->buffer)->syscall_result != 0) {
- #if DEBUG
- printk(OSST_DEB_MSG "osst%d:D: SEEK command from %d to %d failed.n",
- dev, STp->first_frame_position, pp);
- #endif
- result = (-EIO);
- }
- if (pp != ppos)
- osst_wait_ready(STp, aSRpnt, 5 * 60);
- } while ((pp != ppos) && (pp = ppos));
- STp->first_frame_position = STp->last_frame_position = ppos;
- STps->eof = ST_NOEOF;
- STps->at_sm = 0;
- STps->rw = ST_IDLE;
- STp->frame_in_buffer = 0;
- return result;
- }
- /* 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(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt)
- {
- int offset, transfer, blks = 0;
- int result = 0;
- unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request * SRpnt = *aSRpnt;
- ST_partstat * STps;
- int dev = TAPE_NR(STp->devt);
- if ((STp->buffer)->writing) {
- if (SRpnt == (STp->buffer)->last_SRpnt)
- #if DEBUG
- { printk(OSST_DEB_MSG
- "osst%d:D: aSRpnt points to Scsi_Request that write_behind_check will release -- clearedn", dev);
- #endif
- *aSRpnt = SRpnt = NULL;
- #if DEBUG
- } else if (SRpnt)
- printk(OSST_DEB_MSG
- "osst%d:D: aSRpnt does not point to Scsi_Request that write_behind_check will release -- strangen", dev);
- #endif
- osst_write_behind_check(STp);
- if ((STp->buffer)->syscall_result) {
- #if DEBUG
- if (debugging)
- printk(OSST_DEB_MSG "osst%d:D: Async write error (flush) %x.n",
- dev, (STp->buffer)->midlevel_result);
- #endif
- if ((STp->buffer)->midlevel_result == INT_MAX)
- return (-ENOSPC);
- return (-EIO);
- }
- }
- result = 0;
- if (STp->dirty == 1) {
- STp->write_count++;
- STps = &(STp->ps[STp->partition]);
- STps->rw = ST_WRITING;
- offset = STp->buffer->buffer_bytes;
- blks = (offset + STp->block_size - 1) / STp->block_size;
- transfer = OS_FRAME_SIZE;
-
- if (offset < OS_DATA_SIZE)
- osst_zero_buffer_tail(STp->buffer);
- /* TODO: Error handling! */
- if (STp->poll)
- result = osst_wait_frame (STp, aSRpnt, STp->first_frame_position, -50, 120);
- memset(cmd, 0, MAX_COMMAND_SIZE);
- cmd[0] = WRITE_6;
- cmd[1] = 1;
- cmd[4] = 1;
- switch (STp->write_type) {
- case OS_WRITE_DATA:
- #if DEBUG
- if (debugging)
- printk(OSST_DEB_MSG "osst%d:D: Writing %d blocks to frame %d, lblks %d-%dn",
- dev, blks, STp->frame_seq_number,
- STp->logical_blk_num - blks, STp->logical_blk_num - 1);
- #endif
- osst_init_aux(STp, OS_FRAME_TYPE_DATA, STp->frame_seq_number++,
- STp->logical_blk_num - blks, STp->block_size, blks);