check.c 16 KB

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