1
2
3
4
5
6
7
8
9
10
11
12
13#define KMSG_COMPONENT "dasd"
14
15#include <linux/interrupt.h>
16#include <linux/fs.h>
17#include <linux/blkpg.h>
18
19#include <asm/uaccess.h>
20
21
22#define PRINTK_HEADER "dasd_gendisk:"
23
24#include "dasd_int.h"
25
26
27
28
29int dasd_gendisk_alloc(struct dasd_block *block)
30{
31 struct gendisk *gdp;
32 struct dasd_device *base;
33 int len;
34
35
36 base = block->base;
37 if (base->devindex >= DASD_PER_MAJOR)
38 return -EBUSY;
39
40 gdp = alloc_disk(1 << DASD_PARTN_BITS);
41 if (!gdp)
42 return -ENOMEM;
43
44
45 gdp->major = DASD_MAJOR;
46 gdp->first_minor = base->devindex << DASD_PARTN_BITS;
47 gdp->fops = &dasd_device_operations;
48 gdp->driverfs_dev = &base->cdev->dev;
49
50
51
52
53
54
55
56
57 len = sprintf(gdp->disk_name, "dasd");
58 if (base->devindex > 25) {
59 if (base->devindex > 701) {
60 if (base->devindex > 18277)
61 len += sprintf(gdp->disk_name + len, "%c",
62 'a'+(((base->devindex-18278)
63 /17576)%26));
64 len += sprintf(gdp->disk_name + len, "%c",
65 'a'+(((base->devindex-702)/676)%26));
66 }
67 len += sprintf(gdp->disk_name + len, "%c",
68 'a'+(((base->devindex-26)/26)%26));
69 }
70 len += sprintf(gdp->disk_name + len, "%c", 'a'+(base->devindex%26));
71
72 if (base->features & DASD_FEATURE_READONLY ||
73 test_bit(DASD_FLAG_DEVICE_RO, &base->flags))
74 set_disk_ro(gdp, 1);
75 dasd_add_link_to_gendisk(gdp, base);
76 gdp->queue = block->request_queue;
77 block->gdp = gdp;
78 set_capacity(block->gdp, 0);
79 add_disk(block->gdp);
80 return 0;
81}
82
83
84
85
86void dasd_gendisk_free(struct dasd_block *block)
87{
88 if (block->gdp) {
89 del_gendisk(block->gdp);
90 block->gdp->queue = NULL;
91 block->gdp->private_data = NULL;
92 put_disk(block->gdp);
93 block->gdp = NULL;
94 }
95}
96
97
98
99
100int dasd_scan_partitions(struct dasd_block *block)
101{
102 struct block_device *bdev;
103 int rc;
104
105 bdev = bdget_disk(block->gdp, 0);
106 if (!bdev) {
107 DBF_DEV_EVENT(DBF_ERR, block->base, "%s",
108 "scan partitions error, bdget returned NULL");
109 return -ENODEV;
110 }
111
112 rc = blkdev_get(bdev, FMODE_READ, NULL);
113 if (rc < 0) {
114 DBF_DEV_EVENT(DBF_ERR, block->base,
115 "scan partitions error, blkdev_get returned %d",
116 rc);
117 return -ENODEV;
118 }
119
120 rc = blkdev_reread_part(bdev);
121 if (rc)
122 DBF_DEV_EVENT(DBF_ERR, block->base,
123 "scan partitions error, rc %d", rc);
124
125
126
127
128
129
130
131
132
133
134
135 block->bdev = bdev;
136 return 0;
137}
138
139
140
141
142
143void dasd_destroy_partitions(struct dasd_block *block)
144{
145
146 struct blkpg_partition bpart;
147 struct blkpg_ioctl_arg barg;
148 struct block_device *bdev;
149
150
151
152
153
154 bdev = block->bdev;
155 block->bdev = NULL;
156
157
158
159
160
161
162 memset(&bpart, 0, sizeof(struct blkpg_partition));
163 memset(&barg, 0, sizeof(struct blkpg_ioctl_arg));
164 barg.data = (void __force __user *) &bpart;
165 barg.op = BLKPG_DEL_PARTITION;
166 for (bpart.pno = block->gdp->minors - 1; bpart.pno > 0; bpart.pno--)
167 ioctl_by_bdev(bdev, BLKPG, (unsigned long) &barg);
168
169 invalidate_partition(block->gdp, 0);
170
171 blkdev_put(bdev, FMODE_READ);
172 set_capacity(block->gdp, 0);
173}
174
175int dasd_gendisk_init(void)
176{
177 int rc;
178
179
180 rc = register_blkdev(DASD_MAJOR, "dasd");
181 if (rc != 0) {
182 pr_warning("Registering the device driver with major number "
183 "%d failed\n", DASD_MAJOR);
184 return rc;
185 }
186 return 0;
187}
188
189void dasd_gendisk_exit(void)
190{
191 unregister_blkdev(DASD_MAJOR, "dasd");
192}
193