2 * File...........: linux/drivers/s390/block/dasd_genhd.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 * gendisk related functions for the dasd driver.
14 #include <linux/config.h>
15 #include <linux/interrupt.h>
17 #include <linux/blkpg.h>
19 #include <asm/uaccess.h>
22 #define PRINTK_HEADER "dasd_gendisk:"
27 * Allocate and register gendisk structure for device.
30 dasd_gendisk_alloc(struct dasd_device
*device
)
35 /* Make sure the minor for this device exists. */
36 if (device
->devindex
>= DASD_PER_MAJOR
)
39 gdp
= alloc_disk(1 << DASD_PARTN_BITS
);
43 /* Initialize gendisk structure. */
44 gdp
->major
= DASD_MAJOR
;
45 gdp
->first_minor
= device
->devindex
<< DASD_PARTN_BITS
;
46 gdp
->fops
= &dasd_device_operations
;
47 gdp
->driverfs_dev
= &device
->cdev
->dev
;
51 * dasda - dasdz : 26 devices
52 * dasdaa - dasdzz : 676 devices, added up = 702
53 * dasdaaa - dasdzzz : 17576 devices, added up = 18278
54 * dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
56 len
= sprintf(gdp
->disk_name
, "dasd");
57 if (device
->devindex
> 25) {
58 if (device
->devindex
> 701) {
59 if (device
->devindex
> 18277)
60 len
+= sprintf(gdp
->disk_name
+ len
, "%c",
61 'a'+(((device
->devindex
-18278)
63 len
+= sprintf(gdp
->disk_name
+ len
, "%c",
64 'a'+(((device
->devindex
-702)/676)%26));
66 len
+= sprintf(gdp
->disk_name
+ len
, "%c",
67 'a'+(((device
->devindex
-26)/26)%26));
69 len
+= sprintf(gdp
->disk_name
+ len
, "%c", 'a'+(device
->devindex
%26));
71 sprintf(gdp
->devfs_name
, "dasd/%s", device
->cdev
->dev
.bus_id
);
73 if (device
->features
& DASD_FEATURE_READONLY
)
75 gdp
->private_data
= device
;
76 gdp
->queue
= device
->request_queue
;
78 set_capacity(device
->gdp
, 0);
79 add_disk(device
->gdp
);
84 * Unregister and free gendisk structure for device.
87 dasd_gendisk_free(struct dasd_device
*device
)
89 del_gendisk(device
->gdp
);
90 device
->gdp
->queue
= 0;
91 put_disk(device
->gdp
);
96 * Trigger a partition detection.
99 dasd_scan_partitions(struct dasd_device
* device
)
101 struct block_device
*bdev
;
103 bdev
= bdget_disk(device
->gdp
, 0);
104 if (!bdev
|| blkdev_get(bdev
, FMODE_READ
, 1) < 0)
107 * See fs/partition/check.c:register_disk,rescan_partitions
108 * Can't call rescan_partitions directly. Use ioctl.
110 ioctl_by_bdev(bdev
, BLKRRPART
, 0);
112 * Since the matching blkdev_put call to the blkdev_get in
113 * this function is not called before dasd_destroy_partitions
114 * the offline open_count limit needs to be increased from
115 * 0 to 1. This is done by setting device->bdev (see
116 * dasd_generic_set_offline). As long as the partition
117 * detection is running no offline should be allowed. That
118 * is why the assignment to device->bdev is done AFTER
119 * the BLKRRPART ioctl.
126 * Remove all inodes in the system for a device, delete the
127 * partitions and make device unusable by setting its size to zero.
130 dasd_destroy_partitions(struct dasd_device
* device
)
132 /* The two structs have 168/176 byte on 31/64 bit. */
133 struct blkpg_partition bpart
;
134 struct blkpg_ioctl_arg barg
;
135 struct block_device
*bdev
;
138 * Get the bdev pointer from the device structure and clear
139 * device->bdev to lower the offline open_count limit again.
145 * See fs/partition/check.c:delete_partition
146 * Can't call delete_partitions directly. Use ioctl.
147 * The ioctl also does locking and invalidation.
149 memset(&bpart
, 0, sizeof(struct blkpg_partition
));
150 memset(&barg
, 0, sizeof(struct blkpg_ioctl_arg
));
152 barg
.op
= BLKPG_DEL_PARTITION
;
153 for (bpart
.pno
= device
->gdp
->minors
- 1; bpart
.pno
> 0; bpart
.pno
--)
154 ioctl_by_bdev(bdev
, BLKPG
, (unsigned long) &barg
);
156 invalidate_partition(device
->gdp
, 0);
157 /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
159 set_capacity(device
->gdp
, 0);
163 dasd_gendisk_init(void)
167 /* Register to static dasd major 94 */
168 rc
= register_blkdev(DASD_MAJOR
, "dasd");
170 MESSAGE(KERN_WARNING
,
171 "Couldn't register successfully to "
172 "major no %d", DASD_MAJOR
);
179 dasd_gendisk_exit(void)
181 unregister_blkdev(DASD_MAJOR
, "dasd");