diff --git a/sys/include/vfs.h b/sys/include/vfs.h index 9047549c84..13d154382c 100644 --- a/sys/include/vfs.h +++ b/sys/include/vfs.h @@ -926,6 +926,18 @@ int vfs_mount(vfs_mount_t *mountp); */ int vfs_mount_by_path(const char *path); +/** + * @brief Unmount a file system with a pre-configured mount path + * + * @note This assumes mount points have been configured with @ref VFS_AUTO_MOUNT. + * + * @param[in] path Path of the pre-configured mount point + * + * @return 0 on success + * @return <0 on error + */ +int vfs_unmount_by_path(const char *path); + /** * @brief Rename a file * diff --git a/sys/vfs/vfs.c b/sys/vfs/vfs.c index 74ac84508f..90fbbf9aef 100644 --- a/sys/vfs/vfs.c +++ b/sys/vfs/vfs.c @@ -1197,4 +1197,15 @@ int vfs_mount_by_path(const char *path) return -ENOENT; } +int vfs_unmount_by_path(const char *path) +{ + for (unsigned i = 0; i < MOUNTPOINTS_NUMOF; ++i) { + if (strcmp(path, vfs_mountpoints_xfa[i].mount_point) == 0) { + return vfs_umount(&vfs_mountpoints_xfa[i]); + } + } + + return -ENOENT; +} + /** @} */