amiga.c 3.7 KB

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