fs: fat_fs: make IOCTL call to de-initialize disk in fatfs_unmount()
Make call to de-initialize disk in fatfs_unmount(). This will permit the disk to be reinitialized when it is mounted with fatfs_mount(). Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
parent
93ebf1c48f
commit
7981ea0056
3 changed files with 83 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021 Zephyr contributors
|
||||
* Copyright (c) 2022 Nordic Semiconductor ASA
|
||||
* Copyright 2024 NXP
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
@ -12,6 +13,7 @@
|
|||
*/
|
||||
#include <ff.h>
|
||||
#include <diskio.h> /* FatFs lower layer API */
|
||||
#include <zfs_diskio.h> /* Zephyr specific FatFS API */
|
||||
#include <zephyr/storage/disk_access.h>
|
||||
|
||||
static const char * const pdrv_str[] = {FF_VOLUME_STRS};
|
||||
|
@ -31,13 +33,9 @@ DSTATUS disk_status(BYTE pdrv)
|
|||
/* Initialize a Drive */
|
||||
DSTATUS disk_initialize(BYTE pdrv)
|
||||
{
|
||||
__ASSERT(pdrv < ARRAY_SIZE(pdrv_str), "pdrv out-of-range\n");
|
||||
uint8_t param = DISK_IOCTL_POWER_ON;
|
||||
|
||||
if (disk_access_init(pdrv_str[pdrv]) != 0) {
|
||||
return STA_NOINIT;
|
||||
} else {
|
||||
return RES_OK;
|
||||
}
|
||||
return disk_ioctl(pdrv, CTRL_POWER, ¶m);
|
||||
}
|
||||
|
||||
/* Read Sector(s) */
|
||||
|
@ -109,6 +107,27 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
|
|||
}
|
||||
break;
|
||||
|
||||
/* Optional IOCTL command used by Zephyr fs_unmount implementation,
|
||||
* not called by FATFS
|
||||
*/
|
||||
case CTRL_POWER:
|
||||
if (((*(uint8_t *)buff)) == DISK_IOCTL_POWER_OFF) {
|
||||
/* Power disk off */
|
||||
if (disk_access_ioctl(pdrv_str[pdrv],
|
||||
DISK_IOCTL_CTRL_DEINIT,
|
||||
NULL) != 0) {
|
||||
ret = RES_ERROR;
|
||||
}
|
||||
} else {
|
||||
/* Power disk on */
|
||||
if (disk_access_ioctl(pdrv_str[pdrv],
|
||||
DISK_IOCTL_CTRL_INIT,
|
||||
NULL) != 0) {
|
||||
ret = STA_NOINIT;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = RES_PARERR;
|
||||
break;
|
||||
|
|
22
modules/fatfs/zfs_diskio.h
Normal file
22
modules/fatfs/zfs_diskio.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright 2024 NXP
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_MODULES_FATFS_ZFS_DISKIO_H_
|
||||
#define ZEPHYR_MODULES_FATFS_ZFS_DISKIO_H_
|
||||
/*
|
||||
* Header file for Zephyr specific portions of the FatFS disk interface.
|
||||
* These APIs are internal to Zephyr's FatFS VFS implementation
|
||||
*/
|
||||
|
||||
/*
|
||||
* Values that can be passed to buffer pointer used by disk_ioctl() when
|
||||
* sending CTRL_POWER IOCTL
|
||||
*/
|
||||
#define DISK_IOCTL_POWER_OFF 0x0
|
||||
#define DISK_IOCTL_POWER_ON 0x1
|
||||
|
||||
|
||||
#endif /* ZEPHYR_MODULES_FATFS_ZFS_DISKIO_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue