check.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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/slab.h>
  16. #include <linux/ctype.h>
  17. #include <linux/genhd.h>
  18. #include "check.h"
  19. #include "acorn.h"
  20. #include "amiga.h"
  21. #include "atari.h"
  22. #include "ldm.h"
  23. #include "mac.h"
  24. #include "msdos.h"
  25. #include "osf.h"
  26. #include "sgi.h"
  27. #include "sun.h"
  28. #include "ibm.h"
  29. #include "ultrix.h"
  30. #include "efi.h"
  31. #include "karma.h"
  32. #include "sysv68.h"
  33. int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/
  34. static int (*check_part[])(struct parsed_partitions *) = {
  35. /*
  36. * Probe partition formats with tables at disk address 0
  37. * that also have an ADFS boot block at 0xdc0.
  38. */
  39. #ifdef CONFIG_ACORN_PARTITION_ICS
  40. adfspart_check_ICS,
  41. #endif
  42. #ifdef CONFIG_ACORN_PARTITION_POWERTEC
  43. adfspart_check_POWERTEC,
  44. #endif
  45. #ifdef CONFIG_ACORN_PARTITION_EESOX
  46. adfspart_check_EESOX,
  47. #endif
  48. /*
  49. * Now move on to formats that only have partition info at
  50. * disk address 0xdc0. Since these may also have stale
  51. * PC/BIOS partition tables, they need to come before
  52. * the msdos entry.
  53. */
  54. #ifdef CONFIG_ACORN_PARTITION_CUMANA
  55. adfspart_check_CUMANA,
  56. #endif
  57. #ifdef CONFIG_ACORN_PARTITION_ADFS
  58. adfspart_check_ADFS,
  59. #endif
  60. #ifdef CONFIG_EFI_PARTITION
  61. efi_partition, /* this must come before msdos */
  62. #endif
  63. #ifdef CONFIG_SGI_PARTITION
  64. sgi_partition,
  65. #endif
  66. #ifdef CONFIG_LDM_PARTITION
  67. ldm_partition, /* this must come before msdos */
  68. #endif
  69. #ifdef CONFIG_MSDOS_PARTITION
  70. msdos_partition,
  71. #endif
  72. #ifdef CONFIG_OSF_PARTITION
  73. osf_partition,
  74. #endif
  75. #ifdef CONFIG_SUN_PARTITION
  76. sun_partition,
  77. #endif
  78. #ifdef CONFIG_AMIGA_PARTITION
  79. amiga_partition,
  80. #endif
  81. #ifdef CONFIG_ATARI_PARTITION
  82. atari_partition,
  83. #endif
  84. #ifdef CONFIG_MAC_PARTITION
  85. mac_partition,
  86. #endif
  87. #ifdef CONFIG_ULTRIX_PARTITION
  88. ultrix_partition,
  89. #endif
  90. #ifdef CONFIG_IBM_PARTITION
  91. ibm_partition,
  92. #endif
  93. #ifdef CONFIG_KARMA_PARTITION
  94. karma_partition,
  95. #endif
  96. #ifdef CONFIG_SYSV68_PARTITION
  97. sysv68_partition,
  98. #endif
  99. NULL
  100. };
  101. struct parsed_partitions *
  102. check_partition(struct gendisk *hd, struct block_device *bdev)
  103. {
  104. struct parsed_partitions *state;
  105. int i, res, err;
  106. state = kzalloc(sizeof(struct parsed_partitions), GFP_KERNEL);
  107. if (!state)
  108. return NULL;
  109. state->pp_buf = (char *)__get_free_page(GFP_KERNEL);
  110. if (!state->pp_buf) {
  111. kfree(state);
  112. return NULL;
  113. }
  114. state->pp_buf[0] = '\0';
  115. state->bdev = bdev;
  116. disk_name(hd, 0, state->name);
  117. snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name);
  118. if (isdigit(state->name[strlen(state->name)-1]))
  119. sprintf(state->name, "p");
  120. state->limit = disk_max_parts(hd);
  121. i = res = err = 0;
  122. while (!res && check_part[i]) {
  123. memset(&state->parts, 0, sizeof(state->parts));
  124. res = check_part[i++](state);
  125. if (res < 0) {
  126. /* We have hit an I/O error which we don't report now.
  127. * But record it, and let the others do their job.
  128. */
  129. err = res;
  130. res = 0;
  131. }
  132. }
  133. if (res > 0) {
  134. printk(KERN_INFO "%s", state->pp_buf);
  135. free_page((unsigned long)state->pp_buf);
  136. return state;
  137. }
  138. if (state->access_beyond_eod)
  139. err = -ENOSPC;
  140. if (err)
  141. /* The partition is unrecognized. So report I/O errors if there were any */
  142. res = err;
  143. if (!res)
  144. strlcat(state->pp_buf, " unknown partition table\n", PAGE_SIZE);
  145. else if (warn_no_part)
  146. strlcat(state->pp_buf, " unable to read partition table\n", PAGE_SIZE);
  147. printk(KERN_INFO "%s", state->pp_buf);
  148. free_page((unsigned long)state->pp_buf);
  149. kfree(state);
  150. return ERR_PTR(res);
  151. }