Disk I/O interfaces for beginners of fatfs

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.