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
10 * i/o controls for the dasd driver.
12 #include <linux/interrupt.h>
13 #include <linux/major.h>
15 #include <linux/blkpg.h>
17 #include <asm/ccwdev.h>
19 #include <asm/uaccess.h>
22 #define PRINTK_HEADER "dasd_ioctl:"
28 dasd_ioctl_api_version(void __user *argp)
30 int ver = DASD_API_VERSION;
31 return put_user(ver, (int __user *)argp);
36 * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection
39 dasd_ioctl_enable(struct block_device *bdev)
41 struct dasd_device *device = bdev->bd_disk->private_data;
43 if (!capable(CAP_SYS_ADMIN))
46 dasd_enable_device(device);
47 /* Formatting the dasd device can change the capacity. */
48 mutex_lock(&bdev->bd_mutex);
49 i_size_write(bdev->bd_inode, (loff_t)get_capacity(device->gdp) << 9);
50 mutex_unlock(&bdev->bd_mutex);
56 * Used by dasdfmt. Disable I/O operations but allow ioctls.
59 dasd_ioctl_disable(struct block_device *bdev)
61 struct dasd_device *device = bdev->bd_disk->private_data;
63 if (!capable(CAP_SYS_ADMIN))
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.
74 dasd_set_target_state(device, DASD_STATE_BASIC);
76 * Set i_size to zero, since read, write, etc. check against this
79 mutex_lock(&bdev->bd_mutex);
80 i_size_write(bdev->bd_inode, 0);
81 mutex_unlock(&bdev->bd_mutex);
89 dasd_ioctl_quiesce(struct dasd_device *device)
93 if (!capable (CAP_SYS_ADMIN))
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);
109 dasd_ioctl_resume(struct dasd_device *device)
113 if (!capable (CAP_SYS_ADMIN))
116 DEV_MESSAGE (KERN_DEBUG, device, "%s",
117 "resume IO on device");
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);
123 dasd_schedule_bh (device);
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.
134 dasd_format(struct dasd_device * device, struct format_data_t * fdata)
136 struct dasd_ccw_req *cqr;
139 if (device->discipline->format_device == NULL)
142 if (device->state != DASD_STATE_BASIC) {
143 DEV_MESSAGE(KERN_WARNING, device, "%s",
144 "dasd_format: device is not disabled! ");
148 DBF_DEV_EVENT(DBF_NOTICE, device,
149 "formatting units %d to %d (%d B blocks) flags %d",
151 fdata->stop_unit, fdata->blksize, fdata->intensity);
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.
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);
164 while (fdata->start_unit <= fdata->stop_unit) {
165 cqr = device->discipline->format_device(device, fdata);
168 rc = dasd_sleep_on_interruptible(cqr);
169 dasd_sfree_request(cqr, cqr->device);
171 if (rc != -ERESTARTSYS)
172 DEV_MESSAGE(KERN_ERR, device,
173 " Formatting of unit %d failed "
175 fdata->start_unit, rc);
187 dasd_ioctl_format(struct block_device *bdev, void __user *argp)
189 struct dasd_device *device = bdev->bd_disk->private_data;
190 struct format_data_t fdata;
192 if (!capable(CAP_SYS_ADMIN))
197 if (device->features & DASD_FEATURE_READONLY)
199 if (copy_from_user(&fdata, argp, sizeof(struct format_data_t)))
201 if (bdev != bdev->bd_contains) {
202 DEV_MESSAGE(KERN_WARNING, device, "%s",
203 "Cannot low-level format a partition");
206 return dasd_format(device, &fdata);
209 #ifdef CONFIG_DASD_PROFILE
211 * Reset device profile information
214 dasd_ioctl_reset_profile(struct dasd_device *device)
216 memset(&device->profile, 0, sizeof (struct dasd_profile_info_t));
221 * Return device profile information
224 dasd_ioctl_read_profile(struct dasd_device *device, void __user *argp)
226 if (dasd_profile_level == DASD_PROFILE_OFF)
228 if (copy_to_user(argp, &device->profile,
229 sizeof (struct dasd_profile_info_t)))
235 dasd_ioctl_reset_profile(struct dasd_device *device)
241 dasd_ioctl_read_profile(struct dasd_device *device, void __user *argp)
248 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
251 dasd_ioctl_information(struct dasd_device *device,
252 unsigned int cmd, void __user *argp)
254 struct dasd_information2_t *dasd_info;
257 struct ccw_device *cdev;
258 struct ccw_dev_id dev_id;
260 if (!device->discipline->fill_info)
263 dasd_info = kzalloc(sizeof(struct dasd_information2_t), GFP_KERNEL);
264 if (dasd_info == NULL)
267 rc = device->discipline->fill_info(device, dasd_info);
274 ccw_device_get_id(cdev, &dev_id);
276 dasd_info->devno = dev_id.devno;
277 dasd_info->schid = _ccw_device_get_subchannel_number(device->cdev);
278 dasd_info->cu_type = cdev->id.cu_type;
279 dasd_info->cu_model = cdev->id.cu_model;
280 dasd_info->dev_type = cdev->id.dev_type;
281 dasd_info->dev_model = cdev->id.dev_model;
282 dasd_info->status = device->state;
284 * The open_count is increased for every opener, that includes
285 * the blkdev_get in dasd_scan_partitions.
286 * This must be hidden from user-space.
288 dasd_info->open_count = atomic_read(&device->open_count);
290 dasd_info->open_count++;
293 * check if device is really formatted
294 * LDL / CDL was returned by 'fill_info'
296 if ((device->state < DASD_STATE_READY) ||
297 (dasd_check_blocksize(device->bp_block)))
298 dasd_info->format = DASD_FORMAT_NONE;
300 dasd_info->features |=
301 ((device->features & DASD_FEATURE_READONLY) != 0);
303 if (device->discipline)
304 memcpy(dasd_info->type, device->discipline->name, 4);
306 memcpy(dasd_info->type, "none", 4);
308 if (device->request_queue->request_fn) {
310 #ifdef DASD_EXTENDED_PROFILING
313 spin_lock_irqsave(&device->lock, flags);
314 list_for_each(l, &device->request_queue->queue_head)
315 dasd_info->req_queue_len++;
316 spin_unlock_irqrestore(&device->lock, flags);
318 #endif /* DASD_EXTENDED_PROFILING */
319 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
320 list_for_each(l, &device->ccw_queue)
321 dasd_info->chanq_len++;
322 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
327 if (copy_to_user(argp, dasd_info,
328 ((cmd == (unsigned int) BIODASDINFO2) ?
329 sizeof (struct dasd_information2_t) :
330 sizeof (struct dasd_information_t))))
340 dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp)
342 struct dasd_device *device = bdev->bd_disk->private_data;
345 if (!capable(CAP_SYS_ADMIN))
347 if (bdev != bdev->bd_contains)
348 // ro setting is not allowed for partitions
350 if (get_user(intval, (int __user *)argp))
353 set_disk_ro(bdev->bd_disk, intval);
354 return dasd_set_feature(device->cdev, DASD_FEATURE_READONLY, intval);
358 dasd_ioctl_readall_cmb(struct dasd_device *device, unsigned int cmd,
361 struct cmbdata __user *argp = (void __user *) arg;
362 size_t size = _IOC_SIZE(cmd);
366 ret = cmf_readall(device->cdev, &data);
367 if (!ret && copy_to_user(argp, &data, min(size, sizeof(*argp))))
373 dasd_ioctl(struct inode *inode, struct file *file,
374 unsigned int cmd, unsigned long arg)
376 struct block_device *bdev = inode->i_bdev;
377 struct dasd_device *device = bdev->bd_disk->private_data;
378 void __user *argp = (void __user *)arg;
383 if ((_IOC_DIR(cmd) != _IOC_NONE) && !arg) {
384 PRINT_DEBUG("empty data ptr");
390 return dasd_ioctl_disable(bdev);
392 return dasd_ioctl_enable(bdev);
394 return dasd_ioctl_quiesce(device);
396 return dasd_ioctl_resume(device);
398 return dasd_ioctl_format(bdev, argp);
400 return dasd_ioctl_information(device, cmd, argp);
402 return dasd_ioctl_information(device, cmd, argp);
404 return dasd_ioctl_read_profile(device, argp);
406 return dasd_ioctl_reset_profile(device);
408 return dasd_ioctl_set_ro(bdev, argp);
410 return dasd_ioctl_api_version(argp);
411 case BIODASDCMFENABLE:
412 return enable_cmf(device->cdev);
413 case BIODASDCMFDISABLE:
414 return disable_cmf(device->cdev);
415 case BIODASDREADALLCMB:
416 return dasd_ioctl_readall_cmb(device, cmd, arg);
418 /* if the discipline has an ioctl method try it. */
419 if (device->discipline->ioctl) {
420 int rval = device->discipline->ioctl(device, cmd, argp);
421 if (rval != -ENOIOCTLCMD)
430 dasd_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
435 rval = dasd_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
438 return (rval == -EINVAL) ? -ENOIOCTLCMD : rval;