2 SCSI Tape Driver for Linux version 1.1 and newer. See the accompanying 3 file README.st for more information. 6 Rewritten from Dwayne Forsyth's SCSI tape driver by Kai Makisara. 7 Contribution and ideas from several people including (in alphabetical 8 order) Klaus Ehrenfried, Wolfgang Denk, Steve Hirsch, Andreas Koppenh"ofer, 9 Michael Leodolter, Eyal Lebedinsky, J"org Weule, and Eric Youngdale. 11 Copyright 1992 - 1997 Kai Makisara 12 email Kai.Makisara@metla.fi 14 Last modified: Wed Jan 1 15:26:54 1997 by makisara@kai.makisara.fi 15 Some small formal changes - aeb, 950809 18 #include <linux/module.h> 21 #include <linux/kernel.h> 22 #include <linux/sched.h> 24 #include <linux/string.h> 25 #include <linux/errno.h> 26 #include <linux/mtio.h> 27 #include <linux/ioctl.h> 28 #include <linux/fcntl.h> 29 #include <asm/uaccess.h> 31 #include <asm/system.h> 33 /* The driver prints some debugging information on the console if DEBUG 34 is defined and non-zero. */ 37 /* The message level for the debug messages is currently set to KERN_NOTICE 38 so that people can easily see the messages. Later when the debugging messages 39 in the drivers are more widely classified, this may be changed to KERN_DEBUG. */ 40 #define ST_DEB_MSG KERN_NOTICE 42 #define MAJOR_NR SCSI_TAPE_MAJOR 43 #include <linux/blk.h> 47 #include <scsi/scsi_ioctl.h> 51 /* The default definitions have been moved to st_options.h */ 53 #define ST_BLOCK_SIZE 1024 55 #include"st_options.h" 57 #define ST_BUFFER_SIZE (ST_BUFFER_BLOCKS * ST_BLOCK_SIZE) 58 #define ST_WRITE_THRESHOLD (ST_WRITE_THRESHOLD_BLOCKS * ST_BLOCK_SIZE) 60 /* The buffer size should fit into the 24 bits for length in the 61 6-byte SCSI read and write commands. */ 62 #if ST_BUFFER_SIZE >= (2 << 24 - 1) 63 #error"Buffer size should not exceed (2 << 24 - 1) bytes!" 67 static int debugging
=1; 71 #define MAX_WRITE_RETRIES 0 72 #define MAX_READY_RETRIES 5 73 #define NO_TAPE NOT_READY 75 #define ST_TIMEOUT (900 * HZ) 76 #define ST_LONG_TIMEOUT (14000 * HZ) 78 #define TAPE_NR(x) (MINOR(x) & ~(128 | ST_MODE_MASK)) 79 #define TAPE_MODE(x) ((MINOR(x) & ST_MODE_MASK) >> ST_MODE_SHIFT) 81 /* Internal ioctl to set both density (uppermost 8 bits) and blocksize (lower 83 #define SET_DENS_AND_BLK 0x10001 85 static int st_nbr_buffers
; 86 static ST_buffer
**st_buffers
; 87 static int st_buffer_size
= ST_BUFFER_SIZE
; 88 static int st_write_threshold
= ST_WRITE_THRESHOLD
; 89 static int st_max_buffers
= ST_MAX_BUFFERS
; 91 static Scsi_Tape
* scsi_tapes
= NULL
; 93 static int modes_defined
= FALSE
; 95 static ST_buffer
*new_tape_buffer(int,int); 96 static intenlarge_buffer(ST_buffer
*,int,int); 97 static voidnormalize_buffer(ST_buffer
*); 99 static intst_init(void); 100 static intst_attach(Scsi_Device
*); 101 static intst_detect(Scsi_Device
*); 102 static voidst_detach(Scsi_Device
*); 104 struct Scsi_Device_Template st_template
= {NULL
,"tape","st", NULL
, TYPE_TAPE
, 105 SCSI_TAPE_MAJOR
,0,0,0,0, 107 NULL
, st_attach
, st_detach
}; 109 static intst_compression(Scsi_Tape
*,int); 111 static intfind_partition(struct inode
*); 112 static intupdate_partition(struct inode
*); 114 static intst_int_ioctl(struct inode
* inode
,unsigned int cmd_in
, 120 /* Convert the result to success code */ 122 st_chk_result(Scsi_Cmnd
* SCpnt
) 124 int dev
=TAPE_NR(SCpnt
->request
.rq_dev
); 125 int result
= SCpnt
->result
; 126 unsigned char* sense
= SCpnt
->sense_buffer
, scode
; 131 if(!result
/* && SCpnt->sense_buffer[0] == 0 */) 134 scode
= sense
[2] &0x0f; 138 printk(ST_DEB_MSG
"st%d: Error: %x, cmd: %x %x %x %x %x %x Len: %d\n", 140 SCpnt
->data_cmnd
[0], SCpnt
->data_cmnd
[1], SCpnt
->data_cmnd
[2], 141 SCpnt
->data_cmnd
[3], SCpnt
->data_cmnd
[4], SCpnt
->data_cmnd
[5], 142 SCpnt
->request_bufflen
); 143 if(driver_byte(result
) & DRIVER_SENSE
) 144 print_sense("st", SCpnt
); 150 if(!(driver_byte(result
) & DRIVER_SENSE
) || 151 ((sense
[0] &0x70) ==0x70&& 153 scode
!= RECOVERED_ERROR
&& 154 /* scode != UNIT_ATTENTION && */ 155 scode
!= BLANK_CHECK
&& 156 scode
!= VOLUME_OVERFLOW
&& 157 SCpnt
->data_cmnd
[0] != MODE_SENSE
&& 158 SCpnt
->data_cmnd
[0] != TEST_UNIT_READY
)) {/* Abnormal conditions for tape */ 159 if(driver_byte(result
) & DRIVER_SENSE
) { 160 printk(KERN_WARNING
"st%d: Error with sense data: ", dev
); 161 print_sense("st", SCpnt
); 164 printk(KERN_WARNING
"st%d: Error %x.\n", dev
, result
); 167 if((sense
[0] &0x70) ==0x70&& 168 scode
== RECOVERED_ERROR
169 #if ST_RECOVERED_WRITE_FATAL 170 && SCpnt
->data_cmnd
[0] != WRITE_6
171 && SCpnt
->data_cmnd
[0] != WRITE_FILEMARKS
174 scsi_tapes
[dev
].recover_count
++; 175 scsi_tapes
[dev
].mt_status
->mt_erreg
+= (1<< MT_ST_SOFTERR_SHIFT
); 178 if(SCpnt
->data_cmnd
[0] == READ_6
) 180 else if(SCpnt
->data_cmnd
[0] == WRITE_6
) 184 printk(ST_DEB_MSG
"st%d: Recovered %s error (%d).\n", dev
, stp
, 185 scsi_tapes
[dev
].recover_count
); 188 if((sense
[2] &0xe0) ==0) 195 /* Wakeup from interrupt */ 197 st_sleep_done(Scsi_Cmnd
* SCpnt
) 203 if((st_nbr
=TAPE_NR(SCpnt
->request
.rq_dev
)) < st_template
.nr_dev
) { 204 STp
= &(scsi_tapes
[st_nbr
]); 205 if((STp
->buffer
)->writing
&& 206 (SCpnt
->sense_buffer
[0] &0x70) ==0x70&& 207 (SCpnt
->sense_buffer
[2] &0x40)) { 208 /* EOM at write-behind, has all been written? */ 209 if((SCpnt
->sense_buffer
[0] &0x80) !=0) 210 remainder
= (SCpnt
->sense_buffer
[3] <<24) | 211 (SCpnt
->sense_buffer
[4] <<16) | 212 (SCpnt
->sense_buffer
[5] <<8) | SCpnt
->sense_buffer
[6]; 215 if((SCpnt
->sense_buffer
[2] &0x0f) == VOLUME_OVERFLOW
|| 217 (STp
->buffer
)->last_result
= SCpnt
->result
;/* Error */ 219 (STp
->buffer
)->last_result
= INT_MAX
;/* OK */ 222 (STp
->buffer
)->last_result
= SCpnt
->result
; 223 if((STp
->buffer
)->writing
) { 224 /* Process errors before releasing request */ 225 (STp
->buffer
)->last_result_fatal
=st_chk_result(SCpnt
); 226 SCpnt
->request
.rq_status
= RQ_INACTIVE
; 229 SCpnt
->request
.rq_status
= RQ_SCSI_DONE
; 232 STp
->write_pending
=0; 234 up(SCpnt
->request
.sem
); 238 printk(KERN_ERR
"st?: Illegal interrupt device %x\n", st_nbr
); 243 /* Do the scsi command */ 245 st_do_scsi(Scsi_Cmnd
*SCpnt
, Scsi_Tape
*STp
,unsigned char*cmd
,int bytes
, 246 int timeout
,int retries
) 249 if((SCpnt
=allocate_device(NULL
, STp
->device
,1)) == NULL
) { 250 printk(KERN_ERR
"st%d: Can't get SCSI request.\n",TAPE_NR(STp
->devt
)); 254 cmd
[1] |= (SCpnt
->lun
<<5) &0xe0; 255 STp
->sem
= MUTEX_LOCKED
; 256 SCpnt
->request
.sem
= &(STp
->sem
); 257 SCpnt
->request
.rq_status
= RQ_SCSI_BUSY
; 258 SCpnt
->request
.rq_dev
= STp
->devt
; 260 scsi_do_cmd(SCpnt
, (void*)cmd
, (STp
->buffer
)->b_data
, bytes
, 261 st_sleep_done
, timeout
, retries
); 263 down(SCpnt
->request
.sem
); 265 (STp
->buffer
)->last_result_fatal
=st_chk_result(SCpnt
); 271 /* Handle the write-behind checking */ 273 write_behind_check(Scsi_Tape
*STp
) 275 ST_buffer
* STbuffer
; 278 STbuffer
= STp
->buffer
; 281 if(STp
->write_pending
) 289 if(STbuffer
->writing
< STbuffer
->buffer_bytes
) 290 memcpy(STbuffer
->b_data
, 291 STbuffer
->b_data
+ STbuffer
->writing
, 292 STbuffer
->buffer_bytes
- STbuffer
->writing
); 293 STbuffer
->buffer_bytes
-= STbuffer
->writing
; 294 STps
= &(STp
->ps
[STp
->partition
]); 295 if(STps
->drv_block
>=0) { 296 if(STp
->block_size
==0) 299 STps
->drv_block
+= STbuffer
->writing
/ STp
->block_size
; 301 STbuffer
->writing
=0; 307 /* Step over EOF if it has been inadvertently crossed (ioctl not used because 308 it messes up the block number). */ 310 cross_eof(Scsi_Tape
*STp
,int forward
) 313 unsigned char cmd
[10]; 316 cmd
[1] =0x01;/* Space FileMarks */ 322 cmd
[2] = cmd
[3] = cmd
[4] =0xff;/* -1 filemarks */ 326 printk(ST_DEB_MSG
"st%d: Stepping over filemark %s.\n", 327 TAPE_NR(STp
->devt
), forward
?"forward":"backward"); 330 SCpnt
=st_do_scsi(NULL
, STp
, cmd
,0, ST_TIMEOUT
, MAX_RETRIES
); 334 SCpnt
->request
.rq_status
= RQ_INACTIVE
; 335 if((STp
->buffer
)->last_result
!=0) 336 printk(KERN_ERR
"st%d: Stepping over filemark %s failed.\n", 337 TAPE_NR(STp
->devt
), forward
?"forward":"backward"); 339 return(STp
->buffer
)->last_result_fatal
; 343 /* Flush the write buffer (never need to write if variable blocksize). */ 345 flush_write_buffer(Scsi_Tape
*STp
) 347 int offset
, transfer
, blks
; 349 unsigned char cmd
[10]; 353 if((STp
->buffer
)->writing
) { 354 write_behind_check(STp
); 355 if((STp
->buffer
)->last_result_fatal
) { 358 printk(ST_DEB_MSG
"st%d: Async write error (flush) %x.\n", 359 TAPE_NR(STp
->devt
), (STp
->buffer
)->last_result
); 361 if((STp
->buffer
)->last_result
== INT_MAX
) 367 if(STp
->block_size
==0) 373 offset
= (STp
->buffer
)->buffer_bytes
; 374 transfer
= ((offset
+ STp
->block_size
-1) / 375 STp
->block_size
) * STp
->block_size
; 378 printk(ST_DEB_MSG
"st%d: Flushing %d bytes.\n",TAPE_NR(STp
->devt
), transfer
); 380 memset((STp
->buffer
)->b_data
+ offset
,0, transfer
- offset
); 385 blks
= transfer
/ STp
->block_size
; 390 SCpnt
=st_do_scsi(NULL
, STp
, cmd
, transfer
, ST_TIMEOUT
, MAX_WRITE_RETRIES
); 394 STps
= &(STp
->ps
[STp
->partition
]); 395 if((STp
->buffer
)->last_result_fatal
!=0) { 396 if((SCpnt
->sense_buffer
[0] &0x70) ==0x70&& 397 (SCpnt
->sense_buffer
[2] &0x40) && 398 (SCpnt
->sense_buffer
[2] &0x0f) == NO_SENSE
) { 400 (STp
->buffer
)->buffer_bytes
=0; 404 printk(KERN_ERR
"st%d: Error on flush.\n",TAPE_NR(STp
->devt
)); 407 STps
->drv_block
= (-1); 410 if(STps
->drv_block
>=0) 411 STps
->drv_block
+= blks
; 413 (STp
->buffer
)->buffer_bytes
=0; 415 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 421 /* Flush the tape buffer. The tape will be positioned correctly unless 422 seek_next is true. */ 424 flush_buffer(struct inode
* inode
,struct file
* filp
,int seek_next
) 426 int backspace
, result
; 428 ST_buffer
* STbuffer
; 430 int dev
=TAPE_NR(inode
->i_rdev
); 432 STp
= &(scsi_tapes
[dev
]); 433 STbuffer
= STp
->buffer
; 436 * If there was a bus reset, block further access 439 if( STp
->device
->was_reset
) 442 if(STp
->ready
!= ST_READY
) 445 STps
= &(STp
->ps
[STp
->partition
]); 446 if(STps
->rw
== ST_WRITING
)/* Writing */ 447 returnflush_write_buffer(STp
); 449 if(STp
->block_size
==0) 452 backspace
= ((STp
->buffer
)->buffer_bytes
+ 453 (STp
->buffer
)->read_pointer
) / STp
->block_size
- 454 ((STp
->buffer
)->read_pointer
+ STp
->block_size
-1) / 456 (STp
->buffer
)->buffer_bytes
=0; 457 (STp
->buffer
)->read_pointer
=0; 460 if(STps
->eof
== ST_FM_HIT
) { 461 result
=cross_eof(STp
, FALSE
);/* Back over the EOF hit */ 463 STps
->eof
= ST_NOEOF
; 465 if(STps
->drv_file
>=0) 470 if(!result
&& backspace
>0) 471 result
=st_int_ioctl(inode
, MTBSR
, backspace
); 473 else if(STps
->eof
== ST_FM_HIT
) { 474 if(STps
->drv_file
>=0) 477 STps
->eof
= ST_NOEOF
; 484 \f/* Set the mode parameters */ 486 set_mode_densblk(struct inode
* inode
, Scsi_Tape
*STp
, ST_mode
*STm
) 490 int dev
=TAPE_NR(inode
->i_rdev
); 492 if(!STp
->density_changed
&& 493 STm
->default_density
>=0&& 494 STm
->default_density
!= STp
->density
) { 495 arg
= STm
->default_density
; 500 arg
<<= MT_ST_DENSITY_SHIFT
; 501 if(!STp
->blksize_changed
&& 502 STm
->default_blksize
>=0&& 503 STm
->default_blksize
!= STp
->block_size
) { 504 arg
|= STm
->default_blksize
; 508 arg
|= STp
->block_size
; 510 st_int_ioctl(inode
, SET_DENS_AND_BLK
, arg
)) { 512 "st%d: Can't set default block size to %d bytes and density %x.\n", 513 dev
, STm
->default_blksize
, STm
->default_density
); 521 /* Open the device */ 523 scsi_tape_open(struct inode
* inode
,struct file
* filp
) 525 unsigned short flags
; 526 int i
, need_dma_buffer
, new_session
= FALSE
; 527 unsigned char cmd
[10]; 532 int dev
=TAPE_NR(inode
->i_rdev
); 533 int mode
=TAPE_MODE(inode
->i_rdev
); 535 if(dev
>= st_template
.dev_max
|| !scsi_tapes
[dev
].device
) 537 STp
= &(scsi_tapes
[dev
]); 540 printk(ST_DEB_MSG
"st%d: Device already in use.\n", dev
); 544 STp
->rew_at_close
= (MINOR(inode
->i_rdev
) &0x80) ==0; 546 if(mode
!= STp
->current_mode
) { 549 printk(ST_DEB_MSG
"st%d: Mode change from %d to %d.\n", 550 dev
, STp
->current_mode
, mode
); 553 STp
->current_mode
= mode
; 555 STm
= &(STp
->modes
[STp
->current_mode
]); 557 /* Allocate buffer for this user */ 558 need_dma_buffer
= STp
->restr_dma
; 559 for(i
=0; i
< st_nbr_buffers
; i
++) 560 if(!st_buffers
[i
]->in_use
&& 561 (!need_dma_buffer
|| st_buffers
[i
]->dma
)) 563 if(i
>= st_nbr_buffers
) { 564 STp
->buffer
=new_tape_buffer(FALSE
, need_dma_buffer
); 565 if(STp
->buffer
== NULL
) { 566 printk(KERN_WARNING
"st%d: Can't allocate tape buffer.\n", dev
); 571 STp
->buffer
= st_buffers
[i
]; 572 (STp
->buffer
)->in_use
=1; 573 (STp
->buffer
)->writing
=0; 575 flags
= filp
->f_flags
; 576 STp
->write_prot
= ((flags
& O_ACCMODE
) == O_RDONLY
); 579 for(i
=0; i
< ST_NBR_PARTITIONS
; i
++) { 580 STps
= &(STp
->ps
[i
]); 583 STp
->ready
= ST_READY
; 584 STp
->recover_count
=0; 586 STp
->nbr_waits
= STp
->nbr_finished
=0; 589 if(scsi_tapes
[dev
].device
->host
->hostt
->module
) 590 __MOD_INC_USE_COUNT(scsi_tapes
[dev
].device
->host
->hostt
->module
); 591 if(st_template
.module
) 592 __MOD_INC_USE_COUNT(st_template
.module
); 594 memset((void*) &cmd
[0],0,10); 595 cmd
[0] = TEST_UNIT_READY
; 597 SCpnt
=st_do_scsi(NULL
, STp
, cmd
,0, ST_LONG_TIMEOUT
, MAX_READY_RETRIES
); 599 if(scsi_tapes
[dev
].device
->host
->hostt
->module
) 600 __MOD_DEC_USE_COUNT(scsi_tapes
[dev
].device
->host
->hostt
->module
); 601 if(st_template
.module
) 602 __MOD_DEC_USE_COUNT(st_template
.module
); 606 if((SCpnt
->sense_buffer
[0] &0x70) ==0x70&& 607 (SCpnt
->sense_buffer
[2] &0x0f) == UNIT_ATTENTION
) {/* New media? */ 608 memset((void*) &cmd
[0],0,10); 609 cmd
[0] = TEST_UNIT_READY
; 611 SCpnt
=st_do_scsi(SCpnt
, STp
, cmd
,0, ST_LONG_TIMEOUT
, MAX_READY_RETRIES
); 613 (STp
->device
)->was_reset
=0; 614 STp
->partition
= STp
->new_partition
=0; 615 if(STp
->can_partitions
) 616 STp
->nbr_partitions
=1;/* This guess will be updated later if necessary */ 617 for(i
=0; i
< ST_NBR_PARTITIONS
; i
++) { 618 STps
= &(STp
->ps
[i
]); 620 STps
->eof
= ST_NOEOF
; 622 STps
->last_block_valid
= FALSE
; 629 if((STp
->buffer
)->last_result_fatal
!=0) { 630 if((SCpnt
->sense_buffer
[0] &0x70) ==0x70&& 631 (SCpnt
->sense_buffer
[2] &0x0f) == NO_TAPE
) { 632 STp
->ready
= ST_NO_TAPE
; 634 STp
->ready
= ST_NOT_READY
; 635 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 636 STp
->density
=0;/* Clear the erroneous "residue" */ 639 STp
->ps
[0].drv_file
= STp
->ps
[0].drv_block
=0; 640 STp
->partition
= STp
->new_partition
=0; 641 STp
->door_locked
= ST_UNLOCKED
; 646 if(STp
->omit_blklims
) 647 STp
->min_block
= STp
->max_block
= (-1); 649 memset((void*) &cmd
[0],0,10); 650 cmd
[0] = READ_BLOCK_LIMITS
; 652 SCpnt
=st_do_scsi(SCpnt
, STp
, cmd
,6, ST_TIMEOUT
, MAX_READY_RETRIES
); 654 if(!SCpnt
->result
&& !SCpnt
->sense_buffer
[0]) { 655 STp
->max_block
= ((STp
->buffer
)->b_data
[1] <<16) | 656 ((STp
->buffer
)->b_data
[2] <<8) | (STp
->buffer
)->b_data
[3]; 657 STp
->min_block
= ((STp
->buffer
)->b_data
[4] <<8) | 658 (STp
->buffer
)->b_data
[5]; 661 printk(ST_DEB_MSG
"st%d: Block limits %d - %d bytes.\n", dev
, STp
->min_block
, 666 STp
->min_block
= STp
->max_block
= (-1); 669 printk(ST_DEB_MSG
"st%d: Can't read block limits.\n", dev
); 674 memset((void*) &cmd
[0],0,10); 678 SCpnt
=st_do_scsi(SCpnt
, STp
, cmd
,12, ST_TIMEOUT
, MAX_READY_RETRIES
); 680 if((STp
->buffer
)->last_result_fatal
!=0) { 683 printk(ST_DEB_MSG
"st%d: No Mode Sense.\n", dev
); 685 STp
->block_size
= ST_DEFAULT_BLOCK
;/* Educated guess (?) */ 686 (STp
->buffer
)->last_result_fatal
=0;/* Prevent error propagation */ 687 STp
->drv_write_prot
=0; 693 printk(ST_DEB_MSG
"st%d: Mode sense. Length %d, medium %x, WBS %x, BLL %d\n", 695 (STp
->buffer
)->b_data
[0], (STp
->buffer
)->b_data
[1], 696 (STp
->buffer
)->b_data
[2], (STp
->buffer
)->b_data
[3]); 699 if((STp
->buffer
)->b_data
[3] >=8) { 700 STp
->drv_buffer
= ((STp
->buffer
)->b_data
[2] >>4) &7; 701 STp
->density
= (STp
->buffer
)->b_data
[4]; 702 STp
->block_size
= (STp
->buffer
)->b_data
[9] *65536+ 703 (STp
->buffer
)->b_data
[10] *256+ (STp
->buffer
)->b_data
[11]; 706 printk(ST_DEB_MSG
"st%d: Density %x, tape length: %x, drv buffer: %d\n", 707 dev
, STp
->density
, (STp
->buffer
)->b_data
[5] *65536+ 708 (STp
->buffer
)->b_data
[6] *256+ (STp
->buffer
)->b_data
[7], 713 if(STp
->block_size
> (STp
->buffer
)->buffer_size
&& 714 !enlarge_buffer(STp
->buffer
, STp
->block_size
, STp
->restr_dma
)) { 715 printk(KERN_NOTICE
"st%d: Blocksize %d too large for buffer.\n", dev
, 717 (STp
->buffer
)->in_use
=0; 719 if(scsi_tapes
[dev
].device
->host
->hostt
->module
) 720 __MOD_DEC_USE_COUNT(scsi_tapes
[dev
].device
->host
->hostt
->module
); 721 if(st_template
.module
) 722 __MOD_DEC_USE_COUNT(st_template
.module
); 725 STp
->drv_write_prot
= ((STp
->buffer
)->b_data
[2] &0x80) !=0; 727 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 729 if(STp
->block_size
>0) 730 (STp
->buffer
)->buffer_blocks
= st_buffer_size
/ STp
->block_size
; 732 (STp
->buffer
)->buffer_blocks
=1; 733 (STp
->buffer
)->buffer_bytes
= (STp
->buffer
)->read_pointer
=0; 737 printk(ST_DEB_MSG
"st%d: Block size: %d, buffer size: %d (%d blocks).\n", dev
, 738 STp
->block_size
, (STp
->buffer
)->buffer_size
, 739 (STp
->buffer
)->buffer_blocks
); 742 if(STp
->drv_write_prot
) { 746 printk(ST_DEB_MSG
"st%d: Write protected\n", dev
); 748 if((flags
& O_ACCMODE
) == O_WRONLY
|| (flags
& O_ACCMODE
) == O_RDWR
) { 749 (STp
->buffer
)->in_use
=0; 751 if(scsi_tapes
[dev
].device
->host
->hostt
->module
) 752 __MOD_DEC_USE_COUNT(scsi_tapes
[dev
].device
->host
->hostt
->module
); 753 if(st_template
.module
) 754 __MOD_DEC_USE_COUNT(st_template
.module
); 759 if(STp
->can_partitions
&& STp
->nbr_partitions
<1) { 760 /* This code is reached when the device is opened for the first time 761 after the driver has been initialized with tape in the drive and the 762 partition support has been enabled. */ 765 printk(ST_DEB_MSG
"st%d: Updating partition number in status.\n", dev
); 767 if((STp
->partition
=find_partition(inode
)) <0) { 768 (STp
->buffer
)->in_use
=0; 770 if(scsi_tapes
[dev
].device
->host
->hostt
->module
) 771 __MOD_DEC_USE_COUNT(scsi_tapes
[dev
].device
->host
->hostt
->module
); 772 if(st_template
.module
) 773 __MOD_DEC_USE_COUNT(st_template
.module
); 774 return STp
->partition
; 776 STp
->new_partition
= STp
->partition
; 777 STp
->nbr_partitions
=1;/* This guess will be updated when necessary */ 780 if(new_session
) {/* Change the drive parameters for the new mode */ 781 STp
->density_changed
= STp
->blksize_changed
= FALSE
; 782 STp
->compression_changed
= FALSE
; 783 if(!(STm
->defaults_for_writes
) && 784 (i
=set_mode_densblk(inode
, STp
, STm
)) <0) { 785 (STp
->buffer
)->in_use
=0; 787 if(scsi_tapes
[dev
].device
->host
->hostt
->module
) 788 __MOD_DEC_USE_COUNT(scsi_tapes
[dev
].device
->host
->hostt
->module
); 789 if(st_template
.module
) 790 __MOD_DEC_USE_COUNT(st_template
.module
); 793 if(STp
->default_drvbuffer
!=0xff) { 794 if(st_int_ioctl(inode
, MTSETDRVBUFFER
, STp
->default_drvbuffer
)) 795 printk(KERN_WARNING
"st%d: Can't set default drive buffering to %d.\n", 796 dev
, STp
->default_drvbuffer
); 806 /* Close the device*/ 808 scsi_tape_close(struct inode
* inode
,struct file
* filp
) 811 static unsigned char cmd
[10]; 817 kdev_t devt
= inode
->i_rdev
; 821 STp
= &(scsi_tapes
[dev
]); 822 STm
= &(STp
->modes
[STp
->current_mode
]); 823 STps
= &(STp
->ps
[STp
->partition
]); 825 if(STp
->can_partitions
&& 826 update_partition(inode
) <0) { 829 printk(ST_DEB_MSG
"st%d: update_partition at close failed.\n", dev
); 834 if( STps
->rw
== ST_WRITING
&& !(STp
->device
)->was_reset
) { 836 result
=flush_write_buffer(STp
); 840 printk(ST_DEB_MSG
"st%d: File length %ld bytes.\n", 841 dev
, (long)(filp
->f_pos
)); 842 printk(ST_DEB_MSG
"st%d: Async write waits %d, finished %d.\n", 843 dev
, STp
->nbr_waits
, STp
->nbr_finished
); 847 if(result
==0|| result
== (-ENOSPC
)) { 850 cmd
[0] = WRITE_FILEMARKS
; 851 cmd
[4] =1+ STp
->two_fm
; 853 SCpnt
=st_do_scsi(NULL
, STp
, cmd
,0, ST_TIMEOUT
, MAX_WRITE_RETRIES
); 857 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 859 if((STp
->buffer
)->last_result_fatal
!=0&& 860 ((SCpnt
->sense_buffer
[0] &0x70) !=0x70|| 861 (SCpnt
->sense_buffer
[2] &0x4f) !=0x40|| 862 ((SCpnt
->sense_buffer
[0] &0x80) !=0&& 863 (SCpnt
->sense_buffer
[3] | SCpnt
->sense_buffer
[4] | 864 SCpnt
->sense_buffer
[5] | 865 SCpnt
->sense_buffer
[6]) ==0)))/* Filter out successful write at EOM */ 866 printk(KERN_ERR
"st%d: Error on write filemark.\n", dev
); 868 if(STps
->drv_file
>=0) 872 cross_eof(STp
, FALSE
); 879 printk(ST_DEB_MSG
"st%d: Buffer flushed, %d EOF(s) written\n", 883 else if(!STp
->rew_at_close
) { 884 STps
= &(STp
->ps
[STp
->partition
]); 885 if(!STm
->sysv
|| STps
->rw
!= ST_READING
) { 887 flush_buffer(inode
, filp
,0); 888 else if(STps
->eof
== ST_FM_HIT
) { 889 if(cross_eof(STp
, FALSE
)) { 890 if(STps
->drv_file
>=0) 896 STps
->eof
= ST_NOEOF
; 899 else if((STps
->eof
== ST_NOEOF
&& !cross_eof(STp
, TRUE
)) || 900 STps
->eof
== ST_FM_HIT
) { 901 if(STps
->drv_file
>=0) 909 if(STp
->rew_at_close
) 910 st_int_ioctl(inode
, MTREW
,1); 912 if(STp
->door_locked
== ST_LOCKED_AUTO
) 913 st_int_ioctl(inode
, MTUNLOCK
,0); 915 if(STp
->buffer
!= NULL
) { 916 normalize_buffer(STp
->buffer
); 917 (STp
->buffer
)->in_use
=0; 921 if(scsi_tapes
[dev
].device
->host
->hostt
->module
) 922 __MOD_DEC_USE_COUNT(scsi_tapes
[dev
].device
->host
->hostt
->module
); 923 if(st_template
.module
) 924 __MOD_DEC_USE_COUNT(st_template
.module
); 932 st_write(struct inode
* inode
,struct file
* filp
,const char* buf
, 936 int i
, do_count
, blks
, retval
, transfer
; 939 static unsigned char cmd
[10]; 941 Scsi_Cmnd
* SCpnt
= NULL
; 945 int dev
=TAPE_NR(inode
->i_rdev
); 947 STp
= &(scsi_tapes
[dev
]); 948 if(STp
->ready
!= ST_READY
) 950 STm
= &(STp
->modes
[STp
->current_mode
]); 957 * If there was a bus reset, block further access 960 if( STp
->device
->was_reset
) 965 printk(ST_DEB_MSG
"st%d: Incorrect device.\n", dev
); 970 if(STp
->can_partitions
&& 971 (retval
=update_partition(inode
)) <0) 973 STps
= &(STp
->ps
[STp
->partition
]); 978 if(STp
->block_size
==0&& 979 count
> (STp
->buffer
)->buffer_size
&& 980 !enlarge_buffer(STp
->buffer
, count
, STp
->restr_dma
)) 983 if(STp
->do_auto_lock
&& STp
->door_locked
== ST_UNLOCKED
&& 984 !st_int_ioctl(inode
, MTLOCK
,0)) 985 STp
->door_locked
= ST_LOCKED_AUTO
; 987 if(STps
->rw
== ST_READING
) { 988 retval
=flush_buffer(inode
, filp
,0); 991 STps
->rw
= ST_WRITING
; 993 else if(STps
->rw
!= ST_WRITING
&& 994 STps
->drv_file
==0&& STps
->drv_block
==0) { 995 if((retval
=set_mode_densblk(inode
, STp
, STm
)) <0) 997 if(STm
->default_compression
!= ST_DONT_TOUCH
&& 998 !(STp
->compression_changed
)) { 999 if(st_compression(STp
, (STm
->default_compression
== ST_YES
))) { 1000 printk(KERN_WARNING
"st%d: Can't set default compression.\n", 1008 if((STp
->buffer
)->writing
) { 1009 write_behind_check(STp
); 1010 if((STp
->buffer
)->last_result_fatal
) { 1013 printk(ST_DEB_MSG
"st%d: Async write error (write) %x.\n", dev
, 1014 (STp
->buffer
)->last_result
); 1016 if((STp
->buffer
)->last_result
== INT_MAX
) 1017 STps
->eof
= ST_EOM_OK
; 1019 STps
->eof
= ST_EOM_ERROR
; 1022 if(STps
->eof
== ST_EOM_OK
) 1024 else if(STps
->eof
== ST_EOM_ERROR
) 1027 /* Check the buffer readability in cases where copy_user might catch 1028 the problems after some tape movement. */ 1029 if(STp
->block_size
!=0&& 1030 (copy_from_user(&i
, buf
,1) !=0|| 1031 copy_from_user(&i
, buf
+ count
-1,1) !=0)) 1034 if(!STm
->do_buffer_writes
) { 1035 if(STp
->block_size
!=0&& (count
% STp
->block_size
) !=0) 1036 return(-EIO
);/* Write must be integral number of blocks */ 1040 write_threshold
= (STp
->buffer
)->buffer_blocks
* STp
->block_size
; 1041 if(!STm
->do_async_writes
) 1048 cmd
[1] = (STp
->block_size
!=0); 1050 STps
->rw
= ST_WRITING
; 1053 while((STp
->block_size
==0&& !STm
->do_async_writes
&& count
>0) || 1054 (STp
->block_size
!=0&& 1055 (STp
->buffer
)->buffer_bytes
+ count
> write_threshold
)) 1058 if(STp
->block_size
==0) 1061 do_count
= (STp
->buffer
)->buffer_blocks
* STp
->block_size
- 1062 (STp
->buffer
)->buffer_bytes
; 1063 if(do_count
> count
) 1067 i
=copy_from_user((STp
->buffer
)->b_data
+ 1068 (STp
->buffer
)->buffer_bytes
, b_point
, do_count
); 1071 SCpnt
->request
.rq_status
= RQ_INACTIVE
; 1075 if(STp
->block_size
==0) 1076 blks
= transfer
= do_count
; 1078 blks
= ((STp
->buffer
)->buffer_bytes
+ do_count
) / 1080 transfer
= blks
* STp
->block_size
; 1086 SCpnt
=st_do_scsi(SCpnt
, STp
, cmd
, transfer
, ST_TIMEOUT
, MAX_WRITE_RETRIES
); 1090 if((STp
->buffer
)->last_result_fatal
!=0) { 1093 printk(ST_DEB_MSG
"st%d: Error on write:\n", dev
); 1095 if((SCpnt
->sense_buffer
[0] &0x70) ==0x70&& 1096 (SCpnt
->sense_buffer
[2] &0x40)) { 1097 if(STp
->block_size
!=0&& (SCpnt
->sense_buffer
[0] &0x80) !=0) 1098 transfer
= (SCpnt
->sense_buffer
[3] <<24) | 1099 (SCpnt
->sense_buffer
[4] <<16) | 1100 (SCpnt
->sense_buffer
[5] <<8) | SCpnt
->sense_buffer
[6]; 1101 else if(STp
->block_size
==0&& 1102 (SCpnt
->sense_buffer
[2] &0x0f) == VOLUME_OVERFLOW
) 1103 transfer
= do_count
; 1106 if(STp
->block_size
!=0) 1107 transfer
*= STp
->block_size
; 1108 if(transfer
<= do_count
) { 1109 filp
->f_pos
+= do_count
- transfer
; 1110 count
-= do_count
- transfer
; 1111 if(STps
->drv_block
>=0) { 1112 if(STp
->block_size
==0&& transfer
< do_count
) 1114 else if(STp
->block_size
!=0) 1115 STps
->drv_block
+= (do_count
- transfer
) / STp
->block_size
; 1117 STps
->eof
= ST_EOM_OK
; 1118 retval
= (-ENOSPC
);/* EOM within current request */ 1121 printk(ST_DEB_MSG
"st%d: EOM with %d bytes unwritten.\n", 1126 STps
->eof
= ST_EOM_ERROR
; 1127 STps
->drv_block
= (-1);/* Too cautious? */ 1128 retval
= (-EIO
);/* EOM for old data */ 1131 printk(ST_DEB_MSG
"st%d: EOM with lost data.\n", dev
); 1136 STps
->drv_block
= (-1);/* Too cautious? */ 1140 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 1141 (STp
->buffer
)->buffer_bytes
=0; 1144 return total
- count
; 1148 filp
->f_pos
+= do_count
; 1149 b_point
+= do_count
; 1151 if(STps
->drv_block
>=0) { 1152 if(STp
->block_size
==0) 1155 STps
->drv_block
+= blks
; 1157 (STp
->buffer
)->buffer_bytes
=0; 1162 i
=copy_from_user((STp
->buffer
)->b_data
+ 1163 (STp
->buffer
)->buffer_bytes
, b_point
, count
); 1166 SCpnt
->request
.rq_status
= RQ_INACTIVE
; 1169 filp
->f_pos
+= count
; 1170 (STp
->buffer
)->buffer_bytes
+= count
; 1174 if(doing_write
&& (STp
->buffer
)->last_result_fatal
!=0) { 1175 SCpnt
->request
.rq_status
= RQ_INACTIVE
; 1176 return(STp
->buffer
)->last_result_fatal
; 1179 if(STm
->do_async_writes
&& 1180 ((STp
->buffer
)->buffer_bytes
>= STp
->write_threshold
|| 1181 STp
->block_size
==0) ) { 1182 /* Schedule an asynchronous write */ 1184 SCpnt
=allocate_device(NULL
, STp
->device
,1); 1188 if(STp
->block_size
==0) 1189 (STp
->buffer
)->writing
= (STp
->buffer
)->buffer_bytes
; 1191 (STp
->buffer
)->writing
= ((STp
->buffer
)->buffer_bytes
/ 1192 STp
->block_size
) * STp
->block_size
; 1193 STp
->dirty
= !((STp
->buffer
)->writing
== 1194 (STp
->buffer
)->buffer_bytes
); 1196 if(STp
->block_size
==0) 1197 blks
= (STp
->buffer
)->writing
; 1199 blks
= (STp
->buffer
)->writing
/ STp
->block_size
; 1203 STp
->sem
= MUTEX_LOCKED
; 1204 SCpnt
->request
.sem
= &(STp
->sem
); 1205 SCpnt
->request
.rq_status
= RQ_SCSI_BUSY
; 1206 SCpnt
->request
.rq_dev
= STp
->devt
; 1208 STp
->write_pending
=1; 1212 (void*) cmd
, (STp
->buffer
)->b_data
, 1213 (STp
->buffer
)->writing
, 1214 st_sleep_done
, ST_TIMEOUT
, MAX_WRITE_RETRIES
); 1216 else if(SCpnt
!= NULL
) 1217 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 1219 STps
->at_sm
&= (total
==0); 1221 STps
->eof
= ST_NOEOF
; 1226 /* Read data from the tape. Returns zero in the normal case, one if the 1227 eof status has changed, and the negative error code in case of a 1228 fatal error. Otherwise updates the buffer and the eof state. */ 1230 read_tape(struct inode
*inode
,long count
, Scsi_Cmnd
**aSCpnt
) 1232 int transfer
, blks
, bytes
; 1233 static unsigned char cmd
[10]; 1238 int dev
=TAPE_NR(inode
->i_rdev
); 1244 STp
= &(scsi_tapes
[dev
]); 1245 STm
= &(STp
->modes
[STp
->current_mode
]); 1246 STps
= &(STp
->ps
[STp
->partition
]); 1247 if(STps
->eof
== ST_FM_HIT
) 1252 cmd
[1] = (STp
->block_size
!=0); 1253 if(STp
->block_size
==0) 1254 blks
= bytes
= count
; 1256 if(STm
->do_read_ahead
) { 1257 blks
= (STp
->buffer
)->buffer_blocks
; 1258 bytes
= blks
* STp
->block_size
; 1262 if(bytes
> (STp
->buffer
)->buffer_size
) 1263 bytes
= (STp
->buffer
)->buffer_size
; 1264 blks
= bytes
/ STp
->block_size
; 1265 bytes
= blks
* STp
->block_size
; 1273 SCpnt
=st_do_scsi(SCpnt
, STp
, cmd
, bytes
, ST_TIMEOUT
, MAX_RETRIES
); 1278 (STp
->buffer
)->read_pointer
=0; 1282 /* Something to check */ 1283 if((STp
->buffer
)->last_result_fatal
) { 1287 printk(ST_DEB_MSG
"st%d: Sense: %2x %2x %2x %2x %2x %2x %2x %2x\n", 1289 SCpnt
->sense_buffer
[0], SCpnt
->sense_buffer
[1], 1290 SCpnt
->sense_buffer
[2], SCpnt
->sense_buffer
[3], 1291 SCpnt
->sense_buffer
[4], SCpnt
->sense_buffer
[5], 1292 SCpnt
->sense_buffer
[6], SCpnt
->sense_buffer
[7]); 1294 if((SCpnt
->sense_buffer
[0] &0x70) ==0x70) {/* extended sense */ 1296 if((SCpnt
->sense_buffer
[2] &0x0f) == BLANK_CHECK
) 1297 SCpnt
->sense_buffer
[2] &=0xcf;/* No need for EOM in this case */ 1299 if((SCpnt
->sense_buffer
[2] &0xe0) !=0) {/* EOF, EOM, or ILI */ 1300 /* Compute the residual count */ 1301 if((SCpnt
->sense_buffer
[0] &0x80) !=0) 1302 transfer
= (SCpnt
->sense_buffer
[3] <<24) | 1303 (SCpnt
->sense_buffer
[4] <<16) | 1304 (SCpnt
->sense_buffer
[5] <<8) | SCpnt
->sense_buffer
[6]; 1307 if(STp
->block_size
==0&& 1308 (SCpnt
->sense_buffer
[2] &0x0f) == MEDIUM_ERROR
) 1311 if(SCpnt
->sense_buffer
[2] &0x20) {/* ILI */ 1312 if(STp
->block_size
==0) { 1315 (STp
->buffer
)->buffer_bytes
= bytes
- transfer
; 1318 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 1320 if(transfer
== blks
) {/* We did not get anything, error */ 1321 printk(KERN_NOTICE
"st%d: Incorrect block size.\n", dev
); 1322 if(STps
->drv_block
>=0) 1323 STps
->drv_block
+= blks
- transfer
+1; 1324 st_int_ioctl(inode
, MTBSR
,1); 1327 /* We have some data, deliver it */ 1328 (STp
->buffer
)->buffer_bytes
= (blks
- transfer
) * 1333 "st%d: ILI but enough data received %ld %d.\n", 1334 dev
, count
, (STp
->buffer
)->buffer_bytes
); 1336 if(STps
->drv_block
>=0) 1337 STps
->drv_block
+=1; 1338 if(st_int_ioctl(inode
, MTBSR
,1)) 1342 else if(SCpnt
->sense_buffer
[2] &0x80) {/* FM overrides EOM */ 1343 if(STps
->eof
!= ST_FM_HIT
) 1344 STps
->eof
= ST_FM_HIT
; 1346 STps
->eof
= ST_EOD_2
; 1347 if(STp
->block_size
==0) 1348 (STp
->buffer
)->buffer_bytes
=0; 1350 (STp
->buffer
)->buffer_bytes
= 1351 bytes
- transfer
* STp
->block_size
; 1355 "st%d: EOF detected (%d bytes read).\n", 1356 dev
, (STp
->buffer
)->buffer_bytes
); 1359 else if(SCpnt
->sense_buffer
[2] &0x40) { 1360 if(STps
->eof
== ST_FM
) 1361 STps
->eof
= ST_EOD_1
; 1363 STps
->eof
= ST_EOM_OK
; 1364 if(STp
->block_size
==0) 1365 (STp
->buffer
)->buffer_bytes
= bytes
- transfer
; 1367 (STp
->buffer
)->buffer_bytes
= 1368 bytes
- transfer
* STp
->block_size
; 1371 printk(ST_DEB_MSG
"st%d: EOM detected (%d bytes read).\n", 1372 dev
, (STp
->buffer
)->buffer_bytes
); 1375 }/* end of EOF, EOM, ILI test */ 1376 else{/* nonzero sense key */ 1379 printk(ST_DEB_MSG
"st%d: Tape error while reading.\n", dev
); 1381 STps
->drv_block
= (-1); 1382 if(STps
->eof
== ST_FM
&& 1383 (SCpnt
->sense_buffer
[2] &0x0f) == BLANK_CHECK
) { 1387 "st%d: Zero returned for first BLANK CHECK after EOF.\n", 1390 STps
->eof
= ST_EOD_2
;/* First BLANK_CHECK after FM */ 1392 else/* Some other extended sense code */ 1395 }/* End of extended sense test */ 1396 else{/* Non-extended sense */ 1397 retval
= (STp
->buffer
)->last_result_fatal
; 1400 }/* End of error handling */ 1401 else/* Read successful */ 1402 (STp
->buffer
)->buffer_bytes
= bytes
; 1404 if(STps
->drv_block
>=0) { 1405 if(STp
->block_size
==0) 1408 STps
->drv_block
+= (STp
->buffer
)->buffer_bytes
/ STp
->block_size
; 1417 st_read(struct inode
* inode
,struct file
* filp
,char* buf
,unsigned long count
) 1422 Scsi_Cmnd
* SCpnt
= NULL
; 1426 int dev
=TAPE_NR(inode
->i_rdev
); 1428 STp
= &(scsi_tapes
[dev
]); 1429 if(STp
->ready
!= ST_READY
) 1431 STm
= &(STp
->modes
[STp
->current_mode
]); 1436 printk(ST_DEB_MSG
"st%d: Incorrect device.\n", dev
); 1441 if(STp
->can_partitions
&& 1442 (total
=update_partition(inode
)) <0) 1445 if(STp
->block_size
==0&& 1446 count
> (STp
->buffer
)->buffer_size
&& 1447 !enlarge_buffer(STp
->buffer
, count
, STp
->restr_dma
)) 1450 if(!(STm
->do_read_ahead
) && STp
->block_size
!=0&& 1451 (count
% STp
->block_size
) !=0) 1452 return(-EIO
);/* Read must be integral number of blocks */ 1454 if(STp
->do_auto_lock
&& STp
->door_locked
== ST_UNLOCKED
&& 1455 !st_int_ioctl(inode
, MTLOCK
,0)) 1456 STp
->door_locked
= ST_LOCKED_AUTO
; 1458 STps
= &(STp
->ps
[STp
->partition
]); 1459 if(STps
->rw
== ST_WRITING
) { 1460 transfer
=flush_buffer(inode
, filp
,0); 1463 STps
->rw
= ST_READING
; 1467 if(debugging
&& STps
->eof
!= ST_NOEOF
) 1468 printk(ST_DEB_MSG
"st%d: EOF/EOM flag up (%d). Bytes %d\n", dev
, 1469 STps
->eof
, (STp
->buffer
)->buffer_bytes
); 1471 if((STp
->buffer
)->buffer_bytes
==0&& 1472 STps
->eof
>= ST_EOD_1
) { 1473 if(STps
->eof
< ST_EOD
) { 1477 return(-EIO
);/* EOM or Blank Check */ 1480 /* Check the buffer writability before any tape movement. Don't alter 1482 if(copy_from_user(&i
, buf
,1) !=0|| 1483 copy_to_user(buf
, &i
,1) !=0|| 1484 copy_from_user(&i
, buf
+ count
-1,1) !=0|| 1485 copy_to_user(buf
+ count
-1, &i
,1) !=0) 1488 STps
->rw
= ST_READING
; 1491 /* Loop until enough data in buffer or a special condition found */ 1492 for(total
=0, special
=0; total
< count
&& !special
; ) { 1494 /* Get new data if the buffer is empty */ 1495 if((STp
->buffer
)->buffer_bytes
==0) { 1496 special
=read_tape(inode
, count
- total
, &SCpnt
); 1497 if(special
<0) {/* No need to continue read */ 1499 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 1504 /* Move the data from driver buffer to user buffer */ 1505 if((STp
->buffer
)->buffer_bytes
>0) { 1507 if(debugging
&& STps
->eof
!= ST_NOEOF
) 1508 printk(ST_DEB_MSG
"st%d: EOF up (%d). Left %d, needed %ld.\n", dev
, 1509 STps
->eof
, (STp
->buffer
)->buffer_bytes
, count
- total
); 1511 transfer
= (STp
->buffer
)->buffer_bytes
< count
- total
? 1512 (STp
->buffer
)->buffer_bytes
: count
- total
; 1513 i
=copy_to_user(buf
, (STp
->buffer
)->b_data
+ 1514 (STp
->buffer
)->read_pointer
, transfer
); 1517 SCpnt
->request
.rq_status
= RQ_INACTIVE
; 1520 filp
->f_pos
+= transfer
; 1523 (STp
->buffer
)->buffer_bytes
-= transfer
; 1524 (STp
->buffer
)->read_pointer
+= transfer
; 1527 if(STp
->block_size
==0) 1528 break;/* Read only one variable length block */ 1530 }/* for (total = 0, special = 0; total < count && !special; ) */ 1533 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 1535 /* Change the eof state if no data from tape or buffer */ 1537 if(STps
->eof
== ST_FM_HIT
) { 1540 if(STps
->drv_file
>=0) 1543 else if(STps
->eof
== ST_EOD_1
) { 1544 STps
->eof
= ST_EOD_2
; 1546 if(STps
->drv_file
>=0) 1549 else if(STps
->eof
== ST_EOD_2
) 1552 else if(STps
->eof
== ST_FM
) 1553 STps
->eof
= ST_NOEOF
; 1560 /* Set the driver options */ 1562 st_log_options(Scsi_Tape
*STp
, ST_mode
*STm
,int dev
) 1565 "st%d: Mode %d options: buffer writes: %d, async writes: %d, read ahead: %d\n", 1566 dev
, STp
->current_mode
, STm
->do_buffer_writes
, STm
->do_async_writes
, 1567 STm
->do_read_ahead
); 1569 "st%d: can bsr: %d, two FMs: %d, fast mteom: %d, auto lock: %d,\n", 1570 dev
, STp
->can_bsr
, STp
->two_fm
, STp
->fast_mteom
, STp
->do_auto_lock
); 1572 "st%d: defs for wr: %d, no block limits: %d, partitions: %d, s2 log: %d\n", 1573 dev
, STm
->defaults_for_writes
, STp
->omit_blklims
, STp
->can_partitions
, 1574 STp
->scsi2_logical
); 1577 "st%d: debugging: %d\n", 1584 st_set_options(struct inode
* inode
,long options
) 1590 int dev
=TAPE_NR(inode
->i_rdev
); 1592 STp
= &(scsi_tapes
[dev
]); 1593 STm
= &(STp
->modes
[STp
->current_mode
]); 1595 memcpy(STm
, &(STp
->modes
[0]),sizeof(ST_mode
)); 1596 modes_defined
= TRUE
; 1599 printk(ST_DEB_MSG
"st%d: Initialized mode %d definition from mode 0\n", 1600 dev
, STp
->current_mode
); 1604 code
= options
& MT_ST_OPTIONS
; 1605 if(code
== MT_ST_BOOLEANS
) { 1606 STm
->do_buffer_writes
= (options
& MT_ST_BUFFER_WRITES
) !=0; 1607 STm
->do_async_writes
= (options
& MT_ST_ASYNC_WRITES
) !=0; 1608 STm
->defaults_for_writes
= (options
& MT_ST_DEF_WRITES
) !=0; 1609 STm
->do_read_ahead
= (options
& MT_ST_READ_AHEAD
) !=0; 1610 STp
->two_fm
= (options
& MT_ST_TWO_FM
) !=0; 1611 STp
->fast_mteom
= (options
& MT_ST_FAST_MTEOM
) !=0; 1612 STp
->do_auto_lock
= (options
& MT_ST_AUTO_LOCK
) !=0; 1613 STp
->can_bsr
= (options
& MT_ST_CAN_BSR
) !=0; 1614 STp
->omit_blklims
= (options
& MT_ST_NO_BLKLIMS
) !=0; 1615 if((STp
->device
)->scsi_level
>= SCSI_2
) 1616 STp
->can_partitions
= (options
& MT_ST_CAN_PARTITIONS
) !=0; 1617 STp
->scsi2_logical
= (options
& MT_ST_SCSI2LOGICAL
) !=0; 1619 debugging
= (options
& MT_ST_DEBUGGING
) !=0; 1621 st_log_options(STp
, STm
, dev
); 1623 else if(code
== MT_ST_SETBOOLEANS
|| code
== MT_ST_CLEARBOOLEANS
) { 1624 value
= (code
== MT_ST_SETBOOLEANS
); 1625 if((options
& MT_ST_BUFFER_WRITES
) !=0) 1626 STm
->do_buffer_writes
= value
; 1627 if((options
& MT_ST_ASYNC_WRITES
) !=0) 1628 STm
->do_async_writes
= value
; 1629 if((options
& MT_ST_DEF_WRITES
) !=0) 1630 STm
->defaults_for_writes
= value
; 1631 if((options
& MT_ST_READ_AHEAD
) !=0) 1632 STm
->do_read_ahead
= value
; 1633 if((options
& MT_ST_TWO_FM
) !=0) 1634 STp
->two_fm
= value
; 1635 if((options
& MT_ST_FAST_MTEOM
) !=0) 1636 STp
->fast_mteom
= value
; 1637 if((options
& MT_ST_AUTO_LOCK
) !=0) 1638 STp
->do_auto_lock
= value
; 1639 if((options
& MT_ST_CAN_BSR
) !=0) 1640 STp
->can_bsr
= value
; 1641 if((options
& MT_ST_NO_BLKLIMS
) !=0) 1642 STp
->omit_blklims
= value
; 1643 if((STp
->device
)->scsi_level
>= SCSI_2
&& 1644 (options
& MT_ST_CAN_PARTITIONS
) !=0) 1645 STp
->can_partitions
= value
; 1646 if((options
& MT_ST_SCSI2LOGICAL
) !=0) 1647 STp
->scsi2_logical
= value
; 1649 if((options
& MT_ST_DEBUGGING
) !=0) 1652 st_log_options(STp
, STm
, dev
); 1654 else if(code
== MT_ST_WRITE_THRESHOLD
) { 1655 value
= (options
& ~MT_ST_OPTIONS
) * ST_BLOCK_SIZE
; 1656 if(value
<1|| value
> st_buffer_size
) { 1657 printk(KERN_WARNING
"st%d: Write threshold %d too small or too large.\n", 1661 STp
->write_threshold
= value
; 1662 printk(KERN_INFO
"st%d: Write threshold set to %d bytes.\n", 1665 else if(code
== MT_ST_DEF_BLKSIZE
) { 1666 value
= (options
& ~MT_ST_OPTIONS
); 1667 if(value
== ~MT_ST_OPTIONS
) { 1668 STm
->default_blksize
= (-1); 1669 printk(KERN_INFO
"st%d: Default block size disabled.\n", dev
); 1672 STm
->default_blksize
= value
; 1673 printk(KERN_INFO
"st%d: Default block size set to %d bytes.\n", 1674 dev
, STm
->default_blksize
); 1677 else if(code
== MT_ST_DEF_OPTIONS
) { 1678 code
= (options
& ~MT_ST_CLEAR_DEFAULT
); 1679 value
= (options
& MT_ST_CLEAR_DEFAULT
); 1680 if(code
== MT_ST_DEF_DENSITY
) { 1681 if(value
== MT_ST_CLEAR_DEFAULT
) { 1682 STm
->default_density
= (-1); 1683 printk(KERN_INFO
"st%d: Density default disabled.\n", dev
); 1686 STm
->default_density
= value
&0xff; 1687 printk(KERN_INFO
"st%d: Density default set to %x\n", 1688 dev
, STm
->default_density
); 1691 else if(code
== MT_ST_DEF_DRVBUFFER
) { 1692 if(value
== MT_ST_CLEAR_DEFAULT
) { 1693 STp
->default_drvbuffer
=0xff; 1694 printk(KERN_INFO
"st%d: Drive buffer default disabled.\n", dev
); 1697 STp
->default_drvbuffer
= value
&7; 1698 printk(KERN_INFO
"st%d: Drive buffer default set to %x\n", 1699 dev
, STp
->default_drvbuffer
); 1702 else if(code
== MT_ST_DEF_COMPRESSION
) { 1703 if(value
== MT_ST_CLEAR_DEFAULT
) { 1704 STm
->default_compression
= ST_DONT_TOUCH
; 1705 printk(KERN_INFO
"st%d: Compression default disabled.\n", dev
); 1708 STm
->default_compression
= (value
&1? ST_YES
: ST_NO
); 1709 printk(KERN_INFO
"st%d: Compression default set to %x\n", 1721 #define COMPRESSION_PAGE 0x0f 1722 #define COMPRESSION_PAGE_LENGTH 16 1724 #define MODE_HEADER_LENGTH 4 1726 #define DCE_MASK 0x80 1727 #define DCC_MASK 0x40 1728 #define RED_MASK 0x60 1731 /* Control the compression with mode page 15. Algorithm not changed if zero. */ 1733 st_compression(Scsi_Tape
* STp
,int state
) 1736 unsigned char cmd
[10]; 1737 Scsi_Cmnd
* SCpnt
= NULL
; 1739 if(STp
->ready
!= ST_READY
) 1742 /* Read the current page contents */ 1744 cmd
[0] = MODE_SENSE
; 1746 cmd
[2] = COMPRESSION_PAGE
; 1747 cmd
[4] = COMPRESSION_PAGE_LENGTH
+ MODE_HEADER_LENGTH
; 1749 SCpnt
=st_do_scsi(SCpnt
, STp
, cmd
, cmd
[4], ST_TIMEOUT
,0); 1752 dev
=TAPE_NR(SCpnt
->request
.rq_dev
); 1754 if((STp
->buffer
)->last_result_fatal
!=0) { 1757 printk(ST_DEB_MSG
"st%d: Compression mode page not supported.\n", dev
); 1759 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 1764 printk(ST_DEB_MSG
"st%d: Compression state is %d.\n", dev
, 1765 ((STp
->buffer
)->b_data
[MODE_HEADER_LENGTH
+2] & DCE_MASK
?1:0)); 1768 /* Check if compression can be changed */ 1769 if(((STp
->buffer
)->b_data
[MODE_HEADER_LENGTH
+2] & DCC_MASK
) ==0) { 1772 printk(ST_DEB_MSG
"st%d: Compression not supported.\n", dev
); 1774 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 1780 (STp
->buffer
)->b_data
[MODE_HEADER_LENGTH
+2] |= DCE_MASK
; 1782 (STp
->buffer
)->b_data
[MODE_HEADER_LENGTH
+2] &= ~DCE_MASK
; 1785 cmd
[0] = MODE_SELECT
; 1787 cmd
[4] = COMPRESSION_PAGE_LENGTH
+ MODE_HEADER_LENGTH
; 1789 (STp
->buffer
)->b_data
[0] =0;/* Reserved data length */ 1790 (STp
->buffer
)->b_data
[1] =0;/* Reserved media type byte */ 1791 (STp
->buffer
)->b_data
[MODE_HEADER_LENGTH
] &=0x3f; 1792 SCpnt
=st_do_scsi(SCpnt
, STp
, cmd
, cmd
[4], ST_TIMEOUT
,0); 1794 if((STp
->buffer
)->last_result_fatal
!=0) { 1797 printk(ST_DEB_MSG
"st%d: Compression change failed.\n", dev
); 1799 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 1805 printk(ST_DEB_MSG
"st%d: Compression state changed to %d.\n", 1809 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 1810 STp
->compression_changed
= TRUE
; 1815 /* Internal ioctl function */ 1817 st_int_ioctl(struct inode
* inode
, 1818 unsigned int cmd_in
,unsigned long arg
) 1820 int timeout
= ST_LONG_TIMEOUT
; 1822 int i
, ioctl_result
; 1824 unsigned char cmd
[10]; 1828 int fileno
, blkno
, at_sm
, undone
, datalen
; 1829 int dev
=TAPE_NR(inode
->i_rdev
); 1831 STp
= &(scsi_tapes
[dev
]); 1832 if(STp
->ready
!= ST_READY
&& cmd_in
!= MTLOAD
) 1834 STps
= &(STp
->ps
[STp
->partition
]); 1835 fileno
= STps
->drv_file
; 1836 blkno
= STps
->drv_block
; 1837 at_sm
= STps
->at_sm
; 1843 chg_eof
= FALSE
;/* Changed from the FSF after this */ 1846 cmd
[1] =0x01;/* Space FileMarks */ 1847 cmd
[2] = (arg
>>16); 1852 printk(ST_DEB_MSG
"st%d: Spacing tape forward over %d filemarks.\n", 1853 dev
, cmd
[2] *65536+ cmd
[3] *256+ cmd
[4]); 1861 chg_eof
= FALSE
;/* Changed from the FSF after this */ 1864 cmd
[1] =0x01;/* Space FileMarks */ 1866 cmd
[2] = (ltmp
>>16); 1867 cmd
[3] = (ltmp
>>8); 1873 ltmp
= ltmp
| (cmd
[2] <<16) | (cmd
[3] <<8) | cmd
[4]; 1874 printk(ST_DEB_MSG
"st%d: Spacing tape backward over %ld filemarks.\n", 1880 blkno
= (-1);/* We can't know the block number */ 1885 cmd
[1] =0x00;/* Space Blocks */ 1886 cmd
[2] = (arg
>>16); 1891 printk(ST_DEB_MSG
"st%d: Spacing tape forward %d blocks.\n", dev
, 1892 cmd
[2] *65536+ cmd
[3] *256+ cmd
[4]); 1900 cmd
[1] =0x00;/* Space Blocks */ 1902 cmd
[2] = (ltmp
>>16); 1903 cmd
[3] = (ltmp
>>8); 1909 ltmp
= ltmp
| (cmd
[2] <<16) | (cmd
[3] <<8) | cmd
[4]; 1910 printk(ST_DEB_MSG
"st%d: Spacing tape backward %ld blocks.\n", dev
, (-ltmp
)); 1919 cmd
[1] =0x04;/* Space Setmarks */ 1920 cmd
[2] = (arg
>>16); 1925 printk(ST_DEB_MSG
"st%d: Spacing tape forward %d setmarks.\n", dev
, 1926 cmd
[2] *65536+ cmd
[3] *256+ cmd
[4]); 1929 blkno
= fileno
= (-1); 1935 cmd
[1] =0x04;/* Space Setmarks */ 1937 cmd
[2] = (ltmp
>>16); 1938 cmd
[3] = (ltmp
>>8); 1944 ltmp
= ltmp
| (cmd
[2] <<16) | (cmd
[3] <<8) | cmd
[4]; 1945 printk(ST_DEB_MSG
"st%d: Spacing tape backward %ld setmarks.\n", 1950 blkno
= fileno
= (-1); 1958 cmd
[0] = WRITE_FILEMARKS
; 1961 cmd
[2] = (arg
>>16); 1964 timeout
= ST_TIMEOUT
; 1967 if(cmd_in
== MTWEOF
) 1968 printk(ST_DEB_MSG
"st%d: Writing %d filemarks.\n", dev
, 1969 cmd
[2] *65536+ cmd
[3] *256+ cmd
[4]); 1971 printk(ST_DEB_MSG
"st%d: Writing %d setmarks.\n", dev
, 1972 cmd
[2] *65536+ cmd
[3] *256+ cmd
[4]); 1978 at_sm
= (cmd_in
== MTWSM
); 1981 cmd
[0] = REZERO_UNIT
; 1983 cmd
[1] =1;/* Don't wait for completion */ 1984 timeout
= ST_TIMEOUT
; 1988 printk(ST_DEB_MSG
"st%d: Rewinding tape.\n", dev
); 1990 fileno
= blkno
= at_sm
=0; 1995 cmd
[0] = START_STOP
; 1996 if(cmd_in
== MTLOAD
) 1999 * If arg >= 1 && arg <= 6 Enhanced load/unload in HP C1553A 2001 if(cmd_in
!= MTOFFL
&& 2002 arg
>=1+ MT_ST_HPLOADER_OFFSET
2003 && arg
<=6+ MT_ST_HPLOADER_OFFSET
) { 2006 printk(ST_DEB_MSG
"st%d: Enhanced %sload slot %2ld.\n", 2007 dev
, (cmd
[4]) ?"":"un", 2008 arg
- MT_ST_HPLOADER_OFFSET
); 2011 cmd
[3] = arg
- MT_ST_HPLOADER_OFFSET
;/* MediaID field of C1553A */ 2014 cmd
[1] =1;/* Don't wait for completion */ 2015 timeout
= ST_TIMEOUT
; 2017 timeout
= ST_LONG_TIMEOUT
*8; 2021 if(cmd_in
!= MTLOAD
) 2022 printk(ST_DEB_MSG
"st%d: Unloading tape.\n", dev
); 2024 printk(ST_DEB_MSG
"st%d: Loading tape.\n", dev
); 2027 fileno
= blkno
= at_sm
=0; 2032 printk(ST_DEB_MSG
"st%d: No op on tape.\n", dev
); 2034 return0;/* Should do something ? */ 2037 cmd
[0] = START_STOP
; 2039 cmd
[1] =1;/* Don't wait for completion */ 2040 timeout
= ST_TIMEOUT
; 2045 printk(ST_DEB_MSG
"st%d: Retensioning tape.\n", dev
); 2047 fileno
= blkno
= at_sm
=0; 2050 if(!STp
->fast_mteom
) { 2051 /* space to the end of tape */ 2052 ioctl_result
=st_int_ioctl(inode
, MTFSF
,0x3fff); 2053 fileno
= STps
->drv_file
; 2054 if(STps
->eof
>= ST_EOD_1
) 2056 /* The next lines would hide the number of spaced FileMarks 2057 That's why I inserted the previous lines. I had no luck 2058 with detecting EOM with FSF, so we go now to EOM. 2067 printk(ST_DEB_MSG
"st%d: Spacing to end of recorded medium.\n", dev
); 2076 cmd
[1] =1;/* To the end of tape */ 2078 cmd
[1] |=2;/* Don't wait for completion */ 2079 timeout
= ST_TIMEOUT
; 2081 timeout
= ST_LONG_TIMEOUT
*8; 2085 printk(ST_DEB_MSG
"st%d: Erasing tape.\n", dev
); 2087 fileno
= blkno
= at_sm
=0; 2091 cmd
[0] = ALLOW_MEDIUM_REMOVAL
; 2092 cmd
[4] = SCSI_REMOVAL_PREVENT
; 2095 printk(ST_DEB_MSG
"st%d: Locking drive door.\n", dev
); 2100 cmd
[0] = ALLOW_MEDIUM_REMOVAL
; 2101 cmd
[4] = SCSI_REMOVAL_ALLOW
; 2104 printk(ST_DEB_MSG
"st%d: Unlocking drive door.\n", dev
); 2107 case MTSETBLK
:/* Set block length */ 2108 case MTSETDENSITY
:/* Set tape density */ 2109 case MTSETDRVBUFFER
:/* Set drive buffering */ 2110 case SET_DENS_AND_BLK
:/* Set density and block size */ 2112 if(STp
->dirty
|| (STp
->buffer
)->buffer_bytes
!=0) 2113 return(-EIO
);/* Not allowed if data in buffer */ 2114 if((cmd_in
== MTSETBLK
|| cmd_in
== SET_DENS_AND_BLK
) && 2115 (arg
& MT_ST_BLKSIZE_MASK
) !=0&& 2116 ((arg
& MT_ST_BLKSIZE_MASK
) < STp
->min_block
|| 2117 (arg
& MT_ST_BLKSIZE_MASK
) > STp
->max_block
|| 2118 (arg
& MT_ST_BLKSIZE_MASK
) > st_buffer_size
)) { 2119 printk(KERN_WARNING
"st%d: Illegal block size.\n", dev
); 2122 cmd
[0] = MODE_SELECT
; 2123 cmd
[4] = datalen
=12; 2125 memset((STp
->buffer
)->b_data
,0,12); 2126 if(cmd_in
== MTSETDRVBUFFER
) 2127 (STp
->buffer
)->b_data
[2] = (arg
&7) <<4; 2129 (STp
->buffer
)->b_data
[2] = 2130 STp
->drv_buffer
<<4; 2131 (STp
->buffer
)->b_data
[3] =8;/* block descriptor length */ 2132 if(cmd_in
== MTSETDENSITY
) { 2133 (STp
->buffer
)->b_data
[4] = arg
; 2134 STp
->density_changed
= TRUE
;/* At least we tried ;-) */ 2136 else if(cmd_in
== SET_DENS_AND_BLK
) 2137 (STp
->buffer
)->b_data
[4] = arg
>>24; 2139 (STp
->buffer
)->b_data
[4] = STp
->density
; 2140 if(cmd_in
== MTSETBLK
|| cmd_in
== SET_DENS_AND_BLK
) { 2141 ltmp
= arg
& MT_ST_BLKSIZE_MASK
; 2142 if(cmd_in
== MTSETBLK
) 2143 STp
->blksize_changed
= TRUE
;/* At least we tried ;-) */ 2146 ltmp
= STp
->block_size
; 2147 (STp
->buffer
)->b_data
[9] = (ltmp
>>16); 2148 (STp
->buffer
)->b_data
[10] = (ltmp
>>8); 2149 (STp
->buffer
)->b_data
[11] = ltmp
; 2150 timeout
= ST_TIMEOUT
; 2153 if(cmd_in
== MTSETBLK
|| cmd_in
== SET_DENS_AND_BLK
) 2154 printk(ST_DEB_MSG
"st%d: Setting block size to %d bytes.\n", dev
, 2155 (STp
->buffer
)->b_data
[9] *65536+ 2156 (STp
->buffer
)->b_data
[10] *256+ 2157 (STp
->buffer
)->b_data
[11]); 2158 if(cmd_in
== MTSETDENSITY
|| cmd_in
== SET_DENS_AND_BLK
) 2159 printk(ST_DEB_MSG
"st%d: Setting density code to %x.\n", dev
, 2160 (STp
->buffer
)->b_data
[4]); 2161 if(cmd_in
== MTSETDRVBUFFER
) 2162 printk(ST_DEB_MSG
"st%d: Setting drive buffer code to %d.\n", dev
, 2163 ((STp
->buffer
)->b_data
[2] >>4) &7); 2171 SCpnt
=st_do_scsi(NULL
, STp
, cmd
, datalen
, timeout
, MAX_RETRIES
); 2175 ioctl_result
= (STp
->buffer
)->last_result_fatal
; 2177 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 2179 if(!ioctl_result
) {/* SCSI command successful */ 2180 STps
->drv_block
= blkno
; 2181 STps
->drv_file
= fileno
; 2182 STps
->at_sm
= at_sm
; 2184 if(cmd_in
== MTLOCK
) 2185 STp
->door_locked
= ST_LOCKED_EXPLICIT
; 2186 else if(cmd_in
== MTUNLOCK
) 2187 STp
->door_locked
= ST_UNLOCKED
; 2189 if(cmd_in
== MTBSFM
) 2190 ioctl_result
=st_int_ioctl(inode
, MTFSF
,1); 2191 else if(cmd_in
== MTFSFM
) 2192 ioctl_result
=st_int_ioctl(inode
, MTBSF
,1); 2194 if(cmd_in
== MTSETBLK
|| cmd_in
== SET_DENS_AND_BLK
) { 2195 STp
->block_size
= arg
& MT_ST_BLKSIZE_MASK
; 2196 if(STp
->block_size
!=0) 2197 (STp
->buffer
)->buffer_blocks
= 2198 (STp
->buffer
)->buffer_size
/ STp
->block_size
; 2199 (STp
->buffer
)->buffer_bytes
= (STp
->buffer
)->read_pointer
=0; 2200 if(cmd_in
== SET_DENS_AND_BLK
) 2201 STp
->density
= arg
>> MT_ST_DENSITY_SHIFT
; 2203 else if(cmd_in
== MTSETDRVBUFFER
) 2204 STp
->drv_buffer
= (arg
&7); 2205 else if(cmd_in
== MTSETDENSITY
) 2210 else if(cmd_in
== MTFSF
) 2213 STps
->eof
= ST_NOEOF
; 2216 if(cmd_in
== MTOFFL
|| cmd_in
== MTUNLOAD
) 2217 STp
->rew_at_close
=0; 2218 else if(cmd_in
== MTLOAD
) { 2219 STp
->rew_at_close
= (MINOR(inode
->i_rdev
) &0x80) ==0; 2220 for(i
=0; i
< ST_NBR_PARTITIONS
; i
++) { 2221 STp
->ps
[i
].rw
= ST_IDLE
; 2222 STp
->ps
[i
].last_block_valid
= FALSE
; 2227 }else{/* SCSI command was not completely successful */ 2229 if(SCpnt
->sense_buffer
[2] &0x40) { 2230 if(cmd_in
!= MTBSF
&& cmd_in
!= MTBSFM
&& 2231 cmd_in
!= MTBSR
&& cmd_in
!= MTBSS
) 2232 STps
->eof
= ST_EOM_OK
; 2237 (SCpnt
->sense_buffer
[3] <<24) + 2238 (SCpnt
->sense_buffer
[4] <<16) + 2239 (SCpnt
->sense_buffer
[5] <<8) + 2240 SCpnt
->sense_buffer
[6] ); 2241 if(cmd_in
== MTWEOF
&& 2242 (SCpnt
->sense_buffer
[0] &0x70) ==0x70&& 2243 (SCpnt
->sense_buffer
[2] &0x4f) ==0x40&& 2244 ((SCpnt
->sense_buffer
[0] &0x80) ==0|| undone
==0)) { 2245 ioctl_result
=0;/* EOF written succesfully at EOM */ 2248 STps
->drv_file
= fileno
; 2249 STps
->eof
= ST_NOEOF
; 2251 else if( (cmd_in
== MTFSF
) || (cmd_in
== MTFSFM
) ) { 2253 STps
->drv_file
= fileno
- undone
; 2255 STps
->drv_file
= fileno
; 2257 STps
->eof
= ST_NOEOF
; 2259 else if( (cmd_in
== MTBSF
) || (cmd_in
== MTBSFM
) ) { 2261 STps
->drv_file
= fileno
+ undone
; 2263 STps
->drv_file
= fileno
; 2265 STps
->eof
= ST_NOEOF
; 2267 else if(cmd_in
== MTFSR
) { 2268 if(SCpnt
->sense_buffer
[2] &0x80) {/* Hit filemark */ 2269 if(STps
->drv_file
>=0) 2276 STps
->drv_block
= blkno
- undone
; 2278 STps
->drv_block
= (-1); 2279 STps
->eof
= ST_NOEOF
; 2282 else if(cmd_in
== MTBSR
) { 2283 if(SCpnt
->sense_buffer
[2] &0x80) {/* Hit filemark */ 2285 STps
->drv_block
= (-1); 2289 STps
->drv_block
= blkno
+ undone
; 2291 STps
->drv_block
= (-1); 2293 STps
->eof
= ST_NOEOF
; 2295 else if(cmd_in
== MTEOM
) { 2296 STps
->drv_file
= (-1); 2297 STps
->drv_block
= (-1); 2301 STps
->eof
= ST_NOEOF
; 2303 if((SCpnt
->sense_buffer
[2] &0x0f) == BLANK_CHECK
) 2306 if(cmd_in
== MTLOCK
) 2307 STp
->door_locked
= ST_LOCK_FAILS
; 2310 return ioctl_result
; 2314 \f/* Get the tape position. If bt == 2, arg points into a kernel space mt_loc 2318 get_location(struct inode
* inode
,unsigned int*block
,int*partition
, 2322 int dev
=TAPE_NR(inode
->i_rdev
); 2324 unsigned char scmd
[10]; 2327 STp
= &(scsi_tapes
[dev
]); 2328 if(STp
->ready
!= ST_READY
) 2332 if((STp
->device
)->scsi_level
< SCSI_2
) { 2333 scmd
[0] = QFA_REQUEST_BLOCK
; 2337 scmd
[0] = READ_POSITION
; 2338 if(!logical
&& !STp
->scsi2_logical
) 2341 SCpnt
=st_do_scsi(NULL
, STp
, scmd
,20, ST_TIMEOUT
, MAX_READY_RETRIES
); 2345 if((STp
->buffer
)->last_result_fatal
!=0|| 2346 (STp
->device
->scsi_level
>= SCSI_2
&& 2347 ((STp
->buffer
)->b_data
[0] &4) !=0)) { 2348 *block
= *partition
=0; 2351 printk(ST_DEB_MSG
"st%d: Can't read tape position.\n", dev
); 2357 if((STp
->device
)->scsi_level
< SCSI_2
) { 2358 *block
= ((STp
->buffer
)->b_data
[0] <<16) 2359 + ((STp
->buffer
)->b_data
[1] <<8) 2360 + (STp
->buffer
)->b_data
[2]; 2364 *block
= ((STp
->buffer
)->b_data
[4] <<24) 2365 + ((STp
->buffer
)->b_data
[5] <<16) 2366 + ((STp
->buffer
)->b_data
[6] <<8) 2367 + (STp
->buffer
)->b_data
[7]; 2368 *partition
= (STp
->buffer
)->b_data
[1]; 2369 if(((STp
->buffer
)->b_data
[0] &0x80) && 2370 (STp
->buffer
)->b_data
[1] ==0)/* BOP of partition 0 */ 2371 STp
->ps
[0].drv_block
= STp
->ps
[0].drv_file
=0; 2375 printk(ST_DEB_MSG
"st%d: Got tape pos. blk %d part %d.\n", dev
, 2376 *block
, *partition
); 2380 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 2386 /* Set the tape block and partition. Negative partition means that only the 2387 block should be set in vendor specific way. */ 2389 set_location(struct inode
* inode
,unsigned int block
,int partition
, 2394 int dev
=TAPE_NR(inode
->i_rdev
); 2397 int timeout
= ST_LONG_TIMEOUT
; 2398 unsigned char scmd
[10]; 2401 STp
= &(scsi_tapes
[dev
]); 2402 if(STp
->ready
!= ST_READY
) 2404 STps
= &(STp
->ps
[STp
->partition
]); 2408 printk(ST_DEB_MSG
"st%d: Setting block to %d and partition to %d.\n", 2409 dev
, block
, partition
); 2414 /* Update the location at the partition we are leaving */ 2415 if((!STp
->can_partitions
&& partition
!=0) || 2416 partition
>= ST_NBR_PARTITIONS
) 2418 if(partition
!= STp
->partition
) { 2419 if(get_location(inode
, &blk
, &p
,1)) 2420 STps
->last_block_valid
= FALSE
; 2422 STps
->last_block_valid
= TRUE
; 2423 STps
->last_block_visited
= blk
; 2426 printk(ST_DEB_MSG
"st%d: Visited block %d for partition %d saved.\n", 2427 dev
, blk
, STp
->partition
); 2433 if((STp
->device
)->scsi_level
< SCSI_2
) { 2434 scmd
[0] = QFA_SEEK_BLOCK
; 2435 scmd
[2] = (block
>>16); 2436 scmd
[3] = (block
>>8); 2442 scmd
[3] = (block
>>24); 2443 scmd
[4] = (block
>>16); 2444 scmd
[5] = (block
>>8); 2446 if(!logical
&& !STp
->scsi2_logical
) 2448 if(STp
->partition
!= partition
) { 2450 scmd
[8] = partition
; 2453 printk(ST_DEB_MSG
"st%d: Trying to change partition from %d to %d\n", 2454 dev
, STp
->partition
, partition
); 2459 scmd
[1] |=1;/* Don't wait for completion */ 2460 timeout
= ST_TIMEOUT
; 2463 SCpnt
=st_do_scsi(NULL
, STp
, scmd
,20, timeout
, MAX_READY_RETRIES
); 2467 STps
->drv_block
= STps
->drv_file
= (-1); 2468 STps
->eof
= ST_NOEOF
; 2469 if((STp
->buffer
)->last_result_fatal
!=0) { 2471 if(STp
->can_partitions
&& 2472 (STp
->device
)->scsi_level
>= SCSI_2
&& 2473 (p
=find_partition(inode
)) >=0) 2477 if(STp
->can_partitions
) { 2478 STp
->partition
= partition
; 2479 STps
= &(STp
->ps
[partition
]); 2480 if(!STps
->last_block_valid
|| 2481 STps
->last_block_visited
!= block
) { 2489 STps
->drv_block
= STps
->drv_file
=0; 2492 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 2498 /* Find the current partition number for the drive status. Called from open and 2499 returns either partition number of negative error code. */ 2501 find_partition(struct inode
*inode
) 2506 if((i
=get_location(inode
, &block
, &partition
,1)) <0) 2508 if(partition
>= ST_NBR_PARTITIONS
) 2514 /* Change the partition if necessary */ 2516 update_partition(struct inode
* inode
) 2518 int dev
=TAPE_NR(inode
->i_rdev
); 2522 STp
= &(scsi_tapes
[dev
]); 2523 if(STp
->partition
== STp
->new_partition
) 2525 STps
= &(STp
->ps
[STp
->new_partition
]); 2526 if(!STps
->last_block_valid
) 2527 STps
->last_block_visited
=0; 2528 returnset_location(inode
, STps
->last_block_visited
, STp
->new_partition
,1); 2531 \f/* Functions for reading and writing the medium partition mode page. These 2532 seem to work with Wangtek 6200HS and HP C1533A. */ 2534 #define PART_PAGE 0x11 2535 #define PART_PAGE_LENGTH 10 2537 /* Get the number of partitions on the tape. As a side effect reads the 2538 mode page into the tape buffer. */ 2540 nbr_partitions(struct inode
* inode
) 2542 int dev
=TAPE_NR(inode
->i_rdev
), result
; 2544 Scsi_Cmnd
* SCpnt
= NULL
; 2545 unsigned char cmd
[10]; 2547 STp
= &(scsi_tapes
[dev
]); 2548 if(STp
->ready
!= ST_READY
) 2551 memset((void*) &cmd
[0],0,10); 2552 cmd
[0] = MODE_SENSE
; 2553 cmd
[1] =8;/* Page format */ 2557 SCpnt
=st_do_scsi(SCpnt
, STp
, cmd
,200, ST_TIMEOUT
, MAX_READY_RETRIES
); 2560 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 2562 if((STp
->buffer
)->last_result_fatal
!=0) { 2565 printk(ST_DEB_MSG
"st%d: Can't read medium partition page.\n", dev
); 2570 result
= (STp
->buffer
)->b_data
[MODE_HEADER_LENGTH
+3] +1; 2573 printk(ST_DEB_MSG
"st%d: Number of partitions %d.\n", dev
, result
); 2581 /* Partition the tape into two partitions if size > 0 or one partition if 2584 partition_tape(struct inode
* inode
,int size
) 2586 int dev
=TAPE_NR(inode
->i_rdev
), result
; 2589 Scsi_Cmnd
* SCpnt
= NULL
; 2590 unsigned char cmd
[10], *bp
; 2592 if((result
=nbr_partitions(inode
)) <0) 2594 STp
= &(scsi_tapes
[dev
]); 2596 /* The mode page is in the buffer. Let's modify it and write it. */ 2597 bp
= &((STp
->buffer
)->b_data
[0]); 2600 bp
[MODE_HEADER_LENGTH
+3] =0; 2603 printk(ST_DEB_MSG
"st%d: Formatting tape with one partition.\n", dev
); 2608 bp
[MODE_HEADER_LENGTH
+3] =1; 2609 bp
[MODE_HEADER_LENGTH
+8] = (size
>>8) &0xff; 2610 bp
[MODE_HEADER_LENGTH
+9] = size
&0xff; 2613 printk(ST_DEB_MSG
"st%d: Formatting tape with two partition (1 = %d MB).\n", 2617 bp
[MODE_HEADER_LENGTH
+6] =0; 2618 bp
[MODE_HEADER_LENGTH
+7] =0; 2619 bp
[MODE_HEADER_LENGTH
+4] =0x30;/* IDP | PSUM = MB */ 2623 bp
[MODE_HEADER_LENGTH
] &=0x3f; 2624 bp
[MODE_HEADER_LENGTH
+1] = length
-2; 2627 cmd
[0] = MODE_SELECT
; 2629 cmd
[4] = length
+ MODE_HEADER_LENGTH
; 2631 SCpnt
=st_do_scsi(SCpnt
, STp
, cmd
, cmd
[4], ST_LONG_TIMEOUT
, MAX_READY_RETRIES
); 2634 SCpnt
->request
.rq_status
= RQ_INACTIVE
;/* Mark as not busy */ 2636 if((STp
->buffer
)->last_result_fatal
!=0) { 2637 printk(KERN_INFO
"st%d: Partitioning of tape failed.\n", dev
); 2648 /* The ioctl command */ 2650 st_ioctl(struct inode
* inode
,struct file
* file
, 2651 unsigned int cmd_in
,unsigned long arg
) 2653 int i
, cmd_nr
, cmd_type
, bt
; 2656 struct mtpos mt_pos
; 2660 int dev
=TAPE_NR(inode
->i_rdev
); 2662 STp
= &(scsi_tapes
[dev
]); 2664 if(debugging
&& !STp
->in_use
) { 2665 printk(ST_DEB_MSG
"st%d: Incorrect device.\n", dev
); 2669 STm
= &(STp
->modes
[STp
->current_mode
]); 2670 STps
= &(STp
->ps
[STp
->partition
]); 2672 cmd_type
=_IOC_TYPE(cmd_in
); 2673 cmd_nr
=_IOC_NR(cmd_in
); 2675 if(cmd_type
==_IOC_TYPE(MTIOCTOP
) && cmd_nr
==_IOC_NR(MTIOCTOP
)) { 2676 if(_IOC_SIZE(cmd_in
) !=sizeof(mtc
)) 2679 i
=copy_from_user((char*) &mtc
, (char*)arg
,sizeof(struct mtop
)); 2683 if(mtc
.mt_op
== MTSETDRVBUFFER
&& !suser()) { 2684 printk(KERN_WARNING
"st%d: MTSETDRVBUFFER only allowed for root.\n", dev
); 2688 (mtc
.mt_op
!= MTSETDRVBUFFER
&& (mtc
.mt_count
& MT_ST_OPTIONS
) ==0)) 2691 if(!(STp
->device
)->was_reset
) { 2693 if(STps
->eof
== ST_FM_HIT
) { 2694 if(mtc
.mt_op
== MTFSF
|| mtc
.mt_op
== MTFSFM
|| mtc
.mt_op
== MTEOM
) { 2696 if(STps
->drv_file
>=0) 2699 else if(mtc
.mt_op
== MTBSF
|| mtc
.mt_op
== MTBSFM
) { 2701 if(STps
->drv_file
>=0) 2706 i
=flush_buffer(inode
, file
,/* mtc.mt_op == MTSEEK || */ 2707 mtc
.mt_op
== MTREW
|| mtc
.mt_op
== MTOFFL
|| 2708 mtc
.mt_op
== MTRETEN
|| mtc
.mt_op
== MTEOM
|| 2709 mtc
.mt_op
== MTLOCK
|| mtc
.mt_op
== MTLOAD
|| 2710 mtc
.mt_op
== MTCOMPRESSION
); 2716 * If there was a bus reset, block further access 2717 * to this device. If the user wants to rewind the tape, 2718 * then reset the flag and allow access again. 2720 if(mtc
.mt_op
!= MTREW
&& 2721 mtc
.mt_op
!= MTOFFL
&& 2722 mtc
.mt_op
!= MTRETEN
&& 2723 mtc
.mt_op
!= MTERASE
&& 2724 mtc
.mt_op
!= MTSEEK
&& 2727 STp
->device
->was_reset
=0; 2728 if(STp
->door_locked
!= ST_UNLOCKED
&& 2729 STp
->door_locked
!= ST_LOCK_FAILS
) { 2730 if(st_int_ioctl(inode
, MTLOCK
,0)) { 2731 printk(KERN_NOTICE
"st%d: Could not relock door after bus reset.\n", 2733 STp
->door_locked
= ST_UNLOCKED
; 2738 if(mtc
.mt_op
!= MTNOP
&& mtc
.mt_op
!= MTSETBLK
&& 2739 mtc
.mt_op
!= MTSETDENSITY
&& mtc
.mt_op
!= MTWSM
&& 2740 mtc
.mt_op
!= MTSETDRVBUFFER
&& mtc
.mt_op
!= MTSETPART
) 2741 STps
->rw
= ST_IDLE
;/* Prevent automatic WEOF and fsf */ 2743 if(mtc
.mt_op
== MTOFFL
&& STp
->door_locked
!= ST_UNLOCKED
) 2744 st_int_ioctl(inode
, MTUNLOCK
,0);/* Ignore result! */ 2746 if(mtc
.mt_op
== MTSETDRVBUFFER
&& 2747 (mtc
.mt_count
& MT_ST_OPTIONS
) !=0) 2748 returnst_set_options(inode
, mtc
.mt_count
); 2749 if(mtc
.mt_op
== MTSETPART
) { 2750 if(!STp
->can_partitions
|| 2751 mtc
.mt_count
<0|| mtc
.mt_count
>= ST_NBR_PARTITIONS
) 2753 if(mtc
.mt_count
>= STp
->nbr_partitions
&& 2754 (STp
->nbr_partitions
=nbr_partitions(inode
)) <0) 2756 if(mtc
.mt_count
>= STp
->nbr_partitions
) 2758 STp
->new_partition
= mtc
.mt_count
; 2761 if(mtc
.mt_op
== MTMKPART
) { 2762 if(!STp
->can_partitions
) 2764 if((i
=st_int_ioctl(inode
, MTREW
,0)) <0|| 2765 (i
=partition_tape(inode
, mtc
.mt_count
)) <0) 2767 for(i
=0; i
< ST_NBR_PARTITIONS
; i
++) { 2768 STp
->ps
[i
].rw
= ST_IDLE
; 2769 STp
->ps
[i
].at_sm
=0; 2770 STp
->ps
[i
].last_block_valid
= FALSE
; 2772 STp
->partition
= STp
->new_partition
=0; 2773 STp
->nbr_partitions
=1;/* Bad guess ?-) */ 2774 STps
->drv_block
= STps
->drv_file
=0; 2777 if(mtc
.mt_op
== MTSEEK
) { 2778 i
=set_location(inode
, mtc
.mt_count
, STp
->new_partition
,0); 2779 if(!STp
->can_partitions
) 2780 STp
->ps
[0].rw
= ST_IDLE
; 2783 if(STp
->can_partitions
&& STp
->ready
== ST_READY
&& 2784 (i
=update_partition(inode
)) <0) 2786 if(mtc
.mt_op
== MTCOMPRESSION
) 2787 returnst_compression(STp
, (mtc
.mt_count
&1)); 2789 returnst_int_ioctl(inode
, mtc
.mt_op
, mtc
.mt_count
); 2795 if((i
=flush_buffer(inode
, file
, FALSE
)) <0) 2797 if(STp
->can_partitions
&& 2798 (i
=update_partition(inode
)) <0) 2801 if(cmd_type
==_IOC_TYPE(MTIOCGET
) && cmd_nr
==_IOC_NR(MTIOCGET
)) { 2803 if(_IOC_SIZE(cmd_in
) !=sizeof(struct mtget
)) 2806 (STp
->mt_status
)->mt_dsreg
= 2807 ((STp
->block_size
<< MT_ST_BLKSIZE_SHIFT
) & MT_ST_BLKSIZE_MASK
) | 2808 ((STp
->density
<< MT_ST_DENSITY_SHIFT
) & MT_ST_DENSITY_MASK
); 2809 (STp
->mt_status
)->mt_blkno
= STps
->drv_block
; 2810 (STp
->mt_status
)->mt_fileno
= STps
->drv_file
; 2811 if(STp
->block_size
!=0) { 2812 if(STps
->rw
== ST_WRITING
) 2813 (STp
->mt_status
)->mt_blkno
+= 2814 (STp
->buffer
)->buffer_bytes
/ STp
->block_size
; 2815 else if(STps
->rw
== ST_READING
) 2816 (STp
->mt_status
)->mt_blkno
-= ((STp
->buffer
)->buffer_bytes
+ 2817 STp
->block_size
-1) / STp
->block_size
; 2820 (STp
->mt_status
)->mt_gstat
=0; 2821 if(STp
->drv_write_prot
) 2822 (STp
->mt_status
)->mt_gstat
|=GMT_WR_PROT(0xffffffff); 2823 if((STp
->mt_status
)->mt_blkno
==0) { 2824 if((STp
->mt_status
)->mt_fileno
==0) 2825 (STp
->mt_status
)->mt_gstat
|=GMT_BOT(0xffffffff); 2827 (STp
->mt_status
)->mt_gstat
|=GMT_EOF(0xffffffff); 2829 (STp
->mt_status
)->mt_resid
= STp
->partition
; 2830 if(STps
->eof
== ST_EOM_OK
|| STps
->eof
== ST_EOM_ERROR
) 2831 (STp
->mt_status
)->mt_gstat
|=GMT_EOT(0xffffffff); 2832 else if(STps
->eof
>= ST_EOM_OK
) 2833 (STp
->mt_status
)->mt_gstat
|=GMT_EOD(0xffffffff); 2834 if(STp
->density
==1) 2835 (STp
->mt_status
)->mt_gstat
|=GMT_D_800(0xffffffff); 2836 else if(STp
->density
==2) 2837 (STp
->mt_status
)->mt_gstat
|=GMT_D_1600(0xffffffff); 2838 else if(STp
->density
==3) 2839 (STp
->mt_status
)->mt_gstat
|=GMT_D_6250(0xffffffff); 2840 if(STp
->ready
== ST_READY
) 2841 (STp
->mt_status
)->mt_gstat
|=GMT_ONLINE(0xffffffff); 2842 if(STp
->ready
== ST_NO_TAPE
) 2843 (STp
->mt_status
)->mt_gstat
|=GMT_DR_OPEN(0xffffffff); 2845 (STp
->mt_status
)->mt_gstat
|=GMT_SM(0xffffffff); 2846 if(STm
->do_async_writes
|| (STm
->do_buffer_writes
&& STp
->block_size
!=0) || 2847 STp
->drv_buffer
!=0) 2848 (STp
->mt_status
)->mt_gstat
|=GMT_IM_REP_EN(0xffffffff); 2850 i
=copy_to_user((char*)arg
, (char*)(STp
->mt_status
), 2851 sizeof(struct mtget
)); 2855 (STp
->mt_status
)->mt_erreg
=0;/* Clear after read */ 2857 }/* End of MTIOCGET */ 2859 if(cmd_type
==_IOC_TYPE(MTIOCPOS
) && cmd_nr
==_IOC_NR(MTIOCPOS
)) { 2860 if(_IOC_SIZE(cmd_in
) !=sizeof(struct mtpos
)) 2862 if((i
=get_location(inode
, &blk
, &bt
,0)) <0) 2864 mt_pos
.mt_blkno
= blk
; 2865 i
=copy_to_user((char*)arg
, (char*) (&mt_pos
),sizeof(struct mtpos
)); 2871 returnscsi_ioctl(STp
->device
, cmd_in
, (void*) arg
); 2875 /* Try to allocate a new tape buffer */ 2877 new_tape_buffer(int from_initialization
,int need_dma
) 2879 int priority
, a_size
; 2882 if(st_nbr_buffers
>= st_template
.dev_max
) 2883 return NULL
;/* Should never happen */ 2885 if(from_initialization
) { 2886 priority
= GFP_ATOMIC
; 2887 a_size
= st_buffer_size
; 2890 priority
= GFP_KERNEL
; 2891 for(a_size
= PAGE_SIZE
; a_size
< st_buffer_size
; a_size
<<=1) 2892 ;/* Make sure we allocate efficiently */ 2894 tb
= (ST_buffer
*)scsi_init_malloc(sizeof(ST_buffer
), priority
); 2897 priority
|= GFP_DMA
; 2898 tb
->b_data
= (unsigned char*)scsi_init_malloc(a_size
, priority
); 2900 scsi_init_free((char*)tb
,sizeof(ST_buffer
)); 2905 printk(KERN_NOTICE
"st: Can't allocate new tape buffer (nbr %d).\n", 2912 "st: Allocated tape buffer %d (%d bytes, dma: %d, a: %p).\n", 2913 st_nbr_buffers
, a_size
, need_dma
, tb
->b_data
); 2917 tb
->buffer_size
= a_size
; 2919 tb
->orig_b_data
= NULL
; 2920 st_buffers
[st_nbr_buffers
++] = tb
; 2925 /* Try to allocate a temporary enlarged tape buffer */ 2927 enlarge_buffer(ST_buffer
*STbuffer
,int new_size
,int need_dma
) 2929 int a_size
, priority
; 2932 normalize_buffer(STbuffer
); 2934 for(a_size
= PAGE_SIZE
; a_size
< new_size
; a_size
<<=1) 2935 ;/* Make sure that we allocate efficiently */ 2937 priority
= GFP_KERNEL
; 2939 priority
|= GFP_DMA
; 2940 tbd
= (unsigned char*)scsi_init_malloc(a_size
, priority
); 2946 "st: Buffer at %p enlarged to %d bytes (dma: %d, a: %p).\n", 2947 STbuffer
->b_data
, a_size
, need_dma
, tbd
); 2950 STbuffer
->orig_b_data
= STbuffer
->b_data
; 2951 STbuffer
->orig_size
= STbuffer
->buffer_size
; 2952 STbuffer
->b_data
= tbd
; 2953 STbuffer
->buffer_size
= a_size
; 2958 /* Release the extra buffer */ 2960 normalize_buffer(ST_buffer
*STbuffer
) 2962 if(STbuffer
->orig_b_data
== NULL
) 2965 scsi_init_free(STbuffer
->b_data
, STbuffer
->buffer_size
); 2966 STbuffer
->b_data
= STbuffer
->orig_b_data
; 2967 STbuffer
->orig_b_data
= NULL
; 2968 STbuffer
->buffer_size
= STbuffer
->orig_size
; 2972 printk(ST_DEB_MSG
"st: Buffer at %p normalized to %d bytes.\n", 2973 STbuffer
->b_data
, STbuffer
->buffer_size
); 2979 /* Set the boot options. Syntax: st=xxx,yyy 2980 where xxx is buffer size in 1024 byte blocks and yyy is write threshold 2981 in 1024 byte blocks. */ 2983 st_setup(char*str
,int*ints
) 2985 if(ints
[0] >0&& ints
[1] >0) 2986 st_buffer_size
= ints
[1] * ST_BLOCK_SIZE
; 2987 if(ints
[0] >1&& ints
[2] >0) { 2988 st_write_threshold
= ints
[2] * ST_BLOCK_SIZE
; 2989 if(st_write_threshold
> st_buffer_size
) 2990 st_write_threshold
= st_buffer_size
; 2992 if(ints
[0] >2&& ints
[3] >0) 2993 st_max_buffers
= ints
[3]; 2998 static struct file_operations st_fops
= { 2999 NULL
,/* lseek - default */ 3000 st_read
,/* read - general block-dev read */ 3001 st_write
,/* write - general block-dev write */ 3002 NULL
,/* readdir - bad */ 3004 st_ioctl
,/* ioctl */ 3006 scsi_tape_open
,/* open */ 3007 scsi_tape_close
,/* release */ 3011 static intst_attach(Scsi_Device
* SDp
){ 3017 if(SDp
->type
!= TYPE_TAPE
)return1; 3019 if(st_template
.nr_dev
>= st_template
.dev_max
) 3025 for(tpnt
= scsi_tapes
, i
=0; i
<st_template
.dev_max
; i
++, tpnt
++) 3026 if(!tpnt
->device
)break; 3028 if(i
>= st_template
.dev_max
)panic("scsi_devices corrupt (st)"); 3030 scsi_tapes
[i
].device
= SDp
; 3031 if(SDp
->scsi_level
<=2) 3032 scsi_tapes
[i
].mt_status
->mt_type
= MT_ISSCSI1
; 3034 scsi_tapes
[i
].mt_status
->mt_type
= MT_ISSCSI2
; 3036 tpnt
->devt
=MKDEV(SCSI_TAPE_MAJOR
, i
); 3038 tpnt
->waiting
= NULL
; 3040 tpnt
->drv_buffer
=1;/* Try buffering if no mode sense */ 3041 tpnt
->restr_dma
= (SDp
->host
)->unchecked_isa_dma
; 3043 tpnt
->do_auto_lock
= ST_AUTO_LOCK
; 3044 tpnt
->can_bsr
= ST_IN_FILE_POS
; 3045 tpnt
->can_partitions
=0; 3046 tpnt
->two_fm
= ST_TWO_FM
; 3047 tpnt
->fast_mteom
= ST_FAST_MTEOM
; 3048 tpnt
->scsi2_logical
=0; 3049 tpnt
->write_threshold
= st_write_threshold
; 3050 tpnt
->default_drvbuffer
=0xff;/* No forced buffering */ 3052 tpnt
->new_partition
=0; 3053 tpnt
->nbr_partitions
=0; 3055 for(i
=0; i
< ST_NBR_MODES
; i
++) { 3056 STm
= &(tpnt
->modes
[i
]); 3057 STm
->defined
= FALSE
; 3058 STm
->sysv
= ST_SYSV
; 3059 STm
->defaults_for_writes
=0; 3060 STm
->do_async_writes
= ST_ASYNC_WRITES
; 3061 STm
->do_buffer_writes
= ST_BUFFER_WRITES
; 3062 STm
->do_read_ahead
= ST_READ_AHEAD
; 3063 STm
->default_compression
= ST_DONT_TOUCH
; 3064 STm
->default_blksize
= (-1);/* No forced size */ 3065 STm
->default_density
= (-1);/* No forced density */ 3068 for(i
=0; i
< ST_NBR_PARTITIONS
; i
++) { 3069 STps
= &(tpnt
->ps
[i
]); 3071 STps
->eof
= ST_NOEOF
; 3073 STps
->last_block_valid
= FALSE
; 3078 tpnt
->current_mode
=0; 3079 tpnt
->modes
[0].defined
= TRUE
; 3081 tpnt
->density_changed
= tpnt
->compression_changed
= 3082 tpnt
->blksize_changed
= FALSE
; 3084 st_template
.nr_dev
++; 3088 static intst_detect(Scsi_Device
* SDp
) 3090 if(SDp
->type
!= TYPE_TAPE
)return0; 3093 "Detected scsi tape st%d at scsi%d, channel %d, id %d, lun %d\n", 3094 st_template
.dev_noticed
++, 3095 SDp
->host
->host_no
, SDp
->channel
, SDp
->id
, SDp
->lun
); 3100 static int st_registered
=0; 3102 /* Driver initialization */ 3107 #if !ST_RUNTIME_BUFFERS 3111 if(st_template
.dev_noticed
==0)return0; 3113 if(!st_registered
) { 3114 if(register_chrdev(SCSI_TAPE_MAJOR
,"st",&st_fops
)) { 3115 printk(KERN_ERR
"Unable to get major %d for SCSI tapes\n",MAJOR_NR
); 3121 if(scsi_tapes
)return0; 3122 st_template
.dev_max
= st_template
.dev_noticed
+ ST_EXTRA_DEVS
; 3123 if(st_template
.dev_max
< ST_MAX_TAPES
) 3124 st_template
.dev_max
= ST_MAX_TAPES
; 3125 if(st_template
.dev_max
>128/ ST_NBR_MODES
) 3126 printk(KERN_INFO
"st: Only %d tapes accessible.\n",128/ ST_NBR_MODES
); 3128 (Scsi_Tape
*)scsi_init_malloc(st_template
.dev_max
*sizeof(Scsi_Tape
), 3130 if(scsi_tapes
== NULL
) { 3131 printk(KERN_ERR
"Unable to allocate descriptors for SCSI tapes.\n"); 3132 unregister_chrdev(SCSI_TAPE_MAJOR
,"st"); 3137 printk(ST_DEB_MSG
"st: Buffer size %d bytes, write threshold %d bytes.\n", 3138 st_buffer_size
, st_write_threshold
); 3141 memset(scsi_tapes
,0, st_template
.dev_max
*sizeof(Scsi_Tape
)); 3142 for(i
=0; i
< st_template
.dev_max
; ++i
) { 3143 STp
= &(scsi_tapes
[i
]); 3144 STp
->capacity
=0xfffff; 3145 STp
->mt_status
= (struct mtget
*)scsi_init_malloc(sizeof(struct mtget
), 3147 /* Initialize status */ 3148 memset((void*) scsi_tapes
[i
].mt_status
,0,sizeof(struct mtget
)); 3151 /* Allocate the buffers */ 3153 (ST_buffer
**)scsi_init_malloc(st_template
.dev_max
*sizeof(ST_buffer
*), 3155 if(st_buffers
== NULL
) { 3156 printk(KERN_ERR
"Unable to allocate tape buffer pointers.\n"); 3157 unregister_chrdev(SCSI_TAPE_MAJOR
,"st"); 3158 scsi_init_free((char*) scsi_tapes
, 3159 st_template
.dev_max
*sizeof(Scsi_Tape
)); 3163 #if ST_RUNTIME_BUFFERS 3166 target_nbr
= st_template
.dev_noticed
; 3167 if(target_nbr
< ST_EXTRA_DEVS
) 3168 target_nbr
= ST_EXTRA_DEVS
; 3169 if(target_nbr
> st_max_buffers
) 3170 target_nbr
= st_max_buffers
; 3172 for(i
=st_nbr_buffers
=0; i
< target_nbr
; i
++) { 3173 if(!new_tape_buffer(TRUE
, TRUE
)) { 3176 printk(KERN_ERR
"Can't continue without at least one tape buffer.\n"); 3177 unregister_chrdev(SCSI_TAPE_MAJOR
,"st"); 3178 scsi_init_free((char*) st_buffers
, 3179 st_template
.dev_max
*sizeof(ST_buffer
*)); 3180 scsi_init_free((char*) scsi_tapes
, 3181 st_template
.dev_max
*sizeof(Scsi_Tape
)); 3184 printk(KERN_INFO
"No tape buffers allocated at initialization.\n"); 3188 printk(KERN_INFO
"Number of tape buffers adjusted.\n"); 3196 static voidst_detach(Scsi_Device
* SDp
) 3201 for(tpnt
= scsi_tapes
, i
=0; i
<st_template
.dev_max
; i
++, tpnt
++) 3202 if(tpnt
->device
== SDp
) { 3203 tpnt
->device
= NULL
; 3205 st_template
.nr_dev
--; 3206 st_template
.dev_noticed
--; 3215 intinit_module(void) { 3216 st_template
.module
= &__this_module
; 3217 returnscsi_register_module(MODULE_SCSI_DEV
, &st_template
); 3220 voidcleanup_module(void) 3224 scsi_unregister_module(MODULE_SCSI_DEV
, &st_template
); 3225 unregister_chrdev(SCSI_TAPE_MAJOR
,"st"); 3227 if(scsi_tapes
!= NULL
) { 3228 scsi_init_free((char*) scsi_tapes
, 3229 st_template
.dev_max
*sizeof(Scsi_Tape
)); 3231 if(st_buffers
!= NULL
) { 3232 for(i
=0; i
< st_nbr_buffers
; i
++) 3233 if(st_buffers
[i
] != NULL
) { 3234 scsi_init_free((char*) st_buffers
[i
]->b_data
, 3235 st_buffers
[i
]->buffer_size
); 3236 scsi_init_free((char*) st_buffers
[i
],sizeof(ST_buffer
)); 3239 scsi_init_free((char*) st_buffers
, 3240 st_template
.dev_max
*sizeof(ST_buffer
*)); 3243 st_template
.dev_max
=0; 3244 printk(KERN_INFO
"st: Unloaded.\n");