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