Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File...........: linux/drivers/s390/block/dasd_ioctl.c |
| 3 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> |
| 4 | * Horst Hummel <Horst.Hummel@de.ibm.com> |
| 5 | * Carsten Otte <Cotte@de.ibm.com> |
| 6 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 7 | * Bugreports.to..: <Linux390@de.ibm.com> |
| 8 | * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001 |
| 9 | * |
| 10 | * i/o controls for the dasd driver. |
| 11 | */ |
| 12 | #include <linux/config.h> |
| 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/major.h> |
| 15 | #include <linux/fs.h> |
| 16 | #include <linux/blkpg.h> |
| 17 | |
| 18 | #include <asm/ccwdev.h> |
Christoph Hellwig | 8b2eb66 | 2006-03-24 03:15:21 -0800 | [diff] [blame] | 19 | #include <asm/cmb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/uaccess.h> |
| 21 | |
| 22 | /* This is ugly... */ |
| 23 | #define PRINTK_HEADER "dasd_ioctl:" |
| 24 | |
| 25 | #include "dasd_int.h" |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 29 | dasd_ioctl_api_version(void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | { |
| 31 | int ver = DASD_API_VERSION; |
Bastian Blank | b502962 | 2006-03-24 03:15:32 -0800 | [diff] [blame] | 32 | return put_user(ver, (int __user *)argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | /* |
| 36 | * Enable device. |
| 37 | * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection |
| 38 | */ |
| 39 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 40 | dasd_ioctl_enable(struct block_device *bdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 42 | struct dasd_device *device = bdev->bd_disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | if (!capable(CAP_SYS_ADMIN)) |
| 45 | return -EACCES; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | dasd_enable_device(device); |
| 48 | /* Formatting the dasd device can change the capacity. */ |
Arjan van de Ven | c039e31 | 2006-03-23 03:00:28 -0800 | [diff] [blame] | 49 | mutex_lock(&bdev->bd_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | i_size_write(bdev->bd_inode, (loff_t)get_capacity(device->gdp) << 9); |
Arjan van de Ven | c039e31 | 2006-03-23 03:00:28 -0800 | [diff] [blame] | 51 | mutex_unlock(&bdev->bd_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * Disable device. |
| 57 | * Used by dasdfmt. Disable I/O operations but allow ioctls. |
| 58 | */ |
| 59 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 60 | dasd_ioctl_disable(struct block_device *bdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 62 | struct dasd_device *device = bdev->bd_disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | if (!capable(CAP_SYS_ADMIN)) |
| 65 | return -EACCES; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | /* |
| 68 | * Man this is sick. We don't do a real disable but only downgrade |
| 69 | * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses |
| 70 | * BIODASDDISABLE to disable accesses to the device via the block |
| 71 | * device layer but it still wants to do i/o on the device by |
| 72 | * using the BIODASDFMT ioctl. Therefore the correct state for the |
| 73 | * device is DASD_STATE_BASIC that allows to do basic i/o. |
| 74 | */ |
| 75 | dasd_set_target_state(device, DASD_STATE_BASIC); |
| 76 | /* |
| 77 | * Set i_size to zero, since read, write, etc. check against this |
| 78 | * value. |
| 79 | */ |
Arjan van de Ven | c039e31 | 2006-03-23 03:00:28 -0800 | [diff] [blame] | 80 | mutex_lock(&bdev->bd_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | i_size_write(bdev->bd_inode, 0); |
Arjan van de Ven | c039e31 | 2006-03-23 03:00:28 -0800 | [diff] [blame] | 82 | mutex_unlock(&bdev->bd_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * Quiesce device. |
| 88 | */ |
| 89 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 90 | dasd_ioctl_quiesce(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | unsigned long flags; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame^] | 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | if (!capable (CAP_SYS_ADMIN)) |
| 95 | return -EACCES; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame^] | 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | DEV_MESSAGE (KERN_DEBUG, device, "%s", |
| 98 | "Quiesce IO on device"); |
| 99 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 100 | device->stopped |= DASD_STOPPED_QUIESCE; |
| 101 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | /* |
| 107 | * Quiesce device. |
| 108 | */ |
| 109 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 110 | dasd_ioctl_resume(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | unsigned long flags; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame^] | 113 | |
| 114 | if (!capable (CAP_SYS_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | return -EACCES; |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | DEV_MESSAGE (KERN_DEBUG, device, "%s", |
| 118 | "resume IO on device"); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame^] | 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 121 | device->stopped &= ~DASD_STOPPED_QUIESCE; |
| 122 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 123 | |
| 124 | dasd_schedule_bh (device); |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * performs formatting of _device_ according to _fdata_ |
| 130 | * Note: The discipline's format_function is assumed to deliver formatting |
| 131 | * commands to format a single unit of the device. In terms of the ECKD |
| 132 | * devices this means CCWs are generated to format a single track. |
| 133 | */ |
| 134 | static int |
| 135 | dasd_format(struct dasd_device * device, struct format_data_t * fdata) |
| 136 | { |
| 137 | struct dasd_ccw_req *cqr; |
| 138 | int rc; |
| 139 | |
| 140 | if (device->discipline->format_device == NULL) |
| 141 | return -EPERM; |
| 142 | |
| 143 | if (device->state != DASD_STATE_BASIC) { |
| 144 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 145 | "dasd_format: device is not disabled! "); |
| 146 | return -EBUSY; |
| 147 | } |
| 148 | |
| 149 | DBF_DEV_EVENT(DBF_NOTICE, device, |
| 150 | "formatting units %d to %d (%d B blocks) flags %d", |
| 151 | fdata->start_unit, |
| 152 | fdata->stop_unit, fdata->blksize, fdata->intensity); |
| 153 | |
| 154 | /* Since dasdfmt keeps the device open after it was disabled, |
| 155 | * there still exists an inode for this device. |
| 156 | * We must update i_blkbits, otherwise we might get errors when |
| 157 | * enabling the device later. |
| 158 | */ |
| 159 | if (fdata->start_unit == 0) { |
| 160 | struct block_device *bdev = bdget_disk(device->gdp, 0); |
| 161 | bdev->bd_inode->i_blkbits = blksize_bits(fdata->blksize); |
| 162 | bdput(bdev); |
| 163 | } |
| 164 | |
| 165 | while (fdata->start_unit <= fdata->stop_unit) { |
| 166 | cqr = device->discipline->format_device(device, fdata); |
| 167 | if (IS_ERR(cqr)) |
| 168 | return PTR_ERR(cqr); |
| 169 | rc = dasd_sleep_on_interruptible(cqr); |
| 170 | dasd_sfree_request(cqr, cqr->device); |
| 171 | if (rc) { |
| 172 | if (rc != -ERESTARTSYS) |
| 173 | DEV_MESSAGE(KERN_ERR, device, |
| 174 | " Formatting of unit %d failed " |
| 175 | "with rc = %d", |
| 176 | fdata->start_unit, rc); |
| 177 | return rc; |
| 178 | } |
| 179 | fdata->start_unit++; |
| 180 | } |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | /* |
| 185 | * Format device. |
| 186 | */ |
| 187 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 188 | dasd_ioctl_format(struct block_device *bdev, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 190 | struct dasd_device *device = bdev->bd_disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | struct format_data_t fdata; |
| 192 | |
| 193 | if (!capable(CAP_SYS_ADMIN)) |
| 194 | return -EACCES; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 195 | if (!argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | return -EINVAL; |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 197 | |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 198 | if (device->features & DASD_FEATURE_READONLY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | return -EROFS; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 200 | if (copy_from_user(&fdata, argp, sizeof(struct format_data_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | return -EFAULT; |
| 202 | if (bdev != bdev->bd_contains) { |
| 203 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
| 204 | "Cannot low-level format a partition"); |
| 205 | return -EINVAL; |
| 206 | } |
| 207 | return dasd_format(device, &fdata); |
| 208 | } |
| 209 | |
| 210 | #ifdef CONFIG_DASD_PROFILE |
| 211 | /* |
| 212 | * Reset device profile information |
| 213 | */ |
| 214 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 215 | dasd_ioctl_reset_profile(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | memset(&device->profile, 0, sizeof (struct dasd_profile_info_t)); |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * Return device profile information |
| 223 | */ |
| 224 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 225 | dasd_ioctl_read_profile(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
Horst Hummel | 9a7af28 | 2006-01-06 00:19:14 -0800 | [diff] [blame] | 227 | if (dasd_profile_level == DASD_PROFILE_OFF) |
| 228 | return -EIO; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 229 | if (copy_to_user(argp, &device->profile, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | sizeof (struct dasd_profile_info_t))) |
| 231 | return -EFAULT; |
| 232 | return 0; |
| 233 | } |
| 234 | #else |
| 235 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 236 | dasd_ioctl_reset_profile(struct dasd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { |
| 238 | return -ENOSYS; |
| 239 | } |
| 240 | |
| 241 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 242 | dasd_ioctl_read_profile(struct dasd_device *device, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
| 244 | return -ENOSYS; |
| 245 | } |
| 246 | #endif |
| 247 | |
| 248 | /* |
| 249 | * Return dasd information. Used for BIODASDINFO and BIODASDINFO2. |
| 250 | */ |
| 251 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 252 | dasd_ioctl_information(struct dasd_device *device, |
| 253 | unsigned int cmd, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | struct dasd_information2_t *dasd_info; |
| 256 | unsigned long flags; |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 257 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | struct ccw_device *cdev; |
| 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (!device->discipline->fill_info) |
| 261 | return -EINVAL; |
| 262 | |
Horst Hummel | 554a826 | 2006-03-24 03:15:24 -0800 | [diff] [blame] | 263 | dasd_info = kzalloc(sizeof(struct dasd_information2_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | if (dasd_info == NULL) |
| 265 | return -ENOMEM; |
| 266 | |
| 267 | rc = device->discipline->fill_info(device, dasd_info); |
| 268 | if (rc) { |
| 269 | kfree(dasd_info); |
| 270 | return rc; |
| 271 | } |
| 272 | |
| 273 | cdev = device->cdev; |
| 274 | |
| 275 | dasd_info->devno = _ccw_device_get_device_number(device->cdev); |
| 276 | dasd_info->schid = _ccw_device_get_subchannel_number(device->cdev); |
| 277 | dasd_info->cu_type = cdev->id.cu_type; |
| 278 | dasd_info->cu_model = cdev->id.cu_model; |
| 279 | dasd_info->dev_type = cdev->id.dev_type; |
| 280 | dasd_info->dev_model = cdev->id.dev_model; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | dasd_info->status = device->state; |
Horst Hummel | 5746719 | 2006-02-01 03:06:36 -0800 | [diff] [blame] | 282 | /* |
| 283 | * The open_count is increased for every opener, that includes |
| 284 | * the blkdev_get in dasd_scan_partitions. |
| 285 | * This must be hidden from user-space. |
| 286 | */ |
| 287 | dasd_info->open_count = atomic_read(&device->open_count); |
| 288 | if (!device->bdev) |
| 289 | dasd_info->open_count++; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame^] | 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | /* |
| 292 | * check if device is really formatted |
| 293 | * LDL / CDL was returned by 'fill_info' |
| 294 | */ |
| 295 | if ((device->state < DASD_STATE_READY) || |
| 296 | (dasd_check_blocksize(device->bp_block))) |
| 297 | dasd_info->format = DASD_FORMAT_NONE; |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 298 | |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 299 | dasd_info->features |= |
| 300 | ((device->features & DASD_FEATURE_READONLY) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | if (device->discipline) |
| 303 | memcpy(dasd_info->type, device->discipline->name, 4); |
| 304 | else |
| 305 | memcpy(dasd_info->type, "none", 4); |
Horst Hummel | 554a826 | 2006-03-24 03:15:24 -0800 | [diff] [blame] | 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | if (device->request_queue->request_fn) { |
| 308 | struct list_head *l; |
| 309 | #ifdef DASD_EXTENDED_PROFILING |
| 310 | { |
| 311 | struct list_head *l; |
| 312 | spin_lock_irqsave(&device->lock, flags); |
| 313 | list_for_each(l, &device->request_queue->queue_head) |
| 314 | dasd_info->req_queue_len++; |
| 315 | spin_unlock_irqrestore(&device->lock, flags); |
| 316 | } |
| 317 | #endif /* DASD_EXTENDED_PROFILING */ |
| 318 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 319 | list_for_each(l, &device->ccw_queue) |
| 320 | dasd_info->chanq_len++; |
| 321 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), |
| 322 | flags); |
| 323 | } |
| 324 | |
| 325 | rc = 0; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 326 | if (copy_to_user(argp, dasd_info, |
| 327 | ((cmd == (unsigned int) BIODASDINFO2) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | sizeof (struct dasd_information2_t) : |
| 329 | sizeof (struct dasd_information_t)))) |
| 330 | rc = -EFAULT; |
| 331 | kfree(dasd_info); |
| 332 | return rc; |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | * Set read only |
| 337 | */ |
| 338 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 339 | dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 341 | struct dasd_device *device = bdev->bd_disk->private_data; |
| 342 | int intval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
| 344 | if (!capable(CAP_SYS_ADMIN)) |
| 345 | return -EACCES; |
| 346 | if (bdev != bdev->bd_contains) |
| 347 | // ro setting is not allowed for partitions |
| 348 | return -EINVAL; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 349 | if (get_user(intval, (int *)argp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | return -EFAULT; |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | set_disk_ro(bdev->bd_disk, intval); |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 353 | return dasd_set_feature(device->cdev, DASD_FEATURE_READONLY, intval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Christoph Hellwig | 8b2eb66 | 2006-03-24 03:15:21 -0800 | [diff] [blame] | 356 | static int |
| 357 | dasd_ioctl_readall_cmb(struct dasd_device *device, unsigned int cmd, |
| 358 | unsigned long arg) |
| 359 | { |
| 360 | struct cmbdata __user *argp = (void __user *) arg; |
| 361 | size_t size = _IOC_SIZE(cmd); |
| 362 | struct cmbdata data; |
| 363 | int ret; |
| 364 | |
| 365 | ret = cmf_readall(device->cdev, &data); |
| 366 | if (!ret && copy_to_user(argp, &data, min(size, sizeof(*argp)))) |
| 367 | return -EFAULT; |
| 368 | return ret; |
| 369 | } |
| 370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 372 | dasd_ioctl(struct inode *inode, struct file *file, |
| 373 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | { |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 375 | struct block_device *bdev = inode->i_bdev; |
| 376 | struct dasd_device *device = bdev->bd_disk->private_data; |
| 377 | void __user *argp = (void __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 379 | if (!device) |
| 380 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 382 | if ((_IOC_DIR(cmd) != _IOC_NONE) && !arg) { |
| 383 | PRINT_DEBUG("empty data ptr"); |
| 384 | return -EINVAL; |
| 385 | } |
| 386 | |
| 387 | switch (cmd) { |
| 388 | case BIODASDDISABLE: |
| 389 | return dasd_ioctl_disable(bdev); |
| 390 | case BIODASDENABLE: |
| 391 | return dasd_ioctl_enable(bdev); |
| 392 | case BIODASDQUIESCE: |
| 393 | return dasd_ioctl_quiesce(device); |
| 394 | case BIODASDRESUME: |
| 395 | return dasd_ioctl_resume(device); |
| 396 | case BIODASDFMT: |
| 397 | return dasd_ioctl_format(bdev, argp); |
| 398 | case BIODASDINFO: |
| 399 | return dasd_ioctl_information(device, cmd, argp); |
| 400 | case BIODASDINFO2: |
| 401 | return dasd_ioctl_information(device, cmd, argp); |
| 402 | case BIODASDPRRD: |
| 403 | return dasd_ioctl_read_profile(device, argp); |
| 404 | case BIODASDPRRST: |
| 405 | return dasd_ioctl_reset_profile(device); |
| 406 | case BLKROSET: |
| 407 | return dasd_ioctl_set_ro(bdev, argp); |
| 408 | case DASDAPIVER: |
| 409 | return dasd_ioctl_api_version(argp); |
Christoph Hellwig | 8b2eb66 | 2006-03-24 03:15:21 -0800 | [diff] [blame] | 410 | case BIODASDCMFENABLE: |
| 411 | return enable_cmf(device->cdev); |
| 412 | case BIODASDCMFDISABLE: |
| 413 | return disable_cmf(device->cdev); |
| 414 | case BIODASDREADALLCMB: |
| 415 | return dasd_ioctl_readall_cmb(device, cmd, arg); |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 416 | default: |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 417 | /* if the discipline has an ioctl method try it. */ |
| 418 | if (device->discipline->ioctl) { |
| 419 | int rval = device->discipline->ioctl(device, cmd, argp); |
| 420 | if (rval != -ENOIOCTLCMD) |
| 421 | return rval; |
| 422 | } |
| 423 | |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 424 | return -EINVAL; |
| 425 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 428 | long |
| 429 | dasd_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | { |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 431 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 433 | lock_kernel(); |
| 434 | rval = dasd_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); |
| 435 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 437 | return (rval == -EINVAL) ? -ENOIOCTLCMD : rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |