Commit 02558d08 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] file->private_data in st.c and osst.c

	->open() of st and osst sets file->private_data to Scsi_Tape in
question, other methods use it (same as in sg.c)
parent 10e76361
......@@ -3075,7 +3075,6 @@ static int osst_write_frame(OS_Scsi_Tape * STp, Scsi_Request ** aSRpnt, int sync
/* Write command */
static ssize_t osst_write(struct file * filp, const char * buf, size_t count, loff_t *ppos)
{
struct inode *inode = filp->f_dentry->d_inode;
ssize_t total, retval = 0;
ssize_t i, do_count, blks, transfer;
int write_threshold;
......@@ -3084,8 +3083,7 @@ static ssize_t osst_write(struct file * filp, const char * buf, size_t count, lo
Scsi_Request * SRpnt = NULL;
ST_mode * STm;
ST_partstat * STps;
int dev = TAPE_NR(inode->i_rdev);
OS_Scsi_Tape * STp = os_scsi_tapes[dev];
OS_Scsi_Tape * STp = filp->private_data;
char *name = tape_name(STp);
......@@ -3404,15 +3402,13 @@ if (SRpnt) printk(KERN_ERR "%s:A: Not supposed to have SRpnt at line %d\n", name
/* Read command */
static ssize_t osst_read(struct file * filp, char * buf, size_t count, loff_t *ppos)
{
struct inode * inode = filp->f_dentry->d_inode;
ssize_t total, retval = 0;
ssize_t i, transfer;
int special;
ST_mode * STm;
ST_partstat * STps;
Scsi_Request *SRpnt = NULL;
int dev = TAPE_NR(inode->i_rdev);
OS_Scsi_Tape * STp = os_scsi_tapes[dev];
OS_Scsi_Tape * STp = filp->private_data;
char *name = tape_name(STp);
......@@ -4169,6 +4165,7 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
if (dev >= osst_template.dev_max || (STp = os_scsi_tapes[dev]) == NULL || !STp->device)
return (-ENXIO);
filp->private_data = STp;
name = tape_name(STp);
if( !scsi_block_when_processing_errors(STp->device) ) {
......@@ -4540,18 +4537,15 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
/* Flush the tape buffer before close */
static int os_scsi_tape_flush(struct file * filp)
{
struct inode *inode = filp->f_dentry->d_inode;
kdev_t devt = inode->i_rdev;
int dev = TAPE_NR(devt);
int result = 0, result2;
OS_Scsi_Tape * STp = os_scsi_tapes[dev];
OS_Scsi_Tape * STp = filp->private_data;
ST_mode * STm = &(STp->modes[STp->current_mode]);
ST_partstat * STps = &(STp->ps[STp->partition]);
Scsi_Request *SRpnt = NULL;
char *name = tape_name(STp);
if (file_count(filp) > 1)
return 0;
return 0;
if ( STps->rw == ST_WRITING && !(STp->device)->was_reset) {
result = osst_flush_write_buffer(STp, &SRpnt);
......@@ -4646,9 +4640,7 @@ static int os_scsi_tape_flush(struct file * filp)
static int os_scsi_tape_close(struct inode * inode, struct file * filp)
{
int result = 0;
kdev_t devt = inode->i_rdev;
int dev = TAPE_NR(devt);
OS_Scsi_Tape * STp = os_scsi_tapes[dev];
OS_Scsi_Tape * STp = filp->private_data;
Scsi_Request * SRpnt = NULL;
if (STp->door_locked == ST_LOCKED_AUTO)
......@@ -4682,8 +4674,7 @@ static int osst_ioctl(struct inode * inode,struct file * file,
ST_mode *STm;
ST_partstat *STps;
Scsi_Request *SRpnt = NULL;
int dev = TAPE_NR(inode->i_rdev);
OS_Scsi_Tape *STp = os_scsi_tapes[dev];
OS_Scsi_Tape *STp = file->private_data;
char *name = tape_name(STp);
if (down_interruptible(&STp->lock))
......@@ -5577,52 +5568,53 @@ static int osst_registered = 0;
/* Driver initialization (not __initfunc because may be called later) */
static int osst_init()
{
int i;
int i;
if (osst_template.dev_noticed == 0) return 0;
if (osst_template.dev_noticed == 0)
return 0;
if(!osst_registered) {
if (register_chrdev(MAJOR_NR,"osst",&osst_fops)) {
printk(KERN_ERR "osst :W: Unable to get major %d for OnStream tapes\n",MAJOR_NR);
if (!osst_registered) {
if (register_chrdev(MAJOR_NR,"osst",&osst_fops)) {
printk(KERN_ERR "osst :W: Unable to get major %d for OnStream tapes\n",MAJOR_NR);
return 1;
}
osst_registered++;
}
if (os_scsi_tapes)
return 0;
osst_template.dev_max = OSST_MAX_TAPES;
if (osst_template.dev_max > 128 / ST_NBR_MODES)
printk(KERN_INFO "osst :I: Only %d tapes accessible.\n", 128 / ST_NBR_MODES);
os_scsi_tapes = kmalloc(osst_template.dev_max * sizeof(OS_Scsi_Tape *),
GFP_ATOMIC);
if (!os_scsi_tapes) {
printk(KERN_ERR "osst :W: Unable to allocate array for OnStream SCSI tapes.\n");
unregister_chrdev(MAJOR_NR, "osst");
return 1;
}
osst_registered++;
}
if (os_scsi_tapes) return 0;
osst_template.dev_max = OSST_MAX_TAPES;
if (osst_template.dev_max > 128 / ST_NBR_MODES)
printk(KERN_INFO "osst :I: Only %d tapes accessible.\n", 128 / ST_NBR_MODES);
os_scsi_tapes =
(OS_Scsi_Tape **)kmalloc(osst_template.dev_max * sizeof(OS_Scsi_Tape *),
GFP_ATOMIC);
if (os_scsi_tapes == NULL) {
printk(KERN_ERR "osst :W: Unable to allocate array for OnStream SCSI tapes.\n");
unregister_chrdev(MAJOR_NR, "osst");
return 1;
}
for (i=0; i < osst_template.dev_max; ++i) os_scsi_tapes[i] = NULL;
for (i=0; i < osst_template.dev_max; ++i)
os_scsi_tapes[i] = NULL;
/* Allocate the buffer pointers */
osst_buffers =
(OSST_buffer **)kmalloc(osst_template.dev_max * sizeof(OSST_buffer *),
GFP_ATOMIC);
if (osst_buffers == NULL) {
printk(KERN_ERR "osst :W: Unable to allocate tape buffer pointers.\n");
unregister_chrdev(MAJOR_NR, "osst");
kfree(os_scsi_tapes);
return 1;
}
osst_nbr_buffers = 0;
/* Allocate the buffer pointers */
osst_buffers = kmalloc(osst_template.dev_max * sizeof(OSST_buffer *),
GFP_ATOMIC);
if (!osst_buffers) {
printk(KERN_ERR "osst :W: Unable to allocate tape buffer pointers.\n");
unregister_chrdev(MAJOR_NR, "osst");
kfree(os_scsi_tapes);
return 1;
}
osst_nbr_buffers = 0;
printk(KERN_INFO "osst :I: Tape driver with OnStream support version %s\nosst :I: %s\n", osst_version, cvsid);
printk(KERN_INFO "osst :I: Tape driver with OnStream support version %s\nosst :I: %s\n", osst_version, cvsid);
#if DEBUG
printk(OSST_DEB_MSG "osst :D: Buffer size %d bytes, write threshold %d bytes.\n",
osst_buffer_size, osst_write_threshold);
printk(OSST_DEB_MSG "osst :D: Buffer size %d bytes, write threshold %d bytes.\n",
osst_buffer_size, osst_write_threshold);
#endif
return 0;
return 0;
}
......@@ -5640,10 +5632,10 @@ static void osst_detach(Scsi_Device * SDp)
tpnt->device = NULL;
#ifdef CONFIG_DEVFS_FS
for (mode = 0; mode < ST_NBR_MODES; ++mode) {
devfs_unregister (tpnt->de_r[mode]);
tpnt->de_r[mode] = NULL;
devfs_unregister (tpnt->de_n[mode]);
tpnt->de_n[mode] = NULL;
devfs_unregister (tpnt->de_r[mode]);
tpnt->de_r[mode] = NULL;
devfs_unregister (tpnt->de_n[mode]);
tpnt->de_n[mode] = NULL;
}
#endif
kfree(tpnt);
......@@ -5665,34 +5657,36 @@ static int __init init_osst(void)
static void __exit exit_osst (void)
{
int i;
OS_Scsi_Tape * STp;
scsi_unregister_device(&osst_template);
unregister_chrdev(MAJOR_NR, "osst");
osst_registered--;
if(os_scsi_tapes != NULL) {
for (i=0; i < osst_template.dev_max; ++i) {
if ((STp = os_scsi_tapes[i])) {
if (STp->header_cache != NULL) vfree(STp->header_cache);
kfree(STp);
}
}
kfree(os_scsi_tapes);
if (osst_buffers != NULL) {
for (i=0; i < osst_nbr_buffers; i++)
if (osst_buffers[i] != NULL) {
osst_buffers[i]->orig_sg_segs = 0;
normalize_buffer(osst_buffers[i]);
kfree(osst_buffers[i]);
}
int i;
OS_Scsi_Tape * STp;
kfree(osst_buffers);
scsi_unregister_device(&osst_template);
unregister_chrdev(MAJOR_NR, "osst");
osst_registered--;
if (os_scsi_tapes) {
for (i=0; i < osst_template.dev_max; ++i) {
STp = os_scsi_tapes[i];
if (!STp)
continue;
if (STp->header_cache)
vfree(STp->header_cache);
kfree(STp);
}
kfree(os_scsi_tapes);
if (osst_buffers) {
for (i=0; i < osst_nbr_buffers; i++) {
if (osst_buffers[i]) {
osst_buffers[i]->orig_sg_segs = 0;
normalize_buffer(osst_buffers[i]);
kfree(osst_buffers[i]);
}
}
kfree(osst_buffers);
}
}
}
osst_template.dev_max = 0;
printk(KERN_INFO "osst :I: Unloaded.\n");
osst_template.dev_max = 0;
printk(KERN_INFO "osst :I: Unloaded.\n");
}
module_init(init_osst);
......
......@@ -986,6 +986,7 @@ static int st_open(struct inode *inode, struct file *filp)
write_unlock(&st_dev_arr_lock);
return (-ENXIO);
}
filp->private_data = STp;
name = tape_name(STp);
if (STp->in_use) {
......@@ -1052,26 +1053,16 @@ static int st_open(struct inode *inode, struct file *filp)
static int st_flush(struct file *filp)
{
int result = 0, result2;
struct inode *inode = filp->f_dentry->d_inode;
kdev_t devt = inode->i_rdev;
int dev = TAPE_NR(devt);
unsigned char cmd[MAX_COMMAND_SIZE];
Scsi_Request *SRpnt;
Scsi_Tape *STp;
ST_mode *STm;
ST_partstat *STps;
char *name;
Scsi_Tape *STp = filp->private_data;
ST_mode *STm = &(STp->modes[STp->current_mode]);
ST_partstat *STps = &(STp->ps[STp->partition]);
char *name = tape_name(STp);
if (file_count(filp) > 1)
return 0;
read_lock(&st_dev_arr_lock);
STp = scsi_tapes[dev];
read_unlock(&st_dev_arr_lock);
STm = &(STp->modes[STp->current_mode]);
STps = &(STp->ps[STp->partition]);
name = tape_name(STp);
if (STps->rw == ST_WRITING && !STp->pos_unknown) {
result = flush_write_buffer(STp);
if (result != 0 && result != (-ENOSPC))
......@@ -1176,15 +1167,7 @@ static int st_flush(struct file *filp)
static int st_release(struct inode *inode, struct file *filp)
{
int result = 0;
Scsi_Tape *STp;
kdev_t devt = inode->i_rdev;
int dev;
dev = TAPE_NR(devt);
read_lock(&st_dev_arr_lock);
STp = scsi_tapes[dev];
read_unlock(&st_dev_arr_lock);
Scsi_Tape *STp = filp->private_data;
if (STp->door_locked == ST_LOCKED_AUTO)
do_door_lock(STp, 0);
......@@ -1332,7 +1315,6 @@ static int setup_buffering(Scsi_Tape *STp, const char *buf, size_t count, int is
static ssize_t
st_write(struct file *filp, const char *buf, size_t count, loff_t * ppos)
{
struct inode *inode = filp->f_dentry->d_inode;
ssize_t total;
ssize_t i, do_count, blks, transfer;
ssize_t retval;
......@@ -1341,17 +1323,11 @@ static ssize_t
unsigned char cmd[MAX_COMMAND_SIZE];
const char *b_point;
Scsi_Request *SRpnt = NULL;
Scsi_Tape *STp;
Scsi_Tape *STp = filp->private_data;
ST_mode *STm;
ST_partstat *STps;
ST_buffer *STbp;
int dev = TAPE_NR(inode->i_rdev);
char *name;
read_lock(&st_dev_arr_lock);
STp = scsi_tapes[dev];
read_unlock(&st_dev_arr_lock);
name = tape_name(STp);
char *name = tape_name(STp);
if (down_interruptible(&STp->lock))
return -ERESTARTSYS;
......@@ -1781,24 +1757,16 @@ static long read_tape(Scsi_Tape *STp, long count, Scsi_Request ** aSRpnt)
static ssize_t
st_read(struct file *filp, char *buf, size_t count, loff_t * ppos)
{
struct inode *inode = filp->f_dentry->d_inode;
ssize_t total;
ssize_t retval = 0;
ssize_t i, transfer;
int special;
Scsi_Request *SRpnt = NULL;
Scsi_Tape *STp;
Scsi_Tape *STp = filp->private_data;
ST_mode *STm;
ST_partstat *STps;
ST_buffer *STbp;
int dev = TAPE_NR(inode->i_rdev);
char *name;
read_lock(&st_dev_arr_lock);
STp = scsi_tapes[dev];
read_unlock(&st_dev_arr_lock);
name = tape_name(STp);
STbp = STp->buffer;
ST_buffer *STbp = STp->buffer;
DEB( char *name = tape_name(STp); )
if (down_interruptible(&STp->lock))
return -ERESTARTSYS;
......@@ -3077,17 +3045,10 @@ static int st_ioctl(struct inode *inode, struct file *file,
int i, cmd_nr, cmd_type, bt;
int retval = 0;
unsigned int blk;
Scsi_Tape *STp;
Scsi_Tape *STp = file->private_data;
ST_mode *STm;
ST_partstat *STps;
int dev = TAPE_NR(inode->i_rdev);
char *name;
read_lock(&st_dev_arr_lock);
STp = scsi_tapes[dev];
read_unlock(&st_dev_arr_lock);
name = tape_name(STp);
char *name = tape_name(STp);
if (down_interruptible(&STp->lock))
return -ERESTARTSYS;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment