FAT 32 driver.

Summary
FAT 32 driver.
FAT32_MAX_PATHMaximum character length of a path.
FAT32_MAX_PARTITION_COUNTMaximum number of msdos partitions.
FAT32_MBR_SIGNATUREMaster Boot Record signature.
FAT32_PARTITION
FAT32_INT13_PARTITION
FAT32_BOOT_JMPJMP opcode (x86).
FAT32_BOOT_NOPNOP opcode (x86).
FAT32_MEDIA_TYPE
FAT32_BYTES_PER_SECTORNumber of bytes per sector.
FAT32_FAT_COUNTMaximum number of File Attribute Tables.
FAT32 directory entry attribute flag
FAT32_READ_ONLY
FAT32_HIDDEN
FAT32_SYSTEM
FAT32_VOLUME_ID
FAT32_DIRECTORY
FAT32_ARCHIVE
FAT32_LONG_NAME
FAT32 routines
fat32_read_sectorCopies 512 bytes from the specified sector to the destination buffer.
fat32_read_mbrReads partition table from sector.
fat32_mountMount a FAT32 partition and opens its root directory.
_fat32_open_root_dirOpens root directory of current partition.
_fat32_read_boot_sectorReads FAT32 boot sector.
_fat32_sector_addressComputes the sector id of a cluster.
_fat32_end_of_fatChecks if the last fat sector was reached.
_fat32_next_clusterRetrieves the next data cluster from the File Allocation Table.
_fat32_next_sectorReads next data sector and stores the data at the memory location pointed by fat32.data_buffer.
fat32_read_entryRetrieves the next valid directory entry and moves fat32.data_offset past it.
_fat32_is_lfnChecks if the current directory entry is a long filename (LFN) entry.
_fat32_checksumComputes the directory entry checksum.
fat32_lfn_getRetrieves the directory entry long file name (if any).
fat32_get_filenameRetrieves the directory entry file name.
fat32_openOpens the file whose directory entry is pointed by _si for reading.
fat32_readReads _cx bytes from the currently opened file and stores them at the memory location given by fat32.dst.
_fat32_8.3_cmpChecks it the 8.3 filename stored in a directory entry matches current string.
fat32_find_fileOpens the file whose name is the string pointed to by _r1.
fat32_free_clusterInspects the FAT in order to find the id of the first free cluster.

FAT32_MAX_PATH

FAT32_MAX_PATH = 260

Maximum character length of a path.

FAT32_MAX_PARTITION_COUNT

FAT32_MAX_PARTITION_COUNT = 4

Maximum number of msdos partitions.

FAT32_MBR_SIGNATURE

FAT32_MBR_SIGNATURE = $AA55

Master Boot Record signature.

FAT32_PARTITION

FAT32_PARTITION = $0b

FAT32_INT13_PARTITION

FAT32_INT13_PARTITION = $0c

FAT32_BOOT_JMP

FAT32_BOOT_JMP = $EB

JMP opcode (x86).

FAT32_BOOT_NOP

FAT32_BOOT_NOP = $90

NOP opcode (x86).

FAT32_MEDIA_TYPE

FAT32_MEDIA_TYPE = $f8

FAT32_BYTES_PER_SECTOR

FAT32_BYTES_PER_SECTOR = $200

Number of bytes per sector.

FAT32_FAT_COUNT

FAT32_FAT_COUNT = $02

Maximum number of File Attribute Tables.

FAT32 directory entry attribute flag

FAT32_READ_ONLY

FAT32_READ_ONLY = %0000_0001

FAT32_HIDDEN

FAT32_HIDDEN = %0000_0010

FAT32_SYSTEM

FAT32_SYSTEM = %0000_0100

FAT32_VOLUME_ID

FAT32_VOLUME_ID = %0000_1000

FAT32_DIRECTORY

FAT32_DIRECTORY = %0001_0000

FAT32_ARCHIVE

FAT32_ARCHIVE = %0010_0000

FAT32_LONG_NAME

FAT32_LONG_NAME = $0f

FAT32 routines

fat32_read_sector

Copies 512 bytes from the specified sector to the destination buffer.

Note

This is a user-defined routine.

Parameters

_ax : sector id bytes 0 and 1 _bx : sector id bytes 2 and 3 _di : output buffer

Return

Carry flagSet if the sector was successfully read.

fat32_read_mbr

Reads partition table from sector.

Parameters

fat32.data_bufferaddress of sector buffer.

Return

fat32.partition.sectorPartitions sector address.
fat32.partition.countNumber of active partitions.
XFAT32_OK on success.

fat32_mount

Mount a FAT32 partition and opens its root directory.

Parameters

AId of the partition to mount.

Return

fat32.partition.currentPartition id.
fat32.sectors_per_clusterNumber of sectors per cluster.
fat32.sectors_per_fatNumber of sectors stored in FAT.
fat32.root_dir_cluster1st cluster of the root directory.
fat32.fat_begin_lba1st FAT sector.
fat32.cluster_begin_lba1st data cluster.
fat32.current_cluster1st cluster of the root directory.
fat32.current_sector1st sector of the root directory.
fat32.fat_sectorCurrent FAT sector.
fat32.fat_entryCurrent FAT entry.
XFAT32_OK if the partition was successfully mounted.

_fat32_open_root_dir

Opens root directory of current partition.

Parameters

fat32.root_dir_cluster1st cluster of the root directory.
fat32.fat_bufferAddress of the FAT RAM buffer.
fat32.data_bufferAddress of the data RAM buffer.

Return

fat32.current_cluster1st cluster of the root directory.
fat32.current_sector1st sector of the root directory.
fat32.fat_sectorCurrent FAT sector.
fat32.fat_entryCurrent FAT entry.
XFAT32_OK on success.

_fat32_read_boot_sector

Reads FAT32 boot sector.

Parameters

fat32.data_bufferaddress of sector buffer.

Return

fat32.sectors_per_clusterNumber of sectors per cluster.
fat32.sectors_per_fatNumber of sectors stored in FAT.
fat32.root_dir_cluster1st cluster of the root directory.
fat32.fat_begin_lba1st FAT sector.
fat32.cluster_begin_lba1st data cluster.
XFAT32_OK if a valid FAT32 boot sector was read.

_fat32_sector_address

Computes the sector id of a cluster.

Parameters

fat32.current_clustercluster number.

Return

fat32.current_sectorsector number.

_fat32_end_of_fat

Checks if the last fat sector was reached.

Parameters

_ax : sector id bytes 0 and 1 _bx : sector id bytes 2 and 3

Return

Carry flagSet if the last fat sector was reached.

_fat32_next_cluster

Retrieves the next data cluster from the File Allocation Table.

Parameters

fat32.current_clusterCurrent data cluster.

Return

fat32.current_clusterNext data cluster upon success.  It’s left unchanged if the current cluster is the last one.
Carry flagSet if the current cluster is the last cluster, cleared otherwise.

_fat32_next_sector

Reads next data sector and stores the data at the memory location pointed by fat32.data_buffer.

Parameters

fat32.sector_offsetCurrent cluster sector.

Return

XFAT32_OK on success.

fat32_read_entry

Retrieves the next valid directory entry and moves fat32.data_offset past it.

Parameters

fat32.data_offsetOffset of the current directory entry.

Return

_siAddress of the valid directory entry (file or directory).
fat32.data_offsetOffset of the next directory entry.
Carry flagSet if a valid entry was found.

_fat32_is_lfn

Checks if the current directory entry is a long filename (LFN) entry.

Parameters

_sidirectory entry address.

Return

carry flag1 if the current directory entry is a LFN entry, 0 otherwise.

_fat32_checksum

Computes the directory entry checksum.

Parameters

Return

Achecksum.

fat32_lfn_get

Retrieves the directory entry long file name (if any).

Parameters

_siAddress of the current short file name (SFN) directory entry.
_distring buffer address.

Return

_r0directory entry checksum.
Carry flagSet if there is a LFN associated with the directory entry.

fat32_get_filename

Retrieves the directory entry file name.

Parameters

_siAddress of the directory entry.
_distring buffer address.

Return

fat32_open

Opens the file whose directory entry is pointed by _si for reading.

Parameters

_siMemory location of the file entry.

Return

XFAT32_OK on success.

fat32_read

Reads _cx bytes from the currently opened file and stores them at the memory location given by fat32.dst.

Parameters

_cxnumber of bytes to read from the currently opened file.
fat32.dstmemory location where the read bytes will be stored.

Return

_cxnumber of bytes read.

_fat32_8.3_cmp

Checks it the 8.3 filename stored in a directory entry matches current string.

Parameters

<_siDirectory entry filename.
<_r1Input string.

Return

Carry flagSet if the entry filename matches.

fat32_find_file

Opens the file whose name is the string pointed to by _r1.

Parameters

_r1File path address.
_dxTemporary buffer address.

Return

XFAT32_OK if the file was succesfully opened.

fat32_free_cluster

Inspects the FAT in order to find the id of the first free cluster.

Parameters

Return

_cxId of the first free cluster.
XFAT32_OK on success.
FAT32_MAX_PATH = 260
Maximum character length of a path.
FAT32_MAX_PARTITION_COUNT = 4
Maximum number of msdos partitions.
FAT32_MBR_SIGNATURE = $AA55
Master Boot Record signature.
FAT32_PARTITION = $0b
FAT32_INT13_PARTITION = $0c
FAT32_BOOT_JMP = $EB
JMP opcode (x86).
FAT32_BOOT_NOP = $90
NOP opcode (x86).
FAT32_MEDIA_TYPE = $f8
FAT32_BYTES_PER_SECTOR = $200
Number of bytes per sector.
FAT32_FAT_COUNT = $02
Maximum number of File Attribute Tables.
FAT32_READ_ONLY = %0000_0001
FAT32_HIDDEN = %0000_0010
FAT32_SYSTEM = %0000_0100
FAT32_VOLUME_ID = %0000_1000
FAT32_DIRECTORY = %0001_0000
FAT32_ARCHIVE = %0010_0000
FAT32_LONG_NAME = $0f
Close