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:
parent
29400b18a6
commit
7a96ed2771
4 changed files with 64 additions and 0 deletions
|
@ -605,6 +605,23 @@ int fs_stat(const char *path, struct fs_dirent *entry);
|
||||||
*/
|
*/
|
||||||
int fs_statvfs(const char *path, struct fs_statvfs *stat);
|
int fs_statvfs(const char *path, struct fs_statvfs *stat);
|
||||||
|
|
||||||
|
#if defined(CONFIG_FILE_SYSTEM_MKFS)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create fresh file system
|
||||||
|
*
|
||||||
|
* @param fs_type Type of file system to create.
|
||||||
|
* @param dev_id Id of storage device.
|
||||||
|
* @param cfg Backend dependent init object. If NULL then default configuration is used.
|
||||||
|
* @param flags Additional flags for file system implementation.
|
||||||
|
*
|
||||||
|
* @retval 0 on success;
|
||||||
|
* @retval <0 negative errno code on error.
|
||||||
|
*/
|
||||||
|
int fs_mkfs(int fs_type, uintptr_t dev_id, void *cfg, int flags);
|
||||||
|
|
||||||
|
#endif /* CONFIG_FILE_SYSTEM_MKFS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Register a file system
|
* @brief Register a file system
|
||||||
*
|
*
|
||||||
|
|
|
@ -38,6 +38,8 @@ extern "C" {
|
||||||
* @param stat Checks the status of a file or directory specified by the path
|
* @param stat Checks the status of a file or directory specified by the path
|
||||||
* @param statvfs Returns the total and available space on the file system
|
* @param statvfs Returns the total and available space on the file system
|
||||||
* volume
|
* volume
|
||||||
|
* @param mkfs Formats a device to specified file system type. Note that this
|
||||||
|
* operation destroys existing data on a target device.
|
||||||
*/
|
*/
|
||||||
struct fs_file_system_t {
|
struct fs_file_system_t {
|
||||||
/* File operations */
|
/* File operations */
|
||||||
|
@ -66,6 +68,9 @@ struct fs_file_system_t {
|
||||||
struct fs_dirent *entry);
|
struct fs_dirent *entry);
|
||||||
int (*statvfs)(struct fs_mount_t *mountp, const char *path,
|
int (*statvfs)(struct fs_mount_t *mountp, const char *path,
|
||||||
struct fs_statvfs *stat);
|
struct fs_statvfs *stat);
|
||||||
|
#if defined(CONFIG_FILE_SYSTEM_MKFS)
|
||||||
|
int (*mkfs)(uintptr_t dev_id, void *cfg, int flags);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -51,6 +51,12 @@ config FILE_SYSTEM_SHELL
|
||||||
This shell provides basic browsing of the contents of the
|
This shell provides basic browsing of the contents of the
|
||||||
file system.
|
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
|
config FUSE_FS_ACCESS
|
||||||
bool "FUSE based access to file system partitions"
|
bool "FUSE based access to file system partitions"
|
||||||
depends on ARCH_POSIX
|
depends on ARCH_POSIX
|
||||||
|
|
|
@ -721,6 +721,42 @@ mount_err:
|
||||||
return rc;
|
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)
|
int fs_unmount(struct fs_mount_t *mp)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue