2001-07-10 00:19:33 +02:00
|
|
|
/****************************************************************/
|
|
|
|
/* */
|
|
|
|
/* initDISK.c */
|
|
|
|
/* */
|
|
|
|
/* Copyright (c) 2001 */
|
|
|
|
/* tom ehlert */
|
|
|
|
/* All Rights Reserved */
|
|
|
|
/* */
|
|
|
|
/* This file is part of DOS-C. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C 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, or (at your option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C 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 DOS-C; see the file COPYING. If not, */
|
|
|
|
/* write to the Free Software Foundation, 675 Mass Ave, */
|
|
|
|
/* Cambridge, MA 02139, USA. */
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
#include "portab.h"
|
|
|
|
#include "init-mod.h"
|
|
|
|
#include "dyndata.h"
|
|
|
|
#ifdef VERSION_STRINGS
|
2001-11-18 15:01:12 +01:00
|
|
|
static BYTE *dskRcsId =
|
|
|
|
"$Id$";
|
2001-07-10 00:19:33 +02:00
|
|
|
#endif
|
|
|
|
|
2004-04-14 01:46:25 +02:00
|
|
|
UBYTE InitDiskTransferBuffer[SEC_SIZE] BSS_INIT({0});
|
|
|
|
COUNT nUnits BSS_INIT(0);
|
2003-06-15 20:40:03 +02:00
|
|
|
|
2001-07-10 00:19:33 +02:00
|
|
|
/*
|
|
|
|
* Rev 1.0 13 May 2001 tom ehlert
|
|
|
|
* Initial revision.
|
|
|
|
*
|
|
|
|
* this module implements the disk scanning for DOS accesible partitions
|
|
|
|
* the drive letter ordering is somewhat chaotic, but like MSDOS does it.
|
|
|
|
*
|
|
|
|
* this module expects to run with CS = INIT_TEXT, like other init_code,
|
|
|
|
* but SS = DS = DATA = DOS_DS, unlike other init_code.
|
|
|
|
*
|
|
|
|
* history:
|
|
|
|
* 1.0 extracted the disk init code from DSK.C
|
|
|
|
* added LBA support
|
|
|
|
* moved code to INIT_TEXT
|
|
|
|
* done the funny code segment stuff to switch between INIT_TEXT and TEXT
|
|
|
|
* added a couple of snity checks for partitions
|
|
|
|
*
|
|
|
|
****************************************************************************
|
|
|
|
*
|
|
|
|
* Implementation note:
|
|
|
|
* this module needs some interfacing to INT 13
|
|
|
|
* how to implement them
|
|
|
|
*
|
|
|
|
* a) using inline assembly
|
|
|
|
* _ASM mov ax,0x1314
|
|
|
|
*
|
|
|
|
* b) using assembly routines in some external FLOPPY.ASM
|
|
|
|
*
|
|
|
|
* c) using the funny TURBO-C style
|
|
|
|
* _AX = 0x1314
|
|
|
|
*
|
|
|
|
* d) using intr(intno, ®s) method.
|
|
|
|
*
|
|
|
|
* whynot's
|
|
|
|
*
|
|
|
|
* a) this is my personal favorite, combining the best aof all worlds.
|
|
|
|
* TURBO-C does support inline assembly, but only by using TASM,
|
|
|
|
* which is not free.
|
|
|
|
* so - unfortunately- its excluded.
|
|
|
|
*
|
|
|
|
* b) keeping funny memory model in sync with external assembly
|
|
|
|
* routines is everything, but not fun
|
|
|
|
*
|
|
|
|
* c) you never know EXACT, what the compiler does, if its a bit
|
|
|
|
* more complicated. does
|
|
|
|
* _DL = drive & 0xff
|
|
|
|
* _BL = driveParam.chs.Sector;
|
|
|
|
* destroy any other register? sure? _really_ sure?
|
|
|
|
* at least, it has it's surprises.
|
|
|
|
* and - I found a couple of optimizer induced bugs (TC 2.01)
|
|
|
|
* believe me.
|
|
|
|
* it was coded - and operational that way.
|
|
|
|
* but - there are many surprises waiting there. so I opted against.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* d) this method is somewhat clumsy and certainly not the
|
|
|
|
* fastest way to do things.
|
|
|
|
* on the other hand, this is INIT code, executed once.
|
|
|
|
* and scince it's the only portable method, I opted for it.
|
|
|
|
*
|
|
|
|
* e) and all this is my private opinion. tom ehlert.
|
|
|
|
*
|
2001-11-14 00:36:45 +01:00
|
|
|
*
|
|
|
|
* Some thoughts about LBA vs. CHS. by Bart Oldeman 2001/Nov/11
|
|
|
|
* Matthias Paul writes in www.freedos.org/freedos/news/technote/113.html:
|
|
|
|
* (...) MS-DOS 7.10+, which will always access logical drives in a type
|
|
|
|
* 05h extended partition via CHS, even if the individual logical drives
|
|
|
|
* in there are of LBA type, or go beyond 8 Gb... (Although this workaround
|
|
|
|
* is sometimes used in conjunction with OS/2, using a 05h partition going
|
|
|
|
* beyond 8 Gb may cause MS-DOS 7.10 to hang or corrupt your data...) (...)
|
|
|
|
*
|
|
|
|
* Also at http://www.win.tue.nl/~aeb/partitions/partition_types-1.html:
|
|
|
|
* (...) 5 DOS 3.3+ Extended Partition
|
|
|
|
* Supports at most 8.4 GB disks: with type 5 DOS/Windows will not use the
|
|
|
|
* extended BIOS call, even if it is available. (...)
|
|
|
|
*
|
|
|
|
* So MS-DOS 7.10+ is brain-dead in this respect, but we knew that ;-)
|
|
|
|
* However there is one reason to use old-style CHS calls:
|
|
|
|
* some programs intercept int 13 and do not support LBA addressing. So
|
|
|
|
* it is worth using CHS if possible, unless the user asks us not to,
|
|
|
|
* either by specifying a 0x0c/0x0e/0x0f partition type or enabling
|
|
|
|
* the ForceLBA setting in the fd kernel (sys) config. This will make
|
|
|
|
* multi-sector reads and BIOS computations more efficient, at the cost
|
|
|
|
* of some compatibility.
|
|
|
|
*
|
|
|
|
* However we need to be safe, and with varying CHS at different levels
|
|
|
|
* that might be difficult. Hence we _only_ trust the LBA values in the
|
|
|
|
* partition tables and the heads and sectors values the BIOS gives us.
|
|
|
|
* After all these are the values the BIOS uses to process our CHS values.
|
|
|
|
* So unless the BIOS is buggy, using CHS on one partition and LBA on another
|
|
|
|
* should be safe. The CHS values in the partition table are NOT trusted.
|
|
|
|
* We print a warning if there is a mismatch with the calculated values.
|
|
|
|
*
|
|
|
|
* The CHS values in the boot sector are used at a higher level. The CHS
|
|
|
|
* that DOS uses in various INT21/AH=44 IOCTL calls are converted to LBA
|
|
|
|
* using the boot sector values and then converted back to CHS using BIOS
|
|
|
|
* values if necessary. Internally we do LBA as much as possible.
|
|
|
|
*
|
|
|
|
* However if the partition extends beyond cylinder 1023 and is not labelled
|
|
|
|
* as one of the LBA types, we can't use CHS and print a warning, using LBA
|
|
|
|
* instead if possible, and otherwise refuse to use it.
|
|
|
|
*
|
|
|
|
* As for EXTENDED_LBA vs. EXTENDED, FreeDOS makes no difference. This is
|
|
|
|
* boot time - there is no reason not to use LBA for reading partition tables,
|
|
|
|
* and the MSDOS 7.10 behaviour is not desirable.
|
|
|
|
*
|
|
|
|
* Note: for floppies we need the boot sector values though and the boot sector
|
|
|
|
* code does not use LBA addressing yet.
|
|
|
|
*
|
|
|
|
* Conclusion: with all this implemented, FreeDOS should be able to gracefully
|
|
|
|
* handle and read foreign hard disks moved across computers, whether using
|
|
|
|
* CHS or LBA, strengthening its role as a rescue environment.
|
2001-07-10 00:19:33 +02:00
|
|
|
*/
|
|
|
|
|
2001-07-22 03:58:58 +02:00
|
|
|
/* #define DEBUG */
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
#define _BETA_ /* messages for initial phase only */
|
2001-07-10 00:19:33 +02:00
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2001-11-18 15:01:12 +01:00
|
|
|
#define DebugPrintf(x) printf x
|
2001-07-10 00:19:33 +02:00
|
|
|
#else
|
2001-11-18 15:01:12 +01:00
|
|
|
#define DebugPrintf(x)
|
2001-07-10 00:19:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_BETA_)
|
2001-11-18 15:01:12 +01:00
|
|
|
#define BetaPrintf(x) printf x
|
2001-07-10 00:19:33 +02:00
|
|
|
#else
|
2001-11-18 15:01:12 +01:00
|
|
|
#define BetaPrintf(x)
|
2001-07-10 00:19:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define LBA_to_CHS init_LBA_to_CHS
|
|
|
|
|
2001-07-22 03:58:58 +02:00
|
|
|
/*
|
|
|
|
interesting macros - used internally only
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SCAN_PRIMARYBOOT 0x00
|
|
|
|
#define SCAN_PRIMARY 0x01
|
|
|
|
#define SCAN_EXTENDED 0x02
|
|
|
|
#define SCAN_PRIMARY2 0x03
|
|
|
|
|
|
|
|
#define FAT12 0x01
|
|
|
|
#define FAT16SMALL 0x04
|
|
|
|
#define EXTENDED 0x05
|
|
|
|
#define FAT16LARGE 0x06
|
2001-11-18 15:01:12 +01:00
|
|
|
#define FAT32 0x0b /* FAT32 partition that ends before the 8.4 */
|
2001-07-22 03:58:58 +02:00
|
|
|
/* GB boundary */
|
2001-11-18 15:01:12 +01:00
|
|
|
#define FAT32_LBA 0x0c /* FAT32 partition that ends after the 8.4GB */
|
2001-07-22 03:58:58 +02:00
|
|
|
/* boundary. LBA is needed to access this. */
|
2001-11-18 15:01:12 +01:00
|
|
|
#define FAT16_LBA 0x0e /* like 0x06, but it is supposed to end past */
|
2001-07-22 03:58:58 +02:00
|
|
|
/* the 8.4GB boundary */
|
2001-11-18 15:01:12 +01:00
|
|
|
#define FAT12_LBA 0xff /* fake FAT12 LBA entry for internal use */
|
|
|
|
#define EXTENDED_LBA 0x0f /* like 0x05, but it is supposed to end past */
|
2001-07-22 03:58:58 +02:00
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
/* Let's play it safe and do not allow partitions with clusters above *
|
|
|
|
* or equal to 0xff0/0xfff0/0xffffff0 to be created *
|
|
|
|
* the problem with fff0-fff6 is that they might be interpreted as BAD *
|
|
|
|
* even though the standard BAD value is ...ff7 */
|
2001-11-18 15:01:12 +01:00
|
|
|
|
2002-12-09 01:17:15 +01:00
|
|
|
#define FAT12MAX (FAT_MAGIC-6)
|
|
|
|
#define FAT16MAX (FAT_MAGIC16-6)
|
|
|
|
#define FAT32MAX (FAT_MAGIC32-6)
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2001-07-22 03:58:58 +02:00
|
|
|
#define IsExtPartition(parttyp) ((parttyp) == EXTENDED || \
|
|
|
|
(parttyp) == EXTENDED_LBA )
|
|
|
|
|
2001-11-14 00:36:45 +01:00
|
|
|
#define IsLBAPartition(parttyp) ((parttyp) == FAT12_LBA || \
|
|
|
|
(parttyp) == FAT16_LBA || \
|
|
|
|
(parttyp) == FAT32_LBA)
|
|
|
|
|
2001-09-23 22:39:44 +02:00
|
|
|
#ifdef WITHFAT32
|
|
|
|
#define IsFATPartition(parttyp) ((parttyp) == FAT12 || \
|
|
|
|
(parttyp) == FAT16SMALL || \
|
|
|
|
(parttyp) == FAT16LARGE || \
|
|
|
|
(parttyp) == FAT16_LBA || \
|
|
|
|
(parttyp) == FAT32 || \
|
|
|
|
(parttyp) == FAT32_LBA)
|
|
|
|
#else
|
|
|
|
#define IsFATPartition(parttyp) ((parttyp) == FAT12 || \
|
|
|
|
(parttyp) == FAT16SMALL || \
|
|
|
|
(parttyp) == FAT16LARGE || \
|
|
|
|
(parttyp) == FAT16_LBA)
|
|
|
|
#endif
|
2001-07-22 03:58:58 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
#define MSDOS_EXT_SIGN 0x29 /* extended boot sector signature */
|
2001-07-22 03:58:58 +02:00
|
|
|
#define MSDOS_FAT12_SIGN "FAT12 " /* FAT12 filesystem signature */
|
|
|
|
#define MSDOS_FAT16_SIGN "FAT16 " /* FAT16 filesystem signature */
|
|
|
|
#define MSDOS_FAT32_SIGN "FAT32 " /* FAT32 filesystem signature */
|
|
|
|
|
|
|
|
/* local - returned and used for BIOS interface INT 13, AH=48*/
|
|
|
|
struct _bios_LBA_disk_parameterS {
|
2001-11-18 15:01:12 +01:00
|
|
|
UWORD size;
|
|
|
|
UWORD information;
|
|
|
|
ULONG cylinders;
|
|
|
|
ULONG heads;
|
|
|
|
ULONG sectors;
|
2001-07-22 03:58:58 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
ULONG totalSect;
|
|
|
|
ULONG totalSectHigh;
|
|
|
|
UWORD BytesPerSector;
|
2001-07-22 03:58:58 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
ULONG eddparameters;
|
|
|
|
};
|
2001-07-22 03:58:58 +02:00
|
|
|
|
|
|
|
/* physical characteristics of a drive */
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
struct DriveParamS {
|
|
|
|
UBYTE driveno; /* = 0x8x */
|
2004-04-13 12:54:33 +02:00
|
|
|
UWORD descflags;
|
2001-11-18 15:01:12 +01:00
|
|
|
ULONG total_sectors;
|
2001-07-22 03:58:58 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
struct CHS chs; /* for normal INT 13 */
|
2001-07-22 03:58:58 +02:00
|
|
|
};
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
struct PartTableEntry /* INTERNAL representation of partition table entry */
|
|
|
|
{
|
|
|
|
UBYTE Bootable;
|
|
|
|
UBYTE FileSystem;
|
|
|
|
struct CHS Begin;
|
|
|
|
struct CHS End;
|
|
|
|
ULONG RelSect;
|
|
|
|
ULONG NumSect;
|
|
|
|
};
|
2001-07-28 20:13:06 +02:00
|
|
|
|
2001-07-10 00:19:33 +02:00
|
|
|
/*
|
|
|
|
internal global data
|
|
|
|
*/
|
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
BOOL ExtLBAForce = FALSE;
|
|
|
|
|
2001-09-23 22:39:44 +02:00
|
|
|
COUNT init_readdasd(UBYTE drive)
|
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
static iregs regs;
|
|
|
|
|
|
|
|
regs.a.b.h = 0x15;
|
|
|
|
regs.d.b.l = drive;
|
|
|
|
init_call_intr(0x13, ®s);
|
|
|
|
if ((regs.flags & 1) == 0)
|
|
|
|
switch (regs.a.b.h)
|
2001-09-23 22:39:44 +02:00
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
case 2:
|
|
|
|
return DF_CHANGELINE;
|
|
|
|
case 3:
|
|
|
|
return DF_FIXED;
|
2001-09-23 22:39:44 +02:00
|
|
|
}
|
2001-11-18 15:01:12 +01:00
|
|
|
return 0;
|
2001-09-23 22:39:44 +02:00
|
|
|
}
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
typedef struct {
|
2001-11-04 20:47:39 +01:00
|
|
|
UWORD bpb_nbyte; /* Bytes per Sector */
|
|
|
|
UBYTE bpb_nsector; /* Sectors per Allocation Unit */
|
|
|
|
UWORD bpb_nreserved; /* # Reserved Sectors */
|
|
|
|
UBYTE bpb_nfat; /* # FAT's */
|
|
|
|
UWORD bpb_ndirent; /* # Root Directory entries */
|
|
|
|
UWORD bpb_nsize; /* Size in sectors */
|
|
|
|
UBYTE bpb_mdesc; /* MEDIA Descriptor Byte */
|
|
|
|
UWORD bpb_nfsect; /* FAT size in sectors */
|
|
|
|
UWORD bpb_nsecs; /* Sectors per track */
|
|
|
|
UWORD bpb_nheads; /* Number of heads */
|
|
|
|
} floppy_bpb;
|
|
|
|
|
|
|
|
floppy_bpb floppy_bpbs[5] = {
|
2001-11-18 15:01:12 +01:00
|
|
|
/* copied from Brian Reifsnyder's FORMAT, bpb.h */
|
|
|
|
{SEC_SIZE, 2, 1, 2, 112, 720, 0xfd, 2, 9, 2}, /* FD360 5.25 DS */
|
|
|
|
{SEC_SIZE, 1, 1, 2, 224, 2400, 0xf9, 7, 15, 2}, /* FD1200 5.25 HD */
|
|
|
|
{SEC_SIZE, 2, 1, 2, 112, 1440, 0xf9, 3, 9, 2}, /* FD720 3.5 LD */
|
|
|
|
{SEC_SIZE, 1, 1, 2, 224, 2880, 0xf0, 9, 18, 2}, /* FD1440 3.5 HD */
|
|
|
|
{SEC_SIZE, 2, 1, 2, 240, 5760, 0xf0, 9, 36, 2} /* FD2880 3.5 ED */
|
2001-11-04 20:47:39 +01:00
|
|
|
};
|
|
|
|
|
2004-04-09 17:39:56 +02:00
|
|
|
COUNT init_getdriveparm(UBYTE drive, bpb * pbpbarray)
|
2001-11-04 20:47:39 +01:00
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
static iregs regs;
|
|
|
|
REG UBYTE type;
|
|
|
|
|
|
|
|
if (drive & 0x80)
|
|
|
|
return 5;
|
|
|
|
regs.a.b.h = 0x08;
|
|
|
|
regs.d.b.l = drive;
|
|
|
|
init_call_intr(0x13, ®s);
|
|
|
|
type = regs.b.b.l - 1;
|
|
|
|
if (regs.flags & 1)
|
|
|
|
type = 0; /* return 320-360 for XTs */
|
|
|
|
else if (type > 6)
|
|
|
|
type = 8; /* any odd ball drives get 8&7=0: the 320-360 table */
|
|
|
|
else if (type == 5)
|
|
|
|
type = 4; /* 5 and 4 are both 2.88 MB */
|
|
|
|
|
2004-04-09 17:39:56 +02:00
|
|
|
memcpy(pbpbarray, &floppy_bpbs[type & 7], sizeof(floppy_bpb));
|
2005-01-09 12:30:44 +01:00
|
|
|
((bpb *)pbpbarray)->bpb_hidden = 0; /* very important to init to 0, see bug#1789 */
|
|
|
|
((bpb *)pbpbarray)->bpb_huge = 0;
|
2001-11-18 15:01:12 +01:00
|
|
|
|
|
|
|
if (type == 3)
|
|
|
|
return 7; /* 1.44 MB */
|
|
|
|
|
|
|
|
if (type == 4)
|
|
|
|
return 9; /* 2.88 almost forgot this one */
|
|
|
|
|
|
|
|
/* 0=320-360kB, 1=1.2MB, 2=720kB, 8=any odd ball drives */
|
|
|
|
return type;
|
2001-11-04 20:47:39 +01:00
|
|
|
}
|
|
|
|
|
2001-07-10 00:19:33 +02:00
|
|
|
/*
|
|
|
|
translate LBA sectors into CHS addressing
|
|
|
|
copied and pasted from dsk.c!
|
|
|
|
*/
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
void init_LBA_to_CHS(struct CHS *chs, ULONG LBA_address,
|
|
|
|
struct DriveParamS *driveparam)
|
2001-07-10 00:19:33 +02:00
|
|
|
{
|
2002-12-09 01:17:15 +01:00
|
|
|
unsigned hs = driveparam->chs.Sector * driveparam->chs.Head;
|
|
|
|
unsigned hsrem = (unsigned)(LBA_address % hs);
|
2002-10-22 04:40:19 +02:00
|
|
|
|
2002-12-09 01:17:15 +01:00
|
|
|
LBA_address /= hs;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2002-12-09 01:17:15 +01:00
|
|
|
chs->Cylinder = LBA_address >= 0x10000ul ? 0xffffu : (unsigned)LBA_address;
|
|
|
|
chs->Head = hsrem / driveparam->chs.Sector;
|
|
|
|
chs->Sector = hsrem % driveparam->chs.Sector + 1;
|
2001-07-10 00:19:33 +02:00
|
|
|
}
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
void printCHS(char *title, struct CHS *chs)
|
2001-07-10 00:19:33 +02:00
|
|
|
{
|
2003-06-15 21:26:49 +02:00
|
|
|
/* has no fixed size for head/sect: is often 1/1 in our context */
|
2004-05-11 00:46:41 +02:00
|
|
|
printf("%s%4u-%u-%u", title, chs->Cylinder, chs->Head, chs->Sector);
|
2001-11-18 15:01:12 +01:00
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
reason for this modules existence:
|
|
|
|
|
|
|
|
we have found a partition, and add them to the global
|
|
|
|
partition structure.
|
|
|
|
|
|
|
|
*/
|
2001-07-22 03:58:58 +02:00
|
|
|
|
|
|
|
/* Compute ceil(a/b) */
|
|
|
|
#define cdiv(a, b) (((a) + (b) - 1) / (b))
|
|
|
|
|
|
|
|
/* calculates FAT data:
|
|
|
|
code adapted by Bart Oldeman from mkdosfs from the Linux dosfstools:
|
|
|
|
Author: Dave Hudson
|
|
|
|
Updated by: Roman Hodek
|
|
|
|
Portions copyright 1992, 1993 Remy Card
|
|
|
|
and 1991 Linus Torvalds
|
|
|
|
*/
|
2004-04-09 17:39:56 +02:00
|
|
|
VOID CalculateFATData(ddt * pddt, ULONG NumSectors, UBYTE FileSystem)
|
2001-07-22 03:58:58 +02:00
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
UBYTE maxclustsize;
|
|
|
|
ULONG fatdata;
|
|
|
|
|
2004-04-09 17:39:56 +02:00
|
|
|
bpb *defbpb = &pddt->ddt_defbpb;
|
2001-11-18 15:01:12 +01:00
|
|
|
|
|
|
|
/* FAT related items */
|
|
|
|
defbpb->bpb_nfat = 2;
|
|
|
|
defbpb->bpb_ndirent = (FileSystem == FAT32
|
|
|
|
|| FileSystem == FAT32_LBA) ? 0 : 512;
|
|
|
|
/* normal value of number of entries in root dir */
|
|
|
|
defbpb->bpb_nreserved = (FileSystem == FAT32
|
|
|
|
|| FileSystem == FAT32_LBA) ? 0x20 : 1;
|
|
|
|
|
|
|
|
fatdata =
|
|
|
|
NumSectors - cdiv(defbpb->bpb_ndirent * DIRENT_SIZE,
|
|
|
|
defbpb->bpb_nbyte) - defbpb->bpb_nreserved;
|
|
|
|
maxclustsize = 128;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (FileSystem != FAT12)
|
|
|
|
DebugPrintf(("%ld sectors for FAT+data, starting with %d sectors/cluster\n", fatdata, defbpb->bpb_nsector));
|
|
|
|
#endif
|
|
|
|
switch (FileSystem)
|
|
|
|
{
|
2001-07-22 03:58:58 +02:00
|
|
|
|
|
|
|
case FAT12:
|
2001-11-18 15:01:12 +01:00
|
|
|
case FAT12_LBA:
|
2003-12-13 04:07:49 +01:00
|
|
|
{
|
|
|
|
unsigned fatdat, fatlength, clust, maxclust;
|
2001-11-18 15:01:12 +01:00
|
|
|
/* in DOS, FAT12 defaults to 4096kb (8 sector) - clusters. */
|
|
|
|
defbpb->bpb_nsector = 8;
|
|
|
|
/* Force maximal fatdata=32696 sectors since with our only possible sector
|
|
|
|
size (512 bytes) this is the maximum for 4k clusters.
|
|
|
|
#clus*secperclus+#fats*fatlength= 4077 * 8 + 2 * 12 = 32640.
|
|
|
|
max FAT12 size for FreeDOS = 16,728,064 bytes */
|
2003-12-13 04:07:49 +01:00
|
|
|
fatdat = (unsigned)fatdata;
|
2001-11-18 15:01:12 +01:00
|
|
|
if (fatdata > 32640)
|
2003-12-13 04:07:49 +01:00
|
|
|
fatdat = 32640;
|
|
|
|
/* The "+2*defbpb->bpb_nsector" is for the reserved first two FAT entries */
|
|
|
|
fatlength = cdiv(fatdat + 2 * defbpb->bpb_nsector,
|
|
|
|
defbpb->bpb_nbyte * 2 * defbpb->bpb_nsector / 3 +
|
|
|
|
defbpb->bpb_nfat);
|
|
|
|
/* Need to calculate number of clusters, since the unused parts of the
|
2001-11-18 15:01:12 +01:00
|
|
|
* FATS and data area together could make up space for an additional,
|
|
|
|
* not really present cluster. */
|
|
|
|
clust =
|
2003-12-13 04:07:49 +01:00
|
|
|
(fatdat - defbpb->bpb_nfat * fatlength) / defbpb->bpb_nsector;
|
2001-11-18 15:01:12 +01:00
|
|
|
maxclust = (fatlength * 2 * defbpb->bpb_nbyte) / 3;
|
|
|
|
if (maxclust > FAT12MAX)
|
|
|
|
maxclust = FAT12MAX;
|
2003-12-13 04:07:49 +01:00
|
|
|
DebugPrintf(("FAT12: #clu=%u, fatlength=%u, maxclu=%u, limit=%u\n",
|
2002-01-23 23:29:41 +01:00
|
|
|
clust, fatlength, maxclust, FAT12MAX));
|
2001-11-18 15:01:12 +01:00
|
|
|
if (clust > maxclust - 2)
|
|
|
|
{
|
|
|
|
clust = maxclust - 2;
|
|
|
|
DebugPrintf(("FAT12: too many clusters: setting to maxclu-2\n"));
|
|
|
|
}
|
|
|
|
defbpb->bpb_nfsect = fatlength;
|
2004-04-09 18:08:57 +02:00
|
|
|
memcpy(pddt->ddt_fstype, MSDOS_FAT12_SIGN, 8);
|
2001-11-18 15:01:12 +01:00
|
|
|
break;
|
2003-12-13 04:07:49 +01:00
|
|
|
}
|
2001-11-18 15:01:12 +01:00
|
|
|
case FAT16SMALL:
|
|
|
|
case FAT16LARGE:
|
|
|
|
case FAT16_LBA:
|
2003-12-13 04:07:49 +01:00
|
|
|
{
|
|
|
|
unsigned fatlength;
|
|
|
|
unsigned long clust, maxclust;
|
2001-11-18 15:01:12 +01:00
|
|
|
/* FAT16: start at 4 sectors per cluster */
|
|
|
|
defbpb->bpb_nsector = 4;
|
|
|
|
/* Force maximal fatdata=8387584 sectors (NumSectors=8387617)
|
|
|
|
since with our only possible sectorsize (512 bytes) this is the
|
|
|
|
maximum we can address with 64k clusters
|
|
|
|
#clus*secperclus+#fats*fatlength=65517 * 128 + 2 * 256=8386688.
|
|
|
|
max FAT16 size for FreeDOS = 4,293,984,256 bytes = 4GiB-983,040 */
|
|
|
|
if (fatdata > 8386688ul)
|
|
|
|
fatdata = 8386688ul;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
DebugPrintf(("Trying with %d sectors/cluster:\n",
|
|
|
|
defbpb->bpb_nsector));
|
|
|
|
|
2003-12-13 04:07:49 +01:00
|
|
|
fatlength = (unsigned)cdiv(fatdata + 2 * defbpb->bpb_nsector,
|
|
|
|
(ULONG)defbpb->bpb_nbyte * defbpb->bpb_nsector / 2 +
|
|
|
|
defbpb->bpb_nfat);
|
|
|
|
/* Need to calculate number of clusters, since the unused parts of the
|
2001-07-22 03:58:58 +02:00
|
|
|
* FATS and data area together could make up space for an additional,
|
|
|
|
* not really present cluster. */
|
2001-11-18 15:01:12 +01:00
|
|
|
clust =
|
|
|
|
(fatdata - defbpb->bpb_nfat * fatlength) / defbpb->bpb_nsector;
|
2004-01-25 18:52:11 +01:00
|
|
|
maxclust = ((unsigned long)fatlength * defbpb->bpb_nbyte) / 2;
|
2001-11-18 15:01:12 +01:00
|
|
|
if (maxclust > FAT16MAX)
|
|
|
|
maxclust = FAT16MAX;
|
2003-12-13 04:07:49 +01:00
|
|
|
DebugPrintf(("FAT16: #clu=%lu, fatlen=%u, maxclu=%lu, limit=%u\n",
|
2001-11-18 15:01:12 +01:00
|
|
|
clust, fatlength, maxclust, FAT_MAGIC16));
|
|
|
|
if (clust > maxclust - 2)
|
|
|
|
{
|
|
|
|
DebugPrintf(("FAT16: too many clusters\n"));
|
|
|
|
clust = 0;
|
2001-07-22 03:58:58 +02:00
|
|
|
}
|
2001-11-18 15:01:12 +01:00
|
|
|
else if (clust <= FAT_MAGIC)
|
|
|
|
{
|
|
|
|
/* The <= 4086 avoids that the filesystem will be misdetected as having a
|
|
|
|
* 12 bit FAT. */
|
|
|
|
DebugPrintf(("FAT16: would be misdetected as FAT12\n"));
|
|
|
|
clust = 0;
|
2001-07-22 03:58:58 +02:00
|
|
|
}
|
2001-11-18 15:01:12 +01:00
|
|
|
if (clust)
|
|
|
|
break;
|
|
|
|
defbpb->bpb_nsector <<= 1;
|
|
|
|
}
|
|
|
|
while (defbpb->bpb_nsector && defbpb->bpb_nsector <= maxclustsize);
|
|
|
|
defbpb->bpb_nfsect = fatlength;
|
2004-04-09 18:08:57 +02:00
|
|
|
memcpy(pddt->ddt_fstype, MSDOS_FAT16_SIGN, 8);
|
2001-11-18 15:01:12 +01:00
|
|
|
break;
|
2003-12-13 04:07:49 +01:00
|
|
|
}
|
2001-07-22 03:58:58 +02:00
|
|
|
#ifdef WITHFAT32
|
|
|
|
case FAT32:
|
2001-11-04 20:47:39 +01:00
|
|
|
case FAT32_LBA:
|
2003-12-13 04:07:49 +01:00
|
|
|
{
|
|
|
|
unsigned long fatlength, clust, maxclust;
|
|
|
|
|
2004-01-26 03:01:34 +01:00
|
|
|
/* For FAT32, use the cluster size table described in the FAT spec:
|
|
|
|
* http://www.microsoft.com/hwdev/download/hardware/fatgen103.pdf
|
|
|
|
*/
|
|
|
|
unsigned sz_gb = (unsigned)(NumSectors / 2097152UL);
|
|
|
|
unsigned char nsector = 64; /* disks greater than 32 GB, 32K cluster */
|
|
|
|
if (sz_gb <= 32) /* disks up to 32 GB, 16K cluster */
|
|
|
|
nsector = 32;
|
|
|
|
if (sz_gb <= 16) /* disks up to 16 GB, 8K cluster */
|
|
|
|
nsector = 16;
|
|
|
|
if (sz_gb <= 8) /* disks up to 8 GB, 4K cluster */
|
|
|
|
nsector = 8;
|
2004-01-31 16:04:09 +01:00
|
|
|
if (NumSectors <= 532480UL) /* disks up to 260 MB, 0.5K cluster */
|
2004-01-26 03:01:34 +01:00
|
|
|
nsector = 1;
|
|
|
|
defbpb->bpb_nsector = nsector;
|
2001-11-18 15:01:12 +01:00
|
|
|
do
|
|
|
|
{
|
2003-12-13 04:07:49 +01:00
|
|
|
fatlength = cdiv(fatdata + 2 * defbpb->bpb_nsector,
|
|
|
|
(ULONG)defbpb->bpb_nbyte * defbpb->bpb_nsector / 4 +
|
|
|
|
defbpb->bpb_nfat);
|
|
|
|
/* Need to calculate number of clusters, since the unused parts of the
|
2001-11-18 15:01:12 +01:00
|
|
|
* FATS and data area together could make up space for an additional,
|
|
|
|
* not really present cluster. */
|
|
|
|
clust =
|
|
|
|
(fatdata - defbpb->bpb_nfat * fatlength) / defbpb->bpb_nsector;
|
|
|
|
maxclust = (fatlength * defbpb->bpb_nbyte) / 4;
|
|
|
|
if (maxclust > FAT32MAX)
|
|
|
|
maxclust = FAT32MAX;
|
|
|
|
DebugPrintf(("FAT32: #clu=%u, fatlen=%u, maxclu=%u, limit=%u\n",
|
2002-01-23 23:29:41 +01:00
|
|
|
clust, fatlength, maxclust, FAT32MAX));
|
2001-11-18 15:01:12 +01:00
|
|
|
if (clust > maxclust - 2)
|
2001-07-10 00:19:33 +02:00
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
clust = 0;
|
|
|
|
DebugPrintf(("FAT32: too many clusters\n"));
|
2001-07-10 00:19:33 +02:00
|
|
|
}
|
2001-11-18 15:01:12 +01:00
|
|
|
if (clust)
|
|
|
|
break;
|
|
|
|
defbpb->bpb_nsector <<= 1;
|
|
|
|
}
|
|
|
|
while (defbpb->bpb_nsector && defbpb->bpb_nsector <= maxclustsize);
|
|
|
|
defbpb->bpb_nfsect = 0;
|
|
|
|
defbpb->bpb_xnfsect = fatlength;
|
|
|
|
/* set up additional FAT32 fields */
|
|
|
|
defbpb->bpb_xflags = 0;
|
|
|
|
defbpb->bpb_xfsversion = 0;
|
|
|
|
defbpb->bpb_xrootclst = 2;
|
|
|
|
defbpb->bpb_xfsinfosec = 1;
|
|
|
|
defbpb->bpb_xbackupsec = 6;
|
2004-04-09 18:08:57 +02:00
|
|
|
memcpy(pddt->ddt_fstype, MSDOS_FAT32_SIGN, 8);
|
2001-11-18 15:01:12 +01:00
|
|
|
break;
|
2003-12-13 04:07:49 +01:00
|
|
|
}
|
2001-11-18 15:01:12 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
pddt->ddt_fstype[8] = '\0';
|
2001-07-10 00:19:33 +02:00
|
|
|
}
|
|
|
|
|
2004-04-10 11:37:45 +02:00
|
|
|
STATIC void push_ddt(ddt *pddt)
|
|
|
|
{
|
|
|
|
ddt FAR *fddt = DynAlloc("ddt", 1, sizeof(ddt));
|
|
|
|
fmemcpy(fddt, pddt, sizeof(ddt));
|
|
|
|
if (pddt->ddt_logdriveno != 0) {
|
|
|
|
(fddt - 1)->ddt_next = fddt;
|
|
|
|
if (pddt->ddt_driveno == 0 && pddt->ddt_logdriveno == 1)
|
|
|
|
(fddt - 1)->ddt_descflags |= DF_CURLOG | DF_MULTLOG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
void DosDefinePartition(struct DriveParamS *driveParam,
|
|
|
|
ULONG StartSector, struct PartTableEntry *pEntry,
|
|
|
|
int extendedPartNo, int PrimaryNum)
|
2001-07-10 00:19:33 +02:00
|
|
|
{
|
2004-04-09 17:39:56 +02:00
|
|
|
ddt nddt;
|
|
|
|
ddt *pddt = &nddt;
|
2001-11-18 15:01:12 +01:00
|
|
|
struct CHS chs;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (nUnits >= NDEV)
|
|
|
|
{
|
|
|
|
printf("more Partitions detected then possible, max = %d\n", NDEV);
|
|
|
|
return; /* we are done */
|
|
|
|
}
|
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
pddt->ddt_next = MK_FP(0, 0xffff);
|
2001-11-18 15:01:12 +01:00
|
|
|
pddt->ddt_driveno = driveParam->driveno;
|
|
|
|
pddt->ddt_logdriveno = nUnits;
|
2004-04-13 19:21:30 +02:00
|
|
|
pddt->ddt_descflags = driveParam->descflags;
|
2001-11-18 15:01:12 +01:00
|
|
|
/* Turn of LBA if not forced and the partition is within 1023 cyls and of the right type */
|
|
|
|
/* the FileSystem type was internally converted to LBA_xxxx if a non-LBA partition
|
|
|
|
above cylinder 1023 was found */
|
2002-01-23 23:29:41 +01:00
|
|
|
if (!InitKernelConfig.ForceLBA && !ExtLBAForce && !IsLBAPartition(pEntry->FileSystem))
|
2004-04-13 12:54:33 +02:00
|
|
|
pddt->ddt_descflags &= ~DF_LBA;
|
2001-11-18 15:01:12 +01:00
|
|
|
pddt->ddt_ncyl = driveParam->chs.Cylinder;
|
|
|
|
|
2002-08-03 04:37:59 +02:00
|
|
|
#ifdef DEBUG
|
2004-04-13 12:54:33 +02:00
|
|
|
if (pddt->ddt_descflags & DF_LBA)
|
2001-11-18 15:01:12 +01:00
|
|
|
DebugPrintf(("LBA enabled for drive %c:\n", 'A' + nUnits));
|
2002-08-03 04:37:59 +02:00
|
|
|
#endif
|
2001-11-18 15:01:12 +01:00
|
|
|
|
|
|
|
pddt->ddt_offset = StartSector;
|
|
|
|
|
|
|
|
pddt->ddt_defbpb.bpb_nbyte = SEC_SIZE;
|
|
|
|
pddt->ddt_defbpb.bpb_mdesc = 0xf8;
|
|
|
|
pddt->ddt_defbpb.bpb_nheads = driveParam->chs.Head;
|
|
|
|
pddt->ddt_defbpb.bpb_nsecs = driveParam->chs.Sector;
|
|
|
|
pddt->ddt_defbpb.bpb_nsize = 0;
|
|
|
|
pddt->ddt_defbpb.bpb_hidden = pEntry->RelSect;
|
|
|
|
if (pEntry->NumSect > 0xffff)
|
|
|
|
pddt->ddt_defbpb.bpb_huge = pEntry->NumSect;
|
|
|
|
else
|
|
|
|
pddt->ddt_defbpb.bpb_nsize = (UWORD) (pEntry->NumSect);
|
|
|
|
|
|
|
|
/* sectors per cluster, sectors per FAT etc. */
|
|
|
|
CalculateFATData(pddt, pEntry->NumSect, pEntry->FileSystem);
|
|
|
|
|
|
|
|
pddt->ddt_serialno = 0x12345678l;
|
|
|
|
/* drive inaccessible until bldbpb successful */
|
2004-04-13 19:21:30 +02:00
|
|
|
pddt->ddt_descflags |= init_readdasd(pddt->ddt_driveno) | DF_NOACCESS;
|
2001-11-18 15:01:12 +01:00
|
|
|
pddt->ddt_type = 5;
|
2004-04-09 17:39:56 +02:00
|
|
|
memcpy(&pddt->ddt_bpb, &pddt->ddt_defbpb, sizeof(bpb));
|
|
|
|
|
2004-04-10 11:37:45 +02:00
|
|
|
push_ddt(pddt);
|
2001-11-18 15:01:12 +01:00
|
|
|
|
|
|
|
/* Alain whishes to keep this in later versions, too
|
|
|
|
Tom likes this too, so he made it configurable by SYS CONFIG ...
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (InitKernelConfig.InitDiskShowDriveAssignment)
|
|
|
|
{
|
2004-05-11 00:46:41 +02:00
|
|
|
char *ExtPri;
|
|
|
|
int num;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2004-05-11 00:46:41 +02:00
|
|
|
LBA_to_CHS(&chs, StartSector, driveParam);
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2004-05-11 00:46:41 +02:00
|
|
|
ExtPri = "Pri";
|
|
|
|
num = PrimaryNum + 1;
|
2001-11-18 15:01:12 +01:00
|
|
|
if (extendedPartNo)
|
2004-05-11 00:46:41 +02:00
|
|
|
{
|
|
|
|
ExtPri = "Ext";
|
|
|
|
num = extendedPartNo;
|
|
|
|
}
|
|
|
|
printf("\r%c: HD%d, %s[%2d]", 'A' + nUnits,
|
|
|
|
(driveParam->driveno & 0x7f) + 1, ExtPri, num);
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2003-06-15 21:26:49 +02:00
|
|
|
printCHS(", CHS= ", &chs);
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2004-05-11 00:46:41 +02:00
|
|
|
printf(", start=%6lu MB, size=%6lu MB\n",
|
2001-11-18 15:01:12 +01:00
|
|
|
StartSector / 2048, pEntry->NumSect / 2048);
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
nUnits++;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* Get the parameters of the hard disk */
|
2004-05-25 21:24:55 +02:00
|
|
|
STATIC int LBA_Get_Drive_Parameters(int drive, struct DriveParamS *driveParam)
|
2001-11-18 15:01:12 +01:00
|
|
|
{
|
|
|
|
iregs regs;
|
|
|
|
struct _bios_LBA_disk_parameterS lba_bios_parameters;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2004-05-25 21:24:55 +02:00
|
|
|
ExtLBAForce = FALSE;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2004-05-25 21:24:55 +02:00
|
|
|
memset(driveParam, 0, sizeof *driveParam);
|
2001-11-18 15:01:12 +01:00
|
|
|
drive |= 0x80;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* for tests - disable LBA support,
|
|
|
|
even if exists */
|
|
|
|
if (!InitKernelConfig.GlobalEnableLBAsupport)
|
|
|
|
{
|
|
|
|
goto StandardBios;
|
|
|
|
}
|
|
|
|
/* check for LBA support */
|
|
|
|
regs.b.x = 0x55aa;
|
|
|
|
regs.a.b.h = 0x41;
|
|
|
|
regs.d.b.l = drive;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
init_call_intr(0x13, ®s);
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (regs.b.x != 0xaa55 || (regs.flags & 0x01))
|
|
|
|
{
|
|
|
|
goto StandardBios;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* by ralph :
|
|
|
|
if DAP cannot be used, don't use
|
|
|
|
LBA
|
|
|
|
*/
|
|
|
|
if ((regs.c.x & 1) == 0)
|
|
|
|
{
|
|
|
|
goto StandardBios;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* drive supports LBA addressing */
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* version 1.0, 2.0 have different verify */
|
|
|
|
if (regs.a.x < 0x2100)
|
|
|
|
LBA_WRITE_VERIFY = 0x4301;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
memset(&lba_bios_parameters, 0, sizeof(lba_bios_parameters));
|
|
|
|
lba_bios_parameters.size = sizeof(lba_bios_parameters);
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
regs.si = FP_OFF(&lba_bios_parameters);
|
|
|
|
regs.ds = FP_SEG(&lba_bios_parameters);
|
|
|
|
regs.a.b.h = 0x48;
|
|
|
|
regs.d.b.l = drive;
|
|
|
|
init_call_intr(0x13, ®s);
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
/* error or DMA boundary errors not handled transparently */
|
2001-11-18 15:01:12 +01:00
|
|
|
if (regs.flags & 0x01)
|
|
|
|
{
|
|
|
|
goto StandardBios;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* verify maximum settings, we can't handle more */
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (lba_bios_parameters.heads > 0xffff ||
|
|
|
|
lba_bios_parameters.sectors > 0xffff ||
|
|
|
|
lba_bios_parameters.totalSectHigh != 0)
|
|
|
|
{
|
2003-06-15 21:26:49 +02:00
|
|
|
printf("Drive is too large to handle, using only 1st 8 GB\n"
|
2001-11-18 15:01:12 +01:00
|
|
|
" drive %02x heads %lu sectors %lu , total=0x%lx-%08lx\n",
|
|
|
|
drive,
|
|
|
|
(ULONG) lba_bios_parameters.heads,
|
|
|
|
(ULONG) lba_bios_parameters.sectors,
|
|
|
|
(ULONG) lba_bios_parameters.totalSect,
|
|
|
|
(ULONG) lba_bios_parameters.totalSectHigh);
|
|
|
|
|
|
|
|
goto StandardBios;
|
|
|
|
}
|
|
|
|
|
|
|
|
driveParam->total_sectors = lba_bios_parameters.totalSect;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* if we arrive here, success */
|
2004-04-13 12:54:33 +02:00
|
|
|
driveParam->descflags = DF_LBA;
|
|
|
|
if (lba_bios_parameters.information & 8)
|
|
|
|
driveParam->descflags |= DF_WRTVERIFY;
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
StandardBios: /* old way to get parameters */
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
regs.a.b.h = 0x08;
|
|
|
|
regs.d.b.l = drive;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
init_call_intr(0x13, ®s);
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (regs.flags & 0x01)
|
|
|
|
goto ErrorReturn;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
driveParam->chs.Head = (regs.d.x >> 8) + 1;
|
|
|
|
driveParam->chs.Sector = (regs.c.x & 0x3f);
|
|
|
|
driveParam->chs.Cylinder = (regs.c.x >> 8) | ((regs.c.x & 0xc0) << 2);
|
2003-06-15 21:26:49 +02:00
|
|
|
|
|
|
|
if (driveParam->chs.Sector == 0) {
|
|
|
|
/* happens e.g. with Bochs 1.x if no harddisk defined */
|
|
|
|
driveParam->chs.Sector = 63; /* avoid division by zero...! */
|
|
|
|
printf("BIOS reported 0 sectors/track, assuming 63!\n");
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2004-04-13 12:54:33 +02:00
|
|
|
if (!(driveParam->descflags & DF_LBA))
|
2001-11-18 15:01:12 +01:00
|
|
|
{
|
|
|
|
driveParam->total_sectors =
|
|
|
|
min(driveParam->chs.Cylinder, 1023)
|
|
|
|
* driveParam->chs.Head * driveParam->chs.Sector;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
driveParam->driveno = drive;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
DebugPrintf(("drive parameters %02x - %04lu-%u-%u",
|
|
|
|
drive,
|
|
|
|
driveParam->chs.Cylinder,
|
|
|
|
driveParam->chs.Head, driveParam->chs.Sector));
|
|
|
|
DebugPrintf((" total size %luMB\n\n", driveParam->total_sectors / 2048));
|
2001-07-10 00:19:33 +02:00
|
|
|
|
|
|
|
ErrorReturn:
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
return driveParam->driveno;
|
2001-07-10 00:19:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
converts physical into logical representation of partition entry
|
|
|
|
*/
|
|
|
|
|
2004-04-09 17:39:56 +02:00
|
|
|
STATIC void ConvCHSToIntern(struct CHS *chs, UBYTE * pDisk)
|
|
|
|
{
|
|
|
|
chs->Head = pDisk[0];
|
|
|
|
chs->Sector = pDisk[1] & 0x3f;
|
|
|
|
chs->Cylinder = pDisk[2] + ((pDisk[1] & 0xc0) << 2);
|
|
|
|
}
|
|
|
|
|
2002-08-03 04:37:59 +02:00
|
|
|
BOOL ConvPartTableEntryToIntern(struct PartTableEntry * pEntry,
|
2003-06-15 20:40:03 +02:00
|
|
|
UBYTE * pDisk)
|
2001-07-10 00:19:33 +02:00
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
int i;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (pDisk[0x1fe] != 0x55 || pDisk[0x1ff] != 0xaa)
|
|
|
|
{
|
|
|
|
memset(pEntry, 0, 4 * sizeof(struct PartTableEntry));
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
pDisk += 0x1be;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
for (i = 0; i < 4; i++, pDisk += 16, pEntry++)
|
|
|
|
{
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2004-04-09 17:39:56 +02:00
|
|
|
pEntry->Bootable = pDisk[0];
|
|
|
|
pEntry->FileSystem = pDisk[4];
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2004-04-09 17:39:56 +02:00
|
|
|
ConvCHSToIntern(&pEntry->Begin, pDisk+1);
|
|
|
|
ConvCHSToIntern(&pEntry->End, pDisk+5);
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2004-04-09 17:39:56 +02:00
|
|
|
pEntry->RelSect = *(ULONG *) (pDisk + 8);
|
|
|
|
pEntry->NumSect = *(ULONG *) (pDisk + 12);
|
2001-11-18 15:01:12 +01:00
|
|
|
}
|
|
|
|
return TRUE;
|
2001-07-10 00:19:33 +02:00
|
|
|
}
|
|
|
|
|
2004-02-25 00:46:04 +01:00
|
|
|
BOOL is_suspect(struct CHS *chs, struct CHS *pEntry_chs)
|
|
|
|
{
|
2004-05-25 21:24:55 +02:00
|
|
|
/* Valid entry:
|
|
|
|
entry == chs || // partition entry equal to computed values
|
|
|
|
(chs->Cylinder > 1023 && // or LBA partition
|
|
|
|
(entry->Cylinder == 1023 ||
|
|
|
|
entry->Cylinder == (0x3FF & chs->Cylinder)))
|
|
|
|
*/
|
|
|
|
return !((pEntry_chs->Cylinder == chs->Cylinder &&
|
|
|
|
pEntry_chs->Head == chs->Head &&
|
|
|
|
pEntry_chs->Sector == chs->Sector) ||
|
|
|
|
chs->Cylinder > 1023u &&
|
|
|
|
(pEntry_chs->Cylinder == 1023 ||
|
|
|
|
pEntry_chs->Cylinder == (0x3ff & chs->Cylinder)));
|
2004-02-25 00:46:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_warning_suspect(char *partitionName, UBYTE fs, struct CHS *chs,
|
|
|
|
struct CHS *pEntry_chs)
|
|
|
|
{
|
|
|
|
printf("WARNING: using suspect partition %s FS %02x:", partitionName, fs);
|
|
|
|
printCHS(" with calculated values ", chs);
|
|
|
|
printCHS(" instead of ", pEntry_chs);
|
|
|
|
printf("\n");
|
|
|
|
memcpy(pEntry_chs, chs, sizeof(struct CHS));
|
|
|
|
}
|
|
|
|
|
2002-08-03 04:37:59 +02:00
|
|
|
BOOL ScanForPrimaryPartitions(struct DriveParamS * driveParam, int scan_type,
|
2001-11-18 15:01:12 +01:00
|
|
|
struct PartTableEntry * pEntry, ULONG startSector,
|
|
|
|
int partitionsToIgnore, int extendedPartNo)
|
2001-07-10 00:19:33 +02:00
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
int i;
|
|
|
|
struct CHS chs, end;
|
|
|
|
ULONG partitionStart;
|
|
|
|
char partitionName[12];
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
for (i = 0; i < 4; i++, pEntry++)
|
|
|
|
{
|
|
|
|
if (pEntry->FileSystem == 0)
|
|
|
|
continue;
|
2001-11-14 00:36:45 +01:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (partitionsToIgnore & (1 << i))
|
|
|
|
continue;
|
2001-11-14 00:36:45 +01:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (IsExtPartition(pEntry->FileSystem))
|
|
|
|
continue;
|
2001-11-14 00:36:45 +01:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (scan_type == SCAN_PRIMARYBOOT && !pEntry->Bootable)
|
|
|
|
continue;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
partitionStart = startSector + pEntry->RelSect;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (!IsFATPartition(pEntry->FileSystem))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (extendedPartNo)
|
|
|
|
sprintf(partitionName, "Ext:%d", extendedPartNo);
|
|
|
|
else
|
|
|
|
sprintf(partitionName, "Pri:%d", i + 1);
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/*
|
|
|
|
some sanity checks, that partition
|
|
|
|
structure is OK
|
|
|
|
*/
|
|
|
|
LBA_to_CHS(&chs, partitionStart, driveParam);
|
|
|
|
LBA_to_CHS(&end, partitionStart + pEntry->NumSect - 1, driveParam);
|
|
|
|
|
|
|
|
/* some FDISK's enter for partitions
|
|
|
|
> 8 GB cyl = 1023, other (cyl&1023)
|
|
|
|
*/
|
|
|
|
|
2004-02-25 00:46:04 +01:00
|
|
|
if (is_suspect(&chs, &pEntry->Begin))
|
2001-11-18 15:01:12 +01:00
|
|
|
{
|
2004-02-25 00:46:04 +01:00
|
|
|
print_warning_suspect(partitionName, pEntry->FileSystem, &chs,
|
|
|
|
&pEntry->Begin);
|
2001-11-18 15:01:12 +01:00
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2004-02-25 00:46:04 +01:00
|
|
|
if (is_suspect(&end, &pEntry->End))
|
2001-11-18 15:01:12 +01:00
|
|
|
{
|
|
|
|
if (pEntry->NumSect == 0)
|
|
|
|
{
|
|
|
|
printf("Not using partition %s with 0 sectors\n", partitionName);
|
|
|
|
continue;
|
|
|
|
}
|
2004-02-25 00:46:04 +01:00
|
|
|
print_warning_suspect(partitionName, pEntry->FileSystem, &end,
|
|
|
|
&pEntry->End);
|
2001-11-18 15:01:12 +01:00
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (chs.Cylinder > 1023 || end.Cylinder > 1023)
|
|
|
|
{
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2004-04-13 12:54:33 +02:00
|
|
|
if (!(driveParam->descflags & DF_LBA))
|
2001-11-18 15:01:12 +01:00
|
|
|
{
|
|
|
|
printf
|
|
|
|
("can't use LBA partition without LBA support - part %s FS %02x",
|
|
|
|
partitionName, pEntry->FileSystem);
|
|
|
|
|
|
|
|
printCHS(" start ", &chs);
|
|
|
|
printCHS(", end ", &end);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
if (!InitKernelConfig.ForceLBA && !ExtLBAForce
|
2001-11-18 15:01:12 +01:00
|
|
|
&& !IsLBAPartition(pEntry->FileSystem))
|
|
|
|
{
|
|
|
|
printf
|
|
|
|
("WARNING: Partition ID does not suggest LBA - part %s FS %02x.\n"
|
|
|
|
"Please run FDISK to correct this - using LBA to access partition.\n",
|
|
|
|
partitionName, pEntry->FileSystem);
|
|
|
|
|
|
|
|
printCHS(" start ", &chs);
|
|
|
|
printCHS(", end ", &end);
|
|
|
|
printf("\n");
|
|
|
|
pEntry->FileSystem = (pEntry->FileSystem == FAT12 ? FAT12_LBA :
|
|
|
|
pEntry->FileSystem == FAT32 ? FAT32_LBA :
|
|
|
|
/* pEntry->FileSystem == FAT16 ? */
|
|
|
|
FAT16_LBA);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* else its a diagnostic message only */
|
2001-11-04 20:47:39 +01:00
|
|
|
#ifdef DEBUG
|
2001-11-18 15:01:12 +01:00
|
|
|
printf("found and using LBA partition %s FS %02x",
|
|
|
|
partitionName, pEntry->FileSystem);
|
|
|
|
printCHS(" start ", &chs);
|
|
|
|
printCHS(", end ", &end);
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/*
|
|
|
|
here we have a partition table in our hand !!
|
|
|
|
*/
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
partitionsToIgnore |= 1 << i;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
DosDefinePartition(driveParam, partitionStart, pEntry,
|
|
|
|
extendedPartNo, i);
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (scan_type == SCAN_PRIMARYBOOT || scan_type == SCAN_PRIMARY)
|
|
|
|
{
|
|
|
|
return partitionsToIgnore;
|
|
|
|
}
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
return partitionsToIgnore;
|
2001-07-10 00:19:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BIOS_drive_reset(unsigned drive);
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
int Read1LBASector(struct DriveParamS *driveParam, unsigned drive,
|
2003-06-15 20:40:03 +02:00
|
|
|
ULONG LBA_address, void * buffer)
|
2001-07-10 00:19:33 +02:00
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
static struct _bios_LBA_address_packet dap = {
|
|
|
|
16, 0, 0, 0, 0, 0, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CHS chs;
|
|
|
|
iregs regs;
|
|
|
|
int num_retries;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-07-22 03:58:58 +02:00
|
|
|
/* disabled because this should not happen and if it happens the BIOS
|
|
|
|
should complain; also there are weird disks around with
|
|
|
|
CMOS geometry < real geometry */
|
|
|
|
#if 0
|
2001-11-18 15:01:12 +01:00
|
|
|
if (LBA_address >= driveParam->total_sectors)
|
|
|
|
{
|
|
|
|
printf("LBA-Transfer error : address overflow = %lu > %lu max\n",
|
|
|
|
LBA_address + 1, driveParam->total_sectors);
|
|
|
|
return 1;
|
|
|
|
}
|
2001-07-22 03:58:58 +02:00
|
|
|
#endif
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
for (num_retries = 0; num_retries < N_RETRY; num_retries++)
|
|
|
|
{
|
|
|
|
regs.d.b.l = drive | 0x80;
|
2004-04-13 12:54:33 +02:00
|
|
|
if (driveParam->descflags & DF_LBA)
|
2001-11-18 15:01:12 +01:00
|
|
|
{
|
|
|
|
dap.number_of_blocks = 1;
|
|
|
|
dap.buffer_address = buffer;
|
|
|
|
dap.block_address_high = 0; /* clear high part */
|
|
|
|
dap.block_address = LBA_address; /* clear high part */
|
|
|
|
|
|
|
|
/* Load the registers and call the interrupt. */
|
|
|
|
regs.a.x = LBA_READ;
|
|
|
|
regs.si = FP_OFF(&dap);
|
|
|
|
regs.ds = FP_SEG(&dap);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* transfer data, using old bios functions */
|
2002-10-22 04:40:19 +02:00
|
|
|
LBA_to_CHS(&chs, LBA_address, driveParam);
|
2001-11-18 15:01:12 +01:00
|
|
|
/* avoid overflow at end of track */
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (chs.Cylinder > 1023)
|
|
|
|
{
|
|
|
|
printf("LBA-Transfer error : cylinder %u > 1023\n", chs.Cylinder);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
regs.a.x = 0x0201;
|
|
|
|
regs.b.x = FP_OFF(buffer);
|
|
|
|
regs.c.x =
|
|
|
|
((chs.Cylinder & 0xff) << 8) + ((chs.Cylinder & 0x300) >> 2) +
|
|
|
|
chs.Sector;
|
|
|
|
regs.d.b.h = chs.Head;
|
|
|
|
regs.es = FP_SEG(buffer);
|
|
|
|
} /* end of retries */
|
|
|
|
init_call_intr(0x13, ®s);
|
|
|
|
if ((regs.flags & FLG_CARRY) == 0)
|
|
|
|
break;
|
|
|
|
BIOS_drive_reset(driveParam->driveno);
|
|
|
|
}
|
|
|
|
|
|
|
|
return regs.flags & FLG_CARRY ? 1 : 0;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
|
|
|
/* Load the Partition Tables and get information on all drives */
|
|
|
|
int ProcessDisk(int scanType, unsigned drive, int PartitionsToIgnore)
|
|
|
|
{
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
struct PartTableEntry PTable[4];
|
|
|
|
ULONG RelSectorOffset;
|
|
|
|
ULONG ExtendedPartitionOffset;
|
|
|
|
int iPart;
|
|
|
|
int strangeHardwareLoop;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
int num_extended_found = 0;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
struct DriveParamS driveParam;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* Get the hard drive parameters and ensure that the drive exists. */
|
|
|
|
/* If there was an error accessing the drive, skip that drive. */
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (!LBA_Get_Drive_Parameters(drive, &driveParam))
|
|
|
|
{
|
|
|
|
printf("can't get drive parameters for drive %02x\n", drive);
|
|
|
|
return PartitionsToIgnore;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
RelSectorOffset = 0; /* boot sector */
|
|
|
|
ExtendedPartitionOffset = 0; /* not found yet */
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* Read the Primary Partition Table. */
|
2001-07-10 00:19:33 +02:00
|
|
|
|
|
|
|
ReadNextPartitionTable:
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
strangeHardwareLoop = 0;
|
2001-07-10 00:19:33 +02:00
|
|
|
strange_restart:
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (Read1LBASector
|
2003-06-15 20:40:03 +02:00
|
|
|
(&driveParam, drive, RelSectorOffset, InitDiskTransferBuffer))
|
2001-11-18 15:01:12 +01:00
|
|
|
{
|
|
|
|
printf("Error reading partition table drive %02x sector %lu", drive,
|
|
|
|
RelSectorOffset);
|
|
|
|
return PartitionsToIgnore;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2003-06-15 20:40:03 +02:00
|
|
|
if (!ConvPartTableEntryToIntern(PTable, InitDiskTransferBuffer))
|
2001-11-18 15:01:12 +01:00
|
|
|
{
|
|
|
|
/* there is some strange hardware out in the world,
|
|
|
|
which returns OK on first read, but the data are
|
|
|
|
rubbish. simply retrying works fine.
|
|
|
|
there is no logic behind this, but it works TE */
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (++strangeHardwareLoop < 3)
|
|
|
|
goto strange_restart;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
printf("illegal partition table - drive %02x sector %lu\n", drive,
|
|
|
|
RelSectorOffset);
|
|
|
|
return PartitionsToIgnore;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (scanType == SCAN_PRIMARYBOOT ||
|
|
|
|
scanType == SCAN_PRIMARY ||
|
|
|
|
scanType == SCAN_PRIMARY2 || num_extended_found != 0)
|
|
|
|
{
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
PartitionsToIgnore = ScanForPrimaryPartitions(&driveParam, scanType,
|
|
|
|
PTable, RelSectorOffset,
|
|
|
|
PartitionsToIgnore,
|
|
|
|
num_extended_found);
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (scanType != SCAN_EXTENDED)
|
|
|
|
{
|
|
|
|
return PartitionsToIgnore;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* scan for extended partitions now */
|
|
|
|
PartitionsToIgnore = 0;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
for (iPart = 0; iPart < 4; iPart++)
|
|
|
|
{
|
|
|
|
if (IsExtPartition(PTable[iPart].FileSystem))
|
|
|
|
{
|
|
|
|
RelSectorOffset = ExtendedPartitionOffset + PTable[iPart].RelSect;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (ExtendedPartitionOffset == 0)
|
|
|
|
{
|
|
|
|
ExtendedPartitionOffset = PTable[iPart].RelSect;
|
2002-01-23 23:29:41 +01:00
|
|
|
/* grand parent LBA -> all children and grandchildren LBA */
|
|
|
|
ExtLBAForce = (PTable[iPart].FileSystem == EXTENDED_LBA);
|
2001-11-18 15:01:12 +01:00
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
num_extended_found++;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (num_extended_found > 30)
|
|
|
|
{
|
|
|
|
printf("found more then 30 extended partitions, terminated\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
goto ReadNextPartitionTable;
|
2001-07-10 00:19:33 +02:00
|
|
|
}
|
2001-11-18 15:01:12 +01:00
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
return PartitionsToIgnore;
|
2001-07-10 00:19:33 +02:00
|
|
|
}
|
|
|
|
|
2001-07-22 03:58:58 +02:00
|
|
|
int BIOS_nrdrives(void)
|
2001-07-10 00:19:33 +02:00
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
iregs regs;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
regs.a.b.h = 0x08;
|
|
|
|
regs.d.b.l = 0x80;
|
|
|
|
init_call_intr(0x13, ®s);
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (regs.flags & 1)
|
|
|
|
{
|
|
|
|
printf("no hard disks detected\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
return regs.d.b.l;
|
2001-07-10 00:19:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BIOS_drive_reset(unsigned drive)
|
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
iregs regs;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
regs.d.b.l = drive | 0x80;
|
|
|
|
regs.a.b.h = 0;
|
|
|
|
|
|
|
|
init_call_intr(0x13, ®s);
|
2001-07-10 00:19:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
thats what MSDN says:
|
|
|
|
|
|
|
|
How Windows 2000 Assigns, Reserves, and Stores Drive Letters
|
|
|
|
ID: q234048
|
|
|
|
|
|
|
|
BASIC Disk - Drive Letter Assignment Rules
|
|
|
|
The following are the basic disk drive letter assignment rules for Windows 2000:
|
|
|
|
Scan all fixed hard disks as they are enumerated, assign drive letters
|
|
|
|
starting with any active primary partitions (if there is one), otherwise,
|
|
|
|
scan the first primary partition on each drive. Assign next available
|
|
|
|
letter starting with C:
|
|
|
|
|
|
|
|
Repeat scan for all fixed hard disks and removable (JAZ, MO) disks
|
|
|
|
and assign drive letters to all logical drives in an extended partition,
|
|
|
|
or the removable disk(s) as enumerated. Assign next available letter
|
|
|
|
starting with C:
|
|
|
|
|
|
|
|
Finally, repeat scan for all fixed hard disk drives, and assign drive
|
|
|
|
letters to all remaining primary partitions. Assign next available letter
|
|
|
|
starting with C:
|
|
|
|
|
|
|
|
Floppy drives. Assign letter starting with A:
|
|
|
|
|
|
|
|
CD-ROM drives. Assign next available letter starting with D:
|
|
|
|
|
|
|
|
*************************************************************************
|
|
|
|
Order in Which MS-DOS and Windows Assign Drive Letters
|
|
|
|
ID: q51978
|
|
|
|
|
|
|
|
MORE INFORMATION
|
|
|
|
The following occurs at startup:
|
|
|
|
|
|
|
|
MS-DOS checks all installed disk devices, assigning the drive letter A
|
|
|
|
to the first physical floppy disk drive that is found.
|
|
|
|
|
|
|
|
If a second physical floppy disk drive is present, it is assigned drive letter B. If it is not present, a logical drive B is created that uses the first physical floppy disk drive.
|
|
|
|
|
|
|
|
Regardless of whether a second floppy disk drive is present,
|
|
|
|
MS-DOS then assigns the drive letter C to the primary MS-DOS
|
|
|
|
partition on the first physical hard disk, and then goes on
|
|
|
|
to check for a second hard disk.
|
|
|
|
|
|
|
|
If a second physical hard disk is found, and a primary partition exists
|
|
|
|
on the second physical drive, the primary MS-DOS partition on the second
|
|
|
|
physical hard drive is assigned the letter D. MS-DOS version 5.0, which
|
|
|
|
supports up to eight physical drives, will continue to search for more
|
|
|
|
physical hard disk drives at this point. For example, if a third physical
|
|
|
|
hard disk is found, and a primary partition exists on the third physical
|
|
|
|
drive, the primary MS-DOS partition on the third physical hard drive is
|
|
|
|
assigned the letter E.
|
|
|
|
|
|
|
|
MS-DOS returns to the first physical hard disk drive and assigns drive
|
|
|
|
letters to any additional logical drives (in extended MS-DOS partitions)
|
|
|
|
on that drive in sequence.
|
|
|
|
|
|
|
|
MS-DOS repeats this process for the second physical hard disk drive,
|
|
|
|
if present. MS-DOS 5.0 will repeat this process for up to eight physical
|
|
|
|
hard drives, if present. After all logical drives (in extended MS-DOS
|
|
|
|
partitions) have been assigned drive letters, MS-DOS 5.0 returns to
|
|
|
|
the first physical drive and assigns drive letters to any other primary
|
|
|
|
MS-DOS partitions that exist, then searches other physical drives for
|
|
|
|
additional primary MS-DOS partitions. This support for multiple primary
|
|
|
|
MS-DOS partitions was added to version 5.0 for backward compatibility
|
|
|
|
with the previous OEM MS-DOS versions that support multiple primary partitions.
|
|
|
|
|
|
|
|
After all logical drives on the hard disk(s) have been assigned drive
|
|
|
|
letters, drive letters are assigned to drives installed using DRIVER.SYS
|
|
|
|
or created using RAMDRIVE.SYS in the order in which the drivers are loaded
|
|
|
|
in the CONFIG.SYS file. Which drive letters are assigned to which devices
|
|
|
|
can be influenced by changing the order of the device drivers or, if necessary,
|
|
|
|
by creating "dummy" drive letters with DRIVER.SYS.
|
|
|
|
|
|
|
|
********************************************************
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
as rather well documented, DOS searches 1st) 1 primary patitions on
|
|
|
|
all drives, 2nd) all extended partitions. that
|
|
|
|
makes many people (including me) unhappy, as all DRIVES D:,E:...
|
|
|
|
on 1st disk will move up/down, if other disk with
|
|
|
|
primary partitions are added/removed, but
|
|
|
|
thats the way it is (hope I got it right)
|
|
|
|
TE (with a little help from my friends)
|
|
|
|
see also above for WIN2000,DOS,MSDN
|
|
|
|
|
|
|
|
I don't know, if I did it right, but I tried to do it that way. TE
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
2004-05-25 21:24:55 +02:00
|
|
|
STATIC void make_ddt (ddt *pddt, int Unit, int driveno, int flags)
|
|
|
|
{
|
|
|
|
pddt->ddt_next = MK_FP(0, 0xffff);
|
|
|
|
pddt->ddt_logdriveno = Unit;
|
|
|
|
pddt->ddt_driveno = driveno;
|
|
|
|
pddt->ddt_type = init_getdriveparm(driveno, &pddt->ddt_defbpb);
|
|
|
|
pddt->ddt_ncyl = (pddt->ddt_type & 7) ? 80 : 40;
|
|
|
|
pddt->ddt_descflags = init_readdasd(driveno) | flags;
|
|
|
|
|
|
|
|
pddt->ddt_offset = 0;
|
|
|
|
pddt->ddt_serialno = 0x12345678l;
|
|
|
|
memcpy(&pddt->ddt_bpb, &pddt->ddt_defbpb, sizeof(bpb));
|
|
|
|
push_ddt(pddt);
|
|
|
|
}
|
|
|
|
|
2001-07-10 00:19:33 +02:00
|
|
|
void ReadAllPartitionTables(void)
|
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
UBYTE foundPartitions[MAX_HARD_DRIVE];
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
int HardDrive;
|
2004-05-25 21:24:55 +02:00
|
|
|
int nHardDisk;
|
2004-04-09 17:39:56 +02:00
|
|
|
ddt nddt;
|
2001-11-18 15:01:12 +01:00
|
|
|
static iregs regs;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2002-05-09 00:49:35 +02:00
|
|
|
/* quick adjustment of diskette parameter table */
|
|
|
|
fmemcpy(int1e_table, *(char FAR * FAR *)MK_FP(0, 0x1e*4), sizeof(int1e_table));
|
|
|
|
/* enforce min. 9 sectors per track */
|
|
|
|
if (int1e_table[4] < 9)
|
|
|
|
int1e_table[4] = 9;
|
|
|
|
/* and adjust int1e */
|
|
|
|
setvec(0x1e, (intvec)int1e_table);
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* Setup media info and BPBs arrays for floppies */
|
2004-05-25 21:24:55 +02:00
|
|
|
make_ddt(&nddt, 0, 0, 0);
|
2002-08-03 04:37:59 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/*
|
|
|
|
this is a quick patch - see if B: exists
|
|
|
|
test for A: also, need not exist
|
|
|
|
*/
|
|
|
|
init_call_intr(0x11, ®s); /* get equipment list */
|
2004-05-25 21:24:55 +02:00
|
|
|
/*if ((regs.AL & 1)==0)*//* no floppy drives installed */
|
|
|
|
if ((regs.AL & 1) && (regs.AL & 0xc0))
|
2001-11-18 15:01:12 +01:00
|
|
|
{
|
|
|
|
/* floppy drives installed and a B: drive */
|
2004-05-25 21:24:55 +02:00
|
|
|
make_ddt(&nddt, 1, 1, 0);
|
2001-11-18 15:01:12 +01:00
|
|
|
}
|
|
|
|
else
|
2004-05-25 21:24:55 +02:00
|
|
|
{
|
|
|
|
/* set up the DJ method : multiple logical drives */
|
|
|
|
make_ddt(&nddt, 1, 0, DF_MULTLOG);
|
2001-11-18 15:01:12 +01:00
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2004-05-25 21:24:55 +02:00
|
|
|
/* Initial number of disk units */
|
|
|
|
nUnits = 2;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2004-05-25 21:24:55 +02:00
|
|
|
nHardDisk = BIOS_nrdrives();
|
|
|
|
if (nHardDisk > LENGTH(foundPartitions))
|
|
|
|
nHardDisk = LENGTH(foundPartitions);
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
DebugPrintf(("DSK init: found %d disk drives\n", nHardDisk));
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* Reset the drives */
|
|
|
|
for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++)
|
2004-05-25 21:24:55 +02:00
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
BIOS_drive_reset(HardDrive);
|
2004-05-25 21:24:55 +02:00
|
|
|
foundPartitions[HardDrive] = 0;
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (InitKernelConfig.DLASortByDriveNo == 0)
|
|
|
|
{
|
2004-05-25 21:24:55 +02:00
|
|
|
/* printf("Drive Letter Assignment - DOS order\n"); */
|
2001-07-10 00:19:33 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* Process primary partition table 1 partition only */
|
2001-07-10 00:19:33 +02:00
|
|
|
for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++)
|
2001-11-18 15:01:12 +01:00
|
|
|
{
|
|
|
|
foundPartitions[HardDrive] =
|
|
|
|
ProcessDisk(SCAN_PRIMARYBOOT, HardDrive, 0);
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (foundPartitions[HardDrive] == 0)
|
|
|
|
foundPartitions[HardDrive] =
|
|
|
|
ProcessDisk(SCAN_PRIMARY, HardDrive, 0);
|
|
|
|
}
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* Process extended partition table */
|
|
|
|
for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++)
|
2001-07-10 00:19:33 +02:00
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
ProcessDisk(SCAN_EXTENDED, HardDrive, 0);
|
2001-07-10 00:19:33 +02:00
|
|
|
}
|
2001-11-18 15:01:12 +01:00
|
|
|
|
|
|
|
/* Process primary a 2nd time */
|
|
|
|
for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++)
|
2001-07-10 00:19:33 +02:00
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
ProcessDisk(SCAN_PRIMARY2, HardDrive, foundPartitions[HardDrive]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-25 21:24:55 +02:00
|
|
|
UBYTE bootdrv = peekb(0,0x5e0);
|
2003-09-18 22:57:53 +02:00
|
|
|
|
|
|
|
/* printf("Drive Letter Assignment - sorted by drive\n"); */
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* Process primary partition table 1 partition only */
|
|
|
|
for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++)
|
|
|
|
{
|
2004-05-25 21:24:55 +02:00
|
|
|
struct DriveParamS driveParam;
|
|
|
|
if (LBA_Get_Drive_Parameters(HardDrive, &driveParam) &&
|
|
|
|
driveParam.driveno == bootdrv)
|
2003-09-18 22:57:53 +02:00
|
|
|
{
|
2004-05-25 21:24:55 +02:00
|
|
|
foundPartitions[HardDrive] =
|
|
|
|
ProcessDisk(SCAN_PRIMARYBOOT, HardDrive, 0);
|
|
|
|
break;
|
2003-09-18 22:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++)
|
|
|
|
{
|
|
|
|
if (foundPartitions[HardDrive] == 0)
|
2004-05-25 21:24:55 +02:00
|
|
|
{
|
2003-09-18 22:57:53 +02:00
|
|
|
foundPartitions[HardDrive] =
|
2001-11-18 15:01:12 +01:00
|
|
|
ProcessDisk(SCAN_PRIMARYBOOT, HardDrive, 0);
|
|
|
|
|
2004-05-25 21:24:55 +02:00
|
|
|
if (foundPartitions[HardDrive] == 0)
|
|
|
|
foundPartitions[HardDrive] =
|
2001-11-18 15:01:12 +01:00
|
|
|
ProcessDisk(SCAN_PRIMARY, HardDrive, 0);
|
2004-05-25 21:24:55 +02:00
|
|
|
}
|
2001-11-18 15:01:12 +01:00
|
|
|
|
|
|
|
/* Process extended partition table */
|
|
|
|
ProcessDisk(SCAN_EXTENDED, HardDrive, 0);
|
|
|
|
|
|
|
|
/* Process primary a 2nd time */
|
|
|
|
ProcessDisk(SCAN_PRIMARY2, HardDrive, foundPartitions[HardDrive]);
|
|
|
|
}
|
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* disk initialization: returns number of units */
|
|
|
|
COUNT dsk_init()
|
|
|
|
{
|
2002-05-09 00:49:35 +02:00
|
|
|
printf(" - InitDisk");
|
2001-07-10 00:19:33 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-11-18 15:01:12 +01:00
|
|
|
{
|
2001-07-10 00:19:33 +02:00
|
|
|
iregs regs;
|
2001-11-18 15:01:12 +01:00
|
|
|
regs.a.x = 0x1112; /* select 43 line mode - more space for partinfo */
|
2001-07-10 00:19:33 +02:00
|
|
|
regs.b.x = 0;
|
|
|
|
init_call_intr(0x10, ®s);
|
2001-11-18 15:01:12 +01:00
|
|
|
}
|
2001-07-10 00:19:33 +02:00
|
|
|
#endif
|
2001-11-18 15:01:12 +01:00
|
|
|
|
2001-07-10 00:19:33 +02:00
|
|
|
/* Reset the drives */
|
|
|
|
BIOS_drive_reset(0);
|
|
|
|
|
|
|
|
ReadAllPartitionTables();
|
|
|
|
|
|
|
|
return nUnits;
|
|
|
|
}
|