check.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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_stat_show(struct device *dev,
  203. struct device_attribute *attr, char *buf)
  204. {
  205. struct hd_struct *p = dev_to_part(dev);
  206. int cpu;
  207. cpu = part_stat_lock();
  208. part_round_stats(cpu, p);
  209. part_stat_unlock();
  210. return sprintf(buf,
  211. "%8lu %8lu %8llu %8u "
  212. "%8lu %8lu %8llu %8u "
  213. "%8u %8u %8u"
  214. "\n",
  215. part_stat_read(p, ios[READ]),
  216. part_stat_read(p, merges[READ]),
  217. (unsigned long long)part_stat_read(p, sectors[READ]),
  218. jiffies_to_msecs(part_stat_read(p, ticks[READ])),
  219. part_stat_read(p, ios[WRITE]),
  220. part_stat_read(p, merges[WRITE]),
  221. (unsigned long long)part_stat_read(p, sectors[WRITE]),
  222. jiffies_to_msecs(part_stat_read(p, ticks[WRITE])),
  223. part_in_flight(p),
  224. jiffies_to_msecs(part_stat_read(p, io_ticks)),
  225. jiffies_to_msecs(part_stat_read(p, time_in_queue)));
  226. }
  227. ssize_t part_inflight_show(struct device *dev,
  228. struct device_attribute *attr, char *buf)
  229. {
  230. struct hd_struct *p = dev_to_part(dev);
  231. return sprintf(buf, "%8u %8u\n", p->in_flight[0], p->in_flight[1]);
  232. }
  233. #ifdef CONFIG_FAIL_MAKE_REQUEST
  234. ssize_t part_fail_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, "%d\n", p->make_it_fail);
  239. }
  240. ssize_t part_fail_store(struct device *dev,
  241. struct device_attribute *attr,
  242. const char *buf, size_t count)
  243. {
  244. struct hd_struct *p = dev_to_part(dev);
  245. int i;
  246. if (count > 0 && sscanf(buf, "%d", &i) > 0)
  247. p->make_it_fail = (i == 0) ? 0 : 1;
  248. return count;
  249. }
  250. #endif
  251. static DEVICE_ATTR(partition, S_IRUGO, part_partition_show, NULL);
  252. static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL);
  253. static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
  254. static DEVICE_ATTR(alignment_offset, S_IRUGO, part_alignment_offset_show, NULL);
  255. static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL);
  256. static DEVICE_ATTR(inflight, S_IRUGO, part_inflight_show, NULL);
  257. #ifdef CONFIG_FAIL_MAKE_REQUEST
  258. static struct device_attribute dev_attr_fail =
  259. __ATTR(make-it-fail, S_IRUGO|S_IWUSR, part_fail_show, part_fail_store);
  260. #endif
  261. static struct attribute *part_attrs[] = {
  262. &dev_attr_partition.attr,
  263. &dev_attr_start.attr,
  264. &dev_attr_size.attr,
  265. &dev_attr_alignment_offset.attr,
  266. &dev_attr_stat.attr,
  267. &dev_attr_inflight.attr,
  268. #ifdef CONFIG_FAIL_MAKE_REQUEST
  269. &dev_attr_fail.attr,
  270. #endif
  271. NULL
  272. };
  273. static struct attribute_group part_attr_group = {
  274. .attrs = part_attrs,
  275. };
  276. static const struct attribute_group *part_attr_groups[] = {
  277. &part_attr_group,
  278. #ifdef CONFIG_BLK_DEV_IO_TRACE
  279. &blk_trace_attr_group,
  280. #endif
  281. NULL
  282. };
  283. static void part_release(struct device *dev)
  284. {
  285. struct hd_struct *p = dev_to_part(dev);
  286. free_part_stats(p);
  287. kfree(p);
  288. }
  289. struct device_type part_type = {
  290. .name = "partition",
  291. .groups = part_attr_groups,
  292. .release = part_release,
  293. };
  294. static void delete_partition_rcu_cb(struct rcu_head *head)
  295. {
  296. struct hd_struct *part = container_of(head, struct hd_struct, rcu_head);
  297. part->start_sect = 0;
  298. part->nr_sects = 0;
  299. part_stat_set_all(part, 0);
  300. put_device(part_to_dev(part));
  301. }
  302. void delete_partition(struct gendisk *disk, int partno)
  303. {
  304. struct disk_part_tbl *ptbl = disk->part_tbl;
  305. struct hd_struct *part;
  306. if (partno >= ptbl->len)
  307. return;
  308. part = ptbl->part[partno];
  309. if (!part)
  310. return;
  311. blk_free_devt(part_devt(part));
  312. rcu_assign_pointer(ptbl->part[partno], NULL);
  313. rcu_assign_pointer(ptbl->last_lookup, NULL);
  314. kobject_put(part->holder_dir);
  315. device_del(part_to_dev(part));
  316. call_rcu(&part->rcu_head, delete_partition_rcu_cb);
  317. }
  318. static ssize_t whole_disk_show(struct device *dev,
  319. struct device_attribute *attr, char *buf)
  320. {
  321. return 0;
  322. }
  323. static DEVICE_ATTR(whole_disk, S_IRUSR | S_IRGRP | S_IROTH,
  324. whole_disk_show, NULL);
  325. struct hd_struct *add_partition(struct gendisk *disk, int partno,
  326. sector_t start, sector_t len, int flags)
  327. {
  328. struct hd_struct *p;
  329. dev_t devt = MKDEV(0, 0);
  330. struct device *ddev = disk_to_dev(disk);
  331. struct device *pdev;
  332. struct disk_part_tbl *ptbl;
  333. const char *dname;
  334. int err;
  335. err = disk_expand_part_tbl(disk, partno);
  336. if (err)
  337. return ERR_PTR(err);
  338. ptbl = disk->part_tbl;
  339. if (ptbl->part[partno])
  340. return ERR_PTR(-EBUSY);
  341. p = kzalloc(sizeof(*p), GFP_KERNEL);
  342. if (!p)
  343. return ERR_PTR(-EBUSY);
  344. if (!init_part_stats(p)) {
  345. err = -ENOMEM;
  346. goto out_free;
  347. }
  348. pdev = part_to_dev(p);
  349. p->start_sect = start;
  350. p->alignment_offset = queue_sector_alignment_offset(disk->queue, start);
  351. p->nr_sects = len;
  352. p->partno = partno;
  353. p->policy = get_disk_ro(disk);
  354. dname = dev_name(ddev);
  355. if (isdigit(dname[strlen(dname) - 1]))
  356. dev_set_name(pdev, "%sp%d", dname, partno);
  357. else
  358. dev_set_name(pdev, "%s%d", dname, partno);
  359. device_initialize(pdev);
  360. pdev->class = &block_class;
  361. pdev->type = &part_type;
  362. pdev->parent = ddev;
  363. err = blk_alloc_devt(p, &devt);
  364. if (err)
  365. goto out_free_stats;
  366. pdev->devt = devt;
  367. /* delay uevent until 'holders' subdir is created */
  368. dev_set_uevent_suppress(pdev, 1);
  369. err = device_add(pdev);
  370. if (err)
  371. goto out_put;
  372. err = -ENOMEM;
  373. p->holder_dir = kobject_create_and_add("holders", &pdev->kobj);
  374. if (!p->holder_dir)
  375. goto out_del;
  376. dev_set_uevent_suppress(pdev, 0);
  377. if (flags & ADDPART_FLAG_WHOLEDISK) {
  378. err = device_create_file(pdev, &dev_attr_whole_disk);
  379. if (err)
  380. goto out_del;
  381. }
  382. /* everything is up and running, commence */
  383. INIT_RCU_HEAD(&p->rcu_head);
  384. rcu_assign_pointer(ptbl->part[partno], p);
  385. /* suppress uevent if the disk supresses it */
  386. if (!dev_get_uevent_suppress(ddev))
  387. kobject_uevent(&pdev->kobj, KOBJ_ADD);
  388. return p;
  389. out_free_stats:
  390. free_part_stats(p);
  391. out_free:
  392. kfree(p);
  393. return ERR_PTR(err);
  394. out_del:
  395. kobject_put(p->holder_dir);
  396. device_del(pdev);
  397. out_put:
  398. put_device(pdev);
  399. blk_free_devt(devt);
  400. return ERR_PTR(err);
  401. }
  402. /* Not exported, helper to add_disk(). */
  403. void register_disk(struct gendisk *disk)
  404. {
  405. struct device *ddev = disk_to_dev(disk);
  406. struct block_device *bdev;
  407. struct disk_part_iter piter;
  408. struct hd_struct *part;
  409. int err;
  410. ddev->parent = disk->driverfs_dev;
  411. dev_set_name(ddev, disk->disk_name);
  412. /* delay uevents, until we scanned partition table */
  413. dev_set_uevent_suppress(ddev, 1);
  414. if (device_add(ddev))
  415. return;
  416. #ifndef CONFIG_SYSFS_DEPRECATED
  417. err = sysfs_create_link(block_depr, &ddev->kobj,
  418. kobject_name(&ddev->kobj));
  419. if (err) {
  420. device_del(ddev);
  421. return;
  422. }
  423. #endif
  424. disk->part0.holder_dir = kobject_create_and_add("holders", &ddev->kobj);
  425. disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
  426. /* No minors to use for partitions */
  427. if (!disk_partitionable(disk))
  428. goto exit;
  429. /* No such device (e.g., media were just removed) */
  430. if (!get_capacity(disk))
  431. goto exit;
  432. bdev = bdget_disk(disk, 0);
  433. if (!bdev)
  434. goto exit;
  435. bdev->bd_invalidated = 1;
  436. err = blkdev_get(bdev, FMODE_READ);
  437. if (err < 0)
  438. goto exit;
  439. blkdev_put(bdev, FMODE_READ);
  440. exit:
  441. /* announce disk after possible partitions are created */
  442. dev_set_uevent_suppress(ddev, 0);
  443. kobject_uevent(&ddev->kobj, KOBJ_ADD);
  444. /* announce possible partitions */
  445. disk_part_iter_init(&piter, disk, 0);
  446. while ((part = disk_part_iter_next(&piter)))
  447. kobject_uevent(&part_to_dev(part)->kobj, KOBJ_ADD);
  448. disk_part_iter_exit(&piter);
  449. }
  450. int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
  451. {
  452. struct disk_part_iter piter;
  453. struct hd_struct *part;
  454. struct parsed_partitions *state;
  455. int p, highest, res;
  456. if (bdev->bd_part_count)
  457. return -EBUSY;
  458. res = invalidate_partition(disk, 0);
  459. if (res)
  460. return res;
  461. disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
  462. while ((part = disk_part_iter_next(&piter)))
  463. delete_partition(disk, part->partno);
  464. disk_part_iter_exit(&piter);
  465. if (disk->fops->revalidate_disk)
  466. disk->fops->revalidate_disk(disk);
  467. check_disk_size_change(disk, bdev);
  468. bdev->bd_invalidated = 0;
  469. if (!get_capacity(disk) || !(state = check_partition(disk, bdev)))
  470. return 0;
  471. if (IS_ERR(state)) /* I/O error reading the partition table */
  472. return -EIO;
  473. /* tell userspace that the media / partition table may have changed */
  474. kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
  475. /* Detect the highest partition number and preallocate
  476. * disk->part_tbl. This is an optimization and not strictly
  477. * necessary.
  478. */
  479. for (p = 1, highest = 0; p < state->limit; p++)
  480. if (state->parts[p].size)
  481. highest = p;
  482. disk_expand_part_tbl(disk, highest);
  483. /* add partitions */
  484. for (p = 1; p < state->limit; p++) {
  485. sector_t size, from;
  486. try_scan:
  487. size = state->parts[p].size;
  488. if (!size)
  489. continue;
  490. from = state->parts[p].from;
  491. if (from >= get_capacity(disk)) {
  492. printk(KERN_WARNING
  493. "%s: p%d ignored, start %llu is behind the end of the disk\n",
  494. disk->disk_name, p, (unsigned long long) from);
  495. continue;
  496. }
  497. if (from + size > get_capacity(disk)) {
  498. const struct block_device_operations *bdops = disk->fops;
  499. unsigned long long capacity;
  500. printk(KERN_WARNING
  501. "%s: p%d size %llu exceeds device capacity, ",
  502. disk->disk_name, p, (unsigned long long) size);
  503. if (bdops->set_capacity &&
  504. (disk->flags & GENHD_FL_NATIVE_CAPACITY) == 0) {
  505. printk(KERN_CONT "enabling native capacity\n");
  506. capacity = bdops->set_capacity(disk, ~0ULL);
  507. disk->flags |= GENHD_FL_NATIVE_CAPACITY;
  508. if (capacity > get_capacity(disk)) {
  509. set_capacity(disk, capacity);
  510. check_disk_size_change(disk, bdev);
  511. bdev->bd_invalidated = 0;
  512. }
  513. goto try_scan;
  514. } else {
  515. /*
  516. * we can not ignore partitions of broken tables
  517. * created by for example camera firmware, but
  518. * we limit them to the end of the disk to avoid
  519. * creating invalid block devices
  520. */
  521. printk(KERN_CONT "limited to end of disk\n");
  522. size = get_capacity(disk) - from;
  523. }
  524. }
  525. part = add_partition(disk, p, from, size,
  526. state->parts[p].flags);
  527. if (IS_ERR(part)) {
  528. printk(KERN_ERR " %s: p%d could not be added: %ld\n",
  529. disk->disk_name, p, -PTR_ERR(part));
  530. continue;
  531. }
  532. #ifdef CONFIG_BLK_DEV_MD
  533. if (state->parts[p].flags & ADDPART_FLAG_RAID)
  534. md_autodetect_dev(part_to_dev(part)->devt);
  535. #endif
  536. }
  537. kfree(state);
  538. return 0;
  539. }
  540. unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)
  541. {
  542. struct address_space *mapping = bdev->bd_inode->i_mapping;
  543. struct page *page;
  544. page = read_mapping_page(mapping, (pgoff_t)(n >> (PAGE_CACHE_SHIFT-9)),
  545. NULL);
  546. if (!IS_ERR(page)) {
  547. if (PageError(page))
  548. goto fail;
  549. p->v = page;
  550. return (unsigned char *)page_address(page) + ((n & ((1 << (PAGE_CACHE_SHIFT - 9)) - 1)) << 9);
  551. fail:
  552. page_cache_release(page);
  553. }
  554. p->v = NULL;
  555. return NULL;
  556. }
  557. EXPORT_SYMBOL(read_dev_sector);
  558. void del_gendisk(struct gendisk *disk)
  559. {
  560. struct disk_part_iter piter;
  561. struct hd_struct *part;
  562. /* invalidate stuff */
  563. disk_part_iter_init(&piter, disk,
  564. DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE);
  565. while ((part = disk_part_iter_next(&piter))) {
  566. invalidate_partition(disk, part->partno);
  567. delete_partition(disk, part->partno);
  568. }
  569. disk_part_iter_exit(&piter);
  570. invalidate_partition(disk, 0);
  571. blk_free_devt(disk_to_dev(disk)->devt);
  572. set_capacity(disk, 0);
  573. disk->flags &= ~GENHD_FL_UP;
  574. unlink_gendisk(disk);
  575. part_stat_set_all(&disk->part0, 0);
  576. disk->part0.stamp = 0;
  577. kobject_put(disk->part0.holder_dir);
  578. kobject_put(disk->slave_dir);
  579. disk->driverfs_dev = NULL;
  580. #ifndef CONFIG_SYSFS_DEPRECATED
  581. sysfs_remove_link(block_depr, dev_name(disk_to_dev(disk)));
  582. #endif
  583. device_del(disk_to_dev(disk));
  584. }