Lines Matching refs:STp
176 static int osst_int_ioctl(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt, unsigned int cmd_in,unsigned l…
178 static int osst_set_frame_position(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt, int frame, int skip);
180 static int osst_get_frame_position(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt);
182 static int osst_flush_write_buffer(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt);
184 static int osst_write_error_recovery(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int pending);
190 static int osst_chk_result(OS_Scsi_Tape * STp, Scsi_Request * SRpnt) in osst_chk_result() argument
192 int dev = TAPE_NR(STp->devt); in osst_chk_result()
253 STp->recover_count++; in osst_chk_result()
254 STp->recover_erreg++; in osst_chk_result()
278 OS_Scsi_Tape * STp; in osst_sleep_done() local
280 if (os_scsi_tapes && (STp = os_scsi_tapes[dev])) { in osst_sleep_done()
281 if ((STp->buffer)->writing && in osst_sleep_done()
286 (STp->buffer)->midlevel_result = SCpnt->result; /* Error */ in osst_sleep_done()
288 (STp->buffer)->midlevel_result = INT_MAX; /* OK */ in osst_sleep_done()
291 (STp->buffer)->midlevel_result = SCpnt->result; in osst_sleep_done()
293 (STp->buffer)->last_SRpnt = SCpnt->sc_request; in osst_sleep_done()
296 STp->write_pending = 0; in osst_sleep_done()
310 static Scsi_Request * osst_do_scsi(Scsi_Request *SRpnt, OS_Scsi_Tape *STp, in osst_do_scsi() argument
319 if ((SRpnt = scsi_allocate_request(STp->device)) == NULL) { in osst_do_scsi()
320 printk(KERN_ERR "osst%d:E: Can't get SCSI request.\n", TAPE_NR(STp->devt)); in osst_do_scsi()
322 (STp->buffer)->syscall_result = (-EINTR); in osst_do_scsi()
324 (STp->buffer)->syscall_result = (-EBUSY); in osst_do_scsi()
331 init_completion(&STp->wait); in osst_do_scsi()
332 SRpnt->sr_use_sg = (bytes > (STp->buffer)->sg[0].length) ? in osst_do_scsi()
333 (STp->buffer)->use_sg : 0; in osst_do_scsi()
335 bp = (char *)&(STp->buffer->sg[0]); in osst_do_scsi()
336 if (STp->buffer->sg_segs < SRpnt->sr_use_sg) in osst_do_scsi()
337 SRpnt->sr_use_sg = STp->buffer->sg_segs; in osst_do_scsi()
340 bp = (STp->buffer)->b_data; in osst_do_scsi()
343 SRpnt->sr_request.waiting = &(STp->wait); in osst_do_scsi()
345 SRpnt->sr_request.rq_dev = STp->devt; in osst_do_scsi()
352 STp->buffer->syscall_result = osst_chk_result(STp, SRpnt); in osst_do_scsi()
354 if (STp->buffer->syscall_result == 0 && in osst_do_scsi()
358 (STp->first_frame_position == 240 in osst_do_scsi()
361 printk(OSST_DEB_MSG "osst%d:D: Injecting read error\n", TAPE_NR(STp->devt)); in osst_do_scsi()
362 STp->buffer->last_result_fatal = 1; in osst_do_scsi()
371 static void osst_write_behind_check(OS_Scsi_Tape *STp) in osst_write_behind_check() argument
375 STbuffer = STp->buffer; in osst_write_behind_check()
378 if (STp->write_pending) in osst_write_behind_check()
379 STp->nbr_waits++; in osst_write_behind_check()
381 STp->nbr_finished++; in osst_write_behind_check()
383 wait_for_completion(&(STp->wait)); in osst_write_behind_check()
384 (STp->buffer)->last_SRpnt->sr_request.waiting = NULL; in osst_write_behind_check()
386 STp->buffer->syscall_result = osst_chk_result(STp, STp->buffer->last_SRpnt); in osst_write_behind_check()
388 if ((STp->buffer)->syscall_result) in osst_write_behind_check()
389 (STp->buffer)->syscall_result = in osst_write_behind_check()
390 osst_write_error_recovery(STp, &((STp->buffer)->last_SRpnt), 1); in osst_write_behind_check()
392 STp->first_frame_position++; in osst_write_behind_check()
394 scsi_release_request((STp->buffer)->last_SRpnt); in osst_write_behind_check()
411 static void osst_init_aux(OS_Scsi_Tape * STp, int frame_type, int frame_seq_number, in osst_init_aux() argument
414 os_aux_t *aux = STp->buffer->aux; in osst_init_aux()
418 if (STp->raw) return; in osst_init_aux()
428 aux->update_frame_cntr = htonl(STp->update_frame_cntr); in osst_init_aux()
438 aux->next_mark_ppos = htonl(STp->first_mark_ppos); in osst_init_aux()
455 par->wrt_pass_cntr = htons(STp->wrt_pass_cntr); in osst_init_aux()
456 par->first_frame_ppos = htonl(STp->first_data_ppos); in osst_init_aux()
457 par->last_frame_ppos = htonl(STp->capacity); in osst_init_aux()
464 aux->filemark_cnt = ntohl(STp->filemark_cnt); in osst_init_aux()
466 aux->last_mark_ppos = ntohl(STp->last_mark_ppos); in osst_init_aux()
467 aux->last_mark_lbn = ntohl(STp->last_mark_lbn); in osst_init_aux()
473 static int osst_verify_frame(OS_Scsi_Tape * STp, int frame_seq_number, int quiet) in osst_verify_frame() argument
475 os_aux_t * aux = STp->buffer->aux; in osst_verify_frame()
477 ST_partstat * STps = &(STp->ps[STp->partition]); in osst_verify_frame()
478 int dev = TAPE_NR(STp->devt); in osst_verify_frame()
481 if (STp->raw) { in osst_verify_frame()
482 if (STp->buffer->syscall_result) { in osst_verify_frame()
483 for (i=0; i < STp->buffer->sg_segs; i++) in osst_verify_frame()
484 memset(STp->buffer->sg[i].address, 0, STp->buffer->sg[i].length); in osst_verify_frame()
485 strcpy(STp->buffer->b_data, "READ ERROR ON FRAME"); in osst_verify_frame()
487 STp->buffer->buffer_bytes = OS_FRAME_SIZE; in osst_verify_frame()
490 if (STp->buffer->syscall_result) { in osst_verify_frame()
502 if (memcmp(aux->application_sig, STp->application_sig, 4) != 0 && in osst_verify_frame()
503 (memcmp(aux->application_sig, "LIN3", 4) != 0 || STp->linux_media_version != 4)) { in osst_verify_frame()
510 if (!STp->linux_media || STp->linux_media_version != 2) { in osst_verify_frame()
524 if (ntohs(par->wrt_pass_cntr) != STp->wrt_pass_cntr) { in osst_verify_frame()
527 dev, ntohs(par->wrt_pass_cntr), STp->wrt_pass_cntr); in osst_verify_frame()
541 STp->first_frame_position < STp->eod_frame_ppos) { in osst_verify_frame()
543 STp->first_frame_position); in osst_verify_frame()
558 if (STp->header_cache != NULL && i < OS_FM_TAB_MAX && (i > STp->filemark_cnt || in osst_verify_frame()
559 STp->first_frame_position - 1 != ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[i]))) { in osst_verify_frame()
562 STp->header_cache->dat_fm_tab.fm_tab_ent[i] == 0?"Learned":"Corrected", in osst_verify_frame()
563 i, STp->first_frame_position - 1); in osst_verify_frame()
565 STp->header_cache->dat_fm_tab.fm_tab_ent[i] = htonl(STp->first_frame_position - 1); in osst_verify_frame()
566 if (i >= STp->filemark_cnt) in osst_verify_frame()
567 STp->filemark_cnt = i+1; in osst_verify_frame()
572 STp->frame_in_buffer = 1; in osst_verify_frame()
577 STp->buffer->buffer_bytes = blk_cnt * blk_sz; in osst_verify_frame()
578 STp->buffer->read_pointer = 0; in osst_verify_frame()
579 STp->frame_in_buffer = 1; in osst_verify_frame()
582 if (STp->block_size != blk_sz && blk_sz > 0) { in osst_verify_frame()
586 STp->block_size<1024?STp->block_size:STp->block_size/1024, in osst_verify_frame()
587 STp->block_size<1024?'b':'k'); in osst_verify_frame()
588 STp->block_size = blk_sz; in osst_verify_frame()
589 STp->buffer->buffer_blocks = OS_DATA_SIZE / blk_sz; in osst_verify_frame()
593 STp->frame_seq_number = ntohl(aux->frame_seq_num); in osst_verify_frame()
594 STp->logical_blk_num = ntohl(aux->logical_blk_num); in osst_verify_frame()
598 if (STp->read_error_frame == 0) in osst_verify_frame()
599 STp->read_error_frame = STp->first_frame_position - 1; in osst_verify_frame()
606 static int osst_wait_ready(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, unsigned timeout, int initia… in osst_wait_ready() argument
613 int dev = TAPE_NR(STp->devt); in osst_wait_ready()
626 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_READY_RETRIES, TRUE); in osst_wait_ready()
630 while ( STp->buffer->syscall_result && time_before(jiffies, startwait + timeout*HZ) && in osst_wait_ready()
648 … SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_READY_RETRIES, TRUE); in osst_wait_ready()
654 if ( STp->buffer->syscall_result && in osst_wait_ready()
655 osst_write_error_recovery(STp, aSRpnt, 0) ) { in osst_wait_ready()
659 STp->buffer->syscall_result, SRpnt->sr_sense_buffer[0], SRpnt->sr_sense_buffer[2], in osst_wait_ready()
673 static int osst_wait_for_medium(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, unsigned timeout) in osst_wait_for_medium() argument
680 int dev = TAPE_NR(STp->devt); in osst_wait_for_medium()
688 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_READY_RETRIES, TRUE); in osst_wait_for_medium()
692 while ( STp->buffer->syscall_result && time_before(jiffies, startwait + timeout*HZ) && in osst_wait_for_medium()
708 … SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_READY_RETRIES, TRUE); in osst_wait_for_medium()
714 if ( STp->buffer->syscall_result && SRpnt->sr_sense_buffer[2] != 2 && in osst_wait_for_medium()
719 STp->buffer->syscall_result, SRpnt->sr_sense_buffer[0], SRpnt->sr_sense_buffer[2], in osst_wait_for_medium()
730 static int osst_position_tape_and_confirm(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int frame) in osst_position_tape_and_confirm() argument
734 osst_wait_ready(STp, aSRpnt, 15 * 60, 0); /* TODO - can this catch a write error? */ in osst_position_tape_and_confirm()
735 retval = osst_set_frame_position(STp, aSRpnt, frame, 0); in osst_position_tape_and_confirm()
737 osst_wait_ready(STp, aSRpnt, 15 * 60, OSST_WAIT_POSITION_COMPLETE); in osst_position_tape_and_confirm()
738 return (osst_get_frame_position(STp, aSRpnt)); in osst_position_tape_and_confirm()
744 static int osst_flush_drive_buffer(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt) in osst_flush_drive_buffer() argument
752 int dev = TAPE_NR(STp->devt); in osst_flush_drive_buffer()
761 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_WRITE_RETRIES, TRUE); in osst_flush_drive_buffer()
764 if (STp->buffer->syscall_result) { in osst_flush_drive_buffer()
770 result = osst_write_error_recovery(STp, aSRpnt, 0); in osst_flush_drive_buffer()
772 result |= osst_wait_ready(STp, aSRpnt, 5 * 60, delay); in osst_flush_drive_buffer()
773 STp->ps[STp->partition].rw = OS_WRITING_COMPLETE; in osst_flush_drive_buffer()
779 static int osst_wait_frame(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int curr, int minlast, int t… in osst_wait_frame() argument
782 int dev = TAPE_NR(STp->devt); in osst_wait_frame()
786 if (minlast >= 0 && STp->ps[STp->partition].rw != ST_READING) in osst_wait_frame()
792 result = osst_get_frame_position (STp, aSRpnt); in osst_wait_frame()
794 if ((result = osst_write_error_recovery(STp, aSRpnt, 0)) == 0) in osst_wait_frame()
797 if (STp->first_frame_position == curr && in osst_wait_frame()
799 (signed)STp->last_frame_position > (signed)curr + minlast) || in osst_wait_frame()
800 (minlast >= 0 && STp->cur_frames > minlast) in osst_wait_frame()
807 dev, curr, curr+minlast, STp->first_frame_position, in osst_wait_frame()
808 STp->last_frame_position, STp->cur_frames, in osst_wait_frame()
818 dev, curr, curr+minlast, STp->first_frame_position, in osst_wait_frame()
819 STp->last_frame_position, STp->cur_frames, result); in osst_wait_frame()
828 dev, curr, curr+minlast, STp->first_frame_position, in osst_wait_frame()
829 STp->last_frame_position, STp->cur_frames, in osst_wait_frame()
838 static int osst_read_frame(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int timeout) in osst_read_frame() argument
844 os_aux_t * aux = STp->buffer->aux; in osst_read_frame()
845 int dev = TAPE_NR(STp->devt); in osst_read_frame()
849 if (STp->poll) in osst_read_frame()
850 retval = osst_wait_frame (STp, aSRpnt, STp->first_frame_position, 0, timeout); in osst_read_frame()
861 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, OS_FRAME_SIZE, SCSI_DATA_READ, in osst_read_frame()
862 STp->timeout, MAX_READ_RETRIES, TRUE); in osst_read_frame()
867 if ((STp->buffer)->syscall_result) { in osst_read_frame()
869 if (STp->read_error_frame == 0) { in osst_read_frame()
870 STp->read_error_frame = STp->first_frame_position; in osst_read_frame()
872 printk(OSST_DEB_MSG "osst%d:D: Recording read error at %d\n", dev, STp->read_error_frame); in osst_read_frame()
886 STp->first_frame_position++; in osst_read_frame()
907 static int osst_initiate_read(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt) in osst_initiate_read() argument
909 ST_partstat * STps = &(STp->ps[STp->partition]); in osst_initiate_read()
914 int dev = TAPE_NR(STp->devt); in osst_initiate_read()
918 if (STps->rw == ST_WRITING || STp->dirty) { in osst_initiate_read()
919 STp->write_type = OS_WRITE_DATA; in osst_initiate_read()
920 osst_flush_write_buffer(STp, aSRpnt); in osst_initiate_read()
921 osst_flush_drive_buffer(STp, aSRpnt); in osst_initiate_read()
924 STp->frame_in_buffer = 0; in osst_initiate_read()
937 …SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_READ_RETRIES, TRUE); in osst_initiate_read()
939 retval = STp->buffer->syscall_result; in osst_initiate_read()
945 static int osst_get_logical_frame(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int frame_seq_number,… in osst_get_logical_frame() argument
947 ST_partstat * STps = &(STp->ps[STp->partition]); in osst_get_logical_frame()
948 int dev = TAPE_NR(STp->devt); in osst_get_logical_frame()
958 if (frame_seq_number == -1 && STp->frame_in_buffer) { in osst_get_logical_frame()
960 printk(OSST_DEB_MSG "osst%d:D: Frame %d still in buffer\n", dev, STp->frame_seq_number); in osst_get_logical_frame()
971 if (STp->read_error_frame) { in osst_get_logical_frame()
972 osst_set_frame_position(STp, aSRpnt, STp->read_error_frame, 0); in osst_get_logical_frame()
975 dev, STp->read_error_frame); in osst_get_logical_frame()
977 STp->read_error_frame = 0; in osst_get_logical_frame()
986 if ( osst_initiate_read(STp, aSRpnt) in osst_get_logical_frame()
987 || ( (!STp->frame_in_buffer) && osst_read_frame(STp, aSRpnt, 30) ) ) { in osst_get_logical_frame()
988 if (STp->raw) in osst_get_logical_frame()
990 position = osst_get_frame_position(STp, aSRpnt); in osst_get_logical_frame()
993 else if (position > STp->eod_frame_ppos || ++bad == 10) { in osst_get_logical_frame()
994 position = STp->read_error_frame - 1; in osst_get_logical_frame()
1004 osst_set_frame_position(STp, aSRpnt, position, 0); in osst_get_logical_frame()
1007 if (osst_verify_frame(STp, frame_seq_number, quiet)) in osst_get_logical_frame()
1009 if (osst_verify_frame(STp, -1, quiet)) { in osst_get_logical_frame()
1010 x = ntohl(STp->buffer->aux->frame_seq_num); in osst_get_logical_frame()
1011 if (STp->fast_open) { in osst_get_logical_frame()
1015 STp->header_ok = 0; in osst_get_logical_frame()
1016 STp->read_error_frame = 0; in osst_get_logical_frame()
1022 position = STp->read_error_frame - 1; in osst_get_logical_frame()
1025 position = osst_get_frame_position(STp, aSRpnt) in osst_get_logical_frame()
1028 if (STp->first_frame_position >= 3000 && position < 3000) in osst_get_logical_frame()
1035 STp->first_frame_position - position); in osst_get_logical_frame()
1037 osst_set_frame_position(STp, aSRpnt, position, 0); in osst_get_logical_frame()
1043 if (osst_get_frame_position(STp, aSRpnt) == 0xbaf) { in osst_get_logical_frame()
1047 osst_set_frame_position(STp, aSRpnt, 0xbb8, 0); in osst_get_logical_frame()
1050 STp->frame_in_buffer = 0; in osst_get_logical_frame()
1053 STp->recover_count++; in osst_get_logical_frame()
1054 STp->recover_erreg++; in osst_get_logical_frame()
1056 dev, STp->read_error_frame); in osst_get_logical_frame()
1058 STp->read_count++; in osst_get_logical_frame()
1064 dev, frame_seq_number, STp->frame_seq_number, STps->eof); in osst_get_logical_frame()
1066 STp->fast_open = FALSE; in osst_get_logical_frame()
1067 STp->read_error_frame = 0; in osst_get_logical_frame()
1071 static int osst_seek_logical_blk(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int logical_blk_num) in osst_seek_logical_blk() argument
1073 ST_partstat * STps = &(STp->ps[STp->partition]); in osst_seek_logical_blk()
1074 int dev = TAPE_NR(STp->devt); in osst_seek_logical_blk()
1081 dev, logical_blk_num, STp->logical_blk_num, in osst_seek_logical_blk()
1082 STp->block_size<1024?STp->block_size:STp->block_size/1024, in osst_seek_logical_blk()
1083 STp->block_size<1024?'b':'k'); in osst_seek_logical_blk()
1087 move = logical_blk_num - STp->logical_blk_num; in osst_seek_logical_blk()
1088 if (move < 0) move -= (OS_DATA_SIZE / STp->block_size) - 1; in osst_seek_logical_blk()
1089 move /= (OS_DATA_SIZE / STp->block_size); in osst_seek_logical_blk()
1090 frame_seq_estimate = STp->frame_seq_number + move; in osst_seek_logical_blk()
1092 frame_seq_estimate = logical_blk_num * STp->block_size / OS_DATA_SIZE; in osst_seek_logical_blk()
1097 if (ppos_estimate > STp->eod_frame_ppos-2) { in osst_seek_logical_blk()
1098 frame_seq_estimate += STp->eod_frame_ppos - 2 - ppos_estimate; in osst_seek_logical_blk()
1099 ppos_estimate = STp->eod_frame_ppos - 2; in osst_seek_logical_blk()
1105 osst_set_frame_position(STp, aSRpnt, ppos_estimate, 0); in osst_seek_logical_blk()
1106 if (osst_get_logical_frame(STp, aSRpnt, frame_seq_estimate, 1) >= 0) { in osst_seek_logical_blk()
1108 if (logical_blk_num < STp->logical_blk_num || in osst_seek_logical_blk()
1109 … logical_blk_num >= STp->logical_blk_num + ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt)) { in osst_seek_logical_blk()
1111 move = logical_blk_num < STp->logical_blk_num? -2 : 1; in osst_seek_logical_blk()
1113 move = logical_blk_num - STp->logical_blk_num; in osst_seek_logical_blk()
1114 if (move < 0) move -= (OS_DATA_SIZE / STp->block_size) - 1; in osst_seek_logical_blk()
1115 move /= (OS_DATA_SIZE / STp->block_size); in osst_seek_logical_blk()
1117 if (!move) move = logical_blk_num > STp->logical_blk_num ? 1 : -1; in osst_seek_logical_blk()
1121 dev, retries, ppos_estimate, STp->frame_seq_number, frame_seq_estimate, in osst_seek_logical_blk()
1122 STp->logical_blk_num, logical_blk_num, move); in osst_seek_logical_blk()
1128 STp->buffer->read_pointer = (logical_blk_num - STp->logical_blk_num) * STp->block_size; in osst_seek_logical_blk()
1129 STp->buffer->buffer_bytes -= STp->buffer->read_pointer; in osst_seek_logical_blk()
1130 STp->logical_blk_num = logical_blk_num; in osst_seek_logical_blk()
1134 dev, ppos_estimate, STp->frame_seq_number, STp->frame_in_buffer, in osst_seek_logical_blk()
1135 STp->buffer->buffer_bytes, STp->buffer->read_pointer / STp->block_size, in osst_seek_logical_blk()
1136 STp->block_size); in osst_seek_logical_blk()
1138 STps->drv_file = ntohl(STp->buffer->aux->filemark_cnt); in osst_seek_logical_blk()
1143 STps->drv_block = ntohl(STp->buffer->aux->last_mark_lbn)? in osst_seek_logical_blk()
1144 STp->logical_blk_num - in osst_seek_logical_blk()
1145 (STps->drv_file ? ntohl(STp->buffer->aux->last_mark_lbn) + 1 : 0): in osst_seek_logical_blk()
1148 STps->eof = (STp->first_frame_position >= STp->eod_frame_ppos)?ST_EOD:ST_NOEOF; in osst_seek_logical_blk()
1152 if (osst_get_logical_frame(STp, aSRpnt, -1, 1) < 0) in osst_seek_logical_blk()
1157 dev, retries, ppos_estimate, STp->frame_seq_number, frame_seq_estimate, in osst_seek_logical_blk()
1158 STp->logical_blk_num, logical_blk_num); in osst_seek_logical_blk()
1160 if (frame_seq_estimate != STp->frame_seq_number) in osst_seek_logical_blk()
1161 ppos_estimate += frame_seq_estimate - STp->frame_seq_number; in osst_seek_logical_blk()
1167 dev, logical_blk_num, STp->logical_blk_num, retries); in osst_seek_logical_blk()
1180 static int osst_get_sector(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt) in osst_get_sector() argument
1184 int dev = TAPE_NR(STp->devt); in osst_get_sector()
1188 dev, STp->first_frame_position, STp->frame_seq_number, STp->logical_blk_num, in osst_get_sector()
1189 STp->ps[STp->partition].drv_file, STp->ps[STp->partition].drv_block, in osst_get_sector()
1190 STp->ps[STp->partition].rw == ST_WRITING?'w':'r', in osst_get_sector()
1191 STp->ps[STp->partition].rw == ST_WRITING?STp->buffer->buffer_bytes: in osst_get_sector()
1192 STp->buffer->read_pointer, STp->ps[STp->partition].eof); in osst_get_sector()
1195 if (STp->ps[STp->partition].drv_block >= 0) { in osst_get_sector()
1196 sector = (STp->frame_in_buffer ? STp->first_frame_position-1 : in osst_get_sector()
1197 STp->first_frame_position) << OSST_FRAME_SHIFT; in osst_get_sector()
1198 if (STp->ps[STp->partition].rw == ST_WRITING) in osst_get_sector()
1199 sector |= (STp->buffer->buffer_bytes >> OSST_SECTOR_SHIFT) & OSST_SECTOR_MASK; in osst_get_sector()
1201 sector |= (STp->buffer->read_pointer >> OSST_SECTOR_SHIFT) & OSST_SECTOR_MASK; in osst_get_sector()
1203 sector = osst_get_frame_position(STp, aSRpnt); in osst_get_sector()
1210 static int osst_seek_sector(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int sector) in osst_seek_sector() argument
1212 ST_partstat * STps = &(STp->ps[STp->partition]); in osst_seek_sector()
1217 int dev = TAPE_NR(STp->devt); in osst_seek_sector()
1222 if (frame < 0 || frame >= STp->capacity) return (-ENXIO); in osst_seek_sector()
1224 if (frame <= STp->first_data_ppos) { in osst_seek_sector()
1225 STp->frame_seq_number = STp->logical_blk_num = STps->drv_file = STps->drv_block = 0; in osst_seek_sector()
1226 return (osst_set_frame_position(STp, aSRpnt, frame, 0)); in osst_seek_sector()
1228 r = osst_set_frame_position(STp, aSRpnt, offset?frame:frame-1, 0); in osst_seek_sector()
1231 r = osst_get_logical_frame(STp, aSRpnt, -1, 1); in osst_seek_sector()
1234 if (osst_get_frame_position(STp, aSRpnt) != (offset?frame+1:frame)) return (-EIO); in osst_seek_sector()
1237 STp->logical_blk_num += offset / STp->block_size; in osst_seek_sector()
1238 STp->buffer->read_pointer = offset; in osst_seek_sector()
1239 STp->buffer->buffer_bytes -= offset; in osst_seek_sector()
1241 STp->frame_seq_number++; in osst_seek_sector()
1242 STp->frame_in_buffer = 0; in osst_seek_sector()
1243 STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt); in osst_seek_sector()
1244 STp->buffer->buffer_bytes = STp->buffer->read_pointer = 0; in osst_seek_sector()
1246 STps->drv_file = ntohl(STp->buffer->aux->filemark_cnt); in osst_seek_sector()
1251 STps->drv_block = ntohl(STp->buffer->aux->last_mark_lbn)? in osst_seek_sector()
1252 STp->logical_blk_num - in osst_seek_sector()
1253 (STps->drv_file ? ntohl(STp->buffer->aux->last_mark_lbn) + 1 : 0): in osst_seek_sector()
1256 STps->eof = (STp->first_frame_position >= STp->eod_frame_ppos)?ST_EOD:ST_NOEOF; in osst_seek_sector()
1260 dev, STp->first_frame_position, STp->frame_seq_number, STp->logical_blk_num, in osst_seek_sector()
1261 STps->drv_file, STps->drv_block, STp->buffer->read_pointer, STps->eof); in osst_seek_sector()
1273 static int osst_read_back_buffer_and_rewrite(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, in osst_read_back_buffer_and_rewrite() argument
1280 int nframes = STp->cur_frames; in osst_read_back_buffer_and_rewrite()
1281 int blks_per_frame = ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt); in osst_read_back_buffer_and_rewrite()
1282 int frame_seq_number = ntohl(STp->buffer->aux->frame_seq_num) in osst_read_back_buffer_and_rewrite()
1284 int logical_blk_num = ntohl(STp->buffer->aux->logical_blk_num) in osst_read_back_buffer_and_rewrite()
1286 int dev = TAPE_NR(STp->devt); in osst_read_back_buffer_and_rewrite()
1298 osst_copy_from_buffer(STp->buffer, (p = &buffer[nframes * OS_DATA_SIZE])); in osst_read_back_buffer_and_rewrite()
1314 SRpnt = osst_do_scsi(SRpnt, STp, cmd, OS_FRAME_SIZE, SCSI_DATA_READ, in osst_read_back_buffer_and_rewrite()
1315 STp->timeout, MAX_READ_RETRIES, TRUE); in osst_read_back_buffer_and_rewrite()
1317 if ((STp->buffer)->syscall_result || !SRpnt) { in osst_read_back_buffer_and_rewrite()
1323 osst_copy_from_buffer(STp->buffer, p); in osst_read_back_buffer_and_rewrite()
1331 osst_get_frame_position(STp, aSRpnt); in osst_read_back_buffer_and_rewrite()
1334 printk(OSST_DEB_MSG "osst%d:D: Frames left in buffer: %d\n", dev, STp->cur_frames); in osst_read_back_buffer_and_rewrite()
1342 if (STp->write_type == OS_WRITE_HEADER) { in osst_read_back_buffer_and_rewrite()
1354 osst_set_frame_position(STp, aSRpnt, new_frame + i, 0); in osst_read_back_buffer_and_rewrite()
1355 osst_wait_ready(STp, aSRpnt, 60, OSST_WAIT_POSITION_COMPLETE); in osst_read_back_buffer_and_rewrite()
1356 osst_get_frame_position(STp, aSRpnt); in osst_read_back_buffer_and_rewrite()
1367 osst_copy_to_buffer(STp->buffer, p); in osst_read_back_buffer_and_rewrite()
1371 osst_init_aux(STp, STp->buffer->aux->frame_type, frame_seq_number+i, in osst_read_back_buffer_and_rewrite()
1373 ntohl(STp->buffer->aux->dat.dat_list[0].blk_sz), blks_per_frame); in osst_read_back_buffer_and_rewrite()
1386 SRpnt = osst_do_scsi(SRpnt, STp, cmd, OS_FRAME_SIZE, SCSI_DATA_WRITE, in osst_read_back_buffer_and_rewrite()
1387 STp->timeout, MAX_WRITE_RETRIES, TRUE); in osst_read_back_buffer_and_rewrite()
1389 if (STp->buffer->syscall_result) in osst_read_back_buffer_and_rewrite()
1402 SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, SCSI_DATA_NONE, in osst_read_back_buffer_and_rewrite()
1403 STp->timeout, MAX_WRITE_RETRIES, TRUE); in osst_read_back_buffer_and_rewrite()
1411 flag = STp->buffer->syscall_result; in osst_read_back_buffer_and_rewrite()
1417 SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, in osst_read_back_buffer_and_rewrite()
1427 if (STp->buffer->syscall_result) in osst_read_back_buffer_and_rewrite()
1454 osst_get_frame_position(STp, aSRpnt); in osst_read_back_buffer_and_rewrite()
1457 dev, STp->first_frame_position, STp->last_frame_position); in osst_read_back_buffer_and_rewrite()
1462 osst_copy_to_buffer(STp->buffer, p); /* so buffer content == at entry in all cases */ in osst_read_back_buffer_and_rewrite()
1467 static int osst_reposition_and_retry(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, in osst_reposition_and_retry() argument
1472 int dev = TAPE_NR(STp->devt); in osst_reposition_and_retry()
1486 if (frame < 2990 && frame+skip+STp->cur_frames+pending >= 2990) in osst_reposition_and_retry()
1488 expected = frame+skip+STp->cur_frames+pending; in osst_reposition_and_retry()
1491 dev, frame+skip, STp->frame_seq_number-STp->cur_frames-pending); in osst_reposition_and_retry()
1493 osst_set_frame_position(STp, aSRpnt, frame + skip, 1); in osst_reposition_and_retry()
1499 if (osst_get_frame_position(STp, aSRpnt) < 0) { /* additional write error */ in osst_reposition_and_retry()
1502 dev, STp->first_frame_position, in osst_reposition_and_retry()
1503 STp->last_frame_position, STp->cur_frames); in osst_reposition_and_retry()
1505 frame = STp->last_frame_position; in osst_reposition_and_retry()
1509 if (pending && STp->cur_frames < 50) { in osst_reposition_and_retry()
1517 dev, STp->frame_seq_number-1, STp->first_frame_position); in osst_reposition_and_retry()
1519 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, OS_FRAME_SIZE, SCSI_DATA_WRITE, in osst_reposition_and_retry()
1520 STp->timeout, MAX_WRITE_RETRIES, TRUE); in osst_reposition_and_retry()
1523 if (STp->buffer->syscall_result) { /* additional write error */ in osst_reposition_and_retry()
1539 if (STp->cur_frames == 0) { in osst_reposition_and_retry()
1544 if (STp->first_frame_position != expected) { in osst_reposition_and_retry()
1546 dev, STp->first_frame_position, expected); in osst_reposition_and_retry()
1572 static int osst_write_error_recovery(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int pending) in osst_write_error_recovery() argument
1575 ST_partstat * STps = & STp->ps[STp->partition]; in osst_write_error_recovery()
1576 int dev = TAPE_NR(STp->devt); in osst_write_error_recovery()
1601 osst_get_frame_position(STp, aSRpnt); in osst_write_error_recovery()
1604 dev, STp->first_frame_position, STp->last_frame_position); in osst_write_error_recovery()
1606 switch (STp->write_type) { in osst_write_error_recovery()
1612 dev, STp->cur_frames, frame, (frame + skip > 3000 && frame < 3000)?3000:frame + skip); in osst_write_error_recovery()
1613 if (STp->os_fw_rev >= 10600) in osst_write_error_recovery()
1614 retval = osst_reposition_and_retry(STp, aSRpnt, frame, skip, pending); in osst_write_error_recovery()
1616 retval = osst_read_back_buffer_and_rewrite(STp, aSRpnt, frame, skip, pending); in osst_write_error_recovery()
1624 osst_set_frame_position(STp, aSRpnt, frame + STp->cur_frames + pending, 0); in osst_write_error_recovery()
1629 retval = osst_read_back_buffer_and_rewrite(STp, aSRpnt, frame, 1, pending); in osst_write_error_recovery()
1633 osst_set_frame_position(STp, aSRpnt, frame + STp->cur_frames + pending, 0); in osst_write_error_recovery()
1635 osst_get_frame_position(STp, aSRpnt); in osst_write_error_recovery()
1638 dev, STp->cur_frames, STp->first_frame_position, STp->last_frame_position); in osst_write_error_recovery()
1639 printk(OSST_DEB_MSG "osst%d:D: next logical frame to write: %d\n", dev, STp->logical_blk_num); in osst_write_error_recovery()
1642 STp->recover_count++; in osst_write_error_recovery()
1643 STp->recover_erreg++; in osst_write_error_recovery()
1649 static int osst_space_over_filemarks_backward(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, in osst_space_over_filemarks_backward() argument
1652 int dev = TAPE_NR(STp->devt); in osst_space_over_filemarks_backward()
1659 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) { in osst_space_over_filemarks_backward()
1665 if (STp->linux_media_version >= 4) { in osst_space_over_filemarks_backward()
1669 cnt = ntohl(STp->buffer->aux->filemark_cnt); in osst_space_over_filemarks_backward()
1670 if (STp->header_ok && in osst_space_over_filemarks_backward()
1671 STp->header_cache != NULL && in osst_space_over_filemarks_backward()
1674 (cnt - mt_count) < STp->filemark_cnt && in osst_space_over_filemarks_backward()
1675 STp->header_cache->dat_fm_tab.fm_tab_ent[cnt-1] == STp->buffer->aux->last_mark_ppos) in osst_space_over_filemarks_backward()
1677 last_mark_ppos = ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[cnt - mt_count]); in osst_space_over_filemarks_backward()
1679 if (STp->header_cache == NULL || (cnt - mt_count) < 0 || (cnt - mt_count) >= OS_FM_TAB_MAX) in osst_space_over_filemarks_backward()
1681 STp->header_cache == NULL?"lack of header cache":"count out of range"); in osst_space_over_filemarks_backward()
1685 ((cnt == -1 && ntohl(STp->buffer->aux->last_mark_ppos) == -1) || in osst_space_over_filemarks_backward()
1686 (STp->header_cache->dat_fm_tab.fm_tab_ent[cnt-1] == in osst_space_over_filemarks_backward()
1687 STp->buffer->aux->last_mark_ppos))?"match":"error", in osst_space_over_filemarks_backward()
1690 if (last_mark_ppos > 10 && last_mark_ppos < STp->eod_frame_ppos) { in osst_space_over_filemarks_backward()
1691 osst_position_tape_and_confirm(STp, aSRpnt, last_mark_ppos); in osst_space_over_filemarks_backward()
1692 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) { in osst_space_over_filemarks_backward()
1699 if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) { in osst_space_over_filemarks_backward()
1712 last_mark_ppos = ntohl(STp->buffer->aux->last_mark_ppos); in osst_space_over_filemarks_backward()
1718 osst_position_tape_and_confirm(STp, aSRpnt, last_mark_ppos); in osst_space_over_filemarks_backward()
1720 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) { in osst_space_over_filemarks_backward()
1726 if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) { in osst_space_over_filemarks_backward()
1734 STp->frame_seq_number++; in osst_space_over_filemarks_backward()
1735 STp->frame_in_buffer = 0; in osst_space_over_filemarks_backward()
1736 STp->buffer->buffer_bytes = 0; in osst_space_over_filemarks_backward()
1737 STp->buffer->read_pointer = 0; in osst_space_over_filemarks_backward()
1738 STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt); in osst_space_over_filemarks_backward()
1748 static int osst_space_over_filemarks_forward_slow(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, in osst_space_over_filemarks_forward_slow() argument
1753 int dev = TAPE_NR(STp->devt); in osst_space_over_filemarks_forward_slow()
1757 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) { in osst_space_over_filemarks_forward_slow()
1764 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) { in osst_space_over_filemarks_forward_slow()
1770 if (STp->buffer->aux->frame_type == OS_FRAME_TYPE_MARKER) in osst_space_over_filemarks_forward_slow()
1772 if (STp->buffer->aux->frame_type == OS_FRAME_TYPE_EOD) { in osst_space_over_filemarks_forward_slow()
1776 if (STp->first_frame_position > STp->eod_frame_ppos+1) { in osst_space_over_filemarks_forward_slow()
1779 dev, STp->eod_frame_ppos, STp->first_frame_position-1); in osst_space_over_filemarks_forward_slow()
1781 STp->eod_frame_ppos = STp->first_frame_position-1; in osst_space_over_filemarks_forward_slow()
1787 STp->frame_in_buffer = 0; in osst_space_over_filemarks_forward_slow()
1790 STp->frame_seq_number++; in osst_space_over_filemarks_forward_slow()
1791 STp->frame_in_buffer = 0; in osst_space_over_filemarks_forward_slow()
1792 STp->buffer->buffer_bytes = 0; in osst_space_over_filemarks_forward_slow()
1793 STp->buffer->read_pointer = 0; in osst_space_over_filemarks_forward_slow()
1794 STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt); in osst_space_over_filemarks_forward_slow()
1802 static int osst_space_over_filemarks_forward_fast(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, in osst_space_over_filemarks_forward_fast() argument
1805 int dev = TAPE_NR(STp->devt); in osst_space_over_filemarks_forward_fast()
1812 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) { in osst_space_over_filemarks_forward_fast()
1819 if (STp->linux_media_version >= 4) { in osst_space_over_filemarks_forward_fast()
1823 cnt = ntohl(STp->buffer->aux->filemark_cnt) - 1; in osst_space_over_filemarks_forward_fast()
1824 if (STp->header_ok && in osst_space_over_filemarks_forward_fast()
1825 STp->header_cache != NULL && in osst_space_over_filemarks_forward_fast()
1827 (cnt + mt_count) < STp->filemark_cnt && in osst_space_over_filemarks_forward_fast()
1828 ((cnt == -1 && ntohl(STp->buffer->aux->last_mark_ppos) == -1) || in osst_space_over_filemarks_forward_fast()
1829 (STp->header_cache->dat_fm_tab.fm_tab_ent[cnt] == STp->buffer->aux->last_mark_ppos))) in osst_space_over_filemarks_forward_fast()
1831 next_mark_ppos = ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[cnt + mt_count]); in osst_space_over_filemarks_forward_fast()
1833 if (STp->header_cache == NULL || (cnt + mt_count) >= OS_FM_TAB_MAX) in osst_space_over_filemarks_forward_fast()
1835 STp->header_cache == NULL?"lack of header cache":"count out of range"); in osst_space_over_filemarks_forward_fast()
1839 ((cnt == -1 && ntohl(STp->buffer->aux->last_mark_ppos) == -1) || in osst_space_over_filemarks_forward_fast()
1840 (STp->header_cache->dat_fm_tab.fm_tab_ent[cnt] == in osst_space_over_filemarks_forward_fast()
1841 STp->buffer->aux->last_mark_ppos))?"match":"error", in osst_space_over_filemarks_forward_fast()
1844 if (next_mark_ppos <= 10 || next_mark_ppos > STp->eod_frame_ppos) { in osst_space_over_filemarks_forward_fast()
1848 return osst_space_over_filemarks_forward_slow(STp, aSRpnt, mt_op, mt_count); in osst_space_over_filemarks_forward_fast()
1850 osst_position_tape_and_confirm(STp, aSRpnt, next_mark_ppos); in osst_space_over_filemarks_forward_fast()
1851 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) { in osst_space_over_filemarks_forward_fast()
1858 if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) { in osst_space_over_filemarks_forward_fast()
1863 if (ntohl(STp->buffer->aux->filemark_cnt) != cnt + mt_count) { in osst_space_over_filemarks_forward_fast()
1866 ntohl(STp->buffer->aux->filemark_cnt)); in osst_space_over_filemarks_forward_fast()
1875 if (STp->buffer->aux->frame_type == OS_FRAME_TYPE_MARKER) in osst_space_over_filemarks_forward_fast()
1877 if (STp->buffer->aux->frame_type == OS_FRAME_TYPE_EOD) { in osst_space_over_filemarks_forward_fast()
1883 if (ntohl(STp->buffer->aux->filemark_cnt) == 0) { in osst_space_over_filemarks_forward_fast()
1884 if (STp->first_mark_ppos == -1) { in osst_space_over_filemarks_forward_fast()
1888 return osst_space_over_filemarks_forward_slow(STp, aSRpnt, mt_op, mt_count); in osst_space_over_filemarks_forward_fast()
1890 osst_position_tape_and_confirm(STp, aSRpnt, STp->first_mark_ppos); in osst_space_over_filemarks_forward_fast()
1891 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) { in osst_space_over_filemarks_forward_fast()
1899 if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) { in osst_space_over_filemarks_forward_fast()
1901 dev, STp->first_mark_ppos); in osst_space_over_filemarks_forward_fast()
1905 if (osst_space_over_filemarks_backward(STp, aSRpnt, MTBSF, 1) < 0) in osst_space_over_filemarks_forward_fast()
1912 next_mark_ppos = ntohl(STp->buffer->aux->next_mark_ppos); in osst_space_over_filemarks_forward_fast()
1913 if (!next_mark_ppos || next_mark_ppos > STp->eod_frame_ppos) { in osst_space_over_filemarks_forward_fast()
1917 return osst_space_over_filemarks_forward_slow(STp, aSRpnt, mt_op, mt_count - cnt); in osst_space_over_filemarks_forward_fast()
1922 osst_position_tape_and_confirm(STp, aSRpnt, next_mark_ppos); in osst_space_over_filemarks_forward_fast()
1924 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) { in osst_space_over_filemarks_forward_fast()
1931 if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) { in osst_space_over_filemarks_forward_fast()
1939 STp->frame_seq_number++; in osst_space_over_filemarks_forward_fast()
1940 STp->frame_in_buffer = 0; in osst_space_over_filemarks_forward_fast()
1941 STp->buffer->buffer_bytes = 0; in osst_space_over_filemarks_forward_fast()
1942 STp->buffer->read_pointer = 0; in osst_space_over_filemarks_forward_fast()
1943 STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt); in osst_space_over_filemarks_forward_fast()
1953 static void osst_set_retries(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int retries) in osst_set_retries() argument
1957 int dev = TAPE_NR(STp->devt); in osst_set_retries()
1964 (STp->buffer)->b_data[0] = cmd[4] - 1; in osst_set_retries()
1965 (STp->buffer)->b_data[1] = 0; /* Medium Type - ignoring */ in osst_set_retries()
1966 (STp->buffer)->b_data[2] = 0; /* Reserved */ in osst_set_retries()
1967 (STp->buffer)->b_data[3] = 0; /* Block Descriptor Length */ in osst_set_retries()
1968 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 0] = NUMBER_RETRIES_PAGE | (1 << 7); in osst_set_retries()
1969 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 1] = 2; in osst_set_retries()
1970 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 2] = 4; in osst_set_retries()
1971 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 3] = retries; in osst_set_retries()
1976 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_WRITE, STp->timeout, 0, TRUE); in osst_set_retries()
1979 if ((STp->buffer)->syscall_result) in osst_set_retries()
1985 static int osst_write_filemark(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt) in osst_write_filemark() argument
1988 int this_mark_ppos = STp->first_frame_position; in osst_write_filemark()
1989 int this_mark_lbn = STp->logical_blk_num; in osst_write_filemark()
1991 int dev = TAPE_NR(STp->devt); in osst_write_filemark()
1994 if (STp->raw) return 0; in osst_write_filemark()
1996 STp->write_type = OS_WRITE_NEW_MARK; in osst_write_filemark()
1999 dev, STp->filemark_cnt, this_mark_ppos, STp->frame_seq_number, this_mark_lbn); in osst_write_filemark()
2001 STp->dirty = 1; in osst_write_filemark()
2002 result = osst_flush_write_buffer(STp, aSRpnt); in osst_write_filemark()
2003 result |= osst_flush_drive_buffer(STp, aSRpnt); in osst_write_filemark()
2004 STp->last_mark_ppos = this_mark_ppos; in osst_write_filemark()
2005 STp->last_mark_lbn = this_mark_lbn; in osst_write_filemark()
2006 if (STp->header_cache != NULL && STp->filemark_cnt < OS_FM_TAB_MAX) in osst_write_filemark()
2007 STp->header_cache->dat_fm_tab.fm_tab_ent[STp->filemark_cnt] = htonl(this_mark_ppos); in osst_write_filemark()
2008 if (STp->filemark_cnt++ == 0) in osst_write_filemark()
2009 STp->first_mark_ppos = this_mark_ppos; in osst_write_filemark()
2013 static int osst_write_eod(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt) in osst_write_eod() argument
2017 int dev = TAPE_NR(STp->devt); in osst_write_eod()
2020 if (STp->raw) return 0; in osst_write_eod()
2022 STp->write_type = OS_WRITE_EOD; in osst_write_eod()
2023 STp->eod_frame_ppos = STp->first_frame_position; in osst_write_eod()
2026 STp->eod_frame_ppos, STp->frame_seq_number, STp->logical_blk_num); in osst_write_eod()
2028 STp->dirty = 1; in osst_write_eod()
2030 result = osst_flush_write_buffer(STp, aSRpnt); in osst_write_eod()
2031 result |= osst_flush_drive_buffer(STp, aSRpnt); in osst_write_eod()
2032 STp->eod_frame_lfa = --(STp->frame_seq_number); in osst_write_eod()
2036 static int osst_write_filler(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int where, int count) in osst_write_filler() argument
2038 int dev = TAPE_NR(STp->devt); in osst_write_filler()
2043 osst_wait_ready(STp, aSRpnt, 60 * 5, 0); in osst_write_filler()
2044 osst_set_frame_position(STp, aSRpnt, where, 0); in osst_write_filler()
2045 STp->write_type = OS_WRITE_FILLER; in osst_write_filler()
2047 memcpy(STp->buffer->b_data, "Filler", 6); in osst_write_filler()
2048 STp->buffer->buffer_bytes = 6; in osst_write_filler()
2049 STp->dirty = 1; in osst_write_filler()
2050 if (osst_flush_write_buffer(STp, aSRpnt)) { in osst_write_filler()
2058 return osst_flush_drive_buffer(STp, aSRpnt); in osst_write_filler()
2061 static int __osst_write_header(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int where, int count) in __osst_write_header() argument
2063 int dev = TAPE_NR(STp->devt); in __osst_write_header()
2069 osst_wait_ready(STp, aSRpnt, 60 * 5, 0); in __osst_write_header()
2070 osst_set_frame_position(STp, aSRpnt, where, 0); in __osst_write_header()
2071 STp->write_type = OS_WRITE_HEADER; in __osst_write_header()
2073 osst_copy_to_buffer(STp->buffer, (unsigned char *)STp->header_cache); in __osst_write_header()
2074 STp->buffer->buffer_bytes = sizeof(os_header_t); in __osst_write_header()
2075 STp->dirty = 1; in __osst_write_header()
2076 if (osst_flush_write_buffer(STp, aSRpnt)) { in __osst_write_header()
2081 result = osst_flush_drive_buffer(STp, aSRpnt); in __osst_write_header()
2088 static int osst_write_header(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int locate_eod) in osst_write_header() argument
2092 int dev = TAPE_NR(STp->devt); in osst_write_header()
2097 if (STp->raw) return 0; in osst_write_header()
2099 if (STp->header_cache == NULL) { in osst_write_header()
2100 if ((STp->header_cache = (os_header_t *)vmalloc(sizeof(os_header_t))) == NULL) { in osst_write_header()
2104 memset(STp->header_cache, 0, sizeof(os_header_t)); in osst_write_header()
2109 if (STp->header_ok) STp->update_frame_cntr++; in osst_write_header()
2110 else STp->update_frame_cntr = 0; in osst_write_header()
2112 header = STp->header_cache; in osst_write_header()
2120 header->partition[0].wrt_pass_cntr = htons(STp->wrt_pass_cntr); in osst_write_header()
2121 header->partition[0].first_frame_ppos = htonl(STp->first_data_ppos); in osst_write_header()
2122 header->partition[0].last_frame_ppos = htonl(STp->capacity); in osst_write_header()
2123 header->partition[0].eod_frame_ppos = htonl(STp->eod_frame_ppos); in osst_write_header()
2133 header->ext_track_tb.dat_ext_trk_ey.last_hlb = htonl(STp->eod_frame_lfa); in osst_write_header()
2134 header->ext_track_tb.dat_ext_trk_ey.last_pp = htonl(STp->eod_frame_ppos); in osst_write_header()
2137 header->dat_fm_tab.fm_tab_ent_cnt = htons(STp->filemark_cnt<OS_FM_TAB_MAX? in osst_write_header()
2138 STp->filemark_cnt:OS_FM_TAB_MAX); in osst_write_header()
2140 result = __osst_write_header(STp, aSRpnt, 0xbae, 5); in osst_write_header()
2141 if (STp->update_frame_cntr == 0) in osst_write_header()
2142 osst_write_filler(STp, aSRpnt, 0xbb3, 5); in osst_write_header()
2143 result &= __osst_write_header(STp, aSRpnt, 5, 5); in osst_write_header()
2147 printk(OSST_DEB_MSG "osst%d:D: Locating back to eod frame addr %d\n", dev, STp->eod_frame_ppos); in osst_write_header()
2149 osst_set_frame_position(STp, aSRpnt, STp->eod_frame_ppos, 0); in osst_write_header()
2154 memcpy(STp->application_sig, "LIN4", 4); in osst_write_header()
2155 STp->linux_media = 1; in osst_write_header()
2156 STp->linux_media_version = 4; in osst_write_header()
2157 STp->header_ok = 1; in osst_write_header()
2162 static int osst_reset_header(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt) in osst_reset_header() argument
2164 if (STp->header_cache != NULL) in osst_reset_header()
2165 memset(STp->header_cache, 0, sizeof(os_header_t)); in osst_reset_header()
2167 STp->logical_blk_num = STp->frame_seq_number = 0; in osst_reset_header()
2168 STp->frame_in_buffer = 0; in osst_reset_header()
2169 STp->eod_frame_ppos = STp->first_data_ppos = 0x0000000A; in osst_reset_header()
2170 STp->filemark_cnt = 0; in osst_reset_header()
2171 STp->first_mark_ppos = STp->last_mark_ppos = STp->last_mark_lbn = -1; in osst_reset_header()
2172 return osst_write_header(STp, aSRpnt, 1); in osst_reset_header()
2175 static int __osst_analyze_headers(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int ppos) in __osst_analyze_headers() argument
2177 int dev = TAPE_NR(STp->devt); in __osst_analyze_headers()
2184 if (STp->raw) in __osst_analyze_headers()
2187 if (ppos == 5 || ppos == 0xbae || STp->buffer->syscall_result) { in __osst_analyze_headers()
2188 if (osst_set_frame_position(STp, aSRpnt, ppos, 0)) in __osst_analyze_headers()
2190 osst_wait_ready(STp, aSRpnt, 60 * 15, 0); in __osst_analyze_headers()
2191 if (osst_initiate_read(STp, aSRpnt)) { in __osst_analyze_headers()
2196 if (osst_read_frame(STp, aSRpnt, 180)) { in __osst_analyze_headers()
2202 header = (os_header_t *) STp->buffer->b_data; /* warning: only first segment addressable */ in __osst_analyze_headers()
2203 aux = STp->buffer->aux; in __osst_analyze_headers()
2233 if (update_frame_cntr < STp->update_frame_cntr) { in __osst_analyze_headers()
2236 dev, ppos, update_frame_cntr, STp->update_frame_cntr); in __osst_analyze_headers()
2258 STp->linux_media = 1; in __osst_analyze_headers()
2267 if (linux_media_version < STp->linux_media_version) { in __osst_analyze_headers()
2274 if (linux_media_version > STp->linux_media_version) { in __osst_analyze_headers()
2279 memcpy(STp->application_sig, id_string, 5); in __osst_analyze_headers()
2280 STp->linux_media_version = linux_media_version; in __osst_analyze_headers()
2281 STp->update_frame_cntr = -1; in __osst_analyze_headers()
2283 if (update_frame_cntr > STp->update_frame_cntr) { in __osst_analyze_headers()
2288 if (STp->header_cache == NULL) { in __osst_analyze_headers()
2289 if ((STp->header_cache = (os_header_t *)vmalloc(sizeof(os_header_t))) == NULL) { in __osst_analyze_headers()
2297 osst_copy_from_buffer(STp->buffer, (unsigned char *)STp->header_cache); in __osst_analyze_headers()
2298 header = STp->header_cache; /* further accesses from cached (full) copy */ in __osst_analyze_headers()
2300 STp->wrt_pass_cntr = ntohs(header->partition[0].wrt_pass_cntr); in __osst_analyze_headers()
2301 STp->first_data_ppos = ntohl(header->partition[0].first_frame_ppos); in __osst_analyze_headers()
2302 STp->eod_frame_ppos = ntohl(header->partition[0].eod_frame_ppos); in __osst_analyze_headers()
2303 STp->eod_frame_lfa = ntohl(header->ext_track_tb.dat_ext_trk_ey.last_hlb); in __osst_analyze_headers()
2304 STp->filemark_cnt = ntohl(aux->filemark_cnt); in __osst_analyze_headers()
2305 STp->first_mark_ppos = ntohl(aux->next_mark_ppos); in __osst_analyze_headers()
2306 STp->last_mark_ppos = ntohl(aux->last_mark_ppos); in __osst_analyze_headers()
2307 STp->last_mark_lbn = ntohl(aux->last_mark_lbn); in __osst_analyze_headers()
2308 STp->update_frame_cntr = update_frame_cntr; in __osst_analyze_headers()
2311 dev, STp->wrt_pass_cntr, STp->update_frame_cntr, STp->filemark_cnt); in __osst_analyze_headers()
2313 STp->first_data_ppos, in __osst_analyze_headers()
2317 dev, STp->first_mark_ppos, STp->last_mark_ppos, STp->eod_frame_ppos); in __osst_analyze_headers()
2319 if (header->minor_rev < 4 && STp->linux_media_version == 4) { in __osst_analyze_headers()
2331 header->partition[0].last_frame_ppos != htonl(STp->capacity) || in __osst_analyze_headers()
2341 header->ext_track_tb.dat_ext_trk_ey.last_pp != htonl(STp->eod_frame_ppos) || in __osst_analyze_headers()
2345 htons(STp->filemark_cnt<OS_FM_TAB_MAX?STp->filemark_cnt:OS_FM_TAB_MAX))) in __osst_analyze_headers()
2353 static int osst_analyze_headers(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt) in osst_analyze_headers() argument
2358 int dev = TAPE_NR(STp->devt); in osst_analyze_headers()
2360 position = osst_get_frame_position(STp, aSRpnt); in osst_analyze_headers()
2362 if (STp->raw) { in osst_analyze_headers()
2363 STp->header_ok = STp->linux_media = 1; in osst_analyze_headers()
2364 STp->linux_media_version = 0; in osst_analyze_headers()
2367 STp->header_ok = STp->linux_media = STp->linux_media_version = 0; in osst_analyze_headers()
2368 STp->wrt_pass_cntr = STp->update_frame_cntr = -1; in osst_analyze_headers()
2369 STp->eod_frame_ppos = STp->first_data_ppos = -1; in osst_analyze_headers()
2370 STp->first_mark_ppos = STp->last_mark_ppos = STp->last_mark_lbn = -1; in osst_analyze_headers()
2382 if (__osst_analyze_headers(STp, aSRpnt, ppos)) in osst_analyze_headers()
2389 if (__osst_analyze_headers(STp, aSRpnt, ppos)) in osst_analyze_headers()
2394 STp->eod_frame_ppos = STp->first_data_ppos = 0; in osst_analyze_headers()
2395 osst_set_frame_position(STp, aSRpnt, 10, 0); in osst_analyze_headers()
2398 if (position <= STp->first_data_ppos) { in osst_analyze_headers()
2399 position = STp->first_data_ppos; in osst_analyze_headers()
2400 STp->ps[0].drv_file = STp->ps[0].drv_block = STp->frame_seq_number = STp->logical_blk_num = 0; in osst_analyze_headers()
2402 osst_set_frame_position(STp, aSRpnt, position, 0); in osst_analyze_headers()
2403 STp->header_ok = 1; in osst_analyze_headers()
2408 static int osst_verify_position(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt) in osst_verify_position() argument
2410 int write_pass = STp->wrt_pass_cntr; in osst_verify_position()
2411 int frame_position = STp->first_frame_position; in osst_verify_position()
2412 int frame_seq_numbr = STp->frame_seq_number; in osst_verify_position()
2413 int logical_blk_num = STp->logical_blk_num; in osst_verify_position()
2414 int halfway_frame = STp->frame_in_buffer; in osst_verify_position()
2415 int read_pointer = STp->buffer->read_pointer; in osst_verify_position()
2419 int dev = TAPE_NR(STp->devt); in osst_verify_position()
2423 if (frame_position <= STp->first_data_ppos) { in osst_verify_position()
2425 if (!osst_analyze_headers(STp, aSRpnt) || in osst_verify_position()
2426 (write_pass != STp->wrt_pass_cntr)) { in osst_verify_position()
2434 osst_set_frame_position(STp, aSRpnt, frame_position - 1, 0); in osst_verify_position()
2435 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) { in osst_verify_position()
2442 if (STp->linux_media_version >= 4) { in osst_verify_position()
2443 for (i=0; i<STp->filemark_cnt; i++) in osst_verify_position()
2444 if ((n=ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[i])) < frame_position) in osst_verify_position()
2448 actual_mark_ppos = STp->buffer->aux->frame_type == OS_FRAME_TYPE_MARKER ? in osst_verify_position()
2449 frame_position - 1 : ntohl(STp->buffer->aux->last_mark_ppos); in osst_verify_position()
2450 if (frame_position != STp->first_frame_position || in osst_verify_position()
2451 frame_seq_numbr != STp->frame_seq_number + (halfway_frame?0:1) || in osst_verify_position()
2455 STp->first_frame_position, frame_position, in osst_verify_position()
2456 STp->frame_seq_number + (halfway_frame?0:1), in osst_verify_position()
2463 osst_set_frame_position(STp, aSRpnt, frame_position - 1, 0); in osst_verify_position()
2464 STp->buffer->buffer_bytes = read_pointer; in osst_verify_position()
2465 STp->ps[STp->partition].rw = ST_WRITING; in osst_verify_position()
2466 STp->dirty = 1; in osst_verify_position()
2468 STp->frame_in_buffer = halfway_frame; in osst_verify_position()
2469 STp->frame_seq_number = frame_seq_numbr; in osst_verify_position()
2470 STp->logical_blk_num = logical_blk_num; in osst_verify_position()
2497 static int osst_configure_onstream(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt) in osst_configure_onstream() argument
2500 int dev = TAPE_NR(STp->devt); in osst_configure_onstream()
2508 if (STp->ready != ST_READY) { in osst_configure_onstream()
2515 if (STp->os_fw_rev < 10600) { in osst_configure_onstream()
2516 …printk(KERN_INFO "osst%i:I: Old OnStream firmware revision detected (%s),\n", dev, STp->device->re… in osst_configure_onstream()
2530 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_READ, STp->timeout, 0, TRUE); in osst_configure_onstream()
2538 if ((STp->buffer)->syscall_result != 0) { in osst_configure_onstream()
2543 header = (osst_mode_parameter_header_t *) (STp->buffer)->b_data; in osst_configure_onstream()
2544 …bs = (osst_block_size_page_t *) ((STp->buffer)->b_data + sizeof(osst_mode_parameter_header_t) + he… in osst_configure_onstream()
2567 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_WRITE, STp->timeout, 0, TRUE); in osst_configure_onstream()
2569 if ((STp->buffer)->syscall_result != 0) { in osst_configure_onstream()
2580 osst_set_retries(STp, aSRpnt, 0); in osst_configure_onstream()
2598 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 0] = VENDOR_IDENT_PAGE | (1 << 7); in osst_configure_onstream()
2599 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 1] = 6; in osst_configure_onstream()
2600 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 2] = 'L'; in osst_configure_onstream()
2601 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 3] = 'I'; in osst_configure_onstream()
2602 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 4] = 'N'; in osst_configure_onstream()
2603 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 5] = '4'; in osst_configure_onstream()
2604 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 6] = 0; in osst_configure_onstream()
2605 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 7] = 0; in osst_configure_onstream()
2607 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_WRITE, STp->timeout, 0, TRUE); in osst_configure_onstream()
2610 if ((STp->buffer)->syscall_result != 0) { in osst_configure_onstream()
2612 (char *) ((STp->buffer)->b_data + MODE_HEADER_LENGTH + 2)); in osst_configure_onstream()
2622 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_READ, STp->timeout, 0, TRUE); in osst_configure_onstream()
2625 if ((STp->buffer)->syscall_result != 0) { in osst_configure_onstream()
2630 header = (osst_mode_parameter_header_t *) (STp->buffer)->b_data; in osst_configure_onstream()
2631 cp = (osst_capabilities_page_t *) ((STp->buffer)->b_data + in osst_configure_onstream()
2642 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_READ, STp->timeout, 0, TRUE); in osst_configure_onstream()
2645 if ((STp->buffer)->syscall_result != 0) { in osst_configure_onstream()
2650 header = (osst_mode_parameter_header_t *) (STp->buffer)->b_data; in osst_configure_onstream()
2651 prm = (osst_tape_paramtr_page_t *) ((STp->buffer)->b_data + in osst_configure_onstream()
2654 STp->density = prm->density; in osst_configure_onstream()
2655 STp->capacity = ntohs(prm->segtrk) * ntohs(prm->trks); in osst_configure_onstream()
2658 dev, STp->density, STp->capacity / 32, drive_buffer_size); in osst_configure_onstream()
2668 static int cross_eof(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt, int forward) in cross_eof() argument
2671 int dev = TAPE_NR(STp->devt); in cross_eof()
2681 result = osst_space_over_filemarks_forward_slow(STp, aSRpnt, MTFSF, 1); in cross_eof()
2685 result = osst_seek_logical_blk(STp, aSRpnt, STp->logical_blk_num - 1); in cross_eof()
2697 static int osst_get_frame_position(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt) in osst_get_frame_position() argument
2706 char * olddata = STp->buffer->b_data; in osst_get_frame_position()
2707 int oldsize = STp->buffer->buffer_size; in osst_get_frame_position()
2708 int dev = TAPE_NR(STp->devt); in osst_get_frame_position()
2710 if (STp->ready != ST_READY) return (-EIO); in osst_get_frame_position()
2715 STp->buffer->b_data = mybuf; STp->buffer->buffer_size = 24; in osst_get_frame_position()
2716 SRpnt = osst_do_scsi(*aSRpnt, STp, scmd, 20, SCSI_DATA_READ, in osst_get_frame_position()
2717 STp->timeout, MAX_RETRIES, TRUE); in osst_get_frame_position()
2719 STp->buffer->b_data = olddata; STp->buffer->buffer_size = oldsize; in osst_get_frame_position()
2724 if (STp->buffer->syscall_result) in osst_get_frame_position()
2736 STp->buffer->b_data = mybuf; STp->buffer->buffer_size = 24; in osst_get_frame_position()
2737 SRpnt = osst_do_scsi(SRpnt, STp, scmd, 20, SCSI_DATA_READ, in osst_get_frame_position()
2738 STp->timeout, MAX_RETRIES, TRUE); in osst_get_frame_position()
2739 if (!STp->buffer->syscall_result) in osst_get_frame_position()
2742 STp->first_frame_position = ((STp->buffer)->b_data[4] << 24) in osst_get_frame_position()
2743 + ((STp->buffer)->b_data[5] << 16) in osst_get_frame_position()
2744 + ((STp->buffer)->b_data[6] << 8) in osst_get_frame_position()
2745 + (STp->buffer)->b_data[7]; in osst_get_frame_position()
2746 STp->last_frame_position = ((STp->buffer)->b_data[ 8] << 24) in osst_get_frame_position()
2747 + ((STp->buffer)->b_data[ 9] << 16) in osst_get_frame_position()
2748 + ((STp->buffer)->b_data[10] << 8) in osst_get_frame_position()
2749 + (STp->buffer)->b_data[11]; in osst_get_frame_position()
2750 STp->cur_frames = (STp->buffer)->b_data[15]; in osst_get_frame_position()
2754 STp->first_frame_position, STp->last_frame_position, in osst_get_frame_position()
2755 ((STp->buffer)->b_data[0]&0x80)?" (BOP)": in osst_get_frame_position()
2756 ((STp->buffer)->b_data[0]&0x40)?" (EOP)":"", in osst_get_frame_position()
2757 STp->cur_frames); in osst_get_frame_position()
2760 if (STp->cur_frames == 0 && STp->first_frame_position != STp->last_frame_position) { in osst_get_frame_position()
2763 STp->first_frame_position, STp->last_frame_position, STp->cur_frames); in osst_get_frame_position()
2765 STp->first_frame_position = STp->last_frame_position; in osst_get_frame_position()
2768 STp->buffer->b_data = olddata; STp->buffer->buffer_size = oldsize; in osst_get_frame_position()
2770 return (result == 0 ? STp->first_frame_position : result); in osst_get_frame_position()
2775 static int osst_set_frame_position(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt, int ppos, int skip) in osst_set_frame_position() argument
2782 int dev = TAPE_NR(STp->devt); in osst_set_frame_position()
2784 if (STp->ready != ST_READY) return (-EIO); in osst_set_frame_position()
2786 STps = &(STp->ps[STp->partition]); in osst_set_frame_position()
2788 if (ppos < 0 || ppos > STp->capacity) { in osst_set_frame_position()
2790 pp = ppos = ppos < 0 ? 0 : (STp->capacity - 1); in osst_set_frame_position()
2809 SRpnt = osst_do_scsi(*aSRpnt, STp, scmd, 0, SCSI_DATA_NONE, STp->long_timeout, in osst_set_frame_position()
2815 if ((STp->buffer)->syscall_result != 0) { in osst_set_frame_position()
2818 dev, STp->first_frame_position, pp); in osst_set_frame_position()
2823 osst_wait_ready(STp, aSRpnt, 5 * 60, OSST_WAIT_POSITION_COMPLETE); in osst_set_frame_position()
2825 STp->first_frame_position = STp->last_frame_position = ppos; in osst_set_frame_position()
2829 STp->frame_in_buffer = 0; in osst_set_frame_position()
2833 static int osst_write_trailer(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt, int leave_at_EOT) in osst_write_trailer() argument
2835 ST_partstat * STps = &(STp->ps[STp->partition]); in osst_write_trailer()
2838 if (STp->write_type != OS_WRITE_NEW_MARK) { in osst_write_trailer()
2840 result = osst_flush_drive_buffer(STp, aSRpnt); in osst_write_trailer()
2842 result = osst_write_filemark(STp, aSRpnt); in osst_write_trailer()
2849 result = osst_write_eod(STp, aSRpnt); in osst_write_trailer()
2850 osst_write_header(STp, aSRpnt, leave_at_EOT); in osst_write_trailer()
2860 static int osst_flush_write_buffer(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt) in osst_flush_write_buffer() argument
2867 int dev = TAPE_NR(STp->devt); in osst_flush_write_buffer()
2869 if ((STp->buffer)->writing) { in osst_flush_write_buffer()
2870 if (SRpnt == (STp->buffer)->last_SRpnt) in osst_flush_write_buffer()
2881 osst_write_behind_check(STp); in osst_flush_write_buffer()
2882 if ((STp->buffer)->syscall_result) { in osst_flush_write_buffer()
2886 dev, (STp->buffer)->midlevel_result); in osst_flush_write_buffer()
2888 if ((STp->buffer)->midlevel_result == INT_MAX) in osst_flush_write_buffer()
2895 if (STp->dirty == 1) { in osst_flush_write_buffer()
2897 STp->write_count++; in osst_flush_write_buffer()
2898 STps = &(STp->ps[STp->partition]); in osst_flush_write_buffer()
2900 offset = STp->buffer->buffer_bytes; in osst_flush_write_buffer()
2901 blks = (offset + STp->block_size - 1) / STp->block_size; in osst_flush_write_buffer()
2905 osst_zero_buffer_tail(STp->buffer); in osst_flush_write_buffer()
2908 if (STp->poll) in osst_flush_write_buffer()
2909 result = osst_wait_frame (STp, aSRpnt, STp->first_frame_position, -50, 120); in osst_flush_write_buffer()
2916 switch (STp->write_type) { in osst_flush_write_buffer()
2921 dev, blks, STp->frame_seq_number, in osst_flush_write_buffer()
2922 STp->logical_blk_num - blks, STp->logical_blk_num - 1); in osst_flush_write_buffer()
2924 osst_init_aux(STp, OS_FRAME_TYPE_DATA, STp->frame_seq_number++, in osst_flush_write_buffer()
2925 STp->logical_blk_num - blks, STp->block_size, blks); in osst_flush_write_buffer()
2928 osst_init_aux(STp, OS_FRAME_TYPE_EOD, STp->frame_seq_number++, in osst_flush_write_buffer()
2929 STp->logical_blk_num, 0, 0); in osst_flush_write_buffer()
2932 osst_init_aux(STp, OS_FRAME_TYPE_MARKER, STp->frame_seq_number++, in osst_flush_write_buffer()
2933 STp->logical_blk_num++, 0, blks=1); in osst_flush_write_buffer()
2936 osst_init_aux(STp, OS_FRAME_TYPE_HEADER, 0, 0, 0, blks=0); in osst_flush_write_buffer()
2939 osst_init_aux(STp, OS_FRAME_TYPE_FILL, 0, 0, 0, 0); in osst_flush_write_buffer()
2947 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, transfer, SCSI_DATA_WRITE, in osst_flush_write_buffer()
2948 STp->timeout, MAX_WRITE_RETRIES, TRUE); in osst_flush_write_buffer()
2953 if ((STp->buffer)->syscall_result != 0) { in osst_flush_write_buffer()
2963 STp->dirty = 0; in osst_flush_write_buffer()
2964 (STp->buffer)->buffer_bytes = 0; in osst_flush_write_buffer()
2968 if (osst_write_error_recovery(STp, aSRpnt, 1)) { in osst_flush_write_buffer()
2976 STp->first_frame_position++; in osst_flush_write_buffer()
2977 STp->dirty = 0; in osst_flush_write_buffer()
2978 (STp->buffer)->buffer_bytes = 0; in osst_flush_write_buffer()
2990 static int osst_flush_buffer(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int seek_next) in osst_flush_buffer() argument
2995 int dev = TAPE_NR(STp->devt); in osst_flush_buffer()
3002 if( STp->device->was_reset ) in osst_flush_buffer()
3005 if (STp->ready != ST_READY) in osst_flush_buffer()
3008 STps = &(STp->ps[STp->partition]); in osst_flush_buffer()
3009 if (STps->rw == ST_WRITING || STp->dirty) { /* Writing */ in osst_flush_buffer()
3010 STp->write_type = OS_WRITE_DATA; in osst_flush_buffer()
3011 return osst_flush_write_buffer(STp, aSRpnt); in osst_flush_buffer()
3013 if (STp->block_size == 0) in osst_flush_buffer()
3020 if (!STp->can_bsr) { in osst_flush_buffer()
3021 backspace = ((STp->buffer)->buffer_bytes + (STp->buffer)->read_pointer) / STp->block_size - in osst_flush_buffer()
3022 ((STp->buffer)->read_pointer + STp->block_size - 1 ) / STp->block_size ; in osst_flush_buffer()
3023 (STp->buffer)->buffer_bytes = 0; in osst_flush_buffer()
3024 (STp->buffer)->read_pointer = 0; in osst_flush_buffer()
3025 STp->frame_in_buffer = 0; /* FIXME is this relevant w. OSST? */ in osst_flush_buffer()
3030 result = cross_eof(STp, aSRpnt, FALSE); /* Back over the EOF hit */ in osst_flush_buffer()
3040 result = osst_seek_logical_blk(STp, aSRpnt, STp->logical_blk_num - backspace); in osst_flush_buffer()
3052 static int osst_write_frame(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int synchronous) in osst_write_frame() argument
3058 int dev = TAPE_NR(STp->devt); in osst_write_frame()
3061 if ((!STp-> raw) && (STp->first_frame_position == 0xbae)) { /* _must_ preserve buffer! */ in osst_write_frame()
3065 if (osst_flush_drive_buffer(STp, aSRpnt) < 0) { in osst_write_frame()
3069 if (osst_get_frame_position(STp, aSRpnt) < 0xbb8) { in osst_write_frame()
3073 osst_position_tape_and_confirm(STp, aSRpnt, 0xbb8); in osst_write_frame()
3077 if (STp->poll) in osst_write_frame()
3078 osst_wait_frame (STp, aSRpnt, STp->first_frame_position, -50, 60); in osst_write_frame()
3083 STp->ps[STp->partition].rw = ST_WRITING; in osst_write_frame()
3084 STp->write_type = OS_WRITE_DATA; in osst_write_frame()
3090 blks = STp->buffer->buffer_bytes / STp->block_size; in osst_write_frame()
3094 STp->frame_seq_number, STp->logical_blk_num - blks, STp->logical_blk_num - 1); in osst_write_frame()
3096 osst_init_aux(STp, OS_FRAME_TYPE_DATA, STp->frame_seq_number++, in osst_write_frame()
3097 STp->logical_blk_num - blks, STp->block_size, blks); in osst_write_frame()
3101 STp->write_pending = 1; in osst_write_frame()
3103 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, OS_FRAME_SIZE, SCSI_DATA_WRITE, STp->timeout, in osst_write_frame()
3110 if (STp->buffer->syscall_result != 0) { in osst_write_frame()
3121 if (osst_write_error_recovery(STp, aSRpnt, 1)) in osst_write_frame()
3126 STp->first_frame_position++; in osst_write_frame()
3129 STp->write_count++; in osst_write_frame()
3147 OS_Scsi_Tape * STp; in osst_write() local
3153 STp = os_scsi_tapes[dev]; in osst_write()
3155 if (down_interruptible(&STp->lock)) in osst_write()
3164 if( !scsi_block_when_processing_errors(STp->device) ) { in osst_write()
3175 if (STp->ready != ST_READY) { in osst_write()
3176 if (STp->ready == ST_NO_TAPE) in osst_write()
3182 STm = &(STp->modes[STp->current_mode]); in osst_write()
3194 if (STp->device->was_reset) { in osst_write()
3200 if (!STp->in_use) { in osst_write()
3207 if (STp->write_prot) { in osst_write()
3213 if (STp->block_size != 0 && (count % STp->block_size) != 0) { in osst_write()
3215 dev, (unsigned long)count, STp->block_size<1024? in osst_write()
3216 STp->block_size:STp->block_size/1024, STp->block_size<1024?'b':'k'); in osst_write()
3221 if (STp->first_frame_position >= STp->capacity - OSST_EOM_RESERVE) { in osst_write()
3223 dev, STp->first_frame_position); in osst_write()
3228 STps = &(STp->ps[STp->partition]); in osst_write()
3230 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED && in osst_write()
3231 !osst_int_ioctl(STp, &SRpnt, MTLOCK, 0)) in osst_write()
3232 STp->door_locked = ST_LOCKED_AUTO; in osst_write()
3240 retval = osst_flush_buffer(STp, &SRpnt, 0); in osst_write()
3247 if (!STp->header_ok || in osst_write()
3248 (STp->first_frame_position == STp->first_data_ppos && STps->drv_block < 0) || in osst_write()
3250 STp->wrt_pass_cntr++; in osst_write()
3253 dev, STp->wrt_pass_cntr); in osst_write()
3255 osst_reset_header(STp, &SRpnt); in osst_write()
3260 if ((STp->fast_open && osst_verify_position(STp, &SRpnt)) || in osst_write()
3262 if (STp->first_frame_position == STp->eod_frame_ppos) { /* at EOD */ in osst_write()
3263 STps->drv_file = STp->filemark_cnt; in osst_write()
3276 if ((STps->drv_file + STps->drv_block) > 0 && STps->drv_file < STp->filemark_cnt) { in osst_write()
3277 STp->filemark_cnt = STps->drv_file; in osst_write()
3278 STp->last_mark_ppos = in osst_write()
3279 ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[STp->filemark_cnt-1]); in osst_write()
3282 dev, STps->drv_file, STp->wrt_pass_cntr); in osst_write()
3289 dev, STp->filemark_cnt, STp->last_mark_ppos, STp->last_mark_lbn); in osst_write()
3293 STp->fast_open = FALSE; in osst_write()
3295 if (!STp->header_ok) { in osst_write()
3303 if ((STp->buffer)->writing) { in osst_write()
3305 osst_write_behind_check(STp); in osst_write()
3306 if ((STp->buffer)->syscall_result) { in osst_write()
3310 (STp->buffer)->midlevel_result); in osst_write()
3312 if ((STp->buffer)->midlevel_result == INT_MAX) in osst_write()
3339 write_threshold = (STp->buffer)->buffer_blocks * STp->block_size; in osst_write()
3348 STp->logical_blk_num, STp->frame_seq_number, STp->first_frame_position); in osst_write()
3351 while ((STp->buffer)->buffer_bytes + count > write_threshold) in osst_write()
3354 do_count = (STp->buffer)->buffer_blocks * STp->block_size - in osst_write()
3355 (STp->buffer)->buffer_bytes; in osst_write()
3359 i = append_to_buffer(b_point, STp->buffer, do_count); in osst_write()
3365 blks = do_count / STp->block_size; in osst_write()
3366 STp->logical_blk_num += blks; /* logical_blk_num is incremented as data is moved from user */ in osst_write()
3368 i = osst_write_frame(STp, &SRpnt, TRUE); in osst_write()
3371 transfer = STp->buffer->writing; /* FIXME -- check this logic */ in osst_write()
3376 STps->drv_block += (do_count - transfer) / STp->block_size; in osst_write()
3404 STp->buffer->buffer_bytes = 0; in osst_write()
3405 STp->dirty = 0; in osst_write()
3417 STp->buffer->buffer_bytes = 0; in osst_write()
3418 STp->dirty = 0; in osst_write()
3422 STp->dirty = 1; in osst_write()
3423 i = append_to_buffer(b_point, STp->buffer, count); in osst_write()
3428 blks = count / STp->block_size; in osst_write()
3429 STp->logical_blk_num += blks; in osst_write()
3437 if (doing_write && (STp->buffer)->syscall_result != 0) { in osst_write()
3438 retval = (STp->buffer)->syscall_result; in osst_write()
3442 if (STm->do_async_writes && ((STp->buffer)->buffer_bytes >= STp->write_threshold)) { in osst_write()
3444 (STp->buffer)->writing = ((STp->buffer)->buffer_bytes / in osst_write()
3445 STp->block_size) * STp->block_size; in osst_write()
3446 STp->dirty = !((STp->buffer)->writing == in osst_write()
3447 (STp->buffer)->buffer_bytes); in osst_write()
3449 i = osst_write_frame(STp, &SRpnt, FALSE); in osst_write()
3466 up(&STp->lock); in osst_write()
3479 OS_Scsi_Tape * STp; in osst_read() local
3486 STp = os_scsi_tapes[dev]; in osst_read()
3488 if (down_interruptible(&STp->lock)) in osst_read()
3497 if( !scsi_block_when_processing_errors(STp->device) ) { in osst_read()
3508 if (STp->ready != ST_READY) { in osst_read()
3509 if (STp->ready == ST_NO_TAPE) in osst_read()
3515 STm = &(STp->modes[STp->current_mode]); in osst_read()
3521 if (!STp->in_use) { in osst_read()
3528 if (!STp->header_ok) { in osst_read()
3533 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED && in osst_read()
3534 !osst_int_ioctl(STp, &SRpnt, MTLOCK, 0)) in osst_read()
3535 STp->door_locked = ST_LOCKED_AUTO; in osst_read()
3537 STps = &(STp->ps[STp->partition]); in osst_read()
3539 retval = osst_flush_buffer(STp, &SRpnt, 0); in osst_read()
3546 if ((count % STp->block_size) != 0) { in osst_read()
3549 STp->block_size<1024?STp->block_size:STp->block_size/1024, STp->block_size<1024?'b':'k'); in osst_read()
3555 STps->eof, (STp->buffer)->buffer_bytes); in osst_read()
3557 if ((STp->buffer)->buffer_bytes == 0 && in osst_read()
3579 for (total = 0, special = 0; total < count - STp->block_size + 1 && !special; ) { in osst_read()
3582 if ((STp->buffer)->buffer_bytes == 0) { in osst_read()
3585 special = osst_get_logical_frame(STp, &SRpnt, STp->frame_seq_number, 0); in osst_read()
3587 STp->frame_in_buffer = 0; in osst_read()
3594 if ((STp->buffer)->buffer_bytes > 0) { in osst_read()
3598 STps->eof, (STp->buffer)->buffer_bytes, count - total); in osst_read()
3601 transfer = (((STp->buffer)->buffer_bytes < count - total ? in osst_read()
3602 (STp->buffer)->buffer_bytes : count - total)/ in osst_read()
3603 STp->block_size) * STp->block_size; in osst_read()
3608 dev, count, STp->block_size < 1024? in osst_read()
3609 STp->block_size:STp->block_size/1024, in osst_read()
3610 STp->block_size<1024?'b':'k'); in osst_read()
3613 i = from_buffer(STp->buffer, buf, transfer); in osst_read()
3618 STp->logical_blk_num += transfer / STp->block_size; in osst_read()
3619 STps->drv_block += transfer / STp->block_size; in osst_read()
3625 if ((STp->buffer)->buffer_bytes == 0) { in osst_read()
3629 dev, STp->frame_seq_number); in osst_read()
3631 STp->frame_in_buffer = 0; in osst_read()
3632 STp->frame_seq_number++; /* frame to look for next time */ in osst_read()
3639 STps->eof = (STp->first_frame_position >= STp->eod_frame_ppos)?ST_EOD_2:ST_FM; in osst_read()
3662 up(&STp->lock); in osst_read()
3669 static void osst_log_options(OS_Scsi_Tape *STp, ST_mode *STm, int dev) in osst_log_options() argument
3673 dev, STp->current_mode, STm->do_buffer_writes, STm->do_async_writes, in osst_log_options()
3677 dev, STp->can_bsr, STp->two_fm, STp->fast_mteom, STp->do_auto_lock); in osst_log_options()
3680 dev, STm->defaults_for_writes, STp->omit_blklims, STp->can_partitions, in osst_log_options()
3681 STp->scsi2_logical); in osst_log_options()
3692 static int osst_set_options(OS_Scsi_Tape *STp, long options) in osst_set_options() argument
3697 int dev = TAPE_NR(STp->devt); in osst_set_options()
3699 STm = &(STp->modes[STp->current_mode]); in osst_set_options()
3701 memcpy(STm, &(STp->modes[0]), sizeof(ST_mode)); in osst_set_options()
3706 dev, STp->current_mode); in osst_set_options()
3716 STp->two_fm = (options & MT_ST_TWO_FM) != 0; in osst_set_options()
3717 STp->fast_mteom = (options & MT_ST_FAST_MTEOM) != 0; in osst_set_options()
3718 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0; in osst_set_options()
3719 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0; in osst_set_options()
3720 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0; in osst_set_options()
3721 if ((STp->device)->scsi_level >= SCSI_2) in osst_set_options()
3722 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0; in osst_set_options()
3723 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0; in osst_set_options()
3728 osst_log_options(STp, STm, dev); in osst_set_options()
3741 STp->two_fm = value; in osst_set_options()
3743 STp->fast_mteom = value; in osst_set_options()
3745 STp->do_auto_lock = value; in osst_set_options()
3747 STp->can_bsr = value; in osst_set_options()
3749 STp->omit_blklims = value; in osst_set_options()
3750 if ((STp->device)->scsi_level >= SCSI_2 && in osst_set_options()
3752 STp->can_partitions = value; in osst_set_options()
3754 STp->scsi2_logical = value; in osst_set_options()
3761 osst_log_options(STp, STm, dev); in osst_set_options()
3770 STp->write_threshold = value; in osst_set_options()
3794 STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ; in osst_set_options()
3799 STp->timeout = value * HZ; in osst_set_options()
3819 STp->default_drvbuffer = 0xff; in osst_set_options()
3823 STp->default_drvbuffer = value & 7; in osst_set_options()
3825 dev, STp->default_drvbuffer); in osst_set_options()
3848 static int osst_int_ioctl(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, unsigned int cmd_in, unsigned… in osst_int_ioctl() argument
3859 int dev = TAPE_NR(STp->devt); in osst_int_ioctl()
3861 if (STp->ready != ST_READY && cmd_in != MTLOAD) { in osst_int_ioctl()
3862 if (STp->ready == ST_NO_TAPE) in osst_int_ioctl()
3867 timeout = STp->long_timeout; in osst_int_ioctl()
3868 STps = &(STp->ps[STp->partition]); in osst_int_ioctl()
3872 frame_seq_numbr = STp->frame_seq_number; in osst_int_ioctl()
3873 logical_blk_num = STp->logical_blk_num; in osst_int_ioctl()
3880 if (STp->raw) in osst_int_ioctl()
3882 if (STp->linux_media) in osst_int_ioctl()
3883 ioctl_result = osst_space_over_filemarks_forward_fast(STp, &SRpnt, cmd_in, arg); in osst_int_ioctl()
3885 ioctl_result = osst_space_over_filemarks_forward_slow(STp, &SRpnt, cmd_in, arg); in osst_int_ioctl()
3895 if (STp->raw) in osst_int_ioctl()
3897 ioctl_result = osst_space_over_filemarks_backward(STp, &SRpnt, cmd_in, arg); in osst_int_ioctl()
3919 ioctl_result = osst_seek_logical_blk(STp, &SRpnt, logical_blk_num); in osst_int_ioctl()
3963 if ((STps->rw == ST_WRITING || STp->dirty) && !(STp->device)->was_reset) { in osst_int_ioctl()
3964 STp->write_type = OS_WRITE_DATA; in osst_int_ioctl()
3965 ioctl_result = osst_flush_write_buffer(STp, &SRpnt); in osst_int_ioctl()
3973 ioctl_result |= osst_write_filemark(STp, &SRpnt); in osst_int_ioctl()
3979 if (STp->write_prot) in osst_int_ioctl()
3981 if (!STp->raw) in osst_int_ioctl()
3989 timeout = STp->timeout; in osst_int_ioctl()
4007 if (STp->ready == ST_NO_TAPE) in osst_int_ioctl()
4016 timeout = STp->timeout; in osst_int_ioctl()
4049 if ((osst_position_tape_and_confirm(STp, &SRpnt, STp->eod_frame_ppos) < 0) || in osst_int_ioctl()
4050 (osst_get_logical_frame(STp, &SRpnt, -1, 0) < 0)) { in osst_int_ioctl()
4054 if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_EOD) { in osst_int_ioctl()
4061 ioctl_result = osst_set_frame_position(STp, &SRpnt, STp->eod_frame_ppos, 0); in osst_int_ioctl()
4062 fileno = STp->filemark_cnt; in osst_int_ioctl()
4067 if (STp->write_prot) in osst_int_ioctl()
4069 ioctl_result = osst_reset_header(STp, &SRpnt); in osst_int_ioctl()
4070 i = osst_write_eod(STp, &SRpnt); in osst_int_ioctl()
4072 i = osst_position_tape_and_confirm(STp, &SRpnt, STp->eod_frame_ppos); in osst_int_ioctl()
4109 !STp->dirty && in osst_int_ioctl()
4110 ((STp->buffer)->buffer_bytes == 0) && in osst_int_ioctl()
4120 STp->block_size = (arg & MT_ST_BLKSIZE_MASK); in osst_int_ioctl()
4122 dev, STp->block_size); in osst_int_ioctl()
4129 if (STp->dirty || (STp->buffer)->buffer_bytes != 0) in osst_int_ioctl()
4133 (arg & MT_ST_BLKSIZE_MASK) != STp->block_size ) { in osst_int_ioctl()
4145 SRpnt = osst_do_scsi(SRpnt, STp, cmd, datalen, direction, timeout, MAX_RETRIES, TRUE); in osst_int_ioctl()
4147 ioctl_result = (STp->buffer)->syscall_result; in osst_int_ioctl()
4157 STp->frame_seq_number = frame_seq_numbr; in osst_int_ioctl()
4158 STp->logical_blk_num = logical_blk_num; in osst_int_ioctl()
4182 STp->door_locked = ST_LOCKED_EXPLICIT; in osst_int_ioctl()
4184 STp->door_locked = ST_UNLOCKED; in osst_int_ioctl()
4189 ioctl_result = osst_seek_logical_blk(STp, &SRpnt, STp->logical_blk_num-1); in osst_int_ioctl()
4191 STp->logical_blk_num++; in osst_int_ioctl()
4192 STp->frame_seq_number++; in osst_int_ioctl()
4193 STp->frame_in_buffer = 0; in osst_int_ioctl()
4194 STp->buffer->read_pointer = 0; in osst_int_ioctl()
4197 STps->eof = (STp->first_frame_position >= STp->eod_frame_ppos)?ST_EOD:ST_FM; in osst_int_ioctl()
4202 STp->rew_at_close = 0; in osst_int_ioctl()
4205 STp->ps[i].rw = ST_IDLE; in osst_int_ioctl()
4206 STp->ps[i].last_block_valid = FALSE;/* FIXME - where else is this field maintained? */ in osst_int_ioctl()
4208 STp->partition = 0; in osst_int_ioctl()
4212 ioctl_result = osst_position_tape_and_confirm(STp, &SRpnt, STp->first_data_ppos); in osst_int_ioctl()
4218 if (osst_position_tape_and_confirm(STp, &SRpnt, STp->first_data_ppos) < 0) in osst_int_ioctl()
4224 if (osst_position_tape_and_confirm(STp, &SRpnt, STp->eod_frame_ppos) < 0) in osst_int_ioctl()
4227 STps->drv_file = STp->filemark_cnt; in osst_int_ioctl()
4234 STp->header_ok = 0; in osst_int_ioctl()
4236 STp->header_ok = 0; in osst_int_ioctl()
4249 STp->door_locked = ST_LOCK_FAILS; in osst_int_ioctl()
4251 if (cmd_in == MTLOAD && osst_wait_for_medium(STp, &SRpnt, 60)) in osst_int_ioctl()
4252 ioctl_result = osst_wait_ready(STp, &SRpnt, 5 * 60, OSST_WAIT_POSITION_COMPLETE); in osst_int_ioctl()
4258 ioctl_result?"fail":"success", STp->first_frame_position, STp->frame_seq_number, in osst_int_ioctl()
4259 STp->logical_blk_num, STp->buffer->buffer_bytes, STps->drv_file, STps->drv_block); in osst_int_ioctl()
4272 OS_Scsi_Tape * STp; in os_scsi_tape_open() local
4278 if (dev >= osst_template.dev_max || (STp = os_scsi_tapes[dev]) == NULL || !STp->device) in os_scsi_tape_open()
4281 if( !scsi_block_when_processing_errors(STp->device) ) { in os_scsi_tape_open()
4285 if (STp->in_use) { in os_scsi_tape_open()
4291 STp->in_use = 1; in os_scsi_tape_open()
4292 STp->rew_at_close = (MINOR(inode->i_rdev) & 0x80) == 0; in os_scsi_tape_open()
4294 if (STp->device->host->hostt->module) in os_scsi_tape_open()
4295 __MOD_INC_USE_COUNT(STp->device->host->hostt->module); in os_scsi_tape_open()
4298 STp->device->access_count++; in os_scsi_tape_open()
4300 if (mode != STp->current_mode) { in os_scsi_tape_open()
4304 dev, STp->current_mode, mode); in os_scsi_tape_open()
4307 STp->current_mode = mode; in os_scsi_tape_open()
4309 STm = &(STp->modes[STp->current_mode]); in os_scsi_tape_open()
4312 STp->write_prot = ((flags & O_ACCMODE) == O_RDONLY); in os_scsi_tape_open()
4314 STp->raw = (MINOR(inode->i_rdev) & 0x40) != 0; in os_scsi_tape_open()
4315 if (STp->raw) in os_scsi_tape_open()
4316 STp->header_ok = 0; in os_scsi_tape_open()
4319 need_dma_buffer = STp->restr_dma; in os_scsi_tape_open()
4325 STp->buffer = new_tape_buffer(FALSE, need_dma_buffer); in os_scsi_tape_open()
4326 if (STp->buffer == NULL) { in os_scsi_tape_open()
4333 STp->buffer = osst_buffers[i]; in os_scsi_tape_open()
4334 (STp->buffer)->in_use = 1; in os_scsi_tape_open()
4335 (STp->buffer)->writing = 0; in os_scsi_tape_open()
4336 (STp->buffer)->syscall_result = 0; in os_scsi_tape_open()
4337 (STp->buffer)->use_sg = STp->device->host->sg_tablesize; in os_scsi_tape_open()
4340 if (!(STp->buffer)->use_sg) in os_scsi_tape_open()
4341 (STp->buffer)->buffer_size = (STp->buffer)->sg[0].length; in os_scsi_tape_open()
4343 for (i=0, (STp->buffer)->buffer_size = 0; i < (STp->buffer)->use_sg && in os_scsi_tape_open()
4344 i < (STp->buffer)->sg_segs; i++) in os_scsi_tape_open()
4345 (STp->buffer)->buffer_size += (STp->buffer)->sg[i].length; in os_scsi_tape_open()
4348 STp->dirty = 0; in os_scsi_tape_open()
4350 STps = &(STp->ps[i]); in os_scsi_tape_open()
4353 STp->ready = ST_READY; in os_scsi_tape_open()
4355 STp->nbr_waits = STp->nbr_finished = 0; in os_scsi_tape_open()
4361 SRpnt = osst_do_scsi(NULL, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_READY_RETRIES, TRUE); in os_scsi_tape_open()
4363 retval = (STp->buffer)->syscall_result; in os_scsi_tape_open()
4377 SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, SCSI_DATA_NONE, in os_scsi_tape_open()
4378 STp->timeout, MAX_READY_RETRIES, TRUE); in os_scsi_tape_open()
4380 osst_wait_ready(STp, &SRpnt, (SRpnt->sr_sense_buffer[13]==1?15:3) * 60, 0); in os_scsi_tape_open()
4387 STp->header_ok = 0; in os_scsi_tape_open()
4394 SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, SCSI_DATA_NONE, in os_scsi_tape_open()
4395 STp->timeout, MAX_READY_RETRIES, TRUE); in os_scsi_tape_open()
4401 STp->device->was_reset = 0; in os_scsi_tape_open()
4402 STp->partition = STp->new_partition = 0; in os_scsi_tape_open()
4403 if (STp->can_partitions) in os_scsi_tape_open()
4404 STp->nbr_partitions = 1; /* This guess will be updated later if necessary */ in os_scsi_tape_open()
4406 STps = &(STp->ps[i]); in os_scsi_tape_open()
4415 STp->recover_count = 0; in os_scsi_tape_open()
4421 if (!STp->buffer->syscall_result && STp->header_ok && in os_scsi_tape_open()
4430 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_READ, STp->timeout, 0, TRUE); in os_scsi_tape_open()
4432 if (STp->buffer->syscall_result || in os_scsi_tape_open()
4433 STp->buffer->b_data[MODE_HEADER_LENGTH + 2] != 'L' || in os_scsi_tape_open()
4434 STp->buffer->b_data[MODE_HEADER_LENGTH + 3] != 'I' || in os_scsi_tape_open()
4435 STp->buffer->b_data[MODE_HEADER_LENGTH + 4] != 'N' || in os_scsi_tape_open()
4436 STp->buffer->b_data[MODE_HEADER_LENGTH + 5] != '4' ) { in os_scsi_tape_open()
4439 STp->buffer->b_data[MODE_HEADER_LENGTH + 2], in os_scsi_tape_open()
4440 STp->buffer->b_data[MODE_HEADER_LENGTH + 3], in os_scsi_tape_open()
4441 STp->buffer->b_data[MODE_HEADER_LENGTH + 4], in os_scsi_tape_open()
4442 STp->buffer->b_data[MODE_HEADER_LENGTH + 5]); in os_scsi_tape_open()
4444 STp->header_ok = 0; in os_scsi_tape_open()
4446 i = STp->first_frame_position; in os_scsi_tape_open()
4447 if (STp->header_ok && i == osst_get_frame_position(STp, &SRpnt)) { in os_scsi_tape_open()
4448 if (STp->door_locked == ST_UNLOCKED) { in os_scsi_tape_open()
4449 if (osst_int_ioctl(STp, &SRpnt, MTLOCK, 0)) in os_scsi_tape_open()
4452 STp->door_locked = ST_LOCKED_AUTO; in os_scsi_tape_open()
4454 if (!STp->frame_in_buffer) { in os_scsi_tape_open()
4455 STp->block_size = (STm->default_blksize > 0) ? in os_scsi_tape_open()
4457 STp->buffer->buffer_bytes = STp->buffer->read_pointer = 0; in os_scsi_tape_open()
4459 STp->buffer->buffer_blocks = OS_DATA_SIZE / STp->block_size; in os_scsi_tape_open()
4460 STp->fast_open = TRUE; in os_scsi_tape_open()
4465 if (i != STp->first_frame_position) in os_scsi_tape_open()
4467 dev, i, STp->first_frame_position); in os_scsi_tape_open()
4469 STp->header_ok = 0; in os_scsi_tape_open()
4471 STp->fast_open = FALSE; in os_scsi_tape_open()
4473 if ((STp->buffer)->syscall_result != 0 && /* in all error conditions except no medium */ in os_scsi_tape_open()
4481 (STp->buffer)->b_data[0] = cmd[4] - 1; in os_scsi_tape_open()
4482 (STp->buffer)->b_data[1] = 0; /* Medium Type - ignoring */ in os_scsi_tape_open()
4483 (STp->buffer)->b_data[2] = 0; /* Reserved */ in os_scsi_tape_open()
4484 (STp->buffer)->b_data[3] = 0; /* Block Descriptor Length */ in os_scsi_tape_open()
4485 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 0] = 0x3f; in os_scsi_tape_open()
4486 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 1] = 1; in os_scsi_tape_open()
4487 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 2] = 2; in os_scsi_tape_open()
4488 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 3] = 3; in os_scsi_tape_open()
4493 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_WRITE, STp->timeout, 0, TRUE); in os_scsi_tape_open()
4495 STp->header_ok = 0; in os_scsi_tape_open()
4502 SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, SCSI_DATA_NONE, in os_scsi_tape_open()
4503 STp->timeout, MAX_READY_RETRIES, TRUE); in os_scsi_tape_open()
4509 STp->device->was_reset = 0; in os_scsi_tape_open()
4510 STp->partition = STp->new_partition = 0; in os_scsi_tape_open()
4511 if (STp->can_partitions) in os_scsi_tape_open()
4512 STp->nbr_partitions = 1; /* This guess will be updated later if necessary */ in os_scsi_tape_open()
4514 STps = &(STp->ps[i]); in os_scsi_tape_open()
4527 if (osst_wait_ready(STp, &SRpnt, 15 * 60, 0)) /* FIXME - not allowed with NOBLOCK */ in os_scsi_tape_open()
4530 if ((STp->buffer)->syscall_result != 0) { in os_scsi_tape_open()
4531 if ((STp->device)->scsi_level >= SCSI_2 && in os_scsi_tape_open()
4535 STp->ready = ST_NO_TAPE; in os_scsi_tape_open()
4537 STp->ready = ST_NOT_READY; in os_scsi_tape_open()
4540 STp->density = 0; /* Clear the erroneous "residue" */ in os_scsi_tape_open()
4541 STp->write_prot = 0; in os_scsi_tape_open()
4542 STp->block_size = 0; in os_scsi_tape_open()
4543 STp->ps[0].drv_file = STp->ps[0].drv_block = (-1); in os_scsi_tape_open()
4544 STp->partition = STp->new_partition = 0; in os_scsi_tape_open()
4545 STp->door_locked = ST_UNLOCKED; in os_scsi_tape_open()
4549 osst_configure_onstream(STp, &SRpnt); in os_scsi_tape_open()
4553 if (OS_FRAME_SIZE > (STp->buffer)->buffer_size && in os_scsi_tape_open()
4554 !enlarge_buffer(STp->buffer, OS_FRAME_SIZE, STp->restr_dma)) { in os_scsi_tape_open()
4561 if ((STp->buffer)->buffer_size >= OS_FRAME_SIZE) { in os_scsi_tape_open()
4563 i < STp->buffer->sg_segs && (b_size + STp->buffer->sg[i].length) <= OS_DATA_SIZE; in os_scsi_tape_open()
4564 b_size += STp->buffer->sg[i++].length); in os_scsi_tape_open()
4565 STp->buffer->aux = (os_aux_t *) (STp->buffer->sg[i].address + OS_DATA_SIZE - b_size); in os_scsi_tape_open()
4568 STp->buffer->b_data, STp->buffer->sg[0].address); in os_scsi_tape_open()
4570 STp->buffer->aux, i, STp->buffer->sg[i].address); in os_scsi_tape_open()
4573 STp->buffer->aux = NULL; /* this had better never happen! */ in os_scsi_tape_open()
4575 STp->block_size = STp->raw ? OS_FRAME_SIZE : ( in os_scsi_tape_open()
4577 STp->buffer->buffer_blocks = STp->raw ? 1 : OS_DATA_SIZE / STp->block_size; in os_scsi_tape_open()
4578 STp->buffer->buffer_bytes = in os_scsi_tape_open()
4579 STp->buffer->read_pointer = in os_scsi_tape_open()
4580 STp->frame_in_buffer = 0; in os_scsi_tape_open()
4585 dev, STp->block_size, OS_FRAME_SIZE, (STp->buffer)->buffer_size, in os_scsi_tape_open()
4586 (STp->buffer)->buffer_blocks); in os_scsi_tape_open()
4589 if (STp->drv_write_prot) { in os_scsi_tape_open()
4590 STp->write_prot = 1; in os_scsi_tape_open()
4606 STp->density_changed = STp->blksize_changed = FALSE; in os_scsi_tape_open()
4607 STp->compression_changed = FALSE; in os_scsi_tape_open()
4613 if (STp->door_locked == ST_UNLOCKED) { in os_scsi_tape_open()
4614 if (osst_int_ioctl(STp, &SRpnt, MTLOCK, 0)) in os_scsi_tape_open()
4617 STp->door_locked = ST_LOCKED_AUTO; in os_scsi_tape_open()
4620 osst_analyze_headers(STp, &SRpnt); in os_scsi_tape_open()
4630 if (STp->buffer != NULL) { in os_scsi_tape_open()
4631 STp->buffer->in_use = 0; in os_scsi_tape_open()
4632 STp->buffer = NULL; in os_scsi_tape_open()
4634 STp->in_use = 0; in os_scsi_tape_open()
4635 STp->header_ok = 0; in os_scsi_tape_open()
4636 STp->device->access_count--; in os_scsi_tape_open()
4638 if (STp->device->host->hostt->module) in os_scsi_tape_open()
4639 __MOD_DEC_USE_COUNT(STp->device->host->hostt->module); in os_scsi_tape_open()
4651 OS_Scsi_Tape * STp; in os_scsi_tape_flush() local
4664 STp = os_scsi_tapes[dev]; in os_scsi_tape_flush()
4665 STm = &(STp->modes[STp->current_mode]); in os_scsi_tape_flush()
4666 STps = &(STp->ps[STp->partition]); in os_scsi_tape_flush()
4668 if ((STps->rw == ST_WRITING || STp->dirty) && !(STp->device)->was_reset) { in os_scsi_tape_flush()
4669 STp->write_type = OS_WRITE_DATA; in os_scsi_tape_flush()
4670 result = osst_flush_write_buffer(STp, &SRpnt); in os_scsi_tape_flush()
4674 if ( STps->rw >= ST_WRITING && !(STp->device)->was_reset) { in os_scsi_tape_flush()
4681 dev, STp->nbr_waits, STp->nbr_finished); in os_scsi_tape_flush()
4684 result = osst_write_trailer(STp, &SRpnt, !(STp->rew_at_close)); in os_scsi_tape_flush()
4688 dev, 1+STp->two_fm); in os_scsi_tape_flush()
4691 else if (!STp->rew_at_close) { in os_scsi_tape_flush()
4692 STps = &(STp->ps[STp->partition]); in os_scsi_tape_flush()
4694 if (STp->can_bsr) in os_scsi_tape_flush()
4695 result = osst_flush_buffer(STp, &SRpnt, 0); /* this is the default path */ in os_scsi_tape_flush()
4697 result = cross_eof(STp, &SRpnt, FALSE); in os_scsi_tape_flush()
4709 !(result = cross_eof(STp, &SRpnt, TRUE))) || in os_scsi_tape_flush()
4719 if (STp->rew_at_close) { in os_scsi_tape_flush()
4720 result2 = osst_position_tape_and_confirm(STp, &SRpnt, STp->first_data_ppos); in os_scsi_tape_flush()
4721 STps->drv_file = STps->drv_block = STp->frame_seq_number = STp->logical_blk_num = 0; in os_scsi_tape_flush()
4727 if (STp->recover_count) { in os_scsi_tape_flush()
4728 printk(KERN_INFO "osst%d:I: %d recovered errors in", dev, STp->recover_count); in os_scsi_tape_flush()
4729 if (STp->write_count) in os_scsi_tape_flush()
4730 printk(" %d frames written", STp->write_count); in os_scsi_tape_flush()
4731 if (STp->read_count) in os_scsi_tape_flush()
4732 printk(" %d frames read", STp->read_count); in os_scsi_tape_flush()
4734 STp->recover_count = 0; in os_scsi_tape_flush()
4736 STp->write_count = 0; in os_scsi_tape_flush()
4737 STp->read_count = 0; in os_scsi_tape_flush()
4747 OS_Scsi_Tape * STp; in os_scsi_tape_close() local
4754 STp = os_scsi_tapes[dev]; in os_scsi_tape_close()
4756 if (STp->door_locked == ST_LOCKED_AUTO) in os_scsi_tape_close()
4757 osst_int_ioctl(STp, &SRpnt, MTUNLOCK, 0); in os_scsi_tape_close()
4760 if (STp->buffer != NULL) in os_scsi_tape_close()
4761 STp->buffer->in_use = 0; in os_scsi_tape_close()
4763 if (STp->raw) in os_scsi_tape_close()
4764 STp->header_ok = 0; in os_scsi_tape_close()
4766 STp->in_use = 0; in os_scsi_tape_close()
4767 STp->device->access_count--; in os_scsi_tape_close()
4769 if (STp->device->host->hostt->module) in os_scsi_tape_close()
4770 __MOD_DEC_USE_COUNT(STp->device->host->hostt->module); in os_scsi_tape_close()
4784 OS_Scsi_Tape *STp; in osst_ioctl() local
4790 STp = os_scsi_tapes[dev]; in osst_ioctl()
4792 if (down_interruptible(&STp->lock)) in osst_ioctl()
4796 if (debugging && !STp->in_use) { in osst_ioctl()
4802 STm = &(STp->modes[STp->current_mode]); in osst_ioctl()
4803 STps = &(STp->ps[STp->partition]); in osst_ioctl()
4811 if( !scsi_block_when_processing_errors(STp->device) ) { in osst_ioctl()
4820 cmd_type, cmd_nr, STp->raw?"raw":"normal"); in osst_ioctl()
4848 if (!(STp->device)->was_reset) { in osst_ioctl()
4865 i = !STp->can_partitions || (STp->new_partition != STp->partition); in osst_ioctl()
4873 i = osst_flush_buffer(STp, &SRpnt, i); in osst_ioctl()
4894 STp->device->was_reset = 0; in osst_ioctl()
4895 if (STp->door_locked != ST_UNLOCKED && in osst_ioctl()
4896 STp->door_locked != ST_LOCK_FAILS) { in osst_ioctl()
4897 if (osst_int_ioctl(STp, &SRpnt, MTLOCK, 0)) { in osst_ioctl()
4900 STp->door_locked = ST_UNLOCKED; in osst_ioctl()
4920 STp->first_frame_position, STp->eod_frame_ppos, STp->frame_seq_number, in osst_ioctl()
4921 STp->logical_blk_num, STps->drv_file, STps->drv_block ); in osst_ioctl()
4923 if (STps->rw >= ST_WRITING && STp->first_frame_position >= STp->eod_frame_ppos) { in osst_ioctl()
4924 auto_weof = ((STp->write_type != OS_WRITE_NEW_MARK) && in osst_ioctl()
4926 i = osst_write_trailer(STp, &SRpnt, in osst_ioctl()
4930 dev, auto_weof, STp->first_frame_position, STp->eod_frame_ppos, in osst_ioctl()
4931 STp->frame_seq_number, STp->logical_blk_num, STps->drv_file, STps->drv_block ); in osst_ioctl()
4941 if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED) in osst_ioctl()
4942 osst_int_ioctl(STp, &SRpnt, MTUNLOCK, 0); /* Ignore result! */ in osst_ioctl()
4946 retval = osst_set_options(STp, mtc.mt_count); in osst_ioctl()
4951 if (mtc.mt_count >= STp->nbr_partitions) in osst_ioctl()
4954 STp->new_partition = mtc.mt_count; in osst_ioctl()
4961 if (!STp->can_partitions) { in osst_ioctl()
4965 if ((i = osst_int_ioctl(STp, &SRpnt, MTREW, 0)) < 0 /*|| in osst_ioctl()
4971 STp->ps[i].rw = ST_IDLE; in osst_ioctl()
4972 STp->ps[i].at_sm = 0; in osst_ioctl()
4973 STp->ps[i].last_block_valid = FALSE; in osst_ioctl()
4975 STp->partition = STp->new_partition = 0; in osst_ioctl()
4976 STp->nbr_partitions = 1; /* Bad guess ?-) */ in osst_ioctl()
4983 if (STp->raw) in osst_ioctl()
4984 i = osst_set_frame_position(STp, &SRpnt, mtc.mt_count, 0); in osst_ioctl()
4986 i = osst_seek_sector(STp, &SRpnt, mtc.mt_count); in osst_ioctl()
4987 if (!STp->can_partitions) in osst_ioctl()
4988 STp->ps[0].rw = ST_IDLE; in osst_ioctl()
4994 cross_eof(STp, &SRpnt, FALSE); in osst_ioctl()
5001 retval = osst_int_ioctl(STp, &SRpnt, mtc.mt_op, mtc.mt_count); in osst_ioctl()
5010 if ((i = osst_flush_buffer(STp, &SRpnt, FALSE)) < 0) { in osst_ioctl()
5024 mt_status.mt_erreg = STp->recover_erreg << MT_ST_SOFTERR_SHIFT; in osst_ioctl()
5026 ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) | in osst_ioctl()
5027 ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK); in osst_ioctl()
5030 if (STp->block_size != 0) { in osst_ioctl()
5032 mt_status.mt_blkno += (STp->buffer)->buffer_bytes / STp->block_size; in osst_ioctl()
5034 mt_status.mt_blkno -= ((STp->buffer)->buffer_bytes + in osst_ioctl()
5035 STp->block_size - 1) / STp->block_size; in osst_ioctl()
5039 if (STp->drv_write_prot) in osst_ioctl()
5047 mt_status.mt_resid = STp->partition; in osst_ioctl()
5052 if (STp->density == 1) in osst_ioctl()
5054 else if (STp->density == 2) in osst_ioctl()
5056 else if (STp->density == 3) in osst_ioctl()
5058 if (STp->ready == ST_READY) in osst_ioctl()
5060 if (STp->ready == ST_NO_TAPE) in osst_ioctl()
5064 if (STm->do_async_writes || (STm->do_buffer_writes && STp->block_size != 0) || in osst_ioctl()
5065 STp->drv_buffer != 0) in osst_ioctl()
5075 STp->recover_erreg = 0; /* Clear after read */ in osst_ioctl()
5087 if (STp->raw) in osst_ioctl()
5088 blk = osst_get_frame_position(STp, &SRpnt); in osst_ioctl()
5090 blk = osst_get_sector(STp, &SRpnt); in osst_ioctl()
5103 up(&STp->lock); in osst_ioctl()
5105 return scsi_ioctl(STp->device, cmd_in, (void *) arg); in osst_ioctl()
5110 up(&STp->lock); in osst_ioctl()
5550 OS_Scsi_Tape * STp = (OS_Scsi_Tape *) data; in osst_proc_read() local
5554 if (STp->header_ok && STp->linux_media) in osst_proc_read()
5556 STp->header_cache->major_rev, in osst_proc_read()
5557 STp->header_cache->minor_rev, in osst_proc_read()
5558 STp->linux_media_version, in osst_proc_read()
5559 STp->first_data_ppos, in osst_proc_read()
5560 STp->eod_frame_ppos, in osst_proc_read()
5561 STp->filemark_cnt ); in osst_proc_read()
5573 static void osst_proc_create(OS_Scsi_Tape * STp, int dev) in osst_proc_create() argument
5581 p_entry = create_proc_read_entry(s, 0444, osst_proc_dir, osst_proc_read, (void *) STp); in osst_proc_create()