Hallo liebe Community
Wisst ihr um welche Programmiersprache es sich handelt bei diesen beiden Codeausschnitten?
Ich bin von C ausgegangen aber ich bin mir nicht sicher
Code
#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
#define FAT32 0x0b /* FAT32 partition that ends before the 8.4 */
/* GB boundary */
#define FAT32_LBA 0x0c /* FAT32 partition that ends after the 8.4GB */
/* boundary. LBA is needed to access this. */
#define FAT16_LBA 0x0e /* like 0x06, but it is supposed to end past */
/* the 8.4GB boundary */
#define FAT12_LBA 0xff /* fake FAT12 LBA entry for internal use */
#define EXTENDED_LBA 0x0f /* like 0x05, but it is supposed to end past */
/* 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 */
#define FAT12MAX (FAT_MAGIC-6)
#define FAT16MAX (FAT_MAGIC16-6)
#define FAT32MAX (FAT_MAGIC32-6)
#define IsExtPartition(parttyp) ((parttyp) == EXTENDED || \
(parttyp) == EXTENDED_LBA )
#define IsLBAPartition(parttyp) ((parttyp) == FAT12_LBA || \
(parttyp) == FAT16_LBA || \
(parttyp) == FAT32_LBA)
#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
#define MSDOS_EXT_SIGN 0x29 /* extended boot sector signature */
#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 {
UWORD size;
UWORD information;
ULONG cylinders;
ULONG heads;
ULONG sectors;
ULONG totalSect;
ULONG totalSectHigh;
UWORD BytesPerSector;
ULONG eddparameters;
};
/* physical characteristics of a drive */
struct DriveParamS {
UBYTE driveno; /* = 0x8x */
UWORD descflags;
ULONG total_sectors;
struct CHS chs; /* for normal INT 13 */
};
struct PartTableEntry /* INTERNAL representation of partition table entry */
{
UBYTE Bootable;
UBYTE FileSystem;
struct CHS Begin;
struct CHS End;
ULONG RelSect;
ULONG NumSect;
};
/*
internal global data
*/
BOOL ExtLBAForce = FALSE;
COUNT init_readdasd(UBYTE drive)
{
static iregs regs;
regs.a.b.h = 0x15;
regs.d.b.l = drive;
init_call_intr(0x13, ®s);
if ((regs.flags & FLG_CARRY) == 0)
switch (regs.a.b.h)
{
case 2:
return DF_CHANGELINE;
case 3:
return DF_FIXED;
}
return 0;
}
typedef struct {
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] = {
/* 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 */
};
COUNT init_getdriveparm(UBYTE drive, bpb * pbpbarray)
{
static iregs regs;
REG UBYTE type;
if (drive & 0x80)
return 5;
regs.a.b.h = 0x08;
regs.d.b.l = drive;
/* Note: RBIL suggests setting ES:DI to 0:0 to guard against BIOS bugs */
init_call_intr(0x13, ®s);
type = regs.b.b.l - 1;
if (regs.flags & FLG_CARRY)
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 */
memcpy(pbpbarray, &floppy_bpbs[type & 7], sizeof(floppy_bpb));
((bpb *)pbpbarray)->bpb_hidden = 0; /* very important to init to 0, see bug#1789 */
((bpb *)pbpbarray)->bpb_huge = 0;
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;
}
/*
translate LBA sectors into CHS addressing
copied and pasted from dsk.c!
*/
void LBA_to_CHS(struct CHS *chs, ULONG LBA_address,
struct DriveParamS *driveparam)
{
unsigned hs = driveparam->chs.Sector * driveparam->chs.Head;
unsigned hsrem = (unsigned)(LBA_address % hs);
LBA_address /= hs;
chs->Cylinder = LBA_address >= 0x10000ul ? 0xffffu : (unsigned)LBA_address;
chs->Head = hsrem / driveparam->chs.Sector;
chs->Sector = hsrem % driveparam->chs.Sector + 1;
}
void printCHS(char *title, struct CHS *chs)
{
/* has no fixed size for head/sect: is often 1/1 in our context */
printf("%s%4u-%u-%u", title, chs->Cylinder, chs->Head, chs->Sector);
}
STATIC VOID printStartEnd(struct CHS *chs, struct CHS *end)
{
printCHS(" start ", chs);
printCHS(", end ", end);
printf("\n");
}
/*
reason for this modules existence:
we have found a partition, and add them to the global
partition structure.
*/
/* Compute ceil(a/b) */
STATIC UWORD cdiv(ULONG a, UWORD b)
{
return (UWORD)((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
*/
VOID CalculateFATData(ddt * pddt, ULONG NumSectors, UBYTE FileSystem)
{
UBYTE maxclustsize;
ULONG fatdata;
bpb *defbpb = &pddt->ddt_defbpb;
/* FAT related items */
defbpb->bpb_nfat = 2;
if (FileSystem == FAT32 || FileSystem == FAT32_LBA)
{
defbpb->bpb_ndirent = 0;
defbpb->bpb_nreserved = 0x20;
}
else
{
defbpb->bpb_ndirent = 512;
defbpb->bpb_nreserved = 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)
{
case FAT12:
case FAT12_LBA:
{
unsigned fatdat, fatlength, clust, maxclust;
/* 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 */
fatdat = (unsigned)fatdata;
if (fatdata > 32640)
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
* FATS and data area together could make up space for an additional,
* not really present cluster. */
clust =
(fatdat - defbpb->bpb_nfat * fatlength) / defbpb->bpb_nsector;
maxclust = (fatlength * 2 * defbpb->bpb_nbyte) / 3;
if (maxclust > FAT12MAX)
maxclust = FAT12MAX;
DebugPrintf(("FAT12: #clu=%u, fatlength=%u, maxclu=%u, limit=%u\n",
clust, fatlength, maxclust, FAT12MAX));
if (clust > maxclust - 2)
{
clust = maxclust - 2;
DebugPrintf(("FAT12: too many clusters: setting to maxclu-2\n"));
}
defbpb->bpb_nfsect = fatlength;
memcpy(pddt->ddt_fstype, MSDOS_FAT12_SIGN, 8);
break;
}
case FAT16SMALL:
case FAT16LARGE:
case FAT16_LBA:
{
unsigned fatlength;
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));
fatlength = cdiv(fatdata + 2 * defbpb->bpb_nsector,
defbpb->bpb_nbyte * defbpb->bpb_nsector / 2 + defbpb->bpb_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 - defbpb->bpb_nfat * fatlength) / defbpb->bpb_nsector;
maxclust = ((unsigned long)fatlength * defbpb->bpb_nbyte) / 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:
{
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
*/
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;
if (NumSectors <= 532480UL) /* disks up to 260 MB, 0.5K cluster */
nsector = 1;
defbpb->bpb_nsector = nsector;
do
{
fatlength = cdiv(fatdata + 2 * defbpb->bpb_nsector,
defbpb->bpb_nbyte * defbpb->bpb_nsector / 4 + defbpb->bpb_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 - 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",
clust, fatlength, maxclust, FAT32MAX));
if (clust > maxclust - 2)
{
clust = 0;
DebugPrintf(("FAT32: too many clusters\n"));
}
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;
memcpy(pddt->ddt_fstype, MSDOS_FAT32_SIGN, 8);
break;
}
#endif
}
pddt->ddt_fstype[8] = '\0';
}
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;
}
}
void DosDefinePartition(struct DriveParamS *driveParam,
ULONG StartSector, struct PartTableEntry *pEntry,
int extendedPartNo, int PrimaryNum)
{
ddt nddt;
ddt *pddt = &nddt;
struct CHS chs;
if (nUnits >= NDEV)
{
printf("more Partitions detected then possible, max = %d\n", NDEV);
return; /* we are done */
}
pddt->ddt_next = MK_FP(0, 0xffff);
pddt->ddt_driveno = driveParam->driveno;
pddt->ddt_logdriveno = nUnits;
pddt->ddt_descflags = driveParam->descflags;
/* Turn off 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 */
if (!InitKernelConfig.ForceLBA && !ExtLBAForce && !IsLBAPartition(pEntry->FileSystem))
pddt->ddt_descflags &= ~DF_LBA;
pddt->ddt_ncyl = driveParam->chs.Cylinder;
#ifdef DEBUG
if (pddt->ddt_descflags & DF_LBA)
DebugPrintf(("LBA enabled for drive %c:\n", 'A' + nUnits));
#endif
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_hidden = pEntry->RelSect;
pddt->ddt_defbpb.bpb_nsize = 0;
pddt->ddt_defbpb.bpb_huge = pEntry->NumSect;
if (pEntry->NumSect <= 0xffff)
{
pddt->ddt_defbpb.bpb_nsize = loword (pEntry->NumSect);
pddt->ddt_defbpb.bpb_huge = 0; /* may still be set on Win95 */
}
/* sectors per cluster, sectors per FAT etc. */
CalculateFATData(pddt, pEntry->NumSect, pEntry->FileSystem);
/* drive inaccessible until bldbpb successful */
pddt->ddt_descflags |= init_readdasd(pddt->ddt_driveno) | DF_NOACCESS;
pddt->ddt_type = 5;
memcpy(&pddt->ddt_bpb, &pddt->ddt_defbpb, sizeof(bpb));
push_ddt(pddt);
/* Alain whishes to keep this in later versions, too
Tom likes this too, so he made it configurable by SYS CONFIG ...
*/
if (InitKernelConfig.InitDiskShowDriveAssignment)
{
char *ExtPri;
int num;
LBA_to_CHS(&chs, StartSector, driveParam);
ExtPri = "Pri";
num = PrimaryNum + 1;
if (extendedPartNo)
{
ExtPri = "Ext";
num = extendedPartNo;
}
printf("%c: HD%d, %s[-]", 'A' + nUnits,
(driveParam->driveno & 0x7f) + 1, ExtPri, num);
printCHS(", CHS= ", &chs);
printf(", start=%6lu MB, size=%6lu MB\n",
StartSector / 2048, pEntry->NumSect / 2048);
}
nUnits++;
}
Alles anzeigen
Nummer 2
Code
# TARGET : we create a $(TARGET).sys file
!if $(XCPU)0 == 0
XCPU=86
!endif
CPUOPT=
!if $(XCPU) == 186
CPUOPT=-1
!endif
!if $(XCPU) == 386
CPUOPT=-3
!endif
# extension, if compiler supports it, specify compiler switch in XCPU_EX and set XCPU to 386
!if $(XCPU_EX)0 != 0
XCPU=386
CPUOPT=$(XCPU_EX)
!endif
!if $(XFAT)0 == 0
XFAT=32
!endif
!if $(XFAT) == 32
ALLCFLAGS=-DWITHFAT32 $(ALLCFLAGS)
NASMFLAGS=-DWITHFAT32 $(NASMFLAGS)
!endif
NASMFLAGS=-fobj -i../hdr/ -D$(COMPILER) -DXCPU=$(XCPU) $(NASMFLAGS)
#BINPATH=$(BASE)\bin
INCLUDEPATH=$(BASE)\include
LIBPATH=$(BASE)\lib
INITPATCH=@rem
!if $(LOADSEG)0 == 0
LOADSEG=0x60
!endif
!include "..\mkfiles\$(COMPILER).mak"
TARGET=$(TARGET)$(XCPU)$(XFAT)
INITCFLAGS=$(INITCFLAGS) $(ALLCFLAGS)
CFLAGS=$(CFLAGS) $(ALLCFLAGS)
RM=..\utils\rmfiles
DEPENDS=makefile ..\*.bat ..\mkfiles\*.*
# Implicit Rules #######################################################
.asm.obj:
$(NASM) $(NASMFLAGS) $<
.c.obj:
$(CC) $(CFLAGS) $<
.cpp.obj:
$(CC) $(CFLAGS) $<
.c.com:
$(CL) $(CFLAGST) $<
.c.exe:
$(CL) $(CFLAGSC) $<
Alles anzeigen
Danke im vorraus