For details, see the embedded lecture hall.
Because the fatfs module is completely separated from the disk I/O layer, the underlying disk I/O requires the following functions to read/write the physical disk and obtain the current time. Because the underlying disk I/O module is not part of fatfs, it must be provided by users.
Disk_initialize:
1 /*-----------------------------------------------------------------------*/ 2 /* Inidialize a Drive */ 3 4 DSTATUS disk_initialize ( 5 BYTE drv /* Physical drive nmuber (0..) */ 6 ) 7 { 8 SD_Error Status; 9 /* Supports only single drive */10 if (drv)11 {12 return STA_NOINIT;13 }14 /*-------------------------- SD Init ----------------------------- */15 Status = SD_Init();16 if (Status!=SD_OK )17 {18 return STA_NOINIT;19 }20 else21 {22 return RES_OK;23 }24 25 }
View code
Function: initialize a disk drive.
Description:
The disk_initialize function initializes a physical drive. After the function is successful, the sta_noinit flag in the returned value is cleared.
The disk_initialize function is called by the fatfs module during volume mounting to manage changes to storage media. When the fatfs module works or the fat structure on the volume can be collapsed, the application cannot call this function. You can use the f_mount function to reinitialize the file system.
Disk_status:
1 /*-----------------------------------------------------------------------*/2 /* Return Disk Status */3 4 DSTATUS disk_status (5 BYTE drv /* Physical drive nmuber (0..) */6 )7 {8 return RES_OK;9 }
View code
Function: obtains the status of the current disk.
Disk_read:
1 /*-----------------------------------------------------------------------*/ 2 /* Read Sector(s) */ 3 4 DRESULT disk_read ( 5 BYTE drv, /* Physical drive nmuber (0..) */ 6 BYTE *buff, /* Data buffer to store read data */ 7 DWORD sector, /* Sector address (LBA) */ 8 BYTE count /* Number of sectors to read (1..255) */ 9 )10 {11 return RES_OK;12 }
View code
Function: Read a sector from a disk drive.
Disk_write:
1 /*-----------------------------------------------------------------------*/ 2 /* Write Sector(s) */ 3 4 #if _READONLY == 0 5 DRESULT disk_write ( 6 BYTE drv, /* Physical drive nmuber (0..) */ 7 const BYTE *buff, /* Data to be written */ 8 DWORD sector, /* Sector address (LBA) */ 9 BYTE count /* Number of sectors to write (1..255) */10 )11 {12 return RES_OK;13 }14 #endif /* _READONLY */
View code
Function: Write a sector to a disk drive.
Disk_ioctl:
1 /*-----------------------------------------------------------------------*/ 2 /* Miscellaneous Functions */ 3 4 DRESULT disk_ioctl ( 5 BYTE drv, /* Physical drive nmuber (0..) */ 6 BYTE ctrl, /* Control code */ 7 void *buff /* Buffer to send/receive control data */ 8 ) 9 {10 return RES_OK;11 }
View code
Get_fattime:
1 /*-----------------------------------------------------------------------*/2 /* Get current time */3 /*-----------------------------------------------------------------------*/ 4 DWORD get_fattime(void)5 {6 7 return 0;8 9 }
View code
Function: Get the current time
Description: The get_fattime function must return any valid time, even if the system does not support real-time clock. If 0 is returned, the file does not have a valid time. This function is not required in Read-Only configuration.