check.c 17 KB

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