dev.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * (C) Copyright 2002
  3. * Stäubli Faverges - <www.staubli.com>
  4. * Pierre AUBERT p.aubert@staubli.com
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <config.h>
  26. #include "dos.h"
  27. #include "fdos.h"
  28. #define NB_HEADS 2
  29. #define NB_TRACKS 80
  30. #define NB_SECTORS 18
  31. static int lastwhere;
  32. /*-----------------------------------------------------------------------------
  33. * dev_open --
  34. *-----------------------------------------------------------------------------
  35. */
  36. int dev_open (void)
  37. {
  38. lastwhere = 0;
  39. return (0);
  40. }
  41. /*-----------------------------------------------------------------------------
  42. * dev_read -- len and where are sectors number
  43. *-----------------------------------------------------------------------------
  44. */
  45. int dev_read (void *buffer, int where, int len)
  46. {
  47. PRINTF ("dev_read (len = %d, where = %d)\n", len, where);
  48. /* Si on ne desire pas lire a la position courante, il faut un seek */
  49. if (where != lastwhere) {
  50. if (!fdc_fdos_seek (where)) {
  51. PRINTF ("seek error in dev_read");
  52. lastwhere = -1;
  53. return (-1);
  54. }
  55. }
  56. if (!fdc_fdos_read (buffer, len)) {
  57. PRINTF ("read error\n");
  58. lastwhere = -1;
  59. return (-1);
  60. }
  61. lastwhere = where + len;
  62. return (0);
  63. }
  64. /*-----------------------------------------------------------------------------
  65. * check_dev -- verify the diskette format
  66. *-----------------------------------------------------------------------------
  67. */
  68. int check_dev (BootSector_t *boot, Fs_t *fs)
  69. {
  70. unsigned int heads, sectors, tracks;
  71. int BootP, Infp0, InfpX, InfTm;
  72. int sect_per_track;
  73. /* Display Boot header */
  74. PRINTF ("Jump to boot code 0x%02x 0x%02x 0x%02x\n",
  75. boot -> jump [0], boot -> jump [1], boot -> jump[2]);
  76. PRINTF ("OEM name & version '%*.*s'\n",
  77. BANNER_LG, BANNER_LG, boot -> banner );
  78. PRINTF ("Bytes per sector hopefully 512 %d\n",
  79. __le16_to_cpu (boot -> secsiz));
  80. PRINTF ("Cluster size in sectors %d\n",
  81. boot -> clsiz);
  82. PRINTF ("Number of reserved (boot) sectors %d\n",
  83. __le16_to_cpu (boot -> nrsvsect));
  84. PRINTF ("Number of FAT tables hopefully 2 %d\n",
  85. boot -> nfat);
  86. PRINTF ("Number of directory slots %d\n",
  87. __le16_to_cpu (boot -> dirents));
  88. PRINTF ("Total sectors on disk %d\n",
  89. __le16_to_cpu (boot -> psect));
  90. PRINTF ("Media descriptor=first byte of FAT %d\n",
  91. boot -> descr);
  92. PRINTF ("Sectors in FAT %d\n",
  93. __le16_to_cpu (boot -> fatlen));
  94. PRINTF ("Sectors/track %d\n",
  95. __le16_to_cpu (boot -> nsect));
  96. PRINTF ("Heads %d\n",
  97. __le16_to_cpu (boot -> nheads));
  98. PRINTF ("number of hidden sectors %d\n",
  99. __le32_to_cpu (boot -> nhs));
  100. PRINTF ("big total sectors %d\n",
  101. __le32_to_cpu (boot -> bigsect));
  102. PRINTF ("physical drive ? %d\n",
  103. boot -> physdrive);
  104. PRINTF ("reserved %d\n",
  105. boot -> reserved);
  106. PRINTF ("dos > 4.0 diskette %d\n",
  107. boot -> dos4);
  108. PRINTF ("serial number %d\n",
  109. __le32_to_cpu (boot -> serial));
  110. PRINTF ("disk label %*.*s\n",
  111. LABEL_LG, LABEL_LG, boot -> label);
  112. PRINTF ("FAT type %8.8s\n",
  113. boot -> fat_type);
  114. PRINTF ("reserved by 2M %d\n",
  115. boot -> res_2m);
  116. PRINTF ("2M checksum (not used) %d\n",
  117. boot -> CheckSum);
  118. PRINTF ("2MF format version %d\n",
  119. boot -> fmt_2mf);
  120. PRINTF ("1 if write track after format %d\n",
  121. boot -> wt);
  122. PRINTF ("data transfer rate on track 0 %d\n",
  123. boot -> rate_0);
  124. PRINTF ("data transfer rate on track<>0 %d\n",
  125. boot -> rate_any);
  126. PRINTF ("offset to boot program %d\n",
  127. __le16_to_cpu (boot -> BootP));
  128. PRINTF ("T1: information for track 0 %d\n",
  129. __le16_to_cpu (boot -> Infp0));
  130. PRINTF ("T2: information for track<>0 %d\n",
  131. __le16_to_cpu (boot -> InfpX));
  132. PRINTF ("T3: track sectors size table %d\n",
  133. __le16_to_cpu (boot -> InfTm));
  134. PRINTF ("Format date 0x%04x\n",
  135. __le16_to_cpu (boot -> DateF));
  136. PRINTF ("Format time 0x%04x\n",
  137. __le16_to_cpu (boot -> TimeF));
  138. /* information is extracted from boot sector */
  139. heads = __le16_to_cpu (boot -> nheads);
  140. sectors = __le16_to_cpu (boot -> nsect);
  141. fs -> tot_sectors = __le32_to_cpu (boot -> bigsect);
  142. if (__le16_to_cpu (boot -> psect) != 0) {
  143. fs -> tot_sectors = __le16_to_cpu (boot -> psect);
  144. }
  145. sect_per_track = heads * sectors;
  146. tracks = (fs -> tot_sectors + sect_per_track - 1) / sect_per_track;
  147. BootP = __le16_to_cpu (boot -> BootP);
  148. Infp0 = __le16_to_cpu (boot -> Infp0);
  149. InfpX = __le16_to_cpu (boot -> InfpX);
  150. InfTm = __le16_to_cpu (boot -> InfTm);
  151. if (boot -> dos4 == EXTENDED_BOOT &&
  152. strncmp( boot->banner,"2M", 2 ) == 0 &&
  153. BootP < SZ_STD_SECTOR &&
  154. Infp0 < SZ_STD_SECTOR &&
  155. InfpX < SZ_STD_SECTOR &&
  156. InfTm < SZ_STD_SECTOR &&
  157. BootP >= InfTm + 2 &&
  158. InfTm >= InfpX &&
  159. InfpX >= Infp0 &&
  160. Infp0 >= 76 ) {
  161. return (-1);
  162. }
  163. if (heads != NB_HEADS ||
  164. tracks != NB_TRACKS ||
  165. sectors != NB_SECTORS ||
  166. __le16_to_cpu (boot -> secsiz) != SZ_STD_SECTOR ||
  167. fs -> tot_sectors == 0 ||
  168. (fs -> tot_sectors % sectors) != 0) {
  169. return (-1);
  170. }
  171. return (0);
  172. }