2002-11-18 00:14:45 +00:00
|
|
|
|
/*
|
|
|
|
|
* (C) Copyright 2002
|
|
|
|
|
* St<EFBFBD>ubli Faverges - <www.staubli.com>
|
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_FDOS)
|
|
|
|
|
|
|
|
|
|
#define NB_HEADS 2
|
|
|
|
|
#define NB_TRACKS 80
|
|
|
|
|
#define NB_SECTORS 18
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int lastwhere;
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
2003-06-27 21:31:46 +00:00
|
|
|
|
* dev_open --
|
2002-11-18 00:14:45 +00:00
|
|
|
|
*-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
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)\n", len, where);
|
|
|
|
|
|
|
|
|
|
/* Si on ne desire pas lire a la position courante, il faut un seek */
|
|
|
|
|
if (where != lastwhere) {
|
2003-06-27 21:31:46 +00:00
|
|
|
|
if (!fdc_fdos_seek (where)) {
|
|
|
|
|
PRINTF ("seek error in dev_read");
|
|
|
|
|
lastwhere = -1;
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
2002-11-18 00:14:45 +00:00
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2002-11-18 00:14:45 +00:00
|
|
|
|
if (!fdc_fdos_read (buffer, len)) {
|
2003-06-27 21:31:46 +00:00
|
|
|
|
PRINTF ("read error\n");
|
|
|
|
|
lastwhere = -1;
|
|
|
|
|
return (-1);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
}
|
|
|
|
|
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\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> jump [0], boot -> jump [1], boot -> jump[2]);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("OEM name & version '%*.*s'\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
BANNER_LG, BANNER_LG, boot -> banner );
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("Bytes per sector hopefully 512 %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le16_to_cpu (boot -> secsiz));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("Cluster size in sectors %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> clsiz);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("Number of reserved (boot) sectors %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le16_to_cpu (boot -> nrsvsect));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("Number of FAT tables hopefully 2 %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> nfat);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("Number of directory slots %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le16_to_cpu (boot -> dirents));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("Total sectors on disk %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le16_to_cpu (boot -> psect));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("Media descriptor=first byte of FAT %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> descr);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("Sectors in FAT %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le16_to_cpu (boot -> fatlen));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("Sectors/track %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le16_to_cpu (boot -> nsect));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("Heads %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le16_to_cpu (boot -> nheads));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("number of hidden sectors %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le32_to_cpu (boot -> nhs));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("big total sectors %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le32_to_cpu (boot -> bigsect));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("physical drive ? %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> physdrive);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("reserved %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> reserved);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("dos > 4.0 diskette %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> dos4);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("serial number %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le32_to_cpu (boot -> serial));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("disk label %*.*s\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
LABEL_LG, LABEL_LG, boot -> label);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("FAT type %8.8s\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> fat_type);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("reserved by 2M %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> res_2m);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("2M checksum (not used) %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> CheckSum);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("2MF format version %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> fmt_2mf);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("1 if write track after format %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> wt);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("data transfer rate on track 0 %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> rate_0);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("data transfer rate on track<>0 %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
boot -> rate_any);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("offset to boot program %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le16_to_cpu (boot -> BootP));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("T1: information for track 0 %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le16_to_cpu (boot -> Infp0));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("T2: information for track<>0 %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le16_to_cpu (boot -> InfpX));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("T3: track sectors size table %d\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le16_to_cpu (boot -> InfTm));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("Format date 0x%04x\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le16_to_cpu (boot -> DateF));
|
2002-11-18 00:14:45 +00:00
|
|
|
|
PRINTF ("Format time 0x%04x\n",
|
2003-06-27 21:31:46 +00:00
|
|
|
|
__le16_to_cpu (boot -> TimeF));
|
|
|
|
|
|
2002-11-18 00:14:45 +00:00
|
|
|
|
|
2003-03-06 13:39:27 +00:00
|
|
|
|
/* information is extracted from boot sector */
|
2002-11-18 00:14:45 +00:00
|
|
|
|
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) {
|
2003-06-27 21:31:46 +00:00
|
|
|
|
fs -> tot_sectors = __le16_to_cpu (boot -> psect);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2002-11-18 00:14:45 +00:00
|
|
|
|
sect_per_track = heads * sectors;
|
|
|
|
|
tracks = (fs -> tot_sectors + sect_per_track - 1) / sect_per_track;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2002-11-18 00:14:45 +00:00
|
|
|
|
BootP = __le16_to_cpu (boot -> BootP);
|
|
|
|
|
Infp0 = __le16_to_cpu (boot -> Infp0);
|
|
|
|
|
InfpX = __le16_to_cpu (boot -> InfpX);
|
|
|
|
|
InfTm = __le16_to_cpu (boot -> InfTm);
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2002-11-18 00:14:45 +00:00
|
|
|
|
if (boot -> dos4 == EXTENDED_BOOT &&
|
2003-06-27 21:31:46 +00:00
|
|
|
|
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);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (heads != NB_HEADS ||
|
2003-06-27 21:31:46 +00:00
|
|
|
|
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);
|
2002-11-18 00:14:45 +00:00
|
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
|
2002-11-18 00:14:45 +00:00
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|