Commit | Line | Data |
---|---|---|
94ea4158 AV |
1 | /* |
2 | * Code extracted from drivers/block/genhd.c | |
3 | * Copyright (C) 1991-1998 Linus Torvalds | |
4 | * Re-organised Feb 1998 Russell King | |
5 | * | |
6 | * We now have independent partition support from the | |
7 | * block drivers, which allows all the partition code to | |
8 | * be grouped in one location, and it to be mostly self | |
9 | * contained. | |
10 | */ | |
11 | ||
12 | #include <linux/init.h> | |
13 | #include <linux/module.h> | |
14 | #include <linux/fs.h> | |
15 | #include <linux/slab.h> | |
16 | #include <linux/kmod.h> | |
17 | #include <linux/ctype.h> | |
18 | #include <linux/genhd.h> | |
19 | #include <linux/blktrace_api.h> | |
20 | ||
3c2a0909 S |
21 | #ifdef CONFIG_BLOCK_SUPPORT_STLOG |
22 | #include <linux/stlog.h> | |
23 | #else | |
24 | #define ST_LOG(fmt,...) | |
25 | #endif | |
26 | ||
94ea4158 AV |
27 | #include "partitions/check.h" |
28 | ||
29 | #ifdef CONFIG_BLK_DEV_MD | |
30 | extern void md_autodetect_dev(dev_t dev); | |
31 | #endif | |
32 | ||
33 | /* | |
34 | * disk_name() is used by partition check code and the genhd driver. | |
35 | * It formats the devicename of the indicated disk into | |
36 | * the supplied buffer (of size at least 32), and returns | |
37 | * a pointer to that same buffer (for convenience). | |
38 | */ | |
39 | ||
40 | char *disk_name(struct gendisk *hd, int partno, char *buf) | |
41 | { | |
42 | if (!partno) | |
43 | snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name); | |
44 | else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1])) | |
45 | snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, partno); | |
46 | else | |
47 | snprintf(buf, BDEVNAME_SIZE, "%s%d", hd->disk_name, partno); | |
48 | ||
49 | return buf; | |
50 | } | |
51 | ||
52 | const char *bdevname(struct block_device *bdev, char *buf) | |
53 | { | |
54 | return disk_name(bdev->bd_disk, bdev->bd_part->partno, buf); | |
55 | } | |
56 | ||
57 | EXPORT_SYMBOL(bdevname); | |
58 | ||
59 | /* | |
60 | * There's very little reason to use this, you should really | |
61 | * have a struct block_device just about everywhere and use | |
62 | * bdevname() instead. | |
63 | */ | |
64 | const char *__bdevname(dev_t dev, char *buffer) | |
65 | { | |
66 | scnprintf(buffer, BDEVNAME_SIZE, "unknown-block(%u,%u)", | |
67 | MAJOR(dev), MINOR(dev)); | |
68 | return buffer; | |
69 | } | |
70 | ||
71 | EXPORT_SYMBOL(__bdevname); | |
72 | ||
73 | static ssize_t part_partition_show(struct device *dev, | |
74 | struct device_attribute *attr, char *buf) | |
75 | { | |
76 | struct hd_struct *p = dev_to_part(dev); | |
77 | ||
78 | return sprintf(buf, "%d\n", p->partno); | |
79 | } | |
80 | ||
81 | static ssize_t part_start_show(struct device *dev, | |
82 | struct device_attribute *attr, char *buf) | |
83 | { | |
84 | struct hd_struct *p = dev_to_part(dev); | |
85 | ||
86 | return sprintf(buf, "%llu\n",(unsigned long long)p->start_sect); | |
87 | } | |
88 | ||
89 | ssize_t part_size_show(struct device *dev, | |
90 | struct device_attribute *attr, char *buf) | |
91 | { | |
92 | struct hd_struct *p = dev_to_part(dev); | |
c83f6bf9 | 93 | return sprintf(buf, "%llu\n",(unsigned long long)part_nr_sects_read(p)); |
94ea4158 AV |
94 | } |
95 | ||
96 | static ssize_t part_ro_show(struct device *dev, | |
97 | struct device_attribute *attr, char *buf) | |
98 | { | |
99 | struct hd_struct *p = dev_to_part(dev); | |
100 | return sprintf(buf, "%d\n", p->policy ? 1 : 0); | |
101 | } | |
102 | ||
103 | static ssize_t part_alignment_offset_show(struct device *dev, | |
104 | struct device_attribute *attr, char *buf) | |
105 | { | |
106 | struct hd_struct *p = dev_to_part(dev); | |
107 | return sprintf(buf, "%llu\n", (unsigned long long)p->alignment_offset); | |
108 | } | |
109 | ||
110 | static ssize_t part_discard_alignment_show(struct device *dev, | |
111 | struct device_attribute *attr, char *buf) | |
112 | { | |
113 | struct hd_struct *p = dev_to_part(dev); | |
114 | return sprintf(buf, "%u\n", p->discard_alignment); | |
115 | } | |
116 | ||
117 | ssize_t part_stat_show(struct device *dev, | |
118 | struct device_attribute *attr, char *buf) | |
119 | { | |
120 | struct hd_struct *p = dev_to_part(dev); | |
121 | int cpu; | |
122 | ||
123 | cpu = part_stat_lock(); | |
124 | part_round_stats(cpu, p); | |
125 | part_stat_unlock(); | |
126 | return sprintf(buf, | |
127 | "%8lu %8lu %8llu %8u " | |
128 | "%8lu %8lu %8llu %8u " | |
129 | "%8u %8u %8u" | |
130 | "\n", | |
131 | part_stat_read(p, ios[READ]), | |
132 | part_stat_read(p, merges[READ]), | |
133 | (unsigned long long)part_stat_read(p, sectors[READ]), | |
134 | jiffies_to_msecs(part_stat_read(p, ticks[READ])), | |
135 | part_stat_read(p, ios[WRITE]), | |
136 | part_stat_read(p, merges[WRITE]), | |
137 | (unsigned long long)part_stat_read(p, sectors[WRITE]), | |
138 | jiffies_to_msecs(part_stat_read(p, ticks[WRITE])), | |
139 | part_in_flight(p), | |
140 | jiffies_to_msecs(part_stat_read(p, io_ticks)), | |
141 | jiffies_to_msecs(part_stat_read(p, time_in_queue))); | |
142 | } | |
143 | ||
144 | ssize_t part_inflight_show(struct device *dev, | |
145 | struct device_attribute *attr, char *buf) | |
146 | { | |
147 | struct hd_struct *p = dev_to_part(dev); | |
148 | ||
149 | return sprintf(buf, "%8u %8u\n", atomic_read(&p->in_flight[0]), | |
150 | atomic_read(&p->in_flight[1])); | |
151 | } | |
152 | ||
153 | #ifdef CONFIG_FAIL_MAKE_REQUEST | |
154 | ssize_t part_fail_show(struct device *dev, | |
155 | struct device_attribute *attr, char *buf) | |
156 | { | |
157 | struct hd_struct *p = dev_to_part(dev); | |
158 | ||
159 | return sprintf(buf, "%d\n", p->make_it_fail); | |
160 | } | |
161 | ||
162 | ssize_t part_fail_store(struct device *dev, | |
163 | struct device_attribute *attr, | |
164 | const char *buf, size_t count) | |
165 | { | |
166 | struct hd_struct *p = dev_to_part(dev); | |
167 | int i; | |
168 | ||
169 | if (count > 0 && sscanf(buf, "%d", &i) > 0) | |
170 | p->make_it_fail = (i == 0) ? 0 : 1; | |
171 | ||
172 | return count; | |
173 | } | |
174 | #endif | |
175 | ||
176 | static DEVICE_ATTR(partition, S_IRUGO, part_partition_show, NULL); | |
177 | static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL); | |
178 | static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL); | |
179 | static DEVICE_ATTR(ro, S_IRUGO, part_ro_show, NULL); | |
180 | static DEVICE_ATTR(alignment_offset, S_IRUGO, part_alignment_offset_show, NULL); | |
181 | static DEVICE_ATTR(discard_alignment, S_IRUGO, part_discard_alignment_show, | |
182 | NULL); | |
183 | static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL); | |
184 | static DEVICE_ATTR(inflight, S_IRUGO, part_inflight_show, NULL); | |
185 | #ifdef CONFIG_FAIL_MAKE_REQUEST | |
186 | static struct device_attribute dev_attr_fail = | |
187 | __ATTR(make-it-fail, S_IRUGO|S_IWUSR, part_fail_show, part_fail_store); | |
188 | #endif | |
189 | ||
190 | static struct attribute *part_attrs[] = { | |
191 | &dev_attr_partition.attr, | |
192 | &dev_attr_start.attr, | |
193 | &dev_attr_size.attr, | |
194 | &dev_attr_ro.attr, | |
195 | &dev_attr_alignment_offset.attr, | |
196 | &dev_attr_discard_alignment.attr, | |
197 | &dev_attr_stat.attr, | |
198 | &dev_attr_inflight.attr, | |
199 | #ifdef CONFIG_FAIL_MAKE_REQUEST | |
200 | &dev_attr_fail.attr, | |
201 | #endif | |
202 | NULL | |
203 | }; | |
204 | ||
205 | static struct attribute_group part_attr_group = { | |
206 | .attrs = part_attrs, | |
207 | }; | |
208 | ||
209 | static const struct attribute_group *part_attr_groups[] = { | |
210 | &part_attr_group, | |
211 | #ifdef CONFIG_BLK_DEV_IO_TRACE | |
212 | &blk_trace_attr_group, | |
213 | #endif | |
214 | NULL | |
215 | }; | |
216 | ||
217 | static void part_release(struct device *dev) | |
218 | { | |
219 | struct hd_struct *p = dev_to_part(dev); | |
3710e26e | 220 | blk_free_devt(dev->devt); |
94ea4158 AV |
221 | free_part_stats(p); |
222 | free_part_info(p); | |
223 | kfree(p); | |
224 | } | |
225 | ||
3c2a0909 S |
226 | static int part_uevent(struct device *dev, struct kobj_uevent_env *env) |
227 | { | |
228 | struct hd_struct *part = dev_to_part(dev); | |
229 | ||
230 | add_uevent_var(env, "PARTN=%u", part->partno); | |
231 | if (part->info && part->info->volname[0]) | |
232 | add_uevent_var(env, "PARTNAME=%s", part->info->volname); | |
233 | return 0; | |
234 | } | |
235 | ||
94ea4158 AV |
236 | struct device_type part_type = { |
237 | .name = "partition", | |
238 | .groups = part_attr_groups, | |
239 | .release = part_release, | |
3c2a0909 | 240 | .uevent = part_uevent, |
94ea4158 AV |
241 | }; |
242 | ||
243 | static void delete_partition_rcu_cb(struct rcu_head *head) | |
244 | { | |
245 | struct hd_struct *part = container_of(head, struct hd_struct, rcu_head); | |
246 | ||
247 | part->start_sect = 0; | |
248 | part->nr_sects = 0; | |
249 | part_stat_set_all(part, 0); | |
250 | put_device(part_to_dev(part)); | |
251 | } | |
252 | ||
253 | void __delete_partition(struct hd_struct *part) | |
254 | { | |
255 | call_rcu(&part->rcu_head, delete_partition_rcu_cb); | |
256 | } | |
257 | ||
258 | void delete_partition(struct gendisk *disk, int partno) | |
259 | { | |
260 | struct disk_part_tbl *ptbl = disk->part_tbl; | |
261 | struct hd_struct *part; | |
262 | ||
3c2a0909 S |
263 | #ifdef CONFIG_BLOCK_SUPPORT_STLOG |
264 | struct device *dev; | |
265 | #endif | |
266 | ||
94ea4158 AV |
267 | if (partno >= ptbl->len) |
268 | return; | |
269 | ||
270 | part = ptbl->part[partno]; | |
271 | if (!part) | |
272 | return; | |
273 | ||
94ea4158 AV |
274 | rcu_assign_pointer(ptbl->part[partno], NULL); |
275 | rcu_assign_pointer(ptbl->last_lookup, NULL); | |
276 | kobject_put(part->holder_dir); | |
3c2a0909 S |
277 | #ifdef CONFIG_BLOCK_SUPPORT_STLOG |
278 | dev = part_to_dev(part); | |
279 | ST_LOG("<%s> KOBJ_REMOVE %d:%d %s", | |
280 | __func__, MAJOR(dev->devt), MINOR(dev->devt), dev->kobj.name); | |
281 | #endif | |
94ea4158 AV |
282 | device_del(part_to_dev(part)); |
283 | ||
284 | hd_struct_put(part); | |
285 | } | |
286 | ||
287 | static ssize_t whole_disk_show(struct device *dev, | |
288 | struct device_attribute *attr, char *buf) | |
289 | { | |
290 | return 0; | |
291 | } | |
292 | static DEVICE_ATTR(whole_disk, S_IRUSR | S_IRGRP | S_IROTH, | |
293 | whole_disk_show, NULL); | |
294 | ||
295 | struct hd_struct *add_partition(struct gendisk *disk, int partno, | |
296 | sector_t start, sector_t len, int flags, | |
297 | struct partition_meta_info *info) | |
298 | { | |
299 | struct hd_struct *p; | |
300 | dev_t devt = MKDEV(0, 0); | |
301 | struct device *ddev = disk_to_dev(disk); | |
302 | struct device *pdev; | |
303 | struct disk_part_tbl *ptbl; | |
304 | const char *dname; | |
305 | int err; | |
306 | ||
307 | err = disk_expand_part_tbl(disk, partno); | |
308 | if (err) | |
309 | return ERR_PTR(err); | |
310 | ptbl = disk->part_tbl; | |
311 | ||
312 | if (ptbl->part[partno]) | |
313 | return ERR_PTR(-EBUSY); | |
314 | ||
315 | p = kzalloc(sizeof(*p), GFP_KERNEL); | |
316 | if (!p) | |
317 | return ERR_PTR(-EBUSY); | |
318 | ||
319 | if (!init_part_stats(p)) { | |
320 | err = -ENOMEM; | |
321 | goto out_free; | |
322 | } | |
c83f6bf9 VG |
323 | |
324 | seqcount_init(&p->nr_sects_seq); | |
94ea4158 AV |
325 | pdev = part_to_dev(p); |
326 | ||
327 | p->start_sect = start; | |
328 | p->alignment_offset = | |
329 | queue_limit_alignment_offset(&disk->queue->limits, start); | |
330 | p->discard_alignment = | |
331 | queue_limit_discard_alignment(&disk->queue->limits, start); | |
332 | p->nr_sects = len; | |
333 | p->partno = partno; | |
334 | p->policy = get_disk_ro(disk); | |
335 | ||
336 | if (info) { | |
337 | struct partition_meta_info *pinfo = alloc_part_info(disk); | |
338 | if (!pinfo) | |
339 | goto out_free_stats; | |
340 | memcpy(pinfo, info, sizeof(*info)); | |
341 | p->info = pinfo; | |
342 | } | |
343 | ||
344 | dname = dev_name(ddev); | |
345 | if (isdigit(dname[strlen(dname) - 1])) | |
346 | dev_set_name(pdev, "%sp%d", dname, partno); | |
347 | else | |
348 | dev_set_name(pdev, "%s%d", dname, partno); | |
349 | ||
350 | device_initialize(pdev); | |
351 | pdev->class = &block_class; | |
352 | pdev->type = &part_type; | |
353 | pdev->parent = ddev; | |
354 | ||
355 | err = blk_alloc_devt(p, &devt); | |
356 | if (err) | |
357 | goto out_free_info; | |
358 | pdev->devt = devt; | |
359 | ||
360 | /* delay uevent until 'holders' subdir is created */ | |
361 | dev_set_uevent_suppress(pdev, 1); | |
362 | err = device_add(pdev); | |
363 | if (err) | |
364 | goto out_put; | |
365 | ||
366 | err = -ENOMEM; | |
367 | p->holder_dir = kobject_create_and_add("holders", &pdev->kobj); | |
368 | if (!p->holder_dir) | |
369 | goto out_del; | |
370 | ||
371 | dev_set_uevent_suppress(pdev, 0); | |
372 | if (flags & ADDPART_FLAG_WHOLEDISK) { | |
373 | err = device_create_file(pdev, &dev_attr_whole_disk); | |
374 | if (err) | |
375 | goto out_del; | |
376 | } | |
377 | ||
378 | /* everything is up and running, commence */ | |
379 | rcu_assign_pointer(ptbl->part[partno], p); | |
380 | ||
381 | /* suppress uevent if the disk suppresses it */ | |
382 | if (!dev_get_uevent_suppress(ddev)) | |
383 | kobject_uevent(&pdev->kobj, KOBJ_ADD); | |
384 | ||
385 | hd_ref_init(p); | |
386 | return p; | |
387 | ||
388 | out_free_info: | |
389 | free_part_info(p); | |
390 | out_free_stats: | |
391 | free_part_stats(p); | |
392 | out_free: | |
393 | kfree(p); | |
394 | return ERR_PTR(err); | |
395 | out_del: | |
396 | kobject_put(p->holder_dir); | |
397 | device_del(pdev); | |
398 | out_put: | |
399 | put_device(pdev); | |
400 | blk_free_devt(devt); | |
401 | return ERR_PTR(err); | |
402 | } | |
403 | ||
404 | static bool disk_unlock_native_capacity(struct gendisk *disk) | |
405 | { | |
406 | const struct block_device_operations *bdops = disk->fops; | |
407 | ||
408 | if (bdops->unlock_native_capacity && | |
409 | !(disk->flags & GENHD_FL_NATIVE_CAPACITY)) { | |
410 | printk(KERN_CONT "enabling native capacity\n"); | |
411 | bdops->unlock_native_capacity(disk); | |
412 | disk->flags |= GENHD_FL_NATIVE_CAPACITY; | |
413 | return true; | |
414 | } else { | |
415 | printk(KERN_CONT "truncated\n"); | |
416 | return false; | |
417 | } | |
418 | } | |
419 | ||
fe316bf2 | 420 | static int drop_partitions(struct gendisk *disk, struct block_device *bdev) |
94ea4158 | 421 | { |
94ea4158 AV |
422 | struct disk_part_iter piter; |
423 | struct hd_struct *part; | |
fe316bf2 | 424 | int res; |
94ea4158 AV |
425 | |
426 | if (bdev->bd_part_count) | |
427 | return -EBUSY; | |
428 | res = invalidate_partition(disk, 0); | |
429 | if (res) | |
430 | return res; | |
431 | ||
432 | disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY); | |
433 | while ((part = disk_part_iter_next(&piter))) | |
434 | delete_partition(disk, part->partno); | |
435 | disk_part_iter_exit(&piter); | |
436 | ||
fe316bf2 JN |
437 | return 0; |
438 | } | |
439 | ||
440 | int rescan_partitions(struct gendisk *disk, struct block_device *bdev) | |
441 | { | |
442 | struct parsed_partitions *state = NULL; | |
443 | struct hd_struct *part; | |
444 | int p, highest, res; | |
445 | rescan: | |
446 | if (state && !IS_ERR(state)) { | |
ac2e5327 | 447 | free_partitions(state); |
fe316bf2 JN |
448 | state = NULL; |
449 | } | |
450 | ||
451 | res = drop_partitions(disk, bdev); | |
452 | if (res) | |
453 | return res; | |
454 | ||
94ea4158 AV |
455 | if (disk->fops->revalidate_disk) |
456 | disk->fops->revalidate_disk(disk); | |
457 | check_disk_size_change(disk, bdev); | |
458 | bdev->bd_invalidated = 0; | |
459 | if (!get_capacity(disk) || !(state = check_partition(disk, bdev))) | |
460 | return 0; | |
461 | if (IS_ERR(state)) { | |
462 | /* | |
463 | * I/O error reading the partition table. If any | |
464 | * partition code tried to read beyond EOD, retry | |
465 | * after unlocking native capacity. | |
466 | */ | |
467 | if (PTR_ERR(state) == -ENOSPC) { | |
468 | printk(KERN_WARNING "%s: partition table beyond EOD, ", | |
469 | disk->disk_name); | |
470 | if (disk_unlock_native_capacity(disk)) | |
471 | goto rescan; | |
472 | } | |
473 | return -EIO; | |
474 | } | |
475 | /* | |
476 | * If any partition code tried to read beyond EOD, try | |
477 | * unlocking native capacity even if partition table is | |
478 | * successfully read as we could be missing some partitions. | |
479 | */ | |
480 | if (state->access_beyond_eod) { | |
481 | printk(KERN_WARNING | |
482 | "%s: partition table partially beyond EOD, ", | |
483 | disk->disk_name); | |
484 | if (disk_unlock_native_capacity(disk)) | |
485 | goto rescan; | |
486 | } | |
487 | ||
488 | /* tell userspace that the media / partition table may have changed */ | |
489 | kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE); | |
490 | ||
491 | /* Detect the highest partition number and preallocate | |
492 | * disk->part_tbl. This is an optimization and not strictly | |
493 | * necessary. | |
494 | */ | |
495 | for (p = 1, highest = 0; p < state->limit; p++) | |
496 | if (state->parts[p].size) | |
497 | highest = p; | |
498 | ||
499 | disk_expand_part_tbl(disk, highest); | |
500 | ||
501 | /* add partitions */ | |
502 | for (p = 1; p < state->limit; p++) { | |
503 | sector_t size, from; | |
504 | struct partition_meta_info *info = NULL; | |
505 | ||
506 | size = state->parts[p].size; | |
507 | if (!size) | |
508 | continue; | |
509 | ||
510 | from = state->parts[p].from; | |
511 | if (from >= get_capacity(disk)) { | |
512 | printk(KERN_WARNING | |
513 | "%s: p%d start %llu is beyond EOD, ", | |
514 | disk->disk_name, p, (unsigned long long) from); | |
515 | if (disk_unlock_native_capacity(disk)) | |
516 | goto rescan; | |
517 | continue; | |
518 | } | |
519 | ||
520 | if (from + size > get_capacity(disk)) { | |
521 | printk(KERN_WARNING | |
522 | "%s: p%d size %llu extends beyond EOD, ", | |
523 | disk->disk_name, p, (unsigned long long) size); | |
524 | ||
525 | if (disk_unlock_native_capacity(disk)) { | |
526 | /* free state and restart */ | |
527 | goto rescan; | |
528 | } else { | |
529 | /* | |
530 | * we can not ignore partitions of broken tables | |
531 | * created by for example camera firmware, but | |
532 | * we limit them to the end of the disk to avoid | |
533 | * creating invalid block devices | |
534 | */ | |
535 | size = get_capacity(disk) - from; | |
536 | } | |
537 | } | |
538 | ||
539 | if (state->parts[p].has_info) | |
540 | info = &state->parts[p].info; | |
541 | part = add_partition(disk, p, from, size, | |
542 | state->parts[p].flags, | |
543 | &state->parts[p].info); | |
544 | if (IS_ERR(part)) { | |
545 | printk(KERN_ERR " %s: p%d could not be added: %ld\n", | |
546 | disk->disk_name, p, -PTR_ERR(part)); | |
547 | continue; | |
548 | } | |
549 | #ifdef CONFIG_BLK_DEV_MD | |
550 | if (state->parts[p].flags & ADDPART_FLAG_RAID) | |
551 | md_autodetect_dev(part_to_dev(part)->devt); | |
552 | #endif | |
553 | } | |
ac2e5327 | 554 | free_partitions(state); |
94ea4158 AV |
555 | return 0; |
556 | } | |
557 | ||
fe316bf2 JN |
558 | int invalidate_partitions(struct gendisk *disk, struct block_device *bdev) |
559 | { | |
560 | int res; | |
561 | ||
562 | if (!bdev->bd_invalidated) | |
563 | return 0; | |
564 | ||
565 | res = drop_partitions(disk, bdev); | |
566 | if (res) | |
567 | return res; | |
568 | ||
569 | set_capacity(disk, 0); | |
570 | check_disk_size_change(disk, bdev); | |
571 | bdev->bd_invalidated = 0; | |
572 | /* tell userspace that the media / partition table may have changed */ | |
573 | kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE); | |
574 | ||
575 | return 0; | |
576 | } | |
577 | ||
94ea4158 AV |
578 | unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p) |
579 | { | |
580 | struct address_space *mapping = bdev->bd_inode->i_mapping; | |
581 | struct page *page; | |
582 | ||
583 | page = read_mapping_page(mapping, (pgoff_t)(n >> (PAGE_CACHE_SHIFT-9)), | |
584 | NULL); | |
585 | if (!IS_ERR(page)) { | |
586 | if (PageError(page)) | |
587 | goto fail; | |
588 | p->v = page; | |
589 | return (unsigned char *)page_address(page) + ((n & ((1 << (PAGE_CACHE_SHIFT - 9)) - 1)) << 9); | |
590 | fail: | |
591 | page_cache_release(page); | |
592 | } | |
593 | p->v = NULL; | |
594 | return NULL; | |
595 | } | |
596 | ||
597 | EXPORT_SYMBOL(read_dev_sector); |