mirror of
https://github.com/FDOS/kernel.git
synced 2025-04-08 17:15:17 +02:00
initdisk: further optimizations in CalculateFATData(): merging the FAT16 & FAT32
loops. fatfs: #if DEBUG fix. git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1451 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
parent
9e0b5e5bf6
commit
e3f90446b3
@ -253,8 +253,7 @@ f_node_ptr split_path(const char * path, f_node_ptr fnp)
|
||||
#ifdef DEBUG
|
||||
if (get_cds(path[0]-'A')->cdsFlags & CDSNETWDRV)
|
||||
{
|
||||
printf("split path called for redirected file: `%s'\n",
|
||||
fcbname);
|
||||
printf("split path called for redirected file: `%s'\n", path);
|
||||
return (f_node_ptr) 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -412,15 +412,7 @@ VOID CalculateFATData(ddt * pddt, ULONG NumSectors, UBYTE FileSystem)
|
||||
defbpb->bpb_nreserved = 1;
|
||||
/* SEC_SIZE * DIRENT_SIZE / defbpb->bpb_ndirent + defbpb->bpb_nreserved */
|
||||
fatdata = NumSectors - (DIRENT_SIZE + 1);
|
||||
#ifdef DEBUG
|
||||
if (FileSystem != FAT12)
|
||||
DebugPrintf(("%ld sectors for FAT+data, starting with %d sectors/cluster\n", fatdata, defbpb->bpb_nsector));
|
||||
#endif
|
||||
switch (FileSystem)
|
||||
{
|
||||
|
||||
case FAT12:
|
||||
case FAT12_LBA:
|
||||
if (FileSystem == FAT12 || FileSystem == FAT12_LBA)
|
||||
{
|
||||
unsigned fatdat;
|
||||
/* in DOS, FAT12 defaults to 4096kb (8 sector) - clusters. */
|
||||
@ -445,76 +437,27 @@ VOID CalculateFATData(ddt * pddt, ULONG NumSectors, UBYTE FileSystem)
|
||||
unsigned maxclust = (defbpb->bpb_nfsect * 2 * SEC_SIZE) / 3;
|
||||
if (maxclust > FAT12MAX)
|
||||
maxclust = FAT12MAX;
|
||||
printf(("FAT12: #clu=%u, fatlength=%u, maxclu=%u, limit=%u\n",
|
||||
clust, defbpb->bpb_nfsect, maxclust, FAT12MAX));
|
||||
printf("FAT12: #clu=%u, fatlength=%u, maxclu=%u, limit=%u\n",
|
||||
clust, defbpb->bpb_nfsect, maxclust, FAT12MAX);
|
||||
if (clust > maxclust - 2)
|
||||
{
|
||||
clust = maxclust - 2;
|
||||
printf(("FAT12: too many clusters: setting to maxclu-2\n"));
|
||||
printf("FAT12: too many clusters: setting to maxclu-2\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
memcpy(pddt->ddt_fstype, MSDOS_FAT12_SIGN, 8);
|
||||
break;
|
||||
}
|
||||
case FAT16SMALL:
|
||||
case FAT16LARGE:
|
||||
case FAT16_LBA:
|
||||
{
|
||||
unsigned fatlength;
|
||||
else
|
||||
{ /* FAT16/FAT32 */
|
||||
CLUSTER fatlength, maxcl;
|
||||
unsigned long clust, maxclust;
|
||||
/* 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));
|
||||
unsigned fatentpersec;
|
||||
unsigned divisor;
|
||||
|
||||
fatlength = (unsigned)cdiv(fatdata + 2 * defbpb->bpb_nsector,
|
||||
(SEC_SIZE/2) * defbpb->bpb_nsector + NFAT);
|
||||
/* Need to calculate number of clusters, since the unused parts of the
|
||||
* FATS and data area together could make up space for an additional,
|
||||
* not really present cluster. */
|
||||
clust = (fatdata - NFAT * fatlength) / defbpb->bpb_nsector;
|
||||
maxclust = (unsigned long)fatlength * (SEC_SIZE/2);
|
||||
if (maxclust > FAT16MAX)
|
||||
maxclust = FAT16MAX;
|
||||
DebugPrintf(("FAT16: #clu=%lu, fatlen=%u, maxclu=%lu, limit=%u\n",
|
||||
clust, fatlength, maxclust, FAT_MAGIC16));
|
||||
if (clust > maxclust - 2)
|
||||
{
|
||||
DebugPrintf(("FAT16: too many clusters\n"));
|
||||
clust = 0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (clust)
|
||||
break;
|
||||
defbpb->bpb_nsector <<= 1;
|
||||
}
|
||||
while (defbpb->bpb_nsector && defbpb->bpb_nsector <= MAXCLUSTSIZE);
|
||||
defbpb->bpb_nfsect = fatlength;
|
||||
memcpy(pddt->ddt_fstype, MSDOS_FAT16_SIGN, 8);
|
||||
break;
|
||||
}
|
||||
#ifdef WITHFAT32
|
||||
case FAT32:
|
||||
case FAT32_LBA:
|
||||
if (FileSystem == FAT32 || FileSystem == FAT32_LBA)
|
||||
{
|
||||
unsigned long fatlength, clust, maxclust;
|
||||
|
||||
/* For FAT32, use the cluster size table described in the FAT spec:
|
||||
* http://www.microsoft.com/hwdev/download/hardware/fatgen103.pdf
|
||||
*/
|
||||
@ -532,29 +475,61 @@ VOID CalculateFATData(ddt * pddt, ULONG NumSectors, UBYTE FileSystem)
|
||||
defbpb->bpb_ndirent = 0;
|
||||
defbpb->bpb_nreserved = 0x20;
|
||||
fatdata = NumSectors - 0x20;
|
||||
fatentpersec = SEC_SIZE/4;
|
||||
maxcl = FAT32MAX;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* 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;
|
||||
fatentpersec = SEC_SIZE/2;
|
||||
maxcl = FAT16MAX;
|
||||
}
|
||||
|
||||
DebugPrintf(("%ld sectors for FAT+data, starting with %d sectors/cluster\n", fatdata, defbpb->bpb_nsector));
|
||||
do
|
||||
{
|
||||
fatlength = cdiv(fatdata + 2 * defbpb->bpb_nsector,
|
||||
(SEC_SIZE/4) * defbpb->bpb_nsector + NFAT);
|
||||
DebugPrintf(("Trying with %d sectors/cluster:\n", defbpb->bpb_nsector));
|
||||
divisor = fatentpersec * defbpb->bpb_nsector + NFAT;
|
||||
fatlength = (CLUSTER)((fatdata + (2 * defbpb->bpb_nsector + divisor - 1))/
|
||||
divisor);
|
||||
/* Need to calculate number of clusters, since the unused parts of the
|
||||
* FATS and data area together could make up space for an additional,
|
||||
* not really present cluster. */
|
||||
clust = (fatdata - NFAT * fatlength) / defbpb->bpb_nsector;
|
||||
maxclust = fatlength * (SEC_SIZE/4);
|
||||
if (maxclust > FAT32MAX)
|
||||
maxclust = FAT32MAX;
|
||||
DebugPrintf(("FAT32: #clu=%u, fatlen=%u, maxclu=%u, limit=%u\n",
|
||||
clust, fatlength, maxclust, FAT32MAX));
|
||||
maxclust = fatlength * fatentpersec;
|
||||
if (maxclust > maxcl)
|
||||
maxclust = maxcl;
|
||||
DebugPrintf(("FAT: #clu=%lu, fatlen=%lu, maxclu=%lu, limit=%lu\n",
|
||||
clust, fatlength, maxclust, maxcl));
|
||||
if (clust > maxclust - 2)
|
||||
{
|
||||
clust = 0;
|
||||
DebugPrintf(("FAT32: too many clusters\n"));
|
||||
DebugPrintf(("FAT: too many clusters\n"));
|
||||
}
|
||||
else if (clust <= FAT_MAGIC)
|
||||
{
|
||||
/* The <= 4086 avoids that the filesystem will be misdetected as having a
|
||||
* 12 bit FAT. */
|
||||
DebugPrintf(("FAT: would be misdetected as FAT12\n"));
|
||||
clust = 0;
|
||||
}
|
||||
if (clust)
|
||||
break;
|
||||
defbpb->bpb_nsector <<= 1;
|
||||
}
|
||||
while (defbpb->bpb_nsector && defbpb->bpb_nsector <= MAXCLUSTSIZE);
|
||||
#ifdef WITHFAT32
|
||||
if (FileSystem == FAT32 || FileSystem == FAT32_LBA)
|
||||
{
|
||||
defbpb->bpb_nfsect = 0;
|
||||
defbpb->bpb_xnfsect = fatlength;
|
||||
/* set up additional FAT32 fields */
|
||||
@ -564,9 +539,13 @@ VOID CalculateFATData(ddt * pddt, ULONG NumSectors, UBYTE FileSystem)
|
||||
defbpb->bpb_xfsinfosec = 1;
|
||||
defbpb->bpb_xbackupsec = 6;
|
||||
memcpy(pddt->ddt_fstype, MSDOS_FAT32_SIGN, 8);
|
||||
break;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
defbpb->bpb_nfsect = (UWORD)fatlength;
|
||||
memcpy(pddt->ddt_fstype, MSDOS_FAT16_SIGN, 8);
|
||||
}
|
||||
}
|
||||
pddt->ddt_fstype[8] = '\0';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user