Skip to content

Commit

Permalink
feat(msc_host): Add format MSC support
Browse files Browse the repository at this point in the history
  • Loading branch information
igi540 committed Dec 9, 2024
1 parent 0693422 commit e056e9b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 11 additions & 1 deletion host/class/msc/usb_host_msc/include/usb/msc_host_vfs.h
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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.
*
Expand Down
14 changes: 13 additions & 1 deletion host/class/msc/usb_host_msc/src/msc_host_vfs.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e056e9b

Please sign in to comment.