amiga.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * fs/partitions/amiga.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/types.h>
  10. #include <linux/affs_hardblocks.h>
  11. #include "check.h"
  12. #include "amiga.h"
  13. static __inline__ u32
  14. checksum_block(__be32 *m, int size)
  15. {
  16. u32 sum = 0;
  17. while (size--)
  18. sum += be32_to_cpu(*m++);
  19. return sum;
  20. }
  21. int amiga_partition(struct parsed_partitions *state)
  22. {
  23. Sector sect;
  24. unsigned char *data;
  25. struct RigidDiskBlock *rdb;
  26. struct PartitionBlock *pb;
  27. int start_sect, nr_sects, blk, part, res = 0;
  28. int blksize = 1; /* Multiplier for disk block size */
  29. int slot = 1;
  30. char b[BDEVNAME_SIZE];
  31. for (blk = 0; ; blk++, put_dev_sector(sect)) {
  32. if (blk == RDB_ALLOCATION_LIMIT)
  33. goto rdb_done;
  34. data = read_part_sector(state, blk, &sect);
  35. if (!data) {
  36. if (warn_no_part)
  37. printk("Dev %s: unable to read RDB block %d\n",
  38. bdevname(state->bdev, b), blk);
  39. res = -1;
  40. goto rdb_done;
  41. }
  42. if (*(__be32 *)data != cpu_to_be32(IDNAME_RIGIDDISK))
  43. continue;
  44. rdb = (struct RigidDiskBlock *)data;
  45. if (checksum_block((__be32 *)data, be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F) == 0)
  46. break;
  47. /* Try again with 0xdc..0xdf zeroed, Windows might have
  48. * trashed it.
  49. */
  50. *(__be32 *)(data+0xdc) = 0;
  51. if (checksum_block((__be32 *)data,
  52. be32_to_cpu(rdb->rdb_SummedLongs) & 0x7F)==0) {
  53. printk("Warning: Trashed word at 0xd0 in block %d "
  54. "ignored in checksum calculation\n",blk);
  55. break;
  56. }
  57. printk("Dev %s: RDB in block %d has bad checksum\n",
  58. bdevname(state->bdev, b), blk);
  59. }
  60. /* blksize is blocks per 512 byte standard block */
  61. blksize = be32_to_cpu( rdb->rdb_BlockBytes ) / 512;
  62. {
  63. char tmp[7 + 10 + 1 + 1];
  64. /* Be more informative */
  65. snprintf(tmp, sizeof(tmp), " RDSK (%d)", blksize * 512);
  66. strlcat(state->pp_buf, tmp, PAGE_SIZE);
  67. }
  68. blk = be32_to_cpu(rdb->rdb_PartitionList);
  69. put_dev_sector(sect);
  70. for (part = 1; blk>0 && part<=16; part++, put_dev_sector(sect)) {
  71. blk *= blksize; /* Read in terms partition table understands */
  72. data = read_part_sector(state, blk, &sect);
  73. if (!data) {
  74. if (warn_no_part)
  75. printk("Dev %s: unable to read partition block %d\n",
  76. bdevname(state->bdev, b), blk);
  77. res = -1;
  78. goto rdb_done;
  79. }
  80. pb = (struct PartitionBlock *)data;
  81. blk = be32_to_cpu(pb->pb_Next);
  82. if (pb->pb_ID != cpu_to_be32(IDNAME_PARTITION))
  83. continue;
  84. if (checksum_block((__be32 *)pb, be32_to_cpu(pb->pb_SummedLongs) & 0x7F) != 0 )
  85. continue;
  86. /* Tell Kernel about it */
  87. nr_sects = (be32_to_cpu(pb->pb_Environment[10]) + 1 -
  88. be32_to_cpu(pb->pb_Environment[9])) *
  89. be32_to_cpu(pb->pb_Environment[3]) *
  90. be32_to_cpu(pb->pb_Environment[5]) *
  91. blksize;
  92. if (!nr_sects)
  93. continue;
  94. start_sect = be32_to_cpu(pb->pb_Environment[9]) *
  95. be32_to_cpu(pb->pb_Environment[3]) *
  96. be32_to_cpu(pb->pb_Environment[5]) *
  97. blksize;
  98. put_partition(state,slot++,start_sect,nr_sects);
  99. {
  100. /* Be even more informative to aid mounting */
  101. char dostype[4];
  102. char tmp[42];
  103. __be32 *dt = (__be32 *)dostype;
  104. *dt = pb->pb_Environment[16];
  105. if (dostype[3] < ' ')
  106. snprintf(tmp, sizeof(tmp), " (%c%c%c^%c)",
  107. dostype[0], dostype[1],
  108. dostype[2], dostype[3] + '@' );
  109. else
  110. snprintf(tmp, sizeof(tmp), " (%c%c%c%c)",
  111. dostype[0], dostype[1],
  112. dostype[2], dostype[3]);
  113. strlcat(state->pp_buf, tmp, PAGE_SIZE);
  114. snprintf(tmp, sizeof(tmp), "(res %d spb %d)",
  115. be32_to_cpu(pb->pb_Environment[6]),
  116. be32_to_cpu(pb->pb_Environment[4]));
  117. strlcat(state->pp_buf, tmp, PAGE_SIZE);
  118. }
  119. res = 1;
  120. }
  121. strlcat(state->pp_buf, "\n", PAGE_SIZE);
  122. rdb_done:
  123. return res;
  124. }