dev.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. #if (CONFIG_COMMANDS & CFG_CMD_FDOS)
  29. #define NB_HEADS 2
  30. #define NB_TRACKS 80
  31. #define NB_SECTORS 18
  32. static int lastwhere;
  33. /*-----------------------------------------------------------------------------
  34. * dev_open --
  35. *-----------------------------------------------------------------------------
  36. */
  37. int dev_open (void)
  38. {
  39. lastwhere = 0;
  40. return (0);
  41. }
  42. /*-----------------------------------------------------------------------------
  43. * dev_read -- len and where are sectors number
  44. *-----------------------------------------------------------------------------
  45. */
  46. int dev_read (void *buffer, int where, int len)
  47. {
  48. PRINTF ("dev_read (len = %d, where = %d)\n", len, where);
  49. /* Si on ne desire pas lire a la position courante, il faut un seek */
  50. if (where != lastwhere) {
  51. if (!fdc_fdos_seek (where)) {
  52. PRINTF ("seek error in dev_read");
  53. lastwhere = -1;
  54. return (-1);
  55. }
  56. }
  57. if (!fdc_fdos_read (buffer, len)) {
  58. PRINTF ("read error\n");
  59. lastwhere = -1;
  60. return (-1);
  61. }
  62. lastwhere = where + len;
  63. return (0);
  64. }
  65. /*-----------------------------------------------------------------------------
  66. * check_dev -- verify the diskette format
  67. *-----------------------------------------------------------------------------
  68. */
  69. int check_dev (BootSector_t *boot, Fs_t *fs)
  70. {
  71. unsigned int heads, sectors, tracks;
  72. int BootP, Infp0, InfpX, InfTm;
  73. int sect_per_track;
  74. /* Display Boot header */
  75. PRINTF ("Jump to boot code 0x%02x 0x%02x 0x%02x\n",
  76. boot -> jump [0], boot -> jump [1], boot -> jump[2]);
  77. PRINTF ("OEM name & version '%*.*s'\n",
  78. BANNER_LG, BANNER_LG, boot -> banner );
  79. PRINTF ("Bytes per sector hopefully 512 %d\n",
  80. __le16_to_cpu (boot -> secsiz));
  81. PRINTF ("Cluster size in sectors %d\n",
  82. boot -> clsiz);
  83. PRINTF ("Number of reserved (boot) sectors %d\n",
  84. __le16_to_cpu (boot -> nrsvsect));
  85. PRINTF ("Number of FAT tables hopefully 2 %d\n",
  86. boot -> nfat);
  87. PRINTF ("Number of directory slots %d\n",
  88. __le16_to_cpu (boot -> dirents));
  89. PRINTF ("Total sectors on disk %d\n",
  90. __le16_to_cpu (boot -> psect));
  91. PRINTF ("Media descriptor=first byte of FAT %d\n",
  92. boot -> descr);
  93. PRINTF ("Sectors in FAT %d\n",
  94. __le16_to_cpu (boot -> fatlen));
  95. PRINTF ("Sectors/track %d\n",
  96. __le16_to_cpu (boot -> nsect));
  97. PRINTF ("Heads %d\n",
  98. __le16_to_cpu (boot -> nheads));
  99. PRINTF ("number of hidden sectors %d\n",
  100. __le32_to_cpu (boot -> nhs));
  101. PRINTF ("big total sectors %d\n",
  102. __le32_to_cpu (boot -> bigsect));
  103. PRINTF ("physical drive ? %d\n",
  104. boot -> physdrive);
  105. PRINTF ("reserved %d\n",
  106. boot -> reserved);
  107. PRINTF ("dos > 4.0 diskette %d\n",
  108. boot -> dos4);
  109. PRINTF ("serial number %d\n",
  110. __le32_to_cpu (boot -> serial));
  111. PRINTF ("disk label %*.*s\n",
  112. LABEL_LG, LABEL_LG, boot -> label);
  113. PRINTF ("FAT type %8.8s\n",
  114. boot -> fat_type);
  115. PRINTF ("reserved by 2M %d\n",
  116. boot -> res_2m);
  117. PRINTF ("2M checksum (not used) %d\n",
  118. boot -> CheckSum);
  119. PRINTF ("2MF format version %d\n",
  120. boot -> fmt_2mf);
  121. PRINTF ("1 if write track after format %d\n",
  122. boot -> wt);
  123. PRINTF ("data transfer rate on track 0 %d\n",
  124. boot -> rate_0);
  125. PRINTF ("data transfer rate on track<>0 %d\n",
  126. boot -> rate_any);
  127. PRINTF ("offset to boot program %d\n",
  128. __le16_to_cpu (boot -> BootP));
  129. PRINTF ("T1: information for track 0 %d\n",
  130. __le16_to_cpu (boot -> Infp0));
  131. PRINTF ("T2: information for track<>0 %d\n",
  132. __le16_to_cpu (boot -> InfpX));
  133. PRINTF ("T3: track sectors size table %d\n",
  134. __le16_to_cpu (boot -> InfTm));
  135. PRINTF ("Format date 0x%04x\n",
  136. __le16_to_cpu (boot -> DateF));
  137. PRINTF ("Format time 0x%04x\n",
  138. __le16_to_cpu (boot -> TimeF));
  139. /* informations are extracted from boot sector */
  140. heads = __le16_to_cpu (boot -> nheads);
  141. sectors = __le16_to_cpu (boot -> nsect);
  142. fs -> tot_sectors = __le32_to_cpu (boot -> bigsect);
  143. if (__le16_to_cpu (boot -> psect) != 0) {
  144. fs -> tot_sectors = __le16_to_cpu (boot -> psect);
  145. }
  146. sect_per_track = heads * sectors;
  147. tracks = (fs -> tot_sectors + sect_per_track - 1) / sect_per_track;
  148. BootP = __le16_to_cpu (boot -> BootP);
  149. Infp0 = __le16_to_cpu (boot -> Infp0);
  150. InfpX = __le16_to_cpu (boot -> InfpX);
  151. InfTm = __le16_to_cpu (boot -> InfTm);
  152. if (boot -> dos4 == EXTENDED_BOOT &&
  153. strncmp( boot->banner,"2M", 2 ) == 0 &&
  154. BootP < SZ_STD_SECTOR &&
  155. Infp0 < SZ_STD_SECTOR &&
  156. InfpX < SZ_STD_SECTOR &&
  157. InfTm < SZ_STD_SECTOR &&
  158. BootP >= InfTm + 2 &&
  159. InfTm >= InfpX &&
  160. InfpX >= Infp0 &&
  161. Infp0 >= 76 ) {
  162. return (-1);
  163. }
  164. if (heads != NB_HEADS ||
  165. tracks != NB_TRACKS ||
  166. sectors != NB_SECTORS ||
  167. __le16_to_cpu (boot -> secsiz) != SZ_STD_SECTOR ||
  168. fs -> tot_sectors == 0 ||
  169. (fs -> tot_sectors % sectors) != 0) {
  170. return (-1);
  171. }
  172. return (0);
  173. }
  174. #endif