blob: f21c7a93d37af3b9aa5c998e5fb0801dc93b9866 [file] [log] [blame]
wdenk591dda52002-11-18 00:14:45 +00001/*
2 * (C) Copyright 2002
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +02003 * Stäubli Faverges - <www.staubli.com>
wdenk591dda52002-11-18 00:14:45 +00004 * 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
25#include <common.h>
26#include <config.h>
27
28#include "dos.h"
29#include "fdos.h"
30
wdenk591dda52002-11-18 00:14:45 +000031#define NB_HEADS 2
32#define NB_TRACKS 80
33#define NB_SECTORS 18
34
35
36static int lastwhere;
37
38/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +000039 * dev_open --
wdenk591dda52002-11-18 00:14:45 +000040 *-----------------------------------------------------------------------------
41 */
42int dev_open (void)
43{
44 lastwhere = 0;
45 return (0);
46}
47
48/*-----------------------------------------------------------------------------
49 * dev_read -- len and where are sectors number
50 *-----------------------------------------------------------------------------
51 */
52int dev_read (void *buffer, int where, int len)
53{
54 PRINTF ("dev_read (len = %d, where = %d)\n", len, where);
55
56 /* Si on ne desire pas lire a la position courante, il faut un seek */
57 if (where != lastwhere) {
wdenk57b2d802003-06-27 21:31:46 +000058 if (!fdc_fdos_seek (where)) {
59 PRINTF ("seek error in dev_read");
60 lastwhere = -1;
61 return (-1);
62 }
wdenk591dda52002-11-18 00:14:45 +000063 }
wdenk57b2d802003-06-27 21:31:46 +000064
wdenk591dda52002-11-18 00:14:45 +000065 if (!fdc_fdos_read (buffer, len)) {
wdenk57b2d802003-06-27 21:31:46 +000066 PRINTF ("read error\n");
67 lastwhere = -1;
68 return (-1);
wdenk591dda52002-11-18 00:14:45 +000069 }
70 lastwhere = where + len;
71 return (0);
72}
73/*-----------------------------------------------------------------------------
74 * check_dev -- verify the diskette format
75 *-----------------------------------------------------------------------------
76 */
77int check_dev (BootSector_t *boot, Fs_t *fs)
78{
79 unsigned int heads, sectors, tracks;
80 int BootP, Infp0, InfpX, InfTm;
81 int sect_per_track;
82
83 /* Display Boot header */
84 PRINTF ("Jump to boot code 0x%02x 0x%02x 0x%02x\n",
wdenk57b2d802003-06-27 21:31:46 +000085 boot -> jump [0], boot -> jump [1], boot -> jump[2]);
wdenk591dda52002-11-18 00:14:45 +000086 PRINTF ("OEM name & version '%*.*s'\n",
wdenk57b2d802003-06-27 21:31:46 +000087 BANNER_LG, BANNER_LG, boot -> banner );
wdenk591dda52002-11-18 00:14:45 +000088 PRINTF ("Bytes per sector hopefully 512 %d\n",
wdenk57b2d802003-06-27 21:31:46 +000089 __le16_to_cpu (boot -> secsiz));
wdenk591dda52002-11-18 00:14:45 +000090 PRINTF ("Cluster size in sectors %d\n",
wdenk57b2d802003-06-27 21:31:46 +000091 boot -> clsiz);
wdenk591dda52002-11-18 00:14:45 +000092 PRINTF ("Number of reserved (boot) sectors %d\n",
wdenk57b2d802003-06-27 21:31:46 +000093 __le16_to_cpu (boot -> nrsvsect));
wdenk591dda52002-11-18 00:14:45 +000094 PRINTF ("Number of FAT tables hopefully 2 %d\n",
wdenk57b2d802003-06-27 21:31:46 +000095 boot -> nfat);
wdenk591dda52002-11-18 00:14:45 +000096 PRINTF ("Number of directory slots %d\n",
wdenk57b2d802003-06-27 21:31:46 +000097 __le16_to_cpu (boot -> dirents));
wdenk591dda52002-11-18 00:14:45 +000098 PRINTF ("Total sectors on disk %d\n",
wdenk57b2d802003-06-27 21:31:46 +000099 __le16_to_cpu (boot -> psect));
wdenk591dda52002-11-18 00:14:45 +0000100 PRINTF ("Media descriptor=first byte of FAT %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000101 boot -> descr);
wdenk591dda52002-11-18 00:14:45 +0000102 PRINTF ("Sectors in FAT %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000103 __le16_to_cpu (boot -> fatlen));
wdenk591dda52002-11-18 00:14:45 +0000104 PRINTF ("Sectors/track %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000105 __le16_to_cpu (boot -> nsect));
wdenk591dda52002-11-18 00:14:45 +0000106 PRINTF ("Heads %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000107 __le16_to_cpu (boot -> nheads));
wdenk591dda52002-11-18 00:14:45 +0000108 PRINTF ("number of hidden sectors %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000109 __le32_to_cpu (boot -> nhs));
wdenk591dda52002-11-18 00:14:45 +0000110 PRINTF ("big total sectors %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000111 __le32_to_cpu (boot -> bigsect));
wdenk591dda52002-11-18 00:14:45 +0000112 PRINTF ("physical drive ? %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000113 boot -> physdrive);
wdenk591dda52002-11-18 00:14:45 +0000114 PRINTF ("reserved %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000115 boot -> reserved);
wdenk591dda52002-11-18 00:14:45 +0000116 PRINTF ("dos > 4.0 diskette %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000117 boot -> dos4);
wdenk591dda52002-11-18 00:14:45 +0000118 PRINTF ("serial number %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000119 __le32_to_cpu (boot -> serial));
wdenk591dda52002-11-18 00:14:45 +0000120 PRINTF ("disk label %*.*s\n",
wdenk57b2d802003-06-27 21:31:46 +0000121 LABEL_LG, LABEL_LG, boot -> label);
wdenk591dda52002-11-18 00:14:45 +0000122 PRINTF ("FAT type %8.8s\n",
wdenk57b2d802003-06-27 21:31:46 +0000123 boot -> fat_type);
wdenk591dda52002-11-18 00:14:45 +0000124 PRINTF ("reserved by 2M %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000125 boot -> res_2m);
wdenk591dda52002-11-18 00:14:45 +0000126 PRINTF ("2M checksum (not used) %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000127 boot -> CheckSum);
wdenk591dda52002-11-18 00:14:45 +0000128 PRINTF ("2MF format version %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000129 boot -> fmt_2mf);
wdenk591dda52002-11-18 00:14:45 +0000130 PRINTF ("1 if write track after format %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000131 boot -> wt);
wdenk591dda52002-11-18 00:14:45 +0000132 PRINTF ("data transfer rate on track 0 %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000133 boot -> rate_0);
wdenk591dda52002-11-18 00:14:45 +0000134 PRINTF ("data transfer rate on track<>0 %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000135 boot -> rate_any);
wdenk591dda52002-11-18 00:14:45 +0000136 PRINTF ("offset to boot program %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000137 __le16_to_cpu (boot -> BootP));
wdenk591dda52002-11-18 00:14:45 +0000138 PRINTF ("T1: information for track 0 %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000139 __le16_to_cpu (boot -> Infp0));
wdenk591dda52002-11-18 00:14:45 +0000140 PRINTF ("T2: information for track<>0 %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000141 __le16_to_cpu (boot -> InfpX));
wdenk591dda52002-11-18 00:14:45 +0000142 PRINTF ("T3: track sectors size table %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000143 __le16_to_cpu (boot -> InfTm));
wdenk591dda52002-11-18 00:14:45 +0000144 PRINTF ("Format date 0x%04x\n",
wdenk57b2d802003-06-27 21:31:46 +0000145 __le16_to_cpu (boot -> DateF));
wdenk591dda52002-11-18 00:14:45 +0000146 PRINTF ("Format time 0x%04x\n",
wdenk57b2d802003-06-27 21:31:46 +0000147 __le16_to_cpu (boot -> TimeF));
148
wdenk591dda52002-11-18 00:14:45 +0000149
wdenkcc1e2562003-03-06 13:39:27 +0000150 /* information is extracted from boot sector */
wdenk591dda52002-11-18 00:14:45 +0000151 heads = __le16_to_cpu (boot -> nheads);
152 sectors = __le16_to_cpu (boot -> nsect);
153 fs -> tot_sectors = __le32_to_cpu (boot -> bigsect);
154 if (__le16_to_cpu (boot -> psect) != 0) {
wdenk57b2d802003-06-27 21:31:46 +0000155 fs -> tot_sectors = __le16_to_cpu (boot -> psect);
wdenk591dda52002-11-18 00:14:45 +0000156 }
wdenk57b2d802003-06-27 21:31:46 +0000157
wdenk591dda52002-11-18 00:14:45 +0000158 sect_per_track = heads * sectors;
159 tracks = (fs -> tot_sectors + sect_per_track - 1) / sect_per_track;
wdenk57b2d802003-06-27 21:31:46 +0000160
wdenk591dda52002-11-18 00:14:45 +0000161 BootP = __le16_to_cpu (boot -> BootP);
162 Infp0 = __le16_to_cpu (boot -> Infp0);
163 InfpX = __le16_to_cpu (boot -> InfpX);
164 InfTm = __le16_to_cpu (boot -> InfTm);
wdenk57b2d802003-06-27 21:31:46 +0000165
wdenk591dda52002-11-18 00:14:45 +0000166 if (boot -> dos4 == EXTENDED_BOOT &&
wdenk57b2d802003-06-27 21:31:46 +0000167 strncmp( boot->banner,"2M", 2 ) == 0 &&
168 BootP < SZ_STD_SECTOR &&
169 Infp0 < SZ_STD_SECTOR &&
170 InfpX < SZ_STD_SECTOR &&
171 InfTm < SZ_STD_SECTOR &&
172 BootP >= InfTm + 2 &&
173 InfTm >= InfpX &&
174 InfpX >= Infp0 &&
175 Infp0 >= 76 ) {
wdenk591dda52002-11-18 00:14:45 +0000176
wdenk57b2d802003-06-27 21:31:46 +0000177 return (-1);
wdenk591dda52002-11-18 00:14:45 +0000178 }
179
180 if (heads != NB_HEADS ||
wdenk57b2d802003-06-27 21:31:46 +0000181 tracks != NB_TRACKS ||
182 sectors != NB_SECTORS ||
183 __le16_to_cpu (boot -> secsiz) != SZ_STD_SECTOR ||
184 fs -> tot_sectors == 0 ||
185 (fs -> tot_sectors % sectors) != 0) {
186 return (-1);
wdenk591dda52002-11-18 00:14:45 +0000187 }
wdenk57b2d802003-06-27 21:31:46 +0000188
wdenk591dda52002-11-18 00:14:45 +0000189 return (0);
190}