mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
vfs: add format function in vfs api
This commit is contained in:
parent
bba457290e
commit
2eca6d25fd
@ -426,6 +426,16 @@ struct vfs_dir_ops {
|
||||
* Similar, but not equal, to struct super_operations in Linux
|
||||
*/
|
||||
struct vfs_file_system_ops {
|
||||
/**
|
||||
* @brief Format the file system on the given mount point
|
||||
*
|
||||
* @param[in] mountp file system to format
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return <0 on error
|
||||
*/
|
||||
int (*format) (vfs_mount_t *mountp);
|
||||
|
||||
/**
|
||||
* @brief Perform any extra processing needed after mounting a file system
|
||||
*
|
||||
@ -695,6 +705,21 @@ int vfs_readdir(vfs_DIR *dirp, vfs_dirent_t *entry);
|
||||
*/
|
||||
int vfs_closedir(vfs_DIR *dirp);
|
||||
|
||||
/**
|
||||
* @brief Format a file system
|
||||
*
|
||||
* @p mountp should have been populated in advance with a file system driver,
|
||||
* a mount point, and private_data (if the file system driver uses one).
|
||||
*
|
||||
* @pre @p mountp must not be mounted
|
||||
*
|
||||
* @param[in] mountp pointer to the mount structure of the filesystem to format
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return <0 on error
|
||||
*/
|
||||
int vfs_format(vfs_mount_t *mountp);
|
||||
|
||||
/**
|
||||
* @brief Mount a file system
|
||||
*
|
||||
|
@ -407,9 +407,18 @@ int vfs_closedir(vfs_DIR *dirp)
|
||||
return res;
|
||||
}
|
||||
|
||||
int vfs_mount(vfs_mount_t *mountp)
|
||||
/**
|
||||
* @brief Check if the given mount point is mounted
|
||||
*
|
||||
* If the mount point is not mounted, _mount_mutex will be locked by this function
|
||||
*
|
||||
* @param mountp mount point to check
|
||||
* @return 0 on success (mount point is valid and not mounted)
|
||||
* @return -EINVAL if mountp is invalid
|
||||
* @return -EBUSY if mountp is already mounted
|
||||
*/
|
||||
static int check_mount(vfs_mount_t *mountp)
|
||||
{
|
||||
DEBUG("vfs_mount: %p\n", (void *)mountp);
|
||||
if ((mountp == NULL) || (mountp->fs == NULL) || (mountp->mount_point == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -429,11 +438,43 @@ int vfs_mount(vfs_mount_t *mountp)
|
||||
DEBUG("vfs_mount: Already mounted\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vfs_format(vfs_mount_t *mountp)
|
||||
{
|
||||
DEBUG("vfs_format: %p\n", (void *)mountp);
|
||||
int ret = check_mount(mountp);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
mutex_unlock(&_mount_mutex);
|
||||
|
||||
if (mountp->fs->fs_op != NULL) {
|
||||
if (mountp->fs->fs_op->format != NULL) {
|
||||
return mountp->fs->fs_op->format(mountp);
|
||||
}
|
||||
}
|
||||
|
||||
/* Format operation not supported */
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
int vfs_mount(vfs_mount_t *mountp)
|
||||
{
|
||||
DEBUG("vfs_mount: %p\n", (void *)mountp);
|
||||
int ret = check_mount(mountp);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (mountp->fs->fs_op != NULL) {
|
||||
if (mountp->fs->fs_op->mount != NULL) {
|
||||
/* yes, a file system driver does not need to implement mount/umount */
|
||||
int res = mountp->fs->fs_op->mount(mountp);
|
||||
if (res < 0) {
|
||||
DEBUG("vfs_mount: error %d\n", res);
|
||||
mutex_unlock(&_mount_mutex);
|
||||
return res;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user