From 6eacd6475231a504fae4ed03a12f5cd1cb166ac0 Mon Sep 17 00:00:00 2001 From: Anatoliy Belyanskiy Date: Sat, 23 Sep 2023 07:15:07 +1000 Subject: [PATCH] ... --- constants/Identify_ATA_struct.c | 408 -------------------------------- structures/FileSystem.inc | 347 +++++++++++++++++++++++++-- 2 files changed, 326 insertions(+), 429 deletions(-) delete mode 100644 constants/Identify_ATA_struct.c diff --git a/constants/Identify_ATA_struct.c b/constants/Identify_ATA_struct.c deleted file mode 100644 index 4843ba1..0000000 --- a/constants/Identify_ATA_struct.c +++ /dev/null @@ -1,408 +0,0 @@ -typedef struct _IDENTIFY_DEVICE_DATA { - struct { - USHORT Reserved1 : 1; - USHORT Retired3 : 1; - USHORT ResponseIncomplete : 1; - USHORT Retired2 : 3; - USHORT FixedDevice : 1; - USHORT RemovableMedia : 1; - USHORT Retired1 : 7; - USHORT DeviceType : 1; - } GeneralConfiguration; - - USHORT NumCylinders; - USHORT SpecificConfiguration; - USHORT NumHeads; - USHORT Retired1[2]; - USHORT NumSectorsPerTrack; - USHORT VendorUnique1[3]; - UCHAR SerialNumber[20]; - USHORT Retired2[2]; - USHORT Obsolete1; - UCHAR FirmwareRevision[8]; - UCHAR ModelNumber[40]; - UCHAR MaximumBlockTransfer; - UCHAR VendorUnique2; - - struct { - USHORT FeatureSupported : 1; - USHORT Reserved : 15; - } TrustedComputing; - - struct { - UCHAR CurrentLongPhysicalSectorAlignment : 2; - UCHAR ReservedByte49 : 6; - UCHAR DmaSupported : 1; - UCHAR LbaSupported : 1; - UCHAR IordyDisable : 1; - UCHAR IordySupported : 1; - UCHAR Reserved1 : 1; - UCHAR StandybyTimerSupport : 1; - UCHAR Reserved2 : 2; - USHORT ReservedWord50; - } Capabilities; - - USHORT ObsoleteWords51[2]; - USHORT TranslationFieldsValid : 3; - USHORT Reserved3 : 5; - USHORT FreeFallControlSensitivity : 8; - USHORT NumberOfCurrentCylinders; - USHORT NumberOfCurrentHeads; - USHORT CurrentSectorsPerTrack; - ULONG CurrentSectorCapacity; - UCHAR CurrentMultiSectorSetting; - UCHAR MultiSectorSettingValid : 1; - UCHAR ReservedByte59 : 3; - UCHAR SanitizeFeatureSupported : 1; - UCHAR CryptoScrambleExtCommandSupported : 1; - UCHAR OverwriteExtCommandSupported : 1; - UCHAR BlockEraseExtCommandSupported : 1; - ULONG UserAddressableSectors; - USHORT ObsoleteWord62; - USHORT MultiWordDMASupport : 8; - USHORT MultiWordDMAActive : 8; - USHORT AdvancedPIOModes : 8; - USHORT ReservedByte64 : 8; - USHORT MinimumMWXferCycleTime; - USHORT RecommendedMWXferCycleTime; - USHORT MinimumPIOCycleTime; - USHORT MinimumPIOCycleTimeIORDY; - - struct { - USHORT ZonedCapabilities : 2; - USHORT NonVolatileWriteCache : 1; - USHORT ExtendedUserAddressableSectorsSupported : 1; - USHORT DeviceEncryptsAllUserData : 1; - USHORT ReadZeroAfterTrimSupported : 1; - USHORT Optional28BitCommandsSupported : 1; - USHORT IEEE1667 : 1; - USHORT DownloadMicrocodeDmaSupported : 1; - USHORT SetMaxSetPasswordUnlockDmaSupported : 1; - USHORT WriteBufferDmaSupported : 1; - USHORT ReadBufferDmaSupported : 1; - USHORT DeviceConfigIdentifySetDmaSupported : 1; - USHORT LPSAERCSupported : 1; - USHORT DeterministicReadAfterTrimSupported : 1; - USHORT CFastSpecSupported : 1; - } AdditionalSupported; - - USHORT ReservedWords70[5]; - USHORT QueueDepth : 5; - USHORT ReservedWord75 : 11; - - struct { - USHORT Reserved0 : 1; - USHORT SataGen1 : 1; - USHORT SataGen2 : 1; - USHORT SataGen3 : 1; - USHORT Reserved1 : 4; - USHORT NCQ : 1; - USHORT HIPM : 1; - USHORT PhyEvents : 1; - USHORT NcqUnload : 1; - USHORT NcqPriority : 1; - USHORT HostAutoPS : 1; - USHORT DeviceAutoPS : 1; - USHORT ReadLogDMA : 1; - USHORT Reserved2 : 1; - USHORT CurrentSpeed : 3; - USHORT NcqStreaming : 1; - USHORT NcqQueueMgmt : 1; - USHORT NcqReceiveSend : 1; - USHORT DEVSLPtoReducedPwrState : 1; - USHORT Reserved3 : 8; - } SerialAtaCapabilities; - - struct { - USHORT Reserved0 : 1; - USHORT NonZeroOffsets : 1; - USHORT DmaSetupAutoActivate : 1; - USHORT DIPM : 1; - USHORT InOrderData : 1; - USHORT HardwareFeatureControl : 1; - USHORT SoftwareSettingsPreservation : 1; - USHORT NCQAutosense : 1; - USHORT DEVSLP : 1; - USHORT HybridInformation : 1; - USHORT Reserved1 : 6; - } SerialAtaFeaturesSupported; - - struct { - USHORT Reserved0 : 1; - USHORT NonZeroOffsets : 1; - USHORT DmaSetupAutoActivate : 1; - USHORT DIPM : 1; - USHORT InOrderData : 1; - USHORT HardwareFeatureControl : 1; - USHORT SoftwareSettingsPreservation : 1; - USHORT DeviceAutoPS : 1; - USHORT DEVSLP : 1; - USHORT HybridInformation : 1; - USHORT Reserved1 : 6; - } SerialAtaFeaturesEnabled; - - USHORT MajorRevision; - USHORT MinorRevision; - - struct { - USHORT SmartCommands : 1; - USHORT SecurityMode : 1; - USHORT RemovableMediaFeature : 1; - USHORT PowerManagement : 1; - USHORT Reserved1 : 1; - USHORT WriteCache : 1; - USHORT LookAhead : 1; - USHORT ReleaseInterrupt : 1; - USHORT ServiceInterrupt : 1; - USHORT DeviceReset : 1; - USHORT HostProtectedArea : 1; - USHORT Obsolete1 : 1; - USHORT WriteBuffer : 1; - USHORT ReadBuffer : 1; - USHORT Nop : 1; - USHORT Obsolete2 : 1; - USHORT DownloadMicrocode : 1; - USHORT DmaQueued : 1; - USHORT Cfa : 1; - USHORT AdvancedPm : 1; - USHORT Msn : 1; - USHORT PowerUpInStandby : 1; - USHORT ManualPowerUp : 1; - USHORT Reserved2 : 1; - USHORT SetMax : 1; - USHORT Acoustics : 1; - USHORT BigLba : 1; - USHORT DeviceConfigOverlay : 1; - USHORT FlushCache : 1; - USHORT FlushCacheExt : 1; - USHORT WordValid83 : 2; - USHORT SmartErrorLog : 1; - USHORT SmartSelfTest : 1; - USHORT MediaSerialNumber : 1; - USHORT MediaCardPassThrough : 1; - USHORT StreamingFeature : 1; - USHORT GpLogging : 1; - USHORT WriteFua : 1; - USHORT WriteQueuedFua : 1; - USHORT WWN64Bit : 1; - USHORT URGReadStream : 1; - USHORT URGWriteStream : 1; - USHORT ReservedForTechReport : 2; - USHORT IdleWithUnloadFeature : 1; - USHORT WordValid : 2; - } CommandSetSupport; - - struct { - USHORT SmartCommands : 1; - USHORT SecurityMode : 1; - USHORT RemovableMediaFeature : 1; - USHORT PowerManagement : 1; - USHORT Reserved1 : 1; - USHORT WriteCache : 1; - USHORT LookAhead : 1; - USHORT ReleaseInterrupt : 1; - USHORT ServiceInterrupt : 1; - USHORT DeviceReset : 1; - USHORT HostProtectedArea : 1; - USHORT Obsolete1 : 1; - USHORT WriteBuffer : 1; - USHORT ReadBuffer : 1; - USHORT Nop : 1; - USHORT Obsolete2 : 1; - USHORT DownloadMicrocode : 1; - USHORT DmaQueued : 1; - USHORT Cfa : 1; - USHORT AdvancedPm : 1; - USHORT Msn : 1; - USHORT PowerUpInStandby : 1; - USHORT ManualPowerUp : 1; - USHORT Reserved2 : 1; - USHORT SetMax : 1; - USHORT Acoustics : 1; - USHORT BigLba : 1; - USHORT DeviceConfigOverlay : 1; - USHORT FlushCache : 1; - USHORT FlushCacheExt : 1; - USHORT Resrved3 : 1; - USHORT Words119_120Valid : 1; - USHORT SmartErrorLog : 1; - USHORT SmartSelfTest : 1; - USHORT MediaSerialNumber : 1; - USHORT MediaCardPassThrough : 1; - USHORT StreamingFeature : 1; - USHORT GpLogging : 1; - USHORT WriteFua : 1; - USHORT WriteQueuedFua : 1; - USHORT WWN64Bit : 1; - USHORT URGReadStream : 1; - USHORT URGWriteStream : 1; - USHORT ReservedForTechReport : 2; - USHORT IdleWithUnloadFeature : 1; - USHORT Reserved4 : 2; - } CommandSetActive; - - USHORT UltraDMASupport : 8; - USHORT UltraDMAActive : 8; - - struct { - USHORT TimeRequired : 15; - USHORT ExtendedTimeReported : 1; - } NormalSecurityEraseUnit; - - struct { - USHORT TimeRequired : 15; - USHORT ExtendedTimeReported : 1; - } EnhancedSecurityEraseUnit; - - USHORT CurrentAPMLevel : 8; - USHORT ReservedWord91 : 8; - USHORT MasterPasswordID; - USHORT HardwareResetResult; - USHORT CurrentAcousticValue : 8; - USHORT RecommendedAcousticValue : 8; - USHORT StreamMinRequestSize; - USHORT StreamingTransferTimeDMA; - USHORT StreamingAccessLatencyDMAPIO; - ULONG StreamingPerfGranularity; - ULONG Max48BitLBA[2]; - USHORT StreamingTransferTime; - USHORT DsmCap; - - struct { - USHORT LogicalSectorsPerPhysicalSector : 4; - USHORT Reserved0 : 8; - USHORT LogicalSectorLongerThan256Words : 1; - USHORT MultipleLogicalSectorsPerPhysicalSector : 1; - USHORT Reserved1 : 2; - } PhysicalLogicalSectorSize; - - USHORT InterSeekDelay; - USHORT WorldWideName[4]; - USHORT ReservedForWorldWideName128[4]; - USHORT ReservedForTlcTechnicalReport; - USHORT WordsPerLogicalSector[2]; - - struct { - USHORT ReservedForDrqTechnicalReport : 1; - USHORT WriteReadVerify : 1; - USHORT WriteUncorrectableExt : 1; - USHORT ReadWriteLogDmaExt : 1; - USHORT DownloadMicrocodeMode3 : 1; - USHORT FreefallControl : 1; - USHORT SenseDataReporting : 1; - USHORT ExtendedPowerConditions : 1; - USHORT Reserved0 : 6; - USHORT WordValid : 2; - } CommandSetSupportExt; - - struct { - USHORT ReservedForDrqTechnicalReport : 1; - USHORT WriteReadVerify : 1; - USHORT WriteUncorrectableExt : 1; - USHORT ReadWriteLogDmaExt : 1; - USHORT DownloadMicrocodeMode3 : 1; - USHORT FreefallControl : 1; - USHORT SenseDataReporting : 1; - USHORT ExtendedPowerConditions : 1; - USHORT Reserved0 : 6; - USHORT Reserved1 : 2; - } CommandSetActiveExt; - - USHORT ReservedForExpandedSupportandActive[6]; - USHORT MsnSupport : 2; - USHORT ReservedWord127 : 14; - - struct { - USHORT SecuritySupported : 1; - USHORT SecurityEnabled : 1; - USHORT SecurityLocked : 1; - USHORT SecurityFrozen : 1; - USHORT SecurityCountExpired : 1; - USHORT EnhancedSecurityEraseSupported : 1; - USHORT Reserved0 : 2; - USHORT SecurityLevel : 1; - USHORT Reserved1 : 7; - } SecurityStatus; - - USHORT ReservedWord129[31]; - - struct { - USHORT MaximumCurrentInMA : 12; - USHORT CfaPowerMode1Disabled : 1; - USHORT CfaPowerMode1Required : 1; - USHORT Reserved0 : 1; - USHORT Word160Supported : 1; - } CfaPowerMode1; - - USHORT ReservedForCfaWord161[7]; - USHORT NominalFormFactor : 4; - USHORT ReservedWord168 : 12; - - struct { - USHORT SupportsTrim : 1; - USHORT Reserved0 : 15; - } DataSetManagementFeature; - - USHORT AdditionalProductID[4]; - USHORT ReservedForCfaWord174[2]; - USHORT CurrentMediaSerialNumber[30]; - - struct { - USHORT Supported : 1; - USHORT Reserved0 : 1; - USHORT WriteSameSuported : 1; - USHORT ErrorRecoveryControlSupported : 1; - USHORT FeatureControlSuported : 1; - USHORT DataTablesSuported : 1; - USHORT Reserved1 : 6; - USHORT VendorSpecific : 4; - } SCTCommandTransport; - - USHORT ReservedWord207[2]; - - struct { - USHORT AlignmentOfLogicalWithinPhysical : 14; - USHORT Word209Supported : 1; - USHORT Reserved0 : 1; - } BlockAlignment; - - USHORT WriteReadVerifySectorCountMode3Only[2]; - USHORT WriteReadVerifySectorCountMode2Only[2]; - - struct { - USHORT NVCachePowerModeEnabled : 1; - USHORT Reserved0 : 3; - USHORT NVCacheFeatureSetEnabled : 1; - USHORT Reserved1 : 3; - USHORT NVCachePowerModeVersion : 4; - USHORT NVCacheFeatureSetVersion : 4; - } NVCacheCapabilities; - - USHORT NVCacheSizeLSW; - USHORT NVCacheSizeMSW; - USHORT NominalMediaRotationRate; - USHORT ReservedWord218; - - struct { - UCHAR NVCacheEstimatedTimeToSpinUpInSeconds; - UCHAR Reserved; - } NVCacheOptions; - - USHORT WriteReadVerifySectorCountMode : 8; - USHORT ReservedWord220 : 8; - USHORT ReservedWord221; - - struct { - USHORT MajorVersion : 12; - USHORT TransportType : 4; - } TransportMajorVersion; - - USHORT TransportMinorVersion; - USHORT ReservedWord224[6]; - ULONG ExtendedNumberOfUserAddressableSectors[2]; - USHORT MinBlocksPerDownloadMicrocodeMode03; - USHORT MaxBlocksPerDownloadMicrocodeMode03; - USHORT ReservedWord236[19]; - USHORT Signature : 8; - USHORT CheckSum : 8; -} IDENTIFY_DEVICE_DATA, *PIDENTIFY_DEVICE_DATA; \ No newline at end of file diff --git a/structures/FileSystem.inc b/structures/FileSystem.inc index 2372496..bcbf1d8 100644 --- a/structures/FileSystem.inc +++ b/structures/FileSystem.inc @@ -1,24 +1,329 @@ ; - STRUCT _sBOOT_SEC ; 62 bytes -.JMP: BLOCK 3,0 ; +#00 "JMP" -.ID_NAME: TEXT 8,{"DSS_1.7","0"} ; +#03 DOS NAME - DB "DSS_1.70" + STRUCT _sBOOT_SEC ; 62 bytes +.JMP: BLOCK 3,0 ; +#00 "JMP" +.ID_NAME: TEXT 8, {"DSS_1.7","0"} ; +#03 DOS NAME - DB "DSS_1.70" ; Block Parameters BIOS -.B_P_S: WORD #200 ; +#0B BYTE PER SECTOR -.S_P_C: BYTE 2 ; +#0D SECTORS PER CLUSTER -.RESERVE: WORD 1 ; +#0E RESERVE SECTORS -.FAT_NUM: BYTE 2 ; +#10 AMOUNT FATS -.F_P_DIR: WORD 112 ; +#11 FILES IN DIRECTORY -.S_P_D: WORD 1440 ; +#13 ALL SECTORS ON DISK -.ID_FORM: BYTE #F0 ; +#15 ID FORMAT -.S_P_F: WORD 2 ; +#16 SIZE FAT IN SECTORS -.S_P_T: WORD 9 ; +#18 SECTOR PER TRACK -.HEADS: WORD 2 ; +#1A AMOUNT SIDES -.HIDDEN: DWORD 0 ; +#1C HIDDEN SECTORS -.BPB_BIG_TOTAL_SECTORS: DWORD 0 ; +#20 BIG TOTAL SECTOR -.BPB_PHISICAL_DRIVE_NUMBER: WORD #80 ; +#24 PHISICAL DRIVE NUMBER -.BPB_EXT_BOOT_RECORD_SIGNATURE: BYTE #29 ; +#26 EXTENDED BOOT RECORD SIGNATURE -.BPB_SERIAL_NUMBER: DWORD 0 ; +#27 VOLUME SERIAL NUMBER -.BPB_LABEL: TEXT 11,{"NO NAME"," "} ; +#2B DISK LABEL -.ID_FAT: TEXT 8,{"FAT16"," "} ; +#36 FILE SYSTEM ID ( BPB_FS_ID ) +.B_P_S: WORD #200 ; +#0B BYTE PER SECTOR +.S_P_C: BYTE 2 ; +#0D SECTORS PER CLUSTER +.RESERVE: WORD 1 ; +#0E RESERVE SECTORS +.FAT_NUM: BYTE 2 ; +#10 AMOUNT FATS +.F_P_DIR: WORD 112 ; +#11 FILES IN DIRECTORY +.S_P_D: WORD 1440 ; +#13 ALL SECTORS ON DISK +.ID_FORM: BYTE #F0 ; +#15 ID FORMAT +.S_P_F: WORD 2 ; +#16 SIZE FAT IN SECTORS +.S_P_T: WORD 9 ; +#18 SECTOR PER TRACK +.HEADS: WORD 2 ; +#1A AMOUNT SIDES +.HIDDEN: DWORD 0 ; +#1C HIDDEN SECTORS +.BPB_BIG_TOTAL_SECTORS: DWORD 0 ; +#20 BIG TOTAL SECTOR +.BPB_PHISICAL_DRIVE_NUMBER: WORD #80 ; +#24 PHISICAL DRIVE NUMBER +.BPB_EXT_BOOT_RECORD_SIGNATURE: BYTE #29 ; +#26 EXTENDED BOOT RECORD SIGNATURE +.BPB_SERIAL_NUMBER: DWORD 0 ; +#27 VOLUME SERIAL NUMBER +.BPB_LABEL: TEXT 11, {"NO NAME"," "} ; +#2B DISK LABEL +.ID_FAT: TEXT 8, {"FAT16"," "} ; +#36 FILE SYSTEM ID (BPB_FS_ID) +;.BOOT_CODE BLOCK 448,0 ; +#3E boot loader's code +;.SIGNATURE WORD #AA55 ; +#1FE Signature ENDS -; \ No newline at end of file +; + + STRUCT _sMBR_Table + ENDS + +//--------------------------------------------------------------------------- + +; * DOS partition types +; * +; * Taken from fdisk/i386_sys_types.c and fdisk/common.h of +; * util-linux 2.11n (as packaged by Debian), Feb 08, 2003. +; * +; * Part of the info is also taken from PartInfo tool from PartitionMagic 8 + +; const system_identifier_t system_identifiers[] = +; { +; {0x00, "Empty"}, +; {0x01, "FAT12"}, +; {0x02, "XENIX root"}, +; {0x03, "XENIX usr"}, +; {0x04, "FAT16 <32MB"}, +; {0x05, "Extended"}, +; {0x06, "FAT16B (>= 32 MB)"}, +; {0x07, "Installable File System (NTFS, HPFS)"}, +; {0x08, "AIX"}, +; {0x09, "AIX bootable"}, +; {0x0A, "OS/2 Boot Manager"}, +; {0x0B, "Win95 FAT32"}, +; {0x0C, "Win95 FAT32 (LBA)"}, +; {0x0E, "Win95 FAT16 (LBA)"}, +; {0x0F, "Win95 Extended (LBA)"}, +; {0x10, "OPUS"}, +; {0x11, "Hidden FAT12"}, +; {0x12, "Compaq diagnostics"}, +; {0x14, "Hidden FAT16 <32MB"}, +; {0x16, "Hidden FAT16"}, +; {0x17, "Hidden IFS (HPFS/NTFS)"}, +; {0x18, "AST SmartSleep"}, +; {0x1B, "Hidden Win95 FAT32"}, +; {0x1C, "Hidden Win95 FAT32 (LBA)"}, +; {0x1E, "Hidden Win95 FAT16 (LBA)"}, +; {0x24, "NEC DOS"}, +; {0x2C, "WildFile/Adaptec GOBack"}, +; {0x39, "Plan 9"}, +; {0x3C, "PowerQuest Recoverable Partition"}, +; {0x40, "Venix 80286"}, +; {0x41, "PPC PReP Boot"}, +; {0x42, "Veritas Logical Disk Manager"}, +; {0x4d, "QNX4.x"}, +; {0x4e, "QNX4.x 2nd part"}, +; {0x4f, "QNX4.x 3rd part"}, +; {0x50, "OnTrack DM"}, +; {0x51, "OnTrack DM6 Aux1"}, +; {0x52, "CP/M"}, +; {0x53, "OnTrack DM6 Aux3"}, +; {0x54, "OnTrackDM6"}, +; {0x55, "EZ-Drive"}, +; {0x56, "Golden Bow"}, +; {0x5c, "Priam Edisk"}, +; {0x61, "SpeedStor"}, +; {0x63, "GNU HURD or SysV"}, +; {0x64, "Novell Netware 286"}, +; {0x65, "Novell Netware (3.11 and 4.1)"}, +; {0x66, "Novell Netware 386"}, +; {0x70, "DiskSecure Multi-Boot"}, +; {0x75, "PC/IX"}, +; {0x78, "XOSL"}, +; {0x80, "Old Minix"}, +; {0x81, "Linux/Minix v1.4b+"}, +; {0x82, "Linux swap / Solaris"}, +; {0x83, "Linux native file system (Ext2/3)"}, +; {0x84, "OS/2 hiding type 04h partition"}, +; {0x85, "Linux extended"}, +; {0x86, "NT FAT volume set"}, +; {0x87, "NT IFS volume set"}, +; {0x8e, "Linux LVM"}, +; {0x93, "Amoeba/Hidden Linux native file system (Ext2/3)"}, +; {0x94, "Amoeba BBT"}, +; {0x9f, "BSD/OS"}, +; {0xA0, "IBM Thinkpad hibernation"}, +; {0xA5, "FreeBSD"}, +; {0xA6, "OpenBSD"}, +; {0xA7, "NeXTSTEP"}, +; {0xA9, "NetBSD"}, +; {0xB7, "BSDI fs"}, +; {0xb8, "BSDI swap"}, +; {0xbb, "Boot Wizard hidden"}, +; {0xc1, "DRDOS / sec (FAT-12)"}, +; {0xc4, "DRDOS / sec (FAT-16 < 32M)"}, +; {0xc6, "Disabled NT FAT (FAT-16) volume set/DRDOS"}, +; {0xc7, "Syrinx / Disabled NT IFS volume set"}, +; {0xda, "Non-FS data"}, +; {0xdb, "CP/M / CTOS / ..."}, +; {0xde, "Dell Corporation diagnostic partition"}, +; {0xdf, "BootIt"}, +; {0xe1, "DOS access"}, +; {0xe3, "DOS R/O"}, +; {0xe4, "SpeedStor"}, +; {0xeb, "BeOS fs"}, +; {0xee, "EFI GPT"}, +; {0xef, "EFI (FAT-12/16/32)"}, +; {0xf0, "Linux/PA-RISC boot"}, +; {0xf1, "SpeedStor"}, +; {0xf4, "SpeedStor"}, +; {0xf2, "DOS secondary"}, +; {0xfd, "Linux raid autodetect"}, +; {0xfe, "LANstep"}, +; {0xff, "Bad Track Table"}, +; {0, 0} // End-Of-Table +; }; + +; Limits and boundaries +; MAX_DIR 0x200000 ; Max size of FAT directory +; MAX_DIR_EX 0x10000000 ; Max size of exFAT directory +; MAX_FAT12 0xFF5 ; Max FAT12 clusters (differs from specs, but right for real DOS/Windows behavior) +; MAX_FAT16 0xFFF5 ; Max FAT16 clusters (differs from specs, but right for real DOS/Windows behavior) +; MAX_FAT32 0x0FFFFFF5 ; Max FAT32 clusters (not specified, practical limit) +; MAX_EXFAT 0x7FFFFFFD ; Max exFAT clusters (differs from specs, implementation limit) + + +; Character code support macros +; IsUpper(c) ((c) >= 'A' && (c) <= 'Z') +; IsLower(c) ((c) >= 'a' && (c) <= 'z') +; IsDigit(c) ((c) >= '0' && (c) <= '9') +; IsSeparator(c) ((c) == '/' || (c) == '\\') +; IsTerminator(c) ((UINT)(c) < (FF_USE_LFN ? ' ' : '!')) +; IsSurrogate(c) ((c) >= 0xD800 && (c) <= 0xDFFF) +; IsSurrogateH(c) ((c) >= 0xD800 && (c) <= 0xDBFF) +; IsSurrogateL(c) ((c) >= 0xDC00 && (c) <= 0xDFFF) + + +; Additional file access control and file status flags for internal use +; FA_SEEKEND 0x20 ; Seek to end of the file on file open +; FA_MODIFIED 0x40 ; File has been modified +; FA_DIRTY 0x80 ; FIL.buf[] needs to be written-back + + +; Additional file attribute bits for internal use +; AM_VOL 0x08 ; Volume label +; AM_LFN 0x0F ; LFN entry +; AM_MASK 0x3F ; Mask of defined bits in FAT +; AM_MASKX 0x37 ; Mask of defined bits in exFAT + + +; Name status flags in fn[11] +; NSFLAG 11 ; Index of the name status byte +; NS_LOSS 0x01 ; Out of 8.3 format +; NS_LFN 0x02 ; Force to create LFN entry +; NS_LAST 0x04 ; Last segment +; NS_BODY 0x08 ; Lower case flag (body) +; NS_EXT 0x10 ; Lower case flag (ext) +; NS_DOT 0x20 ; Dot entry +; NS_NOLFN 0x40 ; Do not find LFN +; NS_NONAME 0x80 ; Not followed + + +; exFAT directory entry types +; ET_BITMAP 0x81 ; Allocation bitmap +; ET_UPCASE 0x82 ; Up-case table +; ET_VLABEL 0x83 ; Volume label +; ET_FILEDIR 0x85 ; File and directory +; ET_STREAM 0xC0 ; Stream extension +; ET_FILENAME 0xC1 ; Name extension + + +; FatFs refers the FAT structure as simple byte array instead of structure member +; because the C structure is not binary compatible between different platforms + +; BS_JmpBoot 0 ; x86 jump instruction (3-byte) +; BS_OEMName 3 ; OEM name (8-byte) +; BPB_BytsPerSec 11 ; Sector size [byte] (WORD) +; BPB_SecPerClus 13 ; Cluster size [sector] (BYTE) +; BPB_RsvdSecCnt 14 ; Size of reserved area [sector] (WORD) +; BPB_NumFATs 16 ; Number of FATs (BYTE) +; BPB_RootEntCnt 17 ; Size of root directory area for FAT [entry] (WORD) +; BPB_TotSec16 19 ; Volume size (16-bit) [sector] (WORD) +; BPB_Media 21 ; Media descriptor byte (BYTE) +; BPB_FATSz16 22 ; FAT size (16-bit) [sector] (WORD) +; BPB_SecPerTrk 24 ; Number of sectors per track for int13h [sector] (WORD) +; BPB_NumHeads 26 ; Number of heads for int13h (WORD) +; BPB_HiddSec 28 ; Volume offset from top of the drive (DWORD) +; BPB_TotSec32 32 ; Volume size (32-bit) [sector] (DWORD) +; BS_DrvNum 36 ; Physical drive number for int13h (BYTE) +; BS_NTres 37 ; WindowsNT error flag (BYTE) +; BS_BootSig 38 ; Extended boot signature (BYTE) +; BS_VolID 39 ; Volume serial number (DWORD) +; BS_VolLab 43 ; Volume label string (8-byte) +; BS_FilSysType 54 ; Filesystem type string (8-byte) +; BS_BootCode 62 ; Boot code (448-byte) +; BS_55AA 510 ; Signature word (WORD) + +; BPB_FATSz32 36 ; FAT32: FAT size [sector] (DWORD) +; BPB_ExtFlags32 40 ; FAT32: Extended flags (WORD) +; BPB_FSVer32 42 ; FAT32: Filesystem version (WORD) +; BPB_RootClus32 44 ; FAT32: Root directory cluster (DWORD) +; BPB_FSInfo32 48 ; FAT32: Offset of FSINFO sector (WORD) +; BPB_BkBootSec32 50 ; FAT32: Offset of backup boot sector (WORD) +; BS_DrvNum32 64 ; FAT32: Physical drive number for int13h (BYTE) +; BS_NTres32 65 ; FAT32: Error flag (BYTE) +; BS_BootSig32 66 ; FAT32: Extended boot signature (BYTE) +; BS_VolID32 67 ; FAT32: Volume serial number (DWORD) +; BS_VolLab32 71 ; FAT32: Volume label string (8-byte) +; BS_FilSysType32 82 ; FAT32: Filesystem type string (8-byte) +; BS_BootCode32 90 ; FAT32: Boot code (420-byte) + +; BPB_ZeroedEx 11 ; exFAT: MBZ field (53-byte) +; BPB_VolOfsEx 64 ; exFAT: Volume offset from top of the drive [sector] (QWORD) +; BPB_TotSecEx 72 ; exFAT: Volume size [sector] (QWORD) +; BPB_FatOfsEx 80 ; exFAT: FAT offset from top of the volume [sector] (DWORD) +; BPB_FatSzEx 84 ; exFAT: FAT size [sector] (DWORD) +; BPB_DataOfsEx 88 ; exFAT: Data offset from top of the volume [sector] (DWORD) +; BPB_NumClusEx 92 ; exFAT: Number of clusters (DWORD) +; BPB_RootClusEx 96 ; exFAT: Root directory start cluster (DWORD) +; BPB_VolIDEx 100 ; exFAT: Volume serial number (DWORD) +; BPB_FSVerEx 104 ; exFAT: Filesystem version (WORD) +; BPB_VolFlagEx 106 ; exFAT: Volume flags (WORD) +; BPB_BytsPerSecEx 108 ; exFAT: Log2 of sector size in unit of byte (BYTE) +; BPB_SecPerClusEx 109 ; exFAT: Log2 of cluster size in unit of sector (BYTE) +; BPB_NumFATsEx 110 ; exFAT: Number of FATs (BYTE) +; BPB_DrvNumEx 111 ; exFAT: Physical drive number for int13h (BYTE) +; BPB_PercInUseEx 112 ; exFAT: Percent in use (BYTE) +; BPB_RsvdEx 113 ; exFAT: Reserved (7-byte) +; BS_BootCodeEx 120 ; exFAT: Boot code (390-byte) + +; DIR_Name 0 ; Short file name (11-byte) +; DIR_Attr 11 ; Attribute (BYTE) +; DIR_NTres 12 ; Lower case flag (BYTE) +; DIR_CrtTime10 13 ; Created time sub-second (BYTE) +; DIR_CrtTime 14 ; Created time (DWORD) +; DIR_LstAccDate 18 ; Last accessed date (WORD) +; DIR_FstClusHI 20 ; Higher 16-bit of first cluster (WORD) +; DIR_ModTime 22 ; Modified time (DWORD) +; DIR_FstClusLO 26 ; Lower 16-bit of first cluster (WORD) +; DIR_FileSize 28 ; File size (DWORD) +; LDIR_Ord 0 ; LFN: LFN order and LLE flag (BYTE) +; LDIR_Attr 11 ; LFN: LFN attribute (BYTE) +; LDIR_Type 12 ; LFN: Entry type (BYTE) +; LDIR_Chksum 13 ; LFN: Checksum of the SFN (BYTE) +; LDIR_FstClusLO 26 ; LFN: MBZ field (WORD) +; XDIR_Type 0 ; exFAT: Type of exFAT directory entry (BYTE) +; XDIR_NumLabel 1 ; exFAT: Number of volume label characters (BYTE) +; XDIR_Label 2 ; exFAT: Volume label (11-WORD) +; XDIR_CaseSum 4 ; exFAT: Sum of case conversion table (DWORD) +; XDIR_NumSec 1 ; exFAT: Number of secondary entries (BYTE) +; XDIR_SetSum 2 ; exFAT: Sum of the set of directory entries (WORD) +; XDIR_Attr 4 ; exFAT: File attribute (WORD) +; XDIR_CrtTime 8 ; exFAT: Created time (DWORD) +; XDIR_ModTime 12 ; exFAT: Modified time (DWORD) +; XDIR_AccTime 16 ; exFAT: Last accessed time (DWORD) +; XDIR_CrtTime10 20 ; exFAT: Created time subsecond (BYTE) +; XDIR_ModTime10 21 ; exFAT: Modified time subsecond (BYTE) +; XDIR_CrtTZ 22 ; exFAT: Created timezone (BYTE) +; XDIR_ModTZ 23 ; exFAT: Modified timezone (BYTE) +; XDIR_AccTZ 24 ; exFAT: Last accessed timezone (BYTE) +; XDIR_GenFlags 33 ; exFAT: General secondary flags (BYTE) +; XDIR_NumName 35 ; exFAT: Number of file name characters (BYTE) +; XDIR_NameHash 36 ; exFAT: Hash of file name (WORD) +; XDIR_ValidFileSize 40 ; exFAT: Valid file size (QWORD) +; XDIR_FstClus 52 ; exFAT: First cluster of the file data (DWORD) +; XDIR_FileSize 56 ; exFAT: File/Directory size (QWORD) + +; SZDIRE 32 ; Size of a directory entry +; DDEM 0xE5 ; Deleted directory entry mark set to DIR_Name[0] +; RDDEM 0x05 ; Replacement of the character collides with DDEM +; LLEF 0x40 ; Last long entry flag in LDIR_Ord + +; FSI_LeadSig 0 ; FAT32 FSI: Leading signature (DWORD) +; FSI_StrucSig 484 ; FAT32 FSI: Structure signature (DWORD) +; FSI_Free_Count 488 ; FAT32 FSI: Number of free clusters (DWORD) +; FSI_Nxt_Free 492 ; FAT32 FSI: Last allocated cluster (DWORD) + +; MBR_Table 446 ; MBR: Offset of partition table in the MBR +; SZ_PTE 16 ; MBR: Size of a partition table entry +; PTE_Boot 0 ; MBR PTE: Boot indicator +; PTE_StHead 1 ; MBR PTE: Start head +; PTE_StSec 2 ; MBR PTE: Start sector +; PTE_StCyl 3 ; MBR PTE: Start cylinder +; PTE_System 4 ; MBR PTE: System ID +; PTE_EdHead 5 ; MBR PTE: End head +; PTE_EdSec 6 ; MBR PTE: End sector +; PTE_EdCyl 7 ; MBR PTE: End cylinder +; PTE_StLba 8 ; MBR PTE: Start in LBA +; PTE_SizLba 12 ; MBR PTE: Size in LBA + +; GPTH_Sign 0 ; GPT: Header signature (8-byte) +; GPTH_Rev 8 ; GPT: Revision (DWORD) +; GPTH_Size 12 ; GPT: Header size (DWORD) +; GPTH_Bcc 16 ; GPT: Header BCC (DWORD) +; GPTH_CurLba 24 ; GPT: Main header LBA (QWORD) +; GPTH_BakLba 32 ; GPT: Backup header LBA (QWORD) +; GPTH_FstLba 40 ; GPT: First LBA for partitions (QWORD) +; GPTH_LstLba 48 ; GPT: Last LBA for partitions (QWORD) +; GPTH_DskGuid 56 ; GPT: Disk GUID (16-byte) +; GPTH_PtOfs 72 ; GPT: Partation table LBA (QWORD) +; GPTH_PtNum 80 ; GPT: Number of table entries (DWORD) +; GPTH_PteSize 84 ; GPT: Size of table entry (DWORD) +; GPTH_PtBcc 88 ; GPT: Partation table BCC (DWORD) +; SZ_GPTE 128 ; GPT: Size of partition table entry +; GPTE_PtGuid 0 ; GPT PTE: Partition type GUID (16-byte) +; GPTE_UpGuid 16 ; GPT PTE: Partition unique GUID (16-byte) +; GPTE_FstLba 32 ; GPT PTE: First LBA (QWORD) +; GPTE_LstLba 40 ; GPT PTE: Last LBA inclusive (QWORD) +; GPTE_Flags 48 ; GPT PTE: Flags (QWORD) +; GPTE_Name 56 ; GPT PTE: Name