2002-11-18 09:14:45 +09: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 <malloc.h>
|
|
|
|
|
|
2007-06-12 09:02:20 +09:00
|
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_FDOS) || defined(CONFIG_CMD_FDOS)
|
2002-11-18 09:14:45 +09:00
|
|
|
|
|
|
|
|
|
#include "dos.h"
|
|
|
|
|
#include "fdos.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
2003-06-28 06:31:46 +09:00
|
|
|
|
* fill_fs -- Read info on file system
|
2002-11-18 09:14:45 +09:00
|
|
|
|
*-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static int fill_fs (BootSector_t *boot, Fs_t *fs)
|
|
|
|
|
{
|
2003-06-28 06:31:46 +09:00
|
|
|
|
|
2002-11-18 09:14:45 +09:00
|
|
|
|
fs -> fat_start = __le16_to_cpu (boot -> nrsvsect);
|
|
|
|
|
fs -> fat_len = __le16_to_cpu (boot -> fatlen);
|
|
|
|
|
fs -> nb_fat = boot -> nfat;
|
2003-06-28 06:31:46 +09:00
|
|
|
|
|
2002-11-18 09:14:45 +09:00
|
|
|
|
fs -> dir_start = fs -> fat_start + fs -> nb_fat * fs -> fat_len;
|
|
|
|
|
fs -> dir_len = __le16_to_cpu (boot -> dirents) * MDIR_SIZE / SZ_STD_SECTOR;
|
|
|
|
|
fs -> cluster_size = boot -> clsiz;
|
|
|
|
|
fs -> num_clus = (fs -> tot_sectors - fs -> dir_start - fs -> dir_len) / fs -> cluster_size;
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
2003-06-28 06:31:46 +09:00
|
|
|
|
* fs_init --
|
2002-11-18 09:14:45 +09:00
|
|
|
|
*-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
int fs_init (Fs_t *fs)
|
|
|
|
|
{
|
|
|
|
|
BootSector_t *boot;
|
|
|
|
|
|
|
|
|
|
/* Initialize physical device */
|
|
|
|
|
if (dev_open () < 0) {
|
2003-06-28 06:31:46 +09:00
|
|
|
|
PRINTF ("Unable to initialize the fdc\n");
|
|
|
|
|
return (-1);
|
2002-11-18 09:14:45 +09:00
|
|
|
|
}
|
|
|
|
|
init_subdir ();
|
2003-06-28 06:31:46 +09:00
|
|
|
|
|
2002-11-18 09:14:45 +09:00
|
|
|
|
/* Allocate space for read the boot sector */
|
|
|
|
|
if ((boot = (BootSector_t *)malloc (sizeof (BootSector_t))) == NULL) {
|
2003-06-28 06:31:46 +09:00
|
|
|
|
PRINTF ("Unable to allocate space for boot sector\n");
|
|
|
|
|
return (-1);
|
2002-11-18 09:14:45 +09:00
|
|
|
|
}
|
2003-06-28 06:31:46 +09:00
|
|
|
|
|
2002-11-18 09:14:45 +09:00
|
|
|
|
/* read boot sector */
|
|
|
|
|
if (dev_read (boot, 0, 1)){
|
2003-06-28 06:31:46 +09:00
|
|
|
|
PRINTF ("Error during boot sector read\n");
|
|
|
|
|
free (boot);
|
|
|
|
|
return (-1);
|
2002-11-18 09:14:45 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* we verify it'a a DOS diskette */
|
|
|
|
|
if (boot -> jump [0] != JUMP_0_1 && boot -> jump [0] != JUMP_0_2) {
|
2003-06-28 06:31:46 +09:00
|
|
|
|
PRINTF ("Not a DOS diskette\n");
|
|
|
|
|
free (boot);
|
|
|
|
|
return (-1);
|
2002-11-18 09:14:45 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (boot -> descr < MEDIA_STD) {
|
2003-06-28 06:31:46 +09:00
|
|
|
|
/* We handle only recent medias (type F0) */
|
|
|
|
|
PRINTF ("unrecognized diskette type\n");
|
|
|
|
|
free (boot);
|
|
|
|
|
return (-1);
|
2002-11-18 09:14:45 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (check_dev (boot, fs) < 0) {
|
2003-06-28 06:31:46 +09:00
|
|
|
|
PRINTF ("Bad diskette\n");
|
|
|
|
|
free (boot);
|
|
|
|
|
return (-1);
|
2002-11-18 09:14:45 +09:00
|
|
|
|
}
|
2003-06-28 06:31:46 +09:00
|
|
|
|
|
2002-11-18 09:14:45 +09:00
|
|
|
|
if (fill_fs (boot, fs) < 0) {
|
2003-06-28 06:31:46 +09:00
|
|
|
|
free (boot);
|
2002-11-18 09:14:45 +09:00
|
|
|
|
|
2003-06-28 06:31:46 +09:00
|
|
|
|
return (-1);
|
2002-11-18 09:14:45 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read FAT */
|
|
|
|
|
if (read_fat (boot, fs) < 0) {
|
2003-06-28 06:31:46 +09:00
|
|
|
|
free (boot);
|
|
|
|
|
return (-1);
|
2002-11-18 09:14:45 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free (boot);
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|