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