diff --git a/host/class/msc/usb_host_msc/include/usb/msc_host_vfs.h b/host/class/msc/usb_host_msc/include/usb/msc_host_vfs.h index c116eb7f..833125c8 100644 --- a/host/class/msc/usb_host_msc/include/usb/msc_host_vfs.h +++ b/host/class/msc/usb_host_msc/include/usb/msc_host_vfs.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -16,6 +16,16 @@ extern "C" { typedef struct msc_host_vfs *msc_host_vfs_handle_t; /**< VFS handle to attached Mass Storage device */ +/** + * @brief Format MSC device. + * + * @param[in] device Device handle obtained from MSC callback provided upon initialization + * @param[in] mount_config Mount configuration + * @param[in] vfs_handle Handle to MSC device associated with registered VFS + * @return esp_err_t + */ +esp_err_t esp_vfs_fat_usb_msc_format(msc_host_device_handle_t device, const esp_vfs_fat_mount_config_t *mount_config, const msc_host_vfs_handle_t vfs_handle); + /** * @brief Register MSC device to Virtual filesystem. * diff --git a/host/class/msc/usb_host_msc/src/msc_host_vfs.c b/host/class/msc/usb_host_msc/src/msc_host_vfs.c index eac6bc47..179ce991 100644 --- a/host/class/msc/usb_host_msc/src/msc_host_vfs.c +++ b/host/class/msc/usb_host_msc/src/msc_host_vfs.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -52,6 +52,18 @@ static esp_err_t msc_format_storage(size_t block_size, size_t allocation_size, c return ESP_OK; } +esp_err_t esp_vfs_fat_usb_msc_format(msc_host_device_handle_t device, const esp_vfs_fat_mount_config_t *mount_config, const msc_host_vfs_handle_t vfs_handle) +{ + MSC_RETURN_ON_INVALID_ARG(device); + MSC_RETURN_ON_INVALID_ARG(mount_config); + MSC_RETURN_ON_INVALID_ARG(vfs_handle); + + size_t block_size = ((msc_device_t *)device)->disk.block_size; + size_t alloc_size = mount_config->allocation_unit_size; + + return msc_format_storage(block_size, alloc_size, vfs_handle->drive); +} + static void dealloc_msc_vfs(msc_host_vfs_t *vfs) { free(vfs->base_path);