check.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. /*
  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. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <linux/fs.h>
  18. #include <linux/slab.h>
  19. #include <linux/kmod.h>
  20. #include <linux/ctype.h>
  21. #include <linux/genhd.h>
  22. #include <linux/blktrace_api.h>
  23. #include "check.h"
  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"
  36. #include "karma.h"
  37. #include "sysv68.h"
  38. #ifdef CONFIG_BLK_DEV_MD
  39. extern void md_autodetect_dev(dev_t dev);
  40. #endif
  41. int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/
  42. static int (*check_part[])(struct parsed_partitions *, struct block_device *) = {
  43. /*
  44. * Probe partition formats with tables at disk address 0
  45. * that also have an ADFS boot block at 0xdc0.
  46. */
  47. #ifdef CONFIG_ACORN_PARTITION_ICS
  48. adfspart_check_ICS,
  49. #endif
  50. #ifdef CONFIG_ACORN_PARTITION_POWERTEC
  51. adfspart_check_POWERTEC,
  52. #endif
  53. #ifdef CONFIG_ACORN_PARTITION_EESOX
  54. adfspart_check_EESOX,
  55. #endif
  56. /*
  57. * Now move on to formats that only have partition info at
  58. * disk address 0xdc0. Since these may also have stale
  59. * PC/BIOS partition tables, they need to come before
  60. * the msdos entry.
  61. */
  62. #ifdef CONFIG_ACORN_PARTITION_CUMANA
  63. adfspart_check_CUMANA,
  64. #endif
  65. #ifdef CONFIG_ACORN_PARTITION_ADFS
  66. adfspart_check_ADFS,
  67. #endif
  68. #ifdef CONFIG_EFI_PARTITION
  69. efi_partition, /* this must come before msdos */
  70. #endif
  71. #ifdef CONFIG_SGI_PARTITION
  72. sgi_partition,
  73. #endif
  74. #ifdef CONFIG_LDM_PARTITION
  75. ldm_partition, /* this must come before msdos */
  76. #endif
  77. #ifdef CONFIG_MSDOS_PARTITION
  78. msdos_partition,
  79. #endif
  80. #ifdef CONFIG_OSF_PARTITION
  81. osf_partition,
  82. #endif
  83. #ifdef CONFIG_SUN_PARTITION
  84. sun_partition,
  85. #endif
  86. #ifdef CONFIG_AMIGA_PARTITION
  87. amiga_partition,
  88. #endif
  89. #ifdef CONFIG_ATARI_PARTITION
  90. atari_partition,
  91. #endif
  92. #ifdef CONFIG_MAC_PARTITION
  93. mac_partition,
  94. #endif
  95. #ifdef CONFIG_ULTRIX_PARTITION
  96. ultrix_partition,
  97. #endif
  98. #ifdef CONFIG_IBM_PARTITION
  99. ibm_partition,
  100. #endif
  101. #ifdef CONFIG_KARMA_PARTITION
  102. karma_partition,
  103. #endif
  104. #ifdef CONFIG_SYSV68_PARTITION
  105. sysv68_partition,
  106. #endif
  107. NULL
  108. };
  109. /*
  110. * disk_name() is used by partition check code and the genhd driver.
  111. * It formats the devicename of the indicated disk into
  112. * the supplied buffer (of size at least 32), and returns
  113. * a pointer to that same buffer (for convenience).
  114. */
  115. char *disk_name(struct gendisk *hd, int partno, char *buf)
  116. {
  117. if (!partno)
  118. snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name);
  119. else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1]))
  120. snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, partno);
  121. else
  122. snprintf(buf, BDEVNAME_SIZE, "%s%d", hd->disk_name, partno);
  123. return buf;
  124. }
  125. const char *bdevname(struct block_device *bdev, char *buf)
  126. {
  127. return disk_name(bdev->bd_disk, bdev->bd_part->partno, buf);
  128. }
  129. EXPORT_SYMBOL(bdevname);
  130. /*
  131. * There's very little reason to use this, you should really
  132. * have a struct block_device just about everywhere and use
  133. * bdevname() instead.
  134. */
  135. const char *__bdevname(dev_t dev, char *buffer)
  136. {
  137. scnprintf(buffer, BDEVNAME_SIZE, "unknown-block(%u,%u)",
  138. MAJOR(dev), MINOR(dev));
  139. return buffer;
  140. }
  141. EXPORT_SYMBOL(__bdevname);
  142. static struct parsed_partitions *
  143. check_partition(struct gendisk *hd, struct block_device *bdev)
  144. {
  145. struct parsed_partitions *state;
  146. int i, res, err;
  147. state = kmalloc(sizeof(struct parsed_partitions), GFP_KERNEL);
  148. if (!state)
  149. return NULL;
  150. disk_name(hd, 0, state->name);
  151. printk(KERN_INFO " %s:", state->name);
  152. if (isdigit(state->name[strlen(state->name)-1]))
  153. sprintf(state->name, "p");
  154. state->limit = disk_max_parts(hd);
  155. i = res = err = 0;
  156. while (!res && check_part[i]) {
  157. memset(&state->parts, 0, sizeof(state->parts));
  158. res = check_part[i++](state, bdev);
  159. if (res < 0) {
  160. /* We have hit an I/O error which we don't report now.
  161. * But record it, and let the others do their job.
  162. */
  163. err = res;
  164. res = 0;
  165. }
  166. }
  167. if (res > 0)
  168. return state;
  169. if (err)
  170. /* The partition is unrecognized. So report I/O errors if there were any */
  171. res = err;
  172. if (!res)
  173. printk(" unknown partition table\n");
  174. else if (warn_no_part)
  175. printk(" unable to read partition table\n");
  176. kfree(state);
  177. return ERR_PTR(res);
  178. }
  179. static ssize_t part_partition_show(struct device *dev,
  180. struct device_attribute *attr, char *buf)
  181. {
  182. struct hd_struct *p = dev_to_part(dev);
  183. return sprintf(buf, "%d\n", p->partno);
  184. }
  185. static ssize_t part_start_show(struct device *dev,
  186. struct device_attribute *attr, char *buf)
  187. {
  188. struct hd_struct *p = dev_to_part(dev);
  189. return sprintf(buf, "%llu\n",(unsigned long long)p->start_sect);
  190. }
  191. ssize_t part_size_show(struct device *dev,
  192. struct device_attribute *attr, char *buf)
  193. {
  194. struct hd_struct *p = dev_to_part(dev);
  195. return sprintf(buf, "%llu\n",(unsigned long long)p->nr_sects);
  196. }
  197. ssize_t part_alignment_offset_show(struct device *dev,
  198. struct device_attribute *attr, char *buf)
  199. {
  200. struct hd_struct *p = dev_to_part(dev);
  201. return sprintf(buf, "%llu\n", (unsigned long long)p->alignment_offset);
  202. }
  203. ssize_t part_discard_alignment_show(struct device *dev,
  204. struct device_attribute *attr, char *buf)
  205. {
  206. struct hd_struct *p = dev_to_part(dev);
  207. return sprintf(buf, "%u\n", p->discard_alignment);
  208. }
  209. ssize_t part_stat_show(struct device *dev,
  210. struct device_attribute *attr, char *buf)
  211. {
  212. struct hd_struct *p = dev_to_part(dev);
  213. int cpu;
  214. cpu = part_stat_lock();
  215. part_round_stats(cpu, p);
  216. part_stat_unlock();
  217. return sprintf(buf,
  218. "%8lu %8lu %8llu %8u "
  219. "%8lu %8lu %8llu %8u "
  220. "%8u %8u %8u"
  221. "\n",
  222. part_stat_read(p, ios[READ]),
  223. part_stat_read(p, merges[READ]),
  224. (unsigned long long)part_stat_read(p, sectors[READ]),
  225. jiffies_to_msecs(part_stat_read(p, ticks[READ])),
  226. part_stat_read(p, ios[WRITE]),
  227. part_stat_read(p, merges[WRITE]),
  228. (unsigned long long)part_stat_read(p, sectors[WRITE]),
  229. jiffies_to_msecs(part_stat_read(p, ticks[WRITE])),
  230. part_in_flight(p),
  231. jiffies_to_msecs(part_stat_read(p, io_ticks)),
  232. jiffies_to_msecs(part_stat_read(p, time_in_queue)));
  233. }
  234. ssize_t part_inflight_show(struct device *dev,
  235. struct device_attribute *attr, char *buf)
  236. {
  237. struct hd_struct *p = dev_to_part(dev);
  238. return sprintf(buf, "%8u %8u\n", p->in_flight[0], p->in_flight[1]);
  239. }
  240. #ifdef CONFIG_FAIL_MAKE_REQUEST
  241. ssize_t part_fail_show(struct device *dev,
  242. struct device_attribute *attr, char *buf)
  243. {
  244. struct hd_struct *p = dev_to_part(dev);
  245. return sprintf(buf, "%d\n", p->make_it_fail);
  246. }
  247. ssize_t part_fail_store(struct device *dev,
  248. struct device_attribute *attr,
  249. const char *buf, size_t count)
  250. {
  251. struct hd_struct *p = dev_to_part(dev);
  252. int i;
  253. if (count > 0 && sscanf(buf, "%d", &i) > 0)
  254. p->make_it_fail = (i == 0) ? 0 : 1;
  255. return count;
  256. }
  257. #endif
  258. static DEVICE_ATTR(partition, S_IRUGO, part_partition_show, NULL);
  259. static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL);
  260. static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
  261. static DEVICE_ATTR(alignment_offset, S_IRUGO, part_alignment_offset_show, NULL);
  262. static DEVICE_ATTR(discard_alignment, S_IRUGO, part_discard_alignment_show,
  263. NULL);
  264. static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL);
  265. static DEVICE_ATTR(inflight, S_IRUGO, part_inflight_show, NULL);
  266. #ifdef CONFIG_FAIL_MAKE_REQUEST
  267. static struct device_attribute dev_attr_fail =
  268. __ATTR(make-it-fail, S_IRUGO|S_IWUSR, part_fail_show, part_fail_store);
  269. #endif
  270. static struct attribute *part_attrs[] = {
  271. &dev_attr_partition.attr,
  272. &dev_attr_start.attr,
  273. &dev_attr_size.attr,
  274. &dev_attr_alignment_offset.attr,
  275. &dev_attr_discard_alignment.attr,
  276. &dev_attr_stat.attr,
  277. &dev_attr_inflight.attr,
  278. #ifdef CONFIG_FAIL_MAKE_REQUEST
  279. &dev_attr_fail.attr,
  280. #endif
  281. NULL
  282. };
  283. static struct attribute_group part_attr_group = {
  284. .attrs = part_attrs,
  285. };
  286. static const struct attribute_group *part_attr_groups[] = {
  287. &part_attr_group,
  288. #ifdef CONFIG_BLK_DEV_IO_TRACE
  289. &blk_trace_attr_group,
  290. #endif
  291. NULL
  292. };
  293. static void part_release(struct device *dev)
  294. {
  295. struct hd_struct *p = dev_to_part(dev);
  296. free_part_stats(p);
  297. kfree(p);
  298. }
  299. struct device_type part_type = {
  300. .name = "partition",
  301. .groups = part_attr_groups,
  302. .release = part_release,
  303. };
  304. static void delete_partition_rcu_cb(struct rcu_head *head)
  305. {
  306. struct hd_struct *part = container_of(head, struct hd_struct, rcu_head);
  307. part->start_sect = 0;
  308. part->nr_sects = 0;
  309. part_stat_set_all(part, 0);
  310. put_device(part_to_dev(part));
  311. }
  312. void delete_partition(struct gendisk *disk, int partno)
  313. {
  314. struct disk_part_tbl *ptbl = disk->part_tbl;
  315. struct hd_struct *part;
  316. if (partno >= ptbl->len)
  317. return;
  318. part = ptbl->part[partno];
  319. if (!part)
  320. return;
  321. blk_free_devt(part_devt(part));
  322. rcu_assign_pointer(ptbl->part[partno], NULL);
  323. rcu_assign_pointer(ptbl->last_lookup, NULL);
  324. kobject_put(part->holder_dir);
  325. device_del(part_to_dev(part));
  326. call_rcu(&part->rcu_head, delete_partition_rcu_cb);
  327. }
  328. static ssize_t whole_disk_show(struct device *dev,
  329. struct device_attribute *attr, char *buf)
  330. {
  331. return 0;
  332. }
  333. static DEVICE_ATTR(whole_disk, S_IRUSR | S_IRGRP | S_IROTH,
  334. whole_disk_show, NULL);
  335. struct hd_struct *add_partition(struct gendisk *disk, int partno,
  336. sector_t start, sector_t len, int flags)
  337. {
  338. struct hd_struct *p;
  339. dev_t devt = MKDEV(0, 0);
  340. struct device *ddev = disk_to_dev(disk);
  341. struct device *pdev;
  342. struct disk_part_tbl *ptbl;
  343. const char *dname;
  344. int err;
  345. err = disk_expand_part_tbl(disk, partno);
  346. if (err)
  347. return ERR_PTR(err);
  348. ptbl = disk->part_tbl;
  349. if (ptbl->part[partno])
  350. return ERR_PTR(-EBUSY);
  351. p = kzalloc(sizeof(*p), GFP_KERNEL);
  352. if (!p)
  353. return ERR_PTR(-EBUSY);
  354. if (!init_part_stats(p)) {
  355. err = -ENOMEM;
  356. goto out_free;
  357. }
  358. pdev = part_to_dev(p);
  359. p->start_sect = start;
  360. p->alignment_offset =
  361. queue_limit_alignment_offset(&disk->queue->limits, start);
  362. p->discard_alignment =
  363. queue_limit_discard_alignment(&disk->queue->limits, start);
  364. p->nr_sects = len;
  365. p->partno = partno;
  366. p->policy = get_disk_ro(disk);
  367. dname = dev_name(ddev);
  368. if (isdigit(dname[strlen(dname) - 1]))
  369. dev_set_name(pdev, "%sp%d", dname, partno);
  370. else
  371. dev_set_name(pdev, "%s%d", dname, partno);
  372. device_initialize(pdev);
  373. pdev->class = &block_class;
  374. pdev->type = &part_type;
  375. pdev->parent = ddev;
  376. err = blk_alloc_devt(p, &devt);
  377. if (err)
  378. goto out_free_stats;
  379. pdev->devt = devt;
  380. /* delay uevent until 'holders' subdir is created */
  381. dev_set_uevent_suppress(pdev, 1);
  382. err = device_add(pdev);
  383. if (err)
  384. goto out_put;
  385. err = -ENOMEM;
  386. p->holder_dir = kobject_create_and_add("holders", &pdev->kobj);
  387. if (!p->holder_dir)
  388. goto out_del;
  389. dev_set_uevent_suppress(pdev, 0);
  390. if (flags & ADDPART_FLAG_WHOLEDISK) {
  391. err = device_create_file(pdev, &dev_attr_whole_disk);
  392. if (err)
  393. goto out_del;
  394. }
  395. /* everything is up and running, commence */
  396. INIT_RCU_HEAD(&p->rcu_head);
  397. rcu_assign_pointer(ptbl->part[partno], p);
  398. /* suppress uevent if the disk supresses it */
  399. if (!dev_get_uevent_suppress(ddev))
  400. kobject_uevent(&pdev->kobj, KOBJ_ADD);
  401. return p;
  402. out_free_stats:
  403. free_part_stats(p);
  404. out_free:
  405. kfree(p);
  406. return ERR_PTR(err);
  407. out_del:
  408. kobject_put(p->holder_dir);
  409. device_del(pdev);
  410. out_put:
  411. put_device(pdev);
  412. blk_free_devt(devt);
  413. return ERR_PTR(err);
  414. }
  415. /* Not exported, helper to add_disk(). */
  416. void register_disk(struct gendisk *disk)
  417. {
  418. struct device *ddev = disk_to_dev(disk);
  419. struct block_device *bdev;
  420. struct disk_part_iter piter;
  421. struct hd_struct *part;
  422. int err;
  423. ddev->parent = disk->driverfs_dev;
  424. dev_set_name(ddev, disk->disk_name);
  425. /* delay uevents, until we scanned partition table */
  426. dev_set_uevent_suppress(ddev, 1);
  427. if (device_add(ddev))
  428. return;
  429. #ifndef CONFIG_SYSFS_DEPRECATED
  430. err = sysfs_create_link(block_depr, &ddev->kobj,
  431. kobject_name(&ddev->kobj));
  432. if (err) {
  433. device_del(ddev);
  434. return;
  435. }
  436. #endif
  437. disk->part0.holder_dir = kobject_create_and_add("holders", &ddev->kobj);
  438. disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
  439. /* No minors to use for partitions */
  440. if (!disk_partitionable(disk))
  441. goto exit;
  442. /* No such device (e.g., media were just removed) */
  443. if (!get_capacity(disk))
  444. goto exit;
  445. bdev = bdget_disk(disk, 0);
  446. if (!bdev)
  447. goto exit;
  448. bdev->bd_invalidated = 1;
  449. err = blkdev_get(bdev, FMODE_READ);
  450. if (err < 0)
  451. goto exit;
  452. blkdev_put(bdev, FMODE_READ);
  453. exit:
  454. /* announce disk after possible partitions are created */
  455. dev_set_uevent_suppress(ddev, 0);
  456. kobject_uevent(&ddev->kobj, KOBJ_ADD);
  457. /* announce possible partitions */
  458. disk_part_iter_init(&piter, disk, 0);
  459. while ((part = disk_part_iter_next(&piter)))
  460. kobject_uevent(&part_to_dev(part)->kobj, KOBJ_ADD);
  461. disk_part_iter_exit(&piter);
  462. }
  463. int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
  464. {
  465. struct disk_part_iter piter;
  466. struct hd_struct *part;
  467. struct parsed_partitions *state;
  468. int p, highest, res;
  469. if (bdev->bd_part_count)
  470. return -EBUSY;
  471. res = invalidate_partition(disk, 0);
  472. if (res)
  473. return res;
  474. disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
  475. while ((part = disk_part_iter_next(&piter)))
  476. delete_partition(disk, part->partno);
  477. disk_part_iter_exit(&piter);
  478. if (disk->fops->revalidate_disk)
  479. disk->fops->revalidate_disk(disk);
  480. check_disk_size_change(disk, bdev);
  481. bdev->bd_invalidated = 0;
  482. if (!get_capacity(disk) || !(state = check_partition(disk, bdev)))
  483. return 0;
  484. if (IS_ERR(state)) /* I/O error reading the partition table */
  485. return -EIO;
  486. /* tell userspace that the media / partition table may have changed */
  487. kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
  488. /* Detect the highest partition number and preallocate
  489. * disk->part_tbl. This is an optimization and not strictly
  490. * necessary.
  491. */
  492. for (p = 1, highest = 0; p < state->limit; p++)
  493. if (state->parts[p].size)
  494. highest = p;
  495. disk_expand_part_tbl(disk, highest);
  496. /* add partitions */
  497. for (p = 1; p < state->limit; p++) {
  498. sector_t size, from;
  499. try_scan:
  500. size = state->parts[p].size;
  501. if (!size)
  502. continue;
  503. from = state->parts[p].from;
  504. if (from >= get_capacity(disk)) {
  505. printk(KERN_WARNING
  506. "%s: p%d ignored, start %llu is behind the end of the disk\n",
  507. disk->disk_name, p, (unsigned long long) from);
  508. continue;
  509. }
  510. if (from + size > get_capacity(disk)) {
  511. const struct block_device_operations *bdops = disk->fops;
  512. unsigned long long capacity;
  513. printk(KERN_WARNING
  514. "%s: p%d size %llu exceeds device capacity, ",
  515. disk->disk_name, p, (unsigned long long) size);
  516. if (bdops->set_capacity &&
  517. (disk->flags & GENHD_FL_NATIVE_CAPACITY) == 0) {
  518. printk(KERN_CONT "enabling native capacity\n");
  519. capacity = bdops->set_capacity(disk, ~0ULL);
  520. disk->flags |= GENHD_FL_NATIVE_CAPACITY;
  521. if (capacity > get_capacity(disk)) {
  522. set_capacity(disk, capacity);
  523. check_disk_size_change(disk, bdev);
  524. bdev->bd_invalidated = 0;
  525. }
  526. goto try_scan;
  527. } else {
  528. /*
  529. * we can not ignore partitions of broken tables
  530. * created by for example camera firmware, but
  531. * we limit them to the end of the disk to avoid
  532. * creating invalid block devices
  533. */
  534. printk(KERN_CONT "limited to end of disk\n");
  535. size = get_capacity(disk) - from;
  536. }
  537. }
  538. part = add_partition(disk, p, from, size,
  539. state->parts[p].flags);
  540. if (IS_ERR(part)) {
  541. printk(KERN_ERR " %s: p%d could not be added: %ld\n",
  542. disk->disk_name, p, -PTR_ERR(part));
  543. continue;
  544. }
  545. #ifdef CONFIG_BLK_DEV_MD
  546. if (state->parts[p].flags & ADDPART_FLAG_RAID)
  547. md_autodetect_dev(part_to_dev(part)->devt);
  548. #endif
  549. }
  550. kfree(state);
  551. return 0;
  552. }
  553. unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)
  554. {
  555. struct address_space *mapping = bdev->bd_inode->i_mapping;
  556. struct page *page;
  557. page = read_mapping_page(mapping, (pgoff_t)(n >> (PAGE_CACHE_SHIFT-9)),
  558. NULL);
  559. if (!IS_ERR(page)) {
  560. if (PageError(page))
  561. goto fail;
  562. p->v = page;
  563. return (unsigned char *)page_address(page) + ((n & ((1 << (PAGE_CACHE_SHIFT - 9)) - 1)) << 9);
  564. fail:
  565. page_cache_release(page);
  566. }
  567. p->v = NULL;
  568. return NULL;
  569. }
  570. EXPORT_SYMBOL(read_dev_sector);
  571. void del_gendisk(struct gendisk *disk)
  572. {
  573. struct disk_part_iter piter;
  574. struct hd_struct *part;
  575. /* invalidate stuff */
  576. disk_part_iter_init(&piter, disk,
  577. DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE);
  578. while ((part = disk_part_iter_next(&piter))) {
  579. invalidate_partition(disk, part->partno);
  580. delete_partition(disk, part->partno);
  581. }
  582. disk_part_iter_exit(&piter);
  583. invalidate_partition(disk, 0);
  584. blk_free_devt(disk_to_dev(disk)->devt);
  585. set_capacity(disk, 0);
  586. disk->flags &= ~GENHD_FL_UP;
  587. unlink_gendisk(disk);
  588. part_stat_set_all(&disk->part0, 0);
  589. disk->part0.stamp = 0;
  590. kobject_put(disk->part0.holder_dir);
  591. kobject_put(disk->slave_dir);
  592. disk->driverfs_dev = NULL;
  593. #ifndef CONFIG_SYSFS_DEPRECATED
  594. sysfs_remove_link(block_depr, dev_name(disk_to_dev(disk)));
  595. #endif
  596. device_del(disk_to_dev(disk));
  597. }