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