blob: 739da701ae7b8fec52d10f48392a85509208e286 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/partitions/check.c
3 *
4 * Code extracted from drivers/block/genhd.c
5 * Copyright (C) 1991-1998 Linus Torvalds
6 * Re-organised Feb 1998 Russell King
7 *
8 * We now have independent partition support from the
9 * block drivers, which allows all the partition code to
10 * be grouped in one location, and it to be mostly self
11 * contained.
12 *
13 * Added needed MAJORS for new pairs, {hdi,hdj}, {hdk,hdl}
14 */
15
16#include <linux/init.h>
17#include <linux/module.h>
18#include <linux/fs.h>
19#include <linux/kmod.h>
20#include <linux/ctype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include "check.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#include "acorn.h"
25#include "amiga.h"
26#include "atari.h"
27#include "ldm.h"
28#include "mac.h"
29#include "msdos.h"
30#include "osf.h"
31#include "sgi.h"
32#include "sun.h"
33#include "ibm.h"
34#include "ultrix.h"
35#include "efi.h"
Bob Copeland0e6e1db2006-01-16 22:14:20 -080036#include "karma.h"
Philippe De Muyter19d0e8c2007-05-08 00:29:15 -070037#include "sysv68.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#ifdef CONFIG_BLK_DEV_MD
40extern void md_autodetect_dev(dev_t dev);
41#endif
42
43int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/
44
45static int (*check_part[])(struct parsed_partitions *, struct block_device *) = {
46 /*
47 * Probe partition formats with tables at disk address 0
48 * that also have an ADFS boot block at 0xdc0.
49 */
50#ifdef CONFIG_ACORN_PARTITION_ICS
51 adfspart_check_ICS,
52#endif
53#ifdef CONFIG_ACORN_PARTITION_POWERTEC
54 adfspart_check_POWERTEC,
55#endif
56#ifdef CONFIG_ACORN_PARTITION_EESOX
57 adfspart_check_EESOX,
58#endif
59
60 /*
61 * Now move on to formats that only have partition info at
62 * disk address 0xdc0. Since these may also have stale
63 * PC/BIOS partition tables, they need to come before
64 * the msdos entry.
65 */
66#ifdef CONFIG_ACORN_PARTITION_CUMANA
67 adfspart_check_CUMANA,
68#endif
69#ifdef CONFIG_ACORN_PARTITION_ADFS
70 adfspart_check_ADFS,
71#endif
72
73#ifdef CONFIG_EFI_PARTITION
74 efi_partition, /* this must come before msdos */
75#endif
76#ifdef CONFIG_SGI_PARTITION
77 sgi_partition,
78#endif
79#ifdef CONFIG_LDM_PARTITION
80 ldm_partition, /* this must come before msdos */
81#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#ifdef CONFIG_MSDOS_PARTITION
83 msdos_partition,
84#endif
85#ifdef CONFIG_OSF_PARTITION
86 osf_partition,
87#endif
88#ifdef CONFIG_SUN_PARTITION
89 sun_partition,
90#endif
91#ifdef CONFIG_AMIGA_PARTITION
92 amiga_partition,
93#endif
94#ifdef CONFIG_ATARI_PARTITION
95 atari_partition,
96#endif
97#ifdef CONFIG_MAC_PARTITION
98 mac_partition,
99#endif
100#ifdef CONFIG_ULTRIX_PARTITION
101 ultrix_partition,
102#endif
103#ifdef CONFIG_IBM_PARTITION
104 ibm_partition,
105#endif
Bob Copeland0e6e1db2006-01-16 22:14:20 -0800106#ifdef CONFIG_KARMA_PARTITION
107 karma_partition,
108#endif
Philippe De Muyter19d0e8c2007-05-08 00:29:15 -0700109#ifdef CONFIG_SYSV68_PARTITION
110 sysv68_partition,
111#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 NULL
113};
114
115/*
116 * disk_name() is used by partition check code and the genhd driver.
117 * It formats the devicename of the indicated disk into
118 * the supplied buffer (of size at least 32), and returns
119 * a pointer to that same buffer (for convenience).
120 */
121
122char *disk_name(struct gendisk *hd, int part, char *buf)
123{
124 if (!part)
125 snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name);
126 else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1]))
127 snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, part);
128 else
129 snprintf(buf, BDEVNAME_SIZE, "%s%d", hd->disk_name, part);
130
131 return buf;
132}
133
134const char *bdevname(struct block_device *bdev, char *buf)
135{
136 int part = MINOR(bdev->bd_dev) - bdev->bd_disk->first_minor;
137 return disk_name(bdev->bd_disk, part, buf);
138}
139
140EXPORT_SYMBOL(bdevname);
141
142/*
143 * There's very little reason to use this, you should really
144 * have a struct block_device just about everywhere and use
145 * bdevname() instead.
146 */
147const char *__bdevname(dev_t dev, char *buffer)
148{
149 scnprintf(buffer, BDEVNAME_SIZE, "unknown-block(%u,%u)",
150 MAJOR(dev), MINOR(dev));
151 return buffer;
152}
153
154EXPORT_SYMBOL(__bdevname);
155
156static struct parsed_partitions *
157check_partition(struct gendisk *hd, struct block_device *bdev)
158{
159 struct parsed_partitions *state;
Suzuki K P57881dd2006-12-06 20:35:16 -0800160 int i, res, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 state = kmalloc(sizeof(struct parsed_partitions), GFP_KERNEL);
163 if (!state)
164 return NULL;
165
Greg Kroah-Hartmana2964182005-06-20 21:15:16 -0700166 disk_name(hd, 0, state->name);
167 printk(KERN_INFO " %s:", state->name);
168 if (isdigit(state->name[strlen(state->name)-1]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 sprintf(state->name, "p");
Greg Kroah-Hartmana2964182005-06-20 21:15:16 -0700170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 state->limit = hd->minors;
Suzuki K P57881dd2006-12-06 20:35:16 -0800172 i = res = err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 while (!res && check_part[i]) {
174 memset(&state->parts, 0, sizeof(state->parts));
175 res = check_part[i++](state, bdev);
Suzuki K P57881dd2006-12-06 20:35:16 -0800176 if (res < 0) {
177 /* We have hit an I/O error which we don't report now.
178 * But record it, and let the others do their job.
179 */
180 err = res;
181 res = 0;
182 }
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 }
185 if (res > 0)
186 return state;
suzuki9bebff62007-03-07 20:41:24 -0800187 if (err)
Suzuki K P57881dd2006-12-06 20:35:16 -0800188 /* The partition is unrecognized. So report I/O errors if there were any */
189 res = err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 if (!res)
191 printk(" unknown partition table\n");
192 else if (warn_no_part)
193 printk(" unable to read partition table\n");
194 kfree(state);
Suzuki Kp5127d002006-12-06 20:35:14 -0800195 return ERR_PTR(res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196}
197
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200198static ssize_t part_start_show(struct device *dev,
199 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200201 struct hd_struct *p = dev_to_part(dev);
Kay Sieversa7fd6702005-10-01 14:49:43 +0200202
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200203 return sprintf(buf, "%llu\n",(unsigned long long)p->start_sect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
205
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200206static ssize_t part_size_show(struct device *dev,
207 struct device_attribute *attr, char *buf)
208{
209 struct hd_struct *p = dev_to_part(dev);
210 return sprintf(buf, "%llu\n",(unsigned long long)p->nr_sects);
211}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200213static ssize_t part_stat_show(struct device *dev,
214 struct device_attribute *attr, char *buf)
Kay Sieversa7fd6702005-10-01 14:49:43 +0200215{
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200216 struct hd_struct *p = dev_to_part(dev);
217
218 return sprintf(buf, "%8u %8llu %8u %8llu\n",
Jens Axboea3623572005-11-01 09:26:16 +0100219 p->ios[0], (unsigned long long)p->sectors[0],
220 p->ios[1], (unsigned long long)p->sectors[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Akinobu Mitac17bb492006-12-08 02:39:46 -0800223#ifdef CONFIG_FAIL_MAKE_REQUEST
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200224static ssize_t part_fail_show(struct device *dev,
225 struct device_attribute *attr, char *buf)
226{
227 struct hd_struct *p = dev_to_part(dev);
Akinobu Mitac17bb492006-12-08 02:39:46 -0800228
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200229 return sprintf(buf, "%d\n", p->make_it_fail);
230}
231
232static ssize_t part_fail_store(struct device *dev,
233 struct device_attribute *attr,
Akinobu Mitac17bb492006-12-08 02:39:46 -0800234 const char *buf, size_t count)
235{
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200236 struct hd_struct *p = dev_to_part(dev);
Akinobu Mitac17bb492006-12-08 02:39:46 -0800237 int i;
238
239 if (count > 0 && sscanf(buf, "%d", &i) > 0)
240 p->make_it_fail = (i == 0) ? 0 : 1;
241
242 return count;
243}
Akinobu Mitac17bb492006-12-08 02:39:46 -0800244#endif
245
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200246static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL);
247static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
248static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL);
Akinobu Mitac17bb492006-12-08 02:39:46 -0800249#ifdef CONFIG_FAIL_MAKE_REQUEST
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200250static struct device_attribute dev_attr_fail =
251 __ATTR(make-it-fail, S_IRUGO|S_IWUSR, part_fail_show, part_fail_store);
Akinobu Mitac17bb492006-12-08 02:39:46 -0800252#endif
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200253
254static struct attribute *part_attrs[] = {
255 &dev_attr_start.attr,
256 &dev_attr_size.attr,
257 &dev_attr_stat.attr,
258#ifdef CONFIG_FAIL_MAKE_REQUEST
259 &dev_attr_fail.attr,
260#endif
261 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262};
263
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200264static struct attribute_group part_attr_group = {
265 .attrs = part_attrs,
266};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200268static struct attribute_group *part_attr_groups[] = {
269 &part_attr_group,
270 NULL
271};
272
273static void part_release(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200275 struct hd_struct *p = dev_to_part(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 kfree(p);
277}
278
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200279struct device_type part_type = {
280 .name = "partition",
281 .groups = part_attr_groups,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 .release = part_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283};
284
Jun'ichi Nomura6a4d44c2006-03-27 01:17:55 -0800285static inline void partition_sysfs_add_subdir(struct hd_struct *p)
286{
287 struct kobject *k;
288
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200289 k = kobject_get(&p->dev.kobj);
Greg Kroah-Hartman4ff6abf2007-11-05 22:24:43 -0800290 p->holder_dir = kobject_create_and_add("holders", k);
Jun'ichi Nomura6a4d44c2006-03-27 01:17:55 -0800291 kobject_put(k);
292}
293
294static inline void disk_sysfs_add_subdirs(struct gendisk *disk)
295{
296 struct kobject *k;
297
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200298 k = kobject_get(&disk->dev.kobj);
Greg Kroah-Hartman4ff6abf2007-11-05 22:24:43 -0800299 disk->holder_dir = kobject_create_and_add("holders", k);
300 disk->slave_dir = kobject_create_and_add("slaves", k);
Jun'ichi Nomura6a4d44c2006-03-27 01:17:55 -0800301 kobject_put(k);
302}
Jun'ichi Nomura6a4d44c2006-03-27 01:17:55 -0800303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304void delete_partition(struct gendisk *disk, int part)
305{
306 struct hd_struct *p = disk->part[part-1];
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 if (!p)
309 return;
310 if (!p->nr_sects)
311 return;
312 disk->part[part-1] = NULL;
313 p->start_sect = 0;
314 p->nr_sects = 0;
Jens Axboea3623572005-11-01 09:26:16 +0100315 p->ios[0] = p->ios[1] = 0;
316 p->sectors[0] = p->sectors[1] = 0;
Greg Kroah-Hartman197b12d2007-12-20 08:13:05 -0800317 kobject_put(p->holder_dir);
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200318 device_del(&p->dev);
319 put_device(&p->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320}
321
Fabio Massimo Di Nittod18d7682007-02-10 23:50:00 -0800322void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
324 struct hd_struct *p;
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200325 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700327 p = kzalloc(sizeof(*p), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 if (!p)
329 return;
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 p->start_sect = start;
332 p->nr_sects = len;
333 p->partno = part;
Peter Oberparleiter25e206b2006-07-10 04:44:00 -0700334 p->policy = disk->policy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200336 if (isdigit(disk->dev.bus_id[strlen(disk->dev.bus_id)-1]))
337 snprintf(p->dev.bus_id, BUS_ID_SIZE,
338 "%sp%d", disk->dev.bus_id, part);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 else
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200340 snprintf(p->dev.bus_id, BUS_ID_SIZE,
341 "%s%d", disk->dev.bus_id, part);
342
343 device_initialize(&p->dev);
344 p->dev.devt = MKDEV(disk->major, disk->first_minor + part);
345 p->dev.class = &block_class;
346 p->dev.type = &part_type;
347 p->dev.parent = &disk->dev;
348 disk->part[part-1] = p;
349
350 /* delay uevent until 'holders' subdir is created */
351 p->dev.uevent_suppress = 1;
352 device_add(&p->dev);
353 partition_sysfs_add_subdir(p);
354 p->dev.uevent_suppress = 0;
Fabio Massimo Di Nittod18d7682007-02-10 23:50:00 -0800355 if (flags & ADDPART_FLAG_WHOLEDISK) {
356 static struct attribute addpartattr = {
357 .name = "whole_disk",
358 .mode = S_IRUSR | S_IRGRP | S_IROTH,
Fabio Massimo Di Nittod18d7682007-02-10 23:50:00 -0800359 };
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200360 err = sysfs_create_file(&p->dev.kobj, &addpartattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
Jeff Garzikeee44cc2006-10-17 00:10:23 -0700362
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200363 /* suppress uevent if the disk supresses it */
364 if (!disk->dev.uevent_suppress)
365 kobject_uevent(&p->dev.kobj, KOBJ_ADD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
367
368/* Not exported, helper to add_disk(). */
369void register_disk(struct gendisk *disk)
370{
371 struct block_device *bdev;
372 char *s;
Kay Sieversd4d7e5d2006-03-24 20:45:35 +0100373 int i;
374 struct hd_struct *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 int err;
376
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200377 disk->dev.parent = disk->driverfs_dev;
378 disk->dev.devt = MKDEV(disk->major, disk->first_minor);
379
380 strlcpy(disk->dev.bus_id, disk->disk_name, KOBJ_NAME_LEN);
381 /* ewww... some of these buggers have / in the name... */
382 s = strchr(disk->dev.bus_id, '/');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 if (s)
384 *s = '!';
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200385
386 /* delay uevents, until we scanned partition table */
387 disk->dev.uevent_suppress = 1;
388
389 if (device_add(&disk->dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 return;
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200391#ifndef CONFIG_SYSFS_DEPRECATED
392 err = sysfs_create_link(block_depr, &disk->dev.kobj,
393 kobject_name(&disk->dev.kobj));
Jeff Garzikeee44cc2006-10-17 00:10:23 -0700394 if (err) {
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200395 device_del(&disk->dev);
Jeff Garzikeee44cc2006-10-17 00:10:23 -0700396 return;
397 }
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200398#endif
399 disk_sysfs_add_subdirs(disk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 /* No minors to use for partitions */
Greg Kroah-Hartmana2964182005-06-20 21:15:16 -0700402 if (disk->minors == 1)
Kay Sieversd4d7e5d2006-03-24 20:45:35 +0100403 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 /* No such device (e.g., media were just removed) */
406 if (!get_capacity(disk))
Kay Sieversd4d7e5d2006-03-24 20:45:35 +0100407 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 bdev = bdget_disk(disk, 0);
410 if (!bdev)
Kay Sieversd4d7e5d2006-03-24 20:45:35 +0100411 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 bdev->bd_invalidated = 1;
Kay Sieversd4d7e5d2006-03-24 20:45:35 +0100414 err = blkdev_get(bdev, FMODE_READ, 0);
Kay Sieversd4d7e5d2006-03-24 20:45:35 +0100415 if (err < 0)
416 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 blkdev_put(bdev);
Kay Sieversd4d7e5d2006-03-24 20:45:35 +0100418
419exit:
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200420 /* announce disk after possible partitions are created */
421 disk->dev.uevent_suppress = 0;
422 kobject_uevent(&disk->dev.kobj, KOBJ_ADD);
Kay Sieversd4d7e5d2006-03-24 20:45:35 +0100423
424 /* announce possible partitions */
425 for (i = 1; i < disk->minors; i++) {
426 p = disk->part[i-1];
427 if (!p || !p->nr_sects)
428 continue;
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200429 kobject_uevent(&p->dev.kobj, KOBJ_ADD);
Kay Sieversd4d7e5d2006-03-24 20:45:35 +0100430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
433int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
434{
435 struct parsed_partitions *state;
436 int p, res;
437
438 if (bdev->bd_part_count)
439 return -EBUSY;
440 res = invalidate_partition(disk, 0);
441 if (res)
442 return res;
443 bdev->bd_invalidated = 0;
444 for (p = 1; p < disk->minors; p++)
445 delete_partition(disk, p);
446 if (disk->fops->revalidate_disk)
447 disk->fops->revalidate_disk(disk);
448 if (!get_capacity(disk) || !(state = check_partition(disk, bdev)))
449 return 0;
Suzuki Kp5127d002006-12-06 20:35:14 -0800450 if (IS_ERR(state)) /* I/O error reading the partition table */
suzukib74a2f02007-03-16 13:38:25 -0800451 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 for (p = 1; p < state->limit; p++) {
453 sector_t size = state->parts[p].size;
454 sector_t from = state->parts[p].from;
455 if (!size)
456 continue;
Mike Miller98bd34e2006-06-23 02:06:07 -0700457 if (from + size > get_capacity(disk)) {
458 printk(" %s: p%d exceeds device capacity\n",
459 disk->disk_name, p);
460 }
Fabio Massimo Di Nittod18d7682007-02-10 23:50:00 -0800461 add_partition(disk, p, from, size, state->parts[p].flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#ifdef CONFIG_BLK_DEV_MD
Fabio Massimo Di Nittod18d7682007-02-10 23:50:00 -0800463 if (state->parts[p].flags & ADDPART_FLAG_RAID)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 md_autodetect_dev(bdev->bd_dev+p);
465#endif
466 }
467 kfree(state);
468 return 0;
469}
470
471unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)
472{
473 struct address_space *mapping = bdev->bd_inode->i_mapping;
474 struct page *page;
475
Pekka Enberg090d2b12006-06-23 02:05:08 -0700476 page = read_mapping_page(mapping, (pgoff_t)(n >> (PAGE_CACHE_SHIFT-9)),
477 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 if (!IS_ERR(page)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 if (PageError(page))
480 goto fail;
481 p->v = page;
482 return (unsigned char *)page_address(page) + ((n & ((1 << (PAGE_CACHE_SHIFT - 9)) - 1)) << 9);
483fail:
484 page_cache_release(page);
485 }
486 p->v = NULL;
487 return NULL;
488}
489
490EXPORT_SYMBOL(read_dev_sector);
491
492void del_gendisk(struct gendisk *disk)
493{
494 int p;
495
496 /* invalidate stuff */
497 for (p = disk->minors - 1; p > 0; p--) {
498 invalidate_partition(disk, p);
499 delete_partition(disk, p);
500 }
501 invalidate_partition(disk, 0);
502 disk->capacity = 0;
503 disk->flags &= ~GENHD_FL_UP;
504 unlink_gendisk(disk);
505 disk_stat_set_all(disk, 0);
Chen, Kenneth W20e5c812005-10-13 21:48:42 +0200506 disk->stamp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Greg Kroah-Hartman197b12d2007-12-20 08:13:05 -0800508 kobject_put(disk->holder_dir);
509 kobject_put(disk->slave_dir);
Kay Sieversedfaa7c2007-05-21 22:08:01 +0200510 disk->driverfs_dev = NULL;
511#ifndef CONFIG_SYSFS_DEPRECATED
512 sysfs_remove_link(block_depr, disk->dev.bus_id);
513#endif
514 device_del(&disk->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515}