Import 2.3.18pre1
[davej-history.git] / drivers / scsi / sd_ioctl.c
blob486d911be8df7b240dbff04144e39a658ffd9bbc
1 /*
2 * drivers/scsi/sd_ioctl.c
4 * ioctl handling for SCSI disks
5 */
7 #include <linux/kernel.h>
8 #include <linux/sched.h>
9 #include <linux/mm.h>
10 #include <linux/fs.h>
11 #include <linux/hdreg.h>
12 #include <linux/errno.h>
14 #include <asm/uaccess.h>
16 #define MAJOR_NR SCSI_DISK0_MAJOR
17 #include <linux/blk.h>
18 #include <linux/blkpg.h>
19 #include"scsi.h"
20 #include <scsi/scsi_ioctl.h>
21 #include"hosts.h"
22 #include"sd.h"
23 #include <scsi/scsicam.h>/* must follow "hosts.h" */
25 intsd_ioctl(struct inode * inode,struct file * file,unsigned int cmd,unsigned long arg)
27 kdev_t dev = inode->i_rdev;
28 int error;
29 struct Scsi_Host * host;
30 Scsi_Device * SDev;
31 int diskinfo[4];
32 struct hd_geometry *loc = (struct hd_geometry *) arg;
34 SDev = rscsi_disks[DEVICE_NR(dev)].device;
36 * If we are in the middle of error recovery, don't let anyone
37 * else try and use this device. Also, if error recovery fails, it
38 * may try and take the device offline, in which case all further
39 * access to the device is prohibited.
41 if( !scsi_block_when_processing_errors(SDev) )
43 return-ENODEV;
46 switch(cmd) {
47 case HDIO_GETGEO:/* Return BIOS disk parameters */
48 if(!loc)return-EINVAL;
49 error =verify_area(VERIFY_WRITE, loc,sizeof(*loc));
50 if(error)
51 return error;
52 host = rscsi_disks[DEVICE_NR(dev)].device->host;
54 /* default to most commonly used values */
56 diskinfo[0] =0x40;
57 diskinfo[1] =0x20;
58 diskinfo[2] = rscsi_disks[DEVICE_NR(dev)].capacity >>11;
60 /* override with calculated, extended default, or driver values */
62 if(host->hostt->bios_param != NULL)
63 host->hostt->bios_param(&rscsi_disks[DEVICE_NR(dev)],
64 dev,
65 &diskinfo[0]);
66 elsescsicam_bios_param(&rscsi_disks[DEVICE_NR(dev)],
67 dev, &diskinfo[0]);
69 put_user(diskinfo[0], &loc->heads);
70 put_user(diskinfo[1], &loc->sectors);
71 put_user(diskinfo[2], &loc->cylinders);
72 put_user(sd[SD_PARTITION(inode->i_rdev)].start_sect, &loc->start);
73 return0;
74 case BLKGETSIZE:/* Return device size */
75 if(!arg)return-EINVAL;
76 error =verify_area(VERIFY_WRITE, (long*) arg,sizeof(long));
77 if(error)
78 return error;
79 put_user(sd[SD_PARTITION(inode->i_rdev)].nr_sects,
80 (long*) arg);
81 return0;
83 case BLKROSET:
84 case BLKROGET:
85 case BLKRASET:
86 case BLKRAGET:
87 case BLKFLSBUF:
88 case BLKSSZGET:
89 case BLKPG:
90 returnblk_ioctl(inode->i_rdev, cmd, arg);
92 case BLKRRPART:/* Re-read partition tables */
93 if(!capable(CAP_SYS_ADMIN))
94 return-EACCES;
95 returnrevalidate_scsidisk(dev,1);
97 default:
98 returnscsi_ioctl(rscsi_disks[DEVICE_NR(dev)].device , cmd, (void*) arg);
103 * Overrides for Emacs so that we follow Linus's tabbing style.
104 * Emacs will notice this stuff at the end of the file and automatically
105 * adjust the settings for this buffer only. This must remain at the end
106 * of the file.
107 * ---------------------------------------------------------------------------
108 * Local variables:
109 * c-indent-level: 4
110 * c-brace-imaginary-offset: 0
111 * c-brace-offset: -4
112 * c-argdecl-indent: 4
113 * c-label-offset: -4
114 * c-continued-statement-offset: 4
115 * c-continued-brace-offset: 0
116 * indent-tabs-mode: nil
117 * tab-width: 8
118 * End:
close