3 * Stäubli Faverges - <www.staubli.com>
6 * SPDX-License-Identifier: GPL-2.0+
22 /*-----------------------------------------------------------------------------
24 *-----------------------------------------------------------------------------
32 /*-----------------------------------------------------------------------------
33 * dev_read -- len and where are sectors number
34 *-----------------------------------------------------------------------------
36 int dev_read (void *buffer, int where, int len)
38 PRINTF ("dev_read (len = %d, where = %d)\n", len, where);
40 /* Si on ne desire pas lire a la position courante, il faut un seek */
41 if (where != lastwhere) {
42 if (!fdc_fdos_seek (where)) {
43 PRINTF ("seek error in dev_read");
49 if (!fdc_fdos_read (buffer, len)) {
50 PRINTF ("read error\n");
54 lastwhere = where + len;
57 /*-----------------------------------------------------------------------------
58 * check_dev -- verify the diskette format
59 *-----------------------------------------------------------------------------
61 int check_dev (BootSector_t *boot, Fs_t *fs)
63 unsigned int heads, sectors, tracks;
64 int BootP, Infp0, InfpX, InfTm;
67 /* Display Boot header */
68 PRINTF ("Jump to boot code 0x%02x 0x%02x 0x%02x\n",
69 boot -> jump [0], boot -> jump [1], boot -> jump[2]);
70 PRINTF ("OEM name & version '%*.*s'\n",
71 BANNER_LG, BANNER_LG, boot -> banner );
72 PRINTF ("Bytes per sector hopefully 512 %d\n",
73 __le16_to_cpu (boot -> secsiz));
74 PRINTF ("Cluster size in sectors %d\n",
76 PRINTF ("Number of reserved (boot) sectors %d\n",
77 __le16_to_cpu (boot -> nrsvsect));
78 PRINTF ("Number of FAT tables hopefully 2 %d\n",
80 PRINTF ("Number of directory slots %d\n",
81 __le16_to_cpu (boot -> dirents));
82 PRINTF ("Total sectors on disk %d\n",
83 __le16_to_cpu (boot -> psect));
84 PRINTF ("Media descriptor=first byte of FAT %d\n",
86 PRINTF ("Sectors in FAT %d\n",
87 __le16_to_cpu (boot -> fatlen));
88 PRINTF ("Sectors/track %d\n",
89 __le16_to_cpu (boot -> nsect));
91 __le16_to_cpu (boot -> nheads));
92 PRINTF ("number of hidden sectors %d\n",
93 __le32_to_cpu (boot -> nhs));
94 PRINTF ("big total sectors %d\n",
95 __le32_to_cpu (boot -> bigsect));
96 PRINTF ("physical drive ? %d\n",
98 PRINTF ("reserved %d\n",
100 PRINTF ("dos > 4.0 diskette %d\n",
102 PRINTF ("serial number %d\n",
103 __le32_to_cpu (boot -> serial));
104 PRINTF ("disk label %*.*s\n",
105 LABEL_LG, LABEL_LG, boot -> label);
106 PRINTF ("FAT type %8.8s\n",
108 PRINTF ("reserved by 2M %d\n",
110 PRINTF ("2M checksum (not used) %d\n",
112 PRINTF ("2MF format version %d\n",
114 PRINTF ("1 if write track after format %d\n",
116 PRINTF ("data transfer rate on track 0 %d\n",
118 PRINTF ("data transfer rate on track<>0 %d\n",
120 PRINTF ("offset to boot program %d\n",
121 __le16_to_cpu (boot -> BootP));
122 PRINTF ("T1: information for track 0 %d\n",
123 __le16_to_cpu (boot -> Infp0));
124 PRINTF ("T2: information for track<>0 %d\n",
125 __le16_to_cpu (boot -> InfpX));
126 PRINTF ("T3: track sectors size table %d\n",
127 __le16_to_cpu (boot -> InfTm));
128 PRINTF ("Format date 0x%04x\n",
129 __le16_to_cpu (boot -> DateF));
130 PRINTF ("Format time 0x%04x\n",
131 __le16_to_cpu (boot -> TimeF));
134 /* information is extracted from boot sector */
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) {
139 fs -> tot_sectors = __le16_to_cpu (boot -> psect);
142 sect_per_track = heads * sectors;
143 tracks = (fs -> tot_sectors + sect_per_track - 1) / sect_per_track;
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);
150 if (boot -> dos4 == EXTENDED_BOOT &&
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 &&
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) {