fs: Add fs_mkfs operation to fs api

Adds fs_mkfs function to fs api. It will allow to perform mkfs operation
in file systems added to Zephyr.

Signed-off-by: Franciszek Zdobylak <fzdobylak@internships.antmicro.com>
This commit is contained in:
Franciszek Zdobylak 2022-10-24 08:36:32 +02:00 committed by Carles Cufí
commit 7a96ed2771
4 changed files with 64 additions and 0 deletions

View file

@ -51,6 +51,12 @@ config FILE_SYSTEM_SHELL
This shell provides basic browsing of the contents of the
file system.
config FILE_SYSTEM_MKFS
bool "Allow to format file system"
help
Enables function fs_mkfs that can be used to format a storage
device.
config FUSE_FS_ACCESS
bool "FUSE based access to file system partitions"
depends on ARCH_POSIX

View file

@ -721,6 +721,42 @@ mount_err:
return rc;
}
#if defined(CONFIG_FILE_SYSTEM_MKFS)
int fs_mkfs(int fs_type, uintptr_t dev_id, void *cfg, int flags)
{
int rc = -EINVAL;
const struct fs_file_system_t *fs;
k_mutex_lock(&mutex, K_FOREVER);
/* Get file system information */
fs = fs_type_get(fs_type);
if (fs == NULL) {
LOG_ERR("fs type %d not registered!!",
fs_type);
rc = -ENOENT;
goto mount_err;
}
CHECKIF(fs->mkfs == NULL) {
LOG_ERR("fs type %d does not support mkfs", fs_type);
rc = -ENOTSUP;
goto mount_err;
}
rc = fs->mkfs(dev_id, cfg, flags);
if (rc < 0) {
LOG_ERR("mkfs error (%d)", rc);
goto mount_err;
}
mount_err:
k_mutex_unlock(&mutex);
return rc;
}
#endif /* CONFIG_FILE_SYSTEM_MKFS */
int fs_unmount(struct fs_mount_t *mp)
{