📄 dosformt.c
字号:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x01, 0x00, 0x06, 0x07, 0xE3, 0x66, 0x23, 0x00, 0x00, 0x00, 0x85, 0xB8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xAA}; tffscpy(&partitionTable,bootCode,sizeof partitionTable); partitionTable.activeFlag = 0x80; /* bootable */ if (LE2(bpb->noOfHeads) > 1) { partitionTable.startingHead = 1; toLE2(partitionTable.startingCylinderSector,CYLINDER_SECTOR(0,1)); } else { partitionTable.startingHead = 0; toLE2(partitionTable.startingCylinderSector,CYLINDER_SECTOR(1,1)); } partitionTable.type = FAT12bit ? 1 : 4; partitionTable.endingHead = LE2(bpb->noOfHeads) - 1; toLE2(partitionTable.endingCylinderSector, CYLINDER_SECTOR((cylinders - 1),LE2(bpb->sectorsPerTrack))); toUNAL4(partitionTable.startingSectorOfPartition,LE2(bpb->sectorsPerTrack)); toUNAL4(partitionTable.sectorsInPartition,LE4(bpb->totalSectorsInVolume)); toLE2(partitionTable.signature,PARTITION_SIGNATURE); return vol.writeSector(vol.rec,0,&partitionTable);}/*----------------------------------------------------------------------*//* c r e a t e D O S B o o t S e c t o r *//* *//* Creates the DOS boot sector *//* *//* Parameters: *//* vol : Pointer identifying drive *//* bpb : volume BIOS parameter block *//* volumeId : 32-bit volume id *//* volumeLabel : volume label *//* *//* Returns: *//* FLStatus : 0 on success, failed otherwise *//*----------------------------------------------------------------------*/static FLStatus createDOSbootSector(TL vol, BPB *bpb, const char FAR1 *volumeId, const char FAR1 *volumeLabel){ DOSBootSector bootSector; tffsset(&bootSector,0,sizeof bootSector); bootSector.physicalDriveNo = 0x80; bootSector.extendedBootSignature = 0x29; tffscpy(bootSector.volumeId,volumeId,sizeof bootSector.volumeId); tffsset(bootSector.volumeLabel,' ',sizeof bootSector.volumeLabel); if (volumeLabel) tffscpy(bootSector.volumeLabel,volumeLabel,sizeof bootSector.volumeLabel); tffscpy(bootSector.systemId, FAT12bit ? "FAT12 " : "FAT16 ", sizeof bootSector.systemId); bootSector.bpb = *bpb;#if FALSE tffscpy (&bootSector.bpb, bpb, sizeof(BPB));#endif /* FALSE */ bootSector.bpb.jumpInstruction[0] = 0xe9; tffscpy(bootSector.bpb.OEMname,"MSystems",sizeof bootSector.bpb.OEMname); toLE2(bootSector.signature,PARTITION_SIGNATURE); return vol.writeSector(vol.rec,(SectorNo) LE4(bpb->noOfHiddenSectors),&bootSector);}/*----------------------------------------------------------------------*//* c r e a t e F A T s *//* *//* Creates the FAT's *//* *//* Parameters: *//* vol : Pointer identifying drive *//* bpb : volume BIOS parameter block *//* *//* Returns: *//* FLStatus : 0 on success, failed otherwise *//*----------------------------------------------------------------------*/static FLStatus createFATs(TL vol, BPB *bpb){ int iFAT; SectorNo sectorNo = (SectorNo) (LE4(bpb->noOfHiddenSectors) + LE2(bpb->reservedSectors)); /* create the FATs */ for (iFAT = 0; iFAT < bpb->noOfFATS; iFAT++) { int iSector; unsigned char FATEntry[SECTOR_SIZE]; for (iSector = 0; iSector < LE2(bpb->sectorsPerFAT); iSector++) { tffsset(FATEntry,0,SECTOR_SIZE); if (iSector == 0) { /* write the reserved FAT entries */ FATEntry[0] = bpb->mediaDescriptor; FATEntry[1] = 0xff; FATEntry[2] = 0xff; if (!FAT12bit) FATEntry[3] = 0xff; } checkStatus(vol.writeSector(vol.rec,sectorNo++,FATEntry)); } } return flOK;}/*----------------------------------------------------------------------*//* c r e a t e R o o t D i r e c t o r y *//* *//* Creates the root directory *//* *//* Parameters: *//* vol : Pointer identifying drive *//* bpb : volume BIOS parameter block *//* volumeLabel : volume label *//* *//* Returns: *//* FLStatus : 0 on success, failed otherwise *//*----------------------------------------------------------------------*/static FLStatus createRootDirectory(TL vol, BPB *bpb, const char FAR1 *volumeLabel){ int iEntry; SectorNo sectorNo = (SectorNo) (LE4(bpb->noOfHiddenSectors) + LE2(bpb->reservedSectors) + bpb->noOfFATS * LE2(bpb->sectorsPerFAT)); /* create the root directory */ for (iEntry = 0; iEntry < UNAL2(bpb->rootDirectoryEntries); iEntry += (SECTOR_SIZE / sizeof(DirectoryEntry))) { DirectoryEntry rootDirectorySector[SECTOR_SIZE / sizeof(DirectoryEntry)]; tffsset(rootDirectorySector,0,SECTOR_SIZE); if (iEntry == 0 && volumeLabel) { tffsset(rootDirectorySector[0].name,' ',sizeof rootDirectorySector[0].name); tffscpy(rootDirectorySector[0].name,volumeLabel,sizeof rootDirectorySector[0].name); rootDirectorySector[0].attributes = 0x28; /* VOL + ARC */ toLE2(rootDirectorySector[0].updateTime,0); toLE2(rootDirectorySector[0].updateDate,0x21); /* 1/1/80 */ } checkStatus(vol.writeSector(vol.rec,sectorNo++,rootDirectorySector)); } return flOK;}/*----------------------------------------------------------------------*//* f l D o s F o r m a t *//* *//* Writes a DOS-FAT file system on the Flash volume *//* *//* Parameters: *//* vol : Pointer identifying drive *//* formatParams : Address of FormatParams structure to use *//* *//* Returns: *//* FLStatus : 0 on success, failed otherwise *//*----------------------------------------------------------------------*/FLStatus flDosFormat(TL vol, FormatParams FAR1 *formatParams){ unsigned int cylinders; BPB bpb; getDriveGeometry(&vol,&bpb,&cylinders,formatParams->noOfFATcopies); checkStatus(createMasterBootRecord(&vol,&bpb,cylinders)); checkStatus(createDOSbootSector(&vol,&bpb,formatParams->volumeId,formatParams->volumeLabel)); checkStatus(createFATs(&vol,&bpb)); checkStatus(createRootDirectory(&vol,&bpb,formatParams->volumeLabel)); return flOK;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -