atari.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. rs = read_part_sector(state, 0, &sect);
  40. if (!rs)
  41. return -1;
  42. /* Verify this is an Atari rootsector: */
  43. hd_size = state->bdev->bd_inode->i_size >> 9;
  44. if (!VALID_PARTITION(&rs->part[0], hd_size) &&
  45. !VALID_PARTITION(&rs->part[1], hd_size) &&
  46. !VALID_PARTITION(&rs->part[2], hd_size) &&
  47. !VALID_PARTITION(&rs->part[3], hd_size)) {
  48. /*
  49. * if there's no valid primary partition, assume that no Atari
  50. * format partition table (there's no reliable magic or the like
  51. * :-()
  52. */
  53. put_dev_sector(sect);
  54. return 0;
  55. }
  56. pi = &rs->part[0];
  57. strlcat(state->pp_buf, " AHDI", PAGE_SIZE);
  58. for (slot = 1; pi < &rs->part[4] && slot < state->limit; slot++, pi++) {
  59. struct rootsector *xrs;
  60. Sector sect2;
  61. ulong partsect;
  62. if ( !(pi->flg & 1) )
  63. continue;
  64. /* active partition */
  65. if (memcmp (pi->id, "XGM", 3) != 0) {
  66. /* we don't care about other id's */
  67. put_partition (state, slot, be32_to_cpu(pi->st),
  68. be32_to_cpu(pi->siz));
  69. continue;
  70. }
  71. /* extension partition */
  72. #ifdef ICD_PARTS
  73. part_fmt = 1;
  74. #endif
  75. strlcat(state->pp_buf, " XGM<", PAGE_SIZE);
  76. partsect = extensect = be32_to_cpu(pi->st);
  77. while (1) {
  78. xrs = read_part_sector(state, partsect, &sect2);
  79. if (!xrs) {
  80. printk (" block %ld read failed\n", partsect);
  81. put_dev_sector(sect);
  82. return -1;
  83. }
  84. /* ++roman: sanity check: bit 0 of flg field must be set */
  85. if (!(xrs->part[0].flg & 1)) {
  86. printk( "\nFirst sub-partition in extended partition is not valid!\n" );
  87. put_dev_sector(sect2);
  88. break;
  89. }
  90. put_partition(state, slot,
  91. partsect + be32_to_cpu(xrs->part[0].st),
  92. be32_to_cpu(xrs->part[0].siz));
  93. if (!(xrs->part[1].flg & 1)) {
  94. /* end of linked partition list */
  95. put_dev_sector(sect2);
  96. break;
  97. }
  98. if (memcmp( xrs->part[1].id, "XGM", 3 ) != 0) {
  99. printk("\nID of extended partition is not XGM!\n");
  100. put_dev_sector(sect2);
  101. break;
  102. }
  103. partsect = be32_to_cpu(xrs->part[1].st) + extensect;
  104. put_dev_sector(sect2);
  105. if (++slot == state->limit) {
  106. printk( "\nMaximum number of partitions reached!\n" );
  107. break;
  108. }
  109. }
  110. strlcat(state->pp_buf, " >", PAGE_SIZE);
  111. }
  112. #ifdef ICD_PARTS
  113. if ( part_fmt!=1 ) { /* no extended partitions -> test ICD-format */
  114. pi = &rs->icdpart[0];
  115. /* sanity check: no ICD format if first partition invalid */
  116. if (OK_id(pi->id)) {
  117. strlcat(state->pp_buf, " ICD<", PAGE_SIZE);
  118. for (; pi < &rs->icdpart[8] && slot < state->limit; slot++, pi++) {
  119. /* accept only GEM,BGM,RAW,LNX,SWP partitions */
  120. if (!((pi->flg & 1) && OK_id(pi->id)))
  121. continue;
  122. part_fmt = 2;
  123. put_partition (state, slot,
  124. be32_to_cpu(pi->st),
  125. be32_to_cpu(pi->siz));
  126. }
  127. strlcat(state->pp_buf, " >", PAGE_SIZE);
  128. }
  129. }
  130. #endif
  131. put_dev_sector(sect);
  132. strlcat(state->pp_buf, "\n", PAGE_SIZE);
  133. return 1;
  134. }