atari.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * fs/partitions/atari.c
  3. *
  4. * Code extracted from drivers/block/genhd.c
  5. *
  6. * Copyright (C) 1991-1998 Linus Torvalds
  7. * Re-organised Feb 1998 Russell King
  8. */
  9. #include <linux/ctype.h>
  10. #include "check.h"
  11. #include "atari.h"
  12. /* ++guenther: this should be settable by the user ("make config")?.
  13. */
  14. #define ICD_PARTS
  15. /* check if a partition entry looks valid -- Atari format is assumed if at
  16. least one of the primary entries is ok this way */
  17. #define VALID_PARTITION(pi,hdsiz) \
  18. (((pi)->flg & 1) && \
  19. isalnum((pi)->id[0]) && isalnum((pi)->id[1]) && isalnum((pi)->id[2]) && \
  20. be32_to_cpu((pi)->st) <= (hdsiz) && \
  21. be32_to_cpu((pi)->st) + be32_to_cpu((pi)->siz) <= (hdsiz))
  22. static inline int OK_id(char *s)
  23. {
  24. return memcmp (s, "GEM", 3) == 0 || memcmp (s, "BGM", 3) == 0 ||
  25. memcmp (s, "LNX", 3) == 0 || memcmp (s, "SWP", 3) == 0 ||
  26. memcmp (s, "RAW", 3) == 0 ;
  27. }
  28. int atari_partition(struct parsed_partitions *state)
  29. {
  30. Sector sect;
  31. struct rootsector *rs;
  32. struct partition_info *pi;
  33. u32 extensect;
  34. u32 hd_size;
  35. int slot;
  36. #ifdef ICD_PARTS
  37. int part_fmt = 0; /* 0:unknown, 1:AHDI, 2:ICD/Supra */
  38. #endif
  39. /*
  40. * ATARI partition scheme supports 512 lba only. If this is not
  41. * the case, bail early to avoid miscalculating hd_size.
  42. */
  43. if (bdev_logical_block_size(state->bdev) != 512)
  44. return 0;
  45. rs = read_part_sector(state, 0, &sect);
  46. if (!rs)
  47. return -1;
  48. /* Verify this is an Atari rootsector: */
  49. hd_size = state->bdev->bd_inode->i_size >> 9;
  50. if (!VALID_PARTITION(&rs->part[0], hd_size) &&
  51. !VALID_PARTITION(&rs->part[1], hd_size) &&
  52. !VALID_PARTITION(&rs->part[2], hd_size) &&
  53. !VALID_PARTITION(&rs->part[3], hd_size)) {
  54. /*
  55. * if there's no valid primary partition, assume that no Atari
  56. * format partition table (there's no reliable magic or the like
  57. * :-()
  58. */
  59. put_dev_sector(sect);
  60. return 0;
  61. }
  62. pi = &rs->part[0];
  63. strlcat(state->pp_buf, " AHDI", PAGE_SIZE);
  64. for (slot = 1; pi < &rs->part[4] && slot < state->limit; slot++, pi++) {
  65. struct rootsector *xrs;
  66. Sector sect2;
  67. ulong partsect;
  68. if ( !(pi->flg & 1) )
  69. continue;
  70. /* active partition */
  71. if (memcmp (pi->id, "XGM", 3) != 0) {
  72. /* we don't care about other id's */
  73. put_partition (state, slot, be32_to_cpu(pi->st),
  74. be32_to_cpu(pi->siz));
  75. continue;
  76. }
  77. /* extension partition */
  78. #ifdef ICD_PARTS
  79. part_fmt = 1;
  80. #endif
  81. strlcat(state->pp_buf, " XGM<", PAGE_SIZE);
  82. partsect = extensect = be32_to_cpu(pi->st);
  83. while (1) {
  84. xrs = read_part_sector(state, partsect, &sect2);
  85. if (!xrs) {
  86. printk (" block %ld read failed\n", partsect);
  87. put_dev_sector(sect);
  88. return -1;
  89. }
  90. /* ++roman: sanity check: bit 0 of flg field must be set */
  91. if (!(xrs->part[0].flg & 1)) {
  92. printk( "\nFirst sub-partition in extended partition is not valid!\n" );
  93. put_dev_sector(sect2);
  94. break;
  95. }
  96. put_partition(state, slot,
  97. partsect + be32_to_cpu(xrs->part[0].st),
  98. be32_to_cpu(xrs->part[0].siz));
  99. if (!(xrs->part[1].flg & 1)) {
  100. /* end of linked partition list */
  101. put_dev_sector(sect2);
  102. break;
  103. }
  104. if (memcmp( xrs->part[1].id, "XGM", 3 ) != 0) {
  105. printk("\nID of extended partition is not XGM!\n");
  106. put_dev_sector(sect2);
  107. break;
  108. }
  109. partsect = be32_to_cpu(xrs->part[1].st) + extensect;
  110. put_dev_sector(sect2);
  111. if (++slot == state->limit) {
  112. printk( "\nMaximum number of partitions reached!\n" );
  113. break;
  114. }
  115. }
  116. strlcat(state->pp_buf, " >", PAGE_SIZE);
  117. }
  118. #ifdef ICD_PARTS
  119. if ( part_fmt!=1 ) { /* no extended partitions -> test ICD-format */
  120. pi = &rs->icdpart[0];
  121. /* sanity check: no ICD format if first partition invalid */
  122. if (OK_id(pi->id)) {
  123. strlcat(state->pp_buf, " ICD<", PAGE_SIZE);
  124. for (; pi < &rs->icdpart[8] && slot < state->limit; slot++, pi++) {
  125. /* accept only GEM,BGM,RAW,LNX,SWP partitions */
  126. if (!((pi->flg & 1) && OK_id(pi->id)))
  127. continue;
  128. part_fmt = 2;
  129. put_partition (state, slot,
  130. be32_to_cpu(pi->st),
  131. be32_to_cpu(pi->siz));
  132. }
  133. strlcat(state->pp_buf, " >", PAGE_SIZE);
  134. }
  135. }
  136. #endif
  137. put_dev_sector(sect);
  138. strlcat(state->pp_buf, "\n", PAGE_SIZE);
  139. return 1;
  140. }