If no floppy drives present, don't initialise DDT for drive A:.

" - Initdisk" no longer shifts text if no FAT partitions found.
Converted cdiv() from macro to function; optimise and clean-up.


git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/branches/UNSTABLE@1026 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
Luchezar Georgiev 2004-09-07 14:15:49 +00:00
parent 463535c87d
commit a9c8174b5d
3 changed files with 70 additions and 113 deletions

View File

@ -319,6 +319,10 @@
- optimisation and clean-up - optimisation and clean-up
* fattab.c: ISFAT32 function removed (now macro), "wasfree" optimised * fattab.c: ISFAT32 function removed (now macro), "wasfree" optimised
* globals.h: __TIME__ removed - no two kernels released on same day * globals.h: __TIME__ removed - no two kernels released on same day
* initdisk.c:
- if no floppy drives present, don't initialise DDT for drive A:
- " - Initdisk" no longer shifts text if no FAT partitions found
- converted cdiv() from macro to function; optimise and clean-up
* intr.asm: lseek() added (necessary for COUNTRY.SYS processing) * intr.asm: lseek() added (necessary for COUNTRY.SYS processing)
* ioctl.c: * ioctl.c:
- r_si/r_di contents added as documented in PC-DOS Technical Update - r_si/r_di contents added as documented in PC-DOS Technical Update

View File

@ -151,20 +151,12 @@ COUNT nUnits BSS_INIT(0);
/* #define DEBUG */ /* #define DEBUG */
#define _BETA_ /* messages for initial phase only */
#if defined(DEBUG) #if defined(DEBUG)
#define DebugPrintf(x) printf x #define DebugPrintf(x) printf x
#else #else
#define DebugPrintf(x) #define DebugPrintf(x)
#endif #endif
#if defined(_BETA_)
#define BetaPrintf(x) printf x
#else
#define BetaPrintf(x)
#endif
#define LBA_to_CHS init_LBA_to_CHS #define LBA_to_CHS init_LBA_to_CHS
/* /*
@ -272,7 +264,7 @@ COUNT init_readdasd(UBYTE drive)
regs.a.b.h = 0x15; regs.a.b.h = 0x15;
regs.d.b.l = drive; regs.d.b.l = drive;
init_call_intr(0x13, &regs); init_call_intr(0x13, &regs);
if ((regs.flags & 1) == 0) if ((regs.flags & FLG_CARRY) == 0)
switch (regs.a.b.h) switch (regs.a.b.h)
{ {
case 2: case 2:
@ -316,7 +308,7 @@ COUNT init_getdriveparm(UBYTE drive, bpb * pbpbarray)
regs.d.b.l = drive; regs.d.b.l = drive;
init_call_intr(0x13, &regs); init_call_intr(0x13, &regs);
type = regs.b.b.l - 1; type = regs.b.b.l - 1;
if (regs.flags & 1) if (regs.flags & FLG_CARRY)
type = 0; /* return 320-360 for XTs */ type = 0; /* return 320-360 for XTs */
else if (type > 6) else if (type > 6)
type = 8; /* any odd ball drives get 8&7=0: the 320-360 table */ type = 8; /* any odd ball drives get 8&7=0: the 320-360 table */
@ -340,7 +332,7 @@ COUNT init_getdriveparm(UBYTE drive, bpb * pbpbarray)
copied and pasted from dsk.c! copied and pasted from dsk.c!
*/ */
void init_LBA_to_CHS(struct CHS *chs, ULONG LBA_address, void LBA_to_CHS(struct CHS *chs, ULONG LBA_address,
struct DriveParamS *driveparam) struct DriveParamS *driveparam)
{ {
unsigned hs = driveparam->chs.Sector * driveparam->chs.Head; unsigned hs = driveparam->chs.Sector * driveparam->chs.Head;
@ -368,7 +360,10 @@ void printCHS(char *title, struct CHS *chs)
*/ */
/* Compute ceil(a/b) */ /* Compute ceil(a/b) */
#define cdiv(a, b) (((a) + (b) - 1) / (b)) STATIC UWORD cdiv(ULONG a, UWORD b)
{
return (UWORD)((a + b - 1) / b);
}
/* calculates FAT data: /* calculates FAT data:
code adapted by Bart Oldeman from mkdosfs from the Linux dosfstools: code adapted by Bart Oldeman from mkdosfs from the Linux dosfstools:
@ -386,12 +381,16 @@ VOID CalculateFATData(ddt * pddt, ULONG NumSectors, UBYTE FileSystem)
/* FAT related items */ /* FAT related items */
defbpb->bpb_nfat = 2; defbpb->bpb_nfat = 2;
defbpb->bpb_ndirent = (FileSystem == FAT32 if (FileSystem == FAT32 || FileSystem == FAT32_LBA)
|| FileSystem == FAT32_LBA) ? 0 : 512; {
/* normal value of number of entries in root dir */ defbpb->bpb_ndirent = 0;
defbpb->bpb_nreserved = (FileSystem == FAT32 defbpb->bpb_nreserved = 0x20;
|| FileSystem == FAT32_LBA) ? 0x20 : 1; }
else
{
defbpb->bpb_ndirent = 512;
defbpb->bpb_nreserved = 1;
}
fatdata = fatdata =
NumSectors - cdiv(defbpb->bpb_ndirent * DIRENT_SIZE, NumSectors - cdiv(defbpb->bpb_ndirent * DIRENT_SIZE,
defbpb->bpb_nbyte) - defbpb->bpb_nreserved; defbpb->bpb_nbyte) - defbpb->bpb_nreserved;
@ -418,8 +417,7 @@ VOID CalculateFATData(ddt * pddt, ULONG NumSectors, UBYTE FileSystem)
fatdat = 32640; fatdat = 32640;
/* The "+2*defbpb->bpb_nsector" is for the reserved first two FAT entries */ /* The "+2*defbpb->bpb_nsector" is for the reserved first two FAT entries */
fatlength = cdiv(fatdat + 2 * defbpb->bpb_nsector, fatlength = cdiv(fatdat + 2 * defbpb->bpb_nsector,
defbpb->bpb_nbyte * 2 * defbpb->bpb_nsector / 3 + defbpb->bpb_nbyte * 2 * defbpb->bpb_nsector / 3 + defbpb->bpb_nfat);
defbpb->bpb_nfat);
/* Need to calculate number of clusters, since the unused parts of the /* Need to calculate number of clusters, since the unused parts of the
* FATS and data area together could make up space for an additional, * FATS and data area together could make up space for an additional,
* not really present cluster. */ * not really present cluster. */
@ -459,9 +457,8 @@ VOID CalculateFATData(ddt * pddt, ULONG NumSectors, UBYTE FileSystem)
DebugPrintf(("Trying with %d sectors/cluster:\n", DebugPrintf(("Trying with %d sectors/cluster:\n",
defbpb->bpb_nsector)); defbpb->bpb_nsector));
fatlength = (unsigned)cdiv(fatdata + 2 * defbpb->bpb_nsector, fatlength = cdiv(fatdata + 2 * defbpb->bpb_nsector,
(ULONG)defbpb->bpb_nbyte * defbpb->bpb_nsector / 2 + defbpb->bpb_nbyte * defbpb->bpb_nsector / 2 + defbpb->bpb_nfat);
defbpb->bpb_nfat);
/* Need to calculate number of clusters, since the unused parts of the /* Need to calculate number of clusters, since the unused parts of the
* FATS and data area together could make up space for an additional, * FATS and data area together could make up space for an additional,
* not really present cluster. */ * not really present cluster. */
@ -516,8 +513,7 @@ VOID CalculateFATData(ddt * pddt, ULONG NumSectors, UBYTE FileSystem)
do do
{ {
fatlength = cdiv(fatdata + 2 * defbpb->bpb_nsector, fatlength = cdiv(fatdata + 2 * defbpb->bpb_nsector,
(ULONG)defbpb->bpb_nbyte * defbpb->bpb_nsector / 4 + defbpb->bpb_nbyte * defbpb->bpb_nsector / 4 + defbpb->bpb_nfat);
defbpb->bpb_nfat);
/* Need to calculate number of clusters, since the unused parts of the /* Need to calculate number of clusters, since the unused parts of the
* FATS and data area together could make up space for an additional, * FATS and data area together could make up space for an additional,
* not really present cluster. */ * not really present cluster. */
@ -611,7 +607,6 @@ void DosDefinePartition(struct DriveParamS *driveParam,
/* sectors per cluster, sectors per FAT etc. */ /* sectors per cluster, sectors per FAT etc. */
CalculateFATData(pddt, pEntry->NumSect, pEntry->FileSystem); CalculateFATData(pddt, pEntry->NumSect, pEntry->FileSystem);
pddt->ddt_serialno = 0x12345678l;
/* drive inaccessible until bldbpb successful */ /* drive inaccessible until bldbpb successful */
pddt->ddt_descflags |= init_readdasd(pddt->ddt_driveno) | DF_NOACCESS; pddt->ddt_descflags |= init_readdasd(pddt->ddt_driveno) | DF_NOACCESS;
pddt->ddt_type = 5; pddt->ddt_type = 5;
@ -637,7 +632,7 @@ void DosDefinePartition(struct DriveParamS *driveParam,
ExtPri = "Ext"; ExtPri = "Ext";
num = extendedPartNo; num = extendedPartNo;
} }
printf("\r%c: HD%d, %s[%2d]", 'A' + nUnits, printf("%c: HD%d, %s[%2d]", 'A' + nUnits,
(driveParam->driveno & 0x7f) + 1, ExtPri, num); (driveParam->driveno & 0x7f) + 1, ExtPri, num);
printCHS(", CHS= ", &chs); printCHS(", CHS= ", &chs);
@ -673,7 +668,7 @@ STATIC int LBA_Get_Drive_Parameters(int drive, struct DriveParamS *driveParam)
init_call_intr(0x13, &regs); init_call_intr(0x13, &regs);
if (regs.b.x != 0xaa55 || (regs.flags & 0x01)) if (regs.b.x != 0xaa55 || (regs.flags & FLG_CARRY))
{ {
goto StandardBios; goto StandardBios;
} }
@ -703,7 +698,7 @@ STATIC int LBA_Get_Drive_Parameters(int drive, struct DriveParamS *driveParam)
init_call_intr(0x13, &regs); init_call_intr(0x13, &regs);
/* error or DMA boundary errors not handled transparently */ /* error or DMA boundary errors not handled transparently */
if (regs.flags & 0x01) if (regs.flags & FLG_CARRY)
{ {
goto StandardBios; goto StandardBios;
} }
@ -739,7 +734,7 @@ StandardBios: /* old way to get parameters */
init_call_intr(0x13, &regs); init_call_intr(0x13, &regs);
if (regs.flags & 0x01) if (regs.flags & FLG_CARRY)
goto ErrorReturn; goto ErrorReturn;
driveParam->chs.Head = (regs.d.x >> 8) + 1; driveParam->chs.Head = (regs.d.x >> 8) + 1;
@ -954,17 +949,12 @@ BOOL ScanForPrimaryPartitions(struct DriveParamS * driveParam, int scan_type,
extendedPartNo, i); extendedPartNo, i);
if (scan_type == SCAN_PRIMARYBOOT || scan_type == SCAN_PRIMARY) if (scan_type == SCAN_PRIMARYBOOT || scan_type == SCAN_PRIMARY)
{ break;
return partitionsToIgnore;
} }
}
return partitionsToIgnore; return partitionsToIgnore;
} }
void BIOS_drive_reset(unsigned drive); BOOL Read1LBASector(struct DriveParamS *driveParam, unsigned drive,
int Read1LBASector(struct DriveParamS *driveParam, unsigned drive,
ULONG LBA_address, void * buffer) ULONG LBA_address, void * buffer)
{ {
static struct _bios_LBA_address_packet dap = { static struct _bios_LBA_address_packet dap = {
@ -1023,11 +1013,11 @@ int Read1LBASector(struct DriveParamS *driveParam, unsigned drive,
} /* end of retries */ } /* end of retries */
init_call_intr(0x13, &regs); init_call_intr(0x13, &regs);
if ((regs.flags & FLG_CARRY) == 0) if ((regs.flags & FLG_CARRY) == 0)
break; return 0;
BIOS_drive_reset(driveParam->driveno); regs.a.b.h = 0xD;
init_call_intr(0x13, &regs); /* reset hard disk */
} }
return 1;
return regs.flags & FLG_CARRY ? 1 : 0;
} }
/* Load the Partition Tables and get information on all drives */ /* Load the Partition Tables and get information on all drives */
@ -1141,7 +1131,7 @@ int BIOS_nrdrives(void)
regs.d.b.l = 0x80; regs.d.b.l = 0x80;
init_call_intr(0x13, &regs); init_call_intr(0x13, &regs);
if (regs.flags & 1) if (regs.flags & FLG_CARRY)
{ {
printf("no hard disks detected\n"); printf("no hard disks detected\n");
return 0; return 0;
@ -1150,16 +1140,6 @@ int BIOS_nrdrives(void)
return regs.d.b.l; return regs.d.b.l;
} }
void BIOS_drive_reset(unsigned drive)
{
iregs regs;
regs.d.b.l = drive | 0x80;
regs.a.b.h = 0;
init_call_intr(0x13, &regs);
}
/* /*
thats what MSDN says: thats what MSDN says:
@ -1196,7 +1176,9 @@ The following occurs at startup:
MS-DOS checks all installed disk devices, assigning the drive letter A MS-DOS checks all installed disk devices, assigning the drive letter A
to the first physical floppy disk drive that is found. 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. 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, Regardless of whether a second floppy disk drive is present,
MS-DOS then assigns the drive letter C to the primary MS-DOS MS-DOS then assigns the drive letter C to the primary MS-DOS
@ -1260,20 +1242,29 @@ STATIC void make_ddt (ddt *pddt, int Unit, int driveno, int flags)
pddt->ddt_descflags = init_readdasd(driveno) | flags; pddt->ddt_descflags = init_readdasd(driveno) | flags;
pddt->ddt_offset = 0; pddt->ddt_offset = 0;
pddt->ddt_serialno = 0x12345678l;
memcpy(&pddt->ddt_bpb, &pddt->ddt_defbpb, sizeof(bpb)); memcpy(&pddt->ddt_bpb, &pddt->ddt_defbpb, sizeof(bpb));
push_ddt(pddt); push_ddt(pddt);
} }
void ReadAllPartitionTables(void) /* disk initialization: returns number of units */
COUNT dsk_init()
{ {
UBYTE foundPartitions[MAX_HARD_DRIVE]; static UBYTE foundPartitions[MAX_HARD_DRIVE] = {0};
int HardDrive; int HardDrive;
int nHardDisk; int nHardDisk;
ddt nddt; ddt nddt;
static iregs regs; static iregs regs;
printf(" - InitDisk\r");
#ifdef DEBUG
{
regs.a.x = 0x1112; /* select 43 line mode - more space for partinfo */
regs.b.x = 0;
init_call_intr(0x10, &regs);
}
#endif
/* quick adjustment of diskette parameter table */ /* quick adjustment of diskette parameter table */
fmemcpy(int1e_table, *(char FAR * FAR *)MK_FP(0, 0x1e*4), sizeof(int1e_table)); fmemcpy(int1e_table, *(char FAR * FAR *)MK_FP(0, 0x1e*4), sizeof(int1e_table));
/* enforce min. 9 sectors per track */ /* enforce min. 9 sectors per track */
@ -1283,41 +1274,26 @@ void ReadAllPartitionTables(void)
setvec(0x1e, (intvec)int1e_table); setvec(0x1e, (intvec)int1e_table);
/* Setup media info and BPBs arrays for floppies */ /* Setup media info and BPBs arrays for floppies */
make_ddt(&nddt, 0, 0, 0);
/*
this is a quick patch - see if B: exists
test for A: also, need not exist
*/
init_call_intr(0x11, &regs); /* get equipment list */ init_call_intr(0x11, &regs); /* get equipment list */
/*if ((regs.AL & 1)==0)*//* no floppy drives installed */ if (regs.AL & 1) /* at least one floppy drive installed */
if ((regs.AL & 1) && (regs.AL & 0xc0))
{ {
/* floppy drives installed and a B: drive */ make_ddt(&nddt, 0, 0, 0);
make_ddt(&nddt, 1, 1, 0); if (regs.AL & 0xC0) /* more than one floppy */
} make_ddt(&nddt, 1, 1, 0); /* real B: drive */
else else
{ make_ddt(&nddt, 1, 0, DF_MULTLOG); /* phantom B: drive */
/* set up the DJ method : multiple logical drives */
make_ddt(&nddt, 1, 0, DF_MULTLOG);
} }
/* Initial number of disk units */ /* Initial number of disk units */
nUnits = 2; nUnits = 2;
nHardDisk = BIOS_nrdrives(); nHardDisk = BIOS_nrdrives();
if (nHardDisk > LENGTH(foundPartitions)) if (nHardDisk > MAX_HARD_DRIVE)
nHardDisk = LENGTH(foundPartitions); nHardDisk = MAX_HARD_DRIVE;
DebugPrintf(("DSK init: found %d disk drives\n", nHardDisk)); DebugPrintf(("DSK init: found %d disk drives\n", nHardDisk));
/* Reset the drives */
for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++)
{
BIOS_drive_reset(HardDrive);
foundPartitions[HardDrive] = 0;
}
if (InitKernelConfig.DLASortByDriveNo == 0) if (InitKernelConfig.DLASortByDriveNo == 0)
{ {
/* printf("Drive Letter Assignment - DOS order\n"); */ /* printf("Drive Letter Assignment - DOS order\n"); */
@ -1347,8 +1323,6 @@ void ReadAllPartitionTables(void)
} }
else else
{ {
UBYTE bootdrv = peekb(0,0x5e0);
/* printf("Drive Letter Assignment - sorted by drive\n"); */ /* printf("Drive Letter Assignment - sorted by drive\n"); */
/* Process primary partition table 1 partition only */ /* Process primary partition table 1 partition only */
@ -1356,7 +1330,7 @@ void ReadAllPartitionTables(void)
{ {
struct DriveParamS driveParam; struct DriveParamS driveParam;
if (LBA_Get_Drive_Parameters(HardDrive, &driveParam) && if (LBA_Get_Drive_Parameters(HardDrive, &driveParam) &&
driveParam.driveno == bootdrv) driveParam.driveno == peekb(0,0x5e0))
{ {
foundPartitions[HardDrive] = foundPartitions[HardDrive] =
ProcessDisk(SCAN_PRIMARYBOOT, HardDrive, 0); ProcessDisk(SCAN_PRIMARYBOOT, HardDrive, 0);
@ -1383,26 +1357,5 @@ void ReadAllPartitionTables(void)
ProcessDisk(SCAN_PRIMARY2, HardDrive, foundPartitions[HardDrive]); ProcessDisk(SCAN_PRIMARY2, HardDrive, foundPartitions[HardDrive]);
} }
} }
}
/* disk initialization: returns number of units */
COUNT dsk_init()
{
printf(" - InitDisk");
#ifdef DEBUG
{
iregs regs;
regs.a.x = 0x1112; /* select 43 line mode - more space for partinfo */
regs.b.x = 0;
init_call_intr(0x10, &regs);
}
#endif
/* Reset the drives */
BIOS_drive_reset(0);
ReadAllPartitionTables();
return nUnits; return nUnits;
} }

View File

@ -59,10 +59,10 @@ STATIC COUNT joinMCBs(seg para)
while (p->m_type == MCB_NORMAL) while (p->m_type == MCB_NORMAL)
{ {
q = nxtMCB(p); q = nxtMCB(p);
if (!mcbFree(q))
break;
if (!mcbValid(q)) if (!mcbValid(q))
return DE_MCBDESTRY; return DE_MCBDESTRY;
if (!mcbFree(q))
break;
/* join both MCBs */ /* join both MCBs */
p->m_type = q->m_type; /* possibly the next MCB is the last one */ p->m_type = q->m_type; /* possibly the next MCB is the last one */
p->m_size += q->m_size + 1; /* one for q's MCB itself */ p->m_size += q->m_size + 1; /* one for q's MCB itself */
@ -119,7 +119,7 @@ searchAgain:
/* /*
Hack to the Umb Region direct for now. Save time and program space. Hack to the Umb Region direct for now. Save time and program space.
*/ */
if ((uppermem_link & 1) && uppermem_root != 0xffff) if (uppermem_link && uppermem_root != 0xffff)
{ {
COUNT tmpmode = (mode == LARGEST ? mem_access_mode : mode); COUNT tmpmode = (mode == LARGEST ? mem_access_mode : mode);
if ((mode != LARGEST || size == 0xffff) && if ((mode != LARGEST || size == 0xffff) &&
@ -147,9 +147,9 @@ searchAgain:
/* this block has a "match" size, try the rule set */ /* this block has a "match" size, try the rule set */
switch (mode) switch (mode)
{ {
case LAST_FIT: /* search for last possible */ /* case LAST_FIT: */ /* search for last possible */
case LAST_FIT_U: /* case LAST_FIT_U: */
case LAST_FIT_UO: /* case LAST_FIT_UO: */
default: default:
foundSeg = p; foundSeg = p;
break; break;
@ -189,7 +189,7 @@ searchAgain:
if (!foundSeg || !foundSeg->m_size) if (!foundSeg || !foundSeg->m_size)
{ /* no block to fullfill the request */ { /* no block to fullfill the request */
if ((mode != LARGEST) && (mode & FIRST_FIT_U) && if ((mode != LARGEST) && (mode & FIRST_FIT_U) &&
(uppermem_link & 1) && uppermem_root != 0xffff) uppermem_link && uppermem_root != 0xffff)
{ {
mode &= ~FIRST_FIT_U; mode &= ~FIRST_FIT_U;
goto searchAgain; goto searchAgain;
@ -401,7 +401,7 @@ COUNT DosMemCheck(void)
COUNT FreeProcessMem(UWORD ps) COUNT FreeProcessMem(UWORD ps)
{ {
mcb FAR *p; mcb FAR *p;
BYTE oldumbstate = uppermem_link & 1; BYTE oldumbstate = uppermem_link;
/* link in upper memory to free those , too */ /* link in upper memory to free those , too */
DosUmbLink(1); DosUmbLink(1);
@ -464,7 +464,7 @@ void DosUmbLink(unsigned n)
return; return;
p = para2far(first_mcb); p = para2far(first_mcb);
if (n > 1 || (uppermem_link & 1) == n) if (n > 1 || uppermem_link == n)
return; return;
while (FP_SEG(p) != uppermem_root && p->m_type != MCB_LAST) while (FP_SEG(p) != uppermem_root && p->m_type != MCB_LAST)
{ {