3 * Stäubli Faverges - <www.staubli.com>
4 * Pierre AUBERT p.aubert@staubli.com
6 * See file CREDITS for list of people who contributed to this
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.
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.
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,
31 #if defined(CONFIG_CMD_FDOS)
40 /*-----------------------------------------------------------------------------
42 *-----------------------------------------------------------------------------
50 /*-----------------------------------------------------------------------------
51 * dev_read -- len and where are sectors number
52 *-----------------------------------------------------------------------------
54 int dev_read (void *buffer, int where, int len)
56 PRINTF ("dev_read (len = %d, where = %d)\n", len, where);
58 /* Si on ne desire pas lire a la position courante, il faut un seek */
59 if (where != lastwhere) {
60 if (!fdc_fdos_seek (where)) {
61 PRINTF ("seek error in dev_read");
67 if (!fdc_fdos_read (buffer, len)) {
68 PRINTF ("read error\n");
72 lastwhere = where + len;
75 /*-----------------------------------------------------------------------------
76 * check_dev -- verify the diskette format
77 *-----------------------------------------------------------------------------
79 int check_dev (BootSector_t *boot, Fs_t *fs)
81 unsigned int heads, sectors, tracks;
82 int BootP, Infp0, InfpX, InfTm;
85 /* Display Boot header */
86 PRINTF ("Jump to boot code 0x%02x 0x%02x 0x%02x\n",
87 boot -> jump [0], boot -> jump [1], boot -> jump[2]);
88 PRINTF ("OEM name & version '%*.*s'\n",
89 BANNER_LG, BANNER_LG, boot -> banner );
90 PRINTF ("Bytes per sector hopefully 512 %d\n",
91 __le16_to_cpu (boot -> secsiz));
92 PRINTF ("Cluster size in sectors %d\n",
94 PRINTF ("Number of reserved (boot) sectors %d\n",
95 __le16_to_cpu (boot -> nrsvsect));
96 PRINTF ("Number of FAT tables hopefully 2 %d\n",
98 PRINTF ("Number of directory slots %d\n",
99 __le16_to_cpu (boot -> dirents));
100 PRINTF ("Total sectors on disk %d\n",
101 __le16_to_cpu (boot -> psect));
102 PRINTF ("Media descriptor=first byte of FAT %d\n",
104 PRINTF ("Sectors in FAT %d\n",
105 __le16_to_cpu (boot -> fatlen));
106 PRINTF ("Sectors/track %d\n",
107 __le16_to_cpu (boot -> nsect));
108 PRINTF ("Heads %d\n",
109 __le16_to_cpu (boot -> nheads));
110 PRINTF ("number of hidden sectors %d\n",
111 __le32_to_cpu (boot -> nhs));
112 PRINTF ("big total sectors %d\n",
113 __le32_to_cpu (boot -> bigsect));
114 PRINTF ("physical drive ? %d\n",
116 PRINTF ("reserved %d\n",
118 PRINTF ("dos > 4.0 diskette %d\n",
120 PRINTF ("serial number %d\n",
121 __le32_to_cpu (boot -> serial));
122 PRINTF ("disk label %*.*s\n",
123 LABEL_LG, LABEL_LG, boot -> label);
124 PRINTF ("FAT type %8.8s\n",
126 PRINTF ("reserved by 2M %d\n",
128 PRINTF ("2M checksum (not used) %d\n",
130 PRINTF ("2MF format version %d\n",
132 PRINTF ("1 if write track after format %d\n",
134 PRINTF ("data transfer rate on track 0 %d\n",
136 PRINTF ("data transfer rate on track<>0 %d\n",
138 PRINTF ("offset to boot program %d\n",
139 __le16_to_cpu (boot -> BootP));
140 PRINTF ("T1: information for track 0 %d\n",
141 __le16_to_cpu (boot -> Infp0));
142 PRINTF ("T2: information for track<>0 %d\n",
143 __le16_to_cpu (boot -> InfpX));
144 PRINTF ("T3: track sectors size table %d\n",
145 __le16_to_cpu (boot -> InfTm));
146 PRINTF ("Format date 0x%04x\n",
147 __le16_to_cpu (boot -> DateF));
148 PRINTF ("Format time 0x%04x\n",
149 __le16_to_cpu (boot -> TimeF));
152 /* information is extracted from boot sector */
153 heads = __le16_to_cpu (boot -> nheads);
154 sectors = __le16_to_cpu (boot -> nsect);
155 fs -> tot_sectors = __le32_to_cpu (boot -> bigsect);
156 if (__le16_to_cpu (boot -> psect) != 0) {
157 fs -> tot_sectors = __le16_to_cpu (boot -> psect);
160 sect_per_track = heads * sectors;
161 tracks = (fs -> tot_sectors + sect_per_track - 1) / sect_per_track;
163 BootP = __le16_to_cpu (boot -> BootP);
164 Infp0 = __le16_to_cpu (boot -> Infp0);
165 InfpX = __le16_to_cpu (boot -> InfpX);
166 InfTm = __le16_to_cpu (boot -> InfTm);
168 if (boot -> dos4 == EXTENDED_BOOT &&
169 strncmp( boot->banner,"2M", 2 ) == 0 &&
170 BootP < SZ_STD_SECTOR &&
171 Infp0 < SZ_STD_SECTOR &&
172 InfpX < SZ_STD_SECTOR &&
173 InfTm < SZ_STD_SECTOR &&
174 BootP >= InfTm + 2 &&
182 if (heads != NB_HEADS ||
183 tracks != NB_TRACKS ||
184 sectors != NB_SECTORS ||
185 __le16_to_cpu (boot -> secsiz) != SZ_STD_SECTOR ||
186 fs -> tot_sectors == 0 ||
187 (fs -> tot_sectors % sectors) != 0) {