Unit pff

Description

Petit FatFs is a sub-set of FatFs module for Tiny 8-bit MicroControllers. It can be incorporated into the Tiny MicroControllers with limited memory even if the RAM size is less than sector size.

Overview

Classes, Interfaces, Objects and Records

Name Description
Record FATFS  
Record DIR  
Record FILINFO  

Functions and Procedures

function pf_mount(var fs: FATFS): FRESULT;
function pf_open(path: PChar): FRESULT;
function pf_read(buff: Pointer; btr: UINT; var br: UINT): FRESULT;
function pf_write(buff: Pointer; btw: UINT; bw: pUINT): FRESULT;
function pf_lseek(ofs: DWORD): FRESULT;
function pf_opendir(var dj: DIR; path: PChar): FRESULT;
function pf_readdir(var dj: DIR; var fno: FILINFO): FRESULT;
function pf_rewinddir(var dj: DIR): FRESULT;

Types

PUINT = ˆUINT;
UINT = NativeUInt;
CLUST = DWORD;
PFATFS = ˆFATFS;
PDIR = ˆDIR;
PFILINFO = ˆFILINFO;
FRESULT = (...);

Constants

PF_DEFINED = 8088;
PF_FS_FAT12 = True;
PF_FS_FAT16 = True;
PF_FS_FAT32 = True;
PF_USE_LCC = True;
PF_CODE_PAGE = 857;
FA_OPENED = $01;
FA_WPRT = $02;
FA__WIP = $40;
AM_RDO = $01;
AM_HID = $02;
AM_SYS = $04;
AM_VOL = $08;
AM_LFN = $0F;
AM_DIR = $10;
AM_ARC = $20;
AM_MASK = $3F;
FS_FAT12 = 1;
FS_FAT16 = 2;
FS_FAT32 = 3;
BS_OEMName = 3;
BS_DrvNum = 36;
BS_BootSig = 38;
BS_VolID = 39;
BS_VolLab = 43;
BS_FilSysType = 54;
BS_DrvNum32 = 64;
BS_BootSig32 = 66;
BS_VolID32 = 67;
BS_VolLab32 = 71;
BS_FilSysType32 = 82;
BS_55AA = 510;
BPB_BytsPerSec = 11;
BPB_SecPerClus = 13;
BPB_RsvdSecCnt = 14;
BPB_NumFATs = 16;
BPB_RootEntCnt = 17;
BPB_TotSec16 = 19;
BPB_Media = 21;
BPB_FATSz16 = 22;
BPB_SecPerTrk = 24;
BPB_NumHeads = 26;
BPB_HiddSec = 28;
BPB_TotSec32 = 32;
BPB_FATSz32 = 36;
BPB_ExtFlags = 40;
BPB_FSVer = 42;
BPB_RootClus = 44;
BPB_FSInfo = 48;
BPB_BkBootSec = 50;
MBR_Table = 446;
DIR_Name = 0;
DIR_Attr = 11;
DIR_NTres = 12;
DIR_CrtTime = 14;
DIR_CrtDate = 16;
DIR_FstClusHI = 20;
DIR_WrtTime = 22;
DIR_WrtDate = 24;
DIR_FstClusLO = 26;
DIR_FileSize = 28;

Description

Functions and Procedures

function pf_mount(var fs: FATFS): FRESULT;

Mount/Unmount a logical Drive

The pf_mount() function registers a work area to the Petit FatFs module. The volume is mounted on registration. The volume must be mounted with this function prior to use any file function and after every media changes.

Parameters
fs
Pointer to the work area (file system object) to be registered.
Returns

FR_OK The function succeeded.

FR_NOT_READY The storage device could not be initialized due to a hard error or no medium.

FR_DISK_ERR An error occured in the disk read function.

FR_NO_FILESYSTEM There is no valid FAT partition on the drive.

function pf_open(path: PChar): FRESULT;

Opens an existing file

The file must be opend prior to use pf_read and pf_lseek function. The open file is valid until next open.

Parameters
path
Pointer to a null-terminated string that specifies the file name to open.
Returns

FR_OK The function succeeded.

FR_NO_FILE Could not find the file or path.

FR_DISK_ERR The function failed due to a hard error in the disk function, a wrong FAT structure or an internal error.

FR_NOT_ENABLED The volume has not been mounted.

function pf_read(buff: Pointer; btr: UINT; var br: UINT): FRESULT;

Read data from the open file.

The file read/write pointer in the file system object advances in number of bytes read. After the function succeeded, br should be checked to detect end of file. In case of br is less than btr, it means the read pointer has reached end of the file during read operation. If a null pointer is given to the buff, the read data bytes are forwarded to the outgoing stream instead of the memory. The streaming function depends on each project will be typically built-in the disk_readp function.

Parameters
buff
Pointer to the read buffer (nil: Forward data to the stream)
btr
Number of bytes to read
br
Pointer to number of bytes read
Returns

FRESULT

function pf_write(buff: Pointer; btw: UINT; bw: pUINT): FRESULT;

Write data to the open file. The write function has some restrictions listed below:

Cannot create file. Only existing file can be written. Cannot expand file size. Cannot update time stamp of the file. Write operation can start/stop on the sector boundary only. Read-only attribute of the file cannot block write operation.

The read/write pointer in the file system object advances in number of bytes written. After the function succeeded, bw should be checked to detect end of file. In case of bw is less than btw, it means the read/write pointer reached end of file during the write operation. Once a write operation is initiated, it must be finalized properly, or the written data can be lost.

Parameters
buff
Pointer to the data to be written
btw
Number of bytes to write (0:Finalize the current write operation)
bw
Pointer to number of bytes written
Returns

FRESULT

function pf_lseek(ofs: DWORD): FRESULT;

Move file pointer of the open file

The pf_lseek() function moves the file read/write pointer of the open file. The ofs can be specified in only origin from top of the file.

Parameters
ofs
File pointer from top of file
Returns

FRESULT

function pf_opendir(var dj: DIR; path: PChar): FRESULT;

Create a directory Object.

The pf_opendir() function opens an exsisting directory and creates the directory object for subsequent calls. The directory object structure can be discarded at any time without any procedure.

Parameters
dj
Directory object
path
Directory path
Returns

FRESULT

function pf_readdir(var dj: DIR; var fno: FILINFO): FRESULT;

Read a directory item from the open directory.

The pf_readdir() function reads directory entries in sequence. All items in the directory can be read by calling this function repeatedly. When all directory entries have been read and no item to read, the function returns a null string into member f_name[] in the file information structure without error.

Parameters
dj
Open directory object
fno
Pointer to file information to return
Returns

FRESULT

function pf_rewinddir(var dj: DIR): FRESULT;

Directory rewind.

Parameters
dj
Open directory object
Returns

FRESULT

Types

PUINT = ˆUINT;
 
UINT = NativeUInt;
 
CLUST = DWORD;
 
PFATFS = ˆFATFS;
 
PDIR = ˆDIR;
 
PFILINFO = ˆFILINFO;
 
FRESULT = (...);

File function return code

Values
  • FR_OK = 0
  • FR_DISK_ERR
  • FR_NOT_READY
  • FR_NO_FILE
  • FR_NOT_OPENED
  • FR_NOT_ENABLED
  • FR_NO_FILESYSTEM

Constants

PF_DEFINED = 8088;
 
PF_FS_FAT12 = True;

Revision ID

PF_FS_FAT16 = True;
 
PF_FS_FAT32 = True;
 
PF_USE_LCC = True;
 
PF_CODE_PAGE = 857;
 
FA_OPENED = $01;

File status flag (FATFS.flag)

FA_WPRT = $02;
 
FA__WIP = $40;
 
AM_RDO = $01;

Read only

AM_HID = $02;

Hidden

AM_SYS = $04;

System

AM_VOL = $08;

Volume label

AM_LFN = $0F;

LFN entry

AM_DIR = $10;

Directory

AM_ARC = $20;

Archive

AM_MASK = $3F;

Mask of defined bits

FS_FAT12 = 1;
 
FS_FAT16 = 2;
 
FS_FAT32 = 3;
 
BS_OEMName = 3;
 
BS_DrvNum = 36;
 
BS_BootSig = 38;
 
BS_VolID = 39;
 
BS_VolLab = 43;
 
BS_FilSysType = 54;
 
BS_DrvNum32 = 64;
 
BS_BootSig32 = 66;
 
BS_VolID32 = 67;
 
BS_VolLab32 = 71;
 
BS_FilSysType32 = 82;
 
BS_55AA = 510;
 
BPB_BytsPerSec = 11;
 
BPB_SecPerClus = 13;
 
BPB_RsvdSecCnt = 14;
 
BPB_NumFATs = 16;
 
BPB_RootEntCnt = 17;
 
BPB_TotSec16 = 19;
 
BPB_Media = 21;
 
BPB_FATSz16 = 22;
 
BPB_SecPerTrk = 24;
 
BPB_NumHeads = 26;
 
BPB_HiddSec = 28;
 
BPB_TotSec32 = 32;
 
BPB_FATSz32 = 36;
 
BPB_ExtFlags = 40;
 
BPB_FSVer = 42;
 
BPB_RootClus = 44;
 
BPB_FSInfo = 48;
 
BPB_BkBootSec = 50;
 
MBR_Table = 446;
 
DIR_Name = 0;
 
DIR_Attr = 11;
 
DIR_NTres = 12;
 
DIR_CrtTime = 14;
 
DIR_CrtDate = 16;
 
DIR_FstClusHI = 20;
 
DIR_WrtTime = 22;
 
DIR_WrtDate = 24;
 
DIR_FstClusLO = 26;
 
DIR_FileSize = 28;
 

Generated by PasDoc 0.15.0.