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