I/O control interface routines provide operate on FAT formatted media devices. More...
Functions | |
int32_t | fs_ioc_get_id (const char *drive) |
Check if valid drive is specified and return its ID. | |
fsStatus | fs_ioc_lock (int32_t drv_id) |
Lock drive and block media access to the upper layer. | |
fsStatus | fs_ioc_unlock (int32_t drv_id) |
Unlock drive and allow media access to the upper layer. | |
fsStatus | fs_ioc_get_cache (int32_t drv_id, fsIOC_Cache *cache_info) |
Return IOC cache buffer information. | |
fsStatus | fs_ioc_read_sector (int32_t drv_id, uint32_t sect, uint8_t *buf, uint32_t cnt) |
Read sector from media. | |
fsStatus | fs_ioc_write_sector (int32_t drv_id, uint32_t sect, const uint8_t *buf, uint32_t cnt) |
Write sector to media. | |
fsStatus | fs_ioc_read_info (int32_t drv_id, fsMediaInfo *info) |
Read media configuration info. | |
fsStatus | fs_ioc_device_ctrl (int32_t drv_id, fsDevCtrlCode code, void *p) |
IOC device control access; control code is sent directly to device driver. | |
I/O control interface routines provide operate on FAT formatted media devices.
fsStatus fs_ioc_device_ctrl | ( | int32_t | drv_id, |
fsDevCtrlCode | code, | ||
void * | p | ||
) |
IOC device control access; control code is sent directly to device driver.
[in] | drv_id | Drive ID obtained by fs_ioc_get_id. |
[in] | code | Device control code. |
[in,out] | p | Generic pointer. |
The function fs_ioc_device_ctrl is used to send control code directly to the device driver, causing the device to perform a corresponding operation.
The argument drv_id identifies the drive.
The argument code is specifying the control code to be sent.
The argument p is a generic pointer and is used if the control code requires additional parameters to be passed to the driver or causes return values. The object to which pointer p points to, depends on the control code used.
Control code | Generic pointer | Operation description |
---|---|---|
fsDevCtrlCodeCheckMedia | uint32_t | Checks presence and write protection status of a removable media. |
fsDevCtrlCodeControlMedia | uint32_t | Control media device. |
fsDevCtrlCodeFormat | char | Performs a low level format. |
fsDevCtrlCodeGetCID | fsCID_Register | Reads memory card CID register. |
fsDevCtrlCodeSerial | uint32_t | Reads device serial number. |
fsDevCtrlCodeLockUnlock | fsLockUnlock | Manage memory card password protection. |
fsDevCtrlCodeHealthStatus | fsHealthStatus | Access memory device S.M.A.R.T data. |
When fsDevCtrlCodeCheckMedia is specified, argument p is used to return the bitmask of the following values:
Bit value | Description |
---|---|
FS_MEDIA_INSERTED | Media device is inserted |
FS_MEDIA_PROTECTED | Media device has write protection enabled |
FS_MEDIA_INITIALIZED | Media device is initialized |
FS_MEDIA_NOCHKMEDIA | Nonremovable media device or unable to detect media presence and write protection |
Argument p must point to valid memory location otherwise it will be rejected.
When fsDevCtrlCodeControlMedia is specified, argument p is used to specify the following operations:
Value | Operation description |
---|---|
FS_CONTROL_MEDIA_INIT | Initialize media device |
FS_CONTROL_EMMC_SLEEP | Switch eMMC device to Sleep State and turn off VCC power supply. |
FS_CONTROL_EMMC_AWAKE | Wake-up eMMC device from Sleep State and turn on VCC power supply. |
Argument p must point to valid memory location otherwise it will be rejected.
When fsDevCtrlCodeFormat is specified, argument p is used to specify low level format options. It can be NULL or point to char array containing following option:
Option | Operation description |
---|---|
LLEB | Performs low-level formatting and erases bad block markers. |
If argument p is NULL or unspecified options are specified, only low level format is performed which preserves bad block information.
When fsDevCtrlCodeGetCID is specified, argument p is used to specify the location of fsCID_Register structure where CID register values will be stored. A NULL pointer is not allowed and will be rejected.
When fsDevCtrlCodeSerial is specified, argument p is used to specify the location of 32-bit variable where device serial number will be stored. A NULL pointer is not allowed and will be rejected.
When fsDevCtrlCodeLockUnlock is specified, argument p is used to specify the location of fsLockUnlock structure. A NULL pointer is not allowed and will be rejected.
Structure fsLockUnlock consists of the following members:
Member | Description |
---|---|
password | Pointer to uint8_t buffer containing password data. |
length | Defines password length in bytes. The password length is up to 16 bytes. |
flags | Bit mask which defines set/clear password and/or device lock/erase operation. |
Valid bit mask values for member flags are the following:
Value | Description |
---|---|
FS_DEVICE_SET_PASSWORD | Set new password. |
FS_DEVICE_CLR_PASSWORD | Clear current password. |
FS_DEVICE_LOCK_UNLOCK | Lock the card. Omit this flag to specify unlock operation. |
FS_DEVICE_ERASE | Force device erase operation. |
For detailed functionality description refer to Memory Card Control Layer section Device Specific Features.
When fsDevCtrlCodeHealthStatus is specified, argument p is used to specify the location of fsHealthStatus structure. A NULL pointer is not allowed and will be rejected.
Structure fsHealthStatus consists of the following members:
Member | Description |
---|---|
arg | Argument used to control health status access behavior. |
buf | Defines buffer used to retrieve or to write data and must be 4 byte aligned. |
buf_sz | Defines buffer size in bytes. |
The behavior of fsDevCtrlCodeHealthStatus is device specific and only supported for eMMC and SD devices. See Memory Card Control Layer section Device Specific Features for more information.
Code Examples
fsStatus fs_ioc_get_cache | ( | int32_t | drv_id, |
fsIOC_Cache * | cache_info | ||
) |
Return IOC cache buffer information.
[in] | drv_id | Drive ID obtained by fs_ioc_get_id. |
[out] | cache_info | IOC Cache information. |
The function fs_ioc_get_cache is used to gain information about the file system cache buffer location and its size. The I/O Control Interface can use this buffer as a temporary storage for sector operations using fs_ioc_read_sector and fs_ioc_write_sector or for any other data storage.
The argument cache_info is a pointer to the fsIOC_Cache structure where the buffer location and its size will be stored.
Code Example
int32_t fs_ioc_get_id | ( | const char * | drive | ) |
Check if valid drive is specified and return its ID.
[in] | drive | a string specifying the memory or storage device. |
The function fs_ioc_get_id is used to get the drive identifier associated with the specified drive letter.
The argument drive is specifying a FAT volume drive. The Current Drive is used, if an empty string "" is provided.
fsStatus fs_ioc_lock | ( | int32_t | drv_id | ) |
Lock drive and block media access to the upper layer.
[in] | drv_id | Drive ID obtained by fs_ioc_get_id. |
The function fs_ioc_lock locks a drive in order to block media access to the file system layer while the I/O Control Interface routines are in use. The I/O Control Interface should only be used in the locked state due to possible interference with file system accesses to the media. All file operations will fail while the drive is in the locked state. The function fs_ioc_unlock is used to unlock the drive.
The argument drv_id identifies the drive and must be obtained using the fs_ioc_get_id function.
fsStatus fs_ioc_read_info | ( | int32_t | drv_id, |
fsMediaInfo * | info | ||
) |
Read media configuration info.
[in] | drv_id | Drive ID obtained by fs_ioc_get_id. |
[out] | info | Media information structure. |
The function fs_ioc_read_info reads the media configuration.
The argument drv_id identifies the drive.
The argument info returns the media information structure as specified in fsMediaInfo.
Code Example
fsStatus fs_ioc_read_sector | ( | int32_t | drv_id, |
uint32_t | sect, | ||
uint8_t * | buf, | ||
uint32_t | cnt | ||
) |
Read sector from media.
[in] | drv_id | Drive ID obtained by fs_ioc_get_id. |
[in] | sect | Sector number. |
[out] | buf | Data buffer. |
[in] | cnt | Count of sectors. |
The function fs_ioc_read_sector reads data from one or more sectors of FAT formatted media.
The argument drv_id identifies the drive.
The argument sect specifies the starting sector from where to read the data.
The argument buf is a pointer to the buffer that stores the data.
The argument cnt specifies the number of sectors to read.
Code Example
fsStatus fs_ioc_unlock | ( | int32_t | drv_id | ) |
Unlock drive and allow media access to the upper layer.
[in] | drv_id | Drive ID obtained by fs_ioc_get_id. |
The function fs_ioc_unlock unlocks a drive and releases media access to the file system layer. The I/O Control Interface should only be used in the locked state due to possible interference with file system accesses to the media. The function fs_ioc_lock is used to lock the drive.
The argument drv_id identifies the drive and must be obtained using the fs_ioc_get_id function.
fsStatus fs_ioc_write_sector | ( | int32_t | drv_id, |
uint32_t | sect, | ||
const uint8_t * | buf, | ||
uint32_t | cnt | ||
) |
Write sector to media.
[in] | drv_id | Drive ID obtained by fs_ioc_get_id. |
[in] | sect | Sector number. |
[out] | buf | Data buffer. |
[in] | cnt | Count of sectors. |
The function fs_ioc_write_sector writes data to one or more sectors of FAT formatted media.
The argument drv_id identifies the drive.
The argument sect specifies the starting sector to write the data.
The argument buf is a pointer to the buffer that contains the data to write.
The argument cnt specifies the number of sectors to write to.
Code Example